1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-03-29 17:57:07 -05:00

Merge be_*.c into one ifdef-controlled module.

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.
This commit is contained in:
Simon Tatham 2021-11-26 17:58:55 +00:00
parent 3260e429a1
commit 53f7da8ce7
19 changed files with 158 additions and 185 deletions

View File

@ -97,8 +97,13 @@ add_executable(bidi_test
target_link_libraries(bidi_test guiterminal utils ${platform_libraries})
add_executable(plink
${platform}/plink.c
be_all_s.c)
${platform}/plink.c)
# Note: if we ever port Plink to a platform where we can't implement a
# serial backend, this be_list command will need to become platform-
# dependent, so that it only sets the SERIAL option on platforms where
# that backend exists. For the moment, though, we have serial port
# backends for both our platforms, so we can do this unconditionally.
be_list(plink Plink SSH SERIAL OTHERBACKENDS)
target_link_libraries(plink
eventloop noterminal console sshclient otherbackends settings network crypto
utils
@ -106,16 +111,16 @@ target_link_libraries(plink
installed_program(plink)
add_executable(pscp
pscp.c
be_ssh.c)
pscp.c)
be_list(pscp PSCP SSH)
target_link_libraries(pscp
sftpclient eventloop console sshclient settings network crypto utils
${platform_libraries})
installed_program(pscp)
add_executable(psftp
psftp.c
be_ssh.c)
psftp.c)
be_list(psftp PSFTP SSH)
target_link_libraries(psftp
sftpclient eventloop console sshclient settings network crypto utils
${platform_libraries})

View File

@ -1,31 +0,0 @@
/*
* Linking module for PuTTY proper: list the available backends
* including ssh.
*/
#include <stdio.h>
#include "putty.h"
/*
* This appname is not strictly in the right place, since Plink
* also uses this module. However, Plink doesn't currently use any
* of the dialog-box sorts of things that make use of appname, so
* it shouldn't do any harm here. I'm trying to avoid having to
* have tiny little source modules containing nothing but
* declarations of appname, for as long as I can...
*/
const char *const appname = "PuTTY";
const int be_default_protocol = PROT_SSH;
const struct BackendVtable *const backends[] = {
&ssh_backend,
&telnet_backend,
&rlogin_backend,
&supdup_backend,
&raw_backend,
&sshconn_backend,
NULL
};
const size_t n_ui_backends = 1;

View File

@ -1,32 +0,0 @@
/*
* Linking module for PuTTY proper: list the available backends
* including ssh, plus the serial backend.
*/
#include <stdio.h>
#include "putty.h"
/*
* This appname is not strictly in the right place, since Plink
* also uses this module. However, Plink doesn't currently use any
* of the dialog-box sorts of things that make use of appname, so
* it shouldn't do any harm here. I'm trying to avoid having to
* have tiny little source modules containing nothing but
* declarations of appname, for as long as I can...
*/
const char *const appname = "PuTTY";
const int be_default_protocol = PROT_SSH;
const struct BackendVtable *const backends[] = {
&ssh_backend,
&serial_backend,
&telnet_backend,
&rlogin_backend,
&supdup_backend,
&raw_backend,
&sshconn_backend,
NULL
};
const size_t n_ui_backends = 2;

118
be_list.c Normal file
View File

@ -0,0 +1,118 @@
/*
* 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
;

View File

@ -1,15 +0,0 @@
/*
* Linking module for programs that do not support selection of backend
* (such as pterm).
*/
#include <stdio.h>
#include "putty.h"
const int be_default_protocol = -1;
const struct BackendVtable *const backends[] = {
NULL
};
const size_t n_ui_backends = 0;

View File

@ -1,22 +0,0 @@
/*
* Linking module for PuTTYtel: list the available backends not
* including ssh.
*/
#include <stdio.h>
#include "putty.h"
const int be_default_protocol = PROT_TELNET;
const char *const appname = "PuTTYtel";
const struct BackendVtable *const backends[] = {
&telnet_backend,
&serial_backend,
&rlogin_backend,
&supdup_backend,
&raw_backend,
NULL
};
const size_t n_ui_backends = 2;

View File

@ -1,21 +0,0 @@
/*
* Linking module for PuTTYtel: list the available backends not
* including ssh.
*/
#include <stdio.h>
#include "putty.h"
const int be_default_protocol = PROT_TELNET;
const char *const appname = "PuTTYtel";
const struct BackendVtable *const backends[] = {
&telnet_backend,
&rlogin_backend,
&supdup_backend,
&raw_backend,
NULL
};
const size_t n_ui_backends = 1;

View File

@ -1,18 +0,0 @@
/*
* Linking module for programs that are restricted to only using
* SSH-type protocols (pscp and psftp). These still have a choice of
* two actual backends, because they can also speak PROT_SSHCONN.
*/
#include <stdio.h>
#include "putty.h"
const int be_default_protocol = PROT_SSH;
const struct BackendVtable *const backends[] = {
&ssh_backend,
&sshconn_backend,
NULL
};
const size_t n_ui_backends = 0; /* not used in programs with a config UI */

