* Function that runs a JSON-RPC request * Returns: * -1: internal error * -2: communication error * -3: reply error * 1: success */
| 430 | * 1: success |
| 431 | */ |
| 432 | static int jrpc_request(struct sip_msg *msg, union sockaddr_union *dst, |
| 433 | str *method, str *params, pv_spec_p spec) |
| 434 | { |
| 435 | int id, ret; |
| 436 | char *cmd; |
| 437 | pv_value_t val; |
| 438 | |
| 439 | id = jsonrpc_unique_id(); |
| 440 | cmd = jsonrpc_build_cmd(method, params, &id); |
| 441 | if (!cmd) { |
| 442 | LM_ERR("cannot build jsonrpc command \n"); |
| 443 | return -1; |
| 444 | } |
| 445 | |
| 446 | ret = jsonrpc_handle_cmd(dst, cmd, &id, &val); |
| 447 | cJSON_PurgeString(cmd); |
| 448 | if (ret == -2) { |
| 449 | LM_ERR("communication error with %s:%hu\n", JSONRPC_PRINT(dst)); |
| 450 | return ret; |
| 451 | } |
| 452 | |
| 453 | if (pv_set_value(msg, spec, 0, &val) < 0) { |
| 454 | LM_ERR("cannot set returned value!\n"); |
| 455 | ret = -1; |
| 456 | } |
| 457 | /* XXX: free the value returned */ |
| 458 | if ((val.flags & PV_VAL_STR) && !(val.flags & PV_VAL_INT)) |
| 459 | cJSON_PurgeString(val.rs.s); |
| 460 | |
| 461 | return ret; |
| 462 | } |
| 463 | |
| 464 | static char *jsonrpc_build_cmd(str *method, str *params, int *id) |
| 465 | { |
nothing calls this directly
no test coverage detected