1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

Add /privacy logging command

Add ability to completely turn logs off,
Needed since `/logging` and `/history` didn't stop history logging
in the DB, only in files.
Command might break something on usage,
hence it was primarily introduced for privacy geeks.
Privacy command discussion #1836
This commit is contained in:
John Hernandez 2023-07-03 16:06:24 +02:00
parent f67d548ebf
commit 1c102fec27
8 changed files with 112 additions and 5 deletions

View File

@ -222,9 +222,13 @@ chat_log_msg_in(ProfMessage* message)
} }
static void static void
_chat_log_chat(const char* const login, const char* const other, const char* const msg, _chat_log_chat(const char* const login, const char* const other, const char* msg,
chat_log_direction_t direction, GDateTime* timestamp, const char* const resourcepart) chat_log_direction_t direction, GDateTime* timestamp, const char* const resourcepart)
{ {
auto_gchar gchar* pref_dblog = prefs_get_string(PREF_DBLOG);
if (g_strcmp0(pref_dblog, "redact") == 0) {
msg = "[REDACTED]";
}
char* other_name; char* other_name;
GString* other_str = NULL; GString* other_str = NULL;

View File

@ -122,6 +122,7 @@ static char* _clear_autocomplete(ProfWin* window, const char* const input, gbool
static char* _invite_autocomplete(ProfWin* window, const char* const input, gboolean previous); static char* _invite_autocomplete(ProfWin* window, const char* const input, gboolean previous);
static char* _status_autocomplete(ProfWin* window, const char* const input, gboolean previous); static char* _status_autocomplete(ProfWin* window, const char* const input, gboolean previous);
static char* _logging_autocomplete(ProfWin* window, const char* const input, gboolean previous); static char* _logging_autocomplete(ProfWin* window, const char* const input, gboolean previous);
static char* _privacy_autocomplete(ProfWin* window, const char* const input, gboolean previous);
static char* _color_autocomplete(ProfWin* window, const char* const input, gboolean previous); static char* _color_autocomplete(ProfWin* window, const char* const input, gboolean previous);
static char* _avatar_autocomplete(ProfWin* window, const char* const input, gboolean previous); static char* _avatar_autocomplete(ProfWin* window, const char* const input, gboolean previous);
static char* _correction_autocomplete(ProfWin* window, const char* const input, gboolean previous); static char* _correction_autocomplete(ProfWin* window, const char* const input, gboolean previous);
@ -269,6 +270,8 @@ static Autocomplete status_ac;
static Autocomplete status_state_ac; static Autocomplete status_state_ac;
static Autocomplete logging_ac; static Autocomplete logging_ac;
static Autocomplete logging_group_ac; static Autocomplete logging_group_ac;
static Autocomplete privacy_ac;
static Autocomplete privacy_log_ac;
static Autocomplete color_ac; static Autocomplete color_ac;
static Autocomplete correction_ac; static Autocomplete correction_ac;
static Autocomplete avatar_ac; static Autocomplete avatar_ac;
@ -1070,6 +1073,14 @@ cmd_ac_init(void)
autocomplete_add(logging_ac, "chat"); autocomplete_add(logging_ac, "chat");
autocomplete_add(logging_ac, "group"); autocomplete_add(logging_ac, "group");
privacy_ac = autocomplete_new();
autocomplete_add(privacy_ac, "logging");
privacy_log_ac = autocomplete_new();
autocomplete_add(privacy_log_ac, "on");
autocomplete_add(privacy_log_ac, "off");
autocomplete_add(privacy_log_ac, "redact");
logging_group_ac = autocomplete_new(); logging_group_ac = autocomplete_new();
autocomplete_add(logging_group_ac, "on"); autocomplete_add(logging_group_ac, "on");
autocomplete_add(logging_group_ac, "off"); autocomplete_add(logging_group_ac, "off");
@ -1330,6 +1341,7 @@ cmd_ac_init(void)
g_hash_table_insert(ac_funcs, "/lastactivity", _lastactivity_autocomplete); g_hash_table_insert(ac_funcs, "/lastactivity", _lastactivity_autocomplete);
g_hash_table_insert(ac_funcs, "/log", _log_autocomplete); g_hash_table_insert(ac_funcs, "/log", _log_autocomplete);
g_hash_table_insert(ac_funcs, "/logging", _logging_autocomplete); g_hash_table_insert(ac_funcs, "/logging", _logging_autocomplete);
g_hash_table_insert(ac_funcs, "/privacy", _privacy_autocomplete);
g_hash_table_insert(ac_funcs, "/mood", _mood_autocomplete); g_hash_table_insert(ac_funcs, "/mood", _mood_autocomplete);
g_hash_table_insert(ac_funcs, "/notify", _notify_autocomplete); g_hash_table_insert(ac_funcs, "/notify", _notify_autocomplete);
g_hash_table_insert(ac_funcs, "/occupants", _occupants_autocomplete); g_hash_table_insert(ac_funcs, "/occupants", _occupants_autocomplete);
@ -1682,6 +1694,8 @@ cmd_ac_reset(ProfWin* window)
autocomplete_reset(status_state_ac); autocomplete_reset(status_state_ac);
autocomplete_reset(logging_ac); autocomplete_reset(logging_ac);
autocomplete_reset(logging_group_ac); autocomplete_reset(logging_group_ac);
autocomplete_reset(privacy_ac);
autocomplete_reset(privacy_log_ac);
autocomplete_reset(color_ac); autocomplete_reset(color_ac);
autocomplete_reset(correction_ac); autocomplete_reset(correction_ac);
autocomplete_reset(avatar_ac); autocomplete_reset(avatar_ac);
@ -1867,6 +1881,8 @@ cmd_ac_uninit(void)
autocomplete_free(status_state_ac); autocomplete_free(status_state_ac);
autocomplete_free(logging_ac); autocomplete_free(logging_ac);
autocomplete_free(logging_group_ac); autocomplete_free(logging_group_ac);
autocomplete_free(privacy_ac);
autocomplete_free(privacy_log_ac);
autocomplete_free(color_ac); autocomplete_free(color_ac);
autocomplete_free(correction_ac); autocomplete_free(correction_ac);
autocomplete_free(avatar_ac); autocomplete_free(avatar_ac);
@ -4213,6 +4229,24 @@ _status_autocomplete(ProfWin* window, const char* const input, gboolean previous
return NULL; return NULL;
} }
static char*
_privacy_autocomplete(ProfWin* window, const char* const input, gboolean previous)
{
char* found = NULL;
found = autocomplete_param_with_ac(input, "/privacy", privacy_ac, TRUE, previous);
if (found) {
return found;
}
found = autocomplete_param_with_ac(input, "/privacy logging", privacy_log_ac, TRUE, previous);
if (found) {
return found;
}
return found;
}
static char* static char*
_logging_autocomplete(ProfWin* window, const char* const input, gboolean previous) _logging_autocomplete(ProfWin* window, const char* const input, gboolean previous)
{ {

View File

@ -2720,6 +2720,21 @@ static const struct cmd_t command_defs[] = {
"/strophe verbosity 3", "/strophe verbosity 3",
"/strophe sm no-resend") "/strophe sm no-resend")
}, },
{ CMD_PREAMBLE("/privacy",
parse_args, 2, 3, NULL)
CMD_MAINFUNC(cmd_privacy)
CMD_TAGS(
CMD_TAG_CHAT)
CMD_SYN(
"/privacy logging on|redact|off")
CMD_DESC(
"Configure privacy settings.")
CMD_ARGS(
{ "logging on|redact|off", "Switch chat logging. This will also disable logging in the internally used SQL database. Your messages will not be saved anywhere locally. This might have unintended consequences, such as not being able to decrypt OMEMO encrypted messages received later via MAM, and should be used with caution." })
CMD_EXAMPLES(
"/privacy logging off")
},
// NEXT-COMMAND (search helper) // NEXT-COMMAND (search helper)
}; };

