[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r35454 - in gnunet/src: identity include rest
From: |
gnunet |
Subject: |
[GNUnet-SVN] r35454 - in gnunet/src: identity include rest |
Date: |
Wed, 25 Mar 2015 18:19:55 +0100 |
Author: schanzen
Date: 2015-03-25 18:19:54 +0100 (Wed, 25 Mar 2015)
New Revision: 35454
Modified:
gnunet/src/identity/plugin_rest_identity.c
gnunet/src/include/gnunet_rest_lib.h
gnunet/src/include/gnunet_rest_plugin.h
gnunet/src/rest/rest.c
Log:
-more rest handling
Modified: gnunet/src/identity/plugin_rest_identity.c
===================================================================
--- gnunet/src/identity/plugin_rest_identity.c 2015-03-25 17:18:39 UTC (rev
35453)
+++ gnunet/src/identity/plugin_rest_identity.c 2015-03-25 17:19:54 UTC (rev
35454)
@@ -285,12 +285,15 @@
* @param handle the RequestHandle
*/
void
-ego_info_response (struct RequestHandle *handle)
+ego_info_response (struct RestConnectionDataHandle *con,
+ const char *url,
+ void *cls)
{
const char *egoname;
char *keystring;
char *result_str;
char *subsys_val;
+ struct RequestHandle *handle = cls;
struct EgoEntry *ego_entry;
struct GNUNET_HashCode key;
struct MHD_Response *resp;
@@ -414,9 +417,12 @@
}
static void
-ego_create_cont (struct RequestHandle *handle)
+ego_create_cont (struct RestConnectionDataHandle *con,
+ const char *url,
+ void *cls)
{
const char* egoname;
+ struct RequestHandle *handle = cls;
char term_data[handle->data_size+1];
struct EgoEntry *ego_entry;
struct MHD_Response *resp;
@@ -500,10 +506,13 @@
}
void
-subsys_set_cont (struct RequestHandle *handle)
+subsys_set_cont (struct RestConnectionDataHandle *con,
+ const char *url,
+ void *cls)
{
const char *egoname;
const char *subsys;
+ struct RequestHandle *handle = cls;
char term_data[handle->data_size+1];
struct EgoEntry *ego_entry;
struct MHD_Response *resp;
@@ -604,11 +613,14 @@
}
void
-ego_delete_cont (struct RequestHandle *handle)
+ego_delete_cont (struct RestConnectionDataHandle *con_handle,
+ const char* url,
+ void *cls)
{
const char *egoname;
struct EgoEntry *ego_entry;
struct MHD_Response *resp;
+ struct RequestHandle *handle = cls;
int ego_exists = GNUNET_NO;
if (strlen (API_NAMESPACE) >= strlen (handle->url))
@@ -645,15 +657,15 @@
void
init_cont (struct RequestHandle *handle)
{
- if (0 == strcasecmp (handle->method, MHD_HTTP_METHOD_GET))
- ego_info_response (handle);
- else if (0 == strcasecmp (handle->method, MHD_HTTP_METHOD_POST))
- ego_create_cont (handle);
- else if (0 == strcasecmp (handle->method, MHD_HTTP_METHOD_PUT))
- subsys_set_cont (handle);
- else if (0 == strcasecmp (handle->method, MHD_HTTP_METHOD_DELETE))
- ego_delete_cont (handle);
- else
+ static const struct GNUNET_REST_RestConnectionHandler handlers[] = {
+ {MHD_HTTP_METHOD_GET, API_NAMESPACE, &ego_info_response},
+ {MHD_HTTP_METHOD_POST, API_NAMESPACE, &ego_create_cont},
+ {MHD_HTTP_METHOD_PUT, API_NAMESPACE, &subsys_set_cont},
+ {MHD_HTTP_METHOD_DELETE, API_NAMESPACE, &ego_delete_cont},
+ GNUNET_REST_HANDLER_END
+ };
+
+ if (GNUNET_NO == GNUNET_REST_handle_request (handle->conndata_handle,
handlers, handle))
GNUNET_SCHEDULER_add_now (&do_error, handle);
}
Modified: gnunet/src/include/gnunet_rest_lib.h
===================================================================
--- gnunet/src/include/gnunet_rest_lib.h 2015-03-25 17:18:39 UTC (rev
35453)
+++ gnunet/src/include/gnunet_rest_lib.h 2015-03-25 17:19:54 UTC (rev
35454)
@@ -36,7 +36,53 @@
#define GNUNET_REST_JSONAPI_KEY_TYPE "type"
+#define GNUNET_REST_HANDLER_END {NULL, NULL, NULL}
+
+struct RestConnectionDataHandle
+{
+ struct GNUNET_CONTAINER_MultiHashMap *url_param_map;
+ const char *method;
+ const char *url;
+ const char *data;
+ size_t data_size;
+
+};
+
+struct GNUNET_REST_RestConnectionHandler
+{
+ /**
+ * Http method to handle
+ */
+ const char *method;
+
+ /**
+ * Namespace to handle
+ */
+ const char *namespace;
+
+ /**
+ * callback handler
+ */
+ void (*proc) (struct RestConnectionDataHandle *handle,
+ const char *url,
+ void *cls);
+
+};
+
+
/**
+ * Iterator called on obtained result for a REST result.
+ *
+ * @param cls closure
+ * @param resp the response
+ * @param status status code (HTTP)
+ */
+typedef void (*GNUNET_REST_ResultProcessor) (void *cls,
+ struct MHD_Response *resp,
+ int status);
+
+
+/**
* Resource structs for JSON API
*/
struct JsonApiResource;
@@ -152,5 +198,9 @@
GNUNET_REST_create_json_response (const char *data);
+int
+GNUNET_REST_handle_request (struct RestConnectionDataHandle *conn,
+ const struct GNUNET_REST_RestConnectionHandler
*handlers,
+ void *cls);
#endif
Modified: gnunet/src/include/gnunet_rest_plugin.h
===================================================================
--- gnunet/src/include/gnunet_rest_plugin.h 2015-03-25 17:18:39 UTC (rev
35453)
+++ gnunet/src/include/gnunet_rest_plugin.h 2015-03-25 17:19:54 UTC (rev
35454)
@@ -27,6 +27,7 @@
#define GNUNET_REST_PLUGIN_H
#include "gnunet_util_lib.h"
+#include "gnunet_rest_lib.h"
#include "microhttpd.h"
#ifdef __cplusplus
@@ -39,27 +40,6 @@
/**
- * Iterator called on obtained result for a REST result.
- *
- * @param cls closure
- * @param resp the response
- * @param status status code (HTTP)
- */
-typedef void (*GNUNET_REST_ResultProcessor) (void *cls,
- struct MHD_Response *resp,
- int status);
-
-struct RestConnectionDataHandle
-{
- struct GNUNET_CONTAINER_MultiHashMap *url_param_map;
- const char *method;
- const char *url;
- const char *data;
- size_t data_size;
-
-};
-
-/**
* @brief struct returned by the initialization function of the plugin
*/
struct GNUNET_REST_Plugin
Modified: gnunet/src/rest/rest.c
===================================================================
--- gnunet/src/rest/rest.c 2015-03-25 17:18:39 UTC (rev 35453)
+++ gnunet/src/rest/rest.c 2015-03-25 17:19:54 UTC (rev 35454)
@@ -68,6 +68,7 @@
int res_count;
};
+
/**
* JSON API
*/
@@ -296,4 +297,39 @@
}
+int
+GNUNET_REST_handle_request (struct RestConnectionDataHandle *conn,
+ const struct GNUNET_REST_RestConnectionHandler
*handlers,
+ void *cls)
+{
+ int count;
+ int i;
+ char *url;
+
+ count = 0;
+
+ while (NULL != handlers[count].method)
+ count++;
+
+ GNUNET_asprintf (&url, "%s", conn->url);
+ if (url[strlen (url)-1] == '/')
+ url[strlen (url)-1] = '\0';
+
+ for (i = 0; i < count; i++)
+ {
+ if (0 != strcasecmp (conn->method, handlers[count].method))
+ break;
+ if (strlen (url) < strlen (handlers[count].namespace))
+ break;
+ if (GNUNET_NO == GNUNET_REST_namespace_match (url,
handlers[count].namespace))
+ break;
+ //Match
+ handlers[count].proc (conn, (const char*)url, cls);
+ GNUNET_free (url);
+ return GNUNET_YES;
+ }
+ GNUNET_free (url);
+ return GNUNET_NO;
+}
+
/* end of rest.c */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r35454 - in gnunet/src: identity include rest,
gnunet <=