[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r35377 - gnunet/src/identity
From: |
gnunet |
Subject: |
[GNUnet-SVN] r35377 - gnunet/src/identity |
Date: |
Thu, 12 Mar 2015 18:32:37 +0100 |
Author: schanzen
Date: 2015-03-12 18:32:37 +0100 (Thu, 12 Mar 2015)
New Revision: 35377
Modified:
gnunet/src/identity/plugin_rest_identity.c
Log:
-add ego creation
Modified: gnunet/src/identity/plugin_rest_identity.c
===================================================================
--- gnunet/src/identity/plugin_rest_identity.c 2015-03-12 16:40:40 UTC (rev
35376)
+++ gnunet/src/identity/plugin_rest_identity.c 2015-03-12 17:32:37 UTC (rev
35377)
@@ -32,10 +32,8 @@
#define API_NAMESPACE "/identity"
-#define EGO_NAMESPACE "/identity/ego"
+#define EGO_NAMESPACE "/identity"
-#define SVC_NAMESPACE "/identity/service"
-
#define ID_REST_STATE_INIT 0
#define ID_REST_STATE_POST_INIT 1
@@ -96,6 +94,11 @@
struct GNUNET_IDENTITY_Handle *identity_handle;
/**
+ * IDENTITY Operation
+ */
+ struct GNUNET_IDENTITY_Operation *op;
+
+ /**
* Desired timeout for the lookup (default is no timeout).
*/
struct GNUNET_TIME_Relative timeout;
@@ -150,6 +153,11 @@
*/
size_t data_size;
+ /**
+ * HTTP method
+ */
+ const char* method;
+
};
/**
@@ -254,7 +262,112 @@
}
+static void
+create_finished (void *cls, const char *emsg)
+{
+ struct RequestHandle *handle = cls;
+ handle->op = NULL;
+ if (NULL != emsg)
+ {
+ GNUNET_SCHEDULER_add_now (&do_error, handle);
+ }
+ handle->proc (handle->proc_cls, NULL, 0, GNUNET_OK);
+ cleanup_handle (handle);
+}
+
+static void
+ego_create_cont (struct RequestHandle *handle)
+{
+ const char* egoname;
+ char term_data[handle->data_size];
+ json_t *egoname_json;
+ json_t *root_json;
+ json_error_t error;
+ struct EgoEntry *ego_entry;
+
+ if (strlen (API_NAMESPACE) != strlen (handle->url))
+ {
+ GNUNET_break(0);
+ handle->proc (handle->proc_cls, NULL, 0, GNUNET_SYSERR);
+ cleanup_handle (handle);
+ return;
+ }
+ if (0 >= handle->data_size)
+ {
+ GNUNET_break(0);
+ handle->proc (handle->proc_cls, NULL, 0, GNUNET_SYSERR);
+ cleanup_handle (handle);
+ return;
+ }
+
+ term_data[handle->data_size] = '\0';
+ memcpy (term_data, handle->data, handle->data_size);
+ root_json = json_loads (term_data, 0, &error);
+
+ if ((NULL == root_json) || !json_is_object (root_json))
+ {
+ GNUNET_break(0);
+ handle->proc (handle->proc_cls, NULL, 0, GNUNET_SYSERR);
+ cleanup_handle (handle);
+ return;
+ }
+ egoname_json = json_object_get (root_json, "ego");
+ if (!json_is_string (egoname_json))
+ {
+ GNUNET_break(0);
+ handle->proc (handle->proc_cls, NULL, 0, GNUNET_SYSERR);
+ cleanup_handle (handle);
+ return;
+ }
+ egoname = json_string_value (egoname_json);
+ for (ego_entry = handle->ego_head;
+ NULL != ego_entry;
+ ego_entry = ego_entry->next)
+ {
+ if (0 == strcasecmp (egoname, ego_entry->identifier))
+ {
+ json_decref (egoname_json);
+ json_decref (root_json);
+ handle->proc (handle->proc_cls, NULL, 0, GNUNET_SYSERR);
+ cleanup_handle (handle);
+ return;
+ }
+ }
+ GNUNET_asprintf (&handle->name, "%s", egoname);
+ json_decref (egoname_json);
+ json_decref (root_json);
+ handle->op = GNUNET_IDENTITY_create (handle->identity_handle,
+ handle->name,
+ &create_finished,
+ handle);
+}
+
+void
+subsys_set_cont (struct RequestHandle *handle)
+{
+}
+
+void
+ego_delete_cont (struct RequestHandle *handle)
+{
+}
+
+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
+ GNUNET_SCHEDULER_add_now (&do_error, handle);
+}
+
/**
* If listing is enabled, prints information about the egos.
*
@@ -297,6 +410,19 @@
struct RequestHandle *handle = cls;
struct EgoEntry *ego_entry;
+ if ((NULL == ego) && (ID_REST_STATE_INIT == handle->state))
+ {
+ handle->state = ID_REST_STATE_POST_INIT;
+ init_cont (handle);
+ return;
+ }
+ if (ID_REST_STATE_INIT == handle->state) {
+ ego_entry = GNUNET_new (struct EgoEntry);
+ GNUNET_IDENTITY_ego_get_public_key (ego, &(ego_entry->pk));
+ GNUNET_asprintf (&ego_entry->identifier, "%s", identifier);
+ GNUNET_CONTAINER_DLL_insert_tail(handle->ego_head,handle->ego_tail,
ego_entry);
+ }
+
if ( (NULL == handle->set_ego) &&
(NULL != ego) &&
(NULL != identifier) &&
@@ -325,19 +451,7 @@
GNUNET_free (handle->set_ego); //decref?
handle->set_ego = NULL;
}
- if ((NULL == ego) && (ID_REST_STATE_INIT == handle->state))
- {
- //TODO all read
- handle->state = ID_REST_STATE_POST_INIT;
- ego_info_response (handle);
- return;
- }
- if (ID_REST_STATE_INIT == handle->state) {
- ego_entry = GNUNET_new (struct EgoEntry);
- GNUNET_IDENTITY_ego_get_public_key (ego, &(ego_entry->pk));
- GNUNET_asprintf (&ego_entry->identifier, "%s", identifier);
- GNUNET_CONTAINER_DLL_insert_tail(handle->ego_head,handle->ego_tail,
ego_entry);
- }
+
}
/**
@@ -378,6 +492,7 @@
handle->url = url;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Connected\n");
+ handle->method = method;
}
/**
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r35377 - gnunet/src/identity,
gnunet <=