diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-10-16 11:34:10 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-10-16 11:34:10 +0000 |
commit | b6bfed8309e6b9b3286b8f608ad899bfb0a97205 (patch) | |
tree | 46cadaba7deadf7cb07dcc0b3d07f28fc147ffc2 /src/namestore | |
parent | 5ad45d439b900ea388b93aca8547ad03c53ddc68 (diff) | |
download | gnunet-b6bfed8309e6b9b3286b8f608ad899bfb0a97205.tar.gz gnunet-b6bfed8309e6b9b3286b8f608ad899bfb0a97205.zip |
-moving code to new libgnunetgnsrecord in preparation for addressing #3052
Diffstat (limited to 'src/namestore')
-rw-r--r-- | src/namestore/Makefile.am | 6 | ||||
-rw-r--r-- | src/namestore/gnunet-namestore-fcfsd.c | 5 | ||||
-rw-r--r-- | src/namestore/gnunet-namestore.c | 1 | ||||
-rw-r--r-- | src/namestore/namestore_api_common.c | 654 | ||||
-rw-r--r-- | src/namestore/plugin_namestore_postgres.c | 1 | ||||
-rw-r--r-- | src/namestore/plugin_namestore_sqlite.c | 1 |
6 files changed, 10 insertions, 658 deletions
diff --git a/src/namestore/Makefile.am b/src/namestore/Makefile.am index f6aa2a085..1c9b297ae 100644 --- a/src/namestore/Makefile.am +++ b/src/namestore/Makefile.am | |||
@@ -97,8 +97,9 @@ endif | |||
97 | gnunet_namestore_SOURCES = \ | 97 | gnunet_namestore_SOURCES = \ |
98 | gnunet-namestore.c | 98 | gnunet-namestore.c |
99 | gnunet_namestore_LDADD = \ | 99 | gnunet_namestore_LDADD = \ |
100 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
101 | $(top_builddir)/src/identity/libgnunetidentity.la \ | 100 | $(top_builddir)/src/identity/libgnunetidentity.la \ |
101 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ | ||
102 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
102 | libgnunetnamestore.la \ | 103 | libgnunetnamestore.la \ |
103 | $(GN_LIBINTL) | 104 | $(GN_LIBINTL) |
104 | gnunet_namestore_DEPENDENCIES = \ | 105 | gnunet_namestore_DEPENDENCIES = \ |
@@ -110,9 +111,10 @@ gnunet_namestore_DEPENDENCIES = \ | |||
110 | gnunet_namestore_fcfsd_SOURCES = \ | 111 | gnunet_namestore_fcfsd_SOURCES = \ |
111 | gnunet-namestore-fcfsd.c | 112 | gnunet-namestore-fcfsd.c |
112 | gnunet_namestore_fcfsd_LDADD = -lmicrohttpd \ | 113 | gnunet_namestore_fcfsd_LDADD = -lmicrohttpd \ |
113 | $(top_builddir)/src/util/libgnunetutil.la \ | 114 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ |
114 | $(top_builddir)/src/identity/libgnunetidentity.la \ | 115 | $(top_builddir)/src/identity/libgnunetidentity.la \ |
115 | $(top_builddir)/src/namestore/libgnunetnamestore.la \ | 116 | $(top_builddir)/src/namestore/libgnunetnamestore.la \ |
117 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
116 | $(GN_LIBINTL) | 118 | $(GN_LIBINTL) |
117 | gnunet_namestore_fcfsd_DEPENDENCIES = \ | 119 | gnunet_namestore_fcfsd_DEPENDENCIES = \ |
118 | $(top_builddir)/src/util/libgnunetutil.la \ | 120 | $(top_builddir)/src/util/libgnunetutil.la \ |
diff --git a/src/namestore/gnunet-namestore-fcfsd.c b/src/namestore/gnunet-namestore-fcfsd.c index 08f03a055..14f95c911 100644 --- a/src/namestore/gnunet-namestore-fcfsd.c +++ b/src/namestore/gnunet-namestore-fcfsd.c | |||
@@ -34,6 +34,7 @@ | |||
34 | #include <microhttpd.h> | 34 | #include <microhttpd.h> |
35 | #include "gnunet_util_lib.h" | 35 | #include "gnunet_util_lib.h" |
36 | #include "gnunet_identity_service.h" | 36 | #include "gnunet_identity_service.h" |
37 | #include "gnunet_gnsrecord_lib.h" | ||
37 | #include "gnunet_namestore_service.h" | 38 | #include "gnunet_namestore_service.h" |
38 | 39 | ||
39 | /** | 40 | /** |
@@ -212,7 +213,7 @@ static struct GNUNET_IDENTITY_Operation *id_op; | |||
212 | * Port we use for the HTTP server. | 213 | * Port we use for the HTTP server. |
213 | */ | 214 | */ |
214 | static unsigned long long port; | 215 | static unsigned long long port; |
215 | 216 | ||
216 | 217 | ||
217 | /** | 218 | /** |
218 | * Task run whenever HTTP server operations are pending. | 219 | * Task run whenever HTTP server operations are pending. |
@@ -674,7 +675,7 @@ create_response (void *cls, | |||
674 | return ret; | 675 | return ret; |
675 | } | 676 | } |
676 | if (0 == strcmp (method, MHD_HTTP_METHOD_POST)) | 677 | if (0 == strcmp (method, MHD_HTTP_METHOD_POST)) |
677 | { | 678 | { |
678 | request = *ptr; | 679 | request = *ptr; |
679 | if (NULL == request) | 680 | if (NULL == request) |
680 | { | 681 | { |
diff --git a/src/namestore/gnunet-namestore.c b/src/namestore/gnunet-namestore.c index 322030e65..e4cd856d0 100644 --- a/src/namestore/gnunet-namestore.c +++ b/src/namestore/gnunet-namestore.c | |||
@@ -30,6 +30,7 @@ | |||
30 | #include <gnunet_util_lib.h> | 30 | #include <gnunet_util_lib.h> |
31 | #include <gnunet_dnsparser_lib.h> | 31 | #include <gnunet_dnsparser_lib.h> |
32 | #include <gnunet_identity_service.h> | 32 | #include <gnunet_identity_service.h> |
33 | #include <gnunet_gnsrecord_lib.h> | ||
33 | #include <gnunet_namestore_service.h> | 34 | #include <gnunet_namestore_service.h> |
34 | 35 | ||
35 | 36 | ||
diff --git a/src/namestore/namestore_api_common.c b/src/namestore/namestore_api_common.c index 81662a861..388722cd3 100644 --- a/src/namestore/namestore_api_common.c +++ b/src/namestore/namestore_api_common.c | |||
@@ -515,660 +515,6 @@ GNUNET_NAMESTORE_block_decrypt (const struct GNUNET_NAMESTORE_Block *block, | |||
515 | 515 | ||
516 | 516 | ||
517 | /** | 517 | /** |
518 | * Convert the 'value' of a record to a string. | ||
519 | * | ||
520 | * @param type type of the record | ||
521 | * @param data value in binary encoding | ||
522 | * @param data_size number of bytes in @a data | ||
523 | * @return NULL on error, otherwise human-readable representation of the value | ||
524 | */ | ||
525 | char * | ||
526 | GNUNET_NAMESTORE_value_to_string (uint32_t type, | ||
527 | const void *data, | ||
528 | size_t data_size) | ||
529 | { | ||
530 | const char *cdata; | ||
531 | char* result; | ||
532 | char tmp[INET6_ADDRSTRLEN]; | ||
533 | |||
534 | switch (type) | ||
535 | { | ||
536 | case 0: | ||
537 | return NULL; | ||
538 | case GNUNET_DNSPARSER_TYPE_A: | ||
539 | if (data_size != sizeof (struct in_addr)) | ||
540 | return NULL; | ||
541 | if (NULL == inet_ntop (AF_INET, data, tmp, sizeof (tmp))) | ||
542 | return NULL; | ||
543 | return GNUNET_strdup (tmp); | ||
544 | case GNUNET_DNSPARSER_TYPE_NS: | ||
545 | { | ||
546 | char *ns; | ||
547 | size_t off; | ||
548 | |||
549 | off = 0; | ||
550 | ns = GNUNET_DNSPARSER_parse_name (data, | ||
551 | data_size, | ||
552 | &off); | ||
553 | if ( (NULL == ns) || | ||
554 | (off != data_size) ) | ||
555 | { | ||
556 | GNUNET_break_op (0); | ||
557 | return NULL; | ||
558 | } | ||
559 | return ns; | ||
560 | } | ||
561 | case GNUNET_DNSPARSER_TYPE_CNAME: | ||
562 | { | ||
563 | char *cname; | ||
564 | size_t off; | ||
565 | |||
566 | off = 0; | ||
567 | cname = GNUNET_DNSPARSER_parse_name (data, | ||
568 | data_size, | ||
569 | &off); | ||
570 | if ( (NULL == cname) || | ||
571 | (off != data_size) ) | ||
572 | { | ||
573 | GNUNET_break_op (0); | ||
574 | GNUNET_free_non_null (cname); | ||
575 | return NULL; | ||
576 | } | ||
577 | return cname; | ||
578 | } | ||
579 | case GNUNET_DNSPARSER_TYPE_SOA: | ||
580 | { | ||
581 | struct GNUNET_DNSPARSER_SoaRecord *soa; | ||
582 | size_t off; | ||
583 | |||
584 | off = 0; | ||
585 | soa = GNUNET_DNSPARSER_parse_soa (data, | ||
586 | data_size, | ||
587 | &off); | ||
588 | if ( (NULL == soa) || | ||
589 | (off != data_size) ) | ||
590 | { | ||
591 | GNUNET_break_op (0); | ||
592 | return NULL; | ||
593 | } | ||
594 | GNUNET_asprintf (&result, | ||
595 | "rname=%s mname=%s %lu,%lu,%lu,%lu,%lu", | ||
596 | soa->rname, | ||
597 | soa->mname, | ||
598 | soa->serial, | ||
599 | soa->refresh, | ||
600 | soa->retry, | ||
601 | soa->expire, | ||
602 | soa->minimum_ttl); | ||
603 | GNUNET_DNSPARSER_free_soa (soa); | ||
604 | return result; | ||
605 | } | ||
606 | case GNUNET_DNSPARSER_TYPE_PTR: | ||
607 | { | ||
608 | char *ptr; | ||
609 | size_t off; | ||
610 | |||
611 | off = 0; | ||
612 | ptr = GNUNET_DNSPARSER_parse_name (data, | ||
613 | data_size, | ||
614 | &off); | ||
615 | if ( (NULL == ptr) || | ||
616 | (off != data_size) ) | ||
617 | { | ||
618 | GNUNET_break_op (0); | ||
619 | GNUNET_free_non_null (ptr); | ||
620 | return NULL; | ||
621 | } | ||
622 | return ptr; | ||
623 | } | ||
624 | case GNUNET_DNSPARSER_TYPE_MX: | ||
625 | { | ||
626 | struct GNUNET_DNSPARSER_MxRecord *mx; | ||
627 | size_t off; | ||
628 | |||
629 | off = 0; | ||
630 | mx = GNUNET_DNSPARSER_parse_mx (data, | ||
631 | data_size, | ||
632 | &off); | ||
633 | if ( (NULL == mx) || | ||
634 | (off != data_size) ) | ||
635 | { | ||
636 | GNUNET_break_op (0); | ||
637 | GNUNET_free_non_null (mx); | ||
638 | return NULL; | ||
639 | } | ||
640 | GNUNET_asprintf (&result, | ||
641 | "%hu,%s", | ||
642 | mx->preference, | ||
643 | mx->mxhost); | ||
644 | GNUNET_DNSPARSER_free_mx (mx); | ||
645 | return result; | ||
646 | } | ||
647 | case GNUNET_DNSPARSER_TYPE_TXT: | ||
648 | return GNUNET_strndup (data, data_size); | ||
649 | case GNUNET_DNSPARSER_TYPE_AAAA: | ||
650 | if (data_size != sizeof (struct in6_addr)) | ||
651 | return NULL; | ||
652 | if (NULL == inet_ntop (AF_INET6, data, tmp, sizeof (tmp))) | ||
653 | return NULL; | ||
654 | return GNUNET_strdup (tmp); | ||
655 | case GNUNET_NAMESTORE_TYPE_PKEY: | ||
656 | if (data_size != sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)) | ||
657 | return NULL; | ||
658 | return GNUNET_CRYPTO_ecdsa_public_key_to_string (data); | ||
659 | case GNUNET_NAMESTORE_TYPE_PHONE: | ||
660 | { | ||
661 | const struct GNUNET_CONVERSATION_PhoneRecord *pr; | ||
662 | char *ret; | ||
663 | char *pkey; | ||
664 | |||
665 | if (data_size != sizeof (struct GNUNET_CONVERSATION_PhoneRecord)) | ||
666 | return NULL; | ||
667 | pr = data; | ||
668 | if (0 != ntohl (pr->version)) | ||
669 | return NULL; | ||
670 | pkey = GNUNET_CRYPTO_eddsa_public_key_to_string (&pr->peer.public_key); | ||
671 | GNUNET_asprintf (&ret, | ||
672 | "%u-%s", | ||
673 | ntohl (pr->line), | ||
674 | pkey); | ||
675 | GNUNET_free (pkey); | ||
676 | return ret; | ||
677 | } | ||
678 | case GNUNET_NAMESTORE_TYPE_PSEU: | ||
679 | return GNUNET_strndup (data, data_size); | ||
680 | case GNUNET_NAMESTORE_TYPE_LEHO: | ||
681 | return GNUNET_strndup (data, data_size); | ||
682 | case GNUNET_NAMESTORE_TYPE_VPN: | ||
683 | { | ||
684 | const struct GNUNET_TUN_GnsVpnRecord *vpn; | ||
685 | char* vpn_str; | ||
686 | |||
687 | cdata = data; | ||
688 | if ( (data_size <= sizeof (struct GNUNET_TUN_GnsVpnRecord)) || | ||
689 | ('\0' != cdata[data_size - 1]) ) | ||
690 | return NULL; /* malformed */ | ||
691 | vpn = data; | ||
692 | if (0 == GNUNET_asprintf (&vpn_str, "%u %s %s", | ||
693 | (unsigned int) ntohs (vpn->proto), | ||
694 | (const char*) GNUNET_i2s_full (&vpn->peer), | ||
695 | (const char*) &vpn[1])) | ||
696 | { | ||
697 | GNUNET_free (vpn_str); | ||
698 | return NULL; | ||
699 | } | ||
700 | return vpn_str; | ||
701 | } | ||
702 | case GNUNET_NAMESTORE_TYPE_GNS2DNS: | ||
703 | { | ||
704 | char *ns; | ||
705 | size_t off; | ||
706 | |||
707 | off = 0; | ||
708 | ns = GNUNET_DNSPARSER_parse_name (data, | ||
709 | data_size, | ||
710 | &off); | ||
711 | if ( (NULL == ns) || | ||
712 | (off != data_size) ) | ||
713 | { | ||
714 | GNUNET_break_op (0); | ||
715 | GNUNET_free_non_null (ns); | ||
716 | return NULL; | ||
717 | } | ||
718 | return ns; | ||
719 | } | ||
720 | case GNUNET_DNSPARSER_TYPE_SRV: | ||
721 | { | ||
722 | struct GNUNET_DNSPARSER_SrvRecord *srv; | ||
723 | size_t off; | ||
724 | |||
725 | off = 0; | ||
726 | srv = GNUNET_DNSPARSER_parse_srv ("+", /* FIXME: is this OK? */ | ||
727 | data, | ||
728 | data_size, | ||
729 | &off); | ||
730 | if ( (NULL == srv) || | ||
731 | (off != data_size) ) | ||
732 | { | ||
733 | GNUNET_break_op (0); | ||
734 | return NULL; | ||
735 | } | ||
736 | GNUNET_asprintf (&result, | ||
737 | "%d %d %d _%s._%s.%s", | ||
738 | srv->priority, | ||
739 | srv->weight, | ||
740 | srv->port, | ||
741 | srv->service, | ||
742 | srv->proto, | ||
743 | srv->domain_name); | ||
744 | GNUNET_DNSPARSER_free_srv (srv); | ||
745 | return result; | ||
746 | } | ||
747 | case GNUNET_DNSPARSER_TYPE_TLSA: | ||
748 | { | ||
749 | const struct GNUNET_TUN_DnsTlsaRecord *tlsa; | ||
750 | char* tlsa_str; | ||
751 | |||
752 | cdata = data; | ||
753 | if ( (data_size <= sizeof (struct GNUNET_TUN_DnsTlsaRecord)) || | ||
754 | ('\0' != cdata[data_size - 1]) ) | ||
755 | return NULL; /* malformed */ | ||
756 | tlsa = data; | ||
757 | if (0 == GNUNET_asprintf (&tlsa_str, | ||
758 | "%c %c %c %s", | ||
759 | tlsa->usage, | ||
760 | tlsa->selector, | ||
761 | tlsa->matching_type, | ||
762 | (const char *) &tlsa[1])) | ||
763 | { | ||
764 | GNUNET_free (tlsa_str); | ||
765 | return NULL; | ||
766 | } | ||
767 | return tlsa_str; | ||
768 | } | ||
769 | default: | ||
770 | GNUNET_break (0); | ||
771 | } | ||
772 | GNUNET_break (0); // not implemented | ||
773 | return NULL; | ||
774 | } | ||
775 | |||
776 | |||
777 | /** | ||
778 | * Convert human-readable version of a 'value' of a record to the binary | ||
779 | * representation. | ||
780 | * | ||
781 | * @param type type of the record | ||
782 | * @param s human-readable string | ||
783 | * @param data set to value in binary encoding (will be allocated) | ||
784 | * @param data_size set to number of bytes in @a data | ||
785 | * @return #GNUNET_OK on success | ||
786 | */ | ||
787 | int | ||
788 | GNUNET_NAMESTORE_string_to_value (uint32_t type, | ||
789 | const char *s, | ||
790 | void **data, | ||
791 | size_t *data_size) | ||
792 | { | ||
793 | struct in_addr value_a; | ||
794 | struct in6_addr value_aaaa; | ||
795 | struct GNUNET_CRYPTO_EcdsaPublicKey pkey; | ||
796 | struct GNUNET_TUN_GnsVpnRecord *vpn; | ||
797 | struct GNUNET_TUN_DnsTlsaRecord *tlsa; | ||
798 | char s_peer[103 + 1]; | ||
799 | char s_serv[253 + 1]; | ||
800 | unsigned int proto; | ||
801 | |||
802 | if (NULL == s) | ||
803 | return GNUNET_SYSERR; | ||
804 | switch (type) | ||
805 | { | ||
806 | case 0: | ||
807 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
808 | _("Unsupported record type %d\n"), | ||
809 | (int) type); | ||
810 | return GNUNET_SYSERR; | ||
811 | case GNUNET_DNSPARSER_TYPE_A: | ||
812 | if (1 != inet_pton (AF_INET, s, &value_a)) | ||
813 | { | ||
814 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
815 | _("Unable to parse IPv4 address `%s'\n"), | ||
816 | s); | ||
817 | return GNUNET_SYSERR; | ||
818 | } | ||
819 | *data = GNUNET_malloc (sizeof (struct in_addr)); | ||
820 | memcpy (*data, &value_a, sizeof (value_a)); | ||
821 | *data_size = sizeof (value_a); | ||
822 | return GNUNET_OK; | ||
823 | case GNUNET_DNSPARSER_TYPE_NS: | ||
824 | { | ||
825 | char nsbuf[256]; | ||
826 | size_t off; | ||
827 | |||
828 | off = 0; | ||
829 | if (GNUNET_OK != | ||
830 | GNUNET_DNSPARSER_builder_add_name (nsbuf, | ||
831 | sizeof (nsbuf), | ||
832 | &off, | ||
833 | s)) | ||
834 | { | ||
835 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
836 | _("Failed to serialize NS record with value `%s'\n"), | ||
837 | s); | ||
838 | return GNUNET_SYSERR; | ||
839 | } | ||
840 | *data_size = off; | ||
841 | *data = GNUNET_malloc (off); | ||
842 | memcpy (*data, nsbuf, off); | ||
843 | return GNUNET_OK; | ||
844 | } | ||
845 | case GNUNET_DNSPARSER_TYPE_CNAME: | ||
846 | { | ||
847 | char cnamebuf[256]; | ||
848 | size_t off; | ||
849 | |||
850 | off = 0; | ||
851 | if (GNUNET_OK != | ||
852 | GNUNET_DNSPARSER_builder_add_name (cnamebuf, | ||
853 | sizeof (cnamebuf), | ||
854 | &off, | ||
855 | s)) | ||
856 | { | ||
857 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
858 | _("Failed to serialize CNAME record with value `%s'\n"), | ||
859 | s); | ||
860 | return GNUNET_SYSERR; | ||
861 | } | ||
862 | *data_size = off; | ||
863 | *data = GNUNET_malloc (off); | ||
864 | memcpy (*data, cnamebuf, off); | ||
865 | return GNUNET_OK; | ||
866 | } | ||
867 | case GNUNET_DNSPARSER_TYPE_SOA: | ||
868 | { | ||
869 | struct GNUNET_DNSPARSER_SoaRecord soa; | ||
870 | char soabuf[540]; | ||
871 | char soa_rname[253 + 1]; | ||
872 | char soa_mname[253 + 1]; | ||
873 | unsigned int soa_serial; | ||
874 | unsigned int soa_refresh; | ||
875 | unsigned int soa_retry; | ||
876 | unsigned int soa_expire; | ||
877 | unsigned int soa_min; | ||
878 | size_t off; | ||
879 | |||
880 | if (7 != SSCANF (s, | ||
881 | "rname=%253s mname=%253s %u,%u,%u,%u,%u", | ||
882 | soa_rname, soa_mname, | ||
883 | &soa_serial, &soa_refresh, &soa_retry, &soa_expire, &soa_min)) | ||
884 | { | ||
885 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
886 | _("Unable to parse SOA record `%s'\n"), | ||
887 | s); | ||
888 | return GNUNET_SYSERR; | ||
889 | } | ||
890 | soa.mname = soa_mname; | ||
891 | soa.rname = soa_rname; | ||
892 | soa.serial = (uint32_t) soa_serial; | ||
893 | soa.refresh =(uint32_t) soa_refresh; | ||
894 | soa.retry = (uint32_t) soa_retry; | ||
895 | soa.expire = (uint32_t) soa_expire; | ||
896 | soa.minimum_ttl = (uint32_t) soa_min; | ||
897 | off = 0; | ||
898 | if (GNUNET_OK != | ||
899 | GNUNET_DNSPARSER_builder_add_soa (soabuf, | ||
900 | sizeof (soabuf), | ||
901 | &off, | ||
902 | &soa)) | ||
903 | { | ||
904 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
905 | _("Failed to serialize SOA record with mname `%s' and rname `%s'\n"), | ||
906 | soa_mname, | ||
907 | soa_rname); | ||
908 | return GNUNET_SYSERR; | ||
909 | } | ||
910 | *data_size = off; | ||
911 | *data = GNUNET_malloc (off); | ||
912 | memcpy (*data, soabuf, off); | ||
913 | return GNUNET_OK; | ||
914 | } | ||
915 | case GNUNET_DNSPARSER_TYPE_PTR: | ||
916 | { | ||
917 | char ptrbuf[256]; | ||
918 | size_t off; | ||
919 | |||
920 | off = 0; | ||
921 | if (GNUNET_OK != | ||
922 | GNUNET_DNSPARSER_builder_add_name (ptrbuf, | ||
923 | sizeof (ptrbuf), | ||
924 | &off, | ||
925 | s)) | ||
926 | { | ||
927 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
928 | _("Failed to serialize PTR record with value `%s'\n"), | ||
929 | s); | ||
930 | return GNUNET_SYSERR; | ||
931 | } | ||
932 | *data_size = off; | ||
933 | *data = GNUNET_malloc (off); | ||
934 | memcpy (*data, ptrbuf, off); | ||
935 | return GNUNET_OK; | ||
936 | } | ||
937 | case GNUNET_DNSPARSER_TYPE_MX: | ||
938 | { | ||
939 | struct GNUNET_DNSPARSER_MxRecord mx; | ||
940 | char mxbuf[258]; | ||
941 | char mxhost[253 + 1]; | ||
942 | uint16_t mx_pref; | ||
943 | size_t off; | ||
944 | |||
945 | if (2 != SSCANF(s, "%hu,%253s", &mx_pref, mxhost)) | ||
946 | { | ||
947 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
948 | _("Unable to parse MX record `%s'\n"), | ||
949 | s); | ||
950 | return GNUNET_SYSERR; | ||
951 | } | ||
952 | mx.preference = mx_pref; | ||
953 | mx.mxhost = mxhost; | ||
954 | off = 0; | ||
955 | |||
956 | if (GNUNET_OK != | ||
957 | GNUNET_DNSPARSER_builder_add_mx (mxbuf, | ||
958 | sizeof (mxbuf), | ||
959 | &off, | ||
960 | &mx)) | ||
961 | { | ||
962 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
963 | _("Failed to serialize MX record with hostname `%s'\n"), | ||
964 | mxhost); | ||
965 | return GNUNET_SYSERR; | ||
966 | } | ||
967 | *data_size = off; | ||
968 | *data = GNUNET_malloc (off); | ||
969 | memcpy (*data, mxbuf, off); | ||
970 | return GNUNET_OK; | ||
971 | } | ||
972 | case GNUNET_DNSPARSER_TYPE_TXT: | ||
973 | *data = GNUNET_strdup (s); | ||
974 | *data_size = strlen (s); | ||
975 | return GNUNET_OK; | ||
976 | case GNUNET_DNSPARSER_TYPE_AAAA: | ||
977 | if (1 != inet_pton (AF_INET6, s, &value_aaaa)) | ||
978 | { | ||
979 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
980 | _("Unable to parse IPv6 address `%s'\n"), | ||
981 | s); | ||
982 | return GNUNET_SYSERR; | ||
983 | } | ||
984 | *data = GNUNET_malloc (sizeof (struct in6_addr)); | ||
985 | *data_size = sizeof (struct in6_addr); | ||
986 | memcpy (*data, &value_aaaa, sizeof (value_aaaa)); | ||
987 | return GNUNET_OK; | ||
988 | case GNUNET_NAMESTORE_TYPE_PKEY: | ||
989 | if (GNUNET_OK != | ||
990 | GNUNET_CRYPTO_ecdsa_public_key_from_string (s, strlen (s), &pkey)) | ||
991 | { | ||
992 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
993 | _("Unable to parse PKEY record `%s'\n"), | ||
994 | s); | ||
995 | return GNUNET_SYSERR; | ||
996 | } | ||
997 | *data = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPublicKey); | ||
998 | memcpy (*data, &pkey, sizeof (pkey)); | ||
999 | *data_size = sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey); | ||
1000 | return GNUNET_OK; | ||
1001 | case GNUNET_NAMESTORE_TYPE_PHONE: | ||
1002 | { | ||
1003 | struct GNUNET_CONVERSATION_PhoneRecord *pr; | ||
1004 | unsigned int line; | ||
1005 | const char *dash; | ||
1006 | struct GNUNET_PeerIdentity peer; | ||
1007 | |||
1008 | if ( (NULL == (dash = strchr (s, '-'))) || | ||
1009 | (1 != sscanf (s, "%u-", &line)) || | ||
1010 | (GNUNET_OK != | ||
1011 | GNUNET_CRYPTO_eddsa_public_key_from_string (dash + 1, | ||
1012 | strlen (dash + 1), | ||
1013 | &peer.public_key)) ) | ||
1014 | { | ||
1015 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
1016 | _("Unable to parse PHONE record `%s'\n"), | ||
1017 | s); | ||
1018 | return GNUNET_SYSERR; | ||
1019 | } | ||
1020 | pr = GNUNET_new (struct GNUNET_CONVERSATION_PhoneRecord); | ||
1021 | pr->version = htonl (0); | ||
1022 | pr->line = htonl ((uint32_t) line); | ||
1023 | pr->peer = peer; | ||
1024 | *data = pr; | ||
1025 | *data_size = sizeof (struct GNUNET_CONVERSATION_PhoneRecord); | ||
1026 | return GNUNET_OK; | ||
1027 | } | ||
1028 | case GNUNET_NAMESTORE_TYPE_PSEU: | ||
1029 | *data = GNUNET_strdup (s); | ||
1030 | *data_size = strlen (s); | ||
1031 | return GNUNET_OK; | ||
1032 | case GNUNET_NAMESTORE_TYPE_LEHO: | ||
1033 | *data = GNUNET_strdup (s); | ||
1034 | *data_size = strlen (s); | ||
1035 | return GNUNET_OK; | ||
1036 | case GNUNET_NAMESTORE_TYPE_VPN: | ||
1037 | if (3 != SSCANF (s,"%u %103s %253s", | ||
1038 | &proto, s_peer, s_serv)) | ||
1039 | { | ||
1040 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
1041 | _("Unable to parse VPN record string `%s'\n"), | ||
1042 | s); | ||
1043 | return GNUNET_SYSERR; | ||
1044 | } | ||
1045 | *data_size = sizeof (struct GNUNET_TUN_GnsVpnRecord) + strlen (s_serv) + 1; | ||
1046 | *data = vpn = GNUNET_malloc (*data_size); | ||
1047 | if (GNUNET_OK != GNUNET_CRYPTO_eddsa_public_key_from_string ((char*) s_peer, | ||
1048 | strlen (s_peer), | ||
1049 | &vpn->peer.public_key)) | ||
1050 | { | ||
1051 | GNUNET_free (vpn); | ||
1052 | *data_size = 0; | ||
1053 | return GNUNET_SYSERR; | ||
1054 | } | ||
1055 | vpn->proto = htons ((uint16_t) proto); | ||
1056 | strcpy ((char*)&vpn[1], s_serv); | ||
1057 | return GNUNET_OK; | ||
1058 | case GNUNET_NAMESTORE_TYPE_GNS2DNS: | ||
1059 | { | ||
1060 | char nsbuf[256]; | ||
1061 | size_t off; | ||
1062 | |||
1063 | off = 0; | ||
1064 | if (GNUNET_OK != | ||
1065 | GNUNET_DNSPARSER_builder_add_name (nsbuf, | ||
1066 | sizeof (nsbuf), | ||
1067 | &off, | ||
1068 | s)) | ||
1069 | { | ||
1070 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
1071 | _("Failed to serialize GNS2DNS record with value `%s'\n"), | ||
1072 | s); | ||
1073 | return GNUNET_SYSERR; | ||
1074 | } | ||
1075 | *data_size = off; | ||
1076 | *data = GNUNET_malloc (off); | ||
1077 | memcpy (*data, nsbuf, off); | ||
1078 | return GNUNET_OK; | ||
1079 | } | ||
1080 | case GNUNET_DNSPARSER_TYPE_TLSA: | ||
1081 | *data_size = sizeof (struct GNUNET_TUN_DnsTlsaRecord) + strlen (s) - 6; | ||
1082 | *data = tlsa = GNUNET_malloc (*data_size); | ||
1083 | if (4 != SSCANF (s, "%c %c %c %s", | ||
1084 | &tlsa->usage, | ||
1085 | &tlsa->selector, | ||
1086 | &tlsa->matching_type, | ||
1087 | (char*)&tlsa[1])) | ||
1088 | { | ||
1089 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
1090 | _("Unable to parse TLSA record string `%s'\n"), | ||
1091 | s); | ||
1092 | *data_size = 0; | ||
1093 | GNUNET_free (tlsa); | ||
1094 | return GNUNET_SYSERR; | ||
1095 | } | ||
1096 | return GNUNET_OK; | ||
1097 | default: | ||
1098 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
1099 | _("Unsupported record type %d\n"), | ||
1100 | (int) type); | ||
1101 | return GNUNET_SYSERR; | ||
1102 | } | ||
1103 | } | ||
1104 | |||
1105 | |||
1106 | /** | ||
1107 | * Mapping of record type numbers to human-readable | ||
1108 | * record type names. | ||
1109 | */ | ||
1110 | static struct { | ||
1111 | const char *name; | ||
1112 | uint32_t number; | ||
1113 | } name_map[] = { | ||
1114 | { "A", GNUNET_DNSPARSER_TYPE_A }, | ||
1115 | { "NS", GNUNET_DNSPARSER_TYPE_NS }, | ||
1116 | { "CNAME", GNUNET_DNSPARSER_TYPE_CNAME }, | ||
1117 | { "SOA", GNUNET_DNSPARSER_TYPE_SOA }, | ||
1118 | { "PTR", GNUNET_DNSPARSER_TYPE_PTR }, | ||
1119 | { "MX", GNUNET_DNSPARSER_TYPE_MX }, | ||
1120 | { "TXT", GNUNET_DNSPARSER_TYPE_TXT }, | ||
1121 | { "AAAA", GNUNET_DNSPARSER_TYPE_AAAA }, | ||
1122 | { "PKEY", GNUNET_NAMESTORE_TYPE_PKEY }, | ||
1123 | { "PSEU", GNUNET_NAMESTORE_TYPE_PSEU }, | ||
1124 | { "LEHO", GNUNET_NAMESTORE_TYPE_LEHO }, | ||
1125 | { "VPN", GNUNET_NAMESTORE_TYPE_VPN }, | ||
1126 | { "GNS2DNS", GNUNET_NAMESTORE_TYPE_GNS2DNS }, | ||
1127 | { "PHONE", GNUNET_NAMESTORE_TYPE_PHONE }, | ||
1128 | { "TLSA", GNUNET_DNSPARSER_TYPE_TLSA }, | ||
1129 | { NULL, UINT32_MAX } | ||
1130 | }; | ||
1131 | |||
1132 | |||
1133 | /** | ||
1134 | * Convert a type name (i.e. "AAAA") to the corresponding number. | ||
1135 | * | ||
1136 | * @param dns_typename name to convert | ||
1137 | * @return corresponding number, UINT32_MAX on error | ||
1138 | */ | ||
1139 | uint32_t | ||
1140 | GNUNET_NAMESTORE_typename_to_number (const char *dns_typename) | ||
1141 | { | ||
1142 | unsigned int i; | ||
1143 | |||
1144 | i=0; | ||
1145 | while ( (name_map[i].name != NULL) && | ||
1146 | (0 != strcasecmp (dns_typename, name_map[i].name)) ) | ||
1147 | i++; | ||
1148 | return name_map[i].number; | ||
1149 | } | ||
1150 | |||
1151 | |||
1152 | /** | ||
1153 | * Convert a type number (i.e. 1) to the corresponding type string (i.e. "A") | ||
1154 | * | ||
1155 | * @param type number of a type to convert | ||
1156 | * @return corresponding typestring, NULL on error | ||
1157 | */ | ||
1158 | const char * | ||
1159 | GNUNET_NAMESTORE_number_to_typename (uint32_t type) | ||
1160 | { | ||
1161 | unsigned int i; | ||
1162 | |||
1163 | i=0; | ||
1164 | while ( (name_map[i].name != NULL) && | ||
1165 | (type != name_map[i].number) ) | ||
1166 | i++; | ||
1167 | return name_map[i].name; | ||
1168 | } | ||
1169 | |||
1170 | |||
1171 | /** | ||
1172 | * Test if a given record is expired. | 518 | * Test if a given record is expired. |
1173 | * | 519 | * |
1174 | * @return #GNUNET_YES if the record is expired, | 520 | * @return #GNUNET_YES if the record is expired, |
diff --git a/src/namestore/plugin_namestore_postgres.c b/src/namestore/plugin_namestore_postgres.c index 6a1dc6f2c..0f2721771 100644 --- a/src/namestore/plugin_namestore_postgres.c +++ b/src/namestore/plugin_namestore_postgres.c | |||
@@ -26,6 +26,7 @@ | |||
26 | #include "platform.h" | 26 | #include "platform.h" |
27 | #include "gnunet_namestore_plugin.h" | 27 | #include "gnunet_namestore_plugin.h" |
28 | #include "gnunet_namestore_service.h" | 28 | #include "gnunet_namestore_service.h" |
29 | #include "gnunet_gnsrecord_lib.h" | ||
29 | #include "gnunet_postgres_lib.h" | 30 | #include "gnunet_postgres_lib.h" |
30 | #include "namestore.h" | 31 | #include "namestore.h" |
31 | 32 | ||
diff --git a/src/namestore/plugin_namestore_sqlite.c b/src/namestore/plugin_namestore_sqlite.c index 729b916ca..9e303a427 100644 --- a/src/namestore/plugin_namestore_sqlite.c +++ b/src/namestore/plugin_namestore_sqlite.c | |||
@@ -27,6 +27,7 @@ | |||
27 | #include "platform.h" | 27 | #include "platform.h" |
28 | #include "gnunet_namestore_plugin.h" | 28 | #include "gnunet_namestore_plugin.h" |
29 | #include "gnunet_namestore_service.h" | 29 | #include "gnunet_namestore_service.h" |
30 | #include "gnunet_gnsrecord_lib.h" | ||
30 | #include "namestore.h" | 31 | #include "namestore.h" |
31 | #include <sqlite3.h> | 32 | #include <sqlite3.h> |
32 | 33 | ||