2003-03-29 19:52:50 +00:00
|
|
|
/*
|
|
|
|
* Unix PuTTY main program.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2003-03-31 12:10:53 +00:00
|
|
|
#include <ctype.h>
|
2003-03-31 11:21:07 +00:00
|
|
|
#include <stdlib.h>
|
2003-03-29 19:52:50 +00:00
|
|
|
#include <assert.h>
|
|
|
|
#include <unistd.h>
|
2015-08-22 13:07:02 +00:00
|
|
|
#include <gtk/gtk.h>
|
2004-10-06 22:31:07 +00:00
|
|
|
#include <gdk/gdk.h>
|
2003-03-29 19:52:50 +00:00
|
|
|
|
Make the configuration dialog non-modal.
Now every call to do_config_box is replaced with a call to
create_config_box, which returns immediately having constructed the
new GTK window object, and is passed a callback function which it will
arrange to be called when the dialog terminates (whether by OK or by
Cancel). That callback is now what triggers the construction of a
session window after 'Open' is pressed in the initial config box, or
the actual mid-session reconfiguration action after 'Apply' is pressed
in a Change Settings box.
We were already prepared to ignore the re-selection of 'Change
Settings' from the context menu of a window that already had a Change
Settings box open (and not accidentally create a second config box for
the same window); but now we do slightly better, by finding the
existing config box and un-minimising and raising it, in case the user
had forgotten it was there.
That's a useful featurelet, but not the main purpose of this change.
The mani point, of course, is that now the multi-window GtkApplication
based front ends now don't do anything confusing to the nesting of
gtk_main() when config boxes are involved. Whether you're changing the
settings of one (or more than one) of your already-running sessions,
preparing to start up a new PuTTY connection, or both at once, we stay
in the same top-level instance of gtk_main() and all sessions' top-
level callbacks continue to run sensibly.
2017-11-26 11:58:02 +00:00
|
|
|
#define MAY_REFER_TO_GTK_IN_HEADERS
|
|
|
|
|
2003-03-29 19:52:50 +00:00
|
|
|
#include "putty.h"
|
|
|
|
#include "storage.h"
|
|
|
|
|
2015-08-22 13:07:02 +00:00
|
|
|
#include "gtkcompat.h"
|
|
|
|
|
2005-02-06 15:52:00 +00:00
|
|
|
/*
|
|
|
|
* Stubs to avoid uxpty.c needing to be linked in.
|
|
|
|
*/
|
|
|
|
const int use_pty_argv = FALSE;
|
|
|
|
char **pty_argv; /* never used */
|
2016-03-23 22:13:30 +00:00
|
|
|
char *pty_osx_envrestore_prefix;
|
2005-02-06 15:52:00 +00:00
|
|
|
|
2003-03-29 19:52:50 +00:00
|
|
|
/*
|
|
|
|
* Clean up and exit.
|
|
|
|
*/
|
|
|
|
void cleanup_exit(int code)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Clean up.
|
|
|
|
*/
|
|
|
|
sk_cleanup();
|
|
|
|
random_save_seed();
|
|
|
|
exit(code);
|
|
|
|
}
|
|
|
|
|
2018-09-11 15:23:38 +00:00
|
|
|
const struct Backend_vtable *select_backend(Conf *conf)
|
2003-03-29 19:52:50 +00:00
|
|
|
{
|
2018-09-11 15:23:38 +00:00
|
|
|
const struct Backend_vtable *vt =
|
|
|
|
backend_vt_from_proto(conf_get_int(conf, CONF_protocol));
|
|
|
|
assert(vt != NULL);
|
|
|
|
return vt;
|
2003-03-29 19:52:50 +00:00
|
|
|
}
|
|
|
|
|
Make the configuration dialog non-modal.
Now every call to do_config_box is replaced with a call to
create_config_box, which returns immediately having constructed the
new GTK window object, and is passed a callback function which it will
arrange to be called when the dialog terminates (whether by OK or by
Cancel). That callback is now what triggers the construction of a
session window after 'Open' is pressed in the initial config box, or
the actual mid-session reconfiguration action after 'Apply' is pressed
in a Change Settings box.
We were already prepared to ignore the re-selection of 'Change
Settings' from the context menu of a window that already had a Change
Settings box open (and not accidentally create a second config box for
the same window); but now we do slightly better, by finding the
existing config box and un-minimising and raising it, in case the user
had forgotten it was there.
That's a useful featurelet, but not the main purpose of this change.
The mani point, of course, is that now the multi-window GtkApplication
based front ends now don't do anything confusing to the nesting of
gtk_main() when config boxes are involved. Whether you're changing the
settings of one (or more than one) of your already-running sessions,
preparing to start up a new PuTTY connection, or both at once, we stay
in the same top-level instance of gtk_main() and all sessions' top-
level callbacks continue to run sensibly.
2017-11-26 11:58:02 +00:00
|
|
|
void initial_config_box(Conf *conf, post_dialog_fn_t after, void *afterctx)
|
2003-03-29 19:52:50 +00:00
|
|
|
{
|
2008-06-15 13:26:08 +00:00
|
|
|
char *title = dupcat(appname, " Configuration", NULL);
|
Make the configuration dialog non-modal.
Now every call to do_config_box is replaced with a call to
create_config_box, which returns immediately having constructed the
new GTK window object, and is passed a callback function which it will
arrange to be called when the dialog terminates (whether by OK or by
Cancel). That callback is now what triggers the construction of a
session window after 'Open' is pressed in the initial config box, or
the actual mid-session reconfiguration action after 'Apply' is pressed
in a Change Settings box.
We were already prepared to ignore the re-selection of 'Change
Settings' from the context menu of a window that already had a Change
Settings box open (and not accidentally create a second config box for
the same window); but now we do slightly better, by finding the
existing config box and un-minimising and raising it, in case the user
had forgotten it was there.
That's a useful featurelet, but not the main purpose of this change.
The mani point, of course, is that now the multi-window GtkApplication
based front ends now don't do anything confusing to the nesting of
gtk_main() when config boxes are involved. Whether you're changing the
settings of one (or more than one) of your already-running sessions,
preparing to start up a new PuTTY connection, or both at once, we stay
in the same top-level instance of gtk_main() and all sessions' top-
level callbacks continue to run sensibly.
2017-11-26 11:58:02 +00:00
|
|
|
create_config_box(title, conf, FALSE, 0, after, afterctx);
|
2008-06-15 13:26:08 +00:00
|
|
|
sfree(title);
|
2003-03-29 19:52:50 +00:00
|
|
|
}
|
|
|
|
|
2003-04-12 17:37:15 +00:00
|
|
|
const int use_event_log = 1, new_session = 1, saved_sessions = 1;
|
2016-03-27 13:10:06 +00:00
|
|
|
const int dup_check_launchable = 1;
|
2003-04-09 18:46:45 +00:00
|
|
|
|
2003-03-31 11:42:45 +00:00
|
|
|
char *make_default_wintitle(char *hostname)
|
|
|
|
{
|
2008-06-15 13:26:08 +00:00
|
|
|
return dupcat(hostname, " - ", appname, NULL);
|
2003-03-31 11:42:45 +00:00
|
|
|
}
|
|
|
|
|
2004-10-06 22:31:07 +00:00
|
|
|
/*
|
|
|
|
* X11-forwarding-related things suitable for Gtk app.
|
|
|
|
*/
|
|
|
|
|
|
|
|
char *platform_get_x_display(void) {
|
|
|
|
const char *display;
|
|
|
|
/* Try to take account of --display and what have you. */
|
|
|
|
if (!(display = gdk_get_display()))
|
|
|
|
/* fall back to traditional method */
|
|
|
|
display = getenv("DISPLAY");
|
|
|
|
return dupstr(display);
|
|
|
|
}
|
|
|
|
|
2013-11-17 14:05:41 +00:00
|
|
|
const int share_can_be_downstream = TRUE;
|
|
|
|
const int share_can_be_upstream = TRUE;
|
|
|
|
|
2016-03-23 21:58:40 +00:00
|
|
|
void setup(int single)
|
2003-03-29 19:52:50 +00:00
|
|
|
{
|
|
|
|
sk_init();
|
|
|
|
flags = FLAG_VERBOSE | FLAG_INTERACTIVE;
|
Centralise PuTTY and Plink's non-option argument handling.
This is another piece of long-overdue refactoring similar to the
recent commit e3796cb77. But where that one dealt with normalisation
of stuff already stored _in_ a Conf by whatever means (including, in
particular, handling a user typing 'username@host.name' into the
Hostname box of the GUI session dialog box), this one deals with
handling argv entries and putting them into the Conf.
This isn't exactly a pure no-functional-change-at-all refactoring. On
the other hand, it isn't a full-on cleanup that completely
rationalises all the user-visible behaviour as well as the code
structure. It's somewhere in between: I've preserved all the behaviour
quirks that I could imagine a reason for having intended, but taken
the opportunity to _not_ faithfully replicate anything I thought was
clearly just a bug.
So, for example, the following inconsistency is carefully preserved:
the command 'plink -load session nextword' treats 'nextword' as a host
name if the loaded session hasn't provided a hostname already, and
otherwise treats 'nextword' as the remote command to execute on the
already-specified remote host, but the same combination of arguments
to GUI PuTTY will _always_ treat 'nextword' as a hostname, overriding
a hostname (if any) in the saved session. That makes some sense to me
because of the different shapes of the overall command lines.
On the other hand, there are two behaviour changes I know of as a
result of this commit: a third argument to GUI PuTTY (after a hostname
and port) now provokes an error message instead of being silently
ignored, and in Plink, if you combine a -P option (specifying a port
number) with the historical comma-separated protocol selection prefix
on the hostname argument (which I'd completely forgotten even existed
until this piece of work), then the -P will now override the selected
protocol's default port number, whereas previously the default port
would win. For example, 'plink -P 12345 telnet,hostname' will now
connect via Telnet to port 12345 instead of to port 23.
There may be scope for removing or rethinking some of the command-
line syntax quirks in the wake of this change. If we do decide to do
anything like that, then hopefully having it all in one place will
make it easier to remove or change things consistently across the
tools.
2017-12-07 19:59:43 +00:00
|
|
|
cmdline_tooltype |= TOOLTYPE_HOST_ARG | TOOLTYPE_PORT_ARG;
|
2003-03-29 19:52:50 +00:00
|
|
|
default_protocol = be_default_protocol;
|
|
|
|
/* Find the appropriate default port. */
|
|
|
|
{
|
2018-09-11 15:23:38 +00:00
|
|
|
const struct Backend_vtable *vt =
|
|
|
|
backend_vt_from_proto(default_protocol);
|
2003-03-29 19:52:50 +00:00
|
|
|
default_port = 0; /* illegal */
|
2018-09-11 15:23:38 +00:00
|
|
|
if (vt)
|
|
|
|
default_port = vt->default_port;
|
2003-03-29 19:52:50 +00:00
|
|
|
}
|
|
|
|
}
|