about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2015-06-21 21:42:58 +0100
committerJames Booth <boothj5@gmail.com>2015-06-21 21:42:58 +0100
commit3d2f999efb9995e003f0d18dba059357721b272a (patch)
tree6ee40c60c550eead99a51de119c5d9e8f579b6b4
parent446027b9505342c09f62f6d7a279c65a0d1db107 (diff)
downloadprofani-tty-3d2f999efb9995e003f0d18dba059357721b272a.tar.gz
Added PGP logging preferences
-rw-r--r--src/command/command.c35
-rw-r--r--src/command/commands.c23
-rw-r--r--src/config/preferences.c11
-rw-r--r--src/config/preferences.h1
-rw-r--r--src/event/client_events.c6
-rw-r--r--src/event/server_events.c6
-rw-r--r--src/log.c34
-rw-r--r--src/log.h2
-rw-r--r--tests/unittests/log/stub_log.c2
9 files changed, 100 insertions, 20 deletions
diff --git a/src/command/command.c b/src/command/command.c
index 05ca9737..ac8b1deb 100644
--- a/src/command/command.c
+++ b/src/command/command.c
@@ -869,15 +869,18 @@ static struct cmd_t command_defs[] =
           NULL } } },
 
     { "/pgp",
-        cmd_pgp, parse_args, 1, 3, NULL,
-        { "/pgp keys|libver|fps|start [contact]", "Open PGP.",
-        { "/pgp keys|libver|fps|start [contact]",
-          "------------------------------------",
-          "Open PGP.",
-          "keys            : List private keys."
-          "libver          : Show which version of the libgpgme library is being used.",
-          "fps             : Show received fingerprints.",
-          "start [contact] : Start PGP encrypted chat, current contact will be used if not specified.",
+        cmd_pgp, parse_args, 1, 2, NULL,
+        { "/pgp command [args..]", "Open PGP commands.",
+        { "/pgp command [args..]",
+          "---------------------",
+          "Open PGP commands.",
+          "",
+          "keys              : List private keys."
+          "libver            : Show which version of the libgpgme library is being used.",
+          "fps               : Show received fingerprints.",
+          "start [contact]   : Start PGP encrypted chat, current contact will be used if not specified.",
+          "end               : End PGP encrypted chat with the current recipient.",
+          "log on|off|redact : OTR message logging, default: redact.",
           NULL } } },
 
     { "/otr",
@@ -1236,6 +1239,7 @@ static Autocomplete resource_ac;
 static Autocomplete inpblock_ac;
 static Autocomplete receipts_ac;
 static Autocomplete pgp_ac;
+static Autocomplete pgp_log_ac;
 
 /*
  * Initialise command autocompleter and history
@@ -1609,6 +1613,12 @@ cmd_init(void)
     autocomplete_add(pgp_ac, "libver");
     autocomplete_add(pgp_ac, "start");
     autocomplete_add(pgp_ac, "end");
+    autocomplete_add(pgp_ac, "log");
+
+    pgp_log_ac = autocomplete_new();
+    autocomplete_add(pgp_log_ac, "on");
+    autocomplete_add(pgp_log_ac, "off");
+    autocomplete_add(pgp_log_ac, "redact");
 }
 
 void
@@ -1669,6 +1679,7 @@ cmd_uninit(void)
     autocomplete_free(inpblock_ac);
     autocomplete_free(receipts_ac);
     autocomplete_free(pgp_ac);
+    autocomplete_free(pgp_log_ac);
 }
 
 gboolean
@@ -1842,6 +1853,7 @@ cmd_reset_autocomplete(ProfWin *window)
     autocomplete_reset(inpblock_ac);
     autocomplete_reset(receipts_ac);
     autocomplete_reset(pgp_ac);
+    autocomplete_reset(pgp_log_ac);
 
     if (window->type == WIN_CHAT) {
         ProfChatWin *chatwin = (ProfChatWin*)window;
@@ -2485,6 +2497,11 @@ _pgp_autocomplete(ProfWin *window, const char * const input)
         return found;
     }
 
+    found = autocomplete_param_with_ac(input, "/pgp log", pgp_log_ac, TRUE);
+    if (found) {
+        return found;
+    }
+
     found = autocomplete_param_with_ac(input, "/pgp", pgp_ac, TRUE);
     if (found) {
         return found;
diff --git a/src/command/commands.c b/src/command/commands.c
index 03a3f9f6..38f15a74 100644
--- a/src/command/commands.c
+++ b/src/command/commands.c
@@ -4145,6 +4145,29 @@ cmd_pgp(ProfWin *window, gchar **args, struct cmd_help_t help)
         return TRUE;
     }
 
+    if (g_strcmp0(args[0], "log") == 0) {
+        char *choice = args[1];
+        if (g_strcmp0(choice, "on") == 0) {
+            prefs_set_string(PREF_PGP_LOG, "on");
+            cons_show("PGP messages will be logged as plaintext.");
+            if (!prefs_get_boolean(PREF_CHLOG)) {
+                cons_show("Chat logging is currently disabled, use '/chlog on' to enable.");
+            }
+        } else if (g_strcmp0(choice, "off") == 0) {
+            prefs_set_string(PREF_PGP_LOG, "off");
+            cons_show("PGP message logging disabled.");
+        } else if (g_strcmp0(choice, "redact") == 0) {
+            prefs_set_string(PREF_PGP_LOG, "redact");
+            cons_show("PGP messages will be logged as '[redacted]'.");
+            if (!prefs_get_boolean(PREF_CHLOG)) {
+                cons_show("Chat logging is currently disabled, use '/chlog on' to enable.");
+            }
+        } else {
+            cons_show("Usage: %s", help.usage);
+        }
+        return TRUE;
+    }
+
     if (g_strcmp0(args[0], "keys") == 0) {
         GSList *keys = p_gpg_list_keys();
         if (!keys) {
diff --git a/src/config/preferences.c b/src/config/preferences.c
index 64fb13bd..fef0db0b 100644
--- a/src/config/preferences.c
+++ b/src/config/preferences.c
@@ -55,6 +55,7 @@
 #define PREF_GROUP_CONNECTION "connection"
 #define PREF_GROUP_ALIAS "alias"
 #define PREF_GROUP_OTR "otr"
+#define PREF_GROUP_PGP "pgp"
 
 #define INPBLOCK_DEFAULT 1000
 
@@ -75,8 +76,6 @@ void
 prefs_load(void)
 {
     GError *err;
-
-//    log_info("Loading preferences");
     prefs_loc = _get_preferences_file();
 
     if (g_file_test(prefs_loc, G_FILE_TEST_EXISTS)) {
@@ -94,7 +93,7 @@ prefs_load(void)
         g_error_free(err);
     }
 
-    // move pre 0.4.7 enc.warn to enc.warn
+    // move pre 0.4.7 otr.warn to enc.warn
     err = NULL;
     gboolean otr_warn = g_key_file_get_boolean(prefs, PREF_GROUP_UI, "otr.warn", &err);
     if (err == NULL) {
@@ -535,6 +534,8 @@ _get_group(preference_t pref)
         case PREF_OTR_LOG:
         case PREF_OTR_POLICY:
             return PREF_GROUP_OTR;
+        case PREF_PGP_LOG:
+            return PREF_GROUP_PGP;
         default:
             return NULL;
     }
@@ -659,6 +660,8 @@ _get_key(preference_t pref)
             return "inpblock.dynamic";
         case PREF_ENC_WARN:
             return "enc.warn";
+        case PREF_PGP_LOG:
+            return "log";
         default:
             return NULL;
     }
@@ -725,6 +728,8 @@ _get_default_string(preference_t pref)
             return "seconds";
         case PREF_TIME_STATUSBAR:
             return "minutes";
+        case PREF_PGP_LOG:
+            return "redact";
         default:
             return NULL;
     }
diff --git a/src/config/preferences.h b/src/config/preferences.h
index 16a4d4e0..9e8d2898 100644
--- a/src/config/preferences.h
+++ b/src/config/preferences.h
@@ -103,6 +103,7 @@ typedef enum {
     PREF_RESOURCE_MESSAGE,
     PREF_INPBLOCK_DYNAMIC,
     PREF_ENC_WARN,
+    PREF_PGP_LOG
 } preference_t;
 
 typedef struct prof_alias_t {
diff --git a/src/event/client_events.c b/src/event/client_events.c
index 016f8b24..1ddb3d22 100644
--- a/src/event/client_events.c
+++ b/src/event/client_events.c
@@ -101,8 +101,7 @@ cl_ev_send_msg(ProfChatWin *chatwin, const char * const msg)
         }
     } else { // enc_mode = PROF_ENC_PGP
         char *id = message_send_chat_pgp(chatwin->barejid, msg);
-        // TODO pgp message logger
-        chat_log_msg_out(chatwin->barejid, msg);
+        chat_log_pgp_msg_out(chatwin->barejid, msg);
         ui_outgoing_chat_msg(chatwin, msg, id);
         free(id);
     }
@@ -135,8 +134,7 @@ cl_ev_send_msg(ProfChatWin *chatwin, const char * const msg)
         free(id);
     } else if (enc_mode == PROF_ENC_PGP) {
         char *id = message_send_chat_pgp(chatwin->barejid, msg);
-        // TODO pgp message logger
-        chat_log_msg_out(chatwin->barejid, msg);
+        chat_log_pgp_msg_out(chatwin->barejid, msg);
         ui_outgoing_chat_msg(chatwin, msg, id);
         free(id);
     }
diff --git a/src/event/server_events.c b/src/event/server_events.c
index 824a12cb..004e743b 100644
--- a/src/event/server_events.c
+++ b/src/event/server_events.c
@@ -209,8 +209,7 @@ sv_ev_incoming_message(char *barejid, char *resource, char *message, char *enc_m
                     win_println((ProfWin*)chatwin, "PGP encryption enabled.");
                 }
                 ui_incoming_msg(chatwin, resource, decrypted, NULL, new_win);
-                // TODO pgp message logger
-                chat_log_msg_in(barejid, decrypted);
+                chat_log_pgp_msg_in(barejid, decrypted);
                 chatwin->enc_mode = PROF_ENC_PGP;
             } else {
                 ui_incoming_msg(chatwin, resource, message, NULL, new_win);
@@ -260,8 +259,7 @@ sv_ev_incoming_message(char *barejid, char *resource, char *message, char *enc_m
         char *decrypted = p_gpg_decrypt(jid->barejid, enc_message);
         if (decrypted) {
             ui_incoming_msg(chatwin, resource, decrypted, NULL, new_win);
-            // TODO pgp message logger
-            chat_log_msg_in(barejid, decrypted);
+            chat_log_pgp_msg_in(barejid, decrypted);
             chatwin->enc_mode = PROF_ENC_PGP;
         } else {
             ui_incoming_msg(chatwin, resource, message, NULL, new_win);
diff --git a/src/log.c b/src/log.c
index a7727e8b..941bea6f 100644
--- a/src/log.c
+++ b/src/log.c
@@ -280,6 +280,23 @@ chat_log_otr_msg_out(const char * const barejid, const char * const msg)
 }
 
 void
+chat_log_pgp_msg_out(const char * const barejid, const char * const msg)
+{
+    if (prefs_get_boolean(PREF_CHLOG)) {
+        const char *jid = jabber_get_fulljid();
+        Jid *jidp = jid_create(jid);
+        char *pref_pgp_log = prefs_get_string(PREF_PGP_LOG);
+        if (strcmp(pref_pgp_log, "on") == 0) {
+            _chat_log_chat(jidp->barejid, barejid, msg, PROF_OUT_LOG, NULL);
+        } else if (strcmp(pref_pgp_log, "redact") == 0) {
+            _chat_log_chat(jidp->barejid, barejid, "[redacted]", PROF_OUT_LOG, NULL);
+        }
+        prefs_free_string(pref_pgp_log);
+        jid_destroy(jidp);
+    }
+}
+
+void
 chat_log_otr_msg_in(const char * const barejid, const char * const msg, gboolean was_decrypted)
 {
     if (prefs_get_boolean(PREF_CHLOG)) {
@@ -297,6 +314,23 @@ chat_log_otr_msg_in(const char * const barejid, const char * const msg, gboolean
 }
 
 void
+chat_log_pgp_msg_in(const char * const barejid, const char * const msg)
+{
+    if (prefs_get_boolean(PREF_CHLOG)) {
+        const char *jid = jabber_get_fulljid();
+        Jid *jidp = jid_create(jid);
+        char *pref_pgp_log = prefs_get_string(PREF_PGP_LOG);
+        if (strcmp(pref_pgp_log, "on") == 0) {
+            _chat_log_chat(jidp->barejid, barejid, msg, PROF_IN_LOG, NULL);
+        } else if (strcmp(pref_pgp_log, "redact") == 0) {
+            _chat_log_chat(jidp->barejid, barejid, "[redacted]", PROF_IN_LOG, NULL);
+        }
+        prefs_free_string(pref_pgp_log);
+        jid_destroy(jidp);
+    }
+}
+
+void
 chat_log_msg_in(const char * const barejid, const char * const msg)
 {
     if (prefs_get_boolean(PREF_CHLOG)) {
diff --git a/src/log.h b/src/log.h
index 0689e2e6..3c98c3bd 100644
--- a/src/log.h
+++ b/src/log.h
@@ -67,10 +67,12 @@ void chat_log_init(void);
 
 void chat_log_msg_out(const char * const barejid, const char * const msg);
 void chat_log_otr_msg_out(const char * const barejid, const char * const msg);
+void chat_log_pgp_msg_out(const char * const barejid, const char * const msg);
 
 void chat_log_msg_in(const char * const barejid, const char * const msg);
 void chat_log_msg_in_delayed(const char * const barejid, const char * msg, GTimeVal *tv_stamp);
 void chat_log_otr_msg_in(const char * const barejid, const char * const msg, gboolean was_decrypted);
+void chat_log_pgp_msg_in(const char * const barejid, const char * const msg);
 
 void chat_log_close(void);
 GSList * chat_log_get_previous(const gchar * const login,
diff --git a/tests/unittests/log/stub_log.c b/tests/unittests/log/stub_log.c
index f88871a7..c25057d8 100644
--- a/tests/unittests/log/stub_log.c
+++ b/tests/unittests/log/stub_log.c
@@ -53,10 +53,12 @@ void chat_log_init(void) {}
 
 void chat_log_msg_out(const char * const barejid, const char * const msg) {}
 void chat_log_otr_msg_out(const char * const barejid, const char * const msg) {}
+void chat_log_pgp_msg_out(const char * const barejid, const char * const msg) {}
 
 void chat_log_msg_in(const char * const barejid, const char * const msg) {}
 void chat_log_msg_in_delayed(const char * const barejid, const char * msg, GTimeVal *tv_stamp) {}
 void chat_log_otr_msg_in(const char * const barejid, const char * const msg, gboolean was_decrypted) {}
+void chat_log_pgp_msg_in(const char * const barejid, const char * const msg) {}
 
 void chat_log_close(void) {}
 GSList * chat_log_get_previous(const gchar * const login,