1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Ensure MUC is Non-Anonymous before starting OMEMO

Store MUC anonymous type in mucwin for that purpose.

Fixes #1065
This commit is contained in:
Paul Fariello 2019-04-17 11:07:57 +02:00
parent 02d0f7fc38
commit 8c71a74afe
3 changed files with 33 additions and 6 deletions

View File

@ -8031,14 +8031,14 @@ cmd_omemo_start(ProfWin *window, const char *const command, gchar **args)
ProfMucWin *mucwin = (ProfMucWin*)window; ProfMucWin *mucwin = (ProfMucWin*)window;
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK); assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
/* TODO: Check room is configured correctly, no anonymous and access to if (muc_anonymity_type(mucwin->roomjid) == MUC_ANONYMITY_TYPE_NONANONYMOUS) {
* full jid */ omemo_start_muc_sessions(mucwin->roomjid);
omemo_start_muc_sessions(mucwin->roomjid); mucwin->is_omemo = TRUE;
} else {
mucwin->is_omemo = TRUE; win_println(window, THEME_DEFAULT, '!', "MUC must be non-anonymous (i.e. be configured to present real jid to anyone) in order to support OMEMO.");
}
} else { } else {
win_println(window, THEME_DEFAULT, '-', "You must be in a regular chat window to start an OMEMO session."); win_println(window, THEME_DEFAULT, '-', "You must be in a regular chat window to start an OMEMO session.");
return TRUE;
} }
} }

View File

@ -64,6 +64,7 @@ typedef struct _muc_room_t {
GHashTable *nick_changes; GHashTable *nick_changes;
gboolean roster_received; gboolean roster_received;
muc_member_type_t member_type; muc_member_type_t member_type;
muc_anonymity_type_t anonymity_type;
} ChatRoom; } ChatRoom;
GHashTable *rooms = NULL; GHashTable *rooms = NULL;
@ -223,6 +224,7 @@ muc_join(const char *const room, const char *const nick, const char *const passw
new_room->pending_nick_change = FALSE; new_room->pending_nick_change = FALSE;
new_room->autojoin = autojoin; new_room->autojoin = autojoin;
new_room->member_type = MUC_MEMBER_TYPE_UNKNOWN; new_room->member_type = MUC_MEMBER_TYPE_UNKNOWN;
new_room->anonymity_type = MUC_ANONYMITY_TYPE_UNKNOWN;
g_hash_table_insert(rooms, strdup(room), new_room); g_hash_table_insert(rooms, strdup(room), new_room);
} }
@ -264,6 +266,13 @@ muc_set_features(const char *const room, GSList *features)
} else { } else {
chat_room->member_type = MUC_MEMBER_TYPE_PUBLIC; chat_room->member_type = MUC_MEMBER_TYPE_PUBLIC;
} }
if (g_slist_find_custom(features, "muc_nonanonymous", (GCompareFunc)g_strcmp0)) {
chat_room->anonymity_type = MUC_ANONYMITY_TYPE_NONANONYMOUS;
} else if (g_slist_find_custom(features, "muc_semianonymous", (GCompareFunc)g_strcmp0)) {
chat_room->anonymity_type = MUC_ANONYMITY_TYPE_SEMIANONYMOUS;
} else {
chat_room->anonymity_type = MUC_ANONYMITY_TYPE_UNKNOWN;
}
} }
} }
@ -835,6 +844,17 @@ muc_member_type(const char *const room)
} }
} }
muc_anonymity_type_t
muc_anonymity_type(const char *const room)
{
ChatRoom *chat_room = g_hash_table_lookup(rooms, room);
if (chat_room) {
return chat_room->anonymity_type;
} else {
return MUC_ANONYMITY_TYPE_UNKNOWN;
}
}
static void static void
_free_room(ChatRoom *room) _free_room(ChatRoom *room)

View File

@ -63,6 +63,12 @@ typedef enum {
MUC_MEMBER_TYPE_MEMBERS_ONLY MUC_MEMBER_TYPE_MEMBERS_ONLY
} muc_member_type_t; } muc_member_type_t;
typedef enum {
MUC_ANONYMITY_TYPE_UNKNOWN,
MUC_ANONYMITY_TYPE_NONANONYMOUS,
MUC_ANONYMITY_TYPE_SEMIANONYMOUS
} muc_anonymity_type_t;
typedef struct _muc_occupant_t { typedef struct _muc_occupant_t {
char *nick; char *nick;
gchar *nick_collate_key; gchar *nick_collate_key;
@ -150,5 +156,6 @@ char* muc_role_str(const char *const room);
char* muc_affiliation_str(const char *const room); char* muc_affiliation_str(const char *const room);
muc_member_type_t muc_member_type(const char *const room); muc_member_type_t muc_member_type(const char *const room);
muc_anonymity_type_t muc_anonymity_type(const char *const room);
#endif #endif