Leaked source code of windows server 2003
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.

664 lines
16 KiB

  1. /* File: C:\WACKER\TDLL\recv_dlg.c (Created: 27-Dec-1993)
  2. *
  3. * Copyright 1990,1994 by Hilgraeve Inc. -- Monroe, MI
  4. * All rights reserved
  5. *
  6. * $Revision: 16 $
  7. * $Date: 4/17/02 5:16p $
  8. */
  9. #include <windows.h>
  10. #pragma hdrstop
  11. #include <time.h>
  12. #include "stdtyp.h"
  13. #include "mc.h"
  14. #include "hlptable.h"
  15. #include "tdll.h"
  16. #include "misc.h"
  17. #include <tdll\assert.h>
  18. #include <term\res.h>
  19. #include "session.h"
  20. #include "globals.h"
  21. #include "file_msc.h"
  22. #include "load_res.h"
  23. #include "open_msc.h"
  24. #include "errorbox.h"
  25. #include "cnct.h"
  26. #include "htchar.h"
  27. #include "errorbox.h"
  28. #include "xfer_msc.h"
  29. #include "xfer_msc.hh"
  30. #include <xfer\xfer.h>
  31. #if !defined(DlgParseCmd)
  32. #define DlgParseCmd(i,n,c,w,l) i=LOWORD(w);n=HIWORD(w);c=(HWND)l;
  33. #endif
  34. struct stSaveDlgStuff
  35. {
  36. /*
  37. * Put in whatever else you might need to access later
  38. */
  39. HSESSION hSession;
  40. };
  41. typedef struct stSaveDlgStuff SDS;
  42. #define IDC_TF_FILENAME 100
  43. #define IDC_EB_DIR 101
  44. #define IDC_PB_BROWSE 102
  45. #define IDC_TF_PROTOCOL 103
  46. #define IDC_CB_PROTOCOL 104
  47. #define IDC_PB_CLOSE 105
  48. #define IDC_PB_RECEIVE 106
  49. INT_PTR CALLBACK TransferReceiveFilenameDlg(HWND hDlg,
  50. UINT wMsg,
  51. WPARAM wPar,
  52. LPARAM lPar);
  53. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  54. * FUNCTION: TransferReceiveDlg
  55. *
  56. * DESCRIPTION: Dialog manager stub
  57. *
  58. * ARGUMENTS: Standard Windows dialog manager
  59. *
  60. * RETURNS: Standard Windows dialog manager
  61. *
  62. */
  63. INT_PTR CALLBACK TransferReceiveDlg(HWND hDlg, UINT wMsg, WPARAM wPar, LPARAM lPar)
  64. {
  65. HWND hwndChild;
  66. INT nId;
  67. INT nNtfy;
  68. SDS *pS;
  69. int nProto;
  70. int nIndex;
  71. int nState;
  72. int nProtocol;
  73. int nXferRecvReturn = 0;
  74. TCHAR acBuffer[FNAME_LEN];
  75. TCHAR acName[FNAME_LEN];
  76. LPCTSTR pszDir;
  77. LPTSTR pszPtr;
  78. LPTSTR pszStr;
  79. XFR_PARAMS *pP;
  80. XFR_PROTOCOL *pX;
  81. HSESSION hSession;
  82. HXFER hXfer = NULL;
  83. XD_TYPE *pT = NULL;
  84. static DWORD aHlpTable[] = {IDC_EB_DIR, IDH_TERM_RECEIVE_DIRECTORY,
  85. IDC_TF_FILENAME, IDH_TERM_RECEIVE_DIRECTORY,
  86. IDC_PB_BROWSE, IDH_BROWSE,
  87. IDC_TF_PROTOCOL, IDH_TERM_RECEIVE_PROTOCOL,
  88. IDC_CB_PROTOCOL, IDH_TERM_RECEIVE_PROTOCOL,
  89. IDC_PB_RECEIVE, IDH_TERM_RECEIVE_RECEIVE,
  90. IDC_PB_CLOSE, IDH_CLOSE_DIALOG,
  91. IDCANCEL, IDH_CANCEL,
  92. IDOK, IDH_OK,
  93. 0, 0};
  94. switch (wMsg)
  95. {
  96. case WM_INITDIALOG:
  97. pS = (SDS *)malloc(sizeof(SDS));
  98. SetWindowLongPtr(hDlg, DWLP_USER, (LONG_PTR)pS);
  99. if (pS == 0)
  100. {
  101. EndDialog(hDlg, FALSE);
  102. break;
  103. }
  104. SendMessage(GetDlgItem(hDlg, IDC_EB_DIR),
  105. EM_SETLIMITTEXT,
  106. FNAME_LEN, 0);
  107. hSession = (HSESSION)lPar;
  108. pS->hSession = hSession;
  109. mscCenterWindowOnWindow(hDlg, GetParent(hDlg));
  110. pP = (XFR_PARAMS *)0;
  111. xfrQueryParameters(sessQueryXferHdl(hSession), (VOID **)&pP);
  112. assert(pP);
  113. nState = pP->nRecProtocol;
  114. /*
  115. * Load selections into the PROTOCOL COMBO box
  116. */
  117. nProto = 0;
  118. mscResetComboBox(GetDlgItem(hDlg, IDC_CB_PROTOCOL));
  119. pX = (XFR_PROTOCOL *)0;
  120. xfrGetProtocols(hSession, &pX);
  121. assert(pX);
  122. if (pX != (XFR_PROTOCOL *)0)
  123. {
  124. for (nIndex = 0; pX[nIndex].nProtocol != 0; nIndex += 1)
  125. {
  126. if (nState == pX[nIndex].nProtocol)
  127. nProto = nIndex;
  128. //jmh 02-13-96 Use CB_ADDSTRING to sort entries as
  129. // they are added. CB_INSERTSTRING doesn't do this,
  130. // even if the combo-box has the CBS_SORT style.
  131. SendMessage(GetDlgItem(hDlg, IDC_CB_PROTOCOL),
  132. CB_ADDSTRING,
  133. 0, //(UINT) -1
  134. (LPARAM)&pX[nIndex].acName[0]);
  135. }
  136. SendMessage(GetDlgItem(hDlg, IDC_CB_PROTOCOL),
  137. CB_SELECTSTRING,
  138. 0,
  139. (LPARAM) &pX[nProto].acName[0]);
  140. free(pX);
  141. pX = NULL;
  142. }
  143. PostMessage(hDlg, WM_COMMAND,
  144. IDC_CB_PROTOCOL,
  145. MAKELONG(GetDlgItem(hDlg, IDC_CB_PROTOCOL),CBN_SELCHANGE));
  146. /*
  147. * Set the current directory
  148. */
  149. pszDir = filesQueryRecvDirectory(sessQueryFilesDirsHdl(hSession));
  150. SetDlgItemText(hDlg, IDC_EB_DIR, pszDir);
  151. // Check if we're connected. If not, disable Send button.
  152. //
  153. if (cnctQueryStatus(sessQueryCnctHdl(hSession)) != CNCT_STATUS_TRUE)
  154. EnableWindow(GetDlgItem(hDlg, IDC_PB_RECEIVE), FALSE);
  155. /*
  156. * Set the focus on this control
  157. */
  158. SetFocus(GetDlgItem(hDlg, IDC_EB_DIR));
  159. return 0;
  160. case WM_DESTROY:
  161. mscResetComboBox(GetDlgItem(hDlg, IDC_CB_PROTOCOL));
  162. pS = (SDS *)GetWindowLongPtr(hDlg, DWLP_USER);
  163. if (pS)
  164. {
  165. free(pS);
  166. pS = NULL;
  167. }
  168. break;
  169. case WM_CONTEXTMENU:
  170. doContextHelp(aHlpTable, wPar, lPar, TRUE, TRUE);
  171. break;
  172. case WM_HELP:
  173. doContextHelp(aHlpTable, wPar, lPar, FALSE, FALSE);
  174. break;
  175. case WM_COMMAND:
  176. /*
  177. * Did we plan to put a macro in here to do the parsing ?
  178. */
  179. DlgParseCmd(nId, nNtfy, hwndChild, wPar, lPar);
  180. switch (nId)
  181. {
  182. case IDC_PB_RECEIVE:
  183. case IDC_PB_CLOSE:
  184. pS = (SDS *)GetWindowLongPtr(hDlg, DWLP_USER);
  185. hSession = pS->hSession;
  186. assert(hSession);
  187. if (hSession == NULL)
  188. {
  189. break;
  190. }
  191. hXfer = sessQueryXferHdl(hSession);
  192. assert(hXfer);
  193. if (hXfer == NULL)
  194. {
  195. break;
  196. }
  197. //
  198. // See if a file transfer is currently in progress.
  199. //
  200. pT = (XD_TYPE *)hXfer;
  201. assert(pT);
  202. if (pT == (XD_TYPE *)0)
  203. {
  204. break;
  205. }
  206. else if (pT->nDirection != XFER_NONE)
  207. {
  208. nXferRecvReturn = XFR_IN_PROGRESS;
  209. }
  210. else if(cnctQueryStatus(sessQueryCnctHdl(hSession))
  211. != CNCT_STATUS_TRUE && nId == IDC_PB_RECEIVE)
  212. {
  213. //
  214. // We are currently not connected (loss of carrier),
  215. // so disable the Recieve button. REV: 9/7/2001
  216. //
  217. nXferRecvReturn = XFR_NO_CARRIER;
  218. mscMessageBeep(MB_ICONHAND);
  219. EnableWindow(GetDlgItem(hDlg, IDC_PB_RECEIVE), FALSE);
  220. }
  221. else
  222. {
  223. /*
  224. * Do whatever saving is necessary
  225. */
  226. pP = (XFR_PARAMS *)0;
  227. xfrQueryParameters(hXfer, (VOID **)&pP);
  228. assert(pP);
  229. /*
  230. * Save selection from the PROTOCOL COMBO box
  231. */
  232. pX = (XFR_PROTOCOL *)0;
  233. xfrGetProtocols(hSession, &pX);
  234. assert(pX);
  235. nProtocol = 0;
  236. if (pX != (XFR_PROTOCOL *)0)
  237. {
  238. GetDlgItemText(hDlg,
  239. IDC_CB_PROTOCOL,
  240. acBuffer,
  241. (sizeof(acBuffer) / sizeof(TCHAR)));
  242. for (nIndex = 0; pX[nIndex].nProtocol != 0; nIndex += 1)
  243. {
  244. if (StrCharCmp(acBuffer, pX[nIndex].acName) == 0)
  245. {
  246. nProtocol = pX[nIndex].nProtocol;
  247. break;
  248. }
  249. }
  250. free(pX);
  251. pX = NULL;
  252. }
  253. /*
  254. * Save the current directory
  255. */
  256. GetDlgItemText(hDlg, IDC_EB_DIR,
  257. acBuffer,
  258. sizeof(acBuffer) / sizeof(TCHAR));
  259. // xfer_makepaths checks for the validity of the path and
  260. // prompts to create it if not there.
  261. //
  262. if (xfer_makepaths(hSession, acBuffer) != 0)
  263. {
  264. break;
  265. }
  266. if (nId == IDC_PB_RECEIVE)
  267. {
  268. acName[0] = TEXT('\0');
  269. switch (nProtocol)
  270. {
  271. case XF_XMODEM:
  272. case XF_XMODEM_1K:
  273. pszPtr = (LPTSTR)DoDialog(glblQueryDllHinst(),
  274. MAKEINTRESOURCE(IDD_RECEIVEFILENAME),
  275. hDlg,
  276. TransferReceiveFilenameDlg,
  277. (LPARAM)hSession);
  278. if (pszPtr == NULL)
  279. {
  280. //
  281. // Don't close the recieve dialog here, so state we
  282. // have handled the message. REV: 3/27/2002
  283. //
  284. return TRUE;
  285. }
  286. //
  287. // If we want to allow the user to fully path the Xmodem
  288. // filename, we will have to split the directory and filename
  289. // apart here and set asBuffer with the receive directory.
  290. // We will also have to make sure we call xfer_makepaths()
  291. // so that we are in the directory is correct for the file
  292. // transfer. REV: 3/27/2002
  293. //
  294. StrCharCopyN(acName, pszPtr, FNAME_LEN);
  295. free(pszPtr);
  296. pszPtr = NULL;
  297. break;
  298. default:
  299. break;
  300. }
  301. }
  302. /*
  303. * Save anything that needs to be saved
  304. */
  305. pP->nRecProtocol = nProtocol;
  306. xfrSetParameters(hXfer, (VOID *)pP);
  307. filesSetRecvDirectory(sessQueryFilesDirsHdl(hSession), acBuffer);
  308. if (nId == IDC_PB_RECEIVE)
  309. {
  310. /*
  311. * The directory to use should be in "acBuffer", and the
  312. * file name (if any) should be in acName.
  313. */
  314. nXferRecvReturn = xfrRecvStart(hXfer, acBuffer, acName);
  315. //break; // If the dlg isn't closed here, keyboard msgs
  316. // intended for the rcv progress dlg are
  317. // intercepted by this dlg. rde 31 Oct 01
  318. }
  319. }
  320. //
  321. // Don't save the settings if a file transfer is in
  322. // progress otherwise the current file transfer could
  323. // get corrupted. REV: 08/06/2001.
  324. //
  325. if (nXferRecvReturn == XFR_IN_PROGRESS)
  326. {
  327. TCHAR acMessage[256];
  328. if (sessQuerySound(hSession))
  329. {
  330. mscMessageBeep(MB_ICONHAND);
  331. }
  332. LoadString(glblQueryDllHinst(),
  333. IDS_ER_XFER_RECV_IN_PROCESS,
  334. acMessage,
  335. sizeof(acMessage) / sizeof(TCHAR));
  336. TimedMessageBox(sessQueryHwnd(hSession),
  337. acMessage,
  338. NULL,
  339. MB_OK | MB_ICONEXCLAMATION,
  340. sessQueryTimeout(hSession));
  341. }
  342. else if(nXferRecvReturn == XFR_NO_CARRIER)
  343. {
  344. //
  345. // We are currently not connected (loss of carrier),
  346. // so disable the Recieve button. REV: 9/7/2001
  347. //
  348. mscMessageBeep(MB_ICONHAND);
  349. EnableWindow(GetDlgItem(hDlg, IDC_PB_RECEIVE), FALSE);
  350. }
  351. else
  352. {
  353. EndDialog(hDlg, TRUE);
  354. }
  355. break;
  356. case IDCANCEL:
  357. EndDialog(hDlg, FALSE);
  358. break;
  359. case IDC_PB_BROWSE:
  360. pS = (SDS *)GetWindowLongPtr(hDlg, DWLP_USER);
  361. if (pS)
  362. {
  363. GetDlgItemText(hDlg,
  364. IDC_EB_DIR,
  365. acBuffer,
  366. sizeof(acBuffer) / sizeof(TCHAR));
  367. pszStr = gnrcFindDirectoryDialog(hDlg, pS->hSession, acBuffer);
  368. if (pszStr)
  369. {
  370. SetDlgItemText(hDlg, IDC_EB_DIR, pszStr);
  371. free(pszStr);
  372. pszStr = NULL;
  373. }
  374. }
  375. break;
  376. default:
  377. return FALSE;
  378. }
  379. break;
  380. default:
  381. return FALSE;
  382. }
  383. return TRUE;
  384. }
  385. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  386. * FUNCTION:
  387. * TransferReceiveFilenameDlg
  388. *
  389. * DESCRIPTION:
  390. * This function is called to prompt the user to enter a filename. This is
  391. * necessary for some protocols like XMODEM, which does not send a filename,
  392. * and for other protocols when the user has not checked the option to use
  393. * the received file name.
  394. *
  395. * PARAMETERS:
  396. * Standard dialog box parameters.
  397. *
  398. * RETURNS:
  399. * Indirectly, a pointer to a string (that must be freed by the caller) that
  400. * contains the name, or a NULL if the user canceled.
  401. *
  402. */
  403. #define FOLDER 101
  404. #define DIR_TEXT 102
  405. #define FNAME_LABEL 103
  406. #define FNAME_EDIT 104
  407. #define FILL_TEXT 105
  408. INT_PTR CALLBACK TransferReceiveFilenameDlg(HWND hDlg,
  409. UINT wMsg,
  410. WPARAM wPar,
  411. LPARAM lPar)
  412. {
  413. HWND hwndChild;
  414. INT nId;
  415. INT nNtfy;
  416. SDS *pS;
  417. HWND hwndParent;
  418. TCHAR acDir[FNAME_LEN];
  419. TCHAR acBuffer[FNAME_LEN];
  420. static DWORD aHlpTable[] = {FOLDER, IDH_TERM_RECEIVE_DIRECTORY,
  421. FNAME_LABEL, IDH_TERM_RECEIVE_PROTOCOL,
  422. FNAME_EDIT, IDH_TERM_RECEIVE_PROTOCOL,
  423. IDCANCEL, IDH_CANCEL,
  424. IDOK, IDH_OK,
  425. 0, 0};
  426. switch (wMsg)
  427. {
  428. case WM_INITDIALOG:
  429. pS = (SDS *)malloc(sizeof(SDS));
  430. SetWindowLongPtr(hDlg, DWLP_USER, (LONG_PTR)pS);
  431. if (pS == (SDS *)0)
  432. {
  433. EndDialog(hDlg, FALSE);
  434. break;
  435. }
  436. mscCenterWindowOnWindow(hDlg, GetParent(hDlg));
  437. SendMessage(GetDlgItem(hDlg, FNAME_EDIT),
  438. EM_SETLIMITTEXT,
  439. FNAME_LEN, 0);
  440. hwndParent = GetParent(hDlg);
  441. if (IsWindow(hwndParent))
  442. {
  443. acDir[0] = TEXT('\0');
  444. GetDlgItemText(hwndParent,
  445. IDC_EB_DIR,
  446. acDir,
  447. sizeof(acDir) / sizeof(TCHAR));
  448. if (StrCharGetStrLength(acDir) > 0)
  449. {
  450. SetDlgItemText(hDlg,
  451. DIR_TEXT,
  452. acDir);
  453. }
  454. }
  455. break;
  456. case WM_DESTROY:
  457. pS = (SDS *)GetWindowLongPtr(hDlg, DWLP_USER);
  458. if (pS)
  459. {
  460. free(pS);
  461. pS = NULL;
  462. }
  463. break;
  464. case WM_CONTEXTMENU:
  465. doContextHelp(aHlpTable, wPar, lPar, TRUE, TRUE);
  466. break;
  467. case WM_HELP:
  468. doContextHelp(aHlpTable, wPar, lPar, FALSE, FALSE);
  469. break;
  470. case WM_COMMAND:
  471. /*
  472. * Did we plan to put a macro in here to do the parsing ?
  473. */
  474. DlgParseCmd(nId, nNtfy, hwndChild, wPar, lPar);
  475. switch (nId)
  476. {
  477. case IDOK:
  478. pS = (SDS *)GetWindowLongPtr(hDlg, DWLP_USER);
  479. /*
  480. * Do whatever saving is necessary
  481. */
  482. acBuffer[0] = TEXT('\0');
  483. GetDlgItemText(hDlg, FNAME_EDIT,
  484. acBuffer,
  485. sizeof(acBuffer) / sizeof(TCHAR));
  486. if (StrCharGetStrLength(acBuffer) == 0)
  487. {
  488. TCHAR ach[256];
  489. LoadString(glblQueryDllHinst(), IDS_GNRL_NEED_FNAME, ach,
  490. sizeof(ach)/sizeof(TCHAR));
  491. TimedMessageBox(hDlg, ach, NULL, MB_OK | MB_ICONHAND, 0);
  492. }
  493. else
  494. {
  495. LPTSTR pszStr = NULL;
  496. TCHAR invalid_chars[MAX_PATH];
  497. LPTSTR lpFilePart = NULL;
  498. int numchar = GetFullPathName(acBuffer, 0, pszStr, &lpFilePart);
  499. UINT ErrorId = 0;
  500. LoadString(glblQueryDllHinst(), IDS_GNRL_INVALID_FILE_CHARS,
  501. invalid_chars, MAX_PATH);
  502. if (numchar == 0)
  503. {
  504. ErrorId = IDS_GNRL_NEED_FNAME;
  505. }
  506. else if ((pszStr = (LPTSTR)malloc(numchar * sizeof(TCHAR))) == NULL)
  507. {
  508. ErrorId = IDS_TM_XFER_TWELVE;
  509. }
  510. else if (GetFullPathName(acBuffer, numchar, pszStr, &lpFilePart) == 0)
  511. {
  512. ErrorId = IDS_GNRL_NEED_FNAME;
  513. }
  514. else if (lpFilePart == NULL ||
  515. StrCharPBrk(lpFilePart, invalid_chars) != NULL ||
  516. StrCharPBrk(acBuffer, invalid_chars) != NULL)
  517. {
  518. ErrorId = IDS_GNRL_INVALID_FNAME_CHARS;
  519. }
  520. if (ErrorId == 0)
  521. {
  522. StrCharCopyN(pszStr, lpFilePart, numchar);
  523. EndDialog(hDlg, (INT_PTR)pszStr);
  524. }
  525. else
  526. {
  527. TCHAR ach[256];
  528. TCHAR ach2[256];
  529. if (LoadString(glblQueryDllHinst(), ErrorId, ach, 256) == 0)
  530. {
  531. TCHAR_Fill(ach, TEXT('\0'), 256);
  532. }
  533. if (ErrorId == IDS_GNRL_INVALID_FNAME_CHARS)
  534. {
  535. if (LoadString(glblQueryDllHinst(), ErrorId, ach2, 256))
  536. {
  537. wsprintf(ach, ach2, invalid_chars);
  538. }
  539. }
  540. else
  541. {
  542. LoadString(glblQueryDllHinst(), ErrorId, ach, 256);
  543. }
  544. TimedMessageBox(hDlg, ach, NULL, MB_OK | MB_ICONSTOP,
  545. sessQueryTimeout(pS->hSession));
  546. if (pszStr)
  547. {
  548. free(pszStr);
  549. pszStr = NULL;
  550. }
  551. }
  552. }
  553. break;
  554. case IDCANCEL:
  555. pS = (SDS *)GetWindowLongPtr(hDlg, DWLP_USER);
  556. EndDialog(hDlg, FALSE);
  557. break;
  558. default:
  559. return FALSE;
  560. }
  561. break;
  562. default:
  563. return FALSE;
  564. }
  565. return TRUE;
  566. }