View File

@ -78,6 +78,20 @@ else()
set(platform unix)
endif()
function(be_list TARGET NAME)
cmake_parse_arguments(OPT "SSH;SERIAL;OTHERBACKENDS" "" "" "${ARGN}")
add_library(${TARGET}-be-list OBJECT ${CMAKE_SOURCE_DIR}/be_list.c)
foreach(setting SSH SERIAL OTHERBACKENDS)
if(OPT_${setting})
target_compile_definitions(${TARGET}-be-list PRIVATE ${setting}=1)
else()
target_compile_definitions(${TARGET}-be-list PRIVATE ${setting}=0)
endif()
endforeach()
target_compile_definitions(${TARGET}-be-list PRIVATE APPNAME=${NAME})
target_sources(${TARGET} PRIVATE $<TARGET_OBJECTS:${TARGET}-be-list>)
endfunction()
include(cmake/platforms/${platform}.cmake)
include_directories(

View File

@ -171,7 +171,6 @@ bool dlg_coloursel_results(union control *ctrl, dlgparam *dp,
void dlg_refresh(union control *ctrl, dlgparam *dp) { }
bool dlg_is_visible(union control *ctrl, dlgparam *dp) { return false; }
const char *const appname = "FuZZterm";
const int ngsslibs = 0;
const char *const gsslibnames[0] = { };
const struct keyvalwhere gsslibkeywords[0] = { };

2
pscp.c
View File

@ -49,8 +49,6 @@ static void source(const char *src);
static void rsource(const char *src);
static void sink(const char *targ, const char *src);
const char *const appname = "PSCP";
/*
* The maximum amount of queued data we accept before we stop and
* wait for the server to process some.

View File

@ -14,8 +14,6 @@
#include "ssh.h"
#include "ssh/sftp.h"
const char *const appname = "PSFTP";
/*
* Since SFTP is a request-response oriented protocol, it requires
* no buffer management: when we send data, we stop and wait for an

View File

@ -49,11 +49,11 @@ add_sources_from_current_dir(agent
add_executable(fuzzterm
${CMAKE_SOURCE_DIR}/fuzzterm.c
${CMAKE_SOURCE_DIR}/be_none.c
${CMAKE_SOURCE_DIR}/logging.c
${CMAKE_SOURCE_DIR}/stubs/noprint.c
unicode.c
no-gtk.c)
be_list(fuzzterm FuZZterm)
add_dependencies(fuzzterm generated_licence_h)
target_link_libraries(fuzzterm
guiterminal eventloop charset settings utils)
@ -68,11 +68,11 @@ add_sources_from_current_dir(psocks no-gtk.c)
add_executable(psusan
psusan.c
${CMAKE_SOURCE_DIR}/be_none.c
${CMAKE_SOURCE_DIR}/stubs/nogss.c
${CMAKE_SOURCE_DIR}/ssh/scpserver.c
no-gtk.c
pty.c)
be_list(psusan psusan)
target_link_libraries(psusan
eventloop sshserver keygen settings network crypto utils)
installed_program(psusan)
@ -108,11 +108,11 @@ target_link_libraries(testzlib utils)
add_executable(uppity
uppity.c
${CMAKE_SOURCE_DIR}/be_none.c
${CMAKE_SOURCE_DIR}/ssh/scpserver.c
no-gtk.c
pty.c
${CMAKE_SOURCE_DIR}/stubs/nogss.c)
be_list(uppity Uppity)
target_link_libraries(uppity
eventloop sshserver keygen settings network crypto utils)
@ -131,13 +131,13 @@ if(GTK_FOUND)
add_executable(pageant
pageant.c
${CMAKE_SOURCE_DIR}/be_none.c
${CMAKE_SOURCE_DIR}/stubs/nogss.c
askpass.c
x11.c
noise.c
${CMAKE_SOURCE_DIR}/ssh/x11fwd.c
${CMAKE_SOURCE_DIR}/proxy/nosshproxy.c)
be_list(pageant Pageant)
target_link_libraries(pageant
eventloop console agent settings network crypto utils
${GTK_LIBRARIES})
@ -146,10 +146,10 @@ if(GTK_FOUND)
add_executable(pterm
pterm.c
main-gtk-simple.c
${CMAKE_SOURCE_DIR}/be_none.c
${CMAKE_SOURCE_DIR}/stubs/nogss.c
${CMAKE_SOURCE_DIR}/proxy/nosshproxy.c
pty.c)
be_list(pterm pterm)
target_link_libraries(pterm
guiterminal eventloop settings charset utils
${GTK_LIBRARIES} ${X11_LIBRARIES})
@ -159,18 +159,18 @@ if(GTK_FOUND)
pterm.c
main-gtk-application.c
${CMAKE_SOURCE_DIR}/stubs/nocmdline.c
${CMAKE_SOURCE_DIR}/be_none.c
${CMAKE_SOURCE_DIR}/stubs/nogss.c
${CMAKE_SOURCE_DIR}/proxy/nosshproxy.c
pty.c)
be_list(ptermapp pterm)
target_link_libraries(ptermapp
guiterminal eventloop settings charset utils
${GTK_LIBRARIES} ${X11_LIBRARIES})
add_executable(putty
putty.c
main-gtk-simple.c
${CMAKE_SOURCE_DIR}/be_all_s.c)
main-gtk-simple.c)
be_list(putty PuTTY SSH SERIAL OTHERBACKENDS)
target_link_libraries(putty
guiterminal eventloop sshclient otherbackends settings
network crypto charset utils
@ -182,8 +182,8 @@ if(GTK_FOUND)
add_executable(puttyapp
putty.c
main-gtk-application.c
${CMAKE_SOURCE_DIR}/stubs/nocmdline.c
${CMAKE_SOURCE_DIR}/be_all_s.c)
${CMAKE_SOURCE_DIR}/stubs/nocmdline.c)
be_list(puttyapp PuTTY SSH SERIAL OTHERBACKENDS)
target_link_libraries(puttyapp
guiterminal eventloop sshclient otherbackends settings
network crypto charset utils
@ -192,11 +192,11 @@ if(GTK_FOUND)
add_executable(puttytel
putty.c
main-gtk-simple.c
${CMAKE_SOURCE_DIR}/be_nos_s.c
${CMAKE_SOURCE_DIR}/stubs/nogss.c
${CMAKE_SOURCE_DIR}/stubs/norand.c
${CMAKE_SOURCE_DIR}/proxy/nocproxy.c
${CMAKE_SOURCE_DIR}/proxy/nosshproxy.c)
be_list(puttytel PuTTYtel SERIAL OTHERBACKENDS)
target_link_libraries(puttytel
guiterminal eventloop otherbackends settings network charset utils
${GTK_LIBRARIES} ${X11_LIBRARIES})

View File

@ -235,8 +235,6 @@ void keylist_update(void)
#define PAGEANT_DIR_PREFIX "/tmp/pageant"
const char *const appname = "Pageant";
static bool time_to_die = false;
/*

View File

@ -41,8 +41,6 @@
#include "ssh.h"
#include "ssh/server.h"
const char *const appname = "psusan";
void modalfatalbox(const char *p, ...)
{
va_list ap;

View File

@ -7,7 +7,6 @@
#include "putty.h"
const char *const appname = "pterm";
const bool use_event_log = false; /* pterm doesn't need it */
const bool new_session = false, saved_sessions = false; /* or these */
const bool dup_check_launchable = false; /* no need to check host name

View File

@ -43,8 +43,6 @@
#include "ssh.h"
#include "ssh/server.h"
const char *const appname = "uppity";
void modalfatalbox(const char *p, ...)
{
va_list ap;

View File

@ -92,8 +92,8 @@ add_executable(putty
window.c
putty.c
help.c
${CMAKE_SOURCE_DIR}/be_all_s.c
putty.rc)
be_list(putty PuTTY SSH SERIAL OTHERBACKENDS)
add_dependencies(putty generated_licence_h)
target_link_libraries(putty
guiterminal guimisc eventloop sshclient otherbackends settings network crypto
@ -108,12 +108,12 @@ add_executable(puttytel
window.c
putty.c
help.c
${CMAKE_SOURCE_DIR}/be_nos_s.c
${CMAKE_SOURCE_DIR}/stubs/nogss.c
${CMAKE_SOURCE_DIR}/stubs/norand.c
${CMAKE_SOURCE_DIR}/proxy/nocproxy.c
${CMAKE_SOURCE_DIR}/proxy/nosshproxy.c
puttytel.rc)
be_list(puttytel PuTTYtel SERIAL OTHERBACKENDS)
add_dependencies(puttytel generated_licence_h)
target_link_libraries(puttytel
guiterminal guimisc eventloop otherbackends settings network utils
@ -149,11 +149,11 @@ if(HAVE_CONPTY)
pterm.c
help.c
conpty.c
be_conpty.c
${CMAKE_SOURCE_DIR}/stubs/nogss.c
${CMAKE_SOURCE_DIR}/stubs/norand.c
${CMAKE_SOURCE_DIR}/proxy/stubs/nosshproxy.c
${CMAKE_SOURCE_DIR}/proxy/nosshproxy.c
pterm.rc)
be_list(pterm pterm)
add_dependencies(pterm generated_licence_h)
target_link_libraries(pterm
guiterminal guimisc eventloop settings network utils

View File

@ -1,13 +0,0 @@
#include <stdio.h>
#include "putty.h"
const char *const appname = "pterm";
const int be_default_protocol = -1;
const struct BackendVtable *const backends[] = {
&conpty_backend,
NULL
};
const size_t n_ui_backends = 1;