Improves message formating
[src/app-framework-binder.git] / src / afb-ws-json1.c
index 351a5d0..c9be94d 100644 (file)
@@ -129,6 +129,10 @@ static void aws_on_hangup(struct afb_ws_json1 *ws)
 
 struct afb_wsreq
 {
+       /*
+        * CAUTION: 'context' field should be the first because there
+        * is an implicit convertion to struct afb_context
+        */
        struct afb_context context;
        int refcount;
        struct afb_ws_json1 *aws;
@@ -412,17 +416,15 @@ static void aws_emit(struct afb_ws_json1 *aws, int code, const char *id, size_t
                json_object_array_add(msg, json_object_new_string(token));
 
        /* emits the reply */
-       txt = json_object_to_json_string(msg);
+       txt = json_object_to_json_string_ext(msg, JSON_C_TO_STRING_PLAIN);
        afb_ws_text(aws->ws, txt, strlen(txt));
        json_object_put(msg);
 }
 
 static void wsreq_reply(struct afb_wsreq *wsreq, int retcode, const char *status, const char *info, json_object *resp)
 {
-       const char *uuid = afb_context_sent_uuid(&wsreq->context);
-       const char *token = afb_context_sent_token(&wsreq->context);
-       struct json_object *reply = afb_msg_json_reply(status, info, resp, token, uuid);
-       aws_emit(wsreq->aws, retcode, wsreq->id, wsreq->idlen, reply, token);
+       struct json_object *reply = afb_msg_json_reply(status, info, resp, &wsreq->context, NULL);
+       aws_emit(wsreq->aws, retcode, wsreq->id, wsreq->idlen, reply, afb_context_sent_token(&wsreq->context));
 }
 
 static void wsreq_fail(struct afb_wsreq *wsreq, const char *status, const char *info)