| 280 | (_j)->len, (_j)->s, (_j)->len); \ |
| 281 | } while (0) |
| 282 | static 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); |
nothing calls this directly
no test coverage detected