Some white spaces, some doxygen, some code reorganizing.

We should try to return only at the end of the function so that
we can use "objects" reliably.


git-svn-id: https://pupnp.svn.sourceforge.net/svnroot/pupnp/trunk@375 119443c7-1b9e-41f8-b6fc-b9c35fce742c
This commit is contained in:
Marcelo Roberto Jimenez 2008-05-06 19:29:24 +00:00
parent b503c89f78
commit 263e616403
4 changed files with 329 additions and 314 deletions

View File

@ -36,7 +36,7 @@
/*! /*!
* \file * \file
* *
* \defgroup XMLApi The XML API * \defgroup XMLAPI XML API
* *
* @{ * @{
*/ */
@ -1777,7 +1777,7 @@ EXPORT_SPEC void ixmlFreeDOMString(
#endif #endif
/*@}*/ /* The XML API */ /* @} XMLAPI XML API */
#endif /* IXML_H */ #endif /* IXML_H */

View File

@ -13,9 +13,9 @@
* *
* \version 1.0 * \version 1.0
* *
* \brief Strings implementation in the UPnP library. * \brief String implementation for the UPnP library.
* *
* This class implements basic string operations in the UPnP library. * This class implements string operations in the UPnP library.
* *
* @{ * @{
*/ */

View File

@ -36,7 +36,7 @@
/*! /*!
* \file * \file
* *
* \defgroup TheApi The UPnP API * \defgroup UPnPAPI UPnP API
* *
* @{ * @{
*/ */
@ -895,8 +895,8 @@ EXPORT_SPEC char *UpnpGetServerIp6Address();
* \b UpnpRegisterClient to get a control point handle to perform control * \b UpnpRegisterClient to get a control point handle to perform control
* point functionality). * point functionality).
* *
* \b UpnpRegisterRootDevice is synchronous and does not generate any * This is a synchronous call and does not generate any callbacks. Callbacks
* callbacks. Callbacks can occur as soon as this function returns. * can occur as soon as this function returns.
* *
* \return An integer representing one of the following: * \return An integer representing one of the following:
* \li \c UPNP_E_SUCCESS: The operation completed successfully. * \li \c UPNP_E_SUCCESS: The operation completed successfully.
@ -933,8 +933,9 @@ EXPORT_SPEC int UpnpRegisterRootDevice(
OUT UpnpDevice_Handle *Hnd); OUT UpnpDevice_Handle *Hnd);
/*! /*!
* \brief Similar to \b UpnpRegisterRootDevice, except that it also allows * \brief Registers a device application with the UPnP Library. Similar to
* the description document to be specified as a file or a memory buffer. * \b UpnpRegisterRootDevice, except that it also allows the description
* document to be specified as a file or a memory buffer.
* *
* The description can also be configured to have the correct IP and port * The description can also be configured to have the correct IP and port
* address. * address.
@ -946,8 +947,8 @@ EXPORT_SPEC int UpnpRegisterRootDevice(
* description document is specified as a URL and no configuration is * description document is specified as a URL and no configuration is
* required (i.e. <tt>config_baseURL = 0</tt>.) * required (i.e. <tt>config_baseURL = 0</tt>.)
* *
* This is synchronous and does not generate any callbacks. Callbacks can occur * This is a synchronous call and does not generate any callbacks. Callbacks
* as soon as this function returns. * can occur as soon as this function returns.
* *
* Examples of using different types of description documents: * Examples of using different types of description documents:
* \verbatim * \verbatim
@ -2638,7 +2639,8 @@ EXPORT_SPEC void UpnpRemoveAllVirtualDirs();
#endif /* __cplusplus */ #endif /* __cplusplus */
/* @} TheAPI The UPnP API */ /* @} UPnPAPI UPnP API */
#endif /* UPNP_H */ #endif /* UPNP_H */

View File

