Changeset 961:d95cd3ca9e8d in freeDiameter for include
- Timestamp:
- Mar 7, 2013, 4:09:54 AM (11 years ago)
- Branch:
- default
- Parents:
- 960:f39fa6cd86e0 (diff), 933:04f590da5821 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - Phase:
- public
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
include/freeDiameter/libfdproto.h
r928 r961 110 110 111 111 /* 112 * FUNCTION: fd_log _debug_fstr112 * FUNCTION: fd_log 113 113 * MACRO: fd_log_debug 114 114 * 115 115 * PARAMETERS: 116 * fstr : Stream where the text will be sent (default: stdout)116 * loglevel : Integer, how important the message is 117 117 * format : Same format string as in the printf function 118 118 * ... : Same list as printf 119 119 * 120 120 * DESCRIPTION: 121 * Log internal information for use of developpers only.121 * Write information to log. 122 122 * The format and arguments may contain UTF-8 encoded data. The 123 * output medium (file or console)is expected to support this encoding.123 * output medium is expected to support this encoding. 124 124 * 125 125 * RETURN VALUE: 126 126 * None. 127 127 */ 128 void fd_log_debug_fstr ( FILE * fstr, const char * format, ... ); 129 #define fd_log_debug(format,args...) fd_log_debug_fstr(NULL, format, ## args) 128 void fd_log ( int, const char *, ... ); 129 #define fd_log_debug(format,args...) fd_log(FD_LOG_DEBUG, format, ## args) 130 void fd_log_debug_fstr( FILE *, const char *, ... ); 130 131 131 132 /* these are internal objects of the debug facility, … … 174 175 * 175 176 * PARAMETERS: 176 * fstr : Stream where the text will be sent to (default: stdout)177 * loglevel : priority of the message 177 178 * format : Same format string as in the printf function 178 179 * va_list : Argument list … … 184 185 * int : Success or failure 185 186 */ 186 int fd_log_handler_register ( void (*logger)( const char * format, va_list *args) );187 int fd_log_handler_register ( void (*logger)(int loglevel, const char * format, va_list args) ); 187 188 188 189 /* … … 209 210 #endif /* ASSERT */ 210 211 211 /* levels definitions */ 212 /* log levels definitions */ 213 #define FD_LOG_DEBUG 0 214 #define FD_LOG_ERROR 5 215 216 /* print level definitions */ 212 217 #define NONE 0 /* Display no debug message */ 213 218 #define INFO 1 /* Display errors only */ … … 216 221 #define FCTS 6 /* Display entry parameters of most functions */ 217 222 #define CALL 9 /* Display calls to most functions (with CHECK macros) */ 218 219 /* Increment the debug level for a file at compilation time by defining -DTRACE_LEVEL=FULL for example. */220 #ifndef TRACE_LEVEL221 #define TRACE_LEVEL NONE222 #endif /* TRACE_LEVEL */223 224 /* The level of the file being compiled. */225 static int local_debug_level = TRACE_LEVEL;226 223 227 224 /* A global level, changed by configuration or cmd line for example. Default is INFO (in libfdproto/log.c). */ … … 247 244 /* Boolean for tracing at a certain level */ 248 245 #ifdef DEBUG 249 #define TRACE_BOOL(_level_) ( ((_level_) <= local_debug_level +fd_g_debug_lvl) \246 #define TRACE_BOOL(_level_) ( ((_level_) <= fd_g_debug_lvl) \ 250 247 || (fd_debug_one_function && !strcmp(fd_debug_one_function, __PRETTY_FUNCTION__)) \ 251 248 || (fd_debug_one_file && !strcmp(fd_debug_one_file, __STRIPPED_FILE__) ) ) 252 249 #else /* DEBUG */ 253 #define TRACE_BOOL(_level_) ((_level_) <= local_debug_level +fd_g_debug_lvl)250 #define TRACE_BOOL(_level_) ((_level_) <= fd_g_debug_lvl) 254 251 #endif /* DEBUG */ 255 252 256 253 254 #define STD_TRACE_FMT_STRING "thread %s in %s@%s:%d: " 257 255 /************* 258 256 The general debug macro, each call results in two lines of debug messages (change the macro for more compact output) … … 262 260 #define TRACE_DEBUG(level,format,args... ) { \ 263 261 if ( TRACE_BOOL(level) ) { \ 264 char __buf[25]; \265 262 const char * __thn = ((char *)pthread_getspecific(fd_log_thname) ?: "unnamed"); \ 266 fd_log_debug("\t | tid:%-20s\t%s\tin %s@%s:%d\n" \ 267 "\t%s|%*s" format "\n", \ 268 __thn, fd_log_time(NULL, __buf, sizeof(__buf)), __PRETTY_FUNCTION__, __FILE__, __LINE__,\ 269 (level < FULL)?"@":" ",level, "", ## args); \ 263 fd_log(level, STD_TRACE_FMT_STRING format, \ 264 __thn, __PRETTY_FUNCTION__, __FILE__, __LINE__, ## args); \ 270 265 } \ 271 266 } … … 275 270 if ( TRACE_BOOL(level) ) { \ 276 271 if (fd_g_debug_lvl > FULL) { \ 277 char __buf[25]; \278 272 const char * __thn = ((char *)pthread_getspecific(fd_log_thname) ?: "unnamed"); \ 279 fd_log_debug("\t | tid:%-20s\t%s\tin %s@%s:%d\n" \ 280 "\t%s|%*s" format "\n", \ 281 __thn, fd_log_time(NULL, __buf, sizeof(__buf)), __PRETTY_FUNCTION__, __FILE__, __LINE__,\ 282 (level < FULL)?"@":" ",level, "", ## args); \ 273 fd_log(level, STD_TRACE_FMT_STRING format, \ 274 __thn, __PRETTY_FUNCTION__, __FILE__, __LINE__, ## args); \ 283 275 } else { \ 284 fd_log _debug(format "\n", ## args);\276 fd_log(level, format, ## args); \ 285 277 } \ 286 278 } \ … … 316 308 #define TRACE_DEBUG_BUFFER(level, prefix, buf, bufsz, suffix ) { \ 317 309 if ( TRACE_BOOL(level) ) { \ 318 char __ts[25]; \319 310 int __i; \ 320 311 size_t __sz = (size_t)(bufsz); \ 321 312 uint8_t * __buf = (uint8_t *)(buf); \ 322 313 char * __thn = ((char *)pthread_getspecific(fd_log_thname) ?: "unnamed"); \ 323 fd_log_debug("\t | tid:%-20s\t%s\tin %s@%s:%d\n" \ 324 "\t%s|%*s" prefix , \ 325 __thn, fd_log_time(NULL, __ts, sizeof(__ts)), __PRETTY_FUNCTION__, __FILE__, __LINE__, \ 326 (level < FULL)?"@":" ",level, ""); \ 314 fd_log(level, STD_TRACE_FMT_STRING prefix, \ 315 __thn, __PRETTY_FUNCTION__, __FILE__, __LINE__); \ 327 316 for (__i = 0; __i < __sz; __i++) { \ 328 fd_log _debug("%02.2hhx", __buf[__i]);\317 fd_log(level, "%02.2hhx", __buf[__i]); \ 329 318 } \ 330 fd_log _debug(suffix "\n");\319 fd_log(level, suffix); \ 331 320 } \ 332 321 } … … 345 334 346 335 /* Dump one sockaddr Node information */ 347 #define sSA_DUMP_NODE( sa, flag ) {\336 #define sSA_DUMP_NODE( buf, bufsize, sa, flag ) { \ 348 337 sSA * __sa = (sSA *)(sa); \ 349 338 char __addrbuf[INET6_ADDRSTRLEN]; \ … … 357 346 flag); \ 358 347 if (__rc) \ 359 fd_log_debug("%s", (char *)gai_strerror(__rc)); \348 snprintf(buf, bufsize, "%s", gai_strerror(__rc)); \ 360 349 else \ 361 fd_log_debug("%s", &__addrbuf[0]);\350 snprintf(buf, bufsize, "%s", &__addrbuf[0]); \ 362 351 } else { \ 363 fd_log_debug("(NULL / ANY)");\352 snprintf(buf, bufsize, "(NULL / ANY)"); \ 364 353 } \ 365 354 } 366 355 /* Same but with the port (service) also */ 367 #define sSA_DUMP_NODE_SERV( sa, flag ) {\356 #define sSA_DUMP_NODE_SERV( buf, bufsize, sa, flag ) { \ 368 357 sSA * __sa = (sSA *)(sa); \ 369 358 char __addrbuf[INET6_ADDRSTRLEN]; \ … … 378 367 flag); \ 379 368 if (__rc) \ 380 fd_log_debug("%s", (char *)gai_strerror(__rc));\369 snprintf(buf, bufsize, "%s", gai_strerror(__rc)); \ 381 370 else \ 382 fd_log_debug("[%s]:%s", &__addrbuf[0],&__servbuf[0]);\371 snprintf(buf, bufsize, "[%s]:%s", &__addrbuf[0],&__servbuf[0]); \ 383 372 } else { \ 384 fd_log_debug("(NULL / ANY)");\373 snprintf(buf, bufsize,"(NULL / ANY)"); \ 385 374 } \ 386 375 } … … 389 378 #define TRACE_DEBUG_sSA(level, prefix, sa, flags, suffix ) { \ 390 379 if ( TRACE_BOOL(level) ) { \ 391 char __buf[25];\380 char buf[1024]; \ 392 381 char * __thn = ((char *)pthread_getspecific(fd_log_thname) ?: "unnamed"); \ 393 fd_log_debug("\t | tid:%-20s\t%s\tin %s@%s:%d\n" \ 394 "\t%s|%*s" prefix , \ 395 __thn, fd_log_time(NULL, __buf, sizeof(__buf)), __PRETTY_FUNCTION__, __FILE__, __LINE__,\ 396 (level < FULL)?"@":" ",level, ""); \ 397 sSA_DUMP_NODE_SERV( sa, flags ); \ 398 fd_log_debug(suffix "\n"); \ 382 sSA_DUMP_NODE_SERV(buf, sizeof(buf), sa, flags ); \ 383 fd_log(level, STD_TRACE_FMT_STRING "%s%s%s", \ 384 __thn, __PRETTY_FUNCTION__, __FILE__, __LINE__, prefix, buf, suffix); \ 399 385 } \ 400 386 } … … 418 404 #define TRACE_DEBUG_sSA(level, prefix, sa, flags, suffix ) 419 405 #define TRACE_DEBUG_ERROR(format,args... ) { \ 420 fd_log _debug(format "\n", ## args); \406 fd_log(FD_LOG_ERROR, format, ## args); \ 421 407 } 422 408 #endif /* STRIP_DEBUG_CODE */ … … 1445 1431 1446 1432 ret = fd_dict_search ( dict, DICT_AVP, AVP_BY_NAME_AND_VENDOR, &avpvendorboolean, &avp_sampleboolean, ENOENT); 1433 1434 -- this would also work, but be slower, because it has to search all vendor dictionaries -- 1435 ret = fd_dict_search ( dict, DICT_AVP, AVP_BY_NAME_ALL_VENDORS, "Sample-Boolean", &avp_sampleboolean, ENOENT); 1447 1436 1448 1437 } -
include/freeDiameter/libfdproto.h
r958 r961 3 3 * Author: Sebastien Decugis <sdecugis@freediameter.net> * 4 4 * * 5 * Copyright (c) 201 2, WIDE Project and NICT *5 * Copyright (c) 2013, WIDE Project and NICT * 6 6 * All rights reserved. * 7 7 * *
Note: See TracChangeset
for help on using the changeset viewer.