Upnp_Subscription_Request becomes UpnpSubscriptionRequest. One less externally visible data structure.

git-svn-id: https://pupnp.svn.sourceforge.net/svnroot/pupnp/trunk@360 119443c7-1b9e-41f8-b6fc-b9c35fce742c
This commit is contained in:
Marcelo Roberto Jimenez 2008-05-03 21:19:08 +00:00
parent 98a45e17b5
commit d2c34a15de
14 changed files with 606 additions and 519 deletions

View File

@ -27,6 +27,7 @@ upnpinclude_HEADERS = \
inc/FileInfo.h \ inc/FileInfo.h \
inc/StateVarComplete.h \ inc/StateVarComplete.h \
inc/StateVarRequest.h \ inc/StateVarRequest.h \
inc/SubscriptionRequest.h \
inc/String.h \ inc/String.h \
inc/upnp.h \ inc/upnp.h \
inc/upnpdebug.h inc/upnpdebug.h
@ -129,6 +130,7 @@ libupnp_la_SOURCES += src/api/EventSubscribe.c
libupnp_la_SOURCES += src/api/FileInfo.c libupnp_la_SOURCES += src/api/FileInfo.c
libupnp_la_SOURCES += src/api/StateVarComplete.c libupnp_la_SOURCES += src/api/StateVarComplete.c
libupnp_la_SOURCES += src/api/StateVarRequest.c libupnp_la_SOURCES += src/api/StateVarRequest.c
libupnp_la_SOURCES += src/api/SubscriptionRequest.c
libupnp_la_SOURCES += src/api/String.c libupnp_la_SOURCES += src/api/String.c
libupnp_la_SOURCES += src/api/upnpapi.c libupnp_la_SOURCES += src/api/upnpapi.c
if ENABLE_TOOLS if ENABLE_TOOLS

View File

@ -0,0 +1,53 @@
#ifndef SUBSCRIPTIONREQUEST_H
#define SUBSCRIPTIONREQUEST_H
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/** Returned along with a {\bf UPNP_EVENT_SUBSCRIPTION_REQUEST} callback. */
typedef struct {} UpnpSubscriptionRequest;
#include "String.h" // for UpnpString
/** Constructor */
UpnpSubscriptionRequest *UpnpSubscriptionRequest_new();
/** Destructor */
void UpnpSubscriptionRequest_delete(UpnpSubscriptionRequest *p);
/** Copy Constructor */
UpnpSubscriptionRequest *UpnpSubscriptionRequest_dup(const UpnpSubscriptionRequest *p);
/** Assignment operator */
void UpnpSubscriptionRequest_assign(UpnpSubscriptionRequest *q, const UpnpSubscriptionRequest *p);
/** The identifier for the service being subscribed to. */
const UpnpString *UpnpSubscriptionRequest_get_ServiceId(const UpnpSubscriptionRequest *p);
void UpnpSubscriptionRequest_set_ServiceId(UpnpSubscriptionRequest *p, const UpnpString *s);
void UpnpSubscriptionRequest_strcpy_ServiceId(UpnpSubscriptionRequest *p, const char *s);
/** Universal device name. */
const UpnpString *UpnpSubscriptionRequest_get_UDN(const UpnpSubscriptionRequest *p);
void UpnpSubscriptionRequest_set_UDN(UpnpSubscriptionRequest *p, const UpnpString *s);
void UpnpSubscriptionRequest_strcpy_UDN(UpnpSubscriptionRequest *p, const char *s);
/** The assigned subscription ID for this subscription. */
const UpnpString *UpnpSubscriptionRequest_get_SID(const UpnpSubscriptionRequest *p);
void UpnpSubscriptionRequest_set_SID(UpnpSubscriptionRequest *p, const UpnpString *s);
void UpnpSubscriptionRequest_strcpy_SID(UpnpSubscriptionRequest *p, const char *s);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* SUBSCRIPTIONREQUEST_H */

View File

