chiark / gitweb /
Disobedience login window now only remembers password etc if they
authorRichard Kettlewell <rjk@greenend.org.uk>
Sun, 29 Jun 2008 14:42:43 +0000 (15:42 +0100)
committerRichard Kettlewell <rjk@greenend.org.uk>
Sun, 29 Jun 2008 14:42:43 +0000 (15:42 +0100)
actually worked.

disobedience/client.c
disobedience/login.c
lib/client-common.c
lib/client-common.h
lib/client.c
lib/client.h
lib/configuration.c
lib/configuration.h
lib/eclient.c

index 24069034a548f4a98622ad9571137231e7b38990..80aef8864365856cdda3293dec33b1254c455f3a 100644 (file)
@@ -130,7 +130,7 @@ static void gtkclient_comms_error(void attribute((unused)) *u,
  */
 static void gtkclient_protocol_error(void attribute((unused)) *u,
                                     void attribute((unused)) *v,
-                                     int code,
+                                     int attribute((unused)) code,
                                     const char *msg) {
   D(("gtkclient_protocol_error %s", msg));
   gtk_label_set_text(GTK_LABEL(report_label), msg);
index 7cb64c9d38cc9efce7260356a9ac9f82476a8467..73aaada133dc67302b98dab82d8dee775d5cc6ae 100644 (file)
@@ -49,7 +49,7 @@ struct login_window_item {
   const char *(*get)(void);
 
   /** @brief Set a new value */
-  void (*set)(const char *value);
+  void (*set)(struct config *c, const char *value);
 
   /** @brief Flags
    * 
@@ -80,10 +80,21 @@ static const char *get_service(void) { return config->connect.s[1]; }
 static const char *get_username(void) { return config->username; }
 static const char *get_password(void) { return config->password ? config->password : ""; }
 
-static void set_hostname(const char *s) { config->connect.s[0] = (char *)s; }
-static void set_service(const char *s) { config->connect.s[1] = (char *)s; }
-static void set_username(const char *s) { config->username = s; }
-static void set_password(const char *s) { config->password = s; }
+static void set_hostname(struct config *c, const char *s) {
+  c->connect.s[0] = (char *)s;
+}
+
+static void set_service(struct config *c, const char *s) {
+  c->connect.s[1] = (char *)s;
+}
+
+static void set_username(struct config *c, const char *s) {
+  c->username = s;
+}
+
+static void set_password(struct config *c, const char *s) {
+  c->password = s;
+}
 
 /** @brief Table used to generate the form */
 static const struct login_window_item lwis[] = {
@@ -96,11 +107,15 @@ static const struct login_window_item lwis[] = {
 
 static GtkWidget *lwi_entry[NLWIS];
 
-static void login_update_config(void) {
+static void login_update_config(struct config *c) {
   size_t n;
 
+  if(c->connect.n < 2) {
+    c->connect.n = 2;
+    c->connect.s = xcalloc(2, sizeof (char *));
+  }
   for(n = 0; n < NLWIS; ++n)
-    lwis[n].set(xstrdup(gtk_entry_get_text(GTK_ENTRY(lwi_entry[n]))));
+    lwis[n].set(c, xstrdup(gtk_entry_get_text(GTK_ENTRY(lwi_entry[n]))));
 }
 
 /** @brief Save current login details */
@@ -148,13 +163,17 @@ done:
 static void login_ok(GtkButton attribute((unused)) *button,
                      gpointer attribute((unused)) userdata) {
   disorder_client *c;
+  struct config *tmpconfig = xmalloc(sizeof *tmpconfig);
   
   /* Copy the new config into @ref config */
-  login_update_config();
+  login_update_config(tmpconfig);
   /* Attempt a login with the new details */
   c = disorder_new(0);
-  if(!disorder_connect(c)) {
+  if(!disorder_connect_generic(tmpconfig, c,
+                               tmpconfig->username, tmpconfig->password,
+                               NULL/*cookie*/)) {
     /* Success; save the config and start using it */
+    login_update_config(config);
     login_save_config();
     logged_in();
     /* Pop down login window */
@@ -162,8 +181,6 @@ static void login_ok(GtkButton attribute((unused)) *button,
   } else {
     /* Failed to connect - report the error */
     popup_msg(GTK_MESSAGE_ERROR, disorder_last(c));
-    /* TODO it would be nice to restore the config (not the entry contents!) to
-     * the last known good one if we were already connected to something. */
   }
   disorder_close(c);                    /* no use for this any more */
 }
index 53da8acc66899da0287e19a9280de85188e6c7a2..2c639348019e3d507c89d58a604173e07ade306e 100644 (file)
 #include "mem.h"
 
 /** @brief Figure out what address to connect to
+ * @param c Configuration to honor
  * @param sap Where to store pointer to sockaddr
  * @param namep Where to store socket name
  * @return Socket length, or (socklen_t)-1
  */
-socklen_t find_server(struct sockaddr **sap, char **namep) {
+socklen_t find_server(struct config *c,
+                      struct sockaddr **sap, char **namep) {
   struct sockaddr *sa;
   struct sockaddr_un su;
   struct addrinfo *res = 0;
@@ -50,13 +52,13 @@ socklen_t find_server(struct sockaddr **sap, char **namep) {
     .ai_protocol = IPPROTO_TCP,
   };
 
-  if(config->connect.n) {
-    res = get_address(&config->connect, &pref, &name);
+  if(c->connect.n) {
+    res = get_address(&c->connect, &pref, &name);
     if(!res) return -1;
     sa = res->ai_addr;
     len = res->ai_addrlen;
   } else {
-    name = config_get_file("socket");
+    name = config_get_file2(c, "socket");
     if(strlen(name) >= sizeof su.sun_path) {
       error(errno, "socket path is too long");
       return -1;
index dc50ee99c97ec52e8bfd10a6a2e55e1fedc46352..d6422785e48703f088e86c54e968af968b4851e8 100644 (file)
@@ -24,7 +24,7 @@
 #include <sys/types.h>
 #include <sys/socket.h>
 
-socklen_t find_server(struct sockaddr **sap, char **namep);
+socklen_t find_server(struct config *c, struct sockaddr **sap, char **namep);
 
 #endif /* CLIENT_COMMON_H */
 
index 84eb77e539310175b8aeaf94b9d303f98ad8200c..ba1477aa2436d15b1243b4039e2aca64682b500d 100644 (file)
@@ -37,7 +37,6 @@
 
 #include "log.h"
 #include "mem.h"
-#include "configuration.h"
 #include "queue.h"
 #include "client.h"
 #include "charset.h"
@@ -248,6 +247,7 @@ static int dequote(int rc, char **rp) {
 }
 
 /** @brief Generic connection routine
+ * @param conf Configuration to follow
  * @param c Client
  * @param username Username to log in with or NULL
  * @param password Password to log in with or NULL
@@ -258,10 +258,11 @@ static int dequote(int rc, char **rp) {
  * username must not be.  If @p username is not NULL then nor may @p
  * password be.
  */
-static int disorder_connect_generic(disorder_client *c,
-                                   const char *username,
-                                   const char *password,
-                                   const char *cookie) {
+int disorder_connect_generic(struct config *conf,
+                             disorder_client *c,
+                             const char *username,
+                             const char *password,
+                             const char *cookie) {
   int fd = -1, fd2 = -1, nrvec, rc;
   unsigned char *nonce;
   size_t nl;
@@ -271,7 +272,7 @@ static int disorder_connect_generic(disorder_client *c,
   struct sockaddr *sa;
   socklen_t salen;
 
-  if((salen = find_server(&sa, &c->ident)) == (socklen_t)-1)
+  if((salen = find_server(conf, &sa, &c->ident)) == (socklen_t)-1)
     return -1;
   c->fpin = c->fpout = 0;
   if((fd = socket(sa->sa_family, SOCK_STREAM, 0)) < 0) {
@@ -363,7 +364,8 @@ error_rc:
 int disorder_connect_user(disorder_client *c,
                          const char *username,
                          const char *password) {
-  return disorder_connect_generic(c,
+  return disorder_connect_generic(config,
+                                  c,
                                  username,
                                  password,
                                  0);
@@ -399,7 +401,8 @@ int disorder_connect(disorder_client *c) {
     error(0, "no password configured");
     return -1;
   }
-  return disorder_connect_generic(c,
+  return disorder_connect_generic(config,
+                                  c,
                                  username,
                                  password,
                                  0);
@@ -416,7 +419,8 @@ int disorder_connect(disorder_client *c) {
  */
 int disorder_connect_cookie(disorder_client *c,
                            const char *cookie) {
-  return disorder_connect_generic(c,
+  return disorder_connect_generic(config,
+                                  c,
                                  "guest",
                                  "",
                                  cookie);
index 912fa3255280cb82abc5bad727a0b2829d69eaf6..094147c67e99d00297c3e9808d52c8e714c602f8 100644 (file)
@@ -28,6 +28,7 @@
 #define CLIENT_H
 
 #include <time.h>
+#include "configuration.h"
 
 /** @brief Client data */
 typedef struct disorder_client disorder_client;
@@ -42,6 +43,11 @@ int disorder_connect_user(disorder_client *c,
                          const char *username,
                          const char *password);
 int disorder_connect_cookie(disorder_client *c, const char *cookie);
+int disorder_connect_generic(struct config *conf,
+                             disorder_client *c,
+                             const char *username,
+                             const char *password,
+                             const char *cookie);
 int disorder_close(disorder_client *c);
 int disorder_version(disorder_client *c, char **versionp);
 int disorder_play(disorder_client *c, const char *track);
index 241d101dc30efa6d131866802777656dcff5177f..540084cd0654cedd2f4beef276037d84feeabf99 100644 (file)
@@ -1213,7 +1213,7 @@ static struct config *config_default(void) {
   return c;
 }
 
-static char *get_file(struct config *c, const char *name) {
+char *config_get_file2(struct config *c, const char *name) {
   char *s;
 
   byte_xasprintf(&s, "%s/%s", c->home, name);
@@ -1411,7 +1411,7 @@ char *config_usersysconf(const struct passwd *pw) {
 }
 
 char *config_get_file(const char *name) {
-  return get_file(config, name);
+  return config_get_file2(config, name);
 }
 
 /*
index cc7e1e3756b6d54478795ba90c4d518e3fda620c..ab8917a87d486db428c52e95485bdbfa237de3bf 100644 (file)
@@ -311,6 +311,7 @@ int config_read(int server);
 /* re-read config, return 0 on success or non-0 on error.
  * Only updates @config@ if the new configuration is valid. */
 
+char *config_get_file2(struct config *c, const char *name);
 char *config_get_file(const char *name);
 /* get a filename within the home directory */
 
index e7353df436e89540f113ff763da0ce4b93adf144..f86ecc786f4fc254ec232c4bfd32249a77cb34e8 100644 (file)
@@ -490,7 +490,7 @@ static int start_connect(disorder_eclient *c) {
   socklen_t len;
 
   D(("start_connect"));
-  if((len = find_server(&sa, &c->ident)) == (socklen_t)-1)
+  if((len = find_server(config, &sa, &c->ident)) == (socklen_t)-1)
     return comms_error(c, "cannot look up server"); /* TODO better error */
   if(c->fd != -1) {
     xclose(c->fd);