about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorPaul Fariello <paul@fariello.eu>2019-06-16 22:55:07 +0200
committerPaul Fariello <paul@fariello.eu>2019-06-20 14:30:37 +0200
commit3bb3cc625d1714fd5e81ef0adba61a5172c3212d (patch)
tree1dea4bfe4da4f67d2ba03a70b9bab3ce455763d6 /src
parenta650ecc67d700ae14a1bd05ca6196533829ba5ce (diff)
downloadprofani-tty-3bb3cc625d1714fd5e81ef0adba61a5172c3212d.tar.gz
Use flags in xmmp/message.c for encryption and trust
Diffstat (limited to 'src')
-rw-r--r--src/config/theme.h3
-rw-r--r--src/event/server_events.c10
-rw-r--r--src/ui/ui.h7
-rw-r--r--src/ui/window.c14
-rw-r--r--src/xmpp/message.c30
-rw-r--r--src/xmpp/message.h5
6 files changed, 44 insertions, 25 deletions
diff --git a/src/config/theme.h b/src/config/theme.h
index 69584b30..f4e575b9 100644
--- a/src/config/theme.h
+++ b/src/config/theme.h
@@ -133,7 +133,8 @@ typedef enum {
     THEME_BLACK,
     THEME_BLACK_BOLD,
     THEME_MAGENTA,
-    THEME_MAGENTA_BOLD
+    THEME_MAGENTA_BOLD,
+    THEME_NO_TRUST,
 } theme_item_t;
 
 void theme_init(const char *const theme_name);
