aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPhil <phil.buschmann@tum.de>2018-08-12 23:11:10 +0200
committerPhil <phil.buschmann@tum.de>2018-08-12 23:11:10 +0200
commit4df7069dcd17ac39c786ee6f21455c96e6a6dbf4 (patch)
tree80fe63630f82dd79f73f24cbb954c0703cd873f3 /src
parent89485145a0f33984a70bffdf0f766667b4a3e75e (diff)
downloadgnunet-4df7069dcd17ac39c786ee6f21455c96e6a6dbf4.tar.gz
gnunet-4df7069dcd17ac39c786ee6f21455c96e6a6dbf4.zip
Changed Namestore API, changed error handling, changed gns record json
Diffstat (limited to 'src')
-rw-r--r--src/gns/plugin_rest_gns.c62
-rwxr-xr-xsrc/gns/test_plugin_rest_gns.sh22
-rw-r--r--src/json/json_generator.c32
-rw-r--r--src/json/json_gnsrecord.c8
-rw-r--r--src/namestore/plugin_rest_namestore.c407
-rwxr-xr-xsrc/namestore/test_plugin_rest_namestore.sh137
-rw-r--r--src/peerinfo/plugin_rest_peerinfo.c55
7 files changed, 329 insertions, 394 deletions
diff --git a/src/gns/plugin_rest_gns.c b/src/gns/plugin_rest_gns.c
index fd2469577..0bf4198fc 100644
--- a/src/gns/plugin_rest_gns.c
+++ b/src/gns/plugin_rest_gns.c
@@ -30,15 +30,27 @@
30#include "microhttpd.h" 30#include "microhttpd.h"
31#include <jansson.h> 31#include <jansson.h>
32 32
33/**
34 * Rest API GNS Namespace
35 */
33#define GNUNET_REST_API_NS_GNS "/gns" 36#define GNUNET_REST_API_NS_GNS "/gns"
34 37
35 38/**
36#define GNUNET_REST_GNS_PARAM_NAME "name" 39 * Rest API GNS Parameter record_type
37 40 */
38#define GNUNET_REST_GNS_PARAM_RECORD_TYPE "record_type" 41#define GNUNET_REST_GNS_PARAM_RECORD_TYPE "record_type"
42
43/**
44 * Rest API GNS ERROR Unknown Error
45 */
39#define GNUNET_REST_GNS_ERROR_UNKNOWN "Unknown Error" 46#define GNUNET_REST_GNS_ERROR_UNKNOWN "Unknown Error"
40 47
41/** 48/**
49 * Rest API GNS ERROR Record not found
50 */
51#define GNUNET_REST_GNS_NOT_FOUND "Record not found"
52
53/**
42 * The configuration handle 54 * The configuration handle
43 */ 55 */
44const struct GNUNET_CONFIGURATION_Handle *cfg; 56const struct GNUNET_CONFIGURATION_Handle *cfg;
@@ -56,7 +68,9 @@ struct Plugin
56 const struct GNUNET_CONFIGURATION_Handle *cfg; 68 const struct GNUNET_CONFIGURATION_Handle *cfg;
57}; 69};
58 70
59 71/**
72 * The request handle
73 */
60struct RequestHandle 74struct RequestHandle
61{ 75{
62 76
@@ -116,7 +130,7 @@ struct RequestHandle
116 char *emsg; 130 char *emsg;
117 131
118 /** 132 /**
119 * Reponse code 133 * Response code
120 */ 134 */
121 int response_code; 135 int response_code;
122 136
@@ -214,7 +228,8 @@ handle_gns_response (void *cls,
214 228
215 if (GNUNET_NO == was_gns) 229 if (GNUNET_NO == was_gns)
216 { 230 {
217 handle->emsg = GNUNET_strdup("Name not found in GNS"); 231 handle->response_code = MHD_HTTP_NOT_FOUND;
232 handle->emsg = GNUNET_strdup(GNUNET_REST_GNS_NOT_FOUND);
218 GNUNET_SCHEDULER_add_now (&do_error, handle); 233 GNUNET_SCHEDULER_add_now (&do_error, handle);
219 return; 234 return;
220 } 235 }
@@ -260,21 +275,24 @@ get_gns_cont (struct GNUNET_REST_RequestHandle *con_handle,
260 char *record_type; 275 char *record_type;
261 char *name; 276 char *name;
262 277
263 GNUNET_CRYPTO_hash (GNUNET_REST_GNS_PARAM_NAME, 278 name = NULL;
264 strlen (GNUNET_REST_GNS_PARAM_NAME), 279 handle->name = NULL;
265 &key); 280 if (strlen (GNUNET_REST_API_NS_GNS) < strlen (handle->url))
266 if ( GNUNET_NO 281 {
267 == GNUNET_CONTAINER_multihashmap_contains (con_handle->url_param_map, 282 name = &handle->url[strlen (GNUNET_REST_API_NS_GNS) + 1];
268 &key)) 283 }
284
285 if (NULL == name)
269 { 286 {
270 handle->emsg = GNUNET_strdup("Parameter name is missing"); 287 handle->response_code = MHD_HTTP_NOT_FOUND;
288 handle->emsg = GNUNET_strdup(GNUNET_REST_GNS_NOT_FOUND);
271 GNUNET_SCHEDULER_add_now (&do_error, handle); 289 GNUNET_SCHEDULER_add_now (&do_error, handle);
272 return; 290 return;
273 } 291 }
274 name = GNUNET_CONTAINER_multihashmap_get (con_handle->url_param_map,&key); 292 if (0 >= strlen (name))
275 if(0 >= strlen (name))
276 { 293 {
277 handle->emsg = GNUNET_strdup("Length of parameter name is zero"); 294 handle->response_code = MHD_HTTP_NOT_FOUND;
295 handle->emsg = GNUNET_strdup(GNUNET_REST_GNS_NOT_FOUND);
278 GNUNET_SCHEDULER_add_now (&do_error, handle); 296 GNUNET_SCHEDULER_add_now (&do_error, handle);
279 return; 297 return;
280 } 298 }
@@ -292,27 +310,17 @@ get_gns_cont (struct GNUNET_REST_RequestHandle *con_handle,
292 handle->record_type = GNUNET_GNSRECORD_typename_to_number(record_type); 310 handle->record_type = GNUNET_GNSRECORD_typename_to_number(record_type);
293 } 311 }
294 312
295
296 if(UINT32_MAX == handle->record_type) 313 if(UINT32_MAX == handle->record_type)
297 { 314 {
298 handle->record_type = GNUNET_GNSRECORD_TYPE_ANY; 315 handle->record_type = GNUNET_GNSRECORD_TYPE_ANY;
299 } 316 }
300 317
301 handle->gns = GNUNET_GNS_connect (cfg);
302 if (NULL == handle->gns)
303 {
304 handle->emsg = GNUNET_strdup ("GNS not available");
305 GNUNET_SCHEDULER_add_now (&do_error, handle);
306 return;
307 }
308
309 handle->gns_lookup = GNUNET_GNS_lookup_with_tld (handle->gns, 318 handle->gns_lookup = GNUNET_GNS_lookup_with_tld (handle->gns,
310 handle->name, 319 handle->name,
311 handle->record_type, 320 handle->record_type,
312 GNUNET_NO, 321 GNUNET_NO,
313 &handle_gns_response, 322 &handle_gns_response,
314 handle); 323 handle);
315 return;
316} 324}
317 325
318 326
@@ -397,7 +405,7 @@ rest_process_request(struct GNUNET_REST_RequestHandle *rest_handle,
397 if (handle->url[strlen (handle->url)-1] == '/') 405 if (handle->url[strlen (handle->url)-1] == '/')
398 handle->url[strlen (handle->url)-1] = '\0'; 406 handle->url[strlen (handle->url)-1] = '\0';
399 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n"); 407 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n");
400 408 handle->gns = GNUNET_GNS_connect (cfg);
401 init_cont(handle); 409 init_cont(handle);
402 410
403 handle->timeout_task = 411 handle->timeout_task =
diff --git a/src/gns/test_plugin_rest_gns.sh b/src/gns/test_plugin_rest_gns.sh
index 7ede44501..ec495a04b 100755
--- a/src/gns/test_plugin_rest_gns.sh
+++ b/src/gns/test_plugin_rest_gns.sh
@@ -19,32 +19,32 @@ curl_get () {
19 19
20gnunet-identity -D "test_plugin_rest_gns" > /dev/null 2>&1 20gnunet-identity -D "test_plugin_rest_gns" > /dev/null 2>&1
21 21
22curl_get "$gns_link?name=www.test_plugin_rest_gns" "error" 22curl_get "$gns_link/www.test_plugin_rest_gns" "error"
23 23
24gnunet-identity -C "test_plugin_rest_gns" 24gnunet-identity -C "test_plugin_rest_gns"
25 25
26curl_get "$gns_link?name=www.test_plugin_rest_gns" "\[\]" 26curl_get "$gns_link/www.test_plugin_rest_gns" "\[\]"
27 27
28gnunet-namestore -z "test_plugin_rest_gns" -p -a -n www -e 1d -V 1.1.1.1 -t A 28gnunet-namestore -z "test_plugin_rest_gns" -p -a -n www -e 1d -V 1.1.1.1 -t A
29 29
30curl_get "$gns_link?name=www.test_plugin_rest_gns" "1.1.1.1" 30curl_get "$gns_link/www.test_plugin_rest_gns" "1.1.1.1"
31 31
32gnunet-namestore -z "test_plugin_rest_gns" -p -a -n www -e 1d -V 1::1 -t AAAA 32gnunet-namestore -z "test_plugin_rest_gns" -p -a -n www -e 1d -V 1::1 -t AAAA
33 33
34curl_get "$gns_link?name=www.test_plugin_rest_gns" "1::1.*1.1.1.1" 34curl_get "$gns_link/www.test_plugin_rest_gns" "1::1.*1.1.1.1"
35 35
36gnunet-namestore -z "test_plugin_rest_gns" -p -a -n www -e 1d -V 1.1.1.2 -t A 36gnunet-namestore -z "test_plugin_rest_gns" -p -a -n www -e 1d -V 1.1.1.2 -t A
37 37
38curl_get "$gns_link?name=www.test_plugin_rest_gns" "1.1.1.2.*1::1.*1.1.1.1" 38curl_get "$gns_link/www.test_plugin_rest_gns" "1.1.1.2.*1::1.*1.1.1.1"
39curl_get "$gns_link?name=www.test_plugin_rest_gns&record_type=A" "1.1.1.2.*1.1.1.1" 39curl_get "$gns_link/www.test_plugin_rest_gns?record_type=A" "1.1.1.2.*1.1.1.1"
40curl_get "$gns_link?name=www.test_plugin_rest_gns&record_type=AAAA" "1::1" 40curl_get "$gns_link/www.test_plugin_rest_gns?record_type=AAAA" "1::1"
41curl_get "$gns_link?name=www.test_plugin_rest_gns&record_type=WRONG_TYPE" "1.1.1.2.*1::1.*1.1.1.1" 41curl_get "$gns_link/www.test_plugin_rest_gns?record_type=WRONG_TYPE" "1.1.1.2.*1::1.*1.1.1.1"
42 42
43gnunet-namestore -z "test_plugin_rest_gns" -p -a -n www1 -e 1d -V 1.1.1.1 -t A 43gnunet-namestore -z "test_plugin_rest_gns" -p -a -n www1 -e 1d -V 1.1.1.1 -t A
44curl_get "$gns_link?name=www1.test_plugin_rest_gns" "1.1.1.1" 44curl_get "$gns_link/www1.test_plugin_rest_gns" "1.1.1.1"
45 45
46gnunet-identity -D "test_plugin_rest_gns" 46gnunet-identity -D "test_plugin_rest_gns" > /dev/null 2>&1
47 47
48curl_get "$gns_link?name=www1.test_plugin_rest_gns" "error" 48curl_get "$gns_link/www1.test_plugin_rest_gns" "error"
49 49
50exit 0 50exit 0
diff --git a/src/json/json_generator.c b/src/json/json_generator.c
index d8c82bc86..0ffe5c643 100644
--- a/src/json/json_generator.c
+++ b/src/json/json_generator.c
@@ -182,12 +182,32 @@ GNUNET_JSON_from_gns_record (const char* rname,
182 record_type_str = GNUNET_GNSRECORD_number_to_typename(rd->record_type); 182 record_type_str = GNUNET_GNSRECORD_number_to_typename(rd->record_type);
183 183
184 // ? for possible NULL values 184 // ? for possible NULL values
185 ret = json_pack("{s:s?,s:s?,s:s?,s:i,s:s?}", 185 if (NULL != rname)
186 "value", value_str, 186 {
187 "type", record_type_str, 187 ret = json_pack ("{s:s?,s:s?,s:s?,s:i,s:s?}",
188 "expiration_time", expiration_time_str, 188 "value",
189 "flag", flags, 189 value_str,
190 "label", rname); 190 "record_type",
191 record_type_str,
192 "expiration_time",
193 expiration_time_str,
194 "flag",
195 flags,
196 "label",
197 rname);
198 }
199 else
200 {
201 ret = json_pack ("{s:s?,s:s?,s:s?,s:i}",
202 "value",
203 value_str,
204 "record_type",
205 record_type_str,
206 "expiration_time",
207 expiration_time_str,
208 "flag",
209 flags);
210 }
191 GNUNET_free_non_null(value_str); 211 GNUNET_free_non_null(value_str);
192 return ret; 212 return ret;
193} 213}
diff --git a/src/json/json_gnsrecord.c b/src/json/json_gnsrecord.c
index 7bdf97f06..fe51119b1 100644
--- a/src/json/json_gnsrecord.c
+++ b/src/json/json_gnsrecord.c
@@ -26,10 +26,10 @@
26#include "gnunet_json_lib.h" 26#include "gnunet_json_lib.h"
27 27
28#define GNUNET_JSON_GNSRECORD_VALUE "value" 28#define GNUNET_JSON_GNSRECORD_VALUE "value"
29#define GNUNET_JSON_GNSRECORD_TYPE "type" 29#define GNUNET_JSON_GNSRECORD_TYPE "record_type"
30#define GNUNET_JSON_GNSRECORD_EXPIRATION_TIME "expiration_time" 30#define GNUNET_JSON_GNSRECORD_EXPIRATION_TIME "expiration_time"
31#define GNUNET_JSON_GNSRECORD_FLAG "flag" 31#define GNUNET_JSON_GNSRECORD_FLAG "flag"
32#define GNUNET_JSON_GNSRECORD_LABEL "label" 32#define GNUNET_JSON_GNSRECORD_RECORD_NAME "record_name"
33#define GNUNET_JSON_GNSRECORD_NEVER "never" 33#define GNUNET_JSON_GNSRECORD_NEVER "never"
34 34
35 35
@@ -52,7 +52,7 @@ parse_gnsrecordobject (void *cls,
52 const char *value; 52 const char *value;
53 const char *expiration_time; 53 const char *expiration_time;
54 const char *record_type; 54 const char *record_type;
55 const char *label; 55 const char *name;
56 int flag; 56 int flag;
57 void *rdata = NULL; 57 void *rdata = NULL;
58 size_t rdata_size; 58 size_t rdata_size;
@@ -71,7 +71,7 @@ parse_gnsrecordobject (void *cls,
71 GNUNET_JSON_GNSRECORD_TYPE, &record_type, 71 GNUNET_JSON_GNSRECORD_TYPE, &record_type,
72 GNUNET_JSON_GNSRECORD_EXPIRATION_TIME, &expiration_time, 72 GNUNET_JSON_GNSRECORD_EXPIRATION_TIME, &expiration_time,
73 GNUNET_JSON_GNSRECORD_FLAG, &flag, 73 GNUNET_JSON_GNSRECORD_FLAG, &flag,
74 GNUNET_JSON_GNSRECORD_LABEL, &label); 74 GNUNET_JSON_GNSRECORD_RECORD_NAME, &name);
75 if (0 != unpack_state) 75 if (0 != unpack_state)
76 { 76 {
77 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 77 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
diff --git a/src/namestore/plugin_rest_namestore.c b/src/namestore/plugin_rest_namestore.c
index f14707cce..1d72d13ff 100644
--- a/src/namestore/plugin_rest_namestore.c
+++ b/src/namestore/plugin_rest_namestore.c
@@ -32,22 +32,40 @@
32#include "microhttpd.h" 32#include "microhttpd.h"
33#include <jansson.h> 33#include <jansson.h>
34 34
35 35/**
36 * Namestore Namespace
37 */
36#define GNUNET_REST_API_NS_NAMESTORE "/namestore" 38#define GNUNET_REST_API_NS_NAMESTORE "/namestore"
37#define GNUNET_REST_SUBSYSTEM_NAMESTORE "namestore"
38 39
39/** 40/**
40 * Parameter names 41 * Error message Unknown Error
41 */ 42 */
42#define GNUNET_REST_API_PARAM_PUBKEY "pubkey" 43#define GNUNET_REST_NAMESTORE_ERROR_UNKNOWN "Unknown Error"
43#define GNUNET_REST_API_PARAM_NAME "name"
44 44
45/** 45/**
46 * Error messages 46 * Error message No identity found
47 */ 47 */
48#define GNUNET_REST_NAMESTORE_ERROR_UNKNOWN "Unknown Error" 48#define GNUNET_REST_IDENTITY_NOT_FOUND "No identity found"
49 49
50#define GNUNET_REST_NAMESTORE_RD_COUNT 1 50/**
51 * Error message No default zone specified
52 */
53#define GNUNET_REST_NAMESTORE_NO_DEFAULT_ZONE "No default zone specified"
54
55/**
56 * Error message Failed request
57 */
58#define GNUNET_REST_NAMESTORE_FAILED "Namestore action failed"
59
60/**
61 * Error message invalid data
62 */
63#define GNUNET_REST_NAMESTORE_INVALID_DATA "Data invalid"
64
65/**
66 * Error message No data
67 */
68#define GNUNET_REST_NAMESTORE_NO_DATA "No data"
51 69
52/** 70/**
53 * State while collecting all egos 71 * State while collecting all egos
@@ -107,13 +125,15 @@ struct EgoEntry
107 struct GNUNET_IDENTITY_Ego *ego; 125 struct GNUNET_IDENTITY_Ego *ego;
108}; 126};
109 127
110 128/**
129 * The request handle
130 */
111struct RequestHandle 131struct RequestHandle
112{ 132{
113 /** 133 /**
114 * Records to store 134 * Records to store
115 */ 135 */
116 char *label_name; 136 char *record_name;
117 137
118 /** 138 /**
119 * Records to store 139 * Records to store
@@ -211,7 +231,7 @@ struct RequestHandle
211 char *emsg; 231 char *emsg;
212 232
213 /** 233 /**
214 * Reponse code 234 * Response code
215 */ 235 */
216 int response_code; 236 int response_code;
217 237
@@ -235,8 +255,8 @@ cleanup_handle (void *cls)
235 GNUNET_SCHEDULER_cancel (handle->timeout_task); 255 GNUNET_SCHEDULER_cancel (handle->timeout_task);
236 handle->timeout_task = NULL; 256 handle->timeout_task = NULL;
237 } 257 }
238 if (NULL != handle->label_name) 258 if (NULL != handle->record_name)
239 GNUNET_free(handle->label_name); 259 GNUNET_free(handle->record_name);
240 if (NULL != handle->url) 260 if (NULL != handle->url)
241 GNUNET_free(handle->url); 261 GNUNET_free(handle->url);
242 if (NULL != handle->emsg) 262 if (NULL != handle->emsg)
@@ -318,20 +338,9 @@ do_error (void *cls)
318 * @return EgoEntry or NULL if not found 338 * @return EgoEntry or NULL if not found
319 */ 339 */
320struct EgoEntry* 340struct EgoEntry*
321get_egoentry(struct RequestHandle *handle, char* pubkey, char *name) 341get_egoentry_namestore(struct RequestHandle *handle, char *name)
322{ 342{
323 struct EgoEntry *ego_entry; 343 struct EgoEntry *ego_entry;
324 if (NULL != pubkey)
325 {
326 for (ego_entry = handle->ego_head;
327 NULL != ego_entry;
328 ego_entry = ego_entry->next)
329 {
330 if (0 != strcasecmp (pubkey, ego_entry->keystring))
331 continue;
332 return ego_entry;
333 }
334 }
335 if (NULL != name) 344 if (NULL != name)
336 { 345 {
337 for (ego_entry = handle->ego_head; 346 for (ego_entry = handle->ego_head;
@@ -349,17 +358,26 @@ get_egoentry(struct RequestHandle *handle, char* pubkey, char *name)
349 358
350/** 359/**
351 * Does internal server error when iteration failed. 360 * Does internal server error when iteration failed.
361 *
362 * @param cls the `struct RequestHandle`
352 */ 363 */
353static void 364static void
354namestore_iteration_error (void *cls) 365namestore_iteration_error (void *cls)
355{ 366{
356 struct RequestHandle *handle = cls; 367 struct RequestHandle *handle = cls;
357 struct MHD_Response *resp = GNUNET_REST_create_response (NULL); 368 handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_FAILED);
358 handle->proc (handle->proc_cls, resp, MHD_HTTP_INTERNAL_SERVER_ERROR); 369 GNUNET_SCHEDULER_add_now (&do_error, handle);
359 GNUNET_SCHEDULER_add_now (&cleanup_handle, handle); 370 return;
360} 371}
361 372
362 373
374/**
375 * Create finished callback
376 *
377 * @param cls the `struct RequestHandle`
378 * @param success the success indicating integer, GNUNET_OK on success
379 * @param emsg the error message (can be NULL)
380 */
363static void 381static void
364create_finished (void *cls, int32_t success, const char *emsg) 382create_finished (void *cls, int32_t success, const char *emsg)
365{ 383{
@@ -369,6 +387,12 @@ create_finished (void *cls, int32_t success, const char *emsg)
369 handle->add_qe = NULL; 387 handle->add_qe = NULL;
370 if (GNUNET_YES != success) 388 if (GNUNET_YES != success)
371 { 389 {
390 if (NULL != emsg)
391 {
392 handle->emsg = GNUNET_strdup(emsg);
393 GNUNET_SCHEDULER_add_now (&do_error, handle);
394 return;
395 }
372 handle->emsg = GNUNET_strdup("Error storing records"); 396 handle->emsg = GNUNET_strdup("Error storing records");
373 GNUNET_SCHEDULER_add_now (&do_error, handle); 397 GNUNET_SCHEDULER_add_now (&do_error, handle);
374 return; 398 return;
@@ -379,6 +403,13 @@ create_finished (void *cls, int32_t success, const char *emsg)
379} 403}
380 404
381 405
406/**
407 * Delete finished callback
408 *
409 * @param cls the `struct RequestHandle`
410 * @param success the success indicating integer, GNUNET_OK on success
411 * @param emsg the error message (can be NULL)
412 */
382static void 413static void
383del_finished (void *cls, int32_t success, const char *emsg) 414del_finished (void *cls, int32_t success, const char *emsg)
384{ 415{
@@ -387,12 +418,19 @@ del_finished (void *cls, int32_t success, const char *emsg)
387 handle->add_qe = NULL; 418 handle->add_qe = NULL;
388 if (GNUNET_NO == success) 419 if (GNUNET_NO == success)
389 { 420 {
390 handle->emsg = GNUNET_strdup("Deleting record failed. Record does not exist"); 421 handle->response_code = MHD_HTTP_NOT_FOUND;
422 handle->emsg = GNUNET_strdup("No record found");
391 GNUNET_SCHEDULER_add_now (&do_error, handle); 423 GNUNET_SCHEDULER_add_now (&do_error, handle);
392 return; 424 return;
393 } 425 }
394 if (GNUNET_SYSERR == success) 426 if (GNUNET_SYSERR == success)
395 { 427 {
428 if (NULL != emsg)
429 {
430 handle->emsg = GNUNET_strdup(emsg);
431 GNUNET_SCHEDULER_add_now (&do_error, handle);
432 return;
433 }
396 handle->emsg = GNUNET_strdup("Deleting record failed"); 434 handle->emsg = GNUNET_strdup("Deleting record failed");
397 GNUNET_SCHEDULER_add_now (&do_error, handle); 435 GNUNET_SCHEDULER_add_now (&do_error, handle);
398 return; 436 return;
@@ -452,17 +490,6 @@ namestore_list_iteration (void *cls,
452 if (NULL == handle->resp_object) 490 if (NULL == handle->resp_object)
453 handle->resp_object = json_array(); 491 handle->resp_object = json_array();
454 492
455 /*if ( (NULL != handle->ego_entry->identifier) &&
456 (0 != strcmp (handle->ego_entry->identifier,
457 rname)) )
458 {
459 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
460 "%s does not match %s\n", rname,
461 handle->ego_entry->identifier);
462 GNUNET_NAMESTORE_zone_iterator_next (handle->list_it, 1);
463 return;
464 }*/
465
466 for (unsigned int i = 0; i < rd_len; i++) 493 for (unsigned int i = 0; i < rd_len; i++)
467 { 494 {
468 if ( (GNUNET_GNSRECORD_TYPE_NICK == rd[i].record_type) && 495 if ( (GNUNET_GNSRECORD_TYPE_NICK == rd[i].record_type) &&
@@ -495,40 +522,22 @@ namestore_get (struct GNUNET_REST_RequestHandle *con_handle,
495 void *cls) 522 void *cls)
496{ 523{
497 struct RequestHandle *handle = cls; 524 struct RequestHandle *handle = cls;
498 struct EgoEntry *ego_entry = NULL; 525 struct EgoEntry *ego_entry;
499 struct GNUNET_HashCode key; 526 char *egoname;
500 char *pubkey = NULL; 527
501 char *name = NULL; 528 egoname = NULL;
502 529 ego_entry = NULL;
503 //change zone if pubkey or name specified
504 GNUNET_CRYPTO_hash (GNUNET_REST_API_PARAM_PUBKEY,
505 strlen (GNUNET_REST_API_PARAM_PUBKEY),
506 &key);
507 if ( GNUNET_YES
508 == GNUNET_CONTAINER_multihashmap_contains (con_handle->url_param_map,
509 &key))
510 {
511 pubkey = GNUNET_CONTAINER_multihashmap_get (con_handle->url_param_map,
512 &key);
513 }
514 GNUNET_CRYPTO_hash (GNUNET_REST_API_PARAM_NAME,
515 strlen (GNUNET_REST_API_PARAM_NAME),
516 &key);
517 if ( GNUNET_YES
518 == GNUNET_CONTAINER_multihashmap_contains (con_handle->url_param_map,
519 &key))
520 {
521 name = GNUNET_CONTAINER_multihashmap_get (con_handle->url_param_map,
522 &key);
523 }
524 530
525 ego_entry = get_egoentry(handle,pubkey,name); 531 //set zone to name if given
526 if (NULL == ego_entry) 532 if (strlen (GNUNET_REST_API_NS_NAMESTORE) < strlen (handle->url))
527 { 533 {
528 if (NULL != pubkey || NULL != name) 534 egoname = &handle->url[strlen (GNUNET_REST_API_NS_NAMESTORE)+1];
535 ego_entry = get_egoentry_namestore(handle, egoname);
536
537 if (NULL == ego_entry)
529 { 538 {
530 handle->emsg = GNUNET_strdup("Invalid identity");
531 handle->response_code = MHD_HTTP_NOT_FOUND; 539 handle->response_code = MHD_HTTP_NOT_FOUND;
540 handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_NOT_FOUND);
532 GNUNET_SCHEDULER_add_now (&do_error, handle); 541 GNUNET_SCHEDULER_add_now (&do_error, handle);
533 return; 542 return;
534 } 543 }
@@ -537,6 +546,12 @@ namestore_get (struct GNUNET_REST_RequestHandle *con_handle,
537 { 546 {
538 handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key(ego_entry->ego); 547 handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key(ego_entry->ego);
539 } 548 }
549 if (NULL == handle->zone_pkey)
550 {
551 handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_NO_DEFAULT_ZONE);
552 GNUNET_SCHEDULER_add_now (&do_error, handle);
553 return;
554 }
540 handle->list_it = GNUNET_NAMESTORE_zone_iteration_start (handle->ns_handle, 555 handle->list_it = GNUNET_NAMESTORE_zone_iteration_start (handle->ns_handle,
541 handle->zone_pkey, 556 handle->zone_pkey,
542 &namestore_iteration_error, 557 &namestore_iteration_error,
@@ -545,53 +560,15 @@ namestore_get (struct GNUNET_REST_RequestHandle *con_handle,
545 handle, 560 handle,
546 &namestore_list_finished, 561 &namestore_list_finished,
547 handle); 562 handle);
548} 563 if (NULL == handle->list_it)
549
550
551/**
552 * We're storing a new record; this requires
553 * that no record already exists
554 *
555 * @param cls closure, unused
556 * @param zone_key private key of the zone
557 * @param rec_name name that is being mapped (at most 255 characters long)
558 * @param rd_count number of entries in @a rd array
559 * @param rd array of records with data to store
560 */
561static void
562create_new_record_cont (void *cls,
563 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
564 const char *rec_name,
565 unsigned int rd_count,
566 const struct GNUNET_GNSRECORD_Data *rd)
567{
568 struct RequestHandle *handle = cls;
569
570 handle->add_qe = NULL;
571 if (0 != strcmp (rec_name, handle->label_name))
572 { 564 {
573 GNUNET_break (0); 565 handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_FAILED);
574 GNUNET_SCHEDULER_add_now (&do_error, handle); 566 GNUNET_SCHEDULER_add_now (&do_error, handle);
575 return; 567 return;
576 } 568 }
577
578 if (0 != rd_count)
579 {
580 handle->proc (handle->proc_cls,
581 GNUNET_REST_create_response (NULL),
582 MHD_HTTP_CONFLICT);
583 GNUNET_SCHEDULER_add_now (&cleanup_handle, handle);
584 return;
585 }
586 handle->add_qe = GNUNET_NAMESTORE_records_store (handle->ns_handle,
587 handle->zone_pkey,
588 handle->label_name,
589 GNUNET_REST_NAMESTORE_RD_COUNT,
590 handle->rd,
591 &create_finished,
592 handle);
593} 569}
594 570
571
595/** 572/**
596 * Handle namestore POST request 573 * Handle namestore POST request
597 * 574 *
@@ -606,30 +583,21 @@ namestore_add (struct GNUNET_REST_RequestHandle *con_handle,
606{ 583{
607 struct RequestHandle *handle = cls; 584 struct RequestHandle *handle = cls;
608 struct GNUNET_GNSRECORD_Data *gns_record; 585 struct GNUNET_GNSRECORD_Data *gns_record;
586 struct EgoEntry *ego_entry;
587 char *egoname;
609 json_t *data_js; 588 json_t *data_js;
610 json_t *name_json; 589 json_t *name_json;
611 json_error_t err; 590 json_error_t err;
612
613 struct EgoEntry *ego_entry = NULL;
614 struct GNUNET_HashCode key;
615 char *pubkey = NULL;
616 char *name = NULL;
617
618 char term_data[handle->rest_handle->data_size + 1]; 591 char term_data[handle->rest_handle->data_size + 1];
592
619 struct GNUNET_JSON_Specification gnsspec[] = { 593 struct GNUNET_JSON_Specification gnsspec[] = {
620 GNUNET_JSON_spec_gnsrecord_data(&gns_record), 594 GNUNET_JSON_spec_gnsrecord_data(&gns_record),
621 GNUNET_JSON_spec_end () 595 GNUNET_JSON_spec_end ()
622 }; 596 };
623 597
624 if (strlen (GNUNET_REST_API_NS_NAMESTORE) != strlen (handle->url))
625 {
626 handle->emsg = GNUNET_strdup("Wrong URL");
627 GNUNET_SCHEDULER_add_now (&do_error, handle);
628 return;
629 }
630 if (0 >= handle->rest_handle->data_size) 598 if (0 >= handle->rest_handle->data_size)
631 { 599 {
632 handle->emsg = GNUNET_strdup("No data"); 600 handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_NO_DATA);
633 GNUNET_SCHEDULER_add_now (&do_error, handle); 601 GNUNET_SCHEDULER_add_now (&do_error, handle);
634 return; 602 return;
635 } 603 }
@@ -639,7 +607,7 @@ namestore_add (struct GNUNET_REST_RequestHandle *con_handle,
639 data_js = json_loads (term_data, JSON_DECODE_ANY, &err); 607 data_js = json_loads (term_data, JSON_DECODE_ANY, &err);
640 if (GNUNET_OK != GNUNET_JSON_parse (data_js, gnsspec, NULL, NULL)) 608 if (GNUNET_OK != GNUNET_JSON_parse (data_js, gnsspec, NULL, NULL))
641 { 609 {
642 handle->emsg = GNUNET_strdup("Invalid data"); 610 handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_INVALID_DATA);
643 GNUNET_SCHEDULER_add_now (&do_error, handle); 611 GNUNET_SCHEDULER_add_now (&do_error, handle);
644 GNUNET_JSON_parse_free(gnsspec); 612 GNUNET_JSON_parse_free(gnsspec);
645 json_decref (data_js); 613 json_decref (data_js);
@@ -647,109 +615,74 @@ namestore_add (struct GNUNET_REST_RequestHandle *con_handle,
647 } 615 }
648 handle->rd = gns_record; 616 handle->rd = gns_record;
649 617
650 name_json = json_object_get(data_js, "label"); 618 name_json = json_object_get(data_js, "record_name");
651 if (!json_is_string(name_json)) 619 if (!json_is_string(name_json))
652 { 620 {
653 handle->emsg = GNUNET_strdup("Missing name"); 621 handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_INVALID_DATA);
654 GNUNET_SCHEDULER_add_now (&do_error, handle); 622 GNUNET_SCHEDULER_add_now (&do_error, handle);
655 json_decref (data_js); 623 json_decref (data_js);
656 return; 624 return;
657 } 625 }
658 handle->label_name = GNUNET_strdup(json_string_value(name_json)); 626 handle->record_name = GNUNET_strdup(json_string_value(name_json));
659 if(NULL == handle->label_name) 627 if(NULL == handle->record_name)
660 { 628 {
661 handle->emsg = GNUNET_strdup("Missing name"); 629 handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_INVALID_DATA);
662 GNUNET_SCHEDULER_add_now (&do_error, handle); 630 GNUNET_SCHEDULER_add_now (&do_error, handle);
663 json_decref (data_js); 631 json_decref (data_js);
664 return; 632 return;
665 } 633 }
666 if (0 >= strlen(handle->label_name)) 634 if (0 >= strlen(handle->record_name))
667 { 635 {
668 handle->emsg = GNUNET_strdup("Missing name"); 636 handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_INVALID_DATA);
669 GNUNET_SCHEDULER_add_now (&do_error, handle); 637 GNUNET_SCHEDULER_add_now (&do_error, handle);
670 json_decref (data_js); 638 json_decref (data_js);
671 return; 639 return;
672 } 640 }
673 json_decref (data_js); 641 json_decref (data_js);
674 642
675 //change zone if pubkey or name specified 643 egoname = NULL;
676 GNUNET_CRYPTO_hash (GNUNET_REST_API_PARAM_PUBKEY, 644 ego_entry = NULL;
677 strlen (GNUNET_REST_API_PARAM_PUBKEY),
678 &key);
679 if ( GNUNET_YES
680 == GNUNET_CONTAINER_multihashmap_contains (con_handle->url_param_map,
681 &key))
682 {
683 pubkey = GNUNET_CONTAINER_multihashmap_get (con_handle->url_param_map,
684 &key);
685 }
686 GNUNET_CRYPTO_hash (GNUNET_REST_API_PARAM_NAME,
687 strlen (GNUNET_REST_API_PARAM_NAME),
688 &key);
689 if ( GNUNET_YES
690 == GNUNET_CONTAINER_multihashmap_contains (con_handle->url_param_map,
691 &key))
692 {
693 name = GNUNET_CONTAINER_multihashmap_get (con_handle->url_param_map,
694 &key);
695 }
696 645
697 ego_entry = get_egoentry(handle,pubkey,name); 646 //set zone to name if given
698 if (NULL == ego_entry) 647 if (strlen (GNUNET_REST_API_NS_NAMESTORE) < strlen (handle->url))
699 { 648 {
700 if (NULL != pubkey || NULL != name) 649 egoname = &handle->url[strlen (GNUNET_REST_API_NS_NAMESTORE)+1];
650 ego_entry = get_egoentry_namestore(handle, egoname);
651
652 if (NULL == ego_entry)
701 { 653 {
702 handle->emsg = GNUNET_strdup("Invalid identity");
703 handle->response_code = MHD_HTTP_NOT_FOUND; 654 handle->response_code = MHD_HTTP_NOT_FOUND;
655 handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_NOT_FOUND);
704 GNUNET_SCHEDULER_add_now (&do_error, handle); 656 GNUNET_SCHEDULER_add_now (&do_error, handle);
705 return; 657 return;
706 } 658 }
707 } 659 }
708 if ( NULL != ego_entry ) 660 if (NULL != ego_entry)
709 { 661 {
710 handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key(ego_entry->ego); 662 handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key(ego_entry->ego);
711 } 663 }
712 if (NULL == handle->zone_pkey) 664 if (NULL == handle->zone_pkey)
713 { 665 {
714 handle->emsg = GNUNET_strdup("No default identity for namestore"); 666 handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_NO_DEFAULT_ZONE);
715 GNUNET_SCHEDULER_add_now (&do_error, handle); 667 GNUNET_SCHEDULER_add_now (&do_error, handle);
716 return; 668 return;
717 } 669 }
718 handle->add_qe = GNUNET_NAMESTORE_records_lookup (handle->ns_handle, 670 handle->add_qe = GNUNET_NAMESTORE_records_store (handle->ns_handle,
719 handle->zone_pkey, 671 handle->zone_pkey,
720 handle->label_name, 672 handle->record_name,
721 &do_error, 673 1,
722 handle, 674 handle->rd,
723 &create_new_record_cont, 675 &create_finished,
724 handle); 676 handle);
725} 677 if (NULL == handle->add_qe)
726
727
728static void
729del_cont (void *cls,
730 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
731 const char *label,
732 unsigned int rd_count,
733 const struct GNUNET_GNSRECORD_Data *rd)
734{
735 struct RequestHandle *handle = cls;
736
737 handle->add_qe = NULL;
738 if (0 == rd_count)
739 { 678 {
740 handle->emsg = GNUNET_strdup("Record not found"); 679 handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_FAILED);
741 GNUNET_SCHEDULER_add_now (&do_error, handle); 680 GNUNET_SCHEDULER_add_now (&do_error, handle);
742 return; 681 return;
743 } 682 }
744
745 handle->add_qe = GNUNET_NAMESTORE_records_store (handle->ns_handle,
746 handle->zone_pkey,
747 handle->label_name,
748 0, NULL,
749 &del_finished,
750 handle);
751} 683}
752 684
685
753/** 686/**
754 * Handle namestore DELETE request 687 * Handle namestore DELETE request
755 * 688 *
@@ -764,39 +697,22 @@ namestore_delete (struct GNUNET_REST_RequestHandle *con_handle,
764{ 697{
765 struct RequestHandle *handle = cls; 698 struct RequestHandle *handle = cls;
766 struct GNUNET_HashCode key; 699 struct GNUNET_HashCode key;
767 struct EgoEntry *ego_entry = NULL; 700 struct EgoEntry *ego_entry;
768 char *pubkey = NULL; 701 char *egoname;
769 char *name = NULL; 702
770 703 egoname = NULL;
771 //change zone if pubkey or name specified 704 ego_entry = NULL;
772 GNUNET_CRYPTO_hash (GNUNET_REST_API_PARAM_PUBKEY,
773 strlen (GNUNET_REST_API_PARAM_PUBKEY),
774 &key);
775 if ( GNUNET_YES
776 == GNUNET_CONTAINER_multihashmap_contains (con_handle->url_param_map,
777 &key))
778 {
779 pubkey = GNUNET_CONTAINER_multihashmap_get (con_handle->url_param_map,
780 &key);
781 }
782 GNUNET_CRYPTO_hash (GNUNET_REST_API_PARAM_NAME,
783 strlen (GNUNET_REST_API_PARAM_NAME),
784 &key);
785 if ( GNUNET_YES
786 == GNUNET_CONTAINER_multihashmap_contains (con_handle->url_param_map,
787 &key))
788 {
789 name = GNUNET_CONTAINER_multihashmap_get (con_handle->url_param_map,
790 &key);
791 }
792 705
793 ego_entry = get_egoentry(handle,pubkey,name); 706 //set zone to name if given
794 if (NULL == ego_entry) 707 if (strlen (GNUNET_REST_API_NS_NAMESTORE) < strlen (handle->url))
795 { 708 {
796 if (NULL != pubkey || NULL != name) 709 egoname = &handle->url[strlen (GNUNET_REST_API_NS_NAMESTORE)+1];
710 ego_entry = get_egoentry_namestore(handle, egoname);
711
712 if (NULL == ego_entry)
797 { 713 {
798 handle->emsg = GNUNET_strdup("Invalid identity");
799 handle->response_code = MHD_HTTP_NOT_FOUND; 714 handle->response_code = MHD_HTTP_NOT_FOUND;
715 handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_NOT_FOUND);
800 GNUNET_SCHEDULER_add_now (&do_error, handle); 716 GNUNET_SCHEDULER_add_now (&do_error, handle);
801 return; 717 return;
802 } 718 }
@@ -806,33 +722,38 @@ namestore_delete (struct GNUNET_REST_RequestHandle *con_handle,
806 handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key(ego_entry->ego); 722 handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key(ego_entry->ego);
807 } 723 }
808 724
809 GNUNET_CRYPTO_hash ("label", strlen ("label"), &key); 725 GNUNET_CRYPTO_hash ("record_name", strlen ("record_name"), &key);
810 if ( GNUNET_NO 726 if ( GNUNET_NO
811 == GNUNET_CONTAINER_multihashmap_contains (con_handle->url_param_map, 727 == GNUNET_CONTAINER_multihashmap_contains (con_handle->url_param_map,
812 &key)) 728 &key))
813 { 729 {
814 handle->emsg = GNUNET_strdup("Missing name"); 730 handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_INVALID_DATA);
815 GNUNET_SCHEDULER_add_now (&do_error, handle); 731 GNUNET_SCHEDULER_add_now (&do_error, handle);
816 return; 732 return;
817 } 733 }
818 handle->label_name = GNUNET_strdup( 734 handle->record_name = GNUNET_strdup(
819 GNUNET_CONTAINER_multihashmap_get (con_handle->url_param_map, &key)); 735 GNUNET_CONTAINER_multihashmap_get (con_handle->url_param_map, &key));
820 736
821 if (NULL == handle->zone_pkey) 737 if (NULL == handle->zone_pkey)
822 { 738 {
823 handle->emsg = GNUNET_strdup("No default identity for namestore"); 739 handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_NO_DEFAULT_ZONE);
824 GNUNET_SCHEDULER_add_now (&do_error, handle); 740 GNUNET_SCHEDULER_add_now (&do_error, handle);
825 return; 741 return;
826 } 742 }
827 743
828 handle->add_qe = GNUNET_NAMESTORE_records_lookup (handle->ns_handle, 744 handle->add_qe = GNUNET_NAMESTORE_records_store (handle->ns_handle,
829 handle->zone_pkey, 745 handle->zone_pkey,
830 handle->label_name, 746 handle->record_name,
831 &do_error, 747 0,
832 handle, 748 NULL,
833 &del_cont, 749 &del_finished,
834 handle); 750 handle);
835 751 if (NULL == handle->add_qe)
752 {
753 handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_FAILED);
754 GNUNET_SCHEDULER_add_now (&do_error, handle);
755 return;
756 }
836} 757}
837 758
838 759
@@ -916,7 +837,35 @@ default_ego_cb (void *cls,
916 837
917 838
918/** 839/**
919 * Connect to identity callback 840 * This function is initially called for all egos and then again
841 * whenever a ego's identifier changes or if it is deleted. At the
842 * end of the initial pass over all egos, the function is once called
843 * with 'NULL' for 'ego'. That does NOT mean that the callback won't
844 * be invoked in the future or that there was an error.
845 *
846 * When used with 'GNUNET_IDENTITY_create' or 'GNUNET_IDENTITY_get',
847 * this function is only called ONCE, and 'NULL' being passed in
848 * 'ego' does indicate an error (i.e. name is taken or no default
849 * value is known). If 'ego' is non-NULL and if '*ctx'
850 * is set in those callbacks, the value WILL be passed to a subsequent
851 * call to the identity callback of 'GNUNET_IDENTITY_connect' (if
852 * that one was not NULL).
853 *
854 * When an identity is renamed, this function is called with the
855 * (known) ego but the NEW identifier.
856 *
857 * When an identity is deleted, this function is called with the
858 * (known) ego and "NULL" for the 'identifier'. In this case,
859 * the 'ego' is henceforth invalid (and the 'ctx' should also be
860 * cleaned up).
861 *
862 * @param cls closure
863 * @param ego ego handle
864 * @param ctx context for application to store data for this ego
865 * (during the lifetime of this process, initially NULL)
866 * @param name identifier assigned by the user for this ego,
867 * NULL if the user just deleted the ego and it
868 * must thus no longer be used
920 */ 869 */
921static void 870static void
922id_connect_cb (void *cls, 871id_connect_cb (void *cls,
@@ -931,7 +880,7 @@ id_connect_cb (void *cls,
931 if ((NULL == ego) && (NULL == handle->zone_pkey)) 880 if ((NULL == ego) && (NULL == handle->zone_pkey))
932 { 881 {
933 handle->op = GNUNET_IDENTITY_get (handle->identity_handle, 882 handle->op = GNUNET_IDENTITY_get (handle->identity_handle,
934 GNUNET_REST_SUBSYSTEM_NAMESTORE, 883 "namestore",
935 &default_ego_cb, 884 &default_ego_cb,
936 handle); 885 handle);
937 } 886 }
diff --git a/src/namestore/test_plugin_rest_namestore.sh b/src/namestore/test_plugin_rest_namestore.sh
index de02dfafc..532c7caae 100755
--- a/src/namestore/test_plugin_rest_namestore.sh
+++ b/src/namestore/test_plugin_rest_namestore.sh
@@ -11,7 +11,7 @@ curl_get () {
11 #$1 is link 11 #$1 is link
12 #$2 is grep 12 #$2 is grep
13 cache="$(curl -v "$1" 2>&1 | grep "$2")" 13 cache="$(curl -v "$1" 2>&1 | grep "$2")"
14 #echo $cache 14 echo $cache
15 if [ "" == "$cache" ] 15 if [ "" == "$cache" ]
16 then 16 then
17 exit 1 17 exit 1
@@ -23,7 +23,7 @@ curl_post () {
23 #$2 is data 23 #$2 is data
24 #$3 is grep 24 #$3 is grep
25 cache="$(curl -v -X "POST" "$1" --data "$2" 2>&1 | grep "$3")" 25 cache="$(curl -v -X "POST" "$1" --data "$2" 2>&1 | grep "$3")"
26 #echo $cache 26 echo $cache
27 if [ "" == "$cache" ] 27 if [ "" == "$cache" ]
28 then 28 then
29 exit 1 29 exit 1
@@ -34,7 +34,7 @@ curl_delete () {
34 #$1 is link 34 #$1 is link
35 #$2 is grep 35 #$2 is grep
36 cache="$(curl -v -X "DELETE" "$1" 2>&1 | grep "$2")" 36 cache="$(curl -v -X "DELETE" "$1" 2>&1 | grep "$2")"
37 #echo $cache 37 echo $cache
38 if [ "" == "$cache" ] 38 if [ "" == "$cache" ]
39 then 39 then
40 exit 1 40 exit 1
@@ -64,141 +64,80 @@ public="$(gnunet-identity -d | grep "test_plugin_rest_namestore" | awk 'NR==1{pr
64if [ "" == "$test" ] 64if [ "" == "$test" ]
65then 65then
66 #if no entries for test_plugin_rest_namestore 66 #if no entries for test_plugin_rest_namestore
67 curl_get "${namestore_link}?name=$name" "error" 67 curl_get "${namestore_link}/$name" "error"
68 curl_get "${namestore_link}?name=" "error" 68 curl_get "${namestore_link}/" "error"
69 curl_get "${namestore_link}?name=$public" "error" 69 curl_get "${namestore_link}/$public" "error"
70
71 curl_get "${namestore_link}?pubkey=$public" "error"
72 curl_get "${namestore_link}?pubkey=$name" "error"
73 curl_get "${namestore_link}?pubkey=" "error"
74else 70else
75 #if entries exists (that should not be possible) 71 #if entries exists (that should not be possible)
76 curl_get "${namestore_link}" "HTTP/1.1 200 OK" 72 curl_get "${namestore_link}" "HTTP/1.1 200 OK"
77 curl_get "${namestore_link}?name=$name" "HTTP/1.1 200 OK" 73 curl_get "${namestore_link}/$name" "HTTP/1.1 200 OK"
78 curl_get "${namestore_link}?name=" "error" 74 curl_get "${namestore_link}/" "error"
79 curl_get "${namestore_link}?name=$public" "error" 75 curl_get "${namestore_link}/$public" "error"
80
81 curl_get "${namestore_link}?pubkey=$public" "HTTP/1.1 200 OK"
82 curl_get "${namestore_link}?pubkey=$name" "error"
83 curl_get "${namestore_link}?pubkey=" "error"
84fi 76fi
85gnunet-namestore -z $name -p -a -n "test_entry" -e "1d" -V "HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG" -t "PKEY" 77gnunet-namestore -z $name -p -a -n "test_entry" -e "1d" -V "HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG" -t "PKEY"
86curl_get "${namestore_link}" "HTTP/1.1 200 OK" 78curl_get "${namestore_link}" "HTTP/1.1 200 OK"
87curl_get "${namestore_link}?name=$name" "HTTP/1.1 200 OK" 79curl_get "${namestore_link}/$name" "HTTP/1.1 200 OK"
88curl_get "${namestore_link}?name=" "error" 80curl_get "${namestore_link}/" "error"
89curl_get "${namestore_link}?name=$public" "error" 81curl_get "${namestore_link}/$public" "error"
90curl_get "${namestore_link}?pubkey=$public" "HTTP/1.1 200 OK"
91curl_get "${namestore_link}?pubkey=$name" "error"
92curl_get "${namestore_link}?pubkey=" "error"
93gnunet-namestore -z $name -d -n "test_entry" 82gnunet-namestore -z $name -d -n "test_entry"
94 83
95#Test POST with NAME 84#Test POST with NAME
96curl_post "${namestore_link}?name=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":0,"label":"test_entry"}' "HTTP/1.1 204 No Content" 85curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":0,"record_name":"test_entry"}' "HTTP/1.1 204 No Content"
97gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 86gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
98#value 87#value
99curl_post "${namestore_link}?name=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRGxxx", "type":"PKEY", "expiration_time":"1d","flag":0,"label":"test_entry"}' "error" 88curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRGxxx", "record_type":"PKEY", "expiration_time":"1d","flag":0,"record_name":"test_entry"}' "error"
100gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 89gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
101curl_post "${namestore_link}?name=$name" '{"value":"", "type":"PKEY", "expiration_time":"1d","flag":0,"label":"test_entry"}' "error" 90curl_post "${namestore_link}/$name" '{"value":"", "record_type":"PKEY", "expiration_time":"1d","flag":0,"record_name":"test_entry"}' "error"
102gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 91gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
103curl_post "${namestore_link}?name=$name" '{"value_missing":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRGxxx", "type":"PKEY", "expiration_time":"1d","flag":0,"label":"test_entry"}' "error" 92curl_post "${namestore_link}/$name" '{"value_missing":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRGxxx", "record_type":"PKEY", "expiration_time":"1d","flag":0,"record_name":"test_entry"}' "error"
104gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 93gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
105#time 94#time
106curl_post "${namestore_link}?name=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"0d","flag":0,"label":"test_entry"}' "HTTP/1.1 204" 95curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"0d","flag":0,"record_name":"test_entry"}' "HTTP/1.1 204"
107gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 96gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
108curl_post "${namestore_link}?name=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"10000d","flag":0,"label":"test_entry"}' "HTTP/1.1 204" 97curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"10000d","flag":0,"record_name":"test_entry"}' "HTTP/1.1 204"
109gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 98gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
110curl_post "${namestore_link}?name=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"now","flag":0,"label":"test_entry"}' "error" 99curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"now","flag":0,"record_name":"test_entry"}' "error"
111gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 100gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
112curl_post "${namestore_link}?name=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"","flag":0,"label":"test_entry"}' "error" 101curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"","flag":0,"record_name":"test_entry"}' "error"
113gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 102gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
114curl_post "${namestore_link}?name=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time_missing":"1d","flag":0,"label":"test_entry"}' "error" 103curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time_missing":"1d","flag":0,"record_name":"test_entry"}' "error"
115gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 104gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
116#flag 105#flag
117curl_post "${namestore_link}?name=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":0,"label":"test_entry"}' "HTTP/1.1 204 No Content" 106curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":0,"record_name":"test_entry"}' "HTTP/1.1 204 No Content"
118gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 107gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
119curl_post "${namestore_link}?name=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":2,"label":"test_entry"}' "HTTP/1.1 204 No Content" 108curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":2,"record_name":"test_entry"}' "HTTP/1.1 204 No Content"
120gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 109gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
121curl_post "${namestore_link}?name=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":8,"label":"test_entry"}' "HTTP/1.1 204 No Content" 110curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":8,"record_name":"test_entry"}' "HTTP/1.1 204 No Content"
122gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 111gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
123curl_post "${namestore_link}?name=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":16,"label":"test_entry"}' "HTTP/1.1 204 No Content" 112curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":16,"record_name":"test_entry"}' "HTTP/1.1 204 No Content"
124gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 113gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
125curl_post "${namestore_link}?name=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":-1,"label":"test_entry"}' "error" 114curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":-1,"record_name":"test_entry"}' "error"
126gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 115gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
127curl_post "${namestore_link}?name=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":"Test","label":"test_entry"}' "error" 116curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":"Test","record_name":"test_entry"}' "error"
128gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 117gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
129curl_post "${namestore_link}?name=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":,"label":"test_entry"}' "error" 118curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":,"record_name":"test_entry"}' "error"
130gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 119gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
131curl_post "${namestore_link}?name=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag_missing":0,"label":"test_entry"}' "error" 120curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag_missing":0,"record_name":"test_entry"}' "error"
132gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 121gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
133#label 122#record_name
134curl_post "${namestore_link}?name=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":0,"label":"test_entry"}' "HTTP/1.1 204 No Content" 123curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":0,"record_name":"test_entry"}' "HTTP/1.1 204 No Content"
135curl_post "${namestore_link}?name=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":0,"label":"test_entry"}' "HTTP/1.1 409" 124curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":0,"record_name":"test_entry"}' "HTTP/1.1 204 No Content"
136gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 125gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
137curl_post "${namestore_link}?name=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":0,"label":""}' "error" 126curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":0,"record_name":""}' "error"
138gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 127gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
139curl_post "${namestore_link}?name=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":0,"label_missing":"test_entry"}' "error" 128curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":0,"record_name_missing":"test_entry"}' "error"
140gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
141
142#Test POST with PUBKEY
143curl_post "${namestore_link}?pubkey=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":0,"label":"test_entry"}' "HTTP/1.1 204 No Content"
144gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
145#value
146curl_post "${namestore_link}?pubkey=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRGxxx", "type":"PKEY", "expiration_time":"1d","flag":0,"label":"test_entry"}' "error"
147gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
148curl_post "${namestore_link}?pubkey=$public" '{"value":"", "type":"PKEY", "expiration_time":"1d","flag":0,"label":"test_entry"}' "error"
149gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
150curl_post "${namestore_link}?pubkey=$public" '{"value_missing":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRGxxx", "type":"PKEY", "expiration_time":"1d","flag":0,"label":"test_entry"}' "error"
151gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
152#time
153curl_post "${namestore_link}?pubkey=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"0d","flag":0,"label":"test_entry"}' "HTTP/1.1 204"
154gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
155curl_post "${namestore_link}?pubkey=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"10000d","flag":0,"label":"test_entry"}' "HTTP/1.1 204"
156gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
157curl_post "${namestore_link}?pubkey=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"now","flag":0,"label":"test_entry"}' "error"
158gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
159curl_post "${namestore_link}?pubkey=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"","flag":0,"label":"test_entry"}' "error"
160gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
161curl_post "${namestore_link}?pubkey=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time_missing":"1d","flag":0,"label":"test_entry"}' "error"
162gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
163#flag
164curl_post "${namestore_link}?pubkey=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":0,"label":"test_entry"}' "HTTP/1.1 204 No Content"
165gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
166curl_post "${namestore_link}?pubkey=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":2,"label":"test_entry"}' "HTTP/1.1 204 No Content"
167gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
168curl_post "${namestore_link}?pubkey=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":8,"label":"test_entry"}' "HTTP/1.1 204 No Content"
169gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
170curl_post "${namestore_link}?pubkey=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":16,"label":"test_entry"}' "HTTP/1.1 204 No Content"
171gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
172curl_post "${namestore_link}?pubkey=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":-1,"label":"test_entry"}' "error"
173gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
174curl_post "${namestore_link}?pubkey=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":"Test","label":"test_entry"}' "error"
175gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
176curl_post "${namestore_link}?pubkey=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":,"label":"test_entry"}' "error"
177gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
178curl_post "${namestore_link}?pubkey=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag_missing":0,"label":"test_entry"}' "error"
179gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
180#label
181curl_post "${namestore_link}?pubkey=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":0,"label":"test_entry"}' "HTTP/1.1 204 No Content"
182curl_post "${namestore_link}?pubkey=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":0,"label":"test_entry"}' "HTTP/1.1 409"
183gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
184curl_post "${namestore_link}?pubkey=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":0,"label":""}' "error"
185gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
186curl_post "${namestore_link}?pubkey=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":0,"label_missing":"test_entry"}' "error"
187gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 129gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
188 130
189#wrong zone 131#wrong zone
190curl_post "${namestore_link}?name=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":0,"label":"test_entry"}' "error" 132curl_post "${namestore_link}/$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":0,"record_name":"test_entry"}' "error"
191gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
192curl_post "${namestore_link}?pubkey=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":0,"label":"test_entry"}' "error"
193gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 133gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
194 134
195#Test DELETE 135#Test DELETE
196gnunet-namestore -z $name -p -a -n "test_entry" -e "1d" -V "HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG" -t "PKEY" 136gnunet-namestore -z $name -p -a -n "test_entry" -e "1d" -V "HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG" -t "PKEY"
197curl_delete "${namestore_link}?label=test_entry&name=$name" "HTTP/1.1 204" 137curl_delete "${namestore_link}/$name?record_name=test_entry" "HTTP/1.1 204"
198gnunet-namestore -z $name -p -a -n "test_entry" -e "1d" -V "HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG" -t "PKEY" 138curl_delete "${namestore_link}/$name?record_name=test_entry" "error"
199curl_delete "${namestore_link}?label=test_entry&pubkey=$public" "HTTP/1.1 204"
200gnunet-namestore -z $name -p -a -n "test_entry" -e "1d" -V "HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG" -t "PKEY" 139gnunet-namestore -z $name -p -a -n "test_entry" -e "1d" -V "HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG" -t "PKEY"
201curl_delete "${namestore_link}?label=test_entry&pubkey=$name" "HTTP/1.1 404" 140curl_delete "${namestore_link}/$public?record_name=test_entry" "error"
202 141
203 142
204#Test default identity 143#Test default identity
diff --git a/src/peerinfo/plugin_rest_peerinfo.c b/src/peerinfo/plugin_rest_peerinfo.c
index 97c473e36..e34bde9f5 100644
--- a/src/peerinfo/plugin_rest_peerinfo.c
+++ b/src/peerinfo/plugin_rest_peerinfo.c
@@ -31,13 +31,30 @@
31#include "microhttpd.h" 31#include "microhttpd.h"
32#include <jansson.h> 32#include <jansson.h>
33 33
34/**
35 * Peerinfo Namespace
36 */
34#define GNUNET_REST_API_NS_PEERINFO "/peerinfo" 37#define GNUNET_REST_API_NS_PEERINFO "/peerinfo"
35 38
36#define GNUNET_REST_API_PEERINFO_PEER "peer" 39/**
37#define GNUNET_REST_API_PEERINFO_FRIEND "friend" 40 * Peerinfo parameter peer
38#define GNUNET_REST_API_PEERINFO_ARRAY "array" 41 */
42#define GNUNET_REST_PEERINFO_PEER "peer"
39 43
40#define GNUNET_REST_ERROR_UNKNOWN "Unkown Error" 44/**
45 * Peerinfo parameter friend
46 */
47#define GNUNET_REST_PEERINFO_FRIEND "friend"
48
49/**
50 * Peerinfo parameter array
51 */
52#define GNUNET_REST_PEERINFO_ARRAY "array"
53
54/**
55 * Error message Unknown Error
56 */
57#define GNUNET_REST_PEERINFO_ERROR_UNKNOWN "Unknown Error"
41 58
42/** 59/**
43 * How long until we time out during address lookup? 60 * How long until we time out during address lookup?
@@ -94,7 +111,6 @@ struct AddressRecord
94 */ 111 */
95struct PrintContext 112struct PrintContext
96{ 113{
97
98 /** 114 /**
99 * Kept in DLL. 115 * Kept in DLL.
100 */ 116 */
@@ -152,6 +168,9 @@ static struct PrintContext *pc_head;
152 */ 168 */
153static struct PrintContext *pc_tail; 169static struct PrintContext *pc_tail;
154 170
171/**
172 * The request handle
173 */
155struct RequestHandle 174struct RequestHandle
156{ 175{
157 /** 176 /**
@@ -299,7 +318,7 @@ do_error (void *cls)
299 char *response; 318 char *response;
300 319
301 if (NULL == handle->emsg) 320 if (NULL == handle->emsg)
302 handle->emsg = GNUNET_strdup(GNUNET_REST_ERROR_UNKNOWN); 321 handle->emsg = GNUNET_strdup(GNUNET_REST_PEERINFO_ERROR_UNKNOWN);
303 322
304 json_object_set_new(json_error,"error", json_string(handle->emsg)); 323 json_object_set_new(json_error,"error", json_string(handle->emsg));
305 324
@@ -315,7 +334,9 @@ do_error (void *cls)
315 334
316 335
317/** 336/**
318 * Function that assembles our response. 337 * Function that assembles the response.
338 *
339 * @param cls the `struct RequestHandle`
319 */ 340 */
320static void 341static void
321peerinfo_list_finished (void *cls) 342peerinfo_list_finished (void *cls)
@@ -326,6 +347,7 @@ peerinfo_list_finished (void *cls)
326 347
327 if (NULL == handle->response) 348 if (NULL == handle->response)
328 { 349 {
350 handle->response_code = MHD_HTTP_NOT_FOUND;
329 handle->emsg = GNUNET_strdup ("No peers found"); 351 handle->emsg = GNUNET_strdup ("No peers found");
330 GNUNET_SCHEDULER_add_now (&do_error, handle); 352 GNUNET_SCHEDULER_add_now (&do_error, handle);
331 return; 353 return;
@@ -386,9 +408,6 @@ dump_pc (struct PrintContext *pc)
386 temp_array = json_array(); 408 temp_array = json_array();
387 response_entry = json_object(); 409 response_entry = json_object();
388 410
389// printf (_("%sPeer `%s'\n"),
390// (GNUNET_YES == pc->friend_only) ? "F2F: " : "",
391// GNUNET_i2s_full (&pc->peer));
392 for (i = 0; i < pc->num_addresses; i++) 411 for (i = 0; i < pc->num_addresses; i++)
393 { 412 {
394 if (NULL != pc->address_list[i].result) 413 if (NULL != pc->address_list[i].result)
@@ -417,10 +436,10 @@ dump_pc (struct PrintContext *pc)
417 GNUNET_i2s_full (&pc->peer)); 436 GNUNET_i2s_full (&pc->peer));
418 friend_and_peer_json = json_string(friend_and_peer); 437 friend_and_peer_json = json_string(friend_and_peer);
419 json_object_set(response_entry, 438 json_object_set(response_entry,
420 GNUNET_REST_API_PEERINFO_PEER, 439 GNUNET_REST_PEERINFO_PEER,
421 friend_and_peer_json); 440 friend_and_peer_json);
422 json_object_set(response_entry, 441 json_object_set(response_entry,
423 GNUNET_REST_API_PEERINFO_ARRAY, 442 GNUNET_REST_PEERINFO_ARRAY,
424 temp_array); 443 temp_array);
425 json_array_append(pc->handle->response, response_entry); 444 json_array_append(pc->handle->response, response_entry);
426 json_decref(friend_and_peer_json); 445 json_decref(friend_and_peer_json);
@@ -615,8 +634,8 @@ peerinfo_get (struct GNUNET_REST_RequestHandle *con_handle,
615 char* include_friend_only_str; 634 char* include_friend_only_str;
616 635
617 include_friend_only = GNUNET_NO; 636 include_friend_only = GNUNET_NO;
618 GNUNET_CRYPTO_hash (GNUNET_REST_API_PEERINFO_FRIEND, 637 GNUNET_CRYPTO_hash (GNUNET_REST_PEERINFO_FRIEND,
619 strlen (GNUNET_REST_API_PEERINFO_FRIEND), 638 strlen (GNUNET_REST_PEERINFO_FRIEND),
620 &key); 639 &key);
621 if ( GNUNET_YES 640 if ( GNUNET_YES
622 == GNUNET_CONTAINER_multihashmap_contains (con_handle->url_param_map, 641 == GNUNET_CONTAINER_multihashmap_contains (con_handle->url_param_map,
@@ -631,15 +650,15 @@ peerinfo_get (struct GNUNET_REST_RequestHandle *con_handle,
631 } 650 }
632 651
633 specific_peer = NULL; 652 specific_peer = NULL;
634 GNUNET_CRYPTO_hash (GNUNET_REST_API_PEERINFO_PEER, 653 GNUNET_CRYPTO_hash (GNUNET_REST_PEERINFO_PEER,
635 strlen (GNUNET_REST_API_PEERINFO_PEER), 654 strlen (GNUNET_REST_PEERINFO_PEER),
636 &key); 655 &key);
637 if ( GNUNET_YES 656 if ( GNUNET_YES
638 == GNUNET_CONTAINER_multihashmap_contains (con_handle->url_param_map, 657 == GNUNET_CONTAINER_multihashmap_contains (con_handle->url_param_map,
639 &key)) 658 &key))
640 { 659 {
641 peer_id = *(unsigned int*)GNUNET_CONTAINER_multihashmap_get (con_handle->url_param_map, &key); 660 //peer_id = *(unsigned int*)GNUNET_CONTAINER_multihashmap_get (con_handle->url_param_map, &key);
642 specific_peer = GNUNET_PEER_resolve2(peer_id); 661 //specific_peer = GNUNET_PEER_resolve2(peer_id);
643 } 662 }
644 663
645 handle->list_it = GNUNET_PEERINFO_iterate(handle->peerinfo_handle, 664 handle->list_it = GNUNET_PEERINFO_iterate(handle->peerinfo_handle,