[sr-dev] git:master:9364b169: jsonrpcs: proper propagation of rpc fault code and message

Daniel-Constantin Mierla miconda at gmail.com
Thu Oct 19 08:59:40 CEST 2017


Module: kamailio
Branch: master
Commit: 9364b1691412ec1d3d59ca8a801613470e079c1d
URL: https://github.com/kamailio/kamailio/commit/9364b1691412ec1d3d59ca8a801613470e079c1d

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2017-10-19T08:58:59+02:00

jsonrpcs: proper propagation of rpc fault code and message

---

Modified: src/modules/jsonrpcs/jsonrpcs_mod.c
Modified: src/modules/jsonrpcs/jsonrpcs_mod.h

---

Diff:  https://github.com/kamailio/kamailio/commit/9364b1691412ec1d3d59ca8a801613470e079c1d.diff
Patch: https://github.com/kamailio/kamailio/commit/9364b1691412ec1d3d59ca8a801613470e079c1d.patch

---

diff --git a/src/modules/jsonrpcs/jsonrpcs_mod.c b/src/modules/jsonrpcs/jsonrpcs_mod.c
index e2b4b80cb6..633847fc9d 100644
--- a/src/modules/jsonrpcs/jsonrpcs_mod.c
+++ b/src/modules/jsonrpcs/jsonrpcs_mod.c
@@ -299,13 +299,23 @@ static void jsonrpc_fault(jsonrpc_ctx_t* ctx, int code, char* fmt, ...)
 
 	jsonrpc_delayed_reply_ctx_init(ctx);
 
-	ctx->http_code = code;
+	if(code <= 100) {
+		ctx->http_code = 500;
+	} else {
+		ctx->http_code = code;
+	}
 	va_start(ap, fmt);
 	vsnprintf(jsonrpc_error_buf, JSONRPC_ERROR_REASON_BUF_LEN, fmt, ap);
 	va_end(ap);
-	ctx->http_text.len = strlen(jsonrpc_error_buf);
+	ctx->error_text.len = strlen(jsonrpc_error_buf);
+	ctx->error_text.s = jsonrpc_error_buf;
+	ctx->http_text.len = ctx->error_text.len;
 	ctx->http_text.s = jsonrpc_error_buf;
-	if(ctx->error_code == 0) ctx->error_code = -32000;
+	if(code == 0) {
+		ctx->error_code = -32000;
+	} else {
+		ctx->error_code = code;
+	}
 
 	return;
 }
@@ -348,8 +358,14 @@ static int jsonrpc_send(jsonrpc_ctx_t* ctx)
 					_jsonrpc_error_table[i].text.s,
 					_jsonrpc_error_table[i].text.len);
 			} else {
-				srjson_AddStrStrToObject(ctx->jrpl, nj,
-					"message", 7, "Unexpected Error", 16);
+				if(ctx->error_text.len>0) {
+					srjson_AddStrStrToObject(ctx->jrpl, nj,
+							"message", 7,
+							ctx->error_text.s, ctx->error_text.len);
+				} else {
+					srjson_AddStrStrToObject(ctx->jrpl, nj,
+							"message", 7, "Unexpected Error", 16);
+				}
 			}
 			srjson_AddItemToObject(ctx->jrpl, ctx->jrpl->root, "error", nj);
 		}
diff --git a/src/modules/jsonrpcs/jsonrpcs_mod.h b/src/modules/jsonrpcs/jsonrpcs_mod.h
index eec2a743b0..ef15c3ec93 100644
--- a/src/modules/jsonrpcs/jsonrpcs_mod.h
+++ b/src/modules/jsonrpcs/jsonrpcs_mod.h
@@ -50,6 +50,7 @@ typedef struct jsonrpc_ctx {
 	srjson_t *rpl_node;    /**< Pointer to crt node in json reply doc */
 	int reply_sent;        /**< Flag set if the json reply was sent */
 	int error_code;        /**< Json error code */
+	str error_text;        /**< Json error text */
 	int http_code;         /**< http reply code */
 	str http_text;         /**< http reply reason text */
 	int transport;         /**< RPC transport */




More information about the sr-dev mailing list