Backport of svn 395 and 434:

395: Bob Ciora's patch for lazy UpnpAcceptSubscription().
434: Fixed a buffer overflow due to a bug in the calculation of the
     CONTENT-TYPE header line size, the length was beeing calculated with
     the wrong string, there was a missing colon.


git-svn-id: https://pupnp.svn.sourceforge.net/svnroot/pupnp/branches/branch-1.6.x@461 119443c7-1b9e-41f8-b6fc-b9c35fce742c
This commit is contained in:
Marcelo Roberto Jimenez
2008-07-25 02:56:04 +00:00
parent 423808a095
commit 515233ca56
7 changed files with 2091 additions and 2305 deletions

View File

@@ -21,6 +21,53 @@ Version 1.6.7
* Added an m4 macro to deal with finding libupnp in the users' * Added an m4 macro to deal with finding libupnp in the users'
configure script. configure script.
2008-06-11 Marcelo Jimenez <mroberto(at)users.sourceforge.net>
* Fixed a buffer overflow due to a bug in the calculation of the
CONTENT-TYPE header line size, the length was beeing calculated with
the wrong string, there was a missing colon.
2008-05-26 Marcelo Jimenez <mroberto(at)users.sourceforge.net>
* SF Bug Tracker [ 1903069 ]
Subs (not services) not marked 'active'
Submitted By: Bob Ciora - bobciora
If the UpnpAcceptSubscription is not called, the subscription is not marked
as "active", so no state variables will ever be sent.
I have a "lazy" architecture where a service may not be ready to publish
any state data at the time of a subscription. Subscriptions are still
accepted, there's just nothing to send, so UpnpAcceptSubscription is never
called. As a result, the subscription is never marked as "active" via the
genaInitNotify functions.
A best course of action would be to modify UpnpAcceptSubscription<...>
functions so that they can accept *no* initial state information, but can
still result in the subscription being marked as active. Technically,
then, the "active" flag should be set here, not in the genaInitNotify<...>
functions.
But the UpnpAccept functions don't muck with the subscription table, and
it's more work than it's worth to move that code from the gena fucntions to
the upnpapi functions.
So--- what I've done to correct this problem is to modify both
UpnpAcceptSubscription<...> functions (in upnppapi.c) to accept an empty
state list and still call the gena layer functions. The gena layer
genaInitNotify<...> functions (gena_device.c) then mark the subscription as
"active" *before* checking for an empty state set.
In genaInitNotify, a check for "var_count <= 0" is added immediately after
the "subs->active = 1;" line. If this occurs, then all cleanup is
performed and the function returns GENA_SUCCESS (since now, an empty state
list is not an error). The same check is made for "PropSet == 0" in
genaInitNotifyExt (just after the "subs->active = 1;" line).
I've modifified my proxy layer to call UpnpAcceptSubscriptionExt even when
there is no state data to send. With the suggested changes to
gena_device.c, later state changes are sent correctly.
This has solved my problem.
2008-04-28 Marcelo Jimenez <mroberto(at)users.sourceforge.net> 2008-04-28 Marcelo Jimenez <mroberto(at)users.sourceforge.net>
* Fix in function SetSeed() in threadutil/src/ThreadPool.c for CYGWIN * Fix in function SetSeed() in threadutil/src/ThreadPool.c for CYGWIN
compilation. Thanks to Gary Chan. compilation. Thanks to Gary Chan.

View File

