be_list.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * Source file that is rebuilt per application, and provides the list
  3. * of backends, the default protocol, and the application name.
  4. *
  5. * This file expects the build system to provide some per-application
  6. * definitions on the compiler command line. So you don't just add it
  7. * directly to the sources list for an application. Instead you call
  8. * the be_list() function defined in setup.cmake, e.g.
  9. *
  10. * be_list(target-name AppName [SSH] [SERIAL] [OTHERBACKENDS])
  11. *
  12. * This translates into the following command-line macro definitions
  13. * used by the code below:
  14. *
  15. * - APPNAME should be defined to the name of the program, in
  16. * user-facing capitalisation (e.g. PuTTY rather than putty).
  17. * Unquoted: it's easier to stringify it in the preprocessor than
  18. * to persuade cmake to put the right quotes on the command line on
  19. * all build platforms.
  20. *
  21. * - The following macros should each be defined to 1 if a given set
  22. * of backends should be added to the backends[] list, or 0 if they
  23. * should not be:
  24. *
  25. * * SSH: the two SSH backends (SSH proper, and bare-ssh-connection)
  26. *
  27. * * SERIAL: the serial port backend
  28. *
  29. * * OTHERBACKENDS: the non-cryptographic network protocol backends
  30. * (Telnet, Rlogin, SUPDUP, Raw)
  31. */
  32. #include <stdio.h>
  33. #include "putty.h"
  34. const char *const appname = STR(APPNAME);
  35. /*
  36. * Define the default protocol for the application. This is always a
  37. * network backend (serial ports come second behind network, in every
  38. * case). Applications that don't have either (such as pterm) don't
  39. * need this variable anyway, so just set it to -1.
  40. */
  41. #if SSH
  42. const int be_default_protocol = PROT_SSH;
  43. #elif OTHERBACKENDS
  44. const int be_default_protocol = PROT_TELNET;
  45. #else
  46. const int be_default_protocol = -1;
  47. #endif
  48. /*
  49. * List all the configured backends, in the order they should appear
  50. * in the config box.
  51. */
  52. const struct BackendVtable *const backends[] = {
  53. /*
  54. * Start with the most-preferred network-remote-login protocol.
  55. * That's SSH if present, otherwise Telnet if present.
  56. */
  57. #if SSH
  58. &ssh_backend,
  59. #elif OTHERBACKENDS
  60. &telnet_backend, /* Telnet at the top if SSH is absent */
  61. #endif
  62. /*
  63. * Second on the list is the serial-port backend, if available.
  64. */
  65. #if SERIAL
  66. &serial_backend,
  67. #endif
  68. /*
  69. * After that come the remaining network protocols: Telnet if it
  70. * hasn't already appeared above, and Rlogin, SUPDUP and Raw.
  71. */
  72. #if OTHERBACKENDS && SSH
  73. &telnet_backend, /* only if SSH displaced it at the top */
  74. #endif
  75. #if OTHERBACKENDS
  76. &rlogin_backend,
  77. &supdup_backend,
  78. &raw_backend,
  79. #endif
  80. /*
  81. * Bare ssh-connection / PSUSAN is a niche protocol and goes well
  82. * down the list.
  83. */
  84. #if SSH
  85. &sshconn_backend,
  86. #endif
  87. /*
  88. * Done. Null pointer to mark the end of the list.
  89. */
  90. NULL
  91. };
  92. /*
  93. * Number of backends at the start of the above list that should have
  94. * radio buttons in the config UI.
  95. *
  96. * The rule is: the most-preferred network backend, and Serial, each
  97. * get a radio button if present.
  98. *
  99. * The rest will be relegated to a dropdown list.
  100. */
  101. const size_t n_ui_backends =
  102. 0
  103. #if SSH || OTHERBACKENDS
  104. + 1
  105. #endif
  106. #if SERIAL
  107. + 1
  108. #endif
  109. ;