Module: kamailio
Branch: 5.0
Commit: 1b86bf2faa09d3a9ef3684f42582a83267635668
URL:
https://github.com/kamailio/kamailio/commit/1b86bf2faa09d3a9ef3684f42582a83…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2017-10-19T09:00:34+02:00
jsonrpcs: proper propagation of rpc fault code and message
(cherry picked from commit 9364b1691412ec1d3d59ca8a801613470e079c1d)
---
Modified: src/modules/jsonrpcs/jsonrpcs_mod.c
Modified: src/modules/jsonrpcs/jsonrpcs_mod.h
---
Diff:
https://github.com/kamailio/kamailio/commit/1b86bf2faa09d3a9ef3684f42582a83…
Patch:
https://github.com/kamailio/kamailio/commit/1b86bf2faa09d3a9ef3684f42582a83…
---
diff --git a/src/modules/jsonrpcs/jsonrpcs_mod.c b/src/modules/jsonrpcs/jsonrpcs_mod.c
index 2103f75dfc..adf423d4ef 100644
--- a/src/modules/jsonrpcs/jsonrpcs_mod.c
+++ b/src/modules/jsonrpcs/jsonrpcs_mod.c
@@ -298,13 +298,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;
}
@@ -347,8 +357,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 */