Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

970 lines
32 KiB

  1. //Copyright (c) Microsoft Corporation. All rights reserved.
  2. #include "ime.h"
  3. #define NAMSZ 255
  4. #ifndef WHISTLER_BUILD
  5. #include "winsock2.h"
  6. #include "ws2tcpip.h"
  7. #include "wspiapi.h"
  8. #include "mswsock.h"
  9. #else
  10. #include <winsock2.h>
  11. #include <ws2tcpip.h>
  12. #include <wspiapi.h>
  13. #include <mswsock.h>
  14. #endif
  15. #include "wintelsz.h"
  16. //#define VT52 1
  17. /* display rows array indices */
  18. #define idwDR25 0
  19. #define idwDR43 1
  20. #define idwDR50 2
  21. #define idwDRCustom 3
  22. /* resource #defines */
  23. #define IDM_CONNECT 100
  24. #define IDM_HANGUP 101
  25. #define IDM_EXIT 102
  26. #define IDM_TRIMSPACE 124
  27. #define IDM_LOCALECHO 209
  28. #define IDM_TEXTCOLOUR 210
  29. #define IDM_BACKCOLOUR 211
  30. #define IDM_UNDERLINECURSOR 212
  31. #define IDM_BLINKCURSOR 213
  32. #define IDM_VT100CURSORKEYS 214
  33. #define IDM_VT52MODE 215
  34. #define IDM_VT80MODE 216
  35. #define IDM_VT100MODE 217
  36. #define IDM_TERMPREF 225
  37. #define IDM_BLOCKCURSOR 226
  38. #define IDM_KANJI_LIST 229
  39. #ifdef MAKAG_AMBIGUOUS
  40. #define IDM_VT100MODE 216 // Why is FE value 217?
  41. #define IDM_TERMPREF 217 // Why is FE value 225?
  42. #define IDM_BLOCKCURSOR 218 // Why is FE value 226?
  43. #endif
  44. #define IDM_LOGGING 219
  45. #define IDM_STLOGGING 220
  46. #define IDM_INDEX 400
  47. #define IDM_SEARCH 401
  48. #define IDM_HELP 402
  49. #define IDM_ABOUT 403
  50. // MohsinA, 12-Dec-96.
  51. #ifdef DBG
  52. #define IDM_DBG_FONT 500
  53. #define IDM_DBG_USERINFO 501
  54. #define IDM_DBG_GLOBALS 502
  55. #endif
  56. #define IDC_START_LOGGING 117
  57. #define IDC_APPEND 118
  58. #define ID_WINTEL_HELP 16
  59. #define CID_HOSTNAME 100
  60. #define CID_DISPLAYLINE 101
  61. #define CID_USESTDNETBIOS 102
  62. #define CID_HOSTNAME2 103
  63. #define CID_SERVNAME 104
  64. #define CID_TERMTYPENAME 105
  65. #define IDS_DEBUGFLAGS 121
  66. #define IDS_PROMPTFLAGS 122
  67. #define IDS_HELPFILE 126
  68. #define IDS_TITLEBASE 127
  69. #define IDS_TITLENONE 128
  70. #define IDS_APPNAME 129
  71. #define IDS_CONNECT 130
  72. #define IDS_CONNECTIONLOST 132
  73. #define IDS_CONNECTFAILED 135
  74. #define IDS_CANTACCESSSETTINGS 136
  75. #define IDS_OOM 137
  76. #define IDS_TOOMUCHTEXT 138
  77. #define IDS_VERSION 139
  78. #define IDS_CONNECTING 141
  79. #define IDS_USAGE 142
  80. #define IDS_CANT_INIT_SOCKETS 181
  81. #define IDS_CONNECTFAILEDMSG 185
  82. #define IDS_ONPORT 900
  83. #define IDS_KANJI_JIS 186
  84. #define IDS_KANJI_SJIS 187
  85. #define IDS_KANJI_EUC 188
  86. #define IDS_KANJI_DEC 189
  87. #define IDS_KANJI_NEC 190
  88. #define IDS_KANJI_JIS78 191
  89. #define IDS_KANJI_ACOS 192
  90. #define IDS_BUGEMUFLAGS 193
  91. #define IDS_ACOSFLAG 194
  92. #define IDS_VT100KANJI_EMULATION 195
  93. #ifdef DBCS
  94. #define IDS_INPROPERFONT 200
  95. #endif
  96. #define IDS_SENT_BRK 243
  97. #define IDS_INFO_BANNER 250
  98. #define IDS_ESCAPE_CHAR 903
  99. #define IDS_PROMPT_STR 251
  100. #define IDS_INVALID_STR 252
  101. #define IDS_HELP_STR 253
  102. #define IDS_BUILD_INFO 254
  103. #define IDS_CLOSE 255
  104. #define IDS_DISPLAY 256
  105. #define IDS_HELP 257
  106. #define IDS_OPEN 258
  107. #define IDS_OPENTO 901
  108. #define IDS_OPENUSAGE 902
  109. #define IDS_QUIT 259
  110. #define IDS_SET 260
  111. #define IDS_STATUS 261
  112. #define IDS_UNSET 262
  113. #define IDS_NO_ESCAPE 263
  114. #define IDS_WILL_AUTH 264
  115. #define IDS_WONT_AUTH 265
  116. #define IDS_LOCAL_ECHO_ON 266
  117. #define IDS_LOCAL_ECHO_OFF 267
  118. #define IDS_CONNECTED_TO 268
  119. #define IDS_NOT_CONNECTED 269
  120. #define IDS_NEGO_TERM_TYPE 270
  121. #define IDS_PREF_TERM_TYPE 271
  122. #define IDS_SET_FORMAT 272
  123. #define IDS_SET_HELP 273
  124. #define IDS_UNSET_FORMAT 274
  125. #define IDS_UNSET_HELP 275
  126. #define IDS_ENABLE_IME_SUPPORT 276
  127. #define IDS_ENABLE_IME_FORMAT 277
  128. #define IDS_ENABLE_IME_HELP 278
  129. #define IDS_ENABLE_IME_ON 279
  130. #define IDS_DISABLE_IME_SUPPORT 280
  131. #define IDS_DISABLE_IME_FORMAT 281
  132. #define IDS_DISABLE_IME_HELP 282
  133. #define IDS_SUPPORTED_TERMS 284
  134. #define IDS_SET_HELP_JAP 285
  135. #define IDS_UNSET_HELP_JAP 286
  136. #define IDS_HELP_STR_JAP 287
  137. #define IDS_ERR_LICENSE 288
  138. #define IDS_CONTINUE 289
  139. #define IDS_NO_EMULATION 290
  140. #define IDS_NTLM_PROMPT 904
  141. #define IDS_LOGGING_ON 291
  142. #define IDS_LOGGING_OFF 292
  143. #define IDS_LOGFILE_NAME 293
  144. #define IDS_BAD_LOGFILE 294
  145. #define IDS_NO_LOGFILE 295
  146. #define IDS_SEND 296
  147. #define IDS_SENT_AO 297
  148. #define IDS_SENT_AYT 298
  149. #define IDS_SENT_ESC 299
  150. #define IDS_SENT_IP 300
  151. #define IDS_SEND_HELP 301
  152. #define IDS_SEND_FORMAT 302
  153. #define IDS_SENT_CHARS 303
  154. #define IDS_SENT_SYNCH 304
  155. #define IDS_DELASBACKSPACE 305
  156. #define IDS_BACKSPACEASDEL 306
  157. #define IDS_DELASDEL 307
  158. #define IDS_BACKSPACEASBACKSPACE 308
  159. #define IDS_CRLF 309
  160. #define IDS_CR 310
  161. #define IDS_STREAM 311
  162. #define IDS_CONSOLE 312
  163. #define IDS_CURRENT_MODE 313
  164. #define IDS_STREAM_ONLY 314
  165. #define IDS_CONSOLE_ONLY 315
  166. #define IDS_SUPPORTED_MODES 316
  167. #define IDS_SET_CODESET_FORMAT 317
  168. #define IDS_INVALID_ESC_KEY 318
  169. #define MSG_LOGGING_ON "Client logging on\r\n"
  170. #define MSG_DELASDEL "Delete will be sent as delete\r\n"
  171. #define MSG_BACKSPACEASBACKSPACE "Backspace will be sent as backspace\r\n"
  172. #define MSG_DELASBACKSPACE "Delete will be sent as backspace\r\n"
  173. #define MSG_BACKSPACEASDEL "Backspace will be sent as delete\r\n"
  174. #define MSG_SENT_AO "Sent abort output\r\n"
  175. #define MSG_SENT_AYT "Sent are you there\r\n"
  176. #define MSG_SENT_BRK "Sent break\r\n"
  177. #define MSG_SENT_ESC "Sent escape character\r\n"
  178. #define MSG_SENT_IP "Sent interrupt process\r\n"
  179. #define MSG_SENT_SYNCH "Sent command synch\r\n"
  180. #define MSG_SENT_CHARS "Sent string %s\r\n"
  181. #define MSG_SEND_HELP "ayt\t\tSend telnet command 'Abort Output'\r\nayt\t\tSend telnet command 'Are You There'\r\nbrk\tSend telnet command brk\r\nesc\t\tSend current telnet escape character\r\nip\t\tSend telnet command 'Interrupt Process'\r\nany other string will be sent as it is to the telnet server\r\n"
  182. #define MSG_SEND_FORMAT "Format is 'send String'\r\ntype 'send ?' for help\r\n"
  183. #define MSG_NOT_CONNECTED "Not Connected\r\n"
  184. #define MSG_CRLF "New line mode - Causes return key to send CR, LF\r\n"
  185. #define MSG_CR "Line feed mode - Causes return key to send CR\r\n"
  186. #define MSG_STREAM "Stream mode - Works well with command line applications\r\n"
  187. #define MSG_CONSOLE "Console mode - Works well with screen applications like vi\r\n"
  188. #define MSG_CURRENT_MODE "Current mode: "
  189. #define MSG_STREAM_ONLY "Stream\r\n"
  190. #define MSG_CONSOLE_ONLY "Console\r\n"
  191. #define MSG_SUPPORTED_MODES "Supported modes are console and stream only.\r\n"
  192. #define MSG_SET_CODESET_FORMAT "Supported codesets are Shift JIS, Japanese EUC, JIS Kanji, JIS Kanji(78), DEC Kanji and NEC Kanji only.\r\n"
  193. #define MSG_INVALID_ESC_KEY "Invalid Key Combination\r\n"
  194. #define STREAM "stream"
  195. #define CONSOLE "console"
  196. #define ATTRIB_INVERT 1
  197. #define wKeyPressed ((WORD)0x8000)
  198. #define SV_PROGRESS (WM_USER+350)
  199. #define SV_END (WM_USER+351)
  200. #define SV_DATABUF (0x4000)
  201. #define SV_DONE 0
  202. #define SV_CONNECT 1
  203. #define SV_DISCONNECT 2
  204. #define SV_HANGUP 3
  205. #define SV_QUIT 4
  206. #define BLOCK_CURSOR 50
  207. #define NORMAL_CURSOR 25
  208. #define VK_INSERT_KEY 45
  209. typedef struct _SupportedKanji
  210. {
  211. DWORD KanjiID;
  212. DWORD KanjiEmulationID;
  213. DWORD KanjiMessageID;
  214. DWORD KanjiItemID;
  215. TCHAR KanjiDescription[255];
  216. } KANJILIST;
  217. typedef struct _SendTelInfo
  218. {
  219. LONG lExit;
  220. LONG lCleanup;
  221. HANDLE hthread;
  222. HANDLE hfile;
  223. UCHAR *puchBuffer;
  224. DWORD cbFile;
  225. DWORD cbReadTotal;
  226. volatile DWORD dwCommand;
  227. DWORD dwThreadId;
  228. int nSessionNumber;
  229. } SVI;
  230. #ifdef USETCP
  231. /* Data structure and #defines for TCP stuff */
  232. #define READ_BUF_SZ (4096)
  233. #define DATA_BUF_SZ (2*READ_BUF_SZ)
  234. #endif
  235. #define nSessionNone ((int)-1)
  236. typedef struct _NetOBJData
  237. {
  238. char szHostName[NAMSZ+1];
  239. int SessionNumber;
  240. SOCKET hsd;
  241. char szResolvedHost[MAXGETHOSTSTRUCT+1];
  242. struct addrinfo *ai;
  243. //
  244. // Options can cross packet boundaries. This is the number of bytes
  245. // left over from the previous packet. It is contained in the
  246. // first cbOld bytes of lpTempBuffer.
  247. //
  248. int cbOld;
  249. LPSTR lpTempBuffer;
  250. //
  251. // To prevent endless loops doing option negotiation, we will
  252. // only respond to Will Echo and Will Suppress Go Ahead once
  253. //
  254. BOOL fRespondedToWillEcho;
  255. BOOL fRespondedToWillSGA;
  256. BOOL fRespondedToDoAUTH;
  257. BOOL fRespondedToDoNAWS;
  258. LPSTR lpReadBuffer;
  259. #ifdef __NOT_USED
  260. WORD iHead,
  261. iTail;
  262. char achData[DATA_BUF_SZ];
  263. #endif
  264. } NETDATA, *LPNETDATA;
  265. #define cchMaxHostName (NAMSZ+1)
  266. /* don't prompt for dest. dir on dl */
  267. #define fdwSuppressDestDirPrompt ((DWORD)0x01)
  268. /* Mask off high bit for ASCII-only */
  269. #define fdwASCIIOnly ((DWORD)0x01)
  270. /* Display output stream for debugging */
  271. #define fdwDebugOutput ((DWORD)0x02)
  272. /* Don't pass on VT100 function or cursor keys */
  273. #define fdwNoVT100Keys ((DWORD)0x04)
  274. /* Replace TABs by up to 8 spaces */
  275. #define fdwTABtoSpaces ((DWORD)0x08)
  276. /* Echo user input to display */
  277. #define fdwLocalEcho ((DWORD)0x0010)
  278. /* VT100 Cursor Keys mode */
  279. #define fdwVT100CursorKeys ((DWORD)0x0020)
  280. /* VT52 Mode */
  281. #define fdwVT52Mode ((DWORD)0x0040)
  282. /* VT80 Mode */
  283. #define fdwVT80Mode ((DWORD)0x0080)
  284. /* Kanji Mode Mask */
  285. #define fdwKanjiModeMask ((DWORD)0xFF00)
  286. /* DEC KanjiMode */
  287. #define fdwDECKanjiMode ((DWORD)0x0400)
  288. /* NEC Kanji Mode */
  289. #define fdwNECKanjiMode ((DWORD)0x0800)
  290. /* JIS78 Kanji Mode */
  291. #define fdwJIS78KanjiMode ((DWORD)0x1000)
  292. /* JIS Kanji Mode */
  293. #define fdwJISKanjiMode ((DWORD)0x2000)
  294. /* ShiftJIS Kanji Mode */
  295. #define fdwSJISKanjiMode ((DWORD)0x4000)
  296. /* EUC Kanji Mode */
  297. #define fdwEUCKanjiMode ((DWORD)0x8000)
  298. /* ACOS Kanji Mode */
  299. #define fdwACOSKanjiMode ((DWORD)0x0200)
  300. /* Enable IME Support */
  301. #define fdwEnableIMESupport ((DWORD)0x100000)
  302. /* CRLF sending ==== for backward compatibility with w2k telnet client */
  303. #define fdwOnlyCR ((DWORD)0x80000000)
  304. /* Is the cursor a block or underline? */
  305. #define fdwCursorUnderline ((DWORD)0x01)
  306. /* Is the cursor supposed to blink? */
  307. #define fdwCursorBlink ((DWORD)0x02)
  308. /* Are we in QuickEdit mode? */
  309. #define fdwQuickEditMode ((DWORD)0x04)
  310. /* Trim whitespace at end of every line? */
  311. #define fdwTrimEndWhitespace ((DWORD)0x08)
  312. typedef enum _Term_Type {
  313. TT_UNKNOWN = -1,
  314. TT_ANSI = 0,
  315. TT_VT100,
  316. TT_VT52,
  317. TT_VTNT,
  318. TT_LAST = TT_VTNT
  319. } TERM_TYPE;
  320. typedef struct _USERINFO
  321. {
  322. DWORD dwMaxRow; /* number of rows in display */
  323. DWORD dwMaxCol; /* number of columns in display */
  324. DWORD dwClientRow; /* number of visible rows */
  325. DWORD dwClientCol; /* number of visible columns */
  326. DWORD nScrollRow; /* scroll row */
  327. DWORD nScrollCol; /* scroll column */
  328. DWORD nScrollMaxRow; /* max scroll row */
  329. DWORD nScrollMaxCol; /* max scroll column */
  330. DWORD nCyChar; /* char height */
  331. DWORD nCxChar; /* char width */
  332. DWORD nLeftoff; /* Leftoff */
  333. DWORD fPrompt; /* prompt bit flags */
  334. DWORD fDebug; /* Debug bit flags */
  335. DWORD fFlushOut; /* flushing output */
  336. HANDLE hLogFile; /* Indicates whether logging is turned on now */
  337. DWORD bLogging; /* Handle for the logfile */
  338. DWORD bAppend;
  339. DWORD nottelnet;
  340. DWORD honor_localecho; // This is false till authentication happens, only to a telnet server
  341. DWORD dwCrLf;
  342. DWORD fBugEmulation; /* Bug Emulation bit flags */
  343. DWORD fAcosSupportFlag; /* ACOS-KANJI Support flag */
  344. LOGFONT lf; /* description of font used */
  345. DWORD bWillAUTH;
  346. DWORD bPromptForNtlm;
  347. DWORD bSendCredsToRemoteSite;
  348. } UI;
  349. #define fBugEmulationDBCS ((DWORD)0x0001)
  350. #define fAcosSupport ((DWORD)0x0001)
  351. #define uTerminalTimerID ((UINT)2)
  352. #define uCursorBlinkMsecs ((UINT)250)
  353. /* VT100 Flags */
  354. #define dwVTArrow ((DWORD)0x0001)
  355. #define dwVTKeypad ((DWORD)0x0002)
  356. #define dwVTWrap ((DWORD)0x0004)
  357. #define dwVT52 ((DWORD)0x0008)
  358. #define dwVTCursor ((DWORD)0x0010)
  359. #define dwVTScrSize ((DWORD)0x0020)
  360. #define dwDECCOLM ((DWORD)0x0040)
  361. #define dwDECSCNM ((DWORD)0x0080)
  362. #define dwLineMode ((DWORD)0x0100)
  363. #define dwInsertMode ((DWORD)0x0200)
  364. #define dwVT52Graphics ((DWORD)0x0400)
  365. #define dwKeyLock ((DWORD)0x0800)
  366. #define dwVT80 ((DWORD)0x1000)
  367. #define FIsVTArrow(ptrm) ((ptrm)->dwVT100Flags & dwVTArrow)
  368. #define SetVTArrow(ptrm) ((ptrm)->dwVT100Flags |= dwVTArrow)
  369. #define ClearVTArrow(ptrm) ((ptrm)->dwVT100Flags &= ~dwVTArrow)
  370. #define FIsVTKeypad(ptrm) ((ptrm)->dwVT100Flags & dwVTKeypad)
  371. #define SetVTKeypad(ptrm) ((ptrm)->dwVT100Flags |= dwVTKeypad)
  372. #define ClearVTKeypad(ptrm) ((ptrm)->dwVT100Flags &= ~dwVTKeypad)
  373. #define FIsVTWrap(ptrm) ((ptrm)->dwVT100Flags & dwVTWrap)
  374. #define SetVTWrap(ptrm) ((ptrm)->dwVT100Flags |= dwVTWrap)
  375. #define ClearVTWrap(ptrm) ((ptrm)->dwVT100Flags &= ~dwVTWrap)
  376. #define SetANSI(ptrm) ((ptrm)->CurrentTermType = TT_ANSI)
  377. #define FIsVT52(ptrm) ((ptrm)->CurrentTermType == TT_VT52)
  378. #define SetVT52(ptrm) ((ptrm)->CurrentTermType = TT_VT52)
  379. #define FIsVT80(ptrm) ((ptrm)->dwVT100Flags & dwVT80)
  380. #define SetVT80(ptrm) ((ptrm)->dwVT100Flags |= dwVT80)
  381. #define ClearVT80(ptrm) ((ptrm)->dwVT100Flags &= ~dwVT80)
  382. #define FIsVTCursor(ptrm) ((ptrm)->dwVT100Flags & dwVTCursor)
  383. #define SetVTCursor(ptrm) ((ptrm)->dwVT100Flags |= dwVTCursor)
  384. #define ClearVTCursor(ptrm) ((ptrm)->dwVT100Flags &= ~dwVTCursor)
  385. #define FIsVTScrSize(ptrm) ((ptrm)->dwVT100Flags & dwVTScrSize)
  386. #define SetVTScrSize(ptrm) ((ptrm)->dwVT100Flags |= dwVTScrSize)
  387. #define ClearVTScrSize(ptrm) ((ptrm)->dwVT100Flags &= ~dwVTScrSize)
  388. #define FIsDECCOLM(ptrm) ((ptrm)->dwVT100Flags & dwDECCOLM)
  389. #define SetDECCOLM(ptrm) ((ptrm)->dwVT100Flags |= dwDECCOLM)
  390. #define ClearDECCOLM(ptrm) ((ptrm)->dwVT100Flags &= ~dwDECCOLM)
  391. #define FIsDECSCNM(ptrm) ((ptrm)->dwVT100Flags & dwDECSCNM)
  392. #define SetDECSCNM(ptrm) ((ptrm)->dwVT100Flags |= dwDECSCNM)
  393. #define ClearDECSCNM(ptrm) ((ptrm)->dwVT100Flags &= ~dwDECSCNM)
  394. #define FIsLineMode(ptrm) ((ptrm)->dwVT100Flags & dwLineMode)
  395. #define SetLineMode(ptrm) ((ptrm)->dwVT100Flags |= dwLineMode)
  396. #define ClearLineMode(ptrm) ((ptrm)->dwVT100Flags &= ~dwLineMode)
  397. #define FIsInsertMode(ptrm) ((ptrm)->dwVT100Flags & dwInsertMode)
  398. #define SetInsertMode(ptrm) ((ptrm)->dwVT100Flags |= dwInsertMode)
  399. #define ClearInsertMode(ptrm) ((ptrm)->dwVT100Flags &= ~dwInsertMode)
  400. #define FIsVT52Graphics(ptrm) ((ptrm)->dwVT100Flags & dwVT52Graphics)
  401. #define SetVT52Graphics(ptrm) ((ptrm)->dwVT100Flags |= dwVT52Graphics)
  402. #define ClearVT52Graphics(ptrm) ((ptrm)->dwVT100Flags &= ~dwVT52Graphics)
  403. #define FIsKeyLock(ptrm) ((ptrm)->dwVT100Flags & dwKeyLock)
  404. #define SetKeyLock(ptrm) ((ptrm)->dwVT100Flags |= dwKeyLock)
  405. #define ClearKeyLock(ptrm) ((ptrm)->dwVT100Flags &= ~dwKeyLock)
  406. /* JIS Kanji Mode */
  407. #define dwJISKanji ((DWORD)0x0001)
  408. /* Shift JIS Kanji Mode */
  409. #define dwSJISKanji ((DWORD)0x0002)
  410. /* EUC Kanji Mode */
  411. #define dwEUCKanji ((DWORD)0x0004)
  412. /* NEC Kanji Mode */
  413. #define dwNECKanji ((DWORD)0x0008)
  414. /* DEC Kanji Mode */
  415. #define dwDECKanji ((DWORD)0x0010)
  416. /* JIS78 Kanji Mode */
  417. #define dwJIS78Kanji ((DWORD)0x0020)
  418. /* ACOS Kanji Mode */
  419. #define dwACOSKanji ((DWORD)0x0040)
  420. #define ClearKanjiFlag(ptrm) ((ptrm)->dwKanjiFlags = (DWORD)0)
  421. #define FIsJISKanji(ptrm) ((ptrm)->dwKanjiFlags & dwJISKanji)
  422. #define SetJISKanji(ptrm) ((ptrm)->dwKanjiFlags |= dwJISKanji)
  423. #define ClearJISKanji(ptrm) ((ptrm)->dwKanjiFlags &= ~dwJISKanji)
  424. #define FIsJIS78Kanji(ptrm) ((ptrm)->dwKanjiFlags & dwJIS78Kanji)
  425. #define SetJIS78Kanji(ptrm) ((ptrm)->dwKanjiFlags |= dwJIS78Kanji)
  426. #define ClearJIS78Kanji(ptrm) ((ptrm)->dwKanjiFlags &= ~dwJIS78Kanji)
  427. #define FIsSJISKanji(ptrm) ((ptrm)->dwKanjiFlags & dwSJISKanji)
  428. #define SetSJISKanji(ptrm) ((ptrm)->dwKanjiFlags |= dwSJISKanji)
  429. #define ClearSJISKanji(ptrm) ((ptrm)->dwKanjiFlags &= ~dwSJISKanji)
  430. #define FIsEUCKanji(ptrm) ((ptrm)->dwKanjiFlags & dwEUCKanji)
  431. #define SetEUCKanji(ptrm) ((ptrm)->dwKanjiFlags |= dwEUCKanji)
  432. #define ClearEUCKanji(ptrm) ((ptrm)->dwKanjiFlags &= ~dwEUCKanji)
  433. #define FIsNECKanji(ptrm) ((ptrm)->dwKanjiFlags & dwNECKanji)
  434. #define SetNECKanji(ptrm) ((ptrm)->dwKanjiFlags |= dwNECKanji)
  435. #define ClearNECKanji(ptrm) ((ptrm)->dwKanjiFlags &= ~dwNECKanji)
  436. #define FIsDECKanji(ptrm) ((ptrm)->dwKanjiFlags & dwDECKanji)
  437. #define SetDECKanji(ptrm) ((ptrm)->dwKanjiFlags |= dwDECKanji)
  438. #define ClearDECKanji(ptrm) ((ptrm)->dwKanjiFlags &= ~dwDECKanji)
  439. #define FIsACOSKanji(ptrm) ((ptrm)->dwKanjiFlags & dwACOSKanji)
  440. #define SetACOSKanji(ptrm) ((ptrm)->dwKanjiFlags |= dwACOSKanji)
  441. #define ClearACOSKanji(ptrm) ((ptrm)->dwKanjiFlags &= ~dwACOSKanji)
  442. #define FIsKanjiMode(ptrm,KanjiFlag) ((ptrm)->dwKanjiFlags & (KanjiFlag))
  443. #define SetKanjiMode(ptrm,KanjiFlag) ((ptrm)->dwKanjiFlags |= (KanjiFlag))
  444. #define ClearKanjiMode(ptrm,KanjiFlag) ((ptrm)->dwKanjiFlags &= ~(KanjiFlag))
  445. /* General */
  446. #define SINGLE_SHIFT_2 ((DWORD)0x0001)
  447. #define SINGLE_SHIFT_3 ((DWORD)0x0002)
  448. /* JIS */
  449. /* for recieve status */
  450. #define JIS_INVOKE_MB ((DWORD)0x0010)
  451. #define JIS_INVOKE_SB ((DWORD)0x0020)
  452. #define JIS_KANJI_CODE ((DWORD)0x0040)
  453. /* for send status */
  454. #define JIS_SENDING_KANJI ((DWORD)0x0080)
  455. #define CLEAR_ALL ((DWORD)0xFFFF)
  456. #define GetKanjiStatus(ptrm) ((ptrm)->dwKanjiStatus)
  457. #define SetKanjiStatus(ptrm,val) ((ptrm)->dwKanjiStatus |= val)
  458. #define ClearKanjiStatus(ptrm,val) ((ptrm)->dwKanjiStatus &= ~val)
  459. #define NUMBER_OF_KANJI 7
  460. typedef struct _TERM
  461. {
  462. TERM_TYPE CurrentTermType; /* the Term type that has been
  463. negotiated between server & client. This
  464. is ANSI to start with i.e. if no negotiation
  465. happens. */
  466. TERM_TYPE SentTermType; /* this is the last term type that we sent
  467. to the Server during TermType negotiation */
  468. TERM_TYPE RequestedTermType; /* this is the preferred term type of the user */
  469. TERM_TYPE FirstTermTypeSent; /* this is the first term type sent by us */
  470. DWORD dwCurLine;
  471. DWORD dwCurChar;
  472. DWORD dwEscCodes[10];
  473. DWORD rgdwGraphicRendition[10];
  474. INT dwIndexOfGraphicRendition;
  475. DWORD cEscParams;
  476. DWORD dwScrollTop;
  477. DWORD dwScrollBottom;
  478. DWORD fEsc;
  479. DWORD dwSum;
  480. UCHAR* puchCharSet;
  481. char G0, G1;
  482. int currCharSet;
  483. UINT uTimer;
  484. DWORD cTilde;
  485. DWORD dwVT100Flags;
  486. BOOL fRelCursor;
  487. BOOL fSavedState;
  488. BOOL fInverse;
  489. BOOL fHideCursor;
  490. BOOL fCursorOn;
  491. BOOL fFlushToEOL;
  492. BOOL fLongLine;
  493. UCHAR rgchBufferText[256];
  494. int cchBufferText;
  495. DWORD dwCurCharBT;
  496. DWORD dwCurLineBT;
  497. BOOL fInverseBT;
  498. DWORD rgdwSaveGraphicRendition[10];
  499. INT dwSaveIndexOfGraphicRendition;
  500. char cSaveG0, cSaveG1;
  501. int iSaveCurrCharSet;
  502. UCHAR* pSaveUchCharSet;
  503. DWORD dwSaveChar;
  504. DWORD dwSaveLine;
  505. DWORD dwSaveRelCursor;
  506. DWORD dwKanjiFlags;
  507. DWORD dwKanjiStatus;
  508. UCHAR *g0,*g1,*g2,*g3;
  509. UCHAR *CurrentCharSet[2];
  510. UCHAR *PreviousCharSet[2];
  511. } TRM;
  512. #define uRetryTimerID ((UINT)1)
  513. typedef struct _AUTORETRY
  514. {
  515. HWND hwnd;
  516. LPSTR szHostName;
  517. LPNETDATA lpData;
  518. UINT uTimer;
  519. } AR;
  520. #define dwNothingChanged ((DWORD)0)
  521. #define dwYChanged ((DWORD)0x01)
  522. #define dwXChanged ((DWORD)0x02)
  523. #define dwForceNone ((DWORD)0)
  524. #define dwForceOn ((DWORD)0x01)
  525. #define dwForceOff ((DWORD)0x02)
  526. #define SMALL_STRING 64
  527. typedef struct _SPB
  528. {
  529. POINT ptCursor; /* cursor point */
  530. POINT ptAnchor; /* anchor point */
  531. RECT rectSelect; /* selection rect */
  532. DWORD dwFlags;
  533. WPARAM wData;
  534. } SPB;
  535. typedef enum {
  536. Connecting,
  537. Authenticating,
  538. AuthChallengeRecvd,
  539. Telnet,
  540. Interactive
  541. } SESSION_STATE;
  542. /* Window Information */
  543. #define WL_TelWI (0)
  544. typedef struct _WI
  545. {
  546. NETDATA nd;
  547. TRM trm;
  548. DWORD ichTelXfer;
  549. SVI svi;
  550. SPB spb;
  551. HWND hwnd;
  552. HANDLE hNetworkThread;
  553. HANDLE hOutput;
  554. HANDLE hInput;
  555. CONSOLE_SCREEN_BUFFER_INFO sbi;
  556. CHAR_INFO cinfo;
  557. SESSION_STATE eState;
  558. } WI;
  559. extern UI ui;
  560. extern int iCursorHeight; /* height of cursor */
  561. extern int iCursorWidth; /* width of cursor */
  562. extern BOOL fConnected; /* if we're connected to a machine */
  563. extern BOOL fHungUp;
  564. extern HWND hwndMain; /* HANDLE to main display window */
  565. extern int spec_port; /* user specified port number */
  566. extern CHAR_INFO *g_rgciCharInfo;
  567. extern UCHAR *g_rgchRow; /* One row of char */
  568. extern WCHAR g_chEsc;
  569. extern SHORT g_EscCharShiftState;
  570. extern BOOL g_bDontNAWSReceived;
  571. extern TCHAR g_szLogFile[];
  572. POINT _ptCharSize;
  573. #define aixPos( col ) ( (col)*_ptCharSize.x)
  574. #define aiyPos( col ) ( (col)*_ptCharSize.y)
  575. #ifdef __NOT_USED
  576. extern UCHAR *pchNBBuffer;
  577. #endif
  578. extern HFONT hfontDisplay; /* display font */
  579. extern DWORD rgdwCustColours[16]; /* custom colour array */
  580. extern DWORD cBlocks;
  581. extern TCHAR rgchHostName[cchMaxHostName]; /* name of host we're connected to */
  582. extern TCHAR g_szPortNameOrNo[cchMaxHostName];
  583. extern int rgService;
  584. #if 0
  585. extern char rgchDbgBfr[80];
  586. #endif
  587. #ifdef TCPTEST
  588. extern UCHAR DebugBuffer[256];
  589. #endif
  590. extern UCHAR rgchCharSetWorkArea[256];
  591. extern UCHAR rgchNullChars[128];
  592. extern UCHAR rgchJISRomanChars[128];
  593. extern UCHAR rgchJISKanjiChars[128];
  594. extern UCHAR rgchEUCKanjiChars[128];
  595. extern UCHAR rgchDECKanjiChars[128];
  596. extern UCHAR rgchIBMAnsiChars[128];
  597. extern UCHAR rgchGraphicsChars[128];
  598. extern UCHAR rgchKatakanaChars[128];
  599. extern UCHAR rgchDefaultRightChars[128];
  600. extern KANJILIST KanjiList[NUMBER_OF_KANJI];
  601. extern BOOL fHSCROLL;
  602. extern TCHAR szVT100KanjiEmulation[SMALL_STRING + 1];
  603. extern UCHAR rgchNormalChars[256];
  604. extern UCHAR rgchAlternateChars[256];
  605. extern UCHAR rgchSpecialGraphicsChars[256];
  606. extern UCHAR rgchUKChars[256];
  607. extern CHAR* szUser;
  608. extern BOOL g_bSendDelAsBackSpace;
  609. extern BOOL g_bSendBackSpaceAsDel;
  610. extern DWORD g_dwSockErr;
  611. extern HANDLE g_hTelnetPromptConsoleBuffer;
  612. extern HANDLE g_hSessionConsoleBuffer;
  613. int PASCAL WinMain(HINSTANCE, HINSTANCE, LPSTR, int);
  614. int FInitApplication( int argc, TCHAR **argv, WI *pwi );
  615. BOOL FInitInstance(HINSTANCE, int);
  616. LRESULT CALLBACK MainWndProc(HWND, UINT, WPARAM, LPARAM);
  617. #ifdef WIN32
  618. BOOL APIENTRY About(HWND, UINT, WPARAM, LPARAM);
  619. #endif
  620. BOOL APIENTRY Konnect(HWND, UINT, WPARAM, LPARAM);
  621. void CenterDialog(HWND, HWND);
  622. void GetUserSettings(UI *);
  623. void SetUserSettings(UI *);
  624. void CheckEscCharState( USHORT *ptrvkBracket, UINT *ptriRet, WCHAR chEscKey, LPWSTR szEscCharShiftState );
  625. void HandleCharMappings(WI* pWI, INPUT_RECORD* pInputRecord);
  626. HMENU HmenuGetMRUMenu(HWND, UI *);
  627. /* netio.c */
  628. BOOL FCommandPending(WI *);
  629. BOOL FConnectToServer(WI *, LPSTR, LPNETDATA);
  630. int FWriteToNet(WI *, LPSTR addr, int cnt);
  631. void FCloseConnection(HWND hwnd);
  632. BOOL FPostReceive( LPNETDATA );
  633. #ifdef __NOT_USED
  634. BOOL FStoreData(LPNETDATA, int);
  635. WORD WGetData(LPNETDATA, LPSTR, WORD);
  636. #endif
  637. #ifdef USETCP
  638. void FProcessFDRead(HWND hwnd);
  639. void FProcessFDOOB(HWND hwnd);
  640. void FProcessFDWrite(HWND hwnd);
  641. void FSendSynch(HWND hwnd);
  642. void FSendTelnetCommands(HWND hwnd, char chCommand);
  643. void FSendChars( HWND, WCHAR[], int );
  644. #endif
  645. BOOL FTelXferStart(WI *, int);
  646. BOOL FTelXferEnd(WI *, DWORD);
  647. BOOL FGetFileName(WI *, char *, char *);
  648. DWORD WINAPI SVReceive(SVI *);
  649. BOOL FHangupConnection(WI *, LPNETDATA);
  650. BOOL APIENTRY ConnectAutoRetry(HWND, UINT, WPARAM, LPARAM);
  651. BOOL APIENTRY ConnectFailed(HWND, UINT, WPARAM, LPARAM);
  652. /* mcp.c */
  653. void MarkModeOn(WI *, DWORD);
  654. void MarkModeOff( WI * );
  655. void DoCursorFlicker(HWND, DWORD);
  656. void InvertSelection(HWND, RECT *);
  657. void ExtendSelection(HWND, POINT *, DWORD);
  658. void HandleMCPKeyEvent(HWND, WPARAM, LPARAM);
  659. void HandleMCPMouseEvent(HWND, UINT, WPARAM, LPARAM);
  660. void SetWindowTitle(HWND, DWORD, LPSTR);
  661. /* trmio.c */
  662. void RecalcWindowSize( HWND );
  663. void ReSizeWindow( HWND , long, long );
  664. // was SHORT/SHORT. MohsinA, 10-Dec-96.
  665. void ClearScreen(WI *pwi, TRM *, DWORD);
  666. void DoTermReset(WI *pwi, TRM *);
  667. void DoIBMANSIOutput(WI *, TRM *, DWORD, UCHAR *);
  668. BOOL DoVTNTOutput(WI *, TRM *, int, UCHAR *);
  669. void ClearScreen1(HANDLE hStdout);
  670. //void SetDisplaySize(HWND, DWORD, DWORD *);
  671. void HandleCharEvent(WI *, CHAR, DWORD);
  672. BOOL FHandleKeyDownEvent(WI *, CHAR, DWORD);
  673. void CheckForChangeInWindowSize( );
  674. //RR: BOOL IsDBCSCharPoint(POINT *);
  675. void AlignDBCSPosition(POINT *, BOOL);
  676. void AlignDBCSPosition2(POINT *, LPCSTR , BOOL);
  677. void SetupCharSet(TRM *);
  678. void SetCharSet(TRM *, INT, UCHAR *);
  679. void PushCharSet( TRM *, INT, UCHAR *);
  680. void PopCharSet( TRM *, INT);
  681. void FWriteTextDataToNet(HWND, LPSTR, int);
  682. void SetIMEConvertWindowTimer(HWND, BOOL);
  683. void SetIMEConvertPositionAndFont(HWND, UINT, UINT, BOOL);
  684. void SetEscapeChar( WCHAR );
  685. BOOL InitLogFile( LPTSTR );
  686. BOOL CloseLogging( );
  687. #define GRAPHIC_LEFT 0x00
  688. #define GRAPHIC_RIGHT 0x80
  689. extern HIMC hImeContext;
  690. /* definition for DBCS support */
  691. #define IS_ANY_DBCS_CHARSET( CharSet ) ( ((CharSet) == SHIFTJIS_CHARSET) ? TRUE : \
  692. ((CharSet) == HANGEUL_CHARSET) ? TRUE : \
  693. ((CharSet) == CHINESEBIG5_CHARSET) ? TRUE : \
  694. ((CharSet) == GB2312_CHARSET) ? TRUE : FALSE )
  695. void ErrorMessage(LPCTSTR pStr1, LPCTSTR pStr2);
  696. void ConnectTimeErrorMessage(LPCTSTR pStr1, LPCTSTR pStr2);
  697. /* Owner Notification Messages */
  698. #define NN_RECV (WM_USER+400) // wParam is count of current bytes in
  699. // the buffer.
  700. #define NN_LOST (WM_USER+401) // Connection is lost.
  701. #define NN_OVERRUN (WM_USER+402) // internal buffer overrun
  702. #define NN_HOSTRESOLVED (WM_USER+403) // Usage message box
  703. #define MAX_STRING_LENGTH 512
  704. #define MAX_BUFFER_SIZE 2048
  705. #define ARRAY_SIZE(sz) (sizeof(sz)/sizeof((sz)[0]))
  706. #define USER "USER"
  707. #define WIN32_STRING "WIN32"
  708. #define SYSTEMTYPE "SYSTEMTYPE"
  709. #define TELNET_PORT 23
  710. /* Winsock messages */
  711. #define WS_ASYNC_SELECT (WM_USER+500) // WSAAsyncSelect Occured
  712. #define ALT_PRESSED (LEFT_ALT_PRESSED | RIGHT_ALT_PRESSED)
  713. #define CTRL_PRESSED (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED)
  714. #define N_BITS_IN_BYTE 8 // fact of life
  715. #define N_BITS_IN_UINT (sizeof(UINT) * N_BITS_IN_BYTE)
  716. // General Purpose Bit Array manipulation macros
  717. #define BitFlagSetON(pBitFlagArray, iBit) (pBitFlagArray[(iBit)/N_BITS_IN_UINT]|=(0x1<<((iBit)%N_BITS_IN_UINT)))
  718. #define BitFlagSetOFF(pBitFlagArray, iBit) (pBitFlagArray[(iBit)/N_BITS_IN_UINT]&=(~(0x1<<((iBit)%N_BITS_IN_UINT))))
  719. #define BitFlagReverse(pBitFlagArray, iBit) (pBitFlagArray[(iBit)/N_BITS_IN_UINT] ^= (0x1<<((iBit)%N_BITS_IN_UINT)))
  720. #define FBitFlag(pBitFlagArray, iBit) (pBitFlagArray[(iBit)/N_BITS_IN_UINT] & (0x1<<((iBit)%N_BITS_IN_UINT)))
  721. extern UINT gfCodeModeFlags[];
  722. enum
  723. {
  724. eCodeModeMin, // This must be present so that eCodeModeMax becomes positive
  725. eCodeModeFarEast = 0, // The zeroth one can be same as the eCodeModeMin
  726. eCodeModeVT80,
  727. eCodeModeIMEFarEast,
  728. eCodeModeMax // Obviously this must be the last.
  729. };
  730. #define FGetCodeMode(eCodeMode) FBitFlag(gfCodeModeFlags, eCodeMode)
  731. #define SetCodeModeON(eCodeMode) BitFlagSetON(gfCodeModeFlags, eCodeMode)
  732. #define SetCodeModeOFF(eCodeMode) BitFlagSetOFF(gfCodeModeFlags, eCodeMode)
  733. #define SetCodeMode(eCodeMode, fBool) ((fBool) ? SetCodeModeON(eCodeMode) : SetCodeModeOFF(eCodeMode))
  734. #define TAB_LENGTH 8
  735. #define DEFAULT_ESCAPE_CHAR 0x1D
  736. #define DEFAULT_SHIFT_STATE 2
  737. #define MAX_KEYUPS 7 //This value is out of thin air.
  738. #define SHIFT_KEY 1
  739. #define CTRL_KEY 2
  740. #define ALT_KEY 4
  741. #define ALT_PLUS L"ALT+"
  742. #define CTRL_PLUS L"CTRL+"
  743. #define SHIFT_PLUS L"SHIFT+"
  744. //Means exnded char. They differ for each code page
  745. #define IS_EXTENDED_CHAR( c ) ( ( c ) >= 129 )
  746. #define ASCII_BACKSPACE 0x08
  747. #define ASCII_DEL 0x7f
  748. #define ASCII_CR 0x0D
  749. #define ASCII_LF 0x0A
  750. #define VT302_NEXT '6'
  751. #define VT302_PRIOR '5'
  752. #define VT302_END '4'
  753. #define VT302_INSERT '2'
  754. #define VT302_HOME '1'
  755. #define VT302_PAUSE 'P'
  756. #define CHAR_ZERO '0'
  757. #define CHAR_ONE '1'
  758. #define CHAR_TWO '2'
  759. #define CHAR_THREE '3'
  760. #define CHAR_FOUR '4'
  761. #define CHAR_FIVE '5'
  762. #define CHAR_SEVEN '7'
  763. #define CHAR_EIGHT '8'
  764. #define CHAR_NINE '9'
  765. #define CHAR_NUL 0
  766. #define SFUTLNTVER "SFUTLNTVER"
  767. #define SFUTLNTMODE "SFUTLNTMODE"
  768. #define DELTA 100
  769. #define KOR_CODEPAGE 949
  770. #define JAP_CODEPAGE 932
  771. #define IS_NUMPAD_DIGIT_KEY( KeyEvent ) \
  772. ( !( KeyEvent.dwControlKeyState & ENHANCED_KEY ) && \
  773. ( ( KeyEvent.wVirtualKeyCode == VK_INSERT ) || \
  774. ( KeyEvent.wVirtualKeyCode == VK_END ) || \
  775. ( KeyEvent.wVirtualKeyCode == VK_DOWN ) || \
  776. ( KeyEvent.wVirtualKeyCode == VK_NEXT ) || \
  777. ( KeyEvent.wVirtualKeyCode == VK_LEFT ) || \
  778. ( KeyEvent.wVirtualKeyCode == VK_CLEAR ) || \
  779. ( KeyEvent.wVirtualKeyCode == VK_RIGHT ) || \
  780. ( KeyEvent.wVirtualKeyCode == VK_HOME ) || \
  781. ( KeyEvent.wVirtualKeyCode == VK_UP ) || \
  782. ( KeyEvent.wVirtualKeyCode == VK_PRIOR ) ) )
  783. #define MAP_DIGIT_KEYS_TO_VAL( wVirtualKeyCode ) \
  784. ( ( wVirtualKeyCode == VK_INSERT ? 0 : \
  785. wVirtualKeyCode == VK_END ? 1 : \
  786. wVirtualKeyCode == VK_DOWN ? 2 : \
  787. wVirtualKeyCode == VK_NEXT ? 3 : \
  788. wVirtualKeyCode == VK_LEFT ? 4 : \
  789. wVirtualKeyCode == VK_CLEAR ? 5 : \
  790. wVirtualKeyCode == VK_RIGHT ? 6 : \
  791. wVirtualKeyCode == VK_HOME ? 7 : \
  792. wVirtualKeyCode == VK_UP ? 8 : \
  793. wVirtualKeyCode == VK_PRIOR ? 9 : 0 ) )