From 4ceb6c67d12e7d9c0da70298634df278d7ccbf97 Mon Sep 17 00:00:00 2001 From: Marcelo Roberto Jimenez Date: Wed, 16 May 2007 02:02:16 +0000 Subject: [PATCH] * EXPORT_SPEC missing on some declarations in ixml/inc/ixml.h. Thanks to David Maass. * sizeof is unsigned, so %zu is more adequate than %zd. * Using an invented printf directive PRIzu that on MSVC expands to "lu", and on normal C99 compilers expands to "zu". * Rewrote raw_find_str. Now it no longer uses strcasestr(), but it transforms the first input buffer into lowercase. git-svn-id: https://pupnp.svn.sourceforge.net/svnroot/pupnp/trunk@184 119443c7-1b9e-41f8-b6fc-b9c35fce742c --- ChangeLog | 15 +++++ ixml/inc/ixml.h | 8 +-- upnp/inc/upnp.h | 75 ++++++++++++++---------- upnp/src/gena/gena_device.c | 2 +- upnp/src/genlib/net/http/httpparser.c | 45 +++++++++----- upnp/src/genlib/net/http/httpreadwrite.c | 10 ++-- upnp/src/genlib/net/uri/uri.c | 2 +- upnp/src/inc/httpparser.h | 20 ++++--- 8 files changed, 109 insertions(+), 68 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9f98680..f21f51e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,21 @@ Version 1.4.7 ************************************************************************* +2007-05-15 Marcelo Jimenez + * EXPORT_SPEC missing on some declarations in ixml/inc/ixml.h. + Thanks to David Maass. + +2007-05-15 Marcelo Jimenez + * sizeof is unsigned, so %zu is more adequate than %zd. + +2007-05-15 Marcelo Jimenez + * Using an invented printf directive PRIzu that on MSVC + expands to "lu", and on normal C99 compilers expands to "zu". + +2007-05-15 Marcelo Jimenez + * Rewrote raw_find_str. Now it no longer uses strcasestr(), but it + transforms the first input buffer into lowercase. + 2007-05-08 Marcelo Jimenez * Fix for debug printf format strings. size_t are not expected in a string format like "%.*s". diff --git a/ixml/inc/ixml.h b/ixml/inc/ixml.h index 4ce354f..03098ce 100644 --- a/ixml/inc/ixml.h +++ b/ixml/inc/ixml.h @@ -1738,7 +1738,7 @@ ixmlNodeList_free(IXML_NodeList *nList * of the DOM tree or {\tt NULL} on an error. */ -DOMString +EXPORT_SPEC DOMString ixmlPrintDocument(IXML_Document *doc); /** Renders a {\bf Node} and all sub-elements into an XML text @@ -1756,7 +1756,7 @@ ixmlPrintDocument(IXML_Document *doc); * of the DOM tree or {\tt NULL} on an error. */ -DOMString +EXPORT_SPEC DOMString ixmlPrintNode(IXML_Node *doc /** The root of the {\bf Node} tree to render to XML text. */ ); @@ -1777,7 +1777,7 @@ ixmlPrintNode(IXML_Node *doc * of the DOM tree or {\tt NULL} on an error. */ -DOMString +EXPORT_SPEC DOMString ixmlDocumenttoString(IXML_Document *doc); /** Renders a {\bf Node} and all sub-elements into an XML text @@ -1809,7 +1809,7 @@ ixmlNodetoString(IXML_Node *doc * characters are replaced by the {\bf errorChar}, and invalid "&" entities * are left untranslated. The parsing is then allowed to continue. */ -void +EXPORT_SPEC void ixmlRelaxParser(char errorChar); diff --git a/upnp/inc/upnp.h b/upnp/inc/upnp.h index dad9258..e8fb1fa 100644 --- a/upnp/inc/upnp.h +++ b/upnp/inc/upnp.h @@ -36,66 +36,77 @@ //@{ + #if defined MYLIB_LARGEFILE_SENSITIVE && _FILE_OFFSET_BITS+0 != 64 - #if defined __GNUC__ - #warning libupnp requires largefile mode - use AC_SYS_LARGEFILE - #else - #error libupnp requires largefile mode - use AC_SYS_LARGEFILE - #endif + #if defined __GNUC__ + #warning libupnp requires largefile mode - use AC_SYS_LARGEFILE + #else + #error libupnp requires largefile mode - use AC_SYS_LARGEFILE + #endif #endif + #include #ifdef __FreeBSD__ -#include + #include #endif #include "ixml.h" #include "upnpconfig.h" #if UPNP_HAVE_DEBUG -# include "upnpdebug.h" + #include "upnpdebug.h" #endif + #ifdef WIN32 - #ifndef UPNP_STATIC_LIB - #ifdef LIBUPNP_EXPORTS - // set up declspec for dll export to make functions visible to library users - #define EXPORT_SPEC __declspec(dllexport) - #else - #define EXPORT_SPEC __declspec(dllimport) - #endif - #else - #define EXPORT_SPEC - #endif - #ifdef UPNP_USE_MSVCPP // define some things the M$ VC++ doesn't knows - typedef __int64 int64_t; - #endif - #ifdef UPNP_USE_BCBPP // define some things Borland Builder doesn't knows - typedef __int64 int64_t; - #endif + #ifndef UPNP_STATIC_LIB + #ifdef LIBUPNP_EXPORTS + // set up declspec for dll export to make functions visible to library users + #define EXPORT_SPEC __declspec(dllexport) + #else + #define EXPORT_SPEC __declspec(dllimport) + #endif + #else + #define EXPORT_SPEC + #endif + #ifdef UPNP_USE_MSVCPP // define some things the M$ VC++ doesn't know + typedef __int64 int64_t; + #define PRId64 "I64d" + #define PRIzu "lu" + #endif + #ifdef UPNP_USE_BCBPP // define some things Borland Builder doesn't know + typedef __int64 int64_t; + #define PRIzu "zu" + #endif #else - #define EXPORT_SPEC + #define EXPORT_SPEC + #define PRIzu "zu" #endif + #ifndef WIN32 - #define UpnpCloseSocket close + #define UpnpCloseSocket close #else - #define UpnpCloseSocket closesocket - #define fseeko fseek + #define UpnpCloseSocket closesocket + #define fseeko fseek #endif #define UPNP_SOCKETERROR -1 #define UPNP_INVALID_SOCKET -1 #ifndef WIN32 - #define SOCKET int + #define SOCKET int #endif + #ifndef WIN32 - #include + #include #else - #include - #include + #include + #include #endif + #include + #define NUM_HANDLE 200 #define LINE_SIZE 180 #define NAME_SIZE 256 @@ -104,7 +115,6 @@ #define SERL_NUMR_SIZE 64 #define MODL_DESC_SIZE 64 #define UPNP_INFINITE -1 - #define UPNP_USING_CHUNKED -3 #define UPNP_UNTIL_CLOSE -4 @@ -2724,3 +2734,4 @@ EXPORT_SPEC void UpnpFree( //@} The API #endif + diff --git a/upnp/src/gena/gena_device.c b/upnp/src/gena/gena_device.c index 0ee6a06..4e216be 100644 --- a/upnp/src/gena/gena_device.c +++ b/upnp/src/gena/gena_device.c @@ -574,7 +574,7 @@ genaInitNotify( IN UpnpDevice_Handle device_handle, } sprintf( headers, "CONTENT-TYPE: text/xml\r\nCONTENT-LENGTH: " - "%zd\r\nNT: upnp:event\r\nNTS: upnp:propchange\r\n", + "%"PRIzu"\r\nNT: upnp:event\r\nNTS: upnp:propchange\r\n", strlen( propertySet ) + 1 ); //schedule thread for initial notification diff --git a/upnp/src/genlib/net/http/httpparser.c b/upnp/src/genlib/net/http/httpparser.c index 20253c2..b8385b8 100644 --- a/upnp/src/genlib/net/http/httpparser.c +++ b/upnp/src/genlib/net/http/httpparser.c @@ -2414,37 +2414,50 @@ raw_to_int( IN memptr * raw_value, } /************************************************************************ -* Function: raw_find_str -* -* Parameters: -* IN memptr* raw_value ; Buffer containg the string -* IN const char* str ; Substring to be found -* -* Description: Find a substring from raw character string buffer -* -* Returns: +* Function: raw_find_str +* +* Parameters: +* IN memptr* raw_value ; Buffer containg the string +* IN const char* str ; Substring to be found +* +* Description: Find a substring from raw character string buffer +* +* Side effects: raw_value is transformed to lowercase. +* +* Returns: * int - index at which the substring is found. ************************************************************************/ int -raw_find_str( IN memptr * raw_value, +raw_find_str( IN memptr *raw_value, IN const char *str ) { char c; char *ptr; + int i = 0; - c = raw_value->buf[raw_value->length]; // save - raw_value->buf[raw_value->length] = 0; // null-terminate + // save + c = raw_value->buf[raw_value->length]; - // Use strcasestr because the string may not always be exact case - ptr = strcasestr( raw_value->buf, str ); + // Make it lowercase + for (i = 0; raw_value->buf[i]; ++i) { + raw_value->buf[i] = tolower(raw_value->buf[i]); + } - raw_value->buf[raw_value->length] = c; // restore + // null-terminate + raw_value->buf[raw_value->length] = 0; + + // Find the substring position + ptr = strstr( raw_value->buf, str ); + + // restore the "length" byte + raw_value->buf[raw_value->length] = c; if( ptr == 0 ) { return -1; } - return ptr - raw_value->buf; // return index + // return index + return ptr - raw_value->buf; } /************************************************************************ diff --git a/upnp/src/genlib/net/http/httpreadwrite.c b/upnp/src/genlib/net/http/httpreadwrite.c index 421e5f3..3387e91 100644 --- a/upnp/src/genlib/net/http/httpreadwrite.c +++ b/upnp/src/genlib/net/http/httpreadwrite.c @@ -643,7 +643,7 @@ http_Download( IN const char *url_str, *temp = '/'; DBGONLY( UpnpPrintf ( UPNP_INFO, HTTP, __FILE__, __LINE__, - "HOSTNAME : %s Length : %zu\n", hoststr, hostlen ); + "HOSTNAME : %s Length : %"PRIzu"\n", hoststr, hostlen ); ) ret_code = http_MakeMessage( @@ -800,7 +800,7 @@ MakePostMessage( const char *url_str, hostlen = strlen( hoststr ); *temp = '/'; DBGONLY( UpnpPrintf( UPNP_INFO, HTTP, __FILE__, __LINE__, - "HOSTNAME : %s Length : %zd\n", hoststr, hostlen ); + "HOSTNAME : %s Length : %"PRIzu"\n", hoststr, hostlen ); ) if( contentLength >= 0 ) { @@ -1137,7 +1137,7 @@ MakeGetMessage( const char *url_str, hostlen = strlen( hoststr ); *temp = '/'; DBGONLY( UpnpPrintf( UPNP_INFO, HTTP, __FILE__, __LINE__, - "HOSTNAME : %s Length : %zd\n", hoststr, hostlen ); + "HOSTNAME : %s Length : %"PRIzu"\n", hoststr, hostlen ); ) if( proxy_str ) { @@ -1906,7 +1906,7 @@ http_MakeMessage( INOUT membuffer * buf, { num = ( int )va_arg( argp, int ); - sprintf( tempbuf, "%zu", num ); + sprintf( tempbuf, "%"PRIzu, num ); if( membuffer_append( buf, tempbuf, strlen( tempbuf ) ) != 0 ) { goto error_handler; } @@ -2214,7 +2214,7 @@ MakeGetMessageEx( const char *url_str, *temp = '/'; DBGONLY( UpnpPrintf( UPNP_INFO, HTTP, __FILE__, __LINE__, - "HOSTNAME : %s Length : %zd\n", + "HOSTNAME : %s Length : %"PRIzu"\n", hoststr, hostlen ); ) diff --git a/upnp/src/genlib/net/uri/uri.c b/upnp/src/genlib/net/uri/uri.c index b12a705..b855106 100644 --- a/upnp/src/genlib/net/uri/uri.c +++ b/upnp/src/genlib/net/uri/uri.c @@ -393,7 +393,7 @@ DBGONLY( void print_uri( uri_type * in ) { ************************************************************************/ DBGONLY( void print_token( token * in ) { int i = 0; - printf( "Token Size : %zd\n\'", in->size ); + printf( "Token Size : %"PRIzu"\n\'", in->size ); for( i = 0; i < in->size; i++ ) { putchar( in->buff[i] );} putchar( '\'' ); putchar( '\n' );} diff --git a/upnp/src/inc/httpparser.h b/upnp/src/inc/httpparser.h index 5052aa3..95ef6a9 100644 --- a/upnp/src/inc/httpparser.h +++ b/upnp/src/inc/httpparser.h @@ -448,15 +448,17 @@ int matchstr( IN char *str, IN size_t slen, IN const char* fmt, ... ); int raw_to_int( IN memptr* raw_value, int base ); /************************************************************************ -* Function: raw_find_str -* -* Parameters: -* IN memptr* raw_value ; Buffer containg the string -* IN const char* str ; Substring to be found -* -* Description: Find a substring from raw character string buffer -* -* Returns: +* Function: raw_find_str +* +* Parameters: +* IN memptr* raw_value ; Buffer containg the string +* IN const char* str ; Substring to be found +* +* Description: Find a substring from raw character string buffer +* +* Side effects: raw_value is transformed to lowercase. +* +* Returns: * int - index at which the substring is found. ************************************************************************/ int raw_find_str( IN memptr* raw_value, IN const char* str );