From bd16a0e1de04c79afb9c409cbacabe19825e6aaf Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Sat, 22 Feb 2020 11:52:30 +0000 Subject: [PATCH] cmdline.c: loop over backends list for '-protocol' options. I'm reusing the 'id' string from each BackendVtable as the name of its command-line option, which means I don't need to manually implement an option for each new protocol. --- cmdline.c | 56 +++++++++++++++++-------------------------------------- 1 file changed, 17 insertions(+), 39 deletions(-) diff --git a/cmdline.c b/cmdline.c index aa0000ce..826fc358 100644 --- a/cmdline.c +++ b/cmdline.c @@ -405,45 +405,23 @@ int cmdline_process_param(const char *p, char *value, loaded_session = true; return 2; } - if (!strcmp(p, "-ssh")) { - RETURN(1); - UNAVAILABLE_IN(TOOLTYPE_FILETRANSFER | TOOLTYPE_NONNETWORK); - SAVEABLE(0); - set_protocol(conf, PROT_SSH); - set_port(conf, 22); - return 1; - } - if (!strcmp(p, "-telnet")) { - RETURN(1); - UNAVAILABLE_IN(TOOLTYPE_FILETRANSFER | TOOLTYPE_NONNETWORK); - SAVEABLE(0); - set_protocol(conf, PROT_TELNET); - set_port(conf, 23); - return 1; - } - if (!strcmp(p, "-rlogin")) { - RETURN(1); - UNAVAILABLE_IN(TOOLTYPE_FILETRANSFER | TOOLTYPE_NONNETWORK); - SAVEABLE(0); - set_protocol(conf, PROT_RLOGIN); - set_port(conf, 513); - return 1; - } - if (!strcmp(p, "-raw")) { - RETURN(1); - UNAVAILABLE_IN(TOOLTYPE_FILETRANSFER | TOOLTYPE_NONNETWORK); - SAVEABLE(0); - set_protocol(conf, PROT_RAW); - } - if (!strcmp(p, "-serial")) { - RETURN(1); - /* Serial is not NONNETWORK in an odd sense of the word */ - UNAVAILABLE_IN(TOOLTYPE_FILETRANSFER | TOOLTYPE_NONNETWORK); - SAVEABLE(0); - set_protocol(conf, PROT_SERIAL); - /* The host parameter will already be loaded into CONF_host, - * so copy it across */ - conf_set_str(conf, CONF_serline, conf_get_str(conf, CONF_host)); + for (size_t i = 0; backends[i]; i++) { + if (p[0] == '-' && !strcmp(p+1, backends[i]->id)) { + RETURN(1); + UNAVAILABLE_IN(TOOLTYPE_FILETRANSFER | TOOLTYPE_NONNETWORK); + SAVEABLE(0); + set_protocol(conf, backends[i]->protocol); + if (backends[i]->default_port) + set_port(conf, backends[i]->default_port); + if (backends[i]->protocol == PROT_SERIAL) { + /* Special handling: the 'where to connect to' argument will + * have been placed into CONF_host, but for this protocol, it + * needs to be in CONF_serline */ + conf_set_str(conf, CONF_serline, + conf_get_str(conf, CONF_host)); + } + return 1; + } } if (!strcmp(p, "-v")) { RETURN(1);