1 /* 2 3 W3C Sample Code Library libwww Debug Information and General Purpose 4 Macros 5 6 7 ! 8 Debug Information and General Purpose Macros 9 ! 10 */ 11 12 /* 13 ** (c) COPYRIGHT MIT 1995. 14 ** Please first read the full copyright statement in the file COPYRIGH. 15 */ 16 17 /* 18 19 This module is a part of the W3C Sample 20 Code Library. See also the system dependent file 21 sysdep module for system specific information. 22 */ 23 24 #ifndef HTUTILS_H 25 #define HTUTILS_H 26 27 #ifdef __cplusplus 28 extern "C" { 29 #endif 30 31 /* 32 . 33 Destination for User Print Messages 34 . 35 36 You can send print messages to the user to various destinations 37 depending on the type of your application. By default, on Unix the 38 messages are sent to stdout using 39 fprintf. If we are on MSWindows and have a windows 40 applications then register a HTPrintCallback 41 function. This is done with HTPrint_setCallback. It tells 42 HTPrint to call a HTPrintCallback. If 43 HTDEBUG 44 is not defined then don't do any of the above. 45 */ 46 47 typedef int HTPrintCallback(const char * fmt, va_list pArgs); 48 extern void HTPrint_setCallback(HTPrintCallback * pCall); 49 extern HTPrintCallback * HTPrint_getCallback(void); 50 51 extern int HTPrint(const char * fmt, ...); 52 53 /* 54 . 55 Debug Message Control 56 . 57 58 This is the global flag for setting the WWWTRACE options. 59 The verbose mode is no longer a simple boolean but a bit field so that it 60 is possible to see parts of the output messages. 61 */ 62 63 #if defined(NODEBUG) || defined(NDEBUG) || defined(_NDEBUG) 64 #undef HTDEBUG 65 #else 66 #ifndef HTDEBUG 67 #define HTDEBUG 1 68 #endif /* HTDEBUG */ 69 #endif 70 71 /* 72 ( 73 C Preprocessor defines 74 ) 75 76 Make sure that the following macros are defined 77 */ 78 79 #ifndef __FILE__ 80 #define __FILE__ "" 81 #endif 82 83 #ifndef __LINE__ 84 #define __LINE__ 0L 85 #endif 86 87 /* 88 ( 89 Definition of the Global Trace Flag 90 ) 91 92 The global trace flag variable is available everywhere. 93 */ 94 95 #ifdef HTDEBUG 96 #ifdef WWW_WIN_DLL 97 extern int * WWW_TraceFlag; /* In DLLs, we need the indirection */ 98 #define WWWTRACE (*WWW_TraceFlag) 99 #else 100 extern unsigned int WWW_TraceFlag; /* Global flag for all W3 trace */ 101 #define WWWTRACE (WWW_TraceFlag) 102 #endif /* WWW_WIN_DLL */ 103 #else 104 #define WWWTRACE 0 105 #endif /* HTDEBUG */ 106 107 /* 108 ( 109 Select which Trace Messages to show 110 ) 111 112 Libwww has a huge set of trace messages and it is therefor a good idea to 113 be able to select which ones to see for any particular trace. An easy way 114 to set this is using the funtion 115 HTSetTraceMessageMask. The WWWTRACE 116 define outputs messages if verbose mode is active according to the following 117 rules: 118 */ 119 120 typedef enum _HTTraceFlags { 121 SHOW_UTIL_TRACE = 0x1, 122 SHOW_APP_TRACE = 0x2, 123 SHOW_CACHE_TRACE = 0x4, 124 SHOW_SGML_TRACE = 0x8, 125 SHOW_BIND_TRACE = 0x10, 126 SHOW_THREAD_TRACE = 0x20, 127 SHOW_STREAM_TRACE = 0x40, 128 SHOW_PROTOCOL_TRACE = 0x80, 129 SHOW_MEM_TRACE = 0x100, 130 SHOW_URI_TRACE = 0x200, 131 SHOW_AUTH_TRACE = 0x400, 132 SHOW_ANCHOR_TRACE = 0x800, 133 SHOW_PICS_TRACE = 0x1000, 134 SHOW_CORE_TRACE = 0x2000, 135 SHOW_MUX_TRACE = 0x4000, 136 SHOW_SQL_TRACE = 0x8000, 137 SHOW_XML_TRACE = 0x10000, 138 SHOW_ALL_TRACE = (int) 0xFFFFFFFF 139 } HTTraceFlags; 140 141 /* 142 143 The flags are made so that they can serve as a group flag for correlated 144 trace messages, e.g. showing messages for SGML and HTML at the same time. 145 */ 146 147 #define UTIL_TRACE (WWWTRACE & SHOW_UTIL_TRACE) 148 #define APP_TRACE (WWWTRACE & SHOW_APP_TRACE) 149 #define CACHE_TRACE (WWWTRACE & SHOW_CACHE_TRACE) 150 #define SGML_TRACE (WWWTRACE & SHOW_SGML_TRACE) 151 #define BIND_TRACE (WWWTRACE & SHOW_BIND_TRACE) 152 #define THD_TRACE (WWWTRACE & SHOW_THREAD_TRACE) 153 #define STREAM_TRACE (WWWTRACE & SHOW_STREAM_TRACE) 154 #define PROT_TRACE (WWWTRACE & SHOW_PROTOCOL_TRACE) 155 #define MEM_TRACE (WWWTRACE & SHOW_MEM_TRACE) 156 #define URI_TRACE (WWWTRACE & SHOW_URI_TRACE) 157 #define AUTH_TRACE (WWWTRACE & SHOW_AUTH_TRACE) 158 #define ANCH_TRACE (WWWTRACE & SHOW_ANCHOR_TRACE) 159 #define PICS_TRACE (WWWTRACE & SHOW_PICS_TRACE) 160 #define CORE_TRACE (WWWTRACE & SHOW_CORE_TRACE) 161 #define MUX_TRACE (WWWTRACE & SHOW_MUX_TRACE) 162 #define SQL_TRACE (WWWTRACE & SHOW_SQL_TRACE) 163 #define XML_TRACE (WWWTRACE & SHOW_XML_TRACE) 164 #define ALL_TRACE (WWWTRACE & SHOW_ALL_TRACE) 165 166 /* 167 ( 168 Destination for Trace Messages 169 ) 170 171 You can send trace messages to various destinations depending on the type 172 of your application. By default, on Unix the messages are sent to 173 stderr using fprintf. If we are on MSWindows and 174 have a windows applications then register a HTTraceCallback 175 function. This is done with HTTrace_setCallback. It tells 176 HTTrace to call a HTTraceCallback. If 177 HTDEBUG is not defined then don't do any of the above. 178 */ 179 180 typedef int HTTraceCallback(const char * fmt, va_list pArgs); 181 extern void HTTrace_setCallback(HTTraceCallback * pCall); 182 extern HTTraceCallback * HTTrace_getCallback(void); 183 184 /* 185 186 The HTTRACE macro uses "_" as parameter separater 187 instead of ",". This enables us to use a single macro instead 188 of a macro for each number of arguments which we consider a more elegant 189 and flexible solution. The implication is, however, that we can't have variables 190 that start or end with an "_" if they are to be used in a trace 191 message. 192 */ 193 194 #ifdef HTDEBUG 195 #undef _ 196 #define _ , 197 #define HTTRACE(TYPE, FMT) \ 198 do { if (TYPE) HTTrace(FMT); } while (0); 199 extern int HTTrace(const char * fmt, ...); 200 #else 201 #define HTTRACE(TYPE, FMT) /* empty */ 202 #endif /* HTDEBUG */ 203 204 /* 205 ( 206 Data Trace Logging 207 ) 208 209 A similar mechanism exists for logging data, except that is adds a data and 210 length argument to the trace call. Again, you can register your own callbacks 211 if need be. 212 */ 213 214 typedef int HTTraceDataCallback(char * data, size_t len, char * fmt, va_list pArgs); 215 extern void HTTraceData_setCallback(HTTraceDataCallback * pCall); 216 extern HTTraceDataCallback * HTTraceData_getCallback(void); 217 218 /* 219 220 Again we use the same macro expansion mechanism as for HTTrace 221 */ 222 223 #ifdef HTDEBUG 224 #define HTTRACEDATA(DATA, LEN, FMT) HTTraceData((DATA), (LEN), FMT) 225 extern int HTTraceData(char * data, size_t len, char * fmt, ...); 226 #else 227 #define HTTRACEDATA(DATA, LEN, FMT) /* empty */ 228 #endif /* HTDEBUG */ 229 230 /* 231 ( 232 Debug Breaks 233 ) 234 235 Call this function and the program halts. We use the same macro expansion 236 mechanism as for HTTrace 237 */ 238 239 extern void HTDebugBreak(char * file, unsigned long line, const char * fmt, ...); 240 241 #ifdef HTDEBUG 242 #define HTDEBUGBREAK(FMT) HTDebugBreak(__FILE__, __LINE__, FMT) 243 #else 244 #define HTDEBUGBREAK(FMT) /* empty */ 245 #endif /* HTDEBUG */ 246 247 /* 248 . 249 Macros for Function Declarations 250 . 251 252 These function prefixes are used by scripts and other tools and helps figuring 253 out which functions are exported and which are not. See also the 254 libwww style guide. 255 */ 256 257 #define PUBLIC /* Accessible outside this module */ 258 #define PRIVATE static /* Accessible only within this module */ 259 260 /* 261 . 262 Often used Interger Macros 263 . 264 ( 265 Min and Max functions 266 ) 267 */ 268 269 #ifndef HTMIN 270 #define HTMIN(a,b) ((a) <= (b) ? (a) : (b)) 271 #define HTMAX(a,b) ((a) >= (b) ? (a) : (b)) 272 #endif 273 274 /* 275 ( 276 Double abs function 277 ) 278 */ 279 280 #ifndef HTDABS 281 #define HTDABS(a) ((a) < 0.0 ? (-(a)) : (a)) 282 #endif 283 284 /* 285 286 287 . 288 Return Codes for Protocol Modules and Streams 289 . 290 291 Theese are the codes returned from the protocol modules, and the stream modules. 292 Success are (>=0) and failure are (<0) 293 */ 294 295 #define HT_OK 0 /* Generic success */ 296 #define HT_ALL 1 /* Used by Net Manager */ 297 298 #define HT_CONTINUE 100 /* Continue an operation */ 299 #define HT_UPGRADE 101 /* Switching protocols */ 300 301 #define HT_LOADED 200 /* Everything's OK */ 302 #define HT_CREATED 201 /* New object is created */ 303 #define HT_ACCEPTED 202 /* Accepted */ 304 #define HT_NO_DATA 204 /* OK but no data was loaded */ 305 #define HT_RESET_CONTENT 205 /* Reset content */ 306 #define HT_PARTIAL_CONTENT 206 /* Partial Content */ 307 308 #define HT_MULTIPLE_CHOICES 300 /* Multiple choices */ 309 #define HT_PERM_REDIRECT 301 /* Permanent redirection */ 310 #define HT_FOUND 302 /* Found */ 311 #define HT_SEE_OTHER 303 /* See other */ 312 #define HT_NOT_MODIFIED 304 /* Not Modified */ 313 #define HT_USE_PROXY 305 /* Use Proxy */ 314 #define HT_PROXY_REDIRECT 306 /* Proxy Redirect */ 315 #define HT_TEMP_REDIRECT 307 /* Temporary redirect */ 316 317 #define HT_IGNORE 900 /* Ignore this in the Net manager */ 318 #define HT_CLOSED 901 /* The socket was closed */ 319 #define HT_PENDING 902 /* Wait for connection */ 320 #define HT_RELOAD 903 /* If we must reload the document */ 321 322 #define HT_ERROR -1 /* Generic failure */ 323 324 #define HT_NO_ACCESS -401 /* Unauthorized */ 325 #define HT_FORBIDDEN -403 /* Access forbidden */ 326 #define HT_NOT_FOUND -404 /* Not found */ 327 #define HT_NOT_ACCEPTABLE -406 /* Not Acceptable */ 328 #define HT_NO_PROXY_ACCESS -407 /* Proxy Authentication Failed */ 329 #define HT_CONFLICT -409 /* Conflict */ 330 #define HT_LENGTH_REQUIRED -411 /* Length required */ 331 #define HT_PRECONDITION_FAILED -412 /* Precondition failed */ 332 #define HT_TOO_BIG -413 /* Request entity too large */ 333 #define HT_URI_TOO_BIG -414 /* Request-URI too long */ 334 #define HT_UNSUPPORTED -415 /* Unsupported */ 335 #define HT_BAD_RANGE -416 /* Request Range not satisfiable */ 336 #define HT_EXPECTATION_FAILED -417 /* Expectation Failed */ 337 #define HT_REAUTH -418 /* Reauthentication required */ 338 #define HT_PROXY_REAUTH -419 /* Proxy Reauthentication required */ 339 340 #define HT_RETRY -503 /* If service isn't available */ 341 #define HT_BAD_VERSION -505 /* Bad protocol version */ 342 343 #ifdef HT_DAV /* WebDAV Status codes */ 344 #define HT_PROCESSING 102 /* Processing */ 345 #define HT_MULTI_STATUS 207 /* Multi-Status */ 346 #define HT_UNPROCESSABLE -422 /* Unprocessable Entity */ 347 #define HT_LOCKED -423 /* Locked */ 348 #define HT_FAILED_DEPENDENCY -424 /* Failed Dependency */ 349 #define HT_INSUFFICIENT_STORAGE -507 /* Insufficient Storage */ 350 #endif 351 352 #define HT_INTERNAL -900 /* Weird -- should never happen. */ 353 #define HT_WOULD_BLOCK -901 /* If we are in a select */ 354 #define HT_INTERRUPTED -902 /* Note the negative value! */ 355 #define HT_PAUSE -903 /* If we want to pause a stream */ 356 #define HT_RECOVER_PIPE -904 /* Recover pipe line */ 357 #define HT_TIMEOUT -905 /* Connection timeout */ 358 #define HT_NO_HOST -906 /* Can't locate host */ 359 360 /* 361 . 362 Upper- and Lowercase macros 363 . 364 365 The problem here is that toupper(x) is not defined officially unless isupper(x) 366 is. These macros are CERTAINLY needed on #if defined(pyr) || define(mips) 367 or BDSI platforms. For safefy, we make them mandatory. 368 */ 369 370 #ifndef TOLOWER 371 #define TOLOWER(c) tolower((int) (c)) 372 #define TOUPPER(c) toupper((int) (c)) 373 #endif 374 375 /* 376 . 377 Max and Min values for Integers and Floating Point 378 . 379 */ 380 381 #ifdef FLT_EPSILON /* The ANSI C way define */ 382 #define HT_EPSILON FLT_EPSILON 383 #else 384 #define HT_EPSILON 0.00000001 385 #endif 386 387 /* 388 . 389 The local equivalents of CR and LF 390 . 391 392 We can check for these after net ascii text has been converted to the local 393 representation. Similarly, we include them in strings to be sent as net ascii 394 after translation. 395 */ 396 397 #define LF FROMASCII('\012') /* ASCII line feed LOCAL EQUIVALENT */ 398 #define CR FROMASCII('\015') /* Will be converted to ^M for transmission */ 399 400 /* 401 . 402 Library Dynamic Memory Magement 403 . 404 405 The Library has it's own dynamic memory API which is declared in 406 memory management module. 407 */ 408 409 #include "HTMemory.h" 410 411 /* 412 */ 413 414 #ifdef __cplusplus 415 } 416 #endif 417 418 #endif /* HT_UTILS.h */ 419 420 /* 421 422 423 424 @(#) $Id$ 425 426 */ 427