Namestore Rest API finished
authorPhil <phil.buschmann@tum.de>
Wed, 8 Aug 2018 21:24:10 +0000 (23:24 +0200)
committerPhil <phil.buschmann@tum.de>
Wed, 8 Aug 2018 21:24:10 +0000 (23:24 +0200)
src/json/json_gnsrecord.c
src/namestore/plugin_rest_namestore.c
src/namestore/test_plugin_rest_namestore.sh

index 4f6d30748ed606f40d984fb470e7f2b7793190c8..7bdf97f06dab80141c63010289dc477f3076afed 100644 (file)
@@ -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;
index 3801431b24f70d73906d6b971dfdf2e46e31cee0..f14707cce418107ad604a2a20662fa225b67bec3 100644 (file)
@@ -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,
index 7c1e973974496220a08fd7e570fcad6e817aa7c3..de02dfafca04217b62c4835a8a6661aa4be6c049 100755 (executable)
@@ -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;
+