diff options
Diffstat (limited to 'src/namestore/plugin_rest_namestore.c')
-rw-r--r-- | src/namestore/plugin_rest_namestore.c | 407 |
1 files changed, 178 insertions, 229 deletions
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 | */ | ||
111 | struct RequestHandle | 131 | struct 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 | */ |
320 | struct EgoEntry* | 340 | struct EgoEntry* |
321 | get_egoentry(struct RequestHandle *handle, char* pubkey, char *name) | 341 | get_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 | */ |
353 | static void | 364 | static void |
354 | namestore_iteration_error (void *cls) | 365 | namestore_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 | */ | ||
363 | static void | 381 | static void |
364 | create_finished (void *cls, int32_t success, const char *emsg) | 382 | create_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 | */ | ||
382 | static void | 413 | static void |
383 | del_finished (void *cls, int32_t success, const char *emsg) | 414 | del_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 | */ | ||
561 | static void | ||
562 | create_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 | |||
728 | static void | ||
729 | del_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 | */ |
921 | static void | 870 | static void |
922 | id_connect_cb (void *cls, | 871 | id_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 | } |