Navigation


Changeset 1095:647c7e7015af in freeDiameter for libfdproto


Ignore:
Timestamp:
May 6, 2013, 6:57:05 PM (11 years ago)
Author:
Sebastien Decugis <sdecugis@freediameter.net>
Branch:
default
Phase:
public
Message:

Ported the fd_msg_dump_full function to the new mechanism

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libfdproto/messages.c

    r1093 r1095  
    723723/* messages and AVP formatters */
    724724typedef DECLARE_FD_DUMP_PROTOTYPE( (*msg_dump_formatter_msg), struct msg * msg );
    725 typedef DECLARE_FD_DUMP_PROTOTYPE( (*msg_dump_formatter_avp), struct avp * avp, int level );
     725typedef DECLARE_FD_DUMP_PROTOTYPE( (*msg_dump_formatter_avp), struct avp * avp, int level, int first, int last );
    726726
    727727/* Core function to process the dumping */
     
    736736        switch (_C(obj)->type) {
    737737                case MSG_AVP:
    738                         CHECK_MALLOC_DO( (*avp_format)(FD_DUMP_STD_PARAMS, (struct avp *)obj, 0), return NULL);
     738                        CHECK_MALLOC_DO( (*avp_format)(FD_DUMP_STD_PARAMS, (struct avp *)obj, 0, 1, 1), return NULL);
    739739                        break;
    740740
     
    749749        if (recurse) {
    750750                struct avp * avp = NULL;
     751                int first = 1;
    751752                CHECK_FCT_DO(  fd_msg_browse ( obj, MSG_BRW_FIRST_CHILD, &avp, NULL ), avp = NULL );
    752753                while (avp) {
    753                         CHECK_MALLOC_DO( (*avp_format)(FD_DUMP_STD_PARAMS, avp, 1), return NULL);
    754                         CHECK_FCT_DO(  fd_msg_browse ( avp, MSG_BRW_NEXT, &avp, NULL ), avp = NULL  );
     754                        struct avp * nextavp = NULL;
     755                        CHECK_FCT_DO(  fd_msg_browse ( avp, MSG_BRW_NEXT, &nextavp, NULL ), nextavp = NULL  );
     756                        CHECK_MALLOC_DO( (*avp_format)(FD_DUMP_STD_PARAMS, avp, 1, first, nextavp ? 0 : 1), return NULL);
     757                        avp = nextavp;
     758                        first = 0;
    755759                };
    756760        }
    757        
    758         /* we remove the final \n if any */
    759         FD_DUMP_HANDLE_TRAIL();
    760761       
    761762        return *buf;
     
    765766 * Tree View message dump
    766767 */
    767 
    768768static DECLARE_FD_DUMP_PROTOTYPE( msg_format_treeview, struct msg * msg )
    769769{
    770770        if (!CHECK_MSG(msg)) {
    771                 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "{message}(@%p): INVALID\n", msg), return NULL);
     771                CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "{message}(@%p): INVALID", msg), return NULL);
    772772                return *buf;
    773773        }
     
    799799        CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "  Hop-by-Hop Identifier: 0x%8X\n", msg->msg_public.msg_hbhid), return NULL);
    800800        CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "  End-to-End Identifier: 0x%8X\n", msg->msg_public.msg_eteid), return NULL);
    801         CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "   {debug data}: src:%s(%zd) rwb:%p rt:%d cb:%p,%p(%p) qry:%p asso:%d sess:%p\n", msg->msg_src_id?:"(nil)", msg->msg_src_id_len, msg->msg_rawbuffer, msg->msg_routable, msg->msg_cb.anscb, msg->msg_cb.expirecb, msg->msg_cb.data, msg->msg_query, msg->msg_associated, msg->msg_sess), return NULL);
     801        CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "   {debug data}: src:%s(%zd) rwb:%p rt:%d cb:%p,%p(%p) qry:%p asso:%d sess:%p", msg->msg_src_id?:"(nil)", msg->msg_src_id_len, msg->msg_rawbuffer, msg->msg_routable, msg->msg_cb.anscb, msg->msg_cb.expirecb, msg->msg_cb.data, msg->msg_query, msg->msg_associated, msg->msg_sess), return NULL);
    802802       
    803803        return *buf;
    804804}
    805805
    806 static DECLARE_FD_DUMP_PROTOTYPE( avp_format_treeview, struct avp * avp, int level )
     806static DECLARE_FD_DUMP_PROTOTYPE( avp_format_treeview, struct avp * avp, int level, int first, int last )
    807807{
    808808        char * name;
     
    811811        struct dict_vendor_data  vendordata;
    812812        struct dict_vendor_data *vendorinfo = NULL;
     813       
     814        if (level) {
     815                CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "\n"), return NULL);
     816        }
     817       
    813818        if (!CHECK_AVP(avp)) {
    814                 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "{avp}(@%p): INVALID\n", avp), return NULL);
     819                CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "{avp}(@%p): INVALID", avp), return NULL);
    815820                return *buf;
    816821        }
     
    866871       
    867872        if (dictinfo && (dictinfo->avp_basetype == AVP_TYPE_GROUPED)) {
    868                 struct avp * inavp = NULL;
    869                 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "(grouped)\n"), return NULL);
    870                 CHECK_FCT_DO(  fd_msg_browse ( avp, MSG_BRW_FIRST_CHILD, &inavp, NULL ), inavp = NULL );
    871                 while (inavp) {
    872                         CHECK_MALLOC_DO( avp_format_treeview(FD_DUMP_STD_PARAMS, inavp, level + 1), return NULL);
    873                         CHECK_FCT_DO(  fd_msg_browse ( inavp, MSG_BRW_NEXT, &inavp, NULL ), inavp = NULL  );
    874                 };
     873                CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "(grouped)"), return NULL);
     874                if (level) {
     875                        struct avp * inavp = NULL;
     876                        int first = 1;
     877                        CHECK_FCT_DO(  fd_msg_browse ( avp, MSG_BRW_FIRST_CHILD, &inavp, NULL ), inavp = NULL );
     878                        while (inavp) {
     879                                struct avp * nextavp = NULL;
     880                                CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "\n"), return NULL);
     881                                CHECK_FCT_DO(  fd_msg_browse ( inavp, MSG_BRW_NEXT, &nextavp, NULL ), inavp = NULL  );
     882                                CHECK_MALLOC_DO( avp_format_treeview(FD_DUMP_STD_PARAMS, inavp, level + 1, first, nextavp ? 0 : 1), return NULL);
     883                                inavp = nextavp;
     884                                first = 0;
     885                        };
     886                }
    875887        } else {
    876888                if (avp->avp_public.avp_value) {
     
    881893                        CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "(not set)"), return NULL);
    882894                }
    883                 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "\n"), return NULL);
    884895        }
    885896
     
    894905
    895906
    896 #warning "todo"
     907/*
     908 * One-line dumper for compact but complete traces
     909 */
     910static DECLARE_FD_DUMP_PROTOTYPE( msg_format_full, struct msg * msg )
     911{
     912        int success = 0;
     913        struct dict_cmd_data dictdata;
     914       
     915        if (!CHECK_MSG(msg)) {
     916                CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "INVALID MESSAGE", msg), return NULL);
     917                return *buf;
     918        }
     919       
     920        if (!msg->msg_model) {
     921                CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "(no model) "), return NULL);
     922        } else {
     923                enum dict_object_type dicttype=0;
     924                if (fd_dict_gettype(msg->msg_model, &dicttype) || (dicttype != DICT_COMMAND)) {
     925                        CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "(invalid model %d) ", dicttype), return NULL);
     926                } else if (fd_dict_getval(msg->msg_model, &dictdata)) {
     927                        CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "(error getting model data) "), return NULL);
     928                } else {
     929                        success = 1;
     930                }
     931        }
     932        if (msg->msg_public.msg_appl) {
     933                CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS,
     934                                   "%s(%u/%u)[" DUMP_CMDFL_str "], Length=%u, Hop-By-Hop-Id=0x%08x, End-to-End=0x%08x",
     935                                        success ? dictdata.cmd_name :  "unknown",  msg->msg_public.msg_appl, msg->msg_public.msg_code, DUMP_CMDFL_val(msg->msg_public.msg_flags),
     936                                        msg->msg_public.msg_length, msg->msg_public.msg_hbhid, msg->msg_public.msg_eteid), return NULL);
     937        } else {
     938                CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS,
     939                                   "%s(%u)[" DUMP_CMDFL_str "], Length=%u, Hop-By-Hop-Id=0x%08x, End-to-End=0x%08x",
     940                                        success ? dictdata.cmd_name :  "unknown", msg->msg_public.msg_code, DUMP_CMDFL_val(msg->msg_public.msg_flags),
     941                                        msg->msg_public.msg_length, msg->msg_public.msg_hbhid, msg->msg_public.msg_eteid), return NULL);
     942        }
     943        return *buf;
     944}
     945
     946static DECLARE_FD_DUMP_PROTOTYPE( avp_format_full, struct avp * avp, int level, int first, int last )
     947{
     948        int success = 0;
     949        struct dict_avp_data  dictdata;
     950        struct dict_vendor_data  vendordata;
     951        struct dict_vendor_data *vendorinfo = NULL;
     952       
     953       
     954        if (level) {
     955                if ((first) && ((*buf)[*offset - 1] == '=')) {
     956                        /* We are first AVP of a grouped AVP */
     957                        CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "{ "), return NULL);
     958                } else {
     959                        /* We follow another AVP, or a message header */
     960                        CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, ", { "), return NULL);
     961                }
     962        }
     963       
     964        if (!CHECK_AVP(avp)) {
     965                CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "INVALID AVP"), return NULL);
     966                goto end;
     967        }
     968       
     969
     970        if (avp->avp_model) {
     971                enum dict_object_type dicttype;
     972                if (fd_dict_gettype(avp->avp_model, &dicttype) || (dicttype != DICT_AVP)) {
     973                        CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "(invalid model: %d) ", dicttype), return NULL);
     974                } else if (fd_dict_getval(avp->avp_model, &dictdata)) {
     975                        CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "(error getting model data) "), return NULL);
     976                } else {
     977                        success = 1;
     978                }
     979        }
     980       
     981        if (avp->avp_public.avp_flags & AVP_FLAG_VENDOR) {
     982                CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "%s(%u/%u)[" DUMP_AVPFL_str "]=",
     983                                        success ? dictdata.avp_name : "unknown", avp->avp_public.avp_vendor, avp->avp_public.avp_code, DUMP_AVPFL_val(avp->avp_public.avp_flags)), return NULL);
     984        } else {
     985                CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "%s(%u)[" DUMP_AVPFL_str "]=",
     986                                        success ? dictdata.avp_name : "unknown", avp->avp_public.avp_code, DUMP_AVPFL_val(avp->avp_public.avp_flags)), return NULL);
     987        }
     988
     989               
     990        if (success && (dictdata.avp_basetype == AVP_TYPE_GROUPED)) {
     991                if (level) {
     992                        struct avp * inavp = NULL;
     993                        int first = 1;
     994                        CHECK_FCT_DO(  fd_msg_browse ( avp, MSG_BRW_FIRST_CHILD, &inavp, NULL ), inavp = NULL );
     995                        while (inavp) {
     996                                struct avp * nextavp = NULL;
     997                                CHECK_FCT_DO(  fd_msg_browse ( inavp, MSG_BRW_NEXT, &nextavp, NULL ), inavp = NULL  );
     998                                CHECK_MALLOC_DO( avp_format_full(FD_DUMP_STD_PARAMS, inavp, level + 1, first, nextavp ? 0 : 1), return NULL);
     999                                inavp = nextavp;
     1000                                first = 0;
     1001                        };
     1002                }
     1003        } else {
     1004                if (avp->avp_public.avp_value) {
     1005                        CHECK_MALLOC_DO( fd_dict_dump_avp_value(FD_DUMP_STD_PARAMS, avp->avp_public.avp_value, avp->avp_model, 0, 0), return NULL);
     1006                } else if (avp->avp_rawdata) {
     1007                        CHECK_MALLOC_DO( fd_dump_extend_hexdump(FD_DUMP_STD_PARAMS, avp->avp_rawdata, avp->avp_rawlen, 0, 0), return NULL);
     1008                } else {
     1009                        CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "(not set)"), return NULL);
     1010                }
     1011        }
     1012       
     1013end:
     1014        if (level) {
     1015                CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, " }"), return NULL);
     1016        }
     1017       
     1018        return *buf;
     1019}
    8971020/* one-line dump with all the contents of the message */
    8981021DECLARE_FD_DUMP_PROTOTYPE( fd_msg_dump_full, msg_or_avp *obj, struct dictionary *dict, int force_parsing, int recurse )
    8991022{
    900         return NULL;
    901 }
     1023        return msg_dump_process(FD_DUMP_STD_PARAMS, msg_format_full, avp_format_full, obj, dict, force_parsing, recurse);
     1024}
     1025
     1026#warning "todo"
    9021027
    9031028/* This one only prints a short display, does not go into the complete tree */
Note: See TracChangeset for help on using the changeset viewer.