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

Function dm_send_request_async

modules/aaa_diameter/aaa_diameter.c:549–616  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

547}
548
549static int dm_send_request_async(struct sip_msg *msg, async_ctx *ctx,
550 int *app_id, int *cmd_code, str *avp_json, pv_spec_t *rpl_avps_pv)
551{
552 aaa_message *dmsg = NULL;
553 struct dict_object *req;
554 cJSON *avps;
555 struct dm_async_msg *amsg;
556 struct dm_cond *cond;
557
558 if (fd_dict_search(fd_g_config->cnf_dict, DICT_COMMAND, CMD_BY_CODE_R,
559 cmd_code, &req, ENOENT) == ENOENT) {
560 LM_ERR("unrecognized Request command code: %d\n", *cmd_code);
561 LM_ERR("to fix this, you can define the Request/Answer format in the "
562 "'extra-avps-file' config file\n");
563 return -1;
564 }
565
566 LM_DBG("found a matching dict entry for command code %d\n", *cmd_code);
567
568 if (!avp_json || !avp_json->s) {
569 LM_ERR("NULL JSON input\n");
570 return -1;
571 }
572
573 avps = cJSON_Parse(avp_json->s);
574 if (!avps) {
575 LM_ERR_DM_JSON("failed to parse input JSON", avp_json);
576 return -1;
577 }
578
579 if (avps->type != cJSON_Array) {
580 LM_ERR_DM_JSON("bad JSON type: must be Array", avp_json);
581 goto error;
582 }
583
584 dmsg = _dm_create_message(NULL, AAA_CUSTOM_REQ, *app_id, *cmd_code, NULL);
585 if (!dmsg) {
586 LM_ERR("oom\n");
587 goto error;
588 }
589
590 if (dm_build_avps(&((struct dm_message *)(dmsg->avpair))->avps,
591 avps->child) != 0) {
592 LM_ERR_DM_JSON("failed to unpack JSON", avp_json);
593 _dm_destroy_message(dmsg);
594 goto error;
595 }
596 if (_dm_send_message_async(NULL, dmsg, &async_status, &cond) < 0) {
597 LM_ERR("cannot send async message!\n");
598 goto error;
599 }
600
601 amsg = dm_get_async_msg(rpl_avps_pv, cond);
602 if (!amsg)
603 goto error;
604 cJSON_Delete(avps);
605
606 ASYNC_SET_RESUME_F(ctx, dm_send_request_async_reply);

Callers

nothing calls this directly

Calls 7

_dm_create_messageFunction · 0.85
dm_build_avpsFunction · 0.85
_dm_destroy_messageFunction · 0.85
_dm_send_message_asyncFunction · 0.85
dm_get_async_msgFunction · 0.85
cJSON_ParseFunction · 0.50
cJSON_DeleteFunction · 0.50

Tested by

no test coverage detected