diff --git a/cmdline.c b/cmdline.c index aa8cfda4..1ae74406 100644 --- a/cmdline.c +++ b/cmdline.c @@ -152,6 +152,18 @@ bool cmdline_seat_verbose(Seat *seat) { return cmdline_verbose(); } bool cmdline_lp_verbose(LogPolicy *lp) { return cmdline_verbose(); } bool cmdline_loaded_session(void) { return loaded_session; } +static void set_protocol(Conf *conf, int protocol) +{ + settings_set_default_protocol(protocol); + conf_set_int(conf, CONF_protocol, protocol); +} + +static void set_port(Conf *conf, int port) +{ + settings_set_default_port(port); + conf_set_int(conf, CONF_port, port); +} + int cmdline_process_param(const char *p, char *value, int need_save, Conf *conf) { @@ -269,9 +281,7 @@ int cmdline_process_param(const char *p, char *value, backend_vt_from_name(prefix); if (vt) { - default_protocol = vt->protocol; - conf_set_int(conf, CONF_protocol, - default_protocol); + set_protocol(conf, vt->protocol); port_override = vt->default_port; } else { cmdline_error("unrecognised protocol prefix '%s'", @@ -399,46 +409,38 @@ int cmdline_process_param(const char *p, char *value, RETURN(1); UNAVAILABLE_IN(TOOLTYPE_FILETRANSFER | TOOLTYPE_NONNETWORK); SAVEABLE(0); - default_protocol = PROT_SSH; - default_port = 22; - conf_set_int(conf, CONF_protocol, default_protocol); - conf_set_int(conf, CONF_port, default_port); + 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); - default_protocol = PROT_TELNET; - default_port = 23; - conf_set_int(conf, CONF_protocol, default_protocol); - conf_set_int(conf, CONF_port, default_port); + 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); - default_protocol = PROT_RLOGIN; - default_port = 513; - conf_set_int(conf, CONF_protocol, default_protocol); - conf_set_int(conf, CONF_port, default_port); + 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); - default_protocol = PROT_RAW; - conf_set_int(conf, CONF_protocol, default_protocol); + 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); - default_protocol = PROT_SERIAL; - conf_set_int(conf, CONF_protocol, default_protocol); + 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)); diff --git a/pscp.c b/pscp.c index dc9ebb8d..c25226b9 100644 --- a/pscp.c +++ b/pscp.c @@ -2229,7 +2229,7 @@ int psftp_main(int argc, char *argv[]) int i; bool sanitise_stderr = true; - default_protocol = PROT_TELNET; + settings_set_default_protocol(PROT_TELNET); sk_init(); diff --git a/putty.h b/putty.h index b1d0d30b..0fac7592 100644 --- a/putty.h +++ b/putty.h @@ -4,19 +4,6 @@ #include /* for wchar_t */ #include /* for INT_MAX */ -/* - * Global variables. Most modules declare these `extern', but - * window.c will do `#define PUTTY_DO_GLOBALS' before including this - * module, and so will get them properly defined. - */ -#ifndef GLOBAL -#ifdef PUTTY_DO_GLOBALS -#define GLOBAL -#else -#define GLOBAL extern -#endif -#endif - #include "defs.h" #include "puttyps.h" #include "network.h" @@ -578,14 +565,6 @@ extern const int be_default_protocol; */ extern const char *const appname; -/* - * Likewise, these two variables are set up when the application - * initialises, and inform all default-settings accesses after - * that. - */ -GLOBAL int default_protocol; -GLOBAL int default_port; - /* * Mechanism for getting text strings such as usernames and passwords * from the front-end. @@ -1562,6 +1541,8 @@ void load_open_settings(settings_r *sesskey, Conf *conf); void get_sesslist(struct sesslist *, bool allocate); bool do_defaults(const char *, Conf *); void registry_cleanup(void); +void settings_set_default_protocol(int); +void settings_set_default_port(int); /* * Functions used by settings.c to provide platform-specific diff --git a/settings.c b/settings.c index 7bf7e4d2..5eaaa5f1 100644 --- a/settings.c +++ b/settings.c @@ -69,6 +69,10 @@ const char *const ttymodes[] = { "CS7", "CS8", "PARENB", "PARODD", NULL }; +static int default_protocol, default_port; +void settings_set_default_protocol(int newval) { default_protocol = newval; } +void settings_set_default_port(int newval) { default_port = newval; } + /* * Convenience functions to access the backends[] array * (which is only present in tools that manage settings). diff --git a/unix/uxplink.c b/unix/uxplink.c index 0d555a70..f75b04ce 100644 --- a/unix/uxplink.c +++ b/unix/uxplink.c @@ -598,8 +598,8 @@ int main(int argc, char **argv) * Initialise port and protocol to sensible defaults. (These * will be overridden by more or less anything.) */ - default_protocol = PROT_SSH; - default_port = 22; + settings_set_default_protocol(PROT_SSH); + settings_set_default_port(22); bufchain_init(&stdout_data); bufchain_init(&stderr_data); @@ -615,8 +615,8 @@ int main(int argc, char **argv) */ conf = conf_new(); do_defaults(NULL, conf); - default_protocol = conf_get_int(conf, CONF_protocol); - default_port = conf_get_int(conf, CONF_port); + settings_set_default_protocol(conf_get_int(conf, CONF_protocol)); + settings_set_default_port(conf_get_int(conf, CONF_port)); errors = false; { /* @@ -626,10 +626,10 @@ int main(int argc, char **argv) if (p) { const struct BackendVtable *vt = backend_vt_from_name(p); if (vt) { - default_protocol = vt->protocol; - default_port = vt->default_port; - conf_set_int(conf, CONF_protocol, default_protocol); - conf_set_int(conf, CONF_port, default_port); + settings_set_default_protocol(vt->protocol); + settings_set_default_port(vt->default_port); + conf_set_int(conf, CONF_protocol, vt->protocol); + conf_set_int(conf, CONF_port, vt->default_port); } } } diff --git a/unix/uxpterm.c b/unix/uxpterm.c index ff8ff6cd..9d768a4c 100644 --- a/unix/uxpterm.c +++ b/unix/uxpterm.c @@ -48,7 +48,7 @@ char *make_default_wintitle(char *hostname) void setup(bool single) { - default_protocol = -1; + settings_set_default_protocol(-1); if (single) pty_pre_init(); diff --git a/unix/uxputty.c b/unix/uxputty.c index 3611712b..1b44c2fd 100644 --- a/unix/uxputty.c +++ b/unix/uxputty.c @@ -85,13 +85,13 @@ const unsigned cmdline_tooltype = void setup(bool single) { sk_init(); - default_protocol = be_default_protocol; + settings_set_default_protocol(be_default_protocol); /* Find the appropriate default port. */ { const struct BackendVtable *vt = - backend_vt_from_proto(default_protocol); - default_port = 0; /* illegal */ + backend_vt_from_proto(be_default_protocol); + settings_set_default_port(0); /* illegal */ if (vt) - default_port = vt->default_port; + settings_set_default_port(vt->default_port); } } diff --git a/windows/window.c b/windows/window.c index b223cb9a..3125c55a 100644 --- a/windows/window.c +++ b/windows/window.c @@ -532,14 +532,14 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) char *p; bool special_launchable_argument = false; - default_protocol = be_default_protocol; + settings_set_default_protocol(be_default_protocol); /* Find the appropriate default port. */ { const struct BackendVtable *vt = - backend_vt_from_proto(default_protocol); - default_port = 0; /* illegal */ + backend_vt_from_proto(be_default_protocol); + settings_set_default_port(0); /* illegal */ if (vt) - default_port = vt->default_port; + settings_set_default_port(vt->default_port); } conf_set_int(conf, CONF_logtype, LGTYP_NONE); diff --git a/windows/winplink.c b/windows/winplink.c index d9b2020d..dd0bcc34 100644 --- a/windows/winplink.c +++ b/windows/winplink.c @@ -252,16 +252,16 @@ int main(int argc, char **argv) * Initialise port and protocol to sensible defaults. (These * will be overridden by more or less anything.) */ - default_protocol = PROT_SSH; - default_port = 22; + settings_set_default_protocol(PROT_SSH); + settings_set_default_port(22); /* * Process the command line. */ conf = conf_new(); do_defaults(NULL, conf); - default_protocol = conf_get_int(conf, CONF_protocol); - default_port = conf_get_int(conf, CONF_port); + settings_set_default_protocol(conf_get_int(conf, CONF_protocol)); + settings_set_default_port(conf_get_int(conf, CONF_port)); errors = false; { /* @@ -271,10 +271,10 @@ int main(int argc, char **argv) if (p) { const struct BackendVtable *vt = backend_vt_from_name(p); if (vt) { - default_protocol = vt->protocol; - default_port = vt->default_port; - conf_set_int(conf, CONF_protocol, default_protocol); - conf_set_int(conf, CONF_port, default_port); + settings_set_default_protocol(vt->protocol); + settings_set_default_port(vt->default_port); + conf_set_int(conf, CONF_protocol, vt->protocol); + conf_set_int(conf, CONF_port, vt->default_port); } } }