aboutsummaryrefslogtreecommitdiff
path: root/src/namestore/gnunet-namestore.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-04-30 11:49:52 +0200
committerChristian Grothoff <christian@grothoff.org>2019-04-30 11:49:52 +0200
commit57636ddf7839aaeedd14c90afcd28b375ec516a6 (patch)
tree4c05a7baf23c1c872fdf6da785f4209ade1c55e9 /src/namestore/gnunet-namestore.c
parent2c44a892573bd25e26d12f548775cfdd3a6d9428 (diff)
downloadgnunet-57636ddf7839aaeedd14c90afcd28b375ec516a6.tar.gz
gnunet-57636ddf7839aaeedd14c90afcd28b375ec516a6.zip
implement filtering by record type in gnunet-namestore
Diffstat (limited to 'src/namestore/gnunet-namestore.c')
-rw-r--r--src/namestore/gnunet-namestore.c723
1 files changed, 331 insertions, 392 deletions
diff --git a/src/namestore/gnunet-namestore.c b/src/namestore/gnunet-namestore.c
index 34bbf0111..916f994b7 100644
--- a/src/namestore/gnunet-namestore.c
+++ b/src/namestore/gnunet-namestore.c
@@ -11,7 +11,7 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
@@ -48,7 +48,6 @@ struct RecordSetEntry
48 * The record to add/remove. 48 * The record to add/remove.
49 */ 49 */
50 struct GNUNET_GNSRECORD_Data record; 50 struct GNUNET_GNSRECORD_Data record;
51
52}; 51};
53 52
54 53
@@ -307,12 +306,8 @@ do_shutdown (void *cls)
307static void 306static void
308test_finished () 307test_finished ()
309{ 308{
310 if ( (NULL == add_qe) && 309 if ((NULL == add_qe) && (NULL == add_qe_uri) && (NULL == get_qe) &&
311 (NULL == add_qe_uri) && 310 (NULL == del_qe) && (NULL == reverse_qe) && (NULL == list_it))
312 (NULL == get_qe) &&
313 (NULL == del_qe) &&
314 (NULL == reverse_qe) &&
315 (NULL == list_it) )
316 GNUNET_SCHEDULER_shutdown (); 311 GNUNET_SCHEDULER_shutdown ();
317} 312}
318 313
@@ -328,9 +323,7 @@ test_finished ()
328 * @param emsg NULL on success, otherwise an error message 323 * @param emsg NULL on success, otherwise an error message
329 */ 324 */
330static void 325static void
331add_continuation (void *cls, 326add_continuation (void *cls, int32_t success, const char *emsg)
332 int32_t success,
333 const char *emsg)
334{ 327{
335 struct GNUNET_NAMESTORE_QueueEntry **qe = cls; 328 struct GNUNET_NAMESTORE_QueueEntry **qe = cls;
336 329
@@ -338,8 +331,8 @@ add_continuation (void *cls,
338 if (GNUNET_YES != success) 331 if (GNUNET_YES != success)
339 { 332 {
340 fprintf (stderr, 333 fprintf (stderr,
341 _("Adding record failed: %s\n"), 334 _ ("Adding record failed: %s\n"),
342 (GNUNET_NO == success) ? "record exists" : emsg); 335 (GNUNET_NO == success) ? "record exists" : emsg);
343 if (GNUNET_NO != success) 336 if (GNUNET_NO != success)
344 ret = 1; 337 ret = 1;
345 } 338 }
@@ -359,23 +352,21 @@ add_continuation (void *cls,
359 * @param emsg NULL on success, otherwise an error message 352 * @param emsg NULL on success, otherwise an error message
360 */ 353 */
361static void 354static void
362del_continuation (void *cls, 355del_continuation (void *cls, int32_t success, const char *emsg)
363 int32_t success,
364 const char *emsg)
365{ 356{
366 (void) cls; 357 (void) cls;
367 del_qe = NULL; 358 del_qe = NULL;
368 if (GNUNET_NO == success) 359 if (GNUNET_NO == success)
369 { 360 {
370 fprintf (stderr, 361 fprintf (stderr,
371 _("Deleting record failed, record does not exist%s%s\n"), 362 _ ("Deleting record failed, record does not exist%s%s\n"),
372 (NULL != emsg) ? ": " : "", 363 (NULL != emsg) ? ": " : "",
373 (NULL != emsg) ? emsg : ""); 364 (NULL != emsg) ? emsg : "");
374 } 365 }
375 if (GNUNET_SYSERR == success) 366 if (GNUNET_SYSERR == success)
376 { 367 {
377 fprintf (stderr, 368 fprintf (stderr,
378 _("Deleting record failed%s%s\n"), 369 _ ("Deleting record failed%s%s\n"),
379 (NULL != emsg) ? ": " : "", 370 (NULL != emsg) ? ": " : "",
380 (NULL != emsg) ? emsg : ""); 371 (NULL != emsg) ? emsg : "");
381 } 372 }
@@ -403,8 +394,7 @@ zone_iteration_error_cb (void *cls)
403{ 394{
404 (void) cls; 395 (void) cls;
405 list_it = NULL; 396 list_it = NULL;
406 fprintf (stderr, 397 fprintf (stderr, "Error iterating over zone\n");
407 "Error iterating over zone\n");
408 ret = 1; 398 ret = 1;
409 test_finished (); 399 test_finished ();
410} 400}
@@ -419,40 +409,41 @@ zone_iteration_error_cb (void *cls)
419 */ 409 */
420static void 410static void
421display_record (const char *rname, 411display_record (const char *rname,
422 unsigned int rd_len, 412 unsigned int rd_len,
423 const struct GNUNET_GNSRECORD_Data *rd) 413 const struct GNUNET_GNSRECORD_Data *rd)
424{ 414{
425 const char *typestring; 415 const char *typestr;
426 char *s; 416 char *s;
427 const char *ets; 417 const char *ets;
428 struct GNUNET_TIME_Absolute at; 418 struct GNUNET_TIME_Absolute at;
429 struct GNUNET_TIME_Relative rt; 419 struct GNUNET_TIME_Relative rt;
430 420
431 if ( (NULL != name) && 421 if ((NULL != name) && (0 != strcmp (name, rname)))
432 (0 != strcmp (name, rname)) )
433 { 422 {
434 GNUNET_NAMESTORE_zone_iterator_next (list_it, 423 GNUNET_NAMESTORE_zone_iterator_next (list_it, 1);
435 1);
436 return; 424 return;
437 } 425 }
438 FPRINTF (stdout, 426 FPRINTF (stdout, "%s:\n", rname);
439 "%s:\n", 427 if (NULL != typestring)
440 rname); 428 type = GNUNET_GNSRECORD_typename_to_number (typestring);
441 for (unsigned int i=0;i<rd_len;i++) 429 else
430 type = GNUNET_GNSRECORD_TYPE_ANY;
431 for (unsigned int i = 0; i < rd_len; i++)
442 { 432 {
443 if ( (GNUNET_GNSRECORD_TYPE_NICK == rd[i].record_type) && 433 if ((GNUNET_GNSRECORD_TYPE_NICK == rd[i].record_type) &&
444 (0 != strcmp (rname, 434 (0 != strcmp (rname, GNUNET_GNS_EMPTY_LABEL_AT)))
445 GNUNET_GNS_EMPTY_LABEL_AT)) ) 435 continue;
436 if ((type != rd[i].record_type) && (GNUNET_GNSRECORD_TYPE_ANY != type))
446 continue; 437 continue;
447 typestring = GNUNET_GNSRECORD_number_to_typename (rd[i].record_type); 438 typestr = GNUNET_GNSRECORD_number_to_typename (rd[i].record_type);
448 s = GNUNET_GNSRECORD_value_to_string (rd[i].record_type, 439 s = GNUNET_GNSRECORD_value_to_string (rd[i].record_type,
449 rd[i].data, 440 rd[i].data,
450 rd[i].data_size); 441 rd[i].data_size);
451 if (NULL == s) 442 if (NULL == s)
452 { 443 {
453 FPRINTF (stdout, 444 FPRINTF (stdout,
454 _("\tCorrupt or unsupported record of type %u\n"), 445 _ ("\tCorrupt or unsupported record of type %u\n"),
455 (unsigned int) rd[i].record_type); 446 (unsigned int) rd[i].record_type);
456 continue; 447 continue;
457 } 448 }
458 if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION)) 449 if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION))
@@ -466,12 +457,14 @@ display_record (const char *rname,
466 ets = GNUNET_STRINGS_absolute_time_to_string (at); 457 ets = GNUNET_STRINGS_absolute_time_to_string (at);
467 } 458 }
468 FPRINTF (stdout, 459 FPRINTF (stdout,
469 "\t%s: %s (%s)\t%s\t%s\n", 460 "\t%s: %s (%s)\t%s\t%s\n",
470 typestring, 461 typestr,
471 s, 462 s,
472 ets, 463 ets,
473 (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_PRIVATE)) ? "PRIVATE" : "PUBLIC", 464 (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_PRIVATE)) ? "PRIVATE"
474 (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_SHADOW_RECORD)) ? "SHADOW" : ""); 465 : "PUBLIC",
466 (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_SHADOW_RECORD)) ? "SHADOW"
467 : "");
475 GNUNET_free (s); 468 GNUNET_free (s);
476 } 469 }
477 FPRINTF (stdout, "%s", "\n"); 470 FPRINTF (stdout, "%s", "\n");
@@ -496,11 +489,8 @@ display_record_iterator (void *cls,
496{ 489{
497 (void) cls; 490 (void) cls;
498 (void) zone_key; 491 (void) zone_key;
499 display_record (rname, 492 display_record (rname, rd_len, rd);
500 rd_len, 493 GNUNET_NAMESTORE_zone_iterator_next (list_it, 1);
501 rd);
502 GNUNET_NAMESTORE_zone_iterator_next (list_it,
503 1);
504} 494}
505 495
506 496
@@ -522,11 +512,8 @@ display_record_monitor (void *cls,
522{ 512{
523 (void) cls; 513 (void) cls;
524 (void) zone_key; 514 (void) zone_key;
525 display_record (rname, 515 display_record (rname, rd_len, rd);
526 rd_len, 516 GNUNET_NAMESTORE_zone_monitor_next (zm, 1);
527 rd);
528 GNUNET_NAMESTORE_zone_monitor_next (zm,
529 1);
530} 517}
531 518
532 519
@@ -549,9 +536,7 @@ display_record_lookup (void *cls,
549 (void) cls; 536 (void) cls;
550 (void) zone_key; 537 (void) zone_key;
551 get_qe = NULL; 538 get_qe = NULL;
552 display_record (rname, 539 display_record (rname, rd_len, rd);
553 rd_len,
554 rd);
555 test_finished (); 540 test_finished ();
556} 541}
557 542
@@ -565,9 +550,7 @@ static void
565sync_cb (void *cls) 550sync_cb (void *cls)
566{ 551{
567 (void) cls; 552 (void) cls;
568 FPRINTF (stdout, 553 FPRINTF (stdout, "%s", "Monitor is now in sync.\n");
569 "%s",
570 "Monitor is now in sync.\n");
571} 554}
572 555
573 556
@@ -580,9 +563,7 @@ static void
580monitor_error_cb (void *cls) 563monitor_error_cb (void *cls)
581{ 564{
582 (void) cls; 565 (void) cls;
583 FPRINTF (stderr, 566 FPRINTF (stderr, "%s", "Monitor disconnected and out of sync.\n");
584 "%s",
585 "Monitor disconnected and out of sync.\n");
586} 567}
587 568
588 569
@@ -596,9 +577,7 @@ lookup_error_cb (void *cls)
596{ 577{
597 (void) cls; 578 (void) cls;
598 get_qe = NULL; 579 get_qe = NULL;
599 FPRINTF (stderr, 580 FPRINTF (stderr, "%s", "Failed to lookup record.\n");
600 "%s",
601 "Failed to lookup record.\n");
602 test_finished (); 581 test_finished ();
603} 582}
604 583
@@ -629,10 +608,10 @@ add_error_cb (void *cls)
629 */ 608 */
630static void 609static void
631get_existing_record (void *cls, 610get_existing_record (void *cls,
632 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, 611 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
633 const char *rec_name, 612 const char *rec_name,
634 unsigned int rd_count, 613 unsigned int rd_count,
635 const struct GNUNET_GNSRECORD_Data *rd) 614 const struct GNUNET_GNSRECORD_Data *rd)
636{ 615{
637 struct GNUNET_GNSRECORD_Data rdn[rd_count + 1]; 616 struct GNUNET_GNSRECORD_Data rdn[rd_count + 1];
638 struct GNUNET_GNSRECORD_Data *rde; 617 struct GNUNET_GNSRECORD_Data *rde;
@@ -650,24 +629,29 @@ get_existing_record (void *cls,
650 629
651 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 630 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
652 "Received %u records for name `%s'\n", 631 "Received %u records for name `%s'\n",
653 rd_count, rec_name); 632 rd_count,
654 for (unsigned int i=0;i<rd_count;i++) 633 rec_name);
634 for (unsigned int i = 0; i < rd_count; i++)
655 { 635 {
656 switch (rd[i].record_type) 636 switch (rd[i].record_type)
657 { 637 {
658 case GNUNET_DNSPARSER_TYPE_CNAME: 638 case GNUNET_DNSPARSER_TYPE_CNAME:
659 fprintf (stderr, 639 fprintf (
660 _("A %s record exists already under `%s', no other records can be added.\n"), 640 stderr,
661 "CNAME", 641 _ (
662 rec_name); 642 "A %s record exists already under `%s', no other records can be added.\n"),
643 "CNAME",
644 rec_name);
663 ret = 1; 645 ret = 1;
664 test_finished (); 646 test_finished ();
665 return; 647 return;
666 case GNUNET_GNSRECORD_TYPE_PKEY: 648 case GNUNET_GNSRECORD_TYPE_PKEY:
667 fprintf (stderr, 649 fprintf (
668 _("A %s record exists already under `%s', no other records can be added.\n"), 650 stderr,
669 "PKEY", 651 _ (
670 rec_name); 652 "A %s record exists already under `%s', no other records can be added.\n"),
653 "PKEY",
654 rec_name);
671 ret = 1; 655 ret = 1;
672 test_finished (); 656 test_finished ();
673 return; 657 return;
@@ -679,7 +663,8 @@ get_existing_record (void *cls,
679 if (0 != rd_count) 663 if (0 != rd_count)
680 { 664 {
681 fprintf (stderr, 665 fprintf (stderr,
682 _("Records already exist under `%s', cannot add `%s' record.\n"), 666 _ (
667 "Records already exist under `%s', cannot add `%s' record.\n"),
683 rec_name, 668 rec_name,
684 "CNAME"); 669 "CNAME");
685 ret = 1; 670 ret = 1;
@@ -691,7 +676,8 @@ get_existing_record (void *cls,
691 if (0 != rd_count) 676 if (0 != rd_count)
692 { 677 {
693 fprintf (stderr, 678 fprintf (stderr,
694 _("Records already exist under `%s', cannot add `%s' record.\n"), 679 _ (
680 "Records already exist under `%s', cannot add `%s' record.\n"),
695 rec_name, 681 rec_name,
696 "PKEY"); 682 "PKEY");
697 ret = 1; 683 ret = 1;
@@ -700,24 +686,22 @@ get_existing_record (void *cls,
700 } 686 }
701 break; 687 break;
702 case GNUNET_GNSRECORD_TYPE_GNS2DNS: 688 case GNUNET_GNSRECORD_TYPE_GNS2DNS:
703 for (unsigned int i=0;i<rd_count;i++) 689 for (unsigned int i = 0; i < rd_count; i++)
704 if (GNUNET_GNSRECORD_TYPE_GNS2DNS != rd[i].record_type) 690 if (GNUNET_GNSRECORD_TYPE_GNS2DNS != rd[i].record_type)
705 { 691 {
706 fprintf (stderr, 692 fprintf (
707 _("Non-GNS2DNS records already exist under `%s', cannot add GNS2DNS record.\n"), 693 stderr,
708 rec_name); 694 _ (
695 "Non-GNS2DNS records already exist under `%s', cannot add GNS2DNS record.\n"),
696 rec_name);
709 ret = 1; 697 ret = 1;
710 test_finished (); 698 test_finished ();
711 return; 699 return;
712 } 700 }
713 break; 701 break;
714 } 702 }
715 memset (rdn, 703 memset (rdn, 0, sizeof (struct GNUNET_GNSRECORD_Data));
716 0, 704 GNUNET_memcpy (&rdn[1], rd, rd_count * sizeof (struct GNUNET_GNSRECORD_Data));
717 sizeof (struct GNUNET_GNSRECORD_Data));
718 GNUNET_memcpy (&rdn[1],
719 rd,
720 rd_count * sizeof (struct GNUNET_GNSRECORD_Data));
721 rde = &rdn[0]; 705 rde = &rdn[0];
722 rde->data = data; 706 rde->data = data;
723 rde->data_size = data_size; 707 rde->data_size = data_size;
@@ -733,12 +717,12 @@ get_existing_record (void *cls,
733 rde->expiration_time = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us; 717 rde->expiration_time = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us;
734 GNUNET_assert (NULL != name); 718 GNUNET_assert (NULL != name);
735 add_qe = GNUNET_NAMESTORE_records_store (ns, 719 add_qe = GNUNET_NAMESTORE_records_store (ns,
736 &zone_pkey, 720 &zone_pkey,
737 name, 721 name,
738 rd_count + 1, 722 rd_count + 1,
739 rde, 723 rde,
740 &add_continuation, 724 &add_continuation,
741 &add_qe); 725 &add_qe);
742} 726}
743 727
744 728
@@ -750,9 +734,7 @@ reverse_error_cb (void *cls)
750{ 734{
751 (void) cls; 735 (void) cls;
752 reverse_qe = NULL; 736 reverse_qe = NULL;
753 FPRINTF (stdout, 737 FPRINTF (stdout, "%s.zkey\n", reverse_pkey);
754 "%s.zkey\n",
755 reverse_pkey);
756} 738}
757 739
758 740
@@ -779,14 +761,9 @@ handle_reverse_lookup (void *cls,
779 (void) rd; 761 (void) rd;
780 reverse_qe = NULL; 762 reverse_qe = NULL;
781 if (NULL == label) 763 if (NULL == label)
782 FPRINTF (stdout, 764 FPRINTF (stdout, "%s\n", reverse_pkey);
783 "%s\n",
784 reverse_pkey);
785 else 765 else
786 FPRINTF (stdout, 766 FPRINTF (stdout, "%s.%s\n", label, ego_name);
787 "%s.%s\n",
788 label,
789 ego_name);
790 test_finished (); 767 test_finished ();
791} 768}
792 769
@@ -834,14 +811,14 @@ del_monitor (void *cls,
834 if (0 == rd_count) 811 if (0 == rd_count)
835 { 812 {
836 FPRINTF (stderr, 813 FPRINTF (stderr,
837 _("There are no records under label `%s' that could be deleted.\n"), 814 _ (
815 "There are no records under label `%s' that could be deleted.\n"),
838 label); 816 label);
839 ret = 1; 817 ret = 1;
840 test_finished (); 818 test_finished ();
841 return; 819 return;
842 } 820 }
843 if ( (NULL == value) && 821 if ((NULL == value) && (NULL == typestring))
844 (NULL == typestring) )
845 { 822 {
846 /* delete everything */ 823 /* delete everything */
847 del_qe = GNUNET_NAMESTORE_records_store (ns, 824 del_qe = GNUNET_NAMESTORE_records_store (ns,
@@ -858,25 +835,28 @@ del_monitor (void *cls,
858 type = GNUNET_GNSRECORD_typename_to_number (typestring); 835 type = GNUNET_GNSRECORD_typename_to_number (typestring);
859 else 836 else
860 type = GNUNET_GNSRECORD_TYPE_ANY; 837 type = GNUNET_GNSRECORD_TYPE_ANY;
861 for (unsigned int i=0;i<rd_count;i++) 838 for (unsigned int i = 0; i < rd_count; i++)
862 { 839 {
863 vs = NULL; 840 vs = NULL;
864 if (! ( ( (GNUNET_GNSRECORD_TYPE_ANY == type) || 841 if (! (((GNUNET_GNSRECORD_TYPE_ANY == type) ||
865 (rd[i].record_type == type) ) && 842 (rd[i].record_type == type)) &&
866 ( (NULL == value) || 843 ((NULL == value) ||
867 (NULL == (vs = (GNUNET_GNSRECORD_value_to_string (rd[i].record_type, 844 (NULL ==
868 rd[i].data, 845 (vs = (GNUNET_GNSRECORD_value_to_string (rd[i].record_type,
869 rd[i].data_size)))) || 846 rd[i].data,
870 (0 == strcmp (vs, value)) ) ) ) 847 rd[i].data_size)))) ||
848 (0 == strcmp (vs, value)))))
871 rdx[rd_left++] = rd[i]; 849 rdx[rd_left++] = rd[i];
872 GNUNET_free_non_null (vs); 850 GNUNET_free_non_null (vs);
873 } 851 }
874 if (rd_count == rd_left) 852 if (rd_count == rd_left)
875 { 853 {
876 /* nothing got deleted */ 854 /* nothing got deleted */
877 FPRINTF (stderr, 855 FPRINTF (
878 _("There are no records under label `%s' that match the request for deletion.\n"), 856 stderr,
879 label); 857 _ (
858 "There are no records under label `%s' that match the request for deletion.\n"),
859 label);
880 test_finished (); 860 test_finished ();
881 return; 861 return;
882 } 862 }
@@ -901,40 +881,36 @@ del_monitor (void *cls,
901 */ 881 */
902static int 882static int
903parse_expiration (const char *expirationstring, 883parse_expiration (const char *expirationstring,
904 int *etime_is_rel, 884 int *etime_is_rel,
905 uint64_t *etime) 885 uint64_t *etime)
906{ 886{
907 struct GNUNET_TIME_Relative etime_rel; 887 struct GNUNET_TIME_Relative etime_rel;
908 struct GNUNET_TIME_Absolute etime_abs; 888 struct GNUNET_TIME_Absolute etime_abs;
909 889
910 if (0 == strcmp (expirationstring, 890 if (0 == strcmp (expirationstring, "never"))
911 "never"))
912 { 891 {
913 *etime = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us; 892 *etime = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us;
914 *etime_is_rel = GNUNET_NO; 893 *etime_is_rel = GNUNET_NO;
915 return GNUNET_OK; 894 return GNUNET_OK;
916 } 895 }
917 if (GNUNET_OK == 896 if (GNUNET_OK ==
918 GNUNET_STRINGS_fancy_time_to_relative (expirationstring, 897 GNUNET_STRINGS_fancy_time_to_relative (expirationstring, &etime_rel))
919 &etime_rel))
920 { 898 {
921 *etime_is_rel = GNUNET_YES; 899 *etime_is_rel = GNUNET_YES;
922 *etime = etime_rel.rel_value_us; 900 *etime = etime_rel.rel_value_us;
923 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 901 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
924 "Storing record with relative expiration time of %s\n", 902 "Storing record with relative expiration time of %s\n",
925 GNUNET_STRINGS_relative_time_to_string (etime_rel, 903 GNUNET_STRINGS_relative_time_to_string (etime_rel, GNUNET_NO));
926 GNUNET_NO));
927 return GNUNET_OK; 904 return GNUNET_OK;
928 } 905 }
929 if (GNUNET_OK == 906 if (GNUNET_OK ==
930 GNUNET_STRINGS_fancy_time_to_absolute (expirationstring, 907 GNUNET_STRINGS_fancy_time_to_absolute (expirationstring, &etime_abs))
931 &etime_abs))
932 { 908 {
933 *etime_is_rel = GNUNET_NO; 909 *etime_is_rel = GNUNET_NO;
934 *etime = etime_abs.abs_value_us; 910 *etime = etime_abs.abs_value_us;
935 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 911 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
936 "Storing record with absolute expiration time of %s\n", 912 "Storing record with absolute expiration time of %s\n",
937 GNUNET_STRINGS_absolute_time_to_string (etime_abs)); 913 GNUNET_STRINGS_absolute_time_to_string (etime_abs));
938 return GNUNET_OK; 914 return GNUNET_OK;
939 } 915 }
940 return GNUNET_SYSERR; 916 return GNUNET_SYSERR;
@@ -952,18 +928,16 @@ parse_expiration (const char *expirationstring,
952 * @param emsg NULL on success, otherwise an error message 928 * @param emsg NULL on success, otherwise an error message
953 */ 929 */
954static void 930static void
955replace_cont (void *cls, 931replace_cont (void *cls, int success, const char *emsg)
956 int success,
957 const char *emsg)
958{ 932{
959 (void) cls; 933 (void) cls;
960 934
961 set_qe = NULL; 935 set_qe = NULL;
962 if (GNUNET_OK != success) 936 if (GNUNET_OK != success)
963 { 937 {
964 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, 938 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
965 _("Failed to replace records: %s\n"), 939 _ ("Failed to replace records: %s\n"),
966 emsg); 940 emsg);
967 ret = 1; /* fail from 'main' */ 941 ret = 1; /* fail from 'main' */
968 } 942 }
969 GNUNET_SCHEDULER_shutdown (); 943 GNUNET_SCHEDULER_shutdown ();
@@ -978,31 +952,29 @@ replace_cont (void *cls,
978 * @param ego an ego known to identity service, or NULL 952 * @param ego an ego known to identity service, or NULL
979 */ 953 */
980static void 954static void
981identity_cb (void *cls, 955identity_cb (void *cls, const struct GNUNET_IDENTITY_Ego *ego)
982 const struct GNUNET_IDENTITY_Ego *ego)
983{ 956{
984 const struct GNUNET_CONFIGURATION_Handle *cfg = cls; 957 const struct GNUNET_CONFIGURATION_Handle *cfg = cls;
985 struct GNUNET_CRYPTO_EcdsaPublicKey pub; 958 struct GNUNET_CRYPTO_EcdsaPublicKey pub;
986 struct GNUNET_GNSRECORD_Data rd; 959 struct GNUNET_GNSRECORD_Data rd;
987 960
988 el = NULL; 961 el = NULL;
989 if ( (NULL != name) && 962 if ((NULL != name) && (0 != strchr (name, '.')))
990 (0 != strchr (name, '.')) )
991 { 963 {
992 fprintf (stderr, 964 fprintf (stderr,
993 _("Label `%s' contains `.' which is not allowed\n"), 965 _ ("Label `%s' contains `.' which is not allowed\n"),
994 name); 966 name);
995 GNUNET_SCHEDULER_shutdown (); 967 GNUNET_SCHEDULER_shutdown ();
996 ret = -1; 968 ret = -1;
997 return; 969 return;
998 } 970 }
999 971
1000 if (NULL == ego) 972 if (NULL == ego)
1001 { 973 {
1002 if (NULL != ego_name) 974 if (NULL != ego_name)
1003 { 975 {
1004 fprintf (stderr, 976 fprintf (stderr,
1005 _("Ego `%s' not known to identity service\n"), 977 _ ("Ego `%s' not known to identity service\n"),
1006 ego_name); 978 ego_name);
1007 } 979 }
1008 GNUNET_SCHEDULER_shutdown (); 980 GNUNET_SCHEDULER_shutdown ();
@@ -1013,21 +985,20 @@ identity_cb (void *cls,
1013 GNUNET_free_non_null (ego_name); 985 GNUNET_free_non_null (ego_name);
1014 ego_name = NULL; 986 ego_name = NULL;
1015 987
1016 if (! (add|del|list|(NULL != nickstring)|(NULL != uri)|(NULL != reverse_pkey)|(NULL != recordset)) ) 988 if (! (add | del | list | (NULL != nickstring) | (NULL != uri) |
989 (NULL != reverse_pkey) | (NULL != recordset)))
1017 { 990 {
1018 /* nothing more to be done */ 991 /* nothing more to be done */
1019 fprintf (stderr, 992 fprintf (stderr, _ ("No options given\n"));
1020 _("No options given\n"));
1021 GNUNET_SCHEDULER_shutdown (); 993 GNUNET_SCHEDULER_shutdown ();
1022 return; 994 return;
1023 } 995 }
1024 GNUNET_CRYPTO_ecdsa_key_get_public (&zone_pkey, 996 GNUNET_CRYPTO_ecdsa_key_get_public (&zone_pkey, &pub);
1025 &pub);
1026 ns = GNUNET_NAMESTORE_connect (cfg); 997 ns = GNUNET_NAMESTORE_connect (cfg);
1027 if (NULL == ns) 998 if (NULL == ns)
1028 { 999 {
1029 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1000 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1030 _("Failed to connect to namestore\n")); 1001 _ ("Failed to connect to namestore\n"));
1031 return; 1002 return;
1032 } 1003 }
1033 1004
@@ -1040,8 +1011,9 @@ identity_cb (void *cls,
1040 if (NULL == name) 1011 if (NULL == name)
1041 { 1012 {
1042 fprintf (stderr, 1013 fprintf (stderr,
1043 _("Missing option `%s' for operation `%s'\n"), 1014 _ ("Missing option `%s' for operation `%s'\n"),
1044 "-R", _("replace")); 1015 "-R",
1016 _ ("replace"));
1045 GNUNET_SCHEDULER_shutdown (); 1017 GNUNET_SCHEDULER_shutdown ();
1046 ret = 1; 1018 ret = 1;
1047 return; 1019 return;
@@ -1049,8 +1021,7 @@ identity_cb (void *cls,
1049 rd_count = 0; 1021 rd_count = 0;
1050 for (struct RecordSetEntry *e = recordset; NULL != e; e = e->next) 1022 for (struct RecordSetEntry *e = recordset; NULL != e; e = e->next)
1051 rd_count++; 1023 rd_count++;
1052 rd = GNUNET_new_array (rd_count, 1024 rd = GNUNET_new_array (rd_count, struct GNUNET_GNSRECORD_Data);
1053 struct GNUNET_GNSRECORD_Data);
1054 rd_count = 0; 1025 rd_count = 0;
1055 for (struct RecordSetEntry *e = recordset; NULL != e; e = e->next) 1026 for (struct RecordSetEntry *e = recordset; NULL != e; e = e->next)
1056 { 1027 {
@@ -1058,23 +1029,24 @@ identity_cb (void *cls,
1058 rd_count++; 1029 rd_count++;
1059 } 1030 }
1060 set_qe = GNUNET_NAMESTORE_records_store (ns, 1031 set_qe = GNUNET_NAMESTORE_records_store (ns,
1061 &zone_pkey, 1032 &zone_pkey,
1062 name, 1033 name,
1063 rd_count, 1034 rd_count,
1064 rd, 1035 rd,
1065 &replace_cont, 1036 &replace_cont,
1066 NULL); 1037 NULL);
1067 GNUNET_free (rd); 1038 GNUNET_free (rd);
1068 return; 1039 return;
1069 } 1040 }
1070 1041
1071 if (add) 1042 if (add)
1072 { 1043 {
1073 if (NULL == name) 1044 if (NULL == name)
1074 { 1045 {
1075 fprintf (stderr, 1046 fprintf (stderr,
1076 _("Missing option `%s' for operation `%s'\n"), 1047 _ ("Missing option `%s' for operation `%s'\n"),
1077 "-n", _("add")); 1048 "-n",
1049 _ ("add"));
1078 GNUNET_SCHEDULER_shutdown (); 1050 GNUNET_SCHEDULER_shutdown ();
1079 ret = 1; 1051 ret = 1;
1080 return; 1052 return;
@@ -1082,8 +1054,9 @@ identity_cb (void *cls,
1082 if (NULL == typestring) 1054 if (NULL == typestring)
1083 { 1055 {
1084 fprintf (stderr, 1056 fprintf (stderr,
1085 _("Missing option `%s' for operation `%s'\n"), 1057 _ ("Missing option `%s' for operation `%s'\n"),
1086 "-t", _("add")); 1058 "-t",
1059 _ ("add"));
1087 GNUNET_SCHEDULER_shutdown (); 1060 GNUNET_SCHEDULER_shutdown ();
1088 ret = 1; 1061 ret = 1;
1089 return; 1062 return;
@@ -1091,9 +1064,7 @@ identity_cb (void *cls,
1091 type = GNUNET_GNSRECORD_typename_to_number (typestring); 1064 type = GNUNET_GNSRECORD_typename_to_number (typestring);
1092 if (UINT32_MAX == type) 1065 if (UINT32_MAX == type)
1093 { 1066 {
1094 fprintf (stderr, 1067 fprintf (stderr, _ ("Unsupported type `%s'\n"), typestring);
1095 _("Unsupported type `%s'\n"),
1096 typestring);
1097 GNUNET_SCHEDULER_shutdown (); 1068 GNUNET_SCHEDULER_shutdown ();
1098 ret = 1; 1069 ret = 1;
1099 return; 1070 return;
@@ -1101,22 +1072,20 @@ identity_cb (void *cls,
1101 if (NULL == value) 1072 if (NULL == value)
1102 { 1073 {
1103 fprintf (stderr, 1074 fprintf (stderr,
1104 _("Missing option `%s' for operation `%s'\n"), 1075 _ ("Missing option `%s' for operation `%s'\n"),
1105 "-V", _("add")); 1076 "-V",
1077 _ ("add"));
1106 ret = 1; 1078 ret = 1;
1107 GNUNET_SCHEDULER_shutdown (); 1079 GNUNET_SCHEDULER_shutdown ();
1108 return; 1080 return;
1109 } 1081 }
1110 if (GNUNET_OK != 1082 if (GNUNET_OK !=
1111 GNUNET_GNSRECORD_string_to_value (type, 1083 GNUNET_GNSRECORD_string_to_value (type, value, &data, &data_size))
1112 value,
1113 &data,
1114 &data_size))
1115 { 1084 {
1116 fprintf (stderr, 1085 fprintf (stderr,
1117 _("Value `%s' invalid for record type `%s'\n"), 1086 _ ("Value `%s' invalid for record type `%s'\n"),
1118 value, 1087 value,
1119 typestring); 1088 typestring);
1120 GNUNET_SCHEDULER_shutdown (); 1089 GNUNET_SCHEDULER_shutdown ();
1121 ret = 1; 1090 ret = 1;
1122 return; 1091 return;
@@ -1124,21 +1093,16 @@ identity_cb (void *cls,
1124 if (NULL == expirationstring) 1093 if (NULL == expirationstring)
1125 { 1094 {
1126 fprintf (stderr, 1095 fprintf (stderr,
1127 _("Missing option `%s' for operation `%s'\n"), 1096 _ ("Missing option `%s' for operation `%s'\n"),
1128 "-e", 1097 "-e",
1129 _("add")); 1098 _ ("add"));
1130 GNUNET_SCHEDULER_shutdown (); 1099 GNUNET_SCHEDULER_shutdown ();
1131 ret = 1; 1100 ret = 1;
1132 return; 1101 return;
1133 } 1102 }
1134 if (GNUNET_OK != 1103 if (GNUNET_OK != parse_expiration (expirationstring, &etime_is_rel, &etime))
1135 parse_expiration (expirationstring,
1136 &etime_is_rel,
1137 &etime))
1138 { 1104 {
1139 fprintf (stderr, 1105 fprintf (stderr, _ ("Invalid time format `%s'\n"), expirationstring);
1140 _("Invalid time format `%s'\n"),
1141 expirationstring);
1142 GNUNET_SCHEDULER_shutdown (); 1106 GNUNET_SCHEDULER_shutdown ();
1143 ret = 1; 1107 ret = 1;
1144 return; 1108 return;
@@ -1156,8 +1120,9 @@ identity_cb (void *cls,
1156 if (NULL == name) 1120 if (NULL == name)
1157 { 1121 {
1158 fprintf (stderr, 1122 fprintf (stderr,
1159 _("Missing option `%s' for operation `%s'\n"), 1123 _ ("Missing option `%s' for operation `%s'\n"),
1160 "-n", _("del")); 1124 "-n",
1125 _ ("del"));
1161 GNUNET_SCHEDULER_shutdown (); 1126 GNUNET_SCHEDULER_shutdown ();
1162 ret = 1; 1127 ret = 1;
1163 return; 1128 return;
@@ -1196,11 +1161,11 @@ identity_cb (void *cls,
1196 1161
1197 if (GNUNET_OK != 1162 if (GNUNET_OK !=
1198 GNUNET_CRYPTO_ecdsa_public_key_from_string (reverse_pkey, 1163 GNUNET_CRYPTO_ecdsa_public_key_from_string (reverse_pkey,
1199 strlen (reverse_pkey), 1164 strlen (reverse_pkey),
1200 &pubkey)) 1165 &pubkey))
1201 { 1166 {
1202 fprintf (stderr, 1167 fprintf (stderr,
1203 _("Invalid public key for reverse lookup `%s'\n"), 1168 _ ("Invalid public key for reverse lookup `%s'\n"),
1204 reverse_pkey); 1169 reverse_pkey);
1205 GNUNET_SCHEDULER_shutdown (); 1170 GNUNET_SCHEDULER_shutdown ();
1206 } 1171 }
@@ -1219,18 +1184,11 @@ identity_cb (void *cls,
1219 struct GNUNET_CRYPTO_EcdsaPublicKey pkey; 1184 struct GNUNET_CRYPTO_EcdsaPublicKey pkey;
1220 1185
1221 GNUNET_STRINGS_utf8_tolower (uri, uri); 1186 GNUNET_STRINGS_utf8_tolower (uri, uri);
1222 if ( (2 != (sscanf (uri, 1187 if ((2 != (sscanf (uri, "gnunet://gns/%52s/%63s", sh, sname))) ||
1223 "gnunet://gns/%52s/%63s", 1188 (GNUNET_OK !=
1224 sh, 1189 GNUNET_CRYPTO_ecdsa_public_key_from_string (sh, strlen (sh), &pkey)))
1225 sname)) ) ||
1226 (GNUNET_OK !=
1227 GNUNET_CRYPTO_ecdsa_public_key_from_string (sh,
1228 strlen (sh),
1229 &pkey)) )
1230 { 1190 {
1231 fprintf (stderr, 1191 fprintf (stderr, _ ("Invalid URI `%s'\n"), uri);
1232 _("Invalid URI `%s'\n"),
1233 uri);
1234 GNUNET_SCHEDULER_shutdown (); 1192 GNUNET_SCHEDULER_shutdown ();
1235 ret = 1; 1193 ret = 1;
1236 return; 1194 return;
@@ -1240,46 +1198,44 @@ identity_cb (void *cls,
1240 rd.data_size = sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey); 1198 rd.data_size = sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey);
1241 rd.record_type = GNUNET_GNSRECORD_TYPE_PKEY; 1199 rd.record_type = GNUNET_GNSRECORD_TYPE_PKEY;
1242 rd.expiration_time = etime; 1200 rd.expiration_time = etime;
1243 if (GNUNET_YES == etime_is_rel) 1201 if (GNUNET_YES == etime_is_rel)
1244 rd.flags |= GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; 1202 rd.flags |= GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
1245 if (1 == is_shadow) 1203 if (1 == is_shadow)
1246 rd.flags |= GNUNET_GNSRECORD_RF_SHADOW_RECORD; 1204 rd.flags |= GNUNET_GNSRECORD_RF_SHADOW_RECORD;
1247 add_qe_uri = GNUNET_NAMESTORE_records_store (ns, 1205 add_qe_uri = GNUNET_NAMESTORE_records_store (ns,
1248 &zone_pkey, 1206 &zone_pkey,
1249 sname, 1207 sname,
1250 1, 1208 1,
1251 &rd, 1209 &rd,
1252 &add_continuation, 1210 &add_continuation,
1253 &add_qe_uri); 1211 &add_qe_uri);
1254 } 1212 }
1255 if (NULL != nickstring) 1213 if (NULL != nickstring)
1256 { 1214 {
1257 if (0 == strlen(nickstring)) 1215 if (0 == strlen (nickstring))
1258 { 1216 {
1259 fprintf (stderr, 1217 fprintf (stderr, _ ("Invalid nick `%s'\n"), nickstring);
1260 _("Invalid nick `%s'\n"),
1261 nickstring);
1262 GNUNET_SCHEDULER_shutdown (); 1218 GNUNET_SCHEDULER_shutdown ();
1263 ret = 1; 1219 ret = 1;
1264 return; 1220 return;
1265 } 1221 }
1266 add_qe_uri = GNUNET_NAMESTORE_set_nick (ns, 1222 add_qe_uri = GNUNET_NAMESTORE_set_nick (ns,
1267 &zone_pkey, 1223 &zone_pkey,
1268 nickstring, 1224 nickstring,
1269 &add_continuation, 1225 &add_continuation,
1270 &add_qe_uri); 1226 &add_qe_uri);
1271 } 1227 }
1272 if (monitor) 1228 if (monitor)
1273 { 1229 {
1274 zm = GNUNET_NAMESTORE_zone_monitor_start (cfg, 1230 zm = GNUNET_NAMESTORE_zone_monitor_start (cfg,
1275 &zone_pkey, 1231 &zone_pkey,
1276 GNUNET_YES, 1232 GNUNET_YES,
1277 &monitor_error_cb, 1233 &monitor_error_cb,
1278 NULL, 1234 NULL,
1279 &display_record_monitor, 1235 &display_record_monitor,
1280 NULL, 1236 NULL,
1281 &sync_cb, 1237 &sync_cb,
1282 NULL); 1238 NULL);
1283 } 1239 }
1284} 1240}
1285 1241
@@ -1296,8 +1252,7 @@ default_ego_cb (void *cls,
1296 get_default = NULL; 1252 get_default = NULL;
1297 if (NULL == ego) 1253 if (NULL == ego)
1298 { 1254 {
1299 fprintf (stderr, 1255 fprintf (stderr, _ ("No default ego configured in identity service\n"));
1300 _("No default ego configured in identity service\n"));
1301 GNUNET_SCHEDULER_shutdown (); 1256 GNUNET_SCHEDULER_shutdown ();
1302 ret = -1; 1257 ret = -1;
1303 return; 1258 return;
@@ -1322,10 +1277,8 @@ id_connect_cb (void *cls,
1322 (void) name; 1277 (void) name;
1323 if (NULL == ego) 1278 if (NULL == ego)
1324 { 1279 {
1325 get_default = GNUNET_IDENTITY_get (idh, 1280 get_default =
1326 "namestore", 1281 GNUNET_IDENTITY_get (idh, "namestore", &default_ego_cb, (void *) cfg);
1327 &default_ego_cb,
1328 (void *) cfg);
1329 } 1282 }
1330} 1283}
1331 1284
@@ -1348,31 +1301,24 @@ run (void *cls,
1348 (void) args; 1301 (void) args;
1349 (void) cfgfile; 1302 (void) cfgfile;
1350 if (NULL != args[0]) 1303 if (NULL != args[0])
1351 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1304 GNUNET_log (
1352 _("Superfluous command line arguments (starting with `%s') ignored\n"), 1305 GNUNET_ERROR_TYPE_WARNING,
1353 args[0]); 1306 _ ("Superfluous command line arguments (starting with `%s') ignored\n"),
1354 if ( (NULL != args[0]) && 1307 args[0]);
1355 (NULL == uri) ) 1308 if ((NULL != args[0]) && (NULL == uri))
1356 uri = GNUNET_strdup (args[0]); 1309 uri = GNUNET_strdup (args[0]);
1357 1310
1358 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, 1311 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, (void *) cfg);
1359 (void *) cfg);
1360 1312
1361 if (NULL == ego_name) 1313 if (NULL == ego_name)
1362 { 1314 {
1363 idh = GNUNET_IDENTITY_connect (cfg, 1315 idh = GNUNET_IDENTITY_connect (cfg, &id_connect_cb, (void *) cfg);
1364 &id_connect_cb,
1365 (void *) cfg);
1366 if (NULL == idh) 1316 if (NULL == idh)
1367 fprintf (stderr, 1317 fprintf (stderr, _ ("Cannot connect to identity service\n"));
1368 _("Cannot connect to identity service\n"));
1369 ret = -1; 1318 ret = -1;
1370 return; 1319 return;
1371 } 1320 }
1372 el = GNUNET_IDENTITY_ego_lookup (cfg, 1321 el = GNUNET_IDENTITY_ego_lookup (cfg, ego_name, &identity_cb, (void *) cfg);
1373 ego_name,
1374 &identity_cb,
1375 (void *) cfg);
1376} 1322}
1377 1323
1378 1324
@@ -1389,15 +1335,15 @@ run (void *cls,
1389 * "TTL TYPE FLAGS VALUE" where TTL is an expiration time (rel or abs), 1335 * "TTL TYPE FLAGS VALUE" where TTL is an expiration time (rel or abs),
1390 * always given in seconds (without the unit), 1336 * always given in seconds (without the unit),
1391 * TYPE is a DNS/GNS record type, FLAGS is either "n" for no flags or 1337 * TYPE is a DNS/GNS record type, FLAGS is either "n" for no flags or
1392 * a combination of 's' (shadow) and 'p' (public) and VALUE is the 1338 * a combination of 's' (shadow) and 'p' (public) and VALUE is the
1393 * value (in human-readable format) 1339 * value (in human-readable format)
1394 * @return #GNUNET_OK on success 1340 * @return #GNUNET_OK on success
1395 */ 1341 */
1396static int 1342static int
1397multirecord_process (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, 1343multirecord_process (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
1398 void *scls, 1344 void *scls,
1399 const char *option, 1345 const char *option,
1400 const char *value) 1346 const char *value)
1401{ 1347{
1402 struct RecordSetEntry **head = scls; 1348 struct RecordSetEntry **head = scls;
1403 struct RecordSetEntry *r; 1349 struct RecordSetEntry *r;
@@ -1415,24 +1361,20 @@ multirecord_process (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
1415 if (NULL == tok) 1361 if (NULL == tok)
1416 { 1362 {
1417 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1363 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1418 _("Empty record line argument is not allowed.\n")); 1364 _ ("Empty record line argument is not allowed.\n"));
1419 GNUNET_free (cp); 1365 GNUNET_free (cp);
1420 return GNUNET_SYSERR; 1366 return GNUNET_SYSERR;
1421 } 1367 }
1422 { 1368 {
1423 char *etime_in_s; 1369 char *etime_in_s;
1424 1370
1425 GNUNET_asprintf (&etime_in_s, 1371 GNUNET_asprintf (&etime_in_s, "%s s", tok);
1426 "%s s",
1427 tok);
1428 if (GNUNET_OK != 1372 if (GNUNET_OK !=
1429 parse_expiration (etime_in_s, 1373 parse_expiration (etime_in_s, &etime_is_rel, &record.expiration_time))
1430 &etime_is_rel,
1431 &record.expiration_time))
1432 { 1374 {
1433 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1375 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1434 _("Invalid expiration time `%s' (must be without unit)\n"), 1376 _ ("Invalid expiration time `%s' (must be without unit)\n"),
1435 tok); 1377 tok);
1436 GNUNET_free (cp); 1378 GNUNET_free (cp);
1437 GNUNET_free (etime_in_s); 1379 GNUNET_free (etime_in_s);
1438 return GNUNET_SYSERR; 1380 return GNUNET_SYSERR;
@@ -1443,17 +1385,15 @@ multirecord_process (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
1443 if (NULL == tok) 1385 if (NULL == tok)
1444 { 1386 {
1445 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1387 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1446 _("Missing entries in record line `%s'.\n"), 1388 _ ("Missing entries in record line `%s'.\n"),
1447 value); 1389 value);
1448 GNUNET_free (cp); 1390 GNUNET_free (cp);
1449 return GNUNET_SYSERR; 1391 return GNUNET_SYSERR;
1450 } 1392 }
1451 record.record_type = GNUNET_GNSRECORD_typename_to_number (tok); 1393 record.record_type = GNUNET_GNSRECORD_typename_to_number (tok);
1452 if (UINT32_MAX == record.record_type) 1394 if (UINT32_MAX == record.record_type)
1453 { 1395 {
1454 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1396 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ ("Unknown record type `%s'\n"), tok);
1455 _("Unknown record type `%s'\n"),
1456 tok);
1457 GNUNET_free (cp); 1397 GNUNET_free (cp);
1458 return GNUNET_SYSERR; 1398 return GNUNET_SYSERR;
1459 } 1399 }
@@ -1461,8 +1401,8 @@ multirecord_process (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
1461 if (NULL == tok) 1401 if (NULL == tok)
1462 { 1402 {
1463 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1403 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1464 _("Missing entries in record line `%s'.\n"), 1404 _ ("Missing entries in record line `%s'.\n"),
1465 value); 1405 value);
1466 GNUNET_free (cp); 1406 GNUNET_free (cp);
1467 return GNUNET_SYSERR; 1407 return GNUNET_SYSERR;
1468 } 1408 }
@@ -1470,7 +1410,7 @@ multirecord_process (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
1470 if (etime_is_rel) 1410 if (etime_is_rel)
1471 record.flags |= GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; 1411 record.flags |= GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
1472 if (NULL == strchr (tok, (unsigned char) 'p')) /* p = public */ 1412 if (NULL == strchr (tok, (unsigned char) 'p')) /* p = public */
1473 record.flags |= GNUNET_GNSRECORD_RF_PRIVATE; 1413 record.flags |= GNUNET_GNSRECORD_RF_PRIVATE;
1474 if (NULL != strchr (tok, (unsigned char) 's')) 1414 if (NULL != strchr (tok, (unsigned char) 's'))
1475 record.flags |= GNUNET_GNSRECORD_RF_SHADOW_RECORD; 1415 record.flags |= GNUNET_GNSRECORD_RF_SHADOW_RECORD;
1476 /* find beginning of record value */ 1416 /* find beginning of record value */
@@ -1478,34 +1418,31 @@ multirecord_process (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
1478 if (NULL == tok) 1418 if (NULL == tok)
1479 { 1419 {
1480 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1420 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1481 _("Missing entries in record line `%s'.\n"), 1421 _ ("Missing entries in record line `%s'.\n"),
1482 value); 1422 value);
1483 GNUNET_free (cp); 1423 GNUNET_free (cp);
1484 return GNUNET_SYSERR; 1424 return GNUNET_SYSERR;
1485 } 1425 }
1486 GNUNET_free (cp); 1426 GNUNET_free (cp);
1487 tok++; /* skip space */ 1427 tok++; /* skip space */
1488 if (GNUNET_OK != 1428 if (GNUNET_OK != GNUNET_GNSRECORD_string_to_value (record.record_type,
1489 GNUNET_GNSRECORD_string_to_value (record.record_type, 1429 tok,
1490 tok, 1430 &raw_data,
1491 &raw_data, 1431 &record.data_size))
1492 &record.data_size))
1493 { 1432 {
1494 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1433 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1495 _("Invalid record data for type %s: `%s'.\n"), 1434 _ ("Invalid record data for type %s: `%s'.\n"),
1496 GNUNET_GNSRECORD_number_to_typename (record.record_type), 1435 GNUNET_GNSRECORD_number_to_typename (record.record_type),
1497 tok); 1436 tok);
1498 return GNUNET_SYSERR; 1437 return GNUNET_SYSERR;
1499 } 1438 }
1500 1439
1501 r = GNUNET_malloc (sizeof (struct RecordSetEntry) + record.data_size); 1440 r = GNUNET_malloc (sizeof (struct RecordSetEntry) + record.data_size);
1502 r->next = *head; 1441 r->next = *head;
1503 record.data = &r[1]; 1442 record.data = &r[1];
1504 memcpy (&r[1], 1443 memcpy (&r[1], raw_data, record.data_size);
1505 raw_data,
1506 record.data_size);
1507 GNUNET_free (raw_data); 1444 GNUNET_free (raw_data);
1508 r->record = record; 1445 r->record = record;
1509 *head = r; 1446 *head = r;
1510 return GNUNET_OK; 1447 return GNUNET_OK;
1511} 1448}
@@ -1522,26 +1459,24 @@ multirecord_process (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
1522 */ 1459 */
1523struct GNUNET_GETOPT_CommandLineOption 1460struct GNUNET_GETOPT_CommandLineOption
1524multirecord_option (char shortName, 1461multirecord_option (char shortName,
1525 const char *name, 1462 const char *name,
1526 const char *argumentHelp, 1463 const char *argumentHelp,
1527 const char *description, 1464 const char *description,
1528 struct RecordSetEntry **rs) 1465 struct RecordSetEntry **rs)
1529{ 1466{
1530 struct GNUNET_GETOPT_CommandLineOption clo = { 1467 struct GNUNET_GETOPT_CommandLineOption clo = {.shortName = shortName,
1531 .shortName = shortName, 1468 .name = name,
1532 .name = name, 1469 .argumentHelp = argumentHelp,
1533 .argumentHelp = argumentHelp, 1470 .description = description,
1534 .description = description, 1471 .require_argument = 1,
1535 .require_argument = 1, 1472 .processor =
1536 .processor = &multirecord_process, 1473 &multirecord_process,
1537 .scls = (void *) rs 1474 .scls = (void *) rs};
1538 };
1539 1475
1540 return clo; 1476 return clo;
1541} 1477}
1542 1478
1543 1479
1544
1545/** 1480/**
1546 * The main function for gnunet-namestore. 1481 * The main function for gnunet-namestore.
1547 * 1482 *
@@ -1550,105 +1485,109 @@ multirecord_option (char shortName,
1550 * @return 0 ok, 1 on error 1485 * @return 0 ok, 1 on error
1551 */ 1486 */
1552int 1487int
1553main (int argc, 1488main (int argc, char *const *argv)
1554 char *const *argv)
1555{ 1489{
1556 struct GNUNET_GETOPT_CommandLineOption options[] = { 1490 struct GNUNET_GETOPT_CommandLineOption options[] =
1557 GNUNET_GETOPT_option_flag ('a', 1491 {GNUNET_GETOPT_option_flag ('a', "add", gettext_noop ("add record"), &add),
1558 "add", 1492 GNUNET_GETOPT_option_flag ('d',
1559 gettext_noop ("add record"), 1493 "delete",
1560 &add), 1494 gettext_noop ("delete record"),
1561 GNUNET_GETOPT_option_flag ('d', 1495 &del),
1562 "delete", 1496 GNUNET_GETOPT_option_flag ('D',
1563 gettext_noop ("delete record"), 1497 "display",
1564 &del), 1498 gettext_noop ("display records"),
1565 GNUNET_GETOPT_option_flag ('D', 1499 &list),
1566 "display", 1500 GNUNET_GETOPT_option_string (
1567 gettext_noop ("display records"), 1501 'e',
1568 &list), 1502 "expiration",
1569 GNUNET_GETOPT_option_string ('e', 1503 "TIME",
1570 "expiration", 1504 gettext_noop (
1571 "TIME", 1505 "expiration time for record to use (for adding only), \"never\" is possible"),
1572 gettext_noop ("expiration time for record to use (for adding only), \"never\" is possible"), 1506 &expirationstring),
1573 &expirationstring), 1507 GNUNET_GETOPT_option_string ('i',
1574 GNUNET_GETOPT_option_string ('i', 1508 "nick",
1575 "nick", 1509 "NICKNAME",
1576 "NICKNAME", 1510 gettext_noop (
1577 gettext_noop ("set the desired nick name for the zone"), 1511 "set the desired nick name for the zone"),
1578 &nickstring), 1512 &nickstring),
1579 GNUNET_GETOPT_option_flag ('m', 1513 GNUNET_GETOPT_option_flag ('m',
1580 "monitor", 1514 "monitor",
1581 gettext_noop ("monitor changes in the namestore"), 1515 gettext_noop (
1582 &monitor), 1516 "monitor changes in the namestore"),
1583 GNUNET_GETOPT_option_string ('n', 1517 &monitor),
1584 "name", 1518 GNUNET_GETOPT_option_string ('n',
1585 "NAME", 1519 "name",
1586 gettext_noop ("name of the record to add/delete/display"), 1520 "NAME",
1587 &name), 1521 gettext_noop (
1588 GNUNET_GETOPT_option_string ('r', 1522 "name of the record to add/delete/display"),
1589 "reverse", 1523 &name),
1590 "PKEY", 1524 GNUNET_GETOPT_option_string ('r',
1591 gettext_noop ("determine our name for the given PKEY"), 1525 "reverse",
1592 &reverse_pkey), 1526 "PKEY",
1593 multirecord_option ('R', 1527 gettext_noop (
1594 "replace", 1528 "determine our name for the given PKEY"),
1595 "RECORDLINE", 1529 &reverse_pkey),
1596 gettext_noop ("set record set to values given by (possibly multiple) RECORDLINES; can be specified multiple times"), 1530 multirecord_option (
1597 &recordset), 1531 'R',
1598 GNUNET_GETOPT_option_string ('t', 1532 "replace",
1599 "type", 1533 "RECORDLINE",
1600 "TYPE", 1534 gettext_noop (
1601 gettext_noop ("type of the record to add/delete/display"), 1535 "set record set to values given by (possibly multiple) RECORDLINES; can be specified multiple times"),
1602 &typestring), 1536 &recordset),
1603 GNUNET_GETOPT_option_string ('u', 1537 GNUNET_GETOPT_option_string ('t',
1604 "uri", 1538 "type",
1605 "URI", 1539 "TYPE",
1606 gettext_noop ("URI to import into our zone"), 1540 gettext_noop (
1607 &uri), 1541 "type of the record to add/delete/display"),
1608 GNUNET_GETOPT_option_string ('V', 1542 &typestring),
1609 "value", 1543 GNUNET_GETOPT_option_string ('u',
1610 "VALUE", 1544 "uri",
1611 gettext_noop ("value of the record to add/delete"), 1545 "URI",
1612 &value), 1546 gettext_noop ("URI to import into our zone"),
1613 GNUNET_GETOPT_option_flag ('p', 1547 &uri),
1614 "public", 1548 GNUNET_GETOPT_option_string ('V',
1615 gettext_noop ("create or list public record"), 1549 "value",
1616 &is_public), 1550 "VALUE",
1617 GNUNET_GETOPT_option_flag ('s', 1551 gettext_noop (
1618 "shadow", 1552 "value of the record to add/delete"),
1619 gettext_noop ("create shadow record (only valid if all other records of the same type have expired"), 1553 &value),
1620 &is_shadow), 1554 GNUNET_GETOPT_option_flag ('p',
1621 GNUNET_GETOPT_option_string ('z', 1555 "public",
1622 "zone", 1556 gettext_noop ("create or list public record"),
1623 "EGO", 1557 &is_public),
1624 gettext_noop ("name of the ego controlling the zone"), 1558 GNUNET_GETOPT_option_flag (
1625 &ego_name), 1559 's',
1626 GNUNET_GETOPT_OPTION_END 1560 "shadow",
1627 }; 1561 gettext_noop (
1628 1562 "create shadow record (only valid if all other records of the same type have expired"),
1629 if (GNUNET_OK != 1563 &is_shadow),
1630 GNUNET_STRINGS_get_utf8_args (argc, argv, 1564 GNUNET_GETOPT_option_string ('z',
1631 &argc, &argv)) 1565 "zone",
1566 "EGO",
1567 gettext_noop (
1568 "name of the ego controlling the zone"),
1569 &ego_name),
1570 GNUNET_GETOPT_OPTION_END};
1571
1572 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
1632 return 2; 1573 return 2;
1633 1574
1634 is_public = -1; 1575 is_public = -1;
1635 is_shadow = -1; 1576 is_shadow = -1;
1636 GNUNET_log_setup ("gnunet-namestore", 1577 GNUNET_log_setup ("gnunet-namestore", "WARNING", NULL);
1637 "WARNING", 1578 if (GNUNET_OK != GNUNET_PROGRAM_run (argc,
1638 NULL); 1579 argv,
1639 if (GNUNET_OK != 1580 "gnunet-namestore",
1640 GNUNET_PROGRAM_run (argc, 1581 _ ("GNUnet zone manipulation tool"),
1641 argv, 1582 options,
1642 "gnunet-namestore", 1583 &run,
1643 _("GNUnet zone manipulation tool"), 1584 NULL))
1644 options,
1645 &run, NULL))
1646 { 1585 {
1647 GNUNET_free ((void*) argv); 1586 GNUNET_free ((void *) argv);
1648 GNUNET_CRYPTO_ecdsa_key_clear (&zone_pkey); 1587 GNUNET_CRYPTO_ecdsa_key_clear (&zone_pkey);
1649 return 1; 1588 return 1;
1650 } 1589 }
1651 GNUNET_free ((void*) argv); 1590 GNUNET_free ((void *) argv);
1652 GNUNET_CRYPTO_ecdsa_key_clear (&zone_pkey); 1591 GNUNET_CRYPTO_ecdsa_key_clear (&zone_pkey);
1653 return ret; 1592 return ret;
1654} 1593}