upnpdebug.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. /*******************************************************************************
  2. *
  3. * Copyright (c) 2000-2003 Intel Corporation
  4. * Copyright (c) 2006 Rémi Turboult <r3mi@users.sourceforge.net>
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are met:
  9. *
  10. * - Redistributions of source code must retain the above copyright notice,
  11. * this list of conditions and the following disclaimer.
  12. * - Redistributions in binary form must reproduce the above copyright notice,
  13. * this list of conditions and the following disclaimer in the documentation
  14. * and/or other materials provided with the distribution.
  15. * - Neither name of Intel Corporation nor the names of its contributors
  16. * may be used to endorse or promote products derived from this software
  17. * without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  22. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
  23. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  24. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  25. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  26. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  27. * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  28. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  29. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. *
  31. ******************************************************************************/
  32. #ifndef UPNP_DEBUG_H
  33. #define UPNP_DEBUG_H
  34. /*!
  35. * \file
  36. */
  37. #include "ThreadPool.h"
  38. #include "upnpconfig.h"
  39. #include "UpnpGlobal.h" /* for UPNP_INLINE */
  40. #include <stdio.h>
  41. #ifdef __cplusplus
  42. extern "C" {
  43. #endif
  44. /*! \name Other debugging features
  45. *
  46. * The UPnP SDK contains other features to aid in debugging.
  47. */
  48. /*@{*/
  49. /*! \name Upnp_LogLevel
  50. * The user has the option to select 4 different types of debugging levels,
  51. * see \c UpnpSetLogLevel.
  52. * The critical level will show only those messages
  53. * which can halt the normal processing of the library, like memory
  54. * allocation errors. The remaining three levels are just for debugging
  55. * purposes. Packet level will display all the incoming and outgoing
  56. * packets that are flowing between the control point and the device.
  57. * Info Level displays the other important operational information
  58. * regarding the working of the library. If the user selects All,
  59. * then the library displays all the debugging information that it has.
  60. * \li \c UPNP_CRITICAL [0]
  61. * \li \c UPNP_PACKET [1]
  62. * \li \c UPNP_INFO [2]
  63. * \li \c UPNP_ALL [3]
  64. */
  65. typedef enum Upnp_Module {
  66. SSDP,
  67. SOAP,
  68. GENA,
  69. TPOOL,
  70. MSERV,
  71. DOM,
  72. API,
  73. HTTP
  74. } Dbg_Module;
  75. /*@{*/
  76. typedef enum Upnp_LogLevel_e {
  77. UPNP_CRITICAL,
  78. UPNP_PACKET,
  79. UPNP_INFO,
  80. UPNP_ALL
  81. } Upnp_LogLevel;
  82. /*@}*/
  83. /*!
  84. * Default log level : see \c Upnp_LogLevel
  85. */
  86. #define UPNP_DEFAULT_LOG_LEVEL UPNP_ALL
  87. /*!
  88. * \brief Initialize the log files.
  89. *
  90. * \return -1 if fails or UPNP_E_SUCCESS if succeeds.
  91. */
  92. #ifdef DEBUG
  93. int UpnpInitLog(void);
  94. #else
  95. static UPNP_INLINE int UpnpInitLog(void)
  96. {
  97. return UPNP_E_SUCCESS;
  98. }
  99. #endif
  100. /*!
  101. * \brief Set the log level (see \c Upnp_LogLevel).
  102. */
  103. #ifdef DEBUG
  104. void UpnpSetLogLevel(
  105. /*! [in] Log level. */
  106. Upnp_LogLevel log_level);
  107. #else
  108. static UPNP_INLINE void UpnpSetLogLevel(Upnp_LogLevel log_level)
  109. {
  110. return;
  111. log_level = log_level;
  112. }
  113. #endif
  114. /*!
  115. * \brief Closes the log files.
  116. */
  117. #ifdef DEBUG
  118. void UpnpCloseLog(void);
  119. #else
  120. static UPNP_INLINE void UpnpCloseLog(void)
  121. {
  122. }
  123. #endif
  124. /*!
  125. * \brief Set the name for error and information files, respectively.
  126. */
  127. #ifdef DEBUG
  128. void UpnpSetLogFileNames(
  129. /*! [in] Name of the error file. */
  130. const char *ErrFileName,
  131. /*! [in] Name of the information file. */
  132. const char *InfoFileName);
  133. #else
  134. static UPNP_INLINE void UpnpSetLogFileNames(const char *ErrFileName,
  135. const char *InfoFileName)
  136. {
  137. return;
  138. ErrFileName = ErrFileName;
  139. InfoFileName = InfoFileName;
  140. }
  141. #endif
  142. /*!
  143. * \brief Check if the module is turned on for debug and returns the file
  144. * descriptor corresponding to the debug level
  145. *
  146. * \return NULL if the module is turn off for debug otheriwse returns the
  147. * right file descriptor.
  148. */
  149. #ifdef DEBUG
  150. FILE *UpnpGetDebugFile(
  151. /*! [in] The level of the debug logging. It will decide whether debug
  152. * statement will go to standard output, or any of the log files. */
  153. Upnp_LogLevel level,
  154. /*! [in] debug will go in the name of this module. */
  155. Dbg_Module module);
  156. #else
  157. static UPNP_INLINE FILE *UpnpGetDebugFile(Upnp_LogLevel level, Dbg_Module module)
  158. {
  159. return NULL;
  160. level = level;
  161. module = module;
  162. }
  163. #endif
  164. /*!
  165. * \brief Returns true if debug output should be done in this module.
  166. *
  167. * \return Nonzero value if true, zero if false.
  168. */
  169. #ifdef DEBUG
  170. int DebugAtThisLevel(
  171. /*! [in] The level of the debug logging. It will decide whether debug
  172. * statement will go to standard output, or any of the log files. */
  173. Upnp_LogLevel DLevel,
  174. /*! [in] Debug will go in the name of this module. */
  175. Dbg_Module Module);
  176. #else
  177. static UPNP_INLINE int DebugAtThisLevel(Upnp_LogLevel DLevel, Dbg_Module Module)
  178. {
  179. return 0;
  180. DLevel = DLevel;
  181. Module = Module;
  182. }
  183. #endif
  184. /*!
  185. * \brief Prints the debug statement either on the standard output or log file
  186. * along with the information from where this debug statement is coming.
  187. */
  188. #ifdef DEBUG
  189. void UpnpPrintf(
  190. /*! [in] The level of the debug logging. It will decide whether debug
  191. * statement will go to standard output, or any of the log files. */
  192. Upnp_LogLevel DLevel,
  193. /*! [in] debug will go in the name of this module. */
  194. Dbg_Module Module,
  195. /*! [in] Name of the file from where debug statement is coming. */
  196. const char *DbgFileName,
  197. /*! [in] Line number of the file from where debug statement is coming. */
  198. int DbgLineNo,
  199. /*! [in] Printf like format specification. */
  200. const char *FmtStr,
  201. /*! [in] Printf like Variable number of arguments that will go in the
  202. * debug statement. */
  203. ...)
  204. #if (__GNUC__ >= 3)
  205. /* This enables printf like format checking by the compiler. */
  206. __attribute__ ((format(__printf__, 5, 6)))
  207. #endif
  208. ;
  209. #else /* DEBUG */
  210. static UPNP_INLINE void UpnpPrintf(Upnp_LogLevel DLevel, Dbg_Module Module,
  211. const char *DbgFileName, int DbgLineNo, const char *FmtStr, ...)
  212. {
  213. return;
  214. DLevel = DLevel;
  215. Module = Module;
  216. DbgFileName = DbgFileName;
  217. DbgLineNo = DbgLineNo;
  218. FmtStr = FmtStr;
  219. }
  220. #endif /* DEBUG */
  221. /*!
  222. * \brief Writes the file name and file number from where debug statement is
  223. * coming to the log file.
  224. */
  225. #ifdef DEBUG
  226. void UpnpDisplayFileAndLine(
  227. /*! [in] File descriptor where line number and file name will be
  228. * written. */
  229. FILE * fd,
  230. /*! [in] Name of the file. */
  231. const char *DbgFileName,
  232. /*! [in] Line number of the file. */
  233. int DbgLineNo);
  234. #else
  235. static UPNP_INLINE void UpnpDisplayFileAndLine(FILE *fd,
  236. const char *DbgFileName, int DbgLineNo)
  237. {
  238. return;
  239. fd = fd;
  240. DbgFileName = DbgFileName;
  241. DbgLineNo = DbgLineNo;
  242. }
  243. #endif
  244. /*!
  245. * \brief Writes the buffer in the file as per the requested banner
  246. */
  247. #ifdef DEBUG
  248. void UpnpDisplayBanner(
  249. /*! [in] file descriptor where the banner will be written. */
  250. FILE * fd,
  251. /*! [in] The buffer that will be written. */
  252. const char **lines,
  253. /*! [in] Size of the buffer. */
  254. size_t size,
  255. /*! [in] This parameter provides the width of the banner. */
  256. size_t starlength);
  257. #else
  258. static UPNP_INLINE void UpnpDisplayBanner(FILE *fd, const char **lines,
  259. size_t size, int starlength)
  260. {
  261. return;
  262. fd = fd;
  263. lines = lines;
  264. size = size;
  265. starlength = starlength;
  266. }
  267. #endif
  268. /*@}*/
  269. #ifdef __cplusplus
  270. }
  271. #endif
  272. #endif /* UPNP_DEBUG_H */