@@ -2355,10 +2355,13 @@ UpnpAcceptSubscription( IN UpnpDevice_Handle Hnd,
HandleUnlock(); HandleUnlock();
return UPNP_E_INVALID_PARAM; return UPNP_E_INVALID_PARAM;
} }
/* Now accepts an empty state list, so the code below is commented out */
#if 0
if( VarName == NULL || NewVal == NULL || cVariables < 0 ) { if( VarName == NULL || NewVal == NULL || cVariables < 0 ) {
HandleUnlock(); HandleUnlock();
return UPNP_E_INVALID_PARAM; return UPNP_E_INVALID_PARAM;
} }
#endif
HandleUnlock(); HandleUnlock();
retVal = retVal =
@@ -2431,11 +2434,13 @@ UpnpAcceptSubscriptionExt( IN UpnpDevice_Handle Hnd,
HandleUnlock(); HandleUnlock();
return UPNP_E_INVALID_PARAM; return UPNP_E_INVALID_PARAM;
} }
/* Now accepts an empty state list, so the code below is commented out */
#if 0
if( PropSet == NULL ) { if( PropSet == NULL ) {
HandleUnlock(); HandleUnlock();
return UPNP_E_INVALID_PARAM; return UPNP_E_INVALID_PARAM;
} }
#endif
HandleUnlock(); HandleUnlock();
retVal = genaInitNotifyExt( Hnd, DevID, ServName, PropSet, SubsId ); retVal = genaInitNotifyExt( Hnd, DevID, ServName, PropSet, SubsId );

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,33 +1,34 @@
/////////////////////////////////////////////////////////////////////////// /*******************************************************************************
// *
// Copyright (c) 2000-2003 Intel Corporation * Copyright (c) 2000-2003 Intel Corporation
// All rights reserved. * All rights reserved.
// *
// Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
// *
// * Redistributions of source code must retain the above copyright notice, * - Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice, * - Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
// * Neither name of Intel Corporation nor the names of its contributors * - Neither name of Intel Corporation nor the names of its contributors
// may be used to endorse or promote products derived from this software * may be used to endorse or promote products derived from this software
// without specific prior written permission. * without specific prior written permission.
// *
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// *
/////////////////////////////////////////////////////////////////////////// ******************************************************************************/
/************************************************************************ /************************************************************************
* Purpose: This file defines the functions for services. It defines * Purpose: This file defines the functions for services. It defines
@@ -116,25 +117,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;

View File

@@ -1,65 +1,82 @@
/////////////////////////////////////////////////////////////////////////// /*******************************************************************************
// *
// Copyright (c) 2000-2003 Intel Corporation * Copyright (c) 2000-2003 Intel Corporation
// All rights reserved. * All rights reserved.
// *
// Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
// *
// * Redistributions of source code must retain the above copyright notice, * - Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice, * - Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
// * Neither name of Intel Corporation nor the names of its contributors * - Neither name of Intel Corporation nor the names of its contributors
// may be used to endorse or promote products derived from this software * may be used to endorse or promote products derived from this software
// without specific prior written permission. * without specific prior written permission.
// *
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// *
/////////////////////////////////////////////////////////////////////////// ******************************************************************************/
#ifndef GENA_H
#define GENA_H
/*!
* \file
*/
#ifndef _GENA_
#define _GENA_
#include "config.h" #include "config.h"
#include "service_table.h"
#include "miniserver.h"
#include "uri.h"
#include "upnp.h"
#include <time.h>
#include "ThreadPool.h"
#include <string.h> #include <string.h>
#include <time.h>
#include "client_table.h" #include "client_table.h"
#include "httpparser.h" #include "httpparser.h"
#include "miniserver.h"
#include "service_table.h"
#include "sock.h" #include "sock.h"
#include "ThreadPool.h"
#include "upnp.h"
#include "uri.h"
#ifdef __cplusplus #ifdef __cplusplus
#define EXTERN_C extern "C" #define EXTERN_C extern "C"
#else #else /* __cplusplus */
#ifndef EXTERN_C #ifndef EXTERN_C
#define EXTERN_C #define EXTERN_C
#endif #endif /* EXTERN_C */
#endif #endif /* __cplusplus */
/*!
* \brief XML version comment. Not used because it is not interopeable with
* other UPnP vendors.
*/
#define XML_VERSION "<?xml version='1.0' encoding='ISO-8859-1' ?>\n" #define XML_VERSION "<?xml version='1.0' encoding='ISO-8859-1' ?>\n"
#define XML_PROPERTYSET_HEADER \ #define XML_PROPERTYSET_HEADER \
"<e:propertyset xmlns:e=\"urn:schemas-upnp-org:event-1-0\">\n" "<e:propertyset xmlns:e=\"urn:schemas-upnp-org:event-1-0\">\n"
#define UNABLE_MEMORY "HTTP/1.1 500 Internal Server Error\r\n\r\n" #define UNABLE_MEMORY "HTTP/1.1 500 Internal Server Error\r\n\r\n"
#define UNABLE_SERVICE_UNKNOWN "HTTP/1.1 404 Not Found\r\n\r\n" #define UNABLE_SERVICE_UNKNOWN "HTTP/1.1 404 Not Found\r\n\r\n"
#define UNABLE_SERVICE_NOT_ACCEPT \ #define UNABLE_SERVICE_NOT_ACCEPT "HTTP/1.1 503 Service Not Available\r\n\r\n"
"HTTP/1.1 503 Service Not Available\r\n\r\n"
#define NOT_IMPLEMENTED "HTTP/1.1 501 Not Implemented\r\n\r\n" #define NOT_IMPLEMENTED "HTTP/1.1 501 Not Implemented\r\n\r\n"
@@ -74,6 +91,8 @@
#define MAX_SECONDS 10 #define MAX_SECONDS 10
#define MAX_EVENTS 20 #define MAX_EVENTS 20
#define MAX_PORT_SIZE 10 #define MAX_PORT_SIZE 10
#define GENA_E_BAD_RESPONSE UPNP_E_BAD_RESPONSE #define GENA_E_BAD_RESPONSE UPNP_E_BAD_RESPONSE
#define GENA_E_BAD_SERVICE UPNP_E_INVALID_SERVICE #define GENA_E_BAD_SERVICE UPNP_E_INVALID_SERVICE
#define GENA_E_SUBSCRIPTION_UNACCEPTED UPNP_E_SUBSCRIBE_UNACCEPTED #define GENA_E_SUBSCRIPTION_UNACCEPTED UPNP_E_SUBSCRIBE_UNACCEPTED
@@ -82,16 +101,23 @@
#define GENA_E_NOTIFY_UNACCEPTED UPNP_E_NOTIFY_UNACCEPTED #define GENA_E_NOTIFY_UNACCEPTED UPNP_E_NOTIFY_UNACCEPTED
#define GENA_E_NOTIFY_UNACCEPTED_REMOVE_SUB -9 #define GENA_E_NOTIFY_UNACCEPTED_REMOVE_SUB -9
#define GENA_E_BAD_HANDLE UPNP_E_INVALID_HANDLE #define GENA_E_BAD_HANDLE UPNP_E_INVALID_HANDLE
#define XML_ERROR -5 #define XML_ERROR -5
#define XML_SUCCESS UPNP_E_SUCCESS #define XML_SUCCESS UPNP_E_SUCCESS
#define GENA_SUCCESS UPNP_E_SUCCESS #define GENA_SUCCESS UPNP_E_SUCCESS
#define CALLBACK_SUCCESS 0 #define CALLBACK_SUCCESS 0
#define DEFAULT_TIMEOUT 1801 #define DEFAULT_TIMEOUT 1801
extern ithread_mutex_t GlobalClientSubscribeMutex; extern ithread_mutex_t GlobalClientSubscribeMutex;
// Lock the subscription
/*!
* \brief Locks the subscription.
*/
#define SubscribeLock() \ #define SubscribeLock() \
UpnpPrintf(UPNP_INFO, GENA, __FILE__, __LINE__, \ UpnpPrintf(UPNP_INFO, GENA, __FILE__, __LINE__, \
"Trying Subscribe Lock"); \ "Trying Subscribe Lock"); \
@@ -99,7 +125,10 @@ extern ithread_mutex_t GlobalClientSubscribeMutex;
UpnpPrintf(UPNP_INFO, GENA, __FILE__, __LINE__, \ UpnpPrintf(UPNP_INFO, GENA, __FILE__, __LINE__, \
"Subscribe Lock"); "Subscribe Lock");
// Unlock the subscription
/*!
* \brief Unlocks the subscription.
*/
#define SubscribeUnlock() \ #define SubscribeUnlock() \
UpnpPrintf(UPNP_INFO, GENA, __FILE__, __LINE__, \ UpnpPrintf(UPNP_INFO, GENA, __FILE__, __LINE__, \
"Trying Subscribe UnLock"); \ "Trying Subscribe UnLock"); \
@@ -108,295 +137,248 @@ extern ithread_mutex_t GlobalClientSubscribeMutex;
"Subscribe UnLock"); "Subscribe UnLock");
// Structure to send NOTIFY message to all subscribed control points /*!
* Structure to send NOTIFY message to all subscribed control points
*/
typedef struct NOTIFY_THREAD_STRUCT { typedef struct NOTIFY_THREAD_STRUCT {
char * headers; char *headers;
DOMString propertySet; DOMString propertySet;
char * servId; char *servId;
char * UDN; char *UDN;
Upnp_SID sid; Upnp_SID sid;
int eventKey; int eventKey;
int *reference_count; int *reference_count;
UpnpDevice_Handle device_handle; UpnpDevice_Handle device_handle;
} notify_thread_struct; } notify_thread_struct;
/************************************************************************ /*!
* Function : genaCallback * \brief This is the callback function called by the miniserver to handle
* * incoming GENA requests.
* Parameters: *
* IN http_parser_t *parser: represents the parse state of the request * \return UPNP_E_SUCCESS if successful, otherwise appropriate error code.
* IN http_message_t* request: HTTP message containing GENA request */
* INOUT SOCKINFO *info: Structure containing information about the socket EXTERN_C void genaCallback(
* /*! [in] represents the parse state of the request */
* Description: http_parser_t *parser,
* This is the callback function called by the miniserver to handle /*! [in] HTTP message containing GENA request */
* incoming GENA requests. http_message_t* request,
* /*! [in,out] Structure containing information about the socket */
* Returns: int SOCKINFO *info);
* UPNP_E_SUCCESS if successful else appropriate error
***************************************************************************/
EXTERN_C void genaCallback (IN http_parser_t *parser,
IN http_message_t* request,
IN SOCKINFO *info);
/************************************************************************
* Function : genaSubscribe /*!
* * \brief This function subscribes to a PublisherURL (also mentioned as EventURL
* Parameters: * in some places).
* IN UpnpClient_Handle client_handle: *
* IN char * PublisherURL: NULL Terminated, of the form : * It sends SUBSCRIBE http request to service processes request. Finally adds a
* "http://134.134.156.80:4000/RedBulb/Event" * Subscription to the clients subscription list, if service responds with OK.
* INOUT int * TimeOut: requested Duration, if -1, then "infinite". *
* in the OUT case: actual Duration granted * \return UPNP_E_SUCCESS if service response is OK, otherwise returns the
* by Service, -1 for infinite * appropriate error code
* OUT Upnp_SID out_sid:sid of subscription, memory passed in by caller */
*
* Description:
* This function subscribes to a PublisherURL ( also mentioned as EventURL
* 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: int
* return UPNP_E_SUCCESS if service response is OK else
* returns appropriate error
***************************************************************************/
#ifdef INCLUDE_CLIENT_APIS #ifdef INCLUDE_CLIENT_APIS
EXTERN_C int genaSubscribe( EXTERN_C int genaSubscribe(
/*! [in] The client handle. */
UpnpClient_Handle client_handle, UpnpClient_Handle client_handle,
char * PublisherURL, /*! [in] Of the form: "http://134.134.156.80:4000/RedBulb/Event */
int * TimeOut, const char *PublisherURL,
Upnp_SID out_sid ); /*! [in,out] requested Duration:
#endif * \li if -1, then "infinite".
* \li in the OUT case: actual Duration granted by Service,
* -1 for infinite. */
int *TimeOut,
/*! [out] sid of subscription, memory passed in by caller. */
Upnp_SID out_sid);
#endif /* INCLUDE_CLIENT_APIS */
/************************************************************************ /*!
* Function : genaUnSubscribe * \brief Unsubscribes a SID.
* *
* Parameters: * It first validates the SID and client_handle,copies the subscription, sends
* IN UpnpClient_Handle client_handle: UPnP client handle * UNSUBSCRIBE http request to service processes request and finally removes
* IN SID in_sid: The subscription ID * the subscription.
* *
* Description: * \return UPNP_E_SUCCESS if service response is OK, otherwise returns the
* This function unsubscribes a SID. It first validates the SID and * appropriate error code.
* client_handle,copies the subscription, sends UNSUBSCRIBE http request */
* to service processes request and finally removes the subscription
*
* Returns: int
* return UPNP_E_SUCCESS if service response is OK else
* returns appropriate error
***************************************************************************/
#ifdef INCLUDE_CLIENT_APIS #ifdef INCLUDE_CLIENT_APIS
EXTERN_C int genaUnSubscribe( EXTERN_C int genaUnSubscribe(
/*! [in] UPnP client handle. */
UpnpClient_Handle client_handle, UpnpClient_Handle client_handle,
/*! [in] The subscription ID. */
const Upnp_SID in_sid); const Upnp_SID in_sid);
#endif #endif /* INCLUDE_CLIENT_APIS */
/************************************************************************
* Function : genaUnregisterClient /*!
* * \brief Unsubcribes all the outstanding subscriptions and cleans the
* Parameters: * subscription list.
* IN UpnpClient_Handle client_handle: Handle containing all the control *
* point related information * This function is called when control point unregisters.
* *
* Description: * \returns UPNP_E_SUCCESS if successful, otherwise returns the appropriate
* This function unsubcribes all the outstanding subscriptions and cleans * error code.
* the subscription list. This function is called when control point */
* unregisters.
*
* Returns: int
* return UPNP_E_SUCCESS if successful else returns appropriate error
***************************************************************************/
#ifdef INCLUDE_CLIENT_APIS #ifdef INCLUDE_CLIENT_APIS
EXTERN_C int genaUnregisterClient(UpnpClient_Handle client_handle); EXTERN_C int genaUnregisterClient(
#endif /*! [in] Handle containing all the control point related information. */
UpnpClient_Handle client_handle);
#endif /* INCLUDE_CLIENT_APIS */
//server
/************************************************************************ /*
* Function : genaUnregisterDevice * DEVICE
* */
* Parameters:
* IN UpnpDevice_Handle device_handle: Handle of the root device
* /*!
* Description: * \brief Cleans the service table of the device.
* This function cleans the service table of the device. *
* * \return UPNP_E_SUCCESS if successful, otherwise returns GENA_E_BAD_HANDLE
* Returns: int */
* returns UPNP_E_SUCCESS if successful else returns GENA_E_BAD_HANDLE
****************************************************************************/
#ifdef INCLUDE_DEVICE_APIS #ifdef INCLUDE_DEVICE_APIS
EXTERN_C int genaUnregisterDevice(UpnpDevice_Handle device_handle); EXTERN_C int genaUnregisterDevice(
#endif /*! [in] Handle of the root device */
UpnpDevice_Handle device_handle);
#endif /* INCLUDE_CLIENT_APIS */
/************************************************************************ /*!
* Function : genaRenewSubscription * \brief Renews a SID.
* *
* Parameters: * It first validates the SID and client_handle and copies the subscription.
* IN UpnpClient_Handle client_handle: Client handle * It sends RENEW (modified SUBSCRIBE) http request to service and processes
* IN const Upnp_SID in_sid: subscription ID * the response.
* INOUT int * TimeOut: requested Duration, if -1, then "infinite". *
* in the OUT case: actual Duration granted * \return UPNP_E_SUCCESS if service response is OK, otherwise the
* by Service, -1 for infinite * appropriate error code.
* */
* Description:
* This function 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: int
* return UPNP_E_SUCCESS if service response is OK else
* returns appropriate error
***************************************************************************/
#ifdef INCLUDE_CLIENT_APIS #ifdef INCLUDE_CLIENT_APIS
EXTERN_C int genaRenewSubscription( EXTERN_C int genaRenewSubscription(
IN UpnpClient_Handle client_handle, /*! [in] Client handle. */
IN const Upnp_SID in_sid, UpnpClient_Handle client_handle,
OUT int * TimeOut); /*! [in] Subscription ID. */
#endif const Upnp_SID in_sid,
/**************************************************************************** /*! [in,out] requested Duration, if -1, then "infinite". In the OUT case:
* Function : genaNotifyAll * actual Duration granted by Service, -1 for infinite. */
* int *TimeOut);
* Parameters : #endif /* INCLUDE_CLIENT_APIS */
* IN UpnpDevice_Handle device_handle : Device handle
* IN char *UDN : Device udn
* IN char *servId : Service ID /*!
* IN char **VarNames : array of varible names * \brief Sends a notification to all the subscribed control points.
* IN char **VarValues : array of variable values *
* IN int var_count : number of variables * \return int
* *
* Description : This function sends a notification to all the subscribed * \note This function is similar to the genaNotifyAllExt. The only difference
* control points * is it takes event variable array instead of xml document.
* */
* Return : int
*
* Note : This function is similar to the genaNotifyAllExt. The only difference
* is it takes event variable array instead of xml document.
****************************************************************************/
#ifdef INCLUDE_DEVICE_APIS #ifdef INCLUDE_DEVICE_APIS
EXTERN_C int genaNotifyAll( EXTERN_C int genaNotifyAll(
/*! [in] Device handle. */
UpnpDevice_Handle device_handle, UpnpDevice_Handle device_handle,
/*! [in] Device udn. */
char *UDN, char *UDN,
/*! [in] Service ID. */
char *servId, char *servId,
/*! [in] Array of varible names. */
char **VarNames, char **VarNames,
/*! [in] Array of variable values. */
char **VarValues, char **VarValues,
/*! [in] Number of variables. */
int var_count); int var_count);
#endif #endif /* INCLUDE_DEVICE_APIS */
/****************************************************************************
* Function : genaNotifyAllExt /*!
* * \brief Sends a notification to all the subscribed control points.
* Parameters : *
* IN UpnpDevice_Handle device_handle : Device handle * \return int
* IN char *UDN : Device udn *
* IN char *servId : Service ID * \note This function is similar to the genaNotifyAll. the only difference
* IN IXML_Document *PropSet : XML document Event varible property set * is it takes the document instead of event variable array.
* */
* Description : This function sends a notification to all the subscribed
* control points
*
* Return : int
*
* Note : This function is similar to the genaNotifyAll. the only difference
* is it takes the document instead of event variable array
****************************************************************************/
#ifdef INCLUDE_DEVICE_APIS #ifdef INCLUDE_DEVICE_APIS
EXTERN_C int genaNotifyAllExt( EXTERN_C int genaNotifyAllExt(
/*! [in] Device handle. */
UpnpDevice_Handle device_handle, UpnpDevice_Handle device_handle,
/*! [in] Device udn. */
char *UDN, char *UDN,
/*! [in] Service ID. */
char *servId, char *servId,
IN IXML_Document *PropSet); /*! [in] XML document Event varible property set. */
#endif IXML_Document *PropSet);
#endif /* INCLUDE_DEVICE_APIS */
/****************************************************************************
* Function : genaInitNotify /*!
* * \brief Sends the intial state table dump to newly subscribed control point.
* Parameters : *
* IN UpnpDevice_Handle device_handle : Device handle * \return GENA_E_SUCCESS if successful, otherwise the appropriate error code.
* IN char *UDN : Device udn *
* IN char *servId : Service ID * \note No other event will be sent to this control point before the
* IN char **VarNames : Array of variable names * intial state table dump.
* 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.
****************************************************************************/
#ifdef INCLUDE_DEVICE_APIS #ifdef INCLUDE_DEVICE_APIS
EXTERN_C int genaInitNotify(IN UpnpDevice_Handle device_handle, EXTERN_C int genaInitNotify(
IN char *UDN, /*! [in] Device handle. */
IN char *servId, UpnpDevice_Handle device_handle,
IN char **VarNames, /*! [in] Device udn. */
IN char **VarValues, char *UDN,
IN int var_count, /*! [in] Service ID. */
IN Upnp_SID sid); char *servId,
#endif /*! [in] Array of variable names. */
char **VarNames,
/*! [in] Array of variable values. */
char **VarValues,
/*! [in] Array size. */
int var_count,
/*! [in] Subscription ID. */
const Upnp_SID sid);
#endif /* INCLUDE_DEVICE_APIS */
/****************************************************************************
* Function : genaInitNotifyExt /*!
* * \brief Similar to the genaInitNofity. The only difference is that it
* Parameters : * takes the xml document for the state table and sends the intial state
* IN UpnpDevice_Handle device_handle : Device handle * table dump to newly subscribed control point.
* IN char *UDN : Device udn *
* IN char *servId : Service ID * \return GENA_E_SUCCESS if successful, otherwise the appropriate error code.
* IN IXML_Document *PropSet : Document of the state table *
* IN Upnp_SID sid : subscription ID * \note No other event will be sent to this control point before the
* * intial state table dump.
* 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.
****************************************************************************/
#ifdef INCLUDE_DEVICE_APIS #ifdef INCLUDE_DEVICE_APIS
EXTERN_C int genaInitNotifyExt( EXTERN_C int genaInitNotifyExt(
IN UpnpDevice_Handle device_handle, /*! [in] Device handle. */
IN char *UDN, UpnpDevice_Handle device_handle,
IN char *servId, /*! [in] Device udn. */
IN IXML_Document *PropSet, char *UDN,
IN Upnp_SID sid); /*! [in] Service ID. */
#endif char *servId,
/*! [in] Document of the state table. */
IXML_Document *PropSet,
/************************************************************************ /*! [in] subscription ID. */
* Function : error_respond const Upnp_SID sid);
* #endif /* INCLUDE_DEVICE_APIS */
* Parameters:
* IN SOCKINFO *info: Structure containing information about the socket
* IN int error_code: error code that will be in the GENA response
* IN http_message_t* hmsg: GENA request Packet
*
* Description:
* This function send an error message to the control point in the case
* incorrect GENA requests.
*
* Returns: int
* UPNP_E_SUCCESS if successful else appropriate error
***************************************************************************/
void error_respond( IN SOCKINFO *info, IN int error_code,
IN http_message_t* hmsg );
#endif // GENA
/*!
* \brief Sends an error message to the control point in the case of incorrect
* GENA requests.
*
* \return UPNP_E_SUCCESS if successful, otherwise appropriate error code.
*/
void error_respond(
/*! [in] Structure containing information about the socket. */
SOCKINFO *info,
/*! [in] error code that will be in the GENA response. */
int error_code,
/*! [in] GENA request Packet. */
http_message_t* hmsg);
#endif /* GENA_H */

View File

@@ -1,139 +1,135 @@
/////////////////////////////////////////////////////////////////////////// /*******************************************************************************
// *
// Copyright (c) 2000-2003 Intel Corporation * Copyright (c) 2000-2003 Intel Corporation
// All rights reserved. * All rights reserved.
// *
// Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
// *
// * Redistributions of source code must retain the above copyright notice, * - Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice, * - Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
// * Neither name of Intel Corporation nor the names of its contributors * - Neither name of Intel Corporation nor the names of its contributors
// may be used to endorse or promote products derived from this software * may be used to endorse or promote products derived from this software
// without specific prior written permission. * without specific prior written permission.
// *
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// *
/////////////////////////////////////////////////////////////////////////// ******************************************************************************/
#ifndef SERVICE_TABLE_H
#define SERVICE_TABLE_H
/*!
* \file
*/
#ifndef _SERVICE_TABLE
#define _SERVICE_TABLE
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include "config.h" #include "config.h"
#include "uri.h" #include "uri.h"
#include "ixml.h" #include "ixml.h"
#include "upnp.h" #include "upnp.h"
#include <stdio.h> #include <stdio.h>
//#include <malloc.h>
#include <time.h> #include <time.h>
#define SID_SIZE 41 #define SID_SIZE 41
#ifdef INCLUDE_DEVICE_APIS #ifdef INCLUDE_DEVICE_APIS
typedef struct SUBSCRIPTION { typedef struct SUBSCRIPTION {
Upnp_SID sid; Upnp_SID sid;
int eventKey; int eventKey;
int ToSendEventKey; int ToSendEventKey;
time_t expireTime; time_t expireTime;
int active; int active;
URL_list DeliveryURLs; URL_list DeliveryURLs;
struct SUBSCRIPTION *next; struct SUBSCRIPTION *next;
} subscription; } subscription;
typedef struct SERVICE_INFO { typedef struct SERVICE_INFO {
DOMString serviceType; DOMString serviceType;
DOMString serviceId; DOMString serviceId;
char *SCPDURL ; char *SCPDURL ;
char *controlURL; char *controlURL;
char *eventURL; char *eventURL;
DOMString UDN; DOMString UDN;
int active; int active;
int TotalSubscriptions; int TotalSubscriptions;
subscription *subscriptionList; subscription *subscriptionList;
struct SERVICE_INFO *next; struct SERVICE_INFO *next;
} service_info; } service_info;
typedef struct SERVICE_TABLE { typedef struct SERVICE_TABLE {
DOMString URLBase; DOMString URLBase;
service_info *serviceList; service_info *serviceList;
service_info *endServiceList; service_info *endServiceList;
} service_table; } service_table;
/* Functions for Subscriptions */ /* Functions for Subscriptions */
/************************************************************************
* Function : copy_subscription
*
* Parameters :
* subscription *in ; Source subscription
* subscription *out ; Destination subscription
*
* Description : Makes a copy of the subscription
*
* Return : int ;
* HTTP_SUCCESS - On Sucess
*
* Note :
************************************************************************/
int copy_subscription(subscription *in, subscription *out);
/************************************************************************ /*!
* Function : RemoveSubscriptionSID * \brief Makes a copy of the subscription.
* *
* Parameters : * \return HTTP_SUCCESS on Sucess.
* Upnp_SID sid ; subscription ID */
* service_info * service ; service object providing the list of int copy_subscription(
* subscriptions /*! [in] Source subscription. */
* subscription *in,
* Description : Remove the subscription represented by the /*! [in] Destination subscription. */
* const Upnp_SID sid parameter from the service table and update subscription *out);
* the service table.
*
* Return : void ; /*
* * \brief Remove the subscription represented by the const Upnp_SID sid parameter
* Note : * from the service table and update the service table.
************************************************************************/ */
void RemoveSubscriptionSID(Upnp_SID sid, service_info * service); void RemoveSubscriptionSID(
/*! [in] Subscription ID. */
Upnp_SID sid,
/*! [in] Service object providing the list of subscriptions. */
service_info *service);
/*!
* \brief Return the subscription from the service table that matches
* const Upnp_SID sid value.
*
* \return Pointer to the matching subscription node.
*/
subscription *GetSubscriptionSID(
/*! [in] Subscription ID. */
const Upnp_SID sid,
/*! [in] Service object providing the list of subscriptions. */
service_info *service);
/************************************************************************
* 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);
//returns a pointer to the subscription with the SID, NULL if not found //returns a pointer to the subscription with the SID, NULL if not found