Functions

gena_device.c File Reference

#include "config.h"
#include "gena.h"
#include "httpparser.h"
#include "httpreadwrite.h"
#include "parsetools.h"
#include "ssdplib.h"
#include "statcodes.h"
#include "sysdep.h"
#include "unixutil.h"
#include "upnpapi.h"
#include "uuid.h"
Include dependency graph for gena_device.c:

Functions

int genaUnregisterDevice (UpnpDevice_Handle device_handle)
 Unregisters a device.
static int GeneratePropertySet (char **names, char **values, int count, DOMString *out)
 Generates XML property set for notifications.
static void free_notify_struct (notify_thread_struct *input)
 Frees memory used in notify_threads if the reference count is 0, otherwise decrements the refrence count.
static UPNP_INLINE int notify_send_and_recv (uri_type *destination_url, membuffer *mid_msg, char *propertySet, http_parser_t *response)
 Sends the notify message and returns a reply.
static int genaNotify (char *headers, char *propertySet, subscription *sub)
 Function to Notify a particular subscription of a particular event.
static void genaNotifyThread (void *input)
 Thread job to Notify a control point.
static char * AllocGenaHeaders (const DOMString propertySet)
 Allocates the GENA header.
int genaInitNotify (UpnpDevice_Handle device_handle, char *UDN, char *servId, char **VarNames, char **VarValues, int var_count, const Upnp_SID sid)
 Sends the intial state table dump to newly subscribed control point.
int genaInitNotifyExt (UpnpDevice_Handle device_handle, char *UDN, char *servId, IXML_Document *PropSet, const Upnp_SID sid)
 Similar to the genaInitNofity. The only difference is that it takes the xml document for the state table and sends the intial state table dump to newly subscribed control point.
int genaNotifyAllExt (UpnpDevice_Handle device_handle, char *UDN, char *servId, IXML_Document *PropSet)
 Sends a notification to all the subscribed control points.
int genaNotifyAll (UpnpDevice_Handle device_handle, char *UDN, char *servId, char **VarNames, char **VarValues, int var_count)
 Sends a notification to all the subscribed control points.
static int respond_ok (SOCKINFO *info, int time_out, subscription *sub, http_message_t *request)
 Returns OK message in the case of a subscription request.
static int create_url_list (memptr *url_list, URL_list *out)
 Function to parse the Callback header value in subscription requests.
void gena_process_subscription_request (SOCKINFO *info, http_message_t *request)
 Handles a subscription request from a ctrl point. The socket is not closed on return.
void gena_process_subscription_renewal_request (SOCKINFO *info, http_message_t *request)
 Handles a subscription renewal request from a ctrl point. The connection is not destroyed on return.
void gena_process_unsubscribe_request (SOCKINFO *info, http_message_t *request)
 Handles a subscription cancellation request from a ctrl point. The connection is not destroyed on return.

Detailed Description


Function Documentation

static char* AllocGenaHeaders ( const DOMString  propertySet  )  [static]

Allocates the GENA header.

Note:
The header must be destroyed after with a call to free(), otherwise there will be a memory leak.
Returns:
The constructed header.
Parameters:
[in] propertySet The property set string.

References PRIzu, and UpnpPrintf().

Referenced by genaInitNotify(), genaInitNotifyExt(), genaNotifyAll(), and genaNotifyAllExt().

static int create_url_list ( memptr url_list,
URL_list out 
) [static]

Function to parse the Callback header value in subscription requests.

Takes in a buffer containing URLS delimited by '<' and '>'. The entire buffer is copied into dynamic memory and stored in the URL_list. Pointers to the individual urls within this buffer are allocated and stored in the URL_list. Only URLs with network addresses are considered (i.e. host:port or domain name).

Returns:
The number of URLs parsed if successful, otherwise UPNP_E_OUTOF_MEMORY.
Parameters:
[in] url_list .
[out] out .

References parse_uri(), URL_LIST::parsedURLs, URL_LIST::size, HOSTPORT::text, UPNP_E_OUTOF_MEMORY, and URL_LIST::URLs.

Referenced by gena_process_subscription_request().

static void free_notify_struct ( notify_thread_struct input  )  [static]

