chiark / gitweb /
connect uses new network address support
authorRichard Kettlewell <rjk@greenend.org.uk>
Sat, 14 Mar 2009 16:15:12 +0000 (16:15 +0000)
committerRichard Kettlewell <rjk@greenend.org.uk>
Sat, 14 Mar 2009 16:15:12 +0000 (16:15 +0000)
This include Disobedience.  IPv6 works at least to loopback...

clients/disorder.c
disobedience/login.c
lib/client-common.c
lib/configuration.c
lib/configuration.h

index 5f725e8180ad93200abaf4920e38f12dbac6bd0a..24663111ae745942148ea3c64d3035ad6ee524eb 100644 (file)
@@ -762,7 +762,7 @@ int main(int argc, char **argv) {
   if(password)
     config->password = password;
   if(local)
-    config->connect.n = 0;
+    config->connect.af = -1;
   n = optind;
   optind = 1;                          /* for subsequent getopt calls */
   /* gcrypt initialization */
index 1c6df79c57107c834dd9bc21fd74ff136e5f23e9..36850c11da60b9f201c59da9b0033c3bea1cdedc 100644 (file)
@@ -73,7 +73,7 @@ static void default_connect(void) {
   if(config->password)
     return;
   /* If we already have a host and/or port that's good too */
-  if(config->connect.n)
+  if(config->connect.af != -1)
     return;
   /* If there's a suitable socket that's probably what we wanted */
   const char *s = config_get_file("socket");
@@ -84,11 +84,21 @@ static void default_connect(void) {
 }
 
 static const char *get_hostname(void) {
-  return config->connect.n >= 2 ? config->connect.s[0] : "";
+  if(config->connect.af == -1 || !config->connect.address)
+    return "";
+  else
+    return config->connect.address;
 }
 
 static const char *get_service(void) {
-  return config->connect.n >= 2 ? config->connect.s[1] : "";
+  if(config->connect.af == -1)
+    return "";
+  else {
+    char *s;
+
+    byte_xasprintf(&s, "%d", config->connect.port);
+    return s;
+  }
 }
 
 static const char *get_username(void) {
@@ -100,11 +110,13 @@ static const char *get_password(void) {
 }
 
 static void set_hostname(struct config *c, const char *s) {
-  c->connect.s[0] = (char *)s;
+  if(c->connect.af == -1)
+    c->connect.af = AF_UNSPEC;
+  c->connect.address = xstrdup(s);
 }
 
 static void set_service(struct config *c, const char *s) {
-  c->connect.s[1] = (char *)s;
+  c->connect.port = atoi(s);
 }
 
 static void set_username(struct config *c, const char *s) {
@@ -131,13 +143,10 @@ static void login_update_config(struct config *c) {
   size_t n;
   const gboolean remote = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lwi_remote));
 
-  if(remote) {
-    c->connect.n = 2;
-    c->connect.s = xcalloc(2, sizeof (char *));
-  } else {
-    c->connect.n = 0;
-    c->connect.s = 0;
-  }
+  if(remote)
+    c->connect.af = AF_UNSPEC;
+  else
+    c->connect.af = -1;
   for(n = 0; n < NLWIS; ++n)
     if(remote || !(lwis[n].flags & LWI_REMOTE))
       lwis[n].set(c, xstrdup(gtk_entry_get_text(GTK_ENTRY(lwi_entry[n]))));
@@ -161,10 +170,12 @@ static void login_save_config(void) {
                    "password %s\n",
                    quoteutf8(config->username),
                    quoteutf8(config->password));
-  if(rc >= 0 && config->connect.n)
-    rc = fprintf(fp, "connect %s %s\n",
-                 quoteutf8(config->connect.s[0]),
-                 quoteutf8(config->connect.s[1]));
+  if(rc >= 0 && config->connect.af != -1) {
+    char **vec;
+
+    netaddress_format(&config->connect, NULL, &vec);
+    rc = fprintf(fp, "connect %s %s %s\n", vec[0], vec[1], vec[2]);
+  }
   if(rc < 0) {
     fpopup_msg(GTK_MESSAGE_ERROR, "error writing to %s: %s",
                tmp, strerror(errno));
@@ -327,7 +338,7 @@ void login_box(void) {
   }
   /* Initial settings */
   gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lwi_remote),
-                               config->connect.n >= 2);
+                               config->connect.af != -1);
   lwi_remote_toggled(GTK_TOGGLE_BUTTON(lwi_remote), 0);
   buttonbox = create_buttons(buttons, NBUTTONS);
   vbox = gtk_vbox_new(FALSE, 1);
index ced82e4fb6eaf71199dc79fd422cb9ae4cbca8d4..aa4312430a3ae837c83b4eabeb63ab92b323fd2b 100644 (file)
@@ -45,17 +45,11 @@ socklen_t find_server(struct config *c,
   struct addrinfo *res = 0;
   char *name;
   socklen_t len;
-   
-  static const struct addrinfo pref = {
-    .ai_flags = 0,
-    .ai_family = PF_INET,
-    .ai_socktype = SOCK_STREAM,
-    .ai_protocol = IPPROTO_TCP,
-  };
 
-  if(c->connect.n) {
-    res = get_address(&c->connect, &pref, &name);
-    if(!res) return -1;
+  if(c->connect.af != -1) {
+    res = netaddress_resolve(&c->connect, 0, IPPROTO_TCP);
+    if(!res) 
+      return -1;
     sa = res->ai_addr;
     len = res->ai_addrlen;
   } else {
@@ -73,7 +67,7 @@ socklen_t find_server(struct config *c,
   *sap = xmalloc_noptr(len);
   memcpy(*sap, sa, len);
   if(namep)
-    *namep = name;
+    *namep = format_sockaddr(sa);
   if(res)
     freeaddrinfo(res);
   return len;
index 5691e8ae24e518fa1d79ab3fe53d1a317281ae0a..23ecde27eadf3d35004672e8dec10f69e3374e5c 100644 (file)
@@ -833,27 +833,6 @@ static int validate_alias(const struct config_state *cs,
   return 0;
 }
 
-static int validate_addrport(const struct config_state attribute((unused)) *cs,
-                            int nvec,
-                            char attribute((unused)) **vec) {
-  switch(nvec) {
-  case 0:
-    error(0, "%s:%d: missing address",
-         cs->path, cs->line);
-    return -1;
-  case 1:
-    error(0, "%s:%d: missing port name/number",
-         cs->path, cs->line);
-    return -1;
-  case 2:
-    return 0;
-  default:
-    error(0, "%s:%d: expected ADDRESS PORT",
-         cs->path, cs->line);
-    return -1;
-  }
-}
-
 static int validate_algo(const struct config_state attribute((unused)) *cs,
                         int nvec,
                         char **vec) {
@@ -933,7 +912,7 @@ static const struct conf conf[] = {
   { C(checkpoint_kbyte), &type_integer,          validate_non_negative },
   { C(checkpoint_min),   &type_integer,          validate_non_negative },
   { C(collection),       &type_collections,      validate_any },
-  { C(connect),          &type_stringlist,       validate_addrport },
+  { C(connect),          &type_netaddress,       validate_destaddr },
   { C(cookie_login_lifetime),  &type_integer,    validate_positive },
   { C(cookie_key_lifetime),  &type_integer,      validate_positive },
   { C(dbversion),        &type_integer,          validate_positive },
@@ -1223,6 +1202,7 @@ static struct config *config_default(void) {
   c->broadcast.af = -1;
   c->broadcast_from.af = -1;
   c->listen.af = -1;
+  c->connect.af = -1;
   return c;
 }
 
index 47856d7c52f72e52304cfe78a9dd34a91171f038..4cb56774671ebeec323d4069d6528bb1d75a919f 100644 (file)
@@ -194,7 +194,7 @@ struct config {
   const char *password;
 
   /** @brief Address to connect to */
-  struct stringlist connect;
+  struct netaddress connect;
 
   /** @brief Directories to search for web templates */
   struct stringlist templates;