1
0
mirror of https://github.com/profanity-im/profanity.git synced 2025-01-03 14:57:42 -05:00

Use password for chat room invites

This commit is contained in:
James Booth 2015-03-29 03:16:41 +01:00
parent 1917d4c095
commit 71c2be599b
7 changed files with 47 additions and 17 deletions

View File

@ -2118,10 +2118,15 @@ cmd_join(gchar **args, struct cmd_help_t help)
options_destroy(options);
// In the case that a nick wasn't provided by the optional args...
if (nick == NULL) {
if (!nick) {
nick = account->muc_nick;
}
// When no password, check for invite with password
if (!passwd) {
passwd = muc_invite_password(room);
}
if (!muc_active(room)) {
presence_join_room(room, nick, passwd);
muc_join(room, nick, passwd, FALSE);

View File

@ -66,6 +66,7 @@ typedef struct _muc_room_t {
} ChatRoom;
GHashTable *rooms = NULL;
GHashTable *invite_passwords = NULL;
Autocomplete invite_ac;
static void _free_room(ChatRoom *room);
@ -83,6 +84,7 @@ muc_init(void)
{
invite_ac = autocomplete_new();
rooms = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, (GDestroyNotify)_free_room);
invite_passwords = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
}
void
@ -90,19 +92,25 @@ muc_close(void)
{
autocomplete_free(invite_ac);
g_hash_table_destroy(rooms);
g_hash_table_destroy(invite_passwords);
rooms = NULL;
invite_passwords = NULL;
}
void
muc_invites_add(const char * const room)
muc_invites_add(const char * const room, const char * const password)
{
autocomplete_add(invite_ac, room);
if (password) {
g_hash_table_replace(invite_passwords, strdup(room), strdup(password));
}
}
void
muc_invites_remove(const char * const room)
{
autocomplete_remove(invite_ac, room);
g_hash_table_remove(invite_passwords, room);
}
gint
@ -117,6 +125,12 @@ muc_invites(void)
return autocomplete_create_list(invite_ac);
}
char *
muc_invite_password(const char * const room)
{
return g_hash_table_lookup(invite_passwords, room);
}
gboolean
muc_invites_contain(const char * const room)
{
@ -151,6 +165,7 @@ void
muc_invites_clear(void)
{
autocomplete_clear(invite_ac);
g_hash_table_remove_all(invite_passwords);
}
void

View File

@ -116,7 +116,7 @@ GSList * muc_occupants_by_affiliation(const char * const room, muc_affiliation_t
void muc_occupant_nick_change_start(const char * const room, const char * const new_nick, const char * const old_nick);
char* muc_roster_nick_change_complete(const char * const room, const char * const nick);
void muc_invites_add(const char * const room);
void muc_invites_add(const char * const room, const char * const password);
void muc_invites_remove(const char * const room);
gint muc_invites_count(void);
GSList* muc_invites(void);
@ -124,6 +124,7 @@ gboolean muc_invites_contain(const char * const room);
void muc_invites_reset_ac(void);
char* muc_invites_find(const char * const search_str);
void muc_invites_clear(void);
char* muc_invite_password(const char * const room);
void muc_set_subject(const char * const room, const char * const subject);
char* muc_subject(const char * const room);

View File

@ -257,11 +257,11 @@ handle_disco_items(GSList *items, const char *jid)
void
handle_room_invite(jabber_invite_t invite_type,
const char * const invitor, const char * const room,
const char * const reason)
const char * const reason, const char * const password)
{
if (!muc_active(room) && !muc_invites_contain(room)) {
cons_show_room_invite(invitor, room, reason);
muc_invites_add(room);
muc_invites_add(room, password);
}
}

View File

@ -48,7 +48,7 @@ void handle_room_list(GSList *rooms, const char *conference_node);
void handle_disco_items(GSList *items, const char *jid);
void handle_room_invite(jabber_invite_t invite_type,
const char * const invitor, const char * const room,
const char * const reason);
const char * const reason, const char * const password);
void handle_room_broadcast(const char *const room_jid,
const char * const message);
void handle_room_subject(const char * const room, const char * const nick, const char * const subject);

View File

@ -340,11 +340,18 @@ _muc_user_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
reason = xmpp_stanza_get_text(reason_st);
}
handle_room_invite(INVITE_MEDIATED, invitor, room, reason);
char *password = NULL;
xmpp_stanza_t *password_st = xmpp_stanza_get_child_by_name(xns_muc_user, STANZA_NAME_PASSWORD);
password = xmpp_stanza_get_text(password_st);
handle_room_invite(INVITE_MEDIATED, invitor, room, reason, password);
jid_destroy(jidp);
if (reason != NULL) {
if (reason) {
xmpp_free(ctx, reason);
}
if (password) {
xmpp_free(ctx, password);
}
}
return 1;
@ -359,13 +366,14 @@ _conference_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
char *room = NULL;
char *invitor = NULL;
char *reason = NULL;
char *password = NULL;
if (from == NULL) {
log_warning("Message received with no from attribute, ignoring");
return 1;
}
// XEP-0429
// XEP-0249
room = xmpp_stanza_get_attribute(xns_conference, STANZA_ATTR_JID);
if (room == NULL) {
return 1;
@ -378,8 +386,9 @@ _conference_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
invitor = jidp->barejid;
reason = xmpp_stanza_get_attribute(xns_conference, STANZA_ATTR_REASON);
password = xmpp_stanza_get_attribute(xns_conference, STANZA_ATTR_PASSWORD);
handle_room_invite(INVITE_DIRECT, invitor, room, reason);
handle_room_invite(INVITE_DIRECT, invitor, room, reason, password);
jid_destroy(jidp);

View File

@ -19,7 +19,7 @@ void muc_after_test(void **state)
void test_muc_invites_add(void **state)
{
char *room = "room@conf.server";
muc_invites_add(room);
muc_invites_add(room, NULL);
gboolean invite_exists = muc_invites_contain(room);
@ -29,7 +29,7 @@ void test_muc_invites_add(void **state)
void test_muc_remove_invite(void **state)
{
char *room = "room@conf.server";
muc_invites_add(room);
muc_invites_add(room, NULL);
muc_invites_remove(room);
gboolean invite_exists = muc_invites_contain(room);
@ -46,11 +46,11 @@ void test_muc_invites_count_0(void **state)
void test_muc_invites_count_5(void **state)
{
muc_invites_add("room1@conf.server");
muc_invites_add("room2@conf.server");
muc_invites_add("room3@conf.server");
muc_invites_add("room4@conf.server");
muc_invites_add("room5@conf.server");
muc_invites_add("room1@conf.server", NULL);
muc_invites_add("room2@conf.server", NULL);
muc_invites_add("room3@conf.server", NULL);
muc_invites_add("room4@conf.server", NULL);
muc_invites_add("room5@conf.server", NULL);
int invite_count = muc_invites_count();