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

Function jrpc_request

modules/jsonrpc/jsonrpc.c:432–462  ·  view source on GitHub ↗

* Function that runs a JSON-RPC request * Returns: * -1: internal error * -2: communication error * -3: reply error * 1: success */

Source from the content-addressed store, hash-verified

430 * 1: success
431 */
432static 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
464static char *jsonrpc_build_cmd(str *method, str *params, int *id)
465{

Callers

nothing calls this directly

Calls 5

jsonrpc_build_cmdFunction · 0.85
jsonrpc_handle_cmdFunction · 0.85
cJSON_PurgeStringFunction · 0.85
pv_set_valueFunction · 0.85
jsonrpc_unique_idFunction · 0.70

Tested by

no test coverage detected