gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [gnunet] 64/75: fix lowercase identities


From: gnunet
Subject: [GNUnet-SVN] [gnunet] 64/75: fix lowercase identities
Date: Thu, 09 Aug 2018 23:59:01 +0200

This is an automated email from the git hooks/post-receive script.

martin-schanzenbach pushed a commit to branch master
in repository gnunet.

commit 894aaa280790c55e6ffb10aa189a5cadc5bad8f7
Author: Phil <address@hidden>
AuthorDate: Thu Aug 2 03:08:36 2018 +0200

    fix lowercase identities
---
 src/identity/plugin_rest_identity.c       | 80 ++++++++++++++++++++++---------
 src/identity/test_plugin_rest_identity.sh |  4 +-
 2 files changed, 60 insertions(+), 24 deletions(-)

diff --git a/src/identity/plugin_rest_identity.c 
b/src/identity/plugin_rest_identity.c
index 49fa9f0fb..83bf4075d 100644
--- a/src/identity/plugin_rest_identity.c
+++ b/src/identity/plugin_rest_identity.c
@@ -326,13 +326,13 @@ ego_get (struct GNUNET_REST_RequestHandle *con_handle, 
const char* url,
   struct GNUNET_HashCode key;
   struct MHD_Response *resp;
   char *keystring;
-  const char *egoname;
+  char *egoname;
   json_t *json_root;
   json_t *json_ego;
   char *result_str;
   size_t index;
 
-  //if subsystem
+  //requested default identity of subsystem
   GNUNET_CRYPTO_hash (GNUNET_REST_PARAM_SUBSYSTEM,
                      strlen (GNUNET_REST_PARAM_SUBSYSTEM), &key);
   if ( GNUNET_YES
@@ -360,7 +360,7 @@ ego_get (struct GNUNET_REST_RequestHandle *con_handle, 
const char* url,
   egoname = NULL;
   keystring = NULL;
 
-  //if only one identity requested with key
+  //one identity requested with key
   GNUNET_CRYPTO_hash (GNUNET_REST_PARAM_PUBKEY,
                      strlen (GNUNET_REST_PARAM_PUBKEY),
                      &key);
@@ -381,7 +381,7 @@ ego_get (struct GNUNET_REST_RequestHandle *con_handle, 
const char* url,
     }
   }
 
-  //if only one identity requested with name
+  //one identity requested with name
   if (NULL == egoname)
   {
     GNUNET_CRYPTO_hash (GNUNET_REST_PARAM_NAME,
@@ -393,6 +393,8 @@ ego_get (struct GNUNET_REST_RequestHandle *con_handle, 
const char* url,
     {
       egoname = GNUNET_CONTAINER_multihashmap_get (
          handle->rest_handle->url_param_map, &key);
+      //LOWERCASE ego names?
+      GNUNET_STRINGS_utf8_tolower(egoname, egoname);
     }
   }
 
@@ -410,10 +412,10 @@ ego_get (struct GNUNET_REST_RequestHandle *con_handle, 
const char* url,
 
     json_ego = json_object ();
     json_object_set_new (json_ego,
-    GNUNET_REST_PARAM_PUBKEY,
+                        GNUNET_REST_PARAM_PUBKEY,
                         json_string (ego_entry->keystring));
     json_object_set_new (json_ego,
-    GNUNET_REST_PARAM_NAME,
+                        GNUNET_REST_PARAM_NAME,
                         json_string (ego_entry->identifier));
     json_array_append (json_root, json_ego);
   }
@@ -645,7 +647,7 @@ ego_create (struct GNUNET_REST_RequestHandle *con_handle, 
const char* url,
   term_data[handle->data_size] = '\0';
   GNUNET_memcpy(term_data, handle->data, handle->data_size);
   data_js = json_loads (term_data,
-  JSON_DECODE_ANY,
+                       JSON_DECODE_ANY,
                        &err);
 
   if (NULL == data_js)
@@ -717,35 +719,69 @@ void
 ego_delete (struct GNUNET_REST_RequestHandle *con_handle, const char* url,
            void *cls)
 {
-  const char *keystring;
+  struct RequestHandle *handle = cls;
   struct EgoEntry *ego_entry;
   struct GNUNET_HashCode key;
   struct MHD_Response *resp;
-  struct RequestHandle *handle = cls;
+  const char *keystring;
+  char *egoname;
   int ego_exists = GNUNET_NO;
 
-  //if only one identity requested
+  keystring = NULL;
+  egoname = NULL;
+
+  //delete with pubkey
   GNUNET_CRYPTO_hash (GNUNET_REST_PARAM_PUBKEY,
                      strlen (GNUNET_REST_PARAM_PUBKEY), &key);
-  if ( GNUNET_NO
+  if ( GNUNET_YES
       == GNUNET_CONTAINER_multihashmap_contains (
          handle->rest_handle->url_param_map, &key))
   {
-    handle->emsg = GNUNET_strdup("Missing parameter pubkey");
-    GNUNET_SCHEDULER_add_now (&do_error, handle);
-    return;
+    keystring = GNUNET_CONTAINER_multihashmap_get (
+        handle->rest_handle->url_param_map,&key);
   }
 
-  keystring = GNUNET_CONTAINER_multihashmap_get (
-      handle->rest_handle->url_param_map,&key);
-  for (ego_entry = handle->ego_head;
-  NULL != ego_entry; ego_entry = ego_entry->next)
+  GNUNET_CRYPTO_hash (GNUNET_REST_PARAM_NAME,
+                     strlen (GNUNET_REST_PARAM_NAME), &key);
+  if ( GNUNET_YES
+      == GNUNET_CONTAINER_multihashmap_contains (
+         handle->rest_handle->url_param_map, &key))
   {
-    if (0 != strcasecmp (keystring, ego_entry->keystring))
-      continue;
-    ego_exists = GNUNET_YES;
-    break;
+    egoname = GNUNET_CONTAINER_multihashmap_get (
+       handle->rest_handle->url_param_map, &key);
+    //LOWERCASE ego names?
+    GNUNET_STRINGS_utf8_tolower(egoname, egoname);
+  }
+
+  if (NULL != keystring)
+  {
+    for (ego_entry = handle->ego_head;
+    NULL != ego_entry; ego_entry = ego_entry->next)
+    {
+      if (0 != strcasecmp (keystring, ego_entry->keystring))
+        continue;
+      ego_exists = GNUNET_YES;
+      break;
+    }
   }
+  else if (NULL != egoname)
+  {
+    for (ego_entry = handle->ego_head;
+    NULL != ego_entry; ego_entry = ego_entry->next)
+    {
+      if (0 != strcasecmp (egoname, ego_entry->identifier))
+        continue;
+      ego_exists = GNUNET_YES;
+      break;
+    }
+  }
+  else
+  {
+    handle->emsg = GNUNET_strdup("Missing parameter pubkey or name");
+    GNUNET_SCHEDULER_add_now (&do_error, handle);
+    return;
+  }
+
   if (GNUNET_NO == ego_exists)
   {
     resp = GNUNET_REST_create_response (NULL);
diff --git a/src/identity/test_plugin_rest_identity.sh 
b/src/identity/test_plugin_rest_identity.sh
index 170f3e928..f391f827f 100755
--- a/src/identity/test_plugin_rest_identity.sh
+++ b/src/identity/test_plugin_rest_identity.sh
@@ -84,8 +84,9 @@ fi
 
 id="$(gnunet-identity -d | grep "Test - " | sed  "s/Test - //g")"
 #Test GET (one identity) for success and error json
+#Only lowercase
 cache="$(curl --silent "${link_to_api}?name=Test" | grep "error")"
-if [ "" != "$cache" ]
+if [ "" == "$cache" ]
 then
     exit 1
 fi
@@ -96,7 +97,6 @@ then
     exit 1
 fi
 
-
 #Test DELETE success code, error response code and error json
 #echo "Next tests for DELETE will probably fail when POST fails"
 cache="$(curl -v -X "DELETE" "${link_to_api}?pubkey=$id" 2>&1 | grep "HTTP/1.1 
404")"

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

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