Merge pull request #92 from painless-security/jennifer/reduce_logging
[trust_router.git] / mon / mon_resp_encode.c
index 2a6e5fe..515fb7a 100644 (file)
@@ -37,6 +37,8 @@
 
 #include <mon_internal.h>
 
+/* Monitoring response encoder */
+
 /* Helper for encoding. Adds a newly allocated JSON object to
  * jobj. If the allocation or setting fails, returns NULL after
  * cleaning up. */
@@ -66,7 +68,6 @@ json_t *mon_resp_encode(MON_RESP *resp)
 {
   json_t *resp_json = NULL;
   json_t *jval = NULL;
-  const char *cmd_str = NULL;
 
   /* Get a JSON object */
   resp_json = json_object();
@@ -79,8 +80,8 @@ json_t *mon_resp_encode(MON_RESP *resp)
 
   /* If we have a payload, add it */
   if (resp->payload) {
-    cmd_str = mon_cmd_to_string(resp->req->command); // key for the response payload
-    object_set_or_free_and_return(resp_json, jval, cmd_str, resp->payload);
+    object_set_or_free_and_return(resp_json, jval, "payload", resp->payload);
+    json_incref(resp->payload); /* we just created a second reference to the payload */
   }
 
   return resp_json;