mirror of
https://git.jabber.space/devs/cproof.git
synced 2026-07-19 23:36:21 +00:00
Minor improvements.
* Add new TLS policy `direct` as a replacement for `legacy`. * Document that `/[command]?` prints the help of a command. * Add option to get help via `/command help`. * Fix `my-prof.supp` generation and tests for out-of-source builds. Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
This commit is contained in:
@@ -131,64 +131,8 @@ static gboolean _cmd_execute(ProfWin* window, const char* const command, const c
|
||||
static gboolean _cmd_execute_default(ProfWin* window, const char* inp);
|
||||
static gboolean _cmd_execute_alias(ProfWin* window, const char* const inp, gboolean* ran);
|
||||
static gboolean
|
||||
_string_matches_one_of(const char* what, const char* is, gboolean is_can_be_null, const char* first, ...) __attribute__((sentinel));
|
||||
static gboolean
|
||||
_download_install_plugin(ProfWin* window, gchar* url, gchar* path);
|
||||
|
||||
static gboolean
|
||||
_string_matches_one_of(const char* what, const char* is, gboolean is_can_be_null, const char* first, ...)
|
||||
{
|
||||
gboolean ret = FALSE;
|
||||
va_list ap;
|
||||
const char* cur = first;
|
||||
if (!is)
|
||||
return is_can_be_null;
|
||||
|
||||
va_start(ap, first);
|
||||
while (cur != NULL) {
|
||||
if (g_strcmp0(is, cur) == 0) {
|
||||
ret = TRUE;
|
||||
break;
|
||||
}
|
||||
cur = va_arg(ap, const char*);
|
||||
}
|
||||
va_end(ap);
|
||||
if (!ret && what) {
|
||||
cons_show("Invalid %s: '%s'", what, is);
|
||||
char errmsg[256] = { 0 };
|
||||
size_t sz = 0;
|
||||
int s = snprintf(errmsg, sizeof(errmsg) - sz, "%s must be one of:", what);
|
||||
if (s < 0 || s + sz >= sizeof(errmsg))
|
||||
return ret;
|
||||
sz += s;
|
||||
|
||||
cur = first;
|
||||
va_start(ap, first);
|
||||
while (cur != NULL) {
|
||||
const char* next = va_arg(ap, const char*);
|
||||
if (next) {
|
||||
s = snprintf(errmsg + sz, sizeof(errmsg) - sz, " '%s',", cur);
|
||||
} else {
|
||||
/* remove last ',' */
|
||||
sz--;
|
||||
errmsg[sz] = '\0';
|
||||
s = snprintf(errmsg + sz, sizeof(errmsg) - sz, " or '%s'.", cur);
|
||||
}
|
||||
if (s < 0 || s + sz >= sizeof(errmsg)) {
|
||||
log_debug("Error message too long or some other error occurred (%d).", s);
|
||||
s = -1;
|
||||
break;
|
||||
}
|
||||
sz += s;
|
||||
cur = next;
|
||||
}
|
||||
va_end(ap);
|
||||
if (s > 0)
|
||||
cons_show(errmsg);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Processes a line of input and determines if profanity should continue.
|
||||
*
|
||||
@@ -210,8 +154,10 @@ cmd_process_input(ProfWin* window, char* inp)
|
||||
if (inp[0] == '/') {
|
||||
auto_char char* inp_cpy = strdup(inp);
|
||||
char* command = strtok(inp_cpy, " ");
|
||||
char* second_word = strtok(NULL, " ");
|
||||
gboolean wants_help = second_word ? strcmp(second_word, "help") == 0 : FALSE;
|
||||
char* question_mark = strchr(command, '?');
|
||||
if (question_mark) {
|
||||
if (wants_help || question_mark) {
|
||||
*question_mark = '\0';
|
||||
auto_gchar gchar* fakeinp = g_strdup_printf("/help %s", command + 1);
|
||||
if (fakeinp) {
|
||||
@@ -397,7 +343,7 @@ cmd_connect(ProfWin* window, const char* const command, gchar** args)
|
||||
char* altdomain = g_hash_table_lookup(options, "server");
|
||||
|
||||
char* tls_policy = g_hash_table_lookup(options, "tls");
|
||||
if (!_string_matches_one_of("TLS policy", tls_policy, TRUE, "force", "allow", "trust", "disable", "legacy", NULL)) {
|
||||
if (!valid_tls_policy_option(tls_policy)) {
|
||||
cons_bad_cmd_usage(command);
|
||||
cons_show("");
|
||||
options_destroy(options);
|
||||
@@ -405,7 +351,7 @@ cmd_connect(ProfWin* window, const char* const command, gchar** args)
|
||||
}
|
||||
|
||||
char* auth_policy = g_hash_table_lookup(options, "auth");
|
||||
if (!_string_matches_one_of("Auth policy", auth_policy, TRUE, "default", "legacy", NULL)) {
|
||||
if (!string_matches_one_of("Auth policy", auth_policy, TRUE, "default", "legacy", NULL)) {
|
||||
cons_bad_cmd_usage(command);
|
||||
cons_show("");
|
||||
options_destroy(options);
|
||||
@@ -785,7 +731,7 @@ _account_set_nick(char* account_name, char* nick)
|
||||
gboolean
|
||||
_account_set_otr(char* account_name, char* policy)
|
||||
{
|
||||
if (_string_matches_one_of("OTR policy", policy, FALSE, "manual", "opportunistic", "always", NULL)) {
|
||||
if (string_matches_one_of("OTR policy", policy, FALSE, "manual", "opportunistic", "always", NULL)) {
|
||||
accounts_set_otr_policy(account_name, policy);
|
||||
cons_show("Updated OTR policy for account %s: %s", account_name, policy);
|
||||
cons_show("");
|
||||
@@ -877,7 +823,7 @@ _account_set_theme(char* account_name, char* theme)
|
||||
gboolean
|
||||
_account_set_tls(char* account_name, char* policy)
|
||||
{
|
||||
if (_string_matches_one_of("TLS policy", policy, FALSE, "force", "allow", "trust", "disable", "legacy", NULL)) {
|
||||
if (valid_tls_policy_option(policy)) {
|
||||
accounts_set_tls_policy(account_name, policy);
|
||||
cons_show("Updated TLS policy for account %s: %s", account_name, policy);
|
||||
cons_show("");
|
||||
@@ -888,7 +834,7 @@ _account_set_tls(char* account_name, char* policy)
|
||||
gboolean
|
||||
_account_set_auth(char* account_name, char* policy)
|
||||
{
|
||||
if (_string_matches_one_of("Auth policy", policy, FALSE, "default", "legacy", NULL)) {
|
||||
if (string_matches_one_of("Auth policy", policy, FALSE, "default", "legacy", NULL)) {
|
||||
accounts_set_auth_policy(account_name, policy);
|
||||
cons_show("Updated auth policy for account %s: %s", account_name, policy);
|
||||
cons_show("");
|
||||
@@ -1829,7 +1775,7 @@ _who_room(ProfWin* window, const char* const command, gchar** args)
|
||||
}
|
||||
|
||||
// bad arg
|
||||
if (!_string_matches_one_of(NULL, args[0], TRUE, "online", "available", "unavailable", "away", "chat", "xa", "dnd", "any", "moderator", "participant", "visitor", "owner", "admin", "member", "outcast", "none", NULL)) {
|
||||
if (!string_matches_one_of(NULL, args[0], TRUE, "online", "available", "unavailable", "away", "chat", "xa", "dnd", "any", "moderator", "participant", "visitor", "owner", "admin", "member", "outcast", "none", NULL)) {
|
||||
cons_bad_cmd_usage(command);
|
||||
return;
|
||||
}
|
||||
@@ -1838,7 +1784,7 @@ _who_room(ProfWin* window, const char* const command, gchar** args)
|
||||
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
|
||||
|
||||
// presence filter
|
||||
if (_string_matches_one_of(NULL, args[0], TRUE, "online", "available", "unavailable", "away", "chat", "xa", "dnd", "any", NULL)) {
|
||||
if (string_matches_one_of(NULL, args[0], TRUE, "online", "available", "unavailable", "away", "chat", "xa", "dnd", "any", NULL)) {
|
||||
|
||||
gchar* presence = args[0];
|
||||
GList* occupants = muc_roster(mucwin->roomjid);
|
||||
@@ -1937,7 +1883,7 @@ _who_roster(ProfWin* window, const char* const command, gchar** args)
|
||||
gchar* presence = args[0];
|
||||
|
||||
// bad arg
|
||||
if (!_string_matches_one_of(NULL, presence, TRUE, "online", "available", "unavailable", "offline", "away", "chat", "xa", "dnd", "any", NULL)) {
|
||||
if (!string_matches_one_of(NULL, presence, TRUE, "online", "available", "unavailable", "offline", "away", "chat", "xa", "dnd", "any", NULL)) {
|
||||
cons_bad_cmd_usage(command);
|
||||
return;
|
||||
}
|
||||
@@ -3771,7 +3717,7 @@ cmd_form_field(ProfWin* window, char* tag, gchar** args)
|
||||
if (cmd) {
|
||||
value = args[1];
|
||||
}
|
||||
if (!_string_matches_one_of(NULL, cmd, FALSE, "add", "remove", NULL)) {
|
||||
if (!string_matches_one_of(NULL, cmd, FALSE, "add", "remove", NULL)) {
|
||||
win_println(window, THEME_DEFAULT, "-", "Invalid command, usage:");
|
||||
confwin_field_help(confwin, tag);
|
||||
win_println(window, THEME_DEFAULT, "-", "");
|
||||
@@ -3825,7 +3771,7 @@ cmd_form_field(ProfWin* window, char* tag, gchar** args)
|
||||
if (cmd) {
|
||||
value = args[1];
|
||||
}
|
||||
if (!_string_matches_one_of(NULL, cmd, FALSE, "add", "remove", NULL)) {
|
||||
if (!string_matches_one_of(NULL, cmd, FALSE, "add", "remove", NULL)) {
|
||||
win_println(window, THEME_DEFAULT, "-", "Invalid command, usage:");
|
||||
confwin_field_help(confwin, tag);
|
||||
win_println(window, THEME_DEFAULT, "-", "");
|
||||
@@ -3876,7 +3822,7 @@ cmd_form_field(ProfWin* window, char* tag, gchar** args)
|
||||
if (cmd) {
|
||||
value = args[1];
|
||||
}
|
||||
if (!_string_matches_one_of(NULL, cmd, FALSE, "add", "remove", NULL)) {
|
||||
if (!string_matches_one_of(NULL, cmd, FALSE, "add", "remove", NULL)) {
|
||||
win_println(window, THEME_DEFAULT, "-", "Invalid command, usage:");
|
||||
confwin_field_help(confwin, tag);
|
||||
win_println(window, THEME_DEFAULT, "-", "");
|
||||
@@ -3932,7 +3878,7 @@ cmd_form(ProfWin* window, const char* const command, gchar** args)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (!_string_matches_one_of(NULL, args[0], FALSE, "submit", "cancel", "show", "help", NULL)) {
|
||||
if (!string_matches_one_of(NULL, args[0], FALSE, "submit", "cancel", "show", "help", NULL)) {
|
||||
cons_bad_cmd_usage(command);
|
||||
return TRUE;
|
||||
}
|
||||
@@ -4177,7 +4123,7 @@ cmd_affiliation(ProfWin* window, const char* const command, gchar** args)
|
||||
}
|
||||
|
||||
gchar* affiliation = args[1];
|
||||
if (!_string_matches_one_of(NULL, affiliation, TRUE, "owner", "admin", "member", "none", "outcast", NULL)) {
|
||||
if (!string_matches_one_of(NULL, affiliation, TRUE, "owner", "admin", "member", "none", "outcast", NULL)) {
|
||||
cons_bad_cmd_usage(command);
|
||||
return TRUE;
|
||||
}
|
||||
@@ -4252,7 +4198,7 @@ cmd_role(ProfWin* window, const char* const command, gchar** args)
|
||||
}
|
||||
|
||||
gchar* role = args[1];
|
||||
if (!_string_matches_one_of(NULL, role, TRUE, "visitor", "participant", "moderator", "none", NULL)) {
|
||||
if (!string_matches_one_of(NULL, role, TRUE, "visitor", "participant", "moderator", "none", NULL)) {
|
||||
cons_bad_cmd_usage(command);
|
||||
return TRUE;
|
||||
}
|
||||
@@ -5196,13 +5142,13 @@ cmd_console(ProfWin* window, const char* const command, gchar** args)
|
||||
{
|
||||
gboolean isMuc = (g_strcmp0(args[0], "muc") == 0);
|
||||
|
||||
if (!_string_matches_one_of(NULL, args[0], FALSE, "chat", "private", NULL) && !isMuc) {
|
||||
if (!string_matches_one_of(NULL, args[0], FALSE, "chat", "private", NULL) && !isMuc) {
|
||||
cons_bad_cmd_usage(command);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gchar* setting = args[1];
|
||||
if (!_string_matches_one_of(NULL, setting, FALSE, "all", "first", "none", NULL)) {
|
||||
if (!string_matches_one_of(NULL, setting, FALSE, "all", "first", "none", NULL)) {
|
||||
if (!(isMuc && (g_strcmp0(setting, "mention") == 0))) {
|
||||
cons_bad_cmd_usage(command);
|
||||
return TRUE;
|
||||
@@ -6375,12 +6321,12 @@ cmd_ping(ProfWin* window, const char* const command, gchar** args)
|
||||
gboolean
|
||||
cmd_autoaway(ProfWin* window, const char* const command, gchar** args)
|
||||
{
|
||||
if (!_string_matches_one_of("Setting", args[0], FALSE, "mode", "time", "message", "check", NULL)) {
|
||||
if (!string_matches_one_of("Setting", args[0], FALSE, "mode", "time", "message", "check", NULL)) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (g_strcmp0(args[0], "mode") == 0) {
|
||||
if (_string_matches_one_of("Mode", args[1], FALSE, "idle", "away", "off", NULL)) {
|
||||
if (string_matches_one_of("Mode", args[1], FALSE, "idle", "away", "off", NULL)) {
|
||||
prefs_set_string(PREF_AUTOAWAY_MODE, args[1]);
|
||||
cons_show("Auto away mode set to: %s.", args[1]);
|
||||
}
|
||||
@@ -7725,7 +7671,7 @@ cmd_otr_policy(ProfWin* window, const char* const command, gchar** args)
|
||||
}
|
||||
|
||||
char* choice = args[1];
|
||||
if (!_string_matches_one_of("OTR policy", choice, FALSE, "manual", "opportunistic", "always", NULL)) {
|
||||
if (!string_matches_one_of("OTR policy", choice, FALSE, "manual", "opportunistic", "always", NULL)) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@@ -8911,7 +8857,7 @@ cmd_omemo_policy(ProfWin* window, const char* const command, gchar** args)
|
||||
}
|
||||
|
||||
char* choice = args[1];
|
||||
if (!_string_matches_one_of("OMEMO policy", choice, FALSE, "manual", "automatic", "always", NULL)) {
|
||||
if (!string_matches_one_of("OMEMO policy", choice, FALSE, "manual", "automatic", "always", NULL)) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@@ -9597,7 +9543,7 @@ cmd_register(ProfWin* window, const char* const command, gchar** args)
|
||||
}
|
||||
|
||||
char* tls_policy = g_hash_table_lookup(options, "tls");
|
||||
if (!_string_matches_one_of("TLS policy", tls_policy, TRUE, "force", "allow", "trust", "disable", "legacy", NULL)) {
|
||||
if (!valid_tls_policy_option(tls_policy)) {
|
||||
cons_bad_cmd_usage(command);
|
||||
cons_show("");
|
||||
options_destroy(options);
|
||||
|
||||
Reference in New Issue
Block a user