diff --git a/ChangeLog b/ChangeLog index f21f51e..29384b9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,14 @@ -************************************************************************* +******************************************************************************* Version 1.4.7 -************************************************************************* +******************************************************************************* + +2007-05-17 Marcelo Jimenez + * Removed all uses of the DBGONLY(x) macro. A static inline empty + function now is used and the compiler takes care of optimizing it out. + +2007-05-17 Marcelo Jimenez + * Fixed a bug in UpnpPrintf, function could call va_start() and return + befor calling va_end(). 2007-05-15 Marcelo Jimenez * EXPORT_SPEC missing on some declarations in ixml/inc/ixml.h. @@ -31,16 +39,16 @@ Version 1.4.7 tarball and executes upnp_tv_device from its creation directory, there will be no error -108 for not finding directory web. -************************************************************************* +******************************************************************************* Version 1.4.6 -************************************************************************* +******************************************************************************* 2007-04-19 Marcelo Jimenez * Fix for freebsd host_os in configure.ac. -************************************************************************* +******************************************************************************* Version 1.4.5 -************************************************************************* +******************************************************************************* 2007-04-19 Marcelo Jimenez * Case insensitive comparison in raw_find_str() (httpparser.c) as @@ -66,9 +74,9 @@ Version 1.4.5 (int instead of size_t) in combination with format "b" and "Q". The attached patch should fix this. -************************************************************************* +******************************************************************************* Version 1.4.4 -************************************************************************* +******************************************************************************* 2007-04-06 Marcelo Jimenez * SF Tracker [ 1695399 ] Typo in util.h @@ -103,9 +111,9 @@ Version 1.4.4 Please note, that I enabled some extra debugging lines that were commented, in order to get more information. See attached files. -************************************************************************* +******************************************************************************* Version 1.4.3 -************************************************************************* +******************************************************************************* 2007-03-13 Marcelo Jimenez * SF Tracker [ 1663004 ] Compile on Cygwin @@ -140,9 +148,9 @@ Version 1.4.3 * Fixed nasty segmentation fault bug on membuffer.c. -************************************************************************* +******************************************************************************* Version 1.4.2 -************************************************************************* +******************************************************************************* 2007-02-09 Marcelo Jimenez @@ -244,9 +252,9 @@ Version 1.4.2 * support for large files (>2 GBytes) added -************************************************************************* +******************************************************************************* Version 1.4.1 -************************************************************************* +******************************************************************************* 2006-07-07 Oxy @@ -277,9 +285,9 @@ Version 1.4.1 * Patch to fix memory leaks and reasons for crashes added (thanks to loigu) -************************************************************************* +******************************************************************************* Version 1.4.0 -************************************************************************* +******************************************************************************* 2006-05-26 Oxy @@ -305,9 +313,9 @@ Version 1.4.0 * Bugfix for M-Search packet -************************************************************************* +******************************************************************************* FORK FROM DEAD libupnp -************************************************************************* +******************************************************************************* 2006-04-29 Rémi Turboult diff --git a/build/inc/autoconfig.h b/build/inc/autoconfig.h index f461e4c..39e85b9 100644 --- a/build/inc/autoconfig.h +++ b/build/inc/autoconfig.h @@ -1,4 +1,4 @@ -/* autoconfig.h. Generated by configure. */ +/* autoconfig.h. Generated from autoconfig.h.in by configure. */ /* autoconfig.h.in. Generated from configure.ac by autoheader. */ /* Define to 1 to compile debug code */ @@ -19,15 +19,18 @@ /* Define to 1 if fseeko (and presumably ftello) exists and is declared. */ #define HAVE_FSEEKO 1 +/* Define to 1 if you have the `ftime' function. */ +#define HAVE_FTIME 1 + /* Define to 1 if you have the header file. */ #define HAVE_INTTYPES_H 1 +/* Define to 1 if you have the `compat' library (-lcompat). */ +/* #undef HAVE_LIBCOMPAT */ + /* Define to 1 if you have the header file. */ #define HAVE_LIMITS_H 1 -/* Define to 1 if you have the header file. */ -#define HAVE_MALLOC_H 1 - /* Define to 1 if you have the header file. */ #define HAVE_MEMORY_H 1 @@ -92,19 +95,19 @@ #define PACKAGE "libupnp" /* Define to the address where bug reports for this package should be sent. */ -#define PACKAGE_BUGREPORT "virtual_worlds@gmx.de" +#define PACKAGE_BUGREPORT "mroberto@users.sourceforge.net" /* Define to the full name of this package. */ #define PACKAGE_NAME "libupnp" /* Define to the full name and version of this package. */ -#define PACKAGE_STRING "libupnp 1.4.0" +#define PACKAGE_STRING "libupnp 1.4.7" /* Define to the one symbol short name of this package. */ #define PACKAGE_TARNAME "libupnp" /* Define to the version of this package. */ -#define PACKAGE_VERSION "1.4.0" +#define PACKAGE_VERSION "1.4.7" /* Define to necessary symbol if this constant uses a non-standard name on your system. */ @@ -135,27 +138,30 @@ #define UPNP_VERSION_MINOR 4 /* see upnpconfig.h */ -#define UPNP_VERSION_PATCH 0 +#define UPNP_VERSION_PATCH 7 /* see upnpconfig.h */ -#define UPNP_VERSION_STRING "1.4.0" +#define UPNP_VERSION_STRING "1.4.7" /* Version number of package */ -#define VERSION "1.4.0" +#define VERSION "1.4.7" -/* Number of bits in a file offset, on hosts where this is settable. */ +/* File Offset size */ #define _FILE_OFFSET_BITS 64 /* Define to 1 to make fseeko visible on some hosts (e.g. glibc 2.2). */ /* #undef _LARGEFILE_SOURCE */ -/* Define for large files, on AIX-style hosts. */ -/* #undef _LARGE_FILES */ +/* Large files support */ +#define _LARGE_FILE_SOURCE /* Define to empty if `const' does not conform to ANSI C. */ /* #undef const */ -/* Define to `unsigned' if does not define. */ +/* Define to `long int' if does not define. */ +/* #undef off_t */ + +/* Define to `unsigned int' if does not define. */ /* #undef size_t */ /* Substitute for socklen_t */ diff --git a/build/inc/config.h b/build/inc/config.h index f6a21e3..57688ba 100644 --- a/build/inc/config.h +++ b/build/inc/config.h @@ -34,7 +34,6 @@ #include "autoconfig.h" -#define MAX_JOBS_TOTAL 10 /** @name Compile time configuration options * The Linux SDK for UPnP Devices contains some compile-time parameters @@ -96,6 +95,17 @@ #define MAX_THREADS 12 //@} +/** @name MAX_JOBS_TOTAL + * The {\tt MAX_JOBS_TOTAL} constant determines the maximum number of jobs + * that can be queued. If this limit is reached further jobs will be thrown + * to avoid memory exhaustion. The default value 100. + * (Added by Axis.) + */ + +//@{ +#define MAX_JOBS_TOTAL 100 +//@} + /** @name DEFAULT_SOAP_CONTENT_LENGTH * SOAP messages will read at most {\tt DEFAULT_SOAP_CONTENT_LENGTH} bytes. * This prevents devices that have a misbehaving web server to send @@ -294,68 +304,46 @@ -/** @name DBGONLY - The {\bf DBGONLY} macro allows code to be marked so that it - is only included in the DEBUG build and not the release. To - use this macro, put the code inside of the parentheses: - - {\tt DBGONLY(int i;)} - - This will cause a declaration of the integer {\tt i} only - in the debug build. - */ - -//@{ -#ifdef DEBUG - #define DBGONLY(x) x -#else - #define DBGONLY(x) -#endif -//@} - - - -#undef EXCLUDE_WEB_SERVER -#undef EXCLUDE_MINISERVER +#undef EXCLUDE_WEB_SERVER +#undef EXCLUDE_MINISERVER #ifdef INTERNAL_WEB_SERVER - #define EXCLUDE_WEB_SERVER 0 - #define EXCLUDE_MINISERVER 0 +# define EXCLUDE_WEB_SERVER 0 +# define EXCLUDE_MINISERVER 0 #else - #define EXCLUDE_WEB_SERVER 1 - #define EXCLUDE_MINISERVER 1 +# define EXCLUDE_WEB_SERVER 1 +# define EXCLUDE_MINISERVER 1 #endif #if EXCLUDE_GENA == 1 && EXCLUDE_SOAP == 1 && EXCLUDE_WEB_SERVER == 1 - #undef EXCLUDE_MINISERVER - #define EXCLUDE_MINISERVER 1 - #if INTERNAL_WEB_SERVER - # error "conflicting settings: use configure --disable-webserver" - #endif +# undef EXCLUDE_MINISERVER +# define EXCLUDE_MINISERVER 1 +# if INTERNAL_WEB_SERVER +# error "conflicting settings: use configure --disable-webserver" +# endif #endif #if EXCLUDE_GENA == 0 || EXCLUDE_SOAP == 0 || EXCLUDE_WEB_SERVER == 0 - #undef EXCLUDE_MINISERVER - #define EXCLUDE_MINISERVER 0 - #if EXCLUDE_WEB_SERVER == 0 && !defined INTERNAL_WEB_SERVER - #error "conflicting settings : use configure --enable-webserver" - #endif +# undef EXCLUDE_MINISERVER +# define EXCLUDE_MINISERVER 0 +# if EXCLUDE_WEB_SERVER == 0 && !defined INTERNAL_WEB_SERVER +# error "conflicting settings : use configure --enable-webserver" +# endif #endif #ifdef INCLUDE_CLIENT_APIS - #define CLIENTONLY(x) x -#else - #define CLIENTONLY(x) +# define CLIENTONLY(x) x +#else +# define CLIENTONLY(x) #endif #ifdef INCLUDE_DEVICE_APIS - #define DEVICEONLY(x) x -#else - #define DEVICEONLY(x) +# define DEVICEONLY(x) x +#else +# define DEVICEONLY(x) #endif //@} #endif - diff --git a/build/inc/upnpconfig.h b/build/inc/upnpconfig.h index ec5dacf..352b101 100644 --- a/build/inc/upnpconfig.h +++ b/build/inc/upnpconfig.h @@ -1,46 +1,46 @@ -/* upnp/inc/upnpconfig.h. Generated by configure. */ +/* upnp/inc/upnpconfig.h. Generated from upnpconfig.h.in by configure. */ // -*- C -*- /////////////////////////////////////////////////////////////////////////// // // Copyright (c) 2006 Rémi Turboult -// All rights reserved. +// All rights reserved. // -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are met: +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: // -// * Redistributions of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// * Neither name of Intel Corporation nor the names of its contributors -// may be used to endorse or promote products derived from this software +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither name of Intel Corporation nor the names of its contributors +// may be used to endorse or promote products derived from this software // without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR -// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // /////////////////////////////////////////////////////////////////////////// #ifndef UPNP_CONFIG_H -#define UPNP_CONFIG_H +#define UPNP_CONFIG_H /*************************************************************************** - * Library version - ***************************************************************************/ + * Library version + ***************************************************************************/ /** The library version (string) e.g. "1.3.0" */ -#define UPNP_VERSION_STRING "1.4.0" +#define UPNP_VERSION_STRING "1.4.7" /** Major version of the library */ #define UPNP_VERSION_MAJOR 1 @@ -49,7 +49,7 @@ #define UPNP_VERSION_MINOR 4 /** Patch version of the library */ -#define UPNP_VERSION_PATCH 0 +#define UPNP_VERSION_PATCH 7 /** The library version (numeric) e.g. 10300 means version 1.3.0 */ #define UPNP_VERSION \ @@ -59,25 +59,25 @@ /*************************************************************************** * Library optional features - ***************************************************************************/ + ***************************************************************************/ /* - * The following defines can be tested in order to know which + * The following defines can be tested in order to know which * optional features have been included in the installed library. */ -/** Defined to 1 if the library has been compiled with DEBUG enabled +/** Defined to 1 if the library has been compiled with DEBUG enabled * (i.e. configure --enable-debug) : file is available */ -#undef UPNP_HAVE_DEBUG +/* #undef UPNP_HAVE_DEBUG */ -/** Defined to 1 if the library has been compiled with client API enabled +/** Defined to 1 if the library has been compiled with client API enabled * (i.e. configure --enable-client) */ #define UPNP_HAVE_CLIENT 1 -/** Defined to 1 if the library has been compiled with device API enabled +/** Defined to 1 if the library has been compiled with device API enabled * (i.e. configure --enable-device) */ #define UPNP_HAVE_DEVICE 1 diff --git a/threadutil/inc/ThreadPool.h b/threadutil/inc/ThreadPool.h index 166d6f1..2f70911 100644 --- a/threadutil/inc/ThreadPool.h +++ b/threadutil/inc/ThreadPool.h @@ -82,15 +82,6 @@ typedef enum priority {LOW_PRIORITY, #define DEBUG 1 #endif -//DEBUGGING -#ifndef WIN32 - #ifdef DEBUG - #define DBGONLY(x) x - #else - #define DBGONLY(x) - #endif -#endif - #include "LinkedList.h" #include #include "FreeList.h" diff --git a/upnp/inc/upnp.h b/upnp/inc/upnp.h index e8fb1fa..290cd5e 100644 --- a/upnp/inc/upnp.h +++ b/upnp/inc/upnp.h @@ -52,9 +52,6 @@ #endif #include "ixml.h" #include "upnpconfig.h" -#if UPNP_HAVE_DEBUG - #include "upnpdebug.h" -#endif #ifdef WIN32 @@ -489,6 +486,8 @@ #define INOUT #endif +#include "upnpdebug.h" + enum UpnpOpenFileMode{UPNP_READ, UPNP_WRITE}; /// @name Constants, Structures, and Types diff --git a/upnp/inc/upnpdebug.h b/upnp/inc/upnpdebug.h index 1efbbca..f9822ba 100644 --- a/upnp/inc/upnpdebug.h +++ b/upnp/inc/upnpdebug.h @@ -33,11 +33,9 @@ #ifndef UPNP_DEBUG_H #define UPNP_DEBUG_H +#include "upnp.h" #include "upnpconfig.h" -// Function declarations only if debug compiled into the library -#if UPNP_HAVE_DEBUG - #include #ifdef __cplusplus @@ -70,7 +68,17 @@ extern "C" { * \end{itemize} */ -typedef enum Upnp_Module {SSDP,SOAP,GENA,TPOOL,MSERV,DOM,API, HTTP} Dbg_Module; +typedef enum Upnp_Module { + SSDP, + SOAP, + GENA, + TPOOL, + MSERV, + DOM, + API, + HTTP +} Dbg_Module; + //@{ typedef enum Upnp_LogLevel_e { UPNP_CRITICAL, @@ -81,7 +89,7 @@ typedef enum Upnp_LogLevel_e { //@} // for backward compatibility -#define Dbg_Level Upnp_LogLevel +#define Dbg_Level Upnp_LogLevel /** @@ -102,22 +110,30 @@ typedef enum Upnp_LogLevel_e { * -1 : If fails * UPNP_E_SUCCESS : if success ***************************************************************************/ +#ifdef DEBUG int UpnpInitLog(); +#else +static inline int UpnpInitLog() { return UPNP_E_SUCCESS; } +#endif // for backward compatibility -#define InitLog UpnpInitLog +#define InitLog UpnpInitLog /*************************************************************************** * Function : UpnpSetLogLevel * - * Parameters: void + * Parameters: Upnp_LogLevel log_level * * Description: * This functions set the log level (see {\tt Upnp_LogLevel} * Returns: void ***************************************************************************/ -void UpnpSetLogLevel (Upnp_LogLevel); +#ifdef DEBUG +void UpnpSetLogLevel(Upnp_LogLevel log_level); +#else +static inline void UpnpSetLogLevel(Upnp_LogLevel log_level) {} +#endif /*************************************************************************** @@ -129,7 +145,11 @@ void UpnpSetLogLevel (Upnp_LogLevel); * This functions closes the log files * Returns: void ***************************************************************************/ +#ifdef DEBUG void UpnpCloseLog(); +#else +static inline void UpnpCloseLog() {} +#endif // for backward compatibility #define CloseLog UpnpCloseLog @@ -149,7 +169,15 @@ void UpnpCloseLog(); * per the requested banner * Returns: void ***************************************************************************/ -void UpnpSetLogFileNames (const char* ErrFileName, const char* InfoFileName); +#ifdef DEBUG +void UpnpSetLogFileNames( + const char *ErrFileName, + const char *InfoFileName); +#else +static inline void UpnpSetLogFileNames( + const char *ErrFileName, + const char *InfoFileName) {} +#endif // for backward compatibility #define SetLogFileNames UpnpSetLogFileNames @@ -171,12 +199,45 @@ void UpnpSetLogFileNames (const char* ErrFileName, const char* InfoFileName); * NULL : if the module is turn off for debug * else returns the right file descriptor ***************************************************************************/ -FILE* UpnpGetDebugFile (Upnp_LogLevel level, Dbg_Module module); +#ifdef DEBUG +FILE *UpnpGetDebugFile(Upnp_LogLevel level, Dbg_Module module); +#else +static inline FILE *UpnpGetDebugFile(Upnp_LogLevel level, Dbg_Module module) +{ + return NULL; +} +#endif // for backward compatibility #define GetDebugFile UpnpGetDebugFile +/*************************************************************************** + * Function : DebugAtThisLevel + * + * Parameters: + * IN Dbg_Level 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 + * + * Description: + * This functions returns true if debug output should be done in this + * module. + * + * Returns: int + ***************************************************************************/ +#ifdef DEBUG +int DebugAtThisLevel( + IN Upnp_LogLevel DLevel, + IN Dbg_Module Module); +#else +static inline int DebugAtThisLevel( + IN Upnp_LogLevel DLevel, + IN Dbg_Module Module) { return 0; } +#endif + + /*************************************************************************** * Function : UpnpPrintf * @@ -198,6 +259,7 @@ FILE* UpnpGetDebugFile (Upnp_LogLevel level, Dbg_Module module); * debug statement is coming * Returns: void ***************************************************************************/ +#ifdef DEBUG void UpnpPrintf (Upnp_LogLevel DLevel, Dbg_Module Module, const char* DbgFileName, int DbgLineNo, const char* FmtStr, @@ -206,6 +268,15 @@ void UpnpPrintf (Upnp_LogLevel DLevel, Dbg_Module Module, __attribute__((format (__printf__, 5, 6))) #endif ; +#else +static inline void UpnpPrintf( + Upnp_LogLevel DLevel, + Dbg_Module Module, + const char* DbgFileName, + int DbgLineNo, + const char* FmtStr, + ...) {} +#endif /*************************************************************************** @@ -222,8 +293,19 @@ void UpnpPrintf (Upnp_LogLevel DLevel, Dbg_Module Module, * per the requested banner * Returns: void ***************************************************************************/ -void UpnpDisplayBanner (FILE *fd, - const char** lines, size_t size, int starlength); +#ifdef DEBUG +void UpnpDisplayBanner( + FILE *fd, + const char **lines, + size_t size, + int starlength); +#else +static inline void UpnpDisplayBanner( + FILE *fd, + const char **lines, + size_t size, + int starlength) {} +#endif /*************************************************************************** @@ -240,19 +322,23 @@ void UpnpDisplayBanner (FILE *fd, * debug statement is coming to the log file * Returns: void ***************************************************************************/ -void UpnpDisplayFileAndLine (FILE *fd, const char *DbgFileName, int DbgLineNo); - +#ifdef DEBUG +void UpnpDisplayFileAndLine( + FILE *fd, + const char *DbgFileName, + int DbgLineNo); +#else +static inline void UpnpDisplayFileAndLine( + FILE *fd, + const char *DbgFileName, + int DbgLineNo) {} +#endif //@} - #ifdef __cplusplus } #endif -#endif // UPNP_HAVE_DEBUG - #endif // UPNP_DEBUG_H - - diff --git a/upnp/src/api/upnpapi.c b/upnp/src/api/upnpapi.c index 6c20928..8b8db6c 100644 --- a/upnp/src/api/upnpapi.c +++ b/upnp/src/api/upnpapi.c @@ -200,13 +200,12 @@ int UpnpInit( IN const char *HostIP, srand( time( NULL ) ); // needed by SSDP or other parts - DBGONLY( if( InitLog( ) != UPNP_E_SUCCESS ) - return UPNP_E_INIT_FAILED; ); + if( UpnpInitLog() != UPNP_E_SUCCESS ) { + return UPNP_E_INIT_FAILED; + } - DBGONLY( UpnpPrintf - ( UPNP_INFO, API, __FILE__, __LINE__, "Inside UpnpInit \n" ); - ) - //initialize mutex + UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, "Inside UpnpInit \n" ); + // initialize mutex #ifdef __CYGWIN__ /* On Cygwin, pthread_mutex_init() fails without this memset. */ /* TODO: Fix Cygwin so we don't need this memset(). */ @@ -226,23 +225,23 @@ int UpnpInit( IN const char *HostIP, return UPNP_E_INIT_FAILED;} ) - HandleLock( ); + HandleLock(); if( HostIP != NULL ) strcpy( LOCAL_HOST, HostIP ); else { if( getlocalhostname( LOCAL_HOST ) != UPNP_E_SUCCESS ) { - HandleUnlock( ); + HandleUnlock(); return UPNP_E_INIT_FAILED; } } if( UpnpSdkInit != 0 ) { - HandleUnlock( ); + HandleUnlock(); return UPNP_E_INIT; } - InitHandleList( ); - HandleUnlock( ); + InitHandleList(); + HandleUnlock(); TPAttrInit( &attr ); TPAttrSetMaxThreads( &attr, MAX_THREADS ); @@ -253,13 +252,13 @@ int UpnpInit( IN const char *HostIP, if( ThreadPoolInit( &gSendThreadPool, &attr ) != UPNP_E_SUCCESS ) { UpnpSdkInit = 0; - UpnpFinish( ); + UpnpFinish(); return UPNP_E_INIT_FAILED; } if( ThreadPoolInit( &gRecvThreadPool, &attr ) != UPNP_E_SUCCESS ) { UpnpSdkInit = 0; - UpnpFinish( ); + UpnpFinish(); return UPNP_E_INIT_FAILED; } @@ -276,15 +275,14 @@ int UpnpInit( IN const char *HostIP, &gSendThreadPool ) ) != UPNP_E_SUCCESS ) { UpnpSdkInit = 0; - UpnpFinish( ); + UpnpFinish(); return retVal; } #if EXCLUDE_MINISERVER == 0 if( ( retVal = StartMiniServer( DestPort ) ) <= 0 ) { - DBGONLY( UpnpPrintf( UPNP_CRITICAL, API, __FILE__, __LINE__, - "Miniserver failed to start" ); - ) - UpnpFinish( ); + UpnpPrintf( UPNP_CRITICAL, API, __FILE__, __LINE__, + "Miniserver failed to start" ); + UpnpFinish(); UpnpSdkInit = 0; if( retVal != -1 ) return retVal; @@ -298,25 +296,23 @@ int UpnpInit( IN const char *HostIP, #if EXCLUDE_WEB_SERVER == 0 if( ( retVal = UpnpEnableWebserver( WEB_SERVER_ENABLED ) ) != UPNP_E_SUCCESS ) { - UpnpFinish( ); + UpnpFinish(); UpnpSdkInit = 0; return retVal; } #endif - DBGONLY( UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, - "Host Ip: %s Host Port: %d\n", LOCAL_HOST, - LOCAL_PORT ) ); + UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, + "Host Ip: %s Host Port: %d\n", LOCAL_HOST, + LOCAL_PORT ); - DBGONLY( UpnpPrintf - ( UPNP_INFO, API, __FILE__, __LINE__, "Exiting UpnpInit \n" ); - ) + UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, "Exiting UpnpInit \n" ); - return UPNP_E_SUCCESS; + return UPNP_E_SUCCESS; } /***************** end of UpnpInit ******************/ -DBGONLY( +#ifdef DEBUG static void PrintThreadPoolStats (const char* DbgFileName, int DbgLineNo, const char* msg, const ThreadPoolStats* const stats) @@ -337,7 +333,8 @@ PrintThreadPoolStats (const char* DbgFileName, int DbgLineNo, stats->avgWaitHQ, stats->avgWaitMQ, stats->avgWaitLQ, stats->maxThreads, stats->totalWorkTime, stats->totalIdleTime ); -}) +} +#endif /**************************************************************************** @@ -358,39 +355,43 @@ PrintThreadPoolStats (const char* DbgFileName, int DbgLineNo, * UPNP_E_SUCCESS on success, nonzero on failure. *****************************************************************************/ int -UpnpFinish( ) +UpnpFinish() { DEVICEONLY( UpnpDevice_Handle device_handle; ) - CLIENTONLY( UpnpClient_Handle client_handle; + CLIENTONLY( UpnpClient_Handle client_handle; ) struct Handle_Info *temp; - DBGONLY( ThreadPoolStats stats; - ) +#ifdef DEBUG + ThreadPoolStats stats; +#endif #ifdef WIN32 // WSACleanup( ); #endif - if( UpnpSdkInit != 1 ) + if( UpnpSdkInit != 1 ) return UPNP_E_FINISH; - DBGONLY( UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, - "Inside UpnpFinish : UpnpSdkInit is :%d:\n", - UpnpSdkInit ); if( UpnpSdkInit == 1 ) { - UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, - "UpnpFinish : UpnpSdkInit is ONE\n" );} - ThreadPoolGetStats( &gRecvThreadPool, &stats ); - PrintThreadPoolStats (__FILE__, __LINE__, - "Recv Thread Pool", &stats); - ThreadPoolGetStats( &gSendThreadPool, &stats ); - PrintThreadPoolStats (__FILE__, __LINE__, - "Send Thread Pool", &stats); - ) + UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, + "Inside UpnpFinish : UpnpSdkInit is :%d:\n", + UpnpSdkInit ); +#ifdef DEBUG + if( UpnpSdkInit == 1 ) { + UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, + "UpnpFinish : UpnpSdkInit is ONE\n" ); + } + ThreadPoolGetStats( &gRecvThreadPool, &stats ); + PrintThreadPoolStats (__FILE__, __LINE__, + "Recv Thread Pool", &stats); + ThreadPoolGetStats( &gSendThreadPool, &stats ); + PrintThreadPoolStats (__FILE__, __LINE__, + "Send Thread Pool", &stats); +#endif #ifdef INCLUDE_DEVICE_APIS - if( GetDeviceHandleInfo( &device_handle, &temp ) == HND_DEVICE ) - UpnpUnRegisterRootDevice( device_handle ); + if( GetDeviceHandleInfo( &device_handle, &temp ) == HND_DEVICE ) + UpnpUnRegisterRootDevice( device_handle ); #endif #ifdef INCLUDE_CLIENT_APIS @@ -400,33 +401,41 @@ UpnpFinish( ) TimerThreadShutdown( &gTimerThread ); - StopMiniServer( ); + StopMiniServer(); #if EXCLUDE_WEB_SERVER == 0 - web_server_destroy( ); + web_server_destroy(); #endif +#ifdef DEBUG ThreadPoolShutdown( &gSendThreadPool ); ThreadPoolShutdown( &gRecvThreadPool ); - - DBGONLY( UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, "Exiting UpnpFinish : UpnpSdkInit is :%d:\n", UpnpSdkInit ); ThreadPoolGetStats( &gRecvThreadPool, &stats ); PrintThreadPoolStats ( __FILE__, __LINE__, "Recv Thread Pool", &stats); ThreadPoolGetStats( &gSendThreadPool, &stats ); PrintThreadPoolStats (__FILE__, __LINE__, "Send Thread Pool", &stats); ) // DBGONLY - DBGONLY( CloseLog( ); - ); + UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, + "Exiting UpnpFinish : UpnpSdkInit is :%d:\n", + UpnpSdkInit ); + ThreadPoolGetStats( &gRecvThreadPool, &stats ); + PrintThreadPoolStats( __FILE__, __LINE__, + "Recv Thread Pool", &stats); + ThreadPoolGetStats( &gSendThreadPool, &stats ); + PrintThreadPoolStats(__FILE__, __LINE__, + "Send Thread Pool", &stats); + CloseLog(); +#endif CLIENTONLY( ithread_mutex_destroy( &GlobalClientSubscribeMutex ); ) - ithread_mutex_destroy( &GlobalHndMutex ); + ithread_mutex_destroy( &GlobalHndMutex ); ithread_mutex_destroy( &gUUIDMutex ); // remove all virtual dirs - UpnpRemoveAllVirtualDirs( ); - //leuk_he allow static linking: - #ifdef WIN32 - #ifdef PTW32_STATIC_LIB - pthread_win32_thread_detach_np (); - #endif - #endif + UpnpRemoveAllVirtualDirs(); + // leuk_he allow static linking: +#ifdef WIN32 +#ifdef PTW32_STATIC_LIB + pthread_win32_thread_detach_np (); +#endif +#endif UpnpSdkInit = 0; @@ -512,9 +521,9 @@ UpnpAddRootDevice( IN const char *DescURL, return retVal; } - HandleLock( ); + HandleLock(); if( GetHandleInfo( Hnd, &HInfo ) == UPNP_E_INVALID_HANDLE ) { - HandleUnlock( ); + HandleUnlock(); ixmlDocument_free( temp ); return UPNP_E_INVALID_HANDLE; } @@ -522,20 +531,18 @@ UpnpAddRootDevice( IN const char *DescURL, if( addServiceTable ( ( IXML_Node * ) temp, &HInfo->ServiceTable, DescURL ) ) { - DBGONLY( UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, - "UpnpAddRootDevice: GENA Service Table \n" ); - UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, - "Here are the known services: \n" ); - printServiceTable( &HInfo->ServiceTable, UPNP_INFO, API ); - ) + UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, + "UpnpAddRootDevice: GENA Service Table \n" ); + UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, + "Here are the known services: \n" ); + printServiceTable( &HInfo->ServiceTable, UPNP_INFO, API ); } else { - DBGONLY( UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, - "\nUpnpAddRootDevice: No Eventing Support Found \n" ); - ) + UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, + "\nUpnpAddRootDevice: No Eventing Support Found \n" ); } ixmlDocument_free( temp ); - HandleUnlock( ); + HandleUnlock(); return UPNP_E_SUCCESS; } @@ -579,39 +586,37 @@ UpnpRegisterRootDevice( IN const char *DescUrl, return UPNP_E_FINISH; } - DBGONLY( UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, - "Inside UpnpRegisterRootDevice \n" ); - ) - HandleLock( ); + UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, + "Inside UpnpRegisterRootDevice \n" ); + HandleLock(); if( UpnpSdkDeviceRegistered ) { - HandleUnlock( ); + HandleUnlock(); return UPNP_E_ALREADY_REGISTERED; } if( Hnd == NULL || Fun == NULL || DescUrl == NULL || strlen( DescUrl ) == 0 ) { - HandleUnlock( ); + HandleUnlock(); return UPNP_E_INVALID_PARAM; } - if( ( *Hnd = GetFreeHandle( ) ) == UPNP_E_OUTOF_HANDLE ) { - HandleUnlock( ); + if( ( *Hnd = GetFreeHandle() ) == UPNP_E_OUTOF_HANDLE ) { + HandleUnlock(); return UPNP_E_OUTOF_MEMORY; } HInfo = ( struct Handle_Info * )malloc( sizeof( struct Handle_Info ) ); if( HInfo == NULL ) { - HandleUnlock( ); + HandleUnlock(); return UPNP_E_OUTOF_MEMORY; } HandleTable[*Hnd] = HInfo; - DBGONLY( UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, - "Root device URL is %s\n", DescUrl ); - ) + UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, + "Root device URL is %s\n", DescUrl ); - HInfo->aliasInstalled = 0; + HInfo->aliasInstalled = 0; HInfo->HType = HND_DEVICE; strcpy( HInfo->DescURL, DescUrl ); HInfo->Callback = Fun; @@ -632,28 +637,26 @@ UpnpRegisterRootDevice( IN const char *DescUrl, != UPNP_E_SUCCESS ) { CLIENTONLY( ListDestroy( &HInfo->SsdpSearchList, 0 ) ); FreeHandle( *Hnd ); - HandleUnlock( ); + HandleUnlock(); return retVal; } - DBGONLY( UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, - "UpnpRegisterRootDevice: Valid Description\n" ); - UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, - "UpnpRegisterRootDevice: DescURL : %s\n", - HInfo->DescURL ); - ) + UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, + "UpnpRegisterRootDevice: Valid Description\n" ); + UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, + "UpnpRegisterRootDevice: DescURL : %s\n", + HInfo->DescURL ); - HInfo->DeviceList = + HInfo->DeviceList = ixmlDocument_getElementsByTagName( HInfo->DescDocument, "device" ); if( HInfo->DeviceList == NULL ) { CLIENTONLY( ListDestroy( &HInfo->SsdpSearchList, 0 ) ); ixmlDocument_free( HInfo->DescDocument ); FreeHandle( *Hnd ); - HandleUnlock( ); - DBGONLY( UpnpPrintf( UPNP_CRITICAL, API, __FILE__, __LINE__, - "UpnpRegisterRootDevice: No devices found for RootDevice\n" ); - ) - return UPNP_E_INVALID_DESC; + HandleUnlock(); + UpnpPrintf( UPNP_CRITICAL, API, __FILE__, __LINE__, + "UpnpRegisterRootDevice: No devices found for RootDevice\n" ); + return UPNP_E_INVALID_DESC; } HInfo->ServiceList = @@ -664,45 +667,40 @@ UpnpRegisterRootDevice( IN const char *DescUrl, ixmlNodeList_free( HInfo->DeviceList ); ixmlDocument_free( HInfo->DescDocument ); FreeHandle( *Hnd ); - HandleUnlock( ); - DBGONLY( UpnpPrintf( UPNP_CRITICAL, API, __FILE__, __LINE__, - "UpnpRegisterRootDevice: No services found for RootDevice\n" ); - ) - return UPNP_E_INVALID_DESC; + HandleUnlock(); + UpnpPrintf( UPNP_CRITICAL, API, __FILE__, __LINE__, + "UpnpRegisterRootDevice: No services found for RootDevice\n" ); + return UPNP_E_INVALID_DESC; } - DBGONLY( UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, - "UpnpRegisterRootDevice: Gena Check\n" ); - ) - //******************************* - //GENA SET UP - //******************************* - if( getServiceTable( ( IXML_Node * ) HInfo->DescDocument, + UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, + "UpnpRegisterRootDevice: Gena Check\n" ); + //******************************* + // GENA SET UP + //******************************* + if( getServiceTable( ( IXML_Node * ) HInfo->DescDocument, &HInfo->ServiceTable, HInfo->DescURL ) ) { - DBGONLY( UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, - "UpnpRegisterRootDevice: GENA Service Table \n" ); - UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, - "Here are the known services: \n" ); - printServiceTable( &HInfo->ServiceTable, UPNP_INFO, API ); - ) + UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, + "UpnpRegisterRootDevice: GENA Service Table \n" ); + UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, + "Here are the known services: \n" ); + printServiceTable( &HInfo->ServiceTable, UPNP_INFO, API ); } else { CLIENTONLY( ListDestroy( &HInfo->SsdpSearchList, 0 ) ); FreeHandle( *Hnd ); - HandleUnlock( ); - DBGONLY( UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, - "\nUpnpRegisterRootDevice: Errors retrieving service table \n" ); - ) - return UPNP_E_INVALID_DESC; + HandleUnlock(); + UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, + "\nUpnpRegisterRootDevice: Errors retrieving service table \n" ); + return UPNP_E_INVALID_DESC; } UpnpSdkDeviceRegistered = 1; - HandleUnlock( ); + HandleUnlock(); - DBGONLY( UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, - "Exiting RegisterRootDevice Successfully\n" ); - ) + UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, + "Exiting RegisterRootDevice Successfully\n" ); - return UPNP_E_SUCCESS; + return UPNP_E_SUCCESS; } /****************** End of UpnpRegisterRootDevice *********************/ @@ -744,31 +742,29 @@ UpnpRemoveRootDevice( IN const char *DescURL, return retVal; } - HandleLock( ); + HandleLock(); if( GetHandleInfo( Hnd, &HInfo ) == UPNP_E_INVALID_HANDLE ) { - HandleUnlock( ); + HandleUnlock(); ixmlDocument_free( temp ); return UPNP_E_INVALID_HANDLE; } if( removeServiceTable( ( IXML_Node * ) temp, &HInfo->ServiceTable ) ) { - DBGONLY( UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, - "UpnpRemoveRootDevice: GENA Service Table \n" ); - UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, - "Here are the known services: \n" ); - printServiceTable( &HInfo->ServiceTable, UPNP_INFO, API ); - ) + UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, + "UpnpRemoveRootDevice: GENA Service Table \n" ); + UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, + "Here are the known services: \n" ); + printServiceTable( &HInfo->ServiceTable, UPNP_INFO, API ); } else { - DBGONLY( UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, - "\nUpnpRemoveRootDevice: No Services Removed\n" ); - UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, - "Here are the known services: \n" ); - printServiceTable( &HInfo->ServiceTable, UPNP_INFO, API ); - ) + UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, + "\nUpnpRemoveRootDevice: No Services Removed\n" ); + UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, + "Here are the known services: \n" ); + printServiceTable( &HInfo->ServiceTable, UPNP_INFO, API ); } - HandleUnlock( ); + HandleUnlock(); ixmlDocument_free( temp ); return UPNP_E_SUCCESS; @@ -806,27 +802,26 @@ UpnpUnRegisterRootDevice( IN UpnpDevice_Handle Hnd ) return UPNP_E_FINISH; } - HandleLock( ); + HandleLock(); if( !UpnpSdkDeviceRegistered ) { - HandleUnlock( ); + HandleUnlock(); return UPNP_E_INVALID_HANDLE; } - HandleUnlock( ); + HandleUnlock(); - DBGONLY( UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, - "Inside UpnpUnRegisterRootDevice \n" ); - ) + UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, + "Inside UpnpUnRegisterRootDevice \n" ); #if EXCLUDE_GENA == 0 - if( genaUnregisterDevice( Hnd ) != UPNP_E_SUCCESS ) + if( genaUnregisterDevice( Hnd ) != UPNP_E_SUCCESS ) return UPNP_E_INVALID_HANDLE; #endif - HandleLock( ); + HandleLock(); if( GetHandleInfo( Hnd, &HInfo ) == UPNP_E_INVALID_HANDLE ) { - HandleUnlock( ); + HandleUnlock(); return UPNP_E_INVALID_HANDLE; } - HandleUnlock( ); + HandleUnlock(); #if EXCLUDE_SSDP == 0 retVal = AdvertiseAndReply( -1, Hnd, 0, ( struct sockaddr_in * )NULL, @@ -834,9 +829,9 @@ UpnpUnRegisterRootDevice( IN UpnpDevice_Handle Hnd ) ( char * )NULL, HInfo->MaxAge ); #endif - HandleLock( ); + HandleLock(); if( GetHandleInfo( Hnd, &HInfo ) == UPNP_E_INVALID_HANDLE ) { - HandleUnlock( ); + HandleUnlock(); return UPNP_E_INVALID_HANDLE; } //info = (struct Handle_Info *) HandleTable[Hnd]; @@ -854,13 +849,12 @@ UpnpUnRegisterRootDevice( IN UpnpDevice_Handle Hnd ) FreeHandle( Hnd ); UpnpSdkDeviceRegistered = 0; - HandleUnlock( ); + HandleUnlock(); - DBGONLY( UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, - "Exiting UpnpUnRegisterRootDevice \n" ); - ) + UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, + "Exiting UpnpUnRegisterRootDevice \n" ); - return retVal; + return retVal; } /****************** End of UpnpUnRegisterRootDevice *********************/ @@ -1167,29 +1161,28 @@ UpnpRegisterRootDevice2( IN Upnp_DescType descriptionType, return UPNP_E_FINISH; } - DBGONLY( UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, - "Inside UpnpRegisterRootDevice2 \n" ); - ) + UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, + "Inside UpnpRegisterRootDevice2 \n" ); - if( Hnd == NULL || Fun == NULL ) { + if( Hnd == NULL || Fun == NULL ) { return UPNP_E_INVALID_PARAM; } - HandleLock( ); + HandleLock(); if( UpnpSdkDeviceRegistered ) { - HandleUnlock( ); + HandleUnlock(); return UPNP_E_ALREADY_REGISTERED; } - if( ( *Hnd = GetFreeHandle( ) ) == UPNP_E_OUTOF_HANDLE ) { - HandleUnlock( ); + if( ( *Hnd = GetFreeHandle() ) == UPNP_E_OUTOF_HANDLE ) { + HandleUnlock(); return UPNP_E_OUTOF_MEMORY; } HInfo = ( struct Handle_Info * )malloc( sizeof( struct Handle_Info ) ); if( HInfo == NULL ) { - HandleUnlock( ); + HandleUnlock(); return UPNP_E_OUTOF_MEMORY; } HandleTable[*Hnd] = HInfo; @@ -1204,7 +1197,7 @@ UpnpRegisterRootDevice2( IN Upnp_DescType descriptionType, if( retVal != UPNP_E_SUCCESS ) { FreeHandle( *Hnd ); - HandleUnlock( ); + HandleUnlock(); return retVal; } @@ -1218,30 +1211,28 @@ UpnpRegisterRootDevice2( IN Upnp_DescType descriptionType, HInfo->ServiceList = NULL; CLIENTONLY( HInfo->ClientSubList = NULL; ) - CLIENTONLY( ListInit( &HInfo->SsdpSearchList, NULL, NULL ); + CLIENTONLY( ListInit( &HInfo->SsdpSearchList, NULL, NULL ); ); HInfo->MaxSubscriptions = UPNP_INFINITE; HInfo->MaxSubscriptionTimeOut = UPNP_INFINITE; - DBGONLY( UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, - "UpnpRegisterRootDevice2: Valid Description\n" ); - UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, - "UpnpRegisterRootDevice2: DescURL : %s\n", - HInfo->DescURL ); - ) + UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, + "UpnpRegisterRootDevice2: Valid Description\n" ); + UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, + "UpnpRegisterRootDevice2: DescURL : %s\n", + HInfo->DescURL ); - HInfo->DeviceList = + HInfo->DeviceList = ixmlDocument_getElementsByTagName( HInfo->DescDocument, "device" ); if( HInfo->DeviceList == NULL ) { CLIENTONLY( ListDestroy( &HInfo->SsdpSearchList, 0 ) ); ixmlDocument_free( HInfo->DescDocument ); FreeHandle( *Hnd ); - HandleUnlock( ); - DBGONLY( UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, - "UpnpRegisterRootDevice2: No devices found for RootDevice\n" ); - ) - return UPNP_E_INVALID_DESC; + HandleUnlock(); + UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, + "UpnpRegisterRootDevice2: No devices found for RootDevice\n" ); + return UPNP_E_INVALID_DESC; } HInfo->ServiceList = @@ -1253,39 +1244,34 @@ UpnpRegisterRootDevice2( IN Upnp_DescType descriptionType, ixmlNodeList_free( HInfo->DeviceList ); ixmlDocument_free( HInfo->DescDocument ); FreeHandle( *Hnd ); - HandleUnlock( ); - DBGONLY( UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, - "UpnpRegisterRootDevice2: No services found for RootDevice\n" ); - ) - return UPNP_E_INVALID_DESC; + HandleUnlock(); + UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, + "UpnpRegisterRootDevice2: No services found for RootDevice\n" ); + return UPNP_E_INVALID_DESC; } - DBGONLY( UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, - "UpnpRegisterRootDevice2: Gena Check\n" ); - ) + UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, + "UpnpRegisterRootDevice2: Gena Check\n" ); //******************************* //GENA SET UP //******************************* if( getServiceTable( ( IXML_Node * ) HInfo->DescDocument, &HInfo->ServiceTable, HInfo->DescURL ) ) { - DBGONLY( UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, - "UpnpRegisterRootDevice2: GENA Service Table \n" ); - ) + UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, + "UpnpRegisterRootDevice2: GENA Service Table \n" ); } else { CLIENTONLY( ListDestroy( &HInfo->SsdpSearchList, 0 ) ); FreeHandle( *Hnd ); - HandleUnlock( ); - DBGONLY( UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, - "\nUpnpRegisterRootDevice: Errors retrieving service table \n" ); - ) - return UPNP_E_INVALID_DESC; + HandleUnlock(); + UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, + "\nUpnpRegisterRootDevice: Errors retrieving service table \n" ); + return UPNP_E_INVALID_DESC; } UpnpSdkDeviceRegistered = 1; - HandleUnlock( ); - DBGONLY( UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, - "Exiting RegisterRootDevice2 Successfully\n" ); - ) - return UPNP_E_SUCCESS; + HandleUnlock(); + UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, + "Exiting RegisterRootDevice2 Successfully\n" ); + return UPNP_E_SUCCESS; } /****************** End of UpnpRegisterRootDevice2 *********************/ @@ -1323,28 +1309,27 @@ UpnpRegisterClient( IN Upnp_FunPtr Fun, return UPNP_E_FINISH; } - DBGONLY( UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, - "Inside UpnpRegisterClient \n" ); - ) + UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, + "Inside UpnpRegisterClient \n" ); - if( Fun == NULL || Hnd == NULL ) { + if( Fun == NULL || Hnd == NULL ) { return UPNP_E_INVALID_PARAM; } - HandleLock( ); + HandleLock(); if( UpnpSdkClientRegistered ) { - HandleUnlock( ); + HandleUnlock(); return UPNP_E_ALREADY_REGISTERED; } - if( ( *Hnd = GetFreeHandle( ) ) == UPNP_E_OUTOF_HANDLE ) { - HandleUnlock( ); + if( ( *Hnd = GetFreeHandle() ) == UPNP_E_OUTOF_HANDLE ) { + HandleUnlock(); return UPNP_E_OUTOF_MEMORY; } HInfo = ( struct Handle_Info * )malloc( sizeof( struct Handle_Info ) ); if( HInfo == NULL ) { - HandleUnlock( ); + HandleUnlock(); return UPNP_E_OUTOF_MEMORY; } @@ -1364,13 +1349,12 @@ UpnpRegisterClient( IN Upnp_FunPtr Fun, UpnpSdkClientRegistered = 1; - HandleUnlock( ); + HandleUnlock(); - DBGONLY( UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, - "Exiting UpnpRegisterClient \n" ); - ) + UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, + "Exiting UpnpRegisterClient \n" ); - return UPNP_E_SUCCESS; + return UPNP_E_SUCCESS; } /****************** End of UpnpRegisterClient *********************/ #endif // INCLUDE_CLIENT_APIS @@ -1403,23 +1387,22 @@ UpnpUnRegisterClient( IN UpnpClient_Handle Hnd ) return UPNP_E_FINISH; } - DBGONLY( UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, - "Inside UpnpUnRegisterClient \n" ); - ) - HandleLock( ); + UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, + "Inside UpnpUnRegisterClient \n" ); + HandleLock(); if( !UpnpSdkClientRegistered ) { - HandleUnlock( ); + HandleUnlock(); return UPNP_E_INVALID_HANDLE; } - HandleUnlock( ); + HandleUnlock(); #if EXCLUDE_GENA == 0 if( genaUnregisterClient( Hnd ) != UPNP_E_SUCCESS ) return UPNP_E_INVALID_HANDLE; #endif - HandleLock( ); + HandleLock(); if( GetHandleInfo( Hnd, &HInfo ) == UPNP_E_INVALID_HANDLE ) { - HandleUnlock( ); + HandleUnlock(); return UPNP_E_INVALID_HANDLE; } //clean up search list @@ -1437,11 +1420,10 @@ UpnpUnRegisterClient( IN UpnpClient_Handle Hnd ) ListDestroy( &HInfo->SsdpSearchList, 0 ); FreeHandle( Hnd ); UpnpSdkClientRegistered = 0; - HandleUnlock( ); - DBGONLY( UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, - "Exiting UpnpUnRegisterClient \n" ); - ) - return UPNP_E_SUCCESS; + HandleUnlock(); + UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, + "Exiting UpnpUnRegisterClient \n" ); + return UPNP_E_SUCCESS; } /****************** End of UpnpUnRegisterClient *********************/ #endif // INCLUDE_CLIENT_APIS @@ -1483,19 +1465,18 @@ UpnpSendAdvertisement( IN UpnpDevice_Handle Hnd, return UPNP_E_FINISH; } - DBGONLY( UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, - "Inside UpnpSendAdvertisement \n" ); - ) + UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, + "Inside UpnpSendAdvertisement \n" ); - HandleLock( ); + HandleLock(); if( GetHandleInfo( Hnd, &SInfo ) != HND_DEVICE ) { - HandleUnlock( ); + HandleUnlock(); return UPNP_E_INVALID_HANDLE; } if( Exp < 1 ) Exp = DEFAULT_MAXAGE; SInfo->MaxAge = Exp; - HandleUnlock( ); + HandleUnlock(); retVal = AdvertiseAndReply( 1, Hnd, 0, ( struct sockaddr_in * )NULL, ( char * )NULL, ( char * )NULL, ( char * )NULL, Exp ); @@ -1515,9 +1496,9 @@ UpnpSendAdvertisement( IN UpnpDevice_Handle Hnd, adEvent->handle = Hnd; adEvent->Event = ptrMx; - HandleLock( ); + HandleLock(); if( GetHandleInfo( Hnd, &SInfo ) != HND_DEVICE ) { - HandleUnlock( ); + HandleUnlock(); free( adEvent ); free( ptrMx ); return UPNP_E_INVALID_HANDLE; @@ -1532,7 +1513,7 @@ UpnpSendAdvertisement( IN UpnpDevice_Handle Hnd, REL_SEC, &job, SHORT_TERM, &( adEvent->eventId ) ) ) != UPNP_E_SUCCESS ) { - HandleUnlock( ); + HandleUnlock(); free( adEvent ); free( ptrMx ); return retVal; @@ -1546,18 +1527,18 @@ UpnpSendAdvertisement( IN UpnpDevice_Handle Hnd, REL_SEC, &job, SHORT_TERM, &( adEvent->eventId ) ) ) != UPNP_E_SUCCESS ) { - HandleUnlock( ); + HandleUnlock(); free( adEvent ); free( ptrMx ); return retVal; } #endif - HandleUnlock( ); - DBGONLY( UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, - "Exiting UpnpSendAdvertisement \n" ); ) + HandleUnlock(); + UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, + "Exiting UpnpSendAdvertisement \n" ); - return retVal; + return retVal; } /****************** End of UpnpSendAdvertisement *********************/ #endif // INCLUDE_DEVICE_APIS @@ -1595,33 +1576,31 @@ UpnpSearchAsync( IN UpnpClient_Handle Hnd, return UPNP_E_FINISH; } - DBGONLY( UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, - "Inside UpnpSearchAsync \n" ); - ) + UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, + "Inside UpnpSearchAsync \n" ); - HandleLock( ); + HandleLock(); if( GetHandleInfo( Hnd, &SInfo ) != HND_CLIENT ) { - HandleUnlock( ); + HandleUnlock(); return UPNP_E_INVALID_HANDLE; } if( Mx < 1 ) Mx = DEFAULT_MX; if( Target == NULL ) { - HandleUnlock( ); + HandleUnlock(); return UPNP_E_INVALID_PARAM; } - HandleUnlock( ); + HandleUnlock(); SearchByTarget( Mx, Target, ( void * )Cookie_const ); //HandleUnlock(); - DBGONLY( UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, - "Exiting UpnpSearchAsync \n" ); - ) + UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, + "Exiting UpnpSearchAsync \n" ); - return UPNP_E_SUCCESS; + return UPNP_E_SUCCESS; } /****************** End of UpnpSearchAsync *********************/ #endif // INCLUDE_CLIENT_APIS @@ -1659,25 +1638,23 @@ UpnpSetMaxSubscriptions( IN UpnpDevice_Handle Hnd, return UPNP_E_FINISH; } - DBGONLY( UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, - "Inside UpnpSetMaxSubscriptions \n" ); - ) + UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, + "Inside UpnpSetMaxSubscriptions \n" ); - HandleLock( ); + HandleLock(); if( ( ( MaxSubscriptions != UPNP_INFINITE ) && ( MaxSubscriptions < 0 ) ) || ( GetHandleInfo( Hnd, &SInfo ) != HND_DEVICE ) ) { - HandleUnlock( ); + HandleUnlock(); return UPNP_E_INVALID_HANDLE; } SInfo->MaxSubscriptions = MaxSubscriptions; - HandleUnlock( ); + HandleUnlock(); - DBGONLY( UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, - "Exiting UpnpSetMaxSubscriptions \n" ); - ) + UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, + "Exiting UpnpSetMaxSubscriptions \n" ); - return UPNP_E_SUCCESS; + return UPNP_E_SUCCESS; } /***************** End of UpnpSetMaxSubscriptions ********************/ #endif // INCLUDE_DEVICE_APIS @@ -1710,27 +1687,25 @@ UpnpSetMaxSubscriptionTimeOut( IN UpnpDevice_Handle Hnd, return UPNP_E_FINISH; } - DBGONLY( UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, - "Inside UpnpSetMaxSubscriptionTimeOut \n" ); - ) + UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, + "Inside UpnpSetMaxSubscriptionTimeOut \n" ); - HandleLock( ); + HandleLock(); if( ( ( MaxSubscriptionTimeOut != UPNP_INFINITE ) && ( MaxSubscriptionTimeOut < 0 ) ) || ( GetHandleInfo( Hnd, &SInfo ) != HND_DEVICE ) ) { - HandleUnlock( ); + HandleUnlock(); return UPNP_E_INVALID_HANDLE; } SInfo->MaxSubscriptionTimeOut = MaxSubscriptionTimeOut; - HandleUnlock( ); + HandleUnlock(); - DBGONLY( UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, - "Exiting UpnpSetMaxSubscriptionTimeOut \n" ); - ) + UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, + "Exiting UpnpSetMaxSubscriptionTimeOut \n" ); - return UPNP_E_SUCCESS; + return UPNP_E_SUCCESS; } /****************** End of UpnpSetMaxSubscriptionTimeOut ******************/ #endif // INCLUDE_DEVICE_APIS @@ -1777,25 +1752,24 @@ UpnpSubscribeAsync( IN UpnpClient_Handle Hnd, return UPNP_E_FINISH; } - DBGONLY( UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, - "Inside UpnpSubscribeAsync \n" ); - ) + UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, + "Inside UpnpSubscribeAsync \n" ); - HandleLock( ); + HandleLock(); if( GetHandleInfo( Hnd, &SInfo ) != HND_CLIENT ) { - HandleUnlock( ); + HandleUnlock(); return UPNP_E_INVALID_HANDLE; } if( EvtUrl == NULL ) { - HandleUnlock( ); + HandleUnlock(); return UPNP_E_INVALID_PARAM; } if( TimeOut != UPNP_INFINITE && TimeOut < 1 ) { - HandleUnlock( ); + HandleUnlock(); return UPNP_E_INVALID_PARAM; } if( Fun == NULL ) { - HandleUnlock( ); + HandleUnlock(); return UPNP_E_INVALID_PARAM; } @@ -1803,10 +1777,10 @@ UpnpSubscribeAsync( IN UpnpClient_Handle Hnd, ( struct UpnpNonblockParam * ) malloc( sizeof( struct UpnpNonblockParam ) ); if( Param == NULL ) { - HandleUnlock( ); + HandleUnlock(); return UPNP_E_OUTOF_MEMORY; } - HandleUnlock( ); + HandleUnlock(); Param->FunName = SUBSCRIBE; Param->Handle = Hnd; @@ -1820,11 +1794,10 @@ UpnpSubscribeAsync( IN UpnpClient_Handle Hnd, TPJobSetPriority( &job, MED_PRIORITY ); ThreadPoolAdd( &gSendThreadPool, &job, NULL ); - DBGONLY( UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, - "Exiting UpnpSubscribeAsync \n" ); - ) + UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, + "Exiting UpnpSubscribeAsync \n" ); - return UPNP_E_SUCCESS; + return UPNP_E_SUCCESS; } /****************** End of UpnpSubscribeAsync *********************/ #endif // INCLUDE_CLIENT_APIS @@ -1864,35 +1837,33 @@ UpnpSubscribe( IN UpnpClient_Handle Hnd, return UPNP_E_FINISH; } - DBGONLY( UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, - "Inside UpnpSubscribe \n" ); - ) + UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, + "Inside UpnpSubscribe \n" ); - HandleLock( ); + HandleLock(); if( GetHandleInfo( Hnd, &SInfo ) != HND_CLIENT ) { - HandleUnlock( ); + HandleUnlock(); return UPNP_E_INVALID_HANDLE; } if( EvtUrl == NULL ) { - HandleUnlock( ); + HandleUnlock(); return UPNP_E_INVALID_PARAM; } if( TimeOut == NULL ) { - HandleUnlock( ); + HandleUnlock(); return UPNP_E_INVALID_PARAM; } if( SubsId == NULL ) { - HandleUnlock( ); + HandleUnlock(); return UPNP_E_INVALID_PARAM; } - HandleUnlock( ); + HandleUnlock(); RetVal = genaSubscribe( Hnd, EvtUrl, TimeOut, SubsId ); - DBGONLY( UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, - "Exiting UpnpSubscribe \n" ); - ) + UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, + "Exiting UpnpSubscribe \n" ); - return RetVal; + return RetVal; } /****************** End of UpnpSubscribe *********************/ #endif // INCLUDE_CLIENT_APIS @@ -1926,27 +1897,25 @@ UpnpUnSubscribe( IN UpnpClient_Handle Hnd, return UPNP_E_FINISH; } - DBGONLY( UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, - "Inside UpnpUnSubscribe \n" ); - ) + UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, + "Inside UpnpUnSubscribe \n" ); - HandleLock( ); + HandleLock(); if( GetHandleInfo( Hnd, &SInfo ) != HND_CLIENT ) { - HandleUnlock( ); + HandleUnlock(); return UPNP_E_INVALID_HANDLE; } if( SubsId == NULL ) { - HandleUnlock( ); + HandleUnlock(); return UPNP_E_INVALID_PARAM; } - HandleUnlock( ); + HandleUnlock(); RetVal = genaUnSubscribe( Hnd, SubsId ); - DBGONLY( UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, - "Exiting UpnpUnSubscribe \n" ); - ) + UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, + "Exiting UpnpUnSubscribe \n" ); - return RetVal; + return RetVal; } /****************** End of UpnpUnSubscribe *********************/ #endif // INCLUDE_CLIENT_APIS @@ -1987,25 +1956,24 @@ UpnpUnSubscribeAsync( IN UpnpClient_Handle Hnd, return UPNP_E_FINISH; } - DBGONLY( UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, - "Inside UpnpUnSubscribeAsync \n" ); - ) + UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, + "Inside UpnpUnSubscribeAsync \n" ); - HandleLock( ); + HandleLock(); if( GetHandleInfo( Hnd, &SInfo ) != HND_CLIENT ) { - HandleUnlock( ); + HandleUnlock(); return UPNP_E_INVALID_HANDLE; } if( SubsId == NULL ) { - HandleUnlock( ); + HandleUnlock(); return UPNP_E_INVALID_PARAM; } if( Fun == NULL ) { - HandleUnlock( ); + HandleUnlock(); return UPNP_E_INVALID_PARAM; } - HandleUnlock( ); + HandleUnlock(); Param = ( struct UpnpNonblockParam * ) malloc( sizeof( struct UpnpNonblockParam ) ); @@ -2022,11 +1990,10 @@ UpnpUnSubscribeAsync( IN UpnpClient_Handle Hnd, TPJobSetPriority( &job, MED_PRIORITY ); ThreadPoolAdd( &gSendThreadPool, &job, NULL ); - DBGONLY( UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, - "Exiting UpnpUnSubscribeAsync \n" ); - ) + UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, + "Exiting UpnpUnSubscribeAsync \n" ); - return UPNP_E_SUCCESS; + return UPNP_E_SUCCESS; } /****************** End of UpnpUnSubscribeAsync *********************/ #endif // INCLUDE_CLIENT_APIS @@ -2063,31 +2030,29 @@ UpnpRenewSubscription( IN UpnpClient_Handle Hnd, return UPNP_E_FINISH; } - DBGONLY( UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, - "Inside UpnpRenewSubscription \n" ); - ) + UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, + "Inside UpnpRenewSubscription \n" ); - HandleLock( ); + HandleLock(); if( GetHandleInfo( Hnd, &SInfo ) != HND_CLIENT ) { - HandleUnlock( ); + HandleUnlock(); return UPNP_E_INVALID_HANDLE; } if( TimeOut == NULL ) { - HandleUnlock( ); + HandleUnlock(); return UPNP_E_INVALID_PARAM; } if( SubsId == NULL ) { - HandleUnlock( ); + HandleUnlock(); return UPNP_E_INVALID_PARAM; } - HandleUnlock( ); + HandleUnlock(); RetVal = genaRenewSubscription( Hnd, SubsId, TimeOut ); - DBGONLY( UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, - "Exiting UpnpRenewSubscription \n" ); - ) + UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, + "Exiting UpnpRenewSubscription \n" ); - return RetVal; + return RetVal; } /****************** End of UpnpRenewSubscription *********************/ #endif // INCLUDE_CLIENT_APIS @@ -2131,27 +2096,26 @@ UpnpRenewSubscriptionAsync( IN UpnpClient_Handle Hnd, return UPNP_E_FINISH; } - DBGONLY( UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, - "Inside UpnpRenewSubscriptionAsync \n" ); - ) - HandleLock( ); + UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, + "Inside UpnpRenewSubscriptionAsync \n" ); + HandleLock(); if( GetHandleInfo( Hnd, &SInfo ) != HND_CLIENT ) { - HandleUnlock( ); + HandleUnlock(); return UPNP_E_INVALID_HANDLE; } if( TimeOut != UPNP_INFINITE && TimeOut < 1 ) { - HandleUnlock( ); + HandleUnlock(); return UPNP_E_INVALID_PARAM; } if( SubsId == NULL ) { - HandleUnlock( ); + HandleUnlock(); return UPNP_E_INVALID_PARAM; } if( Fun == NULL ) { - HandleUnlock( ); + HandleUnlock(); return UPNP_E_INVALID_PARAM; } - HandleUnlock( ); + HandleUnlock(); Param = ( struct UpnpNonblockParam * ) @@ -2172,11 +2136,10 @@ UpnpRenewSubscriptionAsync( IN UpnpClient_Handle Hnd, TPJobSetPriority( &job, MED_PRIORITY ); ThreadPoolAdd( &gSendThreadPool, &job, NULL ); - DBGONLY( UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, - "Exiting UpnpRenewSubscriptionAsync \n" ); - ) + UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, + "Exiting UpnpRenewSubscriptionAsync \n" ); - return UPNP_E_SUCCESS; + return UPNP_E_SUCCESS; } /****************** End of UpnpRenewSubscriptionAsync *******************/ #endif // INCLUDE_CLIENT_APIS @@ -2227,37 +2190,35 @@ UpnpNotify( IN UpnpDevice_Handle Hnd, return UPNP_E_FINISH; } - DBGONLY( UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, - "Inside UpnpNotify \n" ); - ) + UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, + "Inside UpnpNotify \n" ); - HandleLock( ); + HandleLock(); if( GetHandleInfo( Hnd, &SInfo ) != HND_DEVICE ) { - HandleUnlock( ); + HandleUnlock(); return UPNP_E_INVALID_HANDLE; } if( DevID == NULL ) { - HandleUnlock( ); + HandleUnlock(); return UPNP_E_INVALID_PARAM; } if( ServName == NULL ) { - HandleUnlock( ); + HandleUnlock(); return UPNP_E_INVALID_PARAM; } if( VarName == NULL || NewVal == NULL || cVariables < 0 ) { - HandleUnlock( ); + HandleUnlock(); return UPNP_E_INVALID_PARAM; } - HandleUnlock( ); + HandleUnlock(); retVal = genaNotifyAll( Hnd, DevID, ServName, VarName, NewVal, cVariables ); - DBGONLY( UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, - "Exiting UpnpNotify \n" ); - ) + UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, + "Exiting UpnpNotify \n" ); - return retVal; + return retVal; } /****************** End of UpnpNotify *********************/ @@ -2300,32 +2261,30 @@ UpnpNotifyExt( IN UpnpDevice_Handle Hnd, return UPNP_E_FINISH; } - DBGONLY( UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, - "Inside UpnpNotify \n" ); - ) + UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, + "Inside UpnpNotify \n" ); - HandleLock( ); + HandleLock(); if( GetHandleInfo( Hnd, &SInfo ) != HND_DEVICE ) { - HandleUnlock( ); + HandleUnlock(); return UPNP_E_INVALID_HANDLE; } if( DevID == NULL ) { - HandleUnlock( ); + HandleUnlock(); return UPNP_E_INVALID_PARAM; } if( ServName == NULL ) { - HandleUnlock( ); + HandleUnlock(); return UPNP_E_INVALID_PARAM; } - HandleUnlock( ); + HandleUnlock(); retVal = genaNotifyAllExt( Hnd, DevID, ServName, PropSet ); - DBGONLY( UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, - "Exiting UpnpNotify \n" ); - ) + UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, + "Exiting UpnpNotify \n" ); - return retVal; + return retVal; } /****************** End of UpnpNotify *********************/ @@ -2379,41 +2338,39 @@ UpnpAcceptSubscription( IN UpnpDevice_Handle Hnd, return UPNP_E_FINISH; } - DBGONLY( UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, - "Inside UpnpAcceptSubscription \n" ); - ) + UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, + "Inside UpnpAcceptSubscription \n" ); - HandleLock( ); + HandleLock(); if( GetHandleInfo( Hnd, &SInfo ) != HND_DEVICE ) { - HandleUnlock( ); + HandleUnlock(); return UPNP_E_INVALID_HANDLE; } if( DevID == NULL ) { - HandleUnlock( ); + HandleUnlock(); return UPNP_E_INVALID_PARAM; } if( ServName == NULL ) { - HandleUnlock( ); + HandleUnlock(); return UPNP_E_INVALID_PARAM; } if( SubsId == NULL ) { - HandleUnlock( ); + HandleUnlock(); return UPNP_E_INVALID_PARAM; } if( VarName == NULL || NewVal == NULL || cVariables < 0 ) { - HandleUnlock( ); + HandleUnlock(); return UPNP_E_INVALID_PARAM; } - HandleUnlock( ); + HandleUnlock(); retVal = genaInitNotify( Hnd, DevID, ServName, VarName, NewVal, cVariables, SubsId ); - DBGONLY( UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, - "Exiting UpnpAcceptSubscription \n" ); - ) - return retVal; + UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, + "Exiting UpnpAcceptSubscription \n" ); + return retVal; } /***************** End of UpnpAcceptSubscription *********************/ @@ -2457,41 +2414,39 @@ UpnpAcceptSubscriptionExt( IN UpnpDevice_Handle Hnd, return UPNP_E_FINISH; } - DBGONLY( UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, - "Inside UpnpAcceptSubscription \n" ); - ) + UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, + "Inside UpnpAcceptSubscription \n" ); - HandleLock( ); + HandleLock(); if( GetHandleInfo( Hnd, &SInfo ) != HND_DEVICE ) { - HandleUnlock( ); + HandleUnlock(); return UPNP_E_INVALID_HANDLE; } if( DevID == NULL ) { - HandleUnlock( ); + HandleUnlock(); return UPNP_E_INVALID_PARAM; } if( ServName == NULL ) { - HandleUnlock( ); + HandleUnlock(); return UPNP_E_INVALID_PARAM; } if( SubsId == NULL ) { - HandleUnlock( ); + HandleUnlock(); return UPNP_E_INVALID_PARAM; } if( PropSet == NULL ) { - HandleUnlock( ); + HandleUnlock(); return UPNP_E_INVALID_PARAM; } - HandleUnlock( ); + HandleUnlock(); retVal = genaInitNotifyExt( Hnd, DevID, ServName, PropSet, SubsId ); - DBGONLY( UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, - "Exiting UpnpAcceptSubscription \n" ); - ) + UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, + "Exiting UpnpAcceptSubscription \n" ); - return retVal; + return retVal; } /****************** End of UpnpAcceptSubscription *********************/ @@ -2551,19 +2506,19 @@ UpnpSendAction( IN UpnpClient_Handle Hnd, return UPNP_E_FINISH; } - DBGONLY( UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, - "Inside UpnpSendAction \n" ); - ) - if(DevUDN_const !=NULL) - DBGONLY(UpnpPrintf(UPNP_ALL,API,__FILE__,__LINE__,"non NULL DevUDN is ignored\n");); + UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, + "Inside UpnpSendAction \n" ); + if(DevUDN_const !=NULL) { + UpnpPrintf(UPNP_ALL,API,__FILE__,__LINE__,"non NULL DevUDN is ignored\n"); + } DevUDN_const = NULL; - HandleLock( ); + HandleLock(); if( GetHandleInfo( Hnd, &SInfo ) != HND_CLIENT ) { - HandleUnlock( ); + HandleUnlock(); return UPNP_E_INVALID_HANDLE; } - HandleUnlock( ); + HandleUnlock(); if( ActionURL == NULL ) { return UPNP_E_INVALID_PARAM; @@ -2577,11 +2532,10 @@ UpnpSendAction( IN UpnpClient_Handle Hnd, retVal = SoapSendAction( ActionURL, ServiceType, Action, RespNodePtr ); - DBGONLY( UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, - "Exiting UpnpSendAction \n" ); - ) + UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, + "Exiting UpnpSendAction \n" ); - return retVal; + return retVal; } /****************** End of UpnpSendAction *********************/ @@ -2634,22 +2588,21 @@ UpnpSendActionEx( IN UpnpClient_Handle Hnd, return UPNP_E_FINISH; } - DBGONLY( UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, - "Inside UpnpSendActionEx \n" ); - ) + UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, + "Inside UpnpSendActionEx \n" ); - if( Header == NULL ) { + if( Header == NULL ) { retVal = UpnpSendAction( Hnd, ActionURL_const, ServiceType_const, DevUDN_const, Action, RespNodePtr ); return retVal; } - HandleLock( ); + HandleLock(); if( GetHandleInfo( Hnd, &SInfo ) != HND_CLIENT ) { - HandleUnlock( ); + HandleUnlock(); return UPNP_E_INVALID_HANDLE; } - HandleUnlock( ); + HandleUnlock(); if( ActionURL == NULL ) { return UPNP_E_INVALID_PARAM; @@ -2661,11 +2614,10 @@ UpnpSendActionEx( IN UpnpClient_Handle Hnd, retVal = SoapSendActionEx( ActionURL, ServiceType, Header, Action, RespNodePtr ); - DBGONLY( UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, - "Exiting UpnpSendAction \n" ); - ) + UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, + "Exiting UpnpSendAction \n" ); - return retVal; + return retVal; } /****************** End of UpnpSendActionEx *********************/ @@ -2718,16 +2670,15 @@ UpnpSendActionAsync( IN UpnpClient_Handle Hnd, return UPNP_E_FINISH; } - DBGONLY( UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, - "Inside UpnpSendActionAsync \n" ); - ) + UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, + "Inside UpnpSendActionAsync \n" ); - HandleLock( ); + HandleLock(); if( GetHandleInfo( Hnd, &SInfo ) != HND_CLIENT ) { - HandleUnlock( ); + HandleUnlock(); return UPNP_E_INVALID_HANDLE; } - HandleUnlock( ); + HandleUnlock(); if( ActionURL == NULL ) { return UPNP_E_INVALID_PARAM; @@ -2774,11 +2725,10 @@ UpnpSendActionAsync( IN UpnpClient_Handle Hnd, TPJobSetPriority( &job, MED_PRIORITY ); ThreadPoolAdd( &gSendThreadPool, &job, NULL ); - DBGONLY( UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, - "Exiting UpnpSendActionAsync \n" ); - ) + UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, + "Exiting UpnpSendActionAsync \n" ); - return UPNP_E_SUCCESS; + return UPNP_E_SUCCESS; } /****************** End of UpnpSendActionAsync *********************/ @@ -2833,23 +2783,22 @@ UpnpSendActionExAsync( IN UpnpClient_Handle Hnd, return UPNP_E_FINISH; } - DBGONLY( UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, - "Inside UpnpSendActionExAsync \n" ); - ) + UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, + "Inside UpnpSendActionExAsync \n" ); - if( Header == NULL ) { + if( Header == NULL ) { retVal = UpnpSendActionAsync( Hnd, ActionURL_const, ServiceType_const, DevUDN_const, Act, Fun, Cookie_const ); return retVal; } - HandleLock( ); + HandleLock(); if( GetHandleInfo( Hnd, &SInfo ) != HND_CLIENT ) { - HandleUnlock( ); + HandleUnlock(); return UPNP_E_INVALID_HANDLE; } - HandleUnlock( ); + HandleUnlock(); if( ActionURL == NULL ) { return UPNP_E_INVALID_PARAM; @@ -2912,11 +2861,10 @@ UpnpSendActionExAsync( IN UpnpClient_Handle Hnd, TPJobSetPriority( &job, MED_PRIORITY ); ThreadPoolAdd( &gSendThreadPool, &job, NULL ); - DBGONLY( UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, - "Exiting UpnpSendActionAsync \n" ); - ) + UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, + "Exiting UpnpSendActionAsync \n" ); - return UPNP_E_SUCCESS; + return UPNP_E_SUCCESS; } /****************** End of UpnpSendActionExAsync *********************/ @@ -2956,16 +2904,15 @@ UpnpGetServiceVarStatusAsync( IN UpnpClient_Handle Hnd, return UPNP_E_FINISH; } - DBGONLY( UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, - "Inside UpnpGetServiceVarStatusAsync \n" ); - ) + UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, + "Inside UpnpGetServiceVarStatusAsync \n" ); - HandleLock( ); + HandleLock(); if( GetHandleInfo( Hnd, &SInfo ) != HND_CLIENT ) { - HandleUnlock( ); + HandleUnlock(); return UPNP_E_INVALID_HANDLE; } - HandleUnlock( ); + HandleUnlock(); if( ActionURL == NULL ) { return UPNP_E_INVALID_PARAM; @@ -2994,11 +2941,10 @@ UpnpGetServiceVarStatusAsync( IN UpnpClient_Handle Hnd, ThreadPoolAdd( &gSendThreadPool, &job, NULL ); - DBGONLY( UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, - "Exiting UpnpGetServiceVarStatusAsync \n" ); - ) + UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, + "Exiting UpnpGetServiceVarStatusAsync \n" ); - return UPNP_E_SUCCESS; + return UPNP_E_SUCCESS; } /****************** End of UpnpGetServiceVarStatusAsync ****************/ @@ -3038,17 +2984,16 @@ UpnpGetServiceVarStatus( IN UpnpClient_Handle Hnd, return UPNP_E_FINISH; } - DBGONLY( UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, - "Inside UpnpGetServiceVarStatus \n" ); - ) + UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, + "Inside UpnpGetServiceVarStatus \n" ); - HandleLock( ); + HandleLock(); if( GetHandleInfo( Hnd, &SInfo ) != HND_CLIENT ) { - HandleUnlock( ); + HandleUnlock(); return UPNP_E_INVALID_HANDLE; } - HandleUnlock( ); + HandleUnlock(); if( ActionURL == NULL ) { return UPNP_E_INVALID_PARAM; @@ -3060,11 +3005,10 @@ UpnpGetServiceVarStatus( IN UpnpClient_Handle Hnd, retVal = SoapGetServiceVarStatus( ActionURL, VarName, &StVarPtr ); *StVar = StVarPtr; - DBGONLY( UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, - "Exiting UpnpGetServiceVarStatus \n" ); - ) + UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, + "Exiting UpnpGetServiceVarStatus \n" ); - return retVal; + return retVal; } /****************** End of UpnpGetServiceVarStatus *********************/ #endif // INCLUDE_CLIENT_APIS @@ -3339,16 +3283,13 @@ UpnpDownloadXmlDoc( const char *url, ret_code = UpnpDownloadUrlItem( url, &xml_buf, content_type ); if( ret_code != UPNP_E_SUCCESS ) { - DBGONLY( UpnpPrintf( UPNP_CRITICAL, API, __FILE__, __LINE__, - "retCode: %d\n", ret_code ); - ) - return ret_code; + UpnpPrintf( UPNP_CRITICAL, API, __FILE__, __LINE__, + "retCode: %d\n", ret_code ); + return ret_code; } if( strncasecmp( content_type, "text/xml", strlen( "text/xml" ) ) ) { - DBGONLY( - UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, "Not text/xml\n" ); - ) + UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, "Not text/xml\n" ); // Linksys WRT54G router returns // "CONTENT-TYPE: application/octet-stream". // Let's be nice to Linksys and try to parse document anyway. @@ -3364,16 +3305,16 @@ UpnpDownloadXmlDoc( const char *url, free( xml_buf ); if( ret_code != IXML_SUCCESS ) { - DBGONLY( UpnpPrintf( UPNP_CRITICAL, API, __FILE__, __LINE__, - "Invalid desc\n" ); - ) - if( ret_code == IXML_INSUFFICIENT_MEMORY ) { + UpnpPrintf( UPNP_CRITICAL, API, __FILE__, __LINE__, + "Invalid desc\n" ); + if( ret_code == IXML_INSUFFICIENT_MEMORY ) { return UPNP_E_OUTOF_MEMORY; } else { return UPNP_E_INVALID_DESC; } } else { - DBGONLY( xml_buf = ixmlPrintNode( ( IXML_Node * ) * xmlDoc ); +#ifdef DEBUG + xml_buf = ixmlPrintNode( ( IXML_Node * ) * xmlDoc ); UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, "Printing the Parsed xml document \n %s\n", xml_buf ); @@ -3381,7 +3322,8 @@ UpnpDownloadXmlDoc( const char *url, "****************** END OF Parsed XML Doc *****************\n" ); ixmlFreeDOMString( xml_buf ); UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, - "Exiting UpnpDownloadXmlDoc\n" ); ) + "Exiting UpnpDownloadXmlDoc\n" ); +#endif return UPNP_E_SUCCESS; } @@ -3410,11 +3352,10 @@ void UpnpThreadDistribution( struct UpnpNonblockParam *Param ) { - DBGONLY( UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, - "Inside UpnpThreadDistribution \n" ); - ) + UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, + "Inside UpnpThreadDistribution \n" ); - switch ( Param->FunName ) { + switch ( Param->FunName ) { #if EXCLUDE_GENA == 0 CLIENTONLY( case SUBSCRIBE: { @@ -3500,9 +3441,8 @@ free( Param ); break;} break; } // end of switch(Param->FunName) - DBGONLY( UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, - "Exiting UpnpThreadDistribution \n" ); - ) + UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, + "Exiting UpnpThreadDistribution \n" ); } /****************** End of UpnpThreadDistribution *********************/ #endif @@ -3537,7 +3477,7 @@ GetCallBackFn( UpnpClient_Handle Hnd ) * ***************************************************************************/ void -InitHandleList( ) +InitHandleList() { int i; @@ -3558,7 +3498,7 @@ InitHandleList( ) * ***************************************************************************/ int -GetFreeHandle( ) +GetFreeHandle() { int i = 1; @@ -3662,28 +3602,22 @@ GetHandleInfo( UpnpClient_Handle Hnd, struct Handle_Info ** HndInfo ) { - DBGONLY( UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, - "GetHandleInfo: Handle is %d\n", Hnd ); - ) + UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, + "GetHandleInfo: Handle is %d\n", Hnd ); - if( Hnd < 1 || Hnd >= NUM_HANDLE ) { - - DBGONLY( UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, - "GetHandleInfo : Handle out of range\n" ); - ) - return UPNP_E_INVALID_HANDLE; + if( Hnd < 1 || Hnd >= NUM_HANDLE ) { + UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, + "GetHandleInfo : Handle out of range\n" ); + return UPNP_E_INVALID_HANDLE; } if( HandleTable[Hnd] != NULL ) { - *HndInfo = ( struct Handle_Info * )HandleTable[Hnd]; return ( ( struct Handle_Info * )*HndInfo )->HType; } + UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, + "GetHandleInfo : exiting\n" ); - DBGONLY( UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, - "GetHandleInfo : exiting\n" ); - ) - - return UPNP_E_INVALID_HANDLE; + return UPNP_E_INVALID_HANDLE; } /****************** End of GetHandleInfo *********************/ @@ -3703,10 +3637,9 @@ int FreeHandle( int Upnp_Handle ) { if( Upnp_Handle < 1 || Upnp_Handle >= NUM_HANDLE ) { - DBGONLY( UpnpPrintf( UPNP_CRITICAL, API, __FILE__, __LINE__, - "FreeHandleInfo : Handle out of range\n" ); - ) - return UPNP_E_INVALID_HANDLE; + UpnpPrintf( UPNP_CRITICAL, API, __FILE__, __LINE__, + "FreeHandleInfo : Handle out of range\n" ); + return UPNP_E_INVALID_HANDLE; } if( HandleTable[Upnp_Handle] == NULL ) { @@ -3736,7 +3669,7 @@ int PrintHandleInfo( IN UpnpClient_Handle Hnd ) struct Handle_Info * HndInfo; if (HandleTable[Hnd] != NULL) { HndInfo = HandleTable[Hnd]; - DBGONLY( +#ifdef DEBUG UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__, "Printing information for Handle_%d\n", Hnd); UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__, @@ -3746,7 +3679,7 @@ int PrintHandleInfo( IN UpnpClient_Handle Hnd ) UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, "DescURL_%s\n", HndInfo->DescURL ); ) - ) +#endif } else { return UPNP_E_INVALID_HANDLE; } @@ -3775,12 +3708,10 @@ void printNodes( IXML_Node * tmpRoot, int depth ) NodeType = ixmlNode_getNodeType(ChildNode1); NodeValue = ixmlNode_getNodeValue(ChildNode1); NodeName = ixmlNode_getNodeName(ChildNode1); - DBGONLY( - 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); - ) + 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); } } @@ -3839,10 +3770,9 @@ void printNodes( IXML_Node * tmpRoot, int depth ) // Create an unbound datagram socket to do the SIOCGIFADDR ioctl on. if( ( LocalSock = socket( AF_INET, SOCK_DGRAM, IPPROTO_UDP ) ) < 0 ) { - DBGONLY( UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, - "Can't create addrlist socket\n" ); - ) - return UPNP_E_INIT; + UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, + "Can't create addrlist socket\n" ); + return UPNP_E_INIT; } // Get the interface configuration information... ifConf.ifc_len = sizeof szBuffer; @@ -3850,11 +3780,10 @@ void printNodes( IXML_Node * tmpRoot, int depth ) nResult = ioctl( LocalSock, SIOCGIFCONF, &ifConf ); if( nResult < 0 ) { - DBGONLY( UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, - "DiscoverInterfaces: SIOCGIFCONF returned error\n" ); - ) + UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, + "DiscoverInterfaces: SIOCGIFCONF returned error\n" ); - return UPNP_E_INIT; + return UPNP_E_INIT; } // Cycle through the list of interfaces looking for IP addresses. @@ -3866,11 +3795,9 @@ void printNodes( IXML_Node * tmpRoot, int depth ) // See if this is the sort of interface we want to deal with. strcpy( ifReq.ifr_name, pifReq->ifr_name ); if( ioctl( LocalSock, SIOCGIFFLAGS, &ifReq ) < 0 ) { - DBGONLY( UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, - "Can't get interface flags for %s:\n", - ifReq.ifr_name ); - ) - + UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, + "Can't get interface flags for %s:\n", + ifReq.ifr_name ); } // Skip loopback, point-to-point and down interfaces, // except don't skip down interfaces @@ -3899,11 +3826,10 @@ void printNodes( IXML_Node * tmpRoot, int depth ) strncpy( out, inet_ntoa( LocalAddr.sin_addr ), LINE_SIZE ); - DBGONLY( UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, - "Inside getlocalhostname : after strncpy %s\n", - out ); - ) - return UPNP_E_SUCCESS; + UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, + "Inside getlocalhostname : after strncpy %s\n", + out ); + return UPNP_E_SUCCESS; #endif } @@ -4128,7 +4054,7 @@ UpnpRemoveVirtualDir( IN const char *dirName ) * ***************************************************************************/ void -UpnpRemoveAllVirtualDirs( ) +UpnpRemoveAllVirtualDirs() { virtualDirList *pCur; @@ -4176,7 +4102,7 @@ UpnpEnableWebserver( IN int enable ) switch ( enable ) { #ifdef INTERNAL_WEB_SERVER case TRUE: - if( ( retVal = web_server_init( ) ) != UPNP_E_SUCCESS ) { + if( ( retVal = web_server_init() ) != UPNP_E_SUCCESS ) { return retVal; } bWebServerState = WEB_SERVER_ENABLED; @@ -4184,7 +4110,7 @@ UpnpEnableWebserver( IN int enable ) break; case FALSE: - web_server_destroy( ); + web_server_destroy(); bWebServerState = WEB_SERVER_DISABLED; SetHTTPGetCallback( NULL ); break; @@ -4209,7 +4135,7 @@ UpnpEnableWebserver( IN int enable ) * 0, if webserver disabled ***************************************************************************/ int -UpnpIsWebserverEnabled( ) +UpnpIsWebserverEnabled() { if( UpnpSdkInit != 1 ) { return 0; @@ -4300,7 +4226,7 @@ UpnpSetContentLength( IN UpnpClient_Handle Hnd, break; } - HandleLock( ); + HandleLock(); errCode = GetHandleInfo( Hnd, &HInfo ); @@ -4318,7 +4244,7 @@ UpnpSetContentLength( IN UpnpClient_Handle Hnd, } while( 0 ); - HandleUnlock( ); + HandleUnlock(); return errCode; } diff --git a/upnp/src/api/upnpdebug.c b/upnp/src/api/upnpdebug.c index 593c4d2..861314e 100644 --- a/upnp/src/api/upnpdebug.c +++ b/upnp/src/api/upnpdebug.c @@ -116,7 +116,7 @@ UpnpInitLog( ) /*************************************************************************** * Function : UpnpSetLogLevel * - * Parameters: void + * Parameters: Upnp_LogLevel log_level * * Description: * This functions set the log level (see {\tt Upnp_LogLevel} @@ -152,6 +152,42 @@ UpnpCloseLog( ) } +/*************************************************************************** + * Function : DebugAtThisLevel + * + * Parameters: + * IN Dbg_Level 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 + * + * Description: + * This functions returns true if debug output should be done in this + * module. + * + * Returns: int + ***************************************************************************/ +#ifdef DEBUG +int DebugAtThisLevel( + IN Upnp_LogLevel DLevel, + IN Dbg_Module Module) +{ + int ret = g_log_level >= DLevel; + ret &= + DEBUG_ALL || + (Module == SSDP && DEBUG_SSDP ) || + (Module == SOAP && DEBUG_SOAP ) || + (Module == GENA && DEBUG_GENA ) || + (Module == TPOOL && DEBUG_TPOOL) || + (Module == MSERV && DEBUG_MSERV) || + (Module == DOM && DEBUG_DOM ) || + (Module == HTTP && DEBUG_HTTP ); + + return ret; +} +#endif + + /*************************************************************************** * Function : UpnpPrintf * @@ -173,64 +209,46 @@ UpnpCloseLog( ) * statement is coming * Returns: void ***************************************************************************/ -DBGONLY( void UpnpPrintf( IN Upnp_LogLevel DLevel, - IN Dbg_Module Module, - IN const char *DbgFileName, - IN int DbgLineNo, - IN const char *FmtStr, - ... ) { - - va_list ArgList; - va_start( ArgList, FmtStr ); - if( g_log_level < DLevel ) return; if( DEBUG_ALL == 0 ) { - switch ( Module ) { -case SSDP: - if( DEBUG_SSDP == 1 ) break; - else -return; case SOAP: - if( DEBUG_SOAP == 1 ) break; - else -return; case GENA: - if( DEBUG_GENA == 1 ) break; - else -return; case TPOOL: - if( DEBUG_TPOOL == 1 ) break; - else -return; case MSERV: - if( DEBUG_MSERV == 1 ) break; - else -return; case DOM: - if( DEBUG_DOM == 1 ) break; - else -return; case HTTP: - if( DEBUG_HTTP == 1 ) break; - else -return; case API: - if( DEBUG_API == 1 ) break; - else -return; default: - return;} - } - - ithread_mutex_lock( &GlobalDebugMutex ); if( DEBUG_TARGET == 0 ) { - if( DbgFileName ) { - UpnpDisplayFileAndLine( stdout, DbgFileName, DbgLineNo );} - vfprintf( stdout, FmtStr, ArgList ); fflush( stdout );} - else - { - if( DLevel == 0 ) { - if( DbgFileName ) { - UpnpDisplayFileAndLine( ErrFileHnd, DbgFileName, DbgLineNo );} - vfprintf( ErrFileHnd, FmtStr, ArgList ); fflush( ErrFileHnd );} - else - { - if( DbgFileName ) { - UpnpDisplayFileAndLine( InfoFileHnd, DbgFileName, DbgLineNo );} - vfprintf( InfoFileHnd, FmtStr, ArgList ); fflush( InfoFileHnd );} - } - va_end( ArgList ); ithread_mutex_unlock( &GlobalDebugMutex );} - - ) +#ifdef DEBUG +void UpnpPrintf( + IN Upnp_LogLevel DLevel, + IN Dbg_Module Module, + IN const char *DbgFileName, + IN int DbgLineNo, + IN const char *FmtStr, + ... ) +{ + va_list ArgList; + + if (!DebugAtThisLevel(DLevel, Module)) { + return; + } + + ithread_mutex_lock(&GlobalDebugMutex); + va_start(ArgList, FmtStr); + if (!DEBUG_TARGET) { + if( DbgFileName ) { + UpnpDisplayFileAndLine(stdout, DbgFileName, DbgLineNo); + } + vfprintf(stdout, FmtStr, ArgList); + fflush(stdout); + } else if (DLevel == 0) { + if (DbgFileName) { + UpnpDisplayFileAndLine(ErrFileHnd, DbgFileName, DbgLineNo); + } + vfprintf(ErrFileHnd, FmtStr, ArgList); + fflush(ErrFileHnd); + } else { + if (DbgFileName) { + UpnpDisplayFileAndLine(InfoFileHnd, DbgFileName, DbgLineNo); + } + vfprintf(InfoFileHnd, FmtStr, ArgList); + fflush(InfoFileHnd); + } + va_end(ArgList); + ithread_mutex_unlock(&GlobalDebugMutex); +} +#endif /*************************************************************************** @@ -249,46 +267,26 @@ return; default: * NULL : if the module is turn off for debug * else returns the right file descriptor ***************************************************************************/ - DBGONLY( FILE * GetDebugFile( Upnp_LogLevel DLevel, Dbg_Module Module ) { - if( g_log_level < DLevel ) return NULL; if( DEBUG_ALL == 0 ) { - switch ( Module ) { -case SSDP: - if( DEBUG_SSDP == 1 ) break; - else -return NULL; case SOAP: - if( DEBUG_SOAP == 1 ) break; - else -return NULL; case GENA: - if( DEBUG_GENA == 1 ) break; - else -return NULL; case TPOOL: - if( DEBUG_TPOOL == 1 ) break; - else -return NULL; case MSERV: - if( DEBUG_MSERV == 1 ) break; - else -return NULL; case DOM: - if( DEBUG_DOM == 1 ) break; - else -return NULL; case API: - if( DEBUG_API == 1 ) break; - else -return NULL; default: - return NULL;} - } +#ifdef DEBUG +FILE *GetDebugFile( Upnp_LogLevel DLevel, Dbg_Module Module ) +{ + FILE *ret; - if( DEBUG_TARGET == 0 ) { - return stdout;} - else - { - if( DLevel == 0 ) { - return ErrFileHnd;} - else - { - return InfoFileHnd;} - } - } - ) + if (!DebugAtThisLevel(DLevel, Module)) { + ret = NULL; + } + + if (!DEBUG_TARGET) { + ret = stdout; + } else if (DLevel == 0) { + ret = ErrFileHnd; + } else { + ret = InfoFileHnd; + } + + return ret; +} +#endif /*************************************************************************** @@ -305,17 +303,26 @@ return NULL; default: * debug statement is coming to the log file * Returns: void ***************************************************************************/ - DBGONLY( void UpnpDisplayFileAndLine( IN FILE * fd, - IN const char *DbgFileName, - IN int DbgLineNo ) { - int starlength = 66; - const char *lines[2]; - char FileAndLine[500]; lines[0] = "DEBUG"; if( DbgFileName ) { - sprintf( FileAndLine, "FILE: %s, LINE: %d", DbgFileName, - DbgLineNo ); lines[1] = FileAndLine;} - - UpnpDisplayBanner( fd, lines, 2, starlength ); fflush( fd );} - ) +#ifdef DEBUG +void UpnpDisplayFileAndLine( + IN FILE * fd, + IN const char *DbgFileName, + IN int DbgLineNo) +{ + int starlength = 66; + const char *lines[2]; + char FileAndLine[500]; + lines[0] = "DEBUG"; + if (DbgFileName) { + sprintf(FileAndLine, + "FILE: %s, LINE: %d", + DbgFileName, DbgLineNo); + lines[1] = FileAndLine; + } + UpnpDisplayBanner(fd, lines, 2, starlength); + fflush(fd); +} +#endif /*************************************************************************** @@ -332,47 +339,58 @@ return NULL; default: * per the requested banner * Returns: void ***************************************************************************/ - DBGONLY( void UpnpDisplayBanner( IN FILE * fd, - IN const char **lines, - IN size_t size, - IN int starLength ) { - char *stars = ( char * )malloc( starLength + 1 ); - const char *line = NULL; - int leftMarginLength = starLength / 2 + 1; - int rightMarginLength = starLength / 2 + 1; - char *leftMargin = ( char * )malloc( leftMarginLength ); - char *rightMargin = ( char * )malloc( rightMarginLength ); - int i = 0; - int LineSize = 0; - char *currentLine = ( char * )malloc( starLength + 1 ); - memset( stars, '*', starLength ); - stars[starLength] = 0; - memset( leftMargin, 0, leftMarginLength ); - memset( rightMargin, 0, rightMarginLength ); - fprintf( fd, "\n%s\n", stars ); for( i = 0; i < size; i++ ) { - LineSize = strlen( lines[i] ); - line = lines[i]; while( LineSize > ( starLength - 2 ) ) { - memcpy( currentLine, line, ( starLength - 2 ) ); - currentLine[( starLength - 2 )] = 0; - fprintf( fd, "*%s*\n", currentLine ); - LineSize -= ( starLength - 2 ); line += ( starLength - 2 );} +#ifdef DEBUG +void UpnpDisplayBanner( + IN FILE * fd, + IN const char **lines, + IN size_t size, + IN int starLength) +{ + int leftMarginLength = starLength / 2 + 1; + int rightMarginLength = starLength / 2 + 1; + int i = 0; + int LineSize = 0; + int starLengthMinus2 = starLength - 2; - if( LineSize % 2 == 0 ) { - leftMarginLength = rightMarginLength = - ( ( starLength - 2 ) - LineSize ) / 2;} - else - { - leftMarginLength = ( ( starLength - 2 ) - LineSize ) / 2; - rightMarginLength = - ( ( starLength - 2 ) - LineSize ) / 2 + 1;} + char *leftMargin = ( char * )malloc( leftMarginLength ); + char *rightMargin = ( char * )malloc( rightMarginLength ); + char *stars = ( char * )malloc( starLength + 1 ); + char *currentLine = ( char * )malloc( starLength + 1 ); + const char *line = NULL; - memset( leftMargin, ' ', leftMarginLength ); - memset( rightMargin, ' ', rightMarginLength ); - leftMargin[leftMarginLength] = 0; - rightMargin[rightMarginLength] = 0; - fprintf( fd, "*%s%s%s*\n", leftMargin, line, rightMargin );} + memset( stars, '*', starLength ); + stars[starLength] = 0; + memset( leftMargin, 0, leftMarginLength ); + memset( rightMargin, 0, rightMarginLength ); + fprintf( fd, "\n%s\n", stars ); + for( i = 0; i < size; i++ ) { + LineSize = strlen( lines[i] ); + line = lines[i]; + while( LineSize > starLengthMinus2 ) { + memcpy( currentLine, line, starLengthMinus2 ); + currentLine[starLengthMinus2] = 0; + fprintf( fd, "*%s*\n", currentLine ); + LineSize -= starLengthMinus2; + line += starLengthMinus2; + } + leftMarginLength = (starLengthMinus2 - LineSize)/2; + if( LineSize % 2 == 0 ) { + rightMarginLength = leftMarginLength; + } else { + rightMarginLength = leftMarginLength + 1; + } + memset( leftMargin, ' ', leftMarginLength ); + memset( rightMargin, ' ', rightMarginLength ); + leftMargin[leftMarginLength] = 0; + rightMargin[rightMarginLength] = 0; + fprintf( fd, "*%s%s%s*\n", leftMargin, line, rightMargin ); + } + fprintf( fd, "%s\n\n", stars ); - fprintf( fd, "%s\n\n", stars ); - free( leftMargin ); - free( rightMargin ); free( stars ); free( currentLine );} - ) + free( currentLine ); + free( stars ); + free( rightMargin ); + free( leftMargin ); +} +#endif + diff --git a/upnp/src/gena/gena_callback2.c b/upnp/src/gena/gena_callback2.c index 4ecc152..4783476 100644 --- a/upnp/src/gena/gena_callback2.c +++ b/upnp/src/gena/gena_callback2.c @@ -104,9 +104,8 @@ genaCallback( IN http_parser_t * parser, // subscribe gena_process_subscription_request( info, request );} - DBGONLY( UpnpPrintf - ( UPNP_ALL, GENA, __FILE__, __LINE__, - "got subscription request\n" ); ) + UpnpPrintf( UPNP_ALL, GENA, __FILE__, __LINE__, + "got subscription request\n" ); ) } else diff --git a/upnp/src/gena/gena_ctrlpt.c b/upnp/src/gena/gena_ctrlpt.c index b949db3..6980cb6 100644 --- a/upnp/src/gena/gena_ctrlpt.c +++ b/upnp/src/gena/gena_ctrlpt.c @@ -72,14 +72,14 @@ GenaAutoRenewSubscription( IN void *input ) int eventType = 0; if( AUTO_RENEW_TIME == 0 ) { - DBGONLY( UpnpPrintf( UPNP_INFO, GENA, __FILE__, __LINE__, - "GENA SUB EXPIRED" ) ); + UpnpPrintf( UPNP_INFO, GENA, __FILE__, __LINE__, + "GENA SUB EXPIRED" ); sub_struct->ErrCode = UPNP_E_SUCCESS; send_callback = 1; eventType = UPNP_EVENT_SUBSCRIPTION_EXPIRED; } else { - DBGONLY( UpnpPrintf( UPNP_INFO, GENA, __FILE__, __LINE__, - "GENA AUTO RENEW" ) ); + UpnpPrintf( UPNP_INFO, GENA, __FILE__, __LINE__, + "GENA AUTO RENEW" ); if( ( ( sub_struct->ErrCode = genaRenewSubscription( event->handle, sub_struct-> Sid, @@ -93,17 +93,17 @@ GenaAutoRenewSubscription( IN void *input ) } } if( send_callback ) { - HandleLock( ); + HandleLock(); if( GetHandleInfo( event->handle, &handle_info ) != HND_CLIENT ) { - HandleUnlock( ); + HandleUnlock(); free_upnp_timeout( event ); return; } - DBGONLY( UpnpPrintf( UPNP_INFO, GENA, __FILE__, __LINE__, - "HANDLE IS VALID" ) ); + UpnpPrintf( UPNP_INFO, GENA, __FILE__, __LINE__, + "HANDLE IS VALID" ); callback_fun = handle_info->Callback; cookie = handle_info->Cookie; - HandleUnlock( ); + HandleUnlock(); //make callback callback_fun( eventType, event->Event, cookie ); @@ -397,9 +397,9 @@ genaUnregisterClient( IN UpnpClient_Handle client_handle ) http_parser_t response; while( TRUE ) { - HandleLock( ); + HandleLock(); if( GetHandleInfo( client_handle, &handle_info ) != HND_CLIENT ) { - HandleUnlock( ); + HandleUnlock(); return GENA_E_BAD_HANDLE; } @@ -417,7 +417,7 @@ genaUnregisterClient( IN UpnpClient_Handle client_handle ) RemoveClientSubClientSID( &handle_info->ClientSubList, sub_copy.sid ); - HandleUnlock( ); + HandleUnlock(); return_code = gena_unsubscribe( sub_copy.EventURL, sub_copy.ActualSID, &response ); @@ -429,7 +429,7 @@ genaUnregisterClient( IN UpnpClient_Handle client_handle ) } freeClientSubList( handle_info->ClientSubList ); - HandleUnlock( ); + HandleUnlock(); return return_code; } @@ -459,25 +459,25 @@ genaUnSubscribe( IN UpnpClient_Handle client_handle, client_subscription sub_copy; http_parser_t response; - HandleLock( ); + HandleLock(); // validate handle and sid if( GetHandleInfo( client_handle, &handle_info ) != HND_CLIENT ) { - HandleUnlock( ); + HandleUnlock(); return GENA_E_BAD_HANDLE; } if( ( sub = GetClientSubClientSID( handle_info->ClientSubList, in_sid ) ) == NULL ) { - HandleUnlock( ); + HandleUnlock(); return GENA_E_BAD_SID; } return_code = copy_client_subscription( sub, &sub_copy ); - HandleUnlock( ); + HandleUnlock(); return_code = gena_unsubscribe( sub_copy.EventURL, sub_copy.ActualSID, &response ); @@ -488,16 +488,16 @@ genaUnSubscribe( IN UpnpClient_Handle client_handle, free_client_subscription( &sub_copy ); - HandleLock( ); + HandleLock(); if( GetHandleInfo( client_handle, &handle_info ) != HND_CLIENT ) { - HandleUnlock( ); + HandleUnlock(); return GENA_E_BAD_HANDLE; } RemoveClientSubClientSID( &handle_info->ClientSubList, in_sid ); - HandleUnlock( ); + HandleUnlock(); return return_code; } @@ -538,28 +538,28 @@ genaSubscribe( IN UpnpClient_Handle client_handle, struct Handle_Info *handle_info; char *EventURL = NULL; - DBGONLY( UpnpPrintf( UPNP_INFO, GENA, __FILE__, __LINE__, - "GENA SUBSCRIBE BEGIN" ) ); - HandleLock( ); + UpnpPrintf( UPNP_INFO, GENA, __FILE__, __LINE__, + "GENA SUBSCRIBE BEGIN" ); + HandleLock(); memset( out_sid, 0, sizeof( Upnp_SID ) ); // validate handle if( GetHandleInfo( client_handle, &handle_info ) != HND_CLIENT ) { - HandleUnlock( ); + HandleUnlock(); return GENA_E_BAD_HANDLE; } - HandleUnlock( ); + HandleUnlock(); // subscribe - SubscribeLock( ); + SubscribeLock(); return_code = gena_subscribe( PublisherURL, TimeOut, NULL, &ActualSID ); - HandleLock( ); + HandleLock(); if( return_code != UPNP_E_SUCCESS ) { - DBGONLY( UpnpPrintf( UPNP_CRITICAL, GENA, __FILE__, __LINE__, - "SUBSCRIBE FAILED in transfer error code: %d returned\n", - return_code ) ); + UpnpPrintf( UPNP_CRITICAL, GENA, __FILE__, __LINE__, + "SUBSCRIBE FAILED in transfer error code: %d returned\n", + return_code ); goto error_handler; } @@ -605,8 +605,8 @@ genaSubscribe( IN UpnpClient_Handle client_handle, free( EventURL ); free( newSubscription ); } - HandleUnlock( ); - SubscribeUnlock( ); + HandleUnlock(); + SubscribeUnlock(); return return_code; } @@ -643,17 +643,17 @@ genaRenewSubscription( IN UpnpClient_Handle client_handle, char *ActualSID; ThreadPoolJob tempJob; - HandleLock( ); + HandleLock(); // validate handle and sid if( GetHandleInfo( client_handle, &handle_info ) != HND_CLIENT ) { - HandleUnlock( ); + HandleUnlock(); return GENA_E_BAD_HANDLE; } if( ( sub = GetClientSubClientSID( handle_info->ClientSubList, in_sid ) ) == NULL ) { - HandleUnlock( ); + HandleUnlock(); return GENA_E_BAD_SID; } // remove old events @@ -663,13 +663,13 @@ genaRenewSubscription( IN UpnpClient_Handle client_handle, free_upnp_timeout( ( upnp_timeout * ) tempJob.arg ); } - DBGONLY( UpnpPrintf( UPNP_INFO, GENA, __FILE__, __LINE__, - "REMOVED AUTO RENEW EVENT" ) ); + UpnpPrintf( UPNP_INFO, GENA, __FILE__, __LINE__, + "REMOVED AUTO RENEW EVENT" ); sub->RenewEventId = -1; return_code = copy_client_subscription( sub, &sub_copy ); - HandleUnlock( ); + HandleUnlock(); if( return_code != HTTP_SUCCESS ) { return return_code; @@ -677,10 +677,10 @@ genaRenewSubscription( IN UpnpClient_Handle client_handle, return_code = gena_subscribe( sub_copy.EventURL, TimeOut, sub_copy.ActualSID, &ActualSID ); - HandleLock( ); + HandleLock(); if( GetHandleInfo( client_handle, &handle_info ) != HND_CLIENT ) { - HandleUnlock( ); + HandleUnlock(); if( return_code == UPNP_E_SUCCESS ) { free( ActualSID ); } @@ -693,7 +693,7 @@ genaRenewSubscription( IN UpnpClient_Handle client_handle, // network failure (remove client sub) RemoveClientSubClientSID( &handle_info->ClientSubList, in_sid ); free_client_subscription( &sub_copy ); - HandleUnlock( ); + HandleUnlock(); return return_code; } // get subscription @@ -701,7 +701,7 @@ genaRenewSubscription( IN UpnpClient_Handle client_handle, in_sid ) ) == NULL ) { free( ActualSID ); free_client_subscription( &sub_copy ); - HandleUnlock( ); + HandleUnlock(); return GENA_E_BAD_SID; } // store actual sid @@ -714,7 +714,7 @@ genaRenewSubscription( IN UpnpClient_Handle client_handle, RemoveClientSubClientSID( &handle_info->ClientSubList, sub->sid ); } free_client_subscription( &sub_copy ); - HandleUnlock( ); + HandleUnlock(); return return_code; } @@ -795,12 +795,12 @@ gena_process_notification_event( IN SOCKINFO * info, return; } - HandleLock( ); + HandleLock(); // get client info if( GetClientHandleInfo( &client_handle, &handle_info ) != HND_CLIENT ) { error_respond( info, HTTP_PRECONDITION_FAILED, event ); - HandleUnlock( ); + HandleUnlock(); ixmlDocument_free( ChangedVars ); return; @@ -813,20 +813,20 @@ gena_process_notification_event( IN SOCKINFO * info, // (if we are in the middle) // this is to avoid mistakenly rejecting the first event if we // receive it before the subscription response - HandleUnlock( ); + HandleUnlock(); // try and get Subscription Lock // (in case we are in the process of subscribing) - SubscribeLock( ); + SubscribeLock(); // get HandleLock again - HandleLock( ); + HandleLock(); if( GetClientHandleInfo( &client_handle, &handle_info ) != HND_CLIENT ) { error_respond( info, HTTP_PRECONDITION_FAILED, event ); - SubscribeUnlock( ); - HandleUnlock( ); + SubscribeUnlock(); + HandleUnlock(); ixmlDocument_free( ChangedVars ); return; @@ -836,17 +836,17 @@ gena_process_notification_event( IN SOCKINFO * info, GetClientSubActualSID( handle_info->ClientSubList, &sid ) ) == NULL ) { error_respond( info, HTTP_PRECONDITION_FAILED, event ); - SubscribeUnlock( ); - HandleUnlock( ); + SubscribeUnlock(); + HandleUnlock(); ixmlDocument_free( ChangedVars ); return; } - SubscribeUnlock( ); + SubscribeUnlock(); } else { error_respond( info, HTTP_PRECONDITION_FAILED, event ); - HandleUnlock( ); + HandleUnlock(); ixmlDocument_free( ChangedVars ); return; @@ -864,7 +864,7 @@ gena_process_notification_event( IN SOCKINFO * info, callback = handle_info->Callback; cookie = handle_info->Cookie; - HandleUnlock( ); + HandleUnlock(); // make callback with event struct // In future, should find a way of mainting diff --git a/upnp/src/gena/gena_device.c b/upnp/src/gena/gena_device.c index 4e216be..76b1577 100644 --- a/upnp/src/gena/gena_device.c +++ b/upnp/src/gena/gena_device.c @@ -62,19 +62,19 @@ genaUnregisterDevice( IN UpnpDevice_Handle device_handle ) { struct Handle_Info *handle_info; - HandleLock( ); + HandleLock(); if( GetHandleInfo( device_handle, &handle_info ) != HND_DEVICE ) { - DBGONLY( UpnpPrintf( UPNP_CRITICAL, GENA, __FILE__, __LINE__, - "genaUnregisterDevice : BAD Handle : %d\n", - device_handle ) ); + UpnpPrintf( UPNP_CRITICAL, GENA, __FILE__, __LINE__, + "genaUnregisterDevice : BAD Handle : %d\n", + device_handle ); - HandleUnlock( ); + HandleUnlock(); return GENA_E_BAD_HANDLE; } freeServiceTable( &handle_info->ServiceTable ); - HandleUnlock( ); + HandleUnlock(); return UPNP_E_SUCCESS; } @@ -203,12 +203,12 @@ notify_send_and_recv( IN uri_type * destination_url, SOCKINFO info; // connect - DBGONLY( UpnpPrintf( UPNP_ALL, GENA, __FILE__, __LINE__, - "gena notify to: %.*s\n", - (int)destination_url->hostport.text.size, - destination_url->hostport.text.buff ); ) + UpnpPrintf( UPNP_ALL, GENA, __FILE__, __LINE__, + "gena notify to: %.*s\n", + (int)destination_url->hostport.text.size, + destination_url->hostport.text.buff ); - conn_fd = http_Connect( destination_url, &url ); + conn_fd = http_Connect( destination_url, &url ); if( conn_fd < 0 ) { return conn_fd; // return UPNP error } @@ -365,12 +365,12 @@ genaNotifyThread( IN void *input ) struct Handle_Info *handle_info; ThreadPoolJob job; - HandleLock( ); + HandleLock(); //validate context if( GetHandleInfo( in->device_handle, &handle_info ) != HND_DEVICE ) { free_notify_struct( in ); - HandleUnlock( ); + HandleUnlock(); return; } @@ -380,7 +380,7 @@ genaNotifyThread( IN void *input ) || ( ( sub = GetSubscriptionSID( in->sid, service ) ) == NULL ) || ( ( copy_subscription( sub, &sub_copy ) != HTTP_SUCCESS ) ) ) { free_notify_struct( in ); - HandleUnlock( ); + HandleUnlock(); return; } //If the event is out of order push it back to the job queue @@ -392,22 +392,22 @@ genaNotifyThread( IN void *input ) ThreadPoolAdd( &gSendThreadPool, &job, NULL ); freeSubscription( &sub_copy ); - HandleUnlock( ); + HandleUnlock(); return; } - HandleUnlock( ); + HandleUnlock(); //send the notify return_code = genaNotify( in->headers, in->propertySet, &sub_copy ); freeSubscription( &sub_copy ); - HandleLock( ); + HandleLock(); if( GetHandleInfo( in->device_handle, &handle_info ) != HND_DEVICE ) { free_notify_struct( in ); - HandleUnlock( ); + HandleUnlock(); return; } //validate context @@ -416,7 +416,7 @@ genaNotifyThread( IN void *input ) || ( !service->active ) || ( ( sub = GetSubscriptionSID( in->sid, service ) ) == NULL ) ) { free_notify_struct( in ); - HandleUnlock( ); + HandleUnlock(); return; } @@ -430,7 +430,7 @@ genaNotifyThread( IN void *input ) } free_notify_struct( in ); - HandleUnlock( ); + HandleUnlock(); } /**************************************************************************** @@ -477,8 +477,8 @@ genaInitNotify( IN UpnpDevice_Handle device_handle, notify_thread_struct *thread_struct = NULL; - DBGONLY( UpnpPrintf( UPNP_INFO, GENA, __FILE__, __LINE__, - "GENA BEGIN INITIAL NOTIFY " ) ); + UpnpPrintf( UPNP_INFO, GENA, __FILE__, __LINE__, + "GENA BEGIN INITIAL NOTIFY " ); reference_count = ( int * )malloc( sizeof( int ) ); @@ -504,13 +504,13 @@ genaInitNotify( IN UpnpDevice_Handle device_handle, strcpy( UDN_copy, UDN ); strcpy( servId_copy, servId ); - HandleLock( ); + HandleLock(); if( GetHandleInfo( device_handle, &handle_info ) != HND_DEVICE ) { free( UDN_copy ); free( reference_count ); free( servId_copy ); - HandleUnlock( ); + HandleUnlock(); return GENA_E_BAD_HANDLE; } @@ -519,26 +519,25 @@ genaInitNotify( IN UpnpDevice_Handle device_handle, free( UDN_copy ); free( reference_count ); free( servId_copy ); - HandleUnlock( ); + HandleUnlock(); return GENA_E_BAD_SERVICE; } - DBGONLY( UpnpPrintf( UPNP_INFO, GENA, __FILE__, __LINE__, - "FOUND SERVICE IN INIT NOTFY: UDN %s, ServID: %s ", - UDN, servId ) ); + UpnpPrintf( UPNP_INFO, GENA, __FILE__, __LINE__, + "FOUND SERVICE IN INIT NOTFY: UDN %s, ServID: %s ", + UDN, servId ); if( ( ( sub = GetSubscriptionSID( sid, service ) ) == NULL ) || ( sub->active ) ) { free( UDN_copy ); free( reference_count ); free( servId_copy ); - HandleUnlock( ); + HandleUnlock(); return GENA_E_BAD_SID; } - DBGONLY( UpnpPrintf( UPNP_INFO, GENA, __FILE__, __LINE__, - "FOUND SUBSCRIPTION IN INIT NOTIFY: SID %s ", - sid ) ); + UpnpPrintf( UPNP_INFO, GENA, __FILE__, __LINE__, + "FOUND SUBSCRIPTION IN INIT NOTIFY: SID %s ", sid ); sub->active = 1; @@ -549,13 +548,13 @@ genaInitNotify( IN UpnpDevice_Handle device_handle, free( UDN_copy ); free( reference_count ); free( servId_copy ); - HandleUnlock( ); + HandleUnlock(); return return_code; } - DBGONLY( UpnpPrintf( UPNP_INFO, GENA, __FILE__, __LINE__, - "GENERATED PROPERY SET IN INIT NOTIFY: \n'%s'\n", - propertySet ) ); + UpnpPrintf( UPNP_INFO, GENA, __FILE__, __LINE__, + "GENERATED PROPERY SET IN INIT NOTIFY: \n'%s'\n", + propertySet ); headers_size = strlen( "CONTENT-TYPE text/xml\r\n" ) + strlen( "CONTENT-LENGTH: \r\n" ) + MAX_CONTENT_LENGTH + @@ -569,7 +568,7 @@ genaInitNotify( IN UpnpDevice_Handle device_handle, free( UDN_copy ); free( servId_copy ); free( reference_count ); - HandleUnlock( ); + HandleUnlock(); return UPNP_E_OUTOF_MEMORY; } @@ -621,7 +620,7 @@ genaInitNotify( IN UpnpDevice_Handle device_handle, free( headers ); } - HandleUnlock( ); + HandleUnlock(); return return_code; } @@ -668,8 +667,8 @@ genaInitNotifyExt( IN UpnpDevice_Handle device_handle, notify_thread_struct *thread_struct = NULL; - DBGONLY( UpnpPrintf( UPNP_INFO, GENA, __FILE__, __LINE__, - "GENA BEGIN INITIAL NOTIFY EXT" ) ); + UpnpPrintf( UPNP_INFO, GENA, __FILE__, __LINE__, + "GENA BEGIN INITIAL NOTIFY EXT" ); reference_count = ( int * )malloc( sizeof( int ) ); if( reference_count == NULL ) { @@ -694,13 +693,13 @@ genaInitNotifyExt( IN UpnpDevice_Handle device_handle, strcpy( UDN_copy, UDN ); strcpy( servId_copy, servId ); - HandleLock( ); + HandleLock(); if( GetHandleInfo( device_handle, &handle_info ) != HND_DEVICE ) { free( UDN_copy ); free( reference_count ); free( servId_copy ); - HandleUnlock( ); + HandleUnlock(); return GENA_E_BAD_HANDLE; } @@ -709,24 +708,23 @@ genaInitNotifyExt( IN UpnpDevice_Handle device_handle, free( UDN_copy ); free( reference_count ); free( servId_copy ); - HandleUnlock( ); + HandleUnlock(); return GENA_E_BAD_SERVICE; } - DBGONLY( UpnpPrintf( UPNP_INFO, GENA, __FILE__, __LINE__, - "FOUND SERVICE IN INIT NOTFY EXT: UDN %s, ServID: %s\n", - UDN, servId ) ); + UpnpPrintf( UPNP_INFO, GENA, __FILE__, __LINE__, + "FOUND SERVICE IN INIT NOTFY EXT: UDN %s, ServID: %s\n", + UDN, servId ); if( ( ( sub = GetSubscriptionSID( sid, service ) ) == NULL ) || ( sub->active ) ) { free( UDN_copy ); free( reference_count ); free( servId_copy ); - HandleUnlock( ); + HandleUnlock(); return GENA_E_BAD_SID; } - DBGONLY( UpnpPrintf( UPNP_INFO, GENA, __FILE__, __LINE__, - "FOUND SUBSCRIPTION IN INIT NOTIFY EXT: SID %s", - sid ) ); + UpnpPrintf( UPNP_INFO, GENA, __FILE__, __LINE__, + "FOUND SUBSCRIPTION IN INIT NOTIFY EXT: SID %s", sid ); sub->active = 1; @@ -735,13 +733,13 @@ genaInitNotifyExt( IN UpnpDevice_Handle device_handle, free( UDN_copy ); free( reference_count ); free( servId_copy ); - HandleUnlock( ); + HandleUnlock(); return UPNP_E_INVALID_PARAM; } - DBGONLY( UpnpPrintf( UPNP_INFO, GENA, __FILE__, __LINE__, - "GENERATED PROPERY SET IN INIT EXT NOTIFY: %s", - propertySet ) ); + UpnpPrintf( UPNP_INFO, GENA, __FILE__, __LINE__, + "GENERATED PROPERY SET IN INIT EXT NOTIFY: %s", + propertySet ); headers_size = strlen( "CONTENT-TYPE text/xml\r\n" ) + strlen( "CONTENT-LENGTH: \r\n" ) + MAX_CONTENT_LENGTH + @@ -754,7 +752,7 @@ genaInitNotifyExt( IN UpnpDevice_Handle device_handle, free( servId_copy ); free( reference_count ); ixmlFreeDOMString( propertySet ); - HandleUnlock( ); + HandleUnlock(); return UPNP_E_OUTOF_MEMORY; } @@ -804,7 +802,7 @@ genaInitNotifyExt( IN UpnpDevice_Handle device_handle, free( thread_struct ); free( headers ); } - HandleUnlock( ); + HandleUnlock(); return return_code; } @@ -899,7 +897,7 @@ genaNotifyAllExt( IN UpnpDevice_Handle device_handle, "%ld\r\nNT: upnp:event\r\nNTS: upnp:propchange\r\n", (long) strlen( propertySet ) + 1 ); - HandleLock( ); + HandleLock(); if( GetHandleInfo( device_handle, &handle_info ) != HND_DEVICE ) return_code = GENA_E_BAD_HANDLE; @@ -959,7 +957,7 @@ genaNotifyAllExt( IN UpnpDevice_Handle device_handle, free( servId_copy ); } - HandleUnlock( ); + HandleUnlock(); return return_code; } @@ -1061,7 +1059,7 @@ genaNotifyAll( IN UpnpDevice_Handle device_handle, " upnp:event\r\nNTS: upnp:propchange\r\n", (long) strlen( propertySet ) + 1 ); - HandleLock( ); + HandleLock(); if( GetHandleInfo( device_handle, &handle_info ) != HND_DEVICE ) { return_code = GENA_E_BAD_HANDLE; @@ -1123,7 +1121,7 @@ genaNotifyAll( IN UpnpDevice_Handle device_handle, free( UDN_copy ); free( servId_copy ); } - HandleUnlock( ); + HandleUnlock(); return return_code; } @@ -1317,8 +1315,8 @@ gena_process_subscription_request( IN SOCKINFO * info, memptr callback_hdr; memptr timeout_hdr; - DBGONLY( UpnpPrintf( UPNP_INFO, GENA, __FILE__, __LINE__, - "Subscription Request Received:\n" ) ); + UpnpPrintf( UPNP_INFO, GENA, __FILE__, __LINE__, + "Subscription Request Received:\n" ); if( httpmsg_find_hdr( request, HDR_NT, &nt_hdr ) == NULL ) { error_respond( info, HTTP_BAD_REQUEST, request ); @@ -1347,18 +1345,17 @@ gena_process_subscription_request( IN SOCKINFO * info, return; } - DBGONLY( UpnpPrintf( UPNP_INFO, GENA, __FILE__, __LINE__, - "SubscriptionRequest for event URL path: %s\n", - event_url_path ); - ) + UpnpPrintf( UPNP_INFO, GENA, __FILE__, __LINE__, + "SubscriptionRequest for event URL path: %s\n", + event_url_path ); - HandleLock( ); + HandleLock(); // CURRENTLY, ONLY ONE DEVICE if( GetDeviceHandleInfo( &device_handle, &handle_info ) != HND_DEVICE ) { free( event_url_path ); error_respond( info, HTTP_INTERNAL_SERVER_ERROR, request ); - HandleUnlock( ); + HandleUnlock(); return; } service = FindServiceEventURLPath( &handle_info->ServiceTable, @@ -1367,28 +1364,28 @@ gena_process_subscription_request( IN SOCKINFO * info, if( service == NULL || !service->active ) { error_respond( info, HTTP_NOT_FOUND, request ); - HandleUnlock( ); + HandleUnlock(); return; } - DBGONLY( UpnpPrintf( UPNP_INFO, GENA, __FILE__, __LINE__, - "Subscription Request: Number of Subscriptions already %d\n " - "Max Subscriptions allowed: %d\n", - service->TotalSubscriptions, - handle_info->MaxSubscriptions ) ); + UpnpPrintf( UPNP_INFO, GENA, __FILE__, __LINE__, + "Subscription Request: Number of Subscriptions already %d\n " + "Max Subscriptions allowed: %d\n", + service->TotalSubscriptions, + handle_info->MaxSubscriptions ); // too many subscriptions if( handle_info->MaxSubscriptions != -1 && service->TotalSubscriptions >= handle_info->MaxSubscriptions ) { error_respond( info, HTTP_INTERNAL_SERVER_ERROR, request ); - HandleUnlock( ); + HandleUnlock(); return; } // generate new subscription sub = ( subscription * ) malloc( sizeof( subscription ) ); if( sub == NULL ) { error_respond( info, HTTP_INTERNAL_SERVER_ERROR, request ); - HandleUnlock( ); + HandleUnlock(); return; } sub->eventKey = 0; @@ -1405,13 +1402,13 @@ gena_process_subscription_request( IN SOCKINFO * info, &sub->DeliveryURLs ) ) == 0 ) { error_respond( info, HTTP_PRECONDITION_FAILED, request ); freeSubscriptionList( sub ); - HandleUnlock( ); + HandleUnlock(); return; } if( return_code == UPNP_E_OUTOF_MEMORY ) { error_respond( info, HTTP_INTERNAL_SERVER_ERROR, request ); freeSubscriptionList( sub ); - HandleUnlock( ); + HandleUnlock(); return; } // set the timeout @@ -1447,7 +1444,7 @@ gena_process_subscription_request( IN SOCKINFO * info, // respond OK if( respond_ok( info, time_out, sub, request ) != UPNP_E_SUCCESS ) { freeSubscriptionList( sub ); - HandleUnlock( ); + HandleUnlock(); return; } //add to subscription list @@ -1464,7 +1461,7 @@ gena_process_subscription_request( IN SOCKINFO * info, callback_fun = handle_info->Callback; cookie = handle_info->Cookie; - HandleUnlock( ); + HandleUnlock(); //make call back with request struct //in the future should find a way of mainting @@ -1527,7 +1524,7 @@ gena_process_subscription_renewal_request( IN SOCKINFO * info, return; } - HandleLock( ); + HandleLock(); // CURRENTLY, ONLY SUPPORT ONE DEVICE if( GetDeviceHandleInfo( &device_handle, &handle_info ) != HND_DEVICE ) { @@ -1544,22 +1541,21 @@ gena_process_subscription_renewal_request( IN SOCKINFO * info, !service->active || ( ( sub = GetSubscriptionSID( sid, service ) ) == NULL ) ) { error_respond( info, HTTP_PRECONDITION_FAILED, request ); - HandleUnlock( ); + HandleUnlock(); return; } - DBGONLY( UpnpPrintf( UPNP_INFO, GENA, __FILE__, __LINE__, - "Renew request: Number of subscriptions already: %d\n " - "Max Subscriptions allowed:%d\n", - service->TotalSubscriptions, - handle_info->MaxSubscriptions ); - ) - // too many subscriptions - if( handle_info->MaxSubscriptions != -1 && + UpnpPrintf( UPNP_INFO, GENA, __FILE__, __LINE__, + "Renew request: Number of subscriptions already: %d\n " + "Max Subscriptions allowed:%d\n", + service->TotalSubscriptions, + handle_info->MaxSubscriptions ); + // too many subscriptions + if( handle_info->MaxSubscriptions != -1 && service->TotalSubscriptions > handle_info->MaxSubscriptions ) { error_respond( info, HTTP_INTERNAL_SERVER_ERROR, request ); RemoveSubscriptionSID( sub->sid, service ); - HandleUnlock( ); + HandleUnlock(); return; } // set the timeout @@ -1598,7 +1594,7 @@ gena_process_subscription_renewal_request( IN SOCKINFO * info, RemoveSubscriptionSID( sub->sid, service ); } - HandleUnlock( ); + HandleUnlock(); } /**************************************************************************** @@ -1651,13 +1647,13 @@ gena_process_unsubscribe_request( IN SOCKINFO * info, return; } - HandleLock( ); + HandleLock(); // CURRENTLY, ONLY SUPPORT ONE DEVICE if( GetDeviceHandleInfo( &device_handle, &handle_info ) != HND_DEVICE ) { error_respond( info, HTTP_PRECONDITION_FAILED, request ); membuffer_destroy( &event_url_path ); - HandleUnlock( ); + HandleUnlock(); return; } service = FindServiceEventURLPath( &handle_info->ServiceTable, @@ -1670,14 +1666,14 @@ gena_process_unsubscribe_request( IN SOCKINFO * info, //CheckSubscriptionSID(sid, service) == NULL ) { error_respond( info, HTTP_PRECONDITION_FAILED, request ); - HandleUnlock( ); + HandleUnlock(); return; } RemoveSubscriptionSID( sid, service ); error_respond( info, HTTP_OK, request ); // success - HandleUnlock( ); + HandleUnlock(); } #endif // INCLUDE_DEVICE_APIS diff --git a/upnp/src/genlib/miniserver/miniserver.c b/upnp/src/genlib/miniserver/miniserver.c index 433a85b..3561894 100644 --- a/upnp/src/genlib/miniserver/miniserver.c +++ b/upnp/src/genlib/miniserver/miniserver.c @@ -174,11 +174,9 @@ dispatch_request( IN SOCKINFO * info, case HTTPMETHOD_NOTIFY: case HTTPMETHOD_SUBSCRIBE: case HTTPMETHOD_UNSUBSCRIBE: - DBGONLY( UpnpPrintf - ( UPNP_INFO, MSERV, __FILE__, __LINE__, - "miniserver %d: got GENA msg\n", info->socket ); - ) - callback = gGenaCallback; + UpnpPrintf( UPNP_INFO, MSERV, __FILE__, __LINE__, + "miniserver %d: got GENA msg\n", info->socket ); + callback = gGenaCallback; break; //HTTP server call @@ -275,12 +273,10 @@ handle_request( void *args ) struct mserv_request_t *request = ( struct mserv_request_t * )args; int connfd = request->connfd; - DBGONLY( UpnpPrintf - ( UPNP_INFO, MSERV, __FILE__, __LINE__, - "miniserver %d: READING\n", connfd ); - ) - //parser_request_init( &parser ); ////LEAK_FIX_MK - hmsg = &parser.msg; + UpnpPrintf( UPNP_INFO, MSERV, __FILE__, __LINE__, + "miniserver %d: READING\n", connfd ); + //parser_request_init( &parser ); ////LEAK_FIX_MK + hmsg = &parser.msg; if( sock_init_with_ip( &info, connfd, request->foreign_ip_addr, request->foreign_ip_port ) != UPNP_E_SUCCESS ) { @@ -295,12 +291,10 @@ handle_request( void *args ) goto error_handler; } - DBGONLY( UpnpPrintf - ( UPNP_INFO, MSERV, __FILE__, __LINE__, - "miniserver %d: PROCESSING...\n", connfd ); - ) - // dispatch - http_error_code = dispatch_request( &info, &parser ); + UpnpPrintf( UPNP_INFO, MSERV, __FILE__, __LINE__, + "miniserver %d: PROCESSING...\n", connfd ); + // dispatch + http_error_code = dispatch_request( &info, &parser ); if( http_error_code != 0 ) { goto error_handler; } @@ -316,11 +310,9 @@ handle_request( void *args ) handle_error( &info, http_error_code, major, minor ); } - DBGONLY( UpnpPrintf - ( UPNP_INFO, MSERV, __FILE__, __LINE__, - "miniserver %d: COMPLETE\n", connfd ); - ) - sock_destroy( &info, SD_BOTH ); //should shutdown completely + UpnpPrintf( UPNP_INFO, MSERV, __FILE__, __LINE__, + "miniserver %d: COMPLETE\n", connfd ); + sock_destroy( &info, SD_BOTH ); //should shutdown completely httpmsg_destroy( hmsg ); free( request ); @@ -352,11 +344,9 @@ schedule_request_job( IN int connfd, ( struct mserv_request_t * ) malloc( sizeof( struct mserv_request_t ) ); if( request == NULL ) { - DBGONLY( UpnpPrintf - ( UPNP_INFO, MSERV, __FILE__, __LINE__, - "mserv %d: out of memory\n", connfd ); - ) - shutdown( request->connfd, SD_BOTH ); + UpnpPrintf( UPNP_INFO, MSERV, __FILE__, __LINE__, + "mserv %d: out of memory\n", connfd ); + shutdown( request->connfd, SD_BOTH ); UpnpCloseSocket( connfd ); return; } @@ -370,10 +360,8 @@ schedule_request_job( IN int connfd, TPJobSetPriority( &job, MED_PRIORITY ); if( ThreadPoolAdd( &gRecvThreadPool, &job, NULL ) != 0 ) { - DBGONLY( UpnpPrintf - ( UPNP_INFO, MSERV, __FILE__, __LINE__, - "mserv %d: cannot schedule request\n", connfd ); - ) + UpnpPrintf( UPNP_INFO, MSERV, __FILE__, __LINE__, + "mserv %d: cannot schedule request\n", connfd ); free( request ); shutdown( connfd, SD_BOTH ); UpnpCloseSocket( connfd ); @@ -446,11 +434,9 @@ RunMiniServer( MiniServerSockArray * miniSock ) if( select( maxMiniSock, &rdSet, NULL, &expSet, NULL ) == UPNP_SOCKETERROR ) { - DBGONLY( UpnpPrintf - ( UPNP_CRITICAL, SSDP, __FILE__, __LINE__, - "Error in select call !!!\n" ); - ) - continue; + UpnpPrintf( UPNP_CRITICAL, SSDP, __FILE__, __LINE__, + "Error in select call !!!\n" ); + continue; } else { if( FD_ISSET( miniServSock, &rdSet ) ) { @@ -459,12 +445,10 @@ RunMiniServer( MiniServerSockArray * miniSock ) ( struct sockaddr * )&clientAddr, &clientLen ); if( connectHnd == UPNP_INVALID_SOCKET ) { - DBGONLY( UpnpPrintf - ( UPNP_INFO, MSERV, __FILE__, __LINE__, - "miniserver: Error" - " in accepting connection\n" ); - ) - continue; + UpnpPrintf( UPNP_INFO, MSERV, __FILE__, __LINE__, + "miniserver: Error" + " in accepting connection\n" ); + continue; } schedule_request_job( connectHnd, &clientAddr ); } @@ -489,24 +473,19 @@ RunMiniServer( MiniServerSockArray * miniSock ) &clientLen ); if( byteReceived > 0 ) { requestBuf[byteReceived] = '\0'; - DBGONLY( UpnpPrintf - ( UPNP_INFO, MSERV, __FILE__, __LINE__, - "Received response !!! %s From host %s \n", - requestBuf, - inet_ntoa( clientAddr.sin_addr ) ); - ) - DBGONLY( UpnpPrintf - ( UPNP_PACKET, MSERV, __FILE__, __LINE__, - "Received multicast packet: \n %s\n", - requestBuf ); - ) + UpnpPrintf( UPNP_INFO, MSERV, __FILE__, __LINE__, + "Received response !!! %s From host %s \n", + requestBuf, inet_ntoa( clientAddr.sin_addr ) ); + UpnpPrintf( UPNP_PACKET, MSERV, __FILE__, __LINE__, + "Received multicast packet: \n %s\n", + requestBuf ); - if( NULL != strstr( requestBuf, "ShutDown" ) ) + if( NULL != strstr( requestBuf, "ShutDown" ) ) { break; + } } } } - } shutdown( miniServSock, SD_BOTH ); @@ -555,12 +534,10 @@ get_port( int sockfd ) } port = ntohs( sockinfo.sin_port ); - DBGONLY( UpnpPrintf - ( UPNP_INFO, MSERV, __FILE__, __LINE__, - "sockfd = %d, .... port = %d\n", sockfd, port ); - ) + UpnpPrintf( UPNP_INFO, MSERV, __FILE__, __LINE__, + "sockfd = %d, .... port = %d\n", sockfd, port ); - return port; + return port; } /************************************************************************ @@ -623,16 +600,10 @@ get_miniserver_sockets( MiniServerSockArray * out, //THIS MAY CAUSE TCP TO BECOME LESS RELIABLE //HOWEVER IT HAS BEEN SUGESTED FOR TCP SERVERS - DBGONLY( UpnpPrintf( UPNP_INFO, MSERV, __FILE__, __LINE__, - "mserv start: resuseaddr set\n" ); - ) - - sockError = setsockopt( listenfd, - SOL_SOCKET, - SO_REUSEADDR, - ( const char * )&reuseaddr_on, - sizeof( int ) - ); + UpnpPrintf( UPNP_INFO, MSERV, __FILE__, __LINE__, + "mserv start: resuseaddr set\n" ); + sockError = setsockopt( listenfd, SOL_SOCKET, SO_REUSEADDR, + ( const char * )&reuseaddr_on, sizeof( int )); if( sockError == UPNP_SOCKETERROR ) { shutdown( listenfd, SD_BOTH ); UpnpCloseSocket( listenfd ); @@ -652,9 +623,9 @@ get_miniserver_sockets( MiniServerSockArray * out, ); if( sockError == UPNP_SOCKETERROR ) { #ifdef WIN32 - errCode = WSAGetLastError(); + errCode = WSAGetLastError(); #else - errCode = errno; + errCode = errno; #endif if( errno == EADDRINUSE ) errCode = 1; @@ -665,18 +636,16 @@ get_miniserver_sockets( MiniServerSockArray * out, } if( sockError == UPNP_SOCKETERROR ) { - DBGONLY( perror( "mserv start: bind failed" ); - ) - shutdown( listenfd, SD_BOTH ); + perror( "mserv start: bind failed" ); + shutdown( listenfd, SD_BOTH ); UpnpCloseSocket( listenfd ); return UPNP_E_SOCKET_BIND; // bind failed } - DBGONLY( UpnpPrintf( UPNP_INFO, MSERV, __FILE__, __LINE__, - "mserv start: bind success\n" ); - ) + UpnpPrintf( UPNP_INFO, MSERV, __FILE__, __LINE__, + "mserv start: bind success\n" ); - success = listen( listenfd, SOMAXCONN ); + success = listen( listenfd, SOMAXCONN ); if( success == UPNP_SOCKETERROR ) { shutdown( listenfd, SD_BOTH ); UpnpCloseSocket( listenfd ); @@ -694,11 +663,10 @@ get_miniserver_sockets( MiniServerSockArray * out, if( ( miniServerStopSock = socket( AF_INET, SOCK_DGRAM, 0 ) ) == UPNP_INVALID_SOCKET ) { - DBGONLY( UpnpPrintf( UPNP_CRITICAL, - MSERV, __FILE__, __LINE__, - "Error in socket operation !!!\n" ); - ) - shutdown( listenfd, SD_BOTH ); + UpnpPrintf( UPNP_CRITICAL, + MSERV, __FILE__, __LINE__, + "Error in socket operation !!!\n" ); + shutdown( listenfd, SD_BOTH ); UpnpCloseSocket( listenfd ); return UPNP_E_OUTOF_SOCKET; } @@ -711,11 +679,10 @@ get_miniserver_sockets( MiniServerSockArray * out, if( bind( miniServerStopSock, ( struct sockaddr * )&serverAddr, sizeof( serverAddr ) ) == UPNP_SOCKETERROR ) { - DBGONLY( UpnpPrintf( UPNP_CRITICAL, - MSERV, __FILE__, __LINE__, - "Error in binding localhost!!!\n" ); - ) - shutdown( listenfd, SD_BOTH ); + UpnpPrintf( UPNP_CRITICAL, + MSERV, __FILE__, __LINE__, + "Error in binding localhost!!!\n" ); + shutdown( listenfd, SD_BOTH ); UpnpCloseSocket( listenfd ); shutdown( miniServerStopSock, SD_BOTH ); UpnpCloseSocket( miniServerStopSock ); @@ -877,11 +844,9 @@ StopMiniServer( void ) sock = socket( AF_INET, SOCK_DGRAM, 0 ); if( sock == UPNP_INVALID_SOCKET ) { - DBGONLY( UpnpPrintf - ( UPNP_INFO, SSDP, __FILE__, __LINE__, - "SSDP_SERVER:StopSSDPServer: Error in socket operation !!!\n" ); - ) - return 0; + UpnpPrintf( UPNP_INFO, SSDP, __FILE__, __LINE__, + "SSDP_SERVER:StopSSDPServer: Error in socket operation !!!\n" ); + return 0; } while( gMServState != MSERV_IDLE ) { diff --git a/upnp/src/genlib/net/http/httpparser.c b/upnp/src/genlib/net/http/httpparser.c index b8385b8..638b6b6 100644 --- a/upnp/src/genlib/net/http/httpparser.c +++ b/upnp/src/genlib/net/http/httpparser.c @@ -101,7 +101,7 @@ str_int_entry Http_Header_Names[NUM_HTTP_HEADER_NAMES] = { /***********************************************************************/ -/************* scanner **************/ +/************* scanner *************/ /***********************************************************************/ @@ -109,17 +109,17 @@ str_int_entry Http_Header_Names[NUM_HTTP_HEADER_NAMES] = { #define TOKCHAR_LF 0xA /************************************************************************ -* Function : scanner_init +* Function : scanner_init * -* Parameters : -* OUT scanner_t* scanner ; Scanner Object to be initialized -* IN membuffer* bufptr ; Buffer to be copied +* Parameters : +* OUT scanner_t* scanner ; Scanner Object to be initialized +* IN membuffer* bufptr ; Buffer to be copied * -* Description : Intialize scanner +* Description : Intialize scanner * -* Return : void ; +* Return : void ; * -* Note : +* Note : ************************************************************************/ static XINLINE void scanner_init( OUT scanner_t * scanner, @@ -131,16 +131,16 @@ scanner_init( OUT scanner_t * scanner, } /************************************************************************ -* Function : is_separator_char +* Function : is_separator_char * -* Parameters : -* IN char c ; character to be tested against used separator values +* Parameters : +* IN char c ; character to be tested against used separator values * -* Description : Finds the separator character. +* Description : Finds the separator character. * -* Return : xboolean ; +* Return : xboolean ; * -* Note : +* Note : ************************************************************************/ static XINLINE xboolean is_separator_char( IN char c ) @@ -149,16 +149,16 @@ is_separator_char( IN char c ) } /************************************************************************ -* Function : is_identifier_char +* Function : is_identifier_char * -* Parameters : -* IN char c ; character to be tested for separator values +* Parameters : +* IN char c ; character to be tested for separator values * -* Description : Calls the function to indentify separator character +* Description : Calls the function to indentify separator character * -* Return : xboolean ; +* Return : xboolean ; * -* Note : +* Note : ************************************************************************/ static XINLINE xboolean is_identifier_char( IN char c ) @@ -167,16 +167,16 @@ is_identifier_char( IN char c ) } /************************************************************************ -* Function : is_control_char +* Function : is_control_char * -* Parameters : -* IN char c ; character to be tested for a control character +* Parameters : +* IN char c ; character to be tested for a control character * -* Description : Determines if the passed value is a control character +* Description : Determines if the passed value is a control character * -* Return : xboolean ; +* Return : xboolean ; * -* Note : +* Note : ************************************************************************/ static XINLINE xboolean is_control_char( IN char c ) @@ -185,16 +185,16 @@ is_control_char( IN char c ) } /************************************************************************ -* Function : is_qdtext_char +* Function : is_qdtext_char * -* Parameters : -* IN char cc ; character to be tested for CR/LF +* Parameters : +* IN char cc ; character to be tested for CR/LF * -* Description : Checks to see if the passed in value is CR/LF +* Description : Checks to see if the passed in value is CR/LF * -* Return : xboolean ; +* Return : xboolean ; * -* Note : +* Note : ************************************************************************/ static XINLINE xboolean is_qdtext_char( IN char cc ) @@ -214,22 +214,22 @@ is_qdtext_char( IN char cc ) } /************************************************************************ -* Function : scanner_get_token +* Function : scanner_get_token * -* Parameters : -* INOUT scanner_t* scanner ; Scanner Object -* OUT memptr* token ; Token -* OUT token_type_t* tok_type ; Type of token +* Parameters : +* INOUT scanner_t* scanner ; Scanner Object +* OUT memptr* token ; Token +* OUT token_type_t* tok_type ; Type of token * -* Description : reads next token from the input stream -* note: 0 and is used as a marker, and will not be valid in a quote +* Description : reads next token from the input stream +* note: 0 and is used as a marker, and will not be valid in a quote * -* Return : parse_status_t ; -* PARSE_OK -* PARSE_INCOMPLETE -- not enuf chars to get a token -* PARSE_FAILURE -- bad msg format +* Return : parse_status_t ; +* PARSE_OK +* PARSE_INCOMPLETE -- not enuf chars to get a token +* PARSE_FAILURE -- bad msg format * -* Note : +* Note : ************************************************************************/ static parse_status_t scanner_get_token( INOUT scanner_t * scanner, @@ -364,16 +364,16 @@ scanner_get_token( INOUT scanner_t * scanner, } /************************************************************************ -* Function : scanner_get_str +* Function : scanner_get_str * -* Parameters : -* IN scanner_t* scanner ; Scanner Object +* Parameters : +* IN scanner_t* scanner ; Scanner Object * -* Description : returns ptr to next char in string +* Description : returns ptr to next char in string * -* Return : char* ; +* Return : char* ; * -* Note : +* Note : ************************************************************************/ static XINLINE char * scanner_get_str( IN scanner_t * scanner ) @@ -382,18 +382,18 @@ scanner_get_str( IN scanner_t * scanner ) } /************************************************************************ -* Function : scanner_pushback +* Function : scanner_pushback * -* Parameters : -* INOUT scanner_t* scanner ; Scanner Object -* IN size_t pushback_bytes ; Bytes to be moved back +* Parameters : +* INOUT scanner_t* scanner ; Scanner Object +* IN size_t pushback_bytes ; Bytes to be moved back * -* Description : Move back by a certain number of bytes. -* This is used to put back one or more tokens back into the input +* Description : Move back by a certain number of bytes. +* This is used to put back one or more tokens back into the input * -* Return : void ; +* Return : void ; * -* Note : +* Note : ************************************************************************/ static XINLINE void scanner_pushback( INOUT scanner_t * scanner, @@ -404,34 +404,34 @@ scanner_pushback( INOUT scanner_t * scanner, /***********************************************************************/ -/************* end of scanner **************/ +/************* end of scanner **************/ /***********************************************************************/ /***********************************************************************/ -/************* parser **************/ +/************* parser **************/ /***********************************************************************/ /***********************************************************************/ -/************* http_message_t **************/ +/************* http_message_t **************/ /***********************************************************************/ /************************************************************************ -* Function : httpmsg_compare +* Function : httpmsg_compare * -* Parameters : -* void* param1 ; -* void* param2 ; +* Parameters : +* void* param1 ; +* void* param2 ; * -* Description : Compares name id in the http headers. +* Description : Compares name id in the http headers. * -* Return : int ; +* Return : int ; * -* Note : +* Note : ************************************************************************/ static int httpmsg_compare( void *param1, @@ -445,16 +445,16 @@ httpmsg_compare( void *param1, } /************************************************************************ -* Function : httpheader_free +* Function : httpheader_free * -* Parameters : -* void *msg ; +* Parameters : +* void *msg ; * -* Description : Free memory allocated for the http header +* Description : Free memory allocated for the http header * -* Return : void ; +* Return : void ; * -* Note : +* Note : ************************************************************************/ static void httpheader_free( void *msg ) @@ -467,16 +467,16 @@ httpheader_free( void *msg ) } /************************************************************************ -* Function : httpmsg_init +* Function : httpmsg_init * -* Parameters : -* INOUT http_message_t* msg ; HTTP Message Object +* Parameters : +* INOUT http_message_t* msg ; HTTP Message Object * -* Description : Initialize and allocate memory for http message +* Description : Initialize and allocate memory for http message * -* Return : void ; +* Return : void ; * -* Note : +* Note : ************************************************************************/ void httpmsg_init( INOUT http_message_t * msg ) @@ -490,16 +490,16 @@ httpmsg_init( INOUT http_message_t * msg ) } /************************************************************************ -* Function : httpmsg_destroy +* Function : httpmsg_destroy * -* Parameters : -* INOUT http_message_t* msg ; HTTP Message Object +* Parameters : +* INOUT http_message_t* msg ; HTTP Message Object * -* Description : Free memory allocated for the http message +* Description : Free memory allocated for the http message * -* Return : void ; +* Return : void ; * -* Note : +* Note : ************************************************************************/ void httpmsg_destroy( INOUT http_message_t * msg ) @@ -516,19 +516,19 @@ httpmsg_destroy( INOUT http_message_t * msg ) } /************************************************************************ -* Function : httpmsg_find_hdr_str +* Function : httpmsg_find_hdr_str * -* Parameters : -* IN http_message_t* msg ; HTTP Message Object -* IN const char* header_name ; Header name to be compared with +* Parameters : +* IN http_message_t* msg ; HTTP Message Object +* IN const char* header_name ; Header name to be compared with * -* Description : Compares the header name with the header names stored -* in the linked list of messages +* Description : Compares the header name with the header names stored +* in the linked list of messages * -* Return : http_header_t* - Pointer to a header on success; -* NULL on failure +* Return : http_header_t* - Pointer to a header on success; +* NULL on failure * -* Note : +* Note : ************************************************************************/ http_header_t * httpmsg_find_hdr_str( IN http_message_t * msg, @@ -553,19 +553,19 @@ httpmsg_find_hdr_str( IN http_message_t * msg, } /************************************************************************ -* Function : httpmsg_find_hdr +* Function : httpmsg_find_hdr * -* Parameters : -* IN http_message_t* msg ; HTTP Message Object -* IN int header_name_id ; Header Name ID to be compared with -* OUT memptr* value ; Buffer to get the ouput to. +* Parameters : +* IN http_message_t* msg ; HTTP Message Object +* IN int header_name_id ; Header Name ID to be compared with +* OUT memptr* value ; Buffer to get the ouput to. * -* Description : Finds header from a list, with the given 'name_id'. +* Description : Finds header from a list, with the given 'name_id'. * -* Return : http_header_t* - Pointer to a header on success; * -* NULL on failure +* Return : http_header_t* - Pointer to a header on success; +* NULL on failure * -* Note : +* Note : ************************************************************************/ http_header_t * httpmsg_find_hdr( IN http_message_t * msg, @@ -598,21 +598,21 @@ httpmsg_find_hdr( IN http_message_t * msg, /***********************************************************************/ -/************* http_parser_t **************/ +/************* http_parser_t **************/ /***********************************************************************/ /************************************************************************ -* Function : skip_blank_lines +* Function : skip_blank_lines * -* Parameters : -* INOUT scanner_t* scanner ; Scanner Object +* Parameters : +* INOUT scanner_t* scanner ; Scanner Object * -* Description : skips blank lines at the start of a msg. +* Description : skips blank lines at the start of a msg. * -* Return : int ; +* Return : int ; * -* Note : +* Note : ************************************************************************/ static XINLINE int skip_blank_lines( INOUT scanner_t * scanner ) @@ -637,19 +637,19 @@ skip_blank_lines( INOUT scanner_t * scanner ) } /************************************************************************ -* Function : skip_lws +* Function : skip_lws * -* Parameters : -* INOUT scanner_t* scanner ; Scanner Object +* Parameters : +* INOUT scanner_t* scanner ; Scanner Object * -* Description : skip linear whitespace. +* Description : skip linear whitespace. * -* Return : int ; -* PARSE_OK: (LWS)* removed from input -* PARSE_FAILURE: bad input -* PARSE_INCOMPLETE: incomplete input +* Return : int ; +* PARSE_OK: (LWS)* removed from input +* PARSE_FAILURE: bad input +* PARSE_INCOMPLETE: incomplete input * -* Note : +* Note : ************************************************************************/ static XINLINE int skip_lws( INOUT scanner_t * scanner ) @@ -690,21 +690,21 @@ skip_lws( INOUT scanner_t * scanner ) } /************************************************************************ -* Function : match_non_ws_string +* Function : match_non_ws_string * -* Parameters : -* INOUT scanner_t* scanner ; Scanner Object -* OUT memptr* str ; Buffer to get the scanner buffer contents. +* Parameters : +* INOUT scanner_t* scanner ; Scanner Object +* OUT memptr* str ; Buffer to get the scanner buffer contents. * -* Description : Match a string without whitespace or CRLF (%S) +* Description : Match a string without whitespace or CRLF (%S) * -* Return : XINLINE parse_status_t ; -* PARSE_OK -* PARSE_NO_MATCH -* PARSE_FAILURE -* PARSE_INCOMPLETE +* Return : XINLINE parse_status_t ; +* PARSE_OK +* PARSE_NO_MATCH +* PARSE_FAILURE +* PARSE_INCOMPLETE * -* Note : +* Note : ************************************************************************/ static XINLINE parse_status_t match_non_ws_string( INOUT scanner_t * scanner, @@ -754,23 +754,23 @@ match_non_ws_string( INOUT scanner_t * scanner, } /************************************************************************ -* Function : match_raw_value +* Function : match_raw_value * -* Parameters : -* INOUT scanner_t* scanner ; Scanner Object -* OUT memptr* raw_value ; Buffer to get the scanner buffer -* contents +* Parameters : +* INOUT scanner_t* scanner ; Scanner Object +* OUT memptr* raw_value ; Buffer to get the scanner buffer +* contents * -* Description : Matches a raw value in a the input; value's length -* can be 0 or more. Whitespace after value is trimmed. On success, -* scanner points the CRLF that ended the value +* Description : Matches a raw value in a the input; value's length +* can be 0 or more. Whitespace after value is trimmed. On success, +* scanner points the CRLF that ended the value * -* Return : parse_status_t ; -* PARSE_OK -* PARSE_INCOMPLETE -* PARSE_FAILURE +* Return : parse_status_t ; +* PARSE_OK +* PARSE_INCOMPLETE +* PARSE_FAILURE * -* Note : +* Note : ************************************************************************/ static XINLINE parse_status_t match_raw_value( INOUT scanner_t * scanner, @@ -846,22 +846,22 @@ match_raw_value( INOUT scanner_t * scanner, /************************************************************************ * Function: match_int -* -* Parameters: -* INOUT scanner_t* scanner ; Scanner Object -* IN int base : Base of number in the string; -* valid values: 10 or 16 -* OUT int* value ; Number stored here -* -* Description: Matches an unsigned integer value in the input. The -* integer is returned in 'value'. Except for PARSE_OK result, the -* scanner's cursor is moved back to its original position on error. -* -* Returns: -* PARSE_OK -* PARSE_NO_MATCH -- got different kind of token -* PARSE_FAILURE -- bad input -* PARSE_INCOMPLETE +* +* Parameters: +* INOUT scanner_t* scanner ; Scanner Object +* IN int base : Base of number in the string; +* valid values: 10 or 16 +* OUT int* value ; Number stored here +* +* Description: Matches an unsigned integer value in the input. The +* integer is returned in 'value'. Except for PARSE_OK result, the +* scanner's cursor is moved back to its original position on error. +* +* Returns: +* PARSE_OK +* PARSE_NO_MATCH -- got different kind of token +* PARSE_FAILURE -- bad input +* PARSE_INCOMPLETE ************************************************************************/ static XINLINE int match_int( INOUT scanner_t * scanner, @@ -907,20 +907,20 @@ match_int( INOUT scanner_t * scanner, } /************************************************************************ -* Function: read_until_crlf -* -* Parameters: -* INOUT scanner_t* scanner ; Scanner Object -* OUT memptr* str ; Buffer to copy scanner buffer contents to -* +* Function: read_until_crlf +* +* Parameters: +* INOUT scanner_t* scanner ;Scanner Object +* OUT memptr* str ; Buffer to copy scanner buffer contents to +* * Description: Reads data until end of line; the crlf at the end of * line is not consumed. On error, scanner is not restored. On * success, 'str' points to a string that runs until eol -* -* Returns: -* PARSE_OK -* PARSE_FAILURE -* PARSE_INCOMPLETE +* +* Returns: +* PARSE_OK +* PARSE_FAILURE +* PARSE_INCOMPLETE ************************************************************************/ static XINLINE int read_until_crlf( INOUT scanner_t * scanner, @@ -951,17 +951,17 @@ read_until_crlf( INOUT scanner_t * scanner, } /************************************************************************ -* Function: skip_to_end_of_header -* -* Parameters: +* Function: skip_to_end_of_header +* +* Parameters: * INOUT scanner_t* scanner ; Scanner Object -* -* Description: Skip to end of header -* -* Returns: -* PARSE_OK -* PARSE_FAILURE -* PARSE_INCOMPLETE +* +* Description: Skip to end of header +* +* Returns: +* PARSE_OK +* PARSE_FAILURE +* PARSE_INCOMPLETE ************************************************************************/ static XINLINE int skip_to_end_of_header( INOUT scanner_t * scanner ) @@ -977,10 +977,10 @@ skip_to_end_of_header( INOUT scanner_t * scanner ) * Function: match_char * * Parameters: -* INOUT scanner_t* scanner ; Scanner Object -* IN char c ; Character to be compared with -* IN xboolean case_sensitive; Flag indicating whether comparison should -* be case sensitive +* INOUT scanner_t* scanner ; Scanner Object +* IN char c ; Character to be compared with +* IN xboolean case_sensitive; Flag indicating whether +* comparison should be case sensitive * * Description: Compares a character to the next char in the scanner; * on error, scanner chars are not restored @@ -1045,24 +1045,24 @@ match_char( INOUT scanner_t * scanner, // PARSE_NO_MATCH -- input does not match pattern /************************************************************************ -* Function : vfmatch +* Function : vfmatch * -* Parameters : -* INOUT scanner_t* scanner ; Scanner Object -* IN const char* fmt ; Pattern Format -* va_list argp ; List of variable arguments +* Parameters : +* INOUT scanner_t* scanner ; Scanner Object +* IN const char* fmt ; Pattern Format +* va_list argp ; List of variable arguments * -* Description : Extracts variable parameters depending on the passed -* in format parameter. Parses data also based on the passed in -* format parameter. +* Description : Extracts variable parameters depending on the passed +* in format parameter. Parses data also based on the passed in +* format parameter. * -* Return : int ; -* PARSE_OK -* PARSE_INCOMPLETE -* PARSE_FAILURE - bad input -* PARSE_NO_MATCH - input does not match pattern +* Return : int ; +* PARSE_OK +* PARSE_INCOMPLETE +* PARSE_FAILURE - bad input +* PARSE_NO_MATCH - input does not match pattern * -* Note : +* Note : ************************************************************************/ static int vfmatch( INOUT scanner_t * scanner, @@ -1242,20 +1242,20 @@ vfmatch( INOUT scanner_t * scanner, } /************************************************************************ -* Function: match -* -* Parameters: -* INOUT scanner_t* scanner ; Scanner Object -* IN const char* fmt; Pattern format -* ... -* -* Description: matches a variable parameter list and takes necessary -* actions based on the data type specified. -* -* Returns: -* PARSE_OK -* PARSE_NO_MATCH -* PARSE_INCOMPLETE +* Function: match +* +* Parameters: +* INOUT scanner_t* scanner ; Scanner Object +* IN const char* fmt; Pattern format +* ... +* +* Description: matches a variable parameter list and takes necessary +* actions based on the data type specified. +* +* Returns: +* PARSE_OK +* PARSE_NO_MATCH +* PARSE_INCOMPLETE ************************************************************************/ static int match( INOUT scanner_t * scanner, @@ -1273,21 +1273,21 @@ match( INOUT scanner_t * scanner, } /************************************************************************ -* Function: matchstr -* -* Parameters: -* IN char *str ; String to be matched -* IN size_t slen ; Length of the string -* IN const char* fmt ; Pattern format -* ... -* -* Description: Matches a variable parameter list with a string -* and takes actions based on the data type specified. -* -* Returns: -* PARSE_OK -* PARSE_NO_MATCH -- failure to match pattern 'fmt' -* PARSE_FAILURE -- 'str' is bad input +* Function: matchstr +* +* Parameters: +* IN char *str ; String to be matched +* IN size_t slen ; Length of the string +* IN const char* fmt ; Pattern format +* ... +* +* Description: Matches a variable parameter list with a string +* and takes actions based on the data type specified. +* +* Returns: +* PARSE_OK +* PARSE_NO_MATCH -- failure to match pattern 'fmt' +* PARSE_FAILURE -- 'str' is bad input ************************************************************************/ int matchstr( IN char *str, @@ -1327,15 +1327,15 @@ matchstr( IN char *str, } /************************************************************************ -* Function: parser_init -* -* Parameters: +* Function: parser_init +* +* Parameters: * OUT http_parser_t* parser ; HTTP Parser object -* -* Description: Initializes the parser object. -* -* Returns: -* void +* +* Description: Initializes the parser object. +* +* Returns: +* void ************************************************************************/ static XINLINE void parser_init( OUT http_parser_t * parser ) @@ -1351,17 +1351,17 @@ parser_init( OUT http_parser_t * parser ) } /************************************************************************ -* Function: parser_parse_requestline -* -* Parameters: -* INOUT http_parser_t* parser ; HTTP Parser object -* -* Description: Get HTTP Method, URL location and version information. -* -* Returns: -* PARSE_OK -* PARSE_SUCCESS -* PARSE_FAILURE +* Function: parser_parse_requestline +* +* Parameters: +* INOUT http_parser_t* parser ; HTTP Parser object +* +* Description: Get HTTP Method, URL location and version information. +* +* Returns: +* PARSE_OK +* PARSE_SUCCESS +* PARSE_FAILURE ************************************************************************/ static parse_status_t parser_parse_requestline( INOUT http_parser_t * parser ) @@ -1467,17 +1467,17 @@ parser_parse_requestline( INOUT http_parser_t * parser ) } /************************************************************************ -* Function: parser_parse_responseline -* -* Parameters: -* INOUT http_parser_t* parser ; HTTP Parser object -* -* Description: Get HTTP Method, URL location and version information. -* -* Returns: -* PARSE_OK -* PARSE_SUCCESS -* PARSE_FAILURE +* Function: parser_parse_responseline +* +* Parameters: +* INOUT http_parser_t* parser ; HTTP Parser object +* +* Description: Get HTTP Method, URL location and version information. +* +* Returns: +* PARSE_OK +* PARSE_SUCCESS +* PARSE_FAILURE ************************************************************************/ parse_status_t parser_parse_responseline( INOUT http_parser_t * parser ) @@ -1564,17 +1564,17 @@ parser_parse_responseline( INOUT http_parser_t * parser ) } /************************************************************************ -* Function: parser_parse_headers -* -* Parameters: -* INOUT http_parser_t* parser ; HTTP Parser object -* -* Description: Get HTTP Method, URL location and version information. -* -* Returns: -* PARSE_OK -* PARSE_SUCCESS -* PARSE_FAILURE +* Function: parser_parse_headers +* +* Parameters: +* INOUT http_parser_t* parser ; HTTP Parser object +* +* Description: Get HTTP Method, URL location and version information. +* +* Returns: +* PARSE_OK +* PARSE_SUCCESS +* PARSE_FAILURE ************************************************************************/ parse_status_t parser_parse_headers( INOUT http_parser_t * parser ) @@ -1860,17 +1860,17 @@ parser_parse_headers_old( INOUT http_parser_t * parser ) // ****************************** /************************************************************************ -* Function: parser_parse_entity_using_clen -* -* Parameters: +* Function: parser_parse_entity_using_clen +* +* Parameters: * INOUT http_parser_t* parser ; HTTP Parser object -* -* Description: reads entity using content-length -* -* Returns: -* PARSE_INCOMPLETE -* PARSE_FAILURE -- entity length > content-length value -* PARSE_SUCCESS +* +* Description: reads entity using content-length +* +* Returns: +* PARSE_INCOMPLETE +* PARSE_FAILURE -- entity length > content-length value +* PARSE_SUCCESS ************************************************************************/ static XINLINE parse_status_t parser_parse_entity_using_clen( INOUT http_parser_t * parser ) @@ -1907,17 +1907,17 @@ parser_parse_entity_using_clen( INOUT http_parser_t * parser ) } /************************************************************************ -* Function: parser_parse_chunky_body -* -* Parameters: +* Function: parser_parse_chunky_body +* +* Parameters: * INOUT http_parser_t* parser ; HTTP Parser object -* -* Description: Read data in the chunks -* -* Returns: -* PARSE_INCOMPLETE -* PARSE_FAILURE -- entity length > content-length value -* PARSE_SUCCESS +* +* Description: Read data in the chunks +* +* Returns: +* PARSE_INCOMPLETE +* PARSE_FAILURE -- entity length > content-length value +* PARSE_SUCCESS ************************************************************************/ static XINLINE parse_status_t parser_parse_chunky_body( INOUT http_parser_t * parser ) @@ -1952,17 +1952,17 @@ parser_parse_chunky_body( INOUT http_parser_t * parser ) } /************************************************************************ -* Function: parser_parse_chunky_headers -* -* Parameters: -* INOUT http_parser_t* parser ; HTTP Parser object -* -* Description: Read headers at the end of the chunked entity -* -* Returns: -* PARSE_INCOMPLETE -* PARSE_FAILURE -- entity length > content-length value -* PARSE_SUCCESS +* Function: parser_parse_chunky_headers +* +* Parameters: +* INOUT http_parser_t* parser ; HTTP Parser object +* +* Description: Read headers at the end of the chunked entity +* +* Returns: +* PARSE_INCOMPLETE +* PARSE_FAILURE -- entity length > content-length value +* PARSE_SUCCESS ************************************************************************/ static XINLINE parse_status_t parser_parse_chunky_headers( INOUT http_parser_t * parser ) @@ -1991,18 +1991,18 @@ parser_parse_chunky_headers( INOUT http_parser_t * parser ) } /************************************************************************ -* Function: parser_parse_chunky_entity -* -* Parameters: -* INOUT http_parser_t* parser - HTTP Parser Object -* -* Description: Read headers at the end of the chunked entity -* -* Returns: -* PARSE_INCOMPLETE -* PARSE_FAILURE -- entity length > content-length value -* PARSE_SUCCESS -* PARSE_CONTINUE_1 +* Function: parser_parse_chunky_entity +* +* Parameters: +* INOUT http_parser_t* parser - HTTP Parser Object +* +* Description: Read headers at the end of the chunked entity +* +* Returns: +* PARSE_INCOMPLETE +* PARSE_FAILURE -- entity length > content-length value +* PARSE_SUCCESS +* PARSE_CONTINUE_1 ************************************************************************/ static XINLINE parse_status_t parser_parse_chunky_entity( INOUT http_parser_t * parser ) @@ -2020,10 +2020,9 @@ parser_parse_chunky_entity( INOUT http_parser_t * parser ) status = match( scanner, "%x%L%c", &parser->chunk_size, &dummy ); if( status != PARSE_OK ) { scanner->cursor = save_pos; - DBGONLY( UpnpPrintf - ( UPNP_INFO, HTTP, __FILE__, __LINE__, - "CHUNK COULD NOT BE PARSED\n" ); ) - return status; + UpnpPrintf( UPNP_INFO, HTTP, __FILE__, __LINE__, + "CHUNK COULD NOT BE PARSED\n" ); + return status; } // remove chunk info just matched; just retain data membuffer_delete( &parser->msg.msg, save_pos, @@ -2046,15 +2045,15 @@ parser_parse_chunky_entity( INOUT http_parser_t * parser ) } /************************************************************************ -* Function: parser_parse_entity_until_close -* -* Parameters: +* Function: parser_parse_entity_until_close +* +* Parameters: * INOUT http_parser_t* parser ; HTTP Parser object -* -* Description: Read headers at the end of the chunked entity -* -* Returns: -* PARSE_INCOMPLETE_ENTITY +* +* Description: Read headers at the end of the chunked entity +* +* Returns: +* PARSE_INCOMPLETE_ENTITY ************************************************************************/ static XINLINE parse_status_t parser_parse_entity_until_close( INOUT http_parser_t * parser ) @@ -2079,17 +2078,17 @@ parser_parse_entity_until_close( INOUT http_parser_t * parser ) } /************************************************************************ -* Function: parser_get_entity_read_method -* -* Parameters: -* INOUT http_parser_t* parser ; HTTP Parser object -* -* Description: Determines method to read entity -* -* Returns: -* PARSE_OK -* PARSE_FAILURE -* PARSE_COMPLETE -- no more reading to do +* Function: parser_get_entity_read_method +* +* Parameters: +* INOUT http_parser_t* parser ; HTTP Parser object +* +* Description: Determines method to read entity +* +* Returns: +* PARSE_OK +* PARSE_FAILURE +* PARSE_COMPLETE -- no more reading to do ************************************************************************/ XINLINE parse_status_t parser_get_entity_read_method( INOUT http_parser_t * parser ) @@ -2149,11 +2148,10 @@ parser_get_entity_read_method( INOUT http_parser_t * parser ) if( raw_find_str( &hdr_value, "chunked" ) >= 0 ) { // read method to use chunked transfer encoding parser->ent_position = ENTREAD_USING_CHUNKED; - DBGONLY( UpnpPrintf - ( UPNP_INFO, HTTP, __FILE__, __LINE__, - "Found Chunked Encoding ....\n" ); ) + UpnpPrintf( UPNP_INFO, HTTP, __FILE__, __LINE__, + "Found Chunked Encoding ....\n" ); - return PARSE_CONTINUE_1; + return PARSE_CONTINUE_1; } } // * use content length @@ -2185,17 +2183,17 @@ parser_get_entity_read_method( INOUT http_parser_t * parser ) } /************************************************************************ -* Function: parser_parse_entity -* -* Parameters: -* INOUT http_parser_t* parser ; HTTP Parser object -* -* Description: Determines method to read entity -* -* Returns: -* PARSE_OK -* PARSE_FAILURE -* PARSE_COMPLETE -- no more reading to do +* Function: parser_parse_entity +* +* Parameters: +* INOUT http_parser_t* parser ; HTTP Parser object +* +* Description: Determines method to read entity +* +* Returns: +* PARSE_OK +* PARSE_FAILURE +* PARSE_COMPLETE -- no more reading to do ************************************************************************/ XINLINE parse_status_t parser_parse_entity( INOUT http_parser_t * parser ) @@ -2240,15 +2238,15 @@ parser_parse_entity( INOUT http_parser_t * parser ) } /************************************************************************ -* Function: parser_request_init -* -* Parameters: -* OUT http_parser_t* parser ; HTTP Parser object -* -* Description: Initializes parser object for a request -* -* Returns: -* void +* Function: parser_request_init +* +* Parameters: +* OUT http_parser_t* parser ; HTTP Parser object +* +* Description: Initializes parser object for a request +* +* Returns: +* void ************************************************************************/ void parser_request_init( OUT http_parser_t * parser ) @@ -2259,16 +2257,16 @@ parser_request_init( OUT http_parser_t * parser ) } /************************************************************************ -* Function: parser_response_init -* -* Parameters: -* OUT http_parser_t* parser ; HTTP Parser object -* IN http_method_t request_method ; Request method -* -* Description: Initializes parser object for a response -* -* Returns: -* void +* Function: parser_response_init +* +* Parameters: +* OUT http_parser_t* parser ; HTTP Parser object +* IN http_method_t request_method ; Request method +* +* Description: Initializes parser object for a response +* +* Returns: +* void ************************************************************************/ void parser_response_init( OUT http_parser_t * parser, @@ -2281,16 +2279,16 @@ parser_response_init( OUT http_parser_t * parser, } /************************************************************************ -* Function: parser_parse -* -* Parameters: -* INOUT http_parser_t* parser ; HTTP Parser object -* -* Description: The parser function. Depending on the position of the -* parser object the actual parsing function is invoked -* -* Returns: -* void +* Function: parser_parse +* +* Parameters: +* INOUT http_parser_t* parser ; HTTP Parser object +* +* Description: The parser function. Depending on the position of the +* parser object the actual parsing function is invoked +* +* Returns: +* void ************************************************************************/ parse_status_t parser_parse( INOUT http_parser_t * parser ) @@ -2337,19 +2335,19 @@ parser_parse( INOUT http_parser_t * parser ) } /************************************************************************ -* Function: parser_append -* -* Parameters: -* INOUT http_parser_t* parser ; HTTP Parser Object -* IN const char* buf ; buffer to be appended to the parser -* buffer -* IN size_t buf_length ; Size of the buffer -* -* Description: The parser function. Depending on the position of the -* parser object the actual parsing function is invoked -* -* Returns: -* void +* Function: parser_append +* +* Parameters: +* INOUT http_parser_t* parser ; HTTP Parser Object +* IN const char* buf ; buffer to be appended to the parser +* buffer +* IN size_t buf_length ; Size of the buffer +* +* Description: The parser function. Depending on the position of the +* parser object the actual parsing function is invoked +* +* Returns: +* void ************************************************************************/ parse_status_t parser_append( INOUT http_parser_t * parser, @@ -2373,20 +2371,20 @@ parser_append( INOUT http_parser_t * parser, } /************************************************************************ -********** end of parser *********** +********** end of parser *********** ************************************************************************/ /************************************************************************ -* Function: raw_to_int -* -* Parameters: -* IN memptr* raw_value ; Buffer to be converted -* IN int base ; Base to use for conversion -* -* Description: Converts raw character data to long-integer value -* -* Returns: -* int +* Function: raw_to_int +* +* Parameters: +* IN memptr* raw_value ; Buffer to be converted +* IN int base ; Base to use for conversion +* +* Description: Converts raw character data to long-integer value +* +* Returns: +* int ************************************************************************/ int raw_to_int( IN memptr * raw_value, @@ -2461,16 +2459,16 @@ raw_find_str( IN memptr *raw_value, } /************************************************************************ -* Function: method_to_str -* -* Parameters: -* IN http_method_t method ; HTTP method -* -* Description: A wrapper function that maps a method id to a method -* nameConverts a http_method id stored in the HTTP Method -* -* Returns: -* const char* ptr - Ptr to the HTTP Method * +* Function: method_to_str +* +* Parameters: +* IN http_method_t method ; HTTP method +* +* Description: A wrapper function that maps a method id to a method +* nameConverts a http_method id stored in the HTTP Method +* +* Returns: +* const char* ptr - Ptr to the HTTP Method ************************************************************************/ const char * method_to_str( IN http_method_t method ) @@ -2485,50 +2483,48 @@ method_to_str( IN http_method_t method ) } /************************************************************************ -* Function: print_http_headers -* -* Parameters: -* http_message_t* hmsg ; HTTP Message object -* -* Description: -* -* Returns: -* void +* Function: print_http_headers +* +* Parameters: +* http_message_t* hmsg ; HTTP Message object +* +* Description: +* +* Returns: +* void ************************************************************************/ +#ifdef DEBUG void print_http_headers( http_message_t * hmsg ) { - ListNode *node; - - //NNS: dlist_node *node; + // NNS: dlist_node *node; http_header_t *header; // print start line if( hmsg->is_request ) { - //printf( "method = %d, version = %d.%d, url = %.*s\n", - // hmsg->method, hmsg->major_version, hmsg->minor_version, - // hmsg->uri.pathquery.size, hmsg->uri.pathquery.buff); + printf( "method = %d, version = %d.%d, url = %.*s\n", + hmsg->method, hmsg->major_version, hmsg->minor_version, + hmsg->uri.pathquery.size, hmsg->uri.pathquery.buff); } else { - // printf( "resp status = %d, version = %d.%d, status msg = %.*s\n", - // hmsg->status_code, hmsg->major_version, hmsg->minor_version, - // (int)hmsg->status_msg.length, hmsg->status_msg.buf); + printf( "resp status = %d, version = %d.%d, status msg = %.*s\n", + hmsg->status_code, hmsg->major_version, hmsg->minor_version, + (int)hmsg->status_msg.length, hmsg->status_msg.buf); } // print headers - node = ListHead( &hmsg->headers ); - //NNS: node = dlist_first_node( &hmsg->headers ); + // NNS: node = dlist_first_node( &hmsg->headers ); while( node != NULL ) { - header = ( http_header_t * ) node->item; - //NNS: header = (http_header_t *)node->data; - //printf( "hdr name: %.*s, value: %.*s\n", - // (int)header->name.length, header->name.buf, - // (int)header->value.length, header->value.buf ); + // NNS: header = (http_header_t *)node->data; + printf( "hdr name: %.*s, value: %.*s\n", + (int)header->name.length, header->name.buf, + (int)header->value.length, header->value.buf ); node = ListNext( &hmsg->headers, node ); - - //NNS: node = dlist_next( &hmsg->headers, node ); + // NNS: node = dlist_next( &hmsg->headers, node ); } } +#endif + diff --git a/upnp/src/genlib/net/http/httpreadwrite.c b/upnp/src/genlib/net/http/httpreadwrite.c index 3387e91..c7a36c0 100644 --- a/upnp/src/genlib/net/http/httpreadwrite.c +++ b/upnp/src/genlib/net/http/httpreadwrite.c @@ -40,25 +40,25 @@ #include #include #ifndef UPNP_USE_BCBPP -#ifndef UPNP_USE_MSVCPP - #include - #include -#endif + #ifndef UPNP_USE_MSVCPP + #include + #include + #endif #endif #ifndef WIN32 - #include - #include - #include - #include - #include - #include - #include - #include - #include + #include + #include + #include + #include + #include + #include + #include + #include + #include #else - #include - #include + #include + #include #endif #include "unixutil.h" #include "upnp.h" @@ -74,17 +74,17 @@ #define DOSOCKET_WRITE 0 /************************************************************************ -* Function: http_FixUrl -* -* Parameters: -* IN uri_type* url ; URL to be validated and fixed +* Function: http_FixUrl +* +* Parameters: +* IN uri_type* url ; URL to be validated and fixed * OUT uri_type* fixed_url ; URL after being fixed. -* -* Description: Validates URL -* -* Returns: -* UPNP_E_INVALID_URL -* UPNP_E_SUCCESS +* +* Description: Validates URL +* +* Returns: +* UPNP_E_INVALID_URL +* UPNP_E_SUCCESS ************************************************************************/ int http_FixUrl( IN uri_type * url, @@ -111,18 +111,18 @@ http_FixUrl( IN uri_type * url, } /************************************************************************ -* Function: http_FixStrUrl -* -* Parameters: -* IN char* urlstr ; Character string as a URL -* IN int urlstrlen ; Length of the character string +* Function: http_FixStrUrl +* +* Parameters: +* IN char* urlstr ; Character string as a URL +* IN int urlstrlen ; Length of the character string * OUT uri_type* fixed_url ; Fixed and corrected URL -* -* Description: Parses URL and then validates URL -* -* Returns: -* UPNP_E_INVALID_URL -* UPNP_E_SUCCESS +* +* Description: Parses URL and then validates URL +* +* Returns: +* UPNP_E_INVALID_URL +* UPNP_E_SUCCESS ************************************************************************/ int http_FixStrUrl( IN char *urlstr, @@ -139,18 +139,18 @@ http_FixStrUrl( IN char *urlstr, } /************************************************************************ -* Function: http_Connect -* -* Parameters: -* IN uri_type* destination_url ; URL containing destination information -* OUT uri_type *url ; Fixed and corrected URL -* +* Function: http_Connect +* +* Parameters: +* IN uri_type* destination_url ; URL containing destination information +* OUT uri_type *url ; Fixed and corrected URL +* * Description: Gets destination address from URL and then connects to the * remote end -* -* Returns: -* socket descriptor on sucess -* UPNP_E_OUTOF_SOCKET +* +* Returns: +* socket descriptor on sucess +* UPNP_E_OUTOF_SOCKET * UPNP_E_SOCKET_CONNECT on error ************************************************************************/ int @@ -169,10 +169,8 @@ http_Connect( IN uri_type * destination_url, if( connect( connfd, ( struct sockaddr * )&url->hostport.IPv4address, sizeof( struct sockaddr_in ) ) == -1 ) { #ifdef WIN32 - DBGONLY( - UpnpPrintf(UPNP_CRITICAL, HTTP, __FILE__, __LINE__, - "connect error: %d\n", WSAGetLastError()); - ) + UpnpPrintf(UPNP_CRITICAL, HTTP, __FILE__, __LINE__, + "connect error: %d\n", WSAGetLastError()); #endif shutdown( connfd, SD_BOTH ); UpnpCloseSocket( connfd ); @@ -183,23 +181,23 @@ http_Connect( IN uri_type * destination_url, } /************************************************************************ -* Function: http_RecvMessage -* -* Parameters: -* IN SOCKINFO *info ; Socket information object -* OUT http_parser_t* parser, HTTP parser object -* IN http_method_t request_method ; HTTP request method -* IN OUT int* timeout_secs ; time out -* OUT int* http_error_code ; HTTP error code returned -* +* Function: http_RecvMessage +* +* Parameters: +* IN SOCKINFO *info ; Socket information object +* OUT http_parser_t* parser, HTTP parser object +* IN http_method_t request_method ; HTTP request method +* IN OUT int* timeout_secs ; time out +* OUT int* http_error_code ; HTTP error code returned +* * Description: Get the data on the socket and take actions based on the * read data to modify the parser objects buffer. If an error is reported * while parsing the data, the error code is passed in the http_errr_code * parameter -* -* Returns: -* UPNP_E_BAD_HTTPMSG -* UPNP_E_SUCCESS +* +* Returns: +* UPNP_E_BAD_HTTPMSG +* UPNP_E_SUCCESS ************************************************************************/ int http_RecvMessage( IN SOCKINFO * info, @@ -226,12 +224,10 @@ http_RecvMessage( IN SOCKINFO * info, status = parser_append( parser, buf, num_read ); if( status == PARSE_SUCCESS ) { - DBGONLY( UpnpPrintf - ( UPNP_INFO, HTTP, __FILE__, __LINE__, - "<<< (RECVD) <<<\n%s\n-----------------\n", - parser->msg.msg.buf ); - //print_http_headers( &parser->msg ); - ) + UpnpPrintf( UPNP_INFO, HTTP, __FILE__, __LINE__, + "<<< (RECVD) <<<\n%s\n-----------------\n", + parser->msg.msg.buf ); + print_http_headers( &parser->msg ); if( parser->content_length > ( unsigned int )g_maxContentLength ) { @@ -252,12 +248,10 @@ http_RecvMessage( IN SOCKINFO * info, } } else if( num_read == 0 ) { if( ok_on_close ) { - DBGONLY( UpnpPrintf - ( UPNP_INFO, HTTP, __FILE__, __LINE__, - "<<< (RECVD) <<<\n%s\n-----------------\n", - parser->msg.msg.buf ); - //print_http_headers( &parser->msg ); - ) + UpnpPrintf( UPNP_INFO, HTTP, __FILE__, __LINE__, + "<<< (RECVD) <<<\n%s\n-----------------\n", + parser->msg.msg.buf ); + print_http_headers( &parser->msg ); return 0; } else { @@ -273,29 +267,29 @@ http_RecvMessage( IN SOCKINFO * info, } /************************************************************************ -* Function: http_SendMessage -* -* Parameters: +* Function: http_SendMessage +* +* Parameters: * IN SOCKINFO *info ; Socket information object -* IN OUT int * TimeOut ; time out value -* IN const char* fmt, ... Pattern format to take actions upon -* -* Description: Sends a message to the destination based on the -* IN const char* fmt parameter -* fmt types: -* 'f': arg = const char * file name -* 'm': arg1 = const char * mem_buffer; arg2= size_t buf_length -* E.g.: -* char *buf = "POST /xyz.cgi http/1.1\r\n\r\n"; -* char *filename = "foo.dat"; -* int status = http_SendMessage( tcpsock, "mf", -* buf, strlen(buf), // args for memory buffer -* filename ); // arg for file -* -* Returns: -* UPNP_E_OUTOF_MEMORY -* UPNP_E_FILE_READ_ERROR -* UPNP_E_SUCCESS +* IN OUT int * TimeOut ; time out value +* IN const char* fmt, ... Pattern format to take actions upon +* +* Description: Sends a message to the destination based on the +* IN const char* fmt parameter +* fmt types: +* 'f': arg = const char * file name +* 'm': arg1 = const char * mem_buffer; arg2= size_t buf_length +* E.g.: +* char *buf = "POST /xyz.cgi http/1.1\r\n\r\n"; +* char *filename = "foo.dat"; +* int status = http_SendMessage( tcpsock, "mf", +* buf, strlen(buf), // args for memory buffer +* filename ); // arg for file +* +* Returns: +* UPNP_E_OUTOF_MEMORY +* UPNP_E_FILE_READ_ERROR +* UPNP_E_SUCCESS ************************************************************************/ int http_SendMessage( IN SOCKINFO * info, @@ -455,11 +449,9 @@ http_SendMessage( IN SOCKINFO * info, num_written = sock_write( info, file_buf, num_read, TimeOut ); - DBGONLY( UpnpPrintf - ( UPNP_INFO, HTTP, __FILE__, __LINE__, - ">>> (SENT) >>>\n%.*s\n------------\n", - ( int )num_written, file_buf ); - ) + UpnpPrintf( UPNP_INFO, HTTP, __FILE__, __LINE__, + ">>> (SENT) >>>\n%.*s\n------------\n", + ( int )num_written, file_buf ); //Send error nothing we can do if( num_written != num_read ) { @@ -485,10 +477,9 @@ http_SendMessage( IN SOCKINFO * info, num_written = sock_write( info, buf, buf_length, TimeOut ); if( ( size_t ) num_written != buf_length ) goto end; - DBGONLY( UpnpPrintf( UPNP_INFO, HTTP, __FILE__, __LINE__, - ">>> (SENT) >>>\n%.*s\n------------\n", - ( int )buf_length, buf ); - ) + UpnpPrintf( UPNP_INFO, HTTP, __FILE__, __LINE__, + ">>> (SENT) >>>\n%.*s\n------------\n", + ( int )buf_length, buf ); } } } @@ -500,24 +491,24 @@ http_SendMessage( IN SOCKINFO * info, } /************************************************************************ -* Function: http_RequestAndResponse -* -* Parameters: -* IN uri_type* destination ; Destination URI object which contains -* remote IP address among other elements -* IN const char* request ; Request to be sent -* IN size_t request_length ; Length of the request +* Function: http_RequestAndResponse +* +* Parameters: +* IN uri_type* destination ; Destination URI object which contains +* remote IP address among other elements +* IN const char* request ; Request to be sent +* IN size_t request_length ; Length of the request * IN http_method_t req_method ; HTTP Request method -* IN int timeout_secs ; time out value -* OUT http_parser_t* response ; Parser object to receive the repsonse -* -* Description: Initiates socket, connects to the destination, sends a -* request and waits for the response from the remote end -* -* Returns: -* UPNP_E_SOCKET_ERROR -* UPNP_E_SOCKET_CONNECT -* Error Codes returned by http_SendMessage +* IN int timeout_secs ; time out value +* OUT http_parser_t* response; Parser object to receive the repsonse +* +* Description: Initiates socket, connects to the destination, sends a +* request and waits for the response from the remote end +* +* Returns: +* UPNP_E_SOCKET_ERROR +* UPNP_E_SOCKET_CONNECT +* Error Codes returned by http_SendMessage * Error Codes returned by http_RecvMessage ************************************************************************/ int @@ -572,25 +563,24 @@ http_RequestAndResponse( IN uri_type * destination, } /************************************************************************ -* Function : http_Download +* Function : http_Download * -* Parameters : -* IN const char* url_str : String as a URL -* IN int timeout_secs : time out value -* OUT char** document : buffer to store the document extracted -* from the donloaded message. -* OUT int* doc_length : length of the extracted document -* OUT char* content_type : Type of content +* Parameters : +* IN const char* url_str: String as a URL +* IN int timeout_secs: time out value +* OUT char** document: buffer to store the document extracted +* from the donloaded message. +* OUT int* doc_length: length of the extracted document +* OUT char* content_type: Type of content * -* Description : Download the document message and extract the document +* Description : Download the document message and extract the document * from the message. * -* Return : int; -* UPNP_E_SUCCESS; -* UPNP_E_INVALID_URL; -* +* Return : int; +* UPNP_E_SUCCESS; +* UPNP_E_INVALID_URL; * -* Note : +* Note : ************************************************************************/ int http_Download( IN const char *url_str, @@ -601,10 +591,10 @@ http_Download( IN const char *url_str, { int ret_code; uri_type url; - char *msg_start, - *entity_start, - *hoststr, - *temp; + char *msg_start; + char *entity_start; + char *hoststr; + char *temp; http_parser_t response; size_t msg_length; size_t hostlen; @@ -614,11 +604,9 @@ http_Download( IN const char *url_str, char *urlPath = alloca( strlen( url_str ) + 1 ); //ret_code = parse_uri( (char*)url_str, strlen(url_str), &url ); - DBGONLY( UpnpPrintf - ( UPNP_INFO, HTTP, __FILE__, __LINE__, "DOWNLOAD URL : %s\n", - url_str ); - ) - ret_code = + UpnpPrintf( UPNP_INFO, HTTP, __FILE__, __LINE__, "DOWNLOAD URL : %s\n", + url_str ); + ret_code = http_FixStrUrl( ( char * )url_str, strlen( url_str ), &url ); if( ret_code != UPNP_E_SUCCESS ) { return ret_code; @@ -641,32 +629,26 @@ http_Download( IN const char *url_str, *temp = '\0'; hostlen = strlen( hoststr ); *temp = '/'; - DBGONLY( UpnpPrintf - ( UPNP_INFO, HTTP, __FILE__, __LINE__, - "HOSTNAME : %s Length : %"PRIzu"\n", hoststr, hostlen ); - ) + UpnpPrintf( UPNP_INFO, HTTP, __FILE__, __LINE__, + "HOSTNAME : %s Length : %"PRIzu"\n", hoststr, hostlen ); - ret_code = http_MakeMessage( - &request, 1, 1, - "Q" "s" "bcDCUc", - HTTPMETHOD_GET, url.pathquery.buff, url.pathquery.size, - "HOST: ", - hoststr, hostlen ); + ret_code = http_MakeMessage( + &request, 1, 1, + "Q" "s" "bcDCUc", + HTTPMETHOD_GET, url.pathquery.buff, url.pathquery.size, + "HOST: ", + hoststr, hostlen ); if( ret_code != 0 ) { - DBGONLY( UpnpPrintf - ( UPNP_INFO, HTTP, __FILE__, __LINE__, - "HTTP Makemessage failed\n" ); - ) + UpnpPrintf( UPNP_INFO, HTTP, __FILE__, __LINE__, + "HTTP Makemessage failed\n" ); membuffer_destroy( &request ); return ret_code; } - DBGONLY( UpnpPrintf - ( UPNP_INFO, HTTP, __FILE__, __LINE__, - "HTTP Buffer:\n %s\n----------END--------\n", request.buf ); - ) - // get doc msg - ret_code = + UpnpPrintf( UPNP_INFO, HTTP, __FILE__, __LINE__, + "HTTP Buffer:\n %s\n----------END--------\n", request.buf ); + // get doc msg + ret_code = http_RequestAndResponse( &url, request.buf, request.length, HTTPMETHOD_GET, timeout_secs, &response ); @@ -676,11 +658,8 @@ http_Download( IN const char *url_str, return ret_code; } - DBGONLY( UpnpPrintf - ( UPNP_INFO, HTTP, __FILE__, __LINE__, "Response\n" ); - ) - DBGONLY( print_http_headers( &response.msg ); - ) + UpnpPrintf( UPNP_INFO, HTTP, __FILE__, __LINE__, "Response\n" ); + print_http_headers( &response.msg ); // optional content-type if( content_type ) { @@ -771,13 +750,10 @@ MakePostMessage( const char *url_str, char *hoststr, *temp; - DBGONLY( UpnpPrintf( UPNP_INFO, HTTP, __FILE__, __LINE__, + UpnpPrintf( UPNP_INFO, HTTP, __FILE__, __LINE__, "DOWNLOAD URL : %s\n", url_str ); - ) - - ret_code = + ret_code = http_FixStrUrl( ( char * )url_str, strlen( url_str ), url ); - if( ret_code != UPNP_E_SUCCESS ) { return ret_code; } @@ -799,9 +775,8 @@ MakePostMessage( const char *url_str, *temp = '\0'; hostlen = strlen( hoststr ); *temp = '/'; - DBGONLY( UpnpPrintf( UPNP_INFO, HTTP, __FILE__, __LINE__, - "HOSTNAME : %s Length : %"PRIzu"\n", hoststr, hostlen ); - ) + UpnpPrintf( UPNP_INFO, HTTP, __FILE__, __LINE__, + "HOSTNAME : %s Length : %"PRIzu"\n", hoststr, hostlen ); if( contentLength >= 0 ) { ret_code = http_MakeMessage( @@ -833,19 +808,18 @@ MakePostMessage( const char *url_str, } if( ret_code != 0 ) { - DBGONLY( UpnpPrintf( UPNP_INFO, HTTP, __FILE__, __LINE__, - "HTTP Makemessage failed\n" ); - ) - membuffer_destroy( request ); + UpnpPrintf( UPNP_INFO, HTTP, __FILE__, __LINE__, + "HTTP Makemessage failed\n" ); + membuffer_destroy( request ); + return ret_code; } - DBGONLY( UpnpPrintf( UPNP_INFO, HTTP, __FILE__, __LINE__, - "HTTP Buffer:\n %s\n" "----------END--------\n", - request->buf ); - ) + UpnpPrintf( UPNP_INFO, HTTP, __FILE__, __LINE__, + "HTTP Buffer:\n %s\n" "----------END--------\n", + request->buf ); - return UPNP_E_SUCCESS; + return UPNP_E_SUCCESS; } /************************************************************************ @@ -1108,11 +1082,10 @@ MakeGetMessage( const char *url_str, char *hoststr, *temp; - DBGONLY( UpnpPrintf( UPNP_INFO, HTTP, __FILE__, __LINE__, - "DOWNLOAD URL : %s\n", url_str ); - ) + UpnpPrintf( UPNP_INFO, HTTP, __FILE__, __LINE__, + "DOWNLOAD URL : %s\n", url_str ); - ret_code = + ret_code = http_FixStrUrl( ( char * )url_str, strlen( url_str ), url ); if( ret_code != UPNP_E_SUCCESS ) { @@ -1136,9 +1109,8 @@ MakeGetMessage( const char *url_str, *temp = '\0'; hostlen = strlen( hoststr ); *temp = '/'; - DBGONLY( UpnpPrintf( UPNP_INFO, HTTP, __FILE__, __LINE__, - "HOSTNAME : %s Length : %"PRIzu"\n", hoststr, hostlen ); - ) + UpnpPrintf( UPNP_INFO, HTTP, __FILE__, __LINE__, + "HOSTNAME : %s Length : %"PRIzu"\n", hoststr, hostlen ); if( proxy_str ) { querystr = url_str; @@ -1156,19 +1128,18 @@ MakeGetMessage( const char *url_str, hoststr, hostlen ); if( ret_code != 0 ) { - DBGONLY( UpnpPrintf( UPNP_INFO, HTTP, __FILE__, __LINE__, - "HTTP Makemessage failed\n" ); - ) - membuffer_destroy( request ); + UpnpPrintf( UPNP_INFO, HTTP, __FILE__, __LINE__, + "HTTP Makemessage failed\n" ); + membuffer_destroy( request ); + return ret_code; } - DBGONLY( UpnpPrintf( UPNP_INFO, HTTP, __FILE__, __LINE__, - "HTTP Buffer:\n %s\n" "----------END--------\n", - request->buf ); - ) + UpnpPrintf( UPNP_INFO, HTTP, __FILE__, __LINE__, + "HTTP Buffer:\n %s\n" "----------END--------\n", + request->buf ); - return UPNP_E_SUCCESS; + return UPNP_E_SUCCESS; } /************************************************************************ @@ -1297,25 +1268,25 @@ ReadResponseLineAndHeaders( IN SOCKINFO * info, } /************************************************************************ -* Function : http_ReadHttpGet +* Function : http_ReadHttpGet * -* Parameters : -* IN void *Handle : Handle to the HTTP get object -* IN OUT char *buf : Buffer to get the read and parsed data -* IN OUT unsigned int *size : Size of the buffer passed -* IN int timeout : time out value +* Parameters : +* IN void *Handle : Handle to the HTTP get object +* IN OUT char *buf : Buffer to get the read and parsed data +* IN OUT unsigned int *size : Size of the buffer passed +* IN int timeout : time out value * -* Description : Parses already existing data, then gets new data. +* Description : Parses already existing data, then gets new data. * Parses and extracts information from the new data. * -* Return : int ; -* UPNP_E_SUCCESS - On Sucess ; -* UPNP_E_INVALID_PARAM - Invalid Parameter; -* UPNP_E_BAD_RESPONSE ; -* UPNP_E_BAD_HTTPMSG ; -* UPNP_E_CANCELED ; +* Return : int ; +* UPNP_E_SUCCESS - On Sucess ; +* UPNP_E_INVALID_PARAM - Invalid Parameter; +* UPNP_E_BAD_RESPONSE ; +* UPNP_E_BAD_HTTPMSG ; +* UPNP_E_CANCELED ; * -* Note : +* Note : ************************************************************************/ int http_ReadHttpGet( IN void *Handle, @@ -1386,11 +1357,9 @@ http_ReadHttpGet( IN void *Handle, } } else if( num_read == 0 ) { if( ok_on_close ) { - DBGONLY( UpnpPrintf( UPNP_INFO, HTTP, __FILE__, __LINE__, - "<<< (RECVD) <<<\n%s\n-----------------\n", - handle->response.msg.msg.buf ); - //print_http_headers( &parser->msg ); - ) + UpnpPrintf( UPNP_INFO, HTTP, __FILE__, __LINE__, + "<<< (RECVD) <<<\n%s\n-----------------\n", + handle->response.msg.msg.buf ); handle->response.position = POS_COMPLETE; } else { // partial msg @@ -1850,31 +1819,26 @@ http_MakeMessage( INOUT membuffer * buf, va_start( argp, fmt ); while( ( c = *fmt++ ) != 0 ) { - - if( c == 's' ) // C string - { + if( c == 's' ) { + // C string s = ( char * )va_arg( argp, char * ); - assert( s ); - - //DBGONLY(UpnpPrintf(UPNP_ALL,HTTP,__FILE__,__LINE__,"Adding a string : %s\n", s);) + UpnpPrintf(UPNP_ALL,HTTP,__FILE__,__LINE__,"Adding a string : %s\n", s); if( membuffer_append( buf, s, strlen( s ) ) != 0 ) { goto error_handler; } - } else if( c == 'K' ) // Add Chunky header - { + } else if( c == 'K' ) { + // Add Chunky header if( membuffer_append ( buf, "TRANSFER-ENCODING: chunked\r\n", strlen( "Transfer-Encoding: chunked\r\n" ) ) != 0 ) { goto error_handler; } - } else if( c == 'G' ) // Add Range header - { + } else if( c == 'G' ) { + // Add Range header struct SendInstruction *RespInstr; - RespInstr = - ( struct SendInstruction * )va_arg( argp, - struct SendInstruction - * ); + RespInstr = (struct SendInstruction *) + va_arg( argp, struct SendInstruction *); assert( RespInstr ); // connection header if( membuffer_append @@ -1882,38 +1846,34 @@ http_MakeMessage( INOUT membuffer * buf, strlen( RespInstr->RangeHeader ) ) != 0 ) { goto error_handler; } - - } else if( c == 'b' ) // mem buffer - { + } else if( c == 'b' ) { + // mem buffer s = ( char * )va_arg( argp, char * ); - //DBGONLY(UpnpPrintf(UPNP_ALL,HTTP,__FILE__,__LINE__,"Adding a char Buffer starting with: %c\n", s[0]);) + UpnpPrintf(UPNP_ALL,HTTP,__FILE__,__LINE__, + "Adding a char Buffer starting with: %c\n", s[0]); assert( s ); length = ( size_t ) va_arg( argp, size_t ); if( membuffer_append( buf, s, length ) != 0 ) { goto error_handler; } } - - else if( c == 'c' ) // crlf - { + else if( c == 'c' ) { + // crlf if( membuffer_append( buf, "\r\n", 2 ) != 0 ) { goto error_handler; } } - - else if( c == 'd' ) // integer - { + else if( c == 'd' ) { + // integer num = ( int )va_arg( argp, int ); - sprintf( tempbuf, "%"PRIzu, num ); if( membuffer_append( buf, tempbuf, strlen( tempbuf ) ) != 0 ) { goto error_handler; } } - - else if( c == 'h' ) // off_t - { + else if( c == 'h' ) { + // off_t bignum = ( off_t )va_arg( argp, off_t ); sprintf( tempbuf, "%"PRId64, (int64_t)bignum ); @@ -1921,9 +1881,8 @@ http_MakeMessage( INOUT membuffer * buf, goto error_handler; } } - - else if( c == 't' || c == 'D' ) // date - { + else if( c == 't' || c == 'D' ) { + // date if( c == 'D' ) { // header start_str = "DATE: "; @@ -1947,9 +1906,7 @@ http_MakeMessage( INOUT membuffer * buf, if( membuffer_append( buf, tempbuf, strlen( tempbuf ) ) != 0 ) { goto error_handler; } - } - - else if( c == 'C' ) { + } else if( c == 'C' ) { if( ( http_major_version > 1 ) || ( http_major_version == 1 && http_minor_version == 1 ) ) { @@ -1959,9 +1916,7 @@ http_MakeMessage( INOUT membuffer * buf, goto error_handler; } } - } - - else if( c == 'N' ) { + } else if( c == 'N' ) { // content-length header bignum = ( off_t )va_arg( argp, off_t ); @@ -1972,11 +1927,8 @@ http_MakeMessage( INOUT membuffer * buf, "CONTENT-LENGTH: ", bignum ) != 0 ) { goto error_handler; } - } - - else if( c == 'S' || c == 'U' ) { + } else if( c == 'S' || c == 'U' ) { // SERVER or USER-AGENT header - temp_str = ( c == 'S' ) ? "SERVER: " : "USER-AGENT: "; get_sdk_info( tempbuf ); if (http_MakeMessage( @@ -1985,34 +1937,25 @@ http_MakeMessage( INOUT membuffer * buf, temp_str, tempbuf ) != 0 ) { goto error_handler; } - } - - else if( c == 'X' ) // C string - { + } else if( c == 'X' ) { + // C string s = ( char * )va_arg( argp, char * ); - assert( s ); - if( membuffer_append_str( buf, "X-User-Agent: ") != 0 ) { goto error_handler; } if( membuffer_append( buf, s, strlen( s ) ) != 0 ) { goto error_handler; } - } - - else if( c == 'R' ) { + } else if( c == 'R' ) { // response start line // e.g.: 'HTTP/1.1 200 OK' // - // code status_code = ( int )va_arg( argp, int ); - assert( status_code > 0 ); sprintf( tempbuf, "HTTP/%d.%d %d ", http_major_version, http_minor_version, status_code ); - // str status_msg = http_get_code_text( status_code ); if (http_MakeMessage( @@ -2022,40 +1965,31 @@ http_MakeMessage( INOUT membuffer * buf, status_msg ) != 0 ) { goto error_handler; } - } - - else if( c == 'B' ) { + } else if( c == 'B' ) { // body of a simple reply // - status_code = ( int )va_arg( argp, int ); - sprintf( tempbuf, "%s%d %s%s", "

