libUPnP
1.8.4
|
Defines the Web Server and has functions to carry out operations of the Web Server. More...
#include "config.h"
#include "webserver.h"
#include "FileInfo.h"
#include "httpparser.h"
#include "httpreadwrite.h"
#include "ithread.h"
#include "membuffer.h"
#include "ssdplib.h"
#include "statcodes.h"
#include "strintmap.h"
#include "unixutil.h"
#include "upnp.h"
#include "upnpapi.h"
#include "UpnpIntTypes.h"
#include "UpnpStdInt.h"
#include "upnputil.h"
#include "VirtualDir.h"
#include <assert.h>
#include <fcntl.h>
#include <sys/stat.h>
Data Structures | |
struct | document_type_t |
struct | xml_alias_t |
Enumerations | |
enum | resp_type { RESP_FILEDOC, RESP_XMLDOC, RESP_HEADERS, RESP_WEBDOC, RESP_POST } |
Functions | |
static UPNP_INLINE void | media_list_init (void) |
Decodes list and stores it in gMediaTypeList. More... | |
static UPNP_INLINE int | search_extension (const char *extension, const char **con_type, const char **con_subtype) |
Based on the extension, returns the content type and content subtype. More... | |
static UPNP_INLINE int | get_content_type (const char *filename, OUT UpnpFileInfo *fileInfo) |
Based on the extension, clones an XML string based on type and content subtype. If content type and sub type are not found, unknown types are used. More... | |
static UPNP_INLINE void | glob_alias_init (void) |
Initialize the global XML document. Allocate buffers for the XML document. More... | |
static UPNP_INLINE int | is_valid_alias (const struct xml_alias_t *alias) |
Check for the validity of the XML object buffer. More... | |
static void | alias_grab (struct xml_alias_t *alias) |
Copy the contents of the global XML document into the local output parameter. More... | |
static void | alias_release (struct xml_alias_t *alias) |
Release the XML document referred to by the input parameter. Free the allocated buffers associated with this object. More... | |
int | web_server_set_alias (const char *alias_name, const char *alias_content, size_t alias_content_length, time_t last_modified) |
Replaces current alias with the given alias. To remove the current alias, set alias_name to NULL. More... | |
int | web_server_init () |
Initilialize the different documents. Initialize the memory for root directory for web server. Call to initialize global XML document. Sets bWebServerState to WEB_SERVER_ENABLED. More... | |
void | web_server_destroy (void) |
Release memory allocated for the global web server root directory and the global XML document. Resets the flag bWebServerState to WEB_SERVER_DISABLED. More... | |
static int | get_file_info (const char *filename, OUT UpnpFileInfo *info) |
Release memory allocated for the global web server root directory and the global XML document. Resets the flag bWebServerState to WEB_SERVER_DISABLED. More... | |
int | web_server_set_root_dir (const char *root_dir) |
Assign the path specfied by the input const char* root_dir parameter to the global Document root directory. Also check for path names ending in '/'. More... | |
static UPNP_INLINE int | get_alias (const char *request_file, struct xml_alias_t *alias, UpnpFileInfo *info) |
Compare the files names between the one on the XML alias the one passed in as the input parameter. If equal extract file information. More... | |
static int | isFileInVirtualDir (char *filePath, const void **cookie) |
Compares filePath with paths from the list of virtual directory lists. More... | |
static void | ToUpperCase (char *s) |
Converts input string to upper case. More... | |
static char * | StrStr (char *s1, const char *s2) |
Finds a substring from a string in a case insensitive way. More... | |
static char * | StrTok (char **Src, const char *Del) |
Finds next token in a string. More... | |
static int | GetNextRange (char **SrcRangeStr, off_t *FirstByte, off_t *LastByte) |
Returns a range of integers from a string. More... | |
static int | 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. More... | |
static int | CheckOtherHTTPHeaders (http_message_t *Req, struct SendInstruction *RespInstr, off_t FileSize) |
Get header id from the request parameter and take appropriate action based on the ids as an HTTP Range Response. More... | |
static int | process_request (http_message_t *req, enum resp_type *rtype, membuffer *headers, membuffer *filename, struct xml_alias_t *alias, struct SendInstruction *RespInstr) |
Processes the request and returns the result in the output parameters. More... | |
static int | http_RecvPostMessage (http_parser_t *parser, SOCKINFO *info, char *filename, struct SendInstruction *Instr) |
Receives the HTTP post message. More... | |
void | web_server_callback (http_parser_t *parser, INOUT http_message_t *req, SOCKINFO *info) |
Variables | |
static const char * | gMediaTypes [] |
static const char * | gEncodedMediaTypes |
static struct document_type_t | gMediaTypeList [70] |
membuffer | gDocumentRootDir |
static struct xml_alias_t | gAliasDoc |
static ithread_mutex_t | gWebMutex |
str_int_entry | Http_Header_Names [33] |
Defines the Web Server and has functions to carry out operations of the Web Server.
enum resp_type |
Response Types.
|
static |
Copy the contents of the global XML document into the local output parameter.
[out] | alias | XML alias object. |
|
static |
Release the XML document referred to by the input parameter. Free the allocated buffers associated with this object.
[in] | alias | XML alias object. |
Referenced by web_server_set_alias().
|
static |
Get header id from the request parameter and take appropriate action based on the ids as an HTTP Range Response.
HTTP_BAD_REQUEST
HTTP_INTERNAL_SERVER_ERROR
HTTP_REQUEST_RANGE_NOT_SATISFIABLE
HTTP_OK
[in] | Req | HTTP Request message. |
[out] | RespInstr | Send Instruction object to data for the response. |
FileSize | Size of the file containing the request document. |
|
static |
Fills in the Offset, read size and contents to send out as an HTTP Range Response.
HTTP_BAD_REQUEST
HTTP_INTERNAL_SERVER_ERROR
HTTP_REQUEST_RANGE_NOT_SATISFIABLE
HTTP_OK
ByteRangeSpecifier | String containing the range. | |
FileLength | Length of the file. | |
[out] | Instr | SendInstruction object where the range operations will be stored. |
References GetNextRange(), SendInstruction::ReadSendSize, and StrStr().
|
static |
Compare the files names between the one on the XML alias the one passed in as the input parameter. If equal extract file information.
TRUE
- On Success FALSE
if request is not an alias [in] | request_file | request file passed in to be compared with. |
[out] | alias | xml alias object which has a file name stored. |
[out] | info | File information object which will be filled up if the file comparison succeeds. |
References membuffer::buf, xml_alias_t::doc, membuffer::length, and xml_alias_t::name.
|
static |
Based on the extension, clones an XML string based on type and content subtype. If content type and sub type are not found, unknown types are used.
0
on success. UPNP_E_OUTOF_MEMORY
- on memory allocation failures. [in] | filename | . |
[out] | fileInfo | . |
|
static |
Release memory allocated for the global web server root directory and the global XML document. Resets the flag bWebServerState to WEB_SERVER_DISABLED.
[in] | filename | Filename having the description document. |
[out] | info | File information object having file attributes such as filelength, when was the file last modified, whether a file or a directory and whether the file or directory is readable. |
|
static |
Returns a range of integers from a string.
SrcRangeStr | string containing the token / range. |
FirstByte | gets the first byte of the token. |
LastByte | gets the last byte of the token. |
References StrTok().
Referenced by CreateHTTPRangeResponseHeader().
|
static |
Initialize the global XML document. Allocate buffers for the XML document.
References xml_alias_t::ct, xml_alias_t::doc, gAliasDoc, xml_alias_t::last_modified, membuffer_init(), and xml_alias_t::name.
|
static |
Receives the HTTP post message.
HTTP_INTERNAL_SERVER_ERROR
HTTP_UNAUTHORIZED
HTTP_BAD_REQUEST
HTTP_SERVICE_UNAVAILABLE
HTTP_OK
parser | HTTP Parser object. | |
[in] | info | Socket Information object. |
filename | File where received data is copied to. | |
Instr | Send Instruction object which gives information whether the file is a virtual file or not. |
References PARSE_OK.
|
static |
Check for the validity of the XML object buffer.
[in] | alias | XML alias object. |
References membuffer::buf, and xml_alias_t::doc.
|
static |
Compares filePath with paths from the list of virtual directory lists.
[in] | filePath | Directory path to be tested for virtual directory. |
[out] | cookie | The cookie registered with this virtual directory, if matched. |
References pVirtualDirList.
|
static |
Decodes list and stores it in gMediaTypeList.
|
static |
Processes the request and returns the result in the output parameters.
HTTP_BAD_REQUEST
HTTP_INTERNAL_SERVER_ERROR
HTTP_REQUEST_RANGE_NOT_SATISFIABLE
HTTP_FORBIDDEN
HTTP_NOT_FOUND
HTTP_NOT_ACCEPTABLE
HTTP_OK
[in] | req | HTTP Request message. |
[out] | rtype | Tpye of response. |
[out] | headers | Headers. |
[out] | filename | Get filename from request document. |
[out] | alias | Xml alias document from the request document. |
[out] | RespInstr | Send Instruction object where the response is set up. |
References http_message_t::method, print_http_headers(), and http_message_t::uri.
|
static |
Based on the extension, returns the content type and content subtype.
0
on success -1
on error [in] | extension | . |
[out] | con_type | . |
[out] | con_subtype | . |
|
static |
Finds a substring from a string in a case insensitive way.
s1 | Input string. |
s2 | Input sub-string. |
References ToUpperCase().
Referenced by CreateHTTPRangeResponseHeader().
|
static |
Finds next token in a string.
Src | String containing the token. |
Del | Set of delimiter characters. |
Referenced by GetNextRange().
|
static |
Converts input string to upper case.
s | Input string to be converted. |
Referenced by StrStr().
void web_server_destroy | ( | void | ) |
Release memory allocated for the global web server root directory and the global XML document. Resets the flag bWebServerState to WEB_SERVER_DISABLED.
References bWebServerState.
int web_server_init | ( | void | ) |
Initilialize the different documents. Initialize the memory for root directory for web server. Call to initialize global XML document. Sets bWebServerState to WEB_SERVER_ENABLED.
0
- OK UPNP_E_OUTOF_MEMORY
References bWebServerState.
Referenced by UpnpEnableWebserver().
int web_server_set_alias | ( | const char * | alias_name, |
const char * | alias_content, | ||
size_t | alias_content_length, | ||
time_t | last_modified | ||
) |
Replaces current alias with the given alias. To remove the current alias, set alias_name to NULL.
0
- OK UPNP_E_OUTOF_MEMORY
[in] | alias_name | Webserver name of alias; created by caller and freed by caller (doesn't even have to be malloc()d. |
[in] | alias_content | The xml doc; this is allocated by the caller; and freed by the web server. |
[in] | alias_content_length | Length of alias body in bytes. |
[in] | last_modified | Time when the contents of alias were last changed (local time). |
References alias_release(), xml_alias_t::ct, xml_alias_t::doc, gAliasDoc, xml_alias_t::last_modified, membuffer_append_str(), membuffer_assign_str(), membuffer_attach(), membuffer_init(), and xml_alias_t::name.
int web_server_set_root_dir | ( | const char * | root_dir | ) |
Assign the path specfied by the input const char* root_dir parameter to the global Document root directory. Also check for path names ending in '/'.
[in] | root_dir | String having the root directory for the document. |
References membuffer::buf, membuffer::length, membuffer_assign_str(), and membuffer_delete().
Referenced by AutoAdvertise().
|
static |
XML document.
Referenced by glob_alias_init(), and web_server_set_alias().
|
static |
module variables - Globals, static and externs.
|
static |