MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / dm_avps2json

Function dm_avps2json

modules/aaa_diameter/dm_impl.c:400–542  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

398
399
400static int dm_avps2json(void *root, cJSON *avps)
401{
402 cJSON *item = NULL;
403 struct avp *it = NULL;
404 struct avp_hdr *h = NULL;
405 int i = 0;
406
407 FD_CHECK_GT(fd_msg_browse(root, MSG_BRW_FIRST_CHILD, &it, NULL));
408
409 LM_DBG("------------ AVP iteration ----------------\n");
410
411 while (it) {
412 cJSON *val;
413 struct dict_object *obj;
414 struct dict_avp_data dm_avp;
415 struct dict_avp_enc_f *dm_func;
416 int int_type = 1;
417 double num_val = 0;
418
419 FD_CHECK_GT(fd_msg_avp_hdr(it, &h));
420
421 if (h->avp_flags & AVP_FLAG_VENDOR) {
422 struct dict_avp_request ar;
423 memset(&ar, 0, sizeof ar);
424 ar.avp_code = h->avp_code;
425 ar.avp_vendor = h->avp_vendor;
426 __FD_CHECK_GT(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_CODE_AND_VENDOR,
427 &ar, &obj, ENOENT), 0, skip);
428 } else {
429 __FD_CHECK_GT(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_CODE,
430 &h->avp_code, &obj, ENOENT), 0, skip);
431 }
432 FD_CHECK_GT(fd_dict_getval(obj, &dm_avp));
433
434 item = cJSON_CreateObject();
435 if (!item) {
436 LM_ERR("oom 2\n");
437 goto out;
438 }
439
440
441 dm_func = dm_enc_get(dm_avp.avp_code, dm_avp.avp_vendor);
442 if (dm_func && dm_func->dec_func) {
443 LM_DBG("%2d. got encoded AVP %s, code: %u\n", i, dm_avp.avp_name, dm_avp.avp_code);
444 val = dm_func->dec_func(h, &dm_avp);
445 if (!val) {
446 LM_ERR("cannot decode value %d/%d\n", dm_avp.avp_code, dm_avp.avp_vendor);
447 goto out;
448 }
449 goto add;
450 }
451
452 switch (dm_avp.avp_basetype) {
453 case AVP_TYPE_GROUPED:
454 LM_DBG("%2d. got grouped AVP %s (%u)\n", i, dm_avp.avp_name, dm_avp.avp_code);
455 int_type = 0;
456
457 val = cJSON_CreateArray();

Callers 2

dm_receive_reqFunction · 0.85
dm_receive_msgFunction · 0.85

Calls 8

dm_enc_getFunction · 0.85
cJSON_CreateStrFunction · 0.85
cJSON_CreateObjectFunction · 0.50
cJSON_CreateArrayFunction · 0.50
cJSON_DeleteFunction · 0.50
cJSON_CreateNumberFunction · 0.50
cJSON_AddItemToObjectFunction · 0.50
cJSON_AddItemToArrayFunction · 0.50

Tested by

no test coverage detected