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:
Steffen Jaeckel
2025-11-12 14:53:25 +01:00
parent a50cd3a885
commit 54fea4afcf
11 changed files with 111 additions and 96 deletions

View File

@@ -285,7 +285,7 @@ endif
TESTS = tests/unittests/unittests TESTS = tests/unittests/unittests
check_PROGRAMS = tests/unittests/unittests check_PROGRAMS = tests/unittests/unittests
tests_unittests_unittests_CPPFLAGS = -Itests/ tests_unittests_unittests_CPPFLAGS = -I$(srcdir)/tests/
tests_unittests_unittests_SOURCES = $(unittest_sources) tests_unittests_unittests_SOURCES = $(unittest_sources)
tests_unittests_unittests_LDADD = -lcmocka tests_unittests_unittests_LDADD = -lcmocka
@@ -348,7 +348,7 @@ endif
.PHONY: my-prof.supp .PHONY: my-prof.supp
my-prof.supp: my-prof.supp:
@sed '/^# AUTO-GENERATED START/q' prof.supp > $@ @sed '/^# AUTO-GENERATED START/q' $(srcdir)/prof.supp > $@
@printf "\n\n# glib\n" >> $@ @printf "\n\n# glib\n" >> $@
@cat /usr/share/glib-2.0/valgrind/glib.supp >> $@ @cat /usr/share/glib-2.0/valgrind/glib.supp >> $@
@printf "\n\n# Python\n" >> $@ @printf "\n\n# Python\n" >> $@

View File

@@ -853,8 +853,9 @@ cmd_ac_init(void)
autocomplete_add(tls_property_ac, "force"); autocomplete_add(tls_property_ac, "force");
autocomplete_add(tls_property_ac, "allow"); autocomplete_add(tls_property_ac, "allow");
autocomplete_add(tls_property_ac, "trust"); autocomplete_add(tls_property_ac, "trust");
autocomplete_add(tls_property_ac, "legacy"); autocomplete_add(tls_property_ac, "direct");
autocomplete_add(tls_property_ac, "disable"); autocomplete_add(tls_property_ac, "disable");
autocomplete_add(tls_property_ac, "legacy");
autocomplete_add(auth_property_ac, "default"); autocomplete_add(auth_property_ac, "default");
autocomplete_add(auth_property_ac, "legacy"); autocomplete_add(auth_property_ac, "legacy");

View File

