aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-10-30 20:52:14 +0000
committerChristian Grothoff <christian@grothoff.org>2012-10-30 20:52:14 +0000
commitc95ddb3eac0292511af734768441444098b90be9 (patch)
tree0f9797ab72aba90fb820aca16ff4078040f6f2bb
parentee1230fff885b67efbae4fd194e7c62c93903ae3 (diff)
downloadgnunet-c95ddb3eac0292511af734768441444098b90be9.tar.gz
gnunet-c95ddb3eac0292511af734768441444098b90be9.zip
-more cleanup and input validation fixes
-rw-r--r--src/gns/gns.h10
-rw-r--r--src/gns/gnunet-service-gns.c18
-rw-r--r--src/gns/gnunet-service-gns_interceptor.c2
-rw-r--r--src/gns/gnunet-service-gns_resolver.c340
-rw-r--r--src/gns/gnunet-service-gns_resolver.h26
-rw-r--r--src/gns/test_gns_cname_lookup.c38
-rw-r--r--src/gns/test_gns_max_queries.c4
-rw-r--r--src/gns/test_gns_simple_zkey_lookup.c2
-rw-r--r--src/include/gnunet_common.h7
-rw-r--r--src/include/gnunet_dnsparser_lib.h11
-rw-r--r--src/include/gnunet_namestore_service.h10
-rw-r--r--src/namestore/namestore_common.c115
12 files changed, 265 insertions, 318 deletions
diff --git a/src/gns/gns.h b/src/gns/gns.h
index 10119800d..e5d48fa27 100644
--- a/src/gns/gns.h
+++ b/src/gns/gns.h
@@ -42,16 +42,6 @@
42 */ 42 */
43#define GNUNET_GNS_TLD_PLUS "+" 43#define GNUNET_GNS_TLD_PLUS "+"
44 44
45/**
46 * Maximum length of a label in DNS.
47 */
48#define MAX_DNS_LABEL_LENGTH 63
49
50/**
51 * Maximum length of a name in DNS.
52 */
53#define MAX_DNS_NAME_LENGTH 253
54
55 45
56GNUNET_NETWORK_STRUCT_BEGIN 46GNUNET_NETWORK_STRUCT_BEGIN
57 47
diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c
index 79c453406..ccb1b8e3d 100644
--- a/src/gns/gnunet-service-gns.c
+++ b/src/gns/gnunet-service-gns.c
@@ -116,17 +116,17 @@ struct ClientShortenHandle
116 /** 116 /**
117 * name to shorten 117 * name to shorten
118 */ 118 */
119 char name[MAX_DNS_NAME_LENGTH]; 119 char name[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
120 120
121 /** 121 /**
122 * name of private zone (relative to root) 122 * name of private zone (relative to root)
123 */ 123 */
124 char private_zone_id[MAX_DNS_NAME_LENGTH]; 124 char private_zone_id[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
125 125
126 /** 126 /**
127 * name of shorten zone (relative to root) 127 * name of shorten zone (relative to root)
128 */ 128 */
129 char shorten_zone_id[MAX_DNS_NAME_LENGTH]; 129 char shorten_zone_id[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
130 130
131}; 131};
132 132
@@ -787,7 +787,7 @@ handle_shorten (void *cls,
787{ 787{
788 struct ClientShortenHandle *csh; 788 struct ClientShortenHandle *csh;
789 const char *utf_in; 789 const char *utf_in;
790 char name[MAX_DNS_NAME_LENGTH]; 790 char name[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
791 char* nameptr = name; 791 char* nameptr = name;
792 uint16_t msg_size; 792 uint16_t msg_size;
793 const struct GNUNET_GNS_ClientShortenMessage *sh_msg; 793 const struct GNUNET_GNS_ClientShortenMessage *sh_msg;
@@ -828,7 +828,7 @@ handle_shorten (void *cls,
828 GNUNET_SERVER_receive_done (client, GNUNET_OK); 828 GNUNET_SERVER_receive_done (client, GNUNET_OK);
829 return; 829 return;
830 } 830 }
831 if (strlen (name) > MAX_DNS_NAME_LENGTH) 831 if (strlen (name) > GNUNET_DNSPARSER_MAX_NAME_LENGTH)
832 { 832 {
833 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 833 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
834 "SHORTEN: %s is too long\n", name); 834 "SHORTEN: %s is too long\n", name);
@@ -922,7 +922,7 @@ handle_get_authority (void *cls,
922{ 922{
923 struct ClientGetAuthHandle *cah; 923 struct ClientGetAuthHandle *cah;
924 const char *utf_in; 924 const char *utf_in;
925 char name[MAX_DNS_NAME_LENGTH]; 925 char name[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
926 char* nameptr = name; 926 char* nameptr = name;
927 uint16_t msg_size; 927 uint16_t msg_size;
928 const struct GNUNET_GNS_ClientGetAuthMessage *sh_msg; 928 const struct GNUNET_GNS_ClientGetAuthMessage *sh_msg;
@@ -957,7 +957,7 @@ handle_get_authority (void *cls,
957 send_get_auth_response(cah, name); 957 send_get_auth_response(cah, name);
958 return; 958 return;
959 } 959 }
960 if (strlen (name) > MAX_DNS_NAME_LENGTH) 960 if (strlen (name) > GNUNET_DNSPARSER_MAX_NAME_LENGTH)
961 { 961 {
962 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 962 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
963 "GET_AUTH: `%s' is too long", name); 963 "GET_AUTH: `%s' is too long", name);
@@ -1059,7 +1059,7 @@ handle_lookup (void *cls,
1059 const struct GNUNET_MessageHeader * message) 1059 const struct GNUNET_MessageHeader * message)
1060{ 1060{
1061 size_t namelen; 1061 size_t namelen;
1062 char name[MAX_DNS_NAME_LENGTH]; 1062 char name[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
1063 struct ClientLookupHandle *clh; 1063 struct ClientLookupHandle *clh;
1064 char* nameptr = name; 1064 char* nameptr = name;
1065 const char *utf_in; 1065 const char *utf_in;
@@ -1113,7 +1113,7 @@ handle_lookup (void *cls,
1113 1113
1114 only_cached = ntohl (sh_msg->only_cached); 1114 only_cached = ntohl (sh_msg->only_cached);
1115 1115
1116 if (strlen (name) > MAX_DNS_NAME_LENGTH) { 1116 if (strlen (name) > GNUNET_DNSPARSER_MAX_NAME_LENGTH) {
1117 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1117 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1118 "LOOKUP: %s is too long", name); 1118 "LOOKUP: %s is too long", name);
1119 clh->name = NULL; 1119 clh->name = NULL;
diff --git a/src/gns/gnunet-service-gns_interceptor.c b/src/gns/gnunet-service-gns_interceptor.c
index 828efc39e..cbacc318d 100644
--- a/src/gns/gnunet-service-gns_interceptor.c
+++ b/src/gns/gnunet-service-gns_interceptor.c
@@ -30,8 +30,6 @@
30#include "gnunet-service-gns_resolver.h" 30#include "gnunet-service-gns_resolver.h"
31#include "gns.h" 31#include "gns.h"
32 32
33#define MAX_DNS_LABEL_LENGTH 63
34
35/** 33/**
36 * Handle to a DNS intercepted 34 * Handle to a DNS intercepted
37 * reslution request 35 * reslution request
diff --git a/src/gns/gnunet-service-gns_resolver.c b/src/gns/gnunet-service-gns_resolver.c
index 0dc1e3f6d..76eb46df0 100644
--- a/src/gns/gnunet-service-gns_resolver.c
+++ b/src/gns/gnunet-service-gns_resolver.c
@@ -50,11 +50,6 @@
50 */ 50 */
51#define DHT_GNS_REPLICATION_LEVEL 5 51#define DHT_GNS_REPLICATION_LEVEL 5
52 52
53/**
54 * Maximum label length of DNS names
55 */
56#define MAX_DNS_LABEL_LENGTH 63
57
58 53
59/** 54/**
60 * Our handle to the namestore service 55 * Our handle to the namestore service
@@ -150,7 +145,8 @@ static const struct GNUNET_CONFIGURATION_Handle *cfg;
150 * a resolution identifier pool variable 145 * a resolution identifier pool variable
151 * This is a non critical identifier useful for debugging 146 * This is a non critical identifier useful for debugging
152 */ 147 */
153static unsigned long long rid = 0; 148static unsigned long long rid_gen;
149
154 150
155/** 151/**
156 * Check if name is in srv format (_x._y.xxx) 152 * Check if name is in srv format (_x._y.xxx)
@@ -159,30 +155,25 @@ static unsigned long long rid = 0;
159 * @return GNUNET_YES if true 155 * @return GNUNET_YES if true
160 */ 156 */
161static int 157static int
162is_srv (char* name) 158is_srv (const char *name)
163{ 159{
164 char* ndup; 160 char *ndup;
165 int ret = GNUNET_YES; 161 int ret;
166 162
167 if (*name != '_') 163 if (*name != '_')
168 return GNUNET_NO; 164 return GNUNET_NO;
169 if (NULL == strstr (name, "._")) 165 if (NULL == strstr (name, "._"))
170 return GNUNET_NO; 166 return GNUNET_NO;
171 167 ret = GNUNET_YES;
172 ndup = GNUNET_strdup (name); 168 ndup = GNUNET_strdup (name);
173 strtok (ndup, "."); 169 strtok (ndup, ".");
174
175 if (NULL == strtok (NULL, ".")) 170 if (NULL == strtok (NULL, "."))
176 ret = GNUNET_NO; 171 ret = GNUNET_NO;
177
178 if (NULL == strtok (NULL, ".")) 172 if (NULL == strtok (NULL, "."))
179 ret = GNUNET_NO; 173 ret = GNUNET_NO;
180
181 if (NULL != strtok (NULL, ".")) 174 if (NULL != strtok (NULL, "."))
182 ret = GNUNET_NO; 175 ret = GNUNET_NO;
183
184 GNUNET_free (ndup); 176 GNUNET_free (ndup);
185
186 return ret; 177 return ret;
187} 178}
188 179
@@ -203,7 +194,7 @@ is_srv (char* name)
203 * @return GNUNET_YES if canonical 194 * @return GNUNET_YES if canonical
204 */ 195 */
205static int 196static int
206is_canonical (const char* name) 197is_canonical (const char *name)
207{ 198{
208 const char *pos; 199 const char *pos;
209 const char *dot; 200 const char *dot;
@@ -243,7 +234,7 @@ shorten_authority_chain (struct GetPseuAuthorityHandle *gph);
243 234
244 235
245/** 236/**
246 * Continueation for pkey record creation (shorten) 237 * Continuation for pkey record creation (shorten)
247 * 238 *
248 * @param cls a GetPseuAuthorityHandle 239 * @param cls a GetPseuAuthorityHandle
249 * @param success unused 240 * @param success unused
@@ -293,7 +284,8 @@ process_pseu_lookup_ns (void* cls,
293 284
294 /* name is free */ 285 /* name is free */
295 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 286 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
296 "GNS_AUTO_PSEU: Name %s not taken in NS! Adding\n", gph->test_name); 287 "GNS_AUTO_PSEU: Name %s not taken in NS! Adding\n",
288 gph->test_name);
297 289
298 new_pkey.expiration_time = UINT64_MAX; 290 new_pkey.expiration_time = UINT64_MAX;
299 new_pkey.data_size = sizeof (struct GNUNET_CRYPTO_ShortHashCode); 291 new_pkey.data_size = sizeof (struct GNUNET_CRYPTO_ShortHashCode);
@@ -310,6 +302,7 @@ process_pseu_lookup_ns (void* cls,
310 gph); 302 gph);
311} 303}
312 304
305
313/** 306/**
314 * process result of a dht pseu lookup 307 * process result of a dht pseu lookup
315 * 308 *
@@ -317,7 +310,8 @@ process_pseu_lookup_ns (void* cls,
317 * @param name the pseu result or NULL 310 * @param name the pseu result or NULL
318 */ 311 */
319static void 312static void
320process_pseu_result (struct GetPseuAuthorityHandle* gph, char* name) 313process_pseu_result (struct GetPseuAuthorityHandle* gph,
314 const char* name)
321{ 315{
322 if (NULL == name) 316 if (NULL == name)
323 { 317 {
@@ -353,7 +347,7 @@ static void
353handle_auth_discovery_timeout (void *cls, 347handle_auth_discovery_timeout (void *cls,
354 const struct GNUNET_SCHEDULER_TaskContext *tc) 348 const struct GNUNET_SCHEDULER_TaskContext *tc)
355{ 349{
356 struct GetPseuAuthorityHandle* gph = (struct GetPseuAuthorityHandle*)cls; 350 struct GetPseuAuthorityHandle* gph = cls;
357 351
358 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 352 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
359 "GNS_GET_AUTH: dht lookup for query PSEU timed out.\n"); 353 "GNS_GET_AUTH: dht lookup for query PSEU timed out.\n");
@@ -571,7 +565,6 @@ process_zone_to_name_discover (void *cls,
571static void 565static void
572shorten_authority_chain (struct GetPseuAuthorityHandle *gph) 566shorten_authority_chain (struct GetPseuAuthorityHandle *gph)
573{ 567{
574
575 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 568 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
576 "GNS_AUTO_PSEU: New authority %s discovered\n", 569 "GNS_AUTO_PSEU: New authority %s discovered\n",
577 gph->auth->name); 570 gph->auth->name);
@@ -581,7 +574,6 @@ shorten_authority_chain (struct GetPseuAuthorityHandle *gph)
581 &gph->auth->zone, 574 &gph->auth->zone,
582 &process_zone_to_name_discover, 575 &process_zone_to_name_discover,
583 gph); 576 gph);
584
585} 577}
586 578
587 579
@@ -626,6 +618,7 @@ start_shorten (struct AuthorityChain *auth,
626 shorten_authority_chain (gph); 618 shorten_authority_chain (gph);
627} 619}
628 620
621
629/** 622/**
630 * Initialize the resolver 623 * Initialize the resolver
631 * 624 *
@@ -726,8 +719,8 @@ cleanup_pending_background_queries (void* cls,
726 struct ResolverHandle *rh = element; 719 struct ResolverHandle *rh = element;
727 720
728 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 721 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
729 "GNS_CLEANUP-%llu: Terminating background lookup for %s\n", 722 "GNS_CLEANUP-%llu: Terminating background lookup\n",
730 rh->id, rh->name); 723 rh->id);
731 GNUNET_CONTAINER_heap_remove_node (node); 724 GNUNET_CONTAINER_heap_remove_node (node);
732 if (0 == GNUNET_CONTAINER_heap_get_size (dht_lookup_heap)) 725 if (0 == GNUNET_CONTAINER_heap_get_size (dht_lookup_heap))
733 { 726 {
@@ -753,36 +746,30 @@ free_resolver_handle (struct ResolverHandle* rh)
753 if (NULL == rh) 746 if (NULL == rh)
754 return; 747 return;
755 748
756 ac = rh->authority_chain_head; 749 ac_next = rh->authority_chain_head;
757 750 while (NULL != (ac = ac_next))
758 while (NULL != ac)
759 { 751 {
760 ac_next = ac->next; 752 ac_next = ac->next;
761 GNUNET_free (ac); 753 GNUNET_free (ac);
762 ac = ac_next;
763 } 754 }
764 755
765 if (NULL != rh->get_handle) 756 if (NULL != rh->get_handle)
766 GNUNET_DHT_get_stop (rh->get_handle); 757 GNUNET_DHT_get_stop (rh->get_handle);
767
768 if (NULL != rh->dns_raw_packet) 758 if (NULL != rh->dns_raw_packet)
769 GNUNET_free (rh->dns_raw_packet); 759 GNUNET_free (rh->dns_raw_packet);
770
771 if (NULL != rh->namestore_task) 760 if (NULL != rh->namestore_task)
761 {
772 GNUNET_NAMESTORE_cancel (rh->namestore_task); 762 GNUNET_NAMESTORE_cancel (rh->namestore_task);
773 rh->namestore_task = NULL; 763 rh->namestore_task = NULL;
774 764 }
775 if (GNUNET_SCHEDULER_NO_TASK != rh->dns_read_task) 765 if (GNUNET_SCHEDULER_NO_TASK != rh->dns_read_task)
776 GNUNET_SCHEDULER_cancel (rh->dns_read_task); 766 GNUNET_SCHEDULER_cancel (rh->dns_read_task);
777
778 if (GNUNET_SCHEDULER_NO_TASK != rh->timeout_task) 767 if (GNUNET_SCHEDULER_NO_TASK != rh->timeout_task)
779 GNUNET_SCHEDULER_cancel (rh->timeout_task); 768 GNUNET_SCHEDULER_cancel (rh->timeout_task);
780
781 if (NULL != rh->dns_sock) 769 if (NULL != rh->dns_sock)
782 GNUNET_NETWORK_socket_close (rh->dns_sock); 770 GNUNET_NETWORK_socket_close (rh->dns_sock);
783 if (NULL != rh->dns_resolver_handle) 771 if (NULL != rh->dns_resolver_handle)
784 GNUNET_RESOLVER_request_cancel (rh->dns_resolver_handle); 772 GNUNET_RESOLVER_request_cancel (rh->dns_resolver_handle);
785
786 if (NULL != rh->rd.data) 773 if (NULL != rh->rd.data)
787 GNUNET_free ((void*)(rh->rd.data)); 774 GNUNET_free ((void*)(rh->rd.data));
788 GNUNET_free (rh); 775 GNUNET_free (rh);
@@ -854,8 +841,9 @@ gns_resolver_cleanup ()
854 } 841 }
855 842
856 s = GNUNET_CONTAINER_heap_get_size (dht_lookup_heap); 843 s = GNUNET_CONTAINER_heap_get_size (dht_lookup_heap);
857 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 844 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
858 "GNS_CLEANUP: %d pending background queries to terminate\n", s); 845 "GNS_CLEANUP: %u pending background queries to terminate\n",
846 s);
859 if (0 != s) 847 if (0 != s)
860 GNUNET_CONTAINER_heap_iterate (dht_lookup_heap, 848 GNUNET_CONTAINER_heap_iterate (dht_lookup_heap,
861 &cleanup_pending_background_queries, 849 &cleanup_pending_background_queries,
@@ -866,6 +854,7 @@ gns_resolver_cleanup ()
866 &cleanup_pending_ns_tasks, 854 &cleanup_pending_ns_tasks,
867 NULL); 855 NULL);
868 } 856 }
857 // FIXME: what about freeing the heaps themselves?
869} 858}
870 859
871 860
@@ -953,7 +942,7 @@ dht_lookup_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
953{ 942{
954 struct ResolverHandle *rh = cls; 943 struct ResolverHandle *rh = cls;
955 struct RecordLookupHandle *rlh = rh->proc_cls; 944 struct RecordLookupHandle *rlh = rh->proc_cls;
956 char new_name[MAX_DNS_NAME_LENGTH]; 945 char new_name[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
957 946
958 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 947 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
959 "GNS_PHASE_REC-%llu: dht lookup for query %s (%llus) timed out.\n", 948 "GNS_PHASE_REC-%llu: dht lookup for query %s (%llus) timed out.\n",
@@ -961,7 +950,7 @@ dht_lookup_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
961 /** 950 /**
962 * Start resolution in bg 951 * Start resolution in bg
963 */ 952 */
964 GNUNET_snprintf (new_name, MAX_DNS_NAME_LENGTH, "%s.%s", 953 GNUNET_snprintf (new_name, GNUNET_DNSPARSER_MAX_NAME_LENGTH, "%s.%s",
965 rh->name, GNUNET_GNS_TLD); 954 rh->name, GNUNET_GNS_TLD);
966 955
967 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 956 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -1012,60 +1001,51 @@ process_record_result_dht (void* cls,
1012 enum GNUNET_BLOCK_Type type, 1001 enum GNUNET_BLOCK_Type type,
1013 size_t size, const void *data) 1002 size_t size, const void *data)
1014{ 1003{
1015 struct ResolverHandle *rh; 1004 struct ResolverHandle *rh = cls;
1016 struct RecordLookupHandle *rlh; 1005 struct RecordLookupHandle *rlh = rh->proc_cls;
1017 struct GNSNameRecordBlock *nrb; 1006 const struct GNSNameRecordBlock *nrb = data;
1018 uint32_t num_records; 1007 uint32_t num_records;
1019 char* name = NULL; 1008 const char* name;
1020 char* rd_data = (char*)data; 1009 const char* rd_data;
1021 int i; 1010 uint32_t i;
1022 int rd_size; 1011 size_t rd_size;
1023 1012
1024 rh = (struct ResolverHandle *)cls;
1025 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1013 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1026 "GNS_PHASE_REC-%llu: got dht result (size=%d)\n", rh->id, size); 1014 "GNS_PHASE_REC-%llu: got dht result (size=%d)\n", rh->id, size);
1027
1028 rlh = (struct RecordLookupHandle *) rh->proc_cls;
1029 nrb = (struct GNSNameRecordBlock*)data;
1030
1031 /* stop lookup and timeout task */ 1015 /* stop lookup and timeout task */
1032 GNUNET_DHT_get_stop (rh->get_handle); 1016 GNUNET_DHT_get_stop (rh->get_handle);
1033 rh->get_handle = NULL; 1017 rh->get_handle = NULL;
1034
1035 if (rh->dht_heap_node != NULL) 1018 if (rh->dht_heap_node != NULL)
1036 { 1019 {
1037 GNUNET_CONTAINER_heap_remove_node (rh->dht_heap_node); 1020 GNUNET_CONTAINER_heap_remove_node (rh->dht_heap_node);
1038 rh->dht_heap_node = NULL; 1021 rh->dht_heap_node = NULL;
1039 } 1022 }
1040
1041 if (rh->timeout_task != GNUNET_SCHEDULER_NO_TASK) 1023 if (rh->timeout_task != GNUNET_SCHEDULER_NO_TASK)
1042 { 1024 {
1043 GNUNET_SCHEDULER_cancel (rh->timeout_task); 1025 GNUNET_SCHEDULER_cancel (rh->timeout_task);
1044 rh->timeout_task = GNUNET_SCHEDULER_NO_TASK; 1026 rh->timeout_task = GNUNET_SCHEDULER_NO_TASK;
1045 } 1027 }
1046
1047 rh->get_handle = NULL; 1028 rh->get_handle = NULL;
1048 name = (char*)&nrb[1]; 1029 name = (const char*) &nrb[1];
1049 num_records = ntohl (nrb->rd_count); 1030 num_records = ntohl (nrb->rd_count);
1050 { 1031 {
1051 struct GNUNET_NAMESTORE_RecordData rd[num_records]; 1032 struct GNUNET_NAMESTORE_RecordData rd[num_records];
1052 struct NamestoreBGTask *ns_heap_root; 1033 struct NamestoreBGTask *ns_heap_root;
1053 struct NamestoreBGTask *namestore_bg_task; 1034 struct NamestoreBGTask *namestore_bg_task;
1054 1035
1055 rd_data += strlen (name) + 1 + sizeof (struct GNSNameRecordBlock); 1036 rd_data = &name[strlen (name) + 1];
1056 rd_size = size - strlen (name) - 1 - sizeof (struct GNSNameRecordBlock); 1037 rd_size = size - strlen (name) - 1 - sizeof (struct GNSNameRecordBlock);
1057 1038 if (GNUNET_SYSERR ==
1058 if (GNUNET_SYSERR == GNUNET_NAMESTORE_records_deserialize (rd_size, 1039 GNUNET_NAMESTORE_records_deserialize (rd_size,
1059 rd_data, 1040 rd_data,
1060 num_records, 1041 num_records,
1061 rd)) 1042 rd))
1062 { 1043 {
1063 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1044 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1064 "GNS_PHASE_REC-%llu: Error deserializing data!\n", rh->id); 1045 "GNS_PHASE_REC-%llu: Error deserializing data!\n", rh->id);
1065 rh->proc (rh->proc_cls, rh, 0, NULL); 1046 rh->proc (rh->proc_cls, rh, 0, NULL);
1066 return; 1047 return;
1067 } 1048 }
1068
1069 for (i = 0; i < num_records; i++) 1049 for (i = 0; i < num_records; i++)
1070 { 1050 {
1071 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1051 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -1120,14 +1100,11 @@ process_record_result_dht (void* cls,
1120 namestore_bg_task->node = GNUNET_CONTAINER_heap_insert (ns_task_heap, 1100 namestore_bg_task->node = GNUNET_CONTAINER_heap_insert (ns_task_heap,
1121 namestore_bg_task, 1101 namestore_bg_task,
1122 GNUNET_TIME_absolute_get().abs_value); 1102 GNUNET_TIME_absolute_get().abs_value);
1123
1124
1125 if (0 < rh->answered) 1103 if (0 < rh->answered)
1126 rh->proc (rh->proc_cls, rh, num_records, rd); 1104 rh->proc (rh->proc_cls, rh, num_records, rd);
1127 else 1105 else
1128 rh->proc (rh->proc_cls, rh, 0, NULL); 1106 rh->proc (rh->proc_cls, rh, 0, NULL);
1129 } 1107 }
1130
1131} 1108}
1132 1109
1133 1110
@@ -1140,9 +1117,9 @@ process_record_result_dht (void* cls,
1140static void 1117static void
1141resolve_record_dht (struct ResolverHandle *rh) 1118resolve_record_dht (struct ResolverHandle *rh)
1142{ 1119{
1120 struct RecordLookupHandle *rlh = rh->proc_cls;
1143 uint32_t xquery; 1121 uint32_t xquery;
1144 struct GNUNET_HashCode lookup_key; 1122 struct GNUNET_HashCode lookup_key;
1145 struct RecordLookupHandle *rlh = rh->proc_cls;
1146 struct ResolverHandle *rh_heap_root; 1123 struct ResolverHandle *rh_heap_root;
1147 1124
1148 GNUNET_GNS_get_key_for_record (rh->name, &rh->authority, &lookup_key); 1125 GNUNET_GNS_get_key_for_record (rh->name, &rh->authority, &lookup_key);
@@ -1233,35 +1210,26 @@ process_record_result_ns (void* cls,
1233 const struct GNUNET_NAMESTORE_RecordData *rd, 1210 const struct GNUNET_NAMESTORE_RecordData *rd,
1234 const struct GNUNET_CRYPTO_RsaSignature *signature) 1211 const struct GNUNET_CRYPTO_RsaSignature *signature)
1235{ 1212{
1236 struct ResolverHandle *rh; 1213 struct ResolverHandle *rh = cls;
1237 struct RecordLookupHandle *rlh; 1214 struct RecordLookupHandle *rlh = rh->proc_cls;
1238 struct GNUNET_TIME_Relative remaining_time; 1215 struct GNUNET_TIME_Relative remaining_time;
1239 struct GNUNET_CRYPTO_ShortHashCode zone; 1216 struct GNUNET_CRYPTO_ShortHashCode zone;
1240 struct GNUNET_TIME_Absolute et; 1217 struct GNUNET_TIME_Absolute et;
1241 unsigned int i; 1218 unsigned int i;
1242 1219
1243 rh = cls;
1244 rlh = rh->proc_cls;
1245
1246 rh->namestore_task = NULL; 1220 rh->namestore_task = NULL;
1247 GNUNET_CRYPTO_short_hash (key, 1221 GNUNET_CRYPTO_short_hash (key,
1248 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), 1222 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
1249 &zone); 1223 &zone);
1250 remaining_time = GNUNET_TIME_absolute_get_remaining (expiration); 1224 remaining_time = GNUNET_TIME_absolute_get_remaining (expiration);
1251
1252
1253
1254 rh->status = 0; 1225 rh->status = 0;
1255
1256 if (NULL != name) 1226 if (NULL != name)
1257 { 1227 {
1258 rh->status |= RSL_RECORD_EXISTS; 1228 rh->status |= RSL_RECORD_EXISTS;
1259
1260 if (remaining_time.rel_value == 0) 1229 if (remaining_time.rel_value == 0)
1261 rh->status |= RSL_RECORD_EXPIRED; 1230 rh->status |= RSL_RECORD_EXPIRED;
1262 } 1231 }
1263 1232 if (0 == rd_count)
1264 if (rd_count == 0)
1265 { 1233 {
1266 /** 1234 /**
1267 * Lookup terminated and no results 1235 * Lookup terminated and no results
@@ -1570,10 +1538,7 @@ read_dns_response (void *cls,
1570 finish_lookup (rh, rlh, 0, NULL); 1538 finish_lookup (rh, rlh, 0, NULL);
1571 return; 1539 return;
1572 } 1540 }
1573 1541 if (NULL == (packet = GNUNET_DNSPARSER_parse (buf, r)))
1574 packet = GNUNET_DNSPARSER_parse (buf, r);
1575
1576 if (NULL == packet)
1577 { 1542 {
1578 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1543 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1579 "Failed to parse DNS reply!\n"); 1544 "Failed to parse DNS reply!\n");
@@ -1584,9 +1549,9 @@ read_dns_response (void *cls,
1584 for (i = 0; i < packet->num_answers; i++) 1549 for (i = 0; i < packet->num_answers; i++)
1585 { 1550 {
1586 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1551 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1587 "Got record type %d (want %d)\n", 1552 "Got record type %d (want %d)\n",
1588 packet->answers[i].type, 1553 packet->answers[i].type,
1589 rlh->record_type); 1554 rlh->record_type);
1590 /* http://tools.ietf.org/html/rfc1034#section-3.6.2 */ 1555 /* http://tools.ietf.org/html/rfc1034#section-3.6.2 */
1591 if (packet->answers[i].type == GNUNET_GNS_RECORD_CNAME) 1556 if (packet->answers[i].type == GNUNET_GNS_RECORD_CNAME)
1592 { 1557 {
@@ -1641,8 +1606,7 @@ read_dns_response (void *cls,
1641 } 1606 }
1642 1607
1643 for (i = 0; i < packet->num_authority_records; i++) 1608 for (i = 0; i < packet->num_authority_records; i++)
1644 { 1609 {
1645
1646 if (packet->authority_records[i].type == GNUNET_GNS_RECORD_NS) 1610 if (packet->authority_records[i].type == GNUNET_GNS_RECORD_NS)
1647 { 1611 {
1648 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1612 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -1676,7 +1640,6 @@ read_dns_response (void *cls,
1676 "Nothing useful in DNS reply!\n"); 1640 "Nothing useful in DNS reply!\n");
1677 finish_lookup (rh, rlh, 0, NULL); 1641 finish_lookup (rh, rlh, 0, NULL);
1678 GNUNET_DNSPARSER_free_packet (packet); 1642 GNUNET_DNSPARSER_free_packet (packet);
1679 return;
1680} 1643}
1681 1644
1682 1645
@@ -1688,12 +1651,13 @@ read_dns_response (void *cls,
1688static void 1651static void
1689send_dns_packet (struct ResolverHandle *rh) 1652send_dns_packet (struct ResolverHandle *rh)
1690{ 1653{
1691 struct GNUNET_NETWORK_FDSet *rset = GNUNET_NETWORK_fdset_create (); 1654 struct GNUNET_NETWORK_FDSet *rset;
1692 GNUNET_NETWORK_fdset_set (rset, rh->dns_sock);
1693 1655
1656 rset = GNUNET_NETWORK_fdset_create ();
1657 GNUNET_NETWORK_fdset_set (rset, rh->dns_sock);
1694 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1658 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1695 "Sending %dbyte DNS query\n", 1659 "Sending %d byte DNS query\n",
1696 rh->dns_raw_packet_size); 1660 (int) rh->dns_raw_packet_size);
1697 1661
1698 if (GNUNET_SYSERR == 1662 if (GNUNET_SYSERR ==
1699 GNUNET_NETWORK_socket_sendto (rh->dns_sock, 1663 GNUNET_NETWORK_socket_sendto (rh->dns_sock,
@@ -1712,9 +1676,7 @@ send_dns_packet (struct ResolverHandle *rh)
1712 NULL, 1676 NULL,
1713 &read_dns_response, 1677 &read_dns_response,
1714 rh); 1678 rh);
1715
1716 GNUNET_NETWORK_fdset_destroy (rset); 1679 GNUNET_NETWORK_fdset_destroy (rset);
1717
1718} 1680}
1719 1681
1720 1682
@@ -1728,17 +1690,17 @@ send_dns_packet (struct ResolverHandle *rh)
1728 */ 1690 */
1729static void 1691static void
1730resolve_record_dns (struct ResolverHandle *rh, 1692resolve_record_dns (struct ResolverHandle *rh,
1731 int rd_count, 1693 unsigned int rd_count,
1732 const struct GNUNET_NAMESTORE_RecordData *rd) 1694 const struct GNUNET_NAMESTORE_RecordData *rd)
1733{ 1695{
1696 struct RecordLookupHandle *rlh = rh->proc_cls;
1734 struct GNUNET_DNSPARSER_Query query; 1697 struct GNUNET_DNSPARSER_Query query;
1735 struct GNUNET_DNSPARSER_Packet packet; 1698 struct GNUNET_DNSPARSER_Packet packet;
1736 struct GNUNET_DNSPARSER_Flags flags; 1699 struct GNUNET_DNSPARSER_Flags flags;
1737 struct in_addr dnsip; 1700 struct in_addr dnsip;
1738 struct sockaddr_in addr; 1701 struct sockaddr_in addr;
1739 struct sockaddr *sa; 1702 struct sockaddr *sa;
1740 int i; 1703 unsigned int i;
1741 struct RecordLookupHandle *rlh = rh->proc_cls;
1742 1704
1743 memset (&packet, 0, sizeof (struct GNUNET_DNSPARSER_Packet)); 1705 memset (&packet, 0, sizeof (struct GNUNET_DNSPARSER_Packet));
1744 memset (rh->dns_name, 0, sizeof (rh->dns_name)); 1706 memset (rh->dns_name, 0, sizeof (rh->dns_name));
@@ -1839,7 +1801,6 @@ resolve_record_dns (struct ResolverHandle *rh,
1839#if HAVE_SOCKADDR_IN_SIN_LEN 1801#if HAVE_SOCKADDR_IN_SIN_LEN
1840 rh->dns_addr.sin_len = (u_char) sizeof (struct sockaddr_in); 1802 rh->dns_addr.sin_len = (u_char) sizeof (struct sockaddr_in);
1841#endif 1803#endif
1842
1843 send_dns_packet (rh); 1804 send_dns_packet (rh);
1844} 1805}
1845 1806
@@ -1854,7 +1815,7 @@ resolve_record_dns (struct ResolverHandle *rh,
1854 */ 1815 */
1855static void 1816static void
1856resolve_record_vpn (struct ResolverHandle *rh, 1817resolve_record_vpn (struct ResolverHandle *rh,
1857 int rd_count, 1818 unsigned int rd_count,
1858 const struct GNUNET_NAMESTORE_RecordData *rd) 1819 const struct GNUNET_NAMESTORE_RecordData *rd)
1859{ 1820{
1860 struct RecordLookupHandle *rlh = rh->proc_cls; 1821 struct RecordLookupHandle *rlh = rh->proc_cls;
@@ -1880,8 +1841,6 @@ resolve_record_vpn (struct ResolverHandle *rh,
1880 } 1841 }
1881 1842
1882 vpn = (struct vpn_data*)rd->data; 1843 vpn = (struct vpn_data*)rd->data;
1883
1884
1885 GNUNET_CRYPTO_hash ((char*)&vpn[1], 1844 GNUNET_CRYPTO_hash ((char*)&vpn[1],
1886 strlen ((char*)&vpn[1]) + 1, 1845 strlen ((char*)&vpn[1]) + 1,
1887 &serv_desc); 1846 &serv_desc);
@@ -1934,7 +1893,7 @@ resolve_record_vpn (struct ResolverHandle *rh,
1934static void 1893static void
1935resolve_record_ns(struct ResolverHandle *rh) 1894resolve_record_ns(struct ResolverHandle *rh)
1936{ 1895{
1937 struct RecordLookupHandle *rlh = (struct RecordLookupHandle *)rh->proc_cls; 1896 struct RecordLookupHandle *rlh = rh->proc_cls;
1938 1897
1939 /* We cancel here as to not include the ns lookup in the timeout */ 1898 /* We cancel here as to not include the ns lookup in the timeout */
1940 if (GNUNET_SCHEDULER_NO_TASK != rh->timeout_task) 1899 if (GNUNET_SCHEDULER_NO_TASK != rh->timeout_task)
@@ -1980,7 +1939,7 @@ dht_authority_lookup_timeout (void *cls,
1980{ 1939{
1981 struct ResolverHandle *rh = cls; 1940 struct ResolverHandle *rh = cls;
1982 struct RecordLookupHandle *rlh = rh->proc_cls; 1941 struct RecordLookupHandle *rlh = rh->proc_cls;
1983 char new_name[MAX_DNS_NAME_LENGTH]; 1942 char new_name[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
1984 1943
1985 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1944 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1986 "GNS_PHASE_DELEGATE_DHT-%llu: dht lookup for query %s (%llus) timed out.\n", 1945 "GNS_PHASE_DELEGATE_DHT-%llu: dht lookup for query %s (%llus) timed out.\n",
@@ -2015,7 +1974,7 @@ dht_authority_lookup_timeout (void *cls,
2015 /** 1974 /**
2016 * Start resolution in bg 1975 * Start resolution in bg
2017 */ 1976 */
2018 GNUNET_snprintf (new_name, MAX_DNS_NAME_LENGTH, 1977 GNUNET_snprintf (new_name, GNUNET_DNSPARSER_MAX_NAME_LENGTH,
2019 "%s.%s.%s", 1978 "%s.%s.%s",
2020 rh->name, rh->authority_name, GNUNET_GNS_TLD); 1979 rh->name, rh->authority_name, GNUNET_GNS_TLD);
2021 strcpy (rh->name, new_name); 1980 strcpy (rh->name, new_name);
@@ -2043,7 +2002,7 @@ dht_authority_lookup_timeout (void *cls,
2043 * @param rh the pending gns query 2002 * @param rh the pending gns query
2044 */ 2003 */
2045static void 2004static void
2046resolve_delegation_dht(struct ResolverHandle *rh); 2005resolve_delegation_dht (struct ResolverHandle *rh);
2047 2006
2048 2007
2049/** 2008/**
@@ -2052,7 +2011,7 @@ resolve_delegation_dht(struct ResolverHandle *rh);
2052 * @param rh the resolver handle 2011 * @param rh the resolver handle
2053 */ 2012 */
2054static void 2013static void
2055resolve_delegation_ns(struct ResolverHandle *rh); 2014resolve_delegation_ns (struct ResolverHandle *rh);
2056 2015
2057 2016
2058/** 2017/**
@@ -2064,9 +2023,9 @@ resolve_delegation_ns(struct ResolverHandle *rh);
2064 * @param rd record data (always NULL) 2023 * @param rd record data (always NULL)
2065 */ 2024 */
2066static void 2025static void
2067handle_delegation_ns(void* cls, struct ResolverHandle *rh, 2026handle_delegation_ns (void* cls, struct ResolverHandle *rh,
2068 unsigned int rd_count, 2027 unsigned int rd_count,
2069 const struct GNUNET_NAMESTORE_RecordData *rd); 2028 const struct GNUNET_NAMESTORE_RecordData *rd);
2070 2029
2071 2030
2072/** 2031/**
@@ -2082,12 +2041,12 @@ handle_delegation_ns(void* cls, struct ResolverHandle *rh,
2082 */ 2041 */
2083static void 2042static void
2084process_pkey_revocation_result_ns (void *cls, 2043process_pkey_revocation_result_ns (void *cls,
2085 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *key, 2044 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *key,
2086 struct GNUNET_TIME_Absolute expiration, 2045 struct GNUNET_TIME_Absolute expiration,
2087 const char *name, 2046 const char *name,
2088 unsigned int rd_count, 2047 unsigned int rd_count,
2089 const struct GNUNET_NAMESTORE_RecordData *rd, 2048 const struct GNUNET_NAMESTORE_RecordData *rd,
2090 const struct GNUNET_CRYPTO_RsaSignature *signature) 2049 const struct GNUNET_CRYPTO_RsaSignature *signature)
2091{ 2050{
2092 struct ResolverHandle *rh = cls; 2051 struct ResolverHandle *rh = cls;
2093 struct GNUNET_TIME_Relative remaining_time; 2052 struct GNUNET_TIME_Relative remaining_time;
@@ -2223,10 +2182,7 @@ process_delegation_result_dht (void* cls,
2223 rh->id); 2182 rh->id);
2224 if (data == NULL) 2183 if (data == NULL)
2225 return; 2184 return;
2226 2185 /* stop dht lookup and timeout task */
2227 nrb = (struct GNSNameRecordBlock*)data;
2228
2229 /* stop dht lookup and timeout task */
2230 GNUNET_DHT_get_stop (rh->get_handle); 2186 GNUNET_DHT_get_stop (rh->get_handle);
2231 rh->get_handle = NULL; 2187 rh->get_handle = NULL;
2232 if (rh->dht_heap_node != NULL) 2188 if (rh->dht_heap_node != NULL)
@@ -2283,7 +2239,7 @@ process_delegation_result_dht (void* cls,
2283 if (0 == strcmp(rh->name, "")) 2239 if (0 == strcmp(rh->name, ""))
2284 strcpy(rh->name, rh->authority_name); 2240 strcpy(rh->name, rh->authority_name);
2285 else 2241 else
2286 GNUNET_snprintf(rh->name, MAX_DNS_NAME_LENGTH, "%s.%s", 2242 GNUNET_snprintf(rh->name, GNUNET_DNSPARSER_MAX_NAME_LENGTH, "%s.%s",
2287 rh->name, rh->authority_name); //FIXME ret 2243 rh->name, rh->authority_name); //FIXME ret
2288 rh->answered = 1; 2244 rh->answered = 1;
2289 break; 2245 break;
@@ -2408,7 +2364,7 @@ process_delegation_result_dht (void* cls,
2408 if (0 == strcmp(rh->name, "")) 2364 if (0 == strcmp(rh->name, ""))
2409 strcpy(rh->name, rh->authority_name); 2365 strcpy(rh->name, rh->authority_name);
2410 else 2366 else
2411 GNUNET_snprintf(rh->name, MAX_DNS_NAME_LENGTH, "%s.%s", 2367 GNUNET_snprintf(rh->name, GNUNET_DNSPARSER_MAX_NAME_LENGTH, "%s.%s",
2412 rh->name, rh->authority_name); //FIXME ret 2368 rh->name, rh->authority_name); //FIXME ret
2413 2369
2414 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2370 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
@@ -2421,9 +2377,9 @@ process_delegation_result_dht (void* cls,
2421 2377
2422//FIXME maybe define somewhere else? 2378//FIXME maybe define somewhere else?
2423#define MAX_SOA_LENGTH sizeof(uint32_t)+sizeof(uint32_t)+sizeof(uint32_t)+sizeof(uint32_t)\ 2379#define MAX_SOA_LENGTH sizeof(uint32_t)+sizeof(uint32_t)+sizeof(uint32_t)+sizeof(uint32_t)\
2424 +(MAX_DNS_NAME_LENGTH*2) 2380 +(GNUNET_DNSPARSER_MAX_NAME_LENGTH*2)
2425#define MAX_MX_LENGTH sizeof(uint16_t)+MAX_DNS_NAME_LENGTH 2381#define MAX_MX_LENGTH sizeof(uint16_t)+GNUNET_DNSPARSER_MAX_NAME_LENGTH
2426#define MAX_SRV_LENGTH (sizeof(uint16_t)*3)+MAX_DNS_NAME_LENGTH 2382#define MAX_SRV_LENGTH (sizeof(uint16_t)*3)+GNUNET_DNSPARSER_MAX_NAME_LENGTH
2427 2383
2428 2384
2429/** 2385/**
@@ -2485,7 +2441,7 @@ finish_lookup (struct ResolverHandle *rh,
2485 const struct GNUNET_NAMESTORE_RecordData *rd) 2441 const struct GNUNET_NAMESTORE_RecordData *rd)
2486{ 2442{
2487 unsigned int i; 2443 unsigned int i;
2488 char new_rr_data[MAX_DNS_NAME_LENGTH]; 2444 char new_rr_data[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
2489 char new_mx_data[MAX_MX_LENGTH]; 2445 char new_mx_data[MAX_MX_LENGTH];
2490 char new_soa_data[MAX_SOA_LENGTH]; 2446 char new_soa_data[MAX_SOA_LENGTH];
2491 char new_srv_data[MAX_SRV_LENGTH]; 2447 char new_srv_data[MAX_SRV_LENGTH];
@@ -2609,9 +2565,9 @@ finish_lookup (struct ResolverHandle *rh,
2609 * @param rd record data 2565 * @param rd record data
2610 */ 2566 */
2611static void 2567static void
2612handle_record_dht(void* cls, struct ResolverHandle *rh, 2568handle_record_dht (void* cls, struct ResolverHandle *rh,
2613 unsigned int rd_count, 2569 unsigned int rd_count,
2614 const struct GNUNET_NAMESTORE_RecordData *rd) 2570 const struct GNUNET_NAMESTORE_RecordData *rd)
2615{ 2571{
2616 struct RecordLookupHandle* rlh = cls; 2572 struct RecordLookupHandle* rlh = cls;
2617 2573
@@ -2712,6 +2668,8 @@ handle_record_ns (void* cls, struct ResolverHandle *rh,
2712 * Move one level up in the domain hierarchy and return the 2668 * Move one level up in the domain hierarchy and return the
2713 * passed top level domain. 2669 * passed top level domain.
2714 * 2670 *
2671 * FIXME: funky API: not only 'dest' is updated, so is 'name'!
2672 *
2715 * @param name the domain 2673 * @param name the domain
2716 * @param dest the destination where the tld will be put 2674 * @param dest the destination where the tld will be put
2717 */ 2675 */
@@ -2722,8 +2680,8 @@ pop_tld (char* name, char* dest)
2722 2680
2723 if (GNUNET_YES == is_canonical (name)) 2681 if (GNUNET_YES == is_canonical (name))
2724 { 2682 {
2725 strcpy(dest, name); 2683 strcpy (dest, name);
2726 strcpy(name, ""); 2684 strcpy (name, "");
2727 return; 2685 return;
2728 } 2686 }
2729 2687
@@ -2744,32 +2702,6 @@ pop_tld (char* name, char* dest)
2744 2702
2745 2703
2746/** 2704/**
2747 * Checks if name is in tld
2748 *
2749 * @param name the name to check
2750 * @param tld the TLD to check for
2751 * @return GNUNET_YES or GNUNET_NO
2752 */
2753int
2754is_tld(const char* name, const char* tld)
2755{
2756 int offset = 0;
2757
2758 if (strlen(name) <= strlen(tld))
2759 return GNUNET_NO;
2760
2761 offset = strlen(name)-strlen(tld);
2762 if (0 != strcmp(name+offset, tld))
2763 {
2764 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2765 "%s is not in .%s TLD\n", name, tld);
2766 return GNUNET_NO;
2767 }
2768 return GNUNET_YES;
2769}
2770
2771
2772/**
2773 * DHT resolution for delegation finished. Processing result. 2705 * DHT resolution for delegation finished. Processing result.
2774 * 2706 *
2775 * @param cls the closure 2707 * @param cls the closure
@@ -2891,6 +2823,32 @@ resolve_delegation_dht (struct ResolverHandle *rh)
2891 2823
2892 2824
2893/** 2825/**
2826 * Checks if name is in tld
2827 *
2828 * @param name the name to check
2829 * @param tld the TLD to check for
2830 * @return GNUNET_YES or GNUNET_NO
2831 */
2832int
2833is_tld (const char* name, const char* tld)
2834{
2835 size_t offset = 0;
2836
2837 if (strlen (name) <= strlen (tld))
2838 return GNUNET_NO;
2839
2840 offset = strlen (name) - strlen (tld);
2841 if (0 != strcmp (name + offset, tld))
2842 {
2843 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2844 "%s is not in .%s TLD\n", name, tld);
2845 return GNUNET_NO;
2846 }
2847 return GNUNET_YES;
2848}
2849
2850
2851/**
2894 * Namestore resolution for delegation finished. Processing result. 2852 * Namestore resolution for delegation finished. Processing result.
2895 * 2853 *
2896 * @param cls the closure 2854 * @param cls the closure
@@ -2903,10 +2861,9 @@ handle_delegation_ns (void* cls, struct ResolverHandle *rh,
2903 unsigned int rd_count, 2861 unsigned int rd_count,
2904 const struct GNUNET_NAMESTORE_RecordData *rd) 2862 const struct GNUNET_NAMESTORE_RecordData *rd)
2905{ 2863{
2906 struct RecordLookupHandle* rlh; 2864 struct RecordLookupHandle* rlh = cls;
2907 rlh = cls; 2865 int check_dht;
2908 int check_dht = GNUNET_YES; 2866 size_t s_len;
2909 int s_len = 0;
2910 2867
2911 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2868 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2912 "GNS_PHASE_DELEGATE_NS-%llu: Resolution status: %d.\n", 2869 "GNS_PHASE_DELEGATE_NS-%llu: Resolution status: %d.\n",
@@ -3063,6 +3020,7 @@ handle_delegation_ns (void* cls, struct ResolverHandle *rh,
3063 * or we are authority 3020 * or we are authority
3064 **/ 3021 **/
3065 3022
3023 check_dht = GNUNET_YES;
3066 if ((rh->status & RSL_RECORD_EXISTS) && 3024 if ((rh->status & RSL_RECORD_EXISTS) &&
3067 !(rh->status & RSL_RECORD_EXPIRED)) 3025 !(rh->status & RSL_RECORD_EXPIRED))
3068 check_dht = GNUNET_NO; 3026 check_dht = GNUNET_NO;
@@ -3130,7 +3088,7 @@ process_delegation_result_ns (void* cls,
3130 struct ResolverHandle *rh = cls; 3088 struct ResolverHandle *rh = cls;
3131 struct GNUNET_TIME_Relative remaining_time; 3089 struct GNUNET_TIME_Relative remaining_time;
3132 struct GNUNET_CRYPTO_ShortHashCode zone; 3090 struct GNUNET_CRYPTO_ShortHashCode zone;
3133 char new_name[MAX_DNS_NAME_LENGTH]; 3091 char new_name[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
3134 unsigned int i; 3092 unsigned int i;
3135 struct GNUNET_TIME_Absolute et; 3093 struct GNUNET_TIME_Absolute et;
3136 3094
@@ -3190,7 +3148,7 @@ process_delegation_result_ns (void* cls,
3190 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3148 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3191 "GNS_PHASE_DELEGATE_NS-%llu: Adding %s back to %s\n", 3149 "GNS_PHASE_DELEGATE_NS-%llu: Adding %s back to %s\n",
3192 rh->id, rh->authority_name, rh->name); 3150 rh->id, rh->authority_name, rh->name);
3193 GNUNET_snprintf (new_name, MAX_DNS_NAME_LENGTH, "%s.%s", 3151 GNUNET_snprintf (new_name, GNUNET_DNSPARSER_MAX_NAME_LENGTH, "%s.%s",
3194 rh->name, rh->authority_name); 3152 rh->name, rh->authority_name);
3195 strcpy (rh->name, new_name); 3153 strcpy (rh->name, new_name);
3196 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3154 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -3348,7 +3306,7 @@ process_delegation_result_ns (void* cls,
3348 } 3306 }
3349 else 3307 else
3350 { 3308 {
3351 GNUNET_snprintf (new_name, MAX_DNS_NAME_LENGTH, 3309 GNUNET_snprintf (new_name, GNUNET_DNSPARSER_MAX_NAME_LENGTH,
3352 "%s.%s", rh->name, rh->authority_name); 3310 "%s.%s", rh->name, rh->authority_name);
3353 strcpy (rh->name, new_name); 3311 strcpy (rh->name, new_name);
3354 rh->proc (rh->proc_cls, rh, 0, NULL); 3312 rh->proc (rh->proc_cls, rh, 0, NULL);
@@ -3405,8 +3363,8 @@ gns_resolver_lookup_record (struct GNUNET_CRYPTO_ShortHashCode zone,
3405{ 3363{
3406 struct ResolverHandle *rh; 3364 struct ResolverHandle *rh;
3407 struct RecordLookupHandle* rlh; 3365 struct RecordLookupHandle* rlh;
3408 char string_hash[MAX_DNS_LABEL_LENGTH]; 3366 char string_hash[GNUNET_DNSPARSER_MAX_LABEL_LENGTH];
3409 char nzkey[MAX_DNS_LABEL_LENGTH]; 3367 char nzkey[GNUNET_DNSPARSER_MAX_LABEL_LENGTH];
3410 char* nzkey_ptr = nzkey; 3368 char* nzkey_ptr = nzkey;
3411 3369
3412 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3370 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -3426,7 +3384,7 @@ gns_resolver_lookup_record (struct GNUNET_CRYPTO_ShortHashCode zone,
3426 rlh = GNUNET_malloc (sizeof(struct RecordLookupHandle)); 3384 rlh = GNUNET_malloc (sizeof(struct RecordLookupHandle));
3427 rh = GNUNET_malloc (sizeof (struct ResolverHandle)); 3385 rh = GNUNET_malloc (sizeof (struct ResolverHandle));
3428 rh->authority = zone; 3386 rh->authority = zone;
3429 rh->id = rid++; 3387 rh->id = rid_gen++;
3430 rh->proc_cls = rlh; 3388 rh->proc_cls = rlh;
3431 rh->priv_key = key; 3389 rh->priv_key = key;
3432 rh->timeout = timeout; 3390 rh->timeout = timeout;
@@ -3612,11 +3570,11 @@ process_zone_to_name_shorten_shorten (void *cls,
3612 const struct GNUNET_CRYPTO_RsaSignature *signature) 3570 const struct GNUNET_CRYPTO_RsaSignature *signature)
3613{ 3571{
3614 struct ResolverHandle *rh = cls; 3572 struct ResolverHandle *rh = cls;
3615 struct NameShortenHandle* nsh = (struct NameShortenHandle*)rh->proc_cls; 3573 struct NameShortenHandle* nsh = rh->proc_cls;
3616 struct AuthorityChain *next_authority; 3574 struct AuthorityChain *next_authority;
3617 3575
3618 char result[MAX_DNS_NAME_LENGTH]; 3576 char result[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
3619 char tmp_name[MAX_DNS_NAME_LENGTH]; 3577 char tmp_name[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
3620 size_t answer_len; 3578 size_t answer_len;
3621 3579
3622 rh->namestore_task = NULL; 3580 rh->namestore_task = NULL;
@@ -3684,7 +3642,7 @@ process_zone_to_name_shorten_shorten (void *cls,
3684 if (0 == strcmp (rh->name, "")) 3642 if (0 == strcmp (rh->name, ""))
3685 strcpy (tmp_name, next_authority->name); 3643 strcpy (tmp_name, next_authority->name);
3686 else 3644 else
3687 GNUNET_snprintf(tmp_name, MAX_DNS_NAME_LENGTH, 3645 GNUNET_snprintf(tmp_name, GNUNET_DNSPARSER_MAX_NAME_LENGTH,
3688 "%s.%s", rh->name, next_authority->name); 3646 "%s.%s", rh->name, next_authority->name);
3689 3647
3690 strcpy(rh->name, tmp_name); 3648 strcpy(rh->name, tmp_name);
@@ -3728,11 +3686,11 @@ process_zone_to_name_shorten_private (void *cls,
3728 const struct GNUNET_CRYPTO_RsaSignature *signature) 3686 const struct GNUNET_CRYPTO_RsaSignature *signature)
3729{ 3687{
3730 struct ResolverHandle *rh = cls; 3688 struct ResolverHandle *rh = cls;
3731 struct NameShortenHandle* nsh = (struct NameShortenHandle*)rh->proc_cls; 3689 struct NameShortenHandle* nsh = rh->proc_cls;
3732 struct AuthorityChain *next_authority; 3690 struct AuthorityChain *next_authority;
3733 3691
3734 char result[MAX_DNS_NAME_LENGTH]; 3692 char result[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
3735 char tmp_name[MAX_DNS_NAME_LENGTH]; 3693 char tmp_name[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
3736 size_t answer_len; 3694 size_t answer_len;
3737 3695
3738 rh->namestore_task = NULL; 3696 rh->namestore_task = NULL;
@@ -3798,7 +3756,7 @@ process_zone_to_name_shorten_private (void *cls,
3798 if (0 == strcmp (rh->name, "")) 3756 if (0 == strcmp (rh->name, ""))
3799 strcpy (tmp_name, next_authority->name); 3757 strcpy (tmp_name, next_authority->name);
3800 else 3758 else
3801 GNUNET_snprintf(tmp_name, MAX_DNS_NAME_LENGTH, 3759 GNUNET_snprintf(tmp_name, GNUNET_DNSPARSER_MAX_NAME_LENGTH,
3802 "%s.%s", rh->name, next_authority->name); 3760 "%s.%s", rh->name, next_authority->name);
3803 3761
3804 strcpy(rh->name, tmp_name); 3762 strcpy(rh->name, tmp_name);
@@ -3843,10 +3801,10 @@ process_zone_to_name_shorten_root (void *cls,
3843 const struct GNUNET_CRYPTO_RsaSignature *signature) 3801 const struct GNUNET_CRYPTO_RsaSignature *signature)
3844{ 3802{
3845 struct ResolverHandle *rh = cls; 3803 struct ResolverHandle *rh = cls;
3846 struct NameShortenHandle* nsh = (struct NameShortenHandle*)rh->proc_cls; 3804 struct NameShortenHandle* nsh = rh->proc_cls;
3847 struct AuthorityChain *next_authority; 3805 struct AuthorityChain *next_authority;
3848 char result[MAX_DNS_NAME_LENGTH]; 3806 char result[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
3849 char tmp_name[MAX_DNS_NAME_LENGTH]; 3807 char tmp_name[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
3850 size_t answer_len; 3808 size_t answer_len;
3851 3809
3852 rh->namestore_task = NULL; 3810 rh->namestore_task = NULL;
@@ -3920,7 +3878,7 @@ process_zone_to_name_shorten_root (void *cls,
3920 if (0 == strcmp (rh->name, "")) 3878 if (0 == strcmp (rh->name, ""))
3921 strcpy (tmp_name, next_authority->name); 3879 strcpy (tmp_name, next_authority->name);
3922 else 3880 else
3923 GNUNET_snprintf(tmp_name, MAX_DNS_NAME_LENGTH, 3881 GNUNET_snprintf(tmp_name, GNUNET_DNSPARSER_MAX_NAME_LENGTH,
3924 "%s.%s", rh->name, next_authority->name); 3882 "%s.%s", rh->name, next_authority->name);
3925 3883
3926 strcpy(rh->name, tmp_name); 3884 strcpy(rh->name, tmp_name);
@@ -3959,7 +3917,7 @@ handle_delegation_ns_shorten (void* cls,
3959 const struct GNUNET_NAMESTORE_RecordData *rd) 3917 const struct GNUNET_NAMESTORE_RecordData *rd)
3960{ 3918{
3961 struct NameShortenHandle *nsh; 3919 struct NameShortenHandle *nsh;
3962 char result[MAX_DNS_NAME_LENGTH]; 3920 char result[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
3963 3921
3964 nsh = (struct NameShortenHandle *)cls; 3922 nsh = (struct NameShortenHandle *)cls;
3965 rh->namestore_task = NULL; 3923 rh->namestore_task = NULL;
@@ -4067,7 +4025,7 @@ process_zone_to_name_zkey(void *cls,
4067{ 4025{
4068 struct ResolverHandle *rh = cls; 4026 struct ResolverHandle *rh = cls;
4069 struct NameShortenHandle *nsh = rh->proc_cls; 4027 struct NameShortenHandle *nsh = rh->proc_cls;
4070 char new_name[MAX_DNS_NAME_LENGTH]; 4028 char new_name[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
4071 4029
4072 rh->namestore_task = NULL; 4030 rh->namestore_task = NULL;
4073 4031
@@ -4084,10 +4042,10 @@ process_zone_to_name_zkey(void *cls,
4084 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 4042 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
4085 "No name found for zkey %s returning verbatim!\n", nsh->result); 4043 "No name found for zkey %s returning verbatim!\n", nsh->result);
4086 /*if (strcmp(rh->name, "") != 0) 4044 /*if (strcmp(rh->name, "") != 0)
4087 GNUNET_snprintf(new_name, MAX_DNS_NAME_LENGTH, "%s.%s.%s", 4045 GNUNET_snprintf(new_name, GNUNET_DNSPARSER_MAX_NAME_LENGTH, "%s.%s.%s",
4088 rh->name, enc, GNUNET_GNS_TLD_ZKEY); 4046 rh->name, enc, GNUNET_GNS_TLD_ZKEY);
4089 else 4047 else
4090 GNUNET_snprintf(new_name, MAX_DNS_NAME_LENGTH, "%s.%s", 4048 GNUNET_snprintf(new_name, GNUNET_DNSPARSER_MAX_NAME_LENGTH, "%s.%s",
4091 enc, GNUNET_GNS_TLD_ZKEY); 4049 enc, GNUNET_GNS_TLD_ZKEY);
4092 4050
4093 strcpy (nsh->result, new_name);*/ 4051 strcpy (nsh->result, new_name);*/
@@ -4097,7 +4055,7 @@ process_zone_to_name_zkey(void *cls,
4097 } 4055 }
4098 4056
4099 if (strcmp(rh->name, "") != 0) 4057 if (strcmp(rh->name, "") != 0)
4100 GNUNET_snprintf(new_name, MAX_DNS_NAME_LENGTH, "%s.%s", 4058 GNUNET_snprintf(new_name, GNUNET_DNSPARSER_MAX_NAME_LENGTH, "%s.%s",
4101 rh->name, name); 4059 rh->name, name);
4102 else 4060 else
4103 strcpy(new_name, name); 4061 strcpy(new_name, name);
@@ -4141,9 +4099,9 @@ gns_resolver_shorten_name (struct GNUNET_CRYPTO_ShortHashCode *zone,
4141{ 4099{
4142 struct ResolverHandle *rh; 4100 struct ResolverHandle *rh;
4143 struct NameShortenHandle *nsh; 4101 struct NameShortenHandle *nsh;
4144 char string_hash[MAX_DNS_LABEL_LENGTH]; 4102 char string_hash[GNUNET_DNSPARSER_MAX_LABEL_LENGTH];
4145 struct GNUNET_CRYPTO_ShortHashCode zkey; 4103 struct GNUNET_CRYPTO_ShortHashCode zkey;
4146 char nzkey[MAX_DNS_LABEL_LENGTH]; 4104 char nzkey[GNUNET_DNSPARSER_MAX_LABEL_LENGTH];
4147 char* nzkey_ptr = nzkey; 4105 char* nzkey_ptr = nzkey;
4148 4106
4149 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4107 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -4169,12 +4127,9 @@ gns_resolver_shorten_name (struct GNUNET_CRYPTO_ShortHashCode *zone,
4169 4127
4170 rh = GNUNET_malloc (sizeof (struct ResolverHandle)); 4128 rh = GNUNET_malloc (sizeof (struct ResolverHandle));
4171 rh->authority = *zone; 4129 rh->authority = *zone;
4172 rh->id = rid++; 4130 rh->id = rid_gen++;
4173 rh->priv_key = NULL;
4174 rh->namestore_task = NULL;
4175 rh->proc = &handle_delegation_ns_shorten; 4131 rh->proc = &handle_delegation_ns_shorten;
4176 rh->proc_cls = nsh; 4132 rh->proc_cls = nsh;
4177 rh->id = rid++;
4178 rh->private_local_zone = *zone; 4133 rh->private_local_zone = *zone;
4179 4134
4180 GNUNET_CONTAINER_DLL_insert (nsh_head, nsh_tail, rh); 4135 GNUNET_CONTAINER_DLL_insert (nsh_head, nsh_tail, rh);
@@ -4245,7 +4200,6 @@ gns_resolver_shorten_name (struct GNUNET_CRYPTO_ShortHashCode *zone,
4245 rh->authority_chain_tail = rh->authority_chain_head; 4200 rh->authority_chain_tail = rh->authority_chain_head;
4246 rh->authority_chain_head->zone = *zone; 4201 rh->authority_chain_head->zone = *zone;
4247 4202
4248
4249 /* Start delegation resolution in our namestore */ 4203 /* Start delegation resolution in our namestore */
4250 resolve_delegation_ns (rh); 4204 resolve_delegation_ns (rh);
4251} 4205}
@@ -4363,7 +4317,7 @@ gns_resolver_get_authority(struct GNUNET_CRYPTO_ShortHashCode zone,
4363 nah = GNUNET_malloc(sizeof (struct GetNameAuthorityHandle)); 4317 nah = GNUNET_malloc(sizeof (struct GetNameAuthorityHandle));
4364 rh = GNUNET_malloc(sizeof (struct ResolverHandle)); 4318 rh = GNUNET_malloc(sizeof (struct ResolverHandle));
4365 rh->authority = zone; 4319 rh->authority = zone;
4366 rh->id = rid++; 4320 rh->id = rid_gen++;
4367 rh->private_local_zone = pzone; 4321 rh->private_local_zone = pzone;
4368 4322
4369 GNUNET_CONTAINER_DLL_insert (nah_head, nah_tail, rh); 4323 GNUNET_CONTAINER_DLL_insert (nah_head, nah_tail, rh);
diff --git a/src/gns/gnunet-service-gns_resolver.h b/src/gns/gnunet-service-gns_resolver.h
index 466e93175..650c5c568 100644
--- a/src/gns/gnunet-service-gns_resolver.h
+++ b/src/gns/gnunet-service-gns_resolver.h
@@ -59,7 +59,7 @@ struct AuthorityChain
59 /** 59 /**
60 * (local) name of the authority 60 * (local) name of the authority
61 */ 61 */
62 char name[MAX_DNS_LABEL_LENGTH]; 62 char name[GNUNET_DNSPARSER_MAX_LABEL_LENGTH];
63 63
64 /** 64 /**
65 * was the ns entry fresh 65 * was the ns entry fresh
@@ -201,7 +201,7 @@ struct ResolverHandle
201 /** 201 /**
202 * The name to resolve 202 * The name to resolve
203 */ 203 */
204 char name[MAX_DNS_NAME_LENGTH]; 204 char name[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
205 205
206 /** 206 /**
207 * has this query been answered? how many matches 207 * has this query been answered? how many matches
@@ -221,7 +221,7 @@ struct ResolverHandle
221 /** 221 /**
222 * the name of the authoritative zone to query 222 * the name of the authoritative zone to query
223 */ 223 */
224 char authority_name[MAX_DNS_LABEL_LENGTH]; 224 char authority_name[GNUNET_DNSPARSER_MAX_LABEL_LENGTH];
225 225
226 /** 226 /**
227 * a handle for dht lookups. should be NULL if no lookups are in progress 227 * a handle for dht lookups. should be NULL if no lookups are in progress
@@ -246,12 +246,12 @@ struct ResolverHandle
246 /** 246 /**
247 * a synthesized dns name 247 * a synthesized dns name
248 */ 248 */
249 char dns_name[MAX_DNS_NAME_LENGTH]; 249 char dns_name[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
250 250
251 /** 251 /**
252 * the authoritative dns zone 252 * the authoritative dns zone
253 */ 253 */
254 char dns_zone[MAX_DNS_NAME_LENGTH]; 254 char dns_zone[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
255 255
256 /** 256 /**
257 * the address of the DNS server FIXME not needed? 257 * the address of the DNS server FIXME not needed?
@@ -361,7 +361,7 @@ struct RecordLookupHandle
361 /** 361 /**
362 * the name to look up 362 * the name to look up
363 */ 363 */
364 char name[MAX_DNS_NAME_LENGTH]; 364 char name[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
365 365
366 /** 366 /**
367 * Method to call on record resolution result 367 * Method to call on record resolution result
@@ -394,7 +394,7 @@ struct NameShortenHandle
394 /** 394 /**
395 * result of shorten 395 * result of shorten
396 */ 396 */
397 char result[MAX_DNS_NAME_LENGTH]; 397 char result[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
398 398
399 /** 399 /**
400 * root zone 400 * root zone
@@ -409,7 +409,7 @@ struct NameShortenHandle
409 /** 409 /**
410 * name of private zone 410 * name of private zone
411 */ 411 */
412 char private_zone_name[MAX_DNS_LABEL_LENGTH]; 412 char private_zone_name[GNUNET_DNSPARSER_MAX_LABEL_LENGTH];
413 413
414 /** 414 /**
415 * shorten zone 415 * shorten zone
@@ -419,7 +419,7 @@ struct NameShortenHandle
419 /** 419 /**
420 * name of shorten zone 420 * name of shorten zone
421 */ 421 */
422 char shorten_zone_name[MAX_DNS_LABEL_LENGTH]; 422 char shorten_zone_name[GNUNET_DNSPARSER_MAX_LABEL_LENGTH];
423 423
424}; 424};
425 425
@@ -432,12 +432,12 @@ struct GetNameAuthorityHandle
432 /** 432 /**
433 * the name to look up authority for 433 * the name to look up authority for
434 */ 434 */
435 char name[MAX_DNS_NAME_LENGTH]; 435 char name[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
436 436
437 /** 437 /**
438 * the result 438 * the result
439 */ 439 */
440 char result[MAX_DNS_NAME_LENGTH]; 440 char result[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
441 441
442 /** 442 /**
443 * Method to call on result 443 * Method to call on result
@@ -469,12 +469,12 @@ struct GetPseuAuthorityHandle
469 /** 469 /**
470 * the name to store the zone under 470 * the name to store the zone under
471 */ 471 */
472 char name[MAX_DNS_LABEL_LENGTH]; 472 char name[GNUNET_DNSPARSER_MAX_LABEL_LENGTH];
473 473
474 /** 474 /**
475 * test name to store the zone under 475 * test name to store the zone under
476 */ 476 */
477 char test_name[MAX_DNS_LABEL_LENGTH]; 477 char test_name[GNUNET_DNSPARSER_MAX_LABEL_LENGTH];
478 478
479 /** 479 /**
480 * the zone of our authority 480 * the zone of our authority
diff --git a/src/gns/test_gns_cname_lookup.c b/src/gns/test_gns_cname_lookup.c
index f73d7b0d8..643a79033 100644
--- a/src/gns/test_gns_cname_lookup.c
+++ b/src/gns/test_gns_cname_lookup.c
@@ -164,32 +164,32 @@ on_lookup_result_dns (void *cls,
164 if (rd_count == 0) 164 if (rd_count == 0)
165 { 165 {
166 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 166 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
167 "Lookup failed, rp_filtering?\n"); 167 "CNAME to DNS delegation failed. System offline?\n");
168 ok = 2;
169 GNUNET_SCHEDULER_shutdown ();
170 return;
171 } 168 }
172 ok = 1; 169 else
173 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "name: %s\n", (char*)cls);
174 for (i=0; i<rd_count; i++)
175 { 170 {
176 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "type: %d\n", rd[i].record_type); 171 ok = 1;
177 if (rd[i].record_type == GNUNET_GNS_RECORD_A) 172 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "name: %s\n", (char*)cls);
173 for (i=0; i<rd_count; i++)
178 { 174 {
179 memcpy(&a, rd[i].data, sizeof(a)); 175 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "type: %d\n", rd[i].record_type);
180 addr = inet_ntoa(a); 176 if (rd[i].record_type == GNUNET_GNS_RECORD_A)
181 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "address: %s\n", addr);
182 if (0 == strcmp(addr, TEST_IP_DNS))
183 { 177 {
184 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 178 memcpy(&a, rd[i].data, sizeof(a));
185 "%s correctly resolved to %s!\n", TEST_DOMAIN_DNS, addr); 179 addr = inet_ntoa(a);
186 ok = 0; 180 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "address: %s\n", addr);
181 if (0 == strcmp(addr, TEST_IP_DNS))
182 {
183 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
184 "%s correctly resolved to %s!\n", TEST_DOMAIN_DNS, addr);
185 ok = 0;
186 }
187 } 187 }
188 } 188 else
189 else
190 { 189 {
191 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No resolution!\n"); 190 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No resolution!\n");
192 } 191 }
192 }
193 } 193 }
194 GNUNET_GNS_lookup (gns_handle, TEST_DOMAIN_PLUS, GNUNET_GNS_RECORD_CNAME, 194 GNUNET_GNS_lookup (gns_handle, TEST_DOMAIN_PLUS, GNUNET_GNS_RECORD_CNAME,
195 GNUNET_YES, 195 GNUNET_YES,
diff --git a/src/gns/test_gns_max_queries.c b/src/gns/test_gns_max_queries.c
index fae90bf72..aadd1a8fa 100644
--- a/src/gns/test_gns_max_queries.c
+++ b/src/gns/test_gns_max_queries.c
@@ -212,7 +212,7 @@ static void
212commence_testing (void *cls, int32_t success, const char *emsg) 212commence_testing (void *cls, int32_t success, const char *emsg)
213{ 213{
214 int i; 214 int i;
215 char lookup_name[MAX_DNS_NAME_LENGTH]; 215 char lookup_name[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
216 struct GNUNET_GNS_LookupRequest *lr; 216 struct GNUNET_GNS_LookupRequest *lr;
217 217
218 gns_handle = GNUNET_GNS_connect(cfg); 218 gns_handle = GNUNET_GNS_connect(cfg);
@@ -229,7 +229,7 @@ commence_testing (void *cls, int32_t success, const char *emsg)
229 for (i=0; i<max_parallel_lookups+TEST_ADDITIONAL_LOOKUPS; i++) 229 for (i=0; i<max_parallel_lookups+TEST_ADDITIONAL_LOOKUPS; i++)
230 { 230 {
231 GNUNET_snprintf(lookup_name, 231 GNUNET_snprintf(lookup_name,
232 MAX_DNS_NAME_LENGTH, 232 GNUNET_DNSPARSER_MAX_NAME_LENGTH,
233 "www.doesnotexist-%d.bob.gads", i); 233 "www.doesnotexist-%d.bob.gads", i);
234 lr = GNUNET_GNS_lookup (gns_handle, lookup_name, GNUNET_GNS_RECORD_A, 234 lr = GNUNET_GNS_lookup (gns_handle, lookup_name, GNUNET_GNS_RECORD_A,
235 GNUNET_NO, 235 GNUNET_NO,
diff --git a/src/gns/test_gns_simple_zkey_lookup.c b/src/gns/test_gns_simple_zkey_lookup.c
index 4fbd6af72..eaf97b9cc 100644
--- a/src/gns/test_gns_simple_zkey_lookup.c
+++ b/src/gns/test_gns_simple_zkey_lookup.c
@@ -162,7 +162,7 @@ on_lookup_result(void *cls, uint32_t rd_count,
162static void 162static void
163commence_testing (void *cls, int32_t success, const char *emsg) 163commence_testing (void *cls, int32_t success, const char *emsg)
164{ 164{
165 char name[MAX_DNS_NAME_LENGTH]; 165 char name[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
166 char* pos; 166 char* pos;
167 struct GNUNET_CRYPTO_ShortHashAsciiEncoded hash_str; 167 struct GNUNET_CRYPTO_ShortHashAsciiEncoded hash_str;
168 168
diff --git a/src/include/gnunet_common.h b/src/include/gnunet_common.h
index bba5152c5..dc842c34c 100644
--- a/src/include/gnunet_common.h
+++ b/src/include/gnunet_common.h
@@ -238,7 +238,7 @@ struct GNUNET_MessageHeader
238 238
239 239
240/** 240/**
241 * @brief 512-bit hashcode 241 * @brief A SHA-512 hashcode
242 */ 242 */
243struct GNUNET_HashCode 243struct GNUNET_HashCode
244{ 244{
@@ -247,9 +247,8 @@ struct GNUNET_HashCode
247 247
248 248
249/** 249/**
250 * FIXME 250 * @brief A SHA-256 hashcode
251 * @brief 256-bit hashcode 251 */
252 **/
253struct GNUNET_CRYPTO_ShortHashCode 252struct GNUNET_CRYPTO_ShortHashCode
254{ 253{
255 uint32_t bits[256 / 8 / sizeof (uint32_t)]; /* = 8 */ 254 uint32_t bits[256 / 8 / sizeof (uint32_t)]; /* = 8 */
diff --git a/src/include/gnunet_dnsparser_lib.h b/src/include/gnunet_dnsparser_lib.h
index f460bbad4..526c40ab2 100644
--- a/src/include/gnunet_dnsparser_lib.h
+++ b/src/include/gnunet_dnsparser_lib.h
@@ -31,6 +31,17 @@
31#include "gnunet_common.h" 31#include "gnunet_common.h"
32 32
33/** 33/**
34 * Maximum length of a label in DNS.
35 */
36#define GNUNET_DNSPARSER_MAX_LABEL_LENGTH 63
37
38/**
39 * Maximum length of a name in DNS.
40 */
41#define GNUNET_DNSPARSER_MAX_NAME_LENGTH 253
42
43
44/**
34 * A few common DNS types. 45 * A few common DNS types.
35 */ 46 */
36#define GNUNET_DNSPARSER_TYPE_A 1 47#define GNUNET_DNSPARSER_TYPE_A 1
diff --git a/src/include/gnunet_namestore_service.h b/src/include/gnunet_namestore_service.h
index c381cc920..4267e2044 100644
--- a/src/include/gnunet_namestore_service.h
+++ b/src/include/gnunet_namestore_service.h
@@ -526,16 +526,6 @@ GNUNET_NAMESTORE_records_deserialize (size_t len,
526 526
527 527
528/** 528/**
529 * Checks if a name is wellformed
530 *
531 * @param name the name to check
532 * @return GNUNET_OK on success, GNUNET_SYSERR on error
533 */
534int
535GNUNET_NAMESTORE_check_name (const char * name);
536
537
538/**
539 * Convert the 'value' of a record to a string. 529 * Convert the 'value' of a record to a string.
540 * 530 *
541 * @param type type of the record 531 * @param type type of the record
diff --git a/src/namestore/namestore_common.c b/src/namestore/namestore_common.c
index 8c42bad67..47029b73b 100644
--- a/src/namestore/namestore_common.c
+++ b/src/namestore/namestore_common.c
@@ -318,22 +318,6 @@ GNUNET_NAMESTORE_create_signature (const struct GNUNET_CRYPTO_RsaPrivateKey *key
318 return sig; 318 return sig;
319} 319}
320 320
321/**
322 * Checks if a name is wellformed
323 *
324 * @param name the name to check
325 * @return GNUNET_OK on success, GNUNET_SYSERR on error
326 */
327int
328GNUNET_NAMESTORE_check_name (const char * name)
329{
330 if (name == NULL)
331 return GNUNET_SYSERR;
332 if (strlen (name) > 63)
333 return GNUNET_SYSERR;
334 return GNUNET_OK;
335}
336
337 321
338/** 322/**
339 * Convert the 'value' of a record to a string. 323 * Convert the 'value' of a record to a string.
@@ -489,11 +473,11 @@ GNUNET_NAMESTORE_string_to_value (uint32_t type,
489 struct soa_data *soa; 473 struct soa_data *soa;
490 struct vpn_data *vpn; 474 struct vpn_data *vpn;
491 struct tlsa_data *tlsa; 475 struct tlsa_data *tlsa;
492 char result[253]; 476 char result[253 + 1];
493 char soa_rname[63]; 477 char soa_rname[253 + 1];
494 char soa_mname[63]; 478 char soa_mname[253 + 1];
495 char s_peer[104]; 479 char s_peer[103 + 1];
496 char s_serv[253]; 480 char s_serv[253 + 1];
497 uint32_t soa_serial; 481 uint32_t soa_serial;
498 uint32_t soa_refresh; 482 uint32_t soa_refresh;
499 uint32_t soa_retry; 483 uint32_t soa_retry;
@@ -502,15 +486,22 @@ GNUNET_NAMESTORE_string_to_value (uint32_t type,
502 uint16_t mx_pref; 486 uint16_t mx_pref;
503 uint16_t mx_pref_n; 487 uint16_t mx_pref_n;
504 uint16_t proto; 488 uint16_t proto;
505 int ret;
506 489
507 switch (type) 490 switch (type)
508 { 491 {
509 case 0: 492 case 0:
493 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
494 _("Unsupported record type %d\n"),
495 (int) type);
510 return GNUNET_SYSERR; 496 return GNUNET_SYSERR;
511 case GNUNET_DNSPARSER_TYPE_A: 497 case GNUNET_DNSPARSER_TYPE_A:
512 if (1 != inet_pton (AF_INET, s, &value_a)) 498 if (1 != inet_pton (AF_INET, s, &value_a))
499 {
500 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
501 _("Unable to parse IPv4 address `%s'\n"),
502 s);
513 return GNUNET_SYSERR; 503 return GNUNET_SYSERR;
504 }
514 *data = GNUNET_malloc (sizeof (struct in_addr)); 505 *data = GNUNET_malloc (sizeof (struct in_addr));
515 memcpy (*data, &value_a, sizeof (value_a)); 506 memcpy (*data, &value_a, sizeof (value_a));
516 *data_size = sizeof (value_a); 507 *data_size = sizeof (value_a);
@@ -524,13 +515,16 @@ GNUNET_NAMESTORE_string_to_value (uint32_t type,
524 *data_size = strlen (s) + 1; 515 *data_size = strlen (s) + 1;
525 return GNUNET_OK; 516 return GNUNET_OK;
526 case GNUNET_DNSPARSER_TYPE_SOA: 517 case GNUNET_DNSPARSER_TYPE_SOA:
527 518 if (7 != SSCANF (s,
528 if (SSCANF(s, "rname=%s mname=%s %u,%u,%u,%u,%u", 519 "rname=%253s mname=%253s %u,%u,%u,%u,%u",
529 soa_rname, soa_mname, 520 soa_rname, soa_mname,
530 &soa_serial, &soa_refresh, &soa_retry, &soa_expire, &soa_min) 521 &soa_serial, &soa_refresh, &soa_retry, &soa_expire, &soa_min))
531 != 7) 522 {
523 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
524 _("Unable to parse SOA record `%s'\n"),
525 s);
532 return GNUNET_SYSERR; 526 return GNUNET_SYSERR;
533 527 }
534 *data_size = sizeof (struct soa_data)+strlen(soa_rname)+strlen(soa_mname)+2; 528 *data_size = sizeof (struct soa_data)+strlen(soa_rname)+strlen(soa_mname)+2;
535 *data = GNUNET_malloc (*data_size); 529 *data = GNUNET_malloc (*data_size);
536 soa = (struct soa_data*)*data; 530 soa = (struct soa_data*)*data;
@@ -542,14 +536,18 @@ GNUNET_NAMESTORE_string_to_value (uint32_t type,
542 strcpy((char*)&soa[1], soa_rname); 536 strcpy((char*)&soa[1], soa_rname);
543 strcpy((char*)&soa[1]+strlen(*data)+1, soa_mname); 537 strcpy((char*)&soa[1]+strlen(*data)+1, soa_mname);
544 return GNUNET_OK; 538 return GNUNET_OK;
545
546 case GNUNET_DNSPARSER_TYPE_PTR: 539 case GNUNET_DNSPARSER_TYPE_PTR:
547 *data = GNUNET_strdup (s); 540 *data = GNUNET_strdup (s);
548 *data_size = strlen (s); 541 *data_size = strlen (s);
549 return GNUNET_OK; 542 return GNUNET_OK;
550 case GNUNET_DNSPARSER_TYPE_MX: 543 case GNUNET_DNSPARSER_TYPE_MX:
551 if (SSCANF(s, "%hu,%s", &mx_pref, result) != 2) 544 if (2 != SSCANF(s, "%hu,%253s", &mx_pref, result))
545 {
546 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
547 _("Unable to parse MX record `%s'\n"),
548 s);
552 return GNUNET_SYSERR; 549 return GNUNET_SYSERR;
550 }
553 *data_size = sizeof (uint16_t)+strlen(result)+1; 551 *data_size = sizeof (uint16_t)+strlen(result)+1;
554 *data = GNUNET_malloc (*data_size); 552 *data = GNUNET_malloc (*data_size);
555 mx_pref_n = htons(mx_pref); 553 mx_pref_n = htons(mx_pref);
@@ -562,7 +560,12 @@ GNUNET_NAMESTORE_string_to_value (uint32_t type,
562 return GNUNET_OK; 560 return GNUNET_OK;
563 case GNUNET_DNSPARSER_TYPE_AAAA: 561 case GNUNET_DNSPARSER_TYPE_AAAA:
564 if (1 != inet_pton (AF_INET6, s, &value_aaaa)) 562 if (1 != inet_pton (AF_INET6, s, &value_aaaa))
565 return GNUNET_SYSERR; 563 {
564 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
565 _("Unable to parse IPv6 address `%s'\n"),
566 s);
567 return GNUNET_SYSERR;
568 }
566 *data = GNUNET_malloc (sizeof (struct in6_addr)); 569 *data = GNUNET_malloc (sizeof (struct in6_addr));
567 *data_size = sizeof (struct in6_addr); 570 *data_size = sizeof (struct in6_addr);
568 memcpy (*data, &value_aaaa, sizeof (value_aaaa)); 571 memcpy (*data, &value_aaaa, sizeof (value_aaaa));
@@ -570,7 +573,12 @@ GNUNET_NAMESTORE_string_to_value (uint32_t type,
570 case GNUNET_NAMESTORE_TYPE_PKEY: 573 case GNUNET_NAMESTORE_TYPE_PKEY:
571 if (GNUNET_OK != 574 if (GNUNET_OK !=
572 GNUNET_CRYPTO_short_hash_from_string (s, &pkey)) 575 GNUNET_CRYPTO_short_hash_from_string (s, &pkey))
576 {
577 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
578 _("Unable to parse PKEY record `%s'\n"),
579 s);
573 return GNUNET_SYSERR; 580 return GNUNET_SYSERR;
581 }
574 *data = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_ShortHashCode)); 582 *data = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_ShortHashCode));
575 memcpy (*data, &pkey, sizeof (pkey)); 583 memcpy (*data, &pkey, sizeof (pkey));
576 *data_size = sizeof (struct GNUNET_CRYPTO_ShortHashCode); 584 *data_size = sizeof (struct GNUNET_CRYPTO_ShortHashCode);
@@ -584,52 +592,49 @@ GNUNET_NAMESTORE_string_to_value (uint32_t type,
584 *data_size = strlen (s); 592 *data_size = strlen (s);
585 return GNUNET_OK; 593 return GNUNET_OK;
586 case GNUNET_NAMESTORE_TYPE_VPN: 594 case GNUNET_NAMESTORE_TYPE_VPN:
587 595 if (3 != SSCANF (s,"%hu %103s %253s",
588 ret = SSCANF (s,"%hu %s %s", 596 &proto, s_peer, s_serv))
589 &proto, s_peer, s_serv);
590 if (3 != ret)
591 { 597 {
592 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 598 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
593 "Unable to parse VPN record string %s %d\n", s, ret); 599 _("Unable to parse VPN record string `%s'\n"),
600 s);
594 return GNUNET_SYSERR; 601 return GNUNET_SYSERR;
595 } 602 }
596 *data_size = sizeof (struct vpn_data) + strlen (s_serv) + 1; 603 *data_size = sizeof (struct vpn_data) + strlen (s_serv) + 1;
597 *data = GNUNET_malloc (*data_size); 604 *data = vpn = GNUNET_malloc (*data_size);
598 605 if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string ((char*)&s_peer,
599 vpn = (struct vpn_data*)*data; 606 &vpn->peer))
600
601 if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string ((char*)&s_peer, &vpn->peer))
602 { 607 {
603 GNUNET_free (*data); 608 GNUNET_free (vpn);
609 *data_size = 0;
604 return GNUNET_SYSERR; 610 return GNUNET_SYSERR;
605 } 611 }
606
607 vpn->proto = htons (proto); 612 vpn->proto = htons (proto);
608 strcpy ((char*)&vpn[1], s_serv); 613 strcpy ((char*)&vpn[1], s_serv);
609 return GNUNET_OK; 614 return GNUNET_OK;
610 case GNUNET_DNSPARSER_TYPE_TLSA: 615 case GNUNET_DNSPARSER_TYPE_TLSA:
611 *data_size = sizeof (struct tlsa_data) + strlen (s) - 6; 616 *data_size = sizeof (struct tlsa_data) + strlen (s) - 6;
612 *data = GNUNET_malloc (*data_size); 617 *data = tlsa = GNUNET_malloc (*data_size);
613 tlsa = (struct tlsa_data*)*data; 618 if (4 != SSCANF (s, "%c %c %c %s",
614 ret = SSCANF (s, "%c %c %c %s", 619 &tlsa->usage,
615 &tlsa->usage, 620 &tlsa->selector,
616 &tlsa->selector, 621 &tlsa->matching_type,
617 &tlsa->matching_type, 622 (char*)&tlsa[1]))
618 (char*)&tlsa[1]);
619
620 if (4 != ret)
621 { 623 {
622 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 624 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
623 "Unable to parse TLSA record string %s\n", s); 625 _("Unable to parse TLSA record string `%s'\n"),
626 s);
624 *data_size = 0; 627 *data_size = 0;
625 GNUNET_free (tlsa); 628 GNUNET_free (tlsa);
626 return GNUNET_SYSERR; 629 return GNUNET_SYSERR;
627 } 630 }
628 return GNUNET_OK; 631 return GNUNET_OK;
629 default: 632 default:
630 GNUNET_break (0); 633 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
634 _("Unsupported record type %d\n"),
635 (int) type);
636 return GNUNET_SYSERR;
631 } 637 }
632 return GNUNET_SYSERR;
633} 638}
634 639
635 640