Module: sip-router
Branch: master
Commit: 01e234a1e42fadcb9f3d14eedbcace1bb2ae56bb
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=01e234a…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: Tue Sep 9 12:06:03 2014 +0200
jsonrpc-s: new config variable $jsonrpl(key)
- access jsonrpc reply when using jsonrpc_exec(cmd)
- the key can be:
- code - the response code as when the jsonrpc would have been executed over
http
- text - the text following the code as when the jsonrpc would have
been executed over http
- body - the body of the jsonrpc response - the full json document
---
modules/jsonrpc-s/jsonrpc-s_mod.c | 90 +++++++++++++++++++++++++++++++------
1 files changed, 76 insertions(+), 14 deletions(-)
diff --git a/modules/jsonrpc-s/jsonrpc-s_mod.c b/modules/jsonrpc-s/jsonrpc-s_mod.c
index ebbf4c6..1951845 100644
--- a/modules/jsonrpc-s/jsonrpc-s_mod.c
+++ b/modules/jsonrpc-s/jsonrpc-s_mod.c
@@ -99,16 +99,25 @@ static param_export_t params[] = {
{0, 0, 0}
};
+static int jsonrpc_pv_get_jrpl(sip_msg_t *msg, pv_param_t *param, pv_value_t *res);
+static int jsonrpc_pv_parse_jrpl_name(pv_spec_t *sp, str *in);
+
+static pv_export_t mod_pvs[] = {
+ { {"jsonrpl", sizeof("jsonrpl")-1}, PVT_OTHER,
jsonrpc_pv_get_jrpl, 0,
+ jsonrpc_pv_parse_jrpl_name, 0, 0, 0 },
+ { {0, 0}, 0, 0, 0, 0, 0, 0, 0 }
+};
+
/** module exports */
struct module_exports exports= {
"jsonrpc-s",
DEFAULT_DLFLAGS, /* dlopen flags */
cmds,
params,
- 0, /* exported statistics */
- 0, /* exported MI functions */
- 0, /* exported pseudo-variables */
- 0, /* extra processes */
+ 0, /* exported statistics */
+ 0, /* exported MI functions */
+ mod_pvs, /* exported pseudo-variables */
+ 0, /* extra processes */
mod_init, /* module initialization function */
0,
0,
@@ -135,24 +144,32 @@ typedef struct jsonrpc_plain_reply {
int rcode; /**< reply code */
str rtext; /**< reply reason text */
str rbody; /**< reply body */
-} jsonrpc_play_reply_t;
+} jsonrpc_plain_reply_t;
-static jsonrpc_play_reply_t _jsonrpc_play_reply;
+static jsonrpc_plain_reply_t _jsonrpc_plain_reply;
static void jsonrpc_set_plain_reply(int rcode, str *rtext, str *rbody,
void (*free_fn)(void*))
{
- if(_jsonrpc_play_reply.rbody.s) {
- free_fn(_jsonrpc_play_reply.rbody.s);
+ if(_jsonrpc_plain_reply.rbody.s) {
+ free_fn(_jsonrpc_plain_reply.rbody.s);
}
- _jsonrpc_play_reply.rcode = rcode;
- _jsonrpc_play_reply.rtext = *rtext;
+ _jsonrpc_plain_reply.rcode = rcode;
+ _jsonrpc_plain_reply.rtext = *rtext;
if(rbody) {
- _jsonrpc_play_reply.rbody = *rbody;
+ _jsonrpc_plain_reply.rbody = *rbody;
} else {
- _jsonrpc_play_reply.rbody.s = NULL;
- _jsonrpc_play_reply.rbody.len = 0;
+ _jsonrpc_plain_reply.rbody.s = NULL;
+ _jsonrpc_plain_reply.rbody.len = 0;
+ }
+}
+
+static void jsonrpc_reset_plain_reply(void (*free_fn)(void*))
+{
+ if(_jsonrpc_plain_reply.rbody.s) {
+ free_fn(_jsonrpc_plain_reply.rbody.s);
}
+ memset(&_jsonrpc_plain_reply, 0, sizeof(jsonrpc_plain_reply_t));
}
/** Implementation of rpc_fault function required by the management API.
@@ -869,7 +886,7 @@ static int mod_init(void)
jsonrpc_register_rpc();
- memset(&_jsonrpc_play_reply, 0, sizeof(jsonrpc_play_reply_t));
+ memset(&_jsonrpc_plain_reply, 0, sizeof(jsonrpc_plain_reply_t));
return 0;
}
@@ -1090,3 +1107,48 @@ static int jsonrpc_register_rpc(void)
}
return 0;
}
+
+/**
+ *
+ */
+static int jsonrpc_pv_get_jrpl(sip_msg_t *msg, pv_param_t *param, pv_value_t *res)
+{
+ switch(param->pvn.u.isname.name.n)
+ {
+ case 0:
+ return pv_get_uintval(msg, param, res,
+ (unsigned int)_jsonrpc_plain_reply.rcode);
+ case 1:
+ if(_jsonrpc_plain_reply.rtext.s==NULL)
+ return pv_get_null(msg, param, res);
+ return pv_get_strval(msg, param, res, &_jsonrpc_plain_reply.rtext);
+ case 2:
+ if(_jsonrpc_plain_reply.rbody.s==NULL)
+ return pv_get_null(msg, param, res);
+ return pv_get_strval(msg, param, res, &_jsonrpc_plain_reply.rbody);
+ default:
+ return pv_get_null(msg, param, res);
+ }
+}
+
+/**
+ *
+ */
+static int jsonrpc_pv_parse_jrpl_name(pv_spec_t *sp, str *in)
+{
+ if(in->len!=4) {
+ LM_ERR("unknown inner name [%.*s]\n", in->len, in->s);
+ return -1;
+ }
+ if(strncmp(in->s, "code", 4)==0) {
+ sp->pvp.pvn.u.isname.name.n = 0;
+ } else if(strncmp(in->s, "text", 4)==0) {
+ sp->pvp.pvn.u.isname.name.n = 1;
+ } else if(strncmp(in->s, "body", 4)==0) {
+ sp->pvp.pvn.u.isname.name.n = 2;
+ } else {
+ LM_ERR("unknown inner name [%.*s]\n", in->len, in->s);
+ return -1;
+ }
+ return 0;
+}