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);
|
|
|
|
}
|
|
|
|
|
Post-release destabilisation! Completely remove the struct type
'Config' in putty.h, which stores all PuTTY's settings and includes an
arbitrary length limit on every single one of those settings which is
stored in string form. In place of it is 'Conf', an opaque data type
everywhere outside the new file conf.c, which stores a list of (key,
value) pairs in which every key contains an integer identifying a
configuration setting, and for some of those integers the key also
contains extra parts (so that, for instance, CONF_environmt is a
string-to-string mapping). Everywhere that a Config was previously
used, a Conf is now; everywhere there was a Config structure copy,
conf_copy() is called; every lookup, adjustment, load and save
operation on a Config has been rewritten; and there's a mechanism for
serialising a Conf into a binary blob and back for use with Duplicate
Session.
User-visible effects of this change _should_ be minimal, though I
don't doubt I've introduced one or two bugs here and there which will
eventually be found. The _intended_ visible effects of this change are
that all arbitrary limits on configuration strings and lists (e.g.
limit on number of port forwardings) should now disappear; that list
boxes in the configuration will now be displayed in a sorted order
rather than the arbitrary order in which they were added to the list
(since the underlying data structure is now a sorted tree234 rather
than an ad-hoc comma-separated string); and one more specific change,
which is that local and dynamic port forwardings on the same port
number are now mutually exclusive in the configuration (putting 'D' in
the key rather than the value was a mistake in the first place).
One other reorganisation as a result of this is that I've moved all
the dialog.c standard handlers (dlg_stdeditbox_handler and friends)
out into config.c, because I can't really justify calling them generic
any more. When they took a pointer to an arbitrary structure type and
the offset of a field within that structure, they were independent of
whether that structure was a Config or something completely different,
but now they really do expect to talk to a Conf, which can _only_ be
used for PuTTY configuration, so I've renamed them all things like
conf_editbox_handler and moved them out of the nominally independent
dialog-box management module into the PuTTY-specific config.c.
[originally from svn r9214]
2011-07-14 18:52:21 +00:00
|
|
|
Backend *select_backend(Conf *conf)
|
2003-03-29 19:52:50 +00:00
|
|
|
{
|
Post-release destabilisation! Completely remove the struct type
'Config' in putty.h, which stores all PuTTY's settings and includes an
arbitrary length limit on every single one of those settings which is
stored in string form. In place of it is 'Conf', an opaque data type
everywhere outside the new file conf.c, which stores a list of (key,
value) pairs in which every key contains an integer identifying a
configuration setting, and for some of those integers the key also
contains extra parts (so that, for instance, CONF_environmt is a
string-to-string mapping). Everywhere that a Config was previously
used, a Conf is now; everywhere there was a Config structure copy,
conf_copy() is called; every lookup, adjustment, load and save
operation on a Config has been rewritten; and there's a mechanism for
serialising a Conf into a binary blob and back for use with Duplicate
Session.
User-visible effects of this change _should_ be minimal, though I
don't doubt I've introduced one or two bugs here and there which will
eventually be found. The _intended_ visible effects of this change are
that all arbitrary limits on configuration strings and lists (e.g.
limit on number of port forwardings) should now disappear; that list
boxes in the configuration will now be displayed in a sorted order
rather than the arbitrary order in which they were added to the list
(since the underlying data structure is now a sorted tree234 rather
than an ad-hoc comma-separated string); and one more specific change,
which is that local and dynamic port forwardings on the same port
number are now mutually exclusive in the configuration (putting 'D' in
the key rather than the value was a mistake in the first place).
One other reorganisation as a result of this is that I've moved all
the dialog.c standard handlers (dlg_stdeditbox_handler and friends)
out into config.c, because I can't really justify calling them generic
any more. When they took a pointer to an arbitrary structure type and
the offset of a field within that structure, they were independent of
whether that structure was a Config or something completely different,
but now they really do expect to talk to a Conf, which can _only_ be
used for PuTTY configuration, so I've renamed them all things like
conf_editbox_handler and moved them out of the nominally independent
dialog-box management module into the PuTTY-specific config.c.
[originally from svn r9214]
2011-07-14 18:52:21 +00:00
|
|
|
Backend *back = backend_from_proto(conf_get_int(conf, CONF_protocol));
|
2003-03-29 19:52:50 +00:00
|
|
|
assert(back != NULL);
|
|
|
|
return back;
|
|
|
|
}
|
|
|
|
|
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. */
|
|
|
|
{
|
2007-06-30 21:56:44 +00:00
|
|
|
Backend *b = backend_from_proto(default_protocol);
|
2003-03-29 19:52:50 +00:00
|
|
|
default_port = 0; /* illegal */
|
2007-06-30 21:56:44 +00:00
|
|
|
if (b)
|
|
|
|
default_port = b->default_port;
|
2003-03-29 19:52:50 +00:00
|
|
|
}
|
|
|
|
}
|