1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-08 08:58:00 +00:00

Mention any extant downstreams in close warning.

Suggested by Brian Rak.
This commit is contained in:
Jacob Nevins 2021-02-21 14:17:03 +00:00
parent a859955689
commit 0ec45782b5
6 changed files with 46 additions and 8 deletions

View File

@ -652,6 +652,12 @@ struct BackendVtable {
/* Only implemented in the SSH protocol: check whether a
* connection-sharing upstream exists for a given configuration. */
bool (*test_for_upstream)(const char *host, int port, Conf *conf);
/* Special-purpose function to return additional information to put
* in a "are you sure you want to close this session" dialog;
* return NULL if no such info, otherwise caller must free.
* Only implemented in the SSH protocol, to warn about downstream
* connections that would be lost if this one were terminated. */
char *(*close_warn_text)(Backend *be);
/* 'id' is a machine-readable name for the backend, used in
* saved-session storage. 'displayname' is a human-readable name

1
raw.c
View File

@ -324,6 +324,7 @@ const BackendVtable raw_backend = {
.unthrottle = raw_unthrottle,
.cfg_info = raw_cfg_info,
.test_for_upstream = NULL,
.close_warn_text = NULL,
.id = "raw",
.displayname = "Raw",
.protocol = PROT_RAW,

View File

@ -422,6 +422,7 @@ const BackendVtable rlogin_backend = {
.unthrottle = rlogin_unthrottle,
.cfg_info = rlogin_cfg_info,
.test_for_upstream = NULL,
.close_warn_text = NULL,
.id = "rlogin",
.displayname = "Rlogin",
.protocol = PROT_RLOGIN,

15
ssh.c
View File

@ -691,6 +691,19 @@ static bool ssh_test_for_upstream(const char *host, int port, Conf *conf)
return ret;
}
static char *ssh_close_warn_text(Backend *be)
{
Ssh *ssh = container_of(be, Ssh, backend);
if (!ssh->connshare)
return NULL;
int ndowns = share_ndownstreams(ssh->connshare);
if (ndowns == 0)
return NULL;
char *msg = dupprintf("This will also close %d downstream connection%s.",
ndowns, ndowns==1 ? "" : "s");
return msg;
}
static const PlugVtable Ssh_plugvt = {
.log = ssh_socket_log,
.closing = ssh_closing,
@ -1204,6 +1217,7 @@ const BackendVtable ssh_backend = {
.unthrottle = ssh_unthrottle,
.cfg_info = ssh_cfg_info,
.test_for_upstream = ssh_test_for_upstream,
.close_warn_text = ssh_close_warn_text,
.id = "ssh",
.displayname = "SSH",
.protocol = PROT_SSH,
@ -1227,6 +1241,7 @@ const BackendVtable sshconn_backend = {
.unthrottle = ssh_unthrottle,
.cfg_info = ssh_cfg_info,
.test_for_upstream = ssh_test_for_upstream,
.close_warn_text = ssh_close_warn_text,
.id = "ssh-connection",
.displayname = "Bare ssh-connection",
.protocol = PROT_SSHCONN,

View File

@ -618,13 +618,21 @@ gint delete_window(GtkWidget *widget, GdkEvent *event, GtkFrontend *inst)
*/
if (!find_and_raise_dialog(inst, DIALOG_SLOT_WARN_ON_CLOSE)) {
char *title = dupcat(appname, " Exit Confirmation");
char *msg, *additional = NULL;
if (inst && inst->backend && inst->backend->vt->close_warn_text) {
additional = inst->backend->vt->close_warn_text(inst->backend);
}
msg = dupprintf("Are you sure you want to close this session?%s%s",
additional ? "\n" : "",
additional ? additional : "");
GtkWidget *dialog = create_message_box(
inst->window, title,
"Are you sure you want to close this session?",
inst->window, title, msg,
string_width("Most of the width of the above text"),
false, &buttons_yn, warn_on_close_callback, inst);
register_dialog(&inst->seat, DIALOG_SLOT_WARN_ON_CLOSE, dialog);
sfree(title);
sfree(msg);
sfree(additional);
}
return true;
}

View File

@ -2122,16 +2122,23 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
case WM_CREATE:
break;
case WM_CLOSE: {
char *str;
char *title, *msg, *additional = NULL;
show_mouseptr(true);
str = dupprintf("%s Exit Confirmation", appname);
title = dupprintf("%s Exit Confirmation", appname);
if (backend && backend->vt->close_warn_text) {
additional = backend->vt->close_warn_text(backend);
}
msg = dupprintf("Are you sure you want to close this session?%s%s",
additional ? "\n" : "",
additional ? additional : "");
if (session_closed || !conf_get_bool(conf, CONF_warn_on_close) ||
MessageBox(hwnd,
"Are you sure you want to close this session?",
str, MB_ICONWARNING | MB_OKCANCEL | MB_DEFBUTTON1)
MessageBox(hwnd, msg, title,
MB_ICONWARNING | MB_OKCANCEL | MB_DEFBUTTON1)
== IDOK)
DestroyWindow(hwnd);
sfree(str);
sfree(title);
sfree(msg);
sfree(additional);
return 0;
}
case WM_DESTROY: