-avoid side-effect in assertion
[oweals/gnunet.git] / src / testbed / testbed_api_hosts.c
index f93a140c5d45113bf4fa500fe372a0390beb3c07..2593f5ff80383956f9dc8bfb0a013df3715bcd40 100644 (file)
@@ -486,13 +486,13 @@ GNUNET_TESTBED_hosts_load_from_file (const char *filename,
     {
       data[offset] = '\0';
       ret =
-          SSCANF (buf, "%255[a-zA-Z0-9_]@%255[a-zA-Z0-9.-]:%5hd", username,
+          SSCANF (buf, "%255[a-zA-Z0-9_]@%255[.a-zA-Z0-9-]:%5hd", username,
                   hostname, &port);
       if (3 == ret)
       {
-        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                    "Successfully read host %s, port %d and user %s from file\n",
-                    hostname, port, username);
+        LOG (GNUNET_ERROR_TYPE_DEBUG,
+             "Successfully read host %s, port %d and user %s from file\n",
+             hostname, port, username);
         /* We store hosts in a static list; hence we only require the starting
          * host pointer in that list to access the newly created list of hosts */
         if (NULL == starting_host)
@@ -561,6 +561,17 @@ simple_resolve (const char *host)
   return hostip;
 }
 
+#if ENABLE_LL
+static int
+cmpstringp(const void *p1, const void *p2)
+{
+  /* The actual arguments to this function are "pointers to
+     pointers to char", but strcmp(3) arguments are "pointers
+     to char", hence the following cast plus dereference */
+  
+  return strcmp(* (char * const *) p1, * (char * const *) p2);
+}
+#endif
 
 /**
  * Loads the set of host allocated by the LoadLeveler Job Scheduler.  This
@@ -689,7 +700,7 @@ GNUNET_TESTBED_hosts_load_from_loadleveler (const struct
     return 0;
   if (NULL == hosts)
     goto cleanup;
-  qsort (hostnames, nhosts, sizeof (hostnames[0]), &strcmp);
+  qsort (hostnames, nhosts, sizeof (hostnames[0]), cmpstringp);
   host_list = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Host *) * nhosts);
   for (host = 0; host < nhosts; host++)
     host_list[host] = GNUNET_TESTBED_host_create (hostnames[host], NULL, cfg, 0);
@@ -1051,7 +1062,6 @@ helper_mst (void *cls, void *client, const struct GNUNET_MessageHeader *message)
   struct GNUNET_TESTBED_ControllerProc *cp = cls;
   const struct GNUNET_TESTBED_HelperReply *msg;
   const char *hostname;
-  const char *hostip;
   char *config;
   uLongf config_size;
   uLongf xconfig_size;
@@ -1079,12 +1089,9 @@ helper_mst (void *cls, void *client, const struct GNUNET_MessageHeader *message)
   if ((NULL == cp->host) ||
       (NULL == (hostname = GNUNET_TESTBED_host_get_hostname (cp->host))))
     hostname = "localhost";
-  hostip = simple_resolve (hostname);
-  if (NULL == hostip)
-    hostip = "127.0.0.1";  
   /* Change the hostname so that we can connect to it */
   GNUNET_CONFIGURATION_set_value_string (cp->host->cfg, "testbed", "hostname",
-                                         hostip);
+                                         hostname);
   cp->host->locked = GNUNET_NO;
   cp->host->controller_started = GNUNET_YES;
   cp->cb (cp->cls, cp->host->cfg, GNUNET_OK);
@@ -1876,4 +1883,27 @@ GNUNET_TESTBED_host_handle_addhostconfirm_ (struct GNUNET_TESTBED_Controller *c,
   return GNUNET_OK;
 }
 
+
+/**
+ * Resolves the hostname of the host to an ip address
+ *
+ * @param host the host whose hostname is to be resolved
+ */
+void
+GNUNET_TESTBED_host_resolve_ (struct GNUNET_TESTBED_Host *host)
+{
+  char *hostname;
+
+  hostname = (char *) host->hostname;
+  host->hostname = simple_resolve (hostname);
+  if (NULL == host->hostname)
+  {
+    GNUNET_break (0);
+    host->hostname = hostname;
+    return;
+  }
+  GNUNET_free (hostname);
+  host->hostname = GNUNET_strdup (host->hostname);
+}
+
 /* end of testbed_api_hosts.c */