libUPnP 1.14.19
Data Structures | Macros | Typedefs | Functions | Variables
soap_device.c File Reference
#include "config.h"
#include "UpnpActionRequest.h"
#include "httpparser.h"
#include "httpreadwrite.h"
#include "parsetools.h"
#include "soaplib.h"
#include "ssdplib.h"
#include "statcodes.h"
#include "unixutil.h"
#include "upnpapi.h"
#include <assert.h>
#include <string.h>
Include dependency graph for soap_device.c:

Data Structures

struct  soap_devserv_t
 

Macros

#define SOAP_TIMEOUT   UPNP_TIMEOUT
 
#define SREQ_HDR_NOT_FOUND   -1
 
#define SREQ_BAD_HDR_FORMAT   -2
 
#define SREQ_NOT_EXTENDED   -3
 
#define SOAP_INVALID_ACTION   401
 
#define SOAP_INVALID_ARGS   402
 
#define SOAP_OUT_OF_SYNC   403
 
#define SOAP_INVALID_VAR   404
 
#define SOAP_ACTION_FAILED   501
 
#define SOAP_MEMORY_OUT   603
 

Typedefs

typedef struct soap_devserv_t soap_devserv_t
 

Functions

static void send_error_response (SOCKINFO *info, int error_code, const char *err_msg, http_message_t *hmsg)
 Sends SOAP error response.
 
static UPNP_INLINE void send_var_query_response (SOCKINFO *info, const char *var_value, http_message_t *hmsg)
 Sends response of get var status.
 
static UPNP_INLINE void send_action_response (SOCKINFO *info, IXML_Document *action_resp, http_message_t *request)
 Sends the SOAP action response.
 
static UPNP_INLINE void handle_query_variable (SOCKINFO *info, http_message_t *request, soap_devserv_t *soap_info, IXML_Node *req_node)
 Handles the SOAP requests to querry the state variables. This functionality has been deprecated in the UPnP V1.0 architecture.
 
static void handle_invoke_action (SOCKINFO *info, http_message_t *request, soap_devserv_t *soap_info, IXML_Node *req_node)
 Handles the SOAP action request.
 
static int get_dev_service (http_message_t *request, int AddressFamily, soap_devserv_t *soap_info)
 Retrieve SOAP device/service information associated with request-URI, which includes the callback function to hand-over the request to the device application.
 
static int get_mpost_acton_hdrval (http_message_t *request, memptr *val)
 Get the SOAPACTION header value for M-POST request.
 
static int check_soapaction_hdr (http_message_t *request, soap_devserv_t *soap_info)
 Check the header validity, and get the action name and the version of the service that the CP wants to use.
 
static int check_soap_request (soap_devserv_t *soap_info, IXML_Document *xml_doc, IXML_Node **req_node)
 Check validity of the SOAP request per UPnP specification.
 
void soap_device_callback (http_parser_t *parser, http_message_t *request, SOCKINFO *info)
 This is a callback called by minisever after receiving the request from the control point. After HTTP processing, it calls handle_soap_request to start SOAP processing.
 

Variables

static const char * SOAP_BODY = "Body"
 
static const char * SOAP_URN
 
static const char * QUERY_STATE_VAR_URN = "urn:schemas-upnp-org:control-1-0"
 
static const char * Soap_Invalid_Action = "Invalid Action"
 
static const char * Soap_Action_Failed = "Action Failed"
 
static const char * Soap_Invalid_Var = "Invalid Var"
 
static const char * Soap_Memory_out = "Out of Memory"
 

Macro Definition Documentation

◆ SOAP_TIMEOUT

#define SOAP_TIMEOUT   UPNP_TIMEOUT

timeout duration in secs for transmission/reception

Function Documentation

◆ check_soap_request()

static int check_soap_request ( soap_devserv_t soap_info,
IXML_Document xml_doc,
IXML_Node **  req_node 
)
static

Check validity of the SOAP request per UPnP specification.

Returns
0 if OK, -1 on failure.
Parameters
[in]soap_infoSOAP device/service information.
[in]xml_docDocument containing the SOAP action request.
[out]req_nodeNode containing the SOAP action request/variable name.

References memptr::buf, DOMString, ixmlNode_getFirstChild(), ixmlNode_getLocalName(), ixmlNode_getNamespaceURI(), and ixmlNode_getNodeType().

Referenced by soap_device_callback().

◆ check_soapaction_hdr()

static int check_soapaction_hdr ( http_message_t request,
soap_devserv_t soap_info 
)
static

Check the header validity, and get the action name and the version of the service that the CP wants to use.

