git-svn-id: https://pupnp.svn.sourceforge.net/svnroot/pupnp/trunk@401 119443c7-1b9e-41f8-b6fc-b9c35fce742c
This commit is contained in:
Marcelo Roberto Jimenez 2008-06-02 22:42:33 +00:00
parent ecb06fa24f
commit c1ac15fccc
12 changed files with 1761 additions and 2466 deletions

View File

@ -707,7 +707,8 @@ enum Upnp_DescType_e {
typedef enum Upnp_DescType_e Upnp_DescType; typedef enum Upnp_DescType_e Upnp_DescType;
/*! All callback functions share the same prototype, documented below. /*!
* All callback functions share the same prototype, documented below.
* Note that any memory passed to the callback function * Note that any memory passed to the callback function
* is valid only during the callback and should be copied if it * is valid only during the callback and should be copied if it
* needs to persist. This callback function needs to be thread * needs to persist. This callback function needs to be thread
@ -731,7 +732,13 @@ typedef enum Upnp_DescType_e Upnp_DescType;
* The return value of the callback is currently ignored. It may be used * The return value of the callback is currently ignored. It may be used
* in the future to communicate results back to the SDK. * in the future to communicate results back to the SDK.
*/ */
typedef int (*Upnp_FunPtr)(IN Upnp_EventType EventType, IN void *Event, IN void *Cookie); typedef int (*Upnp_FunPtr)(
/*! [in] .*/
Upnp_EventType EventType,
/*! [in] .*/
void *Event,
/*! [in] .*/
void *Cookie);
/* @} Constants and Types */ /* @} Constants and Types */
@ -1037,7 +1044,7 @@ EXPORT_SPEC int UpnpRegisterRootDevice2(
* the description is served using the internal web server. */ * the description is served using the internal web server. */
int config_baseURL, int config_baseURL,
/*! [in] Pointer to the callback function for receiving asynchronous events. */ /*! [in] Pointer to the callback function for receiving asynchronous events. */
IN Upnp_FunPtr Fun, Upnp_FunPtr Fun,
/*! [in] Pointer to user data returned with the callback function when /*! [in] Pointer to user data returned with the callback function when
* invoked. */ * invoked. */
const void* Cookie, const void* Cookie,
@ -1224,6 +1231,10 @@ EXPORT_SPEC int UpnpSetMaxContentLength(
* matching root device, device, or service. The application specifies the * matching root device, device, or service. The application specifies the
* search type by the \b Target parameter. * search type by the \b Target parameter.
* *
* This function searches for the devices for the provided maximum time.
* It is an asynchronous function. It schedules a search job and returns.
* The client is notified about the search results after search timer.
*
* Note that there is no way for the SDK to distinguish which client * Note that there is no way for the SDK to distinguish which client
* instance issued a particular search. Therefore, the client can get * instance issued a particular search. Therefore, the client can get
* search callbacks that do not match the original criteria of the search. * search callbacks that do not match the original criteria of the search.
@ -1237,17 +1248,17 @@ EXPORT_SPEC int UpnpSetMaxContentLength(
*/ */
EXPORT_SPEC int UpnpSearchAsync( EXPORT_SPEC int UpnpSearchAsync(
/*! The handle of the client performing the search. */ /*! The handle of the client performing the search. */
IN UpnpClient_Handle Hnd, UpnpClient_Handle Hnd,
/*! The time, in seconds, to wait for responses. If the time is greater /*! The time, in seconds, to wait for responses. If the time is greater
* than \c MAX_SEARCH_TIME then the time is set to \c MAX_SEARCH_TIME. * than \c MAX_SEARCH_TIME then the time is set to \c MAX_SEARCH_TIME.
* If the time is less than \c MIN_SEARCH_TIME then the time is set to * If the time is less than \c MIN_SEARCH_TIME then the time is set to
* \c MIN_SEARCH_TIME. */ * \c MIN_SEARCH_TIME. */
IN int Mx, int Mx,
/*! The search target as defined in the UPnP Device Architecture v1.0 /*! The search target as defined in the UPnP Device Architecture v1.0
* specification. */ * specification. */
IN const char *Target, const char *TTarget_constarget_const,
/*! The user data to pass when the callback function is invoked. */ /*! The user data to pass when the callback function is invoked. */
IN const void *Cookie); const void *Cookie_const);
/*! /*!
* \brief Sends out the discovery announcements for all devices and services * \brief Sends out the discovery announcements for all devices and services
@ -1266,9 +1277,9 @@ EXPORT_SPEC int UpnpSearchAsync(
*/ */
EXPORT_SPEC int UpnpSendAdvertisement( EXPORT_SPEC int UpnpSendAdvertisement(
/*! The device handle for which to send out the announcements. */ /*! The device handle for which to send out the announcements. */
IN UpnpDevice_Handle Hnd, UpnpDevice_Handle Hnd,
/*! The expiration age, in seconds, of the announcements. */ /*! The expiration age, in seconds, of the announcements. */
IN int Exp); int Exp);
/* @} Discovery */ /* @} Discovery */
@ -1316,16 +1327,16 @@ EXPORT_SPEC int UpnpSendAdvertisement(
* according to the device. * according to the device.
*/ */
EXPORT_SPEC int UpnpGetServiceVarStatus( EXPORT_SPEC int UpnpGetServiceVarStatus(
/*! The handle of the control point. */ /*! [in] The handle of the control point. */
IN UpnpClient_Handle Hnd, UpnpClient_Handle Hnd,
/*! The URL of the service. */ /*! [in] The URL of the service. */
IN const char *ActionURL, const char *ActionURL,
/*! The name of the variable to query. */ /*! [in] The name of the variable to query. */
IN const char *VarName, const char *VarName,
/*! The pointer to store the value for \b VarName. The SDK allocates /*! [out] The pointer to store the value for \b VarName. The SDK allocates
* this string and the caller needs to free it using * this string and the caller needs to free it using
* \b ixmlFreeDOMString. */ * \b ixmlFreeDOMString. */
OUT DOMString *StVarVal); DOMString *StVarVal);
/*! /*!
@ -1346,17 +1357,17 @@ EXPORT_SPEC int UpnpGetServiceVarStatus(
* complete this operation. * complete this operation.
*/ */
EXPORT_SPEC int UpnpGetServiceVarStatusAsync( EXPORT_SPEC int UpnpGetServiceVarStatusAsync(
/*! The handle of the control point. */ /*! [in] The handle of the control point. */
IN UpnpClient_Handle Hnd, UpnpClient_Handle Hnd,
/*! The URL of the service. */ /*! [in] The URL of the service. */
IN const char *ActionURL, const char *ActionURL,
/*! The name of the variable to query. */ /*! [in] The name of the variable to query. */
IN const char *VarName, const char *VarName,
/*! Pointer to a callback function to be invoked when the operation /*! [in] Pointer to a callback function to be invoked when the operation
* is complete. */ * is complete. */
IN Upnp_FunPtr Fun, Upnp_FunPtr Fun,
/*! Pointer to user data to pass to the callback function when invoked. */ /*! [in] Pointer to user data to pass to the callback function when invoked. */
IN const void *Cookie); const void *Cookie);
/*! /*!
@ -1383,19 +1394,19 @@ EXPORT_SPEC int UpnpGetServiceVarStatusAsync(
* complete this operation. * complete this operation.
*/ */
EXPORT_SPEC int UpnpSendAction( EXPORT_SPEC int UpnpSendAction(
/*! The handle of the control point sending the action. */ /*! [in] The handle of the control point sending the action. */
IN UpnpClient_Handle Hnd, UpnpClient_Handle Hnd,
/*! The action URL of the service. */ /*! [in] The action URL of the service. */
IN const char *ActionURL, const char *ActionURL,
/*! The type of the service. */ /*! [in] The type of the service. */
IN const char *ServiceType, const char *ServiceType,
/*! This parameter is ignored and must be \c NULL. */ /*! [in] This parameter is ignored and must be \c NULL. */
IN const char *DevUDN, const char *DevUDN,
/*! The DOM document for the action. */ /*! [in] The DOM document for the action. */
IN IXML_Document *Action, IXML_Document *Action,
/*! The DOM document for the response to the action. The SDK allocates /*! [out] The DOM document for the response to the action. The SDK allocates
* this document and the caller needs to free it. */ * this document and the caller needs to free it. */
OUT IXML_Document **RespNode); IXML_Document **RespNode);
/*! /*!
@ -1422,22 +1433,22 @@ EXPORT_SPEC int UpnpSendAction(
* complete this operation. * complete this operation.
*/ */
EXPORT_SPEC int UpnpSendActionEx( EXPORT_SPEC int UpnpSendActionEx(
/*! The handle of the control point sending the action. */ /*! [in] The handle of the control point sending the action. */
IN UpnpClient_Handle Hnd, UpnpClient_Handle Hnd,
/*! The action URL of the service. */ /*! [in] The action URL of the service. */
IN const char *ActionURL, const char *ActionURL,
/*! The type of the service. */ /*! [in] The type of the service. */
IN const char *ServiceType, const char *ServiceType,
/*! This parameter is ignored and must be \c NULL. */ /*! [in] This parameter is ignored and must be \c NULL. */
IN const char *DevUDN, const char *DevUDN,
/*! The DOM document for the SOAP header. This may be \c NULL if the /*! [in] The DOM document for the SOAP header. This may be \c NULL if the
* header is not required. */ * header is not required. */
IN IXML_Document *Header, IXML_Document *Header,
/*! The DOM document for the action. */ /*! [in] The DOM document for the action. */
IN IXML_Document *Action, IXML_Document *Action,
/*! The DOM document for the response to the action. The SDK allocates /*! [out] The DOM document for the response to the action. The SDK allocates
* this document and the caller needs to free it. */ * this document and the caller needs to free it. */
OUT IXML_Document **RespNode); IXML_Document **RespNode);
/*! /*!
@ -1462,22 +1473,22 @@ EXPORT_SPEC int UpnpSendActionEx(
* complete this operation. * complete this operation.
*/ */
EXPORT_SPEC int UpnpSendActionAsync( EXPORT_SPEC int UpnpSendActionAsync(
/*! The handle of the control point sending the action. */ /*! [in] The handle of the control point sending the action. */
IN UpnpClient_Handle Hnd, UpnpClient_Handle Hnd,
/*! The action URL of the service. */ /*! [in] The action URL of the service. */
IN const char *ActionURL, const char *ActionURL,
/*! The type of the service. */ /*! [in] The type of the service. */
IN const char *ServiceType, const char *ServiceType,
/*! This parameter is ignored and must be \c NULL. */ /*! [in] This parameter is ignored and must be \c NULL. */
IN const char *DevUDN, const char *DevUDN,
/*! The DOM document for the action to perform on this device. */ /*! [in] The DOM document for the action to perform on this device. */
IN IXML_Document *Action, IXML_Document *Action,
/*! Pointer to a callback function to be invoked when the operation /*! [in] Pointer to a callback function to be invoked when the operation
* completes. */ * completes. */
IN Upnp_FunPtr Fun, Upnp_FunPtr Fun,
/*! Pointer to user data that to be passed to the callback when /*! [in] Pointer to user data that to be passed to the callback when
* invoked. */ * invoked. */
IN const void *Cookie); const void *Cookie);
/*! /*!
@ -1502,28 +1513,30 @@ EXPORT_SPEC int UpnpSendActionAsync(
* complete this operation. * complete this operation.
*/ */
EXPORT_SPEC int UpnpSendActionExAsync( EXPORT_SPEC int UpnpSendActionExAsync(
/*! The handle of the control point sending the action. */ /*! [in] The handle of the control point sending the action. */
IN UpnpClient_Handle Hnd, UpnpClient_Handle Hnd,
/*! The action URL of the service. */ /*! [in] The action URL of the service. */
IN const char *ActionURL, const char *ActionURL,
/*! The type of the service. */ /*! [in] The type of the service. */
IN const char *ServiceType, const char *ServiceType,
/*! This parameter is ignored and must be \c NULL. */ /*! [in] This parameter is ignored and must be \c NULL. */
IN const char *DevUDN, const char *DevUDN,
/*! The DOM document for the SOAP header. This may be \c NULL if the /*! [in] The DOM document for the SOAP header. This may be \c NULL if the
* header is not required. */ * header is not required. */
IN IXML_Document *Header, IXML_Document *Header,
/*! The DOM document for the action to perform on this device. */ /*! [in] The DOM document for the action to perform on this device. */
IN IXML_Document *Action, IXML_Document *Action,
/*! Pointer to a callback function to be invoked when the operation /*! [in] Pointer to a callback function to be invoked when the operation
* completes. */ * completes. */
IN Upnp_FunPtr Fun, Upnp_FunPtr Fun,
/*! Pointer to user data that to be passed to the callback when /*! [in] Pointer to user data that to be passed to the callback when
* invoked. */ * invoked. */
IN const void *Cookie); const void *Cookie);
/*! @} Control */ /*! @} Control */
/****************************************************************************** /******************************************************************************
****************************************************************************** ******************************************************************************
* * * *
@ -1564,20 +1577,20 @@ EXPORT_SPEC int UpnpSendActionExAsync(
* complete this operation. * complete this operation.
*/ */
EXPORT_SPEC int UpnpAcceptSubscription( EXPORT_SPEC int UpnpAcceptSubscription(
/*! The handle of the device. */ /*! [in] The handle of the device. */
IN UpnpDevice_Handle Hnd, UpnpDevice_Handle Hnd,
/*! The device ID of the subdevice of the service generating the event. */ /*! [in] The device ID of the subdevice of the service generating the event. */
IN const char *DevID, const char *DevID,
/*! The unique service identifier of the service generating the event. */ /*! [in] The unique service identifier of the service generating the event. */
IN const char *ServID, const char *ServID,
/*! Pointer to an array of event variables. */ /*! [in] Pointer to an array of event variables. */
IN const char **VarName, const char **VarName,
/*! Pointer to an array of values for the event variables. */ /*! [in] Pointer to an array of values for the event variables. */
IN const char **NewVal, const char **NewVal,
/*! The number of event variables in \b VarName. */ /*! [in] The number of event variables in \b VarName. */
IN int cVariables, int cVariables,
/*! The subscription ID of the newly registered control point. */ /*! [in] The subscription ID of the newly registered control point. */
IN const Upnp_SID SubsId); const Upnp_SID SubsId);
/*! /*!
@ -1604,18 +1617,18 @@ EXPORT_SPEC int UpnpAcceptSubscription(
* complete this operation. * complete this operation.
*/ */
EXPORT_SPEC int UpnpAcceptSubscriptionExt( EXPORT_SPEC int UpnpAcceptSubscriptionExt(
/*! The handle of the device. */ /*! [in] The handle of the device. */
IN UpnpDevice_Handle Hnd, UpnpDevice_Handle Hnd,
/*! The device ID of the subdevice of the service generating the event. */ /*! [in] The device ID of the subdevice of the service generating the event. */
IN const char *DevID, const char *DevID,
/*! The unique service identifier of the service generating the event. */ /*! [in] The unique service identifier of the service generating the event. */
IN const char *ServID, const char *ServID,
/*! The DOM document for the property set. Property set documents must /*! [in] The DOM document for the property set. Property set documents must
* conform to the XML schema defined in section 4.3 of the Universal * conform to the XML schema defined in section 4.3 of the Universal
* Plug and Play Device Architecture specification. */ * Plug and Play Device Architecture specification. */
IN IXML_Document *PropSet, IXML_Document *PropSet,
/*! The subscription ID of the newly registered control point. */ /*! [in] The subscription ID of the newly registered control point. */
IN Upnp_SID SubsId); Upnp_SID SubsId);
/*! /*!
@ -1640,18 +1653,18 @@ EXPORT_SPEC int UpnpAcceptSubscriptionExt(
* complete this operation. * complete this operation.
*/ */
EXPORT_SPEC int UpnpNotify( EXPORT_SPEC int UpnpNotify(
/*! The handle to the device sending the event. */ /*! [in] The handle to the device sending the event. */
IN UpnpDevice_Handle, UpnpDevice_Handle,
/*! The device ID of the subdevice of the service generating the event. */ /*! [in] The device ID of the subdevice of the service generating the event. */
IN const char *DevID, const char *DevID,
/*! The unique identifier of the service generating the event. */ /*! [in] The unique identifier of the service generating the event. */
IN const char *ServID, const char *ServID,
/*! Pointer to an array of variables that have changed. */ /*! [in] Pointer to an array of variables that have changed. */
IN const char **VarName, const char **VarName,
/*! Pointer to an array of new values for those variables. */ /*! [in] Pointer to an array of new values for those variables. */
IN const char **NewVal, const char **NewVal,
/*! The count of variables included in this notification. */ /*! [in] The count of variables included in this notification. */
IN int cVariables); int cVariables);
/*! /*!
@ -1676,16 +1689,16 @@ EXPORT_SPEC int UpnpNotify(
* complete this operation. * complete this operation.
*/ */
EXPORT_SPEC int UpnpNotifyExt( EXPORT_SPEC int UpnpNotifyExt(
/*! The handle to the device sending the event. */ /*! [in] The handle to the device sending the event. */
IN UpnpDevice_Handle, UpnpDevice_Handle,
/*! The device ID of the subdevice of the service generating the event. */ /*! [in] The device ID of the subdevice of the service generating the event. */
IN const char *DevID, const char *DevID,
/*! The unique identifier of the service generating the event. */ /*! [in] The unique identifier of the service generating the event. */
IN const char *ServID, const char *ServID,
/*! The DOM document for the property set. Property set documents must /*! [in] The DOM document for the property set. Property set documents must
* conform to the XML schema defined in section 4.3 of the Universal * conform to the XML schema defined in section 4.3 of the Universal
* Plug and Play Device Architecture specification. */ * Plug and Play Device Architecture specification. */
IN IXML_Document *PropSet); IXML_Document *PropSet);
/*! /*!
@ -1717,13 +1730,13 @@ EXPORT_SPEC int UpnpNotifyExt(
* complete this operation. * complete this operation.
*/ */
EXPORT_SPEC int UpnpRenewSubscription( EXPORT_SPEC int UpnpRenewSubscription(
/*! The handle of the control point that is renewing the subscription. */ /*! [in] The handle of the control point that is renewing the subscription. */
IN UpnpClient_Handle Hnd, UpnpClient_Handle Hnd,
/*! Pointer to a variable containing the requested subscription time. /*! [in,out] Pointer to a variable containing the requested subscription time.
* Upon return, it contains the actual renewal time. */ * Upon return, it contains the actual renewal time. */
INOUT int *TimeOut, int *TimeOut,
/*! The ID for the subscription to renew. */ /*! [in] The ID for the subscription to renew. */
IN const Upnp_SID SubsId); const Upnp_SID SubsId);
/*! /*!
@ -1774,18 +1787,18 @@ EXPORT_SPEC int UpnpRenewSubscription(
* UpnpEventSubscribe.ErrCode field as part of the callback). * UpnpEventSubscribe.ErrCode field as part of the callback).
*/ */
EXPORT_SPEC int UpnpRenewSubscriptionAsync( EXPORT_SPEC int UpnpRenewSubscriptionAsync(
/*! The handle of the control point that is renewing the subscription. */ /*! [in] The handle of the control point that is renewing the subscription. */
IN UpnpClient_Handle Hnd, UpnpClient_Handle Hnd,
/*! The requested subscription time. The actual timeout value is /*! [in] The requested subscription time. The actual timeout value is
* returned when the callback function is called. */ * returned when the callback function is called. */
IN int TimeOut, int TimeOut,
/*! The ID for the subscription to renew. */ /*! [in] The ID for the subscription to renew. */
IN Upnp_SID SubsId, Upnp_SID SubsId,
/*! Pointer to a callback function to be invoked when the renewal is /*! [in] Pointer to a callback function to be invoked when the renewal is
* complete. */ * complete. */
IN Upnp_FunPtr Fun, Upnp_FunPtr Fun,
/*! Pointer to user data passed to the callback function when invoked. */ /*! [in] Pointer to user data passed to the callback function when invoked. */
IN const void *Cookie); const void *Cookie);
/*! /*!
@ -1804,9 +1817,9 @@ EXPORT_SPEC int UpnpRenewSubscriptionAsync(
EXPORT_SPEC int UpnpSetMaxSubscriptions( EXPORT_SPEC int UpnpSetMaxSubscriptions(
/*! The handle of the device for which the maximum number of /*! The handle of the device for which the maximum number of
* subscriptions is being set. */ * subscriptions is being set. */
IN UpnpDevice_Handle Hnd, UpnpDevice_Handle Hnd,
/*! The maximum number of subscriptions to be allowed per service. */ /*! The maximum number of subscriptions to be allowed per service. */
IN int MaxSubscriptions); int MaxSubscriptions);
/*! /*!
@ -1826,9 +1839,9 @@ EXPORT_SPEC int UpnpSetMaxSubscriptions(
EXPORT_SPEC int UpnpSetMaxSubscriptionTimeOut( EXPORT_SPEC int UpnpSetMaxSubscriptionTimeOut(
/*! The handle of the device for which the maximum subscription /*! The handle of the device for which the maximum subscription
* time-out is being set. */ * time-out is being set. */
IN UpnpDevice_Handle Hnd, UpnpDevice_Handle Hnd,
/*! The maximum subscription time-out to be accepted. */ /*! The maximum subscription time-out to be accepted. */
IN int MaxSubscriptionTimeOut); int MaxSubscriptionTimeOut);
/*! /*!
@ -1861,16 +1874,16 @@ EXPORT_SPEC int UpnpSetMaxSubscriptionTimeOut(
* complete this operation. * complete this operation.
*/ */
EXPORT_SPEC int UpnpSubscribe( EXPORT_SPEC int UpnpSubscribe(
/*! The handle of the control point. */ /*! [in] The handle of the control point. */
IN UpnpClient_Handle Hnd, UpnpClient_Handle Hnd,
/*! The URL of the service to subscribe to. */ /*! [in] The URL of the service to subscribe to. */
IN const char *PublisherUrl, const char *PublisherUrl,
/*! Pointer to a variable containing the requested subscription time. /*! [in,out]Pointer to a variable containing the requested subscription time.
* Upon return, it contains the actual subscription time returned from * Upon return, it contains the actual subscription time returned from
* the service. */ * the service. */
INOUT int *TimeOut, int *TimeOut,
/*! Pointer to a variable to receive the subscription ID (SID). */ /*! [out] Pointer to a variable to receive the subscription ID (SID). */
OUT Upnp_SID SubsId); Upnp_SID SubsId);
/*! /*!
@ -1923,16 +1936,16 @@ EXPORT_SPEC int UpnpSubscribe(
*/ */
EXPORT_SPEC int UpnpSubscribeAsync( EXPORT_SPEC int UpnpSubscribeAsync(
/*! The handle of the control point that is subscribing. */ /*! The handle of the control point that is subscribing. */
IN UpnpClient_Handle Hnd, UpnpClient_Handle Hnd,
/*! The URL of the service to subscribe to. */ /*! The URL of the service to subscribe to. */
IN const char *PublisherUrl, const char *PublisherUrl,
/*! The requested subscription time. Upon return, it contains the actual /*! The requested subscription time. Upon return, it contains the actual
* subscription time returned from the service. */ * subscription time returned from the service. */
IN int TimeOut, int TimeOut,
/*! Pointer to the callback function for this subscribe request. */ /*! Pointer to the callback function for this subscribe request. */
IN Upnp_FunPtr Fun, Upnp_FunPtr Fun,
/*! A user data value passed to the callback function when invoked. */ /*! A user data value passed to the callback function when invoked. */
IN const void *Cookie); const void *Cookie);
/*! /*!
@ -1965,10 +1978,10 @@ EXPORT_SPEC int UpnpSubscribeAsync(
* complete this operation. * complete this operation.
*/ */
EXPORT_SPEC int UpnpUnSubscribe( EXPORT_SPEC int UpnpUnSubscribe(
/*! The handle of the subscribed control point. */ /*! [in] The handle of the subscribed control point. */
IN UpnpClient_Handle Hnd, UpnpClient_Handle Hnd,
/*! The ID returned when the control point subscribed to the service. */ /*! [in] The ID returned when the control point subscribed to the service. */
IN const Upnp_SID SubsId); const Upnp_SID SubsId);
/*! /*!
@ -2018,15 +2031,15 @@ EXPORT_SPEC int UpnpUnSubscribe(
* <b>UpnpEventSubscribe.ErrCode</b> field as part of the callback). * <b>UpnpEventSubscribe.ErrCode</b> field as part of the callback).
*/ */
EXPORT_SPEC int UpnpUnSubscribeAsync( EXPORT_SPEC int UpnpUnSubscribeAsync(
/*! The handle of the subscribed control point. */ /*! [in] The handle of the subscribed control point. */
IN UpnpClient_Handle Hnd, UpnpClient_Handle Hnd,
/*! The ID returned when the control point subscribed to the service. */ /*! [in] The ID returned when the control point subscribed to the service. */
IN Upnp_SID SubsId, Upnp_SID SubsId,
/*! Pointer to a callback function to be called when the operation is /*! [in] Pointer to a callback function to be called when the operation is
* complete. */ * complete. */
IN Upnp_FunPtr Fun, Upnp_FunPtr Fun,
/*! Pointer to user data to pass to the callback function when invoked. */ /*! [in] Pointer to user data to pass to the callback function when invoked. */
IN const void *Cookie); const void *Cookie);
/*! @} Eventing */ /*! @} Eventing */
@ -2470,10 +2483,10 @@ typedef void *UpnpWebFileHandle;
* \brief Get-info callback function prototype. * \brief Get-info callback function prototype.
*/ */
typedef int (*VDCallback_GetInfo)( typedef int (*VDCallback_GetInfo)(
/*! The name of the file to query. */ /*! [in] The name of the file to query. */
IN const char *filename, const char *filename,
/*! Pointer to a structure to store the information on the file. */ /*! [out] Pointer to a structure to store the information on the file. */
OUT UpnpFileInfo *info); UpnpFileInfo *info);
/*! /*!
* \brief Sets the get_info callback function to be used to access a virtual * \brief Sets the get_info callback function to be used to access a virtual
@ -2490,11 +2503,11 @@ EXPORT_SPEC int UpnpVirtualDir_set_GetInfoCallback(VDCallback_GetInfo callback);
* \brief Open callback function prototype. * \brief Open callback function prototype.
*/ */
typedef UpnpWebFileHandle (*VDCallback_Open)( typedef UpnpWebFileHandle (*VDCallback_Open)(
/*! The name of the file to open. */ /*! [in] The name of the file to open. */
IN const char *filename, const char *filename,
/*! The mode in which to open the file. /*! [in] The mode in which to open the file.
* Valid values are \c UPNP_READ or \c UPNP_WRITE. */ * Valid values are \c UPNP_READ or \c UPNP_WRITE. */
IN enum UpnpOpenFileMode Mode); enum UpnpOpenFileMode Mode);
/*! /*!
@ -2512,12 +2525,12 @@ EXPORT_SPEC int UpnpVirtualDir_set_OpenCallback(VDCallback_Open callback);
* \brief Read callback function prototype. * \brief Read callback function prototype.
*/ */
typedef int (*VDCallback_Read)( typedef int (*VDCallback_Read)(
/*! The handle of the file to read. */ /*! [in] The handle of the file to read. */
IN UpnpWebFileHandle fileHnd, UpnpWebFileHandle fileHnd,
/*! The buffer in which to place the data. */ /*! [out] The buffer in which to place the data. */
OUT char *buf, char *buf,
/*! The size of the buffer (i.e. the number of bytes to read). */ /*! [in] The size of the buffer (i.e. the number of bytes to read). */
IN size_t buflen); size_t buflen);
/*! /*!
@ -2535,12 +2548,12 @@ EXPORT_SPEC int UpnpVirtualDir_set_ReadCallback(VDCallback_Read callback);
* \brief Write callback function prototype. * \brief Write callback function prototype.
*/ */
typedef int (*VDCallback_Write)( typedef int (*VDCallback_Write)(
/*! The handle of the file to write. */ /*! [in] The handle of the file to write. */
IN UpnpWebFileHandle fileHnd, UpnpWebFileHandle fileHnd,
/*! The buffer with the bytes to write. */ /*! [in] The buffer with the bytes to write. */
IN char *buf, char *buf,
/*! The number of bytes to write. */ /*! [in] The number of bytes to write. */
IN size_t buflen); size_t buflen);
/*! /*!
@ -2558,17 +2571,17 @@ EXPORT_SPEC int UpnpVirtualDir_set_WriteCallback(VDCallback_Write callback);
* \brief Seek callback function prototype. * \brief Seek callback function prototype.
*/ */
typedef int (*VDCallback_Seek) ( typedef int (*VDCallback_Seek) (
/*! The handle of the file to move the file pointer. */ /*! [in] The handle of the file to move the file pointer. */
IN UpnpWebFileHandle fileHnd, UpnpWebFileHandle fileHnd,
/*! The number of bytes to move in the file. Positive values /*! [in] The number of bytes to move in the file. Positive values
* move foward and negative values move backward. Note that * move foward and negative values move backward. Note that
* this must be positive if the \b origin is \c SEEK_SET. */ * this must be positive if the \b origin is \c SEEK_SET. */
IN off_t offset, off_t offset,
/*! The position to move relative to. It can be \c SEEK_CUR /*! [in] The position to move relative to. It can be \c SEEK_CUR
* to move relative to the current position, \c SEEK_END to * to move relative to the current position, \c SEEK_END to
* move relative to the end of the file, or \c SEEK_SET to * move relative to the end of the file, or \c SEEK_SET to
* specify an absolute offset. */ * specify an absolute offset. */
IN int origin); int origin);
/*! /*!
@ -2586,8 +2599,8 @@ EXPORT_SPEC int UpnpVirtualDir_set_SeekCallback(VDCallback_Seek callback);
* \brief Close callback function prototype. * \brief Close callback function prototype.
*/ */
typedef int (*VDCallback_Close)( typedef int (*VDCallback_Close)(
/*! The handle of the file to close. */ /*! [in] The handle of the file to close. */
IN UpnpWebFileHandle fileHnd); UpnpWebFileHandle fileHnd);
/*! /*!

View File

@ -101,50 +101,36 @@ typedef enum Upnp_LogLevel_e {
/*************************************************************************** /*!
* Function : UpnpInitLog * \brief Initialize the log files.
* *
* Parameters: void * \return -1 if fails or UPNP_E_SUCCESS if succeeds.
* */
* Description:
* This functions initializes the log files
*
* Returns: int
* -1 : If fails
* UPNP_E_SUCCESS : if success
***************************************************************************/
#ifdef DEBUG #ifdef DEBUG
int UpnpInitLog(); int UpnpInitLog();
#else #else
static UPNP_INLINE int UpnpInitLog() { return UPNP_E_SUCCESS; } static UPNP_INLINE int UpnpInitLog()
{
return UPNP_E_SUCCESS;
}
#endif #endif
/*************************************************************************** /*!
* Function : UpnpSetLogLevel * \brief Set the log level (see \c Upnp_LogLevel).
* */
* Parameters: Upnp_LogLevel log_level
*
* Description:
* This functions set the log level (see \c Upnp_LogLevel)
* Returns: void
***************************************************************************/
#ifdef DEBUG #ifdef DEBUG
void UpnpSetLogLevel(Upnp_LogLevel log_level); void UpnpSetLogLevel(
/*! [in] Log level. */
Upnp_LogLevel log_level);
#else #else
static UPNP_INLINE void UpnpSetLogLevel(Upnp_LogLevel log_level) {} static UPNP_INLINE void UpnpSetLogLevel(Upnp_LogLevel log_level) {}
#endif #endif
/*************************************************************************** /*!
* Function : UpnpCloseLog * \brief Closes the log files.
* */
* Parameters: void
*
* Description:
* This functions closes the log files
* Returns: void
***************************************************************************/
#ifdef DEBUG #ifdef DEBUG
void UpnpCloseLog(); void UpnpCloseLog();
#else #else
@ -152,23 +138,14 @@ static UPNP_INLINE void UpnpCloseLog() {}
#endif #endif
/*************************************************************************** /*!
* Function : UpnpSetLogFileNames * \brief Set the name for error and information files, respectively.
* */
* Parameters:
* IN const char* ErrFileName: name of the error file
* IN const char *InfoFileName: name of the information file
* IN int size: Size of the buffer
* IN int starLength: This parameter provides the width of the banner
*
* Description:
* This functions takes the buffer and writes the buffer in the file as
* per the requested banner
* Returns: void
***************************************************************************/
#ifdef DEBUG #ifdef DEBUG
void UpnpSetLogFileNames( void UpnpSetLogFileNames(
/*! [in] Name of the error file. */
const char *ErrFileName, const char *ErrFileName,
/*! [in] Name of the information file. */
const char *InfoFileName); const char *InfoFileName);
#else #else
static UPNP_INLINE void UpnpSetLogFileNames( static UPNP_INLINE void UpnpSetLogFileNames(
@ -177,24 +154,20 @@ static UPNP_INLINE void UpnpSetLogFileNames(
#endif #endif
/*************************************************************************** /*!
* Function : UpnpGetDebugFile * \brief Check if the module is turned on for debug and returns the file
* descriptor corresponding to the debug level
* *
* Parameters: * \return NULL if the module is turn off for debug otheriwse returns the
* IN Upnp_LogLevel DLevel: The level of the debug logging. It will decide * right file descriptor.
* whether debug statement will go to standard output, */
* or any of the log files.
* IN Dbg_Module Module: debug will go in the name of this module
*
* Description:
* This function checks if the module is turned on for debug
* and returns the file descriptor corresponding to the debug level
* Returns: FILE *
* NULL : if the module is turn off for debug
* else returns the right file descriptor
***************************************************************************/
#ifdef DEBUG #ifdef DEBUG
FILE *UpnpGetDebugFile(Upnp_LogLevel level, Dbg_Module module); FILE *UpnpGetDebugFile(
/*! [in] The level of the debug logging. It will decide whether debug
* statement will go to standard output, or any of the log files. */
Upnp_LogLevel level,
/*! [in] debug will go in the name of this module. */
Dbg_Module module);
#else #else
static UPNP_INLINE FILE *UpnpGetDebugFile(Upnp_LogLevel level, Dbg_Module module) static UPNP_INLINE FILE *UpnpGetDebugFile(Upnp_LogLevel level, Dbg_Module module)
{ {
@ -203,36 +176,32 @@ static UPNP_INLINE FILE *UpnpGetDebugFile(Upnp_LogLevel level, Dbg_Module module
#endif #endif
/*************************************************************************** /*!
* Function : DebugAtThisLevel * \brief Returns true if debug output should be done in this module.
* *
* Parameters: * \return Nonzero value if true, zero if false.
* IN Upnp_LogLevel DLevel: The level of the debug logging. It will decide */
* whether debug statement will go to standard output,
* or any of the log files.
* IN Dbg_Module Module: debug will go in the name of this module
*
* Description:
* This functions returns true if debug output should be done in this
* module.
*
* Returns: int
***************************************************************************/
#ifdef DEBUG #ifdef DEBUG
int DebugAtThisLevel( int DebugAtThisLevel(
IN Upnp_LogLevel DLevel, /*! [in] The level of the debug logging. It will decide whether debug
IN Dbg_Module Module); * statement will go to standard output, or any of the log files. */
Upnp_LogLevel DLevel,
/*! [in] Debug will go in the name of this module. */
Dbg_Module Module);
#else #else
static UPNP_INLINE int DebugAtThisLevel( static UPNP_INLINE int DebugAtThisLevel(
IN Upnp_LogLevel DLevel, Upnp_LogLevel DLevel,
IN Dbg_Module Module) { return 0; } Dbg_Module Module)
{
return 0;
}
#endif #endif
/*! /*!
* \brief Prints the debug statement either on the standard output or log file * \brief Prints the debug statement either on the standard output or log file
* along with the information from where this debug statement is coming. * along with the information from where this debug statement is coming.
**/ */
#ifdef DEBUG #ifdef DEBUG
void UpnpPrintf( void UpnpPrintf(
/*! [in] The level of the debug logging. It will decide whether debug /*! [in] The level of the debug logging. It will decide whether debug
@ -261,28 +230,23 @@ static UPNP_INLINE void UpnpPrintf(
const char* DbgFileName, const char* DbgFileName,
int DbgLineNo, int DbgLineNo,
const char* FmtStr, const char* FmtStr,
...) {} ...)
{
}
#endif /* DEBUG */ #endif /* DEBUG */
/*************************************************************************** /*!
* Function : UpnpDisplayFileAndLine * \brief Writes the file name and file number from where debug statement is
* * coming to the log file.
* Parameters: */
* IN FILE *fd: File descriptor where line number and file name will be
* written
* IN char *DbgFileName: Name of the file
* IN int DbgLineNo : Line number of the file
*
* Description:
* This function writes the file name and file number from where
* debug statement is coming to the log file
* Returns: void
***************************************************************************/
#ifdef DEBUG #ifdef DEBUG
void UpnpDisplayFileAndLine( void UpnpDisplayFileAndLine(
/*! [in] File descriptor where line number and file name will be written. */
FILE *fd, FILE *fd,
/*! [in] Name of the file. */
const char *DbgFileName, const char *DbgFileName,
/*! [in] Line number of the file. */
int DbgLineNo); int DbgLineNo);
#else #else
static UPNP_INLINE void UpnpDisplayFileAndLine( static UPNP_INLINE void UpnpDisplayFileAndLine(
@ -292,18 +256,18 @@ static UPNP_INLINE void UpnpDisplayFileAndLine(
#endif #endif
/*! \brief Writes the buffer in the file as per the requested banner /*!
* * \brief Writes the buffer in the file as per the requested banner
* \param [in] fd file descriptor where the banner will be written
* \param [in] lines: The buffer that will be written
* \param [in] size: Size of the buffer
* \param [in] starlength: This parameter provides the width of the banner
*/ */
#ifdef DEBUG #ifdef DEBUG
void UpnpDisplayBanner( void UpnpDisplayBanner(
/*! [in] file descriptor where the banner will be written. */
FILE *fd, FILE *fd,
/*! [in] The buffer that will be written. */
const char **lines, const char **lines,
/*! [in] Size of the buffer. */
size_t size, size_t size,
/*! [in] This parameter provides the width of the banner. */
int starlength); int starlength);
#else #else
static UPNP_INLINE void UpnpDisplayBanner( static UPNP_INLINE void UpnpDisplayBanner(
@ -314,27 +278,27 @@ static UPNP_INLINE void UpnpDisplayBanner(
#endif #endif
/*! \brief Prints thread pool statistics. /*!
* * \brief Prints thread pool statistics.
* \param [in] tp The thread pool
* \param [in] DbgFileName the file name that called this function, use the
* macro __FILE__.
* \param [in] DbgLineNo the line number that the function was called, use
* the macro __LINE__.
* \param [in] msg message.
*/ */
#ifdef DEBUG #ifdef DEBUG
void PrintThreadPoolStats( void PrintThreadPoolStats(
/* [in] The thread pool. */
ThreadPool *tp, ThreadPool *tp,
/* [in] The file name that called this function, use the macro __FILE__. */
const char *DbgFileName, const char *DbgFileName,
/* [in] The line number that the function was called, use the macro __LINE__. */
int DbgLineNo, int DbgLineNo,
/* [in] The message. */
const char *msg); const char *msg);
#else #else
static UPNP_INLINE void PrintThreadPoolStats( static UPNP_INLINE void PrintThreadPoolStats(
ThreadPool *tp, ThreadPool *tp,
const char *DbgFileName, const char *DbgFileName,
int DbgLineNo, int DbgLineNo,
const char *msg) {} const char *msg)
{
}
#endif #endif

File diff suppressed because it is too large Load Diff

View File

@ -44,107 +44,48 @@
//Mutex to synchronize all the log file opeartions in the debug mode /*! Mutex to synchronize all the log file opeartions in the debug mode */
static ithread_mutex_t GlobalDebugMutex; static ithread_mutex_t GlobalDebugMutex;
// Global log level /*! Global log level */
static Upnp_LogLevel g_log_level = UPNP_DEFAULT_LOG_LEVEL; static Upnp_LogLevel g_log_level = UPNP_DEFAULT_LOG_LEVEL;
//File handle for the error log file /*! File handle for the error log file */
static FILE *ErrFileHnd = NULL; static FILE *ErrFileHnd = NULL;
//File handle for the information log file /*! File handle for the information log file */
static FILE *InfoFileHnd = NULL; static FILE *InfoFileHnd = NULL;
//Name of the error file /*! Name of the error file */
static const char *errFileName = "IUpnpErrFile.txt"; static const char *errFileName = "IUpnpErrFile.txt";
//Name of the info file /*! Name of the info file */
static const char *infoFileName = "IUpnpInfoFile.txt"; static const char *infoFileName = "IUpnpInfoFile.txt";
#ifdef DEBUG #ifdef DEBUG
/*************************************************************************** int UpnpInitLog()
* Function : UpnpSetLogFileNames
*
* Parameters:
* IN const char* ErrFileName: name of the error file
* IN const char *InfoFileName: name of the information file
* IN int size: Size of the buffer
* IN int starLength: This parameter provides the width of the banner
*
* Description:
* This functions takes the buffer and writes the buffer in the file as
* per the requested banner
* Returns: void
***************************************************************************/
void
UpnpSetLogFileNames ( IN const char *ErrFileName,
IN const char *InfoFileName )
{
if( ErrFileName ) {
errFileName = ErrFileName;
}
if( InfoFileName ) {
infoFileName = InfoFileName;
}
}
/***************************************************************************
* Function : UpnpInitLog
*
* Parameters: void
*
* Description:
* This functions initializes the log files
*
* Returns: int
* -1 : If fails
* UPNP_E_SUCCESS : if success
***************************************************************************/
int
UpnpInitLog()
{ {
ithread_mutex_init(&GlobalDebugMutex, NULL); ithread_mutex_init(&GlobalDebugMutex, NULL);
if(DEBUG_TARGET == 1) { if(DEBUG_TARGET == 1) {
if( ( ErrFileHnd = fopen( errFileName, "a" ) ) == NULL ) if((ErrFileHnd = fopen( errFileName, "a")) == NULL) {
return -1; return -1;
if( ( InfoFileHnd = fopen( infoFileName, "a" ) ) == NULL ) }
if((InfoFileHnd = fopen( infoFileName, "a")) == NULL) {
return -1; return -1;
} }
}
return UPNP_E_SUCCESS; return UPNP_E_SUCCESS;
} }
/*************************************************************************** void UpnpSetLogLevel(Upnp_LogLevel log_level)
* Function : UpnpSetLogLevel
*
* Parameters: Upnp_LogLevel log_level
*
* Description:
* This functions set the log level (see {\tt Upnp_LogLevel}
* Returns: void
***************************************************************************/
void
UpnpSetLogLevel (Upnp_LogLevel log_level)
{ {
g_log_level = log_level; g_log_level = log_level;
} }
/*************************************************************************** void UpnpCloseLog()
* Function : UpnpCloseLog
*
* Parameters: void
*
* Description:
* This functions closes the log files
* Returns: void
***************************************************************************/
void
UpnpCloseLog()
{ {
if (DEBUG_TARGET == 1) { if (DEBUG_TARGET == 1) {
fflush(ErrFileHnd); fflush(ErrFileHnd);
@ -153,29 +94,27 @@ UpnpCloseLog()
fclose(InfoFileHnd); fclose(InfoFileHnd);
} }
ithread_mutex_destroy(&GlobalDebugMutex); ithread_mutex_destroy(&GlobalDebugMutex);
} }
#endif // DEBUG
/***************************************************************************
* Function : DebugAtThisLevel void UpnpSetLogFileNames(
* const char *ErrFileName,
* Parameters: const char *InfoFileName)
* IN Upnp_LogLevel DLevel: The level of the debug logging. It will decide {
* whether debug statement will go to standard output, if (ErrFileName) {
* or any of the log files. errFileName = ErrFileName;
* IN Dbg_Module Module: debug will go in the name of this module }
* if (InfoFileName) {
* Description: infoFileName = InfoFileName;
* This functions returns true if debug output should be done in this }
* module. }
* #endif /* DEBUG */
* Returns: int
***************************************************************************/
#ifdef DEBUG #ifdef DEBUG
int DebugAtThisLevel( int DebugAtThisLevel(
IN Upnp_LogLevel DLevel, Upnp_LogLevel DLevel,
IN Dbg_Module Module) Dbg_Module Module)
{ {
int ret = DLevel <= g_log_level; int ret = DLevel <= g_log_level;
ret &= ret &=
@ -195,11 +134,11 @@ int DebugAtThisLevel(
#ifdef DEBUG #ifdef DEBUG
void UpnpPrintf( void UpnpPrintf(
IN Upnp_LogLevel DLevel, Upnp_LogLevel DLevel,
IN Dbg_Module Module, Dbg_Module Module,
IN const char *DbgFileName, const char *DbgFileName,
IN int DbgLineNo, int DbgLineNo,
IN const char *FmtStr, const char *FmtStr,
...) ...)
{ {
va_list ArgList; va_list ArgList;
@ -235,22 +174,6 @@ void UpnpPrintf(
#endif #endif
/***************************************************************************
* Function : UpnpGetDebugFile
*
* Parameters:
* IN Upnp_LogLevel DLevel: The level of the debug logging. It will decide
* whether debug statement will go to standard output,
* or any of the log files.
* IN Dbg_Module Module: debug will go in the name of this module
*
* Description:
* This function checks if the module is turned on for debug
* and returns the file descriptor corresponding to the debug level
* Returns: FILE *
* NULL : if the module is turn off for debug
* else returns the right file descriptor
***************************************************************************/
#ifdef DEBUG #ifdef DEBUG
FILE *GetDebugFile(Upnp_LogLevel DLevel, Dbg_Module Module) FILE *GetDebugFile(Upnp_LogLevel DLevel, Dbg_Module Module)
{ {
@ -273,25 +196,11 @@ FILE *GetDebugFile( Upnp_LogLevel DLevel, Dbg_Module Module )
#endif #endif
/***************************************************************************
* Function : UpnpDisplayFileAndLine
*
* Parameters:
* IN FILE *fd: File descriptor where line number and file name will be
* written
* IN char *DbgFileName: Name of the file
* IN int DbgLineNo : Line number of the file
*
* Description:
* This function writes the file name and file number from where
* debug statement is coming to the log file
* Returns: void
***************************************************************************/
#ifdef DEBUG #ifdef DEBUG
void UpnpDisplayFileAndLine( void UpnpDisplayFileAndLine(
IN FILE * fd, FILE *fd,
IN const char *DbgFileName, const char *DbgFileName,
IN int DbgLineNo) int DbgLineNo)
{ {
#define NLINES 2 #define NLINES 2
#define MAX_LINE_SIZE 512 #define MAX_LINE_SIZE 512
@ -329,10 +238,10 @@ void UpnpDisplayFileAndLine(
#ifdef DEBUG #ifdef DEBUG
void UpnpDisplayBanner( void UpnpDisplayBanner(
IN FILE * fd, FILE * fd,
IN const char **lines, const char **lines,
IN size_t size, size_t size,
IN int starLength) int starLength)
{ {
int leftMarginLength = starLength / 2 + 1; int leftMarginLength = starLength / 2 + 1;
int rightMarginLength = starLength / 2 + 1; int rightMarginLength = starLength / 2 + 1;

View File

@ -383,7 +383,7 @@ static int gena_subscribe(
} }
int genaUnregisterClient(IN UpnpClient_Handle client_handle) int genaUnregisterClient(UpnpClient_Handle client_handle)
{ {
ClientSubscription *sub_copy = UpnpClientSubscription_new(); ClientSubscription *sub_copy = UpnpClientSubscription_new();
int return_code = UPNP_E_SUCCESS; int return_code = UPNP_E_SUCCESS;
@ -430,8 +430,8 @@ exit_function:
#ifdef INCLUDE_CLIENT_APIS #ifdef INCLUDE_CLIENT_APIS
int genaUnSubscribe( int genaUnSubscribe(
IN UpnpClient_Handle client_handle, UpnpClient_Handle client_handle,
IN const UpnpString *in_sid) const UpnpString *in_sid)
{ {
ClientSubscription *sub = NULL; ClientSubscription *sub = NULL;
int return_code = GENA_SUCCESS; int return_code = GENA_SUCCESS;
@ -482,10 +482,10 @@ exit_function:
#ifdef INCLUDE_CLIENT_APIS #ifdef INCLUDE_CLIENT_APIS
int genaSubscribe( int genaSubscribe(
IN UpnpClient_Handle client_handle, UpnpClient_Handle client_handle,
IN const UpnpString *PublisherURL, const UpnpString *PublisherURL,
INOUT int *TimeOut, int *TimeOut,
OUT UpnpString *out_sid) UpnpString *out_sid)
{ {
int return_code = GENA_SUCCESS; int return_code = GENA_SUCCESS;
ClientSubscription *newSubscription = UpnpClientSubscription_new(); ClientSubscription *newSubscription = UpnpClientSubscription_new();
@ -564,9 +564,9 @@ error_handler:
int genaRenewSubscription( int genaRenewSubscription(
IN UpnpClient_Handle client_handle, UpnpClient_Handle client_handle,
IN const UpnpString *in_sid, const UpnpString *in_sid,
INOUT int *TimeOut) int *TimeOut)
{ {
int return_code = GENA_SUCCESS; int return_code = GENA_SUCCESS;
ClientSubscription *sub = NULL; ClientSubscription *sub = NULL;
@ -662,8 +662,8 @@ exit_function:
void gena_process_notification_event( void gena_process_notification_event(
IN SOCKINFO *info, SOCKINFO *info,
IN http_message_t *event) http_message_t *event)
{ {
UpnpEvent *event_struct = UpnpEvent_new(); UpnpEvent *event_struct = UpnpEvent_new();
IXML_Document *ChangedVars = NULL; IXML_Document *ChangedVars = NULL;

View File

@ -61,7 +61,7 @@
*/ */
int genaUnregisterDevice( int genaUnregisterDevice(
/*! [in] Device handle. */ /*! [in] Device handle. */
IN UpnpDevice_Handle device_handle) UpnpDevice_Handle device_handle)
{ {
int ret = 0; int ret = 0;
struct Handle_Info *handle_info; struct Handle_Info *handle_info;
@ -92,13 +92,13 @@ int genaUnregisterDevice(
*/ */
static int GeneratePropertySet( static int GeneratePropertySet(
/*! [in] Array of variable names (go in the event notify). */ /*! [in] Array of variable names (go in the event notify). */
IN char **names, char **names,
/*! [in] Array of variable values (go in the event notify). */ /*! [in] Array of variable values (go in the event notify). */
IN char **values, char **values,
/*! [in] number of variables. */ /*! [in] number of variables. */
IN int count, int count,
/*! [out] PropertySet node in the string format. */ /*! [out] PropertySet node in the string format. */
OUT DOMString *out) DOMString *out)
{ {
char *buffer; char *buffer;
int counter = 0; int counter = 0;
@ -147,7 +147,7 @@ static int GeneratePropertySet(
*/ */
static void free_notify_struct( static void free_notify_struct(
/*! [in] Notify structure. */ /*! [in] Notify structure. */
IN notify_thread_struct *input) notify_thread_struct *input)
{ {
( *input->reference_count )--; ( *input->reference_count )--;
if( ( *input->reference_count ) == 0 ) { if( ( *input->reference_count ) == 0 ) {
@ -170,13 +170,13 @@ static void free_notify_struct(
*/ */
static UPNP_INLINE int notify_send_and_recv( static UPNP_INLINE int notify_send_and_recv(
/*! [in] subscription callback URL (URL of the control point). */ /*! [in] subscription callback URL (URL of the control point). */
IN uri_type *destination_url, uri_type *destination_url,
/*! [in] Common HTTP headers. */ /*! [in] Common HTTP headers. */
IN membuffer *mid_msg, membuffer *mid_msg,
/*! [in] The evented XML. */ /*! [in] The evented XML. */
IN char *propertySet, char *propertySet,
/*! [out] The response from the control point. */ /*! [out] The response from the control point. */
OUT http_parser_t *response) http_parser_t *response)
{ {
uri_type url; uri_type url;
int conn_fd; int conn_fd;
@ -258,11 +258,11 @@ static UPNP_INLINE int notify_send_and_recv(
*/ */
static int genaNotify( static int genaNotify(
/*! [in] Null terminated, includes all headers (including \\r\\n) except SID and SEQ. */ /*! [in] Null terminated, includes all headers (including \\r\\n) except SID and SEQ. */
IN char *headers, char *headers,
/*! [in] The evented XML. */ /*! [in] The evented XML. */
IN char *propertySet, char *propertySet,
/*! [in] subscription to be Notified, assumes this is valid for life of function. */ /*! [in] subscription to be Notified, assumes this is valid for life of function. */
IN subscription *sub) subscription *sub)
{ {
int i; int i;
membuffer mid_msg; membuffer mid_msg;
@ -326,7 +326,7 @@ static int genaNotify(
*/ */
static void genaNotifyThread( static void genaNotifyThread(
/*! [in] notify thread structure containing all the headers and property set info. */ /*! [in] notify thread structure containing all the headers and property set info. */
IN void *input) void *input)
{ {
subscription *sub; subscription *sub;
service_info *service; service_info *service;
@ -406,13 +406,13 @@ static void genaNotifyThread(
int genaInitNotify( int genaInitNotify(
IN UpnpDevice_Handle device_handle, UpnpDevice_Handle device_handle,
IN char *UDN, char *UDN,
IN char *servId, char *servId,
IN char **VarNames, char **VarNames,
IN char **VarValues, char **VarValues,
IN int var_count, int var_count,
IN const Upnp_SID sid) const Upnp_SID sid)
{ {
int ret = GENA_SUCCESS; int ret = GENA_SUCCESS;
int line = 0; int line = 0;
@ -574,11 +574,11 @@ ExitFunction:
int genaInitNotifyExt( int genaInitNotifyExt(
IN UpnpDevice_Handle device_handle, UpnpDevice_Handle device_handle,
IN char *UDN, char *UDN,
IN char *servId, char *servId,
IN IXML_Document *PropSet, IXML_Document *PropSet,
IN const Upnp_SID sid) const Upnp_SID sid)
{ {
int ret = GENA_SUCCESS; int ret = GENA_SUCCESS;
int line = 0; int line = 0;
@ -741,10 +741,10 @@ ExitFunction:
int genaNotifyAllExt( int genaNotifyAllExt(
IN UpnpDevice_Handle device_handle, UpnpDevice_Handle device_handle,
IN char *UDN, char *UDN,
IN char *servId, char *servId,
IN IXML_Document *PropSet) IXML_Document *PropSet)
{ {
int ret = GENA_SUCCESS; int ret = GENA_SUCCESS;
int line = 0; int line = 0;
@ -891,12 +891,12 @@ ExitFunction:
int genaNotifyAll( int genaNotifyAll(
IN UpnpDevice_Handle device_handle, UpnpDevice_Handle device_handle,
IN char *UDN, char *UDN,
IN char *servId, char *servId,
IN char **VarNames, char **VarNames,
IN char **VarValues, char **VarValues,
IN int var_count ) int var_count )
{ {
int ret = GENA_SUCCESS; int ret = GENA_SUCCESS;
int line = 0; int line = 0;
@ -1049,13 +1049,13 @@ ExitFunction:
*/ */
static int respond_ok( static int respond_ok(
/*! [in] Socket connection of request. */ /*! [in] Socket connection of request. */
IN SOCKINFO *info, SOCKINFO *info,
/*! [in] Accepted duration. */ /*! [in] Accepted duration. */
IN int time_out, int time_out,
/*! [in] Accepted subscription. */ /*! [in] Accepted subscription. */
IN subscription *sub, subscription *sub,
/*! [in] Http request. */ /*! [in] Http request. */
IN http_message_t *request) http_message_t *request)
{ {
int major; int major;
int minor; int minor;
@ -1109,9 +1109,9 @@ static int respond_ok(
*/ */
static int create_url_list( static int create_url_list(
/*! [in] . */ /*! [in] . */
IN memptr *url_list, memptr *url_list,
/*! [out] . */ /*! [out] . */
OUT URL_list *out) URL_list *out)
{ {
int URLcount = 0; int URLcount = 0;
int i; int i;
@ -1185,8 +1185,8 @@ static int create_url_list(
void gena_process_subscription_request( void gena_process_subscription_request(
IN SOCKINFO *info, SOCKINFO *info,
IN http_message_t *request) http_message_t *request)
{ {
UpnpSubscriptionRequest *request_struct = UpnpSubscriptionRequest_new(); UpnpSubscriptionRequest *request_struct = UpnpSubscriptionRequest_new();
Upnp_SID temp_sid; Upnp_SID temp_sid;
@ -1368,8 +1368,8 @@ exit_function:
void gena_process_subscription_renewal_request( void gena_process_subscription_renewal_request(
IN SOCKINFO *info, SOCKINFO *info,
IN http_message_t *request) http_message_t *request)
{ {
Upnp_SID sid; Upnp_SID sid;
subscription *sub; subscription *sub;
@ -1480,8 +1480,8 @@ void gena_process_subscription_renewal_request(
void gena_process_unsubscribe_request( void gena_process_unsubscribe_request(
IN SOCKINFO *info, SOCKINFO *info,
IN http_message_t *request) http_message_t *request)
{ {
Upnp_SID sid; Upnp_SID sid;
service_info *service; service_info *service;

View File

@ -29,18 +29,27 @@
* *
**************************************************************************/ **************************************************************************/
/************************************************************************
* Purpose: This file implements the functionality and utility functions #include "config.h"
/*!
* \file
*
* \brief This file implements the functionality and utility functions
* used by the Miniserver module. * used by the Miniserver module.
* *
* The miniserver is a central point for processing all network requests. * The miniserver is a central point for processing all network requests.
* It is made of: * It is made of:
* - The SSDP sockets for discovery. * - The SSDP sockets for discovery.
* - The HTTP listeners for description / control / eventing. * - The HTTP listeners for description / control / eventing.
************************************************************************/ *
*/
#include "config.h"
#include "miniserver.h" #include "miniserver.h"
#include "httpreadwrite.h" #include "httpreadwrite.h"
#include "ithread.h" #include "ithread.h"
#include "ssdplib.h" #include "ssdplib.h"
@ -49,6 +58,8 @@
#include "unixutil.h" /* for socklen_t, EAFNOSUPPORT */ #include "unixutil.h" /* for socklen_t, EAFNOSUPPORT */
#include "upnpapi.h" #include "upnpapi.h"
#include "util.h" #include "util.h"
#include <assert.h> #include <assert.h>
#include <errno.h> #include <errno.h>
#include <stdio.h> #include <stdio.h>
@ -59,15 +70,24 @@
#define APPLICATION_LISTENING_PORT 49152 #define APPLICATION_LISTENING_PORT 49152
struct mserv_request_t { struct mserv_request_t {
int connfd; // connection handle /*! Connection handle. */
int connfd;
struct sockaddr_storage foreign_sockaddr; struct sockaddr_storage foreign_sockaddr;
}; };
typedef enum { MSERV_IDLE, MSERV_RUNNING, MSERV_STOPPING } MiniServerState;
typedef enum {
MSERV_IDLE,
MSERV_RUNNING,
MSERV_STOPPING
} MiniServerState;
unsigned short miniStopSockPort; unsigned short miniStopSockPort;
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// module vars // module vars
static MiniServerCallback gGetCallback = NULL; static MiniServerCallback gGetCallback = NULL;
@ -75,88 +95,48 @@ static MiniServerCallback gSoapCallback = NULL;
static MiniServerCallback gGenaCallback = NULL; static MiniServerCallback gGenaCallback = NULL;
static MiniServerState gMServState = MSERV_IDLE; static MiniServerState gMServState = MSERV_IDLE;
/************************************************************************
* Function: SetHTTPGetCallback void SetHTTPGetCallback(MiniServerCallback callback)
*
* Parameters :
* MiniServerCallback callback - HTTP Callback to be invoked
*
* Description:
* Set HTTP Get Callback
*
* Return: void
************************************************************************/
void
SetHTTPGetCallback( MiniServerCallback callback )
{ {
gGetCallback = callback; gGetCallback = callback;
} }
/************************************************************************
* Function: SetSoapCallback
*
* Parameters:
* MiniServerCallback callback - SOAP Callback to be invoked
*
* Description:
* Set SOAP Callback
*
* Return: void
************************************************************************/
#ifdef INCLUDE_DEVICE_APIS #ifdef INCLUDE_DEVICE_APIS
void void SetSoapCallback(MiniServerCallback callback)
SetSoapCallback( MiniServerCallback callback )
{ {
gSoapCallback = callback; gSoapCallback = callback;
} }
#endif /* INCLUDE_DEVICE_APIS */ #endif /* INCLUDE_DEVICE_APIS */
/************************************************************************ void SetGenaCallback(MiniServerCallback callback)
* Function: SetGenaCallback
*
* Parameters:
* MiniServerCallback callback - GENA Callback to be invoked
*
* Description:
* Set GENA Callback
*
* Return: void
************************************************************************/
void
SetGenaCallback( MiniServerCallback callback )
{ {
gGenaCallback = callback; gGenaCallback = callback;
} }
#ifdef INTERNAL_WEB_SERVER #ifdef INTERNAL_WEB_SERVER
/************************************************************************ /*!
* Function : dispatch_request * \brief Based on the type pf message, appropriate callback is issued.
* *
* Parameters : * \return 0 on Success or HTTP_INTERNAL_SERVER_ERROR if Callback is NULL.
* IN SOCKINFO *info - Socket Information object. */
* http_parser_t* hparser - HTTP parser object. static int dispatch_request(
* /*! [in] Socket Information object. */
* Description : IN SOCKINFO *info,
* Based on the type pf message, appropriate callback is issued /*! [in] HTTP parser object. */
*
* Return: int
* 0 - On Success
* HTTP_INTERNAL_SERVER_ERROR - Callback is NULL
************************************************************************/
static int
dispatch_request( IN SOCKINFO * info,
http_parser_t *hparser) http_parser_t *hparser)
{ {
MiniServerCallback callback; MiniServerCallback callback;
switch (hparser->msg.method) { switch (hparser->msg.method) {
//Soap Call /* Soap Call */
case SOAPMETHOD_POST: case SOAPMETHOD_POST:
case HTTPMETHOD_MPOST: case HTTPMETHOD_MPOST:
callback = gSoapCallback; callback = gSoapCallback;
break; break;
//Gena Call /* Gena Call */
case HTTPMETHOD_NOTIFY: case HTTPMETHOD_NOTIFY:
case HTTPMETHOD_SUBSCRIBE: case HTTPMETHOD_SUBSCRIBE:
case HTTPMETHOD_UNSUBSCRIBE: case HTTPMETHOD_UNSUBSCRIBE:
@ -165,7 +145,7 @@ dispatch_request( IN SOCKINFO * info,
callback = gGenaCallback; callback = gGenaCallback;
break; break;
//HTTP server call /* HTTP server call */
case HTTPMETHOD_GET: case HTTPMETHOD_GET:
case HTTPMETHOD_POST: case HTTPMETHOD_POST:
case HTTPMETHOD_HEAD: case HTTPMETHOD_HEAD:
@ -182,46 +162,35 @@ dispatch_request( IN SOCKINFO * info,
} }
callback(hparser, &hparser->msg, info); callback(hparser, &hparser->msg, info);
return 0; return 0;
} }
/************************************************************************
* Function: handle_error /*!
* * \brief Send Error Message.
* Parameters: */
* IN SOCKINFO *info - Socket Inforamtion Object static UPNP_INLINE void handle_error(
* int http_error_code - HTTP Error Code /*! [in] Socket Information object. */
* int major - Major Version Number SOCKINFO *info,
* int minor - Minor Version Number /*! [in] HTTP Error Code. */
*
* Description:
* Send Error Message
*
* Return: void
************************************************************************/
static UPNP_INLINE void
handle_error( IN SOCKINFO * info,
int http_error_code, int http_error_code,
/*! [in] Major Version Number. */
int major, int major,
/*! [in] Minor Version Number. */
int minor) int minor)
{ {
http_SendStatusResponse(info, http_error_code, major, minor); http_SendStatusResponse(info, http_error_code, major, minor);
} }
/************************************************************************
* Function: free_handle_request_arg /*!
* * \brief Free memory assigned for handling request and unitialize socket
* Parameters: * functionality.
* void *args ; Request Message to be freed */
* static void free_handle_request_arg(
* Description: /*! [in] Request Message to be freed. */
* Free memory assigned for handling request and unitialize socket void *args)
* functionality
*
* Return: void
************************************************************************/
static void
free_handle_request_arg( void *args )
{ {
struct mserv_request_t *request = (struct mserv_request_t *)args; struct mserv_request_t *request = (struct mserv_request_t *)args;
@ -230,19 +199,13 @@ free_handle_request_arg( void *args )
free(request); free(request);
} }
/************************************************************************
* Function: handle_request /*!
* * \brief Receive the request and dispatch it for handling.
* Parameters: */
* void *args - Request Message to be handled static void handle_request(
* /*! [in] Request Message to be handled. */
* Description: void *args)
* Receive the request and dispatch it for handling
*
* Return: void
************************************************************************/
static void
handle_request( void *args )
{ {
SOCKINFO info; SOCKINFO info;
int http_error_code; int http_error_code;
@ -260,21 +223,24 @@ handle_request( void *args )
//parser_request_init( &parser ); ////LEAK_FIX_MK //parser_request_init( &parser ); ////LEAK_FIX_MK
hmsg = &parser.msg; hmsg = &parser.msg;
if( sock_init_with_ip( &info, connfd, (struct sockaddr*)&request->foreign_sockaddr ) ret_code = sock_init_with_ip(
!= UPNP_E_SUCCESS ) { &info, connfd, (struct sockaddr *)&request->foreign_sockaddr);
if (ret_code != UPNP_E_SUCCESS) {
free(request); free(request);
httpmsg_destroy(hmsg); httpmsg_destroy(hmsg);
return; return;
} }
// read // read
ret_code = http_RecvMessage( &info, &parser, HTTPMETHOD_UNKNOWN, ret_code = http_RecvMessage(
&timeout, &http_error_code ); &info, &parser, HTTPMETHOD_UNKNOWN, &timeout, &http_error_code);
if (ret_code != 0) { if (ret_code != 0) {
goto error_handler; goto error_handler;
} }
UpnpPrintf(UPNP_INFO, MSERV, __FILE__, __LINE__, UpnpPrintf(UPNP_INFO, MSERV, __FILE__, __LINE__,
"miniserver %d: PROCESSING...\n", connfd); "miniserver %d: PROCESSING...\n", connfd);
// dispatch // dispatch
http_error_code = dispatch_request( &info, &parser ); http_error_code = dispatch_request( &info, &parser );
if (http_error_code != 0) { if (http_error_code != 0) {
@ -300,29 +266,21 @@ handle_request( void *args )
free(request); free(request);
} }
/************************************************************************
* Function: schedule_request_job /*!
* * \brief Initilize the thread pool to handle a request, sets priority for the
* Parameters: * job and adds the job to the thread pool.
* IN int connfd - Socket Descriptor on which connection is accepted */
* IN struct sockaddr* clientAddr - Clients Address information static UPNP_INLINE void schedule_request_job(
* /*! [in] Socket Descriptor on which connection is accepted. */
* Description: int connfd,
* Initilize the thread pool to handle a request. /*! [in] Clients Address information. */
* Sets priority for the job and adds the job to the thread pool struct sockaddr *clientAddr)
*
* Return: void
************************************************************************/
static UPNP_INLINE void
schedule_request_job( IN int connfd,
IN struct sockaddr *clientAddr )
{ {
struct mserv_request_t *request; struct mserv_request_t *request;
ThreadPoolJob job; ThreadPoolJob job;
request = request = (struct mserv_request_t *)malloc(sizeof (struct mserv_request_t));
( struct mserv_request_t * )
malloc( sizeof( struct mserv_request_t ) );
if (request == NULL) { if (request == NULL) {
UpnpPrintf( UPNP_INFO, MSERV, __FILE__, __LINE__, UpnpPrintf( UPNP_INFO, MSERV, __FILE__, __LINE__,
"mserv %d: out of memory\n", connfd ); "mserv %d: out of memory\n", connfd );
@ -332,7 +290,8 @@ schedule_request_job( IN int connfd,
} }
request->connfd = connfd; request->connfd = connfd;
memcpy( &request->foreign_sockaddr, clientAddr, sizeof(request->foreign_sockaddr) ); memcpy(&request->foreign_sockaddr, clientAddr,
sizeof(request->foreign_sockaddr));
TPJobInit(&job, (start_routine)handle_request, (void *)request); TPJobInit(&job, (start_routine)handle_request, (void *)request);
TPJobSetFreeFunction(&job, free_handle_request_arg); TPJobSetFreeFunction(&job, free_handle_request_arg);
@ -346,26 +305,20 @@ schedule_request_job( IN int connfd,
UpnpCloseSocket(connfd); UpnpCloseSocket(connfd);
return; return;
} }
} }
#endif #endif
/************************************************************************
* Function: RunMiniServer /*!
* \brief Run the miniserver.
* *
* Parameters: * The MiniServer accepts a new request and schedules a thread to handle the
* MiniServerSockArray *miniSock - Socket Array * new request. Checks for socket state and invokes appropriate read and
* * shutdown actions for the Miniserver and SSDP sockets.
* Description: */
* Function runs the miniserver. The MiniServer accepts a static void RunMiniServer(
* new request and schedules a thread to handle the new request. /*! [in] Socket Array. */
* Checks for socket state and invokes appropriate read and shutdown MiniServerSockArray *miniSock)
* actions for the Miniserver and SSDP sockets
*
* Return: void
************************************************************************/
static void
RunMiniServer( MiniServerSockArray *miniSock )
{ {
char errorBuffer[ERROR_BUFFER_LEN]; char errorBuffer[ERROR_BUFFER_LEN];
struct sockaddr_storage clientAddr; struct sockaddr_storage clientAddr;
@ -377,11 +330,11 @@ RunMiniServer( MiniServerSockArray *miniSock )
#ifdef INTERNAL_WEB_SERVER #ifdef INTERNAL_WEB_SERVER
SOCKET miniServSock4 = miniSock->miniServerSock4; SOCKET miniServSock4 = miniSock->miniServerSock4;
SOCKET miniServSock6 = miniSock->miniServerSock6; SOCKET miniServSock6 = miniSock->miniServerSock6;
#endif #endif /* INTERNAL_WEB_SERVER */
#ifdef INCLUDE_CLIENT_APIS #ifdef INCLUDE_CLIENT_APIS
SOCKET ssdpReqSock4 = miniSock->ssdpReqSock4; SOCKET ssdpReqSock4 = miniSock->ssdpReqSock4;
SOCKET ssdpReqSock6 = miniSock->ssdpReqSock6; SOCKET ssdpReqSock6 = miniSock->ssdpReqSock6;
#endif #endif /* INCLUDE_CLIENT_APIS */
char buf_ntop[64]; char buf_ntop[64];
fd_set expSet; fd_set expSet;
fd_set rdSet; fd_set rdSet;
@ -391,21 +344,27 @@ RunMiniServer( MiniServerSockArray *miniSock )
int ret = 0; int ret = 0;
#ifdef INTERNAL_WEB_SERVER #ifdef INTERNAL_WEB_SERVER
if( miniServSock4 != INVALID_SOCKET ) if (miniServSock4 != INVALID_SOCKET) {
maxMiniSock = max(maxMiniSock, miniServSock4); maxMiniSock = max(maxMiniSock, miniServSock4);
if( miniServSock6 != INVALID_SOCKET ) }
if (miniServSock6 != INVALID_SOCKET) {
maxMiniSock = max(maxMiniSock, miniServSock6); maxMiniSock = max(maxMiniSock, miniServSock6);
#endif }
if( ssdpSock4 != INVALID_SOCKET ) #endif /* INTERNAL_WEB_SERVER */
if (ssdpSock4 != INVALID_SOCKET) {
maxMiniSock = max(maxMiniSock, ssdpSock4); maxMiniSock = max(maxMiniSock, ssdpSock4);
if( ssdpSock6 != INVALID_SOCKET ) }
if (ssdpSock6 != INVALID_SOCKET) {
maxMiniSock = max(maxMiniSock, ssdpSock6); maxMiniSock = max(maxMiniSock, ssdpSock6);
}
#ifdef INCLUDE_CLIENT_APIS #ifdef INCLUDE_CLIENT_APIS
if( ssdpReqSock4 != INVALID_SOCKET ) if (ssdpReqSock4 != INVALID_SOCKET) {
maxMiniSock = max(maxMiniSock, ssdpReqSock4); maxMiniSock = max(maxMiniSock, ssdpReqSock4);
if( ssdpReqSock6 != INVALID_SOCKET ) }
if (ssdpReqSock6 != INVALID_SOCKET) {
maxMiniSock = max(maxMiniSock, ssdpReqSock6); maxMiniSock = max(maxMiniSock, ssdpReqSock6);
#endif }
#endif /* INCLUDE_CLIENT_APIS */
maxMiniSock = max(maxMiniSock, miniServStopSock); maxMiniSock = max(maxMiniSock, miniServStopSock);
++maxMiniSock; ++maxMiniSock;
@ -417,21 +376,27 @@ RunMiniServer( MiniServerSockArray *miniSock )
FD_SET(miniServStopSock, &expSet); FD_SET(miniServStopSock, &expSet);
FD_SET(miniServStopSock, &rdSet); FD_SET(miniServStopSock, &rdSet);
#ifdef INTERNAL_WEB_SERVER #ifdef INTERNAL_WEB_SERVER
if( miniServSock4 != INVALID_SOCKET ) if(miniServSock4 != INVALID_SOCKET) {
FD_SET(miniServSock4, &rdSet); FD_SET(miniServSock4, &rdSet);
if( miniServSock6 != INVALID_SOCKET ) }
if(miniServSock6 != INVALID_SOCKET) {
FD_SET(miniServSock6, &rdSet); FD_SET(miniServSock6, &rdSet);
#endif }
if( ssdpSock4 != INVALID_SOCKET ) #endif /* INTERNAL_WEB_SERVER */
if(ssdpSock4 != INVALID_SOCKET) {
FD_SET(ssdpSock4, &rdSet); FD_SET(ssdpSock4, &rdSet);
if( ssdpSock6 != INVALID_SOCKET ) }
if(ssdpSock6 != INVALID_SOCKET) {
FD_SET(ssdpSock6, &rdSet); FD_SET(ssdpSock6, &rdSet);
}
#ifdef INCLUDE_CLIENT_APIS #ifdef INCLUDE_CLIENT_APIS
if( ssdpReqSock4 != INVALID_SOCKET ) if(ssdpReqSock4 != INVALID_SOCKET) {
FD_SET(ssdpReqSock4, &rdSet); FD_SET(ssdpReqSock4, &rdSet);
if( ssdpReqSock6 != INVALID_SOCKET ) }
if(ssdpReqSock6 != INVALID_SOCKET) {
FD_SET(ssdpReqSock6, &rdSet); FD_SET(ssdpReqSock6, &rdSet);
#endif }
#endif /* INCLUDE_CLIENT_APIS */
ret = select(maxMiniSock, &rdSet, NULL, &expSet, NULL); ret = select(maxMiniSock, &rdSet, NULL, &expSet, NULL);
if (ret == -1) { if (ret == -1) {
@ -451,10 +416,12 @@ RunMiniServer( MiniServerSockArray *miniSock )
if (connectHnd == -1) { if (connectHnd == -1) {
strerror_r(errno, errorBuffer, ERROR_BUFFER_LEN); strerror_r(errno, errorBuffer, ERROR_BUFFER_LEN);
UpnpPrintf(UPNP_INFO, MSERV, __FILE__, __LINE__, UpnpPrintf(UPNP_INFO, MSERV, __FILE__, __LINE__,
"miniserver: Error in accept(): %s\n", errorBuffer ); "miniserver: Error in accept(): %s\n",
errorBuffer);
continue; continue;
} }
schedule_request_job( connectHnd, (struct sockaddr*)&clientAddr ); schedule_request_job(
connectHnd, (struct sockaddr *)&clientAddr);
} }
if (miniServSock4 != INVALID_SOCKET && if (miniServSock4 != INVALID_SOCKET &&
FD_ISSET(miniServSock4, &rdSet)) { FD_ISSET(miniServSock4, &rdSet)) {
@ -464,12 +431,14 @@ RunMiniServer( MiniServerSockArray *miniSock )
if (connectHnd == -1) { if (connectHnd == -1) {
strerror_r(errno, errorBuffer, ERROR_BUFFER_LEN); strerror_r(errno, errorBuffer, ERROR_BUFFER_LEN);
UpnpPrintf( UPNP_INFO, MSERV, __FILE__, __LINE__, UpnpPrintf( UPNP_INFO, MSERV, __FILE__, __LINE__,
"miniserver: Error in accept(): %s\n", errorBuffer ); "miniserver: Error in accept(): %s\n",
errorBuffer);
continue; continue;
} }
schedule_request_job( connectHnd, (struct sockaddr*)&clientAddr ); schedule_request_job(
connectHnd, (struct sockaddr *)&clientAddr);
} }
#endif #endif /* INTERNAL_WEB_SERVER */
#ifdef INCLUDE_CLIENT_APIS #ifdef INCLUDE_CLIENT_APIS
// ssdp // ssdp
if (ssdpReqSock6 != INVALID_SOCKET && if (ssdpReqSock6 != INVALID_SOCKET &&
@ -480,7 +449,7 @@ RunMiniServer( MiniServerSockArray *miniSock )
FD_ISSET( ssdpReqSock4, &rdSet)) { FD_ISSET( ssdpReqSock4, &rdSet)) {
readFromSSDPSocket(ssdpReqSock4); readFromSSDPSocket(ssdpReqSock4);
} }
#endif #endif /* INCLUDE_CLIENT_APIS */
if (ssdpSock6 != INVALID_SOCKET && if (ssdpSock6 != INVALID_SOCKET &&
FD_ISSET(ssdpSock6, &rdSet)) { FD_ISSET(ssdpSock6, &rdSet)) {
readFromSSDPSocket(ssdpSock6); readFromSSDPSocket(ssdpSock6);
@ -492,10 +461,8 @@ RunMiniServer( MiniServerSockArray *miniSock )
if (FD_ISSET( miniServStopSock, &rdSet)) { if (FD_ISSET( miniServStopSock, &rdSet)) {
clientLen = sizeof(clientAddr); clientLen = sizeof(clientAddr);
memset((char *)&clientAddr, 0, sizeof(clientAddr)); memset((char *)&clientAddr, 0, sizeof(clientAddr));
byteReceived = byteReceived = recvfrom(miniServStopSock, requestBuf,
recvfrom( miniServStopSock, requestBuf, 25, 0, 25, 0, (struct sockaddr *)&clientAddr, &clientLen);
( struct sockaddr * )&clientAddr,
&clientLen );
if (byteReceived > 0) { if (byteReceived > 0) {
requestBuf[byteReceived] = '\0'; requestBuf[byteReceived] = '\0';
inet_ntop(AF_INET, inet_ntop(AF_INET,
@ -520,7 +487,7 @@ RunMiniServer( MiniServerSockArray *miniSock )
UpnpCloseSocket(miniServSock4); UpnpCloseSocket(miniServSock4);
shutdown(miniServSock6, SD_BOTH); shutdown(miniServSock6, SD_BOTH);
UpnpCloseSocket(miniServSock6); UpnpCloseSocket(miniServSock6);
#endif #endif /* INTERNAL_WEB_SERVER */
shutdown(miniServStopSock, SD_BOTH); shutdown(miniServStopSock, SD_BOTH);
UpnpCloseSocket(miniServStopSock); UpnpCloseSocket(miniServStopSock);
shutdown(ssdpSock4, SD_BOTH); shutdown(ssdpSock4, SD_BOTH);
@ -532,7 +499,7 @@ RunMiniServer( MiniServerSockArray *miniSock )
UpnpCloseSocket(ssdpReqSock4); UpnpCloseSocket(ssdpReqSock4);
shutdown(ssdpReqSock6, SD_BOTH); shutdown(ssdpReqSock6, SD_BOTH);
UpnpCloseSocket(ssdpReqSock6); UpnpCloseSocket(ssdpReqSock6);
#endif #endif /* INCLUDE_CLIENT_APIS */
free(miniSock); free(miniSock);
gMServState = MSERV_IDLE; gMServState = MSERV_IDLE;
@ -540,21 +507,15 @@ RunMiniServer( MiniServerSockArray *miniSock )
return; return;
} }
/************************************************************************
* Function: get_port /*!
* \brief Returns port to which socket, sockfd, is bound.
* *
* Parameters: * \return -1 on error; check errno, otherwise > 0 means port number.
* int sockfd - Socket Descriptor */
* static int get_port(
* Description: /*! [in] Socket descriptor. */
* Returns port to which socket, sockfd, is bound. int sockfd)
*
* Return: int
* -1 on error; check errno
* > 0 means port number
************************************************************************/
static int
get_port( int sockfd )
{ {
struct sockaddr_storage sockinfo; struct sockaddr_storage sockinfo;
socklen_t len; socklen_t len;
@ -578,35 +539,29 @@ get_port( int sockfd )
return port; return port;
} }
#ifdef INTERNAL_WEB_SERVER #ifdef INTERNAL_WEB_SERVER
/************************************************************************ /*!
* Function: get_miniserver_sockets * \brief Creates a STREAM socket, binds to INADDR_ANY and listens for
*
* Parameters:
* MiniServerSockArray *out - Socket Array
* unsigned short listen_port4 - port on which the server is
* listening for incoming IPv4 connections
* unsigned short listen_port6 - port on which the server is
* listening for incoming IPv6 connections
*
* Description:
* Creates a STREAM socket, binds to INADDR_ANY and listens for
* incoming connecttions. Returns the actual port which the sockets * incoming connecttions. Returns the actual port which the sockets
* sub-system returned. * sub-system returned.
* *
* Also creates a DGRAM socket, binds to the loop back address and * Also creates a DGRAM socket, binds to the loop back address and
* returns the port allocated by the socket sub-system. * returns the port allocated by the socket sub-system.
* *
* Return: int * \return
* UPNP_E_OUTOF_SOCKET - Failed to create a socket * \li UPNP_E_OUTOF_SOCKET: Failed to create a socket.
* UPNP_E_SOCKET_BIND - Bind() failed * \li UPNP_E_SOCKET_BIND: Bind() failed.
* UPNP_E_LISTEN - Listen() failed * \li UPNP_E_LISTEN: Listen() failed.
* UPNP_E_INTERNAL_ERROR - Port returned by the socket layer is < 0 * \li UPNP_E_INTERNAL_ERROR: Port returned by the socket layer is < 0.
* UPNP_E_SUCCESS - Success * \li UPNP_E_SUCCESS: Success.
************************************************************************/ */
int static int get_miniserver_sockets(
get_miniserver_sockets( MiniServerSockArray * out, /*! [in] Socket Array. */
MiniServerSockArray *out,
/*! [in] port on which the server is listening for incoming IPv4 connections. */
unsigned short listen_port4, unsigned short listen_port4,
/*! [in] port on which the server is listening for incoming IPv6 connections. */
unsigned short listen_port6) unsigned short listen_port6)
{ {
char errorBuffer[ERROR_BUFFER_LEN]; char errorBuffer[ERROR_BUFFER_LEN];
@ -620,7 +575,6 @@ get_miniserver_sockets( MiniServerSockArray * out,
int reuseaddr_on = 0; int reuseaddr_on = 0;
int sockError = UPNP_E_SUCCESS; int sockError = UPNP_E_SUCCESS;
int errCode = 0; int errCode = 0;
int ret = 0;
// Create listen socket for IPv4/IPv6. An error here may indicate // Create listen socket for IPv4/IPv6. An error here may indicate
// that we don't have an IPv4/IPv6 stack. // that we don't have an IPv4/IPv6 stack.
@ -668,7 +622,6 @@ get_miniserver_sockets( MiniServerSockArray * out,
UpnpCloseSocket(listenfd4); UpnpCloseSocket(listenfd4);
shutdown(listenfd6, SD_BOTH); shutdown(listenfd6, SD_BOTH);
UpnpCloseSocket(listenfd6); UpnpCloseSocket(listenfd6);
return UPNP_E_SOCKET_BIND; return UPNP_E_SOCKET_BIND;
} }
@ -683,8 +636,8 @@ get_miniserver_sockets( MiniServerSockArray * out,
UpnpCloseSocket(listenfd4); UpnpCloseSocket(listenfd4);
shutdown(listenfd6, SD_BOTH); shutdown(listenfd6, SD_BOTH);
UpnpCloseSocket(listenfd6); UpnpCloseSocket(listenfd6);
/* Bind failed */
return UPNP_E_SOCKET_BIND; // bind failed return UPNP_E_SOCKET_BIND;
} }
} }
@ -696,12 +649,10 @@ get_miniserver_sockets( MiniServerSockArray * out,
UpnpCloseSocket(listenfd4); UpnpCloseSocket(listenfd4);
shutdown(listenfd6, SD_BOTH); shutdown(listenfd6, SD_BOTH);
UpnpCloseSocket(listenfd6); UpnpCloseSocket(listenfd6);
return UPNP_E_SOCKET_BIND; return UPNP_E_SOCKET_BIND;
} }
sockError = bind( listenfd6, (struct sockaddr *)&__ss_v6, sockError = bind(listenfd6, (struct sockaddr *)&__ss_v6, sizeof (__ss_v6));
sizeof(__ss_v6) );
if (sockError == -1) { if (sockError == -1) {
strerror_r(errno, errorBuffer, ERROR_BUFFER_LEN); strerror_r(errno, errorBuffer, ERROR_BUFFER_LEN);
UpnpPrintf(UPNP_INFO, MSERV, __FILE__, __LINE__, UpnpPrintf(UPNP_INFO, MSERV, __FILE__, __LINE__,
@ -711,8 +662,8 @@ get_miniserver_sockets( MiniServerSockArray * out,
UpnpCloseSocket(listenfd4); UpnpCloseSocket(listenfd4);
shutdown(listenfd6, SD_BOTH); shutdown(listenfd6, SD_BOTH);
UpnpCloseSocket(listenfd6); UpnpCloseSocket(listenfd6);
/* Bind failed */
return UPNP_E_SOCKET_BIND; // bind failed return UPNP_E_SOCKET_BIND;
} }
} }
} else { } else {
@ -730,9 +681,11 @@ get_miniserver_sockets( MiniServerSockArray * out,
if (errno == EADDRINUSE) { if (errno == EADDRINUSE) {
errCode = 1; errCode = 1;
} }
} else } else {
errCode = 0; errCode = 0;
}
} while ( errCode != 0 ); } while ( errCode != 0 );
if (sockError == -1) { if (sockError == -1) {
strerror_r(errno, errorBuffer, ERROR_BUFFER_LEN); strerror_r(errno, errorBuffer, ERROR_BUFFER_LEN);
UpnpPrintf(UPNP_INFO, MSERV, __FILE__, __LINE__, UpnpPrintf(UPNP_INFO, MSERV, __FILE__, __LINE__,
@ -742,7 +695,6 @@ get_miniserver_sockets( MiniServerSockArray * out,
UpnpCloseSocket(listenfd4); UpnpCloseSocket(listenfd4);
shutdown(listenfd6, SD_BOTH); shutdown(listenfd6, SD_BOTH);
UpnpCloseSocket(listenfd6); UpnpCloseSocket(listenfd6);
return UPNP_E_SOCKET_BIND; // bind failed return UPNP_E_SOCKET_BIND; // bind failed
} }
} }
@ -761,9 +713,11 @@ get_miniserver_sockets( MiniServerSockArray * out,
if (errno == EADDRINUSE) { if (errno == EADDRINUSE) {
errCode = 1; errCode = 1;
} }
} else } else {
errCode = 0; errCode = 0;
}
} while (errCode != 0); } while (errCode != 0);
if (sockError == -1) { if (sockError == -1) {
strerror_r(errno, errorBuffer, ERROR_BUFFER_LEN); strerror_r(errno, errorBuffer, ERROR_BUFFER_LEN);
UpnpPrintf(UPNP_INFO, MSERV, __FILE__, __LINE__, UpnpPrintf(UPNP_INFO, MSERV, __FILE__, __LINE__,
@ -773,8 +727,8 @@ get_miniserver_sockets( MiniServerSockArray * out,
UpnpCloseSocket(listenfd4); UpnpCloseSocket(listenfd4);
shutdown(listenfd6, SD_BOTH); shutdown(listenfd6, SD_BOTH);
UpnpCloseSocket(listenfd6); UpnpCloseSocket(listenfd6);
/* Bind failied */
return UPNP_E_SOCKET_BIND; // bind failed return UPNP_E_SOCKET_BIND;
} }
} }
} }
@ -787,12 +741,12 @@ get_miniserver_sockets( MiniServerSockArray * out,
if (ret_code == -1) { if (ret_code == -1) {
strerror_r(errno, errorBuffer, ERROR_BUFFER_LEN); strerror_r(errno, errorBuffer, ERROR_BUFFER_LEN);
UpnpPrintf(UPNP_INFO, MSERV, __FILE__, __LINE__, UpnpPrintf(UPNP_INFO, MSERV, __FILE__, __LINE__,
"mserv start: Error in IPv4 listen(): %s\n", errorBuffer ); "mserv start: Error in IPv4 listen(): %s\n",
errorBuffer);
shutdown(listenfd4, SD_BOTH); shutdown(listenfd4, SD_BOTH);
UpnpCloseSocket(listenfd4); UpnpCloseSocket(listenfd4);
shutdown(listenfd6, SD_BOTH); shutdown(listenfd6, SD_BOTH);
UpnpCloseSocket(listenfd6); UpnpCloseSocket(listenfd6);
return UPNP_E_LISTEN; return UPNP_E_LISTEN;
} }
@ -802,7 +756,6 @@ get_miniserver_sockets( MiniServerSockArray * out,
UpnpCloseSocket(listenfd4); UpnpCloseSocket(listenfd4);
shutdown(listenfd6, SD_BOTH); shutdown(listenfd6, SD_BOTH);
UpnpCloseSocket(listenfd6); UpnpCloseSocket(listenfd6);
return UPNP_E_INTERNAL_ERROR; return UPNP_E_INTERNAL_ERROR;
} }
@ -814,12 +767,12 @@ get_miniserver_sockets( MiniServerSockArray * out,
if (ret_code == -1) { if (ret_code == -1) {
strerror_r(errno, errorBuffer, ERROR_BUFFER_LEN); strerror_r(errno, errorBuffer, ERROR_BUFFER_LEN);
UpnpPrintf(UPNP_INFO, MSERV, __FILE__, __LINE__, UpnpPrintf(UPNP_INFO, MSERV, __FILE__, __LINE__,
"mserv start: Error in IPv6 listen(): %s\n", errorBuffer ); "mserv start: Error in IPv6 listen(): %s\n",
errorBuffer);
shutdown(listenfd4, SD_BOTH); shutdown(listenfd4, SD_BOTH);
UpnpCloseSocket(listenfd4); UpnpCloseSocket(listenfd4);
shutdown(listenfd6, SD_BOTH); shutdown(listenfd6, SD_BOTH);
UpnpCloseSocket(listenfd6); UpnpCloseSocket(listenfd6);
return UPNP_E_LISTEN; return UPNP_E_LISTEN;
} }
@ -829,7 +782,6 @@ get_miniserver_sockets( MiniServerSockArray * out,
UpnpCloseSocket(listenfd4); UpnpCloseSocket(listenfd4);
shutdown(listenfd6, SD_BOTH); shutdown(listenfd6, SD_BOTH);
UpnpCloseSocket(listenfd6); UpnpCloseSocket(listenfd6);
return UPNP_E_INTERNAL_ERROR; return UPNP_E_INTERNAL_ERROR;
} }
@ -841,38 +793,33 @@ get_miniserver_sockets( MiniServerSockArray * out,
return UPNP_E_SUCCESS; return UPNP_E_SUCCESS;
} }
#endif #endif /* INTERNAL_WEB_SERVER */
/************************************************************************ /*!
* Function: get_miniserver_stopsock * \brief Creates the miniserver STOP socket. This socket is created and
*
* Parameters:
* MiniServerSockArray *out - Miniserver Socket Array
*
* Description:
* Creates the miniserver STOP socket. This socket is created and
* listened on to know when it is time to stop the Miniserver. * listened on to know when it is time to stop the Miniserver.
* *
* Return: int * \return
* UPNP_E_OUTOF_SOCKET - Failed to create a socket * \li UPNP_E_OUTOF_SOCKET: Failed to create a socket.
* UPNP_E_SOCKET_BIND - Bind() failed * \li UPNP_E_SOCKET_BIND: Bind() failed.
* UPNP_E_INTERNAL_ERROR - Port returned by the socket layer is < 0 * \li UPNP_E_INTERNAL_ERROR: Port returned by the socket layer is < 0.
* UPNP_E_SUCCESS - Success * \li UPNP_E_SUCCESS: Success.
************************************************************************/ */
int get_miniserver_stopsock( MiniServerSockArray * out ) static int get_miniserver_stopsock(
/*! [in] Miniserver Socket Array. */
MiniServerSockArray *out)
{ {
char errorBuffer[ERROR_BUFFER_LEN]; char errorBuffer[ERROR_BUFFER_LEN];
struct sockaddr_in stop_sockaddr; struct sockaddr_in stop_sockaddr;
int miniServerStopSock; int miniServerStopSock = 0;
int ret; int ret = 0;
miniServerStopSock = socket(AF_INET, SOCK_DGRAM, 0); miniServerStopSock = socket(AF_INET, SOCK_DGRAM, 0);
if (miniServerStopSock == -1) { if (miniServerStopSock == -1) {
strerror_r(errno, errorBuffer, ERROR_BUFFER_LEN); strerror_r(errno, errorBuffer, ERROR_BUFFER_LEN);
UpnpPrintf(UPNP_CRITICAL, MSERV, __FILE__, __LINE__, UpnpPrintf(UPNP_CRITICAL, MSERV, __FILE__, __LINE__,
"Error in socket(): %s\n", errorBuffer); "Error in socket(): %s\n", errorBuffer);
return UPNP_E_OUTOF_SOCKET; return UPNP_E_OUTOF_SOCKET;
} }
@ -888,7 +835,6 @@ int get_miniserver_stopsock( MiniServerSockArray * out )
"Error in binding localhost!!!\n"); "Error in binding localhost!!!\n");
shutdown(miniServerStopSock, SD_BOTH); shutdown(miniServerStopSock, SD_BOTH);
UpnpCloseSocket(miniServerStopSock); UpnpCloseSocket(miniServerStopSock);
return UPNP_E_SOCKET_BIND; return UPNP_E_SOCKET_BIND;
} }
@ -896,7 +842,6 @@ int get_miniserver_stopsock( MiniServerSockArray * out )
if (miniStopSockPort <= 0) { if (miniStopSockPort <= 0) {
shutdown(miniServerStopSock, SD_BOTH); shutdown(miniServerStopSock, SD_BOTH);
UpnpCloseSocket(miniServerStopSock); UpnpCloseSocket(miniServerStopSock);
return UPNP_E_INTERNAL_ERROR; return UPNP_E_INTERNAL_ERROR;
} }
@ -907,29 +852,10 @@ int get_miniserver_stopsock( MiniServerSockArray * out )
} }
/************************************************************************ int StartMiniServer(
* Function: StartMiniServer /*! [in,out] Port on which the server listens for incoming IPv4 connections. */
* unsigned short *listen_port4,
* Parameters: /*! [in,out] Port on which the server listens for incoming IPv6 connections. */
* IN OUT unsigned short *listen_port4 ; Port on which the server
* listens for incoming IPv4 connections.
* IN OUT unsigned short *listen_port6 ; Port on which the server
* listens for incoming IPv6 connections.
*
* Description: Initialize the sockets functionality for the
* Miniserver. Initialize a thread pool job to run the MiniServer
* and the job to the thread pool. If listen port is 0, port is
* dynamically picked
*
* Use timer mechanism to start the MiniServer, failure to meet the
* allowed delay aborts the attempt to launch the MiniServer.
*
* Return: int;
* On success: UPNP_E_SUCCESS
* On error: PNP_E_XXX
************************************************************************/
int
StartMiniServer( unsigned short* listen_port4,
unsigned short *listen_port6) unsigned short *listen_port6)
{ {
int ret_code; int ret_code;
@ -968,7 +894,6 @@ StartMiniServer( unsigned short* listen_port4,
UpnpCloseSocket(miniSocket->miniServerSock6); UpnpCloseSocket(miniSocket->miniServerSock6);
#endif #endif
free(miniSocket); free(miniSocket);
return ret_code; return ret_code;
} }
@ -984,14 +909,12 @@ StartMiniServer( unsigned short* listen_port4,
shutdown(miniSocket->miniServerStopSock, SD_BOTH); shutdown(miniSocket->miniServerStopSock, SD_BOTH);
UpnpCloseSocket(miniSocket->miniServerStopSock); UpnpCloseSocket(miniSocket->miniServerStopSock);
free(miniSocket); free(miniSocket);
return ret_code; return ret_code;
} }
TPJobInit(&job, (start_routine)RunMiniServer, (void *)miniSocket); TPJobInit(&job, (start_routine)RunMiniServer, (void *)miniSocket);
TPJobSetPriority(&job, MED_PRIORITY); TPJobSetPriority(&job, MED_PRIORITY);
TPJobSetFreeFunction(&job, (free_routine)free); TPJobSetFreeFunction(&job, (free_routine)free);
ret_code = ThreadPoolAddPersistent(&gMiniServerThreadPool, &job, NULL); ret_code = ThreadPoolAddPersistent(&gMiniServerThreadPool, &job, NULL);
if (ret_code < 0) { if (ret_code < 0) {
#ifdef INTERNAL_WEB_SERVER #ifdef INTERNAL_WEB_SERVER
@ -1012,7 +935,6 @@ StartMiniServer( unsigned short* listen_port4,
shutdown(miniSocket->ssdpReqSock6, SD_BOTH ); shutdown(miniSocket->ssdpReqSock6, SD_BOTH );
UpnpCloseSocket(miniSocket->ssdpReqSock6 ); UpnpCloseSocket(miniSocket->ssdpReqSock6 );
#endif #endif
return UPNP_E_OUTOF_MEMORY; return UPNP_E_OUTOF_MEMORY;
} }
// wait for miniserver to start // wait for miniserver to start
@ -1042,7 +964,6 @@ StartMiniServer( unsigned short* listen_port4,
shutdown(miniSocket->ssdpReqSock6, SD_BOTH); shutdown(miniSocket->ssdpReqSock6, SD_BOTH);
UpnpCloseSocket(miniSocket->ssdpReqSock6); UpnpCloseSocket(miniSocket->ssdpReqSock6);
#endif #endif
return UPNP_E_INTERNAL_ERROR; return UPNP_E_INTERNAL_ERROR;
} }
#ifdef INTERNAL_WEB_SERVER #ifdef INTERNAL_WEB_SERVER
@ -1053,21 +974,8 @@ StartMiniServer( unsigned short* listen_port4,
return UPNP_E_SUCCESS; return UPNP_E_SUCCESS;
} }
/************************************************************************
* Function: StopMiniServer int StopMiniServer()
*
* Parameters:
* void
*
* Description:
* Stop and Shutdown the MiniServer and free socket
* resources.
*
* Return: int
* Always returns 0
************************************************************************/
int
StopMiniServer()
{ {
char errorBuffer[ERROR_BUFFER_LEN]; char errorBuffer[ERROR_BUFFER_LEN];
int socklen = sizeof (struct sockaddr_in); int socklen = sizeof (struct sockaddr_in);
@ -1086,7 +994,8 @@ StopMiniServer()
if (sock == -1) { if (sock == -1) {
strerror_r(errno, errorBuffer, ERROR_BUFFER_LEN); strerror_r(errno, errorBuffer, ERROR_BUFFER_LEN);
UpnpPrintf(UPNP_INFO, SSDP, __FILE__, __LINE__, UpnpPrintf(UPNP_INFO, SSDP, __FILE__, __LINE__,
"SSDP_SERVER: StopSSDPServer: Error in socket() %s\n", errorBuffer ); "SSDP_SERVER: StopSSDPServer: Error in socket() %s\n",
errorBuffer);
return 0; return 0;
} }
@ -1094,7 +1003,8 @@ StopMiniServer()
ssdpAddr.sin_family = AF_INET; ssdpAddr.sin_family = AF_INET;
ssdpAddr.sin_addr.s_addr = inet_addr("127.0.0.1"); ssdpAddr.sin_addr.s_addr = inet_addr("127.0.0.1");
ssdpAddr.sin_port = htons(miniStopSockPort); ssdpAddr.sin_port = htons(miniStopSockPort);
sendto( sock, buf, bufLen, 0, (struct sockaddr *)&ssdpAddr, socklen ); sendto(sock, buf, bufLen, 0, (struct sockaddr *)&ssdpAddr,
socklen);
usleep(1000); usleep(1000);
if (gMServState == MSERV_IDLE) { if (gMServState == MSERV_IDLE) {
break; break;

View File

@ -161,11 +161,11 @@ typedef struct NOTIFY_THREAD_STRUCT {
*/ */
EXTERN_C void genaCallback( EXTERN_C void genaCallback(
/*! [in] represents the parse state of the request */ /*! [in] represents the parse state of the request */
IN http_parser_t *parser, http_parser_t *parser,
/*! [in] HTTP message containing GENA request */ /*! [in] HTTP message containing GENA request */
IN http_message_t* request, http_message_t* request,
/*! [in,out] Structure containing information about the socket */ /*! [in,out] Structure containing information about the socket */
IN SOCKINFO *info); SOCKINFO *info);
/*! /*!
@ -181,16 +181,16 @@ EXTERN_C void genaCallback(
#ifdef INCLUDE_CLIENT_APIS #ifdef INCLUDE_CLIENT_APIS
EXTERN_C int genaSubscribe( EXTERN_C int genaSubscribe(
/*! [in] The client handle. */ /*! [in] The client handle. */
IN UpnpClient_Handle client_handle, UpnpClient_Handle client_handle,
/*! [in] Of the form: "http://134.134.156.80:4000/RedBulb/Event */ /*! [in] Of the form: "http://134.134.156.80:4000/RedBulb/Event */
IN const UpnpString *PublisherURL, const UpnpString *PublisherURL,
/*! [in,out] requested Duration: /*! [in,out] requested Duration:
* \li if -1, then "infinite". * \li if -1, then "infinite".
* \li in the OUT case: actual Duration granted by Service, * \li in the OUT case: actual Duration granted by Service,
* -1 for infinite. */ * -1 for infinite. */
INOUT int *TimeOut, int *TimeOut,
/*! [out] sid of subscription, memory passed in by caller. */ /*! [out] sid of subscription, memory passed in by caller. */
OUT UpnpString *out_sid); UpnpString *out_sid);
#endif /* INCLUDE_CLIENT_APIS */ #endif /* INCLUDE_CLIENT_APIS */
@ -207,9 +207,9 @@ EXTERN_C int genaSubscribe(
#ifdef INCLUDE_CLIENT_APIS #ifdef INCLUDE_CLIENT_APIS
EXTERN_C int genaUnSubscribe( EXTERN_C int genaUnSubscribe(
/*! [in] UPnP client handle. */ /*! [in] UPnP client handle. */
IN UpnpClient_Handle client_handle, UpnpClient_Handle client_handle,
/*! [in] The subscription ID. */ /*! [in] The subscription ID. */
IN const UpnpString *in_sid); const UpnpString *in_sid);
#endif /* INCLUDE_CLIENT_APIS */ #endif /* INCLUDE_CLIENT_APIS */
@ -259,12 +259,12 @@ EXTERN_C int genaUnregisterDevice(
#ifdef INCLUDE_CLIENT_APIS #ifdef INCLUDE_CLIENT_APIS
EXTERN_C int genaRenewSubscription( EXTERN_C int genaRenewSubscription(
/*! [in] Client handle. */ /*! [in] Client handle. */
IN UpnpClient_Handle client_handle, UpnpClient_Handle client_handle,
/*! [in] Subscription ID. */ /*! [in] Subscription ID. */
IN const UpnpString *in_sid, const UpnpString *in_sid,
/*! [out] requested Duration, if -1, then "infinite". In the OUT case: /*! [in,out] requested Duration, if -1, then "infinite". In the OUT case:
* actual Duration granted by Service, -1 for infinite. */ * actual Duration granted by Service, -1 for infinite. */
OUT int * TimeOut); int *TimeOut);
#endif /* INCLUDE_CLIENT_APIS */ #endif /* INCLUDE_CLIENT_APIS */
@ -310,7 +310,7 @@ EXTERN_C int genaNotifyAllExt(
/*! [in] Service ID. */ /*! [in] Service ID. */
char *servId, char *servId,
/*! [in] XML document Event varible property set. */ /*! [in] XML document Event varible property set. */
IN IXML_Document *PropSet); IXML_Document *PropSet);
#endif /* INCLUDE_DEVICE_APIS */ #endif /* INCLUDE_DEVICE_APIS */
@ -325,19 +325,19 @@ EXTERN_C int genaNotifyAllExt(
#ifdef INCLUDE_DEVICE_APIS #ifdef INCLUDE_DEVICE_APIS
EXTERN_C int genaInitNotify( EXTERN_C int genaInitNotify(
/*! [in] Device handle. */ /*! [in] Device handle. */
IN UpnpDevice_Handle device_handle, UpnpDevice_Handle device_handle,
/*! [in] Device udn. */ /*! [in] Device udn. */
IN char *UDN, char *UDN,
/*! [in] Service ID. */ /*! [in] Service ID. */
IN char *servId, char *servId,
/*! [in] Array of variable names. */ /*! [in] Array of variable names. */
IN char **VarNames, char **VarNames,
/*! [in] Array of variable values. */ /*! [in] Array of variable values. */
IN char **VarValues, char **VarValues,
/*! [in] Array size. */ /*! [in] Array size. */
IN int var_count, int var_count,
/*! [in] Subscription ID. */ /*! [in] Subscription ID. */
IN const Upnp_SID sid); const Upnp_SID sid);
#endif /* INCLUDE_DEVICE_APIS */ #endif /* INCLUDE_DEVICE_APIS */
@ -354,15 +354,15 @@ EXTERN_C int genaInitNotify(
#ifdef INCLUDE_DEVICE_APIS #ifdef INCLUDE_DEVICE_APIS
EXTERN_C int genaInitNotifyExt( EXTERN_C int genaInitNotifyExt(
/*! [in] Device handle. */ /*! [in] Device handle. */
IN UpnpDevice_Handle device_handle, UpnpDevice_Handle device_handle,
/*! [in] Device udn. */ /*! [in] Device udn. */
IN char *UDN, char *UDN,
/*! [in] Service ID. */ /*! [in] Service ID. */
IN char *servId, char *servId,
/*! [in] Document of the state table. */ /*! [in] Document of the state table. */
IN IXML_Document *PropSet, IXML_Document *PropSet,
/*! [in] subscription ID. */ /*! [in] subscription ID. */
IN const Upnp_SID sid); const Upnp_SID sid);
#endif /* INCLUDE_DEVICE_APIS */ #endif /* INCLUDE_DEVICE_APIS */
@ -374,11 +374,11 @@ EXTERN_C int genaInitNotifyExt(
*/ */
void error_respond( void error_respond(
/*! [in] Structure containing information about the socket. */ /*! [in] Structure containing information about the socket. */
IN SOCKINFO *info, SOCKINFO *info,
/*! [in] error code that will be in the GENA response. */ /*! [in] error code that will be in the GENA response. */
IN int error_code, int error_code,
/*! [in] GENA request Packet. */ /*! [in] GENA request Packet. */
IN http_message_t* hmsg); http_message_t* hmsg);
#endif /* GENA_H */ #endif /* GENA_H */

View File

@ -55,9 +55,9 @@
*/ */
void gena_process_notification_event( void gena_process_notification_event(
/*! [in] Socket info of the device. */ /*! [in] Socket info of the device. */
IN SOCKINFO *info, SOCKINFO *info,
/*! [in] The http message contains the GENA notification. */ /*! [in] The http message contains the GENA notification. */
IN http_message_t *event); http_message_t *event);
#endif /* GENA_CTRLPT_H */ #endif /* GENA_CTRLPT_H */

View File

@ -48,9 +48,9 @@
*/ */
void gena_process_subscription_request( void gena_process_subscription_request(
/*! [in] Socket info of the device. */ /*! [in] Socket info of the device. */
IN SOCKINFO *info, SOCKINFO *info,
/*! [in] Subscription request from the control point. */ /*! [in] Subscription request from the control point. */
IN http_message_t *request); http_message_t *request);
/*! /*!
@ -59,9 +59,9 @@ void gena_process_subscription_request(
*/ */
void gena_process_subscription_renewal_request( void gena_process_subscription_renewal_request(
/*! [in] Socket info of the device. */ /*! [in] Socket info of the device. */
IN SOCKINFO *info, SOCKINFO *info,
/*! [in] Subscription renewal request from the control point. */ /*! [in] Subscription renewal request from the control point. */
IN http_message_t *request); http_message_t *request);
/*! /*!
@ -70,9 +70,9 @@ void gena_process_subscription_renewal_request(
*/ */
void gena_process_unsubscribe_request( void gena_process_unsubscribe_request(
/*! [in] Socket info of the device. */ /*! [in] Socket info of the device. */
IN SOCKINFO *info, SOCKINFO *info,
/*! [in] UNSUBSCRIBE request from the control point. */ /*! [in] UNSUBSCRIBE request from the control point. */
IN http_message_t *request); http_message_t *request);
#endif /* GENA_DEVICE_H */ #endif /* GENA_DEVICE_H */

View File

@ -70,81 +70,62 @@ typedef void (*MiniServerCallback)(
extern "C" { extern "C" {
#endif #endif
/************************************************************************
* Function: SetHTTPGetCallback
*
* Parameters:
* MiniServerCallback callback; - HTTP Callback to be invoked
*
* Description: Set HTTP Get Callback
*
* Return: void
************************************************************************/
void SetHTTPGetCallback( MiniServerCallback callback );
/************************************************************************ /*!
* Function: SetSoapCallback * \brief Set HTTP Get Callback.
* */
* Parameters: void SetHTTPGetCallback(
* MiniServerCallback callback; - SOAP Callback to be invoked /*! [in] HTTP Callback to be invoked . */
* MiniServerCallback callback);
* Description: Set SOAP Callback
*
* Return: void /*!
************************************************************************/ * \brief Set SOAP Callback.
*/
#ifdef INCLUDE_DEVICE_APIS #ifdef INCLUDE_DEVICE_APIS
void SetSoapCallback( MiniServerCallback callback ); void SetSoapCallback(
/*! [in] SOAP Callback to be invoked . */
MiniServerCallback callback);
#else /* INCLUDE_DEVICE_APIS */ #else /* INCLUDE_DEVICE_APIS */
static inline void SetSoapCallback(MiniServerCallback callback) {} static inline void SetSoapCallback(MiniServerCallback callback) {}
#endif /* INCLUDE_DEVICE_APIS */ #endif /* INCLUDE_DEVICE_APIS */
/************************************************************************
* Function: SetGenaCallback
*
* Parameters:
* MiniServerCallback callback; - GENA Callback to be invoked
*
* D6escription: Set GENA Callback
*
* Return: void
************************************************************************/
void SetGenaCallback( MiniServerCallback callback );
/************************************************************************ /*!
* Function: StartMiniServer * \brief Set GENA Callback.
*/
void SetGenaCallback(
/*! [in] GENA Callback to be invoked. */
MiniServerCallback callback);
/*!
* \brief Initialize the sockets functionality for the Miniserver.
* *
* Parameters: * Initialize a thread pool job to run the MiniServer and the job to the
* IN OUT unsigned short *listen_port4 ; Port on which the server * thread pool.
* listens for incoming IPv4 connections.
* IN OUT unsigned short *listen_port6 ; Port on which the server
* listens for incoming IPv6 connections.
* *
* Description: Initialize the sockets functionality for the * If listen port is 0, port is dynamically picked.
* Miniserver. Initialize a thread pool job to run the MiniServer
* and the job to the thread pool. If listen port is 0, port is
* dynamically picked
* *
* Use timer mechanism to start the MiniServer, failure to meet the * Use timer mechanism to start the MiniServer, failure to meet the
* allowed delay aborts the attempt to launch the MiniServer. * allowed delay aborts the attempt to launch the MiniServer.
* *
* Return: int; * \return
* On success: UPNP_E_SUCCESS * \li On success: UPNP_E_SUCCESS.
* On error: UPNP_E_XXX * \li On error: UPNP_E_XXX.
************************************************************************/ */
int StartMiniServer( IN OUT unsigned short* listen_port4, int StartMiniServer(
IN OUT unsigned short* listen_port6 ); /*! [in,out] Port on which the server listens for incoming IPv4 connections. */
unsigned short *listen_port4,
/*! [in,out] Port on which the server listens for incoming IPv6 connections. */
unsigned short *listen_port6);
/************************************************************************
* Function: StopMiniServer /*!
* \brief Stop and Shutdown the MiniServer and free socket resources.
* *
* Parameters: * \return Always returns 0.
* void; */
*
* Description: Stop and Shutdown the MiniServer and free socket resources.
*
* Return : int;
* Always returns 0
************************************************************************/
int StopMiniServer(); int StopMiniServer();