defs.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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. #ifdef NDEBUG
  13. /*
  14. * PuTTY is a security project, so assertions are important - if an
  15. * assumption is violated, proceeding anyway may have far worse
  16. * consequences than simple program termination. This check and #error
  17. * should arrange that we don't ever accidentally compile assertions
  18. * out.
  19. */
  20. #error Do not compile this code base with NDEBUG defined!
  21. #endif
  22. #if HAVE_CMAKE_H
  23. #include "cmake.h"
  24. #endif
  25. #include <stddef.h>
  26. #include <stdint.h>
  27. #include <stdio.h> /* for __MINGW_PRINTF_FORMAT */
  28. #include <stdbool.h>
  29. #if defined _MSC_VER && _MSC_VER < 1800
  30. /* Work around lack of inttypes.h and strtoumax in older MSVC */
  31. #define PRIx32 "x"
  32. #define PRIu32 "u"
  33. #define PRIu64 "I64u"
  34. #define PRIdMAX "I64d"
  35. #define PRIXMAX "I64X"
  36. #define SCNu64 "I64u"
  37. #define SIZEx "Ix"
  38. #define SIZEu "Iu"
  39. uintmax_t strtoumax(const char *nptr, char **endptr, int base);
  40. /* Also, define a LEGACY_WINDOWS flag to enable other workarounds */
  41. #define LEGACY_WINDOWS
  42. #else
  43. #include <inttypes.h>
  44. /* Because we still support older MSVC libraries which don't recognise the
  45. * standard C "z" modifier for size_t-sized integers, we must use an
  46. * inttypes.h-style macro for those */
  47. #define SIZEx "zx"
  48. #define SIZEu "zu"
  49. #endif
  50. #if defined __GNUC__ || defined __clang__
  51. /*
  52. * On MinGW, the correct compiler format checking for vsnprintf() etc
  53. * can depend on compile-time flags; these control whether you get
  54. * ISO C or Microsoft's non-standard format strings.
  55. * We sometimes use __attribute__ ((format)) for our own printf-like
  56. * functions, which are ultimately interpreted by the toolchain-chosen
  57. * printf, so we need to take that into account to get correct warnings.
  58. */
  59. #ifdef __MINGW_PRINTF_FORMAT
  60. #define PRINTF_LIKE(fmt_index, ellipsis_index) \
  61. __attribute__ ((format (__MINGW_PRINTF_FORMAT, fmt_index, ellipsis_index)))
  62. #else
  63. #define PRINTF_LIKE(fmt_index, ellipsis_index) \
  64. __attribute__ ((format (printf, fmt_index, ellipsis_index)))
  65. #endif
  66. #else /* __GNUC__ */
  67. #define PRINTF_LIKE(fmt_index, ellipsis_index)
  68. #endif /* __GNUC__ */
  69. typedef struct conf_tag Conf;
  70. typedef struct ConfKeyInfo ConfKeyInfo;
  71. typedef struct ConfSaveEnumValue ConfSaveEnumValue;
  72. typedef struct ConfSaveEnumType ConfSaveEnumType;
  73. typedef struct CmdlineArgList CmdlineArgList;
  74. typedef struct CmdlineArg CmdlineArg;
  75. typedef struct terminal_tag Terminal;
  76. typedef struct term_utf8_decode term_utf8_decode;
  77. typedef struct Filename Filename;
  78. typedef struct FontSpec FontSpec;
  79. typedef struct bufchain_tag bufchain;
  80. typedef struct strbuf strbuf;
  81. typedef struct LoadedFile LoadedFile;
  82. typedef struct RSAKey RSAKey;
  83. typedef struct BinarySink BinarySink;
  84. typedef struct BinarySource BinarySource;
  85. typedef struct stdio_sink stdio_sink;
  86. typedef struct bufchain_sink bufchain_sink;
  87. typedef struct buffer_sink buffer_sink;
  88. typedef struct handle_sink handle_sink;
  89. typedef struct IdempotentCallback IdempotentCallback;
  90. typedef struct SockAddr SockAddr;
  91. typedef struct Socket Socket;
  92. typedef struct Plug Plug;
  93. typedef struct SocketEndpointInfo SocketEndpointInfo;
  94. typedef struct DeferredSocketOpener DeferredSocketOpener;
  95. typedef struct DeferredSocketOpenerVtable DeferredSocketOpenerVtable;
  96. typedef struct Backend Backend;
  97. typedef struct BackendVtable BackendVtable;
  98. typedef struct Interactor Interactor;
  99. typedef struct InteractorVtable InteractorVtable;
  100. typedef struct InteractionReadySeat InteractionReadySeat;
  101. typedef struct Ldisc_tag Ldisc;
  102. typedef struct LogContext LogContext;
  103. typedef struct LogPolicy LogPolicy;
  104. typedef struct LogPolicyVtable LogPolicyVtable;
  105. typedef struct TermLineEditor TermLineEditor;
  106. typedef struct TermLineEditorCallbackReceiver TermLineEditorCallbackReceiver;
  107. typedef struct TermLineEditorCallbackReceiverVtable
  108. TermLineEditorCallbackReceiverVtable;
  109. typedef struct Seat Seat;
  110. typedef struct SeatVtable SeatVtable;
  111. typedef struct SeatDialogText SeatDialogText;
  112. typedef struct SeatDialogTextItem SeatDialogTextItem;
  113. typedef struct SeatDialogPromptDescriptions SeatDialogPromptDescriptions;
  114. typedef struct SeatPromptResult SeatPromptResult;
  115. typedef struct cmdline_get_passwd_input_state cmdline_get_passwd_input_state;
  116. typedef struct TermWin TermWin;
  117. typedef struct TermWinVtable TermWinVtable;
  118. typedef struct Ssh Ssh;
  119. typedef struct mp_int mp_int;
  120. typedef struct MontyContext MontyContext;
  121. typedef struct WeierstrassCurve WeierstrassCurve;
  122. typedef struct WeierstrassPoint WeierstrassPoint;
  123. typedef struct MontgomeryCurve MontgomeryCurve;
  124. typedef struct MontgomeryPoint MontgomeryPoint;
  125. typedef struct EdwardsCurve EdwardsCurve;
  126. typedef struct EdwardsPoint EdwardsPoint;
  127. typedef struct SshServerConfig SshServerConfig;
  128. typedef struct SftpServer SftpServer;
  129. typedef struct SftpServerVtable SftpServerVtable;
  130. typedef struct Channel Channel;
  131. typedef struct SshChannel SshChannel;
  132. typedef struct mainchan mainchan;
  133. typedef struct CertExprBuilder CertExprBuilder;
  134. typedef struct ssh_sharing_state ssh_sharing_state;
  135. typedef struct ssh_sharing_connstate ssh_sharing_connstate;
  136. typedef struct share_channel share_channel;
  137. typedef struct PortFwdManager PortFwdManager;
  138. typedef struct PortFwdRecord PortFwdRecord;
  139. typedef struct ConnectionLayer ConnectionLayer;
  140. typedef struct prng prng;
  141. typedef struct ssh_hashalg ssh_hashalg;
  142. typedef struct ssh_hash ssh_hash;
  143. typedef struct ssh_kex ssh_kex;
  144. typedef struct ssh_kexes ssh_kexes;
  145. typedef struct ssh_keyalg ssh_keyalg;
  146. typedef struct ssh_key ssh_key;
  147. typedef struct ssh_compressor ssh_compressor;
  148. typedef struct ssh_decompressor ssh_decompressor;
  149. typedef struct ssh_compression_alg ssh_compression_alg;
  150. typedef struct ssh2_userkey ssh2_userkey;
  151. typedef struct ssh2_macalg ssh2_macalg;
  152. typedef struct ssh2_mac ssh2_mac;
  153. typedef struct ssh_cipheralg ssh_cipheralg;
  154. typedef struct ssh_cipher ssh_cipher;
  155. typedef struct ssh2_ciphers ssh2_ciphers;
  156. typedef struct dh_ctx dh_ctx;
  157. typedef struct ecdh_key ecdh_key;
  158. typedef struct ecdh_keyalg ecdh_keyalg;
  159. typedef struct NTRUKeyPair NTRUKeyPair;
  160. typedef struct NTRUEncodeSchedule NTRUEncodeSchedule;
  161. typedef struct RFC6979 RFC6979;
  162. typedef struct RFC6979Result RFC6979Result;
  163. typedef struct dlgparam dlgparam;
  164. typedef struct dlgcontrol dlgcontrol;
  165. typedef struct settings_w settings_w;
  166. typedef struct settings_r settings_r;
  167. typedef struct settings_e settings_e;
  168. typedef struct ca_options ca_options;
  169. typedef struct host_ca host_ca;
  170. typedef struct host_ca_enum host_ca_enum;
  171. typedef struct SessionSpecial SessionSpecial;
  172. typedef struct StripCtrlChars StripCtrlChars;
  173. typedef struct BidiContext BidiContext;
  174. /*
  175. * A small structure wrapping up a (pointer, length) pair so that it
  176. * can be conveniently passed to or from a function.
  177. */
  178. typedef struct ptrlen {
  179. const void *ptr;
  180. size_t len;
  181. } ptrlen;
  182. typedef struct logblank_t logblank_t;
  183. typedef struct BinaryPacketProtocol BinaryPacketProtocol;
  184. typedef struct PacketProtocolLayer PacketProtocolLayer;
  185. struct unicode_data;
  186. /* Do a compile-time type-check of 'to_check' (without evaluating it),
  187. * as a side effect of returning the value 'to_return'. Note that
  188. * although this macro double-*expands* to_return, it always
  189. * *evaluates* exactly one copy of it, so it's side-effect safe. */
  190. #define TYPECHECK(to_check, to_return) \
  191. (sizeof(to_check) ? (to_return) : (to_return))
  192. /* Return a pointer to the object of structure type 'type' whose field
  193. * with name 'field' is pointed at by 'object'. */
  194. #define container_of(object, type, field) \
  195. TYPECHECK(object == &((type *)0)->field, \
  196. ((type *)(((char *)(object)) - offsetof(type, field))))
  197. #if defined __GNUC__ || defined __clang__
  198. #define NORETURN __attribute__((__noreturn__))
  199. #elif defined _MSC_VER
  200. #define NORETURN __declspec(noreturn)
  201. #else
  202. #define NORETURN
  203. #endif
  204. /*
  205. * Standard macro definitions. STR() behaves like the preprocessor
  206. * stringification # operator, and CAT() behaves like the token paste
  207. * ## operator, except that each one macro-expands its argument(s)
  208. * first, unlike the raw version. E.g.
  209. *
  210. * #__LINE__ -> "__LINE__"
  211. * STR(__LINE__) -> "1234" (or whatever)
  212. *
  213. * and similarly,
  214. *
  215. * foo ## __LINE__ -> foo__LINE__
  216. * CAT(foo, __LINE__) -> foo1234 (or whatever)
  217. *
  218. * The expansion is achieved by having each macro pass its arguments
  219. * to a secondary inner macro, because parameter lists of a macro call
  220. * get expanded before the called macro is invoked. So STR(__LINE__)
  221. * -> STR_INNER(1234) -> #1234 -> "1234", and similarly for CAT.
  222. */
  223. #define STR_INNER(x) #x
  224. #define STR(x) STR_INNER(x)
  225. #define CAT_INNER(x,y) x ## y
  226. #define CAT(x,y) CAT_INNER(x,y)
  227. /*
  228. * Structure shared between ssh.h and storage.h, giving strictness
  229. * options relating to checking of an OpenSSH certificate. It's a bit
  230. * cheaty to put something so specific in here, but more painful to
  231. * put it in putty.h.
  232. */
  233. struct ca_options {
  234. bool permit_rsa_sha1, permit_rsa_sha256, permit_rsa_sha512;
  235. };
  236. #endif /* PUTTY_DEFS_H */