UPnPsdk 0.1
Universal Plug and Play +, Software Development Kit
 
Loading...
Searching...
No Matches
webserver.cpp File Reference

Internal Web Server and functions to carry out operations of it. More...

#include <webserver.hpp>
#include <UpnpExtraHeaders.hpp>
#include <UpnpIntTypes.hpp>
#include <httpreadwrite.hpp>
#include <ssdp_common.hpp>
#include <statcodes.hpp>
#include <upnpapi.hpp>
#include <UPnPsdk/synclog.hpp>
#include <UPnPsdk/port.hpp>
#include <UPnPsdk/webserver.hpp>
#include <umock/stdlib.hpp>
#include <umock/stdio.hpp>
+ Include dependency graph for webserver.cpp:

Go to the source code of this file.

Classes

struct  compa::anonymous_namespace{webserver.cpp}::CXmlAlias
 Alias directory structure on the webserver for an XML document. More...
 

Namespaces

namespace  compa
 Refactored pupnp program code that is compatible to the original pupnp code.
 

Enumerations

enum  compa::anonymous_namespace{webserver.cpp}::resp_type {
  RESP_UNSPEC , RESP_FILEDOC , RESP_XMLDOC , RESP_HEADERS ,
  RESP_WEBDOC , RESP_POST
}
 Response Types. More...
 

Functions

void web_server_init ()
 Initilialize root directory for web server and different documents.
 
int web_server_set_alias (const char *a_alias_name, const char *a_alias_content, size_t a_alias_content_length, time_t a_last_modified)
 Replaces current alias with the given alias.
 
int web_server_set_root_dir (const char *root_dir)
 Assign the path to the global Document root directory.
 
int web_server_set_cors (const char *cors_string)
 Assign the Access-Control-Allow-Origin specfied by the input const char* cors_string parameterto the global CORS string.
 
void web_server_callback (http_parser_t *a_parser, http_message_t *a_req, SOCKINFO *a_info)
 Main entry point into web server.
 
void SetHTTPGetCallback (MiniServerCallback callback)
 Set HTTP Get Callback.
 
void web_server_destroy ()
 Release memory allocated for the global web server root directory and the global XML document.
 
Scope restricted to file
char * compa::anonymous_namespace{webserver.cpp}::web_server_asctime_r (const struct tm *tm, char *buf)
 Multiplatform wrapper to make win32 asctime_s compatible to posix asctime_r.
 
int compa::anonymous_namespace{webserver.cpp}::search_extension (const char *a_extension, const char **a_con_type, const char **a_con_subtype)
 Based on the extension, returns the content type and content subtype.
 
int compa::anonymous_namespace{webserver.cpp}::get_content_type (const char *filename, UpnpFileInfo *fileInfo)
 Based on the extension of the filename, clones an XML string based on type and content subtype.
 
int compa::anonymous_namespace{webserver.cpp}::get_file_info (const char *filename, UpnpFileInfo *info)
 Get file information.
 
int compa::anonymous_namespace{webserver.cpp}::get_alias (const char *request_file, CXmlAlias *alias, UpnpFileInfo *info)
 Compare file names.
 
int compa::anonymous_namespace{webserver.cpp}::isFileInVirtualDir (char *filePath, const void **cookie)
 Compares filePath with paths from the list of virtual directory lists.
 
void compa::anonymous_namespace{webserver.cpp}::ToUpperCase (char *s)
 Converts C string in place to upper case.
 
char * compa::anonymous_namespace{webserver.cpp}::StrStr (char *s1, const char *s2)
 Finds a substring from a string in a case insensitive way.
 
char * compa::anonymous_namespace{webserver.cpp}::StrTok (char **Src, const char *Del)
 Finds next token in a string.
 
int compa::anonymous_namespace{webserver.cpp}::GetNextRange (char **SrcRangeStr, off_t *FirstByte, off_t *LastByte)
 Returns a range of integers from a string.
 
int compa::anonymous_namespace{webserver.cpp}::CreateHTTPRangeResponseHeader (char *ByteRangeSpecifier, off_t FileLength, struct SendInstruction *Instr)
 Fills in the Offset, read size and contents to send out as an HTTP Range Response.
 
int compa::anonymous_namespace{webserver.cpp}::CheckOtherHTTPHeaders (http_message_t *Req, struct SendInstruction *RespInstr, off_t FileSize)
 Get header id from the request parameter.
 
