about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2014-01-13 20:38:19 +0000
committerJames Booth <boothj5@gmail.com>2014-01-13 20:38:19 +0000
commitecf323de317ffb541e03eab445e611058d4e67e9 (patch)
treea2e96c49004b983d321ad242daae8f5277934477 /src
parent60820007ee6b5a1bc634904d35f9f10292a04195 (diff)
downloadprofani-tty-ecf323de317ffb541e03eab445e611058d4e67e9.tar.gz
Implemented chat logging options for OTR messages
on - Log OTR messages as plaintext
off - Do not log OTR messages
redact - Log, but replace the text with '[redacted]'

Defaults to redact
Diffstat (limited to 'src')
-rw-r--r--src/command/command.c6
-rw-r--r--src/command/commands.c6
-rw-r--r--src/otr.c6
-rw-r--r--src/otr.h3
-rw-r--r--src/server_events.c13
5 files changed, 27 insertions, 7 deletions
diff --git a/src/command/command.c b/src/command/command.c
index e582e2e7..d0d32fe7 100644
--- a/src/command/command.c
+++ b/src/command/command.c
@@ -1176,7 +1176,11 @@ cmd_execute_default(const char * const inp)
                         if (prefs_get_boolean(PREF_CHLOG)) {
                             const char *jid = jabber_get_fulljid();
                             Jid *jidp = jid_create(jid);
-                            chat_log_chat(jidp->barejid, recipient, inp, PROF_OUT_LOG, NULL);
+                            if (strcmp(prefs_get_string(PREF_OTR_LOG), "on") == 0) {
+                                chat_log_chat(jidp->barejid, recipient, inp, PROF_OUT_LOG, NULL);
+                            } else if (strcmp(prefs_get_string(PREF_OTR_LOG), "redact") == 0) {
+                                chat_log_chat(jidp->barejid, recipient, "[redacted]", PROF_OUT_LOG, NULL);
+                            }
                             jid_destroy(jidp);
                         }
 
diff --git a/src/command/commands.c b/src/command/commands.c
index 51296cd6..6285254c 100644
--- a/src/command/commands.c
+++ b/src/command/commands.c
@@ -929,7 +929,11 @@ cmd_msg(gchar **args, struct cmd_help_t help)
                     if (((win_type == WIN_CHAT) || (win_type == WIN_CONSOLE)) && prefs_get_boolean(PREF_CHLOG)) {
                         const char *jid = jabber_get_fulljid();
                         Jid *jidp = jid_create(jid);
-                        chat_log_chat(jidp->barejid, usr_jid, msg, PROF_OUT_LOG, NULL);
+                        if (strcmp(prefs_get_string(PREF_OTR_LOG), "on") == 0) {
+                            chat_log_chat(jidp->barejid, usr_jid, msg, PROF_OUT_LOG, NULL);
+                        } else if (strcmp(prefs_get_string(PREF_OTR_LOG), "redact") == 0) {
+                            chat_log_chat(jidp->barejid, usr_jid, "[redacted]", PROF_OUT_LOG, NULL);
+                        }
                         jid_destroy(jidp);
                     }
                 } else {
diff --git a/src/otr.c b/src/otr.c
index a5981138..9ef96f8a 100644
--- a/src/otr.c
+++ b/src/otr.c
@@ -429,14 +429,14 @@ otr_encrypt_message(const char * const to, const char * const message)
 }
 
 char *
-otr_decrypt_message(const char * const from, const char * const message)
+otr_decrypt_message(const char * const from, const char * const message, gboolean *was_decrypted)
 {
     char *decrypted = NULL;
     OtrlTLV *tlvs = NULL;
     OtrlTLV *tlv = NULL;
     int result = otrl_message_receiving(user_state, &ops, NULL, jid, "xmpp", from, message, &decrypted, &tlvs, NULL, NULL);
 
-    // internal libotr message, ignore
+    // internal libotr message
     if (result == 1) {
         tlv = otrl_tlv_find(tlvs, OTRL_TLV_DISCONNECTED);
         if (tlv) {
@@ -452,10 +452,12 @@ otr_decrypt_message(const char * const from, const char * const message)
 
     // message was decrypted, return to user
     } else if (decrypted != NULL) {
+        *was_decrypted = TRUE;
         return decrypted;
 
     // normal non OTR message
     } else {
+        *was_decrypted = FALSE;
         return strdup(message);
     }
 }
diff --git a/src/otr.h b/src/otr.h
index ff1ad5a5..404e7e07 100644
--- a/src/otr.h
+++ b/src/otr.h
@@ -42,7 +42,8 @@ char * otr_get_my_fingerprint(void);
 char * otr_get_their_fingerprint(const char * const recipient);
 
 char * otr_encrypt_message(const char * const to, const char * const message);
-char * otr_decrypt_message(const char * const from, const char * const message);
+char * otr_decrypt_message(const char * const from, const char * const message,
+    gboolean *was_decrypted);
 
 void otr_free_message(char *message);
 
diff --git a/src/server_events.c b/src/server_events.c
index 792415be..57e04318 100644
--- a/src/server_events.c
+++ b/src/server_events.c
@@ -176,9 +176,12 @@ void
 handle_incoming_message(char *from, char *message, gboolean priv)
 {
 #ifdef HAVE_LIBOTR
+    gboolean was_decrypted = FALSE;
     char *newmessage;
     if (!priv) {
-        newmessage = otr_decrypt_message(from, message);
+        newmessage = otr_decrypt_message(from, message, &was_decrypted);
+
+        // internal OTR message
         if (newmessage == NULL) {
             return;
         }
@@ -193,7 +196,13 @@ handle_incoming_message(char *from, char *message, gboolean priv)
         Jid *from_jid = jid_create(from);
         const char *jid = jabber_get_fulljid();
         Jid *jidp = jid_create(jid);
-        chat_log_chat(jidp->barejid, from_jid->barejid, newmessage, PROF_IN_LOG, NULL);
+
+        if (!was_decrypted || (strcmp(prefs_get_string(PREF_OTR_LOG), "on") == 0)) {
+            chat_log_chat(jidp->barejid, from_jid->barejid, newmessage, PROF_IN_LOG, NULL);
+        } else if (strcmp(prefs_get_string(PREF_OTR_LOG), "redact") == 0) {
+            chat_log_chat(jidp->barejid, from_jid->barejid, "[redacted]", PROF_IN_LOG, NULL);
+        }
+
         jid_destroy(jidp);
         jid_destroy(from_jid);
     }