mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-08 08:58:00 +00:00
53f7da8ce7
This commit replaces all those fiddly little linking modules (be_all.c, be_none.c, be_ssh.c etc) with a single source file controlled by ifdefs, and introduces a function be_list() in setup.cmake that makes it easy to compile a version of it appropriate to each application. This is a net reduction in code according to 'git diff --stat', even though I've introduced more comments. It also gets rid of another pile of annoying little source files in the top-level directory that didn't deserve to take up so much room in 'ls'. More concretely, doing this has some maintenance advantages. Centralisation means less to maintain (e.g. n_ui_backends is worked out once in a way that makes sense everywhere), and also, 'appname' can now be reliably set per program. Previously, some programs got the wrong appname due to sharing the same linking module (e.g. Plink had appname="PuTTY"), which was a latent bug that would have manifested if I'd wanted to reuse the same string in another context. One thing I've changed in this rework is that Windows pterm no longer has the ConPTY backend in its backends[]: it now has an empty one. The special be_conpty.c module shouldn't really have been there in the first place: it was used in the very earliest uncommitted drafts of the ConPTY work, where I was using another method of selecting that backend, but now that Windows pterm has a dedicated backend_vt_from_conf() that refers to conpty_backend by name, it has no need to live in backends[] at all, just as it doesn't have to in Unix pterm.
119 lines
3.2 KiB
C
119 lines
3.2 KiB
C
/*
|
|
* Source file that is rebuilt per application, and provides the list
|
|
* of backends, the default protocol, and the application name.
|
|
*
|
|
* This file expects the build system to provide some per-application
|
|
* definitions on the compiler command line. So you don't just add it
|
|
* directly to the sources list for an application. Instead you call
|
|
* the be_list() function defined in setup.cmake, e.g.
|
|
*
|
|
* be_list(target-name AppName [SSH] [SERIAL] [OTHERBACKENDS])
|
|
*
|
|
* This translates into the following command-line macro definitions
|
|
* used by the code below:
|
|
*
|
|
* - APPNAME should be defined to the name of the program, in
|
|
* user-facing capitalisation (e.g. PuTTY rather than putty).
|
|
* Unquoted: it's easier to stringify it in the preprocessor than
|
|
* to persuade cmake to put the right quotes on the command line on
|
|
* all build platforms.
|
|
*
|
|
* - The following macros should each be defined to 1 if a given set
|
|
* of backends should be added to the backends[] list, or 0 if they
|
|
* should not be:
|
|
*
|
|
* * SSH: the two SSH backends (SSH proper, and bare-ssh-connection)
|
|
*
|
|
* * SERIAL: the serial port backend
|
|
*
|
|
* * OTHERBACKENDS: the non-cryptographic network protocol backends
|
|
* (Telnet, Rlogin, SUPDUP, Raw)
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#include "putty.h"
|
|
|
|
const char *const appname = STR(APPNAME);
|
|
|
|
/*
|
|
* Define the default protocol for the application. This is always a
|
|
* network backend (serial ports come second behind network, in every
|
|
* case). Applications that don't have either (such as pterm) don't
|
|
* need this variable anyway, so just set it to -1.
|
|
*/
|
|
#if SSH
|
|
const int be_default_protocol = PROT_SSH;
|
|
#elif OTHERBACKENDS
|
|
const int be_default_protocol = PROT_TELNET;
|
|
#else
|
|
const int be_default_protocol = -1;
|
|
#endif
|
|
|
|
/*
|
|
* List all the configured backends, in the order they should appear
|
|
* in the config box.
|
|
*/
|
|
const struct BackendVtable *const backends[] = {
|
|
/*
|
|
* Start with the most-preferred network-remote-login protocol.
|
|
* That's SSH if present, otherwise Telnet if present.
|
|
*/
|
|
#if SSH
|
|
&ssh_backend,
|
|
#elif OTHERBACKENDS
|
|
&telnet_backend, /* Telnet at the top if SSH is absent */
|
|
#endif
|
|
|
|
/*
|
|
* Second on the list is the serial-port backend, if available.
|
|
*/
|
|
#if SERIAL
|
|
&serial_backend,
|
|
#endif
|
|
|
|
/*
|
|
* After that come the remaining network protocols: Telnet if it
|
|
* hasn't already appeared above, and Rlogin, SUPDUP and Raw.
|
|
*/
|
|
#if OTHERBACKENDS && SSH
|
|
&telnet_backend, /* only if SSH displaced it at the top */
|
|
#endif
|
|
#if OTHERBACKENDS
|
|
&rlogin_backend,
|
|
&supdup_backend,
|
|
&raw_backend,
|
|
#endif
|
|
|
|
/*
|
|
* Bare ssh-connection / PSUSAN is a niche protocol and goes well
|
|
* down the list.
|
|
*/
|
|
#if SSH
|
|
&sshconn_backend,
|
|
#endif
|
|
|
|
/*
|
|
* Done. Null pointer to mark the end of the list.
|
|
*/
|
|
NULL
|
|
};
|
|
|
|
/*
|
|
* Number of backends at the start of the above list that should have
|
|
* radio buttons in the config UI.
|
|
*
|
|
* The rule is: the most-preferred network backend, and Serial, each
|
|
* get a radio button if present.
|
|
*
|
|
* The rest will be relegated to a dropdown list.
|
|
*/
|
|
const size_t n_ui_backends =
|
|
0
|
|
#if SSH || OTHERBACKENDS
|
|
+ 1
|
|
#endif
|
|
#if SERIAL
|
|
+ 1
|
|
#endif
|
|
;
|