View File

@ -6949,6 +6949,44 @@ cmd_autoconnect(ProfWin* window, const char* const command, gchar** args)
return TRUE; return TRUE;
} }
gboolean
cmd_privacy(ProfWin* window, const char* const command, gchar** args)
{
if (args[0] == NULL) {
cons_bad_cmd_usage(command);
return FALSE;
}
if (g_strcmp0(args[0], "logging") == 0) {
gchar* arg = args[1];
if (arg == NULL) {
cons_bad_cmd_usage(command);
return FALSE;
}
if (g_strcmp0(arg, "on") == 0) {
cons_show("Logging enabled.");
prefs_set_string(PREF_DBLOG, arg);
prefs_set_boolean(PREF_CHLOG, TRUE);
prefs_set_boolean(PREF_HISTORY, TRUE);
} else if (g_strcmp0(arg, "off") == 0) {
cons_show("Logging disabled.");
prefs_set_string(PREF_DBLOG, arg);
prefs_set_boolean(PREF_CHLOG, FALSE);
prefs_set_boolean(PREF_HISTORY, FALSE);
} else if (g_strcmp0(arg, "redact") == 0) {
cons_show("Messages are going to be redacted.");
prefs_set_string(PREF_DBLOG, arg);
} else {
cons_bad_cmd_usage(command);
return FALSE;
}
return TRUE;
}
return TRUE;
}
gboolean gboolean
cmd_logging(ProfWin* window, const char* const command, gchar** args) cmd_logging(ProfWin* window, const char* const command, gchar** args)
{ {
@ -6967,10 +7005,7 @@ cmd_logging(ProfWin* window, const char* const command, gchar** args)
return TRUE; return TRUE;
} else if (g_strcmp0(args[0], "group") == 0 && args[1] != NULL) { } else if (g_strcmp0(args[0], "group") == 0 && args[1] != NULL) {
if (g_strcmp0(args[1], "on") == 0 || g_strcmp0(args[1], "off") == 0) { return _cmd_set_boolean_preference(args[1], "Groupchat logging", PREF_GRLOG);
_cmd_set_boolean_preference(args[1], "Groupchat logging", PREF_GRLOG);
return TRUE;
}
} }
cons_bad_cmd_usage(command); cons_bad_cmd_usage(command);

