From a627df4d100c67a75e5f6ca0f3d9deb0f312e8fb Mon Sep 17 00:00:00 2001 From: Marcelo Roberto Jimenez Date: Fri, 16 Apr 2010 13:38:06 +0000 Subject: [PATCH] SF Patch Tracker [ 2987390 ] upnp_debug vs. ixml_debug Thanks for the load of updates, I'm still assimilating them ! Could I make a suggestion though? The addition of printNodes(IXML_Node) to upnpdebug a dds a new dependency on ixml.h for anything using upnpdebug.h. I'm making quite a bit of use of upnpdebug in porting things to version 1.8.0, and I'd prefer it if printNodes could be added to ixmldebug.h instead. I'm attach ing a patch, what do you think ? Nick git-svn-id: https://pupnp.svn.sourceforge.net/svnroot/pupnp/trunk@532 119443c7-1b9e-41f8-b6fc-b9c35fce742c --- ChangeLog | 11 ++++++++++ ixml/inc/ixmldebug.h | 28 +++++++++++++++++++++++- ixml/src/document.c | 23 ++++++++++---------- ixml/src/ixml.c | 12 +++++----- ixml/src/ixmldebug.c | 47 ++++++++++++++++++++++++++++++++++++---- ixml/src/ixmlparser.c | 24 +++++++------------- upnp/inc/upnpdebug.h | 18 --------------- upnp/src/api/upnpdebug.c | 29 +------------------------ 8 files changed, 107 insertions(+), 85 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9e826e2..6f72468 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,17 @@ Version 1.8.0 ******************************************************************************* +2010-03-27 Marcelo Jimenez + SF Patch Tracker [ 2987390 ] upnp_debug vs. ixml_debug + Thanks for the load of updates, I'm still assimilating them ! Could I make + a suggestion though? The addition of printNodes(IXML_Node) to upnpdebug a + dds a new dependency on ixml.h for anything using upnpdebug.h. I'm making + quite a bit of use of upnpdebug in porting things to version 1.8.0, and I'd + prefer it if printNodes could be added to ixmldebug.h instead. I'm attach + ing a patch, what do you think ? + + Nick + 2010-03-27 Marcelo Jimenez * Forward port of svn revision 505: SF Patch Tracker [ 2836704 ] Patch for Solaris10 compilation and usage. diff --git a/ixml/inc/ixmldebug.h b/ixml/inc/ixmldebug.h index 3e94682..ac97680 100644 --- a/ixml/inc/ixmldebug.h +++ b/ixml/inc/ixmldebug.h @@ -5,6 +5,7 @@ #include "UpnpGlobal.h" +#include "ixml.h" /*! @@ -20,6 +21,13 @@ */ #ifdef DEBUG void IxmlPrintf( + /*! [in] The file name, usually __FILE__. */ + const char *DbgFileName, + /*! [in] The line number, usually __LINE__ or a variable that got the + * __LINE__ at the appropriate place. */ + int DbgLineNo, + /*! [in] The function name. */ + const char *FunctionName, /*! [in] Printf like format specification. */ const char* FmtStr, /*! [in] Printf like Variable number of arguments that will go in the debug @@ -27,7 +35,7 @@ void IxmlPrintf( ...) #if (__GNUC__ >= 3) /* This enables printf like format checking by the compiler */ - __attribute__((format (__printf__, 1, 2))) + __attribute__((format (__printf__, 4, 5))) #endif ; #else /* DEBUG */ @@ -37,5 +45,23 @@ static UPNP_INLINE void IxmlPrintf( #endif /* DEBUG */ +/*! + * \brief Print the node names and values of a XML tree. + */ +#ifdef DEBUG +void printNodes( + /*! [in] The root of the tree to print. */ + IXML_Node *tmpRoot, + /*! [in] The depth to print. */ + int depth); +#else +static UPNP_INLINE void printNodes( + IXML_Node *tmpRoot, + int depth) +{ +} +#endif + + #endif /* IXMLDEBUG_H */ diff --git a/ixml/src/document.c b/ixml/src/document.c index 8fee1f0..4a6c191 100644 --- a/ixml/src/document.c +++ b/ixml/src/document.c @@ -444,17 +444,17 @@ int ixmlDocument_createElementNSEx( IXML_Element **rtElement) { IXML_Element *newElement = NULL; - int errCode = IXML_SUCCESS; + int ret = IXML_SUCCESS; int line = 0; if (doc == NULL || namespaceURI == NULL || qualifiedName == NULL) { line = __LINE__; - errCode = IXML_INVALID_PARAMETER; + ret = IXML_INVALID_PARAMETER; goto ErrorHandler; } - errCode = ixmlDocument_createElementEx(doc, qualifiedName, &newElement); - if (errCode != IXML_SUCCESS) { + ret = ixmlDocument_createElementEx(doc, qualifiedName, &newElement); + if (ret != IXML_SUCCESS) { line = __LINE__; goto ErrorHandler; } @@ -464,16 +464,16 @@ int ixmlDocument_createElementNSEx( line = __LINE__; ixmlElement_free(newElement); newElement = NULL; - errCode = IXML_INSUFFICIENT_MEMORY; + ret = IXML_INSUFFICIENT_MEMORY; goto ErrorHandler; } // set the localName and prefix - errCode = ixmlNode_setNodeName((IXML_Node *)newElement, qualifiedName); - if (errCode != IXML_SUCCESS) { + ret = ixmlNode_setNodeName((IXML_Node *)newElement, qualifiedName); + if (ret != IXML_SUCCESS) { line = __LINE__; ixmlElement_free(newElement); newElement = NULL; - errCode = IXML_INSUFFICIENT_MEMORY; + ret = IXML_INSUFFICIENT_MEMORY; goto ErrorHandler; } @@ -481,12 +481,11 @@ int ixmlDocument_createElementNSEx( ErrorHandler: *rtElement = newElement; - if (errCode != IXML_SUCCESS) { - IxmlPrintf("(%s::ixmlDocument_createElementNSEx): Error %d, line %d\n", - __FILE__, errCode, line); + if (ret != IXML_SUCCESS) { + IxmlPrintf(__FILE__, line, "ixmlDocument_createElementNSEx", "Error %d\n", ret); } - return errCode; + return ret; } diff --git a/ixml/src/ixml.c b/ixml/src/ixml.c index fe9851c..fa0e5aa 100644 --- a/ixml/src/ixml.c +++ b/ixml/src/ixml.c @@ -181,9 +181,9 @@ static void ixmlPrintDomTreeRecursive( break; default: - IxmlPrintf("(%s::ixmlPrintDomTreeRecursive) line %d: " + IxmlPrintf(__FILE__, __LINE__, "ixmlPrintDomTreeRecursive", "Warning, unknown node type %d\n", - __FILE__, __LINE__, ixmlNode_getNodeType(nodeptr)); + ixmlNode_getNodeType(nodeptr)); break; } } @@ -253,9 +253,9 @@ static void ixmlPrintDomTree( break; default: - IxmlPrintf("(%s::ixmlPrintDomTree) line %d: " + IxmlPrintf(__FILE__, __LINE__, "ixmlPrintDomTree", "Warning, unknown node type %d\n", - __FILE__, __LINE__, ixmlNode_getNodeType(nodeptr)); + ixmlNode_getNodeType(nodeptr)); break; } } @@ -324,9 +324,9 @@ static void ixmlDomTreetoString( break; default: - IxmlPrintf("(%s::ixmlDomTreetoString) line %d: " + IxmlPrintf(__FILE__, __LINE__, "ixmlPrintDomTreeRecursive", "Warning, unknown node type %d\n", - __FILE__, __LINE__, ixmlNode_getNodeType(nodeptr)); + ixmlNode_getNodeType(nodeptr)); break; } } diff --git a/ixml/src/ixmldebug.c b/ixml/src/ixmldebug.c index cea4d66..af6e361 100644 --- a/ixml/src/ixmldebug.c +++ b/ixml/src/ixmldebug.c @@ -17,15 +17,54 @@ #ifdef DEBUG void IxmlPrintf( + const char *DbgFileName, + int DbgLineNo, + const char *FunctionName, const char *FmtStr, ...) { va_list ArgList; - va_start(ArgList, FmtStr); - vfprintf(stdout, FmtStr, ArgList); - fflush(stdout); - va_end(ArgList); + FILE *fp = stdout; + fprintf(fp, "(%s::%s), line %d", DbgFileName, FunctionName, DbgLineNo); + if (FmtStr) { + fprintf(fp, ": "); + va_start(ArgList, FmtStr); + vfprintf(fp, FmtStr, ArgList); + fflush(fp); + va_end(ArgList); + } else { + fprintf(fp, "\n"); + } } + + +void printNodes(IXML_Node *tmpRoot, int depth) +{ + int i; + IXML_NodeList *NodeList1; + IXML_Node *ChildNode1; + unsigned short NodeType; + const DOMString NodeValue; + const DOMString NodeName; + NodeList1 = ixmlNode_getChildNodes(tmpRoot); + for (i = 0; i < 100; ++i) { + ChildNode1 = ixmlNodeList_item(NodeList1, i); + if (ChildNode1 == NULL) { + break; + } + + printNodes(ChildNode1, depth+1); + NodeType = ixmlNode_getNodeType(ChildNode1); + NodeValue = ixmlNode_getNodeValue(ChildNode1); + NodeName = ixmlNode_getNodeName(ChildNode1); + IxmlPrintf(__FILE__, __LINE__, "printNodes", + "DEPTH-%2d-IXML_Node Type %d, " + "IXML_Node Name: %s, IXML_Node Value: %s\n", + depth, NodeType, NodeName, NodeValue); + } +} + + #endif diff --git a/ixml/src/ixmlparser.c b/ixml/src/ixmlparser.c index fda11ed..59b0f50 100644 --- a/ixml/src/ixmlparser.c +++ b/ixml/src/ixmlparser.c @@ -542,8 +542,7 @@ static int Parser_UTF8ToInt( *len = 0; ret = -1; } - IxmlPrintf("(%s::Parser_UTF8ToInt): Error %d, line %d\n", - __FILE__, ret, line); + IxmlPrintf(__FILE__, line, "Parser_UTF8ToInt", "Error %d\n", ret); return ret; } } @@ -1302,8 +1301,7 @@ fail_entity: ExitFunction: if (ret == -1 || (g_error_char && ret == g_error_char)) { - IxmlPrintf("(%s::Parser_getChar): Error %d, line %d\n", - __FILE__, ret, line); + IxmlPrintf(__FILE__, line, "Parser_getChar", "Error %d\n", ret); } return ret; @@ -1370,8 +1368,7 @@ static int Parser_copyToken( ExitFunction: if (ret != IXML_SUCCESS) { - IxmlPrintf("(%s::Parser_copyToken): Error %d, line %d\n", - __FILE__, ret, line); + IxmlPrintf(__FILE__, line, "Parser_copyToken", "Error %d\n", ret); } return ret; @@ -1918,8 +1915,7 @@ static int Parser_xmlNamespace( ExitFunction: if (ret != IXML_SUCCESS && ret != IXML_FILE_DONE) { - IxmlPrintf("(%s::Parser_xmlNamespace): Error %d, line %d\n", - __FILE__, ret, line); + IxmlPrintf(__FILE__, line, "Parser_xmlNamespace", "Error %d\n", ret); } return ret; @@ -2248,8 +2244,7 @@ static int Parser_processContent( ExitFunction: if (ret != IXML_SUCCESS) { - IxmlPrintf("(%s::Parser_processContent): Error %d, line %d\n", - __FILE__, ret, line); + IxmlPrintf(__FILE__, line, "Parser_processContent", "Error %d\n", ret); } return ret; @@ -2321,8 +2316,7 @@ static int Parser_processETag( ExitFunction: if (ret != IXML_SUCCESS) { - IxmlPrintf("(%s::Parser_processETag): Error %d, line %d\n", - __FILE__, ret, line); + IxmlPrintf(__FILE__, line, "Parser_processETag", "Error %d\n", ret); } return ret; @@ -2577,8 +2571,7 @@ static int Parser_processAttribute( ExitFunction: if (ret != IXML_SUCCESS && ret != IXML_FILE_DONE) { - IxmlPrintf("(%s::Parser_processAttribute): Error %d, line %d\n", - __FILE__, ret, line); + IxmlPrintf(__FILE__, line, "Parser_processAttribute", "Error %d\n", ret); } return ret; @@ -2681,8 +2674,7 @@ static int Parser_getNextNode( ExitFunction: if (ret != IXML_SUCCESS && ret != IXML_FILE_DONE) { - IxmlPrintf("(%s::Parser_getNextNode): Error %d, line %d\n", - __FILE__, ret, line); + IxmlPrintf(__FILE__, line, "Parser_getNextNode", "Error %d\n", ret); } return ret; diff --git a/upnp/inc/upnpdebug.h b/upnp/inc/upnpdebug.h index b716e82..a7c0674 100644 --- a/upnp/inc/upnpdebug.h +++ b/upnp/inc/upnpdebug.h @@ -304,24 +304,6 @@ static UPNP_INLINE void PrintThreadPoolStats( #endif -/*! - * \brief Print the node names and values of a XML tree. - */ -#ifdef DEBUG -void printNodes( - /*! [in] The root of the tree to print. */ - IXML_Node *tmpRoot, - /*! [in] The depth to print. */ - int depth); -#else -static UPNP_INLINE void printNodes( - IXML_Node *tmpRoot, - int depth) -{ -} -#endif - - /*@}*/ #ifdef __cplusplus diff --git a/upnp/src/api/upnpdebug.c b/upnp/src/api/upnpdebug.c index c34f08f..86eee55 100644 --- a/upnp/src/api/upnpdebug.c +++ b/upnp/src/api/upnpdebug.c @@ -149,7 +149,7 @@ void UpnpPrintf( ithread_mutex_lock(&GlobalDebugMutex); va_start(ArgList, FmtStr); if (!DEBUG_TARGET) { - if( DbgFileName ) { + if (DbgFileName) { UpnpDisplayFileAndLine(stdout, DbgFileName, DbgLineNo); } vfprintf(stdout, FmtStr, ArgList); @@ -324,32 +324,5 @@ void PrintThreadPoolStats( } -void printNodes(IXML_Node *tmpRoot, int depth) -{ - int i; - IXML_NodeList *NodeList1; - IXML_Node *ChildNode1; - unsigned short NodeType; - const DOMString NodeValue; - const DOMString NodeName; - NodeList1 = ixmlNode_getChildNodes(tmpRoot); - for (i = 0; i < 100; ++i) { - ChildNode1 = ixmlNodeList_item(NodeList1, i); - if (ChildNode1 == NULL) { - break; - } - - printNodes(ChildNode1, depth+1); - NodeType = ixmlNode_getNodeType(ChildNode1); - NodeValue = ixmlNode_getNodeValue(ChildNode1); - NodeName = ixmlNode_getNodeName(ChildNode1); - UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__, - "DEPTH-%2d-IXML_Node Type %d, " - "IXML_Node Name: %s, IXML_Node Value: %s\n", - depth, NodeType, NodeName, NodeValue); - } -} - - #endif /* DEBUG */