From: Christian Grothoff Date: Mon, 5 Mar 2012 10:26:56 +0000 (+0000) Subject: -parsing type and common values in gnunet-gns X-Git-Tag: initial-import-from-subversion-38251~14435 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=0333d3afbc95ada40eabbac5e7cf02c598507a67;p=oweals%2Fgnunet.git -parsing type and common values in gnunet-gns --- diff --git a/src/gns/gnunet-gns.c b/src/gns/gnunet-gns.c index b56423c04..738c68788 100644 --- a/src/gns/gnunet-gns.c +++ b/src/gns/gnunet-gns.c @@ -27,6 +27,7 @@ */ #include "platform.h" #include +#include #include /** @@ -121,6 +122,11 @@ run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) { struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pub; + uint32_t type; + const void *data; + size_t data_size; + struct in_addr value_a; + struct in6_addr value_aaaa; if (NULL == keyfile) { @@ -143,12 +149,92 @@ run (void *cls, char *const *args, const char *cfgfile, GNUNET_CRYPTO_hash (&pub, sizeof (pub), &zone); ns = GNUNET_NAMESTORE_connect (cfg); if (NULL == ns) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _("Failed to connect to namestore\n")); + return; + } + GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); + if (NULL == typestring) + type = 0; + else + type = GNUNET_NAMESTORE_typename_to_number (typestring); + if (UINT32_MAX == type) + { + fprintf (stderr, _("Unsupported type `%s'\n"), typestring); + GNUNET_SCHEDULER_shutdown (); + return; + } + if (NULL != value) + { + switch (type) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("Failed to connect to namestore\n")); + case 0: + fprintf (stderr, _("Need a record type to interpret value `%s'\n"), value); + GNUNET_SCHEDULER_shutdown (); + break; + case GNUNET_DNSPARSER_TYPE_A: + if (1 != inet_pton (AF_INET, value, &value_a)) + { + fprintf (stderr, _("Value `%s' invalid for record type `%s'\n"), + value, + typestring); + GNUNET_SCHEDULER_shutdown (); + return; + } + data = &value_a; + data_size = sizeof (value_a); + break; + case GNUNET_DNSPARSER_TYPE_NS: + data = value; + data_size = strlen (value); + break; + case GNUNET_DNSPARSER_TYPE_CNAME: + data = value; + data_size = strlen (value); + break; + case GNUNET_DNSPARSER_TYPE_SOA: + fprintf (stderr, _("Record type `%s' not implemented yet\n"), typestring); + GNUNET_SCHEDULER_shutdown (); + return; + case GNUNET_DNSPARSER_TYPE_PTR: + fprintf (stderr, _("Record type `%s' not implemented yet\n"), typestring); + GNUNET_SCHEDULER_shutdown (); + return; + case GNUNET_DNSPARSER_TYPE_MX: + fprintf (stderr, _("Record type `%s' not implemented yet\n"), typestring); + GNUNET_SCHEDULER_shutdown (); + return; + case GNUNET_DNSPARSER_TYPE_TXT: + data = value; + data_size = strlen (value); + break; + case GNUNET_DNSPARSER_TYPE_AAAA: + if (1 != inet_pton (AF_INET6, value, &value_aaaa)) + { + fprintf (stderr, _("Value `%s' invalid for record type `%s'\n"), + value, + typestring); + GNUNET_SCHEDULER_shutdown (); + return; + } + data = &value_aaaa; + data_size = sizeof (value_aaaa); + break; + case GNUNET_GNS_TYPE_PKEY: + fprintf (stderr, _("Record type `%s' not implemented yet\n"), typestring); + GNUNET_SCHEDULER_shutdown (); return; + case GNUNET_GNS_TYPE_PSEU: + data = value; + data_size = strlen (value); + break; + default: + GNUNET_assert (0); } - GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); + } + + } diff --git a/src/include/gnunet_namestore_service.h b/src/include/gnunet_namestore_service.h index 0278c4a49..a8233fa4b 100644 --- a/src/include/gnunet_namestore_service.h +++ b/src/include/gnunet_namestore_service.h @@ -48,6 +48,11 @@ extern "C" */ #define GNUNET_GNS_TYPE_PKEY 65536 +/** + * Record type for GNS zone transfer ("PSEU"). + */ +#define GNUNET_GNS_TYPE_PSEU 65537 + /** * Entry in the queue. */ @@ -68,6 +73,17 @@ struct GNUNET_NAMESTORE_ZoneIterator; */ #define GNUNET_NAMESTORE_MAX_VALUE_SIZE (63 * 1024) + +/** + * Convert a type name (i.e. "AAAA") to the corresponding number. + * + * @param typename name to convert + * @return corresponding number, UINT32_MAX on error + */ +uint32_t +GNUNET_NAMESTORE_typename_to_number (const char *typename); + + /** * Connect to the namestore service. * diff --git a/src/namestore/namestore_api.c b/src/namestore/namestore_api.c index e4dae859b..7d42b68e4 100644 --- a/src/namestore/namestore_api.c +++ b/src/namestore/namestore_api.c @@ -29,6 +29,7 @@ #include "gnunet_util_lib.h" #include "gnunet_crypto_lib.h" #include "gnunet_constants.h" +#include "gnunet_dnsparser_lib.h" #include "gnunet_arm_service.h" #include "gnunet_signatures.h" #include "gnunet_namestore_service.h" @@ -43,7 +44,15 @@ */ struct GNUNET_NAMESTORE_QueueEntry { + + /** + * Kept in a DLL. + */ struct GNUNET_NAMESTORE_QueueEntry *next; + + /** + * Kept in a DLL. + */ struct GNUNET_NAMESTORE_QueueEntry *prev; struct GNUNET_NAMESTORE_Handle *nsh; @@ -65,7 +74,15 @@ struct GNUNET_NAMESTORE_QueueEntry */ struct GNUNET_NAMESTORE_ZoneIterator { + + /** + * Kept in a DLL. + */ struct GNUNET_NAMESTORE_ZoneIterator *next; + + /** + * Kept in a DLL. + */ struct GNUNET_NAMESTORE_ZoneIterator *prev; uint32_t op_id; @@ -184,6 +201,42 @@ struct GNUNET_NAMESTORE_SimpleRecord }; + +/** + * Convert a type name (i.e. "AAAA") to the corresponding number. + * + * @param typename name to convert + * @return corresponding number, UINT32_MAX on error + */ +uint32_t +GNUNET_NAMESTORE_typename_to_number (const char *typename) +{ + static struct { + const char *name; + uint32_t number; + } map[] = { + { "A", GNUNET_DNSPARSER_TYPE_A }, + { "NS", GNUNET_DNSPARSER_TYPE_NS }, + { "CNAME", GNUNET_DNSPARSER_TYPE_CNAME }, + { "SOA", GNUNET_DNSPARSER_TYPE_SOA }, + { "PTR", GNUNET_DNSPARSER_TYPE_PTR }, + { "MX", GNUNET_DNSPARSER_TYPE_MX }, + { "TXT", GNUNET_DNSPARSER_TYPE_TXT }, + { "AAAA", GNUNET_DNSPARSER_TYPE_AAAA }, + { "PKEY", GNUNET_GNS_TYPE_PKEY }, + { "PSEU", GNUNET_GNS_TYPE_PSEU }, + { NULL, UINT32_MAX } + }; + unsigned int i; + + i=0; + while ( (map[i].name != NULL) && + (0 != strcasecmp (typename, map[i].name)) ) + i++; + return map[i].number; +} + + /** * Disconnect from service and then reconnect. *