if (hreq->postform != NULL)
MHD_destroy_post_processor(hreq->postform);
+ if (hreq->tokener != NULL)
+ json_tokener_free(hreq->tokener);
+
for (data = hreq->data; data; data = hreq->data) {
hreq->data = data->next;
if (data->path) {
#include "afb-xreq.h"
-struct afb_session;
struct json_object;
+struct json_tokener;
+
+struct afb_session;
struct hreq_data;
struct afb_hsrv;
struct locale_search;
struct MHD_PostProcessor *postform;
struct hreq_data *data;
struct json_object *json;
+ struct json_tokener *tokener;
};
extern int afb_hreq_unprefix(struct afb_hreq *request, const char *prefix, size_t length);
#include <errno.h>
#include <sys/stat.h>
+#include <json-c/json.h>
#include <microhttpd.h>
#include "afb-method.h"
}
return MHD_YES;
} else if (strcasestr(type, JSON_CONTENT) != NULL) {
+ hreq->tokener = json_tokener_new();
+ if (hreq->tokener == NULL) {
+ ERROR("Can't create tokener for POST");
+ afb_hreq_reply_error(hreq, MHD_HTTP_INTERNAL_SERVER_ERROR);
+ }
return MHD_YES;
} else {
WARNING("Unsupported media type %s", type);
afb_hreq_reply_error(hreq, MHD_HTTP_INTERNAL_SERVER_ERROR);
return MHD_YES;
}
- } else {
- if (!afb_hreq_post_add(hreq, "", upload_data, *upload_data_size)) {
- afb_hreq_reply_error(hreq, MHD_HTTP_INTERNAL_SERVER_ERROR);
+ } else if (hreq->tokener) {
+ hreq->json = json_tokener_parse_ex(hreq->tokener, upload_data, (int)*upload_data_size);
+ switch (json_tokener_get_error(hreq->tokener)) {
+ case json_tokener_success:
+ case json_tokener_continue:
+ break;
+ default:
+ ERROR("error in POST json: %s", json_tokener_error_desc(json_tokener_get_error(hreq->tokener)));
+ afb_hreq_reply_error(hreq, MHD_HTTP_BAD_REQUEST);
return MHD_YES;
}
}
return MHD_YES;
}
}
+ if (hreq->tokener != NULL) {
+ json_tokener_free(hreq->tokener);
+ hreq->tokener = NULL;
+ }
if (hreq->scanned != 0) {
if (hreq->replied == 0 && hreq->suspended == 0) {