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;
/*! 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
* is valid only during the callback and should be copied if it
* 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
* 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 */
@ -1037,7 +1044,7 @@ EXPORT_SPEC int UpnpRegisterRootDevice2(
* the description is served using the internal web server. */
int config_baseURL,
/*! [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
* invoked. */
const void* Cookie,
@ -1224,6 +1231,10 @@ EXPORT_SPEC int UpnpSetMaxContentLength(
* matching root device, device, or service. The application specifies the
* 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
* instance issued a particular search. Therefore, the client can get
* search callbacks that do not match the original criteria of the search.
@ -1237,17 +1248,17 @@ EXPORT_SPEC int UpnpSetMaxContentLength(
*/
EXPORT_SPEC int UpnpSearchAsync(
/*! 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
* 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
* \c MIN_SEARCH_TIME. */
IN int Mx,
int Mx,
/*! The search target as defined in the UPnP Device Architecture v1.0
* specification. */
IN const char *Target,
const char *TTarget_constarget_const,
/*! 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
@ -1266,9 +1277,9 @@ EXPORT_SPEC int UpnpSearchAsync(
*/
EXPORT_SPEC int UpnpSendAdvertisement(
/*! 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. */
IN int Exp);
int Exp);
/* @} Discovery */
@ -1316,16 +1327,16 @@ EXPORT_SPEC int UpnpSendAdvertisement(
* according to the device.
*/
EXPORT_SPEC int UpnpGetServiceVarStatus(
/*! The handle of the control point. */
IN UpnpClient_Handle Hnd,
/*! The URL of the service. */
IN const char *ActionURL,
/*! The name of the variable to query. */
IN const char *VarName,
/*! The pointer to store the value for \b VarName. The SDK allocates
/*! [in] The handle of the control point. */
UpnpClient_Handle Hnd,
/*! [in] The URL of the service. */
const char *ActionURL,
/*! [in] The name of the variable to query. */
const char *VarName,
/*! [out] The pointer to store the value for \b VarName. The SDK allocates
* this string and the caller needs to free it using
* \b ixmlFreeDOMString. */
OUT DOMString *StVarVal);
DOMString *StVarVal);
/*!
@ -1346,17 +1357,17 @@ EXPORT_SPEC int UpnpGetServiceVarStatus(
* complete this operation.
*/
EXPORT_SPEC int UpnpGetServiceVarStatusAsync(
/*! The handle of the control point. */
IN UpnpClient_Handle Hnd,
/*! The URL of the service. */
IN const char *ActionURL,
/*! The name of the variable to query. */
IN const char *VarName,
/*! Pointer to a callback function to be invoked when the operation
/*! [in] The handle of the control point. */
UpnpClient_Handle Hnd,
/*! [in] The URL of the service. */
const char *ActionURL,
/*! [in] The name of the variable to query. */
const char *VarName,
/*! [in] Pointer to a callback function to be invoked when the operation
* is complete. */
IN Upnp_FunPtr Fun,
/*! Pointer to user data to pass to the callback function when invoked. */
IN const void *Cookie);
Upnp_FunPtr Fun,
/*! [in] Pointer to user data to pass to the callback function when invoked. */
const void *Cookie);
/*!
@ -1383,19 +1394,19 @@ EXPORT_SPEC int UpnpGetServiceVarStatusAsync(
* complete this operation.
*/
EXPORT_SPEC int UpnpSendAction(
/*! The handle of the control point sending the action. */
IN UpnpClient_Handle Hnd,
/*! The action URL of the service. */
IN const char *ActionURL,
/*! The type of the service. */
IN const char *ServiceType,
/*! This parameter is ignored and must be \c NULL. */
IN const char *DevUDN,
/*! The DOM document for the action. */
IN IXML_Document *Action,
/*! The DOM document for the response to the action. The SDK allocates
/*! [in] The handle of the control point sending the action. */
UpnpClient_Handle Hnd,
/*! [in] The action URL of the service. */
const char *ActionURL,
/*! [in] The type of the service. */
const char *ServiceType,
/*! [in] This parameter is ignored and must be \c NULL. */
const char *DevUDN,
/*! [in] The DOM document for the action. */
IXML_Document *Action,
/*! [out] The DOM document for the response to the action. The SDK allocates
* 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.
*/
EXPORT_SPEC int UpnpSendActionEx(
/*! The handle of the control point sending the action. */
IN UpnpClient_Handle Hnd,
/*! The action URL of the service. */
IN const char *ActionURL,
/*! The type of the service. */
IN const char *ServiceType,
/*! This parameter is ignored and must be \c NULL. */
IN const char *DevUDN,
/*! The DOM document for the SOAP header. This may be \c NULL if the
/*! [in] The handle of the control point sending the action. */
UpnpClient_Handle Hnd,
/*! [in] The action URL of the service. */
const char *ActionURL,
/*! [in] The type of the service. */
const char *ServiceType,
/*! [in] This parameter is ignored and must be \c NULL. */
const char *DevUDN,
/*! [in] The DOM document for the SOAP header. This may be \c NULL if the
* header is not required. */
IN IXML_Document *Header,
/*! The DOM document for the action. */
IN IXML_Document *Action,
/*! The DOM document for the response to the action. The SDK allocates
IXML_Document *Header,
/*! [in] The DOM document for the action. */
IXML_Document *Action,
/*! [out] The DOM document for the response to the action. The SDK allocates
* 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.
*/
EXPORT_SPEC int UpnpSendActionAsync(
/*! The handle of the control point sending the action. */
IN UpnpClient_Handle Hnd,
/*! The action URL of the service. */
IN const char *ActionURL,
/*! The type of the service. */
IN const char *ServiceType,
/*! This parameter is ignored and must be \c NULL. */
IN const char *DevUDN,
/*! The DOM document for the action to perform on this device. */
IN IXML_Document *Action,
/*! Pointer to a callback function to be invoked when the operation
/*! [in] The handle of the control point sending the action. */
UpnpClient_Handle Hnd,
/*! [in] The action URL of the service. */
const char *ActionURL,
/*! [in] The type of the service. */
const char *ServiceType,
/*! [in] This parameter is ignored and must be \c NULL. */
const char *DevUDN,
/*! [in] The DOM document for the action to perform on this device. */
IXML_Document *Action,
/*! [in] Pointer to a callback function to be invoked when the operation
* completes. */
IN Upnp_FunPtr Fun,
/*! Pointer to user data that to be passed to the callback when
Upnp_FunPtr Fun,
/*! [in] Pointer to user data that to be passed to the callback when
* invoked. */
IN const void *Cookie);
const void *Cookie);
/*!
@ -1502,28 +1513,30 @@ EXPORT_SPEC int UpnpSendActionAsync(
* complete this operation.
*/
EXPORT_SPEC int UpnpSendActionExAsync(
/*! The handle of the control point sending the action. */
IN UpnpClient_Handle Hnd,
/*! The action URL of the service. */
IN const char *ActionURL,
/*! The type of the service. */
IN const char *ServiceType,
/*! This parameter is ignored and must be \c NULL. */
IN const char *DevUDN,
/*! The DOM document for the SOAP header. This may be \c NULL if the
/*! [in] The handle of the control point sending the action. */
UpnpClient_Handle Hnd,
/*! [in] The action URL of the service. */
const char *ActionURL,
/*! [in] The type of the service. */
const char *ServiceType,
/*! [in] This parameter is ignored and must be \c NULL. */
const char *DevUDN,
/*! [in] The DOM document for the SOAP header. This may be \c NULL if the
* header is not required. */
IN IXML_Document *Header,
/*! The DOM document for the action to perform on this device. */
IN IXML_Document *Action,
/*! Pointer to a callback function to be invoked when the operation
IXML_Document *Header,
/*! [in] The DOM document for the action to perform on this device. */
IXML_Document *Action,
/*! [in] Pointer to a callback function to be invoked when the operation
* completes. */
IN Upnp_FunPtr Fun,
/*! Pointer to user data that to be passed to the callback when
Upnp_FunPtr Fun,
/*! [in] Pointer to user data that to be passed to the callback when
* invoked. */
IN const void *Cookie);
const void *Cookie);
/*! @} Control */
/******************************************************************************
******************************************************************************
* *
@ -1564,20 +1577,20 @@ EXPORT_SPEC int UpnpSendActionExAsync(
* complete this operation.
*/
EXPORT_SPEC int UpnpAcceptSubscription(
/*! The handle of the device. */
IN UpnpDevice_Handle Hnd,
/*! The device ID of the subdevice of the service generating the event. */
IN const char *DevID,
/*! The unique service identifier of the service generating the event. */
IN const char *ServID,
/*! Pointer to an array of event variables. */
IN const char **VarName,
/*! Pointer to an array of values for the event variables. */
IN const char **NewVal,
/*! The number of event variables in \b VarName. */
IN int cVariables,
/*! The subscription ID of the newly registered control point. */
IN const Upnp_SID SubsId);
/*! [in] The handle of the device. */
UpnpDevice_Handle Hnd,
/*! [in] The device ID of the subdevice of the service generating the event. */
const char *DevID,
/*! [in] The unique service identifier of the service generating the event. */
const char *ServID,
/*! [in] Pointer to an array of event variables. */
const char **VarName,
/*! [in] Pointer to an array of values for the event variables. */
const char **NewVal,
/*! [in] The number of event variables in \b VarName. */
int cVariables,
/*! [in] The subscription ID of the newly registered control point. */
const Upnp_SID SubsId);
/*!
@ -1604,18 +1617,18 @@ EXPORT_SPEC int UpnpAcceptSubscription(
* complete this operation.
*/
EXPORT_SPEC int UpnpAcceptSubscriptionExt(
/*! The handle of the device. */
IN UpnpDevice_Handle Hnd,
/*! The device ID of the subdevice of the service generating the event. */
IN const char *DevID,
/*! The unique service identifier of the service generating the event. */
IN const char *ServID,
/*! The DOM document for the property set. Property set documents must
/*! [in] The handle of the device. */
UpnpDevice_Handle Hnd,
/*! [in] The device ID of the subdevice of the service generating the event. */
const char *DevID,
/*! [in] The unique service identifier of the service generating the event. */
const char *ServID,
/*! [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
* Plug and Play Device Architecture specification. */
IN IXML_Document *PropSet,
/*! The subscription ID of the newly registered control point. */
IN Upnp_SID SubsId);
IXML_Document *PropSet,
/*! [in] The subscription ID of the newly registered control point. */
Upnp_SID SubsId);
/*!
@ -1640,18 +1653,18 @@ EXPORT_SPEC int UpnpAcceptSubscriptionExt(
* complete this operation.
*/
EXPORT_SPEC int UpnpNotify(
/*! The handle to the device sending the event. */
IN UpnpDevice_Handle,
/*! The device ID of the subdevice of the service generating the event. */
IN const char *DevID,
/*! The unique identifier of the service generating the event. */
IN const char *ServID,
/*! Pointer to an array of variables that have changed. */
IN const char **VarName,
/*! Pointer to an array of new values for those variables. */
IN const char **NewVal,
/*! The count of variables included in this notification. */
IN int cVariables);
/*! [in] The handle to the device sending the event. */
UpnpDevice_Handle,
/*! [in] The device ID of the subdevice of the service generating the event. */
const char *DevID,
/*! [in] The unique identifier of the service generating the event. */
const char *ServID,
/*! [in] Pointer to an array of variables that have changed. */
const char **VarName,
/*! [in] Pointer to an array of new values for those variables. */
const char **NewVal,
/*! [in] The count of variables included in this notification. */
int cVariables);
/*!
@ -1676,16 +1689,16 @@ EXPORT_SPEC int UpnpNotify(
* complete this operation.
*/
EXPORT_SPEC int UpnpNotifyExt(
/*! The handle to the device sending the event. */
IN UpnpDevice_Handle,
/*! The device ID of the subdevice of the service generating the event. */
IN const char *DevID,
/*! The unique identifier of the service generating the event. */
IN const char *ServID,
/*! The DOM document for the property set. Property set documents must
/*! [in] The handle to the device sending the event. */
UpnpDevice_Handle,
/*! [in] The device ID of the subdevice of the service generating the event. */
const char *DevID,
/*! [in] The unique identifier of the service generating the event. */
const char *ServID,
/*! [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
* Plug and Play Device Architecture specification. */
IN IXML_Document *PropSet);
IXML_Document *PropSet);
/*!
@ -1717,13 +1730,13 @@ EXPORT_SPEC int UpnpNotifyExt(
* complete this operation.
*/
EXPORT_SPEC int UpnpRenewSubscription(
/*! The handle of the control point that is renewing the subscription. */
IN UpnpClient_Handle Hnd,
/*! Pointer to a variable containing the requested subscription time.
/*! [in] The handle of the control point that is renewing the subscription. */
UpnpClient_Handle Hnd,
/*! [in,out] Pointer to a variable containing the requested subscription time.
* Upon return, it contains the actual renewal time. */
INOUT int *TimeOut,
/*! The ID for the subscription to renew. */
IN const Upnp_SID SubsId);
int *TimeOut,
/*! [in] The ID for the subscription to renew. */
const Upnp_SID SubsId);
/*!
@ -1774,18 +1787,18 @@ EXPORT_SPEC int UpnpRenewSubscription(
* UpnpEventSubscribe.ErrCode field as part of the callback).
*/
EXPORT_SPEC int UpnpRenewSubscriptionAsync(
/*! The handle of the control point that is renewing the subscription. */
IN UpnpClient_Handle Hnd,
/*! The requested subscription time. The actual timeout value is
/*! [in] The handle of the control point that is renewing the subscription. */
UpnpClient_Handle Hnd,
/*! [in] The requested subscription time. The actual timeout value is
* returned when the callback function is called. */
IN int TimeOut,
/*! The ID for the subscription to renew. */
IN Upnp_SID SubsId,
/*! Pointer to a callback function to be invoked when the renewal is
int TimeOut,
/*! [in] The ID for the subscription to renew. */
Upnp_SID SubsId,
/*! [in] Pointer to a callback function to be invoked when the renewal is
* complete. */
IN Upnp_FunPtr Fun,
/*! Pointer to user data passed to the callback function when invoked. */
IN const void *Cookie);
Upnp_FunPtr Fun,
/*! [in] Pointer to user data passed to the callback function when invoked. */
const void *Cookie);
/*!
@ -1804,9 +1817,9 @@ EXPORT_SPEC int UpnpRenewSubscriptionAsync(
EXPORT_SPEC int UpnpSetMaxSubscriptions(
/*! The handle of the device for which the maximum number of
* subscriptions is being set. */
IN UpnpDevice_Handle Hnd,
UpnpDevice_Handle Hnd,
/*! 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(
/*! The handle of the device for which the maximum subscription
* time-out is being set. */
IN UpnpDevice_Handle Hnd,
UpnpDevice_Handle Hnd,
/*! The maximum subscription time-out to be accepted. */
IN int MaxSubscriptionTimeOut);
int MaxSubscriptionTimeOut);
/*!
@ -1861,16 +1874,16 @@ EXPORT_SPEC int UpnpSetMaxSubscriptionTimeOut(
* complete this operation.
*/
EXPORT_SPEC int UpnpSubscribe(
/*! The handle of the control point. */
IN UpnpClient_Handle Hnd,
/*! The URL of the service to subscribe to. */
IN const char *PublisherUrl,
/*! Pointer to a variable containing the requested subscription time.
/*! [in] The handle of the control point. */
UpnpClient_Handle Hnd,
/*! [in] The URL of the service to subscribe to. */
const char *PublisherUrl,
/*! [in,out]Pointer to a variable containing the requested subscription time.
* Upon return, it contains the actual subscription time returned from
* the service. */
INOUT int *TimeOut,
/*! Pointer to a variable to receive the subscription ID (SID). */
OUT Upnp_SID SubsId);
int *TimeOut,
/*! [out] Pointer to a variable to receive the subscription ID (SID). */
Upnp_SID SubsId);
/*!
@ -1923,16 +1936,16 @@ EXPORT_SPEC int UpnpSubscribe(
*/
EXPORT_SPEC int UpnpSubscribeAsync(
/*! The handle of the control point that is subscribing. */
IN UpnpClient_Handle Hnd,
UpnpClient_Handle Hnd,
/*! 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
* subscription time returned from the service. */
IN int TimeOut,
int TimeOut,
/*! 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. */
IN const void *Cookie);
const void *Cookie);
/*!
@ -1965,10 +1978,10 @@ EXPORT_SPEC int UpnpSubscribeAsync(
* complete this operation.
*/
EXPORT_SPEC int UpnpUnSubscribe(
/*! The handle of the subscribed control point. */
IN UpnpClient_Handle Hnd,
/*! The ID returned when the control point subscribed to the service. */
IN const Upnp_SID SubsId);
/*! [in] The handle of the subscribed control point. */
UpnpClient_Handle Hnd,
/*! [in] The ID returned when the control point subscribed to the service. */
const Upnp_SID SubsId);
/*!
@ -2018,15 +2031,15 @@ EXPORT_SPEC int UpnpUnSubscribe(
* <b>UpnpEventSubscribe.ErrCode</b> field as part of the callback).
*/
EXPORT_SPEC int UpnpUnSubscribeAsync(
/*! The handle of the subscribed control point. */
IN UpnpClient_Handle Hnd,
/*! The ID returned when the control point subscribed to the service. */
IN Upnp_SID SubsId,
/*! Pointer to a callback function to be called when the operation is
/*! [in] The handle of the subscribed control point. */
UpnpClient_Handle Hnd,
/*! [in] The ID returned when the control point subscribed to the service. */
Upnp_SID SubsId,
/*! [in] Pointer to a callback function to be called when the operation is
* complete. */
IN Upnp_FunPtr Fun,
/*! Pointer to user data to pass to the callback function when invoked. */
IN const void *Cookie);
Upnp_FunPtr Fun,
/*! [in] Pointer to user data to pass to the callback function when invoked. */
const void *Cookie);
/*! @} Eventing */
@ -2470,10 +2483,10 @@ typedef void *UpnpWebFileHandle;
* \brief Get-info callback function prototype.
*/
typedef int (*VDCallback_GetInfo)(
/*! The name of the file to query. */
IN const char *filename,
/*! Pointer to a structure to store the information on the file. */
OUT UpnpFileInfo *info);
/*! [in] The name of the file to query. */
const char *filename,
/*! [out] Pointer to a structure to store the information on the file. */
UpnpFileInfo *info);
/*!
* \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.
*/
typedef UpnpWebFileHandle (*VDCallback_Open)(
/*! The name of the file to open. */
IN const char *filename,
/*! The mode in which to open the file.
/*! [in] The name of the file to open. */
const char *filename,
/*! [in] The mode in which to open the file.
* 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.
*/
typedef int (*VDCallback_Read)(
/*! The handle of the file to read. */
IN UpnpWebFileHandle fileHnd,
/*! The buffer in which to place the data. */
OUT char *buf,
/*! The size of the buffer (i.e. the number of bytes to read). */
IN size_t buflen);
/*! [in] The handle of the file to read. */
UpnpWebFileHandle fileHnd,
/*! [out] The buffer in which to place the data. */
char *buf,
/*! [in] The size of the buffer (i.e. the number of bytes to read). */
size_t buflen);
/*!
@ -2535,12 +2548,12 @@ EXPORT_SPEC int UpnpVirtualDir_set_ReadCallback(VDCallback_Read callback);
* \brief Write callback function prototype.
*/
typedef int (*VDCallback_Write)(
/*! The handle of the file to write. */
IN UpnpWebFileHandle fileHnd,
/*! The buffer with the bytes to write. */
IN char *buf,
/*! The number of bytes to write. */
IN size_t buflen);
/*! [in] The handle of the file to write. */
UpnpWebFileHandle fileHnd,
/*! [in] The buffer with the bytes to write. */
char *buf,
/*! [in] The number of bytes to write. */
size_t buflen);
/*!
@ -2558,17 +2571,17 @@ EXPORT_SPEC int UpnpVirtualDir_set_WriteCallback(VDCallback_Write callback);
* \brief Seek callback function prototype.
*/
typedef int (*VDCallback_Seek) (
/*! The handle of the file to move the file pointer. */
IN UpnpWebFileHandle fileHnd,
/*! The number of bytes to move in the file. Positive values
/*! [in] The handle of the file to move the file pointer. */
UpnpWebFileHandle fileHnd,
/*! [in] The number of bytes to move in the file. Positive values
* move foward and negative values move backward. Note that
* this must be positive if the \b origin is \c SEEK_SET. */
IN off_t offset,
/*! The position to move relative to. It can be \c SEEK_CUR
off_t offset,
/*! [in] The position to move relative to. It can be \c SEEK_CUR
* to move relative to the current position, \c SEEK_END to
* move relative to the end of the file, or \c SEEK_SET to
* 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.
*/
typedef int (*VDCallback_Close)(
/*! The handle of the file to close. */
IN UpnpWebFileHandle fileHnd);
/*! [in] The handle of the file to close. */
UpnpWebFileHandle fileHnd);
/*!

View File

@ -101,50 +101,36 @@ typedef enum Upnp_LogLevel_e {
/***************************************************************************
* Function : UpnpInitLog
/*!
* \brief Initialize the log files.
*
* Parameters: void
*
* Description:
* This functions initializes the log files
*
* Returns: int
* -1 : If fails
* UPNP_E_SUCCESS : if success
***************************************************************************/
* \return -1 if fails or UPNP_E_SUCCESS if succeeds.
*/
#ifdef DEBUG
int UpnpInitLog();
#else
static UPNP_INLINE int UpnpInitLog() { return UPNP_E_SUCCESS; }
static UPNP_INLINE int UpnpInitLog()
{
return UPNP_E_SUCCESS;
}
#endif
/***************************************************************************
* Function : UpnpSetLogLevel
*
* Parameters: Upnp_LogLevel log_level
*
* Description:
* This functions set the log level (see \c Upnp_LogLevel)
* Returns: void
***************************************************************************/
/*!
* \brief Set the log level (see \c Upnp_LogLevel).
*/
#ifdef DEBUG
void UpnpSetLogLevel(Upnp_LogLevel log_level);
void UpnpSetLogLevel(
/*! [in] Log level. */
Upnp_LogLevel log_level);
#else
static UPNP_INLINE void UpnpSetLogLevel(Upnp_LogLevel log_level) {}
#endif
/***************************************************************************
* Function : UpnpCloseLog
*
* Parameters: void
*
* Description:
* This functions closes the log files
* Returns: void
***************************************************************************/
/*!
* \brief Closes the log files.
*/
#ifdef DEBUG
void UpnpCloseLog();
#else
@ -152,23 +138,14 @@ static UPNP_INLINE void UpnpCloseLog() {}
#endif
/***************************************************************************
* 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
***************************************************************************/
/*!
* \brief Set the name for error and information files, respectively.
*/
#ifdef DEBUG
void UpnpSetLogFileNames(
/*! [in] Name of the error file. */
const char *ErrFileName,
/*! [in] Name of the information file. */
const char *InfoFileName);
#else
static UPNP_INLINE void UpnpSetLogFileNames(
@ -177,24 +154,20 @@ static UPNP_INLINE void UpnpSetLogFileNames(
#endif
/***************************************************************************
* Function : UpnpGetDebugFile
/*!
* \brief Check if the module is turned on for debug and returns the file
* descriptor corresponding to the debug level
*
* 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
***************************************************************************/
* \return NULL if the module is turn off for debug otheriwse returns the
* right file descriptor.
*/
#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
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
/***************************************************************************
* Function : DebugAtThisLevel
/*!
* \brief Returns true if debug output should be done in this module.
*
* 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 functions returns true if debug output should be done in this
* module.
*
* Returns: int
***************************************************************************/
* \return Nonzero value if true, zero if false.
*/
#ifdef DEBUG
int DebugAtThisLevel(
IN Upnp_LogLevel DLevel,
IN Dbg_Module Module);
/*! [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 DLevel,
/*! [in] Debug will go in the name of this module. */
Dbg_Module Module);
#else
static UPNP_INLINE int DebugAtThisLevel(
IN Upnp_LogLevel DLevel,
IN Dbg_Module Module) { return 0; }
Upnp_LogLevel DLevel,
Dbg_Module Module)
{
return 0;
}
#endif
/*!
* \brief Prints the debug statement either on the standard output or log file
* along with the information from where this debug statement is coming.
**/
*/
#ifdef DEBUG
void UpnpPrintf(
/*! [in] The level of the debug logging. It will decide whether debug
@ -261,28 +230,23 @@ static UPNP_INLINE void UpnpPrintf(
const char* DbgFileName,
int DbgLineNo,
const char* FmtStr,
...) {}
...)
{
}
#endif /* DEBUG */
/***************************************************************************
* 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
***************************************************************************/
/*!
* \brief Writes the file name and file number from where debug statement is
* coming to the log file.
*/
#ifdef DEBUG
void UpnpDisplayFileAndLine(
/*! [in] File descriptor where line number and file name will be written. */
FILE *fd,
/*! [in] Name of the file. */
const char *DbgFileName,
/*! [in] Line number of the file. */
int DbgLineNo);
#else
static UPNP_INLINE void UpnpDisplayFileAndLine(
@ -292,18 +256,18 @@ static UPNP_INLINE void UpnpDisplayFileAndLine(
#endif
/*! \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
/*!
* \brief Writes the buffer in the file as per the requested banner
*/
#ifdef DEBUG
void UpnpDisplayBanner(
/*! [in] file descriptor where the banner will be written. */
FILE *fd,
/*! [in] The buffer that will be written. */
const char **lines,
/*! [in] Size of the buffer. */
size_t size,
/*! [in] This parameter provides the width of the banner. */
int starlength);
#else
static UPNP_INLINE void UpnpDisplayBanner(
@ -314,27 +278,27 @@ static UPNP_INLINE void UpnpDisplayBanner(
#endif
/*! \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.
/*!
* \brief Prints thread pool statistics.
*/
#ifdef DEBUG
void PrintThreadPoolStats(
/* [in] The thread pool. */
ThreadPool *tp,
/* [in] The file name that called this function, use the macro __FILE__. */
const char *DbgFileName,
/* [in] The line number that the function was called, use the macro __LINE__. */
int DbgLineNo,
/* [in] The message. */
const char *msg);
#else
static UPNP_INLINE void PrintThreadPoolStats(
ThreadPool *tp,
const char *DbgFileName,
int DbgLineNo,
const char *msg) {}
const char *msg)
{
}
#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;
// Global log level
/*! Global 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;
//File handle for the information log file
/*! File handle for the information log file */
static FILE *InfoFileHnd = NULL;
//Name of the error file
/*! Name of the error file */
static const char *errFileName = "IUpnpErrFile.txt";
//Name of the info file
/*! Name of the info file */
static const char *infoFileName = "IUpnpInfoFile.txt";
#ifdef DEBUG
/***************************************************************************
* 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()
int UpnpInitLog()
{
ithread_mutex_init(&GlobalDebugMutex, NULL);
if(DEBUG_TARGET == 1) {
if( ( ErrFileHnd = fopen( errFileName, "a" ) ) == NULL )
if((ErrFileHnd = fopen( errFileName, "a")) == NULL) {
return -1;
if( ( InfoFileHnd = fopen( infoFileName, "a" ) ) == NULL )
}
if((InfoFileHnd = fopen( infoFileName, "a")) == NULL) {
return -1;
}
}
return UPNP_E_SUCCESS;
}
/***************************************************************************
* 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)
void UpnpSetLogLevel(Upnp_LogLevel log_level)
{
g_log_level = log_level;
}
/***************************************************************************
* Function : UpnpCloseLog
*
* Parameters: void
*
* Description:
* This functions closes the log files
* Returns: void
***************************************************************************/
void
UpnpCloseLog()
void UpnpCloseLog()
{
if (DEBUG_TARGET == 1) {
fflush(ErrFileHnd);
@ -153,29 +94,27 @@ UpnpCloseLog()
fclose(InfoFileHnd);
}
ithread_mutex_destroy(&GlobalDebugMutex);
}
#endif // DEBUG
/***************************************************************************
* Function : DebugAtThisLevel
*
* 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 functions returns true if debug output should be done in this
* module.
*
* Returns: int
***************************************************************************/
void UpnpSetLogFileNames(
const char *ErrFileName,
const char *InfoFileName)
{
if (ErrFileName) {
errFileName = ErrFileName;
}
if (InfoFileName) {
infoFileName = InfoFileName;
}
}
#endif /* DEBUG */
#ifdef DEBUG
int DebugAtThisLevel(
IN Upnp_LogLevel DLevel,
IN Dbg_Module Module)
Upnp_LogLevel DLevel,
Dbg_Module Module)
{
int ret = DLevel <= g_log_level;
ret &=
@ -195,11 +134,11 @@ int DebugAtThisLevel(
#ifdef DEBUG
void UpnpPrintf(
IN Upnp_LogLevel DLevel,
IN Dbg_Module Module,
IN const char *DbgFileName,
IN int DbgLineNo,
IN const char *FmtStr,
Upnp_LogLevel DLevel,
Dbg_Module Module,
const char *DbgFileName,
int DbgLineNo,
const char *FmtStr,
...)
{
va_list ArgList;
@ -235,22 +174,6 @@ void UpnpPrintf(
#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
FILE *GetDebugFile(Upnp_LogLevel DLevel, Dbg_Module Module)
{
@ -273,25 +196,11 @@ FILE *GetDebugFile( Upnp_LogLevel DLevel, Dbg_Module Module )
#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
void UpnpDisplayFileAndLine(
IN FILE * fd,
IN const char *DbgFileName,
IN int DbgLineNo)
FILE *fd,
const char *DbgFileName,
int DbgLineNo)
{
#define NLINES 2
#define MAX_LINE_SIZE 512
@ -329,10 +238,10 @@ void UpnpDisplayFileAndLine(
#ifdef DEBUG
void UpnpDisplayBanner(
IN FILE * fd,
IN const char **lines,
IN size_t size,
IN int starLength)
FILE * fd,
const char **lines,
size_t size,
int starLength)
{
int leftMarginLength = 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();
int return_code = UPNP_E_SUCCESS;
@ -430,8 +430,8 @@ exit_function:
#ifdef INCLUDE_CLIENT_APIS
int genaUnSubscribe(
IN UpnpClient_Handle client_handle,
IN const UpnpString *in_sid)
UpnpClient_Handle client_handle,
const UpnpString *in_sid)
{
ClientSubscription *sub = NULL;
int return_code = GENA_SUCCESS;
@ -482,10 +482,10 @@ exit_function:
#ifdef INCLUDE_CLIENT_APIS
int genaSubscribe(
IN UpnpClient_Handle client_handle,
IN const UpnpString *PublisherURL,
INOUT int *TimeOut,
OUT UpnpString *out_sid)
UpnpClient_Handle client_handle,
const UpnpString *PublisherURL,
int *TimeOut,
UpnpString *out_sid)
{
int return_code = GENA_SUCCESS;
ClientSubscription *newSubscription = UpnpClientSubscription_new();
@ -564,9 +564,9 @@ error_handler:
int genaRenewSubscription(
IN UpnpClient_Handle client_handle,
IN const UpnpString *in_sid,
INOUT int *TimeOut)
UpnpClient_Handle client_handle,
const UpnpString *in_sid,
int *TimeOut)
{
int return_code = GENA_SUCCESS;
ClientSubscription *sub = NULL;
@ -662,8 +662,8 @@ exit_function:
void gena_process_notification_event(
IN SOCKINFO *info,
IN http_message_t *event)
SOCKINFO *info,
http_message_t *event)
{
UpnpEvent *event_struct = UpnpEvent_new();
IXML_Document *ChangedVars = NULL;

View File

@ -61,7 +61,7 @@
*/
int genaUnregisterDevice(
/*! [in] Device handle. */
IN UpnpDevice_Handle device_handle)
UpnpDevice_Handle device_handle)
{
int ret = 0;
struct Handle_Info *handle_info;
@ -92,13 +92,13 @@ int genaUnregisterDevice(
*/
static int GeneratePropertySet(
/*! [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 char **values,
char **values,
/*! [in] number of variables. */
IN int count,
int count,
/*! [out] PropertySet node in the string format. */
OUT DOMString *out)
DOMString *out)
{
char *buffer;
int counter = 0;
@ -147,7 +147,7 @@ static int GeneratePropertySet(
*/
static void free_notify_struct(
/*! [in] Notify structure. */
IN notify_thread_struct *input)
notify_thread_struct *input)
{
( *input->reference_count )--;
if( ( *input->reference_count ) == 0 ) {
@ -170,13 +170,13 @@ static void free_notify_struct(
*/
static UPNP_INLINE int notify_send_and_recv(
/*! [in] subscription callback URL (URL of the control point). */
IN uri_type *destination_url,
uri_type *destination_url,
/*! [in] Common HTTP headers. */
IN membuffer *mid_msg,
membuffer *mid_msg,
/*! [in] The evented XML. */
IN char *propertySet,
char *propertySet,
/*! [out] The response from the control point. */
OUT http_parser_t *response)
http_parser_t *response)
{
uri_type url;
int conn_fd;
@ -258,11 +258,11 @@ static UPNP_INLINE int notify_send_and_recv(
*/
static int genaNotify(
/*! [in] Null terminated, includes all headers (including \\r\\n) except SID and SEQ. */
IN char *headers,
char *headers,
/*! [in] The evented XML. */
IN char *propertySet,
char *propertySet,
/*! [in] subscription to be Notified, assumes this is valid for life of function. */
IN subscription *sub)
subscription *sub)
{
int i;
membuffer mid_msg;
@ -326,7 +326,7 @@ static int genaNotify(
*/
static void genaNotifyThread(
/*! [in] notify thread structure containing all the headers and property set info. */
IN void *input)
void *input)
{
subscription *sub;
service_info *service;
@ -406,13 +406,13 @@ static void genaNotifyThread(
int genaInitNotify(
IN UpnpDevice_Handle device_handle,
IN char *UDN,
IN char *servId,
IN char **VarNames,
IN char **VarValues,
IN int var_count,
IN const Upnp_SID sid)
UpnpDevice_Handle device_handle,
char *UDN,
char *servId,
char **VarNames,
char **VarValues,
int var_count,
const Upnp_SID sid)
{
int ret = GENA_SUCCESS;
int line = 0;
@ -574,11 +574,11 @@ ExitFunction:
int genaInitNotifyExt(
IN UpnpDevice_Handle device_handle,
IN char *UDN,
IN char *servId,
IN IXML_Document *PropSet,
IN const Upnp_SID sid)
UpnpDevice_Handle device_handle,
char *UDN,
char *servId,
IXML_Document *PropSet,
const Upnp_SID sid)
{
int ret = GENA_SUCCESS;
int line = 0;
@ -741,10 +741,10 @@ ExitFunction:
int genaNotifyAllExt(
IN UpnpDevice_Handle device_handle,
IN char *UDN,
IN char *servId,
IN IXML_Document *PropSet)
UpnpDevice_Handle device_handle,
char *UDN,
char *servId,
IXML_Document *PropSet)
{
int ret = GENA_SUCCESS;
int line = 0;
@ -891,12 +891,12 @@ ExitFunction:
int genaNotifyAll(
IN UpnpDevice_Handle device_handle,
IN char *UDN,
IN char *servId,
IN char **VarNames,
IN char **VarValues,
IN int var_count )
UpnpDevice_Handle device_handle,
char *UDN,
char *servId,
char **VarNames,
char **VarValues,
int var_count )
{
int ret = GENA_SUCCESS;
int line = 0;
@ -1049,13 +1049,13 @@ ExitFunction:
*/
static int respond_ok(
/*! [in] Socket connection of request. */
IN SOCKINFO *info,
SOCKINFO *info,
/*! [in] Accepted duration. */
IN int time_out,
int time_out,
/*! [in] Accepted subscription. */
IN subscription *sub,
subscription *sub,
/*! [in] Http request. */
IN http_message_t *request)
http_message_t *request)
{
int major;
int minor;
@ -1109,9 +1109,9 @@ static int respond_ok(
*/
static int create_url_list(
/*! [in] . */
IN memptr *url_list,
memptr *url_list,
/*! [out] . */
OUT URL_list *out)
URL_list *out)
{
int URLcount = 0;
int i;
@ -1185,8 +1185,8 @@ static int create_url_list(
void gena_process_subscription_request(
IN SOCKINFO *info,
IN http_message_t *request)
SOCKINFO *info,
http_message_t *request)
{
UpnpSubscriptionRequest *request_struct = UpnpSubscriptionRequest_new();
Upnp_SID temp_sid;
@ -1368,8 +1368,8 @@ exit_function:
void gena_process_subscription_renewal_request(
IN SOCKINFO *info,
IN http_message_t *request)
SOCKINFO *info,
http_message_t *request)
{
Upnp_SID sid;
subscription *sub;
@ -1480,8 +1480,8 @@ void gena_process_subscription_renewal_request(
void gena_process_unsubscribe_request(
IN SOCKINFO *info,
IN http_message_t *request)
SOCKINFO *info,
http_message_t *request)
{
Upnp_SID sid;
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.
*
* The miniserver is a central point for processing all network requests.
* It is made of:
* - The SSDP sockets for discovery.
* - The HTTP listeners for description / control / eventing.
************************************************************************/
*
*/
#include "config.h"
#include "miniserver.h"
#include "httpreadwrite.h"
#include "ithread.h"
#include "ssdplib.h"
@ -49,6 +58,8 @@
#include "unixutil.h" /* for socklen_t, EAFNOSUPPORT */
#include "upnpapi.h"
#include "util.h"
#include <assert.h>
#include <errno.h>
#include <stdio.h>
@ -59,15 +70,24 @@
#define APPLICATION_LISTENING_PORT 49152
struct mserv_request_t {
int connfd; // connection handle
/*! Connection handle. */
int connfd;
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;
////////////////////////////////////////////////////////////////////////////
// module vars
static MiniServerCallback gGetCallback = NULL;
@ -75,88 +95,48 @@ static MiniServerCallback gSoapCallback = NULL;
static MiniServerCallback gGenaCallback = NULL;
static MiniServerState gMServState = MSERV_IDLE;
/************************************************************************
* Function: SetHTTPGetCallback
*
* Parameters :
* MiniServerCallback callback - HTTP Callback to be invoked
*
* Description:
* Set HTTP Get Callback
*
* Return: void
************************************************************************/
void
SetHTTPGetCallback( MiniServerCallback callback )
void SetHTTPGetCallback(MiniServerCallback callback)
{
gGetCallback = callback;
}
/************************************************************************
* Function: SetSoapCallback
*
* Parameters:
* MiniServerCallback callback - SOAP Callback to be invoked
*
* Description:
* Set SOAP Callback
*
* Return: void
************************************************************************/
#ifdef INCLUDE_DEVICE_APIS
void
SetSoapCallback( MiniServerCallback callback )
void SetSoapCallback(MiniServerCallback callback)
{
gSoapCallback = callback;
}
#endif /* INCLUDE_DEVICE_APIS */
/************************************************************************
* Function: SetGenaCallback
*
* Parameters:
* MiniServerCallback callback - GENA Callback to be invoked
*
* Description:
* Set GENA Callback
*
* Return: void
************************************************************************/
void
SetGenaCallback( MiniServerCallback callback )
void SetGenaCallback(MiniServerCallback callback)
{
gGenaCallback = callback;
}
#ifdef INTERNAL_WEB_SERVER
/************************************************************************
* Function : dispatch_request
/*!
* \brief Based on the type pf message, appropriate callback is issued.
*
* Parameters :
* IN SOCKINFO *info - Socket Information object.
* http_parser_t* hparser - HTTP parser object.
*
* Description :
* Based on the type pf message, appropriate callback is issued
*
* Return: int
* 0 - On Success
* HTTP_INTERNAL_SERVER_ERROR - Callback is NULL
************************************************************************/
static int
dispatch_request( IN SOCKINFO * info,
* \return 0 on Success or HTTP_INTERNAL_SERVER_ERROR if Callback is NULL.
*/
static int dispatch_request(
/*! [in] Socket Information object. */
IN SOCKINFO *info,
/*! [in] HTTP parser object. */
http_parser_t *hparser)
{
MiniServerCallback callback;
switch (hparser->msg.method) {
//Soap Call
/* Soap Call */
case SOAPMETHOD_POST:
case HTTPMETHOD_MPOST:
callback = gSoapCallback;
break;
//Gena Call
/* Gena Call */
case HTTPMETHOD_NOTIFY:
case HTTPMETHOD_SUBSCRIBE:
case HTTPMETHOD_UNSUBSCRIBE:
@ -165,7 +145,7 @@ dispatch_request( IN SOCKINFO * info,
callback = gGenaCallback;
break;
//HTTP server call
/* HTTP server call */
case HTTPMETHOD_GET:
case HTTPMETHOD_POST:
case HTTPMETHOD_HEAD:
@ -182,46 +162,35 @@ dispatch_request( IN SOCKINFO * info,
}
callback(hparser, &hparser->msg, info);
return 0;
}
/************************************************************************
* Function: handle_error
*
* Parameters:
* IN SOCKINFO *info - Socket Inforamtion Object
* int http_error_code - HTTP Error Code
* int major - Major Version Number
* int minor - Minor Version Number
*
* Description:
* Send Error Message
*
* Return: void
************************************************************************/
static UPNP_INLINE void
handle_error( IN SOCKINFO * info,
/*!
* \brief Send Error Message.
*/
static UPNP_INLINE void handle_error(
/*! [in] Socket Information object. */
SOCKINFO *info,
/*! [in] HTTP Error Code. */
int http_error_code,
/*! [in] Major Version Number. */
int major,
/*! [in] Minor Version Number. */
int minor)
{
http_SendStatusResponse(info, http_error_code, major, minor);
}
/************************************************************************
* Function: free_handle_request_arg
*
* Parameters:
* void *args ; Request Message to be freed
*
* Description:
* Free memory assigned for handling request and unitialize socket
* functionality
*
* Return: void
************************************************************************/
static void
free_handle_request_arg( void *args )
/*!
* \brief Free memory assigned for handling request and unitialize socket
* functionality.
*/
static void free_handle_request_arg(
/*! [in] Request Message to be freed. */
void *args)
{
struct mserv_request_t *request = (struct mserv_request_t *)args;
@ -230,19 +199,13 @@ free_handle_request_arg( void *args )
free(request);
}
/************************************************************************
* Function: handle_request
*
* Parameters:
* void *args - Request Message to be handled
*
* Description:
* Receive the request and dispatch it for handling
*
* Return: void
************************************************************************/
static void
handle_request( void *args )
/*!
* \brief Receive the request and dispatch it for handling.
*/
static void handle_request(
/*! [in] Request Message to be handled. */
void *args)
{
SOCKINFO info;
int http_error_code;
@ -260,21 +223,24 @@ handle_request( void *args )
//parser_request_init( &parser ); ////LEAK_FIX_MK
hmsg = &parser.msg;
if( sock_init_with_ip( &info, connfd, (struct sockaddr*)&request->foreign_sockaddr )
!= UPNP_E_SUCCESS ) {
ret_code = sock_init_with_ip(
&info, connfd, (struct sockaddr *)&request->foreign_sockaddr);
if (ret_code != UPNP_E_SUCCESS) {
free(request);
httpmsg_destroy(hmsg);
return;
}
// read
ret_code = http_RecvMessage( &info, &parser, HTTPMETHOD_UNKNOWN,
&timeout, &http_error_code );
ret_code = http_RecvMessage(
&info, &parser, HTTPMETHOD_UNKNOWN, &timeout, &http_error_code);
if (ret_code != 0) {
goto error_handler;
}
UpnpPrintf(UPNP_INFO, MSERV, __FILE__, __LINE__,
"miniserver %d: PROCESSING...\n", connfd);
// dispatch
http_error_code = dispatch_request( &info, &parser );
if (http_error_code != 0) {
@ -300,29 +266,21 @@ handle_request( void *args )
free(request);
}
/************************************************************************
* Function: schedule_request_job
*
* Parameters:
* IN int connfd - Socket Descriptor on which connection is accepted
* IN struct sockaddr* clientAddr - Clients Address information
*
* Description:
* Initilize the thread pool to handle a request.
* Sets priority for the job and adds the job to the thread pool
*
* Return: void
************************************************************************/
static UPNP_INLINE void
schedule_request_job( IN int connfd,
IN struct sockaddr *clientAddr )
/*!
* \brief Initilize the thread pool to handle a request, sets priority for the
* job and adds the job to the thread pool.
*/
static UPNP_INLINE void schedule_request_job(
/*! [in] Socket Descriptor on which connection is accepted. */
int connfd,
/*! [in] Clients Address information. */
struct sockaddr *clientAddr)
{
struct mserv_request_t *request;
ThreadPoolJob job;
request =
( struct mserv_request_t * )
malloc( sizeof( struct mserv_request_t ) );
request = (struct mserv_request_t *)malloc(sizeof (struct mserv_request_t));
if (request == NULL) {
UpnpPrintf( UPNP_INFO, MSERV, __FILE__, __LINE__,
"mserv %d: out of memory\n", connfd );
@ -332,7 +290,8 @@ schedule_request_job( IN int 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);
TPJobSetFreeFunction(&job, free_handle_request_arg);
@ -346,26 +305,20 @@ schedule_request_job( IN int connfd,
UpnpCloseSocket(connfd);
return;
}
}
#endif
/************************************************************************
* Function: RunMiniServer
/*!
* \brief Run the miniserver.
*
* Parameters:
* MiniServerSockArray *miniSock - Socket Array
*
* Description:
* Function runs the miniserver. The MiniServer accepts a
* new request and schedules a thread to handle the new request.
* Checks for socket state and invokes appropriate read and shutdown
* actions for the Miniserver and SSDP sockets
*
* Return: void
************************************************************************/
static void
RunMiniServer( MiniServerSockArray *miniSock )
* The MiniServer accepts a new request and schedules a thread to handle the
* new request. Checks for socket state and invokes appropriate read and
* shutdown actions for the Miniserver and SSDP sockets.
*/
static void RunMiniServer(
/*! [in] Socket Array. */
MiniServerSockArray *miniSock)
{
char errorBuffer[ERROR_BUFFER_LEN];
struct sockaddr_storage clientAddr;
@ -377,11 +330,11 @@ RunMiniServer( MiniServerSockArray *miniSock )
#ifdef INTERNAL_WEB_SERVER
SOCKET miniServSock4 = miniSock->miniServerSock4;
SOCKET miniServSock6 = miniSock->miniServerSock6;
#endif
#endif /* INTERNAL_WEB_SERVER */
#ifdef INCLUDE_CLIENT_APIS
SOCKET ssdpReqSock4 = miniSock->ssdpReqSock4;
SOCKET ssdpReqSock6 = miniSock->ssdpReqSock6;
#endif
#endif /* INCLUDE_CLIENT_APIS */
char buf_ntop[64];
fd_set expSet;
fd_set rdSet;
@ -391,21 +344,27 @@ RunMiniServer( MiniServerSockArray *miniSock )
int ret = 0;
#ifdef INTERNAL_WEB_SERVER
if( miniServSock4 != INVALID_SOCKET )
if (miniServSock4 != INVALID_SOCKET) {
maxMiniSock = max(maxMiniSock, miniServSock4);
if( miniServSock6 != INVALID_SOCKET )
}
if (miniServSock6 != INVALID_SOCKET) {
maxMiniSock = max(maxMiniSock, miniServSock6);
#endif
if( ssdpSock4 != INVALID_SOCKET )
}
#endif /* INTERNAL_WEB_SERVER */
if (ssdpSock4 != INVALID_SOCKET) {
maxMiniSock = max(maxMiniSock, ssdpSock4);
if( ssdpSock6 != INVALID_SOCKET )
}
if (ssdpSock6 != INVALID_SOCKET) {
maxMiniSock = max(maxMiniSock, ssdpSock6);
}
#ifdef INCLUDE_CLIENT_APIS
if( ssdpReqSock4 != INVALID_SOCKET )
if (ssdpReqSock4 != INVALID_SOCKET) {
maxMiniSock = max(maxMiniSock, ssdpReqSock4);
if( ssdpReqSock6 != INVALID_SOCKET )
}
if (ssdpReqSock6 != INVALID_SOCKET) {
maxMiniSock = max(maxMiniSock, ssdpReqSock6);
#endif
}
#endif /* INCLUDE_CLIENT_APIS */
maxMiniSock = max(maxMiniSock, miniServStopSock);
++maxMiniSock;
@ -417,21 +376,27 @@ RunMiniServer( MiniServerSockArray *miniSock )
FD_SET(miniServStopSock, &expSet);
FD_SET(miniServStopSock, &rdSet);
#ifdef INTERNAL_WEB_SERVER
if( miniServSock4 != INVALID_SOCKET )
if(miniServSock4 != INVALID_SOCKET) {
FD_SET(miniServSock4, &rdSet);
if( miniServSock6 != INVALID_SOCKET )
}
if(miniServSock6 != INVALID_SOCKET) {
FD_SET(miniServSock6, &rdSet);
#endif
if( ssdpSock4 != INVALID_SOCKET )
}
#endif /* INTERNAL_WEB_SERVER */
if(ssdpSock4 != INVALID_SOCKET) {
FD_SET(ssdpSock4, &rdSet);
if( ssdpSock6 != INVALID_SOCKET )
}
if(ssdpSock6 != INVALID_SOCKET) {
FD_SET(ssdpSock6, &rdSet);
}
#ifdef INCLUDE_CLIENT_APIS
if( ssdpReqSock4 != INVALID_SOCKET )
if(ssdpReqSock4 != INVALID_SOCKET) {
FD_SET(ssdpReqSock4, &rdSet);
if( ssdpReqSock6 != INVALID_SOCKET )
}
if(ssdpReqSock6 != INVALID_SOCKET) {
FD_SET(ssdpReqSock6, &rdSet);
#endif
}
#endif /* INCLUDE_CLIENT_APIS */
ret = select(maxMiniSock, &rdSet, NULL, &expSet, NULL);
if (ret == -1) {
@ -451,10 +416,12 @@ RunMiniServer( MiniServerSockArray *miniSock )
if (connectHnd == -1) {
strerror_r(errno, errorBuffer, ERROR_BUFFER_LEN);
UpnpPrintf(UPNP_INFO, MSERV, __FILE__, __LINE__,
"miniserver: Error in accept(): %s\n", errorBuffer );
"miniserver: Error in accept(): %s\n",
errorBuffer);
continue;
}
schedule_request_job( connectHnd, (struct sockaddr*)&clientAddr );
schedule_request_job(
connectHnd, (struct sockaddr *)&clientAddr);
}
if (miniServSock4 != INVALID_SOCKET &&
FD_ISSET(miniServSock4, &rdSet)) {
@ -464,12 +431,14 @@ RunMiniServer( MiniServerSockArray *miniSock )
if (connectHnd == -1) {
strerror_r(errno, errorBuffer, ERROR_BUFFER_LEN);
UpnpPrintf( UPNP_INFO, MSERV, __FILE__, __LINE__,
"miniserver: Error in accept(): %s\n", errorBuffer );
"miniserver: Error in accept(): %s\n",
errorBuffer);
continue;
}
schedule_request_job( connectHnd, (struct sockaddr*)&clientAddr );
schedule_request_job(
connectHnd, (struct sockaddr *)&clientAddr);
}
#endif
#endif /* INTERNAL_WEB_SERVER */
#ifdef INCLUDE_CLIENT_APIS
// ssdp
if (ssdpReqSock6 != INVALID_SOCKET &&
@ -480,7 +449,7 @@ RunMiniServer( MiniServerSockArray *miniSock )
FD_ISSET( ssdpReqSock4, &rdSet)) {
readFromSSDPSocket(ssdpReqSock4);
}
#endif
#endif /* INCLUDE_CLIENT_APIS */
if (ssdpSock6 != INVALID_SOCKET &&
FD_ISSET(ssdpSock6, &rdSet)) {
readFromSSDPSocket(ssdpSock6);
@ -492,10 +461,8 @@ RunMiniServer( MiniServerSockArray *miniSock )
if (FD_ISSET( miniServStopSock, &rdSet)) {
clientLen = sizeof(clientAddr);
memset((char *)&clientAddr, 0, sizeof(clientAddr));
byteReceived =
recvfrom( miniServStopSock, requestBuf, 25, 0,
( struct sockaddr * )&clientAddr,
&clientLen );
byteReceived = recvfrom(miniServStopSock, requestBuf,
25, 0, (struct sockaddr *)&clientAddr, &clientLen);
if (byteReceived > 0) {
requestBuf[byteReceived] = '\0';
inet_ntop(AF_INET,
@ -520,7 +487,7 @@ RunMiniServer( MiniServerSockArray *miniSock )
UpnpCloseSocket(miniServSock4);
shutdown(miniServSock6, SD_BOTH);
UpnpCloseSocket(miniServSock6);
#endif
#endif /* INTERNAL_WEB_SERVER */
shutdown(miniServStopSock, SD_BOTH);
UpnpCloseSocket(miniServStopSock);
shutdown(ssdpSock4, SD_BOTH);
@ -532,7 +499,7 @@ RunMiniServer( MiniServerSockArray *miniSock )
UpnpCloseSocket(ssdpReqSock4);
shutdown(ssdpReqSock6, SD_BOTH);
UpnpCloseSocket(ssdpReqSock6);
#endif
#endif /* INCLUDE_CLIENT_APIS */
free(miniSock);
gMServState = MSERV_IDLE;
@ -540,21 +507,15 @@ RunMiniServer( MiniServerSockArray *miniSock )
return;
}
/************************************************************************
* Function: get_port
/*!
* \brief Returns port to which socket, sockfd, is bound.
*
* Parameters:
* int sockfd - Socket Descriptor
*
* Description:
* Returns port to which socket, sockfd, is bound.
*
* Return: int
* -1 on error; check errno
* > 0 means port number
************************************************************************/
static int
get_port( int sockfd )
* \return -1 on error; check errno, otherwise > 0 means port number.
*/
static int get_port(
/*! [in] Socket descriptor. */
int sockfd)
{
struct sockaddr_storage sockinfo;
socklen_t len;
@ -578,35 +539,29 @@ get_port( int sockfd )
return port;
}
#ifdef INTERNAL_WEB_SERVER
/************************************************************************
* Function: get_miniserver_sockets
*
* 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
/*!
* \brief Creates a STREAM socket, binds to INADDR_ANY and listens for
* incoming connecttions. Returns the actual port which the sockets
* sub-system returned.
*
* Also creates a DGRAM socket, binds to the loop back address and
* returns the port allocated by the socket sub-system.
*
* Return: int
* UPNP_E_OUTOF_SOCKET - Failed to create a socket
* UPNP_E_SOCKET_BIND - Bind() failed
* UPNP_E_LISTEN - Listen() failed
* UPNP_E_INTERNAL_ERROR - Port returned by the socket layer is < 0
* UPNP_E_SUCCESS - Success
************************************************************************/
int
get_miniserver_sockets( MiniServerSockArray * out,
* \return
* \li UPNP_E_OUTOF_SOCKET: Failed to create a socket.
* \li UPNP_E_SOCKET_BIND: Bind() failed.
* \li UPNP_E_LISTEN: Listen() failed.
* \li UPNP_E_INTERNAL_ERROR: Port returned by the socket layer is < 0.
* \li UPNP_E_SUCCESS: Success.
*/
static int get_miniserver_sockets(
/*! [in] Socket Array. */
MiniServerSockArray *out,
/*! [in] port on which the server is listening for incoming IPv4 connections. */
unsigned short listen_port4,
/*! [in] port on which the server is listening for incoming IPv6 connections. */
unsigned short listen_port6)
{
char errorBuffer[ERROR_BUFFER_LEN];
@ -620,7 +575,6 @@ get_miniserver_sockets( MiniServerSockArray * out,
int reuseaddr_on = 0;
int sockError = UPNP_E_SUCCESS;
int errCode = 0;
int ret = 0;
// Create listen socket for IPv4/IPv6. An error here may indicate
// that we don't have an IPv4/IPv6 stack.
@ -668,7 +622,6 @@ get_miniserver_sockets( MiniServerSockArray * out,
UpnpCloseSocket(listenfd4);
shutdown(listenfd6, SD_BOTH);
UpnpCloseSocket(listenfd6);
return UPNP_E_SOCKET_BIND;
}
@ -683,8 +636,8 @@ get_miniserver_sockets( MiniServerSockArray * out,
UpnpCloseSocket(listenfd4);
shutdown(listenfd6, SD_BOTH);
UpnpCloseSocket(listenfd6);
return UPNP_E_SOCKET_BIND; // bind failed
/* Bind failed */
return UPNP_E_SOCKET_BIND;
}
}
@ -696,12 +649,10 @@ get_miniserver_sockets( MiniServerSockArray * out,
UpnpCloseSocket(listenfd4);
shutdown(listenfd6, SD_BOTH);
UpnpCloseSocket(listenfd6);
return UPNP_E_SOCKET_BIND;
}
sockError = bind( listenfd6, (struct sockaddr *)&__ss_v6,
sizeof(__ss_v6) );
sockError = bind(listenfd6, (struct sockaddr *)&__ss_v6, sizeof (__ss_v6));
if (sockError == -1) {
strerror_r(errno, errorBuffer, ERROR_BUFFER_LEN);
UpnpPrintf(UPNP_INFO, MSERV, __FILE__, __LINE__,
@ -711,8 +662,8 @@ get_miniserver_sockets( MiniServerSockArray * out,
UpnpCloseSocket(listenfd4);
shutdown(listenfd6, SD_BOTH);
UpnpCloseSocket(listenfd6);
return UPNP_E_SOCKET_BIND; // bind failed
/* Bind failed */
return UPNP_E_SOCKET_BIND;
}
}
} else {
@ -730,9 +681,11 @@ get_miniserver_sockets( MiniServerSockArray * out,
if (errno == EADDRINUSE) {
errCode = 1;
}
} else
} else {
errCode = 0;
}
} while ( errCode != 0 );
if (sockError == -1) {
strerror_r(errno, errorBuffer, ERROR_BUFFER_LEN);
UpnpPrintf(UPNP_INFO, MSERV, __FILE__, __LINE__,
@ -742,7 +695,6 @@ get_miniserver_sockets( MiniServerSockArray * out,
UpnpCloseSocket(listenfd4);
shutdown(listenfd6, SD_BOTH);
UpnpCloseSocket(listenfd6);
return UPNP_E_SOCKET_BIND; // bind failed
}
}
@ -761,9 +713,11 @@ get_miniserver_sockets( MiniServerSockArray * out,
if (errno == EADDRINUSE) {
errCode = 1;
}
} else
} else {
errCode = 0;
}
} while (errCode != 0);
if (sockError == -1) {
strerror_r(errno, errorBuffer, ERROR_BUFFER_LEN);
UpnpPrintf(UPNP_INFO, MSERV, __FILE__, __LINE__,
@ -773,8 +727,8 @@ get_miniserver_sockets( MiniServerSockArray * out,
UpnpCloseSocket(listenfd4);
shutdown(listenfd6, SD_BOTH);
UpnpCloseSocket(listenfd6);
return UPNP_E_SOCKET_BIND; // bind failed
/* Bind failied */
return UPNP_E_SOCKET_BIND;
}
}
}
@ -787,12 +741,12 @@ get_miniserver_sockets( MiniServerSockArray * out,
if (ret_code == -1) {
strerror_r(errno, errorBuffer, ERROR_BUFFER_LEN);
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);
UpnpCloseSocket(listenfd4);
shutdown(listenfd6, SD_BOTH);
UpnpCloseSocket(listenfd6);
return UPNP_E_LISTEN;
}
@ -802,7 +756,6 @@ get_miniserver_sockets( MiniServerSockArray * out,
UpnpCloseSocket(listenfd4);
shutdown(listenfd6, SD_BOTH);
UpnpCloseSocket(listenfd6);
return UPNP_E_INTERNAL_ERROR;
}
@ -814,12 +767,12 @@ get_miniserver_sockets( MiniServerSockArray * out,
if (ret_code == -1) {
strerror_r(errno, errorBuffer, ERROR_BUFFER_LEN);
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);
UpnpCloseSocket(listenfd4);
shutdown(listenfd6, SD_BOTH);
UpnpCloseSocket(listenfd6);
return UPNP_E_LISTEN;
}
@ -829,7 +782,6 @@ get_miniserver_sockets( MiniServerSockArray * out,
UpnpCloseSocket(listenfd4);
shutdown(listenfd6, SD_BOTH);
UpnpCloseSocket(listenfd6);
return UPNP_E_INTERNAL_ERROR;
}
@ -841,38 +793,33 @@ get_miniserver_sockets( MiniServerSockArray * out,
return UPNP_E_SUCCESS;
}
#endif
#endif /* INTERNAL_WEB_SERVER */
/************************************************************************
* Function: get_miniserver_stopsock
*
* Parameters:
* MiniServerSockArray *out - Miniserver Socket Array
*
* Description:
* Creates the miniserver STOP socket. This socket is created and
/*!
* \brief Creates the miniserver STOP socket. This socket is created and
* listened on to know when it is time to stop the Miniserver.
*
* Return: int
* UPNP_E_OUTOF_SOCKET - Failed to create a socket
* UPNP_E_SOCKET_BIND - Bind() failed
* UPNP_E_INTERNAL_ERROR - Port returned by the socket layer is < 0
* UPNP_E_SUCCESS - Success
************************************************************************/
int get_miniserver_stopsock( MiniServerSockArray * out )
* \return
* \li UPNP_E_OUTOF_SOCKET: Failed to create a socket.
* \li UPNP_E_SOCKET_BIND: Bind() failed.
* \li UPNP_E_INTERNAL_ERROR: Port returned by the socket layer is < 0.
* \li UPNP_E_SUCCESS: Success.
*/
static int get_miniserver_stopsock(
/*! [in] Miniserver Socket Array. */
MiniServerSockArray *out)
{
char errorBuffer[ERROR_BUFFER_LEN];
struct sockaddr_in stop_sockaddr;
int miniServerStopSock;
int ret;
int miniServerStopSock = 0;
int ret = 0;
miniServerStopSock = socket(AF_INET, SOCK_DGRAM, 0);
if (miniServerStopSock == -1) {
strerror_r(errno, errorBuffer, ERROR_BUFFER_LEN);
UpnpPrintf(UPNP_CRITICAL, MSERV, __FILE__, __LINE__,
"Error in socket(): %s\n", errorBuffer);
return UPNP_E_OUTOF_SOCKET;
}
@ -888,7 +835,6 @@ int get_miniserver_stopsock( MiniServerSockArray * out )
"Error in binding localhost!!!\n");
shutdown(miniServerStopSock, SD_BOTH);
UpnpCloseSocket(miniServerStopSock);
return UPNP_E_SOCKET_BIND;
}
@ -896,7 +842,6 @@ int get_miniserver_stopsock( MiniServerSockArray * out )
if (miniStopSockPort <= 0) {
shutdown(miniServerStopSock, SD_BOTH);
UpnpCloseSocket(miniServerStopSock);
return UPNP_E_INTERNAL_ERROR;
}
@ -907,29 +852,10 @@ int get_miniserver_stopsock( MiniServerSockArray * out )
}
/************************************************************************
* Function: StartMiniServer
*
* Parameters:
* 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,
int StartMiniServer(
/*! [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)
{
int ret_code;
@ -968,7 +894,6 @@ StartMiniServer( unsigned short* listen_port4,
UpnpCloseSocket(miniSocket->miniServerSock6);
#endif
free(miniSocket);
return ret_code;
}
@ -984,14 +909,12 @@ StartMiniServer( unsigned short* listen_port4,
shutdown(miniSocket->miniServerStopSock, SD_BOTH);
UpnpCloseSocket(miniSocket->miniServerStopSock);
free(miniSocket);
return ret_code;
}
TPJobInit(&job, (start_routine)RunMiniServer, (void *)miniSocket);
TPJobSetPriority(&job, MED_PRIORITY);
TPJobSetFreeFunction(&job, (free_routine)free);
ret_code = ThreadPoolAddPersistent(&gMiniServerThreadPool, &job, NULL);
if (ret_code < 0) {
#ifdef INTERNAL_WEB_SERVER
@ -1012,7 +935,6 @@ StartMiniServer( unsigned short* listen_port4,
shutdown(miniSocket->ssdpReqSock6, SD_BOTH );
UpnpCloseSocket(miniSocket->ssdpReqSock6 );
#endif
return UPNP_E_OUTOF_MEMORY;
}
// wait for miniserver to start
@ -1042,7 +964,6 @@ StartMiniServer( unsigned short* listen_port4,
shutdown(miniSocket->ssdpReqSock6, SD_BOTH);
UpnpCloseSocket(miniSocket->ssdpReqSock6);
#endif
return UPNP_E_INTERNAL_ERROR;
}
#ifdef INTERNAL_WEB_SERVER
@ -1053,21 +974,8 @@ StartMiniServer( unsigned short* listen_port4,
return UPNP_E_SUCCESS;
}
/************************************************************************
* Function: StopMiniServer
*
* Parameters:
* void
*
* Description:
* Stop and Shutdown the MiniServer and free socket
* resources.
*
* Return: int
* Always returns 0
************************************************************************/
int
StopMiniServer()
int StopMiniServer()
{
char errorBuffer[ERROR_BUFFER_LEN];
int socklen = sizeof (struct sockaddr_in);
@ -1086,7 +994,8 @@ StopMiniServer()
if (sock == -1) {
strerror_r(errno, errorBuffer, ERROR_BUFFER_LEN);
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;
}
@ -1094,7 +1003,8 @@ StopMiniServer()
ssdpAddr.sin_family = AF_INET;
ssdpAddr.sin_addr.s_addr = inet_addr("127.0.0.1");
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);
if (gMServState == MSERV_IDLE) {
break;

View File

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

View File

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

View File

@ -48,9 +48,9 @@
*/
void gena_process_subscription_request(
/*! [in] Socket info of the device. */
IN SOCKINFO *info,
SOCKINFO *info,
/*! [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(
/*! [in] Socket info of the device. */
IN SOCKINFO *info,
SOCKINFO *info,
/*! [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(
/*! [in] Socket info of the device. */
IN SOCKINFO *info,
SOCKINFO *info,
/*! [in] UNSUBSCRIBE request from the control point. */
IN http_message_t *request);
http_message_t *request);
#endif /* GENA_DEVICE_H */

View File

@ -70,81 +70,62 @@ typedef void (*MiniServerCallback)(
extern "C" {
#endif
/************************************************************************
* Function: SetHTTPGetCallback
*
* Parameters:
* MiniServerCallback callback; - HTTP Callback to be invoked
*
* Description: Set HTTP Get Callback
*
* Return: void
************************************************************************/
void SetHTTPGetCallback( MiniServerCallback callback );
/************************************************************************
* Function: SetSoapCallback
*
* Parameters:
* MiniServerCallback callback; - SOAP Callback to be invoked
*
* Description: Set SOAP Callback
*
* Return: void
************************************************************************/
/*!
* \brief Set HTTP Get Callback.
*/
void SetHTTPGetCallback(
/*! [in] HTTP Callback to be invoked . */
MiniServerCallback callback);
/*!
* \brief Set SOAP Callback.
*/
#ifdef INCLUDE_DEVICE_APIS
void SetSoapCallback( MiniServerCallback callback );
void SetSoapCallback(
/*! [in] SOAP Callback to be invoked . */
MiniServerCallback callback);
#else /* INCLUDE_DEVICE_APIS */
static inline void SetSoapCallback(MiniServerCallback callback) {}
#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:
* 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.
* Initialize a thread pool job to run the MiniServer and the job to the
* thread pool.
*
* 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
* 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: UPNP_E_XXX
************************************************************************/
int StartMiniServer( IN OUT unsigned short* listen_port4,
IN OUT unsigned short* listen_port6 );
* \return
* \li On success: UPNP_E_SUCCESS.
* \li On error: UPNP_E_XXX.
*/
int StartMiniServer(
/*! [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:
* void;
*
* Description: Stop and Shutdown the MiniServer and free socket resources.
*
* Return : int;
* Always returns 0
************************************************************************/
* \return Always returns 0.
*/
int StopMiniServer();