From 28425060bc5a759dead356e3ef49fc80a8c270d8 Mon Sep 17 00:00:00 2001 From: Kristofer M White Date: Wed, 5 Mar 2014 17:13:42 +0000 Subject: [PATCH] Parsing optional args for cmd_join --- src/command/command.c | 10 +++++----- src/command/commands.c | 39 ++++++++++++++++++++++++++++++++------- 2 files changed, 37 insertions(+), 12 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index d7833433..5a1960ad 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -235,9 +235,9 @@ static struct cmd_t command_defs[] = NULL } } }, { "/join", - cmd_join, parse_args_with_freetext, 1, 3, NULL, - { "/join room[@server] [nick] [password]", "Join a chat room.", - { "/join room[@server] [nick] [password]", + cmd_join, parse_args, 1, 5, NULL, + { "/join room[@server] [nick value] [passwd value]", "Join a chat room.", + { "/join room[@server] [nick value] [passwd value]", "--------------------------", "Join a chat room at the conference server.", "If nick is specified you will join with this nickname.", @@ -246,8 +246,8 @@ static struct cmd_t command_defs[] = "If the room doesn't exist, and the server allows it, a new one will be created.", "", "Example : /join jdev@conference.jabber.org", - "Example : /join jdev@conference.jabber.org mynick", - "Example : /join private@conference.jabber.org mynick mypassword", + "Example : /join jdev@conference.jabber.org nick mynick", + "Example : /join private@conference.jabber.org nick mynick passwd mypassword", "Example : /join jdev (as user@jabber.org will join jdev@conference.jabber.org)", NULL } } }, diff --git a/src/command/commands.c b/src/command/commands.c index 7b6fc0f0..2515a5bd 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -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)) {