#include "microhttpd.h"
#include <jansson.h>
+/**
+ * Rest API GNS Namespace
+ */
#define GNUNET_REST_API_NS_GNS "/gns"
-
-#define GNUNET_REST_GNS_PARAM_NAME "name"
-
+/**
+ * Rest API GNS Parameter record_type
+ */
#define GNUNET_REST_GNS_PARAM_RECORD_TYPE "record_type"
+
+/**
+ * Rest API GNS ERROR Unknown Error
+ */
#define GNUNET_REST_GNS_ERROR_UNKNOWN "Unknown Error"
+/**
+ * Rest API GNS ERROR Record not found
+ */
+#define GNUNET_REST_GNS_NOT_FOUND "Record not found"
+
/**
* The configuration handle
*/
const struct GNUNET_CONFIGURATION_Handle *cfg;
};
-
+/**
+ * The request handle
+ */
struct RequestHandle
{
char *emsg;
/**
- * Reponse code
+ * Response code
*/
int response_code;
if (GNUNET_NO == was_gns)
{
- handle->emsg = GNUNET_strdup("Name not found in GNS");
+ handle->response_code = MHD_HTTP_NOT_FOUND;
+ handle->emsg = GNUNET_strdup(GNUNET_REST_GNS_NOT_FOUND);
GNUNET_SCHEDULER_add_now (&do_error, handle);
return;
}
char *record_type;
char *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,
- &key))
+ name = NULL;
+ handle->name = NULL;
+ if (strlen (GNUNET_REST_API_NS_GNS) < strlen (handle->url))
+ {
+ name = &handle->url[strlen (GNUNET_REST_API_NS_GNS) + 1];
+ }
+
+ if (NULL == name)
{
- handle->emsg = GNUNET_strdup("Parameter name is missing");
+ handle->response_code = MHD_HTTP_NOT_FOUND;
+ handle->emsg = GNUNET_strdup(GNUNET_REST_GNS_NOT_FOUND);
GNUNET_SCHEDULER_add_now (&do_error, handle);
return;
}
- name = GNUNET_CONTAINER_multihashmap_get (con_handle->url_param_map,&key);
- if(0 >= strlen (name))
+ if (0 >= strlen (name))
{
- handle->emsg = GNUNET_strdup("Length of parameter name is zero");
+ handle->response_code = MHD_HTTP_NOT_FOUND;
+ handle->emsg = GNUNET_strdup(GNUNET_REST_GNS_NOT_FOUND);
GNUNET_SCHEDULER_add_now (&do_error, handle);
return;
}
handle->record_type = GNUNET_GNSRECORD_typename_to_number(record_type);
}
-
if(UINT32_MAX == handle->record_type)
{
handle->record_type = GNUNET_GNSRECORD_TYPE_ANY;
}
- handle->gns = GNUNET_GNS_connect (cfg);
- if (NULL == handle->gns)
- {
- handle->emsg = GNUNET_strdup ("GNS not available");
- GNUNET_SCHEDULER_add_now (&do_error, handle);
- return;
- }
-
handle->gns_lookup = GNUNET_GNS_lookup_with_tld (handle->gns,
handle->name,
handle->record_type,
GNUNET_NO,
&handle_gns_response,
handle);
- return;
}
if (handle->url[strlen (handle->url)-1] == '/')
handle->url[strlen (handle->url)-1] = '\0';
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n");
-
+ handle->gns = GNUNET_GNS_connect (cfg);
init_cont(handle);
handle->timeout_task =
gnunet-identity -D "test_plugin_rest_gns" > /dev/null 2>&1
-curl_get "$gns_link?name=www.test_plugin_rest_gns" "error"
+curl_get "$gns_link/www.test_plugin_rest_gns" "error"
gnunet-identity -C "test_plugin_rest_gns"
-curl_get "$gns_link?name=www.test_plugin_rest_gns" "\[\]"
+curl_get "$gns_link/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"
+curl_get "$gns_link/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"
+curl_get "$gns_link/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"
+curl_get "$gns_link/www.test_plugin_rest_gns" "1.1.1.2.*1::1.*1.1.1.1"
+curl_get "$gns_link/www.test_plugin_rest_gns?record_type=A" "1.1.1.2.*1.1.1.1"
+curl_get "$gns_link/www.test_plugin_rest_gns?record_type=AAAA" "1::1"
+curl_get "$gns_link/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"
+curl_get "$gns_link/www1.test_plugin_rest_gns" "1.1.1.1"
-gnunet-identity -D "test_plugin_rest_gns"
+gnunet-identity -D "test_plugin_rest_gns" > /dev/null 2>&1
-curl_get "$gns_link?name=www1.test_plugin_rest_gns" "error"
+curl_get "$gns_link/www1.test_plugin_rest_gns" "error"
exit 0
record_type_str = GNUNET_GNSRECORD_number_to_typename(rd->record_type);
// ? for possible NULL values
- ret = json_pack("{s:s?,s:s?,s:s?,s:i,s:s?}",
- "value", value_str,
- "type", record_type_str,
- "expiration_time", expiration_time_str,
- "flag", flags,
- "label", rname);
+ if (NULL != rname)
+ {
+ ret = json_pack ("{s:s?,s:s?,s:s?,s:i,s:s?}",
+ "value",
+ value_str,
+ "record_type",
+ record_type_str,
+ "expiration_time",
+ expiration_time_str,
+ "flag",
+ flags,
+ "label",
+ rname);
+ }
+ else
+ {
+ ret = json_pack ("{s:s?,s:s?,s:s?,s:i}",
+ "value",
+ value_str,
+ "record_type",
+ record_type_str,
+ "expiration_time",
+ expiration_time_str,
+ "flag",
+ flags);
+ }
GNUNET_free_non_null(value_str);
return ret;
}
#include "gnunet_json_lib.h"
#define GNUNET_JSON_GNSRECORD_VALUE "value"
-#define GNUNET_JSON_GNSRECORD_TYPE "type"
+#define GNUNET_JSON_GNSRECORD_TYPE "record_type"
#define GNUNET_JSON_GNSRECORD_EXPIRATION_TIME "expiration_time"
#define GNUNET_JSON_GNSRECORD_FLAG "flag"
-#define GNUNET_JSON_GNSRECORD_LABEL "label"
+#define GNUNET_JSON_GNSRECORD_RECORD_NAME "record_name"
#define GNUNET_JSON_GNSRECORD_NEVER "never"
const char *value;
const char *expiration_time;
const char *record_type;
- const char *label;
+ const char *name;
int flag;
void *rdata = NULL;
size_t rdata_size;
GNUNET_JSON_GNSRECORD_TYPE, &record_type,
GNUNET_JSON_GNSRECORD_EXPIRATION_TIME, &expiration_time,
GNUNET_JSON_GNSRECORD_FLAG, &flag,
- GNUNET_JSON_GNSRECORD_LABEL, &label);
+ GNUNET_JSON_GNSRECORD_RECORD_NAME, &name);
if (0 != unpack_state)
{
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
#include "microhttpd.h"
#include <jansson.h>
-
+/**
+ * Namestore Namespace
+ */
#define GNUNET_REST_API_NS_NAMESTORE "/namestore"
-#define GNUNET_REST_SUBSYSTEM_NAMESTORE "namestore"
/**
- * Parameter names
+ * Error message Unknown Error
*/
-#define GNUNET_REST_API_PARAM_PUBKEY "pubkey"
-#define GNUNET_REST_API_PARAM_NAME "name"
+#define GNUNET_REST_NAMESTORE_ERROR_UNKNOWN "Unknown Error"
/**
- * Error messages
+ * Error message No identity found
*/
-#define GNUNET_REST_NAMESTORE_ERROR_UNKNOWN "Unknown Error"
+#define GNUNET_REST_IDENTITY_NOT_FOUND "No identity found"
-#define GNUNET_REST_NAMESTORE_RD_COUNT 1
+/**
+ * Error message No default zone specified
+ */
+#define GNUNET_REST_NAMESTORE_NO_DEFAULT_ZONE "No default zone specified"
+
+/**
+ * Error message Failed request
+ */
+#define GNUNET_REST_NAMESTORE_FAILED "Namestore action failed"
+
+/**
+ * Error message invalid data
+ */
+#define GNUNET_REST_NAMESTORE_INVALID_DATA "Data invalid"
+
+/**
+ * Error message No data
+ */
+#define GNUNET_REST_NAMESTORE_NO_DATA "No data"
/**
* State while collecting all egos
struct GNUNET_IDENTITY_Ego *ego;
};
-
+/**
+ * The request handle
+ */
struct RequestHandle
{
/**
* Records to store
*/
- char *label_name;
+ char *record_name;
/**
* Records to store
char *emsg;
/**
- * Reponse code
+ * Response code
*/
int response_code;
GNUNET_SCHEDULER_cancel (handle->timeout_task);
handle->timeout_task = NULL;
}
- if (NULL != handle->label_name)
- GNUNET_free(handle->label_name);
+ if (NULL != handle->record_name)
+ GNUNET_free(handle->record_name);
if (NULL != handle->url)
GNUNET_free(handle->url);
if (NULL != handle->emsg)
* @return EgoEntry or NULL if not found
*/
struct EgoEntry*
-get_egoentry(struct RequestHandle *handle, char* pubkey, char *name)
+get_egoentry_namestore(struct RequestHandle *handle, char *name)
{
struct EgoEntry *ego_entry;
- if (NULL != pubkey)
- {
- for (ego_entry = handle->ego_head;
- NULL != ego_entry;
- ego_entry = ego_entry->next)
- {
- if (0 != strcasecmp (pubkey, ego_entry->keystring))
- continue;
- return ego_entry;
- }
- }
if (NULL != name)
{
for (ego_entry = handle->ego_head;
/**
* Does internal server error when iteration failed.
+ *
+ * @param cls the `struct RequestHandle`
*/
static void
namestore_iteration_error (void *cls)
{
struct RequestHandle *handle = cls;
- struct MHD_Response *resp = GNUNET_REST_create_response (NULL);
- handle->proc (handle->proc_cls, resp, MHD_HTTP_INTERNAL_SERVER_ERROR);
- GNUNET_SCHEDULER_add_now (&cleanup_handle, handle);
+ handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_FAILED);
+ GNUNET_SCHEDULER_add_now (&do_error, handle);
+ return;
}
+/**
+ * Create finished callback
+ *
+ * @param cls the `struct RequestHandle`
+ * @param success the success indicating integer, GNUNET_OK on success
+ * @param emsg the error message (can be NULL)
+ */
static void
create_finished (void *cls, int32_t success, const char *emsg)
{
handle->add_qe = NULL;
if (GNUNET_YES != success)
{
+ if (NULL != emsg)
+ {
+ handle->emsg = GNUNET_strdup(emsg);
+ GNUNET_SCHEDULER_add_now (&do_error, handle);
+ return;
+ }
handle->emsg = GNUNET_strdup("Error storing records");
GNUNET_SCHEDULER_add_now (&do_error, handle);
return;
}
+/**
+ * Delete finished callback
+ *
+ * @param cls the `struct RequestHandle`
+ * @param success the success indicating integer, GNUNET_OK on success
+ * @param emsg the error message (can be NULL)
+ */
static void
del_finished (void *cls, int32_t success, const char *emsg)
{
handle->add_qe = NULL;
if (GNUNET_NO == success)
{
- handle->emsg = GNUNET_strdup("Deleting record failed. Record does not exist");
+ handle->response_code = MHD_HTTP_NOT_FOUND;
+ handle->emsg = GNUNET_strdup("No record found");
GNUNET_SCHEDULER_add_now (&do_error, handle);
return;
}
if (GNUNET_SYSERR == success)
{
+ if (NULL != emsg)
+ {
+ handle->emsg = GNUNET_strdup(emsg);
+ GNUNET_SCHEDULER_add_now (&do_error, handle);
+ return;
+ }
handle->emsg = GNUNET_strdup("Deleting record failed");
GNUNET_SCHEDULER_add_now (&do_error, handle);
return;
if (NULL == handle->resp_object)
handle->resp_object = json_array();
- /*if ( (NULL != handle->ego_entry->identifier) &&
- (0 != strcmp (handle->ego_entry->identifier,
- rname)) )
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "%s does not match %s\n", rname,
- handle->ego_entry->identifier);
- GNUNET_NAMESTORE_zone_iterator_next (handle->list_it, 1);
- return;
- }*/
-
for (unsigned int i = 0; i < rd_len; i++)
{
if ( (GNUNET_GNSRECORD_TYPE_NICK == rd[i].record_type) &&
void *cls)
{
struct RequestHandle *handle = cls;
- struct EgoEntry *ego_entry = NULL;
- struct GNUNET_HashCode key;
- char *pubkey = NULL;
- char *name = NULL;
-
- //change zone if pubkey or name specified
- GNUNET_CRYPTO_hash (GNUNET_REST_API_PARAM_PUBKEY,
- strlen (GNUNET_REST_API_PARAM_PUBKEY),
- &key);
- if ( GNUNET_YES
- == GNUNET_CONTAINER_multihashmap_contains (con_handle->url_param_map,
- &key))
- {
- pubkey = GNUNET_CONTAINER_multihashmap_get (con_handle->url_param_map,
- &key);
- }
- GNUNET_CRYPTO_hash (GNUNET_REST_API_PARAM_NAME,
- strlen (GNUNET_REST_API_PARAM_NAME),
- &key);
- if ( GNUNET_YES
- == GNUNET_CONTAINER_multihashmap_contains (con_handle->url_param_map,
- &key))
- {
- name = GNUNET_CONTAINER_multihashmap_get (con_handle->url_param_map,
- &key);
- }
+ struct EgoEntry *ego_entry;
+ char *egoname;
+
+ egoname = NULL;
+ ego_entry = NULL;
- ego_entry = get_egoentry(handle,pubkey,name);
- if (NULL == ego_entry)
+ //set zone to name if given
+ if (strlen (GNUNET_REST_API_NS_NAMESTORE) < strlen (handle->url))
{
- if (NULL != pubkey || NULL != name)
+ egoname = &handle->url[strlen (GNUNET_REST_API_NS_NAMESTORE)+1];
+ ego_entry = get_egoentry_namestore(handle, egoname);
+
+ if (NULL == ego_entry)
{
- handle->emsg = GNUNET_strdup("Invalid identity");
handle->response_code = MHD_HTTP_NOT_FOUND;
+ handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_NOT_FOUND);
GNUNET_SCHEDULER_add_now (&do_error, handle);
return;
}
{
handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key(ego_entry->ego);
}
+ if (NULL == handle->zone_pkey)
+ {
+ handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_NO_DEFAULT_ZONE);
+ GNUNET_SCHEDULER_add_now (&do_error, handle);
+ return;
+ }
handle->list_it = GNUNET_NAMESTORE_zone_iteration_start (handle->ns_handle,
handle->zone_pkey,
&namestore_iteration_error,
handle,
&namestore_list_finished,
handle);
-}
-
-
-/**
- * We're storing a new record; this requires
- * that no record already exists
- *
- * @param cls closure, unused
- * @param zone_key private key of the zone
- * @param rec_name name that is being mapped (at most 255 characters long)
- * @param rd_count number of entries in @a rd array
- * @param rd array of records with data to store
- */
-static void
-create_new_record_cont (void *cls,
- const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
- const char *rec_name,
- unsigned int rd_count,
- const struct GNUNET_GNSRECORD_Data *rd)
-{
- struct RequestHandle *handle = cls;
-
- handle->add_qe = NULL;
- if (0 != strcmp (rec_name, handle->label_name))
+ if (NULL == handle->list_it)
{
- GNUNET_break (0);
+ handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_FAILED);
GNUNET_SCHEDULER_add_now (&do_error, handle);
return;
}
-
- if (0 != rd_count)
- {
- handle->proc (handle->proc_cls,
- GNUNET_REST_create_response (NULL),
- MHD_HTTP_CONFLICT);
- GNUNET_SCHEDULER_add_now (&cleanup_handle, handle);
- return;
- }
- handle->add_qe = GNUNET_NAMESTORE_records_store (handle->ns_handle,
- handle->zone_pkey,
- handle->label_name,
- GNUNET_REST_NAMESTORE_RD_COUNT,
- handle->rd,
- &create_finished,
- handle);
}
+
/**
* Handle namestore POST request
*
{
struct RequestHandle *handle = cls;
struct GNUNET_GNSRECORD_Data *gns_record;
+ struct EgoEntry *ego_entry;
+ char *egoname;
json_t *data_js;
json_t *name_json;
json_error_t err;
-
- struct EgoEntry *ego_entry = NULL;
- struct GNUNET_HashCode key;
- char *pubkey = NULL;
- char *name = NULL;
-
char term_data[handle->rest_handle->data_size + 1];
+
struct GNUNET_JSON_Specification gnsspec[] = {
GNUNET_JSON_spec_gnsrecord_data(&gns_record),
GNUNET_JSON_spec_end ()
};
- if (strlen (GNUNET_REST_API_NS_NAMESTORE) != strlen (handle->url))
- {
- handle->emsg = GNUNET_strdup("Wrong URL");
- GNUNET_SCHEDULER_add_now (&do_error, handle);
- return;
- }
if (0 >= handle->rest_handle->data_size)
{
- handle->emsg = GNUNET_strdup("No data");
+ handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_NO_DATA);
GNUNET_SCHEDULER_add_now (&do_error, handle);
return;
}
data_js = json_loads (term_data, JSON_DECODE_ANY, &err);
if (GNUNET_OK != GNUNET_JSON_parse (data_js, gnsspec, NULL, NULL))
{
- handle->emsg = GNUNET_strdup("Invalid data");
+ handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_INVALID_DATA);
GNUNET_SCHEDULER_add_now (&do_error, handle);
GNUNET_JSON_parse_free(gnsspec);
json_decref (data_js);
}
handle->rd = gns_record;
- name_json = json_object_get(data_js, "label");
+ name_json = json_object_get(data_js, "record_name");
if (!json_is_string(name_json))
{
- handle->emsg = GNUNET_strdup("Missing name");
+ handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_INVALID_DATA);
GNUNET_SCHEDULER_add_now (&do_error, handle);
json_decref (data_js);
return;
}
- handle->label_name = GNUNET_strdup(json_string_value(name_json));
- if(NULL == handle->label_name)
+ handle->record_name = GNUNET_strdup(json_string_value(name_json));
+ if(NULL == handle->record_name)
{
- handle->emsg = GNUNET_strdup("Missing name");
+ handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_INVALID_DATA);
GNUNET_SCHEDULER_add_now (&do_error, handle);
json_decref (data_js);
return;
}
- if (0 >= strlen(handle->label_name))
+ if (0 >= strlen(handle->record_name))
{
- handle->emsg = GNUNET_strdup("Missing name");
+ handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_INVALID_DATA);
GNUNET_SCHEDULER_add_now (&do_error, handle);
json_decref (data_js);
return;
}
json_decref (data_js);
- //change zone if pubkey or name specified
- GNUNET_CRYPTO_hash (GNUNET_REST_API_PARAM_PUBKEY,
- strlen (GNUNET_REST_API_PARAM_PUBKEY),
- &key);
- if ( GNUNET_YES
- == GNUNET_CONTAINER_multihashmap_contains (con_handle->url_param_map,
- &key))
- {
- pubkey = GNUNET_CONTAINER_multihashmap_get (con_handle->url_param_map,
- &key);
- }
- GNUNET_CRYPTO_hash (GNUNET_REST_API_PARAM_NAME,
- strlen (GNUNET_REST_API_PARAM_NAME),
- &key);
- if ( GNUNET_YES
- == GNUNET_CONTAINER_multihashmap_contains (con_handle->url_param_map,
- &key))
- {
- name = GNUNET_CONTAINER_multihashmap_get (con_handle->url_param_map,
- &key);
- }
+ egoname = NULL;
+ ego_entry = NULL;
- ego_entry = get_egoentry(handle,pubkey,name);
- if (NULL == ego_entry)
+ //set zone to name if given
+ if (strlen (GNUNET_REST_API_NS_NAMESTORE) < strlen (handle->url))
{
- if (NULL != pubkey || NULL != name)
+ egoname = &handle->url[strlen (GNUNET_REST_API_NS_NAMESTORE)+1];
+ ego_entry = get_egoentry_namestore(handle, egoname);
+
+ if (NULL == ego_entry)
{
- handle->emsg = GNUNET_strdup("Invalid identity");
handle->response_code = MHD_HTTP_NOT_FOUND;
+ handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_NOT_FOUND);
GNUNET_SCHEDULER_add_now (&do_error, handle);
return;
}
}
- if ( NULL != ego_entry )
+ if (NULL != ego_entry)
{
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");
+ handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_NO_DEFAULT_ZONE);
GNUNET_SCHEDULER_add_now (&do_error, handle);
return;
}
- handle->add_qe = GNUNET_NAMESTORE_records_lookup (handle->ns_handle,
+ handle->add_qe = GNUNET_NAMESTORE_records_store (handle->ns_handle,
handle->zone_pkey,
- handle->label_name,
- &do_error,
- handle,
- &create_new_record_cont,
+ handle->record_name,
+ 1,
+ handle->rd,
+ &create_finished,
handle);
-}
-
-
-static void
-del_cont (void *cls,
- const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
- const char *label,
- unsigned int rd_count,
- const struct GNUNET_GNSRECORD_Data *rd)
-{
- struct RequestHandle *handle = cls;
-
- handle->add_qe = NULL;
- if (0 == rd_count)
+ if (NULL == handle->add_qe)
{
- handle->emsg = GNUNET_strdup("Record not found");
+ handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_FAILED);
GNUNET_SCHEDULER_add_now (&do_error, handle);
return;
}
-
- handle->add_qe = GNUNET_NAMESTORE_records_store (handle->ns_handle,
- handle->zone_pkey,
- handle->label_name,
- 0, NULL,
- &del_finished,
- handle);
}
+
/**
* Handle namestore DELETE request
*
{
struct RequestHandle *handle = cls;
struct GNUNET_HashCode key;
- struct EgoEntry *ego_entry = NULL;
- char *pubkey = NULL;
- char *name = NULL;
-
- //change zone if pubkey or name specified
- GNUNET_CRYPTO_hash (GNUNET_REST_API_PARAM_PUBKEY,
- strlen (GNUNET_REST_API_PARAM_PUBKEY),
- &key);
- if ( GNUNET_YES
- == GNUNET_CONTAINER_multihashmap_contains (con_handle->url_param_map,
- &key))
- {
- pubkey = GNUNET_CONTAINER_multihashmap_get (con_handle->url_param_map,
- &key);
- }
- GNUNET_CRYPTO_hash (GNUNET_REST_API_PARAM_NAME,
- strlen (GNUNET_REST_API_PARAM_NAME),
- &key);
- if ( GNUNET_YES
- == GNUNET_CONTAINER_multihashmap_contains (con_handle->url_param_map,
- &key))
- {
- name = GNUNET_CONTAINER_multihashmap_get (con_handle->url_param_map,
- &key);
- }
+ struct EgoEntry *ego_entry;
+ char *egoname;
+
+ egoname = NULL;
+ ego_entry = NULL;
- ego_entry = get_egoentry(handle,pubkey,name);
- if (NULL == ego_entry)
+ //set zone to name if given
+ if (strlen (GNUNET_REST_API_NS_NAMESTORE) < strlen (handle->url))
{
- if (NULL != pubkey || NULL != name)
+ egoname = &handle->url[strlen (GNUNET_REST_API_NS_NAMESTORE)+1];
+ ego_entry = get_egoentry_namestore(handle, egoname);
+
+ if (NULL == ego_entry)
{
- handle->emsg = GNUNET_strdup("Invalid identity");
handle->response_code = MHD_HTTP_NOT_FOUND;
+ handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_NOT_FOUND);
GNUNET_SCHEDULER_add_now (&do_error, handle);
return;
}
handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key(ego_entry->ego);
}
- GNUNET_CRYPTO_hash ("label", strlen ("label"), &key);
+ GNUNET_CRYPTO_hash ("record_name", strlen ("record_name"), &key);
if ( GNUNET_NO
== GNUNET_CONTAINER_multihashmap_contains (con_handle->url_param_map,
&key))
{
- handle->emsg = GNUNET_strdup("Missing name");
+ handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_INVALID_DATA);
GNUNET_SCHEDULER_add_now (&do_error, handle);
return;
}
- handle->label_name = GNUNET_strdup(
+ handle->record_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");
+ handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_NO_DEFAULT_ZONE);
GNUNET_SCHEDULER_add_now (&do_error, handle);
return;
}
- handle->add_qe = GNUNET_NAMESTORE_records_lookup (handle->ns_handle,
- handle->zone_pkey,
- handle->label_name,
- &do_error,
- handle,
- &del_cont,
- handle);
-
+ handle->add_qe = GNUNET_NAMESTORE_records_store (handle->ns_handle,
+ handle->zone_pkey,
+ handle->record_name,
+ 0,
+ NULL,
+ &del_finished,
+ handle);
+ if (NULL == handle->add_qe)
+ {
+ handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_FAILED);
+ GNUNET_SCHEDULER_add_now (&do_error, handle);
+ return;
+ }
}
/**
- * Connect to identity callback
+ * This function is initially called for all egos and then again
+ * whenever a ego's identifier changes or if it is deleted. At the
+ * end of the initial pass over all egos, the function is once called
+ * with 'NULL' for 'ego'. That does NOT mean that the callback won't
+ * be invoked in the future or that there was an error.
+ *
+ * When used with 'GNUNET_IDENTITY_create' or 'GNUNET_IDENTITY_get',
+ * this function is only called ONCE, and 'NULL' being passed in
+ * 'ego' does indicate an error (i.e. name is taken or no default
+ * value is known). If 'ego' is non-NULL and if '*ctx'
+ * is set in those callbacks, the value WILL be passed to a subsequent
+ * call to the identity callback of 'GNUNET_IDENTITY_connect' (if
+ * that one was not NULL).
+ *
+ * When an identity is renamed, this function is called with the
+ * (known) ego but the NEW identifier.
+ *
+ * When an identity is deleted, this function is called with the
+ * (known) ego and "NULL" for the 'identifier'. In this case,
+ * the 'ego' is henceforth invalid (and the 'ctx' should also be
+ * cleaned up).
+ *
+ * @param cls closure
+ * @param ego ego handle
+ * @param ctx context for application to store data for this ego
+ * (during the lifetime of this process, initially NULL)
+ * @param name identifier assigned by the user for this ego,
+ * NULL if the user just deleted the ego and it
+ * must thus no longer be used
*/
static void
id_connect_cb (void *cls,
if ((NULL == ego) && (NULL == handle->zone_pkey))
{
handle->op = GNUNET_IDENTITY_get (handle->identity_handle,
- GNUNET_REST_SUBSYSTEM_NAMESTORE,
+ "namestore",
&default_ego_cb,
handle);
}
#$1 is link
#$2 is grep
cache="$(curl -v "$1" 2>&1 | grep "$2")"
- #echo $cache
+ echo $cache
if [ "" == "$cache" ]
then
exit 1
#$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
#$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
if [ "" == "$test" ]
then
#if no entries for test_plugin_rest_namestore
- curl_get "${namestore_link}?name=$name" "error"
- curl_get "${namestore_link}?name=" "error"
- curl_get "${namestore_link}?name=$public" "error"
-
- curl_get "${namestore_link}?pubkey=$public" "error"
- curl_get "${namestore_link}?pubkey=$name" "error"
- curl_get "${namestore_link}?pubkey=" "error"
+ curl_get "${namestore_link}/$name" "error"
+ curl_get "${namestore_link}/" "error"
+ curl_get "${namestore_link}/$public" "error"
else
#if entries exists (that should not be possible)
curl_get "${namestore_link}" "HTTP/1.1 200 OK"
- curl_get "${namestore_link}?name=$name" "HTTP/1.1 200 OK"
- curl_get "${namestore_link}?name=" "error"
- curl_get "${namestore_link}?name=$public" "error"
-
- curl_get "${namestore_link}?pubkey=$public" "HTTP/1.1 200 OK"
- curl_get "${namestore_link}?pubkey=$name" "error"
- curl_get "${namestore_link}?pubkey=" "error"
+ curl_get "${namestore_link}/$name" "HTTP/1.1 200 OK"
+ curl_get "${namestore_link}/" "error"
+ curl_get "${namestore_link}/$public" "error"
fi
gnunet-namestore -z $name -p -a -n "test_entry" -e "1d" -V "HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG" -t "PKEY"
curl_get "${namestore_link}" "HTTP/1.1 200 OK"
-curl_get "${namestore_link}?name=$name" "HTTP/1.1 200 OK"
-curl_get "${namestore_link}?name=" "error"
-curl_get "${namestore_link}?name=$public" "error"
-curl_get "${namestore_link}?pubkey=$public" "HTTP/1.1 200 OK"
-curl_get "${namestore_link}?pubkey=$name" "error"
-curl_get "${namestore_link}?pubkey=" "error"
+curl_get "${namestore_link}/$name" "HTTP/1.1 200 OK"
+curl_get "${namestore_link}/" "error"
+curl_get "${namestore_link}/$public" "error"
gnunet-namestore -z $name -d -n "test_entry"
#Test POST with NAME
-curl_post "${namestore_link}?name=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":0,"label":"test_entry"}' "HTTP/1.1 204 No Content"
+curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":0,"record_name":"test_entry"}' "HTTP/1.1 204 No Content"
gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
#value
-curl_post "${namestore_link}?name=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRGxxx", "type":"PKEY", "expiration_time":"1d","flag":0,"label":"test_entry"}' "error"
+curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRGxxx", "record_type":"PKEY", "expiration_time":"1d","flag":0,"record_name":"test_entry"}' "error"
gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
-curl_post "${namestore_link}?name=$name" '{"value":"", "type":"PKEY", "expiration_time":"1d","flag":0,"label":"test_entry"}' "error"
+curl_post "${namestore_link}/$name" '{"value":"", "record_type":"PKEY", "expiration_time":"1d","flag":0,"record_name":"test_entry"}' "error"
gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
-curl_post "${namestore_link}?name=$name" '{"value_missing":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRGxxx", "type":"PKEY", "expiration_time":"1d","flag":0,"label":"test_entry"}' "error"
+curl_post "${namestore_link}/$name" '{"value_missing":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRGxxx", "record_type":"PKEY", "expiration_time":"1d","flag":0,"record_name":"test_entry"}' "error"
gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
#time
-curl_post "${namestore_link}?name=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"0d","flag":0,"label":"test_entry"}' "HTTP/1.1 204"
+curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"0d","flag":0,"record_name":"test_entry"}' "HTTP/1.1 204"
gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
-curl_post "${namestore_link}?name=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"10000d","flag":0,"label":"test_entry"}' "HTTP/1.1 204"
+curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"10000d","flag":0,"record_name":"test_entry"}' "HTTP/1.1 204"
gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
-curl_post "${namestore_link}?name=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"now","flag":0,"label":"test_entry"}' "error"
+curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"now","flag":0,"record_name":"test_entry"}' "error"
gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
-curl_post "${namestore_link}?name=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"","flag":0,"label":"test_entry"}' "error"
+curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"","flag":0,"record_name":"test_entry"}' "error"
gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
-curl_post "${namestore_link}?name=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time_missing":"1d","flag":0,"label":"test_entry"}' "error"
+curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time_missing":"1d","flag":0,"record_name":"test_entry"}' "error"
gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
#flag
-curl_post "${namestore_link}?name=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":0,"label":"test_entry"}' "HTTP/1.1 204 No Content"
+curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":0,"record_name":"test_entry"}' "HTTP/1.1 204 No Content"
gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
-curl_post "${namestore_link}?name=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":2,"label":"test_entry"}' "HTTP/1.1 204 No Content"
+curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":2,"record_name":"test_entry"}' "HTTP/1.1 204 No Content"
gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
-curl_post "${namestore_link}?name=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":8,"label":"test_entry"}' "HTTP/1.1 204 No Content"
+curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":8,"record_name":"test_entry"}' "HTTP/1.1 204 No Content"
gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
-curl_post "${namestore_link}?name=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":16,"label":"test_entry"}' "HTTP/1.1 204 No Content"
+curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":16,"record_name":"test_entry"}' "HTTP/1.1 204 No Content"
gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
-curl_post "${namestore_link}?name=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":-1,"label":"test_entry"}' "error"
+curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":-1,"record_name":"test_entry"}' "error"
gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
-curl_post "${namestore_link}?name=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":"Test","label":"test_entry"}' "error"
+curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":"Test","record_name":"test_entry"}' "error"
gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
-curl_post "${namestore_link}?name=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":,"label":"test_entry"}' "error"
+curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":,"record_name":"test_entry"}' "error"
gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
-curl_post "${namestore_link}?name=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag_missing":0,"label":"test_entry"}' "error"
+curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag_missing":0,"record_name":"test_entry"}' "error"
gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
-#label
-curl_post "${namestore_link}?name=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":0,"label":"test_entry"}' "HTTP/1.1 204 No Content"
-curl_post "${namestore_link}?name=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":0,"label":"test_entry"}' "HTTP/1.1 409"
+#record_name
+curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":0,"record_name":"test_entry"}' "HTTP/1.1 204 No Content"
+curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":0,"record_name":"test_entry"}' "HTTP/1.1 204 No Content"
gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
-curl_post "${namestore_link}?name=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":0,"label":""}' "error"
+curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":0,"record_name":""}' "error"
gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
-curl_post "${namestore_link}?name=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":0,"label_missing":"test_entry"}' "error"
-gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
-
-#Test POST with PUBKEY
-curl_post "${namestore_link}?pubkey=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":0,"label":"test_entry"}' "HTTP/1.1 204 No Content"
-gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
-#value
-curl_post "${namestore_link}?pubkey=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRGxxx", "type":"PKEY", "expiration_time":"1d","flag":0,"label":"test_entry"}' "error"
-gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
-curl_post "${namestore_link}?pubkey=$public" '{"value":"", "type":"PKEY", "expiration_time":"1d","flag":0,"label":"test_entry"}' "error"
-gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
-curl_post "${namestore_link}?pubkey=$public" '{"value_missing":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRGxxx", "type":"PKEY", "expiration_time":"1d","flag":0,"label":"test_entry"}' "error"
-gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
-#time
-curl_post "${namestore_link}?pubkey=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"0d","flag":0,"label":"test_entry"}' "HTTP/1.1 204"
-gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
-curl_post "${namestore_link}?pubkey=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"10000d","flag":0,"label":"test_entry"}' "HTTP/1.1 204"
-gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
-curl_post "${namestore_link}?pubkey=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"now","flag":0,"label":"test_entry"}' "error"
-gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
-curl_post "${namestore_link}?pubkey=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"","flag":0,"label":"test_entry"}' "error"
-gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
-curl_post "${namestore_link}?pubkey=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time_missing":"1d","flag":0,"label":"test_entry"}' "error"
-gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
-#flag
-curl_post "${namestore_link}?pubkey=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":0,"label":"test_entry"}' "HTTP/1.1 204 No Content"
-gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
-curl_post "${namestore_link}?pubkey=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":2,"label":"test_entry"}' "HTTP/1.1 204 No Content"
-gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
-curl_post "${namestore_link}?pubkey=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":8,"label":"test_entry"}' "HTTP/1.1 204 No Content"
-gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
-curl_post "${namestore_link}?pubkey=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":16,"label":"test_entry"}' "HTTP/1.1 204 No Content"
-gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
-curl_post "${namestore_link}?pubkey=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":-1,"label":"test_entry"}' "error"
-gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
-curl_post "${namestore_link}?pubkey=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":"Test","label":"test_entry"}' "error"
-gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
-curl_post "${namestore_link}?pubkey=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":,"label":"test_entry"}' "error"
-gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
-curl_post "${namestore_link}?pubkey=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag_missing":0,"label":"test_entry"}' "error"
-gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
-#label
-curl_post "${namestore_link}?pubkey=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":0,"label":"test_entry"}' "HTTP/1.1 204 No Content"
-curl_post "${namestore_link}?pubkey=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":0,"label":"test_entry"}' "HTTP/1.1 409"
-gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
-curl_post "${namestore_link}?pubkey=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":0,"label":""}' "error"
-gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
-curl_post "${namestore_link}?pubkey=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":0,"label_missing":"test_entry"}' "error"
+curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":0,"record_name_missing":"test_entry"}' "error"
gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
#wrong zone
-curl_post "${namestore_link}?name=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":0,"label":"test_entry"}' "error"
-gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
-curl_post "${namestore_link}?pubkey=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":0,"label":"test_entry"}' "error"
+curl_post "${namestore_link}/$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":0,"record_name":"test_entry"}' "error"
gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
#Test DELETE
gnunet-namestore -z $name -p -a -n "test_entry" -e "1d" -V "HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG" -t "PKEY"
-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"
+curl_delete "${namestore_link}/$name?record_name=test_entry" "HTTP/1.1 204"
+curl_delete "${namestore_link}/$name?record_name=test_entry" "error"
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"
+curl_delete "${namestore_link}/$public?record_name=test_entry" "error"
#Test default identity
#include "microhttpd.h"
#include <jansson.h>
+/**
+ * Peerinfo Namespace
+ */
#define GNUNET_REST_API_NS_PEERINFO "/peerinfo"
-#define GNUNET_REST_API_PEERINFO_PEER "peer"
-#define GNUNET_REST_API_PEERINFO_FRIEND "friend"
-#define GNUNET_REST_API_PEERINFO_ARRAY "array"
+/**
+ * Peerinfo parameter peer
+ */
+#define GNUNET_REST_PEERINFO_PEER "peer"
-#define GNUNET_REST_ERROR_UNKNOWN "Unkown Error"
+/**
+ * Peerinfo parameter friend
+ */
+#define GNUNET_REST_PEERINFO_FRIEND "friend"
+
+/**
+ * Peerinfo parameter array
+ */
+#define GNUNET_REST_PEERINFO_ARRAY "array"
+
+/**
+ * Error message Unknown Error
+ */
+#define GNUNET_REST_PEERINFO_ERROR_UNKNOWN "Unknown Error"
/**
* How long until we time out during address lookup?
*/
struct PrintContext
{
-
/**
* Kept in DLL.
*/
*/
static struct PrintContext *pc_tail;
+/**
+ * The request handle
+ */
struct RequestHandle
{
/**
char *response;
if (NULL == handle->emsg)
- handle->emsg = GNUNET_strdup(GNUNET_REST_ERROR_UNKNOWN);
+ handle->emsg = GNUNET_strdup(GNUNET_REST_PEERINFO_ERROR_UNKNOWN);
json_object_set_new(json_error,"error", json_string(handle->emsg));
/**
- * Function that assembles our response.
+ * Function that assembles the response.
+ *
+ * @param cls the `struct RequestHandle`
*/
static void
peerinfo_list_finished (void *cls)
if (NULL == handle->response)
{
+ handle->response_code = MHD_HTTP_NOT_FOUND;
handle->emsg = GNUNET_strdup ("No peers found");
GNUNET_SCHEDULER_add_now (&do_error, handle);
return;
temp_array = json_array();
response_entry = json_object();
-// printf (_("%sPeer `%s'\n"),
-// (GNUNET_YES == pc->friend_only) ? "F2F: " : "",
-// GNUNET_i2s_full (&pc->peer));
for (i = 0; i < pc->num_addresses; i++)
{
if (NULL != pc->address_list[i].result)
GNUNET_i2s_full (&pc->peer));
friend_and_peer_json = json_string(friend_and_peer);
json_object_set(response_entry,
- GNUNET_REST_API_PEERINFO_PEER,
+ GNUNET_REST_PEERINFO_PEER,
friend_and_peer_json);
json_object_set(response_entry,
- GNUNET_REST_API_PEERINFO_ARRAY,
+ GNUNET_REST_PEERINFO_ARRAY,
temp_array);
json_array_append(pc->handle->response, response_entry);
json_decref(friend_and_peer_json);
char* include_friend_only_str;
include_friend_only = GNUNET_NO;
- GNUNET_CRYPTO_hash (GNUNET_REST_API_PEERINFO_FRIEND,
- strlen (GNUNET_REST_API_PEERINFO_FRIEND),
+ GNUNET_CRYPTO_hash (GNUNET_REST_PEERINFO_FRIEND,
+ strlen (GNUNET_REST_PEERINFO_FRIEND),
&key);
if ( GNUNET_YES
== GNUNET_CONTAINER_multihashmap_contains (con_handle->url_param_map,
}
specific_peer = NULL;
- GNUNET_CRYPTO_hash (GNUNET_REST_API_PEERINFO_PEER,
- strlen (GNUNET_REST_API_PEERINFO_PEER),
+ GNUNET_CRYPTO_hash (GNUNET_REST_PEERINFO_PEER,
+ strlen (GNUNET_REST_PEERINFO_PEER),
&key);
if ( GNUNET_YES
== GNUNET_CONTAINER_multihashmap_contains (con_handle->url_param_map,
&key))
{
- peer_id = *(unsigned int*)GNUNET_CONTAINER_multihashmap_get (con_handle->url_param_map, &key);
- specific_peer = GNUNET_PEER_resolve2(peer_id);
+ //peer_id = *(unsigned int*)GNUNET_CONTAINER_multihashmap_get (con_handle->url_param_map, &key);
+ //specific_peer = GNUNET_PEER_resolve2(peer_id);
}
handle->list_it = GNUNET_PEERINFO_iterate(handle->peerinfo_handle,