46#include <webserver.hpp>
56using compa::uriType::Absolute;
73 size_t ipaddr_port_size)
75 char buf_ntop[INET6_ADDRSTRLEN];
78 if (addr->sa_family == AF_INET) {
79 struct sockaddr_in* sa4 = (
struct sockaddr_in*)addr;
80 inet_ntop(AF_INET, &sa4->sin_addr, buf_ntop,
sizeof(buf_ntop));
81 rc = snprintf(ipaddr_port, ipaddr_port_size,
"%s:%d", buf_ntop,
82 (
int)ntohs(sa4->sin_port));
83 }
else if (addr->sa_family == AF_INET6) {
84 struct sockaddr_in6* sa6 = (
struct sockaddr_in6*)addr;
85 inet_ntop(AF_INET6, &sa6->sin6_addr, buf_ntop,
sizeof(buf_ntop));
86 rc = snprintf(ipaddr_port, ipaddr_port_size,
"[%s]:%d", buf_ntop,
87 (
int)ntohs(sa6->sin6_port));
91 if (rc < 0 || (
unsigned int)rc > ipaddr_port_size)
107 const char* rootPath,
111 const char* aliasPtr;
113 const char* temp_str;
114 size_t new_alias_len;
121 root_len = strlen(rootPath);
122 if (root_len == 0 || rootPath[root_len - 1] !=
'/')
128 aliasPtr = alias + 1;
131 new_alias_len = root_len + strlen(temp_str) + strlen(aliasPtr) + (size_t)1;
132 alias_temp = (
char*)malloc(new_alias_len);
133 if (alias_temp ==
nullptr)
135 memset(alias_temp, 0, new_alias_len);
136 snprintf(alias_temp, new_alias_len,
"%s%s%s", rootPath, temp_str, aliasPtr);
138 *newAlias = alias_temp;
151 const char* ipPortStr,
157 const char* http_scheme =
"http://";
159 assert(ipPortStr != NULL && strlen(ipPortStr) > 0);
160 assert(alias != NULL && strlen(alias) > 0);
162 len = strlen(http_scheme) + strlen(ipPortStr) + strlen(alias) + (size_t)1;
165 snprintf(descURL, len,
"%s%s%s", http_scheme, ipPortStr, alias);
166 UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__,
"desc url: %s\n", descURL);
191 char** root_path_str) {
197 const char* urlBaseStr =
"URLBase";
209 if (baseList == NULL) {
212 if (element == NULL) {
222 if (rootNode == NULL) {
227 if (err_code != IXML_SUCCESS) {
232 if (textNode == NULL) {
236 if (err_code != IXML_SUCCESS) {
243 assert(urlbase_node != NULL);
245 if (textNode == NULL) {
250 if (domStr == NULL) {
254 len =
parse_uri(domStr, strlen(domStr), &uri);
255 if (len < 0 || uri.
type != Absolute) {
279 if (url_str.
buf[url_str.
length - 1] !=
'/') {
285 if (err_code != IXML_SUCCESS) {
308 const char* alias, time_t last_modified,
310 char* root_path = NULL;
311 char* new_alias = NULL;
312 char* xml_str = NULL;
317 err_code =
addrToString(serverAddr, ipaddr_port,
sizeof(ipaddr_port));
328 err_code =
calc_alias(alias, root_path, &new_alias);
333 err_code =
calc_descURL(ipaddr_port, new_alias, docURL);
339 if (xml_str == NULL) {
343 UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__,
"desc url: %s\n", docURL);
344 UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__,
"doc = %s\n", xml_str);
#define UPNP_E_BUFFER_TOO_SMALL
The operation completed successfully.
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.
token scheme
Member variable.
size_t size
Size of the buffer.
compa::uriType type
Member variable.
token pathquery
Member variable.
Represents a URI used in parse_uri and elsewhere.
Data structure common to all types of nodes.
Data structure representing a list of nodes.
Data structure representing an Element node.
Data structure representing the DOM Document.
PUPNP_Api int ixmlNode_appendChild(IXML_Node *nodeptr, IXML_Node *newChild)
Appends a child Node to the list of children of a Node.
PUPNP_Api int ixmlNode_setNodeValue(IXML_Node *nodeptr, const char *newNodeValue)
Assigns a new value to a Node.
PUPNP_Api IXML_Element * ixmlDocument_createElement(IXML_Document *doc, const DOMString tagName)
Creates a new Element node with the given tag name.
#define DOMString
The type of DOM strings.
PUPNP_Api IXML_Node * ixmlDocument_createTextNode(IXML_Document *doc, const DOMString data)
Creates a new Text node with the given data.
PUPNP_Api const DOMString ixmlNode_getNodeValue(IXML_Node *nodeptr)
Returns the value of the Node as a string.
PUPNP_Api IXML_NodeList * ixmlDocument_getElementsByTagName(IXML_Document *doc, const DOMString tagName)
Returns a NodeList of all Elements that match the given tag name in the order in which they were enco...
PUPNP_Api DOMString ixmlPrintDocument(IXML_Document *doc)
Renders a Node and all sub-elements into an XML document representation.
PUPNP_Api void ixmlFreeDOMString(DOMString buf)
Frees a DOMString.
PUPNP_Api void ixmlNodeList_free(IXML_NodeList *nList)
Frees a NodeList object.
PUPNP_Api void ixmlElement_free(IXML_Element *element)
Frees the given Element and any subtree of the Element.
PUPNP_Api IXML_Node * ixmlNode_getFirstChild(IXML_Node *nodeptr)
Retrieves the first child Node of a Node.
PUPNP_Api IXML_Node * ixmlNodeList_item(IXML_NodeList *nList, unsigned long index)
Retrieves a Node from a NodeList specified by a numerical index.
void membuffer_destroy(membuffer *m)
Free's memory allocated for membuffer* m.
void membuffer_init(membuffer *m)
Wrapper to membuffer_initialize().
int membuffer_append(membuffer *m, const void *buf, size_t buf_len)
Invokes function to appends data from a constant buffer to the buffer.
char * membuffer_detach(membuffer *m)
Detaches current buffer and returns it. The caller must free the returned buffer using free()....
int membuffer_append_str(membuffer *m, const char *c_str)
Invokes function to appends data from a constant string to the buffer.
int membuffer_assign(membuffer *m, const void *buf, size_t buf_len)
Allocate memory to membuffer *m and copy the contents of the in parameter const void *buf.
size_t length
length of buffer without terminating null byte (read-only).
char * buf
mem buffer; must not write beyond buf[length-1] (read/write).
Maintains a block of dynamically allocated memory.
#define UPNP_E_SUCCESS
The operation completed successfully.
#define UPNP_E_OUTOF_MEMORY
Not enough resources are currently available to complete the operation.
#define UPNP_E_INVALID_URL
An URL passed into the function is invalid.
#define UPNP_E_INVALID_DESC
The description document passed to UpnpRegisterRootDevice, UpnpRegisterRootDevice2 UpnpRegisterRootDe...
#define UPNP_E_URL_TOO_BIG
The URL passed into a function is too long.
#define UPNP_E_INTERNAL_ERROR
Generic error code for internal conditions not covered by other error codes.
int config_description_doc(IXML_Document *doc, const char *ip_str, char **root_path_str)
Configure the description document.
int calc_descURL(const char *ipPortStr, const char *alias, char descURL[LINE_SIZE])
Determines the description URL.
int addrToString(const sockaddr *addr, char *ipaddr_port, size_t ipaddr_port_size)
Converts an Internet address to a string and stores it in a buffer.
int calc_alias(const char *alias, const char *rootPath, char **newAlias)
Determine alias based urlbase's root path.
Unix-specific network utilities.
Manage Debug messages with levels "critical" to "all".
UPnPsdk_VIS void UpnpPrintf(Upnp_LogLevel DLevel, Dbg_Module Module, const char *DbgFileName, int DbgLineNo, const char *FmtStr,...)
Prints the debug statement.
int parse_uri(const char *in, size_t max, uri_type *out)
Parses a uri as defined in RFC 2396 (explaining URIs).
int configure_urlbase(IXML_Document *doc, const sockaddr *serverAddr, const char *alias, time_t last_modified, char docURL[LINE_SIZE])
Configure the full URL for the description document.
Configure the full URL for the description document.