Frees memory used in notify_threads if the reference count is 0, otherwise decrements the refrence count.

Parameters:
[in] input Notify structure.

References ixmlFreeDOMString().

Referenced by genaInitNotify(), genaInitNotifyExt(), genaNotifyAll(), genaNotifyAllExt(), and genaNotifyThread().

void gena_process_subscription_renewal_request ( SOCKINFO info,
http_message_t request 
)

Handles a subscription renewal request from a ctrl point. The connection is not destroyed on return.

Parameters:
[in] info Socket info of the device.
[in] request Subscription renewal request from the control point.

References error_respond(), GetDeviceHandleInfo(), Handle_Info::MaxSubscriptions, Handle_Info::MaxSubscriptionTimeOut, respond_ok(), Handle_Info::ServiceTable, UPNP_E_SUCCESS, and UpnpPrintf().

void gena_process_subscription_request ( SOCKINFO info,
http_message_t request 
)
void gena_process_unsubscribe_request ( SOCKINFO info,
http_message_t request 
)

Handles a subscription cancellation request from a ctrl point. The connection is not destroyed on return.

Parameters:
[in] info Socket info of the device.
[in] request UNSUBSCRIBE request from the control point.

References error_respond(), GetDeviceHandleInfo(), and Handle_Info::ServiceTable.

int genaInitNotify ( UpnpDevice_Handle  device_handle,
char *  UDN,
char *  servId,
char **  VarNames,
char **  VarValues,
int  var_count,
const Upnp_SID  sid 
)

Sends the intial state table dump to newly subscribed control point.

Returns:
GENA_E_SUCCESS if successful, otherwise the appropriate error code.
Note:
No other event will be sent to this control point before the intial state table dump.
Parameters:
[in] device_handle Device handle.
[in] UDN Device udn.
[in] servId Service ID.
[in] VarNames Array of variable names.
[in] VarValues Array of variable values.
[in] var_count Array size.
[in] sid Subscription ID.

References AllocGenaHeaders(), DOMString, free_notify_struct(), genaNotifyThread(), GeneratePropertySet(), GetHandleInfo(), gSendThreadPool, ixmlFreeDOMString(), Handle_Info::ServiceTable, and UpnpPrintf().

Referenced by UpnpAcceptSubscription().

int genaInitNotifyExt ( UpnpDevice_Handle  device_handle,
char *  UDN,
char *  servId,
IXML_Document PropSet,
const Upnp_SID  sid 
)

Similar to the genaInitNofity. The only difference is that it takes the xml document for the state table and sends the intial state table dump to newly subscribed control point.

Returns:
GENA_E_SUCCESS if successful, otherwise the appropriate error code.
Note:
No other event will be sent to this control point before the intial state table dump.
Parameters:
[in] device_handle Device handle.
[in] UDN Device udn.
[in] servId Service ID.
[in] PropSet Document of the state table.
[in] sid subscription ID.

References AllocGenaHeaders(), DOMString, free_notify_struct(), genaNotifyThread(), GetHandleInfo(), gSendThreadPool, ixmlFreeDOMString(), ixmlPrintNode(), Handle_Info::ServiceTable, and UpnpPrintf().

Referenced by UpnpAcceptSubscriptionExt().

static int genaNotify ( char *  headers,
char *  propertySet,
subscription sub 
) [static]

Function to Notify a particular subscription of a particular event.

In general the service should NOT be blocked around this call (this may cause deadlock with a client).

NOTIFY http request is sent and the reply is processed.

Returns:
GENA_SUCCESS if the event was delivered, otherwise returns the appropriate error code.
Parameters:
[in] headers Null terminated, includes all headers (including \r\n) except SID and SEQ.
[in] propertySet The evented XML.
[in] sub subscription to be Notified, assumes this is valid for life of function.

References notify_send_and_recv(), URL_LIST::parsedURLs, URL_LIST::size, and UPNP_E_SUCCESS.

Referenced by genaNotifyThread().

int genaNotifyAll ( UpnpDevice_Handle  device_handle,
char *  UDN,
char *  servId,
char **  VarNames,
char **  VarValues,
int  var_count 
)

