- added check against statistics
[oweals/gnunet.git] / src / gns / gnunet-gns.c
index b689cab18459e04a912507774c2b30d2a3fd1190..b7102eaa9ec1bdd110c3d96f17ab29f25c883730 100644 (file)
@@ -81,6 +81,7 @@ static void
 process_shorten_result(void* cls, const char* nshort)
 {
   printf("%s shortened to %s\n", (char*) cls, nshort);
+  GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
 }
 
 static void
@@ -88,27 +89,25 @@ process_lookup_result(void* cls, uint32_t rd_count,
                       const struct GNUNET_NAMESTORE_RecordData *rd)
 {
   int i;
-  char* addr;
   char* name = (char*) cls;
+  const char* typename;
+  char* string_val;
 
   if (rd_count == 0)
     printf("No results.\n");
+  else
+    printf("%s:\n", name);
+
+
 
   for (i=0; i<rd_count; i++)
   {
-    if (rd[i].record_type != rtype)
-      continue;
-    if (rd[i].record_type == GNUNET_GNS_RECORD_TYPE_A)
-    {
-      addr = inet_ntoa(*((struct in_addr*)rd[i].data));
-      printf("Got A record for %s: %s\n", name, addr);
-    }
-    if (rd[i].record_type == GNUNET_GNS_RECORD_MX)
-    {
-      printf("Got MX record for %s: %s\n", name, (char*)rd[i].data);
-    }
-
-    //FIXME others? maybe to string method for records?
+    typename = GNUNET_NAMESTORE_number_to_typename (rd[i].record_type);
+    string_val = GNUNET_NAMESTORE_value_to_string(rd[i].record_type,
+                                                  rd[i].data,
+                                                  rd[i].data_size);
+    printf("Got %s record: %s\n", typename, string_val);
+
   }
 
   GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
@@ -118,6 +117,7 @@ static void
 process_auth_result(void* cls, const char* auth)
 {
   printf ("%s\n", auth);
+  GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
 }
 
 /**
@@ -133,7 +133,10 @@ run (void *cls, char *const *args, const char *cfgfile,
      const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
   gns = GNUNET_GNS_connect (cfg);
-  rtype = GNUNET_GNS_RECORD_TYPE_A;
+  if (lookup_type != NULL)
+    rtype = GNUNET_NAMESTORE_typename_to_number(lookup_type);
+  else
+    rtype = GNUNET_GNS_RECORD_TYPE_A;
 
   if (NULL == gns)
   {
@@ -151,6 +154,8 @@ run (void *cls, char *const *args, const char *cfgfile,
 
   if (lookup_name != NULL)
   {
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "Lookup\n");
     GNUNET_GNS_lookup(gns, lookup_name, rtype,
                       &process_lookup_result, lookup_name);
   }