45#include <httpreadwrite.hpp>
50#ifndef COMPA_INTERNAL_CONFIG_HPP
51#error "No or wrong config.hpp header file included."
102 if (node_name == NULL)
104 if (strcmp(name, node_name) == 0)
106 else if (
matchstr((
char*)node_name, strlen(node_name),
"%s:%s%0", &dummy,
108 strcmp(nameptr.
buf, name) == 0)
127 const char* node_name,
135 if (!node_name || !start_node)
138 while (node != NULL) {
141 *matching_node = node;
171 assert(num_names > 0);
175 if (num_names == 1) {
176 *matching_node = start_node;
180 for (i = 1; i < num_names; i++) {
183 if (i == num_names - 1) {
184 *matching_node = match_node;
208 if (text_node == NULL) {
256 ret_code =
matchstr(action, strlen(action),
" <%s:%s", &dummy, name);
258 return ret_code ==
PARSE_OK ? 0 : -1;
272 char* soap_action_hdr;
273 const char* man_hdr =
274 "MAN: \"http://schemas.xmlsoap.org/soap/envelope/\"; ns=01\r\n01-";
279 soap_action_hdr = strstr(headers->
buf,
"SOAPACTION:");
281 assert(soap_action_hdr != NULL);
283 n = (size_t)(soap_action_hdr - headers->
buf);
330 request->
length, HTTPMETHOD_MPOST,
360 int* upnp_error_code,
369 char* node_str = NULL;
370 const char* temp_str = NULL;
374 const char* names[5];
379 hmsg->
status_code != HTTP_INTERNAL_SERVER_ERROR) ||
385 if (root_node == NULL)
389 assert(action_value != NULL);
391 *action_value = NULL;
392 names[0] =
"Envelope";
397 if (node_str == NULL) {
411 assert(str_value != NULL);
414 names[0] =
"Envelope";
416 names[2] =
"QueryStateVariableResponse";
420 if (nodeValue == NULL)
430 names[0] =
"Envelope";
434 names[4] =
"UPnPError";
443 *upnp_error_code = atoi(temp_str);
444 if (*upnp_error_code > 400) {
445 err_code = *upnp_error_code;
454 if (nodeValue == NULL) {
458 if (*str_value == NULL) {
464 if (error_node_str == NULL) {
492 char* action_str = NULL;
501 char* upnp_error_str;
502 int got_response = 0;
504 off_t content_length;
505 const char* xml_start =
507 "xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" "
508 "s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\r\n"
510 const char* xml_end =
"</s:Body>\r\n"
511 "</s:Envelope>\r\n\r\n";
512 size_t xml_start_len;
514 size_t action_str_len;
516 *response_node = NULL;
520 UpnpPrintf(UPNP_INFO, SOAP, __FILE__, __LINE__,
"Inside SoapSendAction():");
527 if (action_str == NULL) {
541 UpnpPrintf(UPNP_INFO, SOAP, __FILE__, __LINE__,
546 xml_start_len = strlen(xml_start);
547 xml_end_len = strlen(xml_end);
548 action_str_len = strlen(action_str);
552 content_length = (off_t)(xml_start_len + action_str_len + xml_end_len);
562 SOAPMETHOD_POST, &url, content_length,
564 name.
buf, name.
length,
"\"", xml_start, xml_start_len,
565 action_str, action_str_len, xml_end,
583 responsename.
buf, &upnp_error_code,
584 (
IXML_Node**)response_node, &upnp_error_str);
589 err_code = upnp_error_code;
608 char* xml_header_str = NULL;
609 char* action_str = NULL;
618 char* upnp_error_str;
619 int got_response = 0;
620 const char* xml_start =
622 "xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" "
623 "s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\r\n";
624 const char* xml_header_start =
"<s:Header>\r\n";
625 const char* xml_header_end =
"</s:Header>\r\n";
626 const char* xml_body_start =
"<s:Body>";
627 const char* xml_end =
"</s:Body>\r\n"
629 size_t xml_start_len;
630 size_t xml_header_start_len;
631 size_t xml_header_str_len;
632 size_t xml_header_end_len;
633 size_t xml_body_start_len;
634 size_t action_str_len;
636 off_t content_length;
638 *response_node = NULL;
642 UpnpPrintf(UPNP_INFO, SOAP, __FILE__, __LINE__,
643 "Inside SoapSendActionEx():");
650 if (xml_header_str == NULL) {
655 if (action_str == NULL) {
669 UpnpPrintf(UPNP_INFO, SOAP, __FILE__, __LINE__,
674 xml_start_len = strlen(xml_start);
675 xml_body_start_len = strlen(xml_body_start);
676 xml_end_len = strlen(xml_end);
677 action_str_len = strlen(action_str);
679 xml_header_start_len = strlen(xml_header_start);
680 xml_header_end_len = strlen(xml_header_end);
681 xml_header_str_len = strlen(xml_header_str);
685 content_length = (off_t)(xml_start_len + xml_header_start_len +
686 xml_header_str_len + xml_header_end_len +
687 xml_body_start_len + action_str_len + xml_end_len);
701 SOAPMETHOD_POST, &url, content_length,
703 name.
buf, name.
length,
"\"", xml_start, xml_start_len,
704 xml_header_start, xml_header_start_len, xml_header_str,
705 xml_header_str_len, xml_header_end, xml_header_end_len,
706 xml_body_start, xml_body_start_len, action_str,
707 action_str_len, xml_end, xml_end_len) != 0) {
724 responsename.
buf, &upnp_error_code,
725 (
IXML_Node**)response_node, &upnp_error_str);
730 err_code = upnp_error_code;
751#ifdef UPNPLIB_PUPNP_BUG
765 off_t content_length;
766 const char* xml_start =
768 "xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" "
769 "s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\r\n"
771 "<u:QueryStateVariable "
772 "xmlns:u=\"urn:schemas-upnp-org:control-1-0\">\r\n"
774 const char* xml_end =
"</u:varName>\r\n"
775 "</u:QueryStateVariable>\r\n"
788 (off_t)(strlen(xml_start) + strlen(var_name) + strlen(xml_end));
798 SOAPMETHOD_POST, path.
buf, path.
length,
"HOST: ", host.
buf,
801 "\"urn:schemas-upnp-org:control-1-0#QueryStateVariable\"",
802 xml_start, var_name, xml_end) != 0) {
813 &upnp_error_code, NULL, var_value);
818 return upnp_error_code;
int http_RequestAndResponse(uri_type *destination, const char *request, size_t request_length, http_method_t req_method, int timeout_secs, http_parser_t *response)
Initiates socket, connects to the remote host, sends a request and waits for the response from the re...
int http_FixStrUrl(const char *urlstr, size_t urlstrlen, uri_type *fixed_url)
Parses URL and then validates URL.
int http_MakeMessage(membuffer *buf, int http_major_version, int http_minor_version, const char *fmt,...)
Generate an HTTP message based on the format that is specified in the input parameters.
http_message_t msg
entire raw message
memptr entity
message body(entity).
Structure of an HTTP parser object.
Structure of an HTTP message.
hostport_type hostport
Member variable.
size_t size
Size of the buffer.
token pathquery
Member variable.
constexpr int HTTP_SUCCESS
Yet another success code.
token text
Pointing to the full host:port string representation.
Represents a URI used in parse_uri and elsewhere.
Data structure common to all types of nodes.
Data structure representing the DOM Document.
PUPNP_Api DOMString ixmlPrintNode(IXML_Node *doc)
Renders a Node and all sub-elements into an XML text representation.
PUPNP_Api int ixmlParseBufferEx(const char *buffer, IXML_Document **doc)
Parses an XML text buffer converting it into an IXML DOM representation.
#define DOMString
The type of DOM strings.
PUPNP_Api IXML_Node * ixmlNode_getNextSibling(IXML_Node *nodeptr)
Retrieves the sibling Node immediately following this Node.
PUPNP_Api const DOMString ixmlNode_getNodeValue(IXML_Node *nodeptr)
Returns the value of the Node as a string.
PUPNP_Api const DOMString ixmlNode_getNodeName(IXML_Node *nodeptr)
Returns the name of the Node, depending on what type of Node it is, in a read-only string.
PUPNP_Api void ixmlFreeDOMString(DOMString buf)
Frees a DOMString.
PUPNP_Api DOMString ixmlCloneDOMString(const DOMString src)
Clones an existing DOMString.
PUPNP_Api IXML_Node * ixmlNode_getFirstChild(IXML_Node *nodeptr)
Retrieves the first child Node of a Node.
PUPNP_Api void ixmlDocument_free(IXML_Document *doc)
Frees a Document object and all Nodes associated with it.
void httpmsg_destroy(http_message_t *msg)
Free memory allocated for the http message.
parse_status_t matchstr(char *str, size_t slen, const char *fmt,...)
Matches a variable parameter list with a string and takes actions based on the data type specified.
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.
int membuffer_append_str(membuffer *m, const char *c_str)
Invokes function to appends data from a constant string to the buffer.
int membuffer_insert(membuffer *m, const void *buf, size_t buf_len, size_t index)
Allocates memory for the new data to be inserted. Does memory management by moving the data from the ...
size_t size_inc
used to increase size; MUST be > 0; (read/write).
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).
size_t length
length of memory (read-only).
char * buf
start of memory (read/write).
pointer to a chunk of memory.
Maintains a block of dynamically allocated memory.
#define UPNP_E_NOT_FOUND
The response to a SOAP request did not contain the required XML constructs.
#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_ACTION
The SOAP action message is invalid.
#define UPNP_E_BAD_RESPONSE
The response received from the remote side of a connection is not correct for the protocol.
int get_response_value(http_message_t *hmsg, int code, char *name, int *upnp_error_code, IXML_Node **action_value, DOMString *str_value)
This function handles the response coming back from the device.
int soap_request_and_response(membuffer *request, uri_type *destination_url, http_parser_t *response)
This function sends the control point's request to the device and receives a response from it.
int add_man_header(membuffer *headers)
Adds "MAN" field in the HTTP header.
int dom_find_deep_node(const char *names[], int num_names, IXML_Node *start_node, IXML_Node **matching_node)
Searches for the node specifed by the last name in the 'name' array.
constexpr int SOAP_VAR_RESP
Control point SOAP status.
int dom_cmp_name(const char *name, IXML_Node *node)
Compares 'name' and node's name.
int dom_find_node(const char *node_name, IXML_Node *start_node, IXML_Node **matching_node)
Goes thru each child of 'start_node' looking for a node having the name 'node_name'.
constexpr int SOAP_ACTION_RESP
Control point SOAP status.
constexpr int SOAP_VAR_RESP_ERROR
Control point SOAP status.
int get_host_and_path(char *ctrl_url, const memptr *host, const memptr *path, uri_type *url)
This function retrives the host and path from the control URL.
constexpr int SOAP_ACTION_RESP_ERROR
Control point SOAP status.
const DOMString get_node_value(IXML_Node *node)
This function returns the value of the text node.
int get_action_name(char *action, memptr *name)
This function retrives the action name in the buffer.
Common SOAP declarations used for SOAP Devices and SOAP Control Points.
constexpr char ContentTypeHeader[]
Common SOAP constant string specifying the content type header.
int SoapSendActionEx(char *action_url, char *service_type, IXML_Document *header, IXML_Document *action_node, IXML_Document **response_node)
This extended function is called by UPnP API to send the SOAP action request.
int SoapGetServiceVarStatus(char *action_url, DOMString var_name, DOMString *var_value)
This function creates a status variable query message send it to the specified URL....
int SoapSendAction(char *action_url, char *service_type, IXML_Document *action_node, IXML_Document **response_node)
This function is called by UPnP API to send the SOAP action request.
SOAP declarations for Control Points using SOAP.
Inititalize the compatible library before it can be used.
#define UPNP_TIMEOUT
UPNP_TIMEOUT.
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).