From 485ed2f52bafd9cc1d1c0a4ed87c87f2bde1de09 Mon Sep 17 00:00:00 2001 From: ailin-nemui Date: Sun, 5 Apr 2020 21:22:19 +0200 Subject: [PATCH] hide the deprecated -ssl options from completion --- src/core/chat-commands.c | 7 +++++- src/core/commands.c | 39 +++++++++++++++++++++++---------- src/fe-common/core/completion.c | 6 ++++- src/fe-common/core/fe-server.c | 15 +++++++++++-- 4 files changed, 51 insertions(+), 16 deletions(-) diff --git a/src/core/chat-commands.c b/src/core/chat-commands.c index 0b4b6591..ae44ef63 100644 --- a/src/core/chat-commands.c +++ b/src/core/chat-commands.c @@ -517,7 +517,12 @@ void chat_commands_init(void) signal_add("server sendmsg", (SIGNAL_FUNC) sig_server_sendmsg); - command_set_options("connect", "4 6 !! -network ssl +ssl_cert +ssl_pkey +ssl_pass ssl_verify +ssl_cafile +ssl_capath +ssl_ciphers +ssl_pinned_cert +ssl_pinned_pubkey tls +tls_cert +tls_pkey +tls_pass tls_verify +tls_cafile +tls_capath +tls_ciphers +tls_pinned_cert +tls_pinned_pubkey +host noproxy -rawlog noautosendcmd"); + command_set_options( + "connect", + "4 6 !! -network ~ssl ~+ssl_cert ~+ssl_pkey ~+ssl_pass ~ssl_verify ~+ssl_cafile " + "~+ssl_capath ~+ssl_ciphers ~+ssl_pinned_cert ~+ssl_pinned_pubkey tls +tls_cert " + "+tls_pkey +tls_pass tls_verify +tls_cafile +tls_capath +tls_ciphers +tls_pinned_cert " + "+tls_pinned_pubkey +host noproxy -rawlog noautosendcmd"); command_set_options("msg", "channel nick"); } diff --git a/src/core/commands.c b/src/core/commands.c index 2805f8c0..198b1327 100644 --- a/src/core/commands.c +++ b/src/core/commands.c @@ -339,11 +339,28 @@ void command_runsub(const char *cmd, const char *data, g_free(orig); } +static char *optname(char *option) +{ + char *opt = option; + if (*opt == '~') + opt++; + if (iscmdtype(*opt)) + opt++; + return opt; +} + +static gboolean optflag(char *option, char *flag) +{ + if (*option == '~') + return optflag(option + 1, flag); + + return (strchr(flag, *option) != NULL) || (!iscmdtype(*option) && strchr(flag, ' ')); +} + static GSList *optlist_find(GSList *optlist, const char *option) { while (optlist != NULL) { - char *name = optlist->data; - if (iscmdtype(*name)) name++; + char *name = optname(optlist->data); if (g_ascii_strcasecmp(name, option) == 0) return optlist; @@ -369,7 +386,7 @@ int command_have_option(const char *cmd, const char *option) return FALSE; for (tmp = rec->options; *tmp != NULL; tmp++) { - char *name = iscmdtype(**tmp) ? (*tmp)+1 : *tmp; + char *name = optname(*tmp); if (g_ascii_strcasecmp(name, option) == 0) return TRUE; @@ -399,7 +416,7 @@ static void command_calc_options(COMMAND_REC *rec, const char *options) /* merge the options */ for (tmp = optlist; *tmp != NULL; tmp++) { - name = iscmdtype(**tmp) ? (*tmp)+1 : *tmp; + name = optname(*tmp); oldopt = optlist_find(list, name); if (oldopt != NULL) { @@ -529,7 +546,7 @@ static int option_find(char **array, const char *option) found = -1; index = 0; multiple = FALSE; for (tmp = array; *tmp != NULL; tmp++, index++) { - const char *text = *tmp + iscmdtype(**tmp); + const char *text = optname(*tmp); if (g_ascii_strncasecmp(text, option, len) == 0) { if (text[len] == '\0') { @@ -568,9 +585,9 @@ static int get_cmd_options(char **data, int ignore_unknown, option = NULL; pos = -1; for (;;) { if (**data == '\0' || **data == '-') { - if (option != NULL && *optlist[pos] == '+') { + if (option != NULL && optflag(optlist[pos], "+")) { /* required argument missing! */ - *data = optlist[pos] + 1; + *data = optname(optlist[pos]); return CMDERR_OPTION_ARG_MISSING; } } @@ -621,14 +638,12 @@ static int get_cmd_options(char **data, int ignore_unknown, if (pos >= 0) { /* if we used a shortcut of parameter, put the whole parameter name in options table */ - option = optlist[pos] + - iscmdtype(*optlist[pos]); + option = optname(optlist[pos]); } if (options != NULL && pos != -3) g_hash_table_insert(options, option, ""); - if (pos < 0 || !iscmdtype(*optlist[pos]) || - *optlist[pos] == '!') + if (pos < 0 || optflag(optlist[pos], " !")) option = NULL; while (**data == ' ') (*data)++; @@ -638,7 +653,7 @@ static int get_cmd_options(char **data, int ignore_unknown, if (option == NULL) break; - if (*optlist[pos] == '@' && !is_numeric(*data, ' ')) + if (optflag(optlist[pos], "@") && !is_numeric(*data, ' ')) break; /* expected a numeric argument */ /* save the argument */ diff --git a/src/fe-common/core/completion.c b/src/fe-common/core/completion.c index 7778d8a4..0102bd2c 100644 --- a/src/fe-common/core/completion.c +++ b/src/fe-common/core/completion.c @@ -544,7 +544,11 @@ static GList *completion_get_options(const char *cmd, const char *option) list = NULL; len = strlen(option); for (tmp = rec->options; *tmp != NULL; tmp++) { - const char *optname = *tmp + iscmdtype(**tmp); + const char *optname; + if (**tmp == '~') + continue; /* deprecated or hidden option */ + + optname = *tmp + iscmdtype(**tmp); if (len == 0 || g_ascii_strncasecmp(optname, option, len) == 0) list = g_list_append(list, g_strconcat("-", optname, NULL)); diff --git a/src/fe-common/core/fe-server.c b/src/fe-common/core/fe-server.c index f5f96324..5ed67170 100644 --- a/src/fe-common/core/fe-server.c +++ b/src/fe-common/core/fe-server.c @@ -453,8 +453,19 @@ void fe_server_init(void) command_bind_first("server", NULL, (SIGNAL_FUNC) server_command); command_bind_first("disconnect", NULL, (SIGNAL_FUNC) server_command); - command_set_options("server add", "4 6 !! ssl nossl +ssl_cert +ssl_pkey +ssl_pass ssl_verify nossl_verify +ssl_cafile +ssl_capath +ssl_ciphers +ssl_fingerprint tls notls +tls_cert +tls_pkey +tls_pass tls_verify notls_verify +tls_cafile +tls_capath +tls_ciphers +tls_pinned_cert +tls_pinned_pubkey auto noauto proxy noproxy -host -port noautosendcmd"); - command_set_options("server modify", "4 6 !! ssl nossl +ssl_cert +ssl_pkey +ssl_pass ssl_verify nossl_verify +ssl_cafile +ssl_capath +ssl_ciphers +ssl_fingerprint tls notls +tls_cert +tls_pkey +tls_pass tls_verify notls_verify +tls_cafile +tls_capath +tls_ciphers +tls_pinned_cert +tls_pinned_pubkey auto noauto proxy noproxy -host -port noautosendcmd"); + command_set_options( + "server add", "4 6 !! ~ssl ~nossl ~+ssl_cert ~+ssl_pkey ~+ssl_pass ~ssl_verify " + "~nossl_verify ~+ssl_cafile ~+ssl_capath ~+ssl_ciphers ~+ssl_fingerprint " + "tls notls +tls_cert +tls_pkey +tls_pass tls_verify notls_verify " + "+tls_cafile +tls_capath +tls_ciphers +tls_pinned_cert " + "+tls_pinned_pubkey auto noauto proxy noproxy -host -port noautosendcmd"); + command_set_options( + "server modify", + "4 6 !! ~ssl ~nossl ~+ssl_cert ~+ssl_pkey ~+ssl_pass ~ssl_verify ~nossl_verify " + "~+ssl_cafile ~+ssl_capath ~+ssl_ciphers ~+ssl_fingerprint tls notls +tls_cert " + "+tls_pkey +tls_pass tls_verify notls_verify +tls_cafile +tls_capath +tls_ciphers " + "+tls_pinned_cert +tls_pinned_pubkey auto noauto proxy noproxy -host -port " + "noautosendcmd"); signal_add("server looking", (SIGNAL_FUNC) sig_server_looking); signal_add("server connecting", (SIGNAL_FUNC) sig_server_connecting);