aboutsummaryrefslogtreecommitdiff
path: root/src/namestore
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/namestore
parent1acf88bc634b8317d53c8675702e586c7d80724b (diff)
downloadgnunet-66d90f54243ad0ca5953a3aba9ab8aaca159d704.tar.gz
gnunet-66d90f54243ad0ca5953a3aba9ab8aaca159d704.zip
-make record data parsing easier for namestore,gns with dnsparser structs
Diffstat (limited to 'src/namestore')
-rw-r--r--src/namestore/namestore_common.c108
1 files changed, 53 insertions, 55 deletions
diff --git a/src/namestore/namestore_common.c b/src/namestore/namestore_common.c
index 996259b51..af7eee04c 100644
--- a/src/namestore/namestore_common.c
+++ b/src/namestore/namestore_common.c
@@ -32,6 +32,7 @@
32#include "gnunet_arm_service.h" 32#include "gnunet_arm_service.h"
33#include "gnunet_namestore_service.h" 33#include "gnunet_namestore_service.h"
34#include "gnunet_dnsparser_lib.h" 34#include "gnunet_dnsparser_lib.h"
35#include "../dns/dnsparser.h"
35#include "namestore.h" 36#include "namestore.h"
36 37
37 38
@@ -322,19 +323,13 @@ GNUNET_NAMESTORE_value_to_string (uint32_t type,
322 char* result; 323 char* result;
323 char* soa_rname; 324 char* soa_rname;
324 char* soa_mname; 325 char* soa_mname;
325 uint32_t* soa_data; 326 struct soa_data *soa;
326 uint32_t soa_serial; 327
327 uint32_t soa_refresh; 328 struct vpn_data *vpn;
328 uint32_t soa_retry;
329 uint32_t soa_expire;
330 uint32_t soa_min;
331 uint32_t *af;
332 uint32_t *proto;
333 char* vpn_str; 329 char* vpn_str;
334 struct GNUNET_HashCode *h_peer; 330 char* srv_str;
335 struct GNUNET_HashCode *h_serv;
336 struct GNUNET_CRYPTO_HashAsciiEncoded s_peer; 331 struct GNUNET_CRYPTO_HashAsciiEncoded s_peer;
337 struct GNUNET_CRYPTO_HashAsciiEncoded s_serv; 332 struct srv_data *srv;
338 333
339 switch (type) 334 switch (type)
340 { 335 {
@@ -351,17 +346,13 @@ GNUNET_NAMESTORE_value_to_string (uint32_t type,
351 case GNUNET_DNSPARSER_TYPE_CNAME: 346 case GNUNET_DNSPARSER_TYPE_CNAME:
352 return GNUNET_strndup (data, data_size); 347 return GNUNET_strndup (data, data_size);
353 case GNUNET_DNSPARSER_TYPE_SOA: 348 case GNUNET_DNSPARSER_TYPE_SOA:
354 soa_rname = (char*)data; 349 soa = (struct soa_data*)data;
355 soa_mname = (char*)data+strlen(soa_rname)+1; 350 soa_rname = (char*)&soa[1];
356 soa_data = (uint32_t*)(soa_mname+strlen(soa_mname)+1); 351 soa_mname = (char*)&soa[1]+strlen(soa_rname)+1;
357 soa_serial = ntohl(soa_data[0]);
358 soa_refresh = ntohl(soa_data[1]);
359 soa_retry = ntohl(soa_data[2]);
360 soa_expire = ntohl(soa_data[3]);
361 soa_min = ntohl(soa_data[4]);
362 if (GNUNET_asprintf(&result, "rname=%s mname=%s %lu,%lu,%lu,%lu,%lu", 352 if (GNUNET_asprintf(&result, "rname=%s mname=%s %lu,%lu,%lu,%lu,%lu",
363 soa_rname, soa_mname, 353 soa_rname, soa_mname,
364 soa_serial, soa_refresh, soa_retry, soa_expire, soa_min)) 354 ntohl (soa->serial), ntohl (soa->refresh),
355 ntohl (soa->retry), ntohl (soa->expire), ntohl (soa->minimum)))
365 return result; 356 return result;
366 else 357 else
367 return NULL; 358 return NULL;
@@ -393,16 +384,25 @@ GNUNET_NAMESTORE_value_to_string (uint32_t type,
393 case GNUNET_NAMESTORE_TYPE_LEHO: 384 case GNUNET_NAMESTORE_TYPE_LEHO:
394 return GNUNET_strndup (data, data_size); 385 return GNUNET_strndup (data, data_size);
395 case GNUNET_NAMESTORE_TYPE_VPN: 386 case GNUNET_NAMESTORE_TYPE_VPN:
396 af = (uint32_t*)data; 387 vpn = (struct vpn_data*)data;
397 proto = (uint32_t*)((char*)af + sizeof (uint32_t)); 388
398 h_peer = (struct GNUNET_HashCode*)((char*)proto + sizeof (struct GNUNET_HashCode)); 389 GNUNET_CRYPTO_hash_to_enc (&vpn->peer, &s_peer);
399 h_serv = (struct GNUNET_HashCode*)((char*)h_peer + sizeof (struct GNUNET_HashCode)); 390 if (GNUNET_OK != GNUNET_asprintf (&vpn_str, "%d:%s:%s",
400 391 vpn->proto,
401 GNUNET_CRYPTO_hash_to_enc (h_peer, &s_peer); 392 (char*)&s_peer,
402 GNUNET_CRYPTO_hash_to_enc (h_serv, &s_serv); 393 (char*)&vpn[1]))
403 if (GNUNET_OK != GNUNET_asprintf (&vpn_str, "%d:%d:%s:%s", af, proto, (char*)&s_peer, (char*)&s_serv))
404 return NULL; 394 return NULL;
405 return vpn_str; 395 return vpn_str;
396 case GNUNET_DNSPARSER_TYPE_SRV:
397 srv = (struct srv_data*)data;
398
399 if (GNUNET_OK != GNUNET_asprintf (&srv_str, "%d:%d:%d:%s",
400 ntohs (srv->prio),
401 ntohs (srv->weight),
402 ntohs (srv->port),
403 (char*)&srv[1]))
404 return NULL;
405 return srv_str;
406 default: 406 default:
407 GNUNET_break (0); 407 GNUNET_break (0);
408 } 408 }
@@ -432,7 +432,7 @@ GNUNET_NAMESTORE_string_to_value (uint32_t type,
432 struct GNUNET_CRYPTO_ShortHashCode pkey; 432 struct GNUNET_CRYPTO_ShortHashCode pkey;
433 uint16_t mx_pref; 433 uint16_t mx_pref;
434 uint16_t mx_pref_n; 434 uint16_t mx_pref_n;
435 uint32_t soa_data[5]; 435 struct soa_data *soa;
436 char result[253]; 436 char result[253];
437 char soa_rname[63]; 437 char soa_rname[63];
438 char soa_mname[63]; 438 char soa_mname[63];
@@ -441,12 +441,10 @@ GNUNET_NAMESTORE_string_to_value (uint32_t type,
441 uint32_t soa_retry; 441 uint32_t soa_retry;
442 uint32_t soa_expire; 442 uint32_t soa_expire;
443 uint32_t soa_min; 443 uint32_t soa_min;
444 struct GNUNET_HashCode *h_peer;
445 struct GNUNET_HashCode *h_serv;
446 struct GNUNET_CRYPTO_HashAsciiEncoded s_peer; 444 struct GNUNET_CRYPTO_HashAsciiEncoded s_peer;
447 struct GNUNET_CRYPTO_HashAsciiEncoded s_serv; 445 char s_serv[253];
448 uint32_t* af; 446 struct vpn_data* vpn;
449 uint32_t* proto; 447 uint16_t proto;
450 448
451 switch (type) 449 switch (type)
452 { 450 {
@@ -475,17 +473,16 @@ GNUNET_NAMESTORE_string_to_value (uint32_t type,
475 != 7) 473 != 7)
476 return GNUNET_SYSERR; 474 return GNUNET_SYSERR;
477 475
478 *data_size = sizeof (soa_data)+strlen(soa_rname)+strlen(soa_mname)+2; 476 *data_size = sizeof (struct soa_data)+strlen(soa_rname)+strlen(soa_mname)+2;
479 *data = GNUNET_malloc (*data_size); 477 *data = GNUNET_malloc (*data_size);
480 soa_data[0] = htonl(soa_serial); 478 soa = (struct soa_data*)*data;
481 soa_data[1] = htonl(soa_refresh); 479 soa->serial = htonl(soa_serial);
482 soa_data[2] = htonl(soa_retry); 480 soa->refresh = htonl(soa_refresh);
483 soa_data[3] = htonl(soa_expire); 481 soa->retry = htonl(soa_retry);
484 soa_data[4] = htonl(soa_min); 482 soa->expire = htonl(soa_expire);
485 strcpy(*data, soa_rname); 483 soa->minimum = htonl(soa_min);
486 strcpy(*data+strlen(*data)+1, soa_mname); 484 strcpy((char*)&soa[1], soa_rname);
487 memcpy(*data+strlen(*data)+1+strlen(soa_mname)+1, 485 strcpy((char*)&soa[1]+strlen(*data)+1, soa_mname);
488 soa_data, sizeof(soa_data));
489 return GNUNET_OK; 486 return GNUNET_OK;
490 487
491 case GNUNET_DNSPARSER_TYPE_PTR: 488 case GNUNET_DNSPARSER_TYPE_PTR:
@@ -530,25 +527,26 @@ GNUNET_NAMESTORE_string_to_value (uint32_t type,
530 return GNUNET_OK; 527 return GNUNET_OK;
531 case GNUNET_NAMESTORE_TYPE_VPN: 528 case GNUNET_NAMESTORE_TYPE_VPN:
532 529
533 *data_size = sizeof (uint32_t) * 2;
534 *data_size += sizeof (struct GNUNET_HashCode) * 2;
535 *data = GNUNET_malloc (*data_size);
536 af = (uint32_t*)(*data);
537 proto = (uint32_t*) ((char*)af + sizeof (uint32_t));
538 h_peer = (struct GNUNET_HashCode*)((char*)proto + sizeof (uint32_t));
539 h_serv = (struct GNUNET_HashCode*)((char*)h_peer + sizeof (struct GNUNET_HashCode));
540 530
541 if (4 != SSCANF (s,"%d:%d:%s:%s", 531 if (4 != SSCANF (s,"%hu:%s:%s",
542 af, proto, (char*)&s_peer, (char*)&s_serv)) 532 &proto, (char*)&s_peer, s_serv))
543 { 533 {
544 return GNUNET_SYSERR; 534 return GNUNET_SYSERR;
545 } 535 }
546 if ((GNUNET_OK != GNUNET_CRYPTO_hash_from_string ((char*)&s_peer, h_peer)) || 536 *data_size = sizeof (struct vpn_data) + strlen (s_serv) + 1;
547 (GNUNET_OK != GNUNET_CRYPTO_hash_from_string ((char*)&s_serv, h_serv))) 537
538 *data = GNUNET_malloc (*data_size);
539
540 vpn = (struct vpn_data*)*data;
541
542 if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string ((char*)&s_peer, &vpn->peer))
548 { 543 {
549 GNUNET_free (*data); 544 GNUNET_free (*data);
550 return GNUNET_SYSERR; 545 return GNUNET_SYSERR;
551 } 546 }
547
548 vpn->proto = htons (proto);
549 strcpy ((char*)&vpn[1], s_serv);
552 return GNUNET_OK; 550 return GNUNET_OK;
553 default: 551 default:
554 GNUNET_break (0); 552 GNUNET_break (0);