aboutsummaryrefslogtreecommitdiff
path: root/src/namestore
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-09-25 17:45:03 +0000
committerChristian Grothoff <christian@grothoff.org>2013-09-25 17:45:03 +0000
commit77f81b949fe89c8a316f49fc5fa75cd51c513468 (patch)
treee6c0ee5d40782e2fb8d604d42f0970a2aeb1bff4 /src/namestore
parent80a5a8965b3e28e6c1eb1a8a92c7b0189d87950b (diff)
downloadgnunet-77f81b949fe89c8a316f49fc5fa75cd51c513468.tar.gz
gnunet-77f81b949fe89c8a316f49fc5fa75cd51c513468.zip
-fix MX record parsing and serialization, others still to be fixed
Diffstat (limited to 'src/namestore')
-rw-r--r--src/namestore/Makefile.am1
-rw-r--r--src/namestore/namestore_api.c6
-rw-r--r--src/namestore/namestore_api_common.c77
3 files changed, 57 insertions, 27 deletions
diff --git a/src/namestore/Makefile.am b/src/namestore/Makefile.am
index 604288431..0cb08fc77 100644
--- a/src/namestore/Makefile.am
+++ b/src/namestore/Makefile.am
@@ -75,6 +75,7 @@ libgnunetnamestore_la_SOURCES = \
75 namestore.h 75 namestore.h
76libgnunetnamestore_la_LIBADD = \ 76libgnunetnamestore_la_LIBADD = \
77 $(top_builddir)/src/statistics/libgnunetstatistics.la \ 77 $(top_builddir)/src/statistics/libgnunetstatistics.la \
78 $(top_builddir)/src/dns/libgnunetdnsparser.la \
78 $(top_builddir)/src/util/libgnunetutil.la \ 79 $(top_builddir)/src/util/libgnunetutil.la \
79 $(GN_LIBINTL) 80 $(GN_LIBINTL)
80libgnunetnamestore_la_LDFLAGS = \ 81libgnunetnamestore_la_LDFLAGS = \
diff --git a/src/namestore/namestore_api.c b/src/namestore/namestore_api.c
index bf9f3ffb8..ff1630b92 100644
--- a/src/namestore/namestore_api.c
+++ b/src/namestore/namestore_api.c
@@ -822,9 +822,9 @@ do_transmit (struct GNUNET_NAMESTORE_Handle *h)
822 if (NULL == h->client) 822 if (NULL == h->client)
823 return; /* currently reconnecting */ 823 return; /* currently reconnecting */
824 h->th = GNUNET_CLIENT_notify_transmit_ready (h->client, p->size, 824 h->th = GNUNET_CLIENT_notify_transmit_ready (h->client, p->size,
825 GNUNET_TIME_UNIT_FOREVER_REL, 825 GNUNET_TIME_UNIT_FOREVER_REL,
826 GNUNET_NO, &transmit_message_to_namestore, 826 GNUNET_NO, &transmit_message_to_namestore,
827 h); 827 h);
828} 828}
829 829
830 830
diff --git a/src/namestore/namestore_api_common.c b/src/namestore/namestore_api_common.c
index 99af01a72..e33508821 100644
--- a/src/namestore/namestore_api_common.c
+++ b/src/namestore/namestore_api_common.c
@@ -509,7 +509,6 @@ GNUNET_NAMESTORE_value_to_string (uint32_t type,
509 const void *data, 509 const void *data,
510 size_t data_size) 510 size_t data_size)
511{ 511{
512 uint16_t mx_pref;
513 const struct GNUNET_TUN_DnsSoaRecord *soa; 512 const struct GNUNET_TUN_DnsSoaRecord *soa;
514 const struct GNUNET_TUN_GnsVpnRecord *vpn; 513 const struct GNUNET_TUN_GnsVpnRecord *vpn;
515 const struct GNUNET_TUN_DnsSrvRecord *srv; 514 const struct GNUNET_TUN_DnsSrvRecord *srv;
@@ -562,14 +561,26 @@ GNUNET_NAMESTORE_value_to_string (uint32_t type,
562 case GNUNET_DNSPARSER_TYPE_PTR: 561 case GNUNET_DNSPARSER_TYPE_PTR:
563 return GNUNET_strndup (data, data_size); 562 return GNUNET_strndup (data, data_size);
564 case GNUNET_DNSPARSER_TYPE_MX: 563 case GNUNET_DNSPARSER_TYPE_MX:
565 mx_pref = ntohs(*((uint16_t*)data));
566 if (GNUNET_asprintf(&result, "%hu,%s", mx_pref, data+sizeof(uint16_t))
567 != 0)
568 return result;
569 else
570 { 564 {
571 GNUNET_free (result); 565 struct GNUNET_DNSPARSER_MxRecord *mx;
572 return NULL; 566 size_t off;
567
568 off = 0;
569 mx = GNUNET_DNSPARSER_parse_mx (data,
570 data_size,
571 &off);
572 if ( (NULL == mx) ||
573 (off != data_size) )
574 {
575 GNUNET_break_op (0);
576 return NULL;
577 }
578 GNUNET_asprintf (&result,
579 "%hu,%s",
580 mx->preference,
581 mx->mxhost);
582 GNUNET_DNSPARSER_free_mx (mx);
583 return result;
573 } 584 }
574 case GNUNET_DNSPARSER_TYPE_TXT: 585 case GNUNET_DNSPARSER_TYPE_TXT:
575 return GNUNET_strndup (data, data_size); 586 return GNUNET_strndup (data, data_size);
@@ -653,8 +664,8 @@ GNUNET_NAMESTORE_value_to_string (uint32_t type,
653 * @param type type of the record 664 * @param type type of the record
654 * @param s human-readable string 665 * @param s human-readable string
655 * @param data set to value in binary encoding (will be allocated) 666 * @param data set to value in binary encoding (will be allocated)
656 * @param data_size set to number of bytes in data 667 * @param data_size set to number of bytes in @a data
657 * @return GNUNET_OK on success 668 * @return #GNUNET_OK on success
658 */ 669 */
659int 670int
660GNUNET_NAMESTORE_string_to_value (uint32_t type, 671GNUNET_NAMESTORE_string_to_value (uint32_t type,
@@ -668,7 +679,6 @@ GNUNET_NAMESTORE_string_to_value (uint32_t type,
668 struct GNUNET_TUN_DnsSoaRecord *soa; 679 struct GNUNET_TUN_DnsSoaRecord *soa;
669 struct GNUNET_TUN_GnsVpnRecord *vpn; 680 struct GNUNET_TUN_GnsVpnRecord *vpn;
670 struct GNUNET_TUN_DnsTlsaRecord *tlsa; 681 struct GNUNET_TUN_DnsTlsaRecord *tlsa;
671 char result[253 + 1];
672 char soa_rname[253 + 1]; 682 char soa_rname[253 + 1];
673 char soa_mname[253 + 1]; 683 char soa_mname[253 + 1];
674 char s_peer[103 + 1]; 684 char s_peer[103 + 1];
@@ -678,8 +688,6 @@ GNUNET_NAMESTORE_string_to_value (uint32_t type,
678 unsigned int soa_retry; 688 unsigned int soa_retry;
679 unsigned int soa_expire; 689 unsigned int soa_expire;
680 unsigned int soa_min; 690 unsigned int soa_min;
681 uint16_t mx_pref;
682 uint16_t mx_pref_n;
683 unsigned int proto; 691 unsigned int proto;
684 692
685 if (NULL == s) 693 if (NULL == s)
@@ -722,7 +730,7 @@ GNUNET_NAMESTORE_string_to_value (uint32_t type,
722 s); 730 s);
723 return GNUNET_SYSERR; 731 return GNUNET_SYSERR;
724 } 732 }
725 *data_size = sizeof (struct GNUNET_TUN_DnsSoaRecord)+strlen(soa_rname)+strlen(soa_mname)+2; 733 *data_size = sizeof (struct GNUNET_TUN_DnsSoaRecord) + strlen(soa_rname) + strlen(soa_mname) + 2;
726 *data = GNUNET_malloc (*data_size); 734 *data = GNUNET_malloc (*data_size);
727 soa = (struct GNUNET_TUN_DnsSoaRecord*)*data; 735 soa = (struct GNUNET_TUN_DnsSoaRecord*)*data;
728 soa->serial = htonl(soa_serial); 736 soa->serial = htonl(soa_serial);
@@ -738,19 +746,40 @@ GNUNET_NAMESTORE_string_to_value (uint32_t type,
738 *data_size = strlen (s); 746 *data_size = strlen (s);
739 return GNUNET_OK; 747 return GNUNET_OK;
740 case GNUNET_DNSPARSER_TYPE_MX: 748 case GNUNET_DNSPARSER_TYPE_MX:
741 if (2 != SSCANF(s, "%hu,%253s", &mx_pref, result))
742 { 749 {
743 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 750 struct GNUNET_DNSPARSER_MxRecord mx;
744 _("Unable to parse MX record `%s'\n"), 751 char mxbuf[258];
745 s); 752 char mxhost[253 + 1];
753 uint16_t mx_pref;
754 size_t off;
755
756 if (2 != SSCANF(s, "%hu,%253s", &mx_pref, mxhost))
757 {
758 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
759 _("Unable to parse MX record `%s'\n"),
760 s);
746 return GNUNET_SYSERR; 761 return GNUNET_SYSERR;
762 }
763 mx.preference = mx_pref;
764 mx.mxhost = mxhost;
765 off = 0;
766
767 if (GNUNET_OK !=
768 GNUNET_DNSPARSER_builder_add_mx (mxbuf,
769 sizeof (mxbuf),
770 &off,
771 &mx))
772 {
773 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
774 _("Failed to serialize MX record with hostname `%s'\n"),
775 mxhost);
776 return GNUNET_SYSERR;
777 }
778 *data_size = off;
779 *data = GNUNET_malloc (off);
780 memcpy (*data, mxbuf, off);
781 return GNUNET_OK;
747 } 782 }
748 *data_size = sizeof (uint16_t)+strlen(result)+1;
749 *data = GNUNET_malloc (*data_size);
750 mx_pref_n = htons(mx_pref);
751 memcpy(*data, &mx_pref_n, sizeof (uint16_t));
752 strcpy((*data)+sizeof (uint16_t), result);
753 return GNUNET_OK;
754 case GNUNET_DNSPARSER_TYPE_TXT: 783 case GNUNET_DNSPARSER_TYPE_TXT:
755 *data = GNUNET_strdup (s); 784 *data = GNUNET_strdup (s);
756 *data_size = strlen (s); 785 *data_size = strlen (s);