[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r20269 - in gnunet/src: gns include namestore
From: |
gnunet |
Subject: |
[GNUnet-SVN] r20269 - in gnunet/src: gns include namestore |
Date: |
Mon, 5 Mar 2012 11:26:56 +0100 |
Author: grothoff
Date: 2012-03-05 11:26:56 +0100 (Mon, 05 Mar 2012)
New Revision: 20269
Modified:
gnunet/src/gns/gnunet-gns.c
gnunet/src/include/gnunet_namestore_service.h
gnunet/src/namestore/namestore_api.c
Log:
-parsing type and common values in gnunet-gns
Modified: gnunet/src/gns/gnunet-gns.c
===================================================================
--- gnunet/src/gns/gnunet-gns.c 2012-03-05 09:48:41 UTC (rev 20268)
+++ gnunet/src/gns/gnunet-gns.c 2012-03-05 10:26:56 UTC (rev 20269)
@@ -27,6 +27,7 @@
*/
#include "platform.h"
#include <gnunet_util_lib.h>
+#include <gnunet_dnsparser_lib.h>
#include <gnunet_namestore_service.h>
/**
@@ -121,6 +122,11 @@
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 @@
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);
+ }
+
+
}
Modified: gnunet/src/include/gnunet_namestore_service.h
===================================================================
--- gnunet/src/include/gnunet_namestore_service.h 2012-03-05 09:48:41 UTC
(rev 20268)
+++ gnunet/src/include/gnunet_namestore_service.h 2012-03-05 10:26:56 UTC
(rev 20269)
@@ -49,6 +49,11 @@
#define GNUNET_GNS_TYPE_PKEY 65536
/**
+ * Record type for GNS zone transfer ("PSEU").
+ */
+#define GNUNET_GNS_TYPE_PSEU 65537
+
+/**
* Entry in the queue.
*/
struct GNUNET_NAMESTORE_QueueEntry;
@@ -68,7 +73,18 @@
*/
#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.
*
* @param cfg configuration to use
Modified: gnunet/src/namestore/namestore_api.c
===================================================================
--- gnunet/src/namestore/namestore_api.c 2012-03-05 09:48:41 UTC (rev
20268)
+++ gnunet/src/namestore/namestore_api.c 2012-03-05 10:26:56 UTC (rev
20269)
@@ -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_ZoneIterator
{
+
+ /**
+ * Kept in a DLL.
+ */
struct GNUNET_NAMESTORE_ZoneIterator *next;
+
+ /**
+ * Kept in a DLL.
+ */
struct GNUNET_NAMESTORE_ZoneIterator *prev;
uint32_t op_id;
@@ -184,7 +201,43 @@
};
+
/**
+ * 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.
*
* @param h our handle
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r20269 - in gnunet/src: gns include namestore,
gnunet <=