Sends a notification to all the subscribed control points.

Returns:
int
Note:
This function is similar to the genaNotifyAllExt. The only difference is it takes event variable array instead of xml document.
Parameters:
[in] device_handle Device handle.
[in] UDN Device udn.
[in] servId Service ID.
[in] VarNames Array of varible names.
[in] VarValues Array of variable values.
[in] var_count Number of variables.

References AllocGenaHeaders(), DOMString, free_notify_struct(), genaNotifyThread(), GeneratePropertySet(), GetHandleInfo(), gSendThreadPool, ixmlFreeDOMString(), Handle_Info::ServiceTable, and UpnpPrintf().

Referenced by UpnpNotify().

int genaNotifyAllExt ( UpnpDevice_Handle  device_handle,
char *  UDN,
char *  servId,
IXML_Document PropSet 
)

Sends a notification to all the subscribed control points.

Returns:
int
Note:
This function is similar to the genaNotifyAll. the only difference is it takes the document instead of event variable array.
Parameters:
[in] device_handle Device handle.
[in] UDN Device udn.
[in] servId Service ID.
[in] PropSet XML document Event varible property set.

References AllocGenaHeaders(), DOMString, free_notify_struct(), genaNotifyThread(), GetHandleInfo(), gSendThreadPool, ixmlFreeDOMString(), ixmlPrintNode(), Handle_Info::ServiceTable, and UpnpPrintf().

Referenced by UpnpNotifyExt().

static void genaNotifyThread ( void *  input  )  [static]

Thread job to Notify a control point.

It validates the subscription and copies the subscription. Also make sure that events are sent in order.

Note:
calls the genaNotify to do the actual work.
Parameters:
[in] input notify thread structure containing all the headers and property set info.

References free_notify_struct(), genaNotify(), GetHandleInfo(), gSendThreadPool, and Handle_Info::ServiceTable.

Referenced by genaInitNotify(), genaInitNotifyExt(), genaNotifyAll(), and genaNotifyAllExt().

int genaUnregisterDevice ( UpnpDevice_Handle  device_handle  ) 

Unregisters a device.

Cleans the service table of the device.

Returns:
UPNP_E_SUCCESS on success, GENA_E_BAD_HANDLE on failure.
Parameters:
[in] device_handle Device handle.

References GetHandleInfo(), Handle_Info::ServiceTable, and UpnpPrintf().

Referenced by UpnpUnRegisterRootDevice().

static int GeneratePropertySet ( char **  names,
char **  values,
int  count,
DOMString *  out 
) [static]

Generates XML property set for notifications.

Returns:
UPNP_E_SUCCESS if successful else returns GENA_E_BAD_HANDLE.
Note:
The XML_VERSION comment is NOT sent due to interoperability issues with other UPnP vendors.
Parameters:
[in] names Array of variable names (go in the event notify).
[in] values Array of variable values (go in the event notify).
[in] count number of variables.
[out] out PropertySet node in the string format.

References ixmlCloneDOMString().

Referenced by genaInitNotify(), and genaNotifyAll().

static UPNP_INLINE int notify_send_and_recv ( uri_type destination_url,
membuffer mid_msg,
char *  propertySet,
http_parser_t response 
) [static]

Sends the notify message and returns a reply.

Returns:
on success returns UPNP_E_SUCCESS, otherwise returns a UPNP error.
Note:
called by genaNotify
Parameters:
[in] destination_url subscription callback URL (URL of the control point).
[in] mid_msg Common HTTP headers.
[in] propertySet The evented XML.
[out] response The response from the control point.

References HOSTPORT::text, and UpnpPrintf().

Referenced by genaNotify().

static int respond_ok ( SOCKINFO info,
int  time_out,
subscription sub,
http_message_t request 
) [static]

Returns OK message in the case of a subscription request.

Returns:
UPNP_E_SUCCESS if successful, otherwise the appropriate error code.
Parameters:
[in] info Socket connection of request.
[in] time_out Accepted duration.
[in] sub Accepted subscription.
[in] request Http request.

References error_respond().

Referenced by gena_process_subscription_renewal_request(), and gena_process_subscription_request().