changeset 1484:7b36b91a4388

New UI message flag (O) when OTR is used When PGP is used, the flag is still '~'. When OTR is used (and PGP is not), the encryption flag is 'O'.
author Mikael Berthe <mikael@lilotux.net>
date Sun, 20 Apr 2008 14:30:25 +0200
parents e74cc83e7158
children 0121b6f3047c
files mcabber/src/commands.c mcabber/src/hbuf.h mcabber/src/hooks.c mcabber/src/hooks.h mcabber/src/jabglue.c mcabber/src/screen.c
diffstat 6 files changed, 43 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/mcabber/src/commands.c	Sun Apr 20 11:45:01 2008 +0200
+++ b/mcabber/src/commands.c	Sun Apr 20 14:30:25 2008 +0200
@@ -1140,8 +1140,7 @@
 
   // Network part
   jb_send_msg(fjid, msg, (isroom ? ROSTER_TYPE_ROOM : ROSTER_TYPE_USER),
-              subj, NULL, &crypted,
-              type_overwrite);
+              subj, NULL, &crypted, type_overwrite);
 
   if (crypted == -1) {
     scr_LogPrint(LPRINT_LOGNORM, "Encryption error.  Message was not sent.");
--- a/mcabber/src/hbuf.h	Sun Apr 20 11:45:01 2008 +0200
+++ b/mcabber/src/hbuf.h	Sun Apr 20 14:30:25 2008 +0200
@@ -26,7 +26,8 @@
 #define HBB_PREFIX_NONE       (1U<<9)
 #define HBB_PREFIX_SPECIAL    (1U<<10)
 #define HBB_PREFIX_PGPCRYPT   (1U<<11)
-#define HBB_PREFIX_CONT       (1U<<12)
+#define HBB_PREFIX_OTRCRYPT   (1U<<12)
+#define HBB_PREFIX_CONT       (1U<<13)
 
 typedef struct {
   time_t timestamp;
--- a/mcabber/src/hooks.c	Sun Apr 20 11:45:01 2008 +0200
+++ b/mcabber/src/hooks.c	Sun Apr 20 14:30:25 2008 +0200
@@ -70,8 +70,10 @@
   unsigned mucnicklen = 0;
   const char *ename = NULL;
 
-  if (encrypted)
+  if (encrypted == ENCRYPTED_PGP)
     message_flags |= HBB_PREFIX_PGPCRYPT;
+  else if (encrypted == ENCRYPTED_OTR)
+    message_flags |= HBB_PREFIX_OTRCRYPT;
 
   if (type && !strcmp(type, "groupchat")) {
     rtype = ROSTER_TYPE_ROOM;
@@ -250,6 +252,7 @@
                            time_t timestamp, const char *msg, guint encrypted)
 {
   char *wmsg = NULL, *bmsg = NULL, *mmsg = NULL;
+  guint cryptflag = 0;
 
   if (nick) {
     wmsg = bmsg = g_strdup_printf("PRIV#<%s> %s", nick, msg);
@@ -271,7 +274,11 @@
   // Note: the hlog_write should not be called first, because in some
   // cases scr_WriteOutgoingMessage() will load the history and we'd
   // have the message twice...
-  scr_WriteOutgoingMessage(bjid, wmsg, (encrypted ? HBB_PREFIX_PGPCRYPT : 0));
+  if (encrypted == ENCRYPTED_PGP)
+    cryptflag = HBB_PREFIX_PGPCRYPT;
+  else if (encrypted == ENCRYPTED_OTR)
+    cryptflag = HBB_PREFIX_OTRCRYPT;
+  scr_WriteOutgoingMessage(bjid, wmsg, cryptflag);
 
   // We don't log private messages
   if (!nick)
--- a/mcabber/src/hooks.h	Sun Apr 20 11:45:01 2008 +0200
+++ b/mcabber/src/hooks.h	Sun Apr 20 14:30:25 2008 +0200
@@ -4,6 +4,9 @@
 #include <time.h>
 #include "jabglue.h"
 
+// These two defines are used by hk_message_{in,out} arguments
+#define ENCRYPTED_PGP   1
+#define ENCRYPTED_OTR   2
 
 void hk_mainloop(void);
 void hk_message_in(const char *bjid, const char *resname,
--- a/mcabber/src/jabglue.c	Sun Apr 20 11:45:01 2008 +0200
+++ b/mcabber/src/jabglue.c	Sun Apr 20 14:30:25 2008 +0200
@@ -641,9 +641,8 @@
         return;
       }
     }
-    if (otr_msg && encrypted) {
-      *encrypted = 1;
-    }
+    if (otr_msg && encrypted)
+      *encrypted = ENCRYPTED_OTR;
   }
 #endif
 
@@ -693,7 +692,7 @@
     xmlnode_put_attrib(y, "xmlns", NS_ENCRYPTED);
     xmlnode_insert_cdata(y, enc, (unsigned) -1);
     if (encrypted)
-      *encrypted = 1;
+      *encrypted = ENCRYPTED_PGP;
     g_free(enc);
   }
 
@@ -1841,6 +1840,15 @@
       (type && strcmp(type, "chat")) ||
       ((s = settings_opt_get("server")) != NULL && !strcasecmp(bjid, s))) {
     gchar *fullbody = NULL;
+    guint encrypted;
+
+    if (decrypted_pgp)
+      encrypted = ENCRYPTED_PGP;
+    else if (otr_msg)
+      encrypted = ENCRYPTED_OTR;
+    else
+      encrypted = 0;
+
     if (subject) {
       if (body)
         fullbody = g_strdup_printf("[%s]\n%s", subject, body);
@@ -1848,8 +1856,7 @@
         fullbody = g_strdup_printf("[%s]\n", subject);
       body = fullbody;
     }
-    hk_message_in(bjid, rname, timestamp, body, type,
-                  ((decrypted_pgp || otr_msg) ? TRUE : FALSE));
+    hk_message_in(bjid, rname, timestamp, body, type, encrypted);
     g_free(fullbody);
   } else {
     scr_LogPrint(LPRINT_LOGNORM, "Blocked a message from <%s>", bjid);
--- a/mcabber/src/screen.c	Sun Apr 20 11:45:01 2008 +0200
+++ b/mcabber/src/screen.c	Sun Apr 20 14:30:25 2008 +0200
@@ -1019,10 +1019,22 @@
         dir = '>';
       g_snprintf(pref, preflen, "%s#%c# ", date, dir);
     } else if (line->flags & HBB_PREFIX_IN) {
-      char cryptflag = line->flags & HBB_PREFIX_PGPCRYPT ? '~' : '=';
+      char cryptflag;
+      if (line->flags & HBB_PREFIX_PGPCRYPT)
+        cryptflag = '~';
+      else if (line->flags & HBB_PREFIX_OTRCRYPT)
+        cryptflag = 'O';
+      else
+        cryptflag = '=';
       g_snprintf(pref, preflen, "%s<%c= ", date, cryptflag);
     } else if (line->flags & HBB_PREFIX_OUT) {
-      char cryptflag = line->flags & HBB_PREFIX_PGPCRYPT ? '~' : '-';
+      char cryptflag;
+      if (line->flags & HBB_PREFIX_PGPCRYPT)
+        cryptflag = '~';
+      else if (line->flags & HBB_PREFIX_OTRCRYPT)
+        cryptflag = 'O';
+      else
+        cryptflag = '=';
       g_snprintf(pref, preflen, "%s-%c> ", date, cryptflag);
     } else if (line->flags & HBB_PREFIX_SPECIAL) {
       strftime(date, 30, getspectprefix(), localtime(&line->timestamp));
@@ -1990,7 +2002,7 @@
 {
   if (!(prefix &
         ~HBB_PREFIX_NOFLAG & ~HBB_PREFIX_HLIGHT & ~HBB_PREFIX_HLIGHT_OUT &
-        ~HBB_PREFIX_PGPCRYPT))
+        ~HBB_PREFIX_PGPCRYPT & ~HBB_PREFIX_OTRCRYPT))
     prefix |= HBB_PREFIX_IN;
 
   scr_WriteMessage(jidfrom, text, timestamp, prefix, mucnicklen);