Improoving IXML debugging.

git-svn-id: https://pupnp.svn.sourceforge.net/svnroot/pupnp/trunk@378 119443c7-1b9e-41f8-b6fc-b9c35fce742c
This commit is contained in:
Marcelo Roberto Jimenez 2008-05-08 17:21:59 +00:00
parent e90e549cbb
commit 9a98f25b95
9 changed files with 216 additions and 129 deletions

View File

@ -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

View File

@ -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;

34
ixml/inc/ixmldebug.h Normal file
View File

@ -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 */

View File

@ -29,6 +29,7 @@
//
///////////////////////////////////////////////////////////////////////////
#include "ixmldebug.h"
#include "ixmlmembuf.h"
#include "ixmlparser.h"

26
ixml/src/ixmldebug.c Normal file
View File

@ -0,0 +1,26 @@
#include "autoconfig.h"
#include "ixmldebug.h"
#include <stdarg.h>
#include <stdio.h>
#ifdef DEBUG
void IxmlPrintf(
const char *FmtStr,
... )
{
va_list ArgList;
va_start(ArgList, FmtStr);
vfprintf(stdout, FmtStr, ArgList);
fflush(stdout);
va_end(ArgList);
}
#endif

View File

@ -29,9 +29,13 @@
//
///////////////////////////////////////////////////////////////////////////
#include <string.h>
#include "ixmldebug.h"
#include "ixmlparser.h"
#include <string.h>
#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 </, read next element
line = __LINE__;
ret = Parser_processETag(xmlParser, node, bETag);
goto ExitFunction;
} else if (*pCurToken == LESSTHAN) {
line = __LINE__;
ret = Parser_processSTag(xmlParser, node);
goto ExitFunction;
} else if (strcmp(pCurToken, COMPLETETAG) == 0) {
lastElement = (xmlParser->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 </, read next element
return Parser_processETag( xmlParser, node, bETag );
} else if( *pCurToken == LESSTHAN ) {
return Parser_processSTag( xmlParser, node );
} else if( strcmp( pCurToken, COMPLETETAG ) == 0 ) {
lastElement = ( xmlParser->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;
}

View File

@ -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

View File

@ -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 */

View File

@ -30,12 +30,16 @@
///////////////////////////////////////////////////////////////////////////
#include "config.h"
#include "upnpdebug.h"
#include <stdlib.h>
#include <stdio.h>
#include "ithread.h"
#include "upnp.h"
#include "upnpdebug.h"
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@ -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,