From 55123b105d5caf1e53cc36eac9f623ef17529d07 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Wed, 27 Feb 2019 20:30:47 +0000 Subject: [PATCH] load_settings, do_defaults: return a boolean success flag. Now the caller of one of those functions can tell whether the session it loaded actually existed at all, or whether it was made up by settings.c. --- putty.h | 8 ++++++-- settings.c | 11 +++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/putty.h b/putty.h index 94e31641..cc14e6e7 100644 --- a/putty.h +++ b/putty.h @@ -1516,16 +1516,20 @@ void random_destroy_seed(void); /* * Exports from settings.c. + * + * load_settings() and do_defaults() return false if the provided + * session name didn't actually exist. But they still fill in the + * provided Conf with _something_. */ const struct BackendVtable *backend_vt_from_name(const char *name); const struct BackendVtable *backend_vt_from_proto(int proto); char *get_remote_username(Conf *conf); /* dynamically allocated */ char *save_settings(const char *section, Conf *conf); void save_open_settings(settings_w *sesskey, Conf *conf); -void load_settings(const char *section, Conf *conf); +bool load_settings(const char *section, Conf *conf); void load_open_settings(settings_r *sesskey, Conf *conf); void get_sesslist(struct sesslist *, bool allocate); -void do_defaults(const char *, Conf *); +bool do_defaults(const char *, Conf *); void registry_cleanup(void); /* diff --git a/settings.c b/settings.c index bc98b155..79d2c861 100644 --- a/settings.c +++ b/settings.c @@ -780,16 +780,19 @@ void save_open_settings(settings_w *sesskey, Conf *conf) wmap(sesskey, "SSHManualHostKeys", conf, CONF_ssh_manual_hostkeys, false); } -void load_settings(const char *section, Conf *conf) +bool load_settings(const char *section, Conf *conf) { settings_r *sesskey; sesskey = open_settings_r(section); + bool exists = (sesskey != NULL); load_open_settings(sesskey, conf); close_settings_r(sesskey); - if (conf_launchable(conf)) + if (exists && conf_launchable(conf)) add_session_to_jumplist(section); + + return exists; } void load_open_settings(settings_r *sesskey, Conf *conf) @@ -1242,9 +1245,9 @@ void load_open_settings(settings_r *sesskey, Conf *conf) gppmap(sesskey, "SSHManualHostKeys", conf, CONF_ssh_manual_hostkeys); } -void do_defaults(const char *session, Conf *conf) +bool do_defaults(const char *session, Conf *conf) { - load_settings(session, conf); + return load_settings(session, conf); } static int sessioncmp(const void *av, const void *bv)