From 79d55a4668e7ae703ee551ad9a14109e084f872d Mon Sep 17 00:00:00 2001 From: Kristofer M White Date: Tue, 25 Feb 2014 18:45:45 +0000 Subject: Updating cmd description --- src/command/command.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/command') diff --git a/src/command/command.c b/src/command/command.c index d8f55205..d7833433 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, 2, NULL, - { "/join room[@server] [nick]", "Join a chat room.", - { "/join room[@server] [nick]", + cmd_join, parse_args_with_freetext, 1, 3, NULL, + { "/join room[@server] [nick] [password]", "Join a chat room.", + { "/join room[@server] [nick] [password]", "--------------------------", "Join a chat room at the conference server.", "If nick is specified you will join with this nickname.", @@ -247,6 +247,7 @@ static struct cmd_t command_defs[] = "", "Example : /join jdev@conference.jabber.org", "Example : /join jdev@conference.jabber.org mynick", + "Example : /join private@conference.jabber.org mynick mypassword", "Example : /join jdev (as user@jabber.org will join jdev@conference.jabber.org)", NULL } } }, -- cgit 1.4.1-2-gfad0 From 8a54c5895dc4c989322611f2bdddf6b593b917d4 Mon Sep 17 00:00:00 2001 From: Kristofer M White Date: Thu, 27 Feb 2014 05:31:10 +0000 Subject: Adding password handling for joining chatrooms --- src/command/commands.c | 10 ++++++++-- src/xmpp/bookmark.c | 2 +- src/xmpp/presence.c | 4 ++-- src/xmpp/stanza.c | 15 ++++++++++++++- src/xmpp/stanza.h | 2 +- src/xmpp/xmpp.h | 2 +- 6 files changed, 27 insertions(+), 8 deletions(-) (limited to 'src/command') diff --git a/src/command/commands.c b/src/command/commands.c index da360da8..7b6fc0f0 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -1594,6 +1594,7 @@ cmd_join(gchar **args, struct cmd_help_t help) int num_args = g_strv_length(args); char *room = NULL; char *nick = NULL; + char *passwd = NULL; GString *room_str = g_string_new(""); Jid *my_jid = jid_create(jabber_get_fulljid()); @@ -1610,7 +1611,7 @@ cmd_join(gchar **args, struct cmd_help_t help) } // nick supplied - if (num_args == 2) { + if (num_args > 1) { nick = args[1]; // otherwise use account preference @@ -1618,10 +1619,15 @@ cmd_join(gchar **args, struct cmd_help_t help) 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)) { - presence_join_room(room_jid); + presence_join_room(room_jid, passwd); } ui_room_join(room_jid); muc_remove_invite(room); diff --git a/src/xmpp/bookmark.c b/src/xmpp/bookmark.c index 1bc102a3..27a768be 100644 --- a/src/xmpp/bookmark.c +++ b/src/xmpp/bookmark.c @@ -301,7 +301,7 @@ _bookmark_handle_result(xmpp_conn_t * const conn, log_debug("Autojoin %s with nick=%s", jid, name); room_jid = jid_create_from_bare_and_resource(jid, name); if (!muc_room_is_active(room_jid)) { - presence_join_room(room_jid); + presence_join_room(room_jid, NULL); /* TODO: this should be removed after fixing #195 */ ui_room_join(room_jid); } diff --git a/src/xmpp/presence.c b/src/xmpp/presence.c index ae392ad9..3098e6e4 100644 --- a/src/xmpp/presence.c +++ b/src/xmpp/presence.c @@ -260,7 +260,7 @@ _send_room_presence(xmpp_conn_t *conn, xmpp_stanza_t *presence) } static void -_presence_join_room(Jid *jid) +_presence_join_room(Jid *jid, char * passwd) { assert(jid != NULL); assert(jid->fulljid != NULL); @@ -275,7 +275,7 @@ _presence_join_room(Jid *jid) int pri = accounts_get_priority_for_presence_type(jabber_get_account_name(), presence_type); - xmpp_stanza_t *presence = stanza_create_room_join_presence(ctx, jid->fulljid); + xmpp_stanza_t *presence = stanza_create_room_join_presence(ctx, jid->fulljid, passwd); stanza_attach_show(ctx, presence, show); stanza_attach_status(ctx, presence, status); stanza_attach_priority(ctx, presence, pri); diff --git a/src/xmpp/stanza.c b/src/xmpp/stanza.c index c37ab124..b89b164b 100644 --- a/src/xmpp/stanza.c +++ b/src/xmpp/stanza.c @@ -249,7 +249,7 @@ stanza_create_invite(xmpp_ctx_t *ctx, const char * const room, xmpp_stanza_t * stanza_create_room_join_presence(xmpp_ctx_t * const ctx, - const char * const full_room_jid) + const char * const full_room_jid, const char * const passwd) { xmpp_stanza_t *presence = xmpp_stanza_new(ctx); xmpp_stanza_set_name(presence, STANZA_NAME_PRESENCE); @@ -260,6 +260,19 @@ stanza_create_room_join_presence(xmpp_ctx_t * const ctx, xmpp_stanza_t *x = xmpp_stanza_new(ctx); xmpp_stanza_set_name(x, STANZA_NAME_X); xmpp_stanza_set_ns(x, STANZA_NS_MUC); + + // if a password was given + if (passwd != NULL) { + xmpp_stanza_t *pass = xmpp_stanza_new(ctx); + xmpp_stanza_set_name(pass, "password"); + xmpp_stanza_t *text = xmpp_stanza_new(ctx); + xmpp_stanza_set_text(text, strdup(passwd)); + xmpp_stanza_add_child(pass, text); + xmpp_stanza_add_child(x, pass); + xmpp_stanza_release(text); + xmpp_stanza_release(pass); + } + xmpp_stanza_add_child(presence, x); xmpp_stanza_release(x); diff --git a/src/xmpp/stanza.h b/src/xmpp/stanza.h index 471a9f76..28f12a32 100644 --- a/src/xmpp/stanza.h +++ b/src/xmpp/stanza.h @@ -158,7 +158,7 @@ xmpp_stanza_t* stanza_create_message(xmpp_ctx_t *ctx, const char * const message, const char * const state); xmpp_stanza_t* stanza_create_room_join_presence(xmpp_ctx_t * const ctx, - const char * const full_room_jid); + const char * const full_room_jid, const char * const passwd); xmpp_stanza_t* stanza_create_room_newnick_presence(xmpp_ctx_t *ctx, const char * const full_room_jid); diff --git a/src/xmpp/xmpp.h b/src/xmpp/xmpp.h index fdbcb500..3ef9c93c 100644 --- a/src/xmpp/xmpp.h +++ b/src/xmpp/xmpp.h @@ -114,7 +114,7 @@ GSList* (*presence_get_subscription_requests)(void); gint (*presence_sub_request_count)(void); void (*presence_reset_sub_request_search)(void); char * (*presence_sub_request_find)(char * search_str); -void (*presence_join_room)(Jid *jid); +void (*presence_join_room)(Jid *jid, char * passwd); void (*presence_change_room_nick)(const char * const room, const char * const nick); void (*presence_leave_chat_room)(const char * const room_jid); void (*presence_update)(resource_presence_t status, const char * const msg, -- cgit 1.4.1-2-gfad0 From 28425060bc5a759dead356e3ef49fc80a8c270d8 Mon Sep 17 00:00:00 2001 From: Kristofer M White Date: Wed, 5 Mar 2014 17:13:42 +0000 Subject: Parsing optional args for cmd_join --- src/command/command.c | 10 +++++----- src/command/commands.c | 39 ++++++++++++++++++++++++++++++++------- 2 files changed, 37 insertions(+), 12 deletions(-) (limited to 'src/command') 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)) { -- cgit 1.4.1-2-gfad0 From a4e28097560676f22fa7fdd8769faf93b3c15189 Mon Sep 17 00:00:00 2001 From: Kristofer M White Date: Wed, 5 Mar 2014 17:25:26 +0000 Subject: Removing strdup calls per cmd_connect design --- src/command/commands.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/command') diff --git a/src/command/commands.c b/src/command/commands.c index 2515a5bd..ee065bcf 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -1623,9 +1623,9 @@ cmd_join(gchar **args, struct cmd_help_t help) return TRUE; } if (strcmp(opt1, "nick") == 0) { - nick = strdup(opt1val); + nick = opt1val; } else if (strcmp(opt1, "passwd") == 0) { - passwd = strdup(opt1val); + passwd = opt1val; } else { cons_show("Usage: %s", help.usage); cons_show(""); @@ -1633,9 +1633,9 @@ cmd_join(gchar **args, struct cmd_help_t help) } if (opt2 != NULL) { if (strcmp(opt2, "nick") == 0) { - nick = strdup(opt2val); + nick = opt2val; } else if (strcmp(opt2, "passwd") == 0) { - passwd = strdup(opt2val); + passwd = opt2val; } else { cons_show("Usage: %s", help.usage); cons_show(""); -- cgit 1.4.1-2-gfad0 From 3f18d933ca91b346bf1f10effcb42f47992468dd Mon Sep 17 00:00:00 2001 From: Kristofer M White Date: Wed, 5 Mar 2014 17:39:44 +0000 Subject: Removing extra `nick = ` line that broke nick assignment --- src/command/commands.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/command') diff --git a/src/command/commands.c b/src/command/commands.c index ee065bcf..d6e33a29 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -1643,7 +1643,7 @@ cmd_join(gchar **args, struct cmd_help_t help) } } } - nick = args[1]; + // otherwise use account preference } else { nick = account->muc_nick; -- cgit 1.4.1-2-gfad0 From 7c6755b62cf35deac7a98e30d91765fad3ca2d7f Mon Sep 17 00:00:00 2001 From: Kristofer M White Date: Wed, 5 Mar 2014 19:55:02 +0000 Subject: Ensuring nick is set when not included in opt args for cmd_join --- src/command/commands.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/command') diff --git a/src/command/commands.c b/src/command/commands.c index d6e33a29..9f4882fa 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -1643,9 +1643,10 @@ cmd_join(gchar **args, struct cmd_help_t help) } } } + } - // otherwise use account preference - } else { + // In the case that a nick wasn't provided by the optional args... + if (nick == NULL) { nick = account->muc_nick; } -- cgit 1.4.1-2-gfad0