1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-09-29 19:56:07 -04:00

Merge remote-tracking branch 'kmwhite/adding_support_for_private_confs'

This commit is contained in:
James Booth 2014-03-05 20:29:41 +00:00
commit 65432c8d64
7 changed files with 62 additions and 16 deletions

View File

@ -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, 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,7 +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 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 } } },

View File

@ -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());
@ -1609,19 +1610,50 @@ cmd_join(gchar **args, struct cmd_help_t help)
room = room_str->str;
}
// nick supplied
if (num_args == 2) {
nick = args[1];
// 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 = opt1val;
} else if (strcmp(opt1, "passwd") == 0) {
passwd = opt1val;
} else {
cons_show("Usage: %s", help.usage);
cons_show("");
return TRUE;
}
if (opt2 != NULL) {
if (strcmp(opt2, "nick") == 0) {
nick = opt2val;
} else if (strcmp(opt2, "passwd") == 0) {
passwd = opt2val;
} else {
cons_show("Usage: %s", help.usage);
cons_show("");
return TRUE;
}
}
}
}
// 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;
}
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);

View File

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

View File

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

View File

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

View File

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

View File

@ -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,