Navigation


Changeset 804:c5b7d4a2cc77 in freeDiameter for libfdproto/fdproto-internal.h


Ignore:
Timestamp:
Aug 22, 2012, 7:22:46 AM (12 years ago)
Author:
Sebastien Decugis <sdecugis@nict.go.jp>
Branch:
default
Phase:
public
Message:

Log message dumps in one call to the dump function to avoid fragmentation in the log files, as per Zack comment

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libfdproto/fdproto-internal.h

    r740 r804  
    6060/* Dispatch / messages / dictionary API */
    6161int fd_dict_disp_cb(enum dict_object_type type, struct dict_object *obj, struct fd_list ** cb_list);
    62 void fd_dict_dump_avp_value(union avp_value *avp_value, struct dict_object * model, int indent, FILE * fstr);
     62int fd_dict_dump_avp_value(union avp_value *avp_value, struct dict_object * model, int indent, char **outstr, size_t *offset, size_t *outlen);
    6363int fd_disp_call_cb_int( struct fd_list * cb_list, struct msg ** msg, struct avp *avp, struct session *sess, enum disp_action *action,
    6464                        struct dict_object * obj_app, struct dict_object * obj_cmd, struct dict_object * obj_avp, struct dict_object * obj_enu);
     
    7070int fd_sess_reclaim_msg ( struct session ** session );
    7171
     72/* For dump routines into string buffers */
     73#include <stdarg.h>
     74static __inline__ int dump_init_str(char **outstr, size_t *offset, size_t *outlen)
     75{
     76        *outlen = 1<<12;
     77        CHECK_MALLOC( *outstr = malloc(*outlen) );
     78        *offset = 0;
     79        (*outstr)[0] = 0;
     80        return 0;
     81}
     82static __inline__ int dump_add_str(char **outstr, size_t *offset, size_t *outlen, char * fmt, ...)
     83{
     84        va_list argp;
     85        int len;
     86        va_start(argp, fmt);
     87        len = vsnprintf(*outstr + *offset, *outlen - *offset, fmt, argp);
     88        va_end(argp);
     89        if ((len + *offset) >= *outlen) {
     90                char * newstr;
     91                /* buffer was too short, extend */
     92                size_t newsize = ((len + *offset) + (1<<12)) & ~((1<<12) - 1); /* next multiple of 4k */
     93                CHECK_MALLOC( newstr = realloc(*outstr, newsize) );
     94               
     95                /* redo */
     96                *outstr = newstr;
     97                *outlen = newsize;
     98                va_start(argp, fmt);
     99                len = vsnprintf(*outstr + *offset, *outlen - *offset, fmt, argp);
     100                va_end(argp);
     101        }
     102        *offset += len;
     103        return 0;
     104}
     105
     106
     107
    72108#endif /* _LIBFDPROTO_INTERNAL_H */
Note: See TracChangeset for help on using the changeset viewer.