Navigation


Changeset 1425:b09f1b4c9fad in freeDiameter for libfdcore


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

fd_msg_add_result: add function

Add fd_msg_add_result() as a superset of fd_msg_rescode_set()
to allow setting of either Result-Code or Experimental-Result (Grouped),
depending upon whether the supplied vendor is 0 or not.

Reimplement fd_msg_rescode_set() in terms of fd_msg_add_result().

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libfdcore/messages.c

    r1383 r1425  
    4343static struct dict_object * dict_avp_FAVP= NULL; /* Failed-AVP */
    4444static struct dict_object * dict_avp_RC  = NULL; /* Result-Code */
     45static struct dict_object * dict_avp_ER  = NULL; /* Experimental-Result */
     46static struct dict_object * dict_avp_VI  = NULL; /* Vendor-Id */
     47static struct dict_object * dict_avp_ERC = NULL; /* Experimental-Result-Code */
    4548struct dict_object * fd_dict_avp_OSI = NULL; /* Origin-State-Id */
    4649struct dict_object * fd_dict_cmd_CER = NULL; /* Capabilities-Exchange-Request */
     
    6467        CHECK_FCT(  fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Error-Reporting-Host", &dict_avp_ERH , ENOENT)  );
    6568        CHECK_FCT(  fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Failed-AVP",         &dict_avp_FAVP, ENOENT)  );
     69        CHECK_FCT(  fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Experimental-Result", &dict_avp_ER, ENOENT)  );
     70        CHECK_FCT(  fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Vendor-Id",          &dict_avp_VI, ENOENT)  );
     71        CHECK_FCT(  fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Experimental-Result-Code", &dict_avp_ERC, ENOENT)  );
    6672
    6773        CHECK_FCT(  fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Disconnect-Cause",   &fd_dict_avp_DC , ENOENT)  );
     
    167173
    168174
    169 /* Add Result-Code and eventually Failed-AVP, Error-Message and Error-Reporting-Host AVPs */
    170 int fd_msg_rescode_set( struct msg * msg, char * rescode, char * errormsg, struct avp * optavp, int type_id )
     175/* Add Result-Code or Experimental-Result, and eventually Failed-AVP, Error-Message and Error-Reporting-Host AVPs */
     176int fd_msg_add_result( struct msg * msg, vendor_id_t vendor, struct dict_object * restype, char * rescode, char * errormsg, struct avp * optavp, int type_id )
    171177{
    172178        union avp_value val;
    173         struct avp * avp_RC  = NULL;
    174         struct avp * avp_EM  = NULL;
    175         struct avp * avp_ERH = NULL;
    176         struct avp * avp_FAVP= NULL;
    177179        uint32_t rc_val = 0;
    178180        int set_e_bit=0;
    179181        int std_err_msg=0;
    180182
    181         TRACE_ENTRY("%p %s %p %p %d", msg, rescode, errormsg, optavp, type_id);
    182 
    183         CHECK_PARAMS(  msg && rescode  );
     183        TRACE_ENTRY("%p %d %p %s %p %p %d", msg, vendor, restype, rescode, errormsg, optavp, type_id);
     184
     185        CHECK_PARAMS(  msg && restype && rescode  );
    184186
    185187        /* Find the enum value corresponding to the rescode string, this will give the class of error */
    186188        {
    187189                struct dict_object * enum_obj = NULL;
     190
     191                /* Search in the restype */
    188192                struct dict_enumval_request req;
    189193                memset(&req, 0, sizeof(struct dict_enumval_request));
    190 
    191                 /* First, get the enumerated type of the Result-Code AVP (this is fast, no need to cache the object) */
    192                 CHECK_FCT(  fd_dict_search( fd_g_config->cnf_dict, DICT_TYPE, TYPE_OF_AVP, dict_avp_RC, &(req.type_obj), ENOENT  )  );
     194                req.type_obj = restype;
    193195
    194196                /* Now search for the value given as parameter */
     
    208210        }
    209211
    210         /* Create the Result-Code AVP */
    211         CHECK_FCT( fd_msg_avp_new( dict_avp_RC, 0, &avp_RC ) );
    212 
    213         /* Set its value */
    214         memset(&val, 0, sizeof(val));
    215         val.u32  = rc_val;
    216         CHECK_FCT( fd_msg_avp_setvalue( avp_RC, &val ) );
    217 
    218         /* Add it to the message */
    219         CHECK_FCT( fd_msg_avp_add( msg, MSG_BRW_LAST_CHILD, avp_RC ) );
     212        if (vendor == 0) {
     213                /* Vendor 0; create the Result-Code AVP */
     214                struct avp * avp_RC  = NULL;
     215                CHECK_FCT( fd_msg_avp_new( dict_avp_RC, 0, &avp_RC ) );
     216
     217                /* Set its value */
     218                memset(&val, 0, sizeof(val));
     219                val.u32  = rc_val;
     220                CHECK_FCT( fd_msg_avp_setvalue( avp_RC, &val ) );
     221
     222                /* Add it to the message */
     223                CHECK_FCT( fd_msg_avp_add( msg, MSG_BRW_LAST_CHILD, avp_RC ) );
     224        } else {
     225                /* Vendor !0; create the Experimental-Result AVP */
     226                struct avp * avp_ER  = NULL;
     227                CHECK_FCT( fd_msg_avp_new( dict_avp_ER, 0, &avp_ER ) );
     228
     229                /* Create the Vendor-Id AVP and add to Experimental-Result */
     230                {
     231                        struct avp * avp_VI  = NULL;
     232                        CHECK_FCT( fd_msg_avp_new( dict_avp_VI, 0, &avp_VI ) );
     233
     234                        /* Set Vendor-Id value to vendor */
     235                        memset(&val, 0, sizeof(val));
     236                        val.u32  = vendor;
     237                        CHECK_FCT( fd_msg_avp_setvalue( avp_VI, &val ) );
     238
     239                        /* Add it to Experimental-Result */
     240                        CHECK_FCT( fd_msg_avp_add( avp_ER, MSG_BRW_LAST_CHILD, avp_VI ) );
     241                }
     242
     243                /* Create the Experimental-Result-Code AVP and add to Experimental-Result */
     244                {
     245                        struct avp * avp_ERC  = NULL;
     246                        CHECK_FCT( fd_msg_avp_new( dict_avp_ERC, 0, &avp_ERC ) );
     247
     248                        /* Set Experimental-Result-Code value to rc_val */
     249                        memset(&val, 0, sizeof(val));
     250                        val.u32  = rc_val;
     251                        CHECK_FCT( fd_msg_avp_setvalue( avp_ERC, &val ) );
     252
     253                        /* Add it to Experimental-Result */
     254                        CHECK_FCT( fd_msg_avp_add( avp_ER, MSG_BRW_LAST_CHILD, avp_ERC ) );
     255                }
     256
     257                /* Add it to the message */
     258                CHECK_FCT( fd_msg_avp_add( msg, MSG_BRW_LAST_CHILD, avp_ER ) );
     259        }
    220260
    221261        if (type_id == 2) {
    222262                /* Add the Error-Reporting-Host AVP */
    223 
     263                struct avp * avp_ERH = NULL;
    224264                CHECK_FCT( fd_msg_avp_new( dict_avp_ERH, 0, &avp_ERH ) );
    225265
     
    232272                /* Add it to the message */
    233273                CHECK_FCT( fd_msg_avp_add( msg, MSG_BRW_LAST_CHILD, avp_ERH ) );
    234 
    235         }
    236 
    237         /* Now add the optavp in a FailedAVP if provided */
     274        }
     275
     276        /* Now add the optavp in a Failed-AVP if provided */
    238277        if (optavp) {
     278                struct avp * avp_FAVP= NULL;
    239279                struct avp * optavp_cpy = NULL;
    240280                struct avp_hdr *opt_hdr, *optcpy_hdr;
     
    310350        if (std_err_msg || errormsg) {
    311351                /* Add the Error-Message AVP */
    312 
     352                struct avp * avp_EM  = NULL;
    313353                CHECK_FCT( fd_msg_avp_new( dict_avp_EM, 0, &avp_EM ) );
    314354
     
    330370
    331371        return 0;
     372}
     373
     374int fd_msg_rescode_set( struct msg * msg, char * rescode, char * errormsg, struct avp * optavp, int type_id )
     375{
     376        struct dict_object * restype = NULL;
     377        CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_TYPE, TYPE_OF_AVP, dict_avp_RC, &restype, ENOENT ) );
     378        return fd_msg_add_result(msg, 0, restype, rescode, errormsg, optavp, type_id);
    332379}
    333380
Note: See TracChangeset for help on using the changeset viewer.