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;
int retVal = 0;
int hasServiceTable = 0;
struct Handle_Info *HInfo; HandleLock();
int retVal = 0;
if( UpnpSdkInit != 1 ) { UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
return UPNP_E_FINISH; "Inside UpnpRegisterRootDevice\n");
}
UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, if (UpnpSdkInit != 1) {
"Inside UpnpRegisterRootDevice\n" ); retVal = UPNP_E_FINISH;
goto exit_function;
}
HandleLock(); if (Hnd == NULL ||
if( Hnd == NULL || Fun == NULL || Fun == NULL ||
DescUrl == NULL || strlen( DescUrl ) == 0 ) { DescUrl == NULL ||
HandleUnlock(); strlen(DescUrl) == 0) {
return UPNP_E_INVALID_PARAM; retVal = UPNP_E_INVALID_PARAM;
} goto exit_function;
}
if( UpnpSdkDeviceRegisteredV4 == 1 ) { if (UpnpSdkDeviceRegisteredV4 == 1) {
HandleUnlock(); retVal = UPNP_E_ALREADY_REGISTERED;
return UPNP_E_ALREADY_REGISTERED; goto exit_function;
} }
if( ( *Hnd = GetFreeHandle() ) == UPNP_E_OUTOF_HANDLE ) { *Hnd = GetFreeHandle();
HandleUnlock(); if (*Hnd == UPNP_E_OUTOF_HANDLE) {
return UPNP_E_OUTOF_MEMORY; retVal = UPNP_E_OUTOF_MEMORY;
} goto exit_function;
}
HInfo = ( struct Handle_Info * )malloc( sizeof( struct Handle_Info ) ); HInfo = (struct Handle_Info *)malloc(sizeof (struct Handle_Info));
if( HInfo == NULL ) { if (HInfo == NULL) {
HandleUnlock(); retVal = UPNP_E_OUTOF_MEMORY;
return 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 ); retVal = retVal;
HandleUnlock(); goto exit_function;
return retVal; }
} UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
"UpnpRegisterRootDevice: Valid Description\n"
"UpnpRegisterRootDevice: DescURL : %s\n",
HInfo->DescURL);
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, HInfo->DeviceList =
"UpnpRegisterRootDevice: Valid Description\n" ); ixmlDocument_getElementsByTagName(HInfo->DescDocument, "device");
UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, if (!HInfo->DeviceList) {
"UpnpRegisterRootDevice: DescURL : %s\n", CLIENTONLY( ListDestroy(&HInfo->SsdpSearchList, 0); )
HInfo->DescURL ); ixmlDocument_free(HInfo->DescDocument);
FreeHandle(*Hnd);
UpnpPrintf(UPNP_CRITICAL, API, __FILE__, __LINE__,
"UpnpRegisterRootDevice: No devices found for RootDevice\n");
retVal = UPNP_E_INVALID_DESC;
goto exit_function;
}
HInfo->DeviceList = HInfo->ServiceList = ixmlDocument_getElementsByTagName(
ixmlDocument_getElementsByTagName( HInfo->DescDocument, "device" ); HInfo->DescDocument, "serviceList");
if( !HInfo->DeviceList ) { if (!HInfo->ServiceList) {
CLIENTONLY( ListDestroy( &HInfo->SsdpSearchList, 0 ) ); UpnpPrintf(UPNP_CRITICAL, API, __FILE__, __LINE__,
ixmlDocument_free( HInfo->DescDocument ); "UpnpRegisterRootDevice: No services found for RootDevice\n");
FreeHandle( *Hnd ); }
HandleUnlock();
UpnpPrintf( UPNP_CRITICAL, API, __FILE__, __LINE__,
"UpnpRegisterRootDevice: No devices found for RootDevice\n" );
return UPNP_E_INVALID_DESC;
}
HInfo->ServiceList = ixmlDocument_getElementsByTagName( /*
HInfo->DescDocument, "serviceList" ); * GENA SET UP
if( !HInfo->ServiceList ) { */
UpnpPrintf( UPNP_CRITICAL, API, __FILE__, __LINE__, UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
"UpnpRegisterRootDevice: No services found for RootDevice\n" ); "UpnpRegisterRootDevice: Gena Check\n");
} hasServiceTable = getServiceTable(
(IXML_Node *)HInfo->DescDocument,
&HInfo->ServiceTable,
HInfo->DescURL);
if (hasServiceTable) {
UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
"UpnpRegisterRootDevice: GENA Service Table\n"
"Here are the known services:\n");
printServiceTable( &HInfo->ServiceTable, UPNP_ALL, API );
} else {
UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
"\nUpnpRegisterRootDevice2: Empty service table\n");
}
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, UpnpSdkDeviceRegisteredV4 = 1;
"UpnpRegisterRootDevice: Gena Check\n" );
//*******************************
// GENA SET UP
//*******************************
if( getServiceTable( ( IXML_Node * ) HInfo->DescDocument,
&HInfo->ServiceTable, HInfo->DescURL ) ) {
UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__,
"UpnpRegisterRootDevice: GENA Service Table \n" );
UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__,
"Here are the known services: \n" );
printServiceTable( &HInfo->ServiceTable, UPNP_INFO, API );
} else {
UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__,
"\nUpnpRegisterRootDevice2: Empty service table\n" );
}
UpnpSdkDeviceRegisteredV4 = 1; retVal = UPNP_E_SUCCESS;
HandleUnlock(); exit_function:
UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
"Exiting RegisterRootDevice Successfully\n" ); "Exiting RegisterRootDevice, return value == %d\n", retVal);
HandleUnlock();
return UPNP_E_SUCCESS; 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,125 +534,129 @@ 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__, HandleLock();
"Inside UpnpRegisterRootDevice2\n" );
if( Hnd == NULL || Fun == NULL ) { UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
return UPNP_E_INVALID_PARAM; "Inside UpnpRegisterRootDevice2\n");
}
HandleLock(); if (UpnpSdkInit != 1) {
if( UpnpSdkDeviceRegisteredV4 == 1 ) { retVal = UPNP_E_FINISH;
HandleUnlock(); goto exit_function;
return UPNP_E_ALREADY_REGISTERED; }
}
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; }
}
HandleTable[*Hnd] = HInfo;
// prevent accidental removal of a non-existent alias *Hnd = GetFreeHandle();
HInfo->aliasInstalled = 0; if (*Hnd == UPNP_E_OUTOF_HANDLE) {
retVal = UPNP_E_OUTOF_MEMORY;
goto exit_function;
}
retVal = GetDescDocumentAndURL( HInfo = (struct Handle_Info *)malloc(sizeof (struct Handle_Info));
descriptionType, description, bufferLen, if (HInfo == NULL) {
config_baseURL, AF_INET, retVal = UPNP_E_OUTOF_MEMORY;
&HInfo->DescDocument, HInfo->DescURL ); goto exit_function;
}
HandleTable[*Hnd] = HInfo;
if( retVal != UPNP_E_SUCCESS ) { // prevent accidental removal of a non-existent alias
FreeHandle( *Hnd ); HInfo->aliasInstalled = 0;
HandleUnlock();
return retVal;
}
HInfo->aliasInstalled = ( config_baseURL != 0 ); retVal = GetDescDocumentAndURL(
HInfo->HType = HND_DEVICE; descriptionType, description, bufferLen,
config_baseURL, AF_INET,
&HInfo->DescDocument, HInfo->DescURL);
if (retVal != UPNP_E_SUCCESS) {
FreeHandle(*Hnd);
goto exit_function;
}
HInfo->Callback = Fun; HInfo->aliasInstalled = config_baseURL != 0;
HInfo->Cookie = ( void * )Cookie; HInfo->HType = HND_DEVICE;
HInfo->MaxAge = DEFAULT_MAXAGE; HInfo->Callback = Fun;
HInfo->DeviceList = NULL; HInfo->Cookie = (void *)Cookie;
HInfo->ServiceList = NULL; HInfo->MaxAge = DEFAULT_MAXAGE;
HInfo->DeviceList = NULL;
HInfo->ServiceList = NULL;
CLIENTONLY( ListInit(&HInfo->SsdpSearchList, NULL, NULL); )
CLIENTONLY( HInfo->ClientSubList = NULL; )
HInfo->MaxSubscriptions = UPNP_INFINITE;
HInfo->MaxSubscriptionTimeOut = UPNP_INFINITE;
HInfo->DeviceAf = AF_INET;
CLIENTONLY( ListInit( &HInfo->SsdpSearchList, NULL, NULL ); ) UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
CLIENTONLY( HInfo->ClientSubList = NULL; ) "UpnpRegisterRootDevice2: Valid Description\n"
HInfo->MaxSubscriptions = UPNP_INFINITE; "UpnpRegisterRootDevice2: DescURL : %s\n",
HInfo->MaxSubscriptionTimeOut = UPNP_INFINITE; HInfo->DescURL);
HInfo->DeviceAf = AF_INET;
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, HInfo->DeviceList =
"UpnpRegisterRootDevice2: Valid Description\n" ); ixmlDocument_getElementsByTagName( HInfo->DescDocument, "device" );
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, if (!HInfo->DeviceList) {
"UpnpRegisterRootDevice2: DescURL : %s\n", CLIENTONLY( ListDestroy(&HInfo->SsdpSearchList, 0); )
HInfo->DescURL ); ixmlDocument_free(HInfo->DescDocument);
FreeHandle(*Hnd);
UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
"UpnpRegisterRootDevice2: No devices found for RootDevice\n" );
retVal = UPNP_E_INVALID_DESC;
goto exit_function;
}
HInfo->DeviceList = HInfo->ServiceList = ixmlDocument_getElementsByTagName(
ixmlDocument_getElementsByTagName( HInfo->DescDocument, "device" ); HInfo->DescDocument, "serviceList" );
if (!HInfo->ServiceList) {
UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
"UpnpRegisterRootDevice2: No services found for RootDevice\n");
}
if( !HInfo->DeviceList ) { /*
CLIENTONLY( ListDestroy( &HInfo->SsdpSearchList, 0 ); ) * GENA SET UP
ixmlDocument_free( HInfo->DescDocument ); */
FreeHandle( *Hnd ); UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
HandleUnlock(); "UpnpRegisterRootDevice2: Gena Check\n" );
UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, hasServiceTable = getServiceTable(
"UpnpRegisterRootDevice2: No devices found for RootDevice\n" ); (IXML_Node *)HInfo->DescDocument,
return UPNP_E_INVALID_DESC; &HInfo->ServiceTable,
} HInfo->DescURL);
if (hasServiceTable) {
UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
"UpnpRegisterRootDevice2: GENA Service Table\n"
"Here are the known services: \n");
printServiceTable(&HInfo->ServiceTable, UPNP_ALL, API);
} else {
UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
"\nUpnpRegisterRootDevice2: Empty service table\n");
}
HInfo->ServiceList = ixmlDocument_getElementsByTagName( UpnpSdkDeviceRegisteredV4 = 1;
HInfo->DescDocument, "serviceList" );
if( !HInfo->ServiceList ) {
UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__,
"UpnpRegisterRootDevice2: No services found for RootDevice\n" );
}
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, retVal = UPNP_E_SUCCESS;
"UpnpRegisterRootDevice2: Gena Check\n" );
//*******************************
// GENA SET UP
//*******************************
if( getServiceTable( ( IXML_Node * ) HInfo->DescDocument,
&HInfo->ServiceTable, HInfo->DescURL ) ) {
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__,
"UpnpRegisterRootDevice2: GENA Service Table\n" );
UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__,
"Here are the known services: \n" );
printServiceTable( &HInfo->ServiceTable, UPNP_INFO, API );
} else {
UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__,
"\nUpnpRegisterRootDevice2: Empty service table\n" );
}
UpnpSdkDeviceRegisteredV4 = 1; exit_function:
UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
"Exiting RegisterRootDevice2, return value == %d\n", retVal);
HandleUnlock();
HandleUnlock(); return retVal;
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__,
"Exiting RegisterRootDevice2 Successfully\n" );
return UPNP_E_SUCCESS;
} }
#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,
@ -658,121 +664,128 @@ int UpnpRegisterRootDevice3(
OUT UpnpDevice_Handle * Hnd, OUT UpnpDevice_Handle * Hnd,
IN const int AddressFamily ) IN const int AddressFamily )
{ {
struct Handle_Info *HInfo; struct Handle_Info *HInfo;
int retVal = 0; int retVal = 0;
int hasServiceTable = 0;
if( UpnpSdkInit != 1 ) { HandleLock();
return UPNP_E_FINISH;
}
UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
"Inside UpnpRegisterRootDevice\n" ); "Inside UpnpRegisterRootDevice\n");
HandleLock();
if( Hnd == NULL || Fun == NULL ||
DescUrl == NULL || strlen( DescUrl ) == 0 ||
(AddressFamily != AF_INET && AddressFamily != AF_INET6) ) {
HandleUnlock();
return UPNP_E_INVALID_PARAM;
}
if( ( AddressFamily == AF_INET && UpnpSdkDeviceRegisteredV4 == 1 ) || if (UpnpSdkInit != 1) {
( AddressFamily == AF_INET6 && UpnpSdkDeviceregisteredV6 == 1 ) ) { retVal = UPNP_E_FINISH;
HandleUnlock(); goto exit_function;
return UPNP_E_ALREADY_REGISTERED; }
}
if( ( *Hnd = GetFreeHandle() ) == UPNP_E_OUTOF_HANDLE ) { if (Hnd == NULL ||
HandleUnlock(); Fun == NULL ||
return UPNP_E_OUTOF_MEMORY; DescUrl == NULL ||
} strlen(DescUrl) == 0 ||
(AddressFamily != AF_INET && AddressFamily != AF_INET6)) {
retVal = UPNP_E_INVALID_PARAM;
goto exit_function;
}
HInfo = ( struct Handle_Info * )malloc( sizeof( struct Handle_Info ) ); if ((AddressFamily == AF_INET && UpnpSdkDeviceRegisteredV4 == 1) ||
if( HInfo == NULL ) { (AddressFamily == AF_INET6 && UpnpSdkDeviceregisteredV6 == 1)) {
HandleUnlock(); retVal = UPNP_E_ALREADY_REGISTERED;
return UPNP_E_OUTOF_MEMORY; goto exit_function;
} }
HandleTable[*Hnd] = HInfo;
UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, *Hnd = GetFreeHandle();
"Root device URL is %s\n", DescUrl ); if (*Hnd == UPNP_E_OUTOF_HANDLE) {
retVal = UPNP_E_OUTOF_MEMORY;
goto exit_function;
}
HInfo->aliasInstalled = 0; HInfo = (struct Handle_Info *)malloc(sizeof (struct Handle_Info));
HInfo->HType = HND_DEVICE; if (HInfo == NULL) {
strcpy( HInfo->DescURL, DescUrl ); retVal = UPNP_E_OUTOF_MEMORY;
HInfo->Callback = Fun; goto exit_function;
HInfo->Cookie = ( void * )Cookie; }
HInfo->MaxAge = DEFAULT_MAXAGE; HandleTable[*Hnd] = HInfo;
HInfo->DeviceList = NULL; UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
HInfo->ServiceList = NULL; "Root device URL is %s\n", DescUrl);
HInfo->DescDocument = NULL;
CLIENTONLY( ListInit( &HInfo->SsdpSearchList, NULL, NULL ); )
CLIENTONLY( HInfo->ClientSubList = NULL; )
HInfo->MaxSubscriptions = UPNP_INFINITE;
HInfo->MaxSubscriptionTimeOut = UPNP_INFINITE;
HInfo->DeviceAf = AddressFamily;
if( ( retVal = HInfo->aliasInstalled = 0;
UpnpDownloadXmlDoc( HInfo->DescURL, &( HInfo->DescDocument ) ) ) HInfo->HType = HND_DEVICE;
!= UPNP_E_SUCCESS ) { strcpy(HInfo->DescURL, DescUrl);
CLIENTONLY( ListDestroy( &HInfo->SsdpSearchList, 0 ) ); HInfo->Callback = Fun;
FreeHandle( *Hnd ); HInfo->Cookie = (void *)Cookie;
HandleUnlock(); HInfo->MaxAge = DEFAULT_MAXAGE;
return retVal; HInfo->DeviceList = NULL;
} HInfo->ServiceList = NULL;
HInfo->DescDocument = NULL;
CLIENTONLY( ListInit(&HInfo->SsdpSearchList, NULL, NULL); )
CLIENTONLY( HInfo->ClientSubList = NULL; )
HInfo->MaxSubscriptions = UPNP_INFINITE;
HInfo->MaxSubscriptionTimeOut = UPNP_INFINITE;
HInfo->DeviceAf = AddressFamily;
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, retVal = UpnpDownloadXmlDoc(HInfo->DescURL, &(HInfo->DescDocument));
"UpnpRegisterRootDevice: Valid Description\n" ); if (retVal != UPNP_E_SUCCESS) {
UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, CLIENTONLY( ListDestroy(&HInfo->SsdpSearchList, 0); )
"UpnpRegisterRootDevice: DescURL : %s\n", FreeHandle(*Hnd);
HInfo->DescURL ); goto exit_function;
}
UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
"UpnpRegisterRootDevice: Valid Description\n"
"UpnpRegisterRootDevice: DescURL : %s\n",
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) {
"Here are the known services: \n" ); UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
printServiceTable( &HInfo->ServiceTable, UPNP_INFO, API ); "UpnpRegisterRootDevice: GENA Service Table \n"
} else { "Here are the known services: \n" );
UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, printServiceTable(&HInfo->ServiceTable, UPNP_ALL, API);
"\nUpnpRegisterRootDevice2: Empty service table\n" ); } else {
} UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
"\nUpnpRegisterRootDevice3: Empty service table\n");
}
if( AddressFamily == AF_INET ) if (AddressFamily == AF_INET) {
UpnpSdkDeviceRegisteredV4 = 1; UpnpSdkDeviceRegisteredV4 = 1;
else } else {
UpnpSdkDeviceregisteredV6 = 1; UpnpSdkDeviceregisteredV6 = 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 RegisterRootDevice3, return value == %d\n", retVal);
HandleUnlock();
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;