1
1
mirror of https://github.com/profanity-im/profanity.git synced 2025-02-02 15:08:15 -05:00

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
This commit is contained in:
James Booth 2014-01-13 20:38:19 +00:00
parent 60820007ee
commit ecf323de31
5 changed files with 27 additions and 7 deletions

View File

@ -1176,7 +1176,11 @@ cmd_execute_default(const char * const inp)
if (prefs_get_boolean(PREF_CHLOG)) { if (prefs_get_boolean(PREF_CHLOG)) {
const char *jid = jabber_get_fulljid(); const char *jid = jabber_get_fulljid();
Jid *jidp = jid_create(jid); 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); jid_destroy(jidp);
} }

View File

@ -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)) { if (((win_type == WIN_CHAT) || (win_type == WIN_CONSOLE)) && prefs_get_boolean(PREF_CHLOG)) {
const char *jid = jabber_get_fulljid(); const char *jid = jabber_get_fulljid();
Jid *jidp = jid_create(jid); 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); jid_destroy(jidp);
} }
} else { } else {

View File

@ -429,14 +429,14 @@ otr_encrypt_message(const char * const to, const char * const message)
} }
char * 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; char *decrypted = NULL;
OtrlTLV *tlvs = NULL; OtrlTLV *tlvs = NULL;
OtrlTLV *tlv = NULL; OtrlTLV *tlv = NULL;
int result = otrl_message_receiving(user_state, &ops, NULL, jid, "xmpp", from, message, &decrypted, &tlvs, NULL, 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) { if (result == 1) {
tlv = otrl_tlv_find(tlvs, OTRL_TLV_DISCONNECTED); tlv = otrl_tlv_find(tlvs, OTRL_TLV_DISCONNECTED);
if (tlv) { if (tlv) {
@ -452,10 +452,12 @@ otr_decrypt_message(const char * const from, const char * const message)
// message was decrypted, return to user // message was decrypted, return to user
} else if (decrypted != NULL) { } else if (decrypted != NULL) {
*was_decrypted = TRUE;
return decrypted; return decrypted;
// normal non OTR message // normal non OTR message
} else { } else {
*was_decrypted = FALSE;
return strdup(message); return strdup(message);
} }
} }

View File

@ -42,7 +42,8 @@ char * otr_get_my_fingerprint(void);
char * otr_get_their_fingerprint(const char * const recipient); char * otr_get_their_fingerprint(const char * const recipient);
char * otr_encrypt_message(const char * const to, const char * const message); 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); void otr_free_message(char *message);

View File

@ -176,9 +176,12 @@ void
handle_incoming_message(char *from, char *message, gboolean priv) handle_incoming_message(char *from, char *message, gboolean priv)
{ {
#ifdef HAVE_LIBOTR #ifdef HAVE_LIBOTR
gboolean was_decrypted = FALSE;
char *newmessage; char *newmessage;
if (!priv) { if (!priv) {
newmessage = otr_decrypt_message(from, message); newmessage = otr_decrypt_message(from, message, &was_decrypted);
// internal OTR message
if (newmessage == NULL) { if (newmessage == NULL) {
return; return;
} }
@ -193,7 +196,13 @@ handle_incoming_message(char *from, char *message, gboolean priv)
Jid *from_jid = jid_create(from); Jid *from_jid = jid_create(from);
const char *jid = jabber_get_fulljid(); const char *jid = jabber_get_fulljid();
Jid *jidp = jid_create(jid); 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(jidp);
jid_destroy(from_jid); jid_destroy(from_jid);
} }