X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fafb-hreq.c;h=d1ba0c13a2494f56e77bc166b27880ce48920c0a;hb=694e6000719d2d003c3046683347f9388d5fb708;hp=72b90504594806941d103f8bf57038453423903b;hpb=9e3afb8aa598f3e69e2c3723335507c12b4cd1f1;p=src%2Fapp-framework-binder.git diff --git a/src/afb-hreq.c b/src/afb-hreq.c index 72b90504..d1ba0c13 100644 --- a/src/afb-hreq.c +++ b/src/afb-hreq.c @@ -34,6 +34,7 @@ #include "afb-method.h" #include "afb-req-itf.h" +#include "afb-msg-json.h" #include "afb-hreq.h" #include "session.h" #include "verbose.h" @@ -661,24 +662,19 @@ static ssize_t send_json_cb(json_object *obj, uint64_t pos, char *buf, size_t ma static void req_reply(struct afb_hreq *hreq, unsigned retcode, const char *status, const char *info, json_object *resp) { - json_object *root, *request; + struct json_object *reply; + const char *token, *uuid; struct MHD_Response *response; - root = json_object_new_object(); - json_object_object_add(root, "jtype", json_object_new_string("afb-reply")); - request = json_object_new_object(); - json_object_object_add(root, "request", request); - json_object_object_add(request, "status", json_object_new_string(status)); - if (info) - json_object_object_add(request, "info", json_object_new_string(info)); - if (resp) - json_object_object_add(root, "response", resp); - if (hreq->context) { - json_object_object_add(request, uuid_arg, json_object_new_string(hreq->context->uuid)); - json_object_object_add(request, token_arg, json_object_new_string(hreq->context->token)); + if (hreq->context == NULL) { + token = uuid = NULL; + } else { + token = hreq->context->token; + uuid = hreq->context->uuid; } + reply = afb_msg_json_reply(status, info, resp, token, uuid); - response = MHD_create_response_from_callback(MHD_SIZE_UNKNOWN, SIZE_RESPONSE_BUFFER, (void*)send_json_cb, root, (void*)json_object_put); + response = MHD_create_response_from_callback(MHD_SIZE_UNKNOWN, SIZE_RESPONSE_BUFFER, (void*)send_json_cb, reply, (void*)json_object_put); afb_hreq_reply(hreq, retcode, response, NULL); }