1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-06-30 11:02:48 -05: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]
This commit is contained in:
Simon Tatham
2011-07-14 18:52:21 +00:00
parent 7aba365ca9
commit a1f3b7a358
64 changed files with 4443 additions and 3303 deletions

View File

@ -42,8 +42,8 @@ void gtk_setup_config_box(struct controlbox *b, int midsession, void *win)
"Control the scrollback in the window");
ctrl_checkbox(s, "Scrollbar on left", 'l',
HELPCTX(no_help),
dlg_stdcheckbox_handler,
I(offsetof(Config,scrollbar_on_left)));
conf_checkbox_handler,
I(CONF_scrollbar_on_left));
/*
* Really this wants to go just after `Display scrollbar'. See
* if we can find that control, and do some shuffling.
@ -51,7 +51,7 @@ void gtk_setup_config_box(struct controlbox *b, int midsession, void *win)
for (i = 0; i < s->ncontrols; i++) {
c = s->ctrls[i];
if (c->generic.type == CTRL_CHECKBOX &&
c->generic.context.i == offsetof(Config,scrollbar)) {
c->generic.context.i == CONF_scrollbar) {
/*
* Control i is the scrollbar checkbox.
* Control s->ncontrols-1 is the scrollbar-on-left one.
@ -89,29 +89,29 @@ void gtk_setup_config_box(struct controlbox *b, int midsession, void *win)
"Fonts for displaying non-bold text");
ctrl_fontsel(s, "Font used for ordinary text", 'f',
HELPCTX(no_help),
dlg_stdfontsel_handler, I(offsetof(Config,font)));
conf_fontsel_handler, I(CONF_font));
ctrl_fontsel(s, "Font used for wide (CJK) text", 'w',
HELPCTX(no_help),
dlg_stdfontsel_handler, I(offsetof(Config,widefont)));
conf_fontsel_handler, I(CONF_widefont));
s = ctrl_getset(b, "Window/Fonts", "fontbold",
"Fonts for displaying bolded text");
ctrl_fontsel(s, "Font used for bolded text", 'b',
HELPCTX(no_help),
dlg_stdfontsel_handler, I(offsetof(Config,boldfont)));
conf_fontsel_handler, I(CONF_boldfont));
ctrl_fontsel(s, "Font used for bold wide text", 'i',
HELPCTX(no_help),
dlg_stdfontsel_handler, I(offsetof(Config,wideboldfont)));
conf_fontsel_handler, I(CONF_wideboldfont));
ctrl_checkbox(s, "Use shadow bold instead of bold fonts", 'u',
HELPCTX(no_help),
dlg_stdcheckbox_handler,
I(offsetof(Config,shadowbold)));
conf_checkbox_handler,
I(CONF_shadowbold));
ctrl_text(s, "(Note that bold fonts or shadow bolding are only"
" used if you have not requested bolding to be done by"
" changing the text colour.)",
HELPCTX(no_help));
ctrl_editbox(s, "Horizontal offset for shadow bold:", 'z', 20,
HELPCTX(no_help), dlg_stdeditbox_handler,
I(offsetof(Config,shadowboldoffset)), I(-1));
HELPCTX(no_help), conf_editbox_handler,
I(CONF_shadowboldoffset), I(-1));
/*
* Markus Kuhn feels, not totally unreasonably, that it's good
@ -125,8 +125,8 @@ void gtk_setup_config_box(struct controlbox *b, int midsession, void *win)
"Character set translation on received data");
ctrl_checkbox(s, "Override with UTF-8 if locale says so", 'l',
HELPCTX(translation_utf8_override),
dlg_stdcheckbox_handler,
I(offsetof(Config,utf8_override)));
conf_checkbox_handler,
I(CONF_utf8_override));
if (!midsession) {
/*
@ -137,8 +137,7 @@ void gtk_setup_config_box(struct controlbox *b, int midsession, void *win)
s = ctrl_getset(b, "Window/Behaviour", "x11",
"X Window System settings");
ctrl_editbox(s, "Window class name:", 'z', 50,
HELPCTX(no_help), dlg_stdeditbox_handler,
I(offsetof(Config,winclass)),
I(sizeof(((Config *)0)->winclass)));
HELPCTX(no_help), conf_editbox_handler,
I(CONF_winclass), I(1));
}
}

View File

@ -330,11 +330,10 @@ void dlg_editbox_set(union control *ctrl, void *dlg, char const *text)
* The first call to "changed", if allowed to proceed normally,
* will cause an EVENT_VALCHANGE event on the edit box, causing
* a call to dlg_editbox_get() which will read the empty string
* out of the GtkEntry - and promptly write it straight into
* the Config structure, which is precisely where our `text'
* pointer is probably pointing, so the second editing
* operation will insert that instead of the string we
* originally asked for.
* out of the GtkEntry - and promptly write it straight into the
* Conf structure, which is precisely where our `text' pointer
* is probably pointing, so the second editing operation will
* insert that instead of the string we originally asked for.
*
* Hence, we must take our own copy of the text before we do
* this.
@ -344,7 +343,7 @@ void dlg_editbox_set(union control *ctrl, void *dlg, char const *text)
sfree(tmpstring);
}
void dlg_editbox_get(union control *ctrl, void *dlg, char *buffer, int length)
char *dlg_editbox_get(union control *ctrl, void *dlg)
{
struct dlgparam *dp = (struct dlgparam *)dlg;
struct uctrl *uc = dlg_find_byctrl(dp, ctrl);
@ -353,25 +352,16 @@ void dlg_editbox_get(union control *ctrl, void *dlg, char *buffer, int length)
#if GTK_CHECK_VERSION(2,4,0)
if (uc->combo) {
#if GTK_CHECK_VERSION(2,6,0)
strncpy(buffer,
gtk_combo_box_get_active_text(GTK_COMBO_BOX(uc->combo)),
length);
return dupstr(gtk_combo_box_get_active_text(GTK_COMBO_BOX(uc->combo)));
#else
strncpy(buffer,
gtk_entry_get_text
(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(uc->combo)))),
length);
return dupstr(gtk_entry_get_text
(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(uc->combo)))));
#endif
buffer[length-1] = '\0';
return;
}
#endif
if (uc->entry) {
strncpy(buffer, gtk_entry_get_text(GTK_ENTRY(uc->entry)),
length);
buffer[length-1] = '\0';
return;
return dupstr(gtk_entry_get_text(GTK_ENTRY(uc->entry)));
}
assert(!"We shouldn't get here");
@ -2826,12 +2816,12 @@ void set_dialog_action_area(GtkDialog *dlg, GtkWidget *w)
#endif
}
int do_config_box(const char *title, Config *cfg, int midsession,
int do_config_box(const char *title, Conf *conf, int midsession,
int protcfginfo)
{
GtkWidget *window, *hbox, *vbox, *cols, *label,
*tree, *treescroll, *panels, *panelvbox;
int index, level;
int index, level, protocol;
struct controlbox *ctrlbox;
char *path;
#if GTK_CHECK_VERSION(2,0,0)
@ -2859,8 +2849,9 @@ int do_config_box(const char *title, Config *cfg, int midsession,
window = gtk_dialog_new();
ctrlbox = ctrl_new_box();
setup_config_box(ctrlbox, midsession, cfg->protocol, protcfginfo);
unix_setup_config_box(ctrlbox, midsession, cfg->protocol);
protocol = conf_get_int(conf, CONF_protocol);
setup_config_box(ctrlbox, midsession, protocol, protcfginfo);
unix_setup_config_box(ctrlbox, midsession, protocol);
gtk_setup_config_box(ctrlbox, midsession, window);
gtk_window_set_title(GTK_WINDOW(window), title);
@ -3095,7 +3086,7 @@ int do_config_box(const char *title, Config *cfg, int midsession,
}
#endif
dp.data = cfg;
dp.data = conf;
dlg_refresh(NULL, &dp);
dp.shortcuts = &selparams[0].shortcuts;

File diff suppressed because it is too large Load Diff

View File

@ -89,7 +89,7 @@ long get_windowid(void *frontend);
void *get_window(void *frontend); /* void * to avoid depending on gtk.h */
/* Things pterm.c needs from gtkdlg.c */
int do_config_box(const char *title, Config *cfg,
int do_config_box(const char *title, Conf *conf,
int midsession, int protcfginfo);
void fatal_message_box(void *window, char *msg);
void about_box(void *window);
@ -100,7 +100,7 @@ int reallyclose(void *frontend);
/* Things pterm.c needs from {ptermm,uxputty}.c */
char *make_default_wintitle(char *hostname);
int process_nonoption_arg(char *arg, Config *cfg, int *allow_launch);
int process_nonoption_arg(char *arg, Conf *conf, int *allow_launch);
/* pterm.c needs this special function in xkeysym.c */
int keysym_to_unicode(int keysym);

View File

@ -12,7 +12,7 @@
#include "ssh.h"
#include "network.h"
void platform_get_x11_auth(struct X11Display *disp, const Config *cfg)
void platform_get_x11_auth(struct X11Display *disp, Conf *conf)
{
char *xauthfile;
int needs_free;

View File

@ -16,11 +16,11 @@ void unix_setup_config_box(struct controlbox *b, int midsession, int protocol)
union control *c;
/*
* The Config structure contains two Unix-specific elements
* which are not configured in here: stamp_utmp and
* login_shell. This is because pterm does not put up a
* configuration box right at the start, which is the only time
* when these elements would be useful to configure.
* The Conf structure contains two Unix-specific elements which
* are not configured in here: stamp_utmp and login_shell. This
* is because pterm does not put up a configuration box right at
* the start, which is the only time when these elements would
* be useful to configure.
*/
/*
@ -41,8 +41,8 @@ void unix_setup_config_box(struct controlbox *b, int midsession, int protocol)
for (i = 0; i < s->ncontrols; i++) {
c = s->ctrls[i];
if (c->generic.type == CTRL_RADIO &&
c->generic.context.i == offsetof(Config, proxy_type)) {
assert(c->generic.handler == dlg_stdradiobutton_handler);
c->generic.context.i == CONF_proxy_type) {
assert(c->generic.handler == conf_radiobutton_handler);
c->radio.nbuttons++;
c->radio.buttons =
sresize(c->radio.buttons, c->radio.nbuttons, char *);
@ -58,9 +58,8 @@ void unix_setup_config_box(struct controlbox *b, int midsession, int protocol)
for (i = 0; i < s->ncontrols; i++) {
c = s->ctrls[i];
if (c->generic.type == CTRL_EDITBOX &&
c->generic.context.i ==
offsetof(Config, proxy_telnet_command)) {
assert(c->generic.handler == dlg_stdeditbox_handler);
c->generic.context.i == CONF_proxy_telnet_command) {
assert(c->generic.handler == conf_editbox_handler);
sfree(c->generic.label);
c->generic.label = dupstr("Telnet command, or local"
" proxy command");

View File

@ -53,9 +53,10 @@ static void gss_init(struct ssh_gss_library *lib, void *dlhandle,
}
/* Dynamically load gssapi libs. */
struct ssh_gss_liblist *ssh_gss_setup(const Config *cfg)
struct ssh_gss_liblist *ssh_gss_setup(Conf *conf)
{
void *gsslib;
char *gsspath;
struct ssh_gss_liblist *list = snew(struct ssh_gss_liblist);
list->libraries = snewn(4, struct ssh_gss_library);
@ -77,11 +78,11 @@ struct ssh_gss_liblist *ssh_gss_setup(const Config *cfg)
2, "Using GSSAPI from libgss.so.1");
/* User-specified GSSAPI library */
if (cfg->ssh_gss_custom.path[0] &&
(gsslib = dlopen(cfg->ssh_gss_custom.path, RTLD_LAZY)) != NULL)
gsspath = conf_get_filename(conf, CONF_ssh_gss_custom)->path;
if (*gsspath && (gsslib = dlopen(gsspath, RTLD_LAZY)) != NULL)
gss_init(&list->libraries[list->nlibraries++], gsslib,
3, dupprintf("Using GSSAPI from user-specified"
" library '%s'", cfg->ssh_gss_custom.path));
" library '%s'", gsspath));
return list;
}
@ -129,7 +130,7 @@ const struct keyvalwhere gsslibkeywords[] = {
#include <gssapi/gssapi.h>
/* Dynamically load gssapi libs. */
struct ssh_gss_liblist *ssh_gss_setup(const Config *cfg)
struct ssh_gss_liblist *ssh_gss_setup(Conf *conf)
{
struct ssh_gss_liblist *list = snew(struct ssh_gss_liblist);

View File

@ -98,7 +98,7 @@ static int local_tty = FALSE; /* do we have a local tty? */
static Backend *back;
static void *backhandle;
static Config cfg;
static Conf *conf;
/*
* Default settings that are specific to pterm.
@ -605,10 +605,11 @@ int main(int argc, char **argv)
/*
* Process the command line.
*/
do_defaults(NULL, &cfg);
conf = conf_new();
do_defaults(NULL, conf);
loaded_session = FALSE;
default_protocol = cfg.protocol;
default_port = cfg.port;
default_protocol = conf_get_int(conf, CONF_protocol);
default_port = conf_get_int(conf, CONF_port);
errors = 0;
{
/*
@ -618,8 +619,10 @@ int main(int argc, char **argv)
if (p) {
const Backend *b = backend_from_name(p);
if (b) {
default_protocol = cfg.protocol = b->protocol;
default_port = cfg.port = b->default_port;
default_protocol = b->protocol;
default_port = b->default_port;
conf_set_int(conf, CONF_protocol, default_protocol);
conf_set_int(conf, CONF_port, default_port);
}
}
}
@ -627,7 +630,7 @@ int main(int argc, char **argv)
char *p = *++argv;
if (*p == '-') {
int ret = cmdline_process_param(p, (argc > 1 ? argv[1] : NULL),
1, &cfg);
1, conf);
if (ret == -2) {
fprintf(stderr,
"plink: option \"%s\" requires an argument\n", p);
@ -639,7 +642,7 @@ int main(int argc, char **argv)
} else if (!strcmp(p, "-batch")) {
console_batch_mode = 1;
} else if (!strcmp(p, "-s")) {
/* Save status to write to cfg later. */
/* Save status to write to conf later. */
use_subsystem = 1;
} else if (!strcmp(p, "-V")) {
version();
@ -660,7 +663,7 @@ int main(int argc, char **argv)
errors = 1;
}
} else if (*p) {
if (!cfg_launchable(&cfg) || !(got_host || loaded_session)) {
if (!conf_launchable(conf) || !(got_host || loaded_session)) {
char *q = p;
/*
@ -674,7 +677,7 @@ int main(int argc, char **argv)
q += 7;
if (q[0] == '/' && q[1] == '/')
q += 2;
cfg.protocol = PROT_TELNET;
conf_set_int(conf, CONF_protocol, PROT_TELNET);
p = q;
while (*p && *p != ':' && *p != '/')
p++;
@ -682,11 +685,10 @@ int main(int argc, char **argv)
if (*p)
*p++ = '\0';
if (c == ':')
cfg.port = atoi(p);
conf_set_int(conf, CONF_port, atoi(p));
else
cfg.port = -1;
strncpy(cfg.host, q, sizeof(cfg.host) - 1);
cfg.host[sizeof(cfg.host) - 1] = '\0';
conf_set_int(conf, CONF_port, -1);
conf_set_str(conf, CONF_host, q);
got_host = TRUE;
} else {
char *r, *user, *host;
@ -701,7 +703,9 @@ int main(int argc, char **argv)
*r = '\0';
b = backend_from_name(p);
if (b) {
default_protocol = cfg.protocol = b->protocol;
default_protocol = b->protocol;
conf_set_int(conf, CONF_protocol,
default_protocol);
portnumber = b->default_port;
}
p = r + 1;
@ -728,26 +732,24 @@ int main(int argc, char **argv)
* same name as the hostname.
*/
{
Config cfg2;
do_defaults(host, &cfg2);
if (loaded_session || !cfg_launchable(&cfg2)) {
Conf *conf2 = conf_new();
do_defaults(host, conf2);
if (loaded_session || !conf_launchable(conf2)) {
/* No settings for this host; use defaults */
/* (or session was already loaded with -load) */
strncpy(cfg.host, host, sizeof(cfg.host) - 1);
cfg.host[sizeof(cfg.host) - 1] = '\0';
cfg.port = default_port;
conf_set_str(conf, CONF_host, host);
conf_set_int(conf, CONF_port, default_port);
got_host = TRUE;
} else {
cfg = cfg2;
conf_copy_into(conf, conf2);
loaded_session = TRUE;
}
conf_free(conf2);
}
if (user) {
/* Patch in specified username. */
strncpy(cfg.username, user,
sizeof(cfg.username) - 1);
cfg.username[sizeof(cfg.username) - 1] = '\0';
conf_set_str(conf, CONF_username, user);
}
}
@ -774,9 +776,9 @@ int main(int argc, char **argv)
}
if (cmdlen) command[--cmdlen]='\0';
/* change trailing blank to NUL */
cfg.remote_cmd_ptr = command;
cfg.remote_cmd_ptr2 = NULL;
cfg.nopty = TRUE; /* command => no terminal */
conf_set_str(conf, CONF_remote_cmd, command);
conf_set_str(conf, CONF_remote_cmd2, "");
conf_set_int(conf, CONF_nopty, TRUE); /* command => no tty */
break; /* done with cmdline */
}
@ -786,70 +788,78 @@ int main(int argc, char **argv)
if (errors)
return 1;
if (!cfg_launchable(&cfg) || !(got_host || loaded_session)) {
if (!conf_launchable(conf) || !(got_host || loaded_session)) {
usage();
}
/*
* Trim leading whitespace off the hostname if it's there.
* Muck about with the hostname in various ways.
*/
{
int space = strspn(cfg.host, " \t");
memmove(cfg.host, cfg.host+space, 1+strlen(cfg.host)-space);
}
char *hostbuf = dupstr(conf_get_str(conf, CONF_host));
char *host = hostbuf;
char *p, *q;
/* See if host is of the form user@host */
if (cfg.host[0] != '\0') {
char *atsign = strrchr(cfg.host, '@');
/* Make sure we're not overflowing the user field */
if (atsign) {
if (atsign - cfg.host < sizeof cfg.username) {
strncpy(cfg.username, cfg.host, atsign - cfg.host);
cfg.username[atsign - cfg.host] = '\0';
/*
* Trim leading whitespace.
*/
host += strspn(host, " \t");
/*
* See if host is of the form user@host, and separate out
* the username if so.
*/
if (host[0] != '\0') {
char *atsign = strrchr(host, '@');
if (atsign) {
*atsign = '\0';
conf_set_str(conf, CONF_username, host);
host = atsign + 1;
}
memmove(cfg.host, atsign + 1, 1 + strlen(atsign + 1));
}
/*
* Trim off a colon suffix if it's there.
*/
host[strcspn(host, ":")] = '\0';
/*
* Remove any remaining whitespace.
*/
p = hostbuf;
q = host;
while (*q) {
if (*q != ' ' && *q != '\t')
*p++ = *q;
q++;
}
*p = '\0';
conf_set_str(conf, CONF_host, hostbuf);
sfree(hostbuf);
}
/*
* Perform command-line overrides on session configuration.
*/
cmdline_run_saved(&cfg);
cmdline_run_saved(conf);
/*
* Apply subsystem status.
*/
if (use_subsystem)
cfg.ssh_subsys = TRUE;
conf_set_int(conf, CONF_ssh_subsys, TRUE);
/*
* Trim a colon suffix off the hostname if it's there.
*/
cfg.host[strcspn(cfg.host, ":")] = '\0';
/*
* Remove any remaining whitespace from the hostname.
*/
{
int p1 = 0, p2 = 0;
while (cfg.host[p2] != '\0') {
if (cfg.host[p2] != ' ' && cfg.host[p2] != '\t') {
cfg.host[p1] = cfg.host[p2];
p1++;
}
p2++;
}
cfg.host[p1] = '\0';
}
if (!cfg.remote_cmd_ptr && !*cfg.remote_cmd && !*cfg.ssh_nc_host)
if (!*conf_get_str(conf, CONF_remote_cmd) &&
!*conf_get_str(conf, CONF_remote_cmd2) &&
!*conf_get_str(conf, CONF_ssh_nc_host))
flags |= FLAG_INTERACTIVE;
/*
* Select protocol. This is farmed out into a table in a
* separate file to enable an ssh-free variant.
*/
back = backend_from_proto(cfg.protocol);
back = backend_from_proto(conf_get_int(conf, CONF_protocol));
if (back == NULL) {
fprintf(stderr,
"Internal fault: Unsupported protocol found\n");
@ -860,7 +870,7 @@ int main(int argc, char **argv)
* Select port.
*/
if (portnumber != -1)
cfg.port = portnumber;
conf_set_int(conf, CONF_port, portnumber);
/*
* Set up the pipe we'll use to tell us about SIGWINCH.
@ -879,28 +889,34 @@ int main(int argc, char **argv)
* connection is set up, so if there are none now, we can safely set
* the "simple" flag.
*/
if (cfg.protocol == PROT_SSH && !cfg.x11_forward && !cfg.agentfwd &&
cfg.portfwd[0] == '\0' && cfg.portfwd[1] == '\0')
cfg.ssh_simple = TRUE;
if (conf_get_int(conf, CONF_protocol) == PROT_SSH &&
!conf_get_int(conf, CONF_x11_forward) &&
!conf_get_int(conf, CONF_agentfwd) &&
!conf_get_str_nthstrkey(conf, CONF_portfwd, 0))
conf_set_int(conf, CONF_ssh_simple, TRUE);
/*
* Start up the connection.
*/
logctx = log_init(NULL, &cfg);
logctx = log_init(NULL, conf);
console_provide_logctx(logctx);
{
const char *error;
char *realhost;
/* nodelay is only useful if stdin is a terminal device */
int nodelay = cfg.tcp_nodelay && isatty(0);
int nodelay = conf_get_int(conf, CONF_tcp_nodelay) && isatty(0);
error = back->init(NULL, &backhandle, &cfg, cfg.host, cfg.port,
&realhost, nodelay, cfg.tcp_keepalives);
error = back->init(NULL, &backhandle, conf,
conf_get_str(conf, CONF_host),
conf_get_int(conf, CONF_port),
&realhost, nodelay,
conf_get_int(conf, CONF_tcp_keepalives));
if (error) {
fprintf(stderr, "Unable to open connection:\n%s\n", error);
return 1;
}
back->provide_logctx(backhandle, logctx);
ldisc_create(&cfg, NULL, back, backhandle, NULL);
ldisc_create(conf, NULL, back, backhandle, NULL);
sfree(realhost);
}
connopen = 1;

View File

@ -224,7 +224,7 @@ static int localproxy_select_result(int fd, int event)
Socket platform_new_connection(SockAddr addr, char *hostname,
int port, int privport,
int oobinline, int nodelay, int keepalive,
Plug plug, const Config *cfg)
Plug plug, Conf *conf)
{
char *cmd;
@ -243,10 +243,10 @@ Socket platform_new_connection(SockAddr addr, char *hostname,
Local_Proxy_Socket ret;
int to_cmd_pipe[2], from_cmd_pipe[2], pid;
if (cfg->proxy_type != PROXY_CMD)
if (conf_get_int(conf, CONF_proxy_type) != PROXY_CMD)
return NULL;
cmd = format_telnet_command(addr, port, cfg);
cmd = format_telnet_command(addr, port, conf);
ret = snew(struct Socket_localproxy_tag);
ret->fn = &socket_fn_table;

View File

@ -12,19 +12,19 @@ const int use_event_log = 0; /* pterm doesn't need it */
const int new_session = 0, saved_sessions = 0; /* or these */
const int use_pty_argv = TRUE;
Backend *select_backend(Config *cfg)
Backend *select_backend(Conf *conf)
{
return &pty_backend;
}
int cfgbox(Config *cfg)
int cfgbox(Conf *conf)
{
/*
* This is a no-op in pterm, except that we'll ensure the
* protocol is set to -1 to inhibit the useless Connection
* panel in the config box.
*/
cfg->protocol = -1;
conf_set_int(conf, CONF_protocol, -1);
return 1;
}
@ -33,7 +33,7 @@ void cleanup_exit(int code)
exit(code);
}
int process_nonoption_arg(char *arg, Config *cfg, int *allow_launch)
int process_nonoption_arg(char *arg, Conf *conf, int *allow_launch)
{
return 0; /* pterm doesn't have any. */
}

View File

@ -76,7 +76,7 @@ typedef struct pty_tag *Pty;
static int pty_signal_pipe[2] = { -1, -1 }; /* obviously bogus initial val */
struct pty_tag {
Config cfg;
Conf *conf;
int master_fd, slave_fd;
void *frontend;
char name[FILENAME_MAX];
@ -588,6 +588,8 @@ int pty_real_select_result(Pty pty, int event, int status)
}
if (finished && !pty->finished) {
int close_on_exit;
uxsel_del(pty->master_fd);
pty_close(pty);
pty->master_fd = -1;
@ -600,8 +602,9 @@ int pty_real_select_result(Pty pty, int event, int status)
* Only On Clean and it wasn't a clean exit) do we output a
* `terminated' message.
*/
if (pty->cfg.close_on_exit == FORCE_OFF ||
(pty->cfg.close_on_exit == AUTO && pty->exit_code != 0)) {
close_on_exit = conf_get_int(pty->conf, CONF_close_on_exit);
if (close_on_exit == FORCE_OFF ||
(close_on_exit == AUTO && pty->exit_code != 0)) {
char message[512];
if (WIFEXITED(pty->exit_code))
sprintf(message, "\r\n[pterm: process terminated with exit"
@ -681,7 +684,7 @@ static void pty_uxsel_setup(Pty pty)
* Also places the canonical host name into `realhost'. It must be
* freed by the caller.
*/
static const char *pty_init(void *frontend, void **backend_handle, Config *cfg,
static const char *pty_init(void *frontend, void **backend_handle, Conf *conf,
char *host, int port, char **realhost, int nodelay,
int keepalive)
{
@ -705,9 +708,9 @@ static const char *pty_init(void *frontend, void **backend_handle, Config *cfg,
pty->frontend = frontend;
*backend_handle = NULL; /* we can't sensibly use this, sadly */
pty->cfg = *cfg; /* structure copy */
pty->term_width = cfg->width;
pty->term_height = cfg->height;
pty->conf = conf_copy(conf);
pty->term_width = conf_get_int(conf, CONF_width);
pty->term_height = conf_get_int(conf, CONF_height);
if (pty->master_fd < 0)
pty_open_master(pty);
@ -719,7 +722,8 @@ static const char *pty_init(void *frontend, void **backend_handle, Config *cfg,
{
struct termios attrs;
tcgetattr(pty->master_fd, &attrs);
attrs.c_cc[VERASE] = cfg->bksp_is_delete ? '\177' : '\010';
attrs.c_cc[VERASE] = conf_get_int(conf, CONF_bksp_is_delete)
? '\177' : '\010';
tcsetattr(pty->master_fd, TCSANOW, &attrs);
}
@ -728,7 +732,7 @@ static const char *pty_init(void *frontend, void **backend_handle, Config *cfg,
* Stamp utmp (that is, tell the utmp helper process to do so),
* or not.
*/
if (!cfg->stamp_utmp) {
if (!conf_get_int(conf, CONF_stamp_utmp)) {
close(pty_utmp_helper_pipe); /* just let the child process die */
pty_utmp_helper_pipe = -1;
} else {
@ -787,7 +791,8 @@ static const char *pty_init(void *frontend, void **backend_handle, Config *cfg,
close(open(pty->name, O_WRONLY, 0));
setpgid(pgrp, pgrp);
{
char *term_env_var = dupprintf("TERM=%s", cfg->termtype);
char *term_env_var = dupprintf("TERM=%s",
conf_get_str(conf, CONF_termtype));
putenv(term_env_var);
/* We mustn't free term_env_var, as putenv links it into the
* environment in place.
@ -803,18 +808,12 @@ static const char *pty_init(void *frontend, void **backend_handle, Config *cfg,
}
#endif
{
char *e = cfg->environmt;
char *var, *varend, *val, *varval;
while (*e) {
var = e;
while (*e && *e != '\t') e++;
varend = e;
if (*e == '\t') e++;
val = e;
while (*e) e++;
e++;
char *key, *val;
varval = dupprintf("%.*s=%s", varend-var, var, val);
for (val = conf_get_str_strs(conf, CONF_environmt, NULL, &key);
val != NULL;
val = conf_get_str_strs(conf, CONF_environmt, key, &key)) {
char *varval = dupcat(key, "=", val, NULL);
putenv(varval);
/*
* We must not free varval, since putenv links it
@ -841,7 +840,7 @@ static const char *pty_init(void *frontend, void **backend_handle, Config *cfg,
else {
char *shell = getenv("SHELL");
char *shellname;
if (cfg->login_shell) {
if (conf_get_int(conf, CONF_login_shell)) {
char *p = strrchr(shell, '/');
shellname = snewn(2+strlen(shell), char);
p = p ? p+1 : shell;
@ -884,7 +883,7 @@ static const char *pty_init(void *frontend, void **backend_handle, Config *cfg,
return NULL;
}
static void pty_reconfig(void *handle, Config *cfg)
static void pty_reconfig(void *handle, Conf *conf)
{
Pty pty = (Pty)handle;
/*
@ -892,7 +891,7 @@ static void pty_reconfig(void *handle, Config *cfg)
* unfortunately we do need to pick up the setting of Close On
* Exit so we know whether to give a `terminated' message.
*/
pty->cfg = *cfg; /* structure copy */
conf_copy_into(pty->conf, conf);
}
/*

View File

@ -31,17 +31,17 @@ void cleanup_exit(int code)
exit(code);
}
Backend *select_backend(Config *cfg)
Backend *select_backend(Conf *conf)
{
Backend *back = backend_from_proto(cfg->protocol);
Backend *back = backend_from_proto(conf_get_int(conf, CONF_protocol));
assert(back != NULL);
return back;
}
int cfgbox(Config *cfg)
int cfgbox(Conf *conf)
{
char *title = dupcat(appname, " Configuration", NULL);
int ret = do_config_box(title, cfg, 0, 0);
int ret = do_config_box(title, conf, 0, 0);
sfree(title);
return ret;
}
@ -50,7 +50,7 @@ static int got_host = 0;
const int use_event_log = 1, new_session = 1, saved_sessions = 1;
int process_nonoption_arg(char *arg, Config *cfg, int *allow_launch)
int process_nonoption_arg(char *arg, Conf *conf, int *allow_launch)
{
char *p, *q = arg;
@ -61,7 +61,7 @@ int process_nonoption_arg(char *arg, Config *cfg, int *allow_launch)
* argument, so that it will be deferred until it's a good
* moment to run it.
*/
int ret = cmdline_process_param("-P", arg, 1, cfg);
int ret = cmdline_process_param("-P", arg, 1, conf);
assert(ret == 2);
} else if (!strncmp(q, "telnet:", 7)) {
/*
@ -74,7 +74,7 @@ int process_nonoption_arg(char *arg, Config *cfg, int *allow_launch)
q += 7;
if (q[0] == '/' && q[1] == '/')
q += 2;
cfg->protocol = PROT_TELNET;
conf_set_int(conf, CONF_protocol, PROT_TELNET);
p = q;
while (*p && *p != ':' && *p != '/')
p++;
@ -82,11 +82,10 @@ int process_nonoption_arg(char *arg, Config *cfg, int *allow_launch)
if (*p)
*p++ = '\0';
if (c == ':')
cfg->port = atoi(p);
conf_set_int(conf, CONF_port, atoi(p));
else
cfg->port = -1;
strncpy(cfg->host, q, sizeof(cfg->host) - 1);
cfg->host[sizeof(cfg->host) - 1] = '\0';
conf_set_int(conf, CONF_port, -1);
conf_set_str(conf, CONF_host, q);
got_host = 1;
} else {
/*
@ -97,8 +96,7 @@ int process_nonoption_arg(char *arg, Config *cfg, int *allow_launch)
p++;
if (*p)
*p++ = '\0';
strncpy(cfg->host, q, sizeof(cfg->host) - 1);
cfg->host[sizeof(cfg->host) - 1] = '\0';
conf_set_str(conf, CONF_host, q);
got_host = 1;
}
if (got_host)

View File

@ -60,10 +60,10 @@ static int serial_select_result(int fd, int event);
static void serial_uxsel_setup(Serial serial);
static void serial_try_write(Serial serial);
static const char *serial_configure(Serial serial, Config *cfg)
static const char *serial_configure(Serial serial, Conf *conf)
{
struct termios options;
int bflag, bval;
int bflag, bval, speed, flow, parity;
const char *str;
char *msg;
@ -75,8 +75,9 @@ static const char *serial_configure(Serial serial, Config *cfg)
/*
* Find the appropriate baud rate flag.
*/
speed = conf_get_int(conf, CONF_serspeed);
#define SETBAUD(x) (bflag = B ## x, bval = x)
#define CHECKBAUD(x) do { if (cfg->serspeed >= x) SETBAUD(x); } while (0)
#define CHECKBAUD(x) do { if (speed >= x) SETBAUD(x); } while (0)
SETBAUD(50);
#ifdef B75
CHECKBAUD(75);
@ -183,18 +184,19 @@ static const char *serial_configure(Serial serial, Config *cfg)
sfree(msg);
options.c_cflag &= ~CSIZE;
switch (cfg->serdatabits) {
switch (conf_get_int(conf, CONF_serdatabits)) {
case 5: options.c_cflag |= CS5; break;
case 6: options.c_cflag |= CS6; break;
case 7: options.c_cflag |= CS7; break;
case 8: options.c_cflag |= CS8; break;
default: return "Invalid number of data bits (need 5, 6, 7 or 8)";
}
msg = dupprintf("Configuring %d data bits", cfg->serdatabits);
msg = dupprintf("Configuring %d data bits",
conf_get_int(conf, CONF_serdatabits));
logevent(serial->frontend, msg);
sfree(msg);
if (cfg->serstopbits >= 4) {
if (conf_get_int(conf, CONF_serstopbits) >= 4) {
options.c_cflag |= CSTOPB;
} else {
options.c_cflag &= ~CSTOPB;
@ -211,10 +213,11 @@ static const char *serial_configure(Serial serial, Config *cfg)
#ifdef CNEW_RTSCTS
options.c_cflag &= ~CNEW_RTSCTS;
#endif
if (cfg->serflow == SER_FLOW_XONXOFF) {
flow = conf_get_int(conf, CONF_serflow);
if (flow == SER_FLOW_XONXOFF) {
options.c_iflag |= IXON | IXOFF;
str = "XON/XOFF";
} else if (cfg->serflow == SER_FLOW_RTSCTS) {
} else if (flow == SER_FLOW_RTSCTS) {
#ifdef CRTSCTS
options.c_cflag |= CRTSCTS;
#endif
@ -229,11 +232,12 @@ static const char *serial_configure(Serial serial, Config *cfg)
sfree(msg);
/* Parity */
if (cfg->serparity == SER_PAR_ODD) {
parity = conf_get_int(conf, CONF_serparity);
if (parity == SER_PAR_ODD) {
options.c_cflag |= PARENB;
options.c_cflag |= PARODD;
str = "odd";
} else if (cfg->serparity == SER_PAR_EVEN) {
} else if (parity == SER_PAR_EVEN) {
options.c_cflag |= PARENB;
options.c_cflag &= ~PARODD;
str = "even";
@ -284,12 +288,13 @@ static const char *serial_configure(Serial serial, Config *cfg)
* freed by the caller.
*/
static const char *serial_init(void *frontend_handle, void **backend_handle,
Config *cfg,
Conf *conf,
char *host, int port, char **realhost, int nodelay,
int keepalive)
{
Serial serial;
const char *err;
char *line;
serial = snew(struct serial_backend_data);
*backend_handle = serial;
@ -299,22 +304,23 @@ static const char *serial_init(void *frontend_handle, void **backend_handle,
serial->inbufsize = 0;
bufchain_init(&serial->output_data);
line = conf_get_str(conf, CONF_serline);
{
char *msg = dupprintf("Opening serial device %s", cfg->serline);
char *msg = dupprintf("Opening serial device %s", line);
logevent(serial->frontend, msg);
}
serial->fd = open(cfg->serline, O_RDWR | O_NOCTTY | O_NDELAY | O_NONBLOCK);
serial->fd = open(line, O_RDWR | O_NOCTTY | O_NDELAY | O_NONBLOCK);
if (serial->fd < 0)
return "Unable to open serial port";
cloexec(serial->fd);
err = serial_configure(serial, cfg);
err = serial_configure(serial, conf);
if (err)
return err;
*realhost = dupstr(cfg->serline);
*realhost = dupstr(line);
if (!serial_by_fd)
serial_by_fd = newtree234(serial_compare_by_fd);
@ -349,14 +355,14 @@ static void serial_free(void *handle)
sfree(serial);
}
static void serial_reconfig(void *handle, Config *cfg)
static void serial_reconfig(void *handle, Conf *conf)
{
Serial serial = (Serial) handle;
/*
* FIXME: what should we do if this returns an error?
*/
serial_configure(serial, cfg);
serial_configure(serial, conf);
}
static int serial_select_result(int fd, int event)

View File

@ -34,7 +34,7 @@ char *x_get_default(const char *key)
return NULL; /* this is a stub */
}
void platform_get_x11_auth(struct X11Display *display, const Config *cfg)
void platform_get_x11_auth(struct X11Display *display, Conf *conf)
{
/* Do nothing, therefore no auth. */
}

View File

@ -317,7 +317,7 @@ void *open_settings_r(const char *sessionname)
return ret;
}
char *read_setting_s(void *handle, const char *key, char *buffer, int buflen)
char *read_setting_s(void *handle, const char *key)
{
tree234 *tree = (tree234 *)handle;
const char *val;
@ -333,11 +333,8 @@ char *read_setting_s(void *handle, const char *key, char *buffer, int buflen)
if (!val)
return NULL;
else {
strncpy(buffer, val, buflen);
buffer[buflen-1] = '\0';
return buffer;
}
else
return dupstr(val);
}
int read_setting_i(void *handle, const char *key, int defvalue)
@ -375,26 +372,40 @@ int read_setting_fontspec(void *handle, const char *name, FontSpec *result)
* ("FontName").
*/
char *suffname = dupcat(name, "Name", NULL);
if (read_setting_s(handle, suffname, result->name, sizeof(result->name))) {
char *tmp;
if ((tmp = read_setting_s(handle, suffname)) != NULL) {
strncpy(result->name, tmp, sizeof(result->name)-1);
result->name[sizeof(result->name)-1] = '\0';
sfree(suffname);
sfree(tmp);
return TRUE; /* got new-style name */
}
sfree(suffname);
/* Fall back to old-style name. */
memcpy(result->name, "server:", 7);
if (!read_setting_s(handle, name,
result->name + 7, sizeof(result->name) - 7) ||
!result->name[7]) {
result->name[0] = '\0';
return FALSE;
} else {
tmp = read_setting_s(handle, name);
if (tmp && *tmp) {
strcpy(result->name, "server:");
strncpy(result->name + 7, tmp, sizeof(result->name) - 8);
result->name[sizeof(result->name)-1] = '\0';
sfree(tmp);
return TRUE;
} else {
sfree(tmp);
return FALSE;
}
}
int read_setting_filename(void *handle, const char *name, Filename *result)
{
return !!read_setting_s(handle, name, result->path, sizeof(result->path));
char *tmp = read_setting_s(handle, name);
if (tmp) {
strncpy(result->path, tmp, sizeof(result->path)-1);
result->path[sizeof(result->path)-1] = '\0';
sfree(tmp);
return TRUE;
} else
return FALSE;
}
void write_setting_fontspec(void *handle, const char *name, FontSpec result)

View File

@ -139,7 +139,7 @@ int init_ucs(struct unicode_data *ucsdata, char *linecharset,
/*
* Failing that, line_codepage should be decoded from the
* specification in cfg.
* specification in conf.
*/
if (ucsdata->line_codepage == CS_NONE)
ucsdata->line_codepage = decode_codepage(linecharset);