| 543 | |
| 544 | |
| 545 | static int dm_receive_req(struct msg **_req, struct avp * avp, struct session * sess, void * data, enum disp_action * act) |
| 546 | { |
| 547 | cJSON *avps = NULL, *it; |
| 548 | struct msg *req = *_req; |
| 549 | struct msg_hdr *hdr = NULL; |
| 550 | str tid = STR_NULL, avp_arr = STR_NULL; |
| 551 | |
| 552 | FD_CHECK(fd_msg_hdr(req, &hdr)); |
| 553 | LM_DBG("received Diameter request (appl: %u, cmd: %u)\n", hdr->msg_appl, hdr->msg_code); |
| 554 | |
| 555 | cJSON_InitHooks(&shm_mem_hooks); |
| 556 | avps = cJSON_CreateArray(); |
| 557 | if (!avps) { |
| 558 | LM_ERR("oom 1\n"); |
| 559 | goto error; |
| 560 | } |
| 561 | |
| 562 | if (dm_avps2json(req, avps) != 0) { |
| 563 | LM_ERR("failed to pack request AVPs as JSON string\n"); |
| 564 | goto error; |
| 565 | } |
| 566 | |
| 567 | /* search for any "transaction identifier" in the request */ |
| 568 | for (it = avps->child; it; it = it->next) { |
| 569 | if (it->type != cJSON_Object || !it->child || it->child->next || it->child->type != cJSON_String) |
| 570 | continue; |
| 571 | |
| 572 | if (sess) { |
| 573 | if (!strcmp(it->child->string, "Session-Id")) { |
| 574 | LM_DBG("found Session-id: %s\n", it->child->valuestring); |
| 575 | init_str(&tid, it->child->valuestring); |
| 576 | break; |
| 577 | } |
| 578 | } else if (!strcmp(it->child->string, "Transaction-Id")) { |
| 579 | LM_DBG("found Transaction-id: %s\n", it->child->valuestring); |
| 580 | init_str(&tid, it->child->valuestring); |
| 581 | break; |
| 582 | } |
| 583 | } |
| 584 | |
| 585 | avp_arr.s = cJSON_PrintUnformatted(avps); |
| 586 | if (!avp_arr.s) { |
| 587 | LM_ERR("cJSON_PrintUnformatted failed\n"); |
| 588 | goto error; |
| 589 | } |
| 590 | avp_arr.len = strlen(avp_arr.s); |
| 591 | |
| 592 | /* keep the request for a while in order to be able to generate the answer */ |
| 593 | if (!dm_server_autoreply_error) |
| 594 | dm_update_unreplied_req(req); |
| 595 | |
| 596 | if (dm_dispatch_event_req(req, &tid, hdr->msg_appl, hdr->msg_code, &avp_arr)) |
| 597 | LM_ERR("failed to dispatch DM Request (tid: %.*s, %d/%d)\n", tid.len, |
| 598 | tid.s, hdr->msg_appl, hdr->msg_code); |
| 599 | |
| 600 | if (dm_server_autoreply_error) { |
| 601 | struct dm_message dm; |
| 602 |
no test coverage detected