void compa::anonymous_namespace{webserver.cpp}::FreeExtraHTTPHeaders (UpnpListHead *extraHeadersList)
 Free extra HTTP headers.
 
int compa::anonymous_namespace{webserver.cpp}::ExtraHTTPHeaders (http_message_t *Req, UpnpListHead *extraHeadersList)
 Build an array of unrecognized headers.
 
int compa::anonymous_namespace{webserver.cpp}::process_request_in (SOCKINFO *info, http_message_t *req, enum resp_type *rtype, membuffer *headers, membuffer *filename, CXmlAlias *a_alias, SendInstruction *RespInstr)
 Process a remote request and return the result.
 
int compa::anonymous_namespace{webserver.cpp}::http_RecvPostMessage (http_parser_t *parser, SOCKINFO *info, char *filename, struct SendInstruction *Instr)
 Receives the HTTP post message.
 

Variables

const char * compa::anonymous_namespace{webserver.cpp}::gMediaTypes []
 Media types.
 
constexpr size_t compa::anonymous_namespace{webserver.cpp}::APPLICATION_INDEX {4}
 index to get media type of application from the media types table.
 
constexpr size_t compa::anonymous_namespace{webserver.cpp}::ASCTIME_R_BUFFER_SIZE {26}
 Number of elements for asctime_s on win32, means buffer size.
 
CXmlAlias compa::anonymous_namespace{webserver.cpp}::gAliasDoc
 Global XML document object.
 

Detailed Description

Internal Web Server and functions to carry out operations of it.

Definition in file webserver.cpp.

Function Documentation

◆ web_server_init()

void web_server_init ( )

Initilialize root directory for web server and different documents.

Initilialize the different documents. Initialize the memory for root directory for web server. Sets bWebServerState to WEB_SERVER_ENABLED.

Definition at line 1518 of file webserver.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ web_server_set_alias()

int web_server_set_alias ( const char *  a_alias_name,
const char *  a_alias_content,
size_t  a_alias_content_length,
time_t  a_last_modified 
)

Replaces current alias with the given alias.

To remove the current alias, set a_alias_name to nullptr.

Returns
  • UPNP_E_SUCCESS
  • UPNP_E_INVALID_ARGUMENT
Parameters
[in]a_alias_namePointer to webserver name of alias for a copy; the ownership of this C string with terminating '\0' remains by the caller. He is still responsible to manage it (e.g. deallocating if allocated etc.).
[in,out]a_alias_contentPointer to the xml doc. This string must be allocated by the caller. Ownership of this argument is then taken over by the web server to manage it, in particular also deallocate it. The caller hasn't to worry about memory management.
[in,out]a_alias_content_lengthLength of alias body in bytes. Document can also contain '\0' characters within its length.
[in]a_last_modifiedTime when contents of alias were last changed (local time).

Definition at line 1538 of file webserver.cpp.

+ Here is the caller graph for this function:

◆ web_server_set_root_dir()

int web_server_set_root_dir ( const char *  root_dir)

Assign the path to the global Document root directory.

Also check for path names ending in '/'.

Returns
On success: 0
On error:
  • UPNP_E_INVALID_ARGUMENT
  • UPNP_E_OUTOF_MEMORY
Parameters
[in]root_dirString having the root directory for the document.

Definition at line 1546 of file webserver.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ web_server_set_cors()

int web_server_set_cors ( const char *  cors_string)

Assign the Access-Control-Allow-Origin specfied by the input const char* cors_string parameterto the global CORS string.

Returns
Integer.
Parameters
[in]cors_stringString having the Access-Control-Allow-Origin string.

Definition at line 1564 of file webserver.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ web_server_callback()

void web_server_callback ( http_parser_t a_parser,
http_message_t a_req,
SOCKINFO a_info 
)

Main entry point into web server.

Handles HTTP GET and HEAD requests.

Parameters
[in]a_parser.
[in]a_req.
[in,out]a_info.

Definition at line 1574 of file webserver.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SetHTTPGetCallback()

void SetHTTPGetCallback ( MiniServerCallback  callback)

Set HTTP Get Callback.

Parameters
[in]callbackHTTP Callback to be invoked.

Definition at line 1645 of file webserver.cpp.

+ Here is the caller graph for this function:

◆ web_server_destroy()

void web_server_destroy ( )

Release memory allocated for the global web server root directory and the global XML document.

Resets the flag bWebServerState to WEB_SERVER_DISABLED.

Definition at line 1650 of file webserver.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function: