diff options
author | Martin Schanzenbach <mschanzenbach@posteo.de> | 2016-05-04 09:44:35 +0000 |
---|---|---|
committer | Martin Schanzenbach <mschanzenbach@posteo.de> | 2016-05-04 09:44:35 +0000 |
commit | 493305a0d4e9d7f9bdc35fabfd8027a487586e47 (patch) | |
tree | ec05c1bde5b5cfb7937de6f06dc3586f26f557f9 /src/jsonapi | |
parent | 8e9bb50b7543608c2c1a833a5b92f19941ed7a0a (diff) | |
download | gnunet-493305a0d4e9d7f9bdc35fabfd8027a487586e47.tar.gz gnunet-493305a0d4e9d7f9bdc35fabfd8027a487586e47.zip |
- rework rest/jsonapi API; bugfixes
Diffstat (limited to 'src/jsonapi')
-rw-r--r-- | src/jsonapi/Makefile.am | 1 | ||||
-rw-r--r-- | src/jsonapi/jsonapi.c | 54 |
2 files changed, 55 insertions, 0 deletions
diff --git a/src/jsonapi/Makefile.am b/src/jsonapi/Makefile.am index 8a702440d..bcd4172c6 100644 --- a/src/jsonapi/Makefile.am +++ b/src/jsonapi/Makefile.am | |||
@@ -17,6 +17,7 @@ libgnunetjsonapi_la_SOURCES = \ | |||
17 | libgnunetjsonapi_la_LIBADD = \ | 17 | libgnunetjsonapi_la_LIBADD = \ |
18 | $(top_builddir)/src/util/libgnunetutil.la \ | 18 | $(top_builddir)/src/util/libgnunetutil.la \ |
19 | $(top_builddir)/src/json/libgnunetjson.la \ | 19 | $(top_builddir)/src/json/libgnunetjson.la \ |
20 | $(top_builddir)/src/rest/libgnunetrest.la \ | ||
20 | -ljansson \ | 21 | -ljansson \ |
21 | $(XLIB) | 22 | $(XLIB) |
22 | 23 | ||
diff --git a/src/jsonapi/jsonapi.c b/src/jsonapi/jsonapi.c index 6bd03e0ec..b648590e5 100644 --- a/src/jsonapi/jsonapi.c +++ b/src/jsonapi/jsonapi.c | |||
@@ -20,6 +20,7 @@ | |||
20 | */ | 20 | */ |
21 | #include "platform.h" | 21 | #include "platform.h" |
22 | #include "gnunet_json_lib.h" | 22 | #include "gnunet_json_lib.h" |
23 | #include "gnunet_rest_lib.h" | ||
23 | 24 | ||
24 | #define GNUNET_JSONAPI_KEY_DATA "data" | 25 | #define GNUNET_JSONAPI_KEY_DATA "data" |
25 | 26 | ||
@@ -476,3 +477,56 @@ GNUNET_JSON_spec_jsonapi (struct GNUNET_JSONAPI_Object **jsonapi_object) | |||
476 | *jsonapi_object = NULL; | 477 | *jsonapi_object = NULL; |
477 | return ret; | 478 | return ret; |
478 | } | 479 | } |
480 | |||
481 | /** | ||
482 | * Check rest request for validity | ||
483 | * | ||
484 | * @param req handle to the request | ||
485 | * @return GNUNET_OK if valid | ||
486 | */ | ||
487 | int | ||
488 | GNUNET_JSONAPI_check_request_acceptable (struct GNUNET_REST_RequestHandle *req) | ||
489 | { | ||
490 | //TODO | ||
491 | return GNUNET_OK; | ||
492 | } | ||
493 | |||
494 | /** | ||
495 | * Check rest request for validity | ||
496 | * | ||
497 | * @param req handle to the request | ||
498 | * @return GNUNET_OK if valid | ||
499 | */ | ||
500 | int | ||
501 | GNUNET_JSONAPI_check_request_supported (struct GNUNET_REST_RequestHandle *req) | ||
502 | { | ||
503 | //TODO | ||
504 | return GNUNET_OK; | ||
505 | } | ||
506 | |||
507 | /** | ||
508 | * Handle jsonapi rest request. Checks request headers for jsonapi compliance | ||
509 | * | ||
510 | * @param req rest request handle | ||
511 | * @param handler rest request handlers | ||
512 | * @param cls closure | ||
513 | * @return GNUNET_OK if successful | ||
514 | */ | ||
515 | int | ||
516 | GNUNET_JSONAPI_handle_request (struct GNUNET_REST_RequestHandle *handle, | ||
517 | const struct GNUNET_REST_RequestHandler *handlers, | ||
518 | struct GNUNET_REST_RequestHandlerError *err, | ||
519 | void *cls) | ||
520 | { | ||
521 | if (GNUNET_OK != GNUNET_JSONAPI_check_request_acceptable (handle)) | ||
522 | { | ||
523 | err->error_code = MHD_HTTP_NOT_ACCEPTABLE; | ||
524 | return GNUNET_SYSERR; | ||
525 | } | ||
526 | if (GNUNET_OK != GNUNET_JSONAPI_check_request_supported (handle)) | ||
527 | { | ||
528 | err->error_code = MHD_HTTP_UNSUPPORTED_MEDIA_TYPE; | ||
529 | return GNUNET_SYSERR; | ||
530 | } | ||
531 | return GNUNET_REST_handle_request (handle, handlers, err, cls); | ||
532 | } | ||