aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-10-16 11:34:10 +0000
committerChristian Grothoff <christian@grothoff.org>2013-10-16 11:34:10 +0000
commitb6bfed8309e6b9b3286b8f608ad899bfb0a97205 (patch)
tree46cadaba7deadf7cb07dcc0b3d07f28fc147ffc2 /src
parent5ad45d439b900ea388b93aca8547ad03c53ddc68 (diff)
downloadgnunet-b6bfed8309e6b9b3286b8f608ad899bfb0a97205.tar.gz
gnunet-b6bfed8309e6b9b3286b8f608ad899bfb0a97205.zip
-moving code to new libgnunetgnsrecord in preparation for addressing #3052
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am3
-rw-r--r--src/conversation/Makefile.am39
-rw-r--r--src/conversation/conversation_api.c1
-rw-r--r--src/conversation/gnunet-conversation.c1
-rw-r--r--src/gns/Makefile.am17
-rw-r--r--src/gns/gnunet-gns.c1
-rw-r--r--src/gns/gnunet-service-gns_resolver.c25
-rw-r--r--src/gns/gnunet-service-gns_shorten.c3
-rw-r--r--src/gnsrecord/Makefile.am39
-rw-r--r--src/gnsrecord/gnsrecord.c696
-rw-r--r--src/include/Makefile.am1
-rw-r--r--src/include/gnunet_namestore_service.h93
-rw-r--r--src/namestore/Makefile.am6
-rw-r--r--src/namestore/gnunet-namestore-fcfsd.c5
-rw-r--r--src/namestore/gnunet-namestore.c1
-rw-r--r--src/namestore/namestore_api_common.c654
-rw-r--r--src/namestore/plugin_namestore_postgres.c1
-rw-r--r--src/namestore/plugin_namestore_sqlite.c1
18 files changed, 795 insertions, 792 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 8746a47e2..3fd2d8e86 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -70,6 +70,7 @@ SUBDIRS = \
70 set \ 70 set \
71 dv \ 71 dv \
72 revocation \ 72 revocation \
73 gnsrecord \
73 namestore \ 74 namestore \
74 vpn \ 75 vpn \
75 gns \ 76 gns \
@@ -79,4 +80,4 @@ SUBDIRS = \
79 exit \ 80 exit \
80 pt \ 81 pt \
81 integration-tests \ 82 integration-tests \
82 $(EXP_DIR) 83 $(EXP_DIR)
diff --git a/src/conversation/Makefile.am b/src/conversation/Makefile.am
index bb2b3d77d..5e4ad0d67 100644
--- a/src/conversation/Makefile.am
+++ b/src/conversation/Makefile.am
@@ -17,7 +17,7 @@ pkgcfgdir= $(prefix)/share/gnunet/config.d/
17libexecdir= $(prefix)/lib/gnunet/libexec/ 17libexecdir= $(prefix)/lib/gnunet/libexec/
18 18
19libgnunetmicrophone_la_SOURCES = \ 19libgnunetmicrophone_la_SOURCES = \
20 microphone.c 20 microphone.c
21libgnunetmicrophone_la_LIBADD = \ 21libgnunetmicrophone_la_LIBADD = \
22 $(top_builddir)/src/util/libgnunetutil.la 22 $(top_builddir)/src/util/libgnunetutil.la
23libgnunetmicrophone_la_LDFLAGS = \ 23libgnunetmicrophone_la_LDFLAGS = \
@@ -25,7 +25,7 @@ libgnunetmicrophone_la_LDFLAGS = \
25 -version-info 0:0:0 25 -version-info 0:0:0
26 26
27libgnunetspeaker_la_SOURCES = \ 27libgnunetspeaker_la_SOURCES = \
28 speaker.c 28 speaker.c
29libgnunetspeaker_la_LIBADD = \ 29libgnunetspeaker_la_LIBADD = \
30 $(top_builddir)/src/util/libgnunetutil.la 30 $(top_builddir)/src/util/libgnunetutil.la
31libgnunetspeaker_la_LDFLAGS = \ 31libgnunetspeaker_la_LDFLAGS = \
@@ -34,12 +34,12 @@ libgnunetspeaker_la_LDFLAGS = \
34 34
35 35
36libgnunetconversation_la_SOURCES = \ 36libgnunetconversation_la_SOURCES = \
37 conversation_api.c 37 conversation_api.c
38libgnunetconversation_la_LIBADD = \ 38libgnunetconversation_la_LIBADD = \
39 $(top_builddir)/src/gns/libgnunetgns.la \ 39 $(top_builddir)/src/gns/libgnunetgns.la \
40 $(top_builddir)/src/namestore/libgnunetnamestore.la \ 40 $(top_builddir)/src/namestore/libgnunetnamestore.la \
41 $(top_builddir)/src/identity/libgnunetidentity.la \ 41 $(top_builddir)/src/identity/libgnunetidentity.la \
42 $(top_builddir)/src/util/libgnunetutil.la 42 $(top_builddir)/src/util/libgnunetutil.la
43 43
44libgnunetconversation_la_LDFLAGS = \ 44libgnunetconversation_la_LDFLAGS = \
45 $(GNUNET_LDFLAGS) $(WINFLAGS) \ 45 $(GNUNET_LDFLAGS) $(WINFLAGS) \
@@ -48,10 +48,10 @@ libgnunetconversation_la_LDFLAGS = \
48 48
49bin_PROGRAMS = \ 49bin_PROGRAMS = \
50 gnunet-conversation-test \ 50 gnunet-conversation-test \
51 gnunet-conversation 51 gnunet-conversation
52 52
53libexec_PROGRAMS = \ 53libexec_PROGRAMS = \
54 gnunet-service-conversation 54 gnunet-service-conversation
55 55
56if HAVE_PULSE 56if HAVE_PULSE
57if HAVE_OPUS 57if HAVE_OPUS
@@ -64,7 +64,7 @@ endif
64 64
65 65
66check_PROGRAMS = \ 66check_PROGRAMS = \
67 test_conversation_api 67 test_conversation_api
68 68
69TESTS = $(check_PROGRAMS) 69TESTS = $(check_PROGRAMS)
70 70
@@ -74,18 +74,18 @@ gnunet_helper_audio_record_SOURCES = \
74gnunet_helper_audio_record_LDADD = \ 74gnunet_helper_audio_record_LDADD = \
75 $(top_builddir)/src/util/libgnunetutil.la \ 75 $(top_builddir)/src/util/libgnunetutil.la \
76 -lpulse -lopus\ 76 -lpulse -lopus\
77 $(INTLLIBS) 77 $(INTLLIBS)
78gnunet_helper_audio_record_LDFLAGS = \ 78gnunet_helper_audio_record_LDFLAGS = \
79 $(GNUNET_LDFLAGS) $(WINFLAGS) 79 $(GNUNET_LDFLAGS) $(WINFLAGS)
80 80
81gnunet_helper_audio_playback_SOURCES = \ 81gnunet_helper_audio_playback_SOURCES = \
82 gnunet-helper-audio-playback.c 82 gnunet-helper-audio-playback.c
83gnunet_helper_audio_playback_LDADD = \ 83gnunet_helper_audio_playback_LDADD = \
84 $(top_builddir)/src/util/libgnunetutil.la \ 84 $(top_builddir)/src/util/libgnunetutil.la \
85 -lpulse -lopus\ 85 -lpulse -lopus\
86 $(INTLLIBS) 86 $(INTLLIBS)
87gnunet_helper_audio_playback_LDFLAGS = \ 87gnunet_helper_audio_playback_LDFLAGS = \
88 $(GNUNET_LDFLAGS) $(WINFLAGS) 88 $(GNUNET_LDFLAGS) $(WINFLAGS)
89 89
90gnunet_service_conversation_SOURCES = \ 90gnunet_service_conversation_SOURCES = \
91 gnunet-service-conversation.c 91 gnunet-service-conversation.c
@@ -95,9 +95,9 @@ gnunet_service_conversation_LDADD = \
95 libgnunetmicrophone.la \ 95 libgnunetmicrophone.la \
96 $(top_builddir)/src/mesh/libgnunetmesh.la \ 96 $(top_builddir)/src/mesh/libgnunetmesh.la \
97 $(top_builddir)/src/util/libgnunetutil.la \ 97 $(top_builddir)/src/util/libgnunetutil.la \
98 $(INTLLIBS) 98 $(INTLLIBS)
99gnunet_service_conversation_LDFLAGS = \ 99gnunet_service_conversation_LDFLAGS = \
100 $(GNUNET_LDFLAGS) $(WINFLAGS) 100 $(GNUNET_LDFLAGS) $(WINFLAGS)
101 101
102gnunet_conversation_SOURCES = \ 102gnunet_conversation_SOURCES = \
103 gnunet-conversation.c 103 gnunet-conversation.c
@@ -106,12 +106,13 @@ gnunet_conversation_LDADD = \
106 libgnunetspeaker.la \ 106 libgnunetspeaker.la \
107 libgnunetconversation.la \ 107 libgnunetconversation.la \
108 $(top_builddir)/src/gns/libgnunetgns.la \ 108 $(top_builddir)/src/gns/libgnunetgns.la \
109 $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \
109 $(top_builddir)/src/namestore/libgnunetnamestore.la \ 110 $(top_builddir)/src/namestore/libgnunetnamestore.la \
110 $(top_builddir)/src/identity/libgnunetidentity.la \ 111 $(top_builddir)/src/identity/libgnunetidentity.la \
111 $(top_builddir)/src/util/libgnunetutil.la \ 112 $(top_builddir)/src/util/libgnunetutil.la \
112 $(INTLLIBS) 113 $(INTLLIBS)
113gnunet_conversation_LDFLAGS = \ 114gnunet_conversation_LDFLAGS = \
114 $(GNUNET_LDFLAGS) $(WINFLAGS) 115 $(GNUNET_LDFLAGS) $(WINFLAGS)
115 116
116gnunet_conversation_test_SOURCES = \ 117gnunet_conversation_test_SOURCES = \
117 gnunet-conversation-test.c 118 gnunet-conversation-test.c
@@ -119,17 +120,17 @@ gnunet_conversation_test_LDADD = \
119 libgnunetmicrophone.la \ 120 libgnunetmicrophone.la \
120 libgnunetspeaker.la \ 121 libgnunetspeaker.la \
121 $(top_builddir)/src/util/libgnunetutil.la \ 122 $(top_builddir)/src/util/libgnunetutil.la \
122 $(INTLLIBS) 123 $(INTLLIBS)
123gnunet_conversation_test_LDFLAGS = \ 124gnunet_conversation_test_LDFLAGS = \
124 $(GNUNET_LDFLAGS) $(WINFLAGS) 125 $(GNUNET_LDFLAGS) $(WINFLAGS)
125 126
126 127
127test_conversation_api_SOURCES = \ 128test_conversation_api_SOURCES = \
128 test_conversation_api.c 129 test_conversation_api.c
129test_conversation_api_LDADD = \ 130test_conversation_api_LDADD = \
130 libgnunetconversation.la \ 131 libgnunetconversation.la \
131 $(top_builddir)/src/util/libgnunetutil.la 132 $(top_builddir)/src/util/libgnunetutil.la
132test_conversation_api_LDFLAGS = \ 133test_conversation_api_LDFLAGS = \
133 $(GNUNET_LDFLAGS) $(WINFLAGS) -export-dynamic 134 $(GNUNET_LDFLAGS) $(WINFLAGS) -export-dynamic
134 135
135 pkgcfg_DATA = conversation.conf 136 pkgcfg_DATA = conversation.conf
diff --git a/src/conversation/conversation_api.c b/src/conversation/conversation_api.c
index 4f182d63b..aca0155c8 100644
--- a/src/conversation/conversation_api.c
+++ b/src/conversation/conversation_api.c
@@ -27,6 +27,7 @@
27 */ 27 */
28#include "platform.h" 28#include "platform.h"
29#include "gnunet_conversation_service.h" 29#include "gnunet_conversation_service.h"
30#include "gnunet_gnsrecord_lib.h"
30#include "gnunet_gns_service.h" 31#include "gnunet_gns_service.h"
31#include "conversation.h" 32#include "conversation.h"
32 33
diff --git a/src/conversation/gnunet-conversation.c b/src/conversation/gnunet-conversation.c
index 113c10098..d2122d104 100644
--- a/src/conversation/gnunet-conversation.c
+++ b/src/conversation/gnunet-conversation.c
@@ -26,6 +26,7 @@
26#include "platform.h" 26#include "platform.h"
27#include "gnunet_util_lib.h" 27#include "gnunet_util_lib.h"
28#include "gnunet_constants.h" 28#include "gnunet_constants.h"
29#include "gnunet_gnsrecord_lib.h"
29#include "gnunet_conversation_service.h" 30#include "gnunet_conversation_service.h"
30#include "gnunet_namestore_service.h" 31#include "gnunet_namestore_service.h"
31 32
diff --git a/src/gns/Makefile.am b/src/gns/Makefile.am
index e18a99fad..a3222482c 100644
--- a/src/gns/Makefile.am
+++ b/src/gns/Makefile.am
@@ -58,12 +58,12 @@ endif
58libexec_PROGRAMS = \ 58libexec_PROGRAMS = \
59 gnunet-service-gns \ 59 gnunet-service-gns \
60 $(DO_W32_HELPER) \ 60 $(DO_W32_HELPER) \
61 gnunet-dns2gns 61 gnunet-dns2gns
62# $(DO_PROXY) 62# $(DO_PROXY)
63 63
64bin_PROGRAMS = \ 64bin_PROGRAMS = \
65 $(DO_W32_NSPTOOLS) \ 65 $(DO_W32_NSPTOOLS) \
66 gnunet-gns 66 gnunet-gns
67 67
68bin_SCRIPTS = gnunet-gns-proxy-setup-ca 68bin_SCRIPTS = gnunet-gns-proxy-setup-ca
69 69
@@ -74,6 +74,7 @@ gnunet_gns_SOURCES = \
74 gnunet-gns.c 74 gnunet-gns.c
75gnunet_gns_LDADD = \ 75gnunet_gns_LDADD = \
76 $(top_builddir)/src/gns/libgnunetgns.la \ 76 $(top_builddir)/src/gns/libgnunetgns.la \
77 $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \
77 $(top_builddir)/src/namestore/libgnunetnamestore.la \ 78 $(top_builddir)/src/namestore/libgnunetnamestore.la \
78 $(top_builddir)/src/identity/libgnunetidentity.la \ 79 $(top_builddir)/src/identity/libgnunetidentity.la \
79 $(top_builddir)/src/util/libgnunetutil.la \ 80 $(top_builddir)/src/util/libgnunetutil.la \
@@ -103,7 +104,7 @@ gnunet_dns2gns_DEPENDENCIES = \
103 libgnunetgns.la 104 libgnunetgns.la
104 105
105gnunet_gns_proxy_SOURCES = \ 106gnunet_gns_proxy_SOURCES = \
106 gnunet-gns-proxy.c 107 gnunet-gns-proxy.c
107gnunet_gns_proxy_LDADD = -lmicrohttpd -lcurl -lgnutls \ 108gnunet_gns_proxy_LDADD = -lmicrohttpd -lcurl -lgnutls \
108 $(top_builddir)/src/gns/libgnunetgns.la \ 109 $(top_builddir)/src/gns/libgnunetgns.la \
109 $(top_builddir)/src/identity/libgnunetidentity.la \ 110 $(top_builddir)/src/identity/libgnunetidentity.la \
@@ -140,7 +141,7 @@ gnunet_service_gns_SOURCES = \
140 gnunet-service-gns.c \ 141 gnunet-service-gns.c \
141 gnunet-service-gns_resolver.c gnunet-service-gns_resolver.h \ 142 gnunet-service-gns_resolver.c gnunet-service-gns_resolver.h \
142 gnunet-service-gns_shorten.c gnunet-service-gns_shorten.h \ 143 gnunet-service-gns_shorten.c gnunet-service-gns_shorten.h \
143 gnunet-service-gns_interceptor.c gnunet-service-gns_interceptor.h 144 gnunet-service-gns_interceptor.c gnunet-service-gns_interceptor.h
144gnunet_service_gns_LDADD = \ 145gnunet_service_gns_LDADD = \
145 -lm \ 146 -lm \
146 $(top_builddir)/src/statistics/libgnunetstatistics.la \ 147 $(top_builddir)/src/statistics/libgnunetstatistics.la \
@@ -206,9 +207,9 @@ check_SCRIPTS = \
206 test_gns_ns_lookup.sh \ 207 test_gns_ns_lookup.sh \
207 test_gns_dht_lookup.sh\ 208 test_gns_dht_lookup.sh\
208 test_gns_pseu_shorten.sh\ 209 test_gns_pseu_shorten.sh\
209 test_gns_plus_lookup.sh\ 210 test_gns_plus_lookup.sh\
210 test_gns_zkey_lookup.sh\ 211 test_gns_zkey_lookup.sh\
211 test_gns_cname_lookup.sh 212 test_gns_cname_lookup.sh
212 213
213if ENABLE_TEST_RUN 214if ENABLE_TEST_RUN
214if HAVE_SQLITE 215if HAVE_SQLITE
diff --git a/src/gns/gnunet-gns.c b/src/gns/gnunet-gns.c
index 0a4275f0d..6772844b8 100644
--- a/src/gns/gnunet-gns.c
+++ b/src/gns/gnunet-gns.c
@@ -26,6 +26,7 @@
26#include <gnunet_util_lib.h> 26#include <gnunet_util_lib.h>
27#include <gnunet_dnsparser_lib.h> 27#include <gnunet_dnsparser_lib.h>
28#include <gnunet_identity_service.h> 28#include <gnunet_identity_service.h>
29#include <gnunet_gnsrecord_lib.h>
29#include <gnunet_namestore_service.h> 30#include <gnunet_namestore_service.h>
30#include <gnunet_gns_service.h> 31#include <gnunet_gns_service.h>
31 32
diff --git a/src/gns/gnunet-service-gns_resolver.c b/src/gns/gnunet-service-gns_resolver.c
index 4b26803ff..f8b7e1a42 100644
--- a/src/gns/gnunet-service-gns_resolver.c
+++ b/src/gns/gnunet-service-gns_resolver.c
@@ -34,6 +34,7 @@
34#include "gnunet_util_lib.h" 34#include "gnunet_util_lib.h"
35#include "gnunet_dnsstub_lib.h" 35#include "gnunet_dnsstub_lib.h"
36#include "gnunet_dht_service.h" 36#include "gnunet_dht_service.h"
37#include "gnunet_gnsrecord_lib.h"
37#include "gnunet_namestore_service.h" 38#include "gnunet_namestore_service.h"
38#include "gnunet_dns_service.h" 39#include "gnunet_dns_service.h"
39#include "gnunet_resolver_service.h" 40#include "gnunet_resolver_service.h"
@@ -853,7 +854,7 @@ dns_result_parser (void *cls,
853 continue; 854 continue;
854 } 855 }
855 rd[i - skip].data_size = buf_off - buf_start; 856 rd[i - skip].data_size = buf_off - buf_start;
856 rd[i - skip].data = &buf[buf_start]; 857 rd[i - skip].data = &buf[buf_start];
857 break; 858 break;
858 case GNUNET_DNSPARSER_TYPE_SOA: 859 case GNUNET_DNSPARSER_TYPE_SOA:
859 buf_start = buf_off; 860 buf_start = buf_off;
@@ -868,7 +869,7 @@ dns_result_parser (void *cls,
868 continue; 869 continue;
869 } 870 }
870 rd[i - skip].data_size = buf_off - buf_start; 871 rd[i - skip].data_size = buf_off - buf_start;
871 rd[i - skip].data = &buf[buf_start]; 872 rd[i - skip].data = &buf[buf_start];
872 break; 873 break;
873 case GNUNET_DNSPARSER_TYPE_MX: 874 case GNUNET_DNSPARSER_TYPE_MX:
874 buf_start = buf_off; 875 buf_start = buf_off;
@@ -883,7 +884,7 @@ dns_result_parser (void *cls,
883 continue; 884 continue;
884 } 885 }
885 rd[i - skip].data_size = buf_off - buf_start; 886 rd[i - skip].data_size = buf_off - buf_start;
886 rd[i - skip].data = &buf[buf_start]; 887 rd[i - skip].data = &buf[buf_start];
887 break; 888 break;
888 case GNUNET_DNSPARSER_TYPE_SRV: 889 case GNUNET_DNSPARSER_TYPE_SRV:
889 buf_start = buf_off; 890 buf_start = buf_off;
@@ -898,7 +899,7 @@ dns_result_parser (void *cls,
898 continue; 899 continue;
899 } 900 }
900 rd[i - skip].data_size = buf_off - buf_start; 901 rd[i - skip].data_size = buf_off - buf_start;
901 rd[i - skip].data = &buf[buf_start]; 902 rd[i - skip].data = &buf[buf_start];
902 break; 903 break;
903 default: 904 default:
904 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 905 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
@@ -1187,7 +1188,7 @@ handle_gns_resolution_result (void *cls,
1187 GNUNET_break_op (0); 1188 GNUNET_break_op (0);
1188 rh->proc (rh->proc_cls, 0, NULL); 1189 rh->proc (rh->proc_cls, 0, NULL);
1189 GNS_resolver_lookup_cancel (rh); 1190 GNS_resolver_lookup_cancel (rh);
1190 return; 1191 return;
1191 } 1192 }
1192 handle_gns_cname_result (rh, 1193 handle_gns_cname_result (rh,
1193 cname); 1194 cname);
@@ -1301,7 +1302,7 @@ handle_gns_resolution_result (void *cls,
1301 rd_off++; 1302 rd_off++;
1302 } 1303 }
1303 } 1304 }
1304 GNUNET_free_non_null (cname); 1305 GNUNET_free_non_null (cname);
1305 } 1306 }
1306 break; 1307 break;
1307 case GNUNET_DNSPARSER_TYPE_SOA: 1308 case GNUNET_DNSPARSER_TYPE_SOA:
@@ -1338,7 +1339,7 @@ handle_gns_resolution_result (void *cls,
1338 } 1339 }
1339 } 1340 }
1340 if (NULL != soa) 1341 if (NULL != soa)
1341 GNUNET_DNSPARSER_free_soa (soa); 1342 GNUNET_DNSPARSER_free_soa (soa);
1342 } 1343 }
1343 break; 1344 break;
1344 case GNUNET_DNSPARSER_TYPE_MX: 1345 case GNUNET_DNSPARSER_TYPE_MX:
@@ -1374,8 +1375,8 @@ handle_gns_resolution_result (void *cls,
1374 } 1375 }
1375 } 1376 }
1376 if (NULL != mx) 1377 if (NULL != mx)
1377 GNUNET_DNSPARSER_free_mx (mx); 1378 GNUNET_DNSPARSER_free_mx (mx);
1378 } 1379 }
1379 break; 1380 break;
1380 case GNUNET_DNSPARSER_TYPE_SRV: 1381 case GNUNET_DNSPARSER_TYPE_SRV:
1381 { 1382 {
@@ -1414,7 +1415,7 @@ handle_gns_resolution_result (void *cls,
1414 } 1415 }
1415 } 1416 }
1416 if (NULL != srv) 1417 if (NULL != srv)
1417 GNUNET_DNSPARSER_free_srv (srv); 1418 GNUNET_DNSPARSER_free_srv (srv);
1418 } 1419 }
1419 break; 1420 break;
1420 case GNUNET_NAMESTORE_TYPE_PKEY: 1421 case GNUNET_NAMESTORE_TYPE_PKEY:
@@ -1422,7 +1423,7 @@ handle_gns_resolution_result (void *cls,
1422 if (NULL != rh->shorten_key) 1423 if (NULL != rh->shorten_key)
1423 { 1424 {
1424 struct GNUNET_CRYPTO_EcdsaPublicKey pub; 1425 struct GNUNET_CRYPTO_EcdsaPublicKey pub;
1425 1426
1426 if (rd[i].data_size != sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)) 1427 if (rd[i].data_size != sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))
1427 { 1428 {
1428 GNUNET_break_op (0); 1429 GNUNET_break_op (0);
@@ -1610,7 +1611,7 @@ handle_gns_resolution_result (void *cls,
1610 case GNUNET_DNSPARSER_TYPE_CNAME: 1611 case GNUNET_DNSPARSER_TYPE_CNAME:
1611 { 1612 {
1612 char *cname; 1613 char *cname;
1613 1614
1614 off = 0; 1615 off = 0;
1615 cname = GNUNET_DNSPARSER_parse_name (rd[i].data, 1616 cname = GNUNET_DNSPARSER_parse_name (rd[i].data,
1616 rd[i].data_size, 1617 rd[i].data_size,
diff --git a/src/gns/gnunet-service-gns_shorten.c b/src/gns/gnunet-service-gns_shorten.c
index f0c96716a..3d3ac0094 100644
--- a/src/gns/gnunet-service-gns_shorten.c
+++ b/src/gns/gnunet-service-gns_shorten.c
@@ -27,6 +27,7 @@
27#include "platform.h" 27#include "platform.h"
28#include "gnunet_util_lib.h" 28#include "gnunet_util_lib.h"
29#include "gnunet_dht_service.h" 29#include "gnunet_dht_service.h"
30#include "gnunet_gnsrecord_lib.h"
30#include "gnunet_namestore_service.h" 31#include "gnunet_namestore_service.h"
31#include "gnunet_resolver_service.h" 32#include "gnunet_resolver_service.h"
32#include "gnunet_gns_service.h" 33#include "gnunet_gns_service.h"
@@ -492,7 +493,7 @@ process_zone_to_name_discover (void *cls,
492 } 493 }
493 /* record does not yet exist, go into DHT to find PSEU record */ 494 /* record does not yet exist, go into DHT to find PSEU record */
494 GNUNET_NAMESTORE_query_from_public_key (&gph->target_zone, 495 GNUNET_NAMESTORE_query_from_public_key (&gph->target_zone,
495 GNUNET_GNS_TLD_PLUS, 496 GNUNET_GNS_TLD_PLUS,
496 &lookup_key); 497 &lookup_key);
497 gph->timeout_task = GNUNET_SCHEDULER_add_delayed (DHT_LOOKUP_TIMEOUT, 498 gph->timeout_task = GNUNET_SCHEDULER_add_delayed (DHT_LOOKUP_TIMEOUT,
498 &handle_auth_discovery_timeout, 499 &handle_auth_discovery_timeout,
diff --git a/src/gnsrecord/Makefile.am b/src/gnsrecord/Makefile.am
new file mode 100644
index 000000000..185a5312b
--- /dev/null
+++ b/src/gnsrecord/Makefile.am
@@ -0,0 +1,39 @@
1AM_CPPFLAGS = -I$(top_srcdir)/src/include
2
3plugindir = $(libdir)/gnunet
4
5pkgcfgdir= $(pkgdatadir)/config.d/
6
7libexecdir= $(pkglibdir)/libexec/
8
9if MINGW
10 WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols
11endif
12
13if USE_COVERAGE
14 AM_CFLAGS = --coverage -O0
15 XLIBS = -lgcov
16endif
17
18if ENABLE_TEST_RUN
19TESTS = \
20 $(check_PROGRAMS) \
21 $(check_SCRIPTS)
22endif
23
24lib_LTLIBRARIES = \
25 libgnunetgnsrecord.la
26
27libgnunetgnsrecord_la_SOURCES = \
28 gnsrecord.c
29libgnunetgnsrecord_la_LIBADD = \
30 $(top_builddir)/src/dns/libgnunetdnsparser.la \
31 $(top_builddir)/src/util/libgnunetutil.la \
32 $(GN_LIBINTL)
33libgnunetgnsrecord_la_LDFLAGS = \
34 $(GN_LIB_LDFLAGS) $(WINFLAGS) \
35 -version-info 0:0:0
36
37EXTRA_DIST = \
38 $(check_SCRIPTS)
39
diff --git a/src/gnsrecord/gnsrecord.c b/src/gnsrecord/gnsrecord.c
new file mode 100644
index 000000000..da098ab66
--- /dev/null
+++ b/src/gnsrecord/gnsrecord.c
@@ -0,0 +1,696 @@
1/*
2 This file is part of GNUnet.
3 (C) 2009-2013 Christian Grothoff (and other contributing authors)
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/**
22 * @file gnsrecord/gnsrecord.c
23 * @brief API to access GNS record data
24 * @author Martin Schanzenbach
25 * @author Matthias Wachs
26 * @author Christian Grothoff
27 */
28#include "platform.h"
29#include "gnunet_util_lib.h"
30#include "gnunet_constants.h"
31#include "gnunet_signatures.h"
32#include "gnunet_conversation_service.h"
33#include "gnunet_dnsparser_lib.h"
34#include "gnunet_gnsrecord_lib.h"
35#include "gnunet_tun_lib.h"
36
37
38#define LOG(kind,...) GNUNET_log_from (kind, "gnsrecord",__VA_ARGS__)
39
40
41/**
42 * Convert the 'value' of a record to a string.
43 *
44 * @param type type of the record
45 * @param data value in binary encoding
46 * @param data_size number of bytes in @a data
47 * @return NULL on error, otherwise human-readable representation of the value
48 */
49char *
50GNUNET_NAMESTORE_value_to_string (uint32_t type,
51 const void *data,
52 size_t data_size)
53{
54 const char *cdata;
55 char* result;
56 char tmp[INET6_ADDRSTRLEN];
57
58 switch (type)
59 {
60 case 0:
61 return NULL;
62 case GNUNET_DNSPARSER_TYPE_A:
63 if (data_size != sizeof (struct in_addr))
64 return NULL;
65 if (NULL == inet_ntop (AF_INET, data, tmp, sizeof (tmp)))
66 return NULL;
67 return GNUNET_strdup (tmp);
68 case GNUNET_DNSPARSER_TYPE_NS:
69 {
70 char *ns;
71 size_t off;
72
73 off = 0;
74 ns = GNUNET_DNSPARSER_parse_name (data,
75 data_size,
76 &off);
77 if ( (NULL == ns) ||
78 (off != data_size) )
79 {
80 GNUNET_break_op (0);
81 return NULL;
82 }
83 return ns;
84 }
85 case GNUNET_DNSPARSER_TYPE_CNAME:
86 {
87 char *cname;
88 size_t off;
89
90 off = 0;
91 cname = GNUNET_DNSPARSER_parse_name (data,
92 data_size,
93 &off);
94 if ( (NULL == cname) ||
95 (off != data_size) )
96 {
97 GNUNET_break_op (0);
98 GNUNET_free_non_null (cname);
99 return NULL;
100 }
101 return cname;
102 }
103 case GNUNET_DNSPARSER_TYPE_SOA:
104 {
105 struct GNUNET_DNSPARSER_SoaRecord *soa;
106 size_t off;
107
108 off = 0;
109 soa = GNUNET_DNSPARSER_parse_soa (data,
110 data_size,
111 &off);
112 if ( (NULL == soa) ||
113 (off != data_size) )
114 {
115 GNUNET_break_op (0);
116 return NULL;
117 }
118 GNUNET_asprintf (&result,
119 "rname=%s mname=%s %lu,%lu,%lu,%lu,%lu",
120 soa->rname,
121 soa->mname,
122 soa->serial,
123 soa->refresh,
124 soa->retry,
125 soa->expire,
126 soa->minimum_ttl);
127 GNUNET_DNSPARSER_free_soa (soa);
128 return result;
129 }
130 case GNUNET_DNSPARSER_TYPE_PTR:
131 {
132 char *ptr;
133 size_t off;
134
135 off = 0;
136 ptr = GNUNET_DNSPARSER_parse_name (data,
137 data_size,
138 &off);
139 if ( (NULL == ptr) ||
140 (off != data_size) )
141 {
142 GNUNET_break_op (0);
143 GNUNET_free_non_null (ptr);
144 return NULL;
145 }
146 return ptr;
147 }
148 case GNUNET_DNSPARSER_TYPE_MX:
149 {
150 struct GNUNET_DNSPARSER_MxRecord *mx;
151 size_t off;
152
153 off = 0;
154 mx = GNUNET_DNSPARSER_parse_mx (data,
155 data_size,
156 &off);
157 if ( (NULL == mx) ||
158 (off != data_size) )
159 {
160 GNUNET_break_op (0);
161 GNUNET_free_non_null (mx);
162 return NULL;
163 }
164 GNUNET_asprintf (&result,
165 "%hu,%s",
166 mx->preference,
167 mx->mxhost);
168 GNUNET_DNSPARSER_free_mx (mx);
169 return result;
170 }
171 case GNUNET_DNSPARSER_TYPE_TXT:
172 return GNUNET_strndup (data, data_size);
173 case GNUNET_DNSPARSER_TYPE_AAAA:
174 if (data_size != sizeof (struct in6_addr))
175 return NULL;
176 if (NULL == inet_ntop (AF_INET6, data, tmp, sizeof (tmp)))
177 return NULL;
178 return GNUNET_strdup (tmp);
179 case GNUNET_NAMESTORE_TYPE_PKEY:
180 if (data_size != sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))
181 return NULL;
182 return GNUNET_CRYPTO_ecdsa_public_key_to_string (data);
183 case GNUNET_NAMESTORE_TYPE_PHONE:
184 {
185 const struct GNUNET_CONVERSATION_PhoneRecord *pr;
186 char *ret;
187 char *pkey;
188
189 if (data_size != sizeof (struct GNUNET_CONVERSATION_PhoneRecord))
190 return NULL;
191 pr = data;
192 if (0 != ntohl (pr->version))
193 return NULL;
194 pkey = GNUNET_CRYPTO_eddsa_public_key_to_string (&pr->peer.public_key);
195 GNUNET_asprintf (&ret,
196 "%u-%s",
197 ntohl (pr->line),
198 pkey);
199 GNUNET_free (pkey);
200 return ret;
201 }
202 case GNUNET_NAMESTORE_TYPE_PSEU:
203 return GNUNET_strndup (data, data_size);
204 case GNUNET_NAMESTORE_TYPE_LEHO:
205 return GNUNET_strndup (data, data_size);
206 case GNUNET_NAMESTORE_TYPE_VPN:
207 {
208 const struct GNUNET_TUN_GnsVpnRecord *vpn;
209 char* vpn_str;
210
211 cdata = data;
212 if ( (data_size <= sizeof (struct GNUNET_TUN_GnsVpnRecord)) ||
213 ('\0' != cdata[data_size - 1]) )
214 return NULL; /* malformed */
215 vpn = data;
216 if (0 == GNUNET_asprintf (&vpn_str, "%u %s %s",
217 (unsigned int) ntohs (vpn->proto),
218 (const char*) GNUNET_i2s_full (&vpn->peer),
219 (const char*) &vpn[1]))
220 {
221 GNUNET_free (vpn_str);
222 return NULL;
223 }
224 return vpn_str;
225 }
226 case GNUNET_NAMESTORE_TYPE_GNS2DNS:
227 {
228 char *ns;
229 size_t off;
230
231 off = 0;
232 ns = GNUNET_DNSPARSER_parse_name (data,
233 data_size,
234 &off);
235 if ( (NULL == ns) ||
236 (off != data_size) )
237 {
238 GNUNET_break_op (0);
239 GNUNET_free_non_null (ns);
240 return NULL;
241 }
242 return ns;
243 }
244 case GNUNET_DNSPARSER_TYPE_SRV:
245 {
246 struct GNUNET_DNSPARSER_SrvRecord *srv;
247 size_t off;
248
249 off = 0;
250 srv = GNUNET_DNSPARSER_parse_srv ("+", /* FIXME: is this OK? */
251 data,
252 data_size,
253 &off);
254 if ( (NULL == srv) ||
255 (off != data_size) )
256 {
257 GNUNET_break_op (0);
258 return NULL;
259 }
260 GNUNET_asprintf (&result,
261 "%d %d %d _%s._%s.%s",
262 srv->priority,
263 srv->weight,
264 srv->port,
265 srv->service,
266 srv->proto,
267 srv->domain_name);
268 GNUNET_DNSPARSER_free_srv (srv);
269 return result;
270 }
271 case GNUNET_DNSPARSER_TYPE_TLSA:
272 {
273 const struct GNUNET_TUN_DnsTlsaRecord *tlsa;
274 char* tlsa_str;
275
276 cdata = data;
277 if ( (data_size <= sizeof (struct GNUNET_TUN_DnsTlsaRecord)) ||
278 ('\0' != cdata[data_size - 1]) )
279 return NULL; /* malformed */
280 tlsa = data;
281 if (0 == GNUNET_asprintf (&tlsa_str,
282 "%c %c %c %s",
283 tlsa->usage,
284 tlsa->selector,
285 tlsa->matching_type,
286 (const char *) &tlsa[1]))
287 {
288 GNUNET_free (tlsa_str);
289 return NULL;
290 }
291 return tlsa_str;
292 }
293 default:
294 GNUNET_break (0);
295 }
296 GNUNET_break (0); // not implemented
297 return NULL;
298}
299
300
301/**
302 * Convert human-readable version of a 'value' of a record to the binary
303 * representation.
304 *
305 * @param type type of the record
306 * @param s human-readable string
307 * @param data set to value in binary encoding (will be allocated)
308 * @param data_size set to number of bytes in @a data
309 * @return #GNUNET_OK on success
310 */
311int
312GNUNET_NAMESTORE_string_to_value (uint32_t type,
313 const char *s,
314 void **data,
315 size_t *data_size)
316{
317 struct in_addr value_a;
318 struct in6_addr value_aaaa;
319 struct GNUNET_CRYPTO_EcdsaPublicKey pkey;
320 struct GNUNET_TUN_GnsVpnRecord *vpn;
321 struct GNUNET_TUN_DnsTlsaRecord *tlsa;
322 char s_peer[103 + 1];
323 char s_serv[253 + 1];
324 unsigned int proto;
325
326 if (NULL == s)
327 return GNUNET_SYSERR;
328 switch (type)
329 {
330 case 0:
331 LOG (GNUNET_ERROR_TYPE_ERROR,
332 _("Unsupported record type %d\n"),
333 (int) type);
334 return GNUNET_SYSERR;
335 case GNUNET_DNSPARSER_TYPE_A:
336 if (1 != inet_pton (AF_INET, s, &value_a))
337 {
338 LOG (GNUNET_ERROR_TYPE_ERROR,
339 _("Unable to parse IPv4 address `%s'\n"),
340 s);
341 return GNUNET_SYSERR;
342 }
343 *data = GNUNET_malloc (sizeof (struct in_addr));
344 memcpy (*data, &value_a, sizeof (value_a));
345 *data_size = sizeof (value_a);
346 return GNUNET_OK;
347 case GNUNET_DNSPARSER_TYPE_NS:
348 {
349 char nsbuf[256];
350 size_t off;
351
352 off = 0;
353 if (GNUNET_OK !=
354 GNUNET_DNSPARSER_builder_add_name (nsbuf,
355 sizeof (nsbuf),
356 &off,
357 s))
358 {
359 LOG (GNUNET_ERROR_TYPE_ERROR,
360 _("Failed to serialize NS record with value `%s'\n"),
361 s);
362 return GNUNET_SYSERR;
363 }
364 *data_size = off;
365 *data = GNUNET_malloc (off);
366 memcpy (*data, nsbuf, off);
367 return GNUNET_OK;
368 }
369 case GNUNET_DNSPARSER_TYPE_CNAME:
370 {
371 char cnamebuf[256];
372 size_t off;
373
374 off = 0;
375 if (GNUNET_OK !=
376 GNUNET_DNSPARSER_builder_add_name (cnamebuf,
377 sizeof (cnamebuf),
378 &off,
379 s))
380 {
381 LOG (GNUNET_ERROR_TYPE_ERROR,
382 _("Failed to serialize CNAME record with value `%s'\n"),
383 s);
384 return GNUNET_SYSERR;
385 }
386 *data_size = off;
387 *data = GNUNET_malloc (off);
388 memcpy (*data, cnamebuf, off);
389 return GNUNET_OK;
390 }
391 case GNUNET_DNSPARSER_TYPE_SOA:
392 {
393 struct GNUNET_DNSPARSER_SoaRecord soa;
394 char soabuf[540];
395 char soa_rname[253 + 1];
396 char soa_mname[253 + 1];
397 unsigned int soa_serial;
398 unsigned int soa_refresh;
399 unsigned int soa_retry;
400 unsigned int soa_expire;
401 unsigned int soa_min;
402 size_t off;
403
404 if (7 != SSCANF (s,
405 "rname=%253s mname=%253s %u,%u,%u,%u,%u",
406 soa_rname, soa_mname,
407 &soa_serial, &soa_refresh, &soa_retry, &soa_expire, &soa_min))
408 {
409 LOG (GNUNET_ERROR_TYPE_ERROR,
410 _("Unable to parse SOA record `%s'\n"),
411 s);
412 return GNUNET_SYSERR;
413 }
414 soa.mname = soa_mname;
415 soa.rname = soa_rname;
416 soa.serial = (uint32_t) soa_serial;
417 soa.refresh =(uint32_t) soa_refresh;
418 soa.retry = (uint32_t) soa_retry;
419 soa.expire = (uint32_t) soa_expire;
420 soa.minimum_ttl = (uint32_t) soa_min;
421 off = 0;
422 if (GNUNET_OK !=
423 GNUNET_DNSPARSER_builder_add_soa (soabuf,
424 sizeof (soabuf),
425 &off,
426 &soa))
427 {
428 LOG (GNUNET_ERROR_TYPE_ERROR,
429 _("Failed to serialize SOA record with mname `%s' and rname `%s'\n"),
430 soa_mname,
431 soa_rname);
432 return GNUNET_SYSERR;
433 }
434 *data_size = off;
435 *data = GNUNET_malloc (off);
436 memcpy (*data, soabuf, off);
437 return GNUNET_OK;
438 }
439 case GNUNET_DNSPARSER_TYPE_PTR:
440 {
441 char ptrbuf[256];
442 size_t off;
443
444 off = 0;
445 if (GNUNET_OK !=
446 GNUNET_DNSPARSER_builder_add_name (ptrbuf,
447 sizeof (ptrbuf),
448 &off,
449 s))
450 {
451 LOG (GNUNET_ERROR_TYPE_ERROR,
452 _("Failed to serialize PTR record with value `%s'\n"),
453 s);
454 return GNUNET_SYSERR;
455 }
456 *data_size = off;
457 *data = GNUNET_malloc (off);
458 memcpy (*data, ptrbuf, off);
459 return GNUNET_OK;
460 }
461 case GNUNET_DNSPARSER_TYPE_MX:
462 {
463 struct GNUNET_DNSPARSER_MxRecord mx;
464 char mxbuf[258];
465 char mxhost[253 + 1];
466 uint16_t mx_pref;
467 size_t off;
468
469 if (2 != SSCANF(s, "%hu,%253s", &mx_pref, mxhost))
470 {
471 LOG (GNUNET_ERROR_TYPE_ERROR,
472 _("Unable to parse MX record `%s'\n"),
473 s);
474 return GNUNET_SYSERR;
475 }
476 mx.preference = mx_pref;
477 mx.mxhost = mxhost;
478 off = 0;
479
480 if (GNUNET_OK !=
481 GNUNET_DNSPARSER_builder_add_mx (mxbuf,
482 sizeof (mxbuf),
483 &off,
484 &mx))
485 {
486 LOG (GNUNET_ERROR_TYPE_ERROR,
487 _("Failed to serialize MX record with hostname `%s'\n"),
488 mxhost);
489 return GNUNET_SYSERR;
490 }
491 *data_size = off;
492 *data = GNUNET_malloc (off);
493 memcpy (*data, mxbuf, off);
494 return GNUNET_OK;
495 }
496 case GNUNET_DNSPARSER_TYPE_TXT:
497 *data = GNUNET_strdup (s);
498 *data_size = strlen (s);
499 return GNUNET_OK;
500 case GNUNET_DNSPARSER_TYPE_AAAA:
501 if (1 != inet_pton (AF_INET6, s, &value_aaaa))
502 {
503 LOG (GNUNET_ERROR_TYPE_ERROR,
504 _("Unable to parse IPv6 address `%s'\n"),
505 s);
506 return GNUNET_SYSERR;
507 }
508 *data = GNUNET_malloc (sizeof (struct in6_addr));
509 *data_size = sizeof (struct in6_addr);
510 memcpy (*data, &value_aaaa, sizeof (value_aaaa));
511 return GNUNET_OK;
512 case GNUNET_NAMESTORE_TYPE_PKEY:
513 if (GNUNET_OK !=
514 GNUNET_CRYPTO_ecdsa_public_key_from_string (s, strlen (s), &pkey))
515 {
516 LOG (GNUNET_ERROR_TYPE_ERROR,
517 _("Unable to parse PKEY record `%s'\n"),
518 s);
519 return GNUNET_SYSERR;
520 }
521 *data = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPublicKey);
522 memcpy (*data, &pkey, sizeof (pkey));
523 *data_size = sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey);
524 return GNUNET_OK;
525 case GNUNET_NAMESTORE_TYPE_PHONE:
526 {
527 struct GNUNET_CONVERSATION_PhoneRecord *pr;
528 unsigned int line;
529 const char *dash;
530 struct GNUNET_PeerIdentity peer;
531
532 if ( (NULL == (dash = strchr (s, '-'))) ||
533 (1 != sscanf (s, "%u-", &line)) ||
534 (GNUNET_OK !=
535 GNUNET_CRYPTO_eddsa_public_key_from_string (dash + 1,
536 strlen (dash + 1),
537 &peer.public_key)) )
538 {
539 LOG (GNUNET_ERROR_TYPE_ERROR,
540 _("Unable to parse PHONE record `%s'\n"),
541 s);
542 return GNUNET_SYSERR;
543 }
544 pr = GNUNET_new (struct GNUNET_CONVERSATION_PhoneRecord);
545 pr->version = htonl (0);
546 pr->line = htonl ((uint32_t) line);
547 pr->peer = peer;
548 *data = pr;
549 *data_size = sizeof (struct GNUNET_CONVERSATION_PhoneRecord);
550 return GNUNET_OK;
551 }
552 case GNUNET_NAMESTORE_TYPE_PSEU:
553 *data = GNUNET_strdup (s);
554 *data_size = strlen (s);
555 return GNUNET_OK;
556 case GNUNET_NAMESTORE_TYPE_LEHO:
557 *data = GNUNET_strdup (s);
558 *data_size = strlen (s);
559 return GNUNET_OK;
560 case GNUNET_NAMESTORE_TYPE_VPN:
561 if (3 != SSCANF (s,"%u %103s %253s",
562 &proto, s_peer, s_serv))
563 {
564 LOG (GNUNET_ERROR_TYPE_ERROR,
565 _("Unable to parse VPN record string `%s'\n"),
566 s);
567 return GNUNET_SYSERR;
568 }
569 *data_size = sizeof (struct GNUNET_TUN_GnsVpnRecord) + strlen (s_serv) + 1;
570 *data = vpn = GNUNET_malloc (*data_size);
571 if (GNUNET_OK != GNUNET_CRYPTO_eddsa_public_key_from_string ((char*) s_peer,
572 strlen (s_peer),
573 &vpn->peer.public_key))
574 {
575 GNUNET_free (vpn);
576 *data_size = 0;
577 return GNUNET_SYSERR;
578 }
579 vpn->proto = htons ((uint16_t) proto);
580 strcpy ((char*)&vpn[1], s_serv);
581 return GNUNET_OK;
582 case GNUNET_NAMESTORE_TYPE_GNS2DNS:
583 {
584 char nsbuf[256];
585 size_t off;
586
587 off = 0;
588 if (GNUNET_OK !=
589 GNUNET_DNSPARSER_builder_add_name (nsbuf,
590 sizeof (nsbuf),
591 &off,
592 s))
593 {
594 LOG (GNUNET_ERROR_TYPE_ERROR,
595 _("Failed to serialize GNS2DNS record with value `%s'\n"),
596 s);
597 return GNUNET_SYSERR;
598 }
599 *data_size = off;
600 *data = GNUNET_malloc (off);
601 memcpy (*data, nsbuf, off);
602 return GNUNET_OK;
603 }
604 case GNUNET_DNSPARSER_TYPE_TLSA:
605 *data_size = sizeof (struct GNUNET_TUN_DnsTlsaRecord) + strlen (s) - 6;
606 *data = tlsa = GNUNET_malloc (*data_size);
607 if (4 != SSCANF (s, "%c %c %c %s",
608 &tlsa->usage,
609 &tlsa->selector,
610 &tlsa->matching_type,
611 (char*)&tlsa[1]))
612 {
613 LOG (GNUNET_ERROR_TYPE_ERROR,
614 _("Unable to parse TLSA record string `%s'\n"),
615 s);
616 *data_size = 0;
617 GNUNET_free (tlsa);
618 return GNUNET_SYSERR;
619 }
620 return GNUNET_OK;
621 default:
622 LOG (GNUNET_ERROR_TYPE_ERROR,
623 _("Unsupported record type %d\n"),
624 (int) type);
625 return GNUNET_SYSERR;
626 }
627}
628
629
630/**
631 * Mapping of record type numbers to human-readable
632 * record type names.
633 */
634static struct {
635 const char *name;
636 uint32_t number;
637} name_map[] = {
638 { "A", GNUNET_DNSPARSER_TYPE_A },
639 { "NS", GNUNET_DNSPARSER_TYPE_NS },
640 { "CNAME", GNUNET_DNSPARSER_TYPE_CNAME },
641 { "SOA", GNUNET_DNSPARSER_TYPE_SOA },
642 { "PTR", GNUNET_DNSPARSER_TYPE_PTR },
643 { "MX", GNUNET_DNSPARSER_TYPE_MX },
644 { "TXT", GNUNET_DNSPARSER_TYPE_TXT },
645 { "AAAA", GNUNET_DNSPARSER_TYPE_AAAA },
646 { "PKEY", GNUNET_NAMESTORE_TYPE_PKEY },
647 { "PSEU", GNUNET_NAMESTORE_TYPE_PSEU },
648 { "LEHO", GNUNET_NAMESTORE_TYPE_LEHO },
649 { "VPN", GNUNET_NAMESTORE_TYPE_VPN },
650 { "GNS2DNS", GNUNET_NAMESTORE_TYPE_GNS2DNS },
651 { "PHONE", GNUNET_NAMESTORE_TYPE_PHONE },
652 { "TLSA", GNUNET_DNSPARSER_TYPE_TLSA },
653 { NULL, UINT32_MAX }
654};
655
656
657/**
658 * Convert a type name (i.e. "AAAA") to the corresponding number.
659 *
660 * @param dns_typename name to convert
661 * @return corresponding number, UINT32_MAX on error
662 */
663uint32_t
664GNUNET_NAMESTORE_typename_to_number (const char *dns_typename)
665{
666 unsigned int i;
667
668 i=0;
669 while ( (name_map[i].name != NULL) &&
670 (0 != strcasecmp (dns_typename, name_map[i].name)) )
671 i++;
672 return name_map[i].number;
673}
674
675
676/**
677 * Convert a type number (i.e. 1) to the corresponding type string (i.e. "A")
678 *
679 * @param type number of a type to convert
680 * @return corresponding typestring, NULL on error
681 */
682const char *
683GNUNET_NAMESTORE_number_to_typename (uint32_t type)
684{
685 unsigned int i;
686
687 i=0;
688 while ( (name_map[i].name != NULL) &&
689 (type != name_map[i].number) )
690 i++;
691 return name_map[i].name;
692}
693
694
695
696/* end of namestore_common.c */
diff --git a/src/include/Makefile.am b/src/include/Makefile.am
index 8a848135b..44acd2eb1 100644
--- a/src/include/Makefile.am
+++ b/src/include/Makefile.am
@@ -48,6 +48,7 @@ gnunetinclude_HEADERS = \
48 gnunet_fs_service.h \ 48 gnunet_fs_service.h \
49 gnunet_getopt_lib.h \ 49 gnunet_getopt_lib.h \
50 gnunet_gns_service.h \ 50 gnunet_gns_service.h \
51 gnunet_gnsrecord_lib.h \
51 gnunet_hello_lib.h \ 52 gnunet_hello_lib.h \
52 gnunet_helper_lib.h \ 53 gnunet_helper_lib.h \
53 gnunet_identity_service.h \ 54 gnunet_identity_service.h \
diff --git a/src/include/gnunet_namestore_service.h b/src/include/gnunet_namestore_service.h
index c31c3689b..55fdbef65 100644
--- a/src/include/gnunet_namestore_service.h
+++ b/src/include/gnunet_namestore_service.h
@@ -1,4 +1,3 @@
1
2/* 1/*
3 This file is part of GNUnet 2 This file is part of GNUnet
4 (C) 2012, 2013 Christian Grothoff (and other contributing authors) 3 (C) 2012, 2013 Christian Grothoff (and other contributing authors)
@@ -41,46 +40,6 @@ extern "C"
41#endif 40#endif
42#endif 41#endif
43 42
44/**
45 * Record type indicating any record/'*'
46 */
47#define GNUNET_NAMESTORE_TYPE_ANY 0
48
49/**
50 * Record type for GNS zone transfer ("PKEY").
51 */
52#define GNUNET_NAMESTORE_TYPE_PKEY 65536
53
54/**
55 * Record type for GNS zone transfer ("PSEU").
56 */
57#define GNUNET_NAMESTORE_TYPE_PSEU 65537
58
59/**
60 * Record type for GNS legacy hostnames ("LEHO").
61 */
62#define GNUNET_NAMESTORE_TYPE_LEHO 65538
63
64/**
65 * Record type for VPN resolution
66 */
67#define GNUNET_NAMESTORE_TYPE_VPN 65539
68
69/**
70 * Record type for delegation to DNS.
71 */
72#define GNUNET_NAMESTORE_TYPE_GNS2DNS 65540
73
74/**
75 * Record type for a social place.
76 */
77#define GNUNET_NAMESTORE_TYPE_PLACE 65541
78
79/**
80 * Record type for a phone (of CONVERSATION).
81 */
82#define GNUNET_NAMESTORE_TYPE_PHONE 65542
83
84 43
85/** 44/**
86 * Entry in the queue. 45 * Entry in the queue.
@@ -534,58 +493,6 @@ GNUNET_NAMESTORE_records_deserialize (size_t len,
534 493
535 494
536/** 495/**
537 * Convert the binary value @a data of a record of
538 * type @a type to a human-readable string.
539 *
540 * @param type type of the record
541 * @param data value in binary encoding
542 * @param data_size number of bytes in @a data
543 * @return NULL on error, otherwise human-readable representation of the value
544 */
545char *
546GNUNET_NAMESTORE_value_to_string (uint32_t type,
547 const void *data,
548 size_t data_size);
549
550
551/**
552 * Convert human-readable version of the value @a s of a record
553 * of type @a type to the respective binary representation.
554 *
555 * @param type type of the record
556 * @param s human-readable string
557 * @param data set to value in binary encoding (will be allocated)
558 * @param data_size set to number of bytes in @a data
559 * @return #GNUNET_OK on success
560 */
561int
562GNUNET_NAMESTORE_string_to_value (uint32_t type,
563 const char *s,
564 void **data,
565 size_t *data_size);
566
567
568/**
569 * Convert a type name (i.e. "AAAA") to the corresponding number.
570 *
571 * @param dns_typename name to convert
572 * @return corresponding number, UINT32_MAX on error
573 */
574uint32_t
575GNUNET_NAMESTORE_typename_to_number (const char *dns_typename);
576
577
578/**
579 * Convert a type number (i.e. 1) to the corresponding type string (i.e. "A")
580 *
581 * @param type number of a type to convert
582 * @return corresponding typestring, NULL on error
583 */
584const char *
585GNUNET_NAMESTORE_number_to_typename (uint32_t type);
586
587
588/**
589 * Test if a given record is expired. 496 * Test if a given record is expired.
590 * 497 *
591 * @param rd record to test 498 * @param rd record to test
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
97gnunet_namestore_SOURCES = \ 97gnunet_namestore_SOURCES = \
98 gnunet-namestore.c 98 gnunet-namestore.c
99gnunet_namestore_LDADD = \ 99gnunet_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)
104gnunet_namestore_DEPENDENCIES = \ 105gnunet_namestore_DEPENDENCIES = \
@@ -110,9 +111,10 @@ gnunet_namestore_DEPENDENCIES = \
110gnunet_namestore_fcfsd_SOURCES = \ 111gnunet_namestore_fcfsd_SOURCES = \
111 gnunet-namestore-fcfsd.c 112 gnunet-namestore-fcfsd.c
112gnunet_namestore_fcfsd_LDADD = -lmicrohttpd \ 113gnunet_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)
117gnunet_namestore_fcfsd_DEPENDENCIES = \ 119gnunet_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 */
214static unsigned long long port; 215static 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 */
525char *
526GNUNET_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 */
787int
788GNUNET_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 */
1110static 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 */
1139uint32_t
1140GNUNET_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 */
1158const char *
1159GNUNET_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