WIP - Adding port to account options

This commit is contained in:
James Booth
2014-01-18 01:45:05 +00:00
parent b1de8a4005
commit e7013408e5
6 changed files with 102 additions and 15 deletions

View File

@@ -99,7 +99,7 @@ static struct cmd_t command_defs[] =
NULL } } },
{ "/connect",
cmd_connect, parse_args, 1, 2, NULL,
cmd_connect, parse_args, 1, 5, NULL,
{ "/connect account [server]", "Login to a chat service.",
{ "/connect account [server]",
"-------------------------",

View File

@@ -69,10 +69,72 @@ cmd_connect(gchar **args, struct cmd_help_t help)
result = TRUE;
} else {
char *user = args[0];
char *altdomain = args[1];
char *opt1 = args[1];
char *opt1val = args[2];
char *opt2 = args[3];
char *opt2val = args[4];
char *lower = g_utf8_strdown(user, -1);
char *jid;
// parse options
char *altdomain = NULL;
int port = 0;
gboolean altdomain_set = FALSE;
gboolean port_set = FALSE;
if (opt1 != NULL) {
if (opt1val == NULL) {
cons_show("Usage: %s", help.usage);
cons_show("");
return TRUE;
}
if (strcmp(opt1, "server") == 0) {
altdomain = opt1val;
altdomain_set = TRUE;
} else if (strcmp(opt1, "port") == 0) {
if (_strtoi(opt1val, &port, 1, 65536) != 0) {
port = 0;
cons_show("Port must be in the range 1 to 65535.");
} else {
port_set = TRUE;
}
} else {
cons_show("Usage: %s", help.usage);
cons_show("");
return TRUE;
}
if (opt2 != NULL) {
if (opt2val == NULL) {
cons_show("Usage: %s", help.usage);
cons_show("");
return TRUE;
}
if (strcmp(opt2, "server") == 0) {
if (altdomain_set) {
cons_show("Usage: %s", help.usage);
return TRUE;
}
altdomain = opt2val;
altdomain_set = TRUE;
} else if (strcmp(opt2, "port") == 0) {
if (port_set) {
cons_show("Usage: %s", help.usage);
return TRUE;
}
if (_strtoi(opt2val, &port, 1, 65536) != 0) {
port = 0;
cons_show("Port must be in the range 1 to 65535.");
} else {
port_set = TRUE;
}
} else {
cons_show("Usage: %s", help.usage);
cons_show("");
return TRUE;
}
}
}
ProfAccount *account = accounts_get_account(lower);
if (account != NULL) {
jid = accounts_create_full_jid(account);
@@ -86,7 +148,7 @@ cmd_connect(gchar **args, struct cmd_help_t help)
char *passwd = ui_ask_password();
jid = strdup(lower);
cons_show("Connecting as %s", jid);
conn_status = jabber_connect_with_details(jid, passwd, altdomain);
conn_status = jabber_connect_with_details(jid, passwd, altdomain, port);
free(passwd);
}
g_free(lower);
@@ -140,7 +202,7 @@ cmd_account(gchar **args, struct cmd_help_t help)
if (account_name == NULL) {
cons_show("Usage: %s", help.usage);
} else {
accounts_add(account_name, NULL);
accounts_add(account_name, NULL, 0);
cons_show("Account created.");
cons_show("");
}