diff options
author | Martin Schanzenbach <mschanzenbach@posteo.de> | 2012-03-19 14:17:20 +0000 |
---|---|---|
committer | Martin Schanzenbach <mschanzenbach@posteo.de> | 2012-03-19 14:17:20 +0000 |
commit | 548d396eee189ed02c243dcb47bcd1f02a1f1e07 (patch) | |
tree | f576984dbb71587a6930442b626e48da0dbc480e | |
parent | ab700c23613c8f1df85fe17134a93782d2bd42a2 (diff) | |
download | gnunet-548d396eee189ed02c243dcb47bcd1f02a1f1e07.tar.gz gnunet-548d396eee189ed02c243dcb47bcd1f02a1f1e07.zip |
-less malloc more stack
-rw-r--r-- | src/gns/gns.h | 1 | ||||
-rw-r--r-- | src/gns/gnunet-service-gns_interceptor.c | 21 | ||||
-rw-r--r-- | src/gns/gnunet-service-gns_resolver.c | 157 | ||||
-rw-r--r-- | src/gns/gnunet-service-gns_resolver.h | 15 |
4 files changed, 112 insertions, 82 deletions
diff --git a/src/gns/gns.h b/src/gns/gns.h index b2f4cc98d..0f9d77537 100644 --- a/src/gns/gns.h +++ b/src/gns/gns.h | |||
@@ -29,6 +29,7 @@ | |||
29 | #define GNS_H | 29 | #define GNS_H |
30 | 30 | ||
31 | #define GNUNET_GNS_TLD "gnunet" | 31 | #define GNUNET_GNS_TLD "gnunet" |
32 | #define GNUNET_GNS_TLD_ZKEY "zkey" | ||
32 | #define GNUNET_GNS_DHT_MAX_UPDATE_INTERVAL 3600 | 33 | #define GNUNET_GNS_DHT_MAX_UPDATE_INTERVAL 3600 |
33 | 34 | ||
34 | GNUNET_NETWORK_STRUCT_BEGIN | 35 | GNUNET_NETWORK_STRUCT_BEGIN |
diff --git a/src/gns/gnunet-service-gns_interceptor.c b/src/gns/gnunet-service-gns_interceptor.c index 4160893ad..15289fc35 100644 --- a/src/gns/gnunet-service-gns_interceptor.c +++ b/src/gns/gnunet-service-gns_interceptor.c | |||
@@ -140,8 +140,25 @@ reply_to_dns(void* cls, uint32_t rd_count, | |||
140 | { | 140 | { |
141 | additional_records[i].name = ilh->query->name; | 141 | additional_records[i].name = ilh->query->name; |
142 | additional_records[i].type = rd[i].record_type; | 142 | additional_records[i].type = rd[i].record_type; |
143 | additional_records[i].data.raw.data_len = rd[i].data_size; | 143 | switch(rd[i].record_type) |
144 | additional_records[i].data.raw.data = (char*)rd[i].data; | 144 | { |
145 | case GNUNET_GNS_RECORD_TYPE_NS: | ||
146 | case GNUNET_GNS_RECORD_TYPE_CNAME: | ||
147 | case GNUNET_GNS_RECORD_TYPE_PTR: | ||
148 | additional_records[i].data.hostname = (char*)rd[i].data; | ||
149 | break; | ||
150 | case GNUNET_GNS_RECORD_TYPE_SOA: | ||
151 | additional_records[i].data.soa = | ||
152 | (struct GNUNET_DNSPARSER_SoaRecord *)rd[i].data; | ||
153 | break; | ||
154 | case GNUNET_GNS_RECORD_MX: | ||
155 | additional_records[i].data.mx = | ||
156 | (struct GNUNET_DNSPARSER_MxRecord *)rd[i].data; | ||
157 | break; | ||
158 | default: | ||
159 | additional_records[i].data.raw.data_len = rd[i].data_size; | ||
160 | additional_records[i].data.raw.data = (char*)rd[i].data; | ||
161 | } | ||
145 | additional_records[i].expiration_time = rd[i].expiration; | 162 | additional_records[i].expiration_time = rd[i].expiration; |
146 | additional_records[i].class = GNUNET_DNSPARSER_CLASS_INTERNET;//hmmn | 163 | additional_records[i].class = GNUNET_DNSPARSER_CLASS_INTERNET;//hmmn |
147 | } | 164 | } |
diff --git a/src/gns/gnunet-service-gns_resolver.c b/src/gns/gnunet-service-gns_resolver.c index 077dca039..13c903806 100644 --- a/src/gns/gnunet-service-gns_resolver.c +++ b/src/gns/gnunet-service-gns_resolver.c | |||
@@ -85,16 +85,12 @@ process_pseu_lookup_ns(void* cls, | |||
85 | { | 85 | { |
86 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 86 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
87 | "Intelligent replacement not implemented\n", name); | 87 | "Intelligent replacement not implemented\n", name); |
88 | GNUNET_free(gph->new_name); | ||
89 | GNUNET_free(gph->name); | ||
90 | GNUNET_free(gph); | 88 | GNUNET_free(gph); |
91 | return; | 89 | return; |
92 | } | 90 | } |
93 | 91 | ||
94 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 92 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
95 | "Trying delegated name %s\n", gph->name); | 93 | "Trying delegated name %s\n", gph->name); |
96 | GNUNET_free(gph->new_name); | ||
97 | gph->new_name = GNUNET_malloc(strlen(gph->name)+1); | ||
98 | memcpy(gph->new_name, gph->name, strlen(gph->name)+1); | 94 | memcpy(gph->new_name, gph->name, strlen(gph->name)+1); |
99 | GNUNET_NAMESTORE_lookup_record(namestore_handle, | 95 | GNUNET_NAMESTORE_lookup_record(namestore_handle, |
100 | &gph->zone, | 96 | &gph->zone, |
@@ -119,8 +115,6 @@ process_pseu_lookup_ns(void* cls, | |||
119 | &new_pkey, | 115 | &new_pkey, |
120 | NULL, //cont | 116 | NULL, //cont |
121 | NULL); //cls | 117 | NULL); //cls |
122 | GNUNET_free(gph->new_name); | ||
123 | GNUNET_free(gph->name); | ||
124 | GNUNET_free(gph); | 118 | GNUNET_free(gph); |
125 | 119 | ||
126 | } | 120 | } |
@@ -136,12 +130,10 @@ process_pseu_result(struct GetPseuAuthorityHandle* gph, char* name) | |||
136 | { | 130 | { |
137 | if (NULL == name) | 131 | if (NULL == name) |
138 | { | 132 | { |
139 | gph->new_name = GNUNET_malloc(strlen(gph->name)+1); | ||
140 | memcpy(gph->new_name, name, strlen(gph->name)+1); | 133 | memcpy(gph->new_name, name, strlen(gph->name)+1); |
141 | } | 134 | } |
142 | else | 135 | else |
143 | { | 136 | { |
144 | gph->new_name = GNUNET_malloc(strlen(name)+1); | ||
145 | memcpy(gph->new_name, name, strlen(name)+1); | 137 | memcpy(gph->new_name, name, strlen(name)+1); |
146 | } | 138 | } |
147 | 139 | ||
@@ -216,8 +208,6 @@ process_auth_discovery_dht_result(void* cls, | |||
216 | { | 208 | { |
217 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "got dht result null!\n", size); | 209 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "got dht result null!\n", size); |
218 | GNUNET_break(0); | 210 | GNUNET_break(0); |
219 | GNUNET_free(gph->new_name); | ||
220 | GNUNET_free(gph->name); | ||
221 | GNUNET_free(gph); | 211 | GNUNET_free(gph); |
222 | return; | 212 | return; |
223 | } | 213 | } |
@@ -247,8 +237,6 @@ process_auth_discovery_dht_result(void* cls, | |||
247 | { | 237 | { |
248 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Error deserializing data!\n"); | 238 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Error deserializing data!\n"); |
249 | GNUNET_break(0); | 239 | GNUNET_break(0); |
250 | GNUNET_free(gph->new_name); | ||
251 | GNUNET_free(gph->name); | ||
252 | GNUNET_free(gph); | 240 | GNUNET_free(gph); |
253 | return; | 241 | return; |
254 | } | 242 | } |
@@ -297,8 +285,6 @@ process_zone_to_name_discover(void *cls, | |||
297 | { | 285 | { |
298 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 286 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
299 | "name for zone in our root %d\n", strlen(name)); | 287 | "name for zone in our root %d\n", strlen(name)); |
300 | GNUNET_free(gph->new_name); | ||
301 | GNUNET_free(gph->name); | ||
302 | GNUNET_free(gph); | 288 | GNUNET_free(gph); |
303 | } | 289 | } |
304 | else | 290 | else |
@@ -359,7 +345,6 @@ static void process_discovered_authority(char* name, GNUNET_HashCode zone, | |||
359 | 345 | ||
360 | gph = GNUNET_malloc(sizeof(struct GetPseuAuthorityHandle)); | 346 | gph = GNUNET_malloc(sizeof(struct GetPseuAuthorityHandle)); |
361 | namelen = strlen(name) + 1; | 347 | namelen = strlen(name) + 1; |
362 | gph->name = GNUNET_malloc(namelen); | ||
363 | memcpy(gph->name, name, namelen); | 348 | memcpy(gph->name, name, namelen); |
364 | 349 | ||
365 | gph->new_zone = zone; | 350 | gph->new_zone = zone; |
@@ -409,15 +394,11 @@ free_resolver_handle(struct ResolverHandle* rh) | |||
409 | if (NULL == rh) | 394 | if (NULL == rh) |
410 | return; | 395 | return; |
411 | 396 | ||
412 | GNUNET_free_non_null (rh->name); | ||
413 | GNUNET_free_non_null (rh->authority_name); | ||
414 | |||
415 | ac = rh->authority_chain_head; | 397 | ac = rh->authority_chain_head; |
416 | 398 | ||
417 | while (NULL != ac) | 399 | while (NULL != ac) |
418 | { | 400 | { |
419 | ac_next = ac->next; | 401 | ac_next = ac->next; |
420 | GNUNET_free_non_null (ac->name); | ||
421 | GNUNET_free(ac); | 402 | GNUNET_free(ac); |
422 | ac = ac_next; | 403 | ac = ac_next; |
423 | } | 404 | } |
@@ -886,7 +867,6 @@ process_delegation_result_dht(void* cls, | |||
886 | struct AuthorityChain *auth = | 867 | struct AuthorityChain *auth = |
887 | GNUNET_malloc(sizeof(struct AuthorityChain)); | 868 | GNUNET_malloc(sizeof(struct AuthorityChain)); |
888 | auth->zone = rh->authority; | 869 | auth->zone = rh->authority; |
889 | auth->name = GNUNET_malloc(strlen(rh->authority_name)+1); | ||
890 | memset(auth->name, 0, strlen(rh->authority_name)+1); | 870 | memset(auth->name, 0, strlen(rh->authority_name)+1); |
891 | strcpy(auth->name, rh->authority_name); | 871 | strcpy(auth->name, rh->authority_name); |
892 | GNUNET_CONTAINER_DLL_insert (rh->authority_chain_head, | 872 | GNUNET_CONTAINER_DLL_insert (rh->authority_chain_head, |
@@ -1043,7 +1023,6 @@ finish_lookup(struct ResolverHandle *rh, | |||
1043 | } | 1023 | } |
1044 | 1024 | ||
1045 | rlh->proc(rlh->proc_cls, rd_count, p_rd); | 1025 | rlh->proc(rlh->proc_cls, rd_count, p_rd); |
1046 | GNUNET_free(rlh->name); | ||
1047 | GNUNET_free(rlh); | 1026 | GNUNET_free(rlh); |
1048 | 1027 | ||
1049 | } | 1028 | } |
@@ -1185,6 +1164,32 @@ pop_tld(char* name, char* dest) | |||
1185 | } | 1164 | } |
1186 | 1165 | ||
1187 | /** | 1166 | /** |
1167 | * Checks if name is in .zkey TLD | ||
1168 | * | ||
1169 | * @param name the name to check | ||
1170 | * @return GNUNET_YES or GNUNET_NO | ||
1171 | */ | ||
1172 | int | ||
1173 | is_zkey_tld(const char* name) | ||
1174 | { | ||
1175 | int offset = 0; | ||
1176 | |||
1177 | if (strlen(name) <= strlen(GNUNET_GNS_TLD_ZKEY)) | ||
1178 | { | ||
1179 | return GNUNET_NO; | ||
1180 | } | ||
1181 | |||
1182 | offset = strlen(name)-strlen(GNUNET_GNS_TLD_ZKEY); | ||
1183 | if (strcmp(name+offset, GNUNET_GNS_TLD_ZKEY) != 0) | ||
1184 | { | ||
1185 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | ||
1186 | "%s is not in zkey TLD\n", name); | ||
1187 | return GNUNET_NO; | ||
1188 | } | ||
1189 | return GNUNET_YES; | ||
1190 | } | ||
1191 | |||
1192 | /** | ||
1188 | * DHT resolution for delegation finished. Processing result. | 1193 | * DHT resolution for delegation finished. Processing result. |
1189 | * | 1194 | * |
1190 | * @param cls the closure | 1195 | * @param cls the closure |
@@ -1213,8 +1218,6 @@ handle_delegation_dht(void* cls, struct ResolverHandle *rh, | |||
1213 | /* We resolved full name for delegation. resolving record */ | 1218 | /* We resolved full name for delegation. resolving record */ |
1214 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1219 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1215 | "Resolved full name for delegation via DHT. resolving record '' in ns\n"); | 1220 | "Resolved full name for delegation via DHT. resolving record '' in ns\n"); |
1216 | GNUNET_free(rh->name); | ||
1217 | rh->name = GNUNET_malloc(strlen("+")+1); | ||
1218 | strcpy(rh->name, "+\0"); | 1221 | strcpy(rh->name, "+\0"); |
1219 | rh->proc = &handle_record_ns; | 1222 | rh->proc = &handle_record_ns; |
1220 | resolve_record_ns(rh); | 1223 | resolve_record_ns(rh); |
@@ -1308,8 +1311,6 @@ handle_delegation_ns(void* cls, struct ResolverHandle *rh, | |||
1308 | /* We resolved full name for delegation. resolving record */ | 1311 | /* We resolved full name for delegation. resolving record */ |
1309 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1312 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1310 | "Resolved full name for delegation. resolving record '+'\n"); | 1313 | "Resolved full name for delegation. resolving record '+'\n"); |
1311 | GNUNET_free(rh->name); | ||
1312 | rh->name = GNUNET_malloc(strlen("+")+1); | ||
1313 | strcpy(rh->name, "+\0"); | 1314 | strcpy(rh->name, "+\0"); |
1314 | rh->proc = &handle_record_ns; | 1315 | rh->proc = &handle_record_ns; |
1315 | resolve_record_ns(rh); | 1316 | resolve_record_ns(rh); |
@@ -1381,7 +1382,7 @@ process_delegation_result_ns(void* cls, | |||
1381 | struct ResolverHandle *rh; | 1382 | struct ResolverHandle *rh; |
1382 | struct GNUNET_TIME_Relative remaining_time; | 1383 | struct GNUNET_TIME_Relative remaining_time; |
1383 | GNUNET_HashCode zone; | 1384 | GNUNET_HashCode zone; |
1384 | char* new_name; | 1385 | char new_name[MAX_DNS_NAME_LENGTH]; |
1385 | 1386 | ||
1386 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Got %d records from authority lookup\n", | 1387 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Got %d records from authority lookup\n", |
1387 | rd_count); | 1388 | rd_count); |
@@ -1431,14 +1432,11 @@ process_delegation_result_ns(void* cls, | |||
1431 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1432 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1432 | "Adding %s back to %s\n", | 1433 | "Adding %s back to %s\n", |
1433 | rh->authority_name, rh->name); | 1434 | rh->authority_name, rh->name); |
1434 | new_name = GNUNET_malloc(strlen(rh->name) | ||
1435 | + strlen(rh->authority_name) + 2); | ||
1436 | memset(new_name, 0, strlen(rh->name) + strlen(rh->authority_name) + 2); | 1435 | memset(new_name, 0, strlen(rh->name) + strlen(rh->authority_name) + 2); |
1437 | strcpy(new_name, rh->name); | 1436 | strcpy(new_name, rh->name); |
1438 | strcpy(new_name+strlen(new_name)+1, "."); | 1437 | strcpy(new_name+strlen(new_name)+1, "."); |
1439 | strcpy(new_name+strlen(new_name)+2, rh->authority_name); | 1438 | strcpy(new_name+strlen(new_name)+2, rh->authority_name); |
1440 | GNUNET_free(rh->name); | 1439 | strcpy(rh->name, new_name); |
1441 | rh->name = new_name; | ||
1442 | } | 1440 | } |
1443 | rh->proc(rh->proc_cls, rh, 0, NULL); | 1441 | rh->proc(rh->proc_cls, rh, 0, NULL); |
1444 | return; | 1442 | return; |
@@ -1479,7 +1477,6 @@ process_delegation_result_ns(void* cls, | |||
1479 | memcpy(&rh->authority, rd[i].data, sizeof(GNUNET_HashCode)); | 1477 | memcpy(&rh->authority, rd[i].data, sizeof(GNUNET_HashCode)); |
1480 | struct AuthorityChain *auth = GNUNET_malloc(sizeof(struct AuthorityChain)); | 1478 | struct AuthorityChain *auth = GNUNET_malloc(sizeof(struct AuthorityChain)); |
1481 | auth->zone = rh->authority; | 1479 | auth->zone = rh->authority; |
1482 | auth->name = GNUNET_malloc(strlen(rh->authority_name)+1); | ||
1483 | memset(auth->name, 0, strlen(rh->authority_name)+1); | 1480 | memset(auth->name, 0, strlen(rh->authority_name)+1); |
1484 | strcpy(auth->name, rh->authority_name); | 1481 | strcpy(auth->name, rh->authority_name); |
1485 | GNUNET_CONTAINER_DLL_insert (rh->authority_chain_head, | 1482 | GNUNET_CONTAINER_DLL_insert (rh->authority_chain_head, |
@@ -1547,6 +1544,7 @@ gns_resolver_lookup_record(GNUNET_HashCode zone, | |||
1547 | { | 1544 | { |
1548 | struct ResolverHandle *rh; | 1545 | struct ResolverHandle *rh; |
1549 | struct RecordLookupHandle* rlh; | 1546 | struct RecordLookupHandle* rlh; |
1547 | char* string_hash = ""; | ||
1550 | 1548 | ||
1551 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1549 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1552 | "Starting resolution for %s (type=%d)!\n", | 1550 | "Starting resolution for %s (type=%d)!\n", |
@@ -1556,7 +1554,7 @@ gns_resolver_lookup_record(GNUNET_HashCode zone, | |||
1556 | if (is_canonical((char*)name) && (strcmp(GNUNET_GNS_TLD, name) != 0)) | 1554 | if (is_canonical((char*)name) && (strcmp(GNUNET_GNS_TLD, name) != 0)) |
1557 | { | 1555 | { |
1558 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1556 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1559 | "%s is canonical and gnunet not our TLD!\n", name); | 1557 | "%s is canonical and not gnunet -> cannot resolve!\n", name); |
1560 | proc(cls, 0, NULL); | 1558 | proc(cls, 0, NULL); |
1561 | return; | 1559 | return; |
1562 | } | 1560 | } |
@@ -1570,30 +1568,64 @@ gns_resolver_lookup_record(GNUNET_HashCode zone, | |||
1570 | 1568 | ||
1571 | if (strcmp(GNUNET_GNS_TLD, name) == 0) | 1569 | if (strcmp(GNUNET_GNS_TLD, name) == 0) |
1572 | { | 1570 | { |
1573 | rh->name = GNUNET_malloc(2); | 1571 | /** |
1574 | strcpy(rh->name, ""); | 1572 | * Only 'gnunet' given |
1573 | */ | ||
1574 | strcpy(rh->name, "\0"); | ||
1575 | } | 1575 | } |
1576 | else | 1576 | else |
1577 | { | 1577 | { |
1578 | rh->name = GNUNET_malloc(strlen(name) | 1578 | if (is_zkey_tld(name) == GNUNET_YES) |
1579 | - strlen(GNUNET_GNS_TLD)); | 1579 | { |
1580 | memset(rh->name, 0, | 1580 | /** |
1581 | strlen(name)-strlen(GNUNET_GNS_TLD)); | 1581 | * This is a zkey tld |
1582 | memcpy(rh->name, name, | 1582 | * build hash and use as initial authority |
1583 | strlen(name)-strlen(GNUNET_GNS_TLD) - 1); | 1583 | */ |
1584 | memset(rh->name, 0, | ||
1585 | strlen(name)-strlen(GNUNET_GNS_TLD_ZKEY)); | ||
1586 | memcpy(rh->name, name, | ||
1587 | strlen(name)-strlen(GNUNET_GNS_TLD_ZKEY) - 1); | ||
1588 | pop_tld(rh->name, string_hash); | ||
1589 | |||
1590 | if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string(string_hash, | ||
1591 | &rh->authority)) | ||
1592 | { | ||
1593 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1594 | "Cannot convert ZKEY %s to hash!\n", string_hash); | ||
1595 | GNUNET_free(rh); | ||
1596 | GNUNET_free(rlh); | ||
1597 | proc(cls, 0, NULL); | ||
1598 | return; | ||
1599 | } | ||
1600 | |||
1601 | } | ||
1602 | else | ||
1603 | { | ||
1604 | /** | ||
1605 | * Presumably GNUNET tld | ||
1606 | */ | ||
1607 | memset(rh->name, 0, | ||
1608 | strlen(name)-strlen(GNUNET_GNS_TLD)); | ||
1609 | memcpy(rh->name, name, | ||
1610 | strlen(name)-strlen(GNUNET_GNS_TLD) - 1); | ||
1611 | } | ||
1584 | } | 1612 | } |
1585 | 1613 | ||
1586 | rh->authority_name = GNUNET_malloc(sizeof(char)*MAX_DNS_LABEL_LENGTH); | 1614 | /** |
1615 | * Initialize authority chain | ||
1616 | */ | ||
1587 | rh->authority_chain_head = GNUNET_malloc(sizeof(struct AuthorityChain)); | 1617 | rh->authority_chain_head = GNUNET_malloc(sizeof(struct AuthorityChain)); |
1588 | rh->authority_chain_head->prev = NULL; | 1618 | rh->authority_chain_head->prev = NULL; |
1589 | rh->authority_chain_head->next = NULL; | 1619 | rh->authority_chain_head->next = NULL; |
1590 | rh->authority_chain_tail = rh->authority_chain_head; | 1620 | rh->authority_chain_tail = rh->authority_chain_head; |
1591 | rh->authority_chain_head->zone = zone; | 1621 | rh->authority_chain_head->zone = rh->authority; |
1592 | 1622 | ||
1623 | /** | ||
1624 | * Copy original query into lookup handle | ||
1625 | */ | ||
1593 | rlh->record_type = record_type; | 1626 | rlh->record_type = record_type; |
1594 | rlh->name = GNUNET_malloc(strlen(name) + 1); | ||
1595 | memset(rlh->name, 0, strlen(name) + 1); | 1627 | memset(rlh->name, 0, strlen(name) + 1); |
1596 | strcpy(rlh->name, name); //FIXME | 1628 | strcpy(rlh->name, name); |
1597 | rlh->proc = proc; | 1629 | rlh->proc = proc; |
1598 | rlh->proc_cls = cls; | 1630 | rlh->proc_cls = cls; |
1599 | 1631 | ||
@@ -1629,8 +1661,8 @@ process_zone_to_name_shorten(void *cls, | |||
1629 | struct NameShortenHandle* nsh = (struct NameShortenHandle*)rh->proc_cls; | 1661 | struct NameShortenHandle* nsh = (struct NameShortenHandle*)rh->proc_cls; |
1630 | struct AuthorityChain *next_authority; | 1662 | struct AuthorityChain *next_authority; |
1631 | 1663 | ||
1632 | char* result; | 1664 | char result[MAX_DNS_NAME_LENGTH]; |
1633 | char* next_authority_name; | 1665 | char next_authority_name[MAX_DNS_LABEL_LENGTH]; |
1634 | size_t answer_len; | 1666 | size_t answer_len; |
1635 | 1667 | ||
1636 | /* we found a match in our own zone */ | 1668 | /* we found a match in our own zone */ |
@@ -1639,7 +1671,6 @@ process_zone_to_name_shorten(void *cls, | |||
1639 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1671 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1640 | "result strlen %d\n", strlen(name)); | 1672 | "result strlen %d\n", strlen(name)); |
1641 | answer_len = strlen(rh->name) + strlen(name) + strlen(GNUNET_GNS_TLD) + 3; | 1673 | answer_len = strlen(rh->name) + strlen(name) + strlen(GNUNET_GNS_TLD) + 3; |
1642 | result = GNUNET_malloc(answer_len); | ||
1643 | memset(result, 0, answer_len); | 1674 | memset(result, 0, answer_len); |
1644 | if (strlen(rh->name) > 0) | 1675 | if (strlen(rh->name) > 0) |
1645 | { | 1676 | { |
@@ -1657,14 +1688,12 @@ process_zone_to_name_shorten(void *cls, | |||
1657 | nsh->proc(nsh->proc_cls, result); | 1688 | nsh->proc(nsh->proc_cls, result); |
1658 | GNUNET_free(nsh); | 1689 | GNUNET_free(nsh); |
1659 | free_resolver_handle(rh); | 1690 | free_resolver_handle(rh); |
1660 | GNUNET_free(result); | ||
1661 | } | 1691 | } |
1662 | else if (GNUNET_CRYPTO_hash_cmp(&rh->authority_chain_head->zone, | 1692 | else if (GNUNET_CRYPTO_hash_cmp(&rh->authority_chain_head->zone, |
1663 | &rh->authority_chain_tail->zone)) | 1693 | &rh->authority_chain_tail->zone)) |
1664 | { | 1694 | { |
1665 | /* our zone, just append .gnunet */ | 1695 | /* our zone, just append .gnunet */ |
1666 | answer_len = strlen(rh->name) + strlen(GNUNET_GNS_TLD) + 2; | 1696 | answer_len = strlen(rh->name) + strlen(GNUNET_GNS_TLD) + 2; |
1667 | result = GNUNET_malloc(answer_len); | ||
1668 | memset(result, 0, answer_len); | 1697 | memset(result, 0, answer_len); |
1669 | strcpy(result, rh->name); | 1698 | strcpy(result, rh->name); |
1670 | strcpy(result+strlen(rh->name), "."); | 1699 | strcpy(result+strlen(rh->name), "."); |
@@ -1676,7 +1705,6 @@ process_zone_to_name_shorten(void *cls, | |||
1676 | nsh->proc(nsh->proc_cls, result); | 1705 | nsh->proc(nsh->proc_cls, result); |
1677 | GNUNET_free(nsh); | 1706 | GNUNET_free(nsh); |
1678 | free_resolver_handle(rh); | 1707 | free_resolver_handle(rh); |
1679 | GNUNET_free(result); | ||
1680 | } | 1708 | } |
1681 | else | 1709 | else |
1682 | { | 1710 | { |
@@ -1685,16 +1713,14 @@ process_zone_to_name_shorten(void *cls, | |||
1685 | * continue with next authority | 1713 | * continue with next authority |
1686 | */ | 1714 | */ |
1687 | next_authority = rh->authority_chain_head; | 1715 | next_authority = rh->authority_chain_head; |
1688 | next_authority_name = GNUNET_malloc(strlen(rh->name)+ | 1716 | // strlen(next_authority->name) + 2); |
1689 | strlen(next_authority->name) + 2); | ||
1690 | memset(next_authority_name, 0, strlen(rh->name)+ | 1717 | memset(next_authority_name, 0, strlen(rh->name)+ |
1691 | strlen(next_authority->name) + 2); | 1718 | strlen(next_authority->name) + 2); |
1692 | strcpy(next_authority_name, rh->name); | 1719 | strcpy(next_authority_name, rh->name); |
1693 | strcpy(next_authority_name+strlen(rh->name)+1, "."); | 1720 | strcpy(next_authority_name+strlen(rh->name)+1, "."); |
1694 | strcpy(next_authority_name+strlen(rh->name)+2, next_authority->name); | 1721 | strcpy(next_authority_name+strlen(rh->name)+2, next_authority->name); |
1695 | 1722 | ||
1696 | GNUNET_free(rh->name); | 1723 | strcpy(rh->name, next_authority_name); |
1697 | rh->name = next_authority_name; | ||
1698 | GNUNET_CONTAINER_DLL_remove(rh->authority_chain_head, | 1724 | GNUNET_CONTAINER_DLL_remove(rh->authority_chain_head, |
1699 | rh->authority_chain_tail, | 1725 | rh->authority_chain_tail, |
1700 | next_authority); | 1726 | next_authority); |
@@ -1724,7 +1750,7 @@ handle_delegation_ns_shorten(void* cls, | |||
1724 | const struct GNUNET_NAMESTORE_RecordData *rd) | 1750 | const struct GNUNET_NAMESTORE_RecordData *rd) |
1725 | { | 1751 | { |
1726 | struct NameShortenHandle *nsh; | 1752 | struct NameShortenHandle *nsh; |
1727 | char* result; | 1753 | char result[MAX_DNS_NAME_LENGTH]; |
1728 | size_t answer_len; | 1754 | size_t answer_len; |
1729 | 1755 | ||
1730 | nsh = (struct NameShortenHandle *)cls; | 1756 | nsh = (struct NameShortenHandle *)cls; |
@@ -1749,7 +1775,6 @@ handle_delegation_ns_shorten(void* cls, | |||
1749 | **/ | 1775 | **/ |
1750 | 1776 | ||
1751 | answer_len = strlen(rh->name) + strlen(GNUNET_GNS_TLD) + 2; | 1777 | answer_len = strlen(rh->name) + strlen(GNUNET_GNS_TLD) + 2; |
1752 | result = GNUNET_malloc(answer_len); | ||
1753 | memset(result, 0, answer_len); | 1778 | memset(result, 0, answer_len); |
1754 | strcpy(result, rh->name); | 1779 | strcpy(result, rh->name); |
1755 | strcpy(result+strlen(rh->name), "."); | 1780 | strcpy(result+strlen(rh->name), "."); |
@@ -1761,7 +1786,6 @@ handle_delegation_ns_shorten(void* cls, | |||
1761 | nsh->proc(nsh->proc_cls, result); | 1786 | nsh->proc(nsh->proc_cls, result); |
1762 | GNUNET_free(nsh); | 1787 | GNUNET_free(nsh); |
1763 | free_resolver_handle(rh); | 1788 | free_resolver_handle(rh); |
1764 | GNUNET_free(result); | ||
1765 | return; | 1789 | return; |
1766 | } | 1790 | } |
1767 | 1791 | ||
@@ -1810,14 +1834,11 @@ gns_resolver_shorten_name(GNUNET_HashCode zone, | |||
1810 | 1834 | ||
1811 | rh = GNUNET_malloc(sizeof (struct ResolverHandle)); | 1835 | rh = GNUNET_malloc(sizeof (struct ResolverHandle)); |
1812 | rh->authority = zone; | 1836 | rh->authority = zone; |
1813 | rh->name = GNUNET_malloc(strlen(name) | ||
1814 | - strlen(GNUNET_GNS_TLD)); | ||
1815 | memset(rh->name, 0, | 1837 | memset(rh->name, 0, |
1816 | strlen(name)-strlen(GNUNET_GNS_TLD)); | 1838 | strlen(name)-strlen(GNUNET_GNS_TLD)); |
1817 | memcpy(rh->name, name, | 1839 | memcpy(rh->name, name, |
1818 | strlen(name)-strlen(GNUNET_GNS_TLD)-1); | 1840 | strlen(name)-strlen(GNUNET_GNS_TLD)-1); |
1819 | 1841 | ||
1820 | rh->authority_name = GNUNET_malloc(sizeof(char)*MAX_DNS_LABEL_LENGTH); | ||
1821 | rh->authority_chain_head = GNUNET_malloc(sizeof(struct AuthorityChain)); | 1842 | rh->authority_chain_head = GNUNET_malloc(sizeof(struct AuthorityChain)); |
1822 | rh->authority_chain_tail = rh->authority_chain_head; | 1843 | rh->authority_chain_tail = rh->authority_chain_head; |
1823 | rh->authority_chain_head->zone = zone; | 1844 | rh->authority_chain_head->zone = zone; |
@@ -1847,7 +1868,7 @@ handle_delegation_result_ns_get_auth(void* cls, | |||
1847 | const struct GNUNET_NAMESTORE_RecordData *rd) | 1868 | const struct GNUNET_NAMESTORE_RecordData *rd) |
1848 | { | 1869 | { |
1849 | struct GetNameAuthorityHandle* nah; | 1870 | struct GetNameAuthorityHandle* nah; |
1850 | char* result; | 1871 | char result[MAX_DNS_NAME_LENGTH]; |
1851 | size_t answer_len; | 1872 | size_t answer_len; |
1852 | 1873 | ||
1853 | nah = (struct GetNameAuthorityHandle*) rh->proc_cls; | 1874 | nah = (struct GetNameAuthorityHandle*) rh->proc_cls; |
@@ -1881,7 +1902,6 @@ handle_delegation_result_ns_get_auth(void* cls, | |||
1881 | 1902 | ||
1882 | answer_len = strlen(nah->name) - strlen(rh->name) | 1903 | answer_len = strlen(nah->name) - strlen(rh->name) |
1883 | + strlen(GNUNET_GNS_TLD) + 1; | 1904 | + strlen(GNUNET_GNS_TLD) + 1; |
1884 | result = GNUNET_malloc(answer_len); | ||
1885 | memset(result, 0, answer_len); | 1905 | memset(result, 0, answer_len); |
1886 | strcpy(result, nah->name + strlen(rh->name) + 1); | 1906 | strcpy(result, nah->name + strlen(rh->name) + 1); |
1887 | 1907 | ||
@@ -1889,17 +1909,14 @@ handle_delegation_result_ns_get_auth(void* cls, | |||
1889 | "Got authority result %s\n", result); | 1909 | "Got authority result %s\n", result); |
1890 | 1910 | ||
1891 | nah->proc(nah->proc_cls, result); | 1911 | nah->proc(nah->proc_cls, result); |
1892 | GNUNET_free(nah->name); | ||
1893 | GNUNET_free(nah); | 1912 | GNUNET_free(nah); |
1894 | free_resolver_handle(rh); | 1913 | free_resolver_handle(rh); |
1895 | GNUNET_free(result); | ||
1896 | } | 1914 | } |
1897 | else | 1915 | else |
1898 | { | 1916 | { |
1899 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1917 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1900 | "Unable to resolve authority for remaining %s!\n", rh->name); | 1918 | "Unable to resolve authority for remaining %s!\n", rh->name); |
1901 | nah->proc(nah->proc_cls, ""); | 1919 | nah->proc(nah->proc_cls, ""); |
1902 | GNUNET_free(nah->name); | ||
1903 | GNUNET_free(nah); | 1920 | GNUNET_free(nah); |
1904 | free_resolver_handle(rh); | 1921 | free_resolver_handle(rh); |
1905 | } | 1922 | } |
@@ -1935,26 +1952,20 @@ gns_resolver_get_authority(GNUNET_HashCode zone, | |||
1935 | 1952 | ||
1936 | if (strcmp(GNUNET_GNS_TLD, name) == 0) | 1953 | if (strcmp(GNUNET_GNS_TLD, name) == 0) |
1937 | { | 1954 | { |
1938 | rh->name = GNUNET_malloc(2); | 1955 | strcpy(rh->name, "\0"); |
1939 | strcpy(rh->name, ""); | ||
1940 | } | 1956 | } |
1941 | else | 1957 | else |
1942 | { | 1958 | { |
1943 | rh->name = GNUNET_malloc(strlen(name) | ||
1944 | - strlen(GNUNET_GNS_TLD)); | ||
1945 | memset(rh->name, 0, | 1959 | memset(rh->name, 0, |
1946 | strlen(name)-strlen(GNUNET_GNS_TLD)); | 1960 | strlen(name)-strlen(GNUNET_GNS_TLD)); |
1947 | memcpy(rh->name, name, | 1961 | memcpy(rh->name, name, |
1948 | strlen(name)-strlen(GNUNET_GNS_TLD) - 1); | 1962 | strlen(name)-strlen(GNUNET_GNS_TLD) - 1); |
1949 | } | 1963 | } |
1950 | 1964 | ||
1951 | nah->name = GNUNET_malloc(strlen(name)+1); | ||
1952 | memset(nah->name, 0, | 1965 | memset(nah->name, 0, |
1953 | strlen(name)+1); | 1966 | strlen(name)+1); |
1954 | strcpy(nah->name, name); | 1967 | strcpy(nah->name, name); |
1955 | 1968 | ||
1956 | rh->authority_name = GNUNET_malloc(MAX_DNS_LABEL_LENGTH); | ||
1957 | |||
1958 | rh->authority_chain_head = GNUNET_malloc(sizeof(struct AuthorityChain)); | 1969 | rh->authority_chain_head = GNUNET_malloc(sizeof(struct AuthorityChain)); |
1959 | rh->authority_chain_tail = rh->authority_chain_head; | 1970 | rh->authority_chain_tail = rh->authority_chain_head; |
1960 | rh->authority_chain_head->zone = zone; | 1971 | rh->authority_chain_head->zone = zone; |
diff --git a/src/gns/gnunet-service-gns_resolver.h b/src/gns/gnunet-service-gns_resolver.h index a7f86a2d7..ecd059765 100644 --- a/src/gns/gnunet-service-gns_resolver.h +++ b/src/gns/gnunet-service-gns_resolver.h | |||
@@ -8,6 +8,7 @@ | |||
8 | #define DHT_LOOKUP_TIMEOUT DHT_OPERATION_TIMEOUT | 8 | #define DHT_LOOKUP_TIMEOUT DHT_OPERATION_TIMEOUT |
9 | #define DHT_GNS_REPLICATION_LEVEL 5 | 9 | #define DHT_GNS_REPLICATION_LEVEL 5 |
10 | #define MAX_DNS_LABEL_LENGTH 63 | 10 | #define MAX_DNS_LABEL_LENGTH 63 |
11 | #define MAX_DNS_NAME_LENGTH 253 | ||
11 | 12 | ||
12 | /* | 13 | /* |
13 | * DLL to hold the authority chain | 14 | * DLL to hold the authority chain |
@@ -23,7 +24,7 @@ struct AuthorityChain | |||
23 | GNUNET_HashCode zone; | 24 | GNUNET_HashCode zone; |
24 | 25 | ||
25 | /* (local) name of the authority */ | 26 | /* (local) name of the authority */ |
26 | char* name; | 27 | char name[MAX_DNS_LABEL_LENGTH]; |
27 | 28 | ||
28 | /* was the ns entry fresh */ | 29 | /* was the ns entry fresh */ |
29 | int fresh; | 30 | int fresh; |
@@ -94,7 +95,7 @@ enum ResolutionStatus | |||
94 | struct ResolverHandle | 95 | struct ResolverHandle |
95 | { | 96 | { |
96 | /* The name to resolve */ | 97 | /* The name to resolve */ |
97 | char *name; | 98 | char name[MAX_DNS_NAME_LENGTH]; |
98 | 99 | ||
99 | /* has this query been answered? how many matches */ | 100 | /* has this query been answered? how many matches */ |
100 | int answered; | 101 | int answered; |
@@ -103,7 +104,7 @@ struct ResolverHandle | |||
103 | GNUNET_HashCode authority; | 104 | GNUNET_HashCode authority; |
104 | 105 | ||
105 | /* the name of the authoritative zone to query */ | 106 | /* the name of the authoritative zone to query */ |
106 | char *authority_name; | 107 | char authority_name[MAX_DNS_LABEL_LENGTH]; |
107 | 108 | ||
108 | /** | 109 | /** |
109 | * we have an authority in namestore that | 110 | * we have an authority in namestore that |
@@ -146,7 +147,7 @@ struct RecordLookupHandle | |||
146 | enum GNUNET_GNS_RecordType record_type; | 147 | enum GNUNET_GNS_RecordType record_type; |
147 | 148 | ||
148 | /* the name to look up */ | 149 | /* the name to look up */ |
149 | char *name; | 150 | char name[MAX_DNS_NAME_LENGTH]; |
150 | 151 | ||
151 | /* Method to call on record resolution result */ | 152 | /* Method to call on record resolution result */ |
152 | RecordLookupProcessor proc; | 153 | RecordLookupProcessor proc; |
@@ -179,7 +180,7 @@ struct GetNameAuthorityHandle | |||
179 | { | 180 | { |
180 | 181 | ||
181 | /* the name to look up authority for */ | 182 | /* the name to look up authority for */ |
182 | char* name; | 183 | char name[MAX_DNS_NAME_LENGTH]; |
183 | 184 | ||
184 | /* Method to call on result */ | 185 | /* Method to call on result */ |
185 | GetAuthorityResultProcessor proc; | 186 | GetAuthorityResultProcessor proc; |
@@ -195,10 +196,10 @@ struct GetNameAuthorityHandle | |||
195 | struct GetPseuAuthorityHandle | 196 | struct GetPseuAuthorityHandle |
196 | { | 197 | { |
197 | /* the name given from delegation */ | 198 | /* the name given from delegation */ |
198 | char* name; | 199 | char name[MAX_DNS_LABEL_LENGTH]; |
199 | 200 | ||
200 | /* name to store the pseu under */ | 201 | /* name to store the pseu under */ |
201 | char* new_name; | 202 | char new_name[MAX_DNS_LABEL_LENGTH]; |
202 | 203 | ||
203 | /* the zone of discovered authority */ | 204 | /* the zone of discovered authority */ |
204 | GNUNET_HashCode new_zone; | 205 | GNUNET_HashCode new_zone; |