- 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));
- }
+ token = afb_context_sent_token(&hreq->context);
+ uuid = afb_context_sent_uuid(&hreq->context);
+
+ reply = afb_msg_json_reply(status, info, resp, token, uuid);
+
+ reqid = afb_hreq_get_argument(hreq, long_key_for_reqid);
+ if (reqid == NULL)
+ reqid = afb_hreq_get_argument(hreq, short_key_for_reqid);
+ if (reqid != NULL && json_object_object_get_ex(reply, "request", &request))
+ json_object_object_add (request, short_key_for_reqid, json_object_new_string(reqid));