diff --git a/CMakeLists.txt b/CMakeLists.txt index a3c74d41..6acd9181 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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}) diff --git a/be_all.c b/be_all.c deleted file mode 100644 index 668541b8..00000000 --- a/be_all.c +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Linking module for PuTTY proper: list the available backends - * including ssh. - */ - -#include -#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; diff --git a/be_all_s.c b/be_all_s.c deleted file mode 100644 index 4e502930..00000000 --- a/be_all_s.c +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Linking module for PuTTY proper: list the available backends - * including ssh, plus the serial backend. - */ - -#include -#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; diff --git a/be_list.c b/be_list.c new file mode 100644 index 00000000..09437a69 --- /dev/null +++ b/be_list.c @@ -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 +#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 + ; diff --git a/be_none.c b/be_none.c deleted file mode 100644 index 588bb1d4..00000000 --- a/be_none.c +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Linking module for programs that do not support selection of backend - * (such as pterm). - */ - -#include -#include "putty.h" - -const int be_default_protocol = -1; - -const struct BackendVtable *const backends[] = { - NULL -}; - -const size_t n_ui_backends = 0; diff --git a/be_nos_s.c b/be_nos_s.c deleted file mode 100644 index 097433aa..00000000 --- a/be_nos_s.c +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Linking module for PuTTYtel: list the available backends not - * including ssh. - */ - -#include -#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; diff --git a/be_nossh.c b/be_nossh.c deleted file mode 100644 index 1c94f3ae..00000000 --- a/be_nossh.c +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Linking module for PuTTYtel: list the available backends not - * including ssh. - */ - -#include -#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; diff --git a/be_ssh.c b/be_ssh.c deleted file mode 100644 index 81be62d8..00000000 --- a/be_ssh.c +++ /dev/null @@ -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 -#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 */ diff --git a/cmake/setup.cmake b/cmake/setup.cmake index 6612de97..26079f31 100644 --- a/cmake/setup.cmake +++ b/cmake/setup.cmake @@ -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 $) +endfunction() + include(cmake/platforms/${platform}.cmake) include_directories( diff --git a/fuzzterm.c b/fuzzterm.c index a1902ede..f1477054 100644 --- a/fuzzterm.c +++ b/fuzzterm.c @@ -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] = { }; diff --git a/pscp.c b/pscp.c index 837e89d9..192341c3 100644 --- a/pscp.c +++ b/pscp.c @@ -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. diff --git a/psftp.c b/psftp.c index d0317c2e..bddc18a2 100644 --- a/psftp.c +++ b/psftp.c @@ -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 diff --git a/unix/CMakeLists.txt b/unix/CMakeLists.txt index 1030f486..51d03f0f 100644 --- a/unix/CMakeLists.txt +++ b/unix/CMakeLists.txt @@ -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}) diff --git a/unix/pageant.c b/unix/pageant.c index f2f75eac..f8a766db 100644 --- a/unix/pageant.c +++ b/unix/pageant.c @@ -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; /* diff --git a/unix/psusan.c b/unix/psusan.c index 6560adf2..1d5816d5 100644 --- a/unix/psusan.c +++ b/unix/psusan.c @@ -41,8 +41,6 @@ #include "ssh.h" #include "ssh/server.h" -const char *const appname = "psusan"; - void modalfatalbox(const char *p, ...) { va_list ap; diff --git a/unix/pterm.c b/unix/pterm.c index b18e3442..649e7b83 100644 --- a/unix/pterm.c +++ b/unix/pterm.c @@ -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 diff --git a/unix/uppity.c b/unix/uppity.c index 7f74fed6..b5c30075 100644 --- a/unix/uppity.c +++ b/unix/uppity.c @@ -43,8 +43,6 @@ #include "ssh.h" #include "ssh/server.h" -const char *const appname = "uppity"; - void modalfatalbox(const char *p, ...) { va_list ap; diff --git a/windows/CMakeLists.txt b/windows/CMakeLists.txt index 10769ee1..7338f4c2 100644 --- a/windows/CMakeLists.txt +++ b/windows/CMakeLists.txt @@ -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 diff --git a/windows/be_conpty.c b/windows/be_conpty.c deleted file mode 100644 index d8f000b1..00000000 --- a/windows/be_conpty.c +++ /dev/null @@ -1,13 +0,0 @@ -#include -#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;