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

Function dm_send_request

modules/aaa_diameter/aaa_diameter.c:282–360  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

280 (_j)->len, (_j)->s, (_j)->len); \
281 } while (0)
282static int dm_send_request(struct sip_msg *msg, int *app_id, int *cmd_code,
283 str *avp_json, pv_spec_t *rpl_avps_pv)
284{
285 aaa_message *dmsg = NULL;
286 struct dict_object *req;
287 cJSON *avps;
288 int rc;
289 struct dm_cond *rpl = NULL;
290 char *rpl_avps = NULL;
291
292 if ((rc = fd_dict_search(fd_g_config->cnf_dict, DICT_COMMAND,CMD_BY_CODE_R,
293 cmd_code, &req, ENOENT)) != 0) {
294 LM_ERR("unrecognized Request command code: %d (errno: %d)\n", *cmd_code, rc);
295 LM_ERR("to fix this, you can define the Request/Answer format in the "
296 "'extra-avps-file' config file\n");
297 return -1;
298 }
299
300 LM_DBG("found a matching dict entry for command code %d\n", *cmd_code);
301
302 if (!avp_json || !avp_json->s) {
303 LM_ERR("NULL JSON input\n");
304 return -1;
305 }
306
307 avps = cJSON_Parse(avp_json->s);
308 if (!avps) {
309 LM_ERR_DM_JSON("failed to parse input JSON", avp_json);
310 return -1;
311 }
312
313 if (avps->type != cJSON_Array) {
314 LM_ERR_DM_JSON("bad JSON type: must be Array", avp_json);
315 goto error;
316 }
317
318 dmsg = _dm_create_message(NULL, AAA_CUSTOM_REQ, *app_id, *cmd_code, NULL);
319 if (!dmsg) {
320 LM_ERR("oom\n");
321 goto error;
322 }
323
324 if (dm_build_avps(&((struct dm_message *)(dmsg->avpair))->avps,
325 avps->child) != 0) {
326 LM_ERR_DM_JSON("failed to unpack JSON", avp_json);
327 _dm_destroy_message(dmsg);
328 goto error;
329 }
330 cJSON_Delete(avps);
331
332 if (_dm_send_message(NULL, dmsg, &rpl) != 0)
333 goto ret;
334 rc = _dm_get_message_response(rpl, (rpl_avps_pv?&rpl_avps:NULL));
335
336 if (rpl_avps_pv) {
337 pv_value_t val = {(str){rpl_avps, strlen(rpl_avps)}, 0, PV_VAL_STR};
338 if (pv_set_value(msg, rpl_avps_pv, 0, &val) != 0)
339 LM_ERR("failed to set output rpl_avps pv to: %s\n", rpl_avps);

Callers

nothing calls this directly

Calls 9

_dm_create_messageFunction · 0.85
dm_build_avpsFunction · 0.85
_dm_destroy_messageFunction · 0.85
_dm_send_messageFunction · 0.85
_dm_get_message_responseFunction · 0.85
pv_set_valueFunction · 0.85
cJSON_ParseFunction · 0.50
cJSON_DeleteFunction · 0.50

Tested by

no test coverage detected