diff --git a/ixml/Makefile.am b/ixml/Makefile.am index acf1f85..ebfd2fd 100644 --- a/ixml/Makefile.am +++ b/ixml/Makefile.am @@ -24,15 +24,23 @@ libixml_la_LDFLAGS = -version-info $(LT_VERSION_IXML) \ -export-symbols-regex '^ixml.*' libixml_la_SOURCES = \ - src/ixml.c src/node.c src/ixmlparser.c \ - src/ixmlmembuf.c src/nodeList.c \ - src/element.c src/attr.c src/document.c \ + src/attr.c \ + src/document.c \ + src/element.c \ + src/inc/ixmlmembuf.h \ + src/inc/ixmlparser.h \ + src/ixml.c \ + src/ixmldebug.c \ + src/ixmldebug.h \ + src/ixmlparser.c \ + src/ixmlmembuf.c \ src/namedNodeMap.c \ - src/inc/ixmlmembuf.h src/inc/ixmlparser.h + src/node.c \ + src/nodeList.c upnpincludedir = $(includedir)/upnp -upnpinclude_HEADERS = inc/ixml.h - +upnpinclude_HEADERS = inc/ixml.h \ + inc/ixmldebug.h check_PROGRAMS = test_document TESTS = test/test_document.sh @@ -47,4 +55,3 @@ dist-hook: clean-local: @if [ -d bin ] ; then rm -rf bin ; fi - diff --git a/ixml/inc/ixml.h b/ixml/inc/ixml.h index 849318b..bbfec41 100644 --- a/ixml/inc/ixml.h +++ b/ixml/inc/ixml.h @@ -52,15 +52,26 @@ #ifdef LIBUPNP_EXPORTS /* set up declspec for dll export to make functions visible to library users */ #define EXPORT_SPEC __declspec(dllexport) - #else + #else /* LIBUPNP_EXPORTS */ #define EXPORT_SPEC __declspec(dllimport) - #endif - #else + #endif /* LIBUPNP_EXPORTS */ + #else /* UPNP_STATIC_LIB */ #define EXPORT_SPEC - #endif -#else + #endif /* UPNP_STATIC_LIB */ + + + #ifdef UPNP_USE_MSVCPP + /* define some things the M$ VC++ doesn't know */ + #define IXML_INLINE + #endif /* UPNP_USE_MSVCPP */ + #ifdef UPNP_USE_BCBPP + /* define some things Borland Builder doesn't know */ + #define IXML_INLINE inline + #endif /* UPNP_USE_BCBPP */ +#else /* WIN32 */ #define EXPORT_SPEC -#endif + #define IXML_INLINE inline +#endif /* WIN32 */ typedef int BOOL; diff --git a/ixml/inc/ixmldebug.h b/ixml/inc/ixmldebug.h new file mode 100644 index 0000000..1097453 --- /dev/null +++ b/ixml/inc/ixmldebug.h @@ -0,0 +1,34 @@ + + +#ifndef IXMLDEBUG_H +#define IXMLDEBUG_H + + +#include "ixml.h" + + +/*! + * \brief Prints the debug statement either on the standard output or log file + * along with the information from where this debug statement is coming. + **/ +#ifdef DEBUG +void IxmlPrintf( + /*! [in] Printf like format specification. */ + const char* FmtStr, + /*! [in] Printf like Variable number of arguments that will go in the debug + * statement. */ + ...) +#if (__GNUC__ >= 3) + /* This enables printf like format checking by the compiler */ + __attribute__((format (__printf__, 1, 2))) +#endif +; +#else /* DEBUG */ +static IXML_INLINE void IxmlPrintf( + const char* FmtStr, + ...) {} +#endif /* DEBUG */ + + +#endif /* IXMLDEBUG_H */ + diff --git a/ixml/src/ixml.c b/ixml/src/ixml.c index 32388bb..37f8f1c 100644 --- a/ixml/src/ixml.c +++ b/ixml/src/ixml.c @@ -29,6 +29,7 @@ // /////////////////////////////////////////////////////////////////////////// +#include "ixmldebug.h" #include "ixmlmembuf.h" #include "ixmlparser.h" diff --git a/ixml/src/ixmldebug.c b/ixml/src/ixmldebug.c new file mode 100644 index 0000000..3102117 --- /dev/null +++ b/ixml/src/ixmldebug.c @@ -0,0 +1,26 @@ + + +#include "autoconfig.h" + + +#include "ixmldebug.h" + + +#include +#include + + +#ifdef DEBUG +void IxmlPrintf( + const char *FmtStr, + ... ) +{ + va_list ArgList; + + va_start(ArgList, FmtStr); + vfprintf(stdout, FmtStr, ArgList); + fflush(stdout); + va_end(ArgList); +} +#endif + diff --git a/ixml/src/ixmlparser.c b/ixml/src/ixmlparser.c index 04c74bb..8912ceb 100644 --- a/ixml/src/ixmlparser.c +++ b/ixml/src/ixmlparser.c @@ -29,9 +29,13 @@ // /////////////////////////////////////////////////////////////////////////// -#include + +#include "ixmldebug.h" #include "ixmlparser.h" + +#include + #ifdef WIN32 #define strncasecmp strnicmp #endif @@ -2433,77 +2437,105 @@ Parser_processAttribute( IN Parser * xmlParser, } /*==============================================================================* -* -* Parser_getNextNode -* return next node -* returns IXML_SUCCESS or -* -* -*===============================================================================*/ -static int -Parser_getNextNode( IN Parser * xmlParser, - OUT IXML_Node * node, - OUT BOOL * bETag ) + * + * Parser_getNextNode + * return next node + * returns IXML_SUCCESS or + * + * + *===============================================================================*/ +static int Parser_getNextNode( + IN Parser *xmlParser, + OUT IXML_Node *node, + OUT BOOL *bETag ) { - char *pCurToken = NULL; - char *lastElement = NULL; + char *pCurToken = NULL; + char *lastElement = NULL; + IXML_ERRORCODE ret = IXML_SUCCESS; + int line = 0; + int tokenLen = 0; - // endof file reached? - if( *( xmlParser->curPtr ) == '\0' ) { - *bETag = TRUE; - return IXML_FILE_DONE; - } + // endof file reached? + if (*(xmlParser->curPtr) == '\0') { + *bETag = TRUE; + line = __LINE__; + ret = IXML_FILE_DONE; + goto ExitFunction; + } - if( xmlParser->state == eCONTENT ) { - if( Parser_processContent( xmlParser, node ) != IXML_SUCCESS ) { - return IXML_FAILED; - } - } else { - Parser_skipWhiteSpaces( xmlParser ); + if (xmlParser->state == eCONTENT) { + line = __LINE__; + ret = Parser_processContent(xmlParser, node); + goto ExitFunction; + } else { + Parser_skipWhiteSpaces(xmlParser); + tokenLen = Parser_getNextToken(xmlParser); + if (tokenLen == 0 && + xmlParser->pCurElement == NULL && + *(xmlParser->curPtr) == '\0') { + // comments after the xml doc + line = __LINE__; + ret = IXML_SUCCESS; + goto ExitFunction; + } else if ((xmlParser->tokenBuf).length == 0) { + line = __LINE__; + ret = IXML_SYNTAX_ERR; + goto ExitFunction; + } - if( ( Parser_getNextToken( xmlParser ) == 0 ) && ( xmlParser->pCurElement == NULL ) && ( *( xmlParser->curPtr ) == '\0' ) ) { // comments after the xml doc - return IXML_SUCCESS; - } else if( ( xmlParser->tokenBuf ).length == 0 ) { - return IXML_SYNTAX_ERR; - } + pCurToken = (xmlParser->tokenBuf).buf; + if (*pCurToken == GREATERTHAN) { + line = __LINE__; + ret = IXML_SUCCESS; + goto ExitFunction; + } else if (strcmp(pCurToken, ENDTAG) == 0) { + // we got lastElem).buf; + if (lastElement == NULL) { + line = __LINE__; + ret = IXML_SYNTAX_ERR; + goto ExitFunction; + } - pCurToken = ( xmlParser->tokenBuf ).buf; - if( *pCurToken == GREATERTHAN ) { - return IXML_SUCCESS; - } else if( strcmp( pCurToken, ENDTAG ) == 0 ) { // we got lastElem ).buf; - if( lastElement == NULL ) { - goto ErrorHandler; - } + node->nodeName = safe_strdup( lastElement ); + if( node->nodeName == NULL ) { + line = __LINE__; + ret = IXML_INSUFFICIENT_MEMORY; + goto ExitFunction; + } + node->nodeType = eELEMENT_NODE; + *bETag = TRUE; - node->nodeName = safe_strdup( lastElement ); - if( node->nodeName == NULL ) { - return IXML_INSUFFICIENT_MEMORY; - } - node->nodeType = eELEMENT_NODE; - *bETag = TRUE; + line = __LINE__; + ret = IXML_SUCCESS; + goto ExitFunction; + } else if (xmlParser->state == eATTRIBUTE && xmlParser->pCurElement != NULL) { + if(Parser_processAttribute( xmlParser, node ) != IXML_SUCCESS) { + line = __LINE__; + ret = IXML_SYNTAX_ERR; + goto ExitFunction; + } + } else { + line = __LINE__; + ret = IXML_SYNTAX_ERR; + goto ExitFunction; + } + } - return IXML_SUCCESS; - } else if( (xmlParser->state == eATTRIBUTE) && - (xmlParser->pCurElement != NULL) ) { - if( Parser_processAttribute( xmlParser, node ) != - IXML_SUCCESS ) { - return IXML_SYNTAX_ERR; - } - } else { - return IXML_SYNTAX_ERR; - } - } - - return IXML_SUCCESS; - - ErrorHandler: - - return IXML_SYNTAX_ERR; +ExitFunction: + if (ret != IXML_SUCCESS) { + IxmlPrintf("(ixml::Parser_getNextNode): Error %d, line %d\n", + ret, line); + } + return ret; } diff --git a/upnp/inc/upnp.h b/upnp/inc/upnp.h index c623e66..ce4d37a 100644 --- a/upnp/inc/upnp.h +++ b/upnp/inc/upnp.h @@ -69,19 +69,21 @@ #ifdef LIBUPNP_EXPORTS /* set up declspec for dll export to make functions visible to library users */ #define EXPORT_SPEC __declspec(dllexport) - #else + #else /* LIBUPNP_EXPORTS */ #define EXPORT_SPEC __declspec(dllimport) - #endif - #else + #endif /* LIBUPNP_EXPORTS */ + #else /* UPNP_STATIC_LIB */ #define EXPORT_SPEC - #endif + #endif /* UPNP_STATIC_LIB */ + + #ifdef UPNP_USE_MSVCPP /* define some things the M$ VC++ doesn't know */ #define UPNP_INLINE typedef __int64 int64_t; #define PRId64 "I64d" #define PRIzu "lu" - #endif + #endif /* UPNP_USE_MSVCPP */ #ifdef UPNP_USE_BCBPP /* define some things Borland Builder doesn't know */ #define UPNP_INLINE inline @@ -89,7 +91,7 @@ #warning The Borland C compiler is probably broken on PRId64, please someone provide a proper fix here #define PRId64 "I64d" #define PRIzu "zu" - #endif + #endif /* UPNP_USE_BCBPP */ #else #define EXPORT_SPEC #define UPNP_INLINE inline diff --git a/upnp/inc/upnpdebug.h b/upnp/inc/upnpdebug.h index 2441c0f..6659cca 100644 --- a/upnp/inc/upnpdebug.h +++ b/upnp/inc/upnpdebug.h @@ -229,34 +229,25 @@ static UPNP_INLINE int DebugAtThisLevel( #endif -/*************************************************************************** - * Function : UpnpPrintf - * - * Parameters: - * IN Upnp_LogLevel DLevel: The level of the debug logging. It will decide - * whether debug statement will go to standard output, - * or any of the log files. - * IN Dbg_Module Module: debug will go in the name of this module - * IN char *DbgFileName: Name of the file from where debug statement is - * coming - * IN int DbgLineNo : Line number of the file from where debug statement - * is coming - * IN char * FmtStr, ...: Variable number of arguments that will go - * in the debug statement - * - * Description: - * This functions prints the debug statement either on the startdard - * output or log file along with the information from where this - * debug statement is coming - * Returns: void - ***************************************************************************/ +/*! + * \brief Prints the debug statement either on the standard output or log file + * along with the information from where this debug statement is coming. + **/ #ifdef DEBUG void UpnpPrintf( + /*! [in] The level of the debug logging. It will decide whether debug + * statement will go to standard output, or any of the log files. */ Upnp_LogLevel DLevel, + /*! [in] debug will go in the name of this module. */ Dbg_Module Module, + /*! [in] Name of the file from where debug statement is coming. */ const char* DbgFileName, + /*! [in] Line number of the file from where debug statement is coming. */ int DbgLineNo, + /*! [in] Printf like format specification. */ const char* FmtStr, + /*! [in] Printf like Variable number of arguments that will go in the debug + * statement. */ ...) #if (__GNUC__ >= 3) /* This enables printf like format checking by the compiler */ diff --git a/upnp/src/api/upnpdebug.c b/upnp/src/api/upnpdebug.c index ff48fe0..aeedef3 100644 --- a/upnp/src/api/upnpdebug.c +++ b/upnp/src/api/upnpdebug.c @@ -30,12 +30,16 @@ /////////////////////////////////////////////////////////////////////////// #include "config.h" -#include "upnpdebug.h" -#include -#include + + #include "ithread.h" #include "upnp.h" +#include "upnpdebug.h" + + #include +#include +#include #include @@ -189,27 +193,6 @@ int DebugAtThisLevel( #endif -/*************************************************************************** - * Function : UpnpPrintf - * - * Parameters: - * IN Upnp_LogLevel DLevel: The level of the debug logging. It will decide - * whether debug statement will go to standard output, - * or any of the log files. - * IN Dbg_Module Module: debug will go in the name of this module - * IN char *DbgFileName: Name of the file from where debug statement is - * coming - * IN int DbgLineNo : Line number of the file from where debug statement - * is coming - * IN char * FmtStr, ...: Variable number of arguments that will go - * in the debug statement - * - * Description: - * This functions prints the debug statement either on the startdard - * output or log file along with the information from where this debug - * statement is coming - * Returns: void - ***************************************************************************/ #ifdef DEBUG void UpnpPrintf( IN Upnp_LogLevel DLevel,