1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-09 17:38:00 +00:00

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.
This commit is contained in:
Simon Tatham 2020-02-22 11:52:30 +00:00
parent 9482f33739
commit bd16a0e1de

View File

@ -405,45 +405,23 @@ int cmdline_process_param(const char *p, char *value,
loaded_session = true; loaded_session = true;
return 2; return 2;
} }
if (!strcmp(p, "-ssh")) { for (size_t i = 0; backends[i]; i++) {
RETURN(1); if (p[0] == '-' && !strcmp(p+1, backends[i]->id)) {
UNAVAILABLE_IN(TOOLTYPE_FILETRANSFER | TOOLTYPE_NONNETWORK); RETURN(1);
SAVEABLE(0); UNAVAILABLE_IN(TOOLTYPE_FILETRANSFER | TOOLTYPE_NONNETWORK);
set_protocol(conf, PROT_SSH); SAVEABLE(0);
set_port(conf, 22); set_protocol(conf, backends[i]->protocol);
return 1; if (backends[i]->default_port)
} set_port(conf, backends[i]->default_port);
if (!strcmp(p, "-telnet")) { if (backends[i]->protocol == PROT_SERIAL) {
RETURN(1); /* Special handling: the 'where to connect to' argument will
UNAVAILABLE_IN(TOOLTYPE_FILETRANSFER | TOOLTYPE_NONNETWORK); * have been placed into CONF_host, but for this protocol, it
SAVEABLE(0); * needs to be in CONF_serline */
set_protocol(conf, PROT_TELNET); conf_set_str(conf, CONF_serline,
set_port(conf, 23); conf_get_str(conf, CONF_host));
return 1; }
} 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));
} }
if (!strcmp(p, "-v")) { if (!strcmp(p, "-v")) {
RETURN(1); RETURN(1);