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/StateVarComplete.h \
inc/StateVarRequest.h \
inc/SubscriptionRequest.h \
inc/String.h \
inc/upnp.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/StateVarComplete.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/upnpapi.c
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 "StateVarComplete.h"
#include "StateVarRequest.h"
#include "SubscriptionRequest.h"
enum UpnpOpenFileMode
@ -624,7 +625,7 @@ enum Upnp_EventType_e {
/** Received by a device when a subscription arrives.
* 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}
* needs to be called to confirm the subscription and transmit the
* 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 {
/** Search for all devices and services on the network. */
UPNP_S_ALL,
@ -707,7 +707,6 @@ enum Upnp_SType_e {
/** Search for a particular service type, possibly on a particular
* device type or device instance. */
UPNP_S_SERVICE
};
typedef enum Upnp_SType_e Upnp_SType;
@ -719,7 +718,6 @@ typedef enum Upnp_SType_e Upnp_SType;
interprets the {\bf description} parameter.
*/
enum Upnp_DescType_e {
/** The description is the URL to the description document. */
UPNPREG_URL_DESC,
@ -730,28 +728,11 @@ enum Upnp_DescType_e {
/** The description is a pointer to a character array containing
the XML description document. */
UPNPREG_BUF_DESC
};
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. */
typedef void *UpnpWebFileHandle;
@ -1660,19 +1641,20 @@ EXPORT_SPEC int UpnpSendActionExAsync(
*/
EXPORT_SPEC int UpnpAcceptSubscription(
IN UpnpDevice_Handle Hnd, /** The handle of the device. */
IN const char *DevID, /** The device ID of the subdevice of the
service generating the event. */
IN const char *ServID, /** The unique service identifier of the service
generating the event. */
IN const char **VarName, /** Pointer to an array of event variables. */
IN const char **NewVal, /** Pointer to an array of values for
the event variables. */
IN int cVariables, /** The number of event variables in
{\bf VarName}. */
IN Upnp_SID SubsId /** The subscription ID of the newly
registered control point. */
);
/** The handle of the device. */
IN UpnpDevice_Handle Hnd,
/** The device ID of the subdevice of the service generating the event. */
IN const char *DevID,
/** The unique service identifier of the service generating the event. */
IN const char *ServID,
/** Pointer to an array of event variables. */
IN const char **VarName,
/** Pointer to an array of values for the event variables. */
IN const char **NewVal,
/** The number of event variables in {\bf VarName}. */
IN int cVariables,
/** The subscription ID of the newly registered control point. */
IN const Upnp_SID SubsId);
/** {\bf UpnpAcceptSubscriptionExt} is similar to {\bf UpnpAcceptSubscription}
* 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:
{
struct Upnp_Subscription_Request *sr_event =
(struct Upnp_Subscription_Request *)Event;
UpnpSubscriptionRequest *sr_event = (UpnpSubscriptionRequest *)Event;
SampleUtil_Print(
"ServiceID = %s\n"
"UDN = %s\n"
"SID = %s\n",
sr_event->ServiceId,
sr_event->UDN,
sr_event->Sid );
UpnpString_get_String(UpnpSubscriptionRequest_get_ServiceId(sr_event)),
UpnpString_get_String(UpnpSubscriptionRequest_get_UDN(sr_event)),
UpnpString_get_String(UpnpSubscriptionRequest_get_SID(sr_event)));
}
break;

View File

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

View File

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

View File

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

View File

@ -226,7 +226,7 @@ int TvDeviceStateTableInit(char*);
* sr_event -- The subscription request event structure
*
*****************************************************************************/
int TvDeviceHandleSubscriptionRequest(struct Upnp_Subscription_Request *);
int TvDeviceHandleSubscriptionRequest(const UpnpSubscriptionRequest *);
/******************************************************************************
* 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
* UPNP_E_SUCCESS if successful else sends appropriate error.
***************************************************************************/
int
UpnpAcceptSubscription( IN UpnpDevice_Handle Hnd,
int UpnpAcceptSubscription(
IN UpnpDevice_Handle Hnd,
IN const char *DevID_const,
IN const char *ServName_const,
IN const char **VarName_const,
IN const char **NewVal_const,
int cVariables,
IN Upnp_SID SubsId )
IN const Upnp_SID SubsId)
{
struct Handle_Info *SInfo = NULL;
int retVal;

View File

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

View File

@ -116,25 +116,8 @@ RemoveSubscriptionSID( Upnp_SID sid,
}
/************************************************************************
* Function : GetSubscriptionSID
*
* 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 *GetSubscriptionSID(const Upnp_SID sid, service_info *service)
{
subscription *next = service->subscriptionList;
subscription *previous = NULL;
@ -169,24 +152,8 @@ GetSubscriptionSID( Upnp_SID sid,
}
/************************************************************************
* Function : GetNextSubscription
*
* 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 )
subscription *GetNextSubscription(service_info *service, subscription *current)
{
time_t current_time;
subscription *next = NULL;
@ -218,22 +185,8 @@ GetNextSubscription( service_info * service,
return next;
}
/************************************************************************
* Function : GetFirstSubscription
*
* 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 *GetFirstSubscription(service_info *service)
{
subscription temp;
subscription *next = NULL;
@ -242,24 +195,12 @@ GetFirstSubscription( service_info * service )
next = GetNextSubscription(service, &temp);
service->subscriptionList = temp.next;
// service->subscriptionList = next;
return next;
}
/************************************************************************
* Function : freeSubscription
*
* 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 )
void freeSubscription(subscription *sub)
{
if (sub) {
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 **VarValues,
IN int var_count,
IN Upnp_SID sid);
IN const Upnp_SID sid);
#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 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
* sends the intial state table dump to newly subscribed control point.
*
@ -382,7 +383,7 @@ EXTERN_C int genaInitNotifyExt(
IN char *UDN,
IN char *servId,
IN IXML_Document *PropSet,
IN Upnp_SID sid);
IN const Upnp_SID sid);
#endif /* INCLUDE_DEVICE_APIS */

View File

@ -121,41 +121,43 @@ void RemoveSubscriptionSID(Upnp_SID sid, service_info * service);
* Function: GetSubscriptionSID
*
* Parameters:
* Upnp_SID sid ; subscription ID
* service_info * service ; service object providing the list of
* const Upnp_SID sid: subscription ID
* const 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 :
* Return: subscription *: Pointer to the matching subscription node;
************************************************************************/
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
subscription * CheckSubscriptionSID(Upnp_SID sid,service_info * service);
//returns a pointer to the first subscription
/************************************************************************
* Function: GetFirstSubscription
*
* 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
************************************************************************/
subscription *GetFirstSubscription(service_info *service);
/************************************************************************
* Function: GetNextSubscription
*
* Parameters:
* service_info * service ; service object providing the list of
* service_info *service: service object providing the list of
* subscriptions
* subscription *current ; current subscription object
* subscription *current: current subscription object
*
* Description: Get current and valid subscription from the service
* table.
*
* Return : subscription * - Pointer to the next subscription node;
*
* Note :
* Return: subscription *: pointer to the next subscription node
************************************************************************/
subscription *GetNextSubscription(service_info *service, subscription *current);