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/gns/plugin_rest_gns.c | |
parent | 8e9bb50b7543608c2c1a833a5b92f19941ed7a0a (diff) | |
download | gnunet-493305a0d4e9d7f9bdc35fabfd8027a487586e47.tar.gz gnunet-493305a0d4e9d7f9bdc35fabfd8027a487586e47.zip |
- rework rest/jsonapi API; bugfixes
Diffstat (limited to 'src/gns/plugin_rest_gns.c')
-rw-r--r-- | src/gns/plugin_rest_gns.c | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/src/gns/plugin_rest_gns.c b/src/gns/plugin_rest_gns.c index 91a091f2e..718a9b29b 100644 --- a/src/gns/plugin_rest_gns.c +++ b/src/gns/plugin_rest_gns.c | |||
@@ -77,6 +77,11 @@ struct LookupHandle | |||
77 | struct GNUNET_GNS_LookupRequest *lookup_request; | 77 | struct GNUNET_GNS_LookupRequest *lookup_request; |
78 | 78 | ||
79 | /** | 79 | /** |
80 | * Handle to rest request | ||
81 | */ | ||
82 | struct GNUNET_REST_RequestHandle *rest_handle; | ||
83 | |||
84 | /** | ||
80 | * Lookup an ego with the identity service. | 85 | * Lookup an ego with the identity service. |
81 | */ | 86 | */ |
82 | struct GNUNET_IDENTITY_EgoLookup *el; | 87 | struct GNUNET_IDENTITY_EgoLookup *el; |
@@ -153,6 +158,11 @@ struct LookupHandle | |||
153 | */ | 158 | */ |
154 | struct GNUNET_CRYPTO_EcdsaPrivateKey shorten_key; | 159 | struct GNUNET_CRYPTO_EcdsaPrivateKey shorten_key; |
155 | 160 | ||
161 | /** | ||
162 | * HTTP response code | ||
163 | */ | ||
164 | int response_code; | ||
165 | |||
156 | }; | 166 | }; |
157 | 167 | ||
158 | 168 | ||
@@ -218,7 +228,7 @@ do_error (void *cls) | |||
218 | struct MHD_Response *resp; | 228 | struct MHD_Response *resp; |
219 | 229 | ||
220 | resp = GNUNET_REST_create_json_response (NULL); | 230 | resp = GNUNET_REST_create_json_response (NULL); |
221 | handle->proc (handle->proc_cls, resp, MHD_HTTP_BAD_REQUEST); | 231 | handle->proc (handle->proc_cls, resp, handle->response_code); |
222 | cleanup_handle (handle); | 232 | cleanup_handle (handle); |
223 | } | 233 | } |
224 | 234 | ||
@@ -505,7 +515,7 @@ parse_url (const char *url, struct LookupHandle *handle) | |||
505 | } | 515 | } |
506 | 516 | ||
507 | static void | 517 | static void |
508 | get_gns_cont (struct RestConnectionDataHandle *conndata_handle, | 518 | get_gns_cont (struct GNUNET_REST_RequestHandle *conndata_handle, |
509 | const char* url, | 519 | const char* url, |
510 | void *cls) | 520 | void *cls) |
511 | { | 521 | { |
@@ -621,7 +631,7 @@ get_gns_cont (struct RestConnectionDataHandle *conndata_handle, | |||
621 | * @param handle the lookup handle | 631 | * @param handle the lookup handle |
622 | */ | 632 | */ |
623 | static void | 633 | static void |
624 | options_cont (struct RestConnectionDataHandle *con_handle, | 634 | options_cont (struct GNUNET_REST_RequestHandle *con_handle, |
625 | const char* url, | 635 | const char* url, |
626 | void *cls) | 636 | void *cls) |
627 | { | 637 | { |
@@ -652,24 +662,32 @@ options_cont (struct RestConnectionDataHandle *con_handle, | |||
652 | * @return GNUNET_OK if request accepted | 662 | * @return GNUNET_OK if request accepted |
653 | */ | 663 | */ |
654 | static void | 664 | static void |
655 | rest_gns_process_request(struct RestConnectionDataHandle *conndata_handle, | 665 | rest_gns_process_request(struct GNUNET_REST_RequestHandle *conndata_handle, |
656 | GNUNET_REST_ResultProcessor proc, | 666 | GNUNET_REST_ResultProcessor proc, |
657 | void *proc_cls) | 667 | void *proc_cls) |
658 | { | 668 | { |
659 | struct LookupHandle *handle = GNUNET_new (struct LookupHandle); | 669 | struct LookupHandle *handle = GNUNET_new (struct LookupHandle); |
670 | struct GNUNET_REST_RequestHandlerError err; | ||
660 | 671 | ||
661 | handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL; | 672 | handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL; |
662 | handle->proc_cls = proc_cls; | 673 | handle->proc_cls = proc_cls; |
663 | handle->proc = proc; | 674 | handle->proc = proc; |
675 | handle->rest_handle = conndata_handle; | ||
664 | 676 | ||
665 | static const struct GNUNET_REST_RestConnectionHandler handlers[] = { | 677 | static const struct GNUNET_REST_RequestHandler handlers[] = { |
666 | {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_GNS, &get_gns_cont}, | 678 | {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_GNS, &get_gns_cont}, |
667 | {MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_GNS, &options_cont}, | 679 | {MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_GNS, &options_cont}, |
668 | GNUNET_REST_HANDLER_END | 680 | GNUNET_REST_HANDLER_END |
669 | }; | 681 | }; |
670 | 682 | ||
671 | if (GNUNET_NO == GNUNET_REST_handle_request (conndata_handle, handlers, handle)) | 683 | if (GNUNET_NO == GNUNET_JSONAPI_handle_request (conndata_handle, |
684 | handlers, | ||
685 | &err, | ||
686 | handle)) | ||
687 | { | ||
688 | handle->response_code = err.error_code; | ||
672 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 689 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
690 | } | ||
673 | } | 691 | } |
674 | 692 | ||
675 | 693 | ||