1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

Add optional server parameter to /connect command

This commit is contained in:
James Booth 2012-12-06 20:36:16 +00:00
parent c8b650e8be
commit 8304b30b52
3 changed files with 20 additions and 11 deletions

View File

@ -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...");

View File

@ -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);
}
}
}

View File

@ -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);