const int be_default_protocol = PROT_SSH;
#endif
-struct backend_list backends[] = {
- {PROT_SSH, "ssh", &ssh_backend},
- {PROT_TELNET, "telnet", &telnet_backend},
- {PROT_RLOGIN, "rlogin", &rlogin_backend},
- {PROT_RAW, "raw", &raw_backend},
- {0, NULL}
+Backend *backends[] = {
+ &ssh_backend,
+ &telnet_backend,
+ &rlogin_backend,
+ &raw_backend,
+ NULL
};
const int be_default_protocol = PROT_SSH;
#endif
-struct backend_list backends[] = {
- {PROT_SSH, "ssh", &ssh_backend},
- {PROT_TELNET, "telnet", &telnet_backend},
- {PROT_RLOGIN, "rlogin", &rlogin_backend},
- {PROT_RAW, "raw", &raw_backend},
- {PROT_SERIAL, "serial", &serial_backend},
- {0, NULL}
+Backend *backends[] = {
+ &ssh_backend,
+ &telnet_backend,
+ &rlogin_backend,
+ &raw_backend,
+ &serial_backend,
+ NULL
};
/*
- * Linking module for PSCP: list the available backends, but
- * without accompanying function suites. Used only for name
- * lookups.
+ * Linking module for programs that do not support selection of backend
+ * (such as pscp or pterm).
*/
#include <stdio.h>
#include "putty.h"
-struct backend_list backends[] = {
- {PROT_SSH, "ssh", NULL},
- {PROT_TELNET, "telnet", NULL},
- {PROT_RLOGIN, "rlogin", NULL},
- {PROT_RAW, "raw", NULL},
- {0, NULL}
+Backend *backends[] = {
+ NULL
};
const char *const appname = "PuTTYtel";
-struct backend_list backends[] = {
- {PROT_TELNET, "telnet", &telnet_backend},
- {PROT_RLOGIN, "rlogin", &rlogin_backend},
- {PROT_RAW, "raw", &raw_backend},
- {PROT_SERIAL, "serial", &serial_backend},
- {0, NULL}
+Backend *backends[] = {
+ &telnet_backend,
+ &rlogin_backend,
+ &raw_backend,
+ &serial_backend,
+ NULL
};
/*
const char *const appname = "PuTTYtel";
-struct backend_list backends[] = {
- {PROT_TELNET, "telnet", &telnet_backend},
- {PROT_RLOGIN, "rlogin", &rlogin_backend},
- {PROT_RAW, "raw", &raw_backend},
- {0, NULL}
+Backend *backends[] = {
+ &telnet_backend,
+ &rlogin_backend,
+ &raw_backend,
+ NULL
};
/*
#define HOST_BOX_TITLE "Host Name (or IP address)"
#define PORT_BOX_TITLE "Port"
-/*
- * Convenience function: determine whether this binary supports a
- * given backend.
- */
-static int have_backend(int protocol)
-{
- struct backend_list *p = backends;
- for (p = backends; p->name; p++) {
- if (p->protocol == protocol)
- return 1;
- }
- return 0;
-}
-
static void config_host_handler(union control *ctrl, void *dlg,
void *data, int event)
{
hp->port = c;
ctrl_columns(s, 1, 100);
- if (!have_backend(PROT_SSH)) {
+ if (!backend_from_proto(PROT_SSH)) {
ctrl_radiobuttons(s, "Connection type:", NO_SHORTCUT, 3,
HELPCTX(session_hostname),
config_protocolbuttons_handler, P(hp),
{
char *sshlogname, *sshrawlogname;
if ((midsession && protocol == PROT_SSH) ||
- (!midsession && have_backend(PROT_SSH))) {
+ (!midsession && backend_from_proto(PROT_SSH))) {
sshlogname = "SSH packets";
sshrawlogname = "SSH packets and raw data";
} else {
dlg_stdcheckbox_handler, I(offsetof(Config,logflush)));
if ((midsession && protocol == PROT_SSH) ||
- (!midsession && have_backend(PROT_SSH))) {
+ (!midsession && backend_from_proto(PROT_SSH))) {
s = ctrl_getset(b, "Session/Logging", "ssh",
"Options specific to SSH packet logging");
ctrl_checkbox(s, "Omit known password fields", 'k',
* when we're not doing SSH.
*/
- if (have_backend(PROT_SSH) && (!midsession || protocol == PROT_SSH)) {
+ if (backend_from_proto(PROT_SSH) && (!midsession || protocol == PROT_SSH)) {
/*
* The Connection/SSH panel.
default_protocol = be_default_protocol;
/* Find the appropriate default port. */
{
- int i;
+ Backend *b = backend_from_proto(default_protocol);
default_port = 0; /* illegal */
- for (i = 0; backends[i].backend != NULL; i++)
- if (backends[i].protocol == default_protocol) {
- default_port = backends[i].backend->default_port;
- break;
- }
+ if (b)
+ default_port = b->default_port;
}
flags = FLAG_INTERACTIVE;
* Select protocol. This is farmed out into a table in a
* separate file to enable an ssh-free variant.
*/
- s->back = NULL;
- for (i = 0; backends[i].backend != NULL; i++)
- if (backends[i].protocol == s->cfg.protocol) {
- s->back = backends[i].backend;
- break;
- }
+ s->back = backend_from_proto(s->cfg.protocol);
if (s->back == NULL)
fatalbox("Unsupported protocol number found");
/*
* Set up a backend.
*/
- {
- int i;
+ back = backend_from_proto(cfg.protocol);
+ if (!back)
back = &pty_backend;
- for (i = 0; backends[i].backend != NULL; i++)
- if (backends[i].protocol == cfg.protocol) {
- back = backends[i].backend;
- break;
- }
- }
{
const char *error;
*/
void (*unthrottle) (void *handle, int);
int (*cfg_info) (void *handle);
+ char *name;
+ int protocol;
int default_port;
};
-extern struct backend_list {
- int protocol;
- char *name;
- Backend *backend;
-} backends[];
+extern Backend *backends[];
/*
* Suggested default protocol provided by the backend link module.
/*
* Exports from settings.c.
*/
+Backend *backend_from_name(const char *name);
+Backend *backend_from_proto(int proto);
char *save_settings(char *section, Config * cfg);
void save_open_settings(void *sesskey, Config *cfg);
void load_settings(char *section, Config * cfg);
raw_provide_logctx,
raw_unthrottle,
raw_cfg_info,
+ "raw",
+ PROT_RAW,
1
};
rlogin_provide_logctx,
rlogin_unthrottle,
rlogin_cfg_info,
+ "rlogin",
+ PROT_RLOGIN,
1
};
"CS8", "PARENB", "PARODD", NULL
};
+/*
+ * Convenience functions to access the backends[] array
+ * (which is only present in tools that manage settings).
+ */
+
+Backend *backend_from_name(const char *name)
+{
+ Backend **p;
+ for (p = backends; *p != NULL; p++)
+ if (!strcmp((*p)->name, name))
+ return *p;
+ return NULL;
+}
+
+Backend *backend_from_proto(int proto)
+{
+ Backend **p;
+ for (p = backends; *p != NULL; p++)
+ if ((*p)->protocol == proto)
+ return *p;
+ return NULL;
+}
+
static void gpps(void *handle, const char *name, const char *def,
char *val, int len)
{
write_setting_i(sesskey, "SSHLogOmitPasswords", cfg->logomitpass);
write_setting_i(sesskey, "SSHLogOmitData", cfg->logomitdata);
p = "raw";
- for (i = 0; backends[i].name != NULL; i++)
- if (backends[i].protocol == cfg->protocol) {
- p = backends[i].name;
- break;
- }
+ {
+ const Backend *b = backend_from_proto(cfg->protocol);
+ if (b)
+ p = b->name;
+ }
write_setting_s(sesskey, "Protocol", p);
write_setting_i(sesskey, "PortNumber", cfg->port);
/* The CloseOnExit numbers are arranged in a different order from
gpps(sesskey, "Protocol", "default", prot, 10);
cfg->protocol = default_protocol;
cfg->port = default_port;
- for (i = 0; backends[i].name != NULL; i++)
- if (!strcmp(prot, backends[i].name)) {
- cfg->protocol = backends[i].protocol;
+ {
+ const Backend *b = backend_from_name(prot);
+ if (b) {
+ cfg->protocol = b->protocol;
gppi(sesskey, "PortNumber", default_port, &cfg->port);
- break;
}
+ }
/* Address family selection */
gppi(sesskey, "AddressFamily", ADDRTYPE_UNSPEC, &cfg->addressfamily);
ssh_provide_logctx,
ssh_unthrottle,
ssh_cfg_info,
+ "ssh",
+ PROT_SSH,
22
};
telnet_provide_logctx,
telnet_unthrottle,
telnet_cfg_info,
+ "telnet",
+ PROT_TELNET,
23
};
null_init, null_free, null_reconfig, null_send, null_sendbuffer, null_size,
null_special, null_get_specials, null_connected, null_exitcode, null_sendok,
null_ldisc, null_provide_ldisc, null_provide_logctx, null_unthrottle,
- null_cfg_info, 0
+ null_cfg_info, "null", -1, 0
};
Backend loop_backend = {
loop_init, loop_free, null_reconfig, loop_send, null_sendbuffer, null_size,
null_special, null_get_specials, null_connected, null_exitcode, null_sendok,
null_ldisc, null_provide_ldisc, null_provide_logctx, null_unthrottle,
- null_cfg_info, 0
+ null_cfg_info, "loop", -1, 0
};
struct loop_state {
* Override the default protocol if PLINK_PROTOCOL is set.
*/
char *p = getenv("PLINK_PROTOCOL");
- int i;
if (p) {
- for (i = 0; backends[i].backend != NULL; i++) {
- if (!strcmp(backends[i].name, p)) {
- default_protocol = cfg.protocol = backends[i].protocol;
- default_port = cfg.port =
- backends[i].backend->default_port;
- break;
- }
+ const Backend *b = backend_from_name(p);
+ if (b) {
+ default_protocol = cfg.protocol = b->protocol;
+ default_port = cfg.port = b->default_port;
}
}
}
*/
r = strchr(p, ',');
if (r) {
- int i, j;
- for (i = 0; backends[i].backend != NULL; i++) {
- j = strlen(backends[i].name);
- if (j == r - p &&
- !memcmp(backends[i].name, p, j)) {
- default_protocol = cfg.protocol =
- backends[i].protocol;
- portnumber =
- backends[i].backend->default_port;
- p = r + 1;
- break;
- }
+ const Backend *b;
+ *r = '\0';
+ b = backend_from_name(p);
+ if (b) {
+ default_protocol = cfg.protocol = b->protocol;
+ portnumber = b->default_port;
}
+ p = r + 1;
}
/*
* Select protocol. This is farmed out into a table in a
* separate file to enable an ssh-free variant.
*/
- {
- int i;
- back = NULL;
- for (i = 0; backends[i].backend != NULL; i++)
- if (backends[i].protocol == cfg.protocol) {
- back = backends[i].backend;
- break;
- }
- if (back == NULL) {
- fprintf(stderr,
- "Internal fault: Unsupported protocol found\n");
- return 1;
- }
+ back = backend_from_proto(cfg.protocol);
+ if (back == NULL) {
+ fprintf(stderr,
+ "Internal fault: Unsupported protocol found\n");
+ return 1;
}
/*
pty_provide_logctx,
pty_unthrottle,
pty_cfg_info,
+ "pty",
+ -1,
1
};
Backend *select_backend(Config *cfg)
{
- int i;
- Backend *back = NULL;
- for (i = 0; backends[i].backend != NULL; i++)
- if (backends[i].protocol == cfg->protocol) {
- back = backends[i].backend;
- break;
- }
+ Backend *back = backend_from_proto(cfg->protocol);
assert(back != NULL);
return back;
}
default_protocol = be_default_protocol;
/* Find the appropriate default port. */
{
- int i;
+ Backend *b = backend_from_proto(default_protocol);
default_port = 0; /* illegal */
- for (i = 0; backends[i].backend != NULL; i++)
- if (backends[i].protocol == default_protocol) {
- default_port = backends[i].backend->default_port;
- break;
- }
+ if (b)
+ default_port = b->default_port;
}
return pt_main(argc, argv);
}
serial_provide_logctx,
serial_unthrottle,
serial_cfg_info,
+ "serial",
+ PROT_SERIAL,
1
};
* Select protocol. This is farmed out into a table in a
* separate file to enable an ssh-free variant.
*/
- back = NULL;
- for (i = 0; backends[i].backend != NULL; i++)
- if (backends[i].protocol == cfg.protocol) {
- back = backends[i].backend;
- break;
- }
+ back = backend_from_proto(cfg.protocol);
if (back == NULL) {
char *str = dupprintf("%s Internal Error", appname);
MessageBox(NULL, "Unsupported protocol number found",
default_protocol = be_default_protocol;
/* Find the appropriate default port. */
{
- int i;
+ Backend *b = backend_from_proto(default_protocol);
default_port = 0; /* illegal */
- for (i = 0; backends[i].backend != NULL; i++)
- if (backends[i].protocol == default_protocol) {
- default_port = backends[i].backend->default_port;
- break;
- }
+ if (b)
+ default_port = b->default_port;
}
cfg.logtype = LGTYP_NONE;
char *p = getenv("PLINK_PROTOCOL");
int i;
if (p) {
- for (i = 0; backends[i].backend != NULL; i++) {
- if (!strcmp(backends[i].name, p)) {
- default_protocol = cfg.protocol = backends[i].protocol;
- default_port = cfg.port =
- backends[i].backend->default_port;
- break;
- }
+ const Backend *b = backend_from_name(p);
+ if (b) {
+ default_protocol = cfg.protocol = b->protocol;
+ default_port = cfg.port = b->default_port;
}
}
}
*/
r = strchr(p, ',');
if (r) {
- int i, j;
- for (i = 0; backends[i].backend != NULL; i++) {
- j = strlen(backends[i].name);
- if (j == r - p &&
- !memcmp(backends[i].name, p, j)) {
- default_protocol = cfg.protocol =
- backends[i].protocol;
- portnumber =
- backends[i].backend->default_port;
- p = r + 1;
- break;
- }
+ const Backend *b;
+ *r = '\0';
+ b = backend_from_name(p);
+ if (b) {
+ default_protocol = cfg.protocol = b->protocol;
+ portnumber = b->default_port;
}
+ p = r + 1;
}
/*
* Select protocol. This is farmed out into a table in a
* separate file to enable an ssh-free variant.
*/
- {
- int i;
- back = NULL;
- for (i = 0; backends[i].backend != NULL; i++)
- if (backends[i].protocol == cfg.protocol) {
- back = backends[i].backend;
- break;
- }
- if (back == NULL) {
- fprintf(stderr,
- "Internal fault: Unsupported protocol found\n");
- return 1;
- }
+ back = backend_from_proto(cfg.protocol);
+ if (back == NULL) {
+ fprintf(stderr,
+ "Internal fault: Unsupported protocol found\n");
+ return 1;
}
/*
serial_provide_logctx,
serial_unthrottle,
serial_cfg_info,
+ "serial",
+ PROT_SERIAL,
1
};