-fixes
[oweals/gnunet.git] / src / gns / gnunet-dns2gns.c
index 7d44ceacbf86867bec06b0a09b90baceadec2f2f..e58a87692dc89166e1676c26747a71c41a615fc1 100644 (file)
@@ -159,8 +159,9 @@ do_shutdown (void *cls,
     listen_socket6 = NULL;
   }
   GNUNET_GNS_disconnect (gns);
-  GNUNET_DNSSTUB_stop (dns_stub);
   gns = NULL;
+  GNUNET_DNSSTUB_stop (dns_stub);
+  dns_stub = NULL;
 }
 
 
@@ -270,6 +271,7 @@ result_processor (void *cls,
   //packet->flags.opcode = GNUNET_DNSPARSER_OPCODE_STATUS; // ???
   for (i=0;i<rd_count;i++)
     {
+      rec.expiration_time.abs_value = rd[i].expiration_time;
       switch (rd[i].record_type)
        {
        case GNUNET_DNSPARSER_TYPE_A:
@@ -352,12 +354,12 @@ handle_request (struct GNUNET_NETWORK_Handle *lsock,
                  GNUNET_a2s (addr, addr_len));
       return;
     }
-  GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                 "%d, %d, %d, %d\n",
-                 packet->flags.query_or_response,
-                 packet->num_answers,
-                 packet->num_authority_records,
-                 packet->num_additional_records);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+             "Received request with flags %u, #answers %d, #auth %d, #additional %d\n",
+             (unsigned int) packet->flags.query_or_response,
+             (int) packet->num_answers,
+             (int) packet->num_authority_records,
+             (int) packet->num_additional_records);
   if ( (0 != packet->flags.query_or_response) || 
        (0 != packet->num_answers) ||
        (0 != packet->num_authority_records))
@@ -392,10 +394,11 @@ handle_request (struct GNUNET_NETWORK_Handle *lsock,
        (0 == strcasecmp (dns_suffix,
                         &name[name_len - strlen (dns_suffix)])) )
     {
-      if (0 == strcasecmp (fcfs_suffix,
-                           &name[name_len - strlen (fcfs_suffix)]))
+      if ( (name_len > strlen (fcfs_suffix)) &&
+          (0 == strcasecmp (fcfs_suffix,
+                            &name[name_len - strlen (fcfs_suffix)])) )
       {
-        name[name_len - strlen (dns_suffix) + 1] = '\0';
+        name[name_len - strlen (fcfs_suffix) + 1] = '\0';
         strcat (name, GNUNET_GNS_TLD);
       }
       else
@@ -556,19 +559,16 @@ run (void *cls, char *const *args, const char *cfgfile,
 
   if (NULL == dns_suffix)
     dns_suffix = DNS_SUFFIX;
-
   if (NULL == fcfs_suffix)
     fcfs_suffix = FCFS_SUFFIX;
-
-  gns = GNUNET_GNS_connect (cfg);
-
-  dns_stub = GNUNET_DNSSTUB_start (dns_ip);
-
-  if (NULL == dns_stub)
-    return;
-
-  if (NULL == gns)
+  if (NULL == (gns = GNUNET_GNS_connect (cfg)))
     return;
+  if (NULL == (dns_stub = GNUNET_DNSSTUB_start (dns_ip)))
+    {
+      GNUNET_GNS_disconnect (gns);
+      gns = NULL;
+      return;
+    }
   listen_socket4 = GNUNET_NETWORK_socket_create (PF_INET,
                                                 SOCK_DGRAM, 
                                                 IPPROTO_UDP);
@@ -617,7 +617,13 @@ run (void *cls, char *const *args, const char *cfgfile,
     }
   if ( (NULL == listen_socket4) &&
        (NULL == listen_socket6) )
-    return;
+    {
+      GNUNET_GNS_disconnect (gns);
+      gns = NULL;
+      GNUNET_DNSSTUB_stop (dns_stub);
+      dns_stub = NULL;
+      return;
+    }
   if (NULL != listen_socket4)
     t4 = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
                                        listen_socket4,