comparison libfdproto/messages.c @ 1093:44f3e48dfe27

Align the behavior of all fd_*dump functions wrt final \n
author Sebastien Decugis <sdecugis@freediameter.net>
date Mon, 06 May 2013 16:33:22 +0800
parents e40374ddfeef
children 647c7e7015af
comparison
equal deleted inserted replaced
1092:e40374ddfeef 1093:44f3e48dfe27
718 718
719 719
720 /***************************************************************************************************************/ 720 /***************************************************************************************************************/
721 /* Debug functions: dumping */ 721 /* Debug functions: dumping */
722 722
723 /* messages and AVP formatters */
724 typedef 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 );
726
727 /* Core function to process the dumping */
728 static DECLARE_FD_DUMP_PROTOTYPE( msg_dump_process, msg_dump_formatter_msg msg_format, msg_dump_formatter_avp avp_format, msg_or_avp *obj, struct dictionary *dict, int force_parsing, int recurse )
729 {
730 FD_DUMP_HANDLE_OFFSET();
731
732 if (force_parsing) {
733 (void) fd_msg_parse_dict(obj, dict, NULL);
734 }
735
736 switch (_C(obj)->type) {
737 case MSG_AVP:
738 CHECK_MALLOC_DO( (*avp_format)(FD_DUMP_STD_PARAMS, (struct avp *)obj, 0), return NULL);
739 break;
740
741 case MSG_MSG:
742 CHECK_MALLOC_DO( (*msg_format)(FD_DUMP_STD_PARAMS, (struct msg *)obj), return NULL);
743 break;
744
745 default:
746 ASSERT(0);
747 }
748
749 if (recurse) {
750 struct avp * avp = NULL;
751 CHECK_FCT_DO( fd_msg_browse ( obj, MSG_BRW_FIRST_CHILD, &avp, NULL ), avp = NULL );
752 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 );
755 };
756 }
757
758 /* we remove the final \n if any */
759 FD_DUMP_HANDLE_TRAIL();
760
761 return *buf;
762 }
763
764 /*
765 * Tree View message dump
766 */
767
768 static DECLARE_FD_DUMP_PROTOTYPE( msg_format_treeview, struct msg * msg )
769 {
770 if (!CHECK_MSG(msg)) {
771 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "{message}(@%p): INVALID\n", msg), return NULL);
772 return *buf;
773 }
774
775 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "{message}(@%p): ", msg), return NULL);
776 if (!msg->msg_model) {
777 if (msg->msg_model_not_found.mnf_code) {
778 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "(not found in dictionary)\n"), return NULL);
779 } else {
780 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "(not searched in dictionary)\n"), return NULL);
781 }
782 } else {
783 enum dict_object_type dicttype;
784 struct dict_cmd_data dictdata;
785 if (fd_dict_gettype(msg->msg_model, &dicttype) || (dicttype != DICT_COMMAND)) {
786 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "(invalid model information)\n"), return NULL);
787 } else if (fd_dict_getval(msg->msg_model, &dictdata)) {
788 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "(error getting model information)\n"), return NULL);
789 } else {
790 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "'%s'\n", dictdata.cmd_name), return NULL);
791 }
792 }
793
794 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, " Version: 0x%02hhX\n", msg->msg_public.msg_version), return NULL);
795 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, " Length: %d\n", msg->msg_public.msg_length), return NULL);
796 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, " Flags: 0x%02hhX (" DUMP_CMDFL_str ")\n", msg->msg_public.msg_flags, DUMP_CMDFL_val(msg->msg_public.msg_flags)), return NULL);
797 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, " Command Code: %u\n", msg->msg_public.msg_code), return NULL);
798 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, " ApplicationId: %d\n", msg->msg_public.msg_appl), return NULL);
799 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, " Hop-by-Hop Identifier: 0x%8X\n", msg->msg_public.msg_hbhid), return NULL);
800 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);
802
803 return *buf;
804 }
805
806 static DECLARE_FD_DUMP_PROTOTYPE( avp_format_treeview, struct avp * avp, int level )
807 {
808 char * name;
809 struct dict_avp_data dictdata;
810 struct dict_avp_data *dictinfo = NULL;
811 struct dict_vendor_data vendordata;
812 struct dict_vendor_data *vendorinfo = NULL;
813 if (!CHECK_AVP(avp)) {
814 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "{avp}(@%p): INVALID\n", avp), return NULL);
815 return *buf;
816 }
817
818 if (!level) {
819 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "{avp}(@%p): ", avp), return NULL);
820 } else {
821 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "%*sAVP: ", level * 3, ""), return NULL);
822 }
823
824 if (!avp->avp_model) {
825 if (avp->avp_model_not_found.mnf_code) {
826 name = "(not found in dictionary)";
827 } else {
828 name = "(not searched in dictionary)";
829 }
830 } else {
831 enum dict_object_type dicttype;
832 if (fd_dict_gettype(avp->avp_model, &dicttype) || (dicttype != DICT_AVP)) {
833 name = "(invalid model information)";
834 } else if (fd_dict_getval(avp->avp_model, &dictdata)) {
835 name = "(error getting model information)";
836 } else {
837 name = dictdata.avp_name;
838 dictinfo = &dictdata;
839 if (avp->avp_public.avp_flags & AVP_FLAG_VENDOR) {
840 struct dictionary * dict;
841 struct dict_object * vendor;
842 if ((!fd_dict_getdict(avp->avp_model, &dict))
843 && (!fd_dict_search(dict, DICT_VENDOR, VENDOR_OF_AVP, avp->avp_model, &vendor, ENOENT))
844 && (!fd_dict_getval(vendor, &vendordata))) {
845 vendorinfo = &vendordata;
846 }
847 }
848 }
849 }
850
851 if (dictinfo) {
852 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "'%s'(%u)", name, avp->avp_public.avp_code), return NULL);
853 } else {
854 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "%u%s", avp->avp_public.avp_code, name), return NULL);
855 }
856
857 if (avp->avp_public.avp_flags & AVP_FLAG_VENDOR) {
858 if (vendorinfo) {
859 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, " vend='%s'(%u)", vendorinfo->vendor_name, avp->avp_public.avp_vendor), return NULL);
860 } else {
861 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, " vend=%u", avp->avp_public.avp_vendor), return NULL);
862 }
863 }
864
865 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, " l=%d f=" DUMP_AVPFL_str " val=", avp->avp_public.avp_len, DUMP_AVPFL_val(avp->avp_public.avp_flags)), return NULL);
866
867 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 };
875 } else {
876 if (avp->avp_public.avp_value) {
877 CHECK_MALLOC_DO( fd_dict_dump_avp_value(FD_DUMP_STD_PARAMS, avp->avp_public.avp_value, avp->avp_model, 0, 0), return NULL);
878 } else if (avp->avp_rawdata) {
879 CHECK_MALLOC_DO( fd_dump_extend_hexdump(FD_DUMP_STD_PARAMS, avp->avp_rawdata, avp->avp_rawlen, 0, 0), return NULL);
880 } else {
881 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "(not set)"), return NULL);
882 }
883 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "\n"), return NULL);
884 }
885
886 return *buf;
887 }
888
889 /* multi-line human-readable dump similar to wireshark output */
890 DECLARE_FD_DUMP_PROTOTYPE( fd_msg_dump_treeview, msg_or_avp *obj, struct dictionary *dict, int force_parsing, int recurse )
891 {
892 return msg_dump_process(FD_DUMP_STD_PARAMS, msg_format_treeview, avp_format_treeview, obj, dict, force_parsing, recurse);
893 }
894
895
723 #warning "todo" 896 #warning "todo"
724 DECLARE_FD_DUMP_PROTOTYPE( fd_msg_dump_summary, msg_or_avp *obj, struct dictionary *dict, int force_parsing, int recurse )
725 {
726 return NULL;
727 }
728 /* one-line dump with all the contents of the message */ 897 /* one-line dump with all the contents of the message */
729 DECLARE_FD_DUMP_PROTOTYPE( fd_msg_dump_full, msg_or_avp *obj, struct dictionary *dict, int force_parsing, int recurse ) 898 DECLARE_FD_DUMP_PROTOTYPE( fd_msg_dump_full, msg_or_avp *obj, struct dictionary *dict, int force_parsing, int recurse )
730 { 899 {
731 return NULL; 900 return NULL;
732 } 901 }
733 /* multi-line human-readable dump similar to wireshark output */ 902
734 DECLARE_FD_DUMP_PROTOTYPE( fd_msg_dump_treeview, msg_or_avp *obj, struct dictionary *dict, int force_parsing, int recurse ) 903 /* This one only prints a short display, does not go into the complete tree */
904 DECLARE_FD_DUMP_PROTOTYPE( fd_msg_dump_summary, msg_or_avp *obj, struct dictionary *dict, int force_parsing, int recurse )
735 { 905 {
736 return NULL; 906 return NULL;
737 } 907 }
738 908
739 #ifndef OLD_CODE_TO_BE_REPLACED 909 #ifndef OLD_CODE_TO_BE_REPLACED
"Welcome to our mercurial repository"