Changeset 1425:b09f1b4c9fad in freeDiameter for libfdcore
- Timestamp:
- Feb 19, 2020, 8:26:29 AM (4 years ago)
- Branch:
- default
- Phase:
- public
- committer:
- Luke Mewburn <luke@mewburn.net> 1582068430 -39600
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libfdcore/messages.c
r1383 r1425 43 43 static struct dict_object * dict_avp_FAVP= NULL; /* Failed-AVP */ 44 44 static struct dict_object * dict_avp_RC = NULL; /* Result-Code */ 45 static struct dict_object * dict_avp_ER = NULL; /* Experimental-Result */ 46 static struct dict_object * dict_avp_VI = NULL; /* Vendor-Id */ 47 static struct dict_object * dict_avp_ERC = NULL; /* Experimental-Result-Code */ 45 48 struct dict_object * fd_dict_avp_OSI = NULL; /* Origin-State-Id */ 46 49 struct dict_object * fd_dict_cmd_CER = NULL; /* Capabilities-Exchange-Request */ … … 64 67 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Error-Reporting-Host", &dict_avp_ERH , ENOENT) ); 65 68 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) ); 66 72 67 73 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Disconnect-Cause", &fd_dict_avp_DC , ENOENT) ); … … 167 173 168 174 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 */ 176 int 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 ) 171 177 { 172 178 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;177 179 uint32_t rc_val = 0; 178 180 int set_e_bit=0; 179 181 int std_err_msg=0; 180 182 181 TRACE_ENTRY("%p % s %p %p %d", msg, rescode, errormsg, optavp, type_id);182 183 CHECK_PARAMS( msg && res code );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 ); 184 186 185 187 /* Find the enum value corresponding to the rescode string, this will give the class of error */ 186 188 { 187 189 struct dict_object * enum_obj = NULL; 190 191 /* Search in the restype */ 188 192 struct dict_enumval_request req; 189 193 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; 193 195 194 196 /* Now search for the value given as parameter */ … … 208 210 } 209 211 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 } 220 260 221 261 if (type_id == 2) { 222 262 /* Add the Error-Reporting-Host AVP */ 223 263 struct avp * avp_ERH = NULL; 224 264 CHECK_FCT( fd_msg_avp_new( dict_avp_ERH, 0, &avp_ERH ) ); 225 265 … … 232 272 /* Add it to the message */ 233 273 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 */ 238 277 if (optavp) { 278 struct avp * avp_FAVP= NULL; 239 279 struct avp * optavp_cpy = NULL; 240 280 struct avp_hdr *opt_hdr, *optcpy_hdr; … … 310 350 if (std_err_msg || errormsg) { 311 351 /* Add the Error-Message AVP */ 312 352 struct avp * avp_EM = NULL; 313 353 CHECK_FCT( fd_msg_avp_new( dict_avp_EM, 0, &avp_EM ) ); 314 354 … … 330 370 331 371 return 0; 372 } 373 374 int 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); 332 379 } 333 380
Note: See TracChangeset
for help on using the changeset viewer.