gena_ctrlpt.c File Reference
`#include "config.h"`
`#include "EventSubscribe.h"`
`#include "gena.h"`
`#include "httpparser.h"`
`#include "httpreadwrite.h"`
`#include "parsetools.h"`
`#include "statcodes.h"`
`#include "sysdep.h"`
`#include "uuid.h"`
`#include "upnpapi.h"`
Include dependency graph for gena_ctrlpt.c:

## Functions

static void | GenaAutoRenewSubscription (IN void *input)
| This is a thread function to send the renewal just before the subscription times out. More...
static int | ScheduleGenaAutoRenew (IN int client_handle, IN int TimeOut, IN ClientSubscription *sub)
| Schedules a job to renew the subscription just before time out. More...
static int | gena_unsubscribe (IN const UpnpString *url, IN const UpnpString *sid, OUT http_parser_t *response)
| Sends the UNSUBCRIBE gena request and recieves the response from the device and returns it as a parameter. More...
static int | gena_subscribe (IN const UpnpString *url, INOUT int *timeout, IN const UpnpString *renewal_sid, OUT UpnpString *sid)
| Subscribes or renew subscription. More...
int | genaUnregisterClient (UpnpClient_Handle client_handle)
| Unsubcribes all the outstanding subscriptions and cleans the subscription list. More...
int | genaUnSubscribe (UpnpClient_Handle client_handle, const UpnpString *in_sid)
| Unsubscribes a SID. More...
int | genaSubscribe (UpnpClient_Handle client_handle, const UpnpString *PublisherURL, int *TimeOut, UpnpString *out_sid)
| This function subscribes to a PublisherURL (also mentioned as EventURL in some places). More...
int | genaRenewSubscription (UpnpClient_Handle client_handle, const UpnpString *in_sid, int *TimeOut)
| Renews a SID. More...
void | gena_process_notification_event (SOCKINFO *info, http_message_t *event)
| This function processes NOTIFY events that are sent by devices. More...

## Variables

ithread_mutex_t | GlobalClientSubscribeMutex

## Function Documentation

void gena_process_notification_event | ( | SOCKINFO * | info,
|  | http_message_t * | event
| ) |  |

This function processes NOTIFY events that are sent by devices.

Parameters: IN SOCKINFO *info: Socket structure containing the device socket information IN http_message_t *event: The http message contains the GENA notification

Note
  called by genacallback()

Parameters

  [in] | info | Socket info of the device.
  [in] | event | The http message contains the GENA notification.

References Handle_Info::Callback, Handle_Info::ClientSubList, Handle_Info::Cookie, error_respond(), GetClientHandleInfo(), ixmlDocument_free(), ixmlParseBufferEx(), SubscribeLock, SubscribeUnlock, UPNP_EVENT_RECEIVED, UpnpEvent_delete(), and UpnpEvent_new().

static int gena_subscribe | ( | IN const UpnpString * | url,
|  | INOUT int * | timeout,
|  | IN const UpnpString * | renewal_sid,
|  | OUT UpnpString * | sid
| ) |  |

static

Subscribes or renew subscription.

Returns
  0 if successful, otherwise returns the appropriate error code.

Parameters

  [in] | url | URL of service to subscribe.
  [in,out] | timeout | Subscription time desired (in secs).
  [in] | renewal_sid | for renewal, this contains a currently held subscription SID. For first time subscription, this must be NULL.
  [out] | sid | SID returned by the subscription or renew msg.

References gIF_IPV4, gIF_IPV6, LOCAL_PORT_V4, LOCAL_PORT_V6, UPNP_E_BAD_RESPONSE, UPNP_E_OUTOF_MEMORY, UPNP_E_SUBSCRIBE_UNACCEPTED, UPNP_E_SUCCESS, UpnpString_clear(), UpnpString_get_Length(), UpnpString_get_String(), and UpnpString_set_StringN().

Referenced by genaRenewSubscription(), and genaSubscribe().

static int gena_unsubscribe | ( | IN const UpnpString * | url,
|  | IN const UpnpString * | sid,
|  | OUT http_parser_t * | response
| ) |  |

static

Sends the UNSUBCRIBE gena request and recieves the response from the device and returns it as a parameter.

Returns
  0 if successful, otherwise returns the appropriate error code.

Parameters

  [in] | url | Event URL of the service.
  [in] | sid | The subcription ID.
  [out] | response | The UNSUBCRIBE response from the device.

References UPNP_E_UNSUBSCRIBE_UNACCEPTED, UpnpString_get_Length(), and UpnpString_get_String().

Referenced by genaUnregisterClient(), and genaUnSubscribe().

static void GenaAutoRenewSubscription | ( | IN void * | input | ) |

static

This is a thread function to send the renewal just before the subscription times out.

Parameters

  [in] | input | Thread data(upnp_timeout *) needed to send the renewal.

