1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Added PGP logging preferences

This commit is contained in:
James Booth 2015-06-21 21:42:58 +01:00
parent 446027b950
commit 3d2f999efb
9 changed files with 100 additions and 20 deletions

View File

@ -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;

View File

@ -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) {

View File

@ -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;
}

View File

@ -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 {

View File

@ -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);
}

View File

@ -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);

View File

@ -279,6 +279,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)
{
@ -296,6 +313,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)
{

View File

@ -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,

View File

@ -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,