actually worked.
*/
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);
const char *(*get)(void);
/** @brief Set a new value */
- void (*set)(const char *value);
+ void (*set)(struct config *c, const char *value);
/** @brief Flags
*
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[] = {
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 */
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 */
} 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 */
}
#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;
.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;
#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 */
#include "log.h"
#include "mem.h"
-#include "configuration.h"
#include "queue.h"
#include "client.h"
#include "charset.h"
}
/** @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
* 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;
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) {
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);
error(0, "no password configured");
return -1;
}
- return disorder_connect_generic(c,
+ return disorder_connect_generic(config,
+ c,
username,
password,
0);
*/
int disorder_connect_cookie(disorder_client *c,
const char *cookie) {
- return disorder_connect_generic(c,
+ return disorder_connect_generic(config,
+ c,
"guest",
"",
cookie);
#define CLIENT_H
#include <time.h>
+#include "configuration.h"
/** @brief Client data */
typedef struct disorder_client disorder_client;
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);
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);
}
char *config_get_file(const char *name) {
- return get_file(config, name);
+ return config_get_file2(config, name);
}
/*
/* 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 */
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);