aboutsummaryrefslogtreecommitdiff
path: root/src/gns/gnunet-service-gns_resolver.c
diff options
context:
space:
mode:
authorMartin Schanzenbach <mschanzenbach@posteo.de>2012-06-22 12:54:34 +0000
committerMartin Schanzenbach <mschanzenbach@posteo.de>2012-06-22 12:54:34 +0000
commit66d90f54243ad0ca5953a3aba9ab8aaca159d704 (patch)
treebba06a417916ae611626d21a0e84d5c60e42dea8 /src/gns/gnunet-service-gns_resolver.c
parent1acf88bc634b8317d53c8675702e586c7d80724b (diff)
downloadgnunet-66d90f54243ad0ca5953a3aba9ab8aaca159d704.tar.gz
gnunet-66d90f54243ad0ca5953a3aba9ab8aaca159d704.zip
-make record data parsing easier for namestore,gns with dnsparser structs
Diffstat (limited to 'src/gns/gnunet-service-gns_resolver.c')
-rw-r--r--src/gns/gnunet-service-gns_resolver.c109
1 files changed, 46 insertions, 63 deletions
diff --git a/src/gns/gnunet-service-gns_resolver.c b/src/gns/gnunet-service-gns_resolver.c
index bbeea86f4..eac0a139f 100644
--- a/src/gns/gnunet-service-gns_resolver.c
+++ b/src/gns/gnunet-service-gns_resolver.c
@@ -35,6 +35,7 @@
35#include "gnunet_dns_service.h" 35#include "gnunet_dns_service.h"
36#include "gnunet_resolver_service.h" 36#include "gnunet_resolver_service.h"
37#include "gnunet_dnsparser_lib.h" 37#include "gnunet_dnsparser_lib.h"
38#include "../dns/dnsparser.h"
38#include "gnunet_gns_service.h" 39#include "gnunet_gns_service.h"
39#include "block_gns.h" 40#include "block_gns.h"
40#include "gns.h" 41#include "gns.h"
@@ -1811,14 +1812,10 @@ resolve_record_vpn (struct ResolverHandle *rh,
1811 int rd_count, 1812 int rd_count,
1812 const struct GNUNET_NAMESTORE_RecordData *rd) 1813 const struct GNUNET_NAMESTORE_RecordData *rd)
1813{ 1814{
1814 int af; 1815 struct RecordLookupHandle *rlh = rh->proc_cls;
1815 int proto;
1816 struct GNUNET_HashCode peer_id;
1817 struct GNUNET_CRYPTO_HashAsciiEncoded s_pid;
1818 struct GNUNET_HashCode serv_desc; 1816 struct GNUNET_HashCode serv_desc;
1819 struct GNUNET_CRYPTO_HashAsciiEncoded s_sd; 1817 struct vpn_data* vpn;
1820 char* pos; 1818 int af;
1821 size_t len = (sizeof (uint32_t) * 2) + (sizeof (struct GNUNET_HashCode) * 2);
1822 1819
1823 /* We cancel here as to not include the ns lookup in the timeout */ 1820 /* We cancel here as to not include the ns lookup in the timeout */
1824 if (rh->timeout_task != GNUNET_SCHEDULER_NO_TASK) 1821 if (rh->timeout_task != GNUNET_SCHEDULER_NO_TASK)
@@ -1836,37 +1833,12 @@ resolve_record_vpn (struct ResolverHandle *rh,
1836 rh->priv_key); 1833 rh->priv_key);
1837 } 1834 }
1838 1835
1839 /* Extracting VPN information FIXME rd parsing with NS API?*/ 1836 vpn = (struct vpn_data*)rd;
1840 if (len != rd->data_size)
1841 {
1842 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1843 "GNS_PHASE_REC_VPN-%llu: Error parsing VPN RR!\n",
1844 rh->id);
1845 finish_lookup (rh, rh->proc_cls, 0, NULL);
1846 free_resolver_handle (rh);
1847 return;
1848 }
1849 1837
1850 pos = (char*)rd;
1851 memcpy (&af, pos, sizeof (uint32_t));
1852 pos += sizeof (uint32_t);
1853 memcpy (&proto, pos, sizeof (uint32_t));
1854 pos += sizeof (uint32_t);
1855 memcpy (&s_pid, pos, sizeof (struct GNUNET_HashCode));
1856 pos += sizeof (struct GNUNET_HashCode);
1857 memcpy (&s_sd, pos, sizeof (struct GNUNET_HashCode));
1858 1838
1859 1839 GNUNET_CRYPTO_hash ((char*)&vpn[1],
1860 if ((GNUNET_OK != GNUNET_CRYPTO_hash_from_string ((char*)&s_pid, &peer_id)) || 1840 strlen ((char*)&vpn[1]),
1861 (GNUNET_OK != GNUNET_CRYPTO_hash_from_string ((char*)&s_sd, &serv_desc))) 1841 &serv_desc);
1862 {
1863 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1864 "GNS_PHASE_REC_VPN-%llu: Error parsing VPN RR hashes!\n",
1865 rh->id);
1866 finish_lookup (rh, rh->proc_cls, 0, NULL);
1867 free_resolver_handle (rh);
1868 return;
1869 }
1870 1842
1871 rh->proc = &handle_record_vpn; 1843 rh->proc = &handle_record_vpn;
1872 1844
@@ -1879,11 +1851,16 @@ resolve_record_vpn (struct ResolverHandle *rh,
1879 free_resolver_handle (rh); 1851 free_resolver_handle (rh);
1880 return; 1852 return;
1881 } 1853 }
1854
1855 if (rlh->record_type == GNUNET_GNS_RECORD_TYPE_A)
1856 af = AF_INET;
1857 else
1858 af = AF_INET6;
1882 1859
1883 //FIXME timeout?? 1860 //FIXME timeout??
1884 rh->vpn_handle = GNUNET_VPN_redirect_to_peer (vpn_handle, 1861 rh->vpn_handle = GNUNET_VPN_redirect_to_peer (vpn_handle,
1885 af, proto, 1862 af, ntohs (vpn->proto),
1886 (struct GNUNET_PeerIdentity*)&peer_id, 1863 (struct GNUNET_PeerIdentity *)&vpn->peer,
1887 &serv_desc, 1864 &serv_desc,
1888 GNUNET_NO, //nac 1865 GNUNET_NO, //nac
1889 GNUNET_TIME_UNIT_FOREVER_ABS, //FIXME 1866 GNUNET_TIME_UNIT_FOREVER_ABS, //FIXME
@@ -2351,7 +2328,7 @@ process_delegation_result_dht(void* cls,
2351 2328
2352 2329
2353static void 2330static void
2354expand_plus(char** dest, char* src, char* repl) 2331expand_plus(char* dest, char* src, char* repl)
2355{ 2332{
2356 char* pos; 2333 char* pos;
2357 unsigned int s_len = strlen(src)+1; 2334 unsigned int s_len = strlen(src)+1;
@@ -2365,7 +2342,7 @@ expand_plus(char** dest, char* src, char* repl)
2365 "GNS_POSTPROCESS: %s to short\n", src); 2342 "GNS_POSTPROCESS: %s to short\n", src);
2366 2343
2367 /* no postprocessing */ 2344 /* no postprocessing */
2368 memcpy(*dest, src, s_len+1); 2345 memcpy(dest, src, s_len+1);
2369 return; 2346 return;
2370 } 2347 }
2371 2348
@@ -2373,17 +2350,17 @@ expand_plus(char** dest, char* src, char* repl)
2373 { 2350 {
2374 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2351 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2375 "GNS_POSTPROCESS: Expanding .+ in %s\n", src); 2352 "GNS_POSTPROCESS: Expanding .+ in %s\n", src);
2376 memset(*dest, 0, s_len+strlen(repl)+strlen(GNUNET_GNS_TLD)); 2353 memset(dest, 0, s_len+strlen(repl)+strlen(GNUNET_GNS_TLD));
2377 strcpy(*dest, src); 2354 strcpy(dest, src);
2378 pos = *dest+s_len-2; 2355 pos = dest+s_len-2;
2379 strcpy(pos, repl); 2356 strcpy(pos, repl);
2380 pos += strlen(repl); 2357 pos += strlen(repl);
2381 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2358 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2382 "GNS_POSTPROCESS: Expanded to %s\n", *dest); 2359 "GNS_POSTPROCESS: Expanded to %s\n", dest);
2383 } 2360 }
2384 else 2361 else
2385 { 2362 {
2386 memcpy(*dest, src, s_len+1); 2363 memcpy(dest, src, s_len+1);
2387 } 2364 }
2388} 2365}
2389 2366
@@ -2401,6 +2378,10 @@ finish_lookup(struct ResolverHandle *rh,
2401 char new_mx_data[MAX_MX_LENGTH]; 2378 char new_mx_data[MAX_MX_LENGTH];
2402 char new_soa_data[MAX_SOA_LENGTH]; 2379 char new_soa_data[MAX_SOA_LENGTH];
2403 char new_srv_data[MAX_SRV_LENGTH]; 2380 char new_srv_data[MAX_SRV_LENGTH];
2381 struct srv_data *old_srv;
2382 struct srv_data *new_srv;
2383 struct soa_data *old_soa;
2384 struct soa_data *new_soa;
2404 struct GNUNET_NAMESTORE_RecordData p_rd[rd_count]; 2385 struct GNUNET_NAMESTORE_RecordData p_rd[rd_count];
2405 char* repl_string; 2386 char* repl_string;
2406 char* pos; 2387 char* pos;
@@ -2448,7 +2429,7 @@ finish_lookup(struct ResolverHandle *rh,
2448 memcpy (new_mx_data, (char*)rd[i].data, sizeof(uint16_t)); 2429 memcpy (new_mx_data, (char*)rd[i].data, sizeof(uint16_t));
2449 offset = sizeof(uint16_t); 2430 offset = sizeof(uint16_t);
2450 pos = new_mx_data+offset; 2431 pos = new_mx_data+offset;
2451 expand_plus(&pos, (char*)rd[i].data+sizeof(uint16_t), 2432 expand_plus(pos, (char*)rd[i].data+sizeof(uint16_t),
2452 repl_string); 2433 repl_string);
2453 offset += strlen(new_mx_data+sizeof(uint16_t))+1; 2434 offset += strlen(new_mx_data+sizeof(uint16_t))+1;
2454 p_rd[i].data = new_mx_data; 2435 p_rd[i].data = new_mx_data;
@@ -2459,34 +2440,36 @@ finish_lookup(struct ResolverHandle *rh,
2459 /* 2440 /*
2460 * Prio, weight and port 2441 * Prio, weight and port
2461 */ 2442 */
2462 memcpy (new_srv_data, (char*)rd[i].data, sizeof (uint16_t) * 3); 2443 new_srv = (struct srv_data*)new_srv_data;
2463 offset = sizeof (uint16_t) * 3; 2444 old_srv = (struct srv_data*)rd[i].data;
2464 pos = new_srv_data+offset; 2445 new_srv->prio = old_srv->prio;
2465 expand_plus(&pos, (char*)rd[i].data+(sizeof(uint16_t)*3), 2446 new_srv->weight = old_srv->weight;
2447 new_srv->port = old_srv->port;
2448 expand_plus((char*)&new_srv[1], (char*)&old_srv[1],
2466 repl_string); 2449 repl_string);
2467 offset += strlen(new_srv_data+(sizeof(uint16_t)*3))+1;
2468 p_rd[i].data = new_srv_data; 2450 p_rd[i].data = new_srv_data;
2469 p_rd[i].data_size = offset; 2451 p_rd[i].data_size = sizeof (struct srv_data) + strlen ((char*)&new_srv[1]) + 1;
2470 } 2452 }
2471 else if (rd[i].record_type == GNUNET_GNS_RECORD_TYPE_SOA) 2453 else if (rd[i].record_type == GNUNET_GNS_RECORD_TYPE_SOA)
2472 { 2454 {
2473 /* expand mname and rname */ 2455 /* expand mname and rname */
2474 pos = new_soa_data; 2456 old_soa = (struct soa_data*)rd[i].data;
2475 expand_plus(&pos, (char*)rd[i].data, repl_string); 2457 new_soa = (struct soa_data*)new_soa_data;
2476 offset = strlen(new_soa_data)+1; 2458 memcpy (new_soa, old_soa, sizeof (struct soa_data));
2477 pos = new_soa_data+offset; 2459 expand_plus((char*)&new_soa[1], (char*)&old_soa[1], repl_string);
2478 expand_plus(&pos, (char*)rd[i].data+offset, repl_string); 2460 offset = strlen ((char*)&new_soa[1]) + 1;
2479 offset += strlen(new_soa_data+offset)+1; 2461 expand_plus((char*)&new_soa[1] + offset,
2480 /* cpy the 4 numbers serial refresh retry and expire */ 2462 (char*)&old_soa[1] + strlen ((char*)&old_soa[1]) + 1,
2481 memcpy(new_soa_data+offset, (char*)rd[i].data+offset, sizeof(uint32_t)*5); 2463 repl_string);
2482 offset += sizeof(uint32_t)*5; 2464 p_rd[i].data_size = sizeof (struct soa_data)
2483 p_rd[i].data_size = offset; 2465 + offset
2466 + strlen ((char*)&new_soa[1] + offset);
2484 p_rd[i].data = new_soa_data; 2467 p_rd[i].data = new_soa_data;
2485 } 2468 }
2486 else 2469 else
2487 { 2470 {
2488 pos = new_rr_data; 2471 pos = new_rr_data;
2489 expand_plus(&pos, (char*)rd[i].data, repl_string); 2472 expand_plus(pos, (char*)rd[i].data, repl_string);
2490 p_rd[i].data_size = strlen(new_rr_data)+1; 2473 p_rd[i].data_size = strlen(new_rr_data)+1;
2491 p_rd[i].data = new_rr_data; 2474 p_rd[i].data = new_rr_data;
2492 } 2475 }