#include "platform.h"
#include "gnunet_rest_plugin.h"
#include "gnunet_rest_lib.h"
+#include "gnunet_json_lib.h"
#include "gnunet_gnsrecord_lib.h"
#include "gnunet_gns_service.h"
#include "microhttpd.h"
#define GNUNET_REST_API_NS_GNS "/gns"
-#define GNUNET_REST_PARAMETER_GNS_NAME "name"
+#define GNUNET_REST_GNS_PARAM_NAME "name"
-#define GNUNET_REST_PARAMETER_GNS_RECORD_TYPE "record_type"
+#define GNUNET_REST_GNS_PARAM_RECORD_TYPE "record_type"
#define GNUNET_REST_GNS_ERROR_UNKNOWN "Unknown Error"
/**
uint32_t rd_count,
const struct GNUNET_GNSRECORD_Data *rd)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "TEST4\n");
struct RequestHandle *handle = cls;
struct MHD_Response *resp;
json_t *result_array;
continue;
}
- record_value = GNUNET_GNSRECORD_value_to_string (rd->record_type,
- rd->data,
- rd->data_size);
- record_obj = json_string(record_value);
+ record_obj = GNUNET_JSON_from_gns_record(NULL,&rd[i]);
json_array_append (result_array, record_obj);
json_decref (record_obj);
}
char *record_type;
char *name;
- GNUNET_CRYPTO_hash (GNUNET_REST_PARAMETER_GNS_NAME,
- strlen (GNUNET_REST_PARAMETER_GNS_NAME),
+ GNUNET_CRYPTO_hash (GNUNET_REST_GNS_PARAM_NAME,
+ strlen (GNUNET_REST_GNS_PARAM_NAME),
&key);
if ( GNUNET_NO
== GNUNET_CONTAINER_multihashmap_contains (con_handle->url_param_map,
}
handle->name = GNUNET_strdup(name);
- GNUNET_CRYPTO_hash (GNUNET_REST_PARAMETER_GNS_RECORD_TYPE,
- strlen (GNUNET_REST_PARAMETER_GNS_RECORD_TYPE),
+ handle->record_type = UINT32_MAX;
+ GNUNET_CRYPTO_hash (GNUNET_REST_GNS_PARAM_RECORD_TYPE,
+ strlen (GNUNET_REST_GNS_PARAM_RECORD_TYPE),
&key);
- if ( GNUNET_NO
- == GNUNET_CONTAINER_multihashmap_contains (con_handle->url_param_map,
+ if ( GNUNET_YES
+ == GNUNET_CONTAINER_multihashmap_contains (con_handle->url_param_map,
&key))
{
- handle->emsg = GNUNET_strdup("Parameter record_type is missing");
- GNUNET_SCHEDULER_add_now (&do_error, handle);
- return;
+ record_type = GNUNET_CONTAINER_multihashmap_get (con_handle->url_param_map, &key);
+ handle->record_type = GNUNET_GNSRECORD_typename_to_number(record_type);
}
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "TEST1\n");
-
- record_type = GNUNET_CONTAINER_multihashmap_get (con_handle->url_param_map, &key);
- handle->record_type = GNUNET_GNSRECORD_typename_to_number(record_type);
if(UINT32_MAX == handle->record_type)
{
handle->record_type = GNUNET_GNSRECORD_TYPE_ANY;
GNUNET_SCHEDULER_add_now (&do_error, handle);
return;
}
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "TEST2\n");
handle->gns_lookup = GNUNET_GNS_lookup_with_tld (handle->gns,
handle->name,
--- /dev/null
+#!/usr/bin/bash
+
+#First, start gnunet-arm and the rest-service.
+#Exit 0 means success, exit 1 means failed test
+
+gns_link="http://localhost:7776/gns"
+wrong_link="http://localhost:7776/gnsandmore"
+
+curl_get () {
+ #$1 is link
+ #$2 is grep
+ cache="$(curl -v "$1" 2>&1 | grep "$2")"
+ echo $cache
+ if [ "" == "$cache" ]
+ then
+ exit 1
+ fi
+}
+
+gnunet-identity -D "test_plugin_rest_gns" > /dev/null 2>&1
+
+curl_get "$gns_link?name=www.test_plugin_rest_gns" "error"
+
+gnunet-identity -C "test_plugin_rest_gns"
+
+curl_get "$gns_link?name=www.test_plugin_rest_gns" "\[\]"
+
+gnunet-namestore -z "test_plugin_rest_gns" -p -a -n www -e 1d -V 1.1.1.1 -t A
+
+curl_get "$gns_link?name=www.test_plugin_rest_gns" "1.1.1.1"
+
+gnunet-namestore -z "test_plugin_rest_gns" -p -a -n www -e 1d -V 1::1 -t AAAA
+
+curl_get "$gns_link?name=www.test_plugin_rest_gns" "1::1.*1.1.1.1"
+
+gnunet-namestore -z "test_plugin_rest_gns" -p -a -n www -e 1d -V 1.1.1.2 -t A
+
+curl_get "$gns_link?name=www.test_plugin_rest_gns" "1.1.1.2.*1::1.*1.1.1.1"
+curl_get "$gns_link?name=www.test_plugin_rest_gns&record_type=A" "1.1.1.2.*1.1.1.1"
+curl_get "$gns_link?name=www.test_plugin_rest_gns&record_type=AAAA" "1::1"
+curl_get "$gns_link?name=www.test_plugin_rest_gns&record_type=WRONG_TYPE" "1.1.1.2.*1::1.*1.1.1.1"
+
+gnunet-namestore -z "test_plugin_rest_gns" -p -a -n www1 -e 1d -V 1.1.1.1 -t A
+curl_get "$gns_link?name=www1.test_plugin_rest_gns" "1.1.1.1"
+
+gnunet-identity -D "test_plugin_rest_gns"
+
+curl_get "$gns_link?name=www1.test_plugin_rest_gns" "error"
+
+exit 0