Mercurial > hg > freeDiameter
comparison tests/testmesg.c @ 1300:3f1e79e1273e
Added new callbacks in the derived types definitions to improve value checks during message parsing. Thanks Ranjith for the suggestion.
author | Sebastien Decugis <sdecugis@freediameter.net> |
---|---|
date | Sun, 30 Aug 2015 01:11:55 +0800 |
parents | ab6457399be2 |
children | f6f12521c2aa |
comparison
equal
deleted
inserted
replaced
1299:035f489b845b | 1300:3f1e79e1273e |
---|---|
306 */ | 306 */ |
307 #if 0 | 307 #if 0 |
308 fd_log_debug("%s", fd_dict_dump_object(FD_DUMP_TEST_PARAMS, gavp)); | 308 fd_log_debug("%s", fd_dict_dump_object(FD_DUMP_TEST_PARAMS, gavp)); |
309 #endif | 309 #endif |
310 } | 310 } |
311 | |
312 { | |
313 struct dict_object * type = NULL; | |
314 struct dict_type_data type_data = { AVP_TYPE_OCTETSTRING, "OS test2", NULL, NULL, NULL, fd_dictfct_CharInOS_check, "@." }; | |
315 struct dict_avp_data avp_data = { 73575, 73565, "AVP Test - os2", AVP_FLAG_VENDOR, AVP_FLAG_VENDOR, AVP_TYPE_OCTETSTRING }; | |
316 CHECK( 0, fd_dict_new ( fd_g_config->cnf_dict, DICT_TYPE, &type_data , NULL, &type ) ); | |
317 CHECK( 0, fd_dict_new ( fd_g_config->cnf_dict, DICT_AVP, &avp_data , type, NULL ) ); | |
318 } | |
319 | |
311 #if 0 | 320 #if 0 |
312 { | 321 { |
313 fd_log_debug("%s", fd_dict_dump_object(FD_DUMP_TEST_PARAMS, vendor)); | 322 fd_log_debug("%s", fd_dict_dump_object(FD_DUMP_TEST_PARAMS, vendor)); |
314 } | 323 } |
315 #endif | 324 #endif |
750 CHECK( 0, fd_msg_parse_buffer( &buf_cpy, 344, &msg) ); | 759 CHECK( 0, fd_msg_parse_buffer( &buf_cpy, 344, &msg) ); |
751 CHECK( EBADMSG, fd_msg_parse_dict( msg, fd_g_config->cnf_dict, NULL ) ); | 760 CHECK( EBADMSG, fd_msg_parse_dict( msg, fd_g_config->cnf_dict, NULL ) ); |
752 | 761 |
753 /* reset */ | 762 /* reset */ |
754 CHECK( 0, fd_msg_free ( msg ) ); | 763 CHECK( 0, fd_msg_free ( msg ) ); |
764 } | |
765 | |
766 /* Test with a type verifier */ | |
767 { | |
768 struct fd_pei error_info; | |
769 CPYBUF(); | |
770 buf_cpy[103] = 0x67; /* Replaced AVP code = 0x00011F67, OS test2 type in the dictionary */ | |
771 | |
772 /* Check that we cannot support this message now */ | |
773 CHECK( 0, fd_msg_parse_buffer( &buf_cpy, 344, &msg) ); | |
774 CHECK( EBADMSG, fd_msg_parse_dict( msg, fd_g_config->cnf_dict, NULL ) ); | |
775 | |
776 /* reset */ | |
777 CHECK( 0, fd_msg_free ( msg ) ); | |
778 | |
779 CPYBUF(); | |
780 buf_cpy[103] = 0x67; /* Replaced AVP code = 0x00011F67, OS test2 type in the dictionary */ | |
781 | |
782 /* Check error reporting works */ | |
783 CHECK( 0, fd_msg_parse_buffer( &buf_cpy, 344, &msg) ); | |
784 CHECK( EBADMSG, fd_msg_parse_dict( msg, fd_g_config->cnf_dict, &error_info ) ); | |
785 | |
786 #if 1 | |
787 fd_log_debug("Error reported: %s\n in AVP: %s", error_info.pei_message, fd_msg_dump_treeview(FD_DUMP_TEST_PARAMS, error_info.pei_avp, fd_g_config->cnf_dict, 0, 1)); | |
788 #endif | |
789 | |
790 /* reset */ | |
791 CHECK( 0, fd_msg_free ( msg ) ); | |
792 | |
793 CPYBUF(); | |
794 buf_cpy[103] = 0x67; /* Replaced AVP code = 0x00011F67, OS test2 type in the dictionary */ | |
795 buf_cpy[130] = '@'; | |
796 buf_cpy[140] = '.'; /* now we comply to the constraints */ | |
797 | |
798 /* Check that we cannot support this message now */ | |
799 CHECK( 0, fd_msg_parse_buffer( &buf_cpy, 344, &msg) ); | |
800 CHECK( 0, fd_msg_parse_dict( msg, fd_g_config->cnf_dict, NULL ) ); | |
801 | |
802 /* reset */ | |
803 CHECK( 0, fd_msg_free ( msg ) ); | |
804 | |
805 | |
755 } | 806 } |
756 | 807 |
757 { | 808 { |
758 unsigned char * buftmp = NULL; | 809 unsigned char * buftmp = NULL; |
759 struct msg * error; | 810 struct msg * error; |
1396 | 1447 |
1397 CHECK( 0, fd_msg_free( msg ) ); | 1448 CHECK( 0, fd_msg_free( msg ) ); |
1398 } | 1449 } |
1399 } | 1450 } |
1400 | 1451 |
1401 | |
1402 /* That's all for the tests yet */ | 1452 /* That's all for the tests yet */ |
1403 PASSTEST(); | 1453 PASSTEST(); |
1404 } | 1454 } |
1405 | 1455 |