Module: sems
Branch: master
Commit: dba7bd2c03340571d161ce4de94b026def2e0002
URL:    
http://git.sip-router.org/cgi-bin/gitweb.cgi/sems/?a=commit;h=dba7bd2c03340571d161ce4de94b026def2e0002

Author: Juha Heinanen <[email protected]>
Committer: Juha Heinanen <[email protected]>
Date:   Sat May 24 21:33:48 2014 +0300

apps/jsonrpc: bug fixes

- error member cannot exist if there was no error
- id member must be of same type in response as it was in request
- id cannot be bool

---

 apps/jsonrpc/JsonRPCServer.cpp |   22 ++++++++++++++--------
 1 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/apps/jsonrpc/JsonRPCServer.cpp b/apps/jsonrpc/JsonRPCServer.cpp
index b48524e..7d43373 100644
--- a/apps/jsonrpc/JsonRPCServer.cpp
+++ b/apps/jsonrpc/JsonRPCServer.cpp
@@ -173,14 +173,14 @@ int JsonRpcServer::processMessage(char* msgbuf, unsigned 
int* msg_size,
   }
 
   string id;
+  bool id_is_int = false;
   if (rpc_params.hasMember("id")) {
-    if (isArgCStr(rpc_params["id"]))
+    if (isArgCStr(rpc_params["id"])) {
       id = rpc_params["id"].asCStr();
-    else if (isArgInt(rpc_params["id"]))
+    } else if (isArgInt(rpc_params["id"])) {
       id = int2str(rpc_params["id"].asInt());
-    else if (isArgBool(rpc_params["id"]))
-      id = rpc_params["id"].asBool() ? "True":"False";
-    else {
+      id_is_int = true;
+    } else {
       ERROR("incorrect type for jsonrpc id <%s>\n", 
            AmArg::print(rpc_params["id"]).c_str());
     }
@@ -237,11 +237,18 @@ int JsonRpcServer::processMessage(char* msgbuf, unsigned 
int* msg_size,
   }
 
   AmArg rpc_res;
+  int int_id;
 
   execRpc(rpc_params, rpc_res);
 
-  // rpc_res["error"] = AmArg(); // Undef/null
-  // rpc_res["id"] = rpc_params["id"];
+  if (!id.empty()) {
+    if (id_is_int) {
+      str2int(id, int_id);
+      rpc_res["id"] = int_id;
+    } else {
+      rpc_res["id"] = id;
+    }
+  }
 
   string res_s = arg2json(rpc_res);
   if (res_s.length() > MAX_RPC_MSG_SIZE) {
@@ -287,7 +294,6 @@ void JsonRpcServer::execRpc(const string& method, const 
string& id, const AmArg&
       if (factory == "core") {
        runCoreMethod(fact_meth, params, rpc_res["result"]);
        rpc_res["id"] = id;
-       rpc_res["error"] = AmArg(); // Undef/null
        rpc_res["jsonrpc"] = "2.0";
        return;
       }

_______________________________________________
Semsdev mailing list
[email protected]
http://lists.iptel.org/mailman/listinfo/semsdev

Reply via email to