", status_code, http_get_code_text( status_code ), "

" ); bignum = strlen( tempbuf ); - if (http_MakeMessage( buf, http_major_version, http_minor_version, "NTcs", bignum, // content-length "text/html", // content-type - tempbuf ) != 0 ) // body - { + tempbuf ) != 0 // body + ) { goto error_handler; } - } - - else if( c == 'Q' ) { + } else if( c == 'Q' ) { // request start line // GET /foo/bar.html HTTP/1.1\r\n - method = ( http_method_t ) va_arg( argp, http_method_t ); method_str = method_to_str( method ); url_str = ( const char * )va_arg( argp, const char * ); num = ( size_t )va_arg( argp, size_t ); // length of url_str - if (http_MakeMessage( buf, http_major_version, http_minor_version, "ssbsdsdc", @@ -2064,20 +1998,15 @@ http_MakeMessage( INOUT membuffer * buf, " HTTP/", http_major_version, ".", http_minor_version ) != 0 ) { goto error_handler; } - } - - else if( c == 'q' ) { + } else if( c == 'q' ) { // request start line and HOST header - method = ( http_method_t ) va_arg( argp, http_method_t ); - uri_ptr = ( uri_type * ) va_arg( argp, uri_type * ); assert( uri_ptr ); if( http_FixUrl( uri_ptr, &url ) != 0 ) { error_code = UPNP_E_INVALID_URL; goto error_handler; } - if (http_MakeMessage( buf, http_major_version, http_minor_version, "Q" "sbc", @@ -2085,28 +2014,23 @@ http_MakeMessage( INOUT membuffer * buf, "HOST: ", url.hostport.text.buff, url.hostport.text.size ) != 0 ) { goto error_handler; } - } - - else if( c == 'T' ) { + } else if( c == 'T' ) { // content type header temp_str = ( const char * )va_arg( argp, const char * ); // type/subtype format - if (http_MakeMessage( buf, http_major_version, http_minor_version, "ssc", "CONTENT-TYPE: ", temp_str ) != 0 ) { goto error_handler; } - } - - else { + } else { assert( 0 ); } } return 0; - error_handler: +error_handler: va_end( argp ); membuffer_destroy( buf ); return error_code; @@ -2174,18 +2098,15 @@ MakeGetMessageEx( const char *url_str, *temp; do { - DBGONLY( UpnpPrintf( UPNP_INFO, HTTP, __FILE__, __LINE__, - "DOWNLOAD URL : %s\n", url_str ); - ) + UpnpPrintf( UPNP_INFO, HTTP, __FILE__, __LINE__, + "DOWNLOAD URL : %s\n", url_str ); - if( ( errCode = http_FixStrUrl( ( char * )url_str, - strlen( url_str ), - url ) ) != UPNP_E_SUCCESS ) { + if( ( errCode = http_FixStrUrl( ( char * )url_str, + strlen( url_str ), url ) ) != UPNP_E_SUCCESS ) { break; } // make msg membuffer_init( request ); - urlPath = alloca( strlen( url_str ) + 1 ); if( !urlPath ) { errCode = UPNP_E_OUTOF_MEMORY; @@ -2193,9 +2114,7 @@ MakeGetMessageEx( const char *url_str, } memset( urlPath, 0, strlen( url_str ) + 1 ); - strcpy( urlPath, url_str ); - hoststr = strstr( urlPath, "//" ); if( hoststr == NULL ) { errCode = UPNP_E_INVALID_URL; @@ -2212,13 +2131,11 @@ MakeGetMessageEx( const char *url_str, *temp = '\0'; hostlen = strlen( hoststr ); *temp = '/'; + UpnpPrintf( UPNP_INFO, HTTP, __FILE__, __LINE__, + "HOSTNAME : %s Length : %"PRIzu"\n", + hoststr, hostlen ); - DBGONLY( UpnpPrintf( UPNP_INFO, HTTP, __FILE__, __LINE__, - "HOSTNAME : %s Length : %"PRIzu"\n", - hoststr, hostlen ); - ) - - errCode = http_MakeMessage( + errCode = http_MakeMessage( request, 1, 1, "Q" "s" "bc" "GDCUc", HTTPMETHOD_GET, url->pathquery.buff, url->pathquery.size, @@ -2227,49 +2144,48 @@ MakeGetMessageEx( const char *url_str, pRangeSpecifier ); if( errCode != 0 ) { - DBGONLY( UpnpPrintf( UPNP_INFO, HTTP, __FILE__, __LINE__, - "HTTP Makemessage failed\n" ); - ) - membuffer_destroy( request ); + UpnpPrintf( UPNP_INFO, HTTP, __FILE__, __LINE__, + "HTTP Makemessage failed\n" ); + membuffer_destroy( request ); + return errCode; } } while( 0 ); - DBGONLY( UpnpPrintf( UPNP_INFO, HTTP, __FILE__, __LINE__, - "HTTP Buffer:\n %s\n" "----------END--------\n", - request->buf ); - ) + UpnpPrintf( UPNP_INFO, HTTP, __FILE__, __LINE__, + "HTTP Buffer:\n %s\n" "----------END--------\n", + request->buf ); - return errCode; + return errCode; } #define SIZE_RANGE_BUFFER 50 /************************************************************************ -* Function : http_OpenHttpGetEx +* Function : http_OpenHttpGetEx * -* Parameters : -* IN const char *url_str : String as a URL -* IN OUT void **Handle : Pointer to buffer to store HTTP -* post handle -* IN OUT char **contentType : Type of content -* OUT int *contentLength : length of content -* OUT int *httpStatus : HTTP status returned on receiving a -* response message -* IN int timeout : time out value +* Parameters : +* IN const char *url_str : String as a URL +* IN OUT void **Handle : Pointer to buffer to store HTTP +* post handle +* IN OUT char **contentType : Type of content +* OUT int *contentLength : length of content +* OUT int *httpStatus : HTTP status returned on receiving a +* response message +* IN int timeout : time out value * -* Description : Makes the HTTP GET message, connects to the peer, +* Description : Makes the HTTP GET message, connects to the peer, * sends the HTTP GET request, gets the response and parses the * response. * -* Return : int; -* UPNP_E_SUCCESS - On Success ; -* UPNP_E_INVALID_PARAM - Invalid Paramters ; -* UPNP_E_OUTOF_MEMORY ; -* UPNP_E_SOCKET_ERROR ; -* UPNP_E_BAD_RESPONSE ; +* Return : int; +* UPNP_E_SUCCESS - On Success ; +* UPNP_E_INVALID_PARAM - Invalid Paramters ; +* UPNP_E_OUTOF_MEMORY ; +* UPNP_E_SOCKET_ERROR ; +* UPNP_E_BAD_RESPONSE ; * -* Note : +* Note : * ************************************************************************/ int diff --git a/upnp/src/genlib/net/http/webserver.c b/upnp/src/genlib/net/http/webserver.c index b59ba03..3e6a3ba 100644 --- a/upnp/src/genlib/net/http/webserver.c +++ b/upnp/src/genlib/net/http/webserver.c @@ -637,13 +637,13 @@ get_file_info( IN const char *filename, rc = get_content_type( filename, &info->content_type ); - DBGONLY( UpnpPrintf( UPNP_INFO, HTTP, __FILE__, __LINE__, - "file info: %s, length: %lld, last_mod=%s readable=%d\n", - filename, (long long)info->file_length, - asctime( gmtime( &info->last_modified ) ), - info->is_readable ); ) + UpnpPrintf( UPNP_INFO, HTTP, __FILE__, __LINE__, + "file info: %s, length: %lld, last_mod=%s readable=%d\n", + filename, (long long)info->file_length, + asctime( gmtime( &info->last_modified ) ), + info->is_readable ); - return rc; + return rc; } /************************************************************************ @@ -1586,14 +1586,11 @@ http_RecvPostMessage( http_parser_t * parser, } } else if( num_read == 0 ) { if( ok_on_close ) { - DBGONLY( UpnpPrintf - ( UPNP_INFO, HTTP, __FILE__, __LINE__, - "<<< (RECVD) <<<\n%s\n-----------------\n", - parser->msg.msg.buf ); - //print_http_headers( &parser->msg ); - ) - - parser->position = POS_COMPLETE; + UpnpPrintf( UPNP_INFO, HTTP, __FILE__, __LINE__, + "<<< (RECVD) <<<\n%s\n-----------------\n", + parser->msg.msg.buf ); + print_http_headers( &parser->msg ); + parser->position = POS_COMPLETE; } else { // partial msg parser->http_error_code = HTTP_BAD_REQUEST; // or response @@ -1760,10 +1757,9 @@ web_server_callback( IN http_parser_t * parser, } } - DBGONLY( UpnpPrintf( UPNP_INFO, HTTP, __FILE__, __LINE__, - "webserver: request processed...\n" ); - ) + UpnpPrintf( UPNP_INFO, HTTP, __FILE__, __LINE__, + "webserver: request processed...\n" ); - membuffer_destroy( &headers ); + membuffer_destroy( &headers ); membuffer_destroy( &filename ); } diff --git a/upnp/src/genlib/net/uri/uri.c b/upnp/src/genlib/net/uri/uri.c index b855106..ca3cdc1 100644 --- a/upnp/src/genlib/net/uri/uri.c +++ b/upnp/src/genlib/net/uri/uri.c @@ -367,16 +367,20 @@ free_URL_list( URL_list * list ) * uri_type *in ; URI object * * Description : Function useful in debugging for printing a parsed uri. -* Compiled out with DBGONLY macro. * * Return : void ; * * Note : ************************************************************************/ -DBGONLY( void print_uri( uri_type * in ) { - print_token( &in->scheme ); - print_token( &in->hostport.text ); - print_token( &in->pathquery ); print_token( &in->fragment );} ) +#ifdef DEBUG +void print_uri( uri_type *in ) +{ + print_token( &in->scheme ); + print_token( &in->hostport.text ); + print_token( &in->pathquery ); + print_token( &in->fragment ); +} +#endif /************************************************************************ * Function : print_token @@ -385,20 +389,23 @@ DBGONLY( void print_uri( uri_type * in ) { * token * in ; token * * Description : Function useful in debugging for printing a token. -* Compiled out with DBGONLY macro. * * Return : void ; * * Note : ************************************************************************/ -DBGONLY( void print_token( token * in ) { - int i = 0; - printf( "Token Size : %"PRIzu"\n\'", in->size ); - for( i = 0; i < in->size; i++ ) { - putchar( in->buff[i] );} - putchar( '\'' ); putchar( '\n' );} - - ) +#ifdef DEBUG +void print_token(token * in) +{ + int i = 0; + printf( "Token Size : %"PRIzu"\n\'", in->size ); + for( i = 0; i < in->size; i++ ) { + putchar( in->buff[i] ); + } + putchar( '\'' ); + putchar( '\n' ); +} +#endif /************************************************************************ * Function : token_string_casecmp @@ -417,8 +424,10 @@ DBGONLY( void print_token( token * in ) { * * Note : ************************************************************************/ - int token_string_casecmp( token * in1, - char *in2 ) { +int token_string_casecmp( + token * in1, + char *in2 ) +{ int in2_length = strlen( in2 ); if( in1->size != in2_length ) @@ -790,9 +799,8 @@ remove_dots( char *in, return UPNP_E_OUTOF_MEMORY; Segments[0] = NULL; - DBGONLY( UpnpPrintf - ( UPNP_ALL, API, __FILE__, __LINE__, - "REMOVE_DOTS: before: %s\n", in ) ); + UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, + "REMOVE_DOTS: before: %s\n", in ); while( ( copyFrom < max ) && ( *copyFrom != '?' ) && ( *copyFrom != '#' ) ) { @@ -837,9 +845,8 @@ remove_dots( char *in, } ( *copyTo ) = 0; free( Segments ); - DBGONLY( UpnpPrintf - ( UPNP_ALL, API, __FILE__, __LINE__, - "REMOVE_DOTS: after: %s\n", in ) ); + UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, + "REMOVE_DOTS: after: %s\n", in ); return UPNP_E_SUCCESS; } diff --git a/upnp/src/genlib/service_table/service_table.c b/upnp/src/genlib/service_table/service_table.c index 0a8520b..5ad33d7 100644 --- a/upnp/src/genlib/service_table/service_table.c +++ b/upnp/src/genlib/service_table/service_table.c @@ -443,31 +443,47 @@ FindServiceControlURLPath( service_table * table, * * Note : ************************************************************************/ -DBGONLY( void printService( service_info * service, Dbg_Level level, - Dbg_Module module ) { - if( service ) { - if( service->serviceType ) - UpnpPrintf( level, module, __FILE__, __LINE__, - "serviceType: %s\n", service->serviceType ); - if( service->serviceId ) - UpnpPrintf( level, module, __FILE__, __LINE__, "serviceId: %s\n", - service->serviceId ); if( service->SCPDURL ) - UpnpPrintf( level, module, __FILE__, __LINE__, "SCPDURL: %s\n", - service->SCPDURL ); if( service->controlURL ) - UpnpPrintf( level, module, __FILE__, __LINE__, "controlURL: %s\n", - service->controlURL ); if( service->eventURL ) - UpnpPrintf( level, module, __FILE__, __LINE__, "eventURL: %s\n", - service->eventURL ); if( service->UDN ) - UpnpPrintf( level, module, __FILE__, __LINE__, "UDN: %s\n\n", - service->UDN ); if( service->active ) - UpnpPrintf( level, module, __FILE__, __LINE__, - "Service is active\n" ); - else - UpnpPrintf( level, module, __FILE__, __LINE__, - "Service is inactive\n" );} - } - - ) +#ifdef DEBUG +void printService( + service_info *service, + Dbg_Level level, + Dbg_Module module ) +{ + if( service ) { + if( service->serviceType ) { + UpnpPrintf( level, module, __FILE__, __LINE__, + "serviceType: %s\n", service->serviceType ); + } + if( service->serviceId ) { + UpnpPrintf( level, module, __FILE__, __LINE__, + "serviceId: %s\n", service->serviceId ); + } + if( service->SCPDURL ) { + UpnpPrintf( level, module, __FILE__, __LINE__, + "SCPDURL: %s\n", service->SCPDURL ); + } + if( service->controlURL ) { + UpnpPrintf( level, module, __FILE__, __LINE__, + "controlURL: %s\n", service->controlURL ); + } + if( service->eventURL ) { + UpnpPrintf( level, module, __FILE__, __LINE__, + "eventURL: %s\n", service->eventURL ); + } + if( service->UDN ) { + UpnpPrintf( level, module, __FILE__, __LINE__, + "UDN: %s\n\n", service->UDN ); + } + if( service->active ) { + UpnpPrintf( level, module, __FILE__, __LINE__, + "Service is active\n" ); + } else { + UpnpPrintf( level, module, __FILE__, __LINE__, + "Service is inactive\n" ); + } + } +} +#endif /************************************************************************ * Function : printServiceList @@ -484,36 +500,48 @@ DBGONLY( void printService( service_info * service, Dbg_Level level, * * Note : ************************************************************************/ - DBGONLY( void printServiceList( service_info * service, - Dbg_Level level, - Dbg_Module module ) { - while( service ) { - if( service->serviceType ) - UpnpPrintf( level, module, __FILE__, __LINE__, - "serviceType: %s\n", service->serviceType ); - if( service->serviceId ) - UpnpPrintf( level, module, __FILE__, __LINE__, - "serviceId: %s\n", service->serviceId ); - if( service->SCPDURL ) - UpnpPrintf( level, module, __FILE__, __LINE__, - "SCPDURL: %s\n", service->SCPDURL ); - if( service->controlURL ) - UpnpPrintf( level, module, __FILE__, __LINE__, - "controlURL: %s\n", service->controlURL ); - if( service->eventURL ) - UpnpPrintf( level, module, __FILE__, __LINE__, - "eventURL: %s\n", service->eventURL ); - if( service->UDN ) - UpnpPrintf( level, module, __FILE__, __LINE__, "UDN: %s\n\n", - service->UDN ); if( service->active ) - UpnpPrintf( level, module, __FILE__, __LINE__, - "Service is active\n" ); - else - UpnpPrintf( level, module, __FILE__, __LINE__, - "Service is inactive\n" ); - service = service->next;} - } - ) +#ifdef DEBUG +void printServiceList( + service_info * service, + Dbg_Level level, + Dbg_Module module ) +{ + while( service ) { + if( service->serviceType ) { + UpnpPrintf( level, module, __FILE__, __LINE__, + "serviceType: %s\n", service->serviceType ); + } + if( service->serviceId ) { + UpnpPrintf( level, module, __FILE__, __LINE__, + "serviceId: %s\n", service->serviceId ); + } + if( service->SCPDURL ) { + UpnpPrintf( level, module, __FILE__, __LINE__, + "SCPDURL: %s\n", service->SCPDURL ); + } + if( service->controlURL ) { + UpnpPrintf( level, module, __FILE__, __LINE__, + "controlURL: %s\n", service->controlURL ); + } + if( service->eventURL ) { + UpnpPrintf( level, module, __FILE__, __LINE__, + "eventURL: %s\n", service->eventURL ); + } + if( service->UDN ) { + UpnpPrintf( level, module, __FILE__, __LINE__, + "UDN: %s\n\n", service->UDN ); + } + if( service->active ) { + UpnpPrintf( level, module, __FILE__, __LINE__, + "Service is active\n" ); + } else { + UpnpPrintf( level, module, __FILE__, __LINE__, + "Service is inactive\n" ); + } + service = service->next; + } +} +#endif /************************************************************************ * Function : printServiceTable @@ -531,15 +559,18 @@ DBGONLY( void printService( service_info * service, Dbg_Level level, * * Note : ************************************************************************/ - DBGONLY( void printServiceTable( service_table * table, - Dbg_Level level, - Dbg_Module module ) { - UpnpPrintf( level, module, __FILE__, __LINE__, - "URL_BASE: %s\n", table->URLBase ); - UpnpPrintf( level, module, __FILE__, __LINE__, - "Services: \n" ); - printServiceList( table->serviceList, level, module );} - ) +#ifdef DEBUG +void printServiceTable( + service_table * table, + Dbg_Level level, + Dbg_Module module ) +{ + UpnpPrintf( level, module, __FILE__, __LINE__, + "URL_BASE: %s\n", table->URLBase ); + UpnpPrintf( level, module, __FILE__, __LINE__, + "Services: \n" ); + printServiceList( table->serviceList, level, module );} +#endif /************************************************************************ * Function : freeService @@ -554,7 +585,7 @@ DBGONLY( void printService( service_info * service, Dbg_Level level, * * Note : ************************************************************************/ - void freeService( service_info * in ) +void freeService( service_info * in ) { if( in ) { if( in->serviceType ) @@ -849,12 +880,10 @@ getServiceList( IXML_Node * node, ( ! ( current->controlURL = resolve_rel_url( URLBase, tempDOMString ) ) ) ) { - DBGONLY( UpnpPrintf - ( UPNP_INFO, GENA, __FILE__, __LINE__, - "BAD OR MISSING CONTROL URL" ) ); - DBGONLY( UpnpPrintf - ( UPNP_INFO, GENA, __FILE__, __LINE__, - "CONTROL URL SET TO NULL IN SERVICE INFO" ) ); + UpnpPrintf( UPNP_INFO, GENA, __FILE__, __LINE__, + "BAD OR MISSING CONTROL URL" ); + UpnpPrintf( UPNP_INFO, GENA, __FILE__, __LINE__, + "CONTROL URL SET TO NULL IN SERVICE INFO" ); current->controlURL = NULL; fail = 0; } @@ -870,12 +899,10 @@ getServiceList( IXML_Node * node, ( ! ( current->eventURL = resolve_rel_url( URLBase, tempDOMString ) ) ) ) { - DBGONLY( UpnpPrintf - ( UPNP_INFO, GENA, __FILE__, __LINE__, - "BAD OR MISSING EVENT URL" ) ); - DBGONLY( UpnpPrintf - ( UPNP_INFO, GENA, __FILE__, __LINE__, - "EVENT URL SET TO NULL IN SERVICE INFO" ) ); + UpnpPrintf( UPNP_INFO, GENA, __FILE__, __LINE__, + "BAD OR MISSING EVENT URL" ); + UpnpPrintf( UPNP_INFO, GENA, __FILE__, __LINE__, + "EVENT URL SET TO NULL IN SERVICE INFO" ); current->eventURL = NULL; fail = 0; } diff --git a/upnp/src/inc/config.h b/upnp/src/inc/config.h index 279d2d3..57688ba 100644 --- a/upnp/src/inc/config.h +++ b/upnp/src/inc/config.h @@ -304,27 +304,6 @@ -/** @name DBGONLY - The {\bf DBGONLY} macro allows code to be marked so that it - is only included in the DEBUG build and not the release. To - use this macro, put the code inside of the parentheses: - - {\tt DBGONLY(int i;)} - - This will cause a declaration of the integer {\tt i} only - in the debug build. - */ - -//@{ -#ifdef DEBUG -# define DBGONLY(x) x -#else -# define DBGONLY(x) -#endif -//@} - - - #undef EXCLUDE_WEB_SERVER #undef EXCLUDE_MINISERVER #ifdef INTERNAL_WEB_SERVER @@ -368,4 +347,3 @@ //@} #endif - diff --git a/upnp/src/inc/gena.h b/upnp/src/inc/gena.h index d41cd87..69de0ed 100644 --- a/upnp/src/inc/gena.h +++ b/upnp/src/inc/gena.h @@ -89,25 +89,26 @@ #define DEFAULT_TIMEOUT 1801 - extern ithread_mutex_t GlobalClientSubscribeMutex; -//Lock the subscription +// Lock the subscription #define SubscribeLock() \ - DBGONLY(UpnpPrintf(UPNP_INFO,GENA,__FILE__,__LINE__, \ - "Trying Subscribe Lock")); \ + UpnpPrintf(UPNP_INFO, GENA, __FILE__, __LINE__, \ + "Trying Subscribe Lock"); \ ithread_mutex_lock(&GlobalClientSubscribeMutex); \ - DBGONLY(UpnpPrintf(UPNP_INFO,GENA,__FILE__,__LINE__,"Subscribe Lock");) + UpnpPrintf(UPNP_INFO, GENA, __FILE__, __LINE__, \ + "Subscribe Lock"); -//Unlock the subscription +// Unlock the subscription #define SubscribeUnlock() \ - DBGONLY(UpnpPrintf(UPNP_INFO,GENA,__FILE__,__LINE__, \ - "Trying Subscribe UnLock")); \ + UpnpPrintf(UPNP_INFO, GENA, __FILE__, __LINE__, \ + "Trying Subscribe UnLock"); \ ithread_mutex_unlock(&GlobalClientSubscribeMutex); \ - DBGONLY(UpnpPrintf(UPNP_INFO,GENA,__FILE__,__LINE__,"Subscribe UnLock");) + UpnpPrintf(UPNP_INFO, GENA, __FILE__, __LINE__, \ + "Subscribe UnLock"); -//Structure to send NOTIFY message to all subscribed control points +// Structure to send NOTIFY message to all subscribed control points typedef struct NOTIFY_THREAD_STRUCT { char * headers; DOMString propertySet; diff --git a/upnp/src/inc/http_client.h b/upnp/src/inc/http_client.h index 16eb4aa..fe57b34 100644 --- a/upnp/src/inc/http_client.h +++ b/upnp/src/inc/http_client.h @@ -214,37 +214,101 @@ EXTERN_C ssize_t readLine(int fd, char *out, int max, int *timeout); EXTERN_C int remove_dots(char * in, int size); -DBGONLY(EXTERN_C void print_http_request(http_message - *message,Dbg_Level DLevel, - Dbg_Module Module,char *DbgFileName, - int DbgLineNo);); +#ifdef DEBUG +EXTERN_C void print_http_request( + http_message *message, + Dbg_Level DLevel, + Dbg_Module Module, + char *DbgFileName, + int DbgLineNo); +#else +static inline void print_http_request( + http_message *message, + Dbg_Level DLevel, + Dbg_Module Module, + char *DbgFileName, + int DbgLineNo) {} +#endif -DBGONLY(EXTERN_C void print_http_response(http_message *message, - Dbg_Level DLevel, - Dbg_Module Module,char *DbgFileName, - int DbgLineNo);); +#ifdef DEBUG +EXTERN_C void print_http_response( + http_message *message, + Dbg_Level DLevel, + Dbg_Module Module, + char *DbgFileName, + int DbgLineNo); +#else +static inline void print_http_response( + http_message *message, + Dbg_Level DLevel, + Dbg_Module Module, + char *DbgFileName, + int DbgLineNo) {} +#endif -DBGONLY(EXTERN_C void print_token( token * in, - Dbg_Level DLevel, - Dbg_Module Module, - char *DbgFileName, - int DbgLineNo);); +#ifdef DEBUG +EXTERN_C void print_token( + token *in, + Dbg_Level DLevel, + Dbg_Module Module, + char *DbgFileName, + int DbgLineNo); +#else +static inline void print_token( + token *in, + Dbg_Level DLevel, + Dbg_Module Module, + char *DbgFileName, + int DbgLineNo) {} +#endif -DBGONLY(EXTERN_C void print_status_line(http_status *in, - Dbg_Level DLevel, - Dbg_Module Module, - char *DbgFileName, - int DbgLineNo);); +#ifdef DEBUG +EXTERN_C void print_status_line( + http_status *in, + Dbg_Level DLevel, + Dbg_Module Module, + char *DbgFileName, + int DbgLineNo); +#else +static inline void print_status_line( + http_status *in, + Dbg_Level DLevel, + Dbg_Module Module, + char *DbgFileName, + int DbgLineNo) {} +#endif -DBGONLY(EXTERN_C void print_request_line(http_request *in, - Dbg_Level DLevel, - Dbg_Module Module, - char *DbgFileName,int DbgLineNo)); +#ifdef DEBUG +EXTERN_C void print_request_line( + http_request *in, + Dbg_Level DLevel, + Dbg_Module Module, + char *DbgFileName, + int DbgLineNo); +#else +static inline void print_request_line( + http_request *in, + Dbg_Level DLevel, + Dbg_Module Module, + char *DbgFileName, + int DbgLineNo) {} +#endif -DBGONLY(EXTERN_C void print_uri( uri_type *in, - Dbg_Level DLevel, - Dbg_Module Module, - char *DbgFileName, - int DbgLineNo);); +#ifdef DEBUG +EXTERN_C void print_uri( + uri_type *in, + Dbg_Level DLevel, + Dbg_Module Module, + char *DbgFileName, + int DbgLineNo); +#else +static inline void print_uri( + uri_type *in, + Dbg_Level DLevel, + Dbg_Module Module, + char *DbgFileName, + int DbgLineNo) {} +#endif #endif + diff --git a/upnp/src/inc/httpparser.h b/upnp/src/inc/httpparser.h index 95ef6a9..181b113 100644 --- a/upnp/src/inc/httpparser.h +++ b/upnp/src/inc/httpparser.h @@ -478,17 +478,21 @@ int raw_find_str( IN memptr* raw_value, IN const char* str ); const char* method_to_str( IN http_method_t method ); /************************************************************************ -* Function: print_http_headers -* -* Parameters: -* http_message_t* hmsg ; HTTP Message object -* -* Description: -* -* Returns: -* void +* Function: print_http_headers +* +* Parameters: +* http_message_t* hmsg ; HTTP Message object +* +* Description: +* +* Returns: +* void ************************************************************************/ -void print_http_headers( IN http_message_t* hmsg ); +#ifdef DEBUG +void print_http_headers( IN http_message_t *hmsg ); +#else +static inline void print_http_headers( IN http_message_t *hmsg ) {} +#endif #ifdef __cplusplus } // extern "C" @@ -496,3 +500,4 @@ void print_http_headers( IN http_message_t* hmsg ); #endif // GENLIB_NET_HTTP_HTTPPARSER_H + diff --git a/upnp/src/inc/service_table.h b/upnp/src/inc/service_table.h index 2b857ce..a41ae57 100644 --- a/upnp/src/inc/service_table.h +++ b/upnp/src/inc/service_table.h @@ -47,7 +47,7 @@ extern "C" { #define SID_SIZE 41 -DEVICEONLY( +#ifdef INCLUDE_DEVICE_APIS typedef struct SUBSCRIPTION { Upnp_SID sid; @@ -263,9 +263,17 @@ service_info * FindServiceControlURLPath( service_table *table, * * Note : ************************************************************************/ -DBGONLY(void printService(service_info *service,Dbg_Level - level, - Dbg_Module module)); +#ifdef DEBUG +void printService( + service_info *service, + Dbg_Level level, + Dbg_Module module); +#else +static inline void printService( + service_info *service, + Dbg_Level level, + Dbg_Module module) {} +#endif /************************************************************************ * Function : printServiceList @@ -282,8 +290,17 @@ DBGONLY(void printService(service_info *service,Dbg_Level * * Note : ************************************************************************/ -DBGONLY(void printServiceList(service_info *service, - Dbg_Level level, Dbg_Module module)); +#ifdef DEBUG +void printServiceList( + service_info *service, + Dbg_Level level, + Dbg_Module module); +#else +static inline void printServiceList( + service_info *service, + Dbg_Level level, + Dbg_Module module) {} +#endif /************************************************************************ * Function : printServiceTable @@ -301,9 +318,17 @@ DBGONLY(void printServiceList(service_info *service, * * Note : ************************************************************************/ -DBGONLY(void printServiceTable(service_table * - table,Dbg_Level - level,Dbg_Module module)); +#ifdef DEBUG +void printServiceTable( + service_table *table, + Dbg_Level level, + Dbg_Module module); +#else +static inline void printServiceTable( + service_table *table, + Dbg_Level level, + Dbg_Module module) {} +#endif /************************************************************************ * Function : freeService @@ -451,10 +476,11 @@ int getSubElement(const char *element_name, IXML_Node *node, IXML_Node **out); -) /* DEVICEONLY */ +#endif /* INCLUDE_DEVICE_APIS */ #ifdef __cplusplus } #endif #endif /* _SERVICE_TABLE */ + diff --git a/upnp/src/inc/upnpapi.h b/upnp/src/inc/upnpapi.h index a1ef4e6..a0b9287 100644 --- a/upnp/src/inc/upnpapi.h +++ b/upnp/src/inc/upnpapi.h @@ -96,8 +96,16 @@ struct Handle_Info extern ithread_mutex_t GlobalHndMutex; Upnp_Handle_Type GetHandleInfo(int Hnd, struct Handle_Info **HndInfo); -#define HandleLock() DBGONLY(UpnpPrintf(UPNP_INFO,API,__FILE__,__LINE__,"Trying Lock")); ithread_mutex_lock(&GlobalHndMutex); DBGONLY(UpnpPrintf(UPNP_INFO,API,__FILE__,__LINE__,"LOCK")); -#define HandleUnlock() DBGONLY(UpnpPrintf(UPNP_INFO,API,__FILE__,__LINE__,"Trying Unlock")); ithread_mutex_unlock(&GlobalHndMutex); DBGONLY(UpnpPrintf(UPNP_INFO,API,__FILE__,__LINE__,"Unlock")); +#define HandleLock() \ + UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__, "Trying Lock"); \ + ithread_mutex_lock(&GlobalHndMutex); \ + UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__, "LOCK"); + +#define HandleUnlock() \ + UpnpPrintf(UPNP_INFO, API,__FILE__, __LINE__, "Trying Unlock"); \ + ithread_mutex_unlock(&GlobalHndMutex); \ + UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__, "Unlock"); + Upnp_Handle_Type GetClientHandleInfo(int *client_handle_out, struct Handle_Info **HndInfo); Upnp_Handle_Type GetDeviceHandleInfo(int *device_handle_out, diff --git a/upnp/src/inc/uri.h b/upnp/src/inc/uri.h index 229d653..2b2b1ca 100644 --- a/upnp/src/inc/uri.h +++ b/upnp/src/inc/uri.h @@ -182,13 +182,16 @@ void free_URL_list(URL_list * list); * uri_type *in ; URI object * * Description : Function useful in debugging for printing a parsed uri. -* Compiled out with DBGONLY macro. * * Return : void ; * * Note : ************************************************************************/ -DBGONLY(void print_uri( uri_type *in);) +#ifdef DEBUG +void print_uri(uri_type *in); +#else +static inline void print_uri(uri_type *in) {} +#endif /************************************************************************ * Function : print_token @@ -197,13 +200,16 @@ DBGONLY(void print_uri( uri_type *in);) * token * in ; * * Description : Function useful in debugging for printing a token. -* Compiled out with DBGONLY macro. * * Return : void ; * * Note : ************************************************************************/ -void print_token( token * in); +#ifdef DEBUG +void print_token(token *in); +#else +static inline void print_token(token * in) {} +#endif /************************************************************************ * Function : token_string_casecmp diff --git a/upnp/src/soap/soap_ctrlpt.c b/upnp/src/soap/soap_ctrlpt.c index 5d7966f..fb41a36 100644 --- a/upnp/src/soap/soap_ctrlpt.c +++ b/upnp/src/soap/soap_ctrlpt.c @@ -619,11 +619,10 @@ SoapSendAction( IN char *action_url, err_code = UPNP_E_OUTOF_MEMORY; // default error - DBGONLY( UpnpPrintf( UPNP_INFO, SOAP, __FILE__, __LINE__, - "Inside SoapSendAction():" ); - ) - // init - membuffer_init( &request ); + UpnpPrintf( UPNP_INFO, SOAP, __FILE__, __LINE__, + "Inside SoapSendAction():" ); + // init + membuffer_init( &request ); membuffer_init( &responsename ); // print action @@ -642,12 +641,12 @@ SoapSendAction( IN char *action_url, goto error_handler; } - DBGONLY( UpnpPrintf( UPNP_INFO, SOAP, __FILE__, __LINE__, - "path=%.*s, hostport=%.*s\n", - (int)url.pathquery.size, - url.pathquery.buff, - (int)url.hostport.text.size, - url.hostport.text.buff ); ) + UpnpPrintf( UPNP_INFO, SOAP, __FILE__, __LINE__, + "path=%.*s, hostport=%.*s\n", + (int)url.pathquery.size, + url.pathquery.buff, + (int)url.hostport.text.size, + url.hostport.text.buff ); xml_start_len = strlen( xml_start ); xml_end_len = strlen( xml_end ); @@ -771,11 +770,10 @@ SoapSendActionEx( IN char *action_url, err_code = UPNP_E_OUTOF_MEMORY; // default error - DBGONLY( UpnpPrintf( UPNP_INFO, SOAP, __FILE__, __LINE__, - "Inside SoapSendActionEx():" ); - ) - // init - membuffer_init( &request ); + UpnpPrintf( UPNP_INFO, SOAP, __FILE__, __LINE__, + "Inside SoapSendActionEx():" ); + // init + membuffer_init( &request ); membuffer_init( &responsename ); // header string @@ -799,12 +797,12 @@ SoapSendActionEx( IN char *action_url, goto error_handler; } - DBGONLY( UpnpPrintf( UPNP_INFO, SOAP, __FILE__, __LINE__, - "path=%.*s, hostport=%.*s\n", - (int)url.pathquery.size, - url.pathquery.buff, - (int)url.hostport.text.size, - url.hostport.text.buff ); ) + UpnpPrintf( UPNP_INFO, SOAP, __FILE__, __LINE__, + "path=%.*s, hostport=%.*s\n", + (int)url.pathquery.size, + url.pathquery.buff, + (int)url.hostport.text.size, + url.hostport.text.buff ); xml_start_len = strlen( xml_start ); xml_body_start_len = strlen( xml_body_start ); diff --git a/upnp/src/soap/soap_device.c b/upnp/src/soap/soap_device.c index f8b6350..0b89c7e 100644 --- a/upnp/src/soap/soap_device.c +++ b/upnp/src/soap/soap_device.c @@ -344,11 +344,10 @@ get_action_node( IN IXML_Document * TempDoc, int ret_code = -1; // error, by default IXML_NodeList *nl = NULL; - DBGONLY( UpnpPrintf( UPNP_INFO, SOAP, __FILE__, __LINE__, - "get_action_node(): node name =%s\n ", NodeName ); - ) + UpnpPrintf( UPNP_INFO, SOAP, __FILE__, __LINE__, + "get_action_node(): node name =%s\n ", NodeName ); - * RespNode = NULL; + *RespNode = NULL; // Got the Envelope node here EnvpNode = ixmlNode_getFirstChild( ( IXML_Node * ) TempDoc ); @@ -738,15 +737,15 @@ send_action_response( IN SOCKINFO * info, xml_response, strlen( xml_response ), end_body, strlen( end_body ) ); - DBGONLY( if( ret_code != 0 ) { - UpnpPrintf( UPNP_INFO, SOAP, __FILE__, __LINE__, - "Failed to send response: err code = %d\n", - ret_code );} - ) + if( ret_code != 0 ) { + UpnpPrintf( UPNP_INFO, SOAP, __FILE__, __LINE__, + "Failed to send response: err code = %d\n", + ret_code ); + } - err_code = 0; + err_code = 0; - error_handler: +error_handler: ixmlFreeDOMString( xml_response ); membuffer_destroy( &headers ); if( err_code != 0 ) { @@ -814,14 +813,13 @@ get_var_name( IN IXML_Document * TempDoc, Temp = ixmlNode_getNodeValue( VarNode ); linecopy( VarName, Temp ); - DBGONLY( UpnpPrintf( UPNP_INFO, SOAP, __FILE__, __LINE__, - "Received query for variable name %s\n", - VarName ); - ) + UpnpPrintf( UPNP_INFO, SOAP, __FILE__, __LINE__, + "Received query for variable name %s\n", + VarName ); - ret_val = 0; // success + ret_val = 0; // success - error_handler: +error_handler: return ret_val; } @@ -878,8 +876,8 @@ handle_query_variable( IN SOCKINFO * info, // send event soap_event_callback( UPNP_CONTROL_GET_VAR_REQUEST, &variable, cookie ); - DBGONLY( UpnpPrintf( UPNP_INFO, SOAP, __FILE__, __LINE__, - "Return from callback for var request\n" ) ); + UpnpPrintf( UPNP_INFO, SOAP, __FILE__, __LINE__, + "Return from callback for var request\n" ); // validate, and handle result if( variable.CurrentVal == NULL ) { @@ -968,8 +966,8 @@ handle_invoke_action( IN SOCKINFO * info, action.ErrCode = UPNP_E_SUCCESS; action.CtrlPtIPAddr = info->foreign_ip_addr; - DBGONLY( UpnpPrintf( UPNP_INFO, SOAP, __FILE__, __LINE__, - "Calling Callback\n" ) ); + UpnpPrintf( UPNP_INFO, SOAP, __FILE__, __LINE__, + "Calling Callback\n" ); soap_event_callback( UPNP_CONTROL_ACTION_REQUEST, &action, cookie ); diff --git a/upnp/src/ssdp/ssdp_ctrlpt.c b/upnp/src/ssdp/ssdp_ctrlpt.c index bd1fc9b..ff63e63 100644 --- a/upnp/src/ssdp/ssdp_ctrlpt.c +++ b/upnp/src/ssdp/ssdp_ctrlpt.c @@ -536,11 +536,10 @@ SearchByTarget( IN int Mx, if( ReqBuf == NULL ) return UPNP_E_OUTOF_MEMORY; - DBGONLY( UpnpPrintf( UPNP_INFO, SSDP, __FILE__, __LINE__, - ">>> SSDP SEND >>>\n%s\n", ReqBuf ); - ) + UpnpPrintf( UPNP_INFO, SSDP, __FILE__, __LINE__, + ">>> SSDP SEND >>>\n%s\n", ReqBuf ); - timeTillRead = Mx; + timeTillRead = Mx; if( timeTillRead < MIN_SEARCH_TIME ) { timeTillRead = MIN_SEARCH_TIME; @@ -589,26 +588,23 @@ SearchByTarget( IN int Mx, if( select( gSsdpReqSocket + 1, NULL, &wrSet, NULL, NULL ) == UPNP_SOCKETERROR ) { - DBGONLY( if( errno == EBADF ) { - UpnpPrintf( UPNP_INFO, SSDP, __FILE__, __LINE__, - "SSDP_LIB :RequestHandler:An invalid file descriptor" - " was givenin one of the sets. \n" );} - else - if( errno == EINTR ) { - UpnpPrintf( UPNP_INFO, SSDP, __FILE__, __LINE__, - "SSDP_LIB :RequestHandler: A non blocked " - "signal was caught. \n" );} - else - if( errno == EINVAL ) { - UpnpPrintf( UPNP_INFO, SSDP, __FILE__, __LINE__, - "SSDP_LIB :RequestHandler: n is negative. \n" );} - else - if( errno == ENOMEM ) { - UpnpPrintf( UPNP_INFO, SSDP, __FILE__, __LINE__, - "SSDP_LIB : RequestHandler:select was unable to " - "allocate memory for internal tables.\n" );} - ) -shutdown( gSsdpReqSocket, SD_BOTH ); + if( errno == EBADF ) { + UpnpPrintf( UPNP_INFO, SSDP, __FILE__, __LINE__, + "SSDP_LIB :RequestHandler:An invalid file descriptor" + " was givenin one of the sets. \n" ); + } else if( errno == EINTR ) { + UpnpPrintf( UPNP_INFO, SSDP, __FILE__, __LINE__, + "SSDP_LIB :RequestHandler: A non blocked " + "signal was caught. \n" ); + } else if( errno == EINVAL ) { + UpnpPrintf( UPNP_INFO, SSDP, __FILE__, __LINE__, + "SSDP_LIB :RequestHandler: n is negative. \n" ); + } else if( errno == ENOMEM ) { + UpnpPrintf( UPNP_INFO, SSDP, __FILE__, __LINE__, + "SSDP_LIB : RequestHandler:select was unable to " + "allocate memory for internal tables.\n" ); + } + shutdown( gSsdpReqSocket, SD_BOTH ); UpnpCloseSocket( gSsdpReqSocket ); free( ReqBuf ); return UPNP_E_INTERNAL_ERROR; diff --git a/upnp/src/ssdp/ssdp_device.c b/upnp/src/ssdp/ssdp_device.c index 967a7d1..79efdc1 100644 --- a/upnp/src/ssdp/ssdp_device.c +++ b/upnp/src/ssdp/ssdp_device.c @@ -43,22 +43,22 @@ #include "unixutil.h" #ifdef WIN32 - #include - #include + #include + #include #endif -#define MSGTYPE_SHUTDOWN 0 +#define MSGTYPE_SHUTDOWN 0 #define MSGTYPE_ADVERTISEMENT 1 -#define MSGTYPE_REPLY 2 +#define MSGTYPE_REPLY 2 /************************************************************************ -* Function : advertiseAndReplyThread -* -* Parameters: -* IN void *data: Structure containing the search request +* Function : advertiseAndReplyThread * -* Description: -* This function is a wrapper function to reply the search request +* Parameters: +* IN void *data: Structure containing the search request +* +* Description: +* This function is a wrapper function to reply the search request * coming from the control point. * * Returns: void * @@ -81,11 +81,11 @@ advertiseAndReplyThread( IN void *data ) } /************************************************************************ -* Function : ssdp_handle_device_request -* +* Function : ssdp_handle_device_request +* * Parameters: -* IN http_message_t* hmsg: SSDP search request from the control point -* IN struct sockaddr_in* dest_addr: The address info of control point +* IN http_message_t* hmsg: SSDP search request from the control point +* IN struct sockaddr_in* dest_addr: The address info of control point * * Description: * This function handles the search request. It do the sanity checks of @@ -135,30 +135,30 @@ ssdp_handle_device_request( IN http_message_t * hmsg, return; // bad ST header } - HandleLock( ); + HandleLock(); // device info if( GetDeviceHandleInfo( &handle, &dev_info ) != HND_DEVICE ) { - HandleUnlock( ); + HandleUnlock(); return; // no info found } maxAge = dev_info->MaxAge; - HandleUnlock( ); + HandleUnlock(); - DBGONLY( UpnpPrintf( UPNP_PACKET, API, __FILE__, __LINE__, - "ssdp_handle_device_request with Cmd %d SEARCH\n", - event.Cmd ); - UpnpPrintf( UPNP_PACKET, API, __FILE__, __LINE__, - "MAX-AGE = %d\n", maxAge ); - UpnpPrintf( UPNP_PACKET, API, __FILE__, __LINE__, - "MX = %d\n", event.Mx ); - UpnpPrintf( UPNP_PACKET, API, __FILE__, __LINE__, - "DeviceType = %s\n", event.DeviceType ); - UpnpPrintf( UPNP_PACKET, API, __FILE__, __LINE__, - "DeviceUuid = %s\n", event.UDN ); - UpnpPrintf( UPNP_PACKET, API, __FILE__, __LINE__, - "ServiceType = %s\n", event.ServiceType ); ) + UpnpPrintf( UPNP_PACKET, API, __FILE__, __LINE__, + "ssdp_handle_device_request with Cmd %d SEARCH\n", + event.Cmd ); + UpnpPrintf( UPNP_PACKET, API, __FILE__, __LINE__, + "MAX-AGE = %d\n", maxAge ); + UpnpPrintf( UPNP_PACKET, API, __FILE__, __LINE__, + "MX = %d\n", event.Mx ); + UpnpPrintf( UPNP_PACKET, API, __FILE__, __LINE__, + "DeviceType = %s\n", event.DeviceType ); + UpnpPrintf( UPNP_PACKET, API, __FILE__, __LINE__, + "DeviceUuid = %s\n", event.UDN ); + UpnpPrintf( UPNP_PACKET, API, __FILE__, __LINE__, + "ServiceType = %s\n", event.ServiceType ); - threadArg = + threadArg = ( SsdpSearchReply * ) malloc( sizeof( SsdpSearchReply ) ); if( threadArg == NULL ) { @@ -185,7 +185,7 @@ ssdp_handle_device_request( IN http_message_t * hmsg, mx = 1; } - replyTime = rand( ) % mx; + replyTime = rand() % mx; TimerThreadSchedule( &gTimerThread, replyTime, REL_SEC, &job, SHORT_TERM, NULL ); @@ -220,9 +220,9 @@ NewRequestHandler( IN struct sockaddr_in *DestAddr, ReplySock = socket( AF_INET, SOCK_DGRAM, 0 ); if( ReplySock == UPNP_INVALID_SOCKET ) { - DBGONLY( UpnpPrintf( UPNP_INFO, SSDP, __FILE__, __LINE__, - "SSDP_LIB: New Request Handler:" - "Error in socket operation !!!\n" ) ); + UpnpPrintf( UPNP_INFO, SSDP, __FILE__, __LINE__, + "SSDP_LIB: New Request Handler:" + "Error in socket operation !!!\n" ); return UPNP_E_OUTOF_SOCKET; } @@ -247,13 +247,12 @@ NewRequestHandler( IN struct sockaddr_in *DestAddr, // So, NUM_COPY has been changed from 2 to 1. NumCopy = 0; while( NumCopy < NUM_COPY ) { - DBGONLY( UpnpPrintf( UPNP_INFO, SSDP, __FILE__, __LINE__, - ">>> SSDP SEND >>>\n%s\n", - *( RqPacket + Index ) ); - ) - rc = sendto( ReplySock, *( RqPacket + Index ), - strlen( *( RqPacket + Index ) ), - 0, ( struct sockaddr * )DestAddr, socklen ); + UpnpPrintf( UPNP_INFO, SSDP, __FILE__, __LINE__, + ">>> SSDP SEND >>>\n%s\n", + *( RqPacket + Index ) ); + rc = sendto( ReplySock, *( RqPacket + Index ), + strlen( *( RqPacket + Index ) ), + 0, ( struct sockaddr * )DestAddr, socklen ); imillisleep( SSDP_PAUSE ); ++NumCopy; } @@ -388,11 +387,10 @@ DeviceAdvertisement( IN char *DevType, char *msgs[3]; int ret_code; - DBGONLY( UpnpPrintf( UPNP_INFO, SSDP, __FILE__, __LINE__, - "In function SendDeviceAdvertisemenrt\n" ); - ) + UpnpPrintf( UPNP_INFO, SSDP, __FILE__, __LINE__, + "In function SendDeviceAdvertisemenrt\n" ); - DestAddr.sin_family = AF_INET; + DestAddr.sin_family = AF_INET; DestAddr.sin_addr.s_addr = inet_addr( SSDP_IP ); DestAddr.sin_port = htons( SSDP_PORT ); @@ -783,11 +781,11 @@ DeviceShutdown( IN char *DevType, Mil_Usn, Location, Duration, &msgs[0] ); } - DBGONLY( UpnpPrintf( UPNP_INFO, SSDP, __FILE__, __LINE__, - "In function DeviceShutdown\n" ); ) - // both root and sub-devices need to send these two messages - CreateServicePacket( MSGTYPE_SHUTDOWN, Udn, Udn, - Location, Duration, &msgs[1] ); + UpnpPrintf( UPNP_INFO, SSDP, __FILE__, __LINE__, + "In function DeviceShutdown\n" ); + // both root and sub-devices need to send these two messages + CreateServicePacket( MSGTYPE_SHUTDOWN, Udn, Udn, + Location, Duration, &msgs[1] ); sprintf( Mil_Usn, "%s::%s", Udn, DevType ); CreateServicePacket( MSGTYPE_SHUTDOWN, DevType, Mil_Usn, diff --git a/upnp/src/ssdp/ssdp_server.c b/upnp/src/ssdp/ssdp_server.c index fd3ee8a..d5da2b9 100644 --- a/upnp/src/ssdp/ssdp_server.c +++ b/upnp/src/ssdp/ssdp_server.c @@ -91,14 +91,14 @@ CLIENTONLY( SOCKET gSsdpReqSocket = 0; * Returns: int * UPNP_E_SUCCESS if successful else appropriate error ***************************************************************************/ - int AdvertiseAndReply( IN int AdFlag, - IN UpnpDevice_Handle Hnd, - IN enum SsdpSearchType SearchType, - IN struct sockaddr_in *DestAddr, - IN char *DeviceType, - IN char *DeviceUDN, - IN char *ServiceType, - int Exp ) +int AdvertiseAndReply( IN int AdFlag, + IN UpnpDevice_Handle Hnd, + IN enum SsdpSearchType SearchType, + IN struct sockaddr_in *DestAddr, + IN char *DeviceType, + IN char *DeviceUDN, + IN char *ServiceType, + int Exp ) { int i, j; @@ -115,14 +115,14 @@ CLIENTONLY( SOCKET gSsdpReqSocket = 0; const DOMString tmpStr; char SERVER[200]; - DBGONLY( const DOMString dbgStr; - UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, - "Inside AdvertiseAndReply with AdFlag = %d\n", - AdFlag ); ) + const DOMString dbgStr; + UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, + "Inside AdvertiseAndReply with AdFlag = %d\n", + AdFlag ); - HandleLock( ); + HandleLock(); if( GetHandleInfo( Hnd, &SInfo ) != HND_DEVICE ) { - HandleUnlock( ); + HandleUnlock(); return UPNP_E_INVALID_HANDLE; } defaultExp = SInfo->MaxAge; @@ -139,24 +139,20 @@ CLIENTONLY( SOCKET gSsdpReqSocket = 0; // parse the device list and send advertisements/replies for( i = 0;; i++ ) { - DBGONLY( UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, - "Entering new device list with i = %d\n\n", - i ); - ) + UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, + "Entering new device list with i = %d\n\n", i ); - tmpNode = ixmlNodeList_item( SInfo->DeviceList, i ); + tmpNode = ixmlNodeList_item( SInfo->DeviceList, i ); if( tmpNode == NULL ) { - DBGONLY( UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, - "Exiting new device list with i = %d\n\n", - i ); - ) - break; + UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, + "Exiting new device list with i = %d\n\n", i ); + break; } - DBGONLY( dbgStr = ixmlNode_getNodeName( tmpNode ); + dbgStr = ixmlNode_getNodeName( tmpNode ); UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, - "Extracting device type once for %s\n", - dbgStr ); ) + "Extracting device type once for %s\n", + dbgStr ); // extract device type ixmlNodeList_free( nodeList ); nodeList = NULL; @@ -167,15 +163,14 @@ CLIENTONLY( SOCKET gSsdpReqSocket = 0; continue; } - DBGONLY( dbgStr = ixmlNode_getNodeName( tmpNode ); - UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, - "Extracting UDN for %s\n", dbgStr ); ) + dbgStr = ixmlNode_getNodeName( tmpNode ); + UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, + "Extracting UDN for %s\n", dbgStr ); - DBGONLY( UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, - "Extracting device type\n" ); - ) + UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, + "Extracting device type\n" ); - tmpNode2 = ixmlNodeList_item( nodeList, 0 ); + tmpNode2 = ixmlNodeList_item( nodeList, 0 ); if( tmpNode2 == NULL ) { continue; } @@ -184,11 +179,10 @@ CLIENTONLY( SOCKET gSsdpReqSocket = 0; continue; } - DBGONLY( UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, - "Extracting device type \n" ); - ) + UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, + "Extracting device type \n" ); - tmpStr = ixmlNode_getNodeValue( textNode ); + tmpStr = ixmlNode_getNodeValue( textNode ); if( tmpStr == NULL ) { continue; } @@ -198,47 +192,41 @@ CLIENTONLY( SOCKET gSsdpReqSocket = 0; continue; } - DBGONLY( UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, - "Extracting device type = %s\n", devType ); - if( tmpNode == NULL ) { - UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, - "TempNode is NULL\n" );} - dbgStr = ixmlNode_getNodeName( tmpNode ); - UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, - "Extracting UDN for %s\n", dbgStr ); ) - // extract UDN - ixmlNodeList_free( nodeList ); + UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, + "Extracting device type = %s\n", devType ); + if( tmpNode == NULL ) { + UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, + "TempNode is NULL\n" ); + } + dbgStr = ixmlNode_getNodeName( tmpNode ); + UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, + "Extracting UDN for %s\n", dbgStr ); + // extract UDN + ixmlNodeList_free( nodeList ); nodeList = NULL; nodeList = ixmlElement_getElementsByTagName( ( IXML_Element * ) tmpNode, "UDN" ); if( nodeList == NULL ) { - - DBGONLY( UpnpPrintf( UPNP_CRITICAL, API, __FILE__, - __LINE__, "UDN not found!!!\n" ); - ) + UpnpPrintf( UPNP_CRITICAL, API, __FILE__, + __LINE__, "UDN not found!!!\n" ); continue; } tmpNode2 = ixmlNodeList_item( nodeList, 0 ); if( tmpNode2 == NULL ) { - - DBGONLY( UpnpPrintf( UPNP_CRITICAL, API, __FILE__, - __LINE__, "UDN not found!!!\n" ); - ) - continue; + UpnpPrintf( UPNP_CRITICAL, API, __FILE__, + __LINE__, "UDN not found!!!\n" ); + continue; } textNode = ixmlNode_getFirstChild( tmpNode2 ); if( textNode == NULL ) { - - DBGONLY( UpnpPrintf( UPNP_CRITICAL, API, __FILE__, - __LINE__, "UDN not found!!!\n" ); - ) - continue; + UpnpPrintf( UPNP_CRITICAL, API, __FILE__, + __LINE__, "UDN not found!!!\n" ); + continue; } tmpStr = ixmlNode_getNodeValue( textNode ); if( tmpStr == NULL ) { - DBGONLY( UpnpPrintf( UPNP_CRITICAL, API, __FILE__, __LINE__, - "UDN not found!!!!\n" ); - ) + UpnpPrintf( UPNP_CRITICAL, API, __FILE__, __LINE__, + "UDN not found!!!!\n" ); continue; } strcpy( UDNstr, tmpStr ); @@ -246,9 +234,8 @@ CLIENTONLY( SOCKET gSsdpReqSocket = 0; continue; } - DBGONLY( UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, - "Sending UDNStr = %s \n", UDNstr ); - ) + UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, + "Sending UDNStr = %s \n", UDNstr ); if( AdFlag ) { // send the device advertisement if( AdFlag == 1 ) { @@ -278,22 +265,16 @@ CLIENTONLY( SOCKET gSsdpReqSocket = 0; { if( DeviceUDN != NULL && strlen( DeviceUDN ) != 0 ) { if( strcasecmp( DeviceUDN, UDNstr ) ) { - DBGONLY( UpnpPrintf - ( UPNP_INFO, API, __FILE__, - __LINE__, - "DeviceUDN=%s and search " - "UDN=%s did not match\n", - UDNstr, DeviceUDN ); - ) + UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, + "DeviceUDN=%s and search " + "UDN=%s did not match\n", + UDNstr, DeviceUDN ); break; } else { - DBGONLY( UpnpPrintf - ( UPNP_INFO, API, __FILE__, - __LINE__, - "DeviceUDN=%s and search " - "UDN=%s MATCH\n", UDNstr, - DeviceUDN ); - ) + UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, + "DeviceUDN=%s and search " + "UDN=%s MATCH\n", UDNstr, + DeviceUDN ); SendReply( DestAddr, devType, 0, UDNstr, SInfo->DescURL, defaultExp, 0 ); @@ -306,25 +287,18 @@ CLIENTONLY( SOCKET gSsdpReqSocket = 0; if( !strncasecmp ( DeviceType, devType, strlen( DeviceType ) ) ) { - DBGONLY( UpnpPrintf - ( UPNP_INFO, API, __FILE__, __LINE__, - "DeviceType=%s and search devType=%s MATCH\n", - devType, DeviceType ); - ) - SendReply( DestAddr, devType, 0, UDNstr, - SInfo->DescURL, defaultExp, 1 ); - } - - DBGONLY( - else - UpnpPrintf( UPNP_INFO, API, __FILE__, - __LINE__, - "DeviceType=%s and search devType=%s" - " DID NOT MATCH\n", - devType, DeviceType ); - ) - - break; + UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, + "DeviceType=%s and search devType=%s MATCH\n", + devType, DeviceType ); + SendReply( DestAddr, devType, 0, UDNstr, + SInfo->DescURL, defaultExp, 1 ); + } else { + UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, + "DeviceType=%s and search devType=%s" + " DID NOT MATCH\n", + devType, DeviceType ); + } + break; } default: break; @@ -332,11 +306,10 @@ CLIENTONLY( SOCKET gSsdpReqSocket = 0; } // send service advertisements for services corresponding // to the same device - DBGONLY( UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, - "Sending service Advertisement\n" ); - ) + UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, + "Sending service Advertisement\n" ); - tmpNode = ixmlNodeList_item( SInfo->ServiceList, i ); + tmpNode = ixmlNodeList_item( SInfo->ServiceList, i ); if( tmpNode == NULL ) { continue; } @@ -345,10 +318,9 @@ CLIENTONLY( SOCKET gSsdpReqSocket = 0; nodeList = ixmlElement_getElementsByTagName( ( IXML_Element * ) tmpNode, "service" ); if( nodeList == NULL ) { - DBGONLY( UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, - "Service not found 3\n" ); - ) - continue; + UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, + "Service not found 3\n" ); + continue; } for( j = 0;; j++ ) { tmpNode = ixmlNodeList_item( nodeList, j ); @@ -357,15 +329,11 @@ CLIENTONLY( SOCKET gSsdpReqSocket = 0; ixmlNodeList_free( tmpNodeList ); tmpNodeList = NULL; - tmpNodeList = ixmlElement_getElementsByTagName( ( IXML_Element - * ) tmpNode, - "serviceType" ); - + tmpNodeList = ixmlElement_getElementsByTagName( + ( IXML_Element *)tmpNode, "serviceType" ); if( tmpNodeList == NULL ) { - DBGONLY( UpnpPrintf - ( UPNP_CRITICAL, API, __FILE__, __LINE__, - "ServiceType not found \n" ); - ) + UpnpPrintf( UPNP_CRITICAL, API, __FILE__, __LINE__, + "ServiceType not found \n" ); continue; } tmpNode2 = ixmlNodeList_item( tmpNodeList, 0 ); @@ -386,19 +354,16 @@ CLIENTONLY( SOCKET gSsdpReqSocket = 0; continue; } - DBGONLY( UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, - "ServiceType = %s\n", servType ); - ) - if( AdFlag ) { + UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, + "ServiceType = %s\n", servType ); + if( AdFlag ) { if( AdFlag == 1 ) { ServiceAdvertisement( UDNstr, servType, SInfo->DescURL, Exp ); - } else // AdFlag == -1 - { + } else { // AdFlag == -1 ServiceShutdown( UDNstr, servType, SInfo->DescURL, Exp ); } - } else { switch ( SearchType ) { case SSDP_ALL: @@ -433,11 +398,10 @@ CLIENTONLY( SOCKET gSsdpReqSocket = 0; ixmlNodeList_free( nodeList ); nodeList = NULL; } - DBGONLY( UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, - "Exiting AdvertiseAndReply : \n" ); - ) + UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, + "Exiting AdvertiseAndReply : \n" ); - HandleUnlock( ); + HandleUnlock( ); return UPNP_E_SUCCESS; @@ -733,20 +697,18 @@ start_event_handler( void *Data ) if( status == PARSE_FAILURE ) { if( parser->msg.method != HTTPMETHOD_NOTIFY || !parser->valid_ssdp_notify_hack ) { - DBGONLY( UpnpPrintf( UPNP_INFO, SSDP, __FILE__, __LINE__, - "SSDP recvd bad msg code = %d\n", - status ); - ) - // ignore bad msg, or not enuf mem - goto error_handler; + UpnpPrintf( UPNP_INFO, SSDP, __FILE__, __LINE__, + "SSDP recvd bad msg code = %d\n", + status ); + // ignore bad msg, or not enuf mem + goto error_handler; } // valid notify msg } else if( status != PARSE_SUCCESS ) { - DBGONLY( UpnpPrintf( UPNP_INFO, SSDP, __FILE__, __LINE__, - "SSDP recvd bad msg code = %d\n", status ); - ) + UpnpPrintf( UPNP_INFO, SSDP, __FILE__, __LINE__, + "SSDP recvd bad msg code = %d\n", status ); - goto error_handler; + goto error_handler; } // check msg if( !valid_ssdp_msg( &parser->msg ) ) { @@ -863,21 +825,18 @@ readFromSSDPSocket( SOCKET socket ) if( byteReceived > 0 ) { requestBuf[byteReceived] = '\0'; - DBGONLY( UpnpPrintf( UPNP_INFO, SSDP, + UpnpPrintf( UPNP_INFO, SSDP, __FILE__, __LINE__, "Received response !!! " "%s From host %s \n", requestBuf, inet_ntoa( clientAddr.sin_addr ) ); - ) - DBGONLY( UpnpPrintf( UPNP_PACKET, SSDP, - __FILE__, __LINE__, - "Received multicast packet:" - "\n %s\n", requestBuf ); - ) - //add thread pool job to handle request - if( data != NULL ) { + UpnpPrintf( UPNP_PACKET, SSDP, __FILE__, __LINE__, + "Received multicast packet:" + "\n %s\n", requestBuf ); + //add thread pool job to handle request + if( data != NULL ) { data->parser.msg.msg.length += byteReceived; // null-terminate data->parser.msg.msg.buf[byteReceived] = 0; @@ -891,7 +850,6 @@ readFromSSDPSocket( SOCKET socket ) free_ssdp_event_handler_data( data ); } } - } else { free_ssdp_event_handler_data( data ); } @@ -926,9 +884,9 @@ get_ssdp_sockets( MiniServerSockArray * out ) CLIENTONLY( if( ( ssdpReqSock = socket( AF_INET, SOCK_DGRAM, 0 ) ) == UPNP_INVALID_SOCKET ) { - DBGONLY( UpnpPrintf( UPNP_CRITICAL, - SSDP, __FILE__, __LINE__, - "Error in socket operation !!!\n" ); ) + UpnpPrintf( UPNP_CRITICAL, + SSDP, __FILE__, __LINE__, + "Error in socket operation !!!\n" ); return UPNP_E_OUTOF_SOCKET;} setsockopt( ssdpReqSock, IPPROTO_IP, @@ -938,11 +896,10 @@ get_ssdp_sockets( MiniServerSockArray * out ) if( ( ssdpSock = socket( AF_INET, SOCK_DGRAM, 0 ) ) == UPNP_INVALID_SOCKET ) { - DBGONLY( UpnpPrintf( UPNP_CRITICAL, - SSDP, __FILE__, __LINE__, - "Error in socket operation !!!\n" ); - ) - CLIENTONLY( shutdown( ssdpReqSock, SD_BOTH ) ); + UpnpPrintf( UPNP_CRITICAL, + SSDP, __FILE__, __LINE__, + "Error in socket operation !!!\n" ); + CLIENTONLY( shutdown( ssdpReqSock, SD_BOTH ) ); CLIENTONLY( UpnpCloseSocket( ssdpReqSock ) ); return UPNP_E_OUTOF_SOCKET; } @@ -951,11 +908,10 @@ get_ssdp_sockets( MiniServerSockArray * out ) if( setsockopt( ssdpSock, SOL_SOCKET, SO_REUSEADDR, ( char * )&onOff, sizeof( onOff ) ) != 0 ) { - DBGONLY( UpnpPrintf( UPNP_CRITICAL, - SSDP, __FILE__, __LINE__, - "Error in set reuse addr !!!\n" ); - ) - CLIENTONLY( shutdown( ssdpReqSock, SD_BOTH ) ); + UpnpPrintf( UPNP_CRITICAL, + SSDP, __FILE__, __LINE__, + "Error in set reuse addr !!!\n" ); + CLIENTONLY( shutdown( ssdpReqSock, SD_BOTH ) ); CLIENTONLY( UpnpCloseSocket( ssdpReqSock ) ); shutdown( ssdpSock, SD_BOTH ); UpnpCloseSocket( ssdpSock ); @@ -966,11 +922,10 @@ get_ssdp_sockets( MiniServerSockArray * out ) if( setsockopt( ssdpSock, SOL_SOCKET, SO_REUSEPORT, ( char * )&onOff, sizeof( onOff ) ) != 0 ) { - DBGONLY( UpnpPrintf( UPNP_CRITICAL, - SSDP, __FILE__, __LINE__, - "Error in set reuse port !!!\n" ); - ) - CLIENTONLY( shutdown( ssdpReqSock, SD_BOTH ) ); + UpnpPrintf( UPNP_CRITICAL, + SSDP, __FILE__, __LINE__, + "Error in set reuse port !!!\n" ); + CLIENTONLY( shutdown( ssdpReqSock, SD_BOTH ) ); CLIENTONLY( UpnpCloseSocket( ssdpReqSock ) ); shutdown( ssdpSock, SD_BOTH ); UpnpCloseSocket( ssdpSock ); @@ -986,10 +941,9 @@ get_ssdp_sockets( MiniServerSockArray * out ) if( bind ( ssdpSock, ( struct sockaddr * )&ssdpAddr, sizeof( ssdpAddr ) ) != 0 ) { - DBGONLY( UpnpPrintf - ( UPNP_CRITICAL, SSDP, __FILE__, __LINE__, - "Error in binding !!!\n" ); - ) + UpnpPrintf( UPNP_CRITICAL, + SSDP, __FILE__, __LINE__, + "Error in binding !!!\n" ); shutdown( ssdpSock, SD_BOTH ); UpnpCloseSocket( ssdpSock ); CLIENTONLY( shutdown( ssdpReqSock, SD_BOTH ) ); @@ -1003,11 +957,10 @@ get_ssdp_sockets( MiniServerSockArray * out ) if( setsockopt( ssdpSock, IPPROTO_IP, IP_ADD_MEMBERSHIP, ( char * )&ssdpMcastAddr, sizeof( struct ip_mreq ) ) != 0 ) { - DBGONLY( UpnpPrintf - ( UPNP_CRITICAL, SSDP, __FILE__, __LINE__, - "Error in joining" " multicast group !!!\n" ); - ) - shutdown( ssdpSock, SD_BOTH ); + UpnpPrintf( UPNP_CRITICAL, + SSDP, __FILE__, __LINE__, + "Error in joining" " multicast group !!!\n" ); + shutdown( ssdpSock, SD_BOTH ); CLIENTONLY( shutdown( ssdpReqSock, SD_BOTH ) ); UpnpCloseSocket( ssdpSock ); CLIENTONLY( UpnpCloseSocket( ssdpReqSock ) ); @@ -1019,8 +972,8 @@ get_ssdp_sockets( MiniServerSockArray * out ) addr.s_addr = inet_addr(LOCAL_HOST); if (setsockopt(ssdpSock, IPPROTO_IP, IP_MULTICAST_IF, (char *)&addr, sizeof addr) != 0) { - DBGONLY(UpnpPrintf( UPNP_INFO, SSDP, __FILE__, __LINE__, - "Couldn't set multicast interface.\n" )); + UpnpPrintf( UPNP_INFO, SSDP, __FILE__, __LINE__, + "Couldn't set multicast interface.\n" ); /* This is probably not a critical error, so let's continue. */ } @@ -1029,11 +982,10 @@ get_ssdp_sockets( MiniServerSockArray * out ) IP_MULTICAST_TTL, &ttl, sizeof( ttl ) ); if( setsockopt( ssdpSock, SOL_SOCKET, SO_BROADCAST, ( char * )&option, sizeof( option ) ) != 0 ) { - DBGONLY( UpnpPrintf( UPNP_CRITICAL, - SSDP, __FILE__, __LINE__, - "Error in setting broadcast !!!\n" ); - ) - shutdown( ssdpSock, SD_BOTH ); + UpnpPrintf( UPNP_CRITICAL, + SSDP, __FILE__, __LINE__, + "Error in setting broadcast !!!\n" ); + shutdown( ssdpSock, SD_BOTH ); CLIENTONLY( shutdown( ssdpReqSock, SD_BOTH ) ); UpnpCloseSocket( ssdpSock ); CLIENTONLY( UpnpCloseSocket( ssdpReqSock ) ); diff --git a/upnp/src/urlconfig/urlconfig.c b/upnp/src/urlconfig/urlconfig.c index 621e23f..ec6de8b 100644 --- a/upnp/src/urlconfig/urlconfig.c +++ b/upnp/src/urlconfig/urlconfig.c @@ -168,11 +168,10 @@ calc_descURL( IN const char *ipPortStr, strcat( descURL, ipPortStr ); strcat( descURL, alias ); - DBGONLY( UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, - "desc url: %s\n", descURL ); - ) + UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, + "desc url: %s\n", descURL ); - return UPNP_E_SUCCESS; + return UPNP_E_SUCCESS; } /************************************************************************ @@ -408,18 +407,16 @@ configure_urlbase( INOUT IXML_Document * doc, goto error_handler; } - DBGONLY( UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, - "desc url: %s\n", docURL ); - ) - DBGONLY( UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, - "doc = %s\n", xml_str ); - ) - // store in web server - err_code = + UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, + "desc url: %s\n", docURL ); + UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, + "doc = %s\n", xml_str ); + // store in web server + err_code = web_server_set_alias( new_alias, xml_str, strlen( xml_str ), last_modified ); - error_handler: +error_handler: free( root_path ); free( new_alias );