about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorMichael Vetter <jubalh@iodoru.org>2019-04-17 13:58:45 +0200
committerGitHub <noreply@github.com>2019-04-17 13:58:45 +0200
commit9574127177a8e975add3cef523e85f6e75fe4585 (patch)
treeaf39effa0862736ebe548ae573d34d9aaef65983 /src
parent2eaec58c411f750b7dc8fd18a8608366c4652400 (diff)
parent8c71a74afe7c9fce8e51c17344396ab99676963a (diff)
downloadprofani-tty-9574127177a8e975add3cef523e85f6e75fe4585.tar.gz
Merge pull request #1066 from paulfariello/hotfix/OMEMO-ensure-muc-is-nonanonymous
Ensure MUC is Non-Anonymous before starting OMEMO
Diffstat (limited to 'src')
-rw-r--r--src/command/cmd_funcs.c12
-rw-r--r--src/xmpp/muc.c20
-rw-r--r--src/xmpp/muc.h7
3 files changed, 33 insertions, 6 deletions
diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c
index a212fc86..3bba5cb5 100644
--- a/src/command/cmd_funcs.c
+++ b/src/command/cmd_funcs.c
@@ -8032,14 +8032,14 @@ cmd_omemo_start(ProfWin *window, const char *const command, gchar **args)
             ProfMucWin *mucwin = (ProfMucWin*)window;
             assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
 
-            /* TODO: Check room is configured correctly, no anonymous and access to
-             * full jid */
-            omemo_start_muc_sessions(mucwin->roomjid);
-
-            mucwin->is_omemo = TRUE;
+            if (muc_anonymity_type(mucwin->roomjid) == MUC_ANONYMITY_TYPE_NONANONYMOUS) {
+                omemo_start_muc_sessions(mucwin->roomjid);
+                mucwin->is_omemo = TRUE;
+            } else {
+                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 {
             win_println(window, THEME_DEFAULT, '-', "You must be in a regular chat window to start an OMEMO session.");
-            return TRUE;
         }
 
     }
diff --git a/src/xmpp/muc.c b/src/xmpp/muc.c
index 62a589d7..89e707a1 100644
--- a/src/xmpp/muc.c
+++ b/src/xmpp/muc.c
@@ -64,6 +64,7 @@ typedef struct _muc_room_t {
     GHashTable *nick_changes;
     gboolean roster_received;
     muc_member_type_t member_type;
+    muc_anonymity_type_t anonymity_type;
 } ChatRoom;
 
 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->autojoin = autojoin;
     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);
 }
@@ -264,6 +266,13 @@ muc_set_features(const char *const room, GSList *features)
         } else {
             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
 _free_room(ChatRoom *room)
diff --git a/src/xmpp/muc.h b/src/xmpp/muc.h
index e0b035f2..4b49a954 100644
--- a/src/xmpp/muc.h
+++ b/src/xmpp/muc.h
@@ -63,6 +63,12 @@ typedef enum {
     MUC_MEMBER_TYPE_MEMBERS_ONLY
 } 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 {
     char *nick;
     gchar *nick_collate_key;
@@ -150,5 +156,6 @@ char* muc_role_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_anonymity_type_t muc_anonymity_type(const char *const room);
 
 #endif