@@ -105,6 +105,9 @@ static gboolean _cmd_has_tag(Command* pcmd, const char* const tag);
* Command list * Command list
*/ */
#define CMD_TLS_DIRECT "Use direct TLS for the connection. It means TLS handshake is started right after TCP connection is established."
#define CMD_TLS_LEGACY "Alternative keyword for 'direct', which was created when one still thought that 'STARTTLS' is the future."
// clang-format off // clang-format off
static const struct cmd_t command_defs[] = { static const struct cmd_t command_defs[] = {
{ CMD_PREAMBLE("/help", { CMD_PREAMBLE("/help",
@@ -146,7 +149,7 @@ static const struct cmd_t command_defs[] = {
CMD_TAG_CONNECTION) CMD_TAG_CONNECTION)
CMD_SYN( CMD_SYN(
"/connect [<account>]", "/connect [<account>]",
"/connect <account> [server <server>] [port <port>] [tls force|allow|trust|legacy|disable] [auth default|legacy]", "/connect <account> [server <server>] [port <port>] [tls force|allow|trust|direct|disable|legacy] [auth default|legacy]",
"/connect <server>") "/connect <server>")
CMD_DESC( CMD_DESC(
"Login to a chat service. " "Login to a chat service. "
@@ -161,8 +164,9 @@ static const struct cmd_t command_defs[] = {
{ "tls force", "Force TLS connection, and fail if one cannot be established, this is default behaviour." }, { "tls force", "Force TLS connection, and fail if one cannot be established, this is default behaviour." },
{ "tls allow", "Use TLS for the connection if it is available." }, { "tls allow", "Use TLS for the connection if it is available." },
{ "tls trust", "Force TLS connection and trust server's certificate." }, { "tls trust", "Force TLS connection and trust server's certificate." },
{ "tls legacy", "Use legacy TLS for the connection. It means server doesn't support STARTTLS and TLS is forced just after TCP connection is established." }, { "tls direct", CMD_TLS_DIRECT },
{ "tls disable", "Disable TLS for the connection." }, { "tls disable", "Disable TLS for the connection." },
{ "tls legacy", CMD_TLS_LEGACY },
{ "auth default", "Default authentication process." }, { "auth default", "Default authentication process." },
{ "auth legacy", "Allow legacy authentication." }) { "auth legacy", "Allow legacy authentication." })
CMD_EXAMPLES( CMD_EXAMPLES(
@@ -2070,7 +2074,7 @@ static const struct cmd_t command_defs[] = {
"/account set <account> pgpkeyid <pgpkeyid>", "/account set <account> pgpkeyid <pgpkeyid>",
"/account set <account> startscript <script>", "/account set <account> startscript <script>",
"/account set <account> clientid \"<name> <version>\"", "/account set <account> clientid \"<name> <version>\"",
"/account set <account> tls force|allow|trust|legacy|disable", "/account set <account> tls force|allow|trust|direct|disable|legacy",
"/account set <account> auth default|legacy", "/account set <account> auth default|legacy",
"/account set <account> theme <theme>", "/account set <account> theme <theme>",
"/account set <account> session_alarm <max_sessions>", "/account set <account> session_alarm <max_sessions>",
@@ -2116,8 +2120,9 @@ static const struct cmd_t command_defs[] = {
{ "set <account> tls force", "Force TLS connection, and fail if one cannot be established, this is default behaviour." }, { "set <account> tls force", "Force TLS connection, and fail if one cannot be established, this is default behaviour." },
{ "set <account> tls allow", "Use TLS for the connection if it is available." }, { "set <account> tls allow", "Use TLS for the connection if it is available." },
{ "set <account> tls trust", "Force TLS connection and trust server's certificate." }, { "set <account> tls trust", "Force TLS connection and trust server's certificate." },
{ "set <account> tls legacy", "Use legacy TLS for the connection. It means server doesn't support STARTTLS and TLS is forced just after TCP connection is established." }, { "set <account> tls direct", CMD_TLS_DIRECT },
{ "set <account> tls disable", "Disable TLS for the connection." }, { "set <account> tls disable", "Disable TLS for the connection." },
{ "set <account> tls legacy", CMD_TLS_LEGACY },
{ "set <account> auth default", "Use default authentication process." }, { "set <account> auth default", "Use default authentication process." },
{ "set <account> auth legacy", "Allow legacy authentication." }, { "set <account> auth legacy", "Allow legacy authentication." },
{ "set <account> theme <theme>", "Set the UI theme for the account." }, { "set <account> theme <theme>", "Set the UI theme for the account." },
@@ -2659,7 +2664,7 @@ static const struct cmd_t command_defs[] = {
CMD_TAGS( CMD_TAGS(
CMD_TAG_CONNECTION) CMD_TAG_CONNECTION)
CMD_SYN( CMD_SYN(
"/register <username> <server> [port <port>] [tls force|allow|trust|legacy|disable]") "/register <username> <server> [port <port>] [tls force|allow|trust|direct|disable|legacy]")
CMD_DESC( CMD_DESC(
"Register an account on a server.") "Register an account on a server.")
CMD_ARGS( CMD_ARGS(
@@ -2669,8 +2674,9 @@ static const struct cmd_t command_defs[] = {
{ "tls force", "Force TLS connection, and fail if one cannot be established. This is the default behavior." }, { "tls force", "Force TLS connection, and fail if one cannot be established. This is the default behavior." },
{ "tls allow", "Use TLS for the connection if it is available." }, { "tls allow", "Use TLS for the connection if it is available." },
{ "tls trust", "Force TLS connection and trust the server's certificate." }, { "tls trust", "Force TLS connection and trust the server's certificate." },
{ "tls legacy", "Use legacy TLS for the connection. This forces TLS just after the TCP connection is established. Use when a server doesn't support STARTTLS." }, { "tls direct", CMD_TLS_DIRECT },
{ "tls disable", "Disable TLS for the connection." }) { "tls disable", "Disable TLS for the connection." },
{ "tls legacy", CMD_TLS_LEGACY })
CMD_EXAMPLES( CMD_EXAMPLES(
"/register odin valhalla.edda ", "/register odin valhalla.edda ",
"/register freyr vanaheimr.edda port 5678", "/register freyr vanaheimr.edda port 5678",

View File

@@ -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_default(ProfWin* window, const char* inp);
static gboolean _cmd_execute_alias(ProfWin* window, const char* const inp, gboolean* ran); static gboolean _cmd_execute_alias(ProfWin* window, const char* const inp, gboolean* ran);
static gboolean 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); _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. * @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] == '/') { if (inp[0] == '/') {
auto_char char* inp_cpy = strdup(inp); auto_char char* inp_cpy = strdup(inp);
char* command = strtok(inp_cpy, " "); 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, '?'); char* question_mark = strchr(command, '?');
if (question_mark) { if (wants_help || question_mark) {
*question_mark = '\0'; *question_mark = '\0';
auto_gchar gchar* fakeinp = g_strdup_printf("/help %s", command + 1); auto_gchar gchar* fakeinp = g_strdup_printf("/help %s", command + 1);
if (fakeinp) { 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* altdomain = g_hash_table_lookup(options, "server");
char* tls_policy = g_hash_table_lookup(options, "tls"); 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_bad_cmd_usage(command);
cons_show(""); cons_show("");
options_destroy(options); 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"); 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_bad_cmd_usage(command);
cons_show(""); cons_show("");
options_destroy(options); options_destroy(options);
@@ -785,7 +731,7 @@ _account_set_nick(char* account_name, char* nick)
gboolean gboolean
_account_set_otr(char* account_name, char* policy) _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); accounts_set_otr_policy(account_name, policy);
cons_show("Updated OTR policy for account %s: %s", account_name, policy); cons_show("Updated OTR policy for account %s: %s", account_name, policy);
cons_show(""); cons_show("");
@@ -877,7 +823,7 @@ _account_set_theme(char* account_name, char* theme)
gboolean gboolean
_account_set_tls(char* account_name, char* policy) _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); accounts_set_tls_policy(account_name, policy);
cons_show("Updated TLS policy for account %s: %s", account_name, policy); cons_show("Updated TLS policy for account %s: %s", account_name, policy);
cons_show(""); cons_show("");
@@ -888,7 +834,7 @@ _account_set_tls(char* account_name, char* policy)
gboolean gboolean
_account_set_auth(char* account_name, char* policy) _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); accounts_set_auth_policy(account_name, policy);
cons_show("Updated auth policy for account %s: %s", account_name, policy); cons_show("Updated auth policy for account %s: %s", account_name, policy);
cons_show(""); cons_show("");
@@ -1829,7 +1775,7 @@ _who_room(ProfWin* window, const char* const command, gchar** args)
} }
// bad arg // 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); cons_bad_cmd_usage(command);
return; return;
} }
@@ -1838,7 +1784,7 @@ _who_room(ProfWin* window, const char* const command, gchar** args)
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK); assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
// presence filter // 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]; gchar* presence = args[0];
GList* occupants = muc_roster(mucwin->roomjid); GList* occupants = muc_roster(mucwin->roomjid);
@@ -1937,7 +1883,7 @@ _who_roster(ProfWin* window, const char* const command, gchar** args)
gchar* presence = args[0]; gchar* presence = args[0];
// bad arg // 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); cons_bad_cmd_usage(command);
return; return;
} }
@@ -3771,7 +3717,7 @@ cmd_form_field(ProfWin* window, char* tag, gchar** args)
if (cmd) { if (cmd) {
value = args[1]; 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:"); win_println(window, THEME_DEFAULT, "-", "Invalid command, usage:");
confwin_field_help(confwin, tag); confwin_field_help(confwin, tag);
win_println(window, THEME_DEFAULT, "-", ""); win_println(window, THEME_DEFAULT, "-", "");
@@ -3825,7 +3771,7 @@ cmd_form_field(ProfWin* window, char* tag, gchar** args)
if (cmd) { if (cmd) {
value = args[1]; 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:"); win_println(window, THEME_DEFAULT, "-", "Invalid command, usage:");
confwin_field_help(confwin, tag); confwin_field_help(confwin, tag);
win_println(window, THEME_DEFAULT, "-", ""); win_println(window, THEME_DEFAULT, "-", "");
@@ -3876,7 +3822,7 @@ cmd_form_field(ProfWin* window, char* tag, gchar** args)
if (cmd) { if (cmd) {
value = args[1]; 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:"); win_println(window, THEME_DEFAULT, "-", "Invalid command, usage:");
confwin_field_help(confwin, tag); confwin_field_help(confwin, tag);
win_println(window, THEME_DEFAULT, "-", ""); win_println(window, THEME_DEFAULT, "-", "");
@@ -3932,7 +3878,7 @@ cmd_form(ProfWin* window, const char* const command, gchar** args)
return TRUE; 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); cons_bad_cmd_usage(command);
return TRUE; return TRUE;
} }
@@ -4177,7 +4123,7 @@ cmd_affiliation(ProfWin* window, const char* const command, gchar** args)
} }
gchar* affiliation = args[1]; 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); cons_bad_cmd_usage(command);
return TRUE; return TRUE;
} }
@@ -4252,7 +4198,7 @@ cmd_role(ProfWin* window, const char* const command, gchar** args)
} }
gchar* role = args[1]; 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); cons_bad_cmd_usage(command);
return TRUE; return TRUE;
} }
@@ -5196,13 +5142,13 @@ cmd_console(ProfWin* window, const char* const command, gchar** args)
{ {
gboolean isMuc = (g_strcmp0(args[0], "muc") == 0); 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); cons_bad_cmd_usage(command);
return TRUE; return TRUE;
} }
gchar* setting = args[1]; 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))) { if (!(isMuc && (g_strcmp0(setting, "mention") == 0))) {
cons_bad_cmd_usage(command); cons_bad_cmd_usage(command);
return TRUE; return TRUE;
@@ -6375,12 +6321,12 @@ cmd_ping(ProfWin* window, const char* const command, gchar** args)
gboolean gboolean
cmd_autoaway(ProfWin* window, const char* const command, gchar** args) 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; return TRUE;
} }
if (g_strcmp0(args[0], "mode") == 0) { 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]); prefs_set_string(PREF_AUTOAWAY_MODE, args[1]);
cons_show("Auto away mode set to: %s.", 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]; 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; return TRUE;
} }
@@ -8911,7 +8857,7 @@ cmd_omemo_policy(ProfWin* window, const char* const command, gchar** args)
} }
char* choice = args[1]; 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; 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"); 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_bad_cmd_usage(command);
cons_show(""); cons_show("");
options_destroy(options); options_destroy(options);

