static struct afb_arg req_get(struct afb_hreq *hreq, const char *name)
{
+ const char *value;
struct hreq_data *hdat = get_data(hreq, name, 0);
if (hdat)
return (struct afb_arg){
.value = hdat->value,
.path = hdat->path
};
-
+
+ value = MHD_lookup_connection_value(hreq->connection, MHD_GET_ARGUMENT_KIND, name);
return (struct afb_arg){
- .name = name,
- .value = MHD_lookup_connection_value(hreq->connection, MHD_GET_ARGUMENT_KIND, name),
+ .name = value == NULL ? NULL : name,
+ .value = value,
.path = NULL
};
}
static ssize_t send_json_cb(json_object *obj, uint64_t pos, char *buf, size_t max)
{
- ssize_t len = stpncpy(buf, json_object_to_json_string(obj)+pos, max) - buf;
+ ssize_t len = stpncpy(buf, json_object_to_json_string_ext(obj, JSON_C_TO_STRING_PLAIN)+pos, max) - buf;
return len ? : (ssize_t)MHD_CONTENT_READER_END_OF_STREAM;
}
reply = afb_msg_json_reply(status, info, resp, token, uuid);
reqid = afb_hreq_get_argument(hreq, long_key_for_reqid);
- if (reqid != NULL && json_object_object_get_ex(reply, "request", &request)) {
- json_object_object_add (request, long_key_for_reqid, json_object_new_string(reqid));
- } else {
+ 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));
- }
- }
+ 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));
- response = MHD_create_response_from_callback((uint64_t)strlen(json_object_to_json_string(reply)), SIZE_RESPONSE_BUFFER, (void*)send_json_cb, reply, (void*)json_object_put);
+ response = MHD_create_response_from_callback((uint64_t)strlen(json_object_to_json_string_ext(reply, JSON_C_TO_STRING_PLAIN)), SIZE_RESPONSE_BUFFER, (void*)send_json_cb, reply, (void*)json_object_put);
afb_hreq_reply(hreq, retcode, response, NULL);
}