aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Schanzenbach <mschanzenbach@posteo.de>2015-06-29 15:56:29 +0000
committerMartin Schanzenbach <mschanzenbach@posteo.de>2015-06-29 15:56:29 +0000
commit26d1b687ca01be01505b69ff48ae5d3e0cd4186e (patch)
treecc78aea102debc14542cd7fb33fd242234f05329
parent80b266d3168f014fb3cb4328920703e92796d32a (diff)
downloadgnunet-26d1b687ca01be01505b69ff48ae5d3e0cd4186e.tar.gz
gnunet-26d1b687ca01be01505b69ff48ae5d3e0cd4186e.zip
- clean up gns rest api
-rw-r--r--src/gns/plugin_rest_gns.c90
-rw-r--r--src/identity/plugin_rest_identity.c10
2 files changed, 76 insertions, 24 deletions
diff --git a/src/gns/plugin_rest_gns.c b/src/gns/plugin_rest_gns.c
index d7fc31d4c..9b638b785 100644
--- a/src/gns/plugin_rest_gns.c
+++ b/src/gns/plugin_rest_gns.c
@@ -34,7 +34,7 @@
34#include <gnunet_rest_lib.h> 34#include <gnunet_rest_lib.h>
35#include <jansson.h> 35#include <jansson.h>
36 36
37#define API_NAMESPACE "/resolver" 37#define GNUNET_REST_API_NS_GNS "/gns"
38 38
39#define GNUNET_REST_JSONAPI_GNS_RECORD_TYPE "record_type" 39#define GNUNET_REST_JSONAPI_GNS_RECORD_TYPE "record_type"
40 40
@@ -502,30 +502,16 @@ parse_url (const char *url, struct LookupHandle *handle)
502 return GNUNET_OK; 502 return GNUNET_OK;
503} 503}
504 504
505/**
506 * Function processing the REST call
507 *
508 * @param method HTTP method
509 * @param url URL of the HTTP request
510 * @param data body of the HTTP request (optional)
511 * @param data_size length of the body
512 * @param proc callback function for the result
513 * @param proc_cls closure for callback function
514 * @return GNUNET_OK if request accepted
515 */
516static void 505static void
517rest_gns_process_request(struct RestConnectionDataHandle *conndata_handle, 506get_gns_cont (struct RestConnectionDataHandle *conndata_handle,
518 GNUNET_REST_ResultProcessor proc, 507 const char* url,
519 void *proc_cls) 508 void *cls)
520{ 509{
521 struct LookupHandle *handle = GNUNET_new (struct LookupHandle); 510 struct LookupHandle *handle = cls;
522 struct GNUNET_HashCode key; 511 struct GNUNET_HashCode key;
523 512
524 handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL;
525 handle->proc_cls = proc_cls;
526 handle->proc = proc;
527 //parse name and type from url 513 //parse name and type from url
528 if (GNUNET_OK != parse_url (conndata_handle->url, handle)) 514 if (GNUNET_OK != parse_url (url, handle))
529 { 515 {
530 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error parsing url...\n"); 516 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error parsing url...\n");
531 GNUNET_SCHEDULER_add_now (&do_error, handle); 517 GNUNET_SCHEDULER_add_now (&do_error, handle);
@@ -555,7 +541,7 @@ rest_gns_process_request(struct RestConnectionDataHandle *conndata_handle,
555 &key) ) 541 &key) )
556 { 542 {
557 handle->options = GNUNET_GNS_LO_DEFAULT;//TODO(char*) GNUNET_CONTAINER_multihashmap_get (conndata_handle->url_param_map, 543 handle->options = GNUNET_GNS_LO_DEFAULT;//TODO(char*) GNUNET_CONTAINER_multihashmap_get (conndata_handle->url_param_map,
558 //&key); 544 //&key);
559 } 545 }
560 GNUNET_CRYPTO_hash (GNUNET_REST_JSONAPI_GNS_RECORD_TYPE, 546 GNUNET_CRYPTO_hash (GNUNET_REST_JSONAPI_GNS_RECORD_TYPE,
561 strlen (GNUNET_REST_JSONAPI_GNS_RECORD_TYPE), 547 strlen (GNUNET_REST_JSONAPI_GNS_RECORD_TYPE),
@@ -566,7 +552,7 @@ rest_gns_process_request(struct RestConnectionDataHandle *conndata_handle,
566 { 552 {
567 handle->type = GNUNET_GNSRECORD_typename_to_number 553 handle->type = GNUNET_GNSRECORD_typename_to_number
568 (GNUNET_CONTAINER_multihashmap_get (conndata_handle->url_param_map, 554 (GNUNET_CONTAINER_multihashmap_get (conndata_handle->url_param_map,
569 &key)); 555 &key));
570 } 556 }
571 else 557 else
572 handle->type = GNUNET_GNSRECORD_TYPE_ANY; 558 handle->type = GNUNET_GNSRECORD_TYPE_ANY;
@@ -628,6 +614,64 @@ rest_gns_process_request(struct RestConnectionDataHandle *conndata_handle,
628} 614}
629 615
630/** 616/**
617 * Handle rest request
618 *
619 * @param handle the lookup handle
620 */
621static void
622options_cont (struct RestConnectionDataHandle *con_handle,
623 const char* url,
624 void *cls)
625{
626 struct MHD_Response *resp;
627 struct LookupHandle *handle = cls;
628
629 //For GNS, independent of path return all options
630 resp = GNUNET_REST_create_json_response (NULL);
631 MHD_add_response_header (resp,
632 "Access-Control-Allow-Methods",
633 MHD_HTTP_METHOD_GET);
634 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
635 cleanup_handle (handle);
636 return;
637}
638
639
640/**
641 * Function processing the REST call
642 *
643 * @param method HTTP method
644 * @param url URL of the HTTP request
645 * @param data body of the HTTP request (optional)
646 * @param data_size length of the body
647 * @param proc callback function for the result
648 * @param proc_cls closure for callback function
649 * @return GNUNET_OK if request accepted
650 */
651static void
652rest_gns_process_request(struct RestConnectionDataHandle *conndata_handle,
653 GNUNET_REST_ResultProcessor proc,
654 void *proc_cls)
655{
656 struct LookupHandle *handle = GNUNET_new (struct LookupHandle);
657
658 handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL;
659 handle->proc_cls = proc_cls;
660 handle->proc = proc;
661
662 static const struct GNUNET_REST_RestConnectionHandler handlers[] = {
663 {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_GNS, &get_gns_cont},
664 {MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_GNS, &options_cont},
665 GNUNET_REST_HANDLER_END
666 };
667
668 if (GNUNET_NO == GNUNET_REST_handle_request (conndata_handle, handlers, handle))
669 GNUNET_SCHEDULER_add_now (&do_error, handle);
670}
671
672
673
674/**
631 * Entry point for the plugin. 675 * Entry point for the plugin.
632 * 676 *
633 * @param cls the "struct GNUNET_NAMESTORE_PluginEnvironment*" 677 * @param cls the "struct GNUNET_NAMESTORE_PluginEnvironment*"
@@ -646,7 +690,7 @@ libgnunet_plugin_rest_gns_init (void *cls)
646 plugin.cfg = cfg; 690 plugin.cfg = cfg;
647 api = GNUNET_new (struct GNUNET_REST_Plugin); 691 api = GNUNET_new (struct GNUNET_REST_Plugin);
648 api->cls = &plugin; 692 api->cls = &plugin;
649 api->name = API_NAMESPACE; 693 api->name = GNUNET_REST_API_NS_GNS;
650 api->process_request = &rest_gns_process_request; 694 api->process_request = &rest_gns_process_request;
651 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 695 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
652 _("GNS REST API initialized\n")); 696 _("GNS REST API initialized\n"));
diff --git a/src/identity/plugin_rest_identity.c b/src/identity/plugin_rest_identity.c
index 70ede69eb..ea7d41226 100644
--- a/src/identity/plugin_rest_identity.c
+++ b/src/identity/plugin_rest_identity.c
@@ -654,7 +654,15 @@ ego_delete_cont (struct RestConnectionDataHandle *con_handle,
654 654
655} 655}
656 656
657void 657
658/**
659 * Respond to OPTIONS request
660 *
661 * @param con_handle the connection handle
662 * @param url the url
663 * @param cls the RequestHandle
664 */
665static void
658options_cont (struct RestConnectionDataHandle *con_handle, 666options_cont (struct RestConnectionDataHandle *con_handle,
659 const char* url, 667 const char* url,
660 void *cls) 668 void *cls)