about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--.github/workflows/main.yml23
-rw-r--r--.gitignore5
-rw-r--r--Makefile.am6
-rw-r--r--docs/profanity.144
-rw-r--r--src/command/cmd_defs.c2
-rw-r--r--src/command/cmd_funcs.c125
-rw-r--r--src/config/preferences.c3
-rw-r--r--src/ui/core.c4
-rw-r--r--src/ui/inputwin.c8
-rw-r--r--src/ui/window.c7
-rw-r--r--src/xmpp/connection.c215
-rw-r--r--tests/unittests/test_cmd_account.c3
12 files changed, 228 insertions, 217 deletions
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index daae84d0..dc73b14b 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -34,3 +34,26 @@ jobs:
           # Ensure that "keg-only" Homebrew versions are used.
           PKG_CONFIG_PATH: "/usr/local/opt/ncurses/lib/pkgconfig:/usr/local/opt/expat/lib/pkgconfig:/usr/local/opt/curl/lib/pkgconfig:/usr/local/opt/openssl/lib/pkgconfig:/usr/local/opt/libffi/lib/pkgconfig:/usr/local/opt/sqlite/lib/pkgconfig:$PKG_CONFIG_PATH"
         run: ./ci-build.sh
+
+  code-style:
+    runs-on: ubuntu-20.04
+    name: Check coding style
+    continue-on-error: true
+    steps:
+      - uses: actions/checkout@v2
+      - name: install dependencies
+        run: |
+          sudo apt update
+          sudo apt install -y --no-install-recommends autoconf autoconf-archive automake expect gcc git libcmocka-dev libcurl3-dev libgcrypt-dev libglib2.0-dev libgpgme11-dev libgtk2.0-dev libmicrohttpd-dev libncursesw5-dev libnotify-dev libotr5-dev libreadline-dev libsignal-protocol-c-dev libssl-dev libtool libxss-dev make pkg-config python3-dev python-dev-is-python3 libsqlite3-dev
+      - name: Install libstrophe
+        run: |
+          git clone https://github.com/strophe/libstrophe ../libstrophe
+          cd ../libstrophe && ./bootstrap.sh && ./configure && make -j$(nproc) && sudo make install
+      - name: Configure
+        run: |
+          ./bootstrap.sh
+          ./configure
+      - name: Check style
+        run: |
+          make format
+          git diff --exit-code
diff --git a/.gitignore b/.gitignore
index e06f5136..446a3868 100644
--- a/.gitignore
+++ b/.gitignore
@@ -13,6 +13,9 @@ profanity.workspace
 compile_commands.json
 .tern-port
 .tern-project
+.cproject
+.project
+.settings/
 
 # autotools
 .libs/
@@ -25,6 +28,7 @@ build-aux/
 config.log
 config.status
 configure
+configure*~
 libprofanity.la
 libtool
 m4/
@@ -82,6 +86,7 @@ python3/
 
 .DS_Store
 *.bak
+*.orig
 breaks
 
 *.tar.*
