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

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

#include <miniserver.hpp>
#include <sock.hpp>
+ Include dependency graph for webserver.hpp:

Go to the source code of this file.

Classes

struct  SendInstruction
 Send instruction. More...
 

Macros

#define X_USER_AGENT   "redsonic"
 Can be overwritten by configure CFLAGS argument.
 

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.
 

Variables

membuffer gDocumentRootDir
 
membuffer gWebserverCorsString
 

Detailed Description

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

Definition in file webserver.hpp.


Class Documentation

◆ SendInstruction

struct SendInstruction

Send instruction.

Definition at line 50 of file webserver.hpp.

Class Members
int IsVirtualFile member variable
int IsChunkActive member variable
int IsRangeActive member variable
int IsTrailers member variable
char RangeHeader[200] member variable
char AcceptLanguageHeader[200] member variable
off_t RangeOffset member variable
off_t ReadSendSize Read from local source and send on the network.
long RecvWriteSize Recv from the network and write into local file.
const void * CorsHeader

CorsHeader.

const void * Cookie Cookie associated with the virtualDir.
const void * RequestCookie Cookie associated with the request.

Macro Definition Documentation

◆ X_USER_AGENT

#define X_USER_AGENT   "redsonic"

Can be overwritten by configure CFLAGS argument.

If not already defined, the {X_USER_AGENT} constant specifies the value of the X-User-Agent: HTTP header. The value "redsonic" is needed for the DSM-320. See https://sourceforge.net/forum/message.php?msg_id=3166856 for more information.

Todo:
Check setting of X_USER_AGENT.

Definition at line 87 of file webserver.hpp.

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:

Variable Documentation

◆ gDocumentRootDir

membuffer gDocumentRootDir
inline

Global variable. A local dir which serves as webserver root.

Definition at line 45 of file webserver.hpp.

◆ gWebserverCorsString

membuffer gWebserverCorsString
inline

Global variable. A string which is set in the header field.

Definition at line 47 of file webserver.hpp.