Improoving debug code.

git-svn-id: https://pupnp.svn.sourceforge.net/svnroot/pupnp/trunk@377 119443c7-1b9e-41f8-b6fc-b9c35fce742c
This commit is contained in:
Marcelo Roberto Jimenez 2008-05-07 21:56:49 +00:00
parent efb6812b3e
commit e90e549cbb

View File

@ -464,9 +464,11 @@ int UpnpRegisterRootDevice(
retVal = UpnpDownloadXmlDoc(HInfo->DescURL, &(HInfo->DescDocument)); retVal = UpnpDownloadXmlDoc(HInfo->DescURL, &(HInfo->DescDocument));
if (retVal != UPNP_E_SUCCESS) { if (retVal != UPNP_E_SUCCESS) {
UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
"UpnpRegisterRootDevice: error downloading Document: %d\n",
retVal);
CLIENTONLY( ListDestroy(&HInfo->SsdpSearchList, 0); ) CLIENTONLY( ListDestroy(&HInfo->SsdpSearchList, 0); )
FreeHandle( *Hnd ); FreeHandle(*Hnd);
retVal = retVal;
goto exit_function; goto exit_function;
} }
UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__, UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
@ -846,7 +848,7 @@ int UpnpUnRegisterRootDevice(IN UpnpDevice_Handle Hnd)
UpnpSdkDeviceregisteredV6 = 0; UpnpSdkDeviceregisteredV6 = 0;
} }
FreeHandle( Hnd ); FreeHandle(Hnd);
HandleUnlock(); HandleUnlock();
UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__,
@ -959,7 +961,7 @@ int UpnpUnRegisterClient(IN UpnpClient_Handle Hnd)
} }
ListDestroy( &HInfo->SsdpSearchList, 0 ); ListDestroy( &HInfo->SsdpSearchList, 0 );
FreeHandle( Hnd ); FreeHandle(Hnd);
UpnpSdkClientRegistered = 0; UpnpSdkClientRegistered = 0;
HandleUnlock(); HandleUnlock();
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__,
@ -3144,62 +3146,64 @@ UpnpDownloadUrlItem( const char *url,
* Return Values: int * Return Values: int
* UPNP_E_SUCCESS if successful else sends appropriate error. * UPNP_E_SUCCESS if successful else sends appropriate error.
***************************************************************************/ ***************************************************************************/
int int UpnpDownloadXmlDoc(const char *url, IXML_Document **xmlDoc)
UpnpDownloadXmlDoc( const char *url,
IXML_Document ** xmlDoc )
{ {
int ret_code; int ret_code;
char *xml_buf; char *xml_buf;
char content_type[LINE_SIZE]; char content_type[LINE_SIZE];
if( url == NULL || xmlDoc == NULL ) { if (url == NULL || xmlDoc == NULL) {
return UPNP_E_INVALID_PARAM; return UPNP_E_INVALID_PARAM;
} }
ret_code = UpnpDownloadUrlItem( url, &xml_buf, content_type ); ret_code = UpnpDownloadUrlItem(url, &xml_buf, content_type);
if( ret_code != UPNP_E_SUCCESS ) { if (ret_code != UPNP_E_SUCCESS) {
UpnpPrintf( UPNP_CRITICAL, API, __FILE__, __LINE__, UpnpPrintf(UPNP_CRITICAL, API, __FILE__, __LINE__,
"retCode: %d\n", ret_code ); "Error downloading document, retCode: %d\n", ret_code);
return ret_code; return ret_code;
} }
if( strncasecmp( content_type, "text/xml", strlen( "text/xml" ) ) ) { if (strncasecmp(content_type, "text/xml", strlen("text/xml"))) {
UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, "Not text/xml\n" ); UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__, "Not text/xml\n");
// Linksys WRT54G router returns // Linksys WRT54G router returns
// "CONTENT-TYPE: application/octet-stream". // "CONTENT-TYPE: application/octet-stream".
// Let's be nice to Linksys and try to parse document anyway. // Let's be nice to Linksys and try to parse document anyway.
// If the data sended is not a xml file, ixmlParseBufferEx // If the data sended is not a xml file, ixmlParseBufferEx
// will fail and the function will return UPNP_E_INVALID_DESC too. // will fail and the function will return UPNP_E_INVALID_DESC too.
#if 0 #if 0
free( xml_buf ); free(xml_buf);
return UPNP_E_INVALID_DESC; return UPNP_E_INVALID_DESC;
#endif #endif
} }
ret_code = ixmlParseBufferEx( xml_buf, xmlDoc ); ret_code = ixmlParseBufferEx(xml_buf, xmlDoc);
free( xml_buf ); free(xml_buf);
if (ret_code != IXML_SUCCESS) {
if( ret_code != IXML_SUCCESS ) { if (ret_code == IXML_INSUFFICIENT_MEMORY) {
UpnpPrintf( UPNP_CRITICAL, API, __FILE__, __LINE__, UpnpPrintf(UPNP_CRITICAL, API, __FILE__, __LINE__,
"Invalid desc\n" ); "Out of memory, ixml error code: %d\n",
if( ret_code == IXML_INSUFFICIENT_MEMORY ) { ret_code);
return UPNP_E_OUTOF_MEMORY; return UPNP_E_OUTOF_MEMORY;
} else { } else {
return UPNP_E_INVALID_DESC; UpnpPrintf(UPNP_CRITICAL, API, __FILE__, __LINE__,
} "Invalid Description, ixml error code: %d\n",
} else { ret_code);
return UPNP_E_INVALID_DESC;
}
} else {
#ifdef DEBUG #ifdef DEBUG
xml_buf = ixmlPrintNode( ( IXML_Node * ) * xmlDoc ); xml_buf = ixmlPrintNode((IXML_Node *)*xmlDoc);
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__,
"Printing the Parsed xml document \n %s\n", xml_buf ); "Printing the Parsed xml document \n %s\n", xml_buf);
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__,
"****************** END OF Parsed XML Doc *****************\n" ); "****************** END OF Parsed XML Doc *****************\n");
ixmlFreeDOMString( xml_buf ); ixmlFreeDOMString(xml_buf);
#endif #endif
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__,
"Exiting UpnpDownloadXmlDoc\n" ); "Exiting UpnpDownloadXmlDoc\n");
return UPNP_E_SUCCESS;
} return UPNP_E_SUCCESS;
}
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
@ -4121,15 +4125,15 @@ int FreeHandle(int Upnp_Handle)
int ret = UPNP_E_INVALID_HANDLE; int ret = UPNP_E_INVALID_HANDLE;
UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__, UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__,
"FreeHandleInfo: entering, Handle is %d\n", Upnp_Handle); "FreeHandle: entering, Handle is %d\n", Upnp_Handle);
if (Upnp_Handle < 1 || Upnp_Handle >= NUM_HANDLE) { if (Upnp_Handle < 1 || Upnp_Handle >= NUM_HANDLE) {
UpnpPrintf(UPNP_CRITICAL, API, __FILE__, __LINE__, UpnpPrintf(UPNP_CRITICAL, API, __FILE__, __LINE__,
"FreeHandleInfo: Handle %d is out of range\n", "FreeHandle: Handle %d is out of range\n",
Upnp_Handle); Upnp_Handle);
} else if (HandleTable[Upnp_Handle] == NULL) { } else if (HandleTable[Upnp_Handle] == NULL) {
UpnpPrintf(UPNP_CRITICAL, API, __FILE__, __LINE__, UpnpPrintf(UPNP_CRITICAL, API, __FILE__, __LINE__,
"FreeHandleInfo: HandleTable[%d] is NULL\n", "FreeHandle: HandleTable[%d] is NULL\n",
Upnp_Handle); Upnp_Handle);
} else { } else {
free( HandleTable[Upnp_Handle] ); free( HandleTable[Upnp_Handle] );
@ -4137,7 +4141,8 @@ int FreeHandle(int Upnp_Handle)
ret = UPNP_E_SUCCESS; ret = UPNP_E_SUCCESS;
} }
UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__, "FreeHandleInfo: exiting\n"); UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
"FreeHandle: exiting, ret = %d.\n", ret);
return ret; return ret;
} }