diff --git a/src/event/server_events.c b/src/event/server_events.c
index 0f238c07..9818a762 100644
--- a/src/event/server_events.c
+++ b/src/event/server_events.c
@@ -268,7 +268,7 @@ sv_ev_room_subject(const char *const room, const char *const nick, const char *c
 
 void
 sv_ev_room_history(const char *const room_jid, const char *const nick,
-    GDateTime *timestamp, const char *const message)
+    GDateTime *timestamp, const char *const message, int flags)
 {
     ProfMucWin *mucwin = wins_get_muc(room_jid);
     if (mucwin) {
@@ -290,7 +290,7 @@ sv_ev_room_history(const char *const room_jid, const char *const nick,
 }
 
 void
-sv_ev_room_message(const char *const room_jid, const char *const nick, const char *const message, const char *const id, gboolean omemo)
+sv_ev_room_message(const char *const room_jid, const char *const nick, const char *const message, const char *const id, int flags)
 {
     ProfMucWin *mucwin = wins_get_muc(room_jid);
     if (!mucwin) {
@@ -299,7 +299,7 @@ sv_ev_room_message(const char *const room_jid, const char *const nick, const cha
 
     char *mynick = muc_nick(mucwin->roomjid);
 
-    if (omemo) {
+    if (flags & MSG_ENC_OMEMO) {
         groupchat_log_omemo_msg_in(room_jid, nick, message);
     } else {
         groupchat_log_msg_in(room_jid, nick, message);
@@ -320,8 +320,8 @@ sv_ev_room_message(const char *const room_jid, const char *const nick, const cha
 
     GList *triggers = prefs_message_get_triggers(new_message);
 
-    if (omemo) {
-        mucwin_incoming_msg(mucwin, nick, new_message, id, mentions, triggers, PROF_MSG_OMEMO);
+    if (flags & MSG_ENC_OMEMO) {
+        mucwin_incoming_msg(mucwin, nick, new_message, id, mentions, triggers, flags);
     } else {
         mucwin_incoming_msg(mucwin, nick, new_message, id, mentions, triggers, PROF_MSG_PLAIN);
     }
diff --git a/src/ui/ui.h b/src/ui/ui.h
index b80e5630..51d80b34 100644
--- a/src/ui/ui.h
+++ b/src/ui/ui.h
@@ -53,13 +53,6 @@
 #define NO_COLOUR_FROM  8
 #define NO_COLOUR_DATE  16
 
-typedef enum {
-    PROF_MSG_PLAIN,
-    PROF_MSG_OTR,
-    PROF_MSG_PGP,
-    PROF_MSG_OMEMO
-} prof_enc_t;
-
 // core UI
 void ui_init(void);
 void ui_load_colours(void);
diff --git a/src/ui/window.c b/src/ui/window.c
index 12b6c15b..90508917 100644
--- a/src/ui/window.c
+++ b/src/ui/window.c
@@ -1048,6 +1048,11 @@ win_print_incoming(ProfWin *window, GDateTime *timestamp,
     const char *const from, const char *const message, prof_enc_t enc_mode)
 {
     char enc_char = '-';
+    int flags = NO_ME;
+
+    if (!trusted) {
+        flags != NO_TRUST;
+    }
 
     switch (window->type)
     {
@@ -1063,11 +1068,11 @@ win_print_incoming(ProfWin *window, GDateTime *timestamp,
             } else if (enc_mode == PROF_MSG_OMEMO) {
                 enc_char = prefs_get_omemo_char();
             }
-            _win_printf(window, enc_char, 0, timestamp, NO_ME, THEME_TEXT_THEM, from, "%s", message);
+            _win_printf(window, enc_char, 0, timestamp, flags, THEME_TEXT_THEM, from, "%s", message);
             break;
         }
         case WIN_PRIVATE:
-            _win_printf(window, '-', 0, timestamp, NO_ME, THEME_TEXT_THEM, from, "%s", message);
+            _win_printf(window, '-', 0, timestamp, flags, THEME_TEXT_THEM, from, "%s", message);
             break;
         default:
             assert(FALSE);
@@ -1384,6 +1389,7 @@ _win_print(ProfWin *window, const char show_char, int pad_indent, GDateTime *tim
     //         3rd bit =  0/1 - eol/no eol
     //         4th bit =  0/1 - color from/no color from
     //         5th bit =  0/1 - color date/no date
+    //         6th bit =  0/1 - not trusted/trusted
     gboolean me_message = FALSE;
     int offset = 0;
     int colour = theme_attrs(THEME_ME);
@@ -1462,6 +1468,10 @@ _win_print(ProfWin *window, const char show_char, int pad_indent, GDateTime *tim
         }
     }
 
+    if (flags & NO_TRUST) {
+        colour = theme_attrs(THEME_NO_TRUST);
+    }
+
     if (!me_message) {
         if (receipt && !receipt->received) {
             wbkgdset(window->layout->win, theme_attrs(THEME_RECEIPT_SENT));
diff --git a/src/xmpp/message.c b/src/xmpp/message.c
index bb3733a6..424c59ca 100644
--- a/src/xmpp/message.c
+++ b/src/xmpp/message.c
@@ -696,6 +696,7 @@ static void
 _handle_groupchat(xmpp_stanza_t *const stanza)
 {
     xmpp_ctx_t *ctx = connection_get_ctx();
+    int flags = 0;
     char *message = NULL;
 
     const char *id = xmpp_stanza_get_id(stanza);
@@ -748,11 +749,15 @@ _handle_groupchat(xmpp_stanza_t *const stanza)
     }
 
     // check omemo encryption
-    gboolean omemo = FALSE;
-    gboolean trusted = FALSE;
 #ifdef HAVE_OMEMO
+    gboolean trusted = FALSE;
     message = omemo_receive_message(stanza, &trusted);
-    omemo = message != NULL;
+    if (message != NULL) {
+        flags |= MSG_ENC_OMEMO;
+        if (trusted) {
+            flags |= MSG_TRUSTED;
+        }
+    }
 #endif
 
     if (!message) {
@@ -766,10 +771,10 @@ _handle_groupchat(xmpp_stanza_t *const stanza)
     // determine if the notifications happened whilst offline
     GDateTime *timestamp = stanza_get_delay(stanza);
     if (timestamp) {
-        sv_ev_room_history(jid->barejid, jid->resourcepart, timestamp, message, omemo, trusted);
+        sv_ev_room_history(jid->barejid, jid->resourcepart, timestamp, message, flags);
         g_date_time_unref(timestamp);
     } else {
-        sv_ev_room_message(jid->barejid, jid->resourcepart, message, id, omemo, trusted);
+        sv_ev_room_message(jid->barejid, jid->resourcepart, message, id, flags);
     }
 
     xmpp_free(ctx, message);
@@ -873,6 +878,7 @@ static gboolean
 _handle_carbons(xmpp_stanza_t *const stanza)
 {
     char *message_txt = NULL;
+    int flags = 0;
     xmpp_stanza_t *carbons = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_CARBONS);
     if (!carbons) {
         return FALSE;
@@ -907,11 +913,15 @@ _handle_carbons(xmpp_stanza_t *const stanza)
     }
 
     // check omemo encryption
-    gboolean omemo = FALSE;
-    gboolean trusted = FALSE;
 #ifdef HAVE_OMEMO
+    gboolean trusted = FALSE;
     message_txt = omemo_receive_message(message, &trusted);
-    omemo = message_txt != NULL;
+    if (message_txt != NULL) {
+        flags != MSG_ENC_OMEMO;
+        if (trusted) {
+            flags |= MSG_TRUSTED;
+        }
+    }
 #endif
 
     if (!message_txt) {
@@ -947,11 +957,11 @@ _handle_carbons(xmpp_stanza_t *const stanza)
 
     // if we are the recipient, treat as standard incoming message
     if (g_strcmp0(my_jid->barejid, jid_to->barejid) == 0) {
-        sv_ev_incoming_carbon(jid_from->barejid, jid_from->resourcepart, message_txt, enc_message, omemo, trusted);
+        sv_ev_incoming_carbon(jid_from->barejid, jid_from->resourcepart, message_txt, enc_message, flags);
 
     // else treat as a sent message
     } else {
-        sv_ev_outgoing_carbon(jid_to->barejid, message_txt, enc_message, omemo, trusted);
+        sv_ev_outgoing_carbon(jid_to->barejid, message_txt, enc_message, flags);
     }
 
     xmpp_ctx_t *ctx = connection_get_ctx();
diff --git a/src/xmpp/message.h b/src/xmpp/message.h
index a42644fd..b73406a0 100644
--- a/src/xmpp/message.h
+++ b/src/xmpp/message.h
@@ -35,6 +35,11 @@
 #ifndef XMPP_MESSAGE_H
 #define XMPP_MESSAGE_H
 
+#define PROF_MSG_ENC_OTR     1
+#define PROF_MSG_ENC_PGP     2
+#define PROF_MSG_ENC_OMEMO   4
+#define PROF_MSG_TRUSTED     8
+
 typedef int(*ProfMessageCallback)(xmpp_stanza_t *const stanza, void *const userdata);
 typedef void(*ProfMessageFreeCallback)(void *userdata);