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

## Data Structures

struct | job_arg

## Functions

static void | free_subscribe_arg (void *arg)
| Free memory associated with job's argument.
static void | GenaAutoRenewSubscription (void *input)
| This is a thread function to send the renewal just before the subscription times out.
static int | ScheduleGenaAutoRenew (int client_handle, int TimeOut, GenlibClientSubscription *sub)
| Schedules a job to renew the subscription just before time out.
static int | gena_unsubscribe (const UpnpString *url, const UpnpString *sid, http_parser_t *response)
| Sends the UNSUBCRIBE gena request and recieves the response from the device and returns it as a parameter.
static int | gena_subscribe (const UpnpString *url, int *timeout, const UpnpString *renewal_sid, UpnpString *sid)
| Subscribes or renew subscription.
int | genaUnregisterClient (UpnpClient_Handle client_handle)
| Unsubcribes all the outstanding subscriptions and cleans the subscription list.
int | genaUnSubscribe (UpnpClient_Handle client_handle, const UpnpString *in_sid)
| Unsubscribes a SID.
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).
int | genaRenewSubscription (UpnpClient_Handle client_handle, const UpnpString *in_sid, int *TimeOut)
| Renews a SID.
void | gena_process_notification_event (SOCKINFO *info, http_message_t *event)
| This function processes NOTIFY events that are sent by devices.

## Variables

ithread_mutex_t | GlobalClientSubscribeMutex

## Function Documentation

## free_subscribe_arg()

void free_subscribe_arg | ( | void * | arg | ) |

static

Free memory associated with job's argument.

References UpnpEventSubscribe_delete().

Referenced by GenaAutoRenewSubscription(), and ScheduleGenaAutoRenew().

## gena_process_notification_event()

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 memptr::buf, Handle_Info::Callback, Handle_Info::ClientSubList, Handle_Info::Cookie, http_message_t::entity, GenlibClientSubscription_get_SID(), GetClientHandleInfo(), GetHandleInfo(), has_xml_content_type(), ixmlDocument_free(), ixmlParseBufferEx(), membuffer::length, memptr::length, http_message_t::msg, PARSE_OK, SubscribeLock, SubscribeUnlock, UPNP_EVENT_RECEIVED, UpnpEvent_delete(), UpnpEvent_new(), UpnpEvent_set_ChangedVariables(), UpnpEvent_set_EventKey(), and UpnpEvent_set_SID().

Referenced by genaCallback().

## gena_subscribe()

int gena_subscribe | ( | const UpnpString * | url,
|  | int * | timeout,
|  | const UpnpString * | renewal_sid,
|  | 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 membuffer::buf, memptr::buf, gIF_IPV4, gIF_IPV6, gIF_IPV6_ULA_GUA, http_FixStrUrl(), http_MakeMessage(), membuffer::length, memptr::length, LOCAL_PORT_V4, LOCAL_PORT_V6, LOCAL_PORT_V6_ULA_GUA, PARSE_OK, membuffer::size_inc, http_message_t::status_code, 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().

## gena_unsubscribe()

int gena_unsubscribe | ( | const UpnpString * | url,
|  | const UpnpString * | sid,
|  | 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 membuffer::buf, http_FixStrUrl(), http_MakeMessage(), membuffer::length, membuffer::size_inc, http_message_t::status_code, UPNP_E_UNSUBSCRIBE_UNACCEPTED, UpnpString_get_Length(), and UpnpString_get_String().

Referenced by genaUnregisterClient(), and genaUnSubscribe().

## GenaAutoRenewSubscription()

void GenaAutoRenewSubscription | ( | void * | input | ) |

static

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

Parameters

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

References Handle_Info::Callback, Handle_Info::Cookie, free_subscribe_arg(), genaRenewSubscription(), GetHandleInfo(), UPNP_E_SUCCESS, UPNP_EVENT_AUTORENEWAL_FAILED, UPNP_EVENT_SUBSCRIPTION_EXPIRED, UpnpEventSubscribe_get_SID(), UpnpEventSubscribe_get_TimeOut(), UpnpEventSubscribe_set_ErrCode(), UpnpEventSubscribe_set_TimeOut(), and UpnpPrintf().

Referenced by ScheduleGenaAutoRenew().

## genaRenewSubscription()

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, gena_subscribe(), GenlibClientSubscription_assign(), GenlibClientSubscription_delete(), GenlibClientSubscription_get_ActualSID(), GenlibClientSubscription_get_EventURL(), GenlibClientSubscription_get_RenewEventId(), GenlibClientSubscription_get_SID(), GenlibClientSubscription_new(), GenlibClientSubscription_set_ActualSID(), GenlibClientSubscription_set_RenewEventId(), GetHandleInfo(), gTimerThread, ScheduleGenaAutoRenew(), TimerThreadRemove(), UPNP_E_SUCCESS, UpnpPrintf(), UpnpString_delete(), and UpnpString_new().

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

## genaSubscribe()

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

  [in,out]

  TimeOut

  requested Duration:
  - 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(), GenlibClientSubscription_delete(), GenlibClientSubscription_new(), GenlibClientSubscription_set_ActualSID(), GenlibClientSubscription_set_EventURL(), GenlibClientSubscription_set_Next(), GenlibClientSubscription_set_RenewEventId(), GenlibClientSubscription_set_SID(), 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().

## genaUnregisterClient()

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(), GenlibClientSubscription_assign(), GenlibClientSubscription_delete(), GenlibClientSubscription_get_ActualSID(), GenlibClientSubscription_get_EventURL(), GenlibClientSubscription_get_SID(), GenlibClientSubscription_new(), GetHandleInfo(), and UPNP_E_SUCCESS.

Referenced by UpnpUnRegisterClient().

## genaUnSubscribe()

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(), GenlibClientSubscription_assign(), GenlibClientSubscription_delete(), GenlibClientSubscription_get_ActualSID(), GenlibClientSubscription_get_EventURL(), GenlibClientSubscription_new(), and GetHandleInfo().

Referenced by UpnpThreadDistribution(), and UpnpUnSubscribe().

## ScheduleGenaAutoRenew()

int ScheduleGenaAutoRenew | ( | int | client_handle,
|  | int | TimeOut,
|  | GenlibClientSubscription * | 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_subscribe_arg(), GenaAutoRenewSubscription(), GenlibClientSubscription_get_EventURL(), GenlibClientSubscription_get_SID(), GenlibClientSubscription_set_RenewEventId(), gTimerThread, REL_SEC, TimerThreadSchedule(), TPJobInit(), TPJobSetFreeFunction(), TPJobSetPriority(), UPNP_E_OUTOF_MEMORY, UPNP_E_SUCCESS, UpnpEventSubscribe_new(), UpnpEventSubscribe_set_ErrCode(), UpnpEventSubscribe_set_PublisherUrl(), UpnpEventSubscribe_set_SID(), and UpnpEventSubscribe_set_TimeOut().

Referenced by genaRenewSubscription(), and genaSubscribe().