gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r36364 - in gnunet/src: identity-token rest


From: gnunet
Subject: [GNUnet-SVN] r36364 - in gnunet/src: identity-token rest
Date: Tue, 15 Sep 2015 16:04:54 +0200

Author: schanzen
Date: 2015-09-15 16:04:54 +0200 (Tue, 15 Sep 2015)
New Revision: 36364

Modified:
   gnunet/src/identity-token/plugin_rest_identity_token.c
   gnunet/src/rest/rest.c
Log:
- fixes, store issued tokens in namestore


Modified: gnunet/src/identity-token/plugin_rest_identity_token.c
===================================================================
--- gnunet/src/identity-token/plugin_rest_identity_token.c      2015-09-15 
10:09:58 UTC (rev 36363)
+++ gnunet/src/identity-token/plugin_rest_identity_token.c      2015-09-15 
14:04:54 UTC (rev 36364)
@@ -185,6 +185,11 @@
   struct GNUNET_NAMESTORE_ZoneIterator *ns_it;
 
   /**
+   * NS Handle
+   */
+  struct GNUNET_NAMESTORE_QueueEntry *ns_qe;
+
+  /**
    * Desired timeout for the lookup (default is no timeout).
    */
   struct GNUNET_TIME_Relative timeout;
@@ -274,6 +279,8 @@
     GNUNET_IDENTITY_disconnect (handle->identity_handle);
   if (NULL != handle->ns_it)
     GNUNET_NAMESTORE_zone_iteration_stop (handle->ns_it);
+  if (NULL != handle->ns_qe)
+    GNUNET_NAMESTORE_cancel (handle->ns_qe);
   if (NULL != handle->ns_handle)
     GNUNET_NAMESTORE_disconnect (handle->ns_handle);
 
@@ -319,6 +326,44 @@
 }
 
 /**
+ * Task run on shutdown.  Cleans up everything.
+ *
+ * @param cls unused
+ * @param tc scheduler context
+ */
+static void
+do_cleanup_handle_delayed (void *cls,
+          const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+  struct RequestHandle *handle = cls;
+  cleanup_handle(handle);
+}
+
+void
+store_token_cont (void *cls,
+                  int32_t success,
+                  const char *emsg)
+{
+  char *result_str;
+  struct MHD_Response *resp;
+  struct RequestHandle *handle = cls;
+  
+  handle->ns_qe = NULL;
+  if (GNUNET_SYSERR == success)
+  {
+    GNUNET_SCHEDULER_add_now (&do_error, handle);
+    return;
+  }
+  GNUNET_REST_jsonapi_data_serialize (handle->resp_object, &result_str);
+  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Result %s\n", result_str);
+  resp = GNUNET_REST_create_json_response (result_str);
+  handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
+  GNUNET_free (result_str);
+  GNUNET_SCHEDULER_add_now (&do_cleanup_handle_delayed, handle);
+}
+
+
+/**
  * Build a GNUid token for identity
  * @param handle the handle
  * @param ego_entry the ego to build the token for
@@ -337,7 +382,6 @@
   char *payload_base64;
   char *sig_str;
   char *lbl_str;
-  char *result_str;
   char *token;
   uint64_t time;
   uint64_t lbl;
@@ -346,9 +390,9 @@
   const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key;
   struct GNUNET_CRYPTO_EcdsaSignature sig;
   struct GNUNET_CRYPTO_EccSignaturePurpose *purpose;
-  struct MHD_Response *resp;
   struct JsonApiResource *json_resource;
   struct RequestHandle *handle = cls;
+  struct GNUNET_GNSRECORD_Data token_record;
 
   time = GNUNET_TIME_absolute_get().abs_value_us;
   lbl = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG, UINT64_MAX);
@@ -407,7 +451,6 @@
 
   json_resource = GNUNET_REST_jsonapi_resource_new 
(GNUNET_REST_JSONAPI_IDENTITY_TOKEN,
                                                     lbl_str);
-  GNUNET_free (lbl_str);
   name_str = json_string (handle->ego_entry->identifier);
   GNUNET_REST_jsonapi_resource_add_attr (json_resource,
                                          
GNUNET_REST_JSONAPI_IDENTITY_ISS_REQUEST,
@@ -417,21 +460,32 @@
 
 
   token_str = json_string (token);
-  GNUNET_free (token);
   GNUNET_REST_jsonapi_resource_add_attr (json_resource,
                                          GNUNET_REST_JSONAPI_IDENTITY_TOKEN,
                                          token_str);
+  GNUNET_REST_jsonapi_object_resource_add (handle->resp_object, json_resource);
+  token_record.data = token;
+  token_record.data_size = strlen (token);
+  token_record.expiration_time = 
time+GNUNET_GNUID_TOKEN_EXPIRATION_MICROSECONDS;
+  token_record.record_type = GNUNET_GNSRECORD_TYPE_ID_TOKEN;
+  token_record.flags = GNUNET_GNSRECORD_RF_NONE;
+  //Persist token
+  handle->ns_qe = GNUNET_NAMESTORE_records_store (handle->ns_handle,
+                                                  priv_key,
+                                                  lbl_str,
+                                                  1,
+                                                  &token_record,
+                                                  &store_token_cont,
+                                                  handle);
+  GNUNET_free (lbl_str);
+  GNUNET_free (token);
   json_decref (token_str);
-  GNUNET_REST_jsonapi_object_resource_add (handle->resp_object, json_resource);
-  GNUNET_REST_jsonapi_data_serialize (handle->resp_object, &result_str);
-  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Result %s\n", result_str);
-  resp = GNUNET_REST_create_json_response (result_str);
-  handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
-  GNUNET_free (result_str);
-  cleanup_handle (handle);
 }
 
 
+
+
+
 static void
 attr_collect (void *cls,
               const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,

Modified: gnunet/src/rest/rest.c
===================================================================
--- gnunet/src/rest/rest.c      2015-09-15 10:09:58 UTC (rev 36363)
+++ gnunet/src/rest/rest.c      2015-09-15 14:04:54 UTC (rev 36364)
@@ -435,14 +435,7 @@
 int
 GNUNET_REST_namespace_match (const char *url, const char *namespace)
 {
-  if (0 != strncmp (namespace, url, strlen (namespace)))
-    return GNUNET_NO;
-
-  if ((strlen (namespace) < strlen (url)) &&
-      (url[strlen (namespace)] != '/'))
-    return GNUNET_NO;
-
-  return GNUNET_YES;
+  return 0 == strncmp (namespace, url, strlen (namespace));
 }
 
 /**




reply via email to

[Prev in Thread] Current Thread [Next in Thread]