gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [gnunet] 70/75: Namestore Rest API finished


From: gnunet
Subject: [GNUnet-SVN] [gnunet] 70/75: Namestore Rest API finished
Date: Thu, 09 Aug 2018 23:59:07 +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 0d239903075f518edef85277f13d1b5d303443bf
Author: Phil <address@hidden>
AuthorDate: Wed Aug 8 23:24:10 2018 +0200

    Namestore Rest API finished
---
 src/json/json_gnsrecord.c                   | 18 ++++---
 src/namestore/plugin_rest_namestore.c       | 22 ++++++--
 src/namestore/test_plugin_rest_namestore.sh | 78 +++--------------------------
 3 files changed, 37 insertions(+), 81 deletions(-)

diff --git a/src/json/json_gnsrecord.c b/src/json/json_gnsrecord.c
index 4f6d30748..7bdf97f06 100644
--- a/src/json/json_gnsrecord.c
+++ b/src/json/json_gnsrecord.c
@@ -54,7 +54,7 @@ parse_gnsrecordobject (void *cls,
   const char *record_type;
   const char *label;
   int flag;
-  void *rdata;
+  void *rdata = NULL;
   size_t rdata_size;
 
   GNUNET_assert(NULL != root);
@@ -72,7 +72,7 @@ parse_gnsrecordobject (void *cls,
                             GNUNET_JSON_GNSRECORD_EXPIRATION_TIME, 
&expiration_time,
                             GNUNET_JSON_GNSRECORD_FLAG, &flag,
                             GNUNET_JSON_GNSRECORD_LABEL, &label);
-  if (GNUNET_SYSERR == unpack_state)
+  if (0 != unpack_state)
   {
     GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
               "Error json object has a wrong format!\n");
@@ -82,7 +82,8 @@ parse_gnsrecordobject (void *cls,
   gnsrecord_object->record_type = 
GNUNET_GNSRECORD_typename_to_number(record_type);
   if (UINT32_MAX == gnsrecord_object->record_type)
   {
-    GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,"Unsupported type");
+    GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,"Unsupported type\n");
+    GNUNET_free(gnsrecord_object);
     return GNUNET_SYSERR;
   }
   if (GNUNET_OK
@@ -91,7 +92,8 @@ parse_gnsrecordobject (void *cls,
                                           &rdata,
                                           &rdata_size))
   {
-    GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,"Value invalid for record type");
+    GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,"Value invalid for record type\n");
+    GNUNET_free(gnsrecord_object);
     return GNUNET_SYSERR;
   }
 
@@ -110,7 +112,9 @@ parse_gnsrecordobject (void *cls,
   }
   else
   {
-    GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Expiration time invalid");
+    GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Expiration time invalid\n");
+    GNUNET_free_non_null(rdata);
+    GNUNET_free(gnsrecord_object);
     return GNUNET_SYSERR;
   }
   // check if flag is a valid enum value
@@ -119,7 +123,9 @@ parse_gnsrecordobject (void *cls,
       && (GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION != flag)
       && (GNUNET_GNSRECORD_RF_SHADOW_RECORD) != flag)
   {
-    GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Flag invalid");
+    GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Flag invalid\n");
+    GNUNET_free_non_null(rdata);
+    GNUNET_free(gnsrecord_object);
     return GNUNET_SYSERR;
   }
   gnsrecord_object->flags = (enum GNUNET_GNSRECORD_Flags)flag;
