diff options
Diffstat (limited to 'src/command/cmd_funcs.c')
-rw-r--r-- | src/command/cmd_funcs.c | 408 |
1 files changed, 347 insertions, 61 deletions
diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index 71c8816a..c8aa22b4 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -1,7 +1,7 @@ /* * cmd_funcs.c * - * Copyright (C) 2012 - 2017 James Booth <boothj5@gmail.com> + * Copyright (C) 2012 - 2018 James Booth <boothj5@gmail.com> * * This file is part of Profanity. * @@ -350,7 +350,8 @@ cmd_connect(ProfWin *window, const char *const command, gchar **args) if (tls_policy && (g_strcmp0(tls_policy, "force") != 0) && (g_strcmp0(tls_policy, "allow") != 0) && - (g_strcmp0(tls_policy, "disable") != 0)) { + (g_strcmp0(tls_policy, "disable") != 0) && + (g_strcmp0(tls_policy, "legacy") != 0)) { cons_bad_cmd_usage(command); cons_show(""); return TRUE; @@ -813,8 +814,9 @@ _account_set_tls(char *account_name, char *policy) { if ((g_strcmp0(policy, "force") != 0) && (g_strcmp0(policy, "allow") != 0) - && (g_strcmp0(policy, "disable") != 0)) { - cons_show("TLS policy must be one of: force, allow or disable."); + && (g_strcmp0(policy, "disable") != 0) + && (g_strcmp0(policy, "legacy") != 0)) { + cons_show("TLS policy must be one of: force, allow, legacy or disable."); } else { accounts_set_tls_policy(account_name, policy); cons_show("Updated TLS policy for account %s: %s", account_name, policy); @@ -1251,17 +1253,6 @@ cmd_wins_unread(ProfWin *window, const char *const command, gchar **args) } gboolean -cmd_wins_tidy(ProfWin *window, const char *const command, gchar **args) -{ - if (wins_tidy()) { - cons_show("Windows tidied."); - } else { - cons_show("No tidy needed."); - } - return TRUE; -} - -gboolean cmd_wins_prune(ProfWin *window, const char *const command, gchar **args) { ui_prune_wins(); @@ -1278,38 +1269,34 @@ cmd_wins_swap(ProfWin *window, const char *const command, gchar **args) int source_win = atoi(args[1]); int target_win = atoi(args[2]); + if ((source_win == 1) || (target_win == 1)) { cons_show("Cannot move console window."); - } else if (source_win == 10 || target_win == 10) { + return TRUE; + } + + if (source_win == 10 || target_win == 10) { cons_show("Window 10 does not exist"); - } else if (source_win != target_win) { - gboolean swapped = wins_swap(source_win, target_win); - if (swapped) { - cons_show("Swapped windows %d <-> %d", source_win, target_win); - } else { - cons_show("Window %d does not exist", source_win); - } - } else { + return TRUE; + } + + if (source_win == target_win) { cons_show("Same source and target window supplied."); + return TRUE; } - return TRUE; -} + if (wins_get_by_num(source_win) == NULL) { + cons_show("Window %d does not exist", source_win); + return TRUE; + } -gboolean -cmd_wins_autotidy(ProfWin *window, const char *const command, gchar **args) -{ - if (g_strcmp0(args[1], "on") == 0) { - cons_show("Window autotidy enabled"); - prefs_set_boolean(PREF_WINS_AUTO_TIDY, TRUE); - wins_tidy(); - } else if (g_strcmp0(args[1], "off") == 0) { - cons_show("Window autotidy disabled"); - prefs_set_boolean(PREF_WINS_AUTO_TIDY, FALSE); - } else { - cons_bad_cmd_usage(command); + if (wins_get_by_num(target_win) == NULL) { + cons_show("Window %d does not exist", target_win); + return TRUE; } + wins_swap(source_win, target_win); + cons_show("Swapped windows %d <-> %d", source_win, target_win); return TRUE; } @@ -1405,11 +1392,7 @@ cmd_close(ProfWin *window, const char *const command, gchar **args) // close the window ui_close_win(index); cons_show("Closed window %d", index); - - // Tidy up the window list. - if (prefs_get_boolean(PREF_WINS_AUTO_TIDY)) { - wins_tidy(); - } + wins_tidy(); rosterwin_roster(); return TRUE; @@ -1440,11 +1423,7 @@ cmd_close(ProfWin *window, const char *const command, gchar **args) // close the window ui_close_win(index); cons_show("Closed window %s", args[0]); - - // Tidy up the window list. - if (prefs_get_boolean(PREF_WINS_AUTO_TIDY)) { - wins_tidy(); - } + wins_tidy(); rosterwin_roster(); return TRUE; @@ -2093,7 +2072,7 @@ cmd_who(ProfWin *window, const char *const command, gchar **args) } if (window->type != WIN_CONSOLE && window->type != WIN_MUC) { - status_bar_new(1); + status_bar_new(1, WIN_CONSOLE, "console"); } return TRUE; @@ -2867,6 +2846,30 @@ cmd_roster(ProfWin *window, const char *const command, gchar **args) cons_bad_cmd_usage(command); return TRUE; } + } else if (g_strcmp0(args[1], "show") == 0) { + if (g_strcmp0(args[2], "server") == 0) { + cons_show("Roster room server enabled."); + prefs_set_boolean(PREF_ROSTER_ROOMS_SERVER, TRUE); + if (conn_status == JABBER_CONNECTED) { + rosterwin_roster(); + } + return TRUE; + } else { + cons_bad_cmd_usage(command); + return TRUE; + } + } else if (g_strcmp0(args[1], "hide") == 0) { + if (g_strcmp0(args[2], "server") == 0) { + cons_show("Roster room server disabled."); + prefs_set_boolean(PREF_ROSTER_ROOMS_SERVER, FALSE); + if (conn_status == JABBER_CONNECTED) { + rosterwin_roster(); + } + return TRUE; + } else { + cons_bad_cmd_usage(command); + return TRUE; + } } else { cons_bad_cmd_usage(command); return TRUE; @@ -3916,6 +3919,7 @@ cmd_form(ProfWin *window, const char *const command, gchar **args) } ui_focus_win(new_current); wins_close_by_num(num); + wins_tidy(); } return TRUE; @@ -4367,18 +4371,102 @@ cmd_rooms(ProfWin *window, const char *const command, gchar **args) return TRUE; } - if (args[0]) { - iq_room_list_request(args[0]); - return TRUE; + gchar *service = NULL; + gchar *filter = NULL; + if (args[0] != NULL) { + if (g_strcmp0(args[0], "service") == 0) { + if (args[1] == NULL) { + cons_bad_cmd_usage(command); + cons_show(""); + return TRUE; + } + service = g_strdup(args[1]); + } else if (g_strcmp0(args[0], "filter") == 0) { + if (args[1] == NULL) { + cons_bad_cmd_usage(command); + cons_show(""); + return TRUE; + } + filter = g_strdup(args[1]); + } else if (g_strcmp0(args[0], "cache") == 0) { + if (g_strv_length(args) != 2) { + cons_bad_cmd_usage(command); + cons_show(""); + return TRUE; + } else if (g_strcmp0(args[1], "on") == 0) { + prefs_set_boolean(PREF_ROOM_LIST_CACHE, TRUE); + cons_show("Rooms list cache enabled."); + return TRUE; + } else if (g_strcmp0(args[1], "off") == 0) { + prefs_set_boolean(PREF_ROOM_LIST_CACHE, FALSE); + cons_show("Rooms list cache disabled."); + return TRUE; + } else if (g_strcmp0(args[1], "clear") == 0) { + iq_rooms_cache_clear(); + cons_show("Rooms list cache cleared."); + return TRUE; + } else { + cons_bad_cmd_usage(command); + cons_show(""); + return TRUE; + } + } else { + cons_bad_cmd_usage(command); + cons_show(""); + return TRUE; + } + } + if (g_strv_length(args) >=3 ) { + if (g_strcmp0(args[2], "service") == 0) { + if (args[3] == NULL) { + cons_bad_cmd_usage(command); + cons_show(""); + g_free(service); + g_free(filter); + return TRUE; + } + g_free(service); + service = g_strdup(args[3]); + } else if (g_strcmp0(args[2], "filter") == 0) { + if (args[3] == NULL) { + cons_bad_cmd_usage(command); + cons_show(""); + g_free(service); + g_free(filter); + return TRUE; + } + g_free(filter); + filter = g_strdup(args[3]); + } else { + cons_bad_cmd_usage(command); + cons_show(""); + return TRUE; + } } - ProfAccount *account = accounts_get_account(session_get_account_name()); - if (account->muc_service) { - iq_room_list_request(account->muc_service); + if (service == NULL) { + ProfAccount *account = accounts_get_account(session_get_account_name()); + if (account->muc_service) { + service = g_strdup(account->muc_service); + account_free(account); + } else { + cons_show("Account MUC service property not found."); + account_free(account); + g_free(service); + g_free(filter); + return TRUE; + } + } + + cons_show(""); + if (filter) { + cons_show("Room list request sent: %s, filter: '%s'", service, filter); } else { - cons_show("Account MUC service property not found."); + cons_show("Room list request sent: %s", service); } - account_free(account); + iq_room_list_request(service, filter); + + g_free(service); return TRUE; } @@ -4390,11 +4478,15 @@ cmd_bookmark(ProfWin *window, const char *const command, gchar **args) if (conn_status != JABBER_CONNECTED) { cons_show("You are not currently connected."); + cons_alert(); return TRUE; } + int num_args = g_strv_length(args); gchar *cmd = args[0]; - if (window->type == WIN_MUC && (cmd == NULL || g_strcmp0(cmd, "add") == 0)) { + if (window->type == WIN_MUC + && num_args < 2 + && (cmd == NULL || g_strcmp0(cmd, "add") == 0)) { // default to current nickname, password, and autojoin "on" ProfMucWin *mucwin = (ProfMucWin*)window; assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK); @@ -4409,7 +4501,9 @@ cmd_bookmark(ProfWin *window, const char *const command, gchar **args) return TRUE; } - if (window->type == WIN_MUC && g_strcmp0(cmd, "remove") == 0) { + if (window->type == WIN_MUC + && num_args < 2 + && g_strcmp0(cmd, "remove") == 0) { ProfMucWin *mucwin = (ProfMucWin*)window; assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK); gboolean removed = bookmark_remove(mucwin->roomjid); @@ -4423,6 +4517,7 @@ cmd_bookmark(ProfWin *window, const char *const command, gchar **args) if (cmd == NULL) { cons_bad_cmd_usage(command); + cons_alert(); return TRUE; } @@ -4437,6 +4532,7 @@ cmd_bookmark(ProfWin *window, const char *const command, gchar **args) cons_bad_cmd_usage(command); cons_show(""); } + cons_alert(); return TRUE; } @@ -4451,11 +4547,13 @@ cmd_bookmark(ProfWin *window, const char *const command, gchar **args) if (jid == NULL) { cons_bad_cmd_usage(command); cons_show(""); + cons_alert(); return TRUE; } if (strchr(jid, '@') == NULL) { cons_show("Invalid room, must be of the form room@domain.tld"); cons_show(""); + cons_alert(); return TRUE; } @@ -4466,6 +4564,7 @@ cmd_bookmark(ProfWin *window, const char *const command, gchar **args) } else { cons_show("No bookmark exists for %s.", jid); } + cons_alert(); return TRUE; } @@ -4474,6 +4573,7 @@ cmd_bookmark(ProfWin *window, const char *const command, gchar **args) if (!joined) { cons_show("No bookmark exists for %s.", jid); } + cons_alert(); return TRUE; } @@ -4484,6 +4584,7 @@ cmd_bookmark(ProfWin *window, const char *const command, gchar **args) if (!parsed) { cons_bad_cmd_usage(command); cons_show(""); + cons_alert(); return TRUE; } @@ -4493,6 +4594,7 @@ cmd_bookmark(ProfWin *window, const char *const command, gchar **args) cons_bad_cmd_usage(command); cons_show(""); options_destroy(options); + cons_alert(); return TRUE; } @@ -4507,6 +4609,7 @@ cmd_bookmark(ProfWin *window, const char *const command, gchar **args) cons_show("Bookmark already exists, use /bookmark update to edit."); } options_destroy(options); + cons_alert(); return TRUE; } @@ -4518,11 +4621,13 @@ cmd_bookmark(ProfWin *window, const char *const command, gchar **args) cons_show("No bookmark exists for %s.", jid); } options_destroy(options); + cons_alert(); return TRUE; } cons_bad_cmd_usage(command); options_destroy(options); + cons_alert(); return TRUE; } @@ -5665,6 +5770,177 @@ cmd_mainwin(ProfWin *window, const char *const command, gchar **args) gboolean cmd_statusbar(ProfWin *window, const char *const command, gchar **args) { + if (g_strcmp0(args[0], "show") == 0) { + if (g_strcmp0(args[1], "name") == 0) { + prefs_set_boolean(PREF_STATUSBAR_SHOW_NAME, TRUE); + cons_show("Enabled showing tab names."); + ui_resize(); + return TRUE; + } + if (g_strcmp0(args[1], "number") == 0) { + prefs_set_boolean(PREF_STATUSBAR_SHOW_NUMBER, TRUE); + cons_show("Enabled showing tab numbers."); + ui_resize(); + return TRUE; + } + cons_bad_cmd_usage(command); + return TRUE; + } + + if (g_strcmp0(args[0], "hide") == 0) { + if (g_strcmp0(args[1], "name") == 0) { + if (prefs_get_boolean(PREF_STATUSBAR_SHOW_NUMBER) == FALSE) { + cons_show("Cannot disable both names and numbers in statusbar."); + cons_show("Use '/statusbar maxtabs 0' to hide tabs."); + return TRUE; + } + prefs_set_boolean(PREF_STATUSBAR_SHOW_NAME, FALSE); + cons_show("Disabled showing tab names."); + ui_resize(); + return TRUE; + } + if (g_strcmp0(args[1], "number") == 0) { + if (prefs_get_boolean(PREF_STATUSBAR_SHOW_NAME) == FALSE) { + cons_show("Cannot disable both names and numbers in statusbar."); + cons_show("Use '/statusbar maxtabs 0' to hide tabs."); + return TRUE; + } + prefs_set_boolean(PREF_STATUSBAR_SHOW_NUMBER, FALSE); + cons_show("Disabled showing tab numbers."); + ui_resize(); + return TRUE; + } + cons_bad_cmd_usage(command); + return TRUE; + } + + if (g_strcmp0(args[0], "maxtabs") == 0) { + if (args[1] == NULL) { + cons_bad_cmd_usage(command); + return TRUE; + } + + char *value = args[1]; + int intval = 0; + char *err_msg = NULL; + gboolean res = strtoi_range(value, &intval, 0, INT_MAX, &err_msg); + if (res) { + if (intval < 0 || intval > 10) { + cons_bad_cmd_usage(command); + return TRUE; + } + + prefs_set_statusbartabs(intval); + if (intval == 0) { + cons_show("Status bar tabs disabled."); + } else { + cons_show("Status bar tabs set to %d.", intval); + } + ui_resize(); + return TRUE; + } else { + cons_show(err_msg); + cons_bad_cmd_usage(command); + free(err_msg); + return TRUE; + } + } + + if (g_strcmp0(args[0], "tablen") == 0) { + if (args[1] == NULL) { + cons_bad_cmd_usage(command); + return TRUE; + } + + char *value = args[1]; + int intval = 0; + char *err_msg = NULL; + gboolean res = strtoi_range(value, &intval, 0, INT_MAX, &err_msg); + if (res) { + if (intval < 0) { + cons_bad_cmd_usage(command); + return TRUE; + } + + prefs_set_statusbartablen(intval); + if (intval == 0) { + cons_show("Maximum tab length disabled."); + } else { + cons_show("Maximum tab length set to %d.", intval); + } + ui_resize(); + return TRUE; + } else { + cons_show(err_msg); + cons_bad_cmd_usage(command); + free(err_msg); + return TRUE; + } + } + + if (g_strcmp0(args[0], "self") == 0) { + if (g_strcmp0(args[1], "barejid") == 0) { + prefs_set_string(PREF_STATUSBAR_SELF, "barejid"); + cons_show("Using barejid for statusbar title."); + ui_resize(); + return TRUE; + } + if (g_strcmp0(args[1], "fulljid") == 0) { + prefs_set_string(PREF_STATUSBAR_SELF, "fulljid"); + cons_show("Using fulljid for statusbar title."); + ui_resize(); + return TRUE; + } + if (g_strcmp0(args[1], "user") == 0) { + prefs_set_string(PREF_STATUSBAR_SELF, "user"); + cons_show("Using user for statusbar title."); + ui_resize(); + return TRUE; + } + if (g_strcmp0(args[1], "off") == 0) { + prefs_set_string(PREF_STATUSBAR_SELF, "off"); + cons_show("Disabling statusbar title."); + ui_resize(); + return TRUE; + } + cons_bad_cmd_usage(command); + return TRUE; + } + + if (g_strcmp0(args[0], "chat") == 0) { + if (g_strcmp0(args[1], "jid") == 0) { + prefs_set_string(PREF_STATUSBAR_CHAT, "jid"); + cons_show("Using jid for chat tabs."); + ui_resize(); + return TRUE; + } + if (g_strcmp0(args[1], "user") == 0) { + prefs_set_string(PREF_STATUSBAR_CHAT, "user"); + cons_show("Using user for chat tabs."); + ui_resize(); + return TRUE; + } + cons_bad_cmd_usage(command); + return TRUE; + } + + if (g_strcmp0(args[0], "room") == 0) { + if (g_strcmp0(args[1], "jid") == 0) { + prefs_set_string(PREF_STATUSBAR_ROOM, "jid"); + cons_show("Using jid for room tabs."); + ui_resize(); + return TRUE; + } + if (g_strcmp0(args[1], "room") == 0) { + prefs_set_string(PREF_STATUSBAR_ROOM, "room"); + cons_show("Using room name for room tabs."); + ui_resize(); + return TRUE; + } + cons_bad_cmd_usage(command); + return TRUE; + } + if (g_strcmp0(args[0], "up") == 0) { gboolean result = prefs_statusbar_pos_up(); if (result) { @@ -5863,6 +6139,16 @@ cmd_ping(ProfWin *window, const char *const command, gchar **args) return TRUE; } + if (args[0] == NULL && connection_supports(XMPP_FEATURE_PING) == FALSE) { + cons_show("Server does not support ping requests."); + return TRUE; + } + + if (args[0] != NULL && caps_jid_has_feature(args[0], XMPP_FEATURE_PING) == FALSE) { + cons_show("%s does not support ping requests.", args[0]); + return TRUE; + } + iq_send_ping(args[0]); if (args[0] == NULL) { @@ -6451,11 +6737,11 @@ gboolean cmd_plugins_python_version(ProfWin *window, const char *const command, gchar **args) { #ifdef HAVE_PYTHON - const char *version = python_get_version(); + const char *version = python_get_version_string(); cons_show("Python version:"); cons_show("%s", version); #else - cons_show("This build does not support pytyon plugins."); + cons_show("This build does not support python plugins."); #endif return TRUE; } |