[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r36025 - in gnunet/src: gns identity
From: |
gnunet |
Subject: |
[GNUnet-SVN] r36025 - in gnunet/src: gns identity |
Date: |
Mon, 29 Jun 2015 17:56:29 +0200 |
Author: schanzen
Date: 2015-06-29 17:56:29 +0200 (Mon, 29 Jun 2015)
New Revision: 36025
Modified:
gnunet/src/gns/plugin_rest_gns.c
gnunet/src/identity/plugin_rest_identity.c
Log:
- clean up gns rest api
Modified: gnunet/src/gns/plugin_rest_gns.c
===================================================================
--- gnunet/src/gns/plugin_rest_gns.c 2015-06-29 14:49:40 UTC (rev 36024)
+++ gnunet/src/gns/plugin_rest_gns.c 2015-06-29 15:56:29 UTC (rev 36025)
@@ -34,7 +34,7 @@
#include <gnunet_rest_lib.h>
#include <jansson.h>
-#define API_NAMESPACE "/resolver"
+#define GNUNET_REST_API_NS_GNS "/gns"
#define GNUNET_REST_JSONAPI_GNS_RECORD_TYPE "record_type"
@@ -502,30 +502,16 @@
return GNUNET_OK;
}
-/**
- * Function processing the REST call
- *
- * @param method HTTP method
- * @param url URL of the HTTP request
- * @param data body of the HTTP request (optional)
- * @param data_size length of the body
- * @param proc callback function for the result
- * @param proc_cls closure for callback function
- * @return GNUNET_OK if request accepted
- */
static void
-rest_gns_process_request(struct RestConnectionDataHandle *conndata_handle,
- GNUNET_REST_ResultProcessor proc,
- void *proc_cls)
+get_gns_cont (struct RestConnectionDataHandle *conndata_handle,
+ const char* url,
+ void *cls)
{
- struct LookupHandle *handle = GNUNET_new (struct LookupHandle);
+ struct LookupHandle *handle = cls;
struct GNUNET_HashCode key;
- handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL;
- handle->proc_cls = proc_cls;
- handle->proc = proc;
//parse name and type from url
- if (GNUNET_OK != parse_url (conndata_handle->url, handle))
+ if (GNUNET_OK != parse_url (url, handle))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error parsing url...\n");
GNUNET_SCHEDULER_add_now (&do_error, handle);
@@ -555,7 +541,7 @@
&key) )
{
handle->options = GNUNET_GNS_LO_DEFAULT;//TODO(char*)
GNUNET_CONTAINER_multihashmap_get (conndata_handle->url_param_map,
- //&key);
+ //&key);
}
GNUNET_CRYPTO_hash (GNUNET_REST_JSONAPI_GNS_RECORD_TYPE,
strlen (GNUNET_REST_JSONAPI_GNS_RECORD_TYPE),
@@ -566,7 +552,7 @@
{
handle->type = GNUNET_GNSRECORD_typename_to_number
(GNUNET_CONTAINER_multihashmap_get (conndata_handle->url_param_map,
- &key));
+ &key));
}
else
handle->type = GNUNET_GNSRECORD_TYPE_ANY;
@@ -628,6 +614,64 @@
}
/**
+ * Handle rest request
+ *
+ * @param handle the lookup handle
+ */
+static void
+options_cont (struct RestConnectionDataHandle *con_handle,
+ const char* url,
+ void *cls)
+{
+ struct MHD_Response *resp;
+ struct LookupHandle *handle = cls;
+
+ //For GNS, independent of path return all options
+ resp = GNUNET_REST_create_json_response (NULL);
+ MHD_add_response_header (resp,
+ "Access-Control-Allow-Methods",
+ MHD_HTTP_METHOD_GET);
+ handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
+ cleanup_handle (handle);
+ return;
+}
+
+
+/**
+ * Function processing the REST call
+ *
+ * @param method HTTP method
+ * @param url URL of the HTTP request
+ * @param data body of the HTTP request (optional)
+ * @param data_size length of the body
+ * @param proc callback function for the result
+ * @param proc_cls closure for callback function
+ * @return GNUNET_OK if request accepted
+ */
+static void
+rest_gns_process_request(struct RestConnectionDataHandle *conndata_handle,
+ GNUNET_REST_ResultProcessor proc,
+ void *proc_cls)
+{
+ struct LookupHandle *handle = GNUNET_new (struct LookupHandle);
+
+ handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL;
+ handle->proc_cls = proc_cls;
+ handle->proc = proc;
+
+ static const struct GNUNET_REST_RestConnectionHandler handlers[] = {
+ {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_GNS, &get_gns_cont},
+ {MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_GNS, &options_cont},
+ GNUNET_REST_HANDLER_END
+ };
+
+ if (GNUNET_NO == GNUNET_REST_handle_request (conndata_handle, handlers,
handle))
+ GNUNET_SCHEDULER_add_now (&do_error, handle);
+}
+
+
+
+/**
* Entry point for the plugin.
*
* @param cls the "struct GNUNET_NAMESTORE_PluginEnvironment*"
@@ -646,7 +690,7 @@
plugin.cfg = cfg;
api = GNUNET_new (struct GNUNET_REST_Plugin);
api->cls = &plugin;
- api->name = API_NAMESPACE;
+ api->name = GNUNET_REST_API_NS_GNS;
api->process_request = &rest_gns_process_request;
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
_("GNS REST API initialized\n"));
Modified: gnunet/src/identity/plugin_rest_identity.c
===================================================================
--- gnunet/src/identity/plugin_rest_identity.c 2015-06-29 14:49:40 UTC (rev
36024)
+++ gnunet/src/identity/plugin_rest_identity.c 2015-06-29 15:56:29 UTC (rev
36025)
@@ -654,7 +654,15 @@
}
-void
+
+/**
+ * Respond to OPTIONS request
+ *
+ * @param con_handle the connection handle
+ * @param url the url
+ * @param cls the RequestHandle
+ */
+static void
options_cont (struct RestConnectionDataHandle *con_handle,
const char* url,
void *cls)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r36025 - in gnunet/src: gns identity,
gnunet <=