@ -524,6 +524,7 @@
#include "FileInfo.h" #include "FileInfo.h"
#include "StateVarComplete.h" #include "StateVarComplete.h"
#include "StateVarRequest.h" #include "StateVarRequest.h"
#include "SubscriptionRequest.h"
enum UpnpOpenFileMode enum UpnpOpenFileMode
@ -624,7 +625,7 @@ enum Upnp_EventType_e {
/** Received by a device when a subscription arrives. /** Received by a device when a subscription arrives.
* The {\bf Event} parameter contains a pointer to a {\bf * The {\bf Event} parameter contains a pointer to a {\bf
* Upnp_Subscription_Request} structure. At this point, the * UpnpSubscriptionRequest} structure. At this point, the
* subscription has already been accepted. {\bf UpnpAcceptSubscription} * subscription has already been accepted. {\bf UpnpAcceptSubscription}
* needs to be called to confirm the subscription and transmit the * needs to be called to confirm the subscription and transmit the
* initial state table. This can be done during this callback. The SDK * initial state table. This can be done during this callback. The SDK
@ -693,7 +694,6 @@ typedef char Upnp_SID[44];
*/ */
enum Upnp_SType_e { enum Upnp_SType_e {
/** Search for all devices and services on the network. */ /** Search for all devices and services on the network. */
UPNP_S_ALL, UPNP_S_ALL,
@ -707,7 +707,6 @@ enum Upnp_SType_e {
/** Search for a particular service type, possibly on a particular /** Search for a particular service type, possibly on a particular
* device type or device instance. */ * device type or device instance. */
UPNP_S_SERVICE UPNP_S_SERVICE
}; };
typedef enum Upnp_SType_e Upnp_SType; typedef enum Upnp_SType_e Upnp_SType;
@ -719,7 +718,6 @@ typedef enum Upnp_SType_e Upnp_SType;
interprets the {\bf description} parameter. interprets the {\bf description} parameter.
*/ */
enum Upnp_DescType_e { enum Upnp_DescType_e {
/** The description is the URL to the description document. */ /** The description is the URL to the description document. */
UPNPREG_URL_DESC, UPNPREG_URL_DESC,
@ -730,28 +728,11 @@ enum Upnp_DescType_e {
/** The description is a pointer to a character array containing /** The description is a pointer to a character array containing
the XML description document. */ the XML description document. */
UPNPREG_BUF_DESC UPNPREG_BUF_DESC
}; };
typedef enum Upnp_DescType_e Upnp_DescType; typedef enum Upnp_DescType_e Upnp_DescType;
/** Returned along with a {\bf UPNP_EVENT_SUBSCRIPTION_REQUEST}
* callback. */
struct Upnp_Subscription_Request
{
/** The identifier for the service being subscribed to. */
char *ServiceId;
/** Universal device name. */
char *UDN;
/** The assigned subscription ID for this subscription. */
Upnp_SID Sid;
};
/* The type of handle returned by the web server for open requests. */ /* The type of handle returned by the web server for open requests. */
typedef void *UpnpWebFileHandle; typedef void *UpnpWebFileHandle;
@ -1660,19 +1641,20 @@ EXPORT_SPEC int UpnpSendActionExAsync(
*/ */
EXPORT_SPEC int UpnpAcceptSubscription( EXPORT_SPEC int UpnpAcceptSubscription(
IN UpnpDevice_Handle Hnd, /** The handle of the device. */ /** The handle of the device. */
IN const char *DevID, /** The device ID of the subdevice of the IN UpnpDevice_Handle Hnd,
service generating the event. */ /** The device ID of the subdevice of the service generating the event. */
IN const char *ServID, /** The unique service identifier of the service IN const char *DevID,
generating the event. */ /** The unique service identifier of the service generating the event. */
IN const char **VarName, /** Pointer to an array of event variables. */ IN const char *ServID,
IN const char **NewVal, /** Pointer to an array of values for /** Pointer to an array of event variables. */
the event variables. */ IN const char **VarName,
IN int cVariables, /** The number of event variables in /** Pointer to an array of values for the event variables. */
{\bf VarName}. */ IN const char **NewVal,
IN Upnp_SID SubsId /** The subscription ID of the newly /** The number of event variables in {\bf VarName}. */
registered control point. */ IN int cVariables,
); /** The subscription ID of the newly registered control point. */
IN const Upnp_SID SubsId);
/** {\bf UpnpAcceptSubscriptionExt} is similar to {\bf UpnpAcceptSubscription} /** {\bf UpnpAcceptSubscriptionExt} is similar to {\bf UpnpAcceptSubscription}
* except that it takes a DOM document for the variables to event rather * except that it takes a DOM document for the variables to event rather

View File

@ -534,15 +534,14 @@ SampleUtil_PrintEvent( IN Upnp_EventType EventType,
*/ */
case UPNP_EVENT_SUBSCRIPTION_REQUEST: case UPNP_EVENT_SUBSCRIPTION_REQUEST:
{ {
struct Upnp_Subscription_Request *sr_event = UpnpSubscriptionRequest *sr_event = (UpnpSubscriptionRequest *)Event;
(struct Upnp_Subscription_Request *)Event;
SampleUtil_Print( SampleUtil_Print(
"ServiceID = %s\n" "ServiceID = %s\n"
"UDN = %s\n" "UDN = %s\n"
"SID = %s\n", "SID = %s\n",
sr_event->ServiceId, UpnpString_get_String(UpnpSubscriptionRequest_get_ServiceId(sr_event)),
sr_event->UDN, UpnpString_get_String(UpnpSubscriptionRequest_get_UDN(sr_event)),
sr_event->Sid ); UpnpString_get_String(UpnpSubscriptionRequest_get_SID(sr_event)));
} }
break; break;

View File

@ -364,61 +364,68 @@ TvDeviceStateTableInit( IN char *DescDocURL )
* sr_event -- The subscription request event structure * sr_event -- The subscription request event structure
* *
*****************************************************************************/ *****************************************************************************/
int int TvDeviceHandleSubscriptionRequest(IN const UpnpSubscriptionRequest *sr_event)
TvDeviceHandleSubscriptionRequest( IN struct Upnp_Subscription_Request
*sr_event )
{ {
unsigned int i = 0; //,j=0; unsigned int i = 0;
//unsigned int j = 0;
int cmp1 = 0;
int cmp2 = 0;
const char *l_serviceId = NULL;
const char *l_udn = NULL;
const char *l_sid = NULL;
// IXML_Document *PropSet = NULL; // IXML_Document *PropSet = NULL;
// lock state mutex // lock state mutex
ithread_mutex_lock( &TVDevMutex ); ithread_mutex_lock( &TVDevMutex );
for( i = 0; i < TV_SERVICE_SERVCOUNT; i++ ) { l_serviceId = UpnpString_get_String(UpnpSubscriptionRequest_get_ServiceId(sr_event));
if( ( strcmp( sr_event->UDN, tv_service_table[i].UDN ) == 0 ) && l_udn = UpnpString_get_String(UpnpSubscriptionRequest_get_UDN(sr_event));
( strcmp( sr_event->ServiceId, tv_service_table[i].ServiceId ) l_sid = UpnpString_get_String(UpnpSubscriptionRequest_get_SID(sr_event));
== 0 ) ) { for (i = 0; i < TV_SERVICE_SERVCOUNT; ++i) {
cmp1 = strcmp(l_udn, tv_service_table[i].UDN);
/* cmp2 = strcmp(l_serviceId, tv_service_table[i].ServiceId);
if (cmp1 == 0 && cmp2 == 0) {
#if 0
PropSet = NULL; PropSet = NULL;
for (j=0; j< tv_service_table[i].VariableCount; j++) for (j = 0; j< tv_service_table[i].VariableCount; ++j) {
{
// add each variable to the property set // add each variable to the property set
// for initial state dump // for initial state dump
UpnpAddToPropertySet(&PropSet, UpnpAddToPropertySet(
&PropSet,
tv_service_table[i].VariableName[j], tv_service_table[i].VariableName[j],
tv_service_table[i].VariableStrVal[j]); tv_service_table[i].VariableStrVal[j]);
} }
// dump initial state // dump initial state
UpnpAcceptSubscriptionExt(device_handle, sr_event->UDN, UpnpAcceptSubscriptionExt(
sr_event->ServiceId, device_handle,
PropSet,sr_event->Sid); l_udn,
l_serviceId,
PropSet,
l_sid);
// free document // free document
Document_free(PropSet); Document_free(PropSet);
#endif
*/ UpnpAcceptSubscription(
device_handle,
UpnpAcceptSubscription( device_handle, l_udn,
sr_event->UDN, l_serviceId,
sr_event->ServiceId,
(const char **)tv_service_table[i]. (const char **)tv_service_table[i].
VariableName, VariableName,
(const char **)tv_service_table[i]. (const char **)tv_service_table[i].
VariableStrVal, VariableStrVal,
tv_service_table[i].VariableCount, tv_service_table[i].VariableCount,
sr_event->Sid ); l_sid);
} }
} }
ithread_mutex_unlock( &TVDevMutex ); ithread_mutex_unlock( &TVDevMutex );
return ( 1 ); return 1;
} }
/****************************************************************************** /******************************************************************************
* TvDeviceHandleGetVarRequest * TvDeviceHandleGetVarRequest
* *
@ -1749,7 +1756,7 @@ int TvDeviceCallbackEventHandler(Upnp_EventType EventType, void *Event, void *Co
{ {
switch ( EventType ) { switch ( EventType ) {
case UPNP_EVENT_SUBSCRIPTION_REQUEST: case UPNP_EVENT_SUBSCRIPTION_REQUEST:
TvDeviceHandleSubscriptionRequest( (struct Upnp_Subscription_Request *)Event ); TvDeviceHandleSubscriptionRequest((UpnpSubscriptionRequest *)Event);
break; break;
case UPNP_CONTROL_GET_VAR_REQUEST: case UPNP_CONTROL_GET_VAR_REQUEST:

View File

@ -226,7 +226,7 @@ int TvDeviceStateTableInit(char*);
* sr_event -- The subscription request event structure * sr_event -- The subscription request event structure
* *
*****************************************************************************/ *****************************************************************************/
int TvDeviceHandleSubscriptionRequest(struct Upnp_Subscription_Request *); int TvDeviceHandleSubscriptionRequest(const UpnpSubscriptionRequest *);
/****************************************************************************** /******************************************************************************
* TvDeviceHandleGetVarRequest * TvDeviceHandleGetVarRequest

View File

@ -366,61 +366,68 @@ TvDeviceStateTableInit( IN char *DescDocURL )
* sr_event -- The subscription request event structure * sr_event -- The subscription request event structure
* *
*****************************************************************************/ *****************************************************************************/
int int TvDeviceHandleSubscriptionRequest(IN const UpnpSubscriptionRequest *sr_event)
TvDeviceHandleSubscriptionRequest( IN struct Upnp_Subscription_Request
*sr_event )
{ {
unsigned int i = 0; //,j=0; unsigned int i = 0;
//unsigned int j = 0;
int cmp1 = 0;
int cmp2 = 0;
const char *l_serviceId = NULL;
const char *l_udn = NULL;
const char *l_sid = NULL;
// IXML_Document *PropSet = NULL; // IXML_Document *PropSet = NULL;
// lock state mutex // lock state mutex
ithread_mutex_lock( &TVDevMutex ); ithread_mutex_lock( &TVDevMutex );
for( i = 0; i < TV_SERVICE_SERVCOUNT; i++ ) { l_serviceId = UpnpString_get_String(UpnpSubscriptionRequest_get_ServiceId(sr_event));
if( ( strcmp( sr_event->UDN, tv_service_table[i].UDN ) == 0 ) && l_udn = UpnpString_get_String(UpnpSubscriptionRequest_get_UDN(sr_event));
( strcmp( sr_event->ServiceId, tv_service_table[i].ServiceId ) l_sid = UpnpString_get_String(UpnpSubscriptionRequest_get_SID(sr_event));
== 0 ) ) { for (i = 0; i < TV_SERVICE_SERVCOUNT; ++i) {
cmp1 = strcmp(l_udn, tv_service_table[i].UDN);
/* cmp2 = strcmp(l_serviceId, tv_service_table[i].ServiceId);
if (cmp1 == 0 && cmp2 == 0) {
#if 0
PropSet = NULL; PropSet = NULL;
for (j=0; j< tv_service_table[i].VariableCount; j++) for (j = 0; j< tv_service_table[i].VariableCount; ++j) {
{
// add each variable to the property set // add each variable to the property set
// for initial state dump // for initial state dump
UpnpAddToPropertySet(&PropSet, UpnpAddToPropertySet(
&PropSet,
tv_service_table[i].VariableName[j], tv_service_table[i].VariableName[j],
tv_service_table[i].VariableStrVal[j]); tv_service_table[i].VariableStrVal[j]);
} }
// dump initial state // dump initial state
UpnpAcceptSubscriptionExt(device_handle, sr_event->UDN, UpnpAcceptSubscriptionExt(
sr_event->ServiceId, device_handle,
PropSet,sr_event->Sid); l_udn,
l_serviceId,
PropSet,
l_sid);
// free document // free document
Document_free(PropSet); Document_free(PropSet);
#endif
*/ UpnpAcceptSubscription(
device_handle,
UpnpAcceptSubscription( device_handle, l_udn,
sr_event->UDN, l_serviceId,
sr_event->ServiceId,
(const char **)tv_service_table[i]. (const char **)tv_service_table[i].
VariableName, VariableName,
(const char **)tv_service_table[i]. (const char **)tv_service_table[i].
VariableStrVal, VariableStrVal,
tv_service_table[i].VariableCount, tv_service_table[i].VariableCount,
sr_event->Sid ); l_sid);
} }
} }
ithread_mutex_unlock( &TVDevMutex ); ithread_mutex_unlock( &TVDevMutex );
return ( 1 ); return 1;
} }
/****************************************************************************** /******************************************************************************
* TvDeviceHandleGetVarRequest * TvDeviceHandleGetVarRequest
* *
@ -1751,7 +1758,7 @@ int TvDeviceCallbackEventHandler(Upnp_EventType EventType, void *Event, void *Co
{ {
switch ( EventType ) { switch ( EventType ) {
case UPNP_EVENT_SUBSCRIPTION_REQUEST: case UPNP_EVENT_SUBSCRIPTION_REQUEST:
TvDeviceHandleSubscriptionRequest( (struct Upnp_Subscription_Request *)Event ); TvDeviceHandleSubscriptionRequest((UpnpSubscriptionRequest *)Event);
break; break;
case UPNP_CONTROL_GET_VAR_REQUEST: case UPNP_CONTROL_GET_VAR_REQUEST:

View File

@ -226,7 +226,7 @@ int TvDeviceStateTableInit(char*);
* sr_event -- The subscription request event structure * sr_event -- The subscription request event structure
* *
*****************************************************************************/ *****************************************************************************/
int TvDeviceHandleSubscriptionRequest(struct Upnp_Subscription_Request *); int TvDeviceHandleSubscriptionRequest(const UpnpSubscriptionRequest *);
/****************************************************************************** /******************************************************************************
* TvDeviceHandleGetVarRequest * TvDeviceHandleGetVarRequest

View File

@ -0,0 +1,131 @@
#include "config.h"
#include "SubscriptionRequest.h"
#include <stdlib.h> // for calloc(), free()
#include <string.h> // for memset(), strlen(), strdup()
struct SUpnpSubscriptionRequest
{
UpnpString *m_serviceId;
UpnpString *m_UDN;
UpnpString *m_SID;
};
UpnpSubscriptionRequest *UpnpSubscriptionRequest_new()
{
struct SUpnpSubscriptionRequest *p = calloc(1, sizeof (struct SUpnpSubscriptionRequest));
p->m_serviceId = UpnpString_new();
p->m_UDN = UpnpString_new();
p->m_SID = UpnpString_new();
return (UpnpSubscriptionRequest *)p;
}
void UpnpSubscriptionRequest_delete(UpnpSubscriptionRequest *p)
{
struct SUpnpSubscriptionRequest *q = (struct SUpnpSubscriptionRequest *)p;
UpnpString_delete(q->m_serviceId);
q->m_serviceId = NULL;
UpnpString_delete(q->m_UDN);
q->m_UDN = NULL;
UpnpString_delete(q->m_SID);
q->m_SID = NULL;
free(p);
}
UpnpSubscriptionRequest *UpnpSubscriptionRequest_dup(const UpnpSubscriptionRequest *p)
{
UpnpSubscriptionRequest *q = UpnpSubscriptionRequest_new();
UpnpSubscriptionRequest_assign(q, p);
return q;
}
void UpnpSubscriptionRequest_assign(UpnpSubscriptionRequest *q, const UpnpSubscriptionRequest *p)
{
if (q != p) {
UpnpSubscriptionRequest_set_ServiceId(q, UpnpSubscriptionRequest_get_ServiceId(p));
UpnpSubscriptionRequest_set_UDN(q, UpnpSubscriptionRequest_get_UDN(p));
UpnpSubscriptionRequest_set_SID(q, UpnpSubscriptionRequest_get_SID(p));
}
}
const UpnpString *UpnpSubscriptionRequest_get_ServiceId(const UpnpSubscriptionRequest *p)
{
return ((struct SUpnpSubscriptionRequest *)p)->m_serviceId;
}
void UpnpSubscriptionRequest_set_ServiceId(UpnpSubscriptionRequest *p, const UpnpString *s)
{
UpnpString_delete(((struct SUpnpSubscriptionRequest *)p)->m_serviceId);
((struct SUpnpSubscriptionRequest *)p)->m_serviceId = UpnpString_dup(s);
}
void UpnpSubscriptionRequest_strcpy_ServiceId(UpnpSubscriptionRequest *p, const char *s)
{
UpnpString_delete(((struct SUpnpSubscriptionRequest *)p)->m_serviceId);
((struct SUpnpSubscriptionRequest *)p)->m_serviceId = UpnpString_new();
UpnpString_set_String(((struct SUpnpSubscriptionRequest *)p)->m_serviceId, s);
}
const UpnpString *UpnpSubscriptionRequest_get_UDN(const UpnpSubscriptionRequest *p)
{
return ((struct SUpnpSubscriptionRequest *)p)->m_UDN;
}
void UpnpSubscriptionRequest_set_UDN(UpnpSubscriptionRequest *p, const UpnpString *s)
{
UpnpString_delete(((struct SUpnpSubscriptionRequest *)p)->m_UDN);
((struct SUpnpSubscriptionRequest *)p)->m_UDN = UpnpString_dup(s);
}
void UpnpSubscriptionRequest_strcpy_UDN(UpnpSubscriptionRequest *p, const char *s)
{
UpnpString_delete(((struct SUpnpSubscriptionRequest *)p)->m_UDN);
((struct SUpnpSubscriptionRequest *)p)->m_UDN = UpnpString_new();
UpnpString_set_String(((struct SUpnpSubscriptionRequest *)p)->m_UDN, s);
}
const UpnpString *UpnpSubscriptionRequest_get_SID(const UpnpSubscriptionRequest *p)
{
return ((struct SUpnpSubscriptionRequest *)p)->m_SID;
}
void UpnpSubscriptionRequest_set_SID(UpnpSubscriptionRequest *p, const UpnpString *s)
{
UpnpString_delete(((struct SUpnpSubscriptionRequest *)p)->m_SID);
((struct SUpnpSubscriptionRequest *)p)->m_SID = UpnpString_dup(s);
}
void UpnpSubscriptionRequest_strcpy_SID(UpnpSubscriptionRequest *p, const char *s)
{
UpnpString_delete(((struct SUpnpSubscriptionRequest *)p)->m_SID);
((struct SUpnpSubscriptionRequest *)p)->m_SID = UpnpString_new();
UpnpString_set_String(((struct SUpnpSubscriptionRequest *)p)->m_SID, s);
}

View File

@ -2572,14 +2572,14 @@ UpnpNotifyExt( IN UpnpDevice_Handle Hnd,
* Return Values: int * Return Values: int
* UPNP_E_SUCCESS if successful else sends appropriate error. * UPNP_E_SUCCESS if successful else sends appropriate error.
***************************************************************************/ ***************************************************************************/
int int UpnpAcceptSubscription(
UpnpAcceptSubscription( IN UpnpDevice_Handle Hnd, IN UpnpDevice_Handle Hnd,
IN const char *DevID_const, IN const char *DevID_const,
IN const char *ServName_const, IN const char *ServName_const,
IN const char **VarName_const, IN const char **VarName_const,
IN const char **NewVal_const, IN const char **NewVal_const,
int cVariables, int cVariables,
IN Upnp_SID SubsId ) IN const Upnp_SID SubsId)
{ {
struct Handle_Info *SInfo = NULL; struct Handle_Info *SInfo = NULL;
int retVal; int retVal;

View File

@ -433,35 +433,15 @@ genaNotifyThread( IN void *input )
HandleUnlock(); HandleUnlock();
} }
/****************************************************************************
* Function : genaInitNotify int genaInitNotify(
* IN UpnpDevice_Handle device_handle,
* Parameters :
* IN UpnpDevice_Handle device_handle : Device handle
* IN char *UDN : Device udn
* IN char *servId : Service ID
* IN char **VarNames : Array of variable names
* IN char **VarValues : Array of variable values
* IN int var_count : array size
* IN Upnp_SID sid : subscription ID
*
* Description : This function sends the intial state table dump to
* newly subscribed control point.
*
* Return : int
* returns GENA_E_SUCCESS if successful else returns appropriate error
*
* Note : No other event will be sent to this control point before the
* intial state table dump.
****************************************************************************/
int
genaInitNotify( IN UpnpDevice_Handle device_handle,
IN char *UDN, IN char *UDN,
IN char *servId, IN char *servId,
IN char **VarNames, IN char **VarNames,
IN char **VarValues, IN char **VarValues,
IN int var_count, IN int var_count,
IN Upnp_SID sid ) IN const Upnp_SID sid)
{ {
char *UDN_copy = NULL; char *UDN_copy = NULL;
char *servId_copy = NULL; char *servId_copy = NULL;
@ -527,8 +507,8 @@ genaInitNotify( IN UpnpDevice_Handle device_handle,
"FOUND SERVICE IN INIT NOTFY: UDN %s, ServID: %s ", "FOUND SERVICE IN INIT NOTFY: UDN %s, ServID: %s ",
UDN, servId); UDN, servId);
if( ( ( sub = GetSubscriptionSID( sid, service ) ) == NULL ) || sub = GetSubscriptionSID(sid, service);
( sub->active ) ) { if (sub == NULL || sub->active) {
free( UDN_copy ); free( UDN_copy );
free( reference_count ); free( reference_count );
free( servId_copy ); free( servId_copy );
@ -625,32 +605,13 @@ genaInitNotify( IN UpnpDevice_Handle device_handle,
return return_code; return return_code;
} }
/****************************************************************************
* Function : genaInitNotifyExt int genaInitNotifyExt(
* IN UpnpDevice_Handle device_handle,
* Parameters :
* IN UpnpDevice_Handle device_handle : Device handle
* IN char *UDN : Device udn
* IN char *servId : Service ID
* IN IXML_Document *PropSet : Document of the state table
* IN Upnp_SID sid : subscription ID
*
* Description : This function is 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.
*
* Return : int
* returns GENA_E_SUCCESS if successful else returns appropriate error
*
* Note : No other event will be sent to this control point before the
* intial state table dump.
****************************************************************************/
int
genaInitNotifyExt( IN UpnpDevice_Handle device_handle,
IN char *UDN, IN char *UDN,
IN char *servId, IN char *servId,
IN IXML_Document *PropSet, IN IXML_Document *PropSet,
IN Upnp_SID sid ) IN const Upnp_SID sid)
{ {
char *UDN_copy = NULL; char *UDN_copy = NULL;
char *servId_copy = NULL; char *servId_copy = NULL;
@ -1285,25 +1246,23 @@ create_url_list( IN memptr * url_list,
* *
* Parameters: * Parameters:
* IN SOCKINFO *info: socket info of the device * IN SOCKINFO *info: socket info of the device
* IN http_message_t* request : SUBSCRIPTION request from the control * IN http_message_t* request:
* point * SUBSCRIPTION request from the control point
* *
* Description: This function handles a subscription request from a * Description: This function handles a subscription request from a
* ctrl point. The socket is not closed on return. * ctrl point. The socket is not closed on return.
* *
* Return: void * Return: void
*
* Note :
****************************************************************************/ ****************************************************************************/
void void gena_process_subscription_request(
gena_process_subscription_request( IN SOCKINFO * info, IN SOCKINFO *info,
IN http_message_t *request) IN http_message_t *request)
{ {
UpnpSubscriptionRequest *request_struct = UpnpSubscriptionRequest_new();
Upnp_SID temp_sid; Upnp_SID temp_sid;
int return_code = 1; int return_code = 1;
int time_out = 1801; int time_out = 1801;
service_info *service; service_info *service;
struct Upnp_Subscription_Request request_struct;
subscription *sub; subscription *sub;
uuid_upnp uid; uuid_upnp uid;
struct Handle_Info *handle_info; struct Handle_Info *handle_info;
@ -1320,7 +1279,7 @@ gena_process_subscription_request( IN SOCKINFO * info,
if (httpmsg_find_hdr(request, HDR_NT, &nt_hdr) == NULL) { if (httpmsg_find_hdr(request, HDR_NT, &nt_hdr) == NULL) {
error_respond(info, HTTP_BAD_REQUEST, request); error_respond(info, HTTP_BAD_REQUEST, request);
return; goto exit_function;
} }
// check NT header // check NT header
@ -1328,21 +1287,19 @@ gena_process_subscription_request( IN SOCKINFO * info,
// we accept either upnp:event, or upnp:propchange for the NT header // we accept either upnp:event, or upnp:propchange for the NT header
if (memptr_cmp_nocase(&nt_hdr, "upnp:event") != 0) { if (memptr_cmp_nocase(&nt_hdr, "upnp:event") != 0) {
error_respond(info, HTTP_PRECONDITION_FAILED, request); error_respond(info, HTTP_PRECONDITION_FAILED, request);
return; goto exit_function;
} }
// if a SID is present then the we have a bad request // if a SID is present then the we have a bad request "incompatible headers"
// "incompatible headers"
if (httpmsg_find_hdr(request, HDR_SID, NULL) != NULL) { if (httpmsg_find_hdr(request, HDR_SID, NULL) != NULL) {
error_respond(info, HTTP_BAD_REQUEST, request); error_respond(info, HTTP_BAD_REQUEST, request);
return; goto exit_function;
} }
// look up service by eventURL // look up service by eventURL
if( ( event_url_path = str_alloc( request->uri.pathquery.buff, event_url_path = str_alloc(request->uri.pathquery.buff, request->uri.pathquery.size);
request->uri.pathquery.size ) ) == if (event_url_path == NULL) {
NULL ) {
error_respond(info, HTTP_INTERNAL_SERVER_ERROR, request); error_respond(info, HTTP_INTERNAL_SERVER_ERROR, request);
return; goto exit_function;
} }
UpnpPrintf(UPNP_INFO, GENA, __FILE__, __LINE__, UpnpPrintf(UPNP_INFO, GENA, __FILE__, __LINE__,
@ -1357,16 +1314,15 @@ gena_process_subscription_request( IN SOCKINFO * info,
free(event_url_path); free(event_url_path);
error_respond(info, HTTP_INTERNAL_SERVER_ERROR, request); error_respond(info, HTTP_INTERNAL_SERVER_ERROR, request);
HandleUnlock(); HandleUnlock();
return; goto exit_function;
} }
service = FindServiceEventURLPath( &handle_info->ServiceTable, service = FindServiceEventURLPath(&handle_info->ServiceTable, event_url_path);
event_url_path );
free(event_url_path); free(event_url_path);
if (service == NULL || !service->active) { if (service == NULL || !service->active) {
error_respond(info, HTTP_NOT_FOUND, request); error_respond(info, HTTP_NOT_FOUND, request);
HandleUnlock(); HandleUnlock();
return; goto exit_function;
} }
UpnpPrintf(UPNP_INFO, GENA, __FILE__, __LINE__, UpnpPrintf(UPNP_INFO, GENA, __FILE__, __LINE__,
@ -1380,14 +1336,14 @@ gena_process_subscription_request( IN SOCKINFO * info,
service->TotalSubscriptions >= handle_info->MaxSubscriptions) { service->TotalSubscriptions >= handle_info->MaxSubscriptions) {
error_respond(info, HTTP_INTERNAL_SERVER_ERROR, request); error_respond(info, HTTP_INTERNAL_SERVER_ERROR, request);
HandleUnlock(); HandleUnlock();
return; goto exit_function;
} }
// generate new subscription // generate new subscription
sub = (subscription *)malloc(sizeof (subscription)); sub = (subscription *)malloc(sizeof (subscription));
if (sub == NULL) { if (sub == NULL) {
error_respond(info, HTTP_INTERNAL_SERVER_ERROR, request); error_respond(info, HTTP_INTERNAL_SERVER_ERROR, request);
HandleUnlock(); HandleUnlock();
return; goto exit_function;
} }
sub->eventKey = 0; sub->eventKey = 0;
sub->ToSendEventKey = 0; sub->ToSendEventKey = 0;
@ -1398,30 +1354,36 @@ gena_process_subscription_request( IN SOCKINFO * info,
sub->DeliveryURLs.parsedURLs = NULL; sub->DeliveryURLs.parsedURLs = NULL;
// check for valid callbacks // check for valid callbacks
if( httpmsg_find_hdr( request, HDR_CALLBACK, &callback_hdr ) == NULL || if (httpmsg_find_hdr( request, HDR_CALLBACK, &callback_hdr) == NULL) {
( return_code = create_url_list( &callback_hdr,
&sub->DeliveryURLs ) ) == 0 ) {
error_respond(info, HTTP_PRECONDITION_FAILED, request); error_respond(info, HTTP_PRECONDITION_FAILED, request);
freeSubscriptionList(sub); freeSubscriptionList(sub);
HandleUnlock(); HandleUnlock();
return; goto exit_function;
}
return_code = create_url_list(&callback_hdr, &sub->DeliveryURLs);
if (return_code == 0) {
error_respond(info, HTTP_PRECONDITION_FAILED, request);
freeSubscriptionList(sub);
HandleUnlock();
goto exit_function;
} }
if (return_code == UPNP_E_OUTOF_MEMORY) { if (return_code == UPNP_E_OUTOF_MEMORY) {
error_respond(info, HTTP_INTERNAL_SERVER_ERROR, request); error_respond(info, HTTP_INTERNAL_SERVER_ERROR, request);
freeSubscriptionList(sub); freeSubscriptionList(sub);
HandleUnlock(); HandleUnlock();
return; goto exit_function;
} }
// set the timeout // set the timeout
if (httpmsg_find_hdr(request, HDR_TIMEOUT, &timeout_hdr) != NULL) { if (httpmsg_find_hdr(request, HDR_TIMEOUT, &timeout_hdr) != NULL) {
if (matchstr(timeout_hdr.buf, timeout_hdr.length, if (matchstr(timeout_hdr.buf, timeout_hdr.length,
"%iSecond-%d%0", &time_out) == PARSE_OK) { "%iSecond-%d%0", &time_out) == PARSE_OK) {
// nothing // nothing
} else if( memptr_cmp_nocase( &timeout_hdr, "Second-infinite" ) == } else if(memptr_cmp_nocase(&timeout_hdr, "Second-infinite") == 0) {
0 ) { // infinite timeout
time_out = -1; // infinite timeout time_out = -1;
} else { } else {
time_out = DEFAULT_TIMEOUT; // default is > 1800 seconds // default is > 1800 seconds
time_out = DEFAULT_TIMEOUT;
} }
} }
// replace infinite timeout with max timeout, if possible // replace infinite timeout with max timeout, if possible
@ -1434,7 +1396,8 @@ gena_process_subscription_request( IN SOCKINFO * info,
if (time_out >= 0) { if (time_out >= 0) {
sub->expireTime = time(NULL) + time_out; sub->expireTime = time(NULL) + time_out;
} else { } else {
sub->expireTime = 0; // infinite time // infinite time
sub->expireTime = 0;
} }
// generate SID // generate SID
@ -1446,7 +1409,7 @@ gena_process_subscription_request( IN SOCKINFO * info,
if (respond_ok(info, time_out, sub, request) != UPNP_E_SUCCESS) { if (respond_ok(info, time_out, sub, request) != UPNP_E_SUCCESS) {
freeSubscriptionList(sub); freeSubscriptionList(sub);
HandleUnlock(); HandleUnlock();
return; goto exit_function;
} }
// add to subscription list // add to subscription list
sub->next = service->subscriptionList; sub->next = service->subscriptionList;
@ -1454,9 +1417,9 @@ gena_process_subscription_request( IN SOCKINFO * info,
service->TotalSubscriptions++; service->TotalSubscriptions++;
// finally generate callback for init table dump // finally generate callback for init table dump
request_struct.ServiceId = service->serviceId; UpnpSubscriptionRequest_strcpy_ServiceId(request_struct, service->serviceId);
request_struct.UDN = service->UDN; UpnpSubscriptionRequest_strcpy_UDN(request_struct, service->UDN);
strcpy( ( char * )request_struct.Sid, sub->sid ); UpnpSubscriptionRequest_strcpy_SID(request_struct, sub->sid);
// copy callback // copy callback
callback_fun = handle_info->Callback; callback_fun = handle_info->Callback;
@ -1465,12 +1428,12 @@ gena_process_subscription_request( IN SOCKINFO * info,
HandleUnlock(); HandleUnlock();
// make call back with request struct // make call back with request struct
//in the future should find a way of mainting // in the future should find a way of mainting that the handle
//that the handle is not unregistered in the middle of a // is not unregistered in the middle of a callback
//callback callback_fun(UPNP_EVENT_SUBSCRIPTION_REQUEST, request_struct, cookie);
callback_fun( UPNP_EVENT_SUBSCRIPTION_REQUEST, exit_function:
&request_struct, cookie ); UpnpSubscriptionRequest_delete(request_struct);
} }
/**************************************************************************** /****************************************************************************
@ -1666,7 +1629,6 @@ gena_process_unsubscribe_request( IN SOCKINFO * info,
// validate service // validate service
if( service == NULL || if( service == NULL ||
!service->active || GetSubscriptionSID( sid, service ) == NULL ) !service->active || GetSubscriptionSID( sid, service ) == NULL )
//CheckSubscriptionSID(sid, service) == NULL )
{ {
error_respond( info, HTTP_PRECONDITION_FAILED, request ); error_respond( info, HTTP_PRECONDITION_FAILED, request );
HandleUnlock(); HandleUnlock();

View File

@ -116,25 +116,8 @@ RemoveSubscriptionSID( Upnp_SID sid,
} }
/************************************************************************
* Function : GetSubscriptionSID subscription *GetSubscriptionSID(const Upnp_SID sid, service_info *service)
*
* Parameters :
* Upnp_SID sid ; subscription ID
* service_info * service ; service object providing the list of
* subscriptions
*
* Description : Return the subscription from the service table
* that matches const Upnp_SID sid value.
*
* Return : subscription * - Pointer to the matching subscription
* node;
*
* Note :
************************************************************************/
subscription *
GetSubscriptionSID( Upnp_SID sid,
service_info * service )
{ {
subscription *next = service->subscriptionList; subscription *next = service->subscriptionList;
subscription *previous = NULL; subscription *previous = NULL;
@ -169,24 +152,8 @@ GetSubscriptionSID( Upnp_SID sid,
} }
/************************************************************************
* Function : GetNextSubscription subscription *GetNextSubscription(service_info *service, subscription *current)
*
* Parameters :
* service_info * service ; service object providing the list of
* subscriptions
* subscription *current ; current subscription object
*
* Description : Get current and valid subscription from the service
* table.
*
* Return : subscription * - Pointer to the next subscription node;
*
* Note :
************************************************************************/
subscription *
GetNextSubscription( service_info * service,
subscription * current )
{ {
time_t current_time; time_t current_time;
subscription *next = NULL; subscription *next = NULL;
@ -218,22 +185,8 @@ GetNextSubscription( service_info * service,
return next; return next;
} }
/************************************************************************
* Function : GetFirstSubscription subscription *GetFirstSubscription(service_info *service)
*
* Parameters :
* service_info *service ; service object providing the list of
* subscriptions
*
* Description : Gets pointer to the first subscription node in the
* service table.
*
* Return : subscription * - pointer to the first subscription node ;
*
* Note :
************************************************************************/
subscription *
GetFirstSubscription( service_info * service )
{ {
subscription temp; subscription temp;
subscription *next = NULL; subscription *next = NULL;
@ -242,24 +195,12 @@ GetFirstSubscription( service_info * service )
next = GetNextSubscription(service, &temp); next = GetNextSubscription(service, &temp);
service->subscriptionList = temp.next; service->subscriptionList = temp.next;
// service->subscriptionList = next; // service->subscriptionList = next;
return next; return next;
} }
/************************************************************************
* Function : freeSubscription void freeSubscription(subscription *sub)
*
* Parameters :
* subscription * sub ; subscription to be freed
*
* Description : Free's the memory allocated for storing the URL of
* the subscription.
*
* Return : void ;
*
* Note :
************************************************************************/
void
freeSubscription( subscription * sub )
{ {
if (sub) { if (sub) {
free_URL_list(&sub->DeliveryURLs); free_URL_list(&sub->DeliveryURLs);

View File

@ -352,7 +352,7 @@ EXTERN_C int genaInitNotify(IN UpnpDevice_Handle device_handle,
IN char **VarNames, IN char **VarNames,
IN char **VarValues, IN char **VarValues,
IN int var_count, IN int var_count,
IN Upnp_SID sid); IN const Upnp_SID sid);
#endif /* INCLUDE_DEVICE_APIS */ #endif /* INCLUDE_DEVICE_APIS */
@ -366,7 +366,8 @@ EXTERN_C int genaInitNotify(IN UpnpDevice_Handle device_handle,
* IN IXML_Document *PropSet: Document of the state table * IN IXML_Document *PropSet: Document of the state table
* IN Upnp_SID sid: subscription ID * IN Upnp_SID sid: subscription ID
* *
* Description : This function is similar to the genaInitNofity. The only * Description:
* This function is similar to the genaInitNofity. The only
* difference is that it takes the xml document for the state table and * difference is that it takes the xml document for the state table and
* sends the intial state table dump to newly subscribed control point. * sends the intial state table dump to newly subscribed control point.
* *
@ -382,7 +383,7 @@ EXTERN_C int genaInitNotifyExt(
IN char *UDN, IN char *UDN,
IN char *servId, IN char *servId,
IN IXML_Document *PropSet, IN IXML_Document *PropSet,
IN Upnp_SID sid); IN const Upnp_SID sid);
#endif /* INCLUDE_DEVICE_APIS */ #endif /* INCLUDE_DEVICE_APIS */

View File

@ -121,41 +121,43 @@ void RemoveSubscriptionSID(Upnp_SID sid, service_info * service);
* Function: GetSubscriptionSID * Function: GetSubscriptionSID
* *
* Parameters: * Parameters:
* Upnp_SID sid ; subscription ID * const Upnp_SID sid: subscription ID
* service_info * service ; service object providing the list of * const service_info *service: service object providing the list of
* subscriptions * subscriptions
* *
* Description : Return the subscription from the service table * Description : Return the subscription from the service table
* that matches const Upnp_SID sid value. * that matches const Upnp_SID sid value.
* *
* Return : subscription * - Pointer to the matching subscription * Return: subscription *: Pointer to the matching subscription node;
* node;
*
* Note :
************************************************************************/ ************************************************************************/
subscription * GetSubscriptionSID(Upnp_SID sid,service_info * service); subscription *GetSubscriptionSID(const Upnp_SID sid, service_info *service);
//returns a pointer to the subscription with the SID, NULL if not found /************************************************************************
* Function: GetFirstSubscription
subscription * CheckSubscriptionSID(Upnp_SID sid,service_info * service); *
* Parameters:
//returns a pointer to the first subscription * service_info *service: service object providing the list of
* subscriptions
*
* Description: Gets pointer to the first subscription node in the
* service table.
*
* Return: subscription *: pointer to the first subscription node
************************************************************************/
subscription *GetFirstSubscription(service_info *service); subscription *GetFirstSubscription(service_info *service);
/************************************************************************ /************************************************************************
* Function: GetNextSubscription * Function: GetNextSubscription
* *
* Parameters: * Parameters:
* service_info * service ; service object providing the list of * service_info *service: service object providing the list of
* subscriptions * subscriptions
* subscription *current ; current subscription object * subscription *current: current subscription object
* *
* Description: Get current and valid subscription from the service * Description: Get current and valid subscription from the service
* table. * table.
* *
* Return : subscription * - Pointer to the next subscription node; * Return: subscription *: pointer to the next subscription node
*
* Note :
************************************************************************/ ************************************************************************/
subscription *GetNextSubscription(service_info *service, subscription *current); subscription *GetNextSubscription(service_info *service, subscription *current);