defs.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /*
  2. * defs.h: initial definitions for PuTTY.
  3. *
  4. * The rule about this header file is that it can't depend on any
  5. * other header file in this code base. This is where we define
  6. * things, as much as we can, that other headers will want to refer
  7. * to, such as opaque structure types and their associated typedefs,
  8. * or macros that are used by other headers.
  9. */
  10. #ifndef PUTTY_DEFS_H
  11. #define PUTTY_DEFS_H
  12. #include <stddef.h>
  13. #include <stdint.h>
  14. #include <stdbool.h>
  15. #ifndef WINSCP
  16. // This is used in pageant, pscp, psftp and servers only
  17. #if defined _MSC_VER && _MSC_VER < 1800
  18. /* Work around lack of inttypes.h and strtoumax in older MSVC */
  19. #define PRIx32 "x"
  20. #define PRIu64 "I64u"
  21. #define PRIdMAX "I64d"
  22. #define PRIXMAX "I64X"
  23. #define SCNu64 "I64u"
  24. uintmax_t strtoumax(const char *nptr, char **endptr, int base);
  25. #else
  26. #include <inttypes.h>
  27. #endif
  28. #endif
  29. typedef struct conf_tag Conf;
  30. typedef struct terminal_tag Terminal;
  31. typedef struct term_utf8_decode term_utf8_decode;
  32. typedef struct Filename Filename;
  33. typedef struct FontSpec FontSpec;
  34. typedef struct bufchain_tag bufchain;
  35. typedef struct strbuf strbuf;
  36. typedef struct RSAKey RSAKey;
  37. typedef struct BinarySink BinarySink;
  38. typedef struct BinarySource BinarySource;
  39. typedef struct stdio_sink stdio_sink;
  40. typedef struct bufchain_sink bufchain_sink;
  41. typedef struct handle_sink handle_sink;
  42. typedef struct IdempotentCallback IdempotentCallback;
  43. typedef struct SockAddr SockAddr;
  44. typedef struct Socket Socket;
  45. typedef struct Plug Plug;
  46. typedef struct SocketPeerInfo SocketPeerInfo;
  47. typedef struct Backend Backend;
  48. typedef struct BackendVtable BackendVtable;
  49. typedef struct Ldisc_tag Ldisc;
  50. typedef struct LogContext LogContext;
  51. typedef struct LogPolicy LogPolicy;
  52. typedef struct LogPolicyVtable LogPolicyVtable;
  53. typedef struct Seat Seat;
  54. typedef struct SeatVtable SeatVtable;
  55. typedef struct TermWin TermWin;
  56. typedef struct TermWinVtable TermWinVtable;
  57. typedef struct Ssh Ssh;
  58. typedef struct mp_int mp_int;
  59. typedef struct MontyContext MontyContext;
  60. typedef struct WeierstrassCurve WeierstrassCurve;
  61. typedef struct WeierstrassPoint WeierstrassPoint;
  62. typedef struct MontgomeryCurve MontgomeryCurve;
  63. typedef struct MontgomeryPoint MontgomeryPoint;
  64. typedef struct EdwardsCurve EdwardsCurve;
  65. typedef struct EdwardsPoint EdwardsPoint;
  66. typedef struct SshServerConfig SshServerConfig;
  67. typedef struct SftpServer SftpServer;
  68. typedef struct SftpServerVtable SftpServerVtable;
  69. typedef struct Channel Channel;
  70. typedef struct SshChannel SshChannel;
  71. typedef struct mainchan mainchan;
  72. typedef struct ssh_sharing_state ssh_sharing_state;
  73. typedef struct ssh_sharing_connstate ssh_sharing_connstate;
  74. typedef struct share_channel share_channel;
  75. typedef struct PortFwdManager PortFwdManager;
  76. typedef struct PortFwdRecord PortFwdRecord;
  77. typedef struct ConnectionLayer ConnectionLayer;
  78. typedef struct prng prng;
  79. typedef struct ssh_hashalg ssh_hashalg;
  80. typedef struct ssh_hash ssh_hash;
  81. typedef struct ssh_kex ssh_kex;
  82. typedef struct ssh_kexes ssh_kexes;
  83. typedef struct ssh_keyalg ssh_keyalg;
  84. typedef struct ssh_key ssh_key;
  85. typedef struct ssh_compressor ssh_compressor;
  86. typedef struct ssh_decompressor ssh_decompressor;
  87. typedef struct ssh_compression_alg ssh_compression_alg;
  88. typedef struct ssh2_userkey ssh2_userkey;
  89. typedef struct ssh2_macalg ssh2_macalg;
  90. typedef struct ssh2_mac ssh2_mac;
  91. typedef struct ssh_cipheralg ssh_cipheralg;
  92. typedef struct ssh_cipher ssh_cipher;
  93. typedef struct ssh2_ciphers ssh2_ciphers;
  94. typedef struct dh_ctx dh_ctx;
  95. typedef struct ecdh_key ecdh_key;
  96. typedef struct dlgparam dlgparam;
  97. typedef struct settings_w settings_w;
  98. typedef struct settings_r settings_r;
  99. typedef struct settings_e settings_e;
  100. typedef struct SessionSpecial SessionSpecial;
  101. typedef struct StripCtrlChars StripCtrlChars;
  102. /*
  103. * A small structure wrapping up a (pointer, length) pair so that it
  104. * can be conveniently passed to or from a function.
  105. */
  106. typedef struct ptrlen {
  107. const void *ptr;
  108. size_t len;
  109. } ptrlen;
  110. typedef struct logblank_t logblank_t;
  111. typedef struct BinaryPacketProtocol BinaryPacketProtocol;
  112. typedef struct PacketProtocolLayer PacketProtocolLayer;
  113. /* Do a compile-time type-check of 'to_check' (without evaluating it),
  114. * as a side effect of returning the value 'to_return'. Note that
  115. * although this macro double-*expands* to_return, it always
  116. * *evaluates* exactly one copy of it, so it's side-effect safe. */
  117. #define TYPECHECK(to_check, to_return) \
  118. (sizeof(to_check) ? (to_return) : (to_return))
  119. /* Return a pointer to the object of structure type 'type' whose field
  120. * with name 'field' is pointed at by 'object'. */
  121. #define container_of(object, type, field) \
  122. TYPECHECK(object == &((type *)0)->field, \
  123. ((type *)(((char *)(object)) - offsetof(type, field))))
  124. #if defined __GNUC__ || defined __clang__
  125. #define NORETURN __attribute__((__noreturn__))
  126. #else
  127. #define NORETURN
  128. #endif
  129. /* ----------------------------------------------------------------------
  130. * Platform-specific definitions.
  131. *
  132. * Most of these live in the per-platform header files, of which
  133. * puttyps.h selects the appropriate one. But some of the sources
  134. * (particularly standalone test applications) would prefer not to
  135. * have to include a per-platform header at all, because that makes it
  136. * more portable to platforms not supported by the code base as a
  137. * whole (for example, compiling purely computational parts of the
  138. * code for specialist platforms for test and analysis purposes). So
  139. * any definition that has to affect even _those_ modules will have to
  140. * go here, with the key constraint being that this code has to come
  141. * to _some_ decision even if the compilation platform is not a
  142. * recognised one at all.
  143. */
  144. /* Purely computational code uses smemclr(), so we have to make the
  145. * decision here about whether that's provided by utils.c or by a
  146. * platform implementation. We define PLATFORM_HAS_SMEMCLR to suppress
  147. * utils.c's definition. */
  148. #ifdef _WINDOWS
  149. /* Windows provides the API function 'SecureZeroMemory', which we use
  150. * unless the user has told us not to by defining NO_SECUREZEROMEMORY. */
  151. #ifndef NO_SECUREZEROMEMORY
  152. #define PLATFORM_HAS_SMEMCLR
  153. #endif
  154. #endif
  155. #endif /* PUTTY_DEFS_H */