diff --git a/Makefile.am b/Makefile.am
index cfeb4f7d..0e35a518 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -221,7 +221,7 @@ icons_sources = $(top_srcdir)/icons/*
 
 script_sources = bootstrap.sh
 
-man_sources = $(wildcard docs/profanity*.1)
+man1_sources = $(wildcard $(top_srcdir)/docs/profanity*.1)
 
 if BUILD_PGP
 core_sources += $(pgp_sources)
@@ -289,9 +289,9 @@ tests_unittests_unittests_LDADD = -lcmocka
 #endif
 #endif
 
-man_MANS = $(man_sources)
+man1_MANS = $(man1_sources)
 
-EXTRA_DIST = $(man_sources) $(icons_sources) $(themes_sources) $(script_sources) profrc.example theme_template LICENSE.txt README.md CHANGELOG
+EXTRA_DIST = $(man1_sources) $(icons_sources) $(themes_sources) $(script_sources) profrc.example theme_template LICENSE.txt README.md CHANGELOG
 
 # Ship API documentation with `make dist`
 EXTRA_DIST += \
diff --git a/docs/profanity.1 b/docs/profanity.1
index beb17d8b..42fe50dc 100644
--- a/docs/profanity.1
+++ b/docs/profanity.1
@@ -41,8 +41,17 @@ Specify which theme to use.
 .I THEME
 must be one of the themes installed in $XDG_CONFIG_HOME/profanity/themes
 .SH KEYBINDINGS
-.BI ALT+1..Alt-0
-Choose window 1..0.
+.TP
+.BR Tab , " Shift+Tab"
+Tab completion next, previous.  Works for commands, nicks and
+quotes (when input line starts with
+.BR > ).
+.TP
+.BR ALT+1..Alt-0 " or " F1..F10
+Choose window 1..10.
+.TP
+.BR ALT+q..Alt-p " (in QWERTY layout)"
+Choose window 11..20.
 .TP
 .BI ALT+LEFT
 Choose previous chat window.
@@ -70,13 +79,38 @@ Mark current window for later reading with an attention flag.
 .TP
 .BI ALT+m
 Switch between windows marked with the attention flag.
+.TP
+.BI ALT+c
+Run external editor (see
+.BR profanity-editor (1))
+for current input line.
+.TP
+.BI CTRL+DOWN
+Store current input line in history but do not execute it.
+.PP
+.I Note:
+Profanity is using GNU Readline library to handle input so
+default configuration file
+.I ~/.inputrc
+affects operation. In addition to that
+.I $XDG_CONFIG_HOME/profanity/inputrc
+is read after all default keybindigs are set so one can override
+or add settings there. For reference, see Readline documentation:
+.I "info readline ""Command Line Editing"" ""Readline Init File"" ""Readline Init File Syntax"""
+and the list of available Profanity commands in
+.IR inputwin.c .
 .SH USING PROFANITY
 The user guide can be found at <https://profanity-im.github.io/userguide.html>.
 .SH SEE ALSO
 .B Profanity
-itself has a lot of built\-in help. Check the /help command for more information.
-Type "/help help" for information on how to use help itself.
-Profanity ships with one man page for each built-in command. For /account there is man profanity-account.
+itself has a lot of built\-in help. Check the
+.I /help
+command for more information.  Type "/help help" for information
+on how to use help itself.  Profanity ships with one man page for
+each built-in command, e.g. there is
+.BR profanity-account (1)
+for
+.IR /account .
 .SH CONFIGURATION
 Configuration for
 .B Profanity
diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c
index 24d4a737..281d21c6 100644
--- a/src/command/cmd_defs.c
+++ b/src/command/cmd_defs.c
@@ -2111,7 +2111,7 @@ static struct cmd_t command_defs[] = {
               { "set <account> tls disable", "Disable TLS for the connection." },
               { "set <account> auth default", "Use default authentication process." },
               { "set <account> auth legacy", "Allow legacy authentication." },
-              { "set <account> <theme>", "Set the UI theme for the account." },
+              { "set <account> theme <theme>", "Set the UI theme for the account." },
               { "clear <account> server", "Remove the server setting for this account." },
               { "clear <account> port", "Remove the port setting for this account." },
               { "clear <account> password", "Remove the password setting for this account." },
diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c
index 685369c4..4fd9d20b 100644
--- a/src/command/cmd_funcs.c
+++ b/src/command/cmd_funcs.c
@@ -124,6 +124,62 @@ static void _who_roster(ProfWin* window, const char* const command, gchar** args
 static gboolean _cmd_execute(ProfWin* window, const char* const command, const char* const 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
+_string_matches_one_of(const char* what, const char* is, bool is_can_be_null, const char* first, ...) __attribute__((sentinel));
+
+static gboolean
+_string_matches_one_of(const char* what, const char* is, bool 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;
+}
 
 /*
  * Take a line of input and process it, return TRUE if profanity is to
@@ -339,7 +395,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 (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 (!_string_matches_one_of("TLS policy", tls_policy, TRUE, "force", "allow", "trust", "disable", "legacy", NULL)) {
         cons_bad_cmd_usage(command);
         cons_show("");
         options_destroy(options);
@@ -347,7 +403,7 @@ cmd_connect(ProfWin* window, const char* const command, gchar** args)
     }
 
     char* auth_policy = g_hash_table_lookup(options, "auth");
-    if (auth_policy && (g_strcmp0(auth_policy, "default") != 0) && (g_strcmp0(auth_policy, "legacy") != 0)) {
+    if (!_string_matches_one_of("Auth policy", auth_policy, TRUE, "default", "legacy", NULL)) {
         cons_bad_cmd_usage(command);
         cons_show("");
         options_destroy(options);
@@ -732,11 +788,7 @@ _account_set_nick(char* account_name, char* nick)
 gboolean
 _account_set_otr(char* account_name, char* policy)
 {
-    if ((g_strcmp0(policy, "manual") != 0)
-        && (g_strcmp0(policy, "opportunistic") != 0)
-        && (g_strcmp0(policy, "always") != 0)) {
-        cons_show("OTR policy must be one of: manual, opportunistic or always.");
-    } else {
+    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("");
@@ -821,13 +873,7 @@ _account_set_theme(char* account_name, char* theme)
 gboolean
 _account_set_tls(char* account_name, char* policy)
 {
-    if ((g_strcmp0(policy, "force") != 0)
-        && (g_strcmp0(policy, "allow") != 0)
-        && (g_strcmp0(policy, "trust") != 0)
-        && (g_strcmp0(policy, "disable") != 0)
-        && (g_strcmp0(policy, "legacy") != 0)) {
-        cons_show("TLS policy must be one of: force, allow, legacy or disable.");
-    } else {
+    if (_string_matches_one_of("TLS policy", policy, FALSE, "force", "allow", "trust", "disable", "legacy", NULL)) {
         accounts_set_tls_policy(account_name, policy);
         cons_show("Updated TLS policy for account %s: %s", account_name, policy);
         cons_show("");
@@ -838,10 +884,7 @@ _account_set_tls(char* account_name, char* policy)
 gboolean
 _account_set_auth(char* account_name, char* policy)
 {
-    if ((g_strcmp0(policy, "default") != 0)
-        && (g_strcmp0(policy, "legacy") != 0)) {
-        cons_show("Auth policy must be either default or legacy.");
-    } else {
+    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("");
@@ -1763,7 +1806,7 @@ _who_room(ProfWin* window, const char* const command, gchar** args)
     }
 
     // bad arg
-    if (args[0] && (g_strcmp0(args[0], "online") != 0) && (g_strcmp0(args[0], "available") != 0) && (g_strcmp0(args[0], "unavailable") != 0) && (g_strcmp0(args[0], "away") != 0) && (g_strcmp0(args[0], "chat") != 0) && (g_strcmp0(args[0], "xa") != 0) && (g_strcmp0(args[0], "dnd") != 0) && (g_strcmp0(args[0], "any") != 0) && (g_strcmp0(args[0], "moderator") != 0) && (g_strcmp0(args[0], "participant") != 0) && (g_strcmp0(args[0], "visitor") != 0) && (g_strcmp0(args[0], "owner") != 0) && (g_strcmp0(args[0], "admin") != 0) && (g_strcmp0(args[0], "member") != 0) && (g_strcmp0(args[0], "outcast") != 0) && (g_strcmp0(args[0], "none") != 0)) {
+    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;
     }
@@ -1772,7 +1815,7 @@ _who_room(ProfWin* window, const char* const command, gchar** args)
     assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
 
     // presence filter
-    if (args[0] == NULL || (g_strcmp0(args[0], "online") == 0) || (g_strcmp0(args[0], "available") == 0) || (g_strcmp0(args[0], "unavailable") == 0) || (g_strcmp0(args[0], "away") == 0) || (g_strcmp0(args[0], "chat") == 0) || (g_strcmp0(args[0], "xa") == 0) || (g_strcmp0(args[0], "dnd") == 0) || (g_strcmp0(args[0], "any") == 0)) {
+    if (_string_matches_one_of(NULL, args[0], TRUE, "online", "available", "unavailable", "away", "chat", "xa", "dnd", "any", NULL)) {
 
         char* presence = args[0];
         GList* occupants = muc_roster(mucwin->roomjid);
@@ -1871,16 +1914,7 @@ _who_roster(ProfWin* window, const char* const command, gchar** args)
     char* presence = args[0];
 
     // bad arg
-    if (presence
-        && (strcmp(presence, "online") != 0)
-        && (strcmp(presence, "available") != 0)
-        && (strcmp(presence, "unavailable") != 0)
-        && (strcmp(presence, "offline") != 0)
-        && (strcmp(presence, "away") != 0)
-        && (strcmp(presence, "chat") != 0)
-        && (strcmp(presence, "xa") != 0)
-        && (strcmp(presence, "dnd") != 0)
-        && (strcmp(presence, "any") != 0)) {
+    if (!_string_matches_one_of(NULL, presence, TRUE, "online", "available", "unavailable", "offline", "away", "chat", "xa", "dnd", "any", NULL)) {
         cons_bad_cmd_usage(command);
         return;
     }
@@ -3773,7 +3807,7 @@ cmd_form_field(ProfWin* window, char* tag, gchar** args)
             if (cmd) {
                 value = args[1];
             }
-            if ((g_strcmp0(cmd, "add") != 0) && (g_strcmp0(cmd, "remove"))) {
+            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, "-", "");
@@ -3827,7 +3861,7 @@ cmd_form_field(ProfWin* window, char* tag, gchar** args)
             if (cmd) {
                 value = args[1];
             }
-            if ((g_strcmp0(cmd, "add") != 0) && (g_strcmp0(cmd, "remove"))) {
+            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, "-", "");
@@ -3878,7 +3912,7 @@ cmd_form_field(ProfWin* window, char* tag, gchar** args)
             if (cmd) {
                 value = args[1];
             }
-            if ((g_strcmp0(cmd, "add") != 0) && (g_strcmp0(cmd, "remove"))) {
+            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, "-", "");
@@ -3934,7 +3968,7 @@ cmd_form(ProfWin* window, const char* const command, gchar** args)
         return TRUE;
     }
 
-    if ((g_strcmp0(args[0], "submit") != 0) && (g_strcmp0(args[0], "cancel") != 0) && (g_strcmp0(args[0], "show") != 0) && (g_strcmp0(args[0], "help") != 0)) {
+    if (!_string_matches_one_of(NULL, args[0], FALSE, "submit", "cancel", "show", "help", NULL)) {
         cons_bad_cmd_usage(command);
         return TRUE;
     }
@@ -4183,7 +4217,7 @@ cmd_affiliation(ProfWin* window, const char* const command, gchar** args)
     }
 
     char* affiliation = args[1];
-    if (affiliation && (g_strcmp0(affiliation, "owner") != 0) && (g_strcmp0(affiliation, "admin") != 0) && (g_strcmp0(affiliation, "member") != 0) && (g_strcmp0(affiliation, "none") != 0) && (g_strcmp0(affiliation, "outcast") != 0)) {
+    if (!_string_matches_one_of(NULL, affiliation, TRUE, "owner", "admin", "member", "none", "outcast", NULL)) {
         cons_bad_cmd_usage(command);
         return TRUE;
     }
@@ -4258,7 +4292,7 @@ cmd_role(ProfWin* window, const char* const command, gchar** args)
     }
 
     char* role = args[1];
-    if (role && (g_strcmp0(role, "visitor") != 0) && (g_strcmp0(role, "participant") != 0) && (g_strcmp0(role, "moderator") != 0) && (g_strcmp0(role, "none") != 0)) {
+    if (!_string_matches_one_of(NULL, role, TRUE, "visitor", "participant", "moderator", "none", NULL)) {
         cons_bad_cmd_usage(command);
         return TRUE;
     }
@@ -5242,13 +5276,13 @@ cmd_console(ProfWin* window, const char* const command, gchar** args)
 {
     gboolean isMuc = (g_strcmp0(args[0], "muc") == 0);
 
-    if ((g_strcmp0(args[0], "chat") != 0) && !isMuc && (g_strcmp0(args[0], "private") != 0)) {
+    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 ((g_strcmp0(setting, "all") != 0) && (g_strcmp0(setting, "first") != 0) && (g_strcmp0(setting, "none") != 0)) {
+    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;
@@ -6558,15 +6592,12 @@ cmd_ping(ProfWin* window, const char* const command, gchar** args)
 gboolean
 cmd_autoaway(ProfWin* window, const char* const command, gchar** args)
 {
-    if ((g_strcmp0(args[0], "mode") != 0) && (g_strcmp0(args[0], "time") != 0) && (g_strcmp0(args[0], "message") != 0) && (g_strcmp0(args[0], "check") != 0)) {
-        cons_show("Setting must be one of 'mode', 'time', 'message' or 'check'");
+    if (!_string_matches_one_of("Setting", args[0], FALSE, "mode", "time", "message", "check", NULL)) {
         return TRUE;
     }
 
     if (g_strcmp0(args[0], "mode") == 0) {
-        if ((g_strcmp0(args[1], "idle") != 0) && (g_strcmp0(args[1], "away") != 0) && (g_strcmp0(args[1], "off") != 0)) {
-            cons_show("Mode must be one of 'idle', 'away' or 'off'");
-        } else {
+        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]);
         }
@@ -7752,8 +7783,7 @@ cmd_otr_policy(ProfWin* window, const char* const command, gchar** args)
     }
 
     char* choice = args[1];
-    if ((g_strcmp0(choice, "manual") != 0) && (g_strcmp0(choice, "opportunistic") != 0) && (g_strcmp0(choice, "always") != 0)) {
-        cons_show("OTR policy can be set to: manual, opportunistic or always.");
+    if (!_string_matches_one_of("OTR policy", choice, FALSE, "manual", "opportunistic", "always", NULL)) {
         return TRUE;
     }
 
@@ -8942,8 +8972,7 @@ cmd_omemo_policy(ProfWin* window, const char* const command, gchar** args)
     }
 
     char* choice = args[1];
-    if ((g_strcmp0(choice, "manual") != 0) && (g_strcmp0(choice, "automatic") != 0) && (g_strcmp0(choice, "always") != 0)) {
-        cons_show("OMEMO policy can be set to: manual, automatic or always.");
+    if (!_string_matches_one_of("OMEMO policy", choice, FALSE, "manual", "automatic", "always", NULL)) {
         return TRUE;
     }
 
@@ -9556,7 +9585,7 @@ cmd_register(ProfWin* window, const char* const command, gchar** args)
     }
 
     char* tls_policy = g_hash_table_lookup(options, "tls");
-    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 (!_string_matches_one_of("TLS policy", tls_policy, TRUE, "force", "allow", "trust", "disable", "legacy", NULL)) {
         cons_bad_cmd_usage(command);
         cons_show("");
         options_destroy(options);
diff --git a/src/config/preferences.c b/src/config/preferences.c
index 358c5fbf..43c91b54 100644
--- a/src/config/preferences.c
+++ b/src/config/preferences.c
@@ -2277,7 +2277,8 @@ _get_default_string(preference_t pref)
         return "xdg-open";
     case PREF_URL_OPEN_CMD:
         return "xdg-open %u";
-    case PREF_COMPOSE_EDITOR: {
+    case PREF_COMPOSE_EDITOR:
+    {
         gchar* editor = getenv("EDITOR");
         return editor ? editor : "vim";
     }
diff --git a/src/ui/core.c b/src/ui/core.c
index 3b10888b..5ce42e50 100644
--- a/src/ui/core.c
+++ b/src/ui/core.c
@@ -144,10 +144,8 @@ ui_update(void)
     doupdate();
 
     if (perform_resize) {
-        signal(SIGWINCH, SIG_IGN);
-        ui_resize();
         perform_resize = FALSE;
-        signal(SIGWINCH, ui_sigwinch_handler);
+        ui_resize();
     }
 }
 
diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c
index 6fffad22..4a6cae27 100644
--- a/src/ui/inputwin.c
+++ b/src/ui/inputwin.c
@@ -434,13 +434,18 @@ _inp_rl_addfuncs(void)
     rl_add_funmap_entry("prof_win_prev", _inp_rl_win_prev_handler);
     rl_add_funmap_entry("prof_win_next", _inp_rl_win_next_handler);
     rl_add_funmap_entry("prof_win_next_unread", _inp_rl_win_next_unread_handler);
+    rl_add_funmap_entry("prof_win_set_attention", _inp_rl_win_attention_handler);
+    rl_add_funmap_entry("prof_win_attention_next", _inp_rl_win_attention_next_handler);
     rl_add_funmap_entry("prof_win_pageup", _inp_rl_win_pageup_handler);
     rl_add_funmap_entry("prof_win_pagedown", _inp_rl_win_pagedown_handler);
     rl_add_funmap_entry("prof_subwin_pageup", _inp_rl_subwin_pageup_handler);
     rl_add_funmap_entry("prof_subwin_pagedown", _inp_rl_subwin_pagedown_handler);
+    rl_add_funmap_entry("prof_complete_next", _inp_rl_tab_handler);
+    rl_add_funmap_entry("prof_complete_prev", _inp_rl_shift_tab_handler);
     rl_add_funmap_entry("prof_win_clear", _inp_rl_win_clear_handler);
     rl_add_funmap_entry("prof_win_close", _inp_rl_win_close_handler);
     rl_add_funmap_entry("prof_send_to_editor", _inp_rl_send_to_editor);
+    rl_add_funmap_entry("prof_cut_to_history", _inp_rl_down_arrow_handler);
 }
 
 // Readline callbacks
@@ -483,10 +488,12 @@ _inp_rl_startup_hook(void)
     rl_bind_keyseq("\\e[1;9D", _inp_rl_win_prev_handler);
     rl_bind_keyseq("\\e[1;3D", _inp_rl_win_prev_handler);
     rl_bind_keyseq("\\e\\e[D", _inp_rl_win_prev_handler);
+    rl_bind_keyseq("\\e\\eOD", _inp_rl_win_prev_handler);
 
     rl_bind_keyseq("\\e[1;9C", _inp_rl_win_next_handler);
     rl_bind_keyseq("\\e[1;3C", _inp_rl_win_next_handler);
     rl_bind_keyseq("\\e\\e[C", _inp_rl_win_next_handler);
+    rl_bind_keyseq("\\e\\eOC", _inp_rl_win_next_handler);
 
     rl_bind_keyseq("\\ea", _inp_rl_win_next_unread_handler);
     rl_bind_keyseq("\\ev", _inp_rl_win_attention_handler);
@@ -510,6 +517,7 @@ _inp_rl_startup_hook(void)
     rl_bind_keyseq("\\e[Z", _inp_rl_shift_tab_handler);
 
     rl_bind_keyseq("\\e[1;5B", _inp_rl_down_arrow_handler); // ctrl+arrow down
+    rl_bind_keyseq("\\eOb", _inp_rl_down_arrow_handler);
 
     // unbind unwanted mappings
     rl_bind_keyseq("\\e=", NULL);
diff --git a/src/ui/window.c b/src/ui/window.c
index 7952497c..5ba2281d 100644
--- a/src/ui/window.c
+++ b/src/ui/window.c
@@ -415,6 +415,7 @@ win_get_last_sent_message(ProfWin* window)
         ProfMucWin* mucwin = (ProfMucWin*)window;
         assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
         last_message = mucwin->last_message;
+        break;
     }
     default:
         break;
@@ -1578,7 +1579,7 @@ _win_print_internal(ProfWin* window, const char* show_char, int pad_indent, GDat
 
         char* color_pref = prefs_get_string(PREF_COLOR_NICK);
         if (color_pref != NULL && (strcmp(color_pref, "false") != 0)) {
-            if (flags & NO_ME || (!(flags & NO_ME) && prefs_get_boolean(PREF_COLOR_NICK_OWN))) {
+            if ((flags & NO_ME) || (!(flags & NO_ME) && prefs_get_boolean(PREF_COLOR_NICK_OWN))) {
                 colour = theme_hash_attrs(from);
             }
         }
@@ -2033,8 +2034,8 @@ win_quote_autocomplete(ProfWin* window, const char* const input, gboolean previo
         return NULL;
     }
 
-    gchar **parts = g_strsplit(result, "\n", -1);
-    gchar *quoted_result = g_strjoinv("\n> ", parts);
+    gchar** parts = g_strsplit(result, "\n", -1);
+    gchar* quoted_result = g_strjoinv("\n> ", parts);
 
     GString* replace_with = g_string_new("> ");
     g_string_append(replace_with, quoted_result);
diff --git a/src/xmpp/connection.c b/src/xmpp/connection.c
index 54bb1449..9505622a 100644
--- a/src/xmpp/connection.c
+++ b/src/xmpp/connection.c
@@ -58,7 +58,6 @@
 
 typedef struct prof_conn_t
 {
-    xmpp_log_t* xmpp_log;
     xmpp_ctx_t* xmpp_ctx;
     xmpp_conn_t* xmpp_conn;
     gboolean xmpp_in_event_loop;
@@ -82,25 +81,51 @@ static ProfConnection conn;
 static gchar* profanity_instance_id = NULL;
 static gchar* prof_identifier = NULL;
 
-static xmpp_log_t* _xmpp_get_file_logger(void);
 static void _xmpp_file_logger(void* const userdata, const xmpp_log_level_t level, const char* const area, const char* const msg);
 
 static void _connection_handler(xmpp_conn_t* const xmpp_conn, const xmpp_conn_event_t status, const int error,
                                 xmpp_stream_error_t* const stream_error, void* const userdata);
 
-TLSCertificate* _xmppcert_to_profcert(const xmpp_tlscert_t* xmpptlscert);
+static TLSCertificate* _xmppcert_to_profcert(const xmpp_tlscert_t* xmpptlscert);
 static int _connection_certfail_cb(const xmpp_tlscert_t* xmpptlscert, const char* errormsg);
 
 static void _random_bytes_init(void);
 static void _random_bytes_close(void);
 static void _compute_identifier(const char* barejid);
 
+static void*
+_xmalloc(size_t size, void* userdata)
+{
+    void* ret = malloc(size);
+    assert(ret != NULL);
+    return ret;
+}
+
+static void
+_xfree(void* p, void* userdata)
+{
+    free(p);
+}
+
+static void*
+_xrealloc(void* p, size_t size, void* userdata)
+{
+    void* ret = realloc(p, size);
+    assert(ret != NULL);
+    return ret;
+}
+
+static xmpp_mem_t prof_mem = {
+    _xmalloc, _xfree, _xrealloc, NULL
+};
+static xmpp_log_t prof_log = {
+    _xmpp_file_logger, NULL
+};
+
 void
 connection_init(void)
 {
     xmpp_initialize();
-    conn.xmpp_conn = NULL;
-    conn.xmpp_ctx = NULL;
     conn.xmpp_in_event_loop = FALSE;
     conn.conn_status = JABBER_DISCONNECTED;
     conn.conn_last_event = XMPP_CONN_DISCONNECT;
@@ -110,6 +135,9 @@ connection_init(void)
     conn.available_resources = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)resource_destroy);
     conn.requested_features = g_hash_table_new_full(g_str_hash, g_str_equal, free, NULL);
 
+    conn.xmpp_ctx = xmpp_ctx_new(&prof_mem, &prof_log);
+    conn.xmpp_conn = xmpp_conn_new(conn.xmpp_ctx);
+
     _random_bytes_init();
 }
 
@@ -125,61 +153,38 @@ void
 connection_shutdown(void)
 {
     connection_clear_data();
+    if (conn.xmpp_conn) {
+        xmpp_conn_release(conn.xmpp_conn);
+        conn.xmpp_conn = NULL;
+    }
+    if (conn.xmpp_ctx) {
+        xmpp_ctx_free(conn.xmpp_ctx);
+        conn.xmpp_ctx = NULL;
+    }
     xmpp_shutdown();
 
-    free(conn.xmpp_log);
-    conn.xmpp_log = NULL;
-
     _random_bytes_close();
 }
 
-jabber_conn_status_t
-connection_connect(const char* const jid, const char* const passwd, const char* const altdomain, int port,
-                   const char* const tls_policy, const char* const auth_policy)
+static gboolean
+_conn_apply_settings(const char* const jid, const char* const passwd, const char* const tls_policy, const char* const auth_policy)
 {
-    long flags;
-
-    assert(jid != NULL);
-    assert(passwd != NULL);
-
     Jid* jidp = jid_create(jid);
     if (jidp == NULL) {
         log_error("Malformed JID not able to connect: %s", jid);
         conn.conn_status = JABBER_DISCONNECTED;
-        return conn.conn_status;
+        return FALSE;
     }
 
     _compute_identifier(jidp->barejid);
     jid_destroy(jidp);
 
-    log_info("Connecting as %s", jid);
-
-    if (conn.xmpp_log) {
-        free(conn.xmpp_log);
-    }
-    conn.xmpp_log = _xmpp_get_file_logger();
-
-    if (conn.xmpp_conn) {
-        xmpp_conn_release(conn.xmpp_conn);
-    }
-    if (conn.xmpp_ctx) {
-        xmpp_ctx_free(conn.xmpp_ctx);
-    }
-    conn.xmpp_ctx = xmpp_ctx_new(NULL, conn.xmpp_log);
-    if (conn.xmpp_ctx == NULL) {
-        log_warning("Failed to get libstrophe ctx during connect");
-        return JABBER_DISCONNECTED;
-    }
     xmpp_ctx_set_verbosity(conn.xmpp_ctx, 0);
-    conn.xmpp_conn = xmpp_conn_new(conn.xmpp_ctx);
-    if (conn.xmpp_conn == NULL) {
-        log_warning("Failed to get libstrophe conn during connect");
-        return JABBER_DISCONNECTED;
-    }
     xmpp_conn_set_jid(conn.xmpp_conn, jid);
-    xmpp_conn_set_pass(conn.xmpp_conn, passwd);
+    if (passwd)
+        xmpp_conn_set_pass(conn.xmpp_conn, passwd);
 
-    flags = xmpp_conn_get_flags(conn.xmpp_conn);
+    long flags = xmpp_conn_get_flags(conn.xmpp_conn);
 
     if (!tls_policy || (g_strcmp0(tls_policy, "force") == 0)) {
         flags |= XMPP_CONN_FLAG_MANDATORY_TLS;
@@ -221,6 +226,19 @@ connection_connect(const char* const jid, const char* const passwd, const char*
 
     xmpp_conn_set_certfail_handler(conn.xmpp_conn, _connection_certfail_cb);
 
+    return TRUE;
+}
+
+jabber_conn_status_t
+connection_connect(const char* const jid, const char* const passwd, const char* const altdomain, int port,
+                   const char* const tls_policy, const char* const auth_policy)
+{
+    assert(jid != NULL);
+    assert(passwd != NULL);
+    log_info("Connecting as %s", jid);
+
+    _conn_apply_settings(jid, passwd, tls_policy, auth_policy);
+
     int connect_status = xmpp_connect_client(
         conn.xmpp_conn,
         altdomain,
@@ -465,69 +483,7 @@ jabber_conn_status_t
 connection_register(const char* const altdomain, int port, const char* const tls_policy,
                     const char* const username, const char* const password)
 {
-    long flags;
-
-    Jid* jidp = jid_create(altdomain);
-    if (jidp == NULL) {
-        log_error("Malformed JID not able to connect: %s", altdomain);
-        conn.conn_status = JABBER_DISCONNECTED;
-        return conn.conn_status;
-    }
-
-    _compute_identifier(jidp->barejid);
-    jid_destroy(jidp);
-
-    if (conn.xmpp_log) {
-        free(conn.xmpp_log);
-    }
-    conn.xmpp_log = _xmpp_get_file_logger();
-
-    if (conn.xmpp_conn) {
-        xmpp_conn_release(conn.xmpp_conn);
-    }
-    if (conn.xmpp_ctx) {
-        xmpp_ctx_free(conn.xmpp_ctx);
-    }
-    conn.xmpp_ctx = xmpp_ctx_new(NULL, conn.xmpp_log);
-    if (conn.xmpp_ctx == NULL) {
-        log_warning("Failed to get libstrophe ctx during connect");
-        return JABBER_DISCONNECTED;
-    }
-    conn.xmpp_conn = xmpp_conn_new(conn.xmpp_ctx);
-    if (conn.xmpp_conn == NULL) {
-        log_warning("Failed to get libstrophe conn during connect");
-        return JABBER_DISCONNECTED;
-    }
-    xmpp_conn_set_jid(conn.xmpp_conn, altdomain);
-
-    flags = xmpp_conn_get_flags(conn.xmpp_conn);
-
-    if (!tls_policy || (g_strcmp0(tls_policy, "force") == 0)) {
-        flags |= XMPP_CONN_FLAG_MANDATORY_TLS;
-    } else if (g_strcmp0(tls_policy, "trust") == 0) {
-        flags |= XMPP_CONN_FLAG_MANDATORY_TLS;
-        flags |= XMPP_CONN_FLAG_TRUST_TLS;
-    } else if (g_strcmp0(tls_policy, "disable") == 0) {
-        flags |= XMPP_CONN_FLAG_DISABLE_TLS;
-    } else if (g_strcmp0(tls_policy, "legacy") == 0) {
-        flags |= XMPP_CONN_FLAG_LEGACY_SSL;
-    }
-
-    xmpp_conn_set_flags(conn.xmpp_conn, flags);
-
-    /* Print debug logs that can help when users share the logs */
-    if (flags != 0) {
-        log_debug("Connecting with flags (0x%lx):", flags);
-#define LOG_FLAG_IF_SET(name)  \
-    if (flags & name) {        \
-        log_debug("  " #name); \
-    }
-        LOG_FLAG_IF_SET(XMPP_CONN_FLAG_MANDATORY_TLS);
-        LOG_FLAG_IF_SET(XMPP_CONN_FLAG_TRUST_TLS);
-        LOG_FLAG_IF_SET(XMPP_CONN_FLAG_DISABLE_TLS);
-        LOG_FLAG_IF_SET(XMPP_CONN_FLAG_LEGACY_SSL);
-#undef LOG_FLAG_IF_SET
-    }
+    _conn_apply_settings(altdomain, NULL, tls_policy, NULL);
 
     prof_reg_t* reg;
 
@@ -540,14 +496,6 @@ connection_register(const char* const altdomain, int port, const char* const tls
     reg->username = strdup(username);
     reg->password = strdup(password);
 
-    char* cert_path = prefs_get_tls_certpath();
-    if (cert_path) {
-        xmpp_conn_set_capath(conn.xmpp_conn, cert_path);
-        free(cert_path);
-    }
-
-    xmpp_conn_set_certfail_handler(conn.xmpp_conn, _connection_certfail_cb);
-
     int connect_status = xmpp_connect_raw(
         conn.xmpp_conn,
         altdomain,
@@ -584,12 +532,7 @@ connection_disconnect(void)
     if (!conn.xmpp_in_event_loop) {
         if (conn.xmpp_conn) {
             xmpp_conn_release(conn.xmpp_conn);
-            conn.xmpp_conn = NULL;
-        }
-
-        if (conn.xmpp_ctx) {
-            xmpp_ctx_free(conn.xmpp_ctx);
-            conn.xmpp_ctx = NULL;
+            conn.xmpp_conn = xmpp_conn_new(conn.xmpp_ctx);
         }
     }
 
@@ -909,11 +852,7 @@ _split_url(const char* alturi, gchar** host, gint* port)
      * requires this to be there.
      */
     const char* xmpp = "xmpp://";
-    char* xmpp_uri = malloc(strlen(xmpp) + strlen(alturi) + 1);
-    if (!xmpp_uri) {
-        log_debug("_get_other_host: malloc failed \"%s\"", alturi);
-        return false;
-    }
+    char* xmpp_uri = _xmalloc(strlen(xmpp) + strlen(alturi) + 1, NULL);
     memcpy(xmpp_uri, xmpp, strlen(xmpp));
     memcpy(xmpp_uri + strlen(xmpp), alturi, strlen(alturi) + 1);
     gboolean ret = g_uri_split_network(xmpp_uri, 0, NULL, host, port, NULL);
@@ -1104,34 +1043,6 @@ _xmppcert_to_profcert(const xmpp_tlscert_t* xmpptlscert)
         xmpp_tlscert_get_pem(xmpptlscert));
 }
 
-static xmpp_log_t*
-_xmpp_get_file_logger(void)
-{
-    log_level_t prof_level = log_get_filter();
-    xmpp_log_level_t xmpp_level = XMPP_LEVEL_ERROR;
-
-    switch (prof_level) {
-    case PROF_LEVEL_DEBUG:
-        xmpp_level = XMPP_LEVEL_DEBUG;
-        break;
-    case PROF_LEVEL_INFO:
-        xmpp_level = XMPP_LEVEL_INFO;
-        break;
-    case PROF_LEVEL_WARN:
-        xmpp_level = XMPP_LEVEL_WARN;
-        break;
-    default:
-        xmpp_level = XMPP_LEVEL_ERROR;
-        break;
-    }
-
-    xmpp_log_t* file_log = malloc(sizeof(xmpp_log_t));
-    file_log->handler = _xmpp_file_logger;
-    file_log->userdata = &xmpp_level;
-
-    return file_log;
-}
-
 static void
 _xmpp_file_logger(void* const userdata, const xmpp_log_level_t xmpp_level, const char* const area, const char* const msg)
 {
diff --git a/tests/unittests/test_cmd_account.c b/tests/unittests/test_cmd_account.c
index 69721311..c0eac0e3 100644
--- a/tests/unittests/test_cmd_account.c
+++ b/tests/unittests/test_cmd_account.c
@@ -571,7 +571,8 @@ cmd_account_show_message_for_invalid_otr_policy(void** state)
     expect_any(accounts_account_exists, account_name);
     will_return(accounts_account_exists, TRUE);
 
-    expect_cons_show("OTR policy must be one of: manual, opportunistic or always.");
+    expect_cons_show("Invalid OTR policy: 'bad_otr_policy'");
+    expect_cons_show("OTR policy must be one of: 'manual', 'opportunistic' or 'always'.");
 
     gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args);
     assert_true(result);