Module: kamailio
Branch: master
Commit: 1db7dc4de6588131b4340390b5996141940b7ef0
URL: 
https://github.com/kamailio/kamailio/commit/1db7dc4de6588131b4340390b5996141940b7ef0

Author: Daniel-Constantin Mierla <[email protected]>
Committer: Daniel-Constantin Mierla <[email protected]>
Date: 2018-09-11T23:12:02+02:00

jsonrpcs: set global active context to delayed value for async commands

- GH #1640

---

Modified: src/modules/jsonrpcs/jsonrpcs_mod.c

---

Diff:  
https://github.com/kamailio/kamailio/commit/1db7dc4de6588131b4340390b5996141940b7ef0.diff
Patch: 
https://github.com/kamailio/kamailio/commit/1db7dc4de6588131b4340390b5996141940b7ef0.patch

---

diff --git a/src/modules/jsonrpcs/jsonrpcs_mod.c 
b/src/modules/jsonrpcs/jsonrpcs_mod.c
index 5c558c60c4..1fd737298a 100644
--- a/src/modules/jsonrpcs/jsonrpcs_mod.c
+++ b/src/modules/jsonrpcs/jsonrpcs_mod.c
@@ -120,7 +120,8 @@ extern int jsonrpc_dgram_destroy(void);
  * being currently processed.
  * @sa rpc_ctx
  */
-static jsonrpc_ctx_t _jsonrpc_ctx;
+static jsonrpc_ctx_t _jsonrpc_ctx_global;
+static jsonrpc_ctx_t *_jsonrpc_ctx_active = NULL;
 
 static xhttp_api_t xhttp_api;
 
@@ -277,6 +278,7 @@ static int jsonrpc_delayed_reply_ctx_init(jsonrpc_ctx_t* 
ctx)
                if (jsonrpc_init_reply(ctx) < 0)
                        return -1;
                jsonrpc_reset_plain_reply(ctx->jrpl->free_fn);
+               _jsonrpc_ctx_active = ctx;
        }
        return 0;
 }
@@ -773,10 +775,10 @@ static int jsonrpc_struct_add(srjson_t *jnode, char* fmt, 
...)
        }
        isobject = (jnode->type==srjson_Object);
 
-       ctx = &_jsonrpc_ctx;
-       if(ctx->jrpl==NULL) {
-               LM_ERR("reply object not initialized in rpl context - flags 
0x%x\n",
-                               ctx->flags);
+       ctx = _jsonrpc_ctx_active;
+       if(ctx==NULL || ctx->jrpl==NULL) {
+               LM_ERR("reply object not initialized in rpl context %p - flags 
0x%x\n",
+                               ctx, (ctx)?ctx->flags:0);
                return -1;
        }
 
@@ -844,10 +846,10 @@ static int jsonrpc_array_add(srjson_t *jnode, char* fmt, 
...)
                return -1;
        }
 
-       ctx = &_jsonrpc_ctx;
-       if(ctx->jrpl==NULL) {
-               LM_ERR("reply object not initialized in rpl context - flags 
0x%x\n",
-                               ctx->flags);
+       ctx = _jsonrpc_ctx_active;
+       if(ctx==NULL || ctx->jrpl==NULL) {
+               LM_ERR("reply object not initialized in rpl context %p - flags 
0x%x\n",
+                               ctx, (ctx)?ctx->flags:0);
                return -1;
        }
 
@@ -905,10 +907,10 @@ static int jsonrpc_struct_printf(srjson_t *jnode, char* 
mname, char* fmt, ...)
                return -1;
        }
 
-       ctx = &_jsonrpc_ctx;
-       if(ctx->jrpl==NULL) {
-               LM_ERR("reply object not initialized in rpl context - flags 
0x%x\n",
-                               ctx->flags);
+       ctx = _jsonrpc_ctx_active;
+       if(ctx==NULL || ctx->jrpl==NULL) {
+               LM_ERR("reply object not initialized in rpl context %p - flags 
0x%x\n",
+                               ctx, (ctx)?ctx->flags:0);
                return -1;
        }
 
@@ -1100,6 +1102,7 @@ static void jsonrpc_delayed_ctx_close(struct 
rpc_delayed_ctx* dctx)
        r_ctx->msg=0;
        dctx->reply_ctx=0;
        shm_free(dctx);
+       _jsonrpc_ctx_active = NULL;
 
        return;
 }
@@ -1233,7 +1236,8 @@ static int jsonrpc_dispatch(sip_msg_t* msg, char* s1, 
char* s2)
        }
 
        /* initialize jsonrpc context */
-       ctx = &_jsonrpc_ctx;
+       _jsonrpc_ctx_active = &_jsonrpc_ctx_global;
+       ctx = _jsonrpc_ctx_active;
        memset(ctx, 0, sizeof(jsonrpc_ctx_t));
        ctx->msg = msg;
        /* parse the jsonrpc request */
@@ -1312,7 +1316,8 @@ int jsonrpc_exec_ex(str *cmd, str *rpath)
        scmd = *cmd;
 
        /* initialize jsonrpc context */
-       ctx = &_jsonrpc_ctx;
+       _jsonrpc_ctx_active = &_jsonrpc_ctx_global;
+       ctx = _jsonrpc_ctx_active;
        memset(ctx, 0, sizeof(jsonrpc_ctx_t));
        ctx->msg = NULL; /* mark it not send a reply out */
        /* parse the jsonrpc request */


_______________________________________________
Kamailio (SER) - Development Mailing List
[email protected]
https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-dev

Reply via email to