View File

@@ -64,6 +64,7 @@
#include "log.h" #include "log.h"
#include "common.h" #include "common.h"
#include "config/files.h" #include "config/files.h"
#include "ui/ui.h"
#ifdef HAVE_GIT_VERSION #ifdef HAVE_GIT_VERSION
#include "gitversion.h" #include "gitversion.h"
@@ -361,6 +362,66 @@ strtoi_range(const char* str, int* saveptr, int min, int max, gchar** err_msg)
return TRUE; return TRUE;
} }
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;
}
gboolean
valid_tls_policy_option(const char* is)
{
return string_matches_one_of("TLS policy", is, TRUE, "force", "allow", "trust", "disable", "legacy", "direct", NULL);
}
int int
utf8_display_len(const char* const str) utf8_display_len(const char* const str)
{ {

View File

@@ -189,6 +189,9 @@ char* str_replace(const char* string, const char* substr, const char* replacemen
gboolean strtoi_range(const char* str, int* saveptr, int min, int max, char** err_msg); gboolean strtoi_range(const char* str, int* saveptr, int min, int max, char** err_msg);
int utf8_display_len(const char* const str); int utf8_display_len(const char* const str);
gboolean string_matches_one_of(const char* what, const char* is, gboolean is_can_be_null, const char* first, ...) __attribute__((sentinel));
gboolean valid_tls_policy_option(const char* is);
char* release_get_latest(void); char* release_get_latest(void);
gboolean release_is_new(char* found_version); gboolean release_is_new(char* found_version);

View File

@@ -322,7 +322,7 @@ accounts_get_account(const char* const name)
} }
gchar* tls_policy = g_key_file_get_string(accounts, name, "tls.policy", NULL); gchar* tls_policy = g_key_file_get_string(accounts, name, "tls.policy", NULL);
if (tls_policy && ((g_strcmp0(tls_policy, "force") != 0) && (g_strcmp0(tls_policy, "allow") != 0) && (g_strcmp0(tls_policy, "trust") != 0) && (g_strcmp0(tls_policy, "disable") != 0) && (g_strcmp0(tls_policy, "legacy") != 0))) { if (tls_policy && !valid_tls_policy_option(tls_policy)) {
g_free(tls_policy); g_free(tls_policy);
tls_policy = NULL; tls_policy = NULL;
} }

View File

@@ -53,8 +53,7 @@ _cafile_name(void)
if (!create_dir(certs_dir)) { if (!create_dir(certs_dir)) {
return NULL; return NULL;
} }
gchar* filename = g_strdup_printf("%s/CAfile.pem", certs_dir); return g_strdup_printf("%s/CAfile.pem", certs_dir);
return filename;
} }
void void