View File

@ -112,6 +112,7 @@ gboolean cmd_msg(ProfWin* window, const char* const command, gchar** args);
gboolean cmd_nick(ProfWin* window, const char* const command, gchar** args); gboolean cmd_nick(ProfWin* window, const char* const command, gchar** args);
gboolean cmd_notify(ProfWin* window, const char* const command, gchar** args); gboolean cmd_notify(ProfWin* window, const char* const command, gchar** args);
gboolean cmd_pgp(ProfWin* window, const char* const command, gchar** args); gboolean cmd_pgp(ProfWin* window, const char* const command, gchar** args);
gboolean cmd_privacy(ProfWin* window, const char* const command, gchar** args);
#ifdef HAVE_LIBGPGME #ifdef HAVE_LIBGPGME
gboolean cmd_ox(ProfWin* window, const char* const command, gchar** args); gboolean cmd_ox(ProfWin* window, const char* const command, gchar** args);
gboolean cmd_ox_log(ProfWin* window, const char* const command, gchar** args); gboolean cmd_ox_log(ProfWin* window, const char* const command, gchar** args);

View File

@ -1827,6 +1827,7 @@ _get_group(preference_t pref)
case PREF_TRAY_READ: case PREF_TRAY_READ:
case PREF_ADV_NOTIFY_DISCO_OR_VERSION: case PREF_ADV_NOTIFY_DISCO_OR_VERSION:
return PREF_GROUP_NOTIFICATIONS; return PREF_GROUP_NOTIFICATIONS;
case PREF_DBLOG:
case PREF_CHLOG: case PREF_CHLOG:
case PREF_GRLOG: case PREF_GRLOG:
case PREF_LOG_ROTATE: case PREF_LOG_ROTATE:
@ -1975,6 +1976,8 @@ _get_key(preference_t pref)
return "room.mention.wholeword"; return "room.mention.wholeword";
case PREF_CHLOG: case PREF_CHLOG:
return "chlog"; return "chlog";
case PREF_DBLOG:
return "dblog";
case PREF_GRLOG: case PREF_GRLOG:
return "grlog"; return "grlog";
case PREF_AUTOAWAY_CHECK: case PREF_AUTOAWAY_CHECK:
@ -2321,6 +2324,8 @@ _get_default_string(preference_t pref)
return "on"; return "on";
case PREF_STROPHE_VERBOSITY: case PREF_STROPHE_VERBOSITY:
return "0"; return "0";
case PREF_DBLOG:
return "on";
default: default:
return NULL; return NULL;
} }

View File

@ -127,6 +127,7 @@ typedef enum {
PREF_NOTIFY_MENTION_CASE_SENSITIVE, PREF_NOTIFY_MENTION_CASE_SENSITIVE,
PREF_NOTIFY_MENTION_WHOLE_WORD, PREF_NOTIFY_MENTION_WHOLE_WORD,
PREF_CHLOG, PREF_CHLOG,
PREF_DBLOG,
PREF_GRLOG, PREF_GRLOG,
PREF_AUTOAWAY_CHECK, PREF_AUTOAWAY_CHECK,
PREF_AUTOAWAY_MODE, PREF_AUTOAWAY_MODE,

View File

@ -47,6 +47,7 @@
#include "common.h" #include "common.h"
#include "config/files.h" #include "config/files.h"
#include "database.h" #include "database.h"
#include "config/preferences.h"
#include "xmpp/xmpp.h" #include "xmpp/xmpp.h"
#include "xmpp/message.h" #include "xmpp/message.h"
@ -373,6 +374,17 @@ _get_message_enc_type(const char* const encstr)
static void static void
_add_to_db(ProfMessage* message, char* type, const Jid* const from_jid, const Jid* const to_jid) _add_to_db(ProfMessage* message, char* type, const Jid* const from_jid, const Jid* const to_jid)
{ {
auto_gchar gchar* pref_dblog = prefs_get_string(PREF_DBLOG);
if (g_strcmp0(pref_dblog, "off") == 0) {
return;
} else if (g_strcmp0(pref_dblog, "redact") == 0) {
if (message->plain) {
free(message->plain);
}
message->plain = strdup("[REDACTED]");
}
if (!g_chatlog_database) { if (!g_chatlog_database) {
log_debug("log_database_add() called but db is not initialized"); log_debug("log_database_add() called but db is not initialized");
return; return;