References free_upnp_timeout(), genaRenewSubscription(), GetHandleInfo(), UPNP_E_SUCCESS, UPNP_EVENT_AUTORENEWAL_FAILED, UPNP_EVENT_SUBSCRIPTION_EXPIRED, UpnpEventSubscribe_get_SID(), UpnpEventSubscribe_get_TimeOut(), and UpnpPrintf().

Referenced by ScheduleGenaAutoRenew().

int genaRenewSubscription | ( | UpnpClient_Handle | client_handle,
|  | const UpnpString * | in_sid,
|  | int * | TimeOut
| ) |  |

Renews a SID.

It first validates the SID and client_handle and copies the subscription. It sends RENEW (modified SUBSCRIBE) http request to service and processes the response.

Returns
  UPNP_E_SUCCESS if service response is OK, otherwise the appropriate error code.

Parameters

  [in] | client_handle | Client handle.
  [in] | in_sid | Subscription ID.
  [in,out] | TimeOut | requested Duration, if -1, then "infinite". In the OUT case: actual Duration granted by Service, -1 for infinite.

References Handle_Info::ClientSubList, free_upnp_timeout(), gena_subscribe(), GetHandleInfo(), gTimerThread, ScheduleGenaAutoRenew(), TimerThreadRemove(), UPNP_E_SUCCESS, UpnpPrintf(), UpnpString_delete(), and UpnpString_new().

Referenced by GenaAutoRenewSubscription(), UpnpRenewSubscription(), and UpnpThreadDistribution().

int genaSubscribe | ( | UpnpClient_Handle | client_handle,
|  | const UpnpString * | PublisherURL,
|  | int * | TimeOut,
|  | UpnpString * | out_sid
| ) |  |

This function subscribes to a PublisherURL (also mentioned as EventURL in some places).

It sends SUBSCRIBE http request to service processes request. Finally adds a Subscription to the clients subscription list, if service responds with OK.

Returns
  UPNP_E_SUCCESS if service response is OK, otherwise returns the appropriate error code

Parameters

  [in] | client_handle | The client handle.

  [in]

  PublisherURL

  Of the form: "http://134.134.156.80:4000/RedBulb/Event @param[in,out] TimeOut requested Duration: \li if -1, then "infinite".
  - in the OUT case: actual Duration granted by Service, -1 for infinite.

  [out] | out_sid | sid of subscription, memory passed in by caller.

References Handle_Info::ClientSubList, gena_subscribe(), GetHandleInfo(), ScheduleGenaAutoRenew(), SubscribeLock, SubscribeUnlock, UPNP_E_OUTOF_MEMORY, UPNP_E_SUCCESS, UpnpPrintf(), UpnpString_assign(), UpnpString_clear(), UpnpString_delete(), UpnpString_new(), and UpnpString_set_String().

Referenced by UpnpSubscribe(), and UpnpThreadDistribution().

int genaUnregisterClient | ( | UpnpClient_Handle | client_handle | ) |

Unsubcribes all the outstanding subscriptions and cleans the subscription list.

This function is called when control point unregisters.

Returns
  UPNP_E_SUCCESS if successful, otherwise returns the appropriate error code.

Parameters

  [in] | client_handle | Handle containing all the control point related information.

References Handle_Info::ClientSubList, gena_unsubscribe(), GetHandleInfo(), and UPNP_E_SUCCESS.

Referenced by UpnpUnRegisterClient().

int genaUnSubscribe | ( | UpnpClient_Handle | client_handle,
|  | const UpnpString * | in_sid
| ) |  |

Unsubscribes a SID.

It first validates the SID and client_handle,copies the subscription, sends UNSUBSCRIBE http request to service processes request and finally removes the subscription.

Returns
  UPNP_E_SUCCESS if service response is OK, otherwise returns the appropriate error code.

Parameters

  [in] | client_handle | UPnP client handle.
  [in] | in_sid | The subscription ID.

References Handle_Info::ClientSubList, gena_unsubscribe(), and GetHandleInfo().

Referenced by UpnpThreadDistribution(), and UpnpUnSubscribe().

static int ScheduleGenaAutoRenew | ( | IN int | client_handle,
|  | IN int | TimeOut,
|  | IN ClientSubscription * | sub
| ) |  |

static

Schedules a job to renew the subscription just before time out.

Returns
  GENA_E_SUCCESS if successful, otherwise returns the appropriate error code.

Parameters

  [in] | client_handle | Handle that also contains the subscription list.
  [in] | TimeOut | The time out value of the subscription.
  [in] | sub | Subscription being renewed.

References free_upnp_timeout(), GenaAutoRenewSubscription(), gTimerThread, TimerThreadSchedule(), UPNP_E_OUTOF_MEMORY, UPNP_E_SUCCESS, and UpnpEventSubscribe_new().

Referenced by genaRenewSubscription(), and genaSubscribe().

## Variable Documentation

ithread_mutex_t GlobalClientSubscribeMutex

Mutex to synchronize the subscription handling at the client side.