Module: kamailio
Branch: 5.1
Commit: da08b81446fb4cb64a4c930cc943f851a7b19424
URL:
https://github.com/kamailio/kamailio/commit/da08b81446fb4cb64a4c930cc943f85…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2018-08-20T11:20:03+02:00
jsonrpcs: store id attribute inside context for async response
(cherry picked from commit 8601f89bcc309e5676647019a13246578540ad71)
---
Modified: src/modules/jsonrpcs/jsonrpcs_mod.c
Modified: src/modules/jsonrpcs/jsonrpcs_mod.h
---
Diff:
https://github.com/kamailio/kamailio/commit/da08b81446fb4cb64a4c930cc943f85…
Patch:
https://github.com/kamailio/kamailio/commit/da08b81446fb4cb64a4c930cc943f85…
---
diff --git a/src/modules/jsonrpcs/jsonrpcs_mod.c b/src/modules/jsonrpcs/jsonrpcs_mod.c
index 633847fc9d..6e43e33332 100644
--- a/src/modules/jsonrpcs/jsonrpcs_mod.c
+++ b/src/modules/jsonrpcs/jsonrpcs_mod.c
@@ -387,15 +387,26 @@ static int jsonrpc_send(jsonrpc_ctx_t* ctx)
ctx->rpl_node = 0;
}
}
- nj = srjson_GetObjectItem(ctx->jreq, ctx->jreq->root, "id");
- if(nj!=NULL) {
- if(nj->valuestring!=NULL) {
+ if(ctx->jreq!=NULL && ctx->jreq->root!=NULL) {
+ nj = srjson_GetObjectItem(ctx->jreq, ctx->jreq->root, "id");
+ if(nj!=NULL) {
+ if(nj->valuestring!=NULL) {
+ srjson_AddStrStrToObject(ctx->jrpl, ctx->jrpl->root,
+ "id", 2,
+ nj->valuestring, strlen(nj->valuestring));
+ } else {
+ srjson_AddNumberToObject(ctx->jrpl, ctx->jrpl->root, "id",
+ nj->valuedouble);
+ }
+ }
+ } else {
+ if(ctx->jsrid_type == 1) {
srjson_AddStrStrToObject(ctx->jrpl, ctx->jrpl->root,
"id", 2,
- nj->valuestring, strlen(nj->valuestring));
- } else {
+ ctx->jsrid_val, strlen(ctx->jsrid_val));
+ } else if(ctx->jsrid_type == 2) {
srjson_AddNumberToObject(ctx->jrpl, ctx->jrpl->root, "id",
- nj->valuedouble);
+ (double)(*(long*)ctx->jsrid_val));
}
}
@@ -970,6 +981,7 @@ static struct rpc_delayed_ctx* jsonrpc_delayed_ctx_new(jsonrpc_ctx_t*
ctx)
jsonrpc_ctx_t* r_ctx;
sip_msg_t* shm_msg;
int len;
+ srjson_t *nj = NULL;
ret=0;
shm_msg=0;
@@ -984,6 +996,22 @@ static struct rpc_delayed_ctx* jsonrpc_delayed_ctx_new(jsonrpc_ctx_t*
ctx)
LM_ERR("delayed response implemented only for HTTP transport\n");
return 0;
}
+
+ if(ctx->jreq==NULL || ctx->jreq->root==NULL) {
+ LM_ERR("invalid context attributes\n");
+ return 0;
+ }
+
+ nj = srjson_GetObjectItem(ctx->jreq, ctx->jreq->root, "id");
+ if(nj==NULL) {
+ LM_ERR("id attribute is missing\n");
+ return 0;
+ }
+ if(nj->valuestring!=NULL && strlen(nj->valuestring)>JSONRPC_ID_SIZE-1)
{
+ LM_ERR("id attribute is too long (%lu/%d)\n", strlen(nj->valuestring),
+ JSONRPC_ID_SIZE);
+ return 0;
+ }
/* clone the sip msg */
if(ctx->msg!=NULL) {
shm_msg=sip_msg_shm_clone(ctx->msg, &len, 1);
@@ -1005,6 +1033,14 @@ static struct rpc_delayed_ctx*
jsonrpc_delayed_ctx_new(jsonrpc_ctx_t* ctx)
r_ctx->msg=shm_msg;
r_ctx->msg_shm_block_size=len;
+ if(nj->valuestring!=NULL) {
+ strcpy(r_ctx->jsrid_val, nj->valuestring);
+ r_ctx->jsrid_type = 1;
+ } else {
+ *(long*)r_ctx->jsrid_val = (long)nj->valuedouble;
+ r_ctx->jsrid_type = 2;
+ }
+
return ret;
error:
if (shm_msg)
diff --git a/src/modules/jsonrpcs/jsonrpcs_mod.h b/src/modules/jsonrpcs/jsonrpcs_mod.h
index ef15c3ec93..173810a42e 100644
--- a/src/modules/jsonrpcs/jsonrpcs_mod.h
+++ b/src/modules/jsonrpcs/jsonrpcs_mod.h
@@ -29,6 +29,7 @@
#include "../../core/parser/msg_parser.h"
#include "../../lib/srutils/srjson.h"
+#define JSONRPC_ID_SIZE 64
/** The context of the jsonrpc request being processed.
*
@@ -54,6 +55,8 @@ typedef struct jsonrpc_ctx {
int http_code; /**< http reply code */
str http_text; /**< http reply reason text */
int transport; /**< RPC transport */
+ int jsrid_type; /**< type for Json RPC id value */
+ char jsrid_val[JSONRPC_ID_SIZE]; /**< value for Json RPC id */
} jsonrpc_ctx_t;
/* extra rpc_ctx_t flags */