Some code cleanup.

git-svn-id: https://pupnp.svn.sourceforge.net/svnroot/pupnp/trunk@188 119443c7-1b9e-41f8-b6fc-b9c35fce742c
This commit is contained in:
Marcelo Roberto Jimenez 2007-05-19 02:56:25 +00:00
parent 83fb96fbe2
commit 80fc7c3bb0
3 changed files with 95 additions and 100 deletions

View File

@ -213,11 +213,11 @@ int UpnpInit( IN const char *HostIP,
return UPNP_E_INIT_FAILED; return UPNP_E_INIT_FAILED;
} }
// initialize subscribe mutex // initialize subscribe mutex
CLIENTONLY( if #ifdef INCLUDE_CLIENT_APIS
( ithread_mutex_init( &GlobalClientSubscribeMutex, NULL ) if ( ithread_mutex_init( &GlobalClientSubscribeMutex, NULL ) != 0 ) {
!= 0 ) { return UPNP_E_INIT_FAILED;
return UPNP_E_INIT_FAILED;} }
) #endif
HandleLock(); HandleLock();
if( HostIP != NULL ) if( HostIP != NULL )
@ -418,9 +418,9 @@ UpnpFinish()
CloseLog(); CloseLog();
#endif #endif
CLIENTONLY( ithread_mutex_destroy( &GlobalClientSubscribeMutex ); #ifdef INCLUDE_CLIENT_APIS
) ithread_mutex_destroy( &GlobalClientSubscribeMutex );
#endif
ithread_mutex_destroy( &GlobalHndMutex ); ithread_mutex_destroy( &GlobalHndMutex );
ithread_mutex_destroy( &gUUIDMutex ); ithread_mutex_destroy( &gUUIDMutex );
@ -621,10 +621,8 @@ UpnpRegisterRootDevice( IN const char *DescUrl,
HInfo->DeviceList = NULL; HInfo->DeviceList = NULL;
HInfo->ServiceList = NULL; HInfo->ServiceList = NULL;
HInfo->DescDocument = NULL; HInfo->DescDocument = NULL;
CLIENTONLY( ListInit( &HInfo->SsdpSearchList, NULL, NULL ); CLIENTONLY( ListInit( &HInfo->SsdpSearchList, NULL, NULL ); )
); CLIENTONLY( HInfo->ClientSubList = NULL; )
CLIENTONLY( HInfo->ClientSubList = NULL;
)
HInfo->MaxSubscriptions = UPNP_INFINITE; HInfo->MaxSubscriptions = UPNP_INFINITE;
HInfo->MaxSubscriptionTimeOut = UPNP_INFINITE; HInfo->MaxSubscriptionTimeOut = UPNP_INFINITE;
@ -682,7 +680,7 @@ UpnpRegisterRootDevice( IN const char *DescUrl,
"Here are the known services: \n" ); "Here are the known services: \n" );
printServiceTable( &HInfo->ServiceTable, UPNP_INFO, API ); printServiceTable( &HInfo->ServiceTable, UPNP_INFO, API );
} else { } else {
CLIENTONLY( ListDestroy( &HInfo->SsdpSearchList, 0 ) ); CLIENTONLY( ListDestroy( &HInfo->SsdpSearchList, 0 ); )
FreeHandle( *Hnd ); FreeHandle( *Hnd );
HandleUnlock(); HandleUnlock();
UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__,
@ -835,7 +833,7 @@ UpnpUnRegisterRootDevice( IN UpnpDevice_Handle Hnd )
ixmlNodeList_free( HInfo->ServiceList ); ixmlNodeList_free( HInfo->ServiceList );
ixmlDocument_free( HInfo->DescDocument ); ixmlDocument_free( HInfo->DescDocument );
CLIENTONLY( ListDestroy( &HInfo->SsdpSearchList, 0 ) ); CLIENTONLY( ListDestroy( &HInfo->SsdpSearchList, 0 ); )
#ifdef INTERNAL_WEB_SERVER #ifdef INTERNAL_WEB_SERVER
if( HInfo->aliasInstalled ) { if( HInfo->aliasInstalled ) {
@ -1189,7 +1187,6 @@ UpnpRegisterRootDevice2( IN Upnp_DescType descriptionType,
retVal = GetDescDocumentAndURL( descriptionType, description, retVal = GetDescDocumentAndURL( descriptionType, description,
bufferLen, config_baseURL, bufferLen, config_baseURL,
&HInfo->DescDocument, HInfo->DescURL ); &HInfo->DescDocument, HInfo->DescURL );
//HInfo->DescAlias );
if( retVal != UPNP_E_SUCCESS ) { if( retVal != UPNP_E_SUCCESS ) {
FreeHandle( *Hnd ); FreeHandle( *Hnd );
@ -1205,10 +1202,8 @@ UpnpRegisterRootDevice2( IN Upnp_DescType descriptionType,
HInfo->MaxAge = DEFAULT_MAXAGE; HInfo->MaxAge = DEFAULT_MAXAGE;
HInfo->DeviceList = NULL; HInfo->DeviceList = NULL;
HInfo->ServiceList = NULL; HInfo->ServiceList = NULL;
CLIENTONLY( HInfo->ClientSubList = NULL; CLIENTONLY( HInfo->ClientSubList = NULL; )
) CLIENTONLY( ListInit( &HInfo->SsdpSearchList, NULL, NULL ); )
CLIENTONLY( ListInit( &HInfo->SsdpSearchList, NULL, NULL );
);
HInfo->MaxSubscriptions = UPNP_INFINITE; HInfo->MaxSubscriptions = UPNP_INFINITE;
HInfo->MaxSubscriptionTimeOut = UPNP_INFINITE; HInfo->MaxSubscriptionTimeOut = UPNP_INFINITE;
@ -1222,7 +1217,7 @@ UpnpRegisterRootDevice2( IN Upnp_DescType descriptionType,
ixmlDocument_getElementsByTagName( HInfo->DescDocument, "device" ); ixmlDocument_getElementsByTagName( HInfo->DescDocument, "device" );
if( HInfo->DeviceList == NULL ) { if( HInfo->DeviceList == NULL ) {
CLIENTONLY( ListDestroy( &HInfo->SsdpSearchList, 0 ) ); CLIENTONLY( ListDestroy( &HInfo->SsdpSearchList, 0 ); )
ixmlDocument_free( HInfo->DescDocument ); ixmlDocument_free( HInfo->DescDocument );
FreeHandle( *Hnd ); FreeHandle( *Hnd );
HandleUnlock(); HandleUnlock();
@ -1236,7 +1231,7 @@ UpnpRegisterRootDevice2( IN Upnp_DescType descriptionType,
"serviceList" ); "serviceList" );
if( HInfo->ServiceList == NULL ) { if( HInfo->ServiceList == NULL ) {
CLIENTONLY( ListDestroy( &HInfo->SsdpSearchList, 0 ) ); CLIENTONLY( ListDestroy( &HInfo->SsdpSearchList, 0 ); )
ixmlNodeList_free( HInfo->DeviceList ); ixmlNodeList_free( HInfo->DeviceList );
ixmlDocument_free( HInfo->DescDocument ); ixmlDocument_free( HInfo->DescDocument );
FreeHandle( *Hnd ); FreeHandle( *Hnd );
@ -1256,7 +1251,7 @@ UpnpRegisterRootDevice2( IN Upnp_DescType descriptionType,
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__,
"UpnpRegisterRootDevice2: GENA Service Table \n" ); "UpnpRegisterRootDevice2: GENA Service Table \n" );
} else { } else {
CLIENTONLY( ListDestroy( &HInfo->SsdpSearchList, 0 ) ); CLIENTONLY( ListDestroy( &HInfo->SsdpSearchList, 0 ); )
FreeHandle( *Hnd ); FreeHandle( *Hnd );
HandleUnlock(); HandleUnlock();
UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__,
@ -1350,7 +1345,6 @@ UpnpRegisterClient( IN Upnp_FunPtr Fun,
} /****************** End of UpnpRegisterClient *********************/ } /****************** End of UpnpRegisterClient *********************/
#endif // INCLUDE_CLIENT_APIS #endif // INCLUDE_CLIENT_APIS
#ifdef INCLUDE_CLIENT_APIS
/**************************************************************************** /****************************************************************************
* Function: UpnpUnRegisterClient * Function: UpnpUnRegisterClient
@ -1367,6 +1361,7 @@ UpnpRegisterClient( IN Upnp_FunPtr Fun,
* Return Values: * Return Values:
* UPNP_E_SUCCESS on success, nonzero on failure. * UPNP_E_SUCCESS on success, nonzero on failure.
*****************************************************************************/ *****************************************************************************/
#ifdef INCLUDE_CLIENT_APIS
int int
UpnpUnRegisterClient( IN UpnpClient_Handle Hnd ) UpnpUnRegisterClient( IN UpnpClient_Handle Hnd )
{ {
@ -3326,7 +3321,6 @@ UpnpDownloadXmlDoc( const char *url,
// //
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
#ifdef INCLUDE_CLIENT_APIS
/************************************************************************** /**************************************************************************
* Function: UpnpThreadDistribution * Function: UpnpThreadDistribution
@ -3339,6 +3333,7 @@ UpnpDownloadXmlDoc( const char *url,
* Return Values: VOID * Return Values: VOID
* *
***************************************************************************/ ***************************************************************************/
#ifdef INCLUDE_CLIENT_APIS
void void
UpnpThreadDistribution( struct UpnpNonblockParam *Param ) UpnpThreadDistribution( struct UpnpNonblockParam *Param )
{ {
@ -3348,17 +3343,19 @@ UpnpThreadDistribution( struct UpnpNonblockParam *Param )
switch ( Param->FunName ) { switch ( Param->FunName ) {
#if EXCLUDE_GENA == 0 #if EXCLUDE_GENA == 0
CLIENTONLY( case SUBSCRIBE: case SUBSCRIBE: {
{
struct Upnp_Event_Subscribe Evt; struct Upnp_Event_Subscribe Evt;
Evt.ErrCode = genaSubscribe( Param->Handle, Param->Url, Evt.ErrCode = genaSubscribe(
Param->Handle, Param->Url,
( int * )&( Param->TimeOut ), ( int * )&( Param->TimeOut ),
( char * )Evt.Sid ); ( char * )Evt.Sid );
strcpy( Evt.PublisherUrl, Param->Url ); Evt.TimeOut = Param->TimeOut; strcpy( Evt.PublisherUrl, Param->Url );
Evt.TimeOut = Param->TimeOut;
Param->Fun( UPNP_EVENT_SUBSCRIBE_COMPLETE, &Evt, Param->Cookie ); Param->Fun( UPNP_EVENT_SUBSCRIBE_COMPLETE, &Evt, Param->Cookie );
free( Param ); break;} free( Param );
case UNSUBSCRIBE: break;
{ }
case UNSUBSCRIBE: {
struct Upnp_Event_Subscribe Evt; struct Upnp_Event_Subscribe Evt;
Evt.ErrCode = Evt.ErrCode =
genaUnSubscribe( Param->Handle, genaUnSubscribe( Param->Handle,
@ -3368,9 +3365,10 @@ free( Param ); break;}
Evt.TimeOut = 0; Evt.TimeOut = 0;
Param->Fun( UPNP_EVENT_UNSUBSCRIBE_COMPLETE, Param->Fun( UPNP_EVENT_UNSUBSCRIBE_COMPLETE,
&Evt, Param->Cookie ); &Evt, Param->Cookie );
free( Param ); break;} free( Param );
case RENEW: break;
{ }
case RENEW: {
struct Upnp_Event_Subscribe Evt; struct Upnp_Event_Subscribe Evt;
Evt.ErrCode = Evt.ErrCode =
genaRenewSubscription( Param->Handle, genaRenewSubscription( Param->Handle,
@ -3379,55 +3377,40 @@ free( Param ); break;}
Evt.TimeOut = Param->TimeOut; Evt.TimeOut = Param->TimeOut;
strcpy( ( char * )Evt.Sid, Param->SubsId ); strcpy( ( char * )Evt.Sid, Param->SubsId );
Param->Fun( UPNP_EVENT_RENEWAL_COMPLETE, &Evt, Param->Fun( UPNP_EVENT_RENEWAL_COMPLETE, &Evt,
Param->Cookie ); free( Param ); Param->Cookie );
break;} free( Param );
) break;
#endif }
#endif // EXCLUDE_GENA == 0
#if EXCLUDE_SOAP == 0 #if EXCLUDE_SOAP == 0
case ACTION: case ACTION: {
{
struct Upnp_Action_Complete Evt; struct Upnp_Action_Complete Evt;
Evt.ActionResult = NULL; Evt.ActionResult = NULL;
#ifdef INCLUDE_CLIENT_APIS
Evt.ErrCode = Evt.ErrCode =
SoapSendAction( Param->Url, Param->ServiceType, SoapSendAction( Param->Url, Param->ServiceType,
Param->Act, &Evt.ActionResult ); Param->Act, &Evt.ActionResult );
#endif
Evt.ActionRequest = Param->Act; Evt.ActionRequest = Param->Act;
strcpy( Evt.CtrlUrl, Param->Url ); strcpy( Evt.CtrlUrl, Param->Url );
Param->Fun( UPNP_CONTROL_ACTION_COMPLETE, &Evt, Param->Fun( UPNP_CONTROL_ACTION_COMPLETE, &Evt,
Param->Cookie ); Param->Cookie );
ixmlDocument_free( Evt.ActionRequest ); ixmlDocument_free( Evt.ActionRequest );
ixmlDocument_free( Evt.ActionResult ); ixmlDocument_free( Evt.ActionResult );
free( Param ); free( Param );
break; break;
} }
case STATUS: case STATUS: {
{
struct Upnp_State_Var_Complete Evt; struct Upnp_State_Var_Complete Evt;
Evt.ErrCode = SoapGetServiceVarStatus(
#ifdef INCLUDE_CLIENT_APIS Param->Url, Param->VarName, &( Evt.CurrentVal ) );
Evt.ErrCode = SoapGetServiceVarStatus( Param->Url,
Param->VarName,
&( Evt.
CurrentVal ) );
#endif
strcpy( Evt.StateVarName, Param->VarName ); strcpy( Evt.StateVarName, Param->VarName );
strcpy( Evt.CtrlUrl, Param->Url ); strcpy( Evt.CtrlUrl, Param->Url );
Param->Fun( UPNP_CONTROL_GET_VAR_COMPLETE, &Evt, Param->Fun( UPNP_CONTROL_GET_VAR_COMPLETE, &Evt,
Param->Cookie ); Param->Cookie );
free( Evt.CurrentVal ); free( Evt.CurrentVal );
free( Param ); free( Param );
break; break;
} }
#endif //EXCLUDE_SOAP #endif // EXCLUDE_SOAP == 0
default: default:
break; break;
} // end of switch(Param->FunName) } // end of switch(Param->FunName)
@ -3436,7 +3419,7 @@ free( Param ); break;}
"Exiting UpnpThreadDistribution \n" ); "Exiting UpnpThreadDistribution \n" );
} /****************** End of UpnpThreadDistribution *********************/ } /****************** End of UpnpThreadDistribution *********************/
#endif #endif // INCLUDE_CLIENT_APIS
/************************************************************************** /**************************************************************************
* Function: GetCallBackFn * Function: GetCallBackFn

View File

@ -449,6 +449,7 @@ genaUnregisterClient( IN UpnpClient_Handle client_handle )
* return UPNP_E_SUCCESS if service response is OK else * return UPNP_E_SUCCESS if service response is OK else
* returns appropriate error * returns appropriate error
***************************************************************************/ ***************************************************************************/
#ifdef INCLUDE_CLIENT_APIS
int int
genaUnSubscribe( IN UpnpClient_Handle client_handle, genaUnSubscribe( IN UpnpClient_Handle client_handle,
IN const Upnp_SID in_sid ) IN const Upnp_SID in_sid )
@ -501,6 +502,7 @@ genaUnSubscribe( IN UpnpClient_Handle client_handle,
return return_code; return return_code;
} }
#endif
/************************************************************************ /************************************************************************
* Function : genaSubscribe * Function : genaSubscribe
@ -524,6 +526,7 @@ genaUnSubscribe( IN UpnpClient_Handle client_handle,
* return UPNP_E_SUCCESS if service response is OK else * return UPNP_E_SUCCESS if service response is OK else
* returns appropriate error * returns appropriate error
***************************************************************************/ ***************************************************************************/
#ifdef INCLUDE_CLIENT_APIS
int int
genaSubscribe( IN UpnpClient_Handle client_handle, genaSubscribe( IN UpnpClient_Handle client_handle,
IN char *PublisherURL, IN char *PublisherURL,
@ -609,6 +612,7 @@ genaSubscribe( IN UpnpClient_Handle client_handle,
SubscribeUnlock(); SubscribeUnlock();
return return_code; return return_code;
} }
#endif
/************************************************************************ /************************************************************************
* Function : genaRenewSubscription * Function : genaRenewSubscription

View File

@ -162,11 +162,13 @@ EXTERN_C void genaCallback (IN http_parser_t *parser,
* return UPNP_E_SUCCESS if service response is OK else * return UPNP_E_SUCCESS if service response is OK else
* returns appropriate error * returns appropriate error
***************************************************************************/ ***************************************************************************/
CLIENTONLY( #ifdef INCLUDE_CLIENT_APIS
EXTERN_C int genaSubscribe(UpnpClient_Handle client_handle, EXTERN_C int genaSubscribe(
UpnpClient_Handle client_handle,
char * PublisherURL, char * PublisherURL,
int * TimeOut, int * TimeOut,
Upnp_SID out_sid );) Upnp_SID out_sid );
#endif
/************************************************************************ /************************************************************************
@ -185,8 +187,11 @@ CLIENTONLY(
* return UPNP_E_SUCCESS if service response is OK else * return UPNP_E_SUCCESS if service response is OK else
* returns appropriate error * returns appropriate error
***************************************************************************/ ***************************************************************************/
CLIENTONLY(EXTERN_C int genaUnSubscribe(UpnpClient_Handle client_handle, #ifdef INCLUDE_CLIENT_APIS
const Upnp_SID in_sid);) EXTERN_C int genaUnSubscribe(
UpnpClient_Handle client_handle,
const Upnp_SID in_sid);
#endif
/************************************************************************ /************************************************************************
* Function : genaUnregisterClient * Function : genaUnregisterClient
@ -203,8 +208,9 @@ CLIENTONLY(EXTERN_C int genaUnSubscribe(UpnpClient_Handle client_handle,
* Returns: int * Returns: int
* return UPNP_E_SUCCESS if successful else returns appropriate error * return UPNP_E_SUCCESS if successful else returns appropriate error
***************************************************************************/ ***************************************************************************/
CLIENTONLY(EXTERN_C int genaUnregisterClient( #ifdef INCLUDE_CLIENT_APIS
UpnpClient_Handle client_handle);) EXTERN_C int genaUnregisterClient(UpnpClient_Handle client_handle);
#endif
//server //server
/************************************************************************ /************************************************************************
@ -244,10 +250,12 @@ EXTERN_C int genaUnregisterDevice(UpnpDevice_Handle device_handle);
* return UPNP_E_SUCCESS if service response is OK else * return UPNP_E_SUCCESS if service response is OK else
* returns appropriate error * returns appropriate error
***************************************************************************/ ***************************************************************************/
CLIENTONLY(EXTERN_C int genaRenewSubscription( #ifdef INCLUDE_CLIENT_APIS
EXTERN_C int genaRenewSubscription(
IN UpnpClient_Handle client_handle, IN UpnpClient_Handle client_handle,
IN const Upnp_SID in_sid, IN const Upnp_SID in_sid,
OUT int * TimeOut);) OUT int * TimeOut);
#endif
/**************************************************************************** /****************************************************************************
* Function : genaNotifyAll * Function : genaNotifyAll
* *