From 8304b30b5206c6cedcda44f046b24037eaa364dc Mon Sep 17 00:00:00 2001 From: James Booth Date: Thu, 6 Dec 2012 20:36:16 +0000 Subject: [PATCH] Add optional server parameter to /connect command --- src/command.c | 17 ++++++++++------- src/jabber.c | 12 +++++++++--- src/jabber.h | 2 +- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/command.c b/src/command.c index 31cc108e..0606c12f 100644 --- a/src/command.c +++ b/src/command.c @@ -156,15 +156,17 @@ static struct cmd_t main_commands[] = NULL } } }, { "/connect", - _cmd_connect, parse_args, 1, 1, - { "/connect user@host", "Login to jabber.", - { "/connect user@host", - "------------------", - "Connect to the jabber server at host using the username user.", - "Profanity should work with any XMPP (Jabber) compliant chat host.", + _cmd_connect, parse_args, 1, 2, + { "/connect user@domain [server]", "Login to jabber.", + { "/connect user@domain [server]", + "-----------------------------", + "Connect to the jabber server at domain using the username user.", + "Profanity should work with any XMPP (Jabber) compliant chat service.", "You can use tab completion to autocomplete any logins you have used before.", + "Use the server option if the chat service is hosted at a different domain to the 'domain' part.", "", "Example: /connect myuser@gmail.com", + "Example: /connect myuser@mycompany.com talk.google.com", NULL } } }, { "/disconnect", @@ -930,6 +932,7 @@ _cmd_connect(gchar **args, struct cmd_help_t help) result = TRUE; } else { char *user = args[0]; + char *altdomain = args[1]; char *lower = g_utf8_strdown(user, -1); status_bar_get_password(); @@ -941,7 +944,7 @@ _cmd_connect(gchar **args, struct cmd_help_t help) log_debug("Connecting as %s", lower); - conn_status = jabber_connect(lower, passwd); + conn_status = jabber_connect(lower, passwd, altdomain); if (conn_status == JABBER_CONNECTING) { cons_show("Connecting..."); log_debug("Connecting..."); diff --git a/src/jabber.c b/src/jabber.c index 93234f8a..d414232a 100644 --- a/src/jabber.c +++ b/src/jabber.c @@ -49,6 +49,7 @@ static struct _jabber_conn_t { // for auto reconnect static char *saved_user; static char *saved_password; +static char *saved_altdomain; static GTimer *reconnect_timer; static GHashTable *sub_requests; @@ -103,7 +104,7 @@ jabber_restart(void) jabber_conn_status_t jabber_connect(const char * const user, - const char * const passwd) + const char * const passwd, const char * const altdomain) { if (saved_user == NULL) { saved_user = strdup(user); @@ -111,6 +112,11 @@ jabber_connect(const char * const user, if (saved_password == NULL) { saved_password = strdup(passwd); } + if (saved_altdomain == NULL) { + if (altdomain != NULL) { + saved_altdomain = strdup(altdomain); + } + } log_info("Connecting as %s", saved_user); xmpp_initialize(); @@ -125,7 +131,7 @@ jabber_connect(const char * const user, if (jabber_conn.tls_disabled) xmpp_conn_disable_tls(jabber_conn.conn); - int connect_status = xmpp_connect_client(jabber_conn.conn, NULL, 0, + int connect_status = xmpp_connect_client(jabber_conn.conn, altdomain, 0, _connection_handler, jabber_conn.ctx); if (connect_status == 0) @@ -167,7 +173,7 @@ jabber_process_events(void) (reconnect_timer != NULL)) { if (g_timer_elapsed(reconnect_timer, NULL) > (prefs_get_reconnect() * 1.0)) { log_debug("Attempting reconnect as %s", saved_user); - jabber_connect(saved_user, saved_password); + jabber_connect(saved_user, saved_password, saved_altdomain); } } } diff --git a/src/jabber.h b/src/jabber.h index aad6a61d..31a1c20e 100644 --- a/src/jabber.h +++ b/src/jabber.h @@ -48,7 +48,7 @@ typedef enum { void jabber_init(const int disable_tls); jabber_conn_status_t jabber_connect(const char * const user, - const char * const passwd); + const char * const passwd, const char * const altdomain); void jabber_disconnect(void); void jabber_process_events(void); void jabber_join(const char * const room, const char * const nick);