diff --git a/src/namestore/plugin_rest_namestore.c 
b/src/namestore/plugin_rest_namestore.c
index 3801431b2..f14707cce 100644
--- a/src/namestore/plugin_rest_namestore.c
+++ b/src/namestore/plugin_rest_namestore.c
@@ -641,16 +641,17 @@ namestore_add (struct GNUNET_REST_RequestHandle 
*con_handle,
   {
     handle->emsg = GNUNET_strdup("Invalid data");
     GNUNET_SCHEDULER_add_now (&do_error, handle);
-    GNUNET_free_non_null(gns_record);
+    GNUNET_JSON_parse_free(gnsspec);
     json_decref (data_js);
     return;
   }
+  handle->rd = gns_record;
+
   name_json = json_object_get(data_js, "label");
   if (!json_is_string(name_json))
   {
     handle->emsg = GNUNET_strdup("Missing name");
     GNUNET_SCHEDULER_add_now (&do_error, handle);
-    GNUNET_free_non_null(gns_record);
     json_decref (data_js);
     return;
   }
@@ -659,7 +660,6 @@ namestore_add (struct GNUNET_REST_RequestHandle *con_handle,
   {
     handle->emsg = GNUNET_strdup("Missing name");
     GNUNET_SCHEDULER_add_now (&do_error, handle);
-    GNUNET_free_non_null(gns_record);
     json_decref (data_js);
     return;
   }
@@ -667,12 +667,10 @@ namestore_add (struct GNUNET_REST_RequestHandle 
*con_handle,
   {
     handle->emsg = GNUNET_strdup("Missing name");
     GNUNET_SCHEDULER_add_now (&do_error, handle);
-    GNUNET_free_non_null(gns_record);
     json_decref (data_js);
     return;
   }
   json_decref (data_js);
-  handle->rd = gns_record;
 
   //change zone if pubkey or name specified
   GNUNET_CRYPTO_hash (GNUNET_REST_API_PARAM_PUBKEY,
@@ -711,6 +709,12 @@ namestore_add (struct GNUNET_REST_RequestHandle 
*con_handle,
   {
     handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key(ego_entry->ego);
   }
+  if (NULL == handle->zone_pkey)
+  {
+    handle->emsg = GNUNET_strdup("No default identity for namestore");
+    GNUNET_SCHEDULER_add_now (&do_error, handle);
+    return;
+  }
   handle->add_qe = GNUNET_NAMESTORE_records_lookup (handle->ns_handle,
                                                    handle->zone_pkey,
                                                    handle->label_name,
@@ -813,6 +817,14 @@ namestore_delete (struct GNUNET_REST_RequestHandle 
*con_handle,
   }
   handle->label_name = GNUNET_strdup(
       GNUNET_CONTAINER_multihashmap_get (con_handle->url_param_map, &key));
+
+  if (NULL == handle->zone_pkey)
+  {
+    handle->emsg = GNUNET_strdup("No default identity for namestore");
+    GNUNET_SCHEDULER_add_now (&do_error, handle);
+    return;
+  }
+
   handle->add_qe = GNUNET_NAMESTORE_records_lookup (handle->ns_handle,
                                                     handle->zone_pkey,
                                                     handle->label_name,
diff --git a/src/namestore/test_plugin_rest_namestore.sh 
b/src/namestore/test_plugin_rest_namestore.sh
index 7c1e97397..de02dfafc 100755
--- a/src/namestore/test_plugin_rest_namestore.sh
+++ b/src/namestore/test_plugin_rest_namestore.sh
@@ -11,7 +11,7 @@ curl_get () {
     #$1 is link
     #$2 is grep
     cache="$(curl -v "$1" 2>&1 | grep "$2")"
-    echo $cache
+    #echo $cache
     if [ "" == "$cache" ]
     then
         exit 1
@@ -23,7 +23,7 @@ curl_post () {
     #$2 is data
     #$3 is grep
     cache="$(curl -v -X "POST" "$1" --data "$2" 2>&1 | grep "$3")"
-    echo $cache
+    #echo $cache
     if [ "" == "$cache" ]
     then
         exit 1
@@ -34,7 +34,7 @@ curl_delete () {
     #$1 is link
     #$2 is grep
     cache="$(curl -v -X "DELETE" "$1" 2>&1 | grep "$2")"
-    echo $cache
+    #echo $cache
     if [ "" == "$cache" ]
     then
         exit 1
@@ -197,74 +197,12 @@ gnunet-namestore -z $name -p -a -n "test_entry" -e "1d" 
-V "HVX38H2CB7WJM0WCPWT9
 curl_delete "${namestore_link}?label=test_entry&name=$name" "HTTP/1.1 204" 
 gnunet-namestore -z $name -p -a -n "test_entry" -e "1d" -V 
"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG" -t "PKEY"
 curl_delete "${namestore_link}?label=test_entry&pubkey=$public" "HTTP/1.1 204" 
+gnunet-namestore -z $name -p -a -n "test_entry" -e "1d" -V 
"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG" -t "PKEY"
+curl_delete "${namestore_link}?label=test_entry&pubkey=$name" "HTTP/1.1 404" 
 
-exit 0;
-
-
-
-#pubkey zone
-#name zone
-curl_post "${namestore_link}" '{"name":"test_plugin_rest_identity"}' "HTTP/1.1 
201 Created"
-curl_post "${namestore_link}" '{"name":"test_plugin_rest_identity"}' "HTTP/1.1 
409"
-curl_post "${namestore_link}" '{"name":"Test_plugin_rest_identity"}' "HTTP/1.1 
409"
-curl_post "${namestore_link}" '{}' "error"
-curl_post "${namestore_link}" '' "error"
-curl_post "${namestore_link}" '{"name":""}' "error"
-curl_post "${namestore_link}" '{"name":123}' "error"
-curl_post "${namestore_link}" '{"name":[]}' "error"
-curl_post "${namestore_link}" '{"name1":"test_plugin_rest_identity"}' "error"
-curl_post "${namestore_link}" '{"other":""}' "error"
-curl_post "${namestore_link}" '{"name":"test_plugin_rest_identity1", 
"other":"test_plugin_rest_identity2"}' "error"
-
-#Test PUT
-name="$(gnunet-identity -d | grep "test_plugin_rest_identity" | awk 
'NR==1{print $1}')"
-public="$(gnunet-identity -d | grep "test_plugin_rest_identity" | awk 
'NR==1{print $3}')"
-
-curl_put "${namestore_link}" 
'{"newname":"test_plugin_rest_identity1","pubkey":"'$public'"}' "HTTP/1.1 204"
-curl_put "${namestore_link}" 
'{"newname":"test_plugin_rest_identity1","pubkey":"'$public'"}' "HTTP/1.1 409"
-curl_put "${namestore_link}" 
'{"newname":"test_plugin_rest_identity1","pubkey":"'$public'xx"}' "HTTP/1.1 404"
-curl_put "${namestore_link}" 
'{"newname":"test_plugin_rest_identity1","pubkey":""}' "HTTP/1.1 404"
-curl_put "${namestore_link}" 
'{"newname":"test_plugin_rest_identity1","pubke":""}' "HTTP/1.1 404"
-curl_put "${namestore_link}" 
'{"newname":"test_plugin_rest_identity1","pubke":"","other":"sdfdsf"}' 
"HTTP/1.1 404"
-curl_put "${namestore_link}" 
'{"newname":"test_plugin_rest_identity1","pubke":"","name":"sdfdsf"}' "HTTP/1.1 
404"
-curl_put "${namestore_link}" 
'{"newname":"test_plugin_rest_identity","pubke":"","name":"test_plugin_rest_identity1"}'
 "HTTP/1.1 204"
-curl_put "${namestore_link}" 
'{"newnam":"test_plugin_rest_identity","pubkey":"'$public'"}' "error"
-curl_put "${namestore_link}" 
'{"newname":"test_plugin_rest_identity1","name":"test_plugin_rest_identity"}' 
"HTTP/1.1 204"
-curl_put "${namestore_link}" 
'{"newname":"TEST_plugin_rest_identity1","name":"test_plugin_rest_identity1"}' 
"HTTP/1.1 409"
-curl_put "${namestore_link}" 
'{"newname":"test_plugin_rest_identity1","name":"test_plugin_rest_identity1"}' 
"HTTP/1.1 409"
-curl_put "${namestore_link}" 
'{"newname":"test_plugin_rest_identity","name":"test_plugin_rest_identityxxx"}' 
"HTTP/1.1 404"
-curl_put "${namestore_link}" 
'{"newname":"test_plugin_rest_identity","name":"test_plugin_rest_identity1"}' 
"HTTP/1.1 204"
-curl_put "${namestore_link}" 
'{"newnam":"test_plugin_rest_identityfail","name":"test_plugin_rest_identity"}' 
"error"
-
-
-#Test subsystem
-curl_put "${identity_link}" 
'{"subsystem":"namestore","name":"test_plugin_rest_identity"}' "HTTP/1.1 204"
-curl_put "${identity_link}" 
'{"subsystem":"namestore","name":"test_plugin_rest_identity"}' "HTTP/1.1 204"
-curl_get "${identity_link}?subsystem=namestore" "test_plugin_rest_identity"
-curl_post "${identity_link}" '{"name":"test_plugin_rest_identity1"}' "HTTP/1.1 
201 Created"
-public="$(gnunet-identity -d | grep "test_plugin_rest_identity" | awk 
'NR==1{print $3}')"
-curl_put "${identity_link}" '{"subsystem":"namestore","pubkey":"'"$public"'"}' 
"HTTP/1.1 204"
-curl_get "${identity_link}?subsystem=namestore" "test_plugin_rest_identity1"
-curl_get "${identity_link}?subsystem=test_plugin_rest_identity_no_subsystem" 
"error"
-curl_put "${identity_link}" 
'{"subsystem":"test_plugin_rest_identity_no_subsystem","name":"test_plugin_rest_identity1"}'
 "HTTP/1.1 204"
-curl_get "${identity_link}?subsystem=test_plugin_rest_identity_no_subsystem" 
"test_plugin_rest_identity1"
-
-curl_put "${identity_link}" 
'{"subsyste":"test_plugin_rest_identity_no_subsystem","name":"test_plugin_rest_identity1"}'
 "error"
-curl_put "${identity_link}" 
'{"subsystem":"test_plugin_rest_identity_no_subsystem","name":"Test_plugin_rest_identity1"}'
 "HTTP/1.1 204"
-
-#Test DELETE
-curl_delete "${identity_link}?name=test_plugin_rest_identity" "HTTP/1.1 204"
-curl_get "${identity_link}?name=test_plugin_rest_identity" "error"
-curl_delete "${identity_link}?name=TEST_plugin_rest_identity1" "HTTP/1.1 404"
-curl_delete "${identity_link}?name=test_plugin_rest_identity1" "HTTP/1.1 204"
-curl_get "${identity_link}?name=test_plugin_rest_identity1" "error"
-curl_delete "${identity_link}?name=test_plugin_rest_identity_not_found" 
"HTTP/1.1 404"
-curl_post "${identity_link}" '{"name":"test_plugin_rest_identity1"}' "HTTP/1.1 
201 Created"
-public="$(gnunet-identity -d | grep "test_plugin_rest_identity1" | awk 
'NR==1{print $3}')"
-curl_delete "${identity_link}?pubkey=$public" "HTTP/1.1 204"
-curl_delete "${identity_link}?pubke=$public" "error"
-curl_delete "${identity_link}?pubkey=$public&other=232" "HTTP/1.1 404"
 
-#test default subsystem
+#Test default identity
+#not possible without defining 
 
 exit 0;
+

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



reply via email to

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