Changeset 226:406f74f0789b in freeDiameter for include
- Timestamp:
- Mar 2, 2010, 11:19:11 AM (14 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
include/freeDiameter/libfreeDiameter.h
r216 r226 78 78 /* DEBUG */ 79 79 /*============================================================*/ 80 #ifndef ASSERT81 #define ASSERT(x) assert(x)82 #endif /* ASSERT */83 80 84 81 /* … … 139 136 char * fd_log_time ( struct timespec * ts, char * buf, size_t len ); 140 137 138 139 /*============================================================*/ 140 /* DEBUG MACROS */ 141 /*============================================================*/ 142 143 #ifndef ASSERT 144 #define ASSERT(x) assert(x) 145 #endif /* ASSERT */ 141 146 142 147 /* levels definitions */ … … 175 180 #define __STRIPPED_FILE__ (file_bname ?: (file_bname = basename(__FILE__))) 176 181 182 177 183 /* Boolean for tracing at a certain level */ 178 184 #ifdef DEBUG … … 184 190 #endif /* DEBUG */ 185 191 186 /* The general debug macro, each call results in two lines of debug messages (change the macro for more compact output) */ 192 193 /************* 194 The general debug macro, each call results in two lines of debug messages (change the macro for more compact output) 195 *************/ 187 196 #define TRACE_DEBUG(level,format,args... ) { \ 188 197 if ( TRACE_BOOL(level) ) { \ … … 196 205 } 197 206 207 /************* 208 Derivatives from this macro 209 ************/ 198 210 /* Helper for function entry -- for very detailed trace of the execution */ 199 211 #define TRACE_ENTRY(_format,_args... ) \ … … 218 230 #endif /* ERRORS_ON_TODO */ 219 231 220 221 /* Macros to check a return value and branch out in case of error. 222 * These macro must be used only when errors are highly improbable, not for expected errors. 223 */ 224 225 /* Check the return value of a system function and execute fallback in case of error */ 226 #define CHECK_SYS_DO( __call__, __fallback__ ) { \ 227 int __ret__; \ 228 TRACE_DEBUG_ALL( "Check SYS: " #__call__ ); \ 229 __ret__ = (__call__); \ 230 if (__ret__ < 0) { \ 231 int __err__ = errno; /* We may handle EINTR here */ \ 232 TRACE_DEBUG(NONE, "ERROR: in '" #__call__ "' :\t%s", strerror(__err__));\ 233 __fallback__; \ 234 } \ 232 /* Trace a binary buffer content */ 233 #define TRACE_DEBUG_BUFFER(level, prefix, buf, bufsz, suffix ) { \ 234 if ( TRACE_BOOL(level) ) { \ 235 char __ts[25]; \ 236 int __i; \ 237 size_t __sz = (size_t)(bufsz); \ 238 uint8_t * __buf = (uint8_t *)(buf); \ 239 char * __thn = ((char *)pthread_getspecific(fd_log_thname) ?: "unnamed"); \ 240 fd_log_debug("\t | tid:%-20s\t%s\tin %s@%s:%d\n" \ 241 "\t%s|%*s" prefix , \ 242 __thn, fd_log_time(NULL, __ts, sizeof(__ts)), __PRETTY_FUNCTION__, __FILE__, __LINE__, \ 243 (level < FULL)?"@":" ",level, ""); \ 244 for (__i = 0; __i < __sz; __i++) { \ 245 fd_log_debug("%02.2hhx", __buf[__i]); \ 246 } \ 247 fd_log_debug(suffix "\n"); \ 248 } \ 235 249 } 236 /* Check the return value of a system function, return error code on error */237 #define CHECK_SYS( __call__ ) { \238 int __ret__; \239 TRACE_DEBUG_ALL( "Check SYS: " #__call__ ); \240 __ret__ = (__call__); \241 if (__ret__ < 0) { \242 int __err__ = errno; /* We may handle EINTR here */ \243 TRACE_DEBUG(NONE, "ERROR: in '" #__call__ "' :\t%s", strerror(__err__));\244 return __err__; \245 } \246 }247 248 /* Check the return value of a POSIX function and execute fallback in case of error or special value */249 #define CHECK_POSIX_DO2( __call__, __speval__, __fallback1__, __fallback2__ ) { \250 int __ret__; \251 TRACE_DEBUG_ALL( "Check POSIX: " #__call__ ); \252 __ret__ = (__call__); \253 if (__ret__ != 0) { \254 if (__ret__ == (__speval__)) { \255 __fallback1__; \256 } else { \257 TRACE_DEBUG(NONE, "ERROR: in '" #__call__ "':\t%s", strerror(__ret__)); \258 __fallback2__; \259 } \260 } \261 }262 263 /* Check the return value of a POSIX function and execute fallback in case of error */264 #define CHECK_POSIX_DO( __call__, __fallback__ ) \265 CHECK_POSIX_DO2( (__call__), 0, , __fallback__ );266 267 /* Check the return value of a POSIX function and return it if error */268 #define CHECK_POSIX( __call__ ) { \269 int __v__; \270 CHECK_POSIX_DO( __v__ = (__call__), return __v__ ); \271 }272 273 /* Check that a memory allocator did not return NULL, otherwise log an error and execute fallback */274 #define CHECK_MALLOC_DO( __call__, __fallback__ ) { \275 void * __ret__; \276 TRACE_DEBUG_ALL( "Check MALLOC: " #__call__ ); \277 __ret__ = (void *)( __call__ ); \278 if (__ret__ == NULL) { \279 int __err__ = errno; \280 TRACE_DEBUG(NONE, "ERROR: in '" #__call__ "':\t%s", strerror(__err__)); \281 __fallback__; \282 } \283 }284 285 /* Check that a memory allocator did not return NULL, otherwise return ENOMEM */286 #define CHECK_MALLOC( __call__ ) \287 CHECK_MALLOC_DO( __call__, return ENOMEM );288 289 290 /* The next macros can be used also for expected errors */291 292 /* Check parameters at function entry, execute fallback on error */293 #define CHECK_PARAMS_DO( __bool__, __fallback__ ) \294 TRACE_DEBUG_ALL( "Check PARAMS: " #__bool__ ); \295 if ( ! (__bool__) ) { \296 TRACE_DEBUG(INFO, "Invalid parameter received in '" #__bool__ "'"); \297 __fallback__; \298 }299 /* Check parameters at function entry, return EINVAL if the boolean is false (similar to assert) */300 #define CHECK_PARAMS( __bool__ ) \301 CHECK_PARAMS_DO( __bool__, return EINVAL );302 303 /* Check the return value of an internal function, log and propagate */304 #define CHECK_FCT_DO( __call__, __fallback__ ) { \305 int __ret__; \306 TRACE_DEBUG_ALL( "Check FCT: " #__call__ ); \307 __ret__ = (__call__); \308 if (__ret__ != 0) { \309 TRACE_DEBUG(INFO, "Error in '" #__call__ "':\t%s", strerror(__ret__)); \310 __fallback__; \311 } \312 }313 /* Check the return value of a function call, return any error code */314 #define CHECK_FCT( __call__ ) { \315 int __v__; \316 CHECK_FCT_DO( __v__ = (__call__), return __v__ ); \317 }318 319 320 /*============================================================*/321 /* MACROS */322 /*============================================================*/323 324 /* helper macros (pre-processor hacks to allow macro arguments) */325 #define __str( arg ) #arg326 #define _stringize( arg ) __str( arg )327 #define __agr( arg1, arg2 ) arg1 ## arg2328 #define _aggregate( arg1, arg2 ) __agr( arg1, arg2 )329 250 330 251 /* Some aliases to socket addresses structures */ … … 375 296 } \ 376 297 } 298 377 299 /* Inside a debug trace */ 378 300 #define TRACE_DEBUG_sSA(level, prefix, sa, flags, suffix ) { \ … … 390 312 391 313 314 /*============================================================*/ 315 /* ERROR CHECKING MACRO */ 316 /*============================================================*/ 317 318 /* Macros to check a return value and branch out in case of error. 319 * These macro should be used only when errors are improbable, not for expected errors. 320 */ 321 322 /* Check the return value of a system function and execute fallback in case of error */ 323 #define CHECK_SYS_DO( __call__, __fallback__ ) { \ 324 int __ret__; \ 325 TRACE_DEBUG_ALL( "Check SYS: " #__call__ ); \ 326 __ret__ = (__call__); \ 327 if (__ret__ < 0) { \ 328 int __err__ = errno; /* We may handle EINTR here */ \ 329 TRACE_DEBUG(NONE, "ERROR: in '" #__call__ "' :\t%s", strerror(__err__));\ 330 __fallback__; \ 331 } \ 332 } 333 /* Check the return value of a system function, return error code on error */ 334 #define CHECK_SYS( __call__ ) { \ 335 int __ret__; \ 336 TRACE_DEBUG_ALL( "Check SYS: " #__call__ ); \ 337 __ret__ = (__call__); \ 338 if (__ret__ < 0) { \ 339 int __err__ = errno; /* We may handle EINTR here */ \ 340 TRACE_DEBUG(NONE, "ERROR: in '" #__call__ "' :\t%s", strerror(__err__));\ 341 return __err__; \ 342 } \ 343 } 344 345 /* Check the return value of a POSIX function and execute fallback in case of error or special value */ 346 #define CHECK_POSIX_DO2( __call__, __speval__, __fallback1__, __fallback2__ ) { \ 347 int __ret__; \ 348 TRACE_DEBUG_ALL( "Check POSIX: " #__call__ ); \ 349 __ret__ = (__call__); \ 350 if (__ret__ != 0) { \ 351 if (__ret__ == (__speval__)) { \ 352 __fallback1__; \ 353 } else { \ 354 TRACE_DEBUG(NONE, "ERROR: in '" #__call__ "':\t%s", strerror(__ret__)); \ 355 __fallback2__; \ 356 } \ 357 } \ 358 } 359 360 /* Check the return value of a POSIX function and execute fallback in case of error */ 361 #define CHECK_POSIX_DO( __call__, __fallback__ ) \ 362 CHECK_POSIX_DO2( (__call__), 0, , __fallback__ ); 363 364 /* Check the return value of a POSIX function and return it if error */ 365 #define CHECK_POSIX( __call__ ) { \ 366 int __v__; \ 367 CHECK_POSIX_DO( __v__ = (__call__), return __v__ ); \ 368 } 369 370 /* Check that a memory allocator did not return NULL, otherwise log an error and execute fallback */ 371 #define CHECK_MALLOC_DO( __call__, __fallback__ ) { \ 372 void * __ret__; \ 373 TRACE_DEBUG_ALL( "Check MALLOC: " #__call__ ); \ 374 __ret__ = (void *)( __call__ ); \ 375 if (__ret__ == NULL) { \ 376 int __err__ = errno; \ 377 TRACE_DEBUG(NONE, "ERROR: in '" #__call__ "':\t%s", strerror(__err__)); \ 378 __fallback__; \ 379 } \ 380 } 381 382 /* Check that a memory allocator did not return NULL, otherwise return ENOMEM */ 383 #define CHECK_MALLOC( __call__ ) \ 384 CHECK_MALLOC_DO( __call__, return ENOMEM ); 385 386 387 /* Check parameters at function entry, execute fallback on error */ 388 #define CHECK_PARAMS_DO( __bool__, __fallback__ ) \ 389 TRACE_DEBUG_ALL( "Check PARAMS: " #__bool__ ); \ 390 if ( ! (__bool__) ) { \ 391 TRACE_DEBUG(INFO, "Invalid parameter received in '" #__bool__ "'"); \ 392 __fallback__; \ 393 } 394 /* Check parameters at function entry, return EINVAL if the boolean is false (similar to assert) */ 395 #define CHECK_PARAMS( __bool__ ) \ 396 CHECK_PARAMS_DO( __bool__, return EINVAL ); 397 398 /* Check the return value of an internal function, log and propagate */ 399 #define CHECK_FCT_DO( __call__, __fallback__ ) { \ 400 int __ret__; \ 401 TRACE_DEBUG_ALL( "Check FCT: " #__call__ ); \ 402 __ret__ = (__call__); \ 403 if (__ret__ != 0) { \ 404 TRACE_DEBUG(INFO, "Error in '" #__call__ "':\t%s", strerror(__ret__)); \ 405 __fallback__; \ 406 } \ 407 } 408 /* Check the return value of a function call, return any error code */ 409 #define CHECK_FCT( __call__ ) { \ 410 int __v__; \ 411 CHECK_FCT_DO( __v__ = (__call__), return __v__ ); \ 412 } 413 414 415 /*============================================================*/ 416 /* OTHER MACROS */ 417 /*============================================================*/ 418 419 /* helper macros (pre-processor hacks to allow macro arguments) */ 420 #define __str( arg ) #arg 421 #define _stringize( arg ) __str( arg ) 422 #define __agr( arg1, arg2 ) arg1 ## arg2 423 #define _aggregate( arg1, arg2 ) __agr( arg1, arg2 ) 424 425 392 426 /* A l4 protocol name (TCP / SCTP) */ 393 427 #ifdef DISABLE_SCTP … … 425 459 #endif /* IN_IS_ADDR_UNSPECIFIED */ 426 460 427 428 461 /* create a V4MAPPED address */ 429 462 #define IN6_ADDR_V4MAP( a6, a4 ) { \ … … 440 473 441 474 /* We provide macros to convert 64 bit values to and from network byte-order, on systems where it is not already provided. */ 442 #ifndef HAVE_NTOHLL /* Defined in config.h, if the ntohll symbol is defined on the system */475 #ifndef HAVE_NTOHLL /* Defined by the cmake step, if the ntohll symbol is defined on the system */ 443 476 # if HOST_BIG_ENDIAN 444 477 /* In big-endian systems, we don't have to change the values, since the order is the same as network */ … … 455 488 #define PAD4(_x) ((_x) + ( (4 - (_x)) & 3 ) ) 456 489 457 /* Useful to display a s safe ASCII a value(will garbage UTF-8 output...) */490 /* Useful to display any value as (safe) ASCII (will garbage UTF-8 output...) */ 458 491 #define ASCII(_c) ( ((_c < 32) || (_c > 127)) ? ( _c ? '?' : ' ' ) : _c ) 459 492 … … 462 495 ( ((ts1)->tv_sec < (ts2)->tv_sec ) \ 463 496 || (((ts1)->tv_sec == (ts2)->tv_sec ) && ((ts1)->tv_nsec < (ts2)->tv_nsec) )) 464 465 466 /* Trace a binary buffer content */467 #define TRACE_DEBUG_BUFFER(level, prefix, buf, bufsz, suffix ) { \468 if ( TRACE_BOOL(level) ) { \469 char __ts[25]; \470 int __i; \471 size_t __sz = (size_t)(bufsz); \472 uint8_t * __buf = (uint8_t *)(buf); \473 char * __thn = ((char *)pthread_getspecific(fd_log_thname) ?: "unnamed"); \474 fd_log_debug("\t | tid:%-20s\t%s\tin %s@%s:%d\n" \475 "\t%s|%*s" prefix , \476 __thn, fd_log_time(NULL, __ts, sizeof(__ts)), __PRETTY_FUNCTION__, __FILE__, __LINE__, \477 (level < FULL)?"@":" ",level, ""); \478 for (__i = 0; __i < __sz; __i++) { \479 fd_log_debug("%02.2hhx", __buf[__i]); \480 } \481 fd_log_debug(suffix "\n"); \482 } \483 }484 497 485 498 … … 518 531 } 519 532 520 /* Cleanups for cancellation (all threads should be safely cancelable...) */ 533 /************* 534 Cancelation cleanup handlers for common objects 535 *************/ 521 536 static __inline__ void fd_cleanup_mutex( void * mutex ) 522 537 { … … 551 566 struct fd_list *prev; /* previous element in the list */ 552 567 struct fd_list *head; /* head of the list */ 553 void *o; /* additional avialbe pointer used for start of the parento object or other purpose*/568 void *o; /* additional pointer, used for any purpose (ex: start of the parent object) */ 554 569 }; 555 570 … … 568 583 void fd_list_insert_before ( struct fd_list * ref, struct fd_list * item ); 569 584 570 /* Move a list at the end of another */585 /* Move all elements from a list at the end of another */ 571 586 void fd_list_move_end(struct fd_list * ref, struct fd_list * senti); 572 587 573 /* Insert an item in an ordered list -- ordering function provided. If duplicate object found, EEXIST and it is returned in ref_duplicate */588 /* Insert an item in an ordered list -- ordering function must be provided. If duplicate object found, EEXIST and it is returned in ref_duplicate */ 574 589 int fd_list_insert_ordered( struct fd_list * head, struct fd_list * item, int (*cmp_fct)(void *, void *), void ** ref_duplicate); 575 590 576 591 /* Unlink an item from a list */ 577 592 void fd_list_unlink ( struct fd_list * item ); 593 594 595 596 /*============================================================*/ 597 /* HASH */ 598 /*============================================================*/ 578 599 579 600 /* Compute a hash value of a string (session id, diameter id, ...) */ … … 913 934 dict_avpdata_interpret type_interpret;/* cb to convert the AVP value in more comprehensive format (or NULL) */ 914 935 dict_avpdata_encode type_encode; /* cb to convert formatted data into an AVP value (or NULL) */ 915 void (*type_dump)(union avp_value * val); /* cb called by fd_msg_dump_one for this type of data (if != NULL) */936 void (*type_dump)(union avp_value * val); /* cb called by fd_msg_dump_one for this type of data (if != NULL), to dump the AVP value in debug */ 916 937 }; 917 938 … … 1429 1450 struct session; 1430 1451 1431 /* The state information that a module associate with a session -- each module define its own data format */1452 /* The state information that a module associate with a session -- each module defines its own data format */ 1432 1453 typedef void session_state; 1433 1454
Note: See TracChangeset
for help on using the changeset viewer.