Navigation



Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • include/freeDiameter/libfreeDiameter.h

    r20 r29  
    120120 *
    121121 * PARAMETERS:
     122 *  ts          : The timestamp to log, or NULL for "now"
    122123 *  buf         : An array where the time must be stored
    123124 *  len         : size of the buffer
    124125 *
    125126 * DESCRIPTION:
    126  *  Writes the current timestamp (in human readable format) in a buffer.
     127 *  Writes the timestamp (in human readable format) in a buffer.
    127128 *
    128129 * RETURN VALUE:
    129130 *  pointer to buf.
    130131 */
    131 char * fd_log_time ( char * buf, size_t len );
     132char * fd_log_time ( struct timespec * ts, char * buf, size_t len );
    132133
    133134
     
    173174                fd_log_debug("\t | tid:%-20s\t%s\tin %s@%s:%d\n"                                                                \
    174175                          "\t%s|%*s" format "\n",                                                                               \
    175                                         __thn, fd_log_time(__buf, sizeof(__buf)), __PRETTY_FUNCTION__, __FILE__, __LINE__,      \
     176                                        __thn, fd_log_time(NULL, __buf, sizeof(__buf)), __PRETTY_FUNCTION__, __FILE__, __LINE__,        \
    176177                                        (level < FULL)?"@":" ",level, "", ## args);                                             \
    177178        }                                                                                                                       \
     
    180181/* Helper for function entry -- for very detailed trace of the execution */
    181182#define TRACE_ENTRY(_format,_args... ) \
    182         TRACE_DEBUG(FCTS, "->%s (" #_args ") = (" _format ") >", __PRETTY_FUNCTION__, ##_args );
     183        TRACE_DEBUG(FCTS, "[enter] %s(" _format ") {" #_args "}", __PRETTY_FUNCTION__, ##_args );
    183184
    184185/* Helper for debugging by adding traces -- for debuging a specific location of the code */
     
    328329                        flag);                                  \
    329330          if (__rc)                                             \
    330                 fd_log_debug((char *)gai_strerror(__rc));       \
     331                fd_log_debug("%s", (char *)gai_strerror(__rc)); \
    331332          else                                                  \
    332                 fd_log_debug(&__addrbuf[0]);                    \
     333                fd_log_debug("%s", &__addrbuf[0]);              \
    333334        } else {                                                \
    334335                fd_log_debug("(NULL / ANY)");                   \
    335336        }                                                       \
    336337}
    337 /* if needed, add sSA_DUMP_SERVICE */
     338/* Same but with the port (service) also */
     339#define sSA_DUMP_NODE_SERV( sa, flag ) {                                \
     340        sSA * __sa = (sSA *)(sa);                                       \
     341        char __addrbuf[INET6_ADDRSTRLEN];                               \
     342        char __servbuf[32];                                             \
     343        if (__sa) {                                                     \
     344          int __rc = getnameinfo(__sa,                                  \
     345                        sizeof(sSS),                                    \
     346                        __addrbuf,                                      \
     347                        sizeof(__addrbuf),                              \
     348                        __servbuf,                                      \
     349                        sizeof(__servbuf),                              \
     350                        flag);                                          \
     351          if (__rc)                                                     \
     352                fd_log_debug("%s", (char *)gai_strerror(__rc));         \
     353          else                                                          \
     354                fd_log_debug("[%s]:%s", &__addrbuf[0],&__servbuf[0]);   \
     355        } else {                                                        \
     356                fd_log_debug("(NULL / ANY)");                           \
     357        }                                                               \
     358}
     359/* Inside a debug trace */
     360#define TRACE_DEBUG_sSA(level, prefix, sa, flags, suffix ) {                                                                            \
     361        if ( TRACE_BOOL(level) ) {                                                                                              \
     362                char __buf[25];                                                                                                 \
     363                char * __thn = ((char *)pthread_getspecific(fd_log_thname) ?: "unnamed");                                       \
     364                fd_log_debug("\t | tid:%-20s\t%s\tin %s@%s:%d\n"                                                                \
     365                          "\t%s|%*s" prefix ,                                                                                   \
     366                                        __thn, fd_log_time(NULL, __buf, sizeof(__buf)), __PRETTY_FUNCTION__, __FILE__, __LINE__,\
     367                                        (level < FULL)?"@":" ",level, "");                                                      \
     368                sSA_DUMP_NODE_SERV( sa, flags );                                                                                \
     369                fd_log_debug(suffix "\n");                                                                                      \
     370        }                                                                                                                       \
     371}
     372
    338373
    339374/* A l4 protocol name (TCP / SCTP) */
     
    390425        (    ((ts1)->tv_sec  < (ts2)->tv_sec )  \
    391426          || (((ts1)->tv_sec  == (ts2)->tv_sec ) && ((ts1)->tv_nsec < (ts2)->tv_nsec) ))
     427
     428
     429/* Trace a binary buffer content */
     430#define TRACE_DEBUG_BUFFER(level, prefix, buf, bufsz, suffix ) {                                                                \
     431        if ( TRACE_BOOL(level) ) {                                                                                              \
     432                int __i;                                                                                                        \
     433                size_t __sz = (size_t)(bufsz);                                                                                  \
     434                uint8_t * __buf = (uint8_t *)(buf);                                                                             \
     435                char * __thn = ((char *)pthread_getspecific(fd_log_thname) ?: "unnamed");                                       \
     436                fd_log_debug("\t | tid:%-20s\t%s\tin %s@%s:%d\n"                                                                \
     437                          "\t%s|%*s" prefix ,                                                                                   \
     438                                        __thn, fd_log_time(NULL, __buf, sizeof(__buf)), __PRETTY_FUNCTION__, __FILE__, __LINE__,\
     439                                        (level < FULL)?"@":" ",level, "");                                                      \
     440                for (__i = 0; __i < __sz; __i++) {                                                                              \
     441                        fd_log_debug("%02.2hhx", __buf[__i]);                                                                   \
     442                }                                                                                                               \
     443                fd_log_debug(suffix "\n");                                                                                      \
     444        }                                                                                                                       \
     445}
     446
    392447
    393448
     
    415470       
    416471        if (th_ret != NULL) {
    417                 TRACE_DEBUG(FULL, "The thread returned the following value: %p (ignored)", th_ret);
     472                TRACE_DEBUG(ANNOYING, "The thread returned the following value: %p (ignored)", th_ret);
    418473        }
    419474       
     
    439494        free(buffer);
    440495}
     496static __inline__ void fd_cleanup_socket(void * sockptr)
     497{
     498        if (sockptr) {
     499                shutdown(*(int *)sockptr, SHUT_RDWR);
     500                *(int *)sockptr = 0;
     501        }
     502}
     503
    441504
    442505/*============================================================*/
     
    465528void fd_list_insert_after  ( struct fd_list * ref, struct fd_list * item );
    466529void fd_list_insert_before ( struct fd_list * ref, struct fd_list * item );
     530
     531/* Move a list at the end of another */
     532void fd_list_move_end(struct fd_list * ref, struct fd_list * senti);
    467533
    468534/* Insert an item in an ordered list -- ordering function provided. If duplicate object found, EEXIST and it is returned in ref_duplicate */
     
    23422408
    23432409/*
     2410 * FUNCTION:    fd_fifo_move
     2411 *
     2412 * PARAMETERS:
     2413 *  old         : Location of a FIFO that is to be emptied and deleted.
     2414 *  new         : A FIFO that will receive the old data.
     2415 *  loc_update  : if non NULL, a place to store the pointer to new FIFO atomically with the move.
     2416 *
     2417 * DESCRIPTION:
     2418 *  Delete a queue and move its content to another one atomically.
     2419 *
     2420 * RETURN VALUE:
     2421 *  0           : The queue has been destroyed successfully.
     2422 *  EINVAL      : A parameter is invalid.
     2423 */
     2424int fd_fifo_move ( struct fifo ** old, struct fifo * new, struct fifo ** loc_update );
     2425
     2426/*
    23442427 * FUNCTION:    fd_fifo_length
    23452428 *
Note: See TracChangeset for help on using the changeset viewer.