View File

@@ -662,11 +662,9 @@ otr_get_policy(const char* const recipient)
prof_otrpolicy_t result = PROF_OTRPOLICY_MANUAL; prof_otrpolicy_t result = PROF_OTRPOLICY_MANUAL;
if (g_strcmp0(account->otr_policy, "manual") == 0) { if (g_strcmp0(account->otr_policy, "manual") == 0) {
result = PROF_OTRPOLICY_MANUAL; result = PROF_OTRPOLICY_MANUAL;
} } else if (g_strcmp0(account->otr_policy, "opportunistic") == 0) {
if (g_strcmp0(account->otr_policy, "opportunistic") == 0) {
result = PROF_OTRPOLICY_OPPORTUNISTIC; result = PROF_OTRPOLICY_OPPORTUNISTIC;
} } else if (g_strcmp0(account->otr_policy, "always") == 0) {
if (g_strcmp0(account->otr_policy, "always") == 0) {
result = PROF_OTRPOLICY_ALWAYS; result = PROF_OTRPOLICY_ALWAYS;
} }
account_free(account); account_free(account);

View File

@@ -2365,6 +2365,7 @@ cons_help(void)
cons_show_padded(pad, "/help commands ui : List commands for manipulating the user interface."); cons_show_padded(pad, "/help commands ui : List commands for manipulating the user interface.");
cons_show_padded(pad, "/help commands plugins : List plugin commands."); cons_show_padded(pad, "/help commands plugins : List plugin commands.");
cons_show_padded(pad, "/help [command] : Detailed help on a specific command."); cons_show_padded(pad, "/help [command] : Detailed help on a specific command.");
cons_show_padded(pad, "/[command]? : Shortcut to get detailed help on a specific command.");
cons_show_padded(pad, "/help navigation : How to navigate around Profanity."); cons_show_padded(pad, "/help navigation : How to navigate around Profanity.");
cons_show(""); cons_show("");

View File

@@ -215,7 +215,7 @@ _conn_apply_settings(const char* const jid, const char* const passwd, const char
flags |= XMPP_CONN_FLAG_TRUST_TLS; flags |= XMPP_CONN_FLAG_TRUST_TLS;
} else if (g_strcmp0(tls_policy, "disable") == 0) { } else if (g_strcmp0(tls_policy, "disable") == 0) {
flags |= XMPP_CONN_FLAG_DISABLE_TLS; flags |= XMPP_CONN_FLAG_DISABLE_TLS;
} else if (g_strcmp0(tls_policy, "legacy") == 0) { } else if (g_strcmp0(tls_policy, "direct") == 0 || g_strcmp0(tls_policy, "legacy") == 0) {
flags |= XMPP_CONN_FLAG_LEGACY_SSL; flags |= XMPP_CONN_FLAG_LEGACY_SSL;
} }