Navigation


Changeset 1423:67c263056d78 in freeDiameter


Ignore:
Timestamp:
Feb 19, 2020, 8:20:20 AM (4 years ago)
Author:
Luke Mewburn <luke@mewburn.net>
Branch:
default
Phase:
public
Message:

fd_msg_search_avp: search msg_or_avp, not just msg

Change fd_msg_search_avp() to support searching
struct msg or struct avp, and not just struct msg.

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • include/freeDiameter/libfdproto.h

    r1422 r1423  
    23672367 *
    23682368 * PARAMETERS:
    2369  *  msg         : The message structure in which to search the AVP.
     2369 *  reference   : Pointer to a valid msg or avp in which to search the AVP.
    23702370 *  what        : The dictionary model of the AVP to search.
    23712371 *  avp         : location where the AVP reference is stored if found.
    23722372 *
    23732373 * DESCRIPTION:
    2374  *   Search the first top-level AVP of a given model inside a message.
     2374 *   Search for the first top-level AVP of a given model inside a message or AVP.
    23752375 * Note: only the first instance of the AVP is returned by this function.
    23762376 * Note: only top-level AVPs are searched, not inside grouped AVPs.
     
    23822382 *  ENOENT      : No AVP has been found, and "avp" was NULL (otherwise, *avp is set to NULL and 0 returned).
    23832383 */
    2384 int fd_msg_search_avp ( struct msg * msg, struct dict_object * what, struct avp ** avp );
     2384int fd_msg_search_avp ( msg_or_avp * reference, struct dict_object * what, struct avp ** avp );
    23852385
    23862386/*
  • libfdproto/messages.c

    r1405 r1423  
    597597}
    598598
    599 /* Search a given AVP model in a message */
    600 int fd_msg_search_avp ( struct msg * msg, struct dict_object * what, struct avp ** avp )
     599/* Search a given AVP model in a message or AVP */
     600int fd_msg_search_avp ( msg_or_avp * reference, struct dict_object * what, struct avp ** avp )
    601601{
    602602        struct avp * nextavp;
     
    604604        enum dict_object_type   dicttype;
    605605       
    606         TRACE_ENTRY("%p %p %p", msg, what, avp);
    607        
    608         CHECK_PARAMS( CHECK_MSG(msg) && what );
     606        TRACE_ENTRY("%p %p %p", reference, what, avp);
     607       
     608        CHECK_PARAMS( VALIDATE_OBJ(reference) && what );
    609609       
    610610        CHECK_PARAMS( (fd_dict_gettype(what, &dicttype) == 0) && (dicttype == DICT_AVP) );
    611611        CHECK_FCT(  fd_dict_getval(what, &dictdata)  );
    612612       
    613         /* Loop on all top AVPs */
    614         CHECK_FCT(  fd_msg_browse(msg, MSG_BRW_FIRST_CHILD, (void *)&nextavp, NULL)  );
     613        /* Loop on all top AVPs in message or AVP */
     614        CHECK_FCT(  fd_msg_browse(reference, MSG_BRW_FIRST_CHILD, (void *)&nextavp, NULL)  );
    615615        while (nextavp) {
    616616               
     
    619619                        break;
    620620               
    621                 /* Otherwise move to next AVP in the message */
     621                /* Otherwise move to next AVP in the message or AVP */
    622622                CHECK_FCT( fd_msg_browse(nextavp, MSG_BRW_NEXT, (void *)&nextavp, NULL) );
    623623        }
  • tests/testmesg.c

    r1414 r1423  
    681681                        struct dict_object * avp_model;
    682682                        struct avp         * found;
     683                        struct avp         * grouped = NULL;
    683684                        struct avp_hdr     * avpdata = NULL;
    684685                       
     
    688689                        CPYBUF();
    689690                        CHECK( 0, fd_msg_parse_buffer( &buf_cpy, 344, &msg) );
    690                        
     691                        CHECK( 0, fd_msg_parse_dict( msg, fd_g_config->cnf_dict, NULL ) );
     692#if 0
     693                        LOG_D("msg: %s", fd_msg_dump_treeview(FD_DUMP_TEST_PARAMS, msg, fd_g_config->cnf_dict, 0, 1));
     694#endif
     695
    691696                        /* Search this AVP instance in the msg */
    692697                        CHECK( 0, fd_msg_search_avp( msg, avp_model, &found ) );
     
    695700                        CHECK( 0, fd_msg_avp_hdr ( found, &avpdata ) );
    696701                        CHECK( 3.1415F, avpdata->avp_value->f32 );
    697                        
     702
     703                        /* Search for the first grouped message */
     704                        {
     705                        struct dict_avp_request grouped_req = { 73565, 0, "AVP Test - grouped"};
     706                        CHECK( 0, fd_dict_search ( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME_AND_VENDOR, &grouped_req, &avp_model, ENOENT ) );
     707                        }
     708                        CHECK( 0, fd_msg_search_avp( msg, avp_model, &grouped ) );
     709#if 0
     710                        LOG_D("grouped: %s", fd_msg_dump_treeview(FD_DUMP_TEST_PARAMS, grouped, fd_g_config->cnf_dict, 0, 1));
     711#endif
     712
     713                        /* Find the first item in the grouped */
     714                        {
     715                        struct dict_avp_request avp_req = { 73565, 0, "AVP Test - os"};
     716                        CHECK( 0, fd_dict_search ( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME_AND_VENDOR, &avp_req, &avp_model, ENOENT ) );
     717                        }
     718
     719                        CHECK( 0, fd_msg_search_avp( grouped, avp_model, &found ) );
     720
     721                        /* Check the AVP value is "1" */
     722                        CHECK( 0, fd_msg_avp_hdr ( found, &avpdata ) );
     723                        CHECK( 8, avpdata->avp_value->os.len );
     724                        CHECK( 0, memcmp(avpdata->avp_value->os.data, "12345678", 8));
     725
    698726                        /* reinit the msg */
    699727                        CHECK( 0, fd_msg_free ( msg ) );
Note: See TracChangeset for help on using the changeset viewer.