@ -174,7 +174,6 @@ GetDescDocumentAndURL( IN Upnp_DescType descriptionType,
OUT char descURL[LINE_SIZE] ); OUT char descURL[LINE_SIZE] );
/******************************************************************************/
int UpnpInit(IN const char *HostIP, IN unsigned short DestPort) int UpnpInit(IN const char *HostIP, IN unsigned short DestPort)
{ {
int retVal; int retVal;
@ -228,7 +227,6 @@ int UpnpInit(IN const char *HostIP, IN unsigned short DestPort)
} }
/******************************************************************************/
int UpnpInit2(IN const char *IfName, IN unsigned short DestPort) int UpnpInit2(IN const char *IfName, IN unsigned short DestPort)
{ {
int retVal; int retVal;
@ -275,7 +273,7 @@ int UpnpInit2(IN const char *IfName, IN unsigned short DestPort)
return UPNP_E_SUCCESS; return UPNP_E_SUCCESS;
} }
/******************************************************************************/
int UpnpFinish() int UpnpFinish()
{ {
#ifdef INCLUDE_DEVICE_APIS #ifdef INCLUDE_DEVICE_APIS
@ -359,7 +357,6 @@ int UpnpFinish()
} }
/******************************************************************************/
unsigned short UpnpGetServerPort() unsigned short UpnpGetServerPort()
{ {
if (UpnpSdkInit != 1) { if (UpnpSdkInit != 1) {
@ -369,7 +366,7 @@ unsigned short UpnpGetServerPort()
return LOCAL_PORT_V4; return LOCAL_PORT_V4;
} }
/******************************************************************************/
unsigned short UpnpGetServerPort6() unsigned short UpnpGetServerPort6()
{ {
if (UpnpSdkInit != 1) { if (UpnpSdkInit != 1) {
@ -379,7 +376,7 @@ unsigned short UpnpGetServerPort6()
return LOCAL_PORT_V6; return LOCAL_PORT_V6;
} }
/******************************************************************************/
char *UpnpGetServerIpAddress() char *UpnpGetServerIpAddress()
{ {
if (UpnpSdkInit != 1) { if (UpnpSdkInit != 1) {
@ -389,7 +386,7 @@ char *UpnpGetServerIpAddress()
return gIF_IPV4; return gIF_IPV4;
} }
/******************************************************************************/
char *UpnpGetServerIp6Address() char *UpnpGetServerIp6Address()
{ {
if( UpnpSdkInit != 1 ) { if( UpnpSdkInit != 1 ) {
@ -400,131 +397,136 @@ char *UpnpGetServerIp6Address()
} }
/******************************************************************************/
#ifdef INCLUDE_DEVICE_APIS #ifdef INCLUDE_DEVICE_APIS
int UpnpRegisterRootDevice( int UpnpRegisterRootDevice(
IN const char *DescUrl, IN const char *DescUrl,
IN Upnp_FunPtr Fun, IN Upnp_FunPtr Fun,
IN const void *Cookie, IN const void *Cookie,
OUT UpnpDevice_Handle * Hnd ) OUT UpnpDevice_Handle *Hnd)
{ {
struct Handle_Info *HInfo = NULL;
struct Handle_Info *HInfo;
int retVal = 0; int retVal = 0;
int hasServiceTable = 0;
if( UpnpSdkInit != 1 ) {
return UPNP_E_FINISH;
}
UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__,
"Inside UpnpRegisterRootDevice\n" );
HandleLock(); HandleLock();
if( Hnd == NULL || Fun == NULL ||
DescUrl == NULL || strlen( DescUrl ) == 0 ) { UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
HandleUnlock(); "Inside UpnpRegisterRootDevice\n");
return UPNP_E_INVALID_PARAM;
if (UpnpSdkInit != 1) {
retVal = UPNP_E_FINISH;
goto exit_function;
} }
if( UpnpSdkDeviceRegisteredV4 == 1 ) { if (Hnd == NULL ||
HandleUnlock(); Fun == NULL ||
return UPNP_E_ALREADY_REGISTERED; DescUrl == NULL ||
strlen(DescUrl) == 0) {
retVal = UPNP_E_INVALID_PARAM;
goto exit_function;
} }
if( ( *Hnd = GetFreeHandle() ) == UPNP_E_OUTOF_HANDLE ) { if (UpnpSdkDeviceRegisteredV4 == 1) {
HandleUnlock(); retVal = UPNP_E_ALREADY_REGISTERED;
return UPNP_E_OUTOF_MEMORY; goto exit_function;
} }
HInfo = ( struct Handle_Info * )malloc( sizeof( struct Handle_Info ) ); *Hnd = GetFreeHandle();
if( HInfo == NULL ) { if (*Hnd == UPNP_E_OUTOF_HANDLE) {
HandleUnlock(); retVal = UPNP_E_OUTOF_MEMORY;
return UPNP_E_OUTOF_MEMORY; goto exit_function;
}
HInfo = (struct Handle_Info *)malloc(sizeof (struct Handle_Info));
if (HInfo == NULL) {
retVal = UPNP_E_OUTOF_MEMORY;
goto exit_function;
} }
HandleTable[*Hnd] = HInfo; HandleTable[*Hnd] = HInfo;
UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
"Root device URL is %s\n", DescUrl ); "Root device URL is %s\n", DescUrl );
HInfo->aliasInstalled = 0; HInfo->aliasInstalled = 0;
HInfo->HType = HND_DEVICE; HInfo->HType = HND_DEVICE;
strcpy( HInfo->DescURL, DescUrl ); strcpy(HInfo->DescURL, DescUrl);
HInfo->Callback = Fun; HInfo->Callback = Fun;
HInfo->Cookie = ( void * )Cookie; HInfo->Cookie = (void *)Cookie;
HInfo->MaxAge = DEFAULT_MAXAGE; HInfo->MaxAge = DEFAULT_MAXAGE;
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;
HInfo->DeviceAf = AF_INET; HInfo->DeviceAf = AF_INET;
if( ( retVal = retVal = UpnpDownloadXmlDoc(HInfo->DescURL, &(HInfo->DescDocument));
UpnpDownloadXmlDoc( HInfo->DescURL, &( HInfo->DescDocument ) ) ) if (retVal != UPNP_E_SUCCESS) {
!= UPNP_E_SUCCESS ) { CLIENTONLY( ListDestroy(&HInfo->SsdpSearchList, 0); )
CLIENTONLY( ListDestroy( &HInfo->SsdpSearchList, 0 ) );
FreeHandle( *Hnd ); FreeHandle( *Hnd );
HandleUnlock(); retVal = retVal;
return retVal; goto exit_function;
} }
UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, "UpnpRegisterRootDevice: Valid Description\n"
"UpnpRegisterRootDevice: Valid Description\n" );
UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__,
"UpnpRegisterRootDevice: DescURL : %s\n", "UpnpRegisterRootDevice: DescURL : %s\n",
HInfo->DescURL ); HInfo->DescURL);
HInfo->DeviceList = HInfo->DeviceList =
ixmlDocument_getElementsByTagName( HInfo->DescDocument, "device" ); ixmlDocument_getElementsByTagName(HInfo->DescDocument, "device");
if( !HInfo->DeviceList ) { if (!HInfo->DeviceList) {
CLIENTONLY( ListDestroy( &HInfo->SsdpSearchList, 0 ) ); CLIENTONLY( ListDestroy(&HInfo->SsdpSearchList, 0); )
ixmlDocument_free( HInfo->DescDocument ); ixmlDocument_free(HInfo->DescDocument);
FreeHandle( *Hnd ); FreeHandle(*Hnd);
HandleUnlock(); UpnpPrintf(UPNP_CRITICAL, API, __FILE__, __LINE__,
UpnpPrintf( UPNP_CRITICAL, API, __FILE__, __LINE__, "UpnpRegisterRootDevice: No devices found for RootDevice\n");
"UpnpRegisterRootDevice: No devices found for RootDevice\n" ); retVal = UPNP_E_INVALID_DESC;
return UPNP_E_INVALID_DESC; goto exit_function;
} }
HInfo->ServiceList = ixmlDocument_getElementsByTagName( HInfo->ServiceList = ixmlDocument_getElementsByTagName(
HInfo->DescDocument, "serviceList" ); HInfo->DescDocument, "serviceList");
if( !HInfo->ServiceList ) { if (!HInfo->ServiceList) {
UpnpPrintf( UPNP_CRITICAL, API, __FILE__, __LINE__, UpnpPrintf(UPNP_CRITICAL, API, __FILE__, __LINE__,
"UpnpRegisterRootDevice: No services found for RootDevice\n" ); "UpnpRegisterRootDevice: No services found for RootDevice\n");
} }
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, /*
"UpnpRegisterRootDevice: Gena Check\n" ); * GENA SET UP
//******************************* */
// GENA SET UP UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
//******************************* "UpnpRegisterRootDevice: Gena Check\n");
if( getServiceTable( ( IXML_Node * ) HInfo->DescDocument, hasServiceTable = getServiceTable(
&HInfo->ServiceTable, HInfo->DescURL ) ) { (IXML_Node *)HInfo->DescDocument,
UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, &HInfo->ServiceTable,
"UpnpRegisterRootDevice: GENA Service Table \n" ); HInfo->DescURL);
UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, if (hasServiceTable) {
"Here are the known services: \n" ); UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
printServiceTable( &HInfo->ServiceTable, UPNP_INFO, API ); "UpnpRegisterRootDevice: GENA Service Table\n"
"Here are the known services:\n");
printServiceTable( &HInfo->ServiceTable, UPNP_ALL, API );
} else { } else {
UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
"\nUpnpRegisterRootDevice2: Empty service table\n" ); "\nUpnpRegisterRootDevice2: Empty service table\n");
} }
UpnpSdkDeviceRegisteredV4 = 1; UpnpSdkDeviceRegisteredV4 = 1;
HandleUnlock(); retVal = UPNP_E_SUCCESS;
UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__,
"Exiting RegisterRootDevice Successfully\n" );
return UPNP_E_SUCCESS; exit_function:
UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
"Exiting RegisterRootDevice, return value == %d\n", retVal);
HandleUnlock();
return retVal;
} }
#endif // INCLUDE_DEVICE_APIS #endif // INCLUDE_DEVICE_APIS
#ifdef INCLUDE_DEVICE_APIS #ifdef INCLUDE_DEVICE_APIS
/******************************************************************************/
int UpnpRegisterRootDevice2( int UpnpRegisterRootDevice2(
IN Upnp_DescType descriptionType, IN Upnp_DescType descriptionType,
IN const char *description_const, IN const char *description_const,
@ -532,37 +534,43 @@ int UpnpRegisterRootDevice2(
IN int config_baseURL, IN int config_baseURL,
IN Upnp_FunPtr Fun, IN Upnp_FunPtr Fun,
IN const void *Cookie, IN const void *Cookie,
OUT UpnpDevice_Handle * Hnd ) OUT UpnpDevice_Handle *Hnd)
{ {
struct Handle_Info *HInfo; struct Handle_Info *HInfo = NULL;
int retVal = 0; int retVal = 0;
char *description = ( char * )description_const; int hasServiceTable = 0;
if( UpnpSdkInit != 1 ) { char *description = (char *)description_const;
return UPNP_E_FINISH;
}
UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__,
"Inside UpnpRegisterRootDevice2\n" );
if( Hnd == NULL || Fun == NULL ) {
return UPNP_E_INVALID_PARAM;
}
HandleLock(); HandleLock();
if( UpnpSdkDeviceRegisteredV4 == 1 ) {
HandleUnlock(); UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
return UPNP_E_ALREADY_REGISTERED; "Inside UpnpRegisterRootDevice2\n");
if (UpnpSdkInit != 1) {
retVal = UPNP_E_FINISH;
goto exit_function;
} }
if( ( *Hnd = GetFreeHandle() ) == UPNP_E_OUTOF_HANDLE ) { if (Hnd == NULL || Fun == NULL) {
HandleUnlock(); retVal = UPNP_E_INVALID_PARAM;
return UPNP_E_OUTOF_MEMORY; goto exit_function;
} }
HInfo = ( struct Handle_Info * )malloc( sizeof( struct Handle_Info ) ); if (UpnpSdkDeviceRegisteredV4 == 1) {
if( HInfo == NULL ) { retVal = UPNP_E_ALREADY_REGISTERED;
HandleUnlock(); goto exit_function;
return UPNP_E_OUTOF_MEMORY; }
*Hnd = GetFreeHandle();
if (*Hnd == UPNP_E_OUTOF_HANDLE) {
retVal = UPNP_E_OUTOF_MEMORY;
goto exit_function;
}
HInfo = (struct Handle_Info *)malloc(sizeof (struct Handle_Info));
if (HInfo == NULL) {
retVal = UPNP_E_OUTOF_MEMORY;
goto exit_function;
} }
HandleTable[*Hnd] = HInfo; HandleTable[*Hnd] = HInfo;
@ -572,85 +580,83 @@ int UpnpRegisterRootDevice2(
retVal = GetDescDocumentAndURL( retVal = GetDescDocumentAndURL(
descriptionType, description, bufferLen, descriptionType, description, bufferLen,
config_baseURL, AF_INET, config_baseURL, AF_INET,
&HInfo->DescDocument, HInfo->DescURL ); &HInfo->DescDocument, HInfo->DescURL);
if (retVal != UPNP_E_SUCCESS) {
if( retVal != UPNP_E_SUCCESS ) { FreeHandle(*Hnd);
FreeHandle( *Hnd ); goto exit_function;
HandleUnlock();
return retVal;
} }
HInfo->aliasInstalled = ( config_baseURL != 0 ); HInfo->aliasInstalled = config_baseURL != 0;
HInfo->HType = HND_DEVICE; HInfo->HType = HND_DEVICE;
HInfo->Callback = Fun; HInfo->Callback = Fun;
HInfo->Cookie = ( void * )Cookie; HInfo->Cookie = (void *)Cookie;
HInfo->MaxAge = DEFAULT_MAXAGE; HInfo->MaxAge = DEFAULT_MAXAGE;
HInfo->DeviceList = NULL; HInfo->DeviceList = NULL;
HInfo->ServiceList = NULL; HInfo->ServiceList = 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;
HInfo->DeviceAf = AF_INET; HInfo->DeviceAf = AF_INET;
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
"UpnpRegisterRootDevice2: Valid Description\n" ); "UpnpRegisterRootDevice2: Valid Description\n"
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__,
"UpnpRegisterRootDevice2: DescURL : %s\n", "UpnpRegisterRootDevice2: DescURL : %s\n",
HInfo->DescURL ); HInfo->DescURL);
HInfo->DeviceList = HInfo->DeviceList =
ixmlDocument_getElementsByTagName( HInfo->DescDocument, "device" ); ixmlDocument_getElementsByTagName( HInfo->DescDocument, "device" );
if (!HInfo->DeviceList) {
if( !HInfo->DeviceList ) { CLIENTONLY( ListDestroy(&HInfo->SsdpSearchList, 0); )
CLIENTONLY( ListDestroy( &HInfo->SsdpSearchList, 0 ); ) ixmlDocument_free(HInfo->DescDocument);
ixmlDocument_free( HInfo->DescDocument ); FreeHandle(*Hnd);
FreeHandle( *Hnd ); UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
HandleUnlock();
UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__,
"UpnpRegisterRootDevice2: No devices found for RootDevice\n" ); "UpnpRegisterRootDevice2: No devices found for RootDevice\n" );
return UPNP_E_INVALID_DESC; retVal = UPNP_E_INVALID_DESC;
goto exit_function;
} }
HInfo->ServiceList = ixmlDocument_getElementsByTagName( HInfo->ServiceList = ixmlDocument_getElementsByTagName(
HInfo->DescDocument, "serviceList" ); HInfo->DescDocument, "serviceList" );
if( !HInfo->ServiceList ) { if (!HInfo->ServiceList) {
UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
"UpnpRegisterRootDevice2: No services found for RootDevice\n" ); "UpnpRegisterRootDevice2: No services found for RootDevice\n");
} }
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, /*
* GENA SET UP
*/
UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
"UpnpRegisterRootDevice2: Gena Check\n" ); "UpnpRegisterRootDevice2: Gena Check\n" );
//******************************* hasServiceTable = getServiceTable(
// GENA SET UP (IXML_Node *)HInfo->DescDocument,
//******************************* &HInfo->ServiceTable,
if( getServiceTable( ( IXML_Node * ) HInfo->DescDocument, HInfo->DescURL);
&HInfo->ServiceTable, HInfo->DescURL ) ) { if (hasServiceTable) {
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
"UpnpRegisterRootDevice2: GENA Service Table\n" ); "UpnpRegisterRootDevice2: GENA Service Table\n"
UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, "Here are the known services: \n");
"Here are the known services: \n" ); printServiceTable(&HInfo->ServiceTable, UPNP_ALL, API);
printServiceTable( &HInfo->ServiceTable, UPNP_INFO, API );
} else { } else {
UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
"\nUpnpRegisterRootDevice2: Empty service table\n" ); "\nUpnpRegisterRootDevice2: Empty service table\n");
} }
UpnpSdkDeviceRegisteredV4 = 1; UpnpSdkDeviceRegisteredV4 = 1;
HandleUnlock(); retVal = UPNP_E_SUCCESS;
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__,
"Exiting RegisterRootDevice2 Successfully\n" );
return UPNP_E_SUCCESS; exit_function:
UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
"Exiting RegisterRootDevice2, return value == %d\n", retVal);
HandleUnlock();
return retVal;
} }
#endif // INCLUDE_DEVICE_APIS #endif // INCLUDE_DEVICE_APIS
#ifdef INCLUDE_DEVICE_APIS #ifdef INCLUDE_DEVICE_APIS
/******************************************************************************/
int UpnpRegisterRootDevice3( int UpnpRegisterRootDevice3(
IN const char *DescUrl, IN const char *DescUrl,
IN Upnp_FunPtr Fun, IN Upnp_FunPtr Fun,
@ -660,119 +666,126 @@ int UpnpRegisterRootDevice3(
{ {
struct Handle_Info *HInfo; struct Handle_Info *HInfo;
int retVal = 0; int retVal = 0;
int hasServiceTable = 0;
if( UpnpSdkInit != 1 ) {
return UPNP_E_FINISH;
}
UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__,
"Inside UpnpRegisterRootDevice\n" );
HandleLock(); HandleLock();
if( Hnd == NULL || Fun == NULL ||
DescUrl == NULL || strlen( DescUrl ) == 0 || UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
(AddressFamily != AF_INET && AddressFamily != AF_INET6) ) { "Inside UpnpRegisterRootDevice\n");
HandleUnlock();
return UPNP_E_INVALID_PARAM; if (UpnpSdkInit != 1) {
retVal = UPNP_E_FINISH;
goto exit_function;
} }
if( ( AddressFamily == AF_INET && UpnpSdkDeviceRegisteredV4 == 1 ) || if (Hnd == NULL ||
( AddressFamily == AF_INET6 && UpnpSdkDeviceregisteredV6 == 1 ) ) { Fun == NULL ||
HandleUnlock(); DescUrl == NULL ||
return UPNP_E_ALREADY_REGISTERED; strlen(DescUrl) == 0 ||
(AddressFamily != AF_INET && AddressFamily != AF_INET6)) {
retVal = UPNP_E_INVALID_PARAM;
goto exit_function;
} }
if( ( *Hnd = GetFreeHandle() ) == UPNP_E_OUTOF_HANDLE ) { if ((AddressFamily == AF_INET && UpnpSdkDeviceRegisteredV4 == 1) ||
HandleUnlock(); (AddressFamily == AF_INET6 && UpnpSdkDeviceregisteredV6 == 1)) {
return UPNP_E_OUTOF_MEMORY; retVal = UPNP_E_ALREADY_REGISTERED;
goto exit_function;
} }
HInfo = ( struct Handle_Info * )malloc( sizeof( struct Handle_Info ) ); *Hnd = GetFreeHandle();
if( HInfo == NULL ) { if (*Hnd == UPNP_E_OUTOF_HANDLE) {
HandleUnlock(); retVal = UPNP_E_OUTOF_MEMORY;
return UPNP_E_OUTOF_MEMORY; goto exit_function;
}
HInfo = (struct Handle_Info *)malloc(sizeof (struct Handle_Info));
if (HInfo == NULL) {
retVal = UPNP_E_OUTOF_MEMORY;
goto exit_function;
} }
HandleTable[*Hnd] = HInfo; HandleTable[*Hnd] = HInfo;
UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, "Root device URL is %s\n", DescUrl);
"Root device URL is %s\n", DescUrl );
HInfo->aliasInstalled = 0; HInfo->aliasInstalled = 0;
HInfo->HType = HND_DEVICE; HInfo->HType = HND_DEVICE;
strcpy( HInfo->DescURL, DescUrl ); strcpy(HInfo->DescURL, DescUrl);
HInfo->Callback = Fun; HInfo->Callback = Fun;
HInfo->Cookie = ( void * )Cookie; HInfo->Cookie = (void *)Cookie;
HInfo->MaxAge = DEFAULT_MAXAGE; HInfo->MaxAge = DEFAULT_MAXAGE;
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;
HInfo->DeviceAf = AddressFamily; HInfo->DeviceAf = AddressFamily;
if( ( retVal = retVal = UpnpDownloadXmlDoc(HInfo->DescURL, &(HInfo->DescDocument));
UpnpDownloadXmlDoc( HInfo->DescURL, &( HInfo->DescDocument ) ) ) if (retVal != UPNP_E_SUCCESS) {
!= UPNP_E_SUCCESS ) { CLIENTONLY( ListDestroy(&HInfo->SsdpSearchList, 0); )
CLIENTONLY( ListDestroy( &HInfo->SsdpSearchList, 0 ) ); FreeHandle(*Hnd);
FreeHandle( *Hnd ); goto exit_function;
HandleUnlock();
return retVal;
} }
UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, "UpnpRegisterRootDevice: Valid Description\n"
"UpnpRegisterRootDevice: Valid Description\n" );
UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__,
"UpnpRegisterRootDevice: DescURL : %s\n", "UpnpRegisterRootDevice: DescURL : %s\n",
HInfo->DescURL ); HInfo->DescURL);
HInfo->DeviceList = HInfo->DeviceList = ixmlDocument_getElementsByTagName(
ixmlDocument_getElementsByTagName( HInfo->DescDocument, "device" ); HInfo->DescDocument, "device");
if( !HInfo->DeviceList ) { if (!HInfo->DeviceList) {
CLIENTONLY( ListDestroy( &HInfo->SsdpSearchList, 0 ) ); CLIENTONLY( ListDestroy(&HInfo->SsdpSearchList, 0); )
ixmlDocument_free( HInfo->DescDocument ); ixmlDocument_free(HInfo->DescDocument);
FreeHandle( *Hnd ); FreeHandle(*Hnd);
HandleUnlock(); UpnpPrintf(UPNP_CRITICAL, API, __FILE__, __LINE__,
UpnpPrintf( UPNP_CRITICAL, API, __FILE__, __LINE__, "UpnpRegisterRootDevice: No devices found for RootDevice\n");
"UpnpRegisterRootDevice: No devices found for RootDevice\n" ); retVal = UPNP_E_INVALID_DESC;
return UPNP_E_INVALID_DESC; goto exit_function;
} }
HInfo->ServiceList = ixmlDocument_getElementsByTagName( HInfo->ServiceList = ixmlDocument_getElementsByTagName(
HInfo->DescDocument, "serviceList" ); HInfo->DescDocument, "serviceList" );
if( !HInfo->ServiceList ) { if (!HInfo->ServiceList) {
UpnpPrintf( UPNP_CRITICAL, API, __FILE__, __LINE__, UpnpPrintf(UPNP_CRITICAL, API, __FILE__, __LINE__,
"UpnpRegisterRootDevice: No services found for RootDevice\n" ); "UpnpRegisterRootDevice: No services found for RootDevice\n");
} }
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, /*
"UpnpRegisterRootDevice: Gena Check\n" ); * GENA SET UP
//******************************* */
// GENA SET UP UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
//******************************* "UpnpRegisterRootDevice3: Gena Check\n" );
if( getServiceTable( ( IXML_Node * ) HInfo->DescDocument, hasServiceTable = getServiceTable(
&HInfo->ServiceTable, HInfo->DescURL ) ) { (IXML_Node *)HInfo->DescDocument,
UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, &HInfo->ServiceTable,
"UpnpRegisterRootDevice: GENA Service Table \n" ); HInfo->DescURL);
UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, if (hasServiceTable) {
UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
"UpnpRegisterRootDevice: GENA Service Table \n"
"Here are the known services: \n" ); "Here are the known services: \n" );
printServiceTable( &HInfo->ServiceTable, UPNP_INFO, API ); printServiceTable(&HInfo->ServiceTable, UPNP_ALL, API);
} else { } else {
UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
"\nUpnpRegisterRootDevice2: Empty service table\n" ); "\nUpnpRegisterRootDevice3: Empty service table\n");
} }
if( AddressFamily == AF_INET ) if (AddressFamily == AF_INET) {
UpnpSdkDeviceRegisteredV4 = 1; UpnpSdkDeviceRegisteredV4 = 1;
else } else {
UpnpSdkDeviceregisteredV6 = 1; UpnpSdkDeviceregisteredV6 = 1;
}
retVal = UPNP_E_SUCCESS;
exit_function:
UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
"Exiting RegisterRootDevice3, return value == %d\n", retVal);
HandleUnlock(); HandleUnlock();
UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__,
"Exiting RegisterRootDevice Successfully\n" );
return UPNP_E_SUCCESS; return retVal;
} }
#endif // INCLUDE_DEVICE_APIS #endif // INCLUDE_DEVICE_APIS
@ -785,12 +798,12 @@ int UpnpUnRegisterRootDevice(IN UpnpDevice_Handle Hnd)
// struct Handle_Info *info=NULL; // struct Handle_Info *info=NULL;
if( UpnpSdkInit != 1 ) { if (UpnpSdkInit != 1) {
return UPNP_E_FINISH; return UPNP_E_FINISH;
} }
UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__,
"Inside UpnpUnRegisterRootDevice \n" ); "Inside UpnpUnRegisterRootDevice \n");
#if EXCLUDE_GENA == 0 #if EXCLUDE_GENA == 0
if( genaUnregisterDevice( Hnd ) != UPNP_E_SUCCESS ) if( genaUnregisterDevice( Hnd ) != UPNP_E_SUCCESS )
return UPNP_E_INVALID_HANDLE; return UPNP_E_INVALID_HANDLE;