libUPnP  1.6.17
Functions | Variables
gena_ctrlpt.c File Reference
#include "config.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.
static int ScheduleGenaAutoRenew (IN int client_handle, IN int TimeOut, IN ClientSubscription *sub)
 Schedules a job to renew the subscription just before time out.
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.
static int gena_subscribe (IN const UpnpString *url, INOUT int *timeout, IN const UpnpString *renewal_sid, OUT 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

Detailed Description


Function Documentation

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]infoSocket info of the device.
[in]eventThe http message contains the GENA notification.

References memptr::buf, Handle_Info::Callback, Upnp_Event::ChangedVariables, Handle_Info::ClientSubList, Handle_Info::Cookie, http_message_t::entity, error_respond(), Upnp_Event::EventKey, GetClientHandleInfo(), has_xml_content_type(), ixmlDocument_free(), ixmlParseBufferEx(), memptr::length, membuffer::length, http_message_t::msg, PARSE_OK, Upnp_Event::Sid, SubscribeLock, SubscribeUnlock, UPNP_EVENT_RECEIVED, and UpnpString_get_String().

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]urlURL of service to subscribe.
[in,out]timeoutSubscription time desired (in secs).
[in]renewal_sidfor renewal, this contains a currently held subscription SID. For first time subscription, this must be NULL.
[out]sidSID returned by the subscription or renew msg.

References memptr::buf, membuffer::buf, gIF_IPV4, gIF_IPV6, gIF_IPV6_ULA_GUA, http_MakeMessage(), memptr::length, membuffer::length, LOCAL_PORT_V4, LOCAL_PORT_V6, 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().

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]urlEvent URL of the service.
[in]sidThe subcription ID.
[out]responseThe UNSUBCRIBE response from the device.

References membuffer::buf, http_MakeMessage(), membuffer::length, membuffer::size_inc, 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]inputThread data(upnp_timeout *) needed to send the renewal.

References Upnp_Event_Subscribe::ErrCode, free_upnp_timeout(), genaRenewSubscription(), GetHandleInfo(), Upnp_Event_Subscribe::Sid, Upnp_Event_Subscribe::TimeOut, UPNP_E_SUCCESS, UPNP_EVENT_AUTORENEWAL_FAILED, UPNP_EVENT_SUBSCRIPTION_EXPIRED, UpnpPrintf(), UpnpString_delete(), UpnpString_new(), and UpnpString_set_String().

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_handleClient handle.
[in]in_sidSubscription ID.
[in,out]TimeOutrequested 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_handleThe client handle.
[in]PublisherURLOf 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_sidsid 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(), UpnpString_set_String(), uuid_create(), and uuid_unpack().

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_handleHandle 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_handleUPnP client handle.
[in]in_sidThe 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_handleHandle that also contains the subscription list.
[in]TimeOutThe time out value of the subscription.
[in]subSubscription being renewed.

References Upnp_Event_Subscribe::ErrCode, free_upnp_timeout(), GenaAutoRenewSubscription(), gTimerThread, Upnp_Event_Subscribe::PublisherUrl, REL_SEC, Upnp_Event_Subscribe::Sid, Upnp_Event_Subscribe::TimeOut, TimerThreadSchedule(), TPJobInit(), TPJobSetFreeFunction(), TPJobSetPriority(), UPNP_E_OUTOF_MEMORY, UPNP_E_SUCCESS, UpnpString_assign(), UpnpString_get_String(), and UpnpString_new().

Referenced by genaRenewSubscription(), and genaSubscribe().