Parsing optional args for cmd_join

This commit is contained in:
Kristofer M White
2014-03-05 17:13:42 +00:00
parent ced6e7f411
commit 28425060bc
2 changed files with 37 additions and 12 deletions

View File

@@ -1610,20 +1610,45 @@ cmd_join(gchar **args, struct cmd_help_t help)
room = room_str->str;
}
// nick supplied
// Additional args supplied
if (num_args > 1) {
char *opt1 = args[1];
char *opt1val = args[2];
char *opt2 = args[3];
char *opt2val = args[4];
if (opt1 != NULL) {
if (opt1val == NULL) {
cons_show("Usage: %s", help.usage);
cons_show("");
return TRUE;
}
if (strcmp(opt1, "nick") == 0) {
nick = strdup(opt1val);
} else if (strcmp(opt1, "passwd") == 0) {
passwd = strdup(opt1val);
} else {
cons_show("Usage: %s", help.usage);
cons_show("");
return TRUE;
}
if (opt2 != NULL) {
if (strcmp(opt2, "nick") == 0) {
nick = strdup(opt2val);
} else if (strcmp(opt2, "passwd") == 0) {
passwd = strdup(opt2val);
} else {
cons_show("Usage: %s", help.usage);
cons_show("");
return TRUE;
}
}
}
nick = args[1];
// otherwise use account preference
} else {
nick = account->muc_nick;
}
// pass supplied
if (num_args == 3) {
passwd = args[2];
}
Jid *room_jid = jid_create_from_bare_and_resource(room, nick);
if (!muc_room_is_active(room_jid)) {