Returns
UPNP_E_SUCCESS if OK, error number on failure.
Parameters
[in]requestHTTP request.
[in,out]soap_infoSOAP device/service information.

References memptr::buf, get_mpost_acton_hdrval(), memptr::length, http_message_t::method, namecopy(), PARSE_OK, and UPNP_E_SUCCESS.

Referenced by soap_device_callback().

◆ get_dev_service()

static int get_dev_service ( http_message_t request,
int  AddressFamily,
soap_devserv_t soap_info 
)
static

Retrieve SOAP device/service information associated with request-URI, which includes the callback function to hand-over the request to the device application.

Returns
0 if OK, -1 on error.
Parameters
[in]requestHTTP request.
[in]AddressFamilyAddress family: AF_INET or AF_INET6.
[out]soap_infoSOAP device/service information.

References Handle_Info::Callback, Handle_Info::Cookie, GetDeviceHandleInfoForPath(), namecopy(), and http_message_t::uri.

Referenced by soap_device_callback().

◆ get_mpost_acton_hdrval()

static int get_mpost_acton_hdrval ( http_message_t request,
memptr val 
)
static

Get the SOAPACTION header value for M-POST request.

Returns
UPNP_E_SUCCESS if OK, error number on failure.
Parameters
[in]requestHTTP request.
[out]valBuffer to get the header value

References memptr::buf, membuffer::buf, memptr::length, membuffer::length, http_message_t::method, PARSE_OK, UPNP_E_OUTOF_MEMORY, UPNP_E_SUCCESS, and http_header_t::value.

Referenced by check_soapaction_hdr().

◆ handle_invoke_action()

static void handle_invoke_action ( SOCKINFO info,
http_message_t request,
soap_devserv_t soap_info,
IXML_Node req_node 
)
static

◆ handle_query_variable()

static UPNP_INLINE void handle_query_variable ( SOCKINFO info,
http_message_t request,
soap_devserv_t soap_info,
IXML_Node req_node 
)
static

◆ send_action_response()

static UPNP_INLINE void send_action_response ( SOCKINFO info,
IXML_Document action_resp,
http_message_t request 
)
static

Sends the SOAP action response.

Parameters
[in]infoSocket info.
[in]action_respThe response document.
[in]requestAction request document.

References membuffer::buf, http_MakeMessage(), http_SendMessage(), ixmlFreeDOMString(), ixmlPrintNode(), membuffer::length, send_error_response(), SOAP_TIMEOUT, UPNP_E_OUTOF_MEMORY, and UpnpPrintf().

Referenced by handle_invoke_action().

◆ send_error_response()

static void send_error_response ( SOCKINFO info,
int  error_code,
const char *  err_msg,
http_message_t hmsg 
)
static

Sends SOAP error response.

Parameters
[in]infoSocket info.
[in]error_codeError code.
[in]err_msgError message.
[in]hmsgHTTP request.

References membuffer::buf, http_MakeMessage(), http_SendMessage(), membuffer::length, and SOAP_TIMEOUT.

Referenced by handle_invoke_action(), handle_query_variable(), and send_action_response().

◆ send_var_query_response()

static UPNP_INLINE void send_var_query_response ( SOCKINFO info,
const char *  var_value,
http_message_t hmsg 
)
static

Sends response of get var status.

Parameters
[in]infoSocket info.
[in]var_valueValue of the state variable.
[in]hmsgHTTP request.

References membuffer::buf, http_MakeMessage(), http_SendMessage(), membuffer::length, and SOAP_TIMEOUT.

Referenced by handle_query_variable().

◆ soap_device_callback()

void soap_device_callback ( http_parser_t parser,
http_message_t request,
SOCKINFO info 
)

This is a callback called by minisever after receiving the request from the control point. After HTTP processing, it calls handle_soap_request to start SOAP processing.

This is a callback called by minisever after receiving the request from the control point. This function will start processing the request. It calls handle_invoke_action to handle the SOAP action.

Parameters
[in]parserParsed request received by the device.
[in]requestHTTP request.
[in,out]infoSocket info.

References memptr::buf, check_soap_request(), check_soapaction_hdr(), http_message_t::entity, SOCKINFO::foreign_sockaddr, get_dev_service(), handle_invoke_action(), handle_query_variable(), has_xml_content_type(), ixmlDocument_free(), ixmlParseBufferEx(), UPNP_E_OUTOF_MEMORY, and UPNP_E_SUCCESS.

Referenced by UpnpInitPreamble().

Variable Documentation

◆ SOAP_URN

const char* SOAP_URN
static
Initial value:
= "http:/"
"/schemas.xmlsoap.org/soap/envelope/"