From 3c56b289ed04f8525affd532d0192d653e1dcd95 Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Wed, 18 Mar 2020 18:20:05 +0100 Subject: Add slashguard feature New command `/slashguard` tries to protect against typing ` /quit` by not allowing a slash in the first 4 characters. --- src/command/cmd_ac.c | 2 +- src/command/cmd_defs.c | 17 +++++++++++++++++ src/command/cmd_funcs.c | 12 ++++++++++++ src/command/cmd_funcs.h | 1 + src/config/preferences.c | 3 +++ src/config/preferences.h | 1 + src/ui/console.c | 10 ++++++++++ src/ui/inputwin.c | 7 +++++++ src/ui/ui.h | 1 + 9 files changed, 53 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c index 12331bfb..0266d8f5 100644 --- a/src/command/cmd_ac.c +++ b/src/command/cmd_ac.c @@ -1567,7 +1567,7 @@ _cmd_ac_complete_params(ProfWin *window, const char *const input, gboolean previ // autocomplete boolean settings gchar *boolean_choices[] = { "/beep", "/intype", "/states", "/outtype", "/flash", "/splash", - "/history", "/vercheck", "/privileges", "/wrap", "/carbons", "/lastactivity", "/os"}; + "/history", "/vercheck", "/privileges", "/wrap", "/carbons", "/lastactivity", "/os", "/slashguard"}; for (i = 0; i < ARRAY_SIZE(boolean_choices); i++) { result = autocomplete_param_with_func(input, boolean_choices[i], prefs_autocomplete_boolean_choice, previous, NULL); diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index 8b45f646..3845b901 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -2418,6 +2418,23 @@ static struct cmd_t command_defs[] = { "message", "The corrected message."}) CMD_NOEXAMPLES }, + + { "/slashguard", + parse_args, 1, 1, &cons_slashguard_setting, + CMD_NOSUBFUNCS + CMD_MAINFUNC(cmd_slashguard) + CMD_TAGS( + CMD_TAG_UI, + CMD_TAG_CHAT) + CMD_SYN( + "/slashguard on|off") + CMD_DESC( + "Slashguard won't accept a slash in the first 4 characters of your input field. " + "It tries to protect you from typing ' /quit' and similar things in chats.") + CMD_ARGS( + { "on|off", "Enable or disable slashguard." }) + CMD_NOEXAMPLES + }, }; static GHashTable *search_index; diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index 1776c72e..cee58c7a 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -8836,3 +8836,15 @@ cmd_correct(ProfWin *window, const char *const command, gchar **args) win_println(window, THEME_DEFAULT, "!", "Command /correct only valid in regular chat windows."); return TRUE; } + +gboolean +cmd_slashguard(ProfWin *window, const char *const command, gchar **args) +{ + if (args[0] == NULL) { + return FALSE; + } + + _cmd_set_boolean_preference(args[0], command, "Slashguard", PREF_SLASH_GUARD); + + return TRUE; +} diff --git a/src/command/cmd_funcs.h b/src/command/cmd_funcs.h index 58d99635..bcb633d2 100644 --- a/src/command/cmd_funcs.h +++ b/src/command/cmd_funcs.h @@ -231,4 +231,5 @@ gboolean cmd_avatar(ProfWin *window, const char *const command, gchar **args); gboolean cmd_os(ProfWin *window, const char *const command, gchar **args); gboolean cmd_correction(ProfWin *window, const char *const command, gchar **args); gboolean cmd_correct(ProfWin *window, const char *const command, gchar **args); +gboolean cmd_slashguard(ProfWin *window, const char *const command, gchar **args); #endif diff --git a/src/config/preferences.c b/src/config/preferences.c index a4e5700b..fe9c185b 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -1744,6 +1744,7 @@ _get_group(preference_t pref) case PREF_STATUSBAR_ROOM: case PREF_TITLEBAR_MUC_TITLE: case PREF_HISTORY_COLOR_MUC: + case PREF_SLASH_GUARD: return PREF_GROUP_UI; case PREF_STATES: case PREF_OUTTYPE: @@ -2051,6 +2052,8 @@ _get_key(preference_t pref) return "history.muc.color"; case PREF_AVATAR_CMD: return "avatar.cmd"; + case PREF_SLASH_GUARD: + return "slashguard"; default: return NULL; } diff --git a/src/config/preferences.h b/src/config/preferences.h index 37040214..8703043c 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -167,6 +167,7 @@ typedef enum { PREF_CORRECTION_ALLOW, PREF_HISTORY_COLOR_MUC, PREF_AVATAR_CMD, + PREF_SLASH_GUARD, } preference_t; typedef struct prof_alias_t { diff --git a/src/ui/console.c b/src/ui/console.c index 2b9b8aad..8d2fb26d 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -2049,6 +2049,16 @@ cons_avatar_setting(void) prefs_free_string(pref); } +void +cons_slashguard_setting(void) +{ + if (prefs_get_boolean(PREF_SLASH_GUARD)) { + cons_show("Slashguard (/slashguard) : ON"); + } else { + cons_show("Slashguard (/slashguard) : OFF"); + } +} + void cons_show_connection_prefs(void) { diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index ca3b688c..40875935 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -196,6 +196,13 @@ inp_readline(void) } if (inp_line) { + if (!get_password && prefs_get_boolean(PREF_SLASH_GUARD)) { + char *res = (char*) memchr (inp_line+1, '/', 3); + if (res) { + cons_show("Your text contains a slash in the first 4 characters"); + return NULL; + } + } return strdup(inp_line); } else { return NULL; diff --git a/src/ui/ui.h b/src/ui/ui.h index b3e512aa..a4878106 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -320,6 +320,7 @@ void cons_color_setting(void); void cons_os_setting(void); void cons_correction_setting(void); void cons_avatar_setting(void); +void cons_slashguard_setting(void); void cons_show_contact_online(PContact contact, Resource *resource, GDateTime *last_activity); void cons_show_contact_offline(PContact contact, char *resource, char *status); void cons_theme_properties(void); -- cgit 1.4.1-2-gfad0 af09df0'>^
41fe8c22 ^














9cff3735 ^

41fe8c22 ^
c6288d89 ^
1e37b755 ^
61a09476 ^
fd218ac3 ^

dcc2123e ^
70a79abd ^
a65403c5 ^
c6288d89 ^
41fe8c22 ^
51a7588b ^


41fe8c22 ^

1654f16a ^
ac91e7ef ^
1654f16a ^
41fe8c22 ^
29eb843d ^
8f9f018d ^
51a7588b ^
41fe8c22 ^
51a7588b ^
41fe8c22 ^
61a09476 ^
fd218ac3 ^

dcc2123e ^
41fe8c22 ^






ab08d0a3 ^
d90c47f2 ^
802442ff ^
2350a94c ^
d90c47f2 ^
41fe8c22 ^
8008d8c3 ^

41fe8c22 ^




51a7588b ^
41fe8c22 ^
1654f16a ^

ac91e7ef ^

4c913aa0 ^

efeb2fcf ^






2518aa50 ^

efeb2fcf ^
41fe8c22 ^
194c53c4 ^

a65403c5 ^
623fbe9e ^
fccf56be ^

1b25aa84 ^

c8874cd2 ^



9cfd1782 ^



1b25aa84 ^
7090f85d ^







41fe8c22 ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132