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.

1892 lines
42 KiB

  1. /* File: D:\WACKER\tdll\xfer_msc.c (Created: 28-Dec-1993)
  2. *
  3. * Copyright 1994 by Hilgraeve Inc. -- Monroe, MI
  4. * All rights reserved
  5. *
  6. * $Revision: 24 $
  7. * $Date: 5/15/02 4:38p $
  8. */
  9. #include <windows.h>
  10. #pragma hdrstop
  11. #include <term\res.h>
  12. #include "stdtyp.h"
  13. #include "session.h"
  14. #include "mc.h"
  15. #include "tdll.h"
  16. #include "htchar.h"
  17. #include "cloop.h"
  18. #include "tdll\assert.h"
  19. #include "globals.h"
  20. #include "errorbox.h"
  21. #include "file_msc.h"
  22. #include "xfdspdlg.h"
  23. #include "sf.h"
  24. #include "sess_ids.h"
  25. #include "misc.h"
  26. #include "xfer\xfer.h"
  27. #include "xfer\xfer.hh"
  28. #include "xfer_msc.h"
  29. #include "xfer_msc.hh"
  30. #include "xfer\xfer_tsc.h"
  31. void xferCancelAutoStart(HSESSION hSession, long lProtocol);
  32. static void xfrInitDspStruct(HXFER hXfer);
  33. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  34. *
  35. * X F E R _ M S C . C
  36. *
  37. * This module contains various functions that are used in this dll in order
  38. * to implement transfers. While most of the code exists in the dialog procs
  39. * for the Transfer Send and Transfer Receive dialogs, some is here to make
  40. * things a little bit easier.
  41. *
  42. *=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  43. #define LIST_CHUNK 2
  44. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  45. * FUNCTION:
  46. * CreateXferHdl
  47. *
  48. * DESCRIPTION:
  49. * This function creates an "empty" Xfer handle. It has stuff in it. It
  50. * just didn't come from the user.
  51. *
  52. * PARAMETERS:
  53. * hSession -- the session handle
  54. *
  55. * RETURNS:
  56. * A blinded pointer to the Xfer handle.
  57. *
  58. */
  59. HXFER CreateXferHdl(const HSESSION hSession)
  60. {
  61. int nRet;
  62. XD_TYPE *pX;
  63. pX = (XD_TYPE *)malloc(sizeof(XD_TYPE));
  64. assert(pX);
  65. if (pX)
  66. {
  67. memset(pX, 0, sizeof(XD_TYPE));
  68. nRet = InitializeXferHdl(hSession, (HXFER)pX);
  69. if (nRet != 0)
  70. {
  71. goto CXHexit;
  72. }
  73. pX->nSendListCount = 0;
  74. pX->acSendNames = NULL;
  75. // Make sure to set the Transfer direction to none. REV: 02/14/2001
  76. pX->nDirection = XFER_NONE;
  77. }
  78. return (HXFER)pX;
  79. CXHexit:
  80. if (pX)
  81. {
  82. if (pX->xfer_params)
  83. {
  84. free(pX->xfer_params);
  85. pX->xfer_params = NULL;
  86. }
  87. if (pX->xfer_old_params)
  88. {
  89. free(pX->xfer_old_params);
  90. pX->xfer_old_params = NULL;
  91. }
  92. free(pX);
  93. pX = NULL;
  94. }
  95. return (HXFER)0;
  96. }
  97. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  98. * FUNCTION:
  99. * InitializeXferHdl
  100. *
  101. * DESCRIPTION:
  102. * This function initializes the Xfer handle to a known state.
  103. *
  104. * PARAMETERS:
  105. * hSession -- the session handle
  106. * hXfer -- the Xfer handle
  107. *
  108. * RETURNS:
  109. * ZERO if everything is OK, otherwise an error code.
  110. *
  111. */
  112. INT InitializeXferHdl(const HSESSION hSession, HXFER hXfer)
  113. {
  114. XD_TYPE *pX;
  115. pX = (XD_TYPE *)hXfer;
  116. assert(pX);
  117. if (pX == 0)
  118. {
  119. return -2;
  120. }
  121. else
  122. {
  123. int nIdx;
  124. if (pX->xfer_params)
  125. {
  126. free(pX->xfer_params);
  127. pX->xfer_params = NULL;
  128. }
  129. if (pX->xfer_old_params)
  130. {
  131. free(pX->xfer_old_params);
  132. pX->xfer_old_params = NULL;
  133. }
  134. //
  135. // We don't want to clear out the xfer_proto_params
  136. // since they do not change, but since memset is used
  137. // below, we must. REV: 4/10/2002
  138. //
  139. if (pX->xfer_proto_params)
  140. {
  141. /*
  142. * Loop through the protocol specific stuff
  143. */
  144. for (nIdx = SFID_PROTO_PARAMS_END - SFID_PROTO_PARAMS; nIdx >= 0; nIdx--)
  145. {
  146. if (pX->xfer_proto_params[nIdx])
  147. {
  148. free(pX->xfer_proto_params[nIdx]);
  149. pX->xfer_proto_params[nIdx] = NULL;
  150. }
  151. }
  152. }
  153. if (pX->acSendNames)
  154. {
  155. int nIdx;
  156. /* Clear list */
  157. for (nIdx = pX->nSendListCount - 1; nIdx >= 0; nIdx--)
  158. {
  159. if (pX->acSendNames[nIdx])
  160. {
  161. free(pX->acSendNames[nIdx]);
  162. pX->acSendNames[nIdx] = NULL;
  163. }
  164. pX->nSendListCount = nIdx;
  165. }
  166. free(pX->acSendNames);
  167. pX->acSendNames = NULL;
  168. pX->nSendListCount = 0;
  169. }
  170. if (pX->pXferStuff)
  171. {
  172. free(pX->pXferStuff);
  173. pX->pXferStuff = NULL;
  174. }
  175. //
  176. // TODO:REV 4/10/2002 This should be put into a function to
  177. // initialize the structure instead of just using memset.
  178. //
  179. memset(pX, 0, sizeof(XD_TYPE));
  180. pX->hSession = hSession;
  181. pX->nBps = 0;
  182. pX->nOldBps = pX->nBps;
  183. xfrQueryParameters(sessQueryXferHdl(hSession), &pX->xfer_params);
  184. if (pX->xfer_params == (SZ_TYPE *)0)
  185. return -1;
  186. pX->xfer_old_params = malloc(pX->xfer_params->nSize);
  187. if (pX->xfer_old_params == (SZ_TYPE *)0)
  188. {
  189. free(pX->xfer_params);
  190. pX->xfer_params = (SZ_TYPE *)0;
  191. return -1;
  192. }
  193. MemCopy(pX->xfer_old_params, pX->xfer_params, pX->xfer_params->nSize);
  194. pX->nSendListCount = 0;
  195. pX->acSendNames = NULL;
  196. // Make sure to set the Transfer direction to none. REV: 02/14/2001
  197. pX->nDirection = XFER_NONE;
  198. }
  199. return 0;
  200. }
  201. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  202. * FUNCTION:
  203. * LoadXferHdl
  204. *
  205. * DESCRIPTION:
  206. * This function loads data from the session file into the Xfer handle.
  207. *
  208. * PARAMETERS:
  209. * hSession -- the session handle
  210. *
  211. * RETURNS:
  212. * ZERO if everything is OK, otherwise an error code.
  213. *
  214. */
  215. INT LoadXferHdl(HXFER hXfer)
  216. {
  217. long lSize;
  218. XD_TYPE *pX;
  219. SZ_TYPE *pZ;
  220. pX = (XD_TYPE *)hXfer;
  221. if (pX)
  222. {
  223. InitializeXferHdl(pX->hSession, hXfer);
  224. /*
  225. * Try and load up the general parameters first
  226. */
  227. pZ = (SZ_TYPE *)0;
  228. #if FALSE
  229. /* removed as per MRW request */
  230. sfdGetDataBlock(pX->hSession,
  231. SFID_XFER_PARAMS,
  232. (void **)&pZ);
  233. #endif
  234. pZ = NULL;
  235. lSize = 0;
  236. sfGetSessionItem(sessQuerySysFileHdl(pX->hSession),
  237. SFID_XFER_PARAMS,
  238. &lSize,
  239. NULL);
  240. if (lSize > 0)
  241. {
  242. size_t lXfrParamsStructSize = sizeof(XFR_PARAMS);
  243. assert((size_t)lSize == lXfrParamsStructSize);
  244. if ((size_t)lSize < lXfrParamsStructSize)
  245. {
  246. pZ = malloc(lXfrParamsStructSize);
  247. if (pZ)
  248. {
  249. memset(pZ, 0, lXfrParamsStructSize);
  250. }
  251. }
  252. else
  253. {
  254. pZ = malloc(lSize);
  255. }
  256. if (pZ)
  257. {
  258. sfGetSessionItem(sessQuerySysFileHdl(pX->hSession),
  259. SFID_XFER_PARAMS,
  260. &lSize,
  261. pZ);
  262. }
  263. }
  264. if (pZ)
  265. {
  266. if (pX->xfer_params)
  267. {
  268. free(pX->xfer_params);
  269. pX->xfer_params = NULL;
  270. }
  271. pX->xfer_params = pZ;
  272. if (pX->xfer_old_params)
  273. {
  274. free(pX->xfer_old_params);
  275. pX->xfer_old_params = NULL;
  276. }
  277. pX->xfer_old_params = malloc(lSize);
  278. MemCopy(pX->xfer_old_params, pX->xfer_params, lSize);
  279. }
  280. /*
  281. * Try and get the Bps/Cps flag
  282. */
  283. lSize = sizeof(pX->nBps);
  284. sfGetSessionItem(sessQuerySysFileHdl(pX->hSession),
  285. SFID_XFR_USE_BPS,
  286. &lSize,
  287. &pX->nBps);
  288. pX->nOldBps = pX->nBps;
  289. }
  290. return 0;
  291. }
  292. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  293. * FUNCTION:
  294. * SaveXferHdl
  295. *
  296. * DESCRIPTION:
  297. * This function is called to save all the settings in the Xfer handle out
  298. * to the session file.
  299. *
  300. * PARAMETERS:
  301. * hSession -- the session handle
  302. *
  303. * RETURNS:
  304. * ZERO if everything is OK, otherwise an error code.
  305. *
  306. */
  307. INT SaveXferHdl(HXFER hXfer)
  308. {
  309. int nSize = 0;
  310. XD_TYPE *pX;
  311. SZ_TYPE *pZ;
  312. pX = (XD_TYPE *)hXfer;
  313. if (pX)
  314. {
  315. /*
  316. * Save the generic transfer stuff
  317. */
  318. pZ = pX->xfer_params;
  319. if (pZ)
  320. {
  321. nSize = pZ->nSize;
  322. }
  323. #if FALSE
  324. /* removed as per MRW request */
  325. sfdPutDataBlock(pX->hSession,
  326. SFID_XFER_PARAMS,
  327. pX->xfer_params);
  328. #endif
  329. if (memcmp(pX->xfer_old_params, pX->xfer_params, nSize) != 0)
  330. {
  331. sfPutSessionItem(sessQuerySysFileHdl(pX->hSession),
  332. SFID_XFER_PARAMS,
  333. nSize,
  334. pZ);
  335. }
  336. /*
  337. * Save the Bps/Cps flag
  338. */
  339. if (pX->nBps != pX->nOldBps)
  340. {
  341. sfPutSessionItem(sessQuerySysFileHdl(pX->hSession),
  342. SFID_XFR_USE_BPS,
  343. sizeof(pX->nBps),
  344. &pX->nBps);
  345. pX->nOldBps = pX->nBps;
  346. }
  347. }
  348. return 0;
  349. }
  350. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  351. * FUNCTION:
  352. *
  353. * DESCRIPTION:
  354. *
  355. * PARAMETERS:
  356. *
  357. * RETURNS:
  358. *
  359. */
  360. INT DestroyXferHdl(HXFER hXfer)
  361. {
  362. int nIndex;
  363. XD_TYPE *pX = (XD_TYPE *)hXfer;
  364. if (pX)
  365. {
  366. if (pX->xfer_params)
  367. {
  368. free(pX->xfer_params);
  369. pX->xfer_params = NULL;
  370. }
  371. if (pX->xfer_old_params)
  372. {
  373. free(pX->xfer_old_params);
  374. pX->xfer_old_params = NULL;
  375. }
  376. if (pX->xfer_proto_params)
  377. {
  378. /*
  379. * Loop through the protocol specific stuff
  380. */
  381. for (nIndex = SFID_PROTO_PARAMS_END - SFID_PROTO_PARAMS; nIndex >= 0; nIndex--)
  382. {
  383. if (pX->xfer_proto_params[nIndex])
  384. {
  385. free(pX->xfer_proto_params[nIndex]);
  386. pX->xfer_proto_params[nIndex] = NULL;
  387. }
  388. }
  389. }
  390. /*
  391. * Free up stuff as necessary
  392. */
  393. if (pX->acSendNames)
  394. {
  395. for (nIndex = pX->nSendListCount - 1; nIndex >= 0; nIndex--)
  396. {
  397. if (pX->acSendNames[nIndex])
  398. {
  399. free(pX->acSendNames[nIndex]);
  400. pX->acSendNames[nIndex] = NULL;
  401. }
  402. pX->nSendListCount = nIndex;
  403. }
  404. free(pX->acSendNames);
  405. pX->acSendNames = NULL;
  406. pX->nSendListCount = 0;
  407. }
  408. if (pX->pXferStuff)
  409. {
  410. free(pX->pXferStuff);
  411. pX->pXferStuff = NULL;
  412. }
  413. free(pX);
  414. pX = NULL;
  415. }
  416. return 0;
  417. }
  418. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  419. * FUNCTION:
  420. * xfrSetDataPointer
  421. *
  422. * DESCRIPTION:
  423. * This function is called from the transfer routines in the transfer dll
  424. * to save the pointer to the parameter block that was passed to them.
  425. *
  426. * PARAMETERS:
  427. * hSession -- the session handle
  428. * pData -- the pointer to be saved
  429. *
  430. * RETURNS:
  431. * Nothing.
  432. *
  433. */
  434. VOID WINAPI xfrSetDataPointer(HXFER hXfer, VOID *pData)
  435. {
  436. XD_TYPE *pH;
  437. // pH = (XD_TYPE *)sessQueryXferHdl(hSession);
  438. pH = (XD_TYPE *)hXfer;
  439. assert(pH);
  440. if (pH)
  441. {
  442. pH->pXferStuff = pData;
  443. }
  444. }
  445. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  446. * FUNCTION:
  447. * xfrQueryDataPointer
  448. *
  449. * DESCRIPTION:
  450. * This function is called from the transfer routines in the transfer dll to
  451. * recover the saved data pointer to the parameter block that was passed to
  452. * them.
  453. *
  454. * PARAMETERS:
  455. * hSession -- the session handle
  456. * ppData -- pointer to where to put the pointer
  457. *
  458. * RETURNS:
  459. * Nothing.
  460. *
  461. */
  462. VOID WINAPI xfrQueryDataPointer(HXFER hXfer, VOID **ppData)
  463. {
  464. XD_TYPE *pH;
  465. // pH = (XD_TYPE *)sessQueryXferHdl(hSession);
  466. pH = (XD_TYPE *)hXfer;
  467. assert(pH);
  468. if (pH)
  469. {
  470. *ppData = pH->pXferStuff;
  471. }
  472. }
  473. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  474. * FUNCTION:
  475. * xfrQueryParameters
  476. *
  477. * DESCRIPTION:
  478. * This function returns a pointer to the default transfer parameters. It
  479. * gets the pointer to the block from the session handle and passed the
  480. * the pointer to the caller.
  481. *
  482. * PARAMETERS:
  483. * hSession -- the session handle
  484. * ppData -- pointer to where the pointer should be saved
  485. *
  486. * RETURNS:
  487. * ZERO if everything is OK, otherwise an error code
  488. *
  489. */
  490. INT WINAPI xfrQueryParameters(HXFER hXfer, VOID **ppData)
  491. {
  492. INT nRet = 0;
  493. XD_TYPE *pH = (XD_TYPE *)hXfer;
  494. XFR_PARAMS *pX = NULL;
  495. if (ppData == NULL)
  496. {
  497. assert(FALSE);
  498. nRet = XFR_BAD_PARAMETER;
  499. }
  500. else if (pH && pH->xfer_params)
  501. {
  502. pX = (XFR_PARAMS *)pH->xfer_params;
  503. }
  504. else
  505. {
  506. /* Build a default one */
  507. pX = (XFR_PARAMS *)malloc(sizeof(XFR_PARAMS));
  508. assert(pX);
  509. if (pX == (XFR_PARAMS *)0)
  510. {
  511. assert(FALSE);
  512. nRet = XFR_NO_MEMORY;
  513. }
  514. else
  515. {
  516. pX->nSize = sizeof(XFR_PARAMS);
  517. /* Initialize the defaults */
  518. #if defined(INCL_ZMODEM_CRASH_RECOVERY)
  519. pX->nRecProtocol = XF_ZMODEM_CR;
  520. pX->fSavePartial = TRUE;
  521. #else // defined(INCL_ZMODEM_CRASH_RECOVERY)
  522. pX->nRecProtocol = XF_ZMODEM;
  523. pX->fSavePartial = FALSE;
  524. #endif // defined(INCL_ZMODEM_CRASH_RECOVERY)
  525. pX->fUseFilenames = TRUE;
  526. pX->fUseDateTime = TRUE;
  527. pX->fUseDirectory = FALSE;
  528. pX->nRecOverwrite = XFR_RO_REN_SEQ;
  529. pX->nSndProtocol = XF_ZMODEM_CR;
  530. pX->fChkSubdirs = FALSE;
  531. pX->fIncPaths = FALSE;
  532. }
  533. }
  534. if (nRet == 0)
  535. {
  536. if (hXfer != NULL && pX != NULL)
  537. {
  538. xfrSetParameters(hXfer, (VOID *)pX);
  539. }
  540. if (*ppData != pX)
  541. {
  542. if (*ppData)
  543. {
  544. free(*ppData);
  545. *ppData = NULL;
  546. }
  547. *ppData = (VOID *)pX;
  548. }
  549. }
  550. return nRet;
  551. }
  552. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  553. * FUNCTION:
  554. * xfrSetParameters
  555. *
  556. * DESCRIPTION:
  557. * This function is called to change the default transfer parameters. If
  558. * the parameter block returned is different from the default block, the
  559. * settings are copied. If the block is the same, then they don't need to
  560. * be. Please note that the previous function is exported and can be called
  561. * to get the parameters, but this function is not exported and cannot be
  562. * accessed externally.
  563. *
  564. * PARAMETERS:
  565. * hSession -- the session handle
  566. * pData -- pointer to the new parameter block
  567. *
  568. * RETURNS:
  569. * Nothing.
  570. *
  571. */
  572. void xfrSetParameters(HXFER hXfer, VOID *pData)
  573. {
  574. XD_TYPE *pX;
  575. // pX = (XD_TYPE *)sessQueryXferHdl(hSession);
  576. pX = (XD_TYPE *)hXfer;
  577. if (pX)
  578. {
  579. /* TODO: check that we really need to change it */
  580. if (pX->xfer_params)
  581. {
  582. if (pX->xfer_params != (SZ_TYPE *)pData)
  583. {
  584. free(pX->xfer_params);
  585. pX->xfer_params = NULL;
  586. }
  587. }
  588. pX->xfer_params = (SZ_TYPE *)pData;
  589. }
  590. return;
  591. }
  592. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  593. * FUNCTION:
  594. *
  595. * DESCRIPTION:
  596. *
  597. * PARAMETERS:
  598. *
  599. * RETURNS:
  600. *
  601. */
  602. int WINAPI xfrQueryProtoParams(HXFER hXfer, int nId, VOID **ppData)
  603. {
  604. int nRet = 0;
  605. int nLimit = SFID_PROTO_PARAMS_END - SFID_PROTO_PARAMS;
  606. XD_TYPE *pX = NULL;
  607. if ((nId < 0) || (nId > nLimit))
  608. {
  609. nRet = XFR_BAD_PARAMETER;
  610. }
  611. else
  612. {
  613. // pX = (XD_TYPE *)sessQueryXferHdl(hSession);
  614. pX = (XD_TYPE *)hXfer;
  615. assert(pX);
  616. if (pX)
  617. {
  618. *ppData = (VOID *)pX->xfer_proto_params[nId];
  619. }
  620. }
  621. return nRet;
  622. }
  623. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  624. * FUNCTION:
  625. *
  626. * DESCRIPTION:
  627. *
  628. * PARAMETERS:
  629. *
  630. * RETURNS:
  631. *
  632. */
  633. void WINAPI xfrSetProtoParams(HXFER hXfer, int nId, VOID *pData)
  634. {
  635. }
  636. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  637. * FUNCTION:
  638. * xfrSendAddToList
  639. *
  640. * DESCRIPTION:
  641. * This function is called to add a file to the list of files that are being
  642. * ququed up to send to whatever system we are connected to.
  643. *
  644. * PARAMETERS:
  645. * hSession -- the session handle
  646. * pszFile -- the file name, see note below
  647. *
  648. * NOTE:
  649. * If the second parameter, "pszFile" is NULL, this function acts as a
  650. * empty or clear list function.
  651. *
  652. * RETURNS:
  653. * ZERO if everything is OK, otherwise an error code.
  654. *
  655. */
  656. int xfrSendAddToList(HXFER hXfer, LPCTSTR pszFile)
  657. {
  658. int nRet = 0;
  659. XD_TYPE *pX;
  660. LPTSTR pszName;
  661. // pX = (XD_TYPE *)sessQueryXferHdl(hSession);
  662. pX = (XD_TYPE *)hXfer;
  663. assert(pX);
  664. if (pX)
  665. {
  666. if (pszFile == NULL)
  667. {
  668. int nIdx;
  669. assert(FALSE);
  670. /* Clear list */
  671. for (nIdx = pX->nSendListCount - 1; nIdx >=0; nIdx--)
  672. {
  673. if (pX->acSendNames[nIdx])
  674. {
  675. free(pX->acSendNames[nIdx]);
  676. pX->acSendNames[nIdx] = NULL;
  677. }
  678. pX->nSendListCount = nIdx;
  679. }
  680. free(pX->acSendNames);
  681. pX->acSendNames = NULL;
  682. pX->nSendListCount = 0;
  683. }
  684. else
  685. {
  686. /* Do we have enough space on the list ? */
  687. if (pX->nSendListCount == 0)
  688. {
  689. /* Allocate the initial chunk */
  690. if (pX->acSendNames)
  691. {
  692. int nIdx;
  693. assert(FALSE);
  694. //
  695. // Make sure to clear out all the names in the list.
  696. //
  697. for (nIdx = pX->nSendListCount; nIdx >= 0; nIdx--)
  698. {
  699. if (pX->acSendNames[nIdx])
  700. {
  701. free(pX->acSendNames[nIdx]);
  702. pX->acSendNames[nIdx] = NULL;
  703. }
  704. }
  705. free(pX->acSendNames);
  706. pX->acSendNames = NULL;
  707. }
  708. pX->acSendNames = malloc(sizeof(TCHAR *) * LIST_CHUNK);
  709. if (pX->acSendNames == NULL)
  710. {
  711. nRet = XFR_NO_MEMORY;
  712. goto SATLexit;
  713. }
  714. }
  715. else if (((pX->nSendListCount + 1) % LIST_CHUNK) == 0)
  716. {
  717. /* Need a bigger chunk */
  718. TCHAR **pTempacSendNames = NULL;
  719. pTempacSendNames =
  720. (TCHAR**)realloc(pX->acSendNames,
  721. (unsigned int)sizeof(TCHAR *) * (unsigned int)((pX->nSendListCount + 1 + LIST_CHUNK)));
  722. if (pTempacSendNames == NULL)
  723. {
  724. nRet = XFR_NO_MEMORY;
  725. goto SATLexit;
  726. }
  727. else
  728. {
  729. pX->acSendNames = pTempacSendNames;
  730. }
  731. }
  732. pX->acSendNames[pX->nSendListCount] = NULL;
  733. pX->nSendListCount++;
  734. /* Add item to list */
  735. pszName = malloc(StrCharGetByteCount(pszFile) + 1);
  736. if (pszName == NULL)
  737. {
  738. nRet = XFR_NO_MEMORY;
  739. goto SATLexit;
  740. }
  741. StrCharCopy(pszName, pszFile);
  742. pX->acSendNames[pX->nSendListCount - 1] = pszName;
  743. }
  744. }
  745. SATLexit:
  746. return nRet;
  747. }
  748. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  749. * FUNCTION:
  750. * xfrSendListSend
  751. *
  752. * DESCRIPTION:
  753. * This function is called to send the files that were previously placed on
  754. * the send list. The list is cleared after the operation.
  755. *
  756. * PARAMETERS:
  757. * hSession -- the session handle
  758. *
  759. * RETURNS:
  760. * ZERO if everything is OK, otherwise an error code.
  761. *
  762. */
  763. int xfrSendListSend(HXFER hXfer)
  764. {
  765. HSESSION hSession;
  766. int nRet = 0;
  767. int nIdx;
  768. long lSize;
  769. long lTmp;
  770. LPTSTR pszName;
  771. XD_TYPE *pX;
  772. XFR_SEND *pSend;
  773. HCLOOP hCL;
  774. HWND toolbar;
  775. // pX = (XD_TYPE *)sessQueryXferHdl(hSession);
  776. pX = (XD_TYPE *)hXfer;
  777. assert(pX);
  778. if (pX != NULL)
  779. {
  780. hSession = pX->hSession;
  781. assert(hSession);
  782. if (hSession == NULL)
  783. {
  784. return XFR_BAD_PARAMETER;
  785. }
  786. //
  787. // Return an error if a file transfer is currently
  788. // in progress. REV: 08/06/2001.
  789. //
  790. if (pX->nDirection != XFER_NONE)
  791. {
  792. nRet = XFR_IN_PROGRESS;
  793. return nRet;
  794. }
  795. //
  796. // Return an error if not currently connected due to a
  797. // loss of carrier. REV: 9/7/2001
  798. //
  799. if (pX->nCarrierLost == TRUE)
  800. {
  801. nRet = XFR_NO_CARRIER;
  802. return nRet;
  803. }
  804. pSend = malloc(sizeof(XFR_SEND));
  805. assert(pSend);
  806. if (pSend == NULL)
  807. {
  808. nRet = XFR_NO_MEMORY;
  809. goto SLSexit;
  810. }
  811. memset(pSend, 0, sizeof(XFR_SEND));
  812. /*
  813. * Fill in the single stuff
  814. */
  815. pSend->pParams = (XFR_PARAMS *)pX->xfer_params;
  816. pSend->nProtocol = pSend->pParams->nSndProtocol;
  817. pSend->pProParams = (VOID *)pX->xfer_proto_params[pSend->nProtocol];
  818. pSend->nCount = pX->nSendListCount;
  819. pSend->nIndex = 0;
  820. /* TODO: initialize stuff like the templates and status/event bases */
  821. /*
  822. * Do the file specific stuff
  823. */
  824. pSend->pList = malloc(sizeof(XFR_LIST) * pSend->nCount);
  825. assert(pSend->pList);
  826. if (pSend->pList == NULL)
  827. {
  828. nRet = XFR_NO_MEMORY;
  829. goto SLSexit;
  830. }
  831. for (lSize = 0, nIdx = 0; nIdx < pSend->nCount; nIdx += 1)
  832. {
  833. pszName = pX->acSendNames[nIdx];
  834. lTmp = 0;
  835. GetFileSizeFromName(pszName, &lTmp);
  836. pSend->pList[nIdx].lSize = lTmp;
  837. lSize += lTmp;
  838. pSend->pList[nIdx].pszName = pszName;
  839. }
  840. /* These no longer belong to this side */
  841. //
  842. // The filename buffers have been moved to the list,
  843. // so the SendNames structure is no longer pointing to
  844. // memory that is to be freed by pX. REV: 4/16/2002
  845. //
  846. for (nIdx = pX->nSendListCount - 1; nIdx >=0; nIdx--)
  847. {
  848. if (pX->acSendNames[nIdx])
  849. {
  850. pX->acSendNames[nIdx] = NULL;
  851. }
  852. pX->nSendListCount--;
  853. }
  854. free(pX->acSendNames);
  855. pX->acSendNames = NULL;
  856. pX->nSendListCount = 0;
  857. pX->nDirection = XFER_SEND;
  858. pSend->lSize = lSize;
  859. xfrInitDspStruct(hXfer);
  860. switch (pSend->nProtocol)
  861. {
  862. #if FALSE
  863. case XF_HYPERP:
  864. pX->nLgSingleTemplate = IDD_XFERHPRSNDSTANDARDSINGLE;
  865. pX->nLgMultiTemplate = IDD_XFERHPRSNDSTANDARDDOUBLE;
  866. pX->nStatusBase = IDS_TM_SS_ZERO;
  867. pX->nEventBase = IDS_TM_SE_ZERO;
  868. break;
  869. #endif
  870. case XF_KERMIT:
  871. pX->nLgSingleTemplate = IDD_XFERKRMSNDSTANDARDSINGLE;
  872. pX->nLgMultiTemplate = IDD_XFERKRMSNDSTANDARDDOUBLE;
  873. pX->nStatusBase = pX->nEventBase = IDS_TM_K_ZERO;
  874. break;
  875. case XF_CSB:
  876. default:
  877. assert(FALSE);
  878. case XF_ZMODEM:
  879. case XF_ZMODEM_CR:
  880. pX->nLgSingleTemplate = IDD_XFERZMDMSNDSTANDARDSINGLE;
  881. pX->nLgMultiTemplate = IDD_XFERZMDMSNDSTANDARDDOUBLE;
  882. pX->nStatusBase = IDS_TM_SZ_ZERO;
  883. pX->nEventBase = IDS_TM_SZ_ZERO;
  884. break;
  885. case XF_XMODEM:
  886. case XF_XMODEM_1K:
  887. pX->nLgSingleTemplate = IDD_XFERXMDMSNDSTANDARDDISPLAY;
  888. pX->nLgMultiTemplate = pX->nLgSingleTemplate;
  889. pX->nStatusBase = pX->nEventBase = IDS_TM_RX_ZERO;
  890. break;
  891. case XF_YMODEM:
  892. case XF_YMODEM_G:
  893. pX->nLgSingleTemplate = IDD_XFERYMDMSNDSTANDARDSINGLE;
  894. pX->nLgMultiTemplate = IDD_XFERYMDMSNDSTANDARDDOUBLE;
  895. pX->nStatusBase = pX->nEventBase = IDS_TM_RX_ZERO;
  896. break;
  897. }
  898. toolbar = sessQueryHwndToolbar( hSession );
  899. ToolbarEnableButton( toolbar, IDM_ACTIONS_SEND, FALSE );
  900. ToolbarEnableButton( toolbar, IDM_ACTIONS_RCV, FALSE );
  901. pX->pXferStuff = (VOID *)pSend;
  902. pX->nExpanded = FALSE;
  903. pX->hwndXfrDisplay = DoModelessDialog(glblQueryDllHinst(),
  904. MAKEINTRESOURCE(pX->nLgSingleTemplate),
  905. sessQueryHwnd(hSession),
  906. XfrDisplayDlg,
  907. (LPARAM)hSession);
  908. /*
  909. * Now get it going
  910. */
  911. hCL = sessQueryCLoopHdl(hSession);
  912. if (hCL)
  913. {
  914. // DbgOutStr("Tell CLoop TRANSFER_READY\r\n", 0,0,0,0,0);
  915. CLoopControl(hCL, CLOOP_SET, CLOOP_TRANSFER_READY);
  916. }
  917. }
  918. SLSexit:
  919. if (nRet != 0)
  920. {
  921. /* Clean up before we leave */
  922. if (pSend != NULL)
  923. {
  924. for (nIdx = pSend->nCount - 1; nIdx >= 0; nIdx--)
  925. {
  926. if (pSend->pList[nIdx].pszName)
  927. {
  928. free(pSend->pList[nIdx].pszName);
  929. pSend->pList[nIdx].pszName = NULL;
  930. }
  931. }
  932. free(pSend->pList);
  933. pSend->pList = NULL;
  934. free(pSend);
  935. pSend = NULL;
  936. }
  937. }
  938. return nRet;
  939. }
  940. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  941. * FUNCTION:
  942. * xfrRecvStart
  943. *
  944. * DESCRIPTION:
  945. * This function is called when we think we have everything that we need
  946. * in order to start a Transfer Receive operation.
  947. *
  948. * PARAMETERS:
  949. * hSession -- the session handle
  950. * pszDir -- a string with a directory in it
  951. * pszName -- a string with a file name in it (maybe)
  952. *
  953. * RETURNS:
  954. * ZERO if everything is OK, otherwise an error code.
  955. *
  956. */
  957. int xfrRecvStart(HXFER hXfer, LPCTSTR pszDir, LPCTSTR pszName)
  958. {
  959. HSESSION hSession;
  960. int nRet = 0;
  961. XD_TYPE *pX;
  962. XFR_RECEIVE *pRec;
  963. HCLOOP hCL;
  964. HWND toolbar;
  965. // pX = (XD_TYPE *)sessQueryXferHdl(hSession);
  966. pX = (XD_TYPE *)hXfer;
  967. assert(pX);
  968. if (pX)
  969. {
  970. hSession = pX->hSession;
  971. assert(hSession);
  972. if (hSession == NULL)
  973. {
  974. return XFR_BAD_PARAMETER;
  975. }
  976. //
  977. // Return an error if a file transfer is currently
  978. // in progress. REV: 08/06/2001.
  979. //
  980. if (pX->nDirection != XFER_NONE)
  981. {
  982. nRet = XFR_IN_PROGRESS;
  983. return nRet;
  984. }
  985. //
  986. // Return an error if not currently connected due to a
  987. // loss of carrier. REV: 9/7/2001
  988. //
  989. if (pX->nCarrierLost == TRUE)
  990. {
  991. nRet = XFR_NO_CARRIER;
  992. return nRet;
  993. }
  994. pRec = (XFR_RECEIVE *)malloc(sizeof(XFR_RECEIVE));
  995. assert(pRec);
  996. if (pRec == (XFR_RECEIVE *)0)
  997. {
  998. nRet = XFR_NO_MEMORY;
  999. goto RSexit;
  1000. }
  1001. memset(pRec, 0, sizeof(XFR_RECEIVE));
  1002. pRec->pParams = (XFR_PARAMS *)pX->xfer_params;
  1003. pRec->nProtocol = pRec->pParams->nRecProtocol;
  1004. pRec->pProParams = (VOID *)pX->xfer_proto_params[pRec->nProtocol];
  1005. pRec->pszDir = malloc(StrCharGetByteCount(pszDir) + 1);
  1006. if (pRec->pszDir == (LPTSTR)0)
  1007. {
  1008. nRet = XFR_NO_MEMORY;
  1009. goto RSexit;
  1010. }
  1011. StrCharCopy(pRec->pszDir, pszDir);
  1012. pRec->pszName = malloc(StrCharGetByteCount(pszName) + 1);
  1013. if (pRec->pszName == (LPTSTR)0)
  1014. {
  1015. nRet = XFR_NO_MEMORY;
  1016. goto RSexit;
  1017. }
  1018. StrCharCopy(pRec->pszName, pszName);
  1019. xfrInitDspStruct(hXfer);
  1020. switch (pRec->nProtocol)
  1021. {
  1022. #if FALSE
  1023. case XF_HYPERP:
  1024. pX->nLgSingleTemplate = IDD_XFERHPRRECSTANDARDSINGLE;
  1025. pX->nLgMultiTemplate = IDD_XFERHPRRECSTANDARDDOUBLE;
  1026. pX->nStatusBase = IDS_TM_RS_ZERO;
  1027. pX->nEventBase = IDS_TM_RE_ZERO;
  1028. break;
  1029. #endif
  1030. case XF_KERMIT:
  1031. pX->nLgSingleTemplate = IDD_XFERKRMRECSTANDARDDISPLAY;
  1032. pX->nLgMultiTemplate = pX->nLgSingleTemplate;
  1033. pX->nStatusBase = pX->nEventBase = IDS_TM_K_ZERO;
  1034. break;
  1035. case XF_CSB:
  1036. default:
  1037. assert(FALSE);
  1038. case XF_ZMODEM:
  1039. case XF_ZMODEM_CR:
  1040. pX->nLgSingleTemplate = IDD_XFERZMDMRECSTANDARDSINGLE;
  1041. pX->nLgMultiTemplate = IDD_XFERZMDMRECSTANDARDDOUBLE;
  1042. pX->nStatusBase = IDS_TM_SZ_ZERO;
  1043. pX->nEventBase = IDS_TM_SZ_ZERO;
  1044. break;
  1045. case XF_XMODEM:
  1046. case XF_XMODEM_1K:
  1047. pX->nLgSingleTemplate = IDD_XFERXMDMRECSTANDARDDISPLAY;
  1048. pX->nLgMultiTemplate = pX->nLgSingleTemplate;
  1049. pX->nStatusBase = pX->nEventBase = IDS_TM_RX_ZERO;
  1050. break;
  1051. case XF_YMODEM:
  1052. case XF_YMODEM_G:
  1053. pX->nLgSingleTemplate = IDD_XFERYMDMRECSTANDARDDISPLAY;
  1054. pX->nLgMultiTemplate = pX->nLgSingleTemplate;
  1055. pX->nStatusBase = pX->nEventBase = IDS_TM_RX_ZERO;
  1056. break;
  1057. }
  1058. toolbar = sessQueryHwndToolbar( hSession );
  1059. ToolbarEnableButton( toolbar, IDM_ACTIONS_SEND, FALSE );
  1060. ToolbarEnableButton( toolbar, IDM_ACTIONS_RCV, FALSE );
  1061. pX->nDirection = XFER_RECV;
  1062. pX->pXferStuff = (VOID *)pRec;
  1063. pX->nExpanded = FALSE;
  1064. pX->hwndXfrDisplay = DoModelessDialog(glblQueryDllHinst(),
  1065. MAKEINTRESOURCE(pX->nLgSingleTemplate),
  1066. sessQueryHwnd(hSession),
  1067. XfrDisplayDlg,
  1068. (LPARAM)hSession);
  1069. hCL = sessQueryCLoopHdl(hSession);
  1070. if (hCL)
  1071. {
  1072. CLoopControl(hCL, CLOOP_SET, CLOOP_TRANSFER_READY);
  1073. }
  1074. }
  1075. RSexit:
  1076. if (nRet != 0)
  1077. {
  1078. /*
  1079. * If we failed, clean up the mess.
  1080. */
  1081. if (pRec != (XFR_RECEIVE *)0)
  1082. {
  1083. if (pRec->pszDir != (LPTSTR)0)
  1084. {
  1085. free(pRec->pszDir);
  1086. pRec->pszDir = NULL;
  1087. }
  1088. if (pRec->pszName != (LPTSTR)0)
  1089. {
  1090. free(pRec->pszName);
  1091. pRec->pszName = NULL;
  1092. }
  1093. free(pRec);
  1094. pRec = NULL;
  1095. }
  1096. }
  1097. return nRet;
  1098. }
  1099. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  1100. * FUNCTION:
  1101. * xfrGetEventBase
  1102. *
  1103. * DESCRIPTION:
  1104. * This function is called by the transfer display. It is used to get the
  1105. * starting number (of the the resource strings) of a list of events that
  1106. * can be displayed for some of the transfer protocols.
  1107. *
  1108. * PARAMETERS:
  1109. * hSession -- the session handle
  1110. *
  1111. * RETURNS:
  1112. * A resource ID that should be passed on to LoadString.
  1113. *
  1114. */
  1115. int xfrGetEventBase(HXFER hXfer)
  1116. {
  1117. XD_TYPE *pX;
  1118. // pX = (XD_TYPE *)sessQueryXferHdl(hSession);
  1119. pX = (XD_TYPE *)hXfer;
  1120. assert(pX);
  1121. if (pX)
  1122. {
  1123. return pX->nEventBase;
  1124. }
  1125. return 0;
  1126. }
  1127. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  1128. * FUNCTION:
  1129. * xfrGetStatusBase
  1130. *
  1131. * DESCRIPTION:
  1132. * This function is called bye the transfer display. It is used to get the
  1133. * starting number (of the resource strings) of a list of status messages that
  1134. * can be displayed for some of the transfer protocols.
  1135. *
  1136. * PARAMETERS:
  1137. * hSession -- the session handle
  1138. *
  1139. * RETURNS:
  1140. * A resource ID that should be passed on to LoadString.
  1141. *
  1142. */
  1143. int xfrGetStatusBase(HXFER hXfer)
  1144. {
  1145. XD_TYPE *pX;
  1146. // pX = (XD_TYPE *)sessQueryXferHdl(hSession);
  1147. pX = (XD_TYPE *)hXfer;
  1148. assert(pX);
  1149. if (pX)
  1150. {
  1151. return pX->nStatusBase;
  1152. }
  1153. return 0;
  1154. }
  1155. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  1156. * FUNCTION:
  1157. * xfrGetXferDspBps
  1158. *
  1159. * DESCRIPTION:
  1160. * This function is called to get the current value of the BPS/CPS flag.
  1161. *
  1162. * PARAMETERS:
  1163. * hSession -- the session handle
  1164. *
  1165. * RETURNS:
  1166. * The current value of the BPS flag.
  1167. *
  1168. */
  1169. int xfrGetXferDspBps(HXFER hXfer)
  1170. {
  1171. XD_TYPE *pX;
  1172. // pX = (XD_TYPE *)sessQueryXferHdl(hSession);
  1173. pX = (XD_TYPE *)hXfer;
  1174. assert(pX);
  1175. if (pX)
  1176. {
  1177. return pX->nBps;
  1178. }
  1179. return 0;
  1180. }
  1181. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  1182. * FUNCTION:
  1183. * xfrSetXferDspBps
  1184. *
  1185. * DESCRIPTION:
  1186. * This function is called to set the BPS/CPS flag in the tranfer handle.
  1187. *
  1188. * PARAMETERS:
  1189. * hSession -- the session handle
  1190. * nBps -- the new BPS flag
  1191. *
  1192. * RETURNS:
  1193. * The old value of the BPS flag.
  1194. *
  1195. */
  1196. int xfrSetXferDspBps(HXFER hXfer, int nBps)
  1197. {
  1198. return 0;
  1199. }
  1200. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  1201. * FUNCTION:
  1202. * xfrInitDspStruct
  1203. *
  1204. * DESCRIPTION:
  1205. * This function is called before a transfer is started to make sure that
  1206. * the display variables in the transfer structure are all set to a known
  1207. * initial value.
  1208. *
  1209. * PARAMETERS:
  1210. * hSession -- the session handle
  1211. *
  1212. * RETURNS:
  1213. * Nothing.
  1214. */
  1215. static void xfrInitDspStruct(HXFER hXfer)
  1216. {
  1217. XD_TYPE *pX;
  1218. // pX = (XD_TYPE *)sessQueryXferHdl(hSession);
  1219. pX = (XD_TYPE *)hXfer;
  1220. assert(pX);
  1221. if (pX)
  1222. {
  1223. pX->nClose = 0;
  1224. pX->nCloseStatus = 0;
  1225. pX->bChecktype = 0;
  1226. pX->bErrorCnt = 0;
  1227. pX->bPcktErrCnt = 0;
  1228. pX->bLastErrtype = 0;
  1229. pX->bTotalSoFar = 0;
  1230. pX->bFileSize = 0;
  1231. pX->bFileSoFar = 0;
  1232. pX->bPacketNumber = 0;
  1233. pX->bTotalCnt = 0;
  1234. pX->bTotalSize = 0;
  1235. pX->bFileCnt = 0;
  1236. pX->bEvent = 0;
  1237. pX->bStatus = 0;
  1238. pX->bElapsedTime = 0;
  1239. pX->bRemainingTime = 0;
  1240. pX->bThroughput = 0;
  1241. pX->bProtocol = 0;
  1242. pX->bMessage = 0;
  1243. pX->bOurName = 0;
  1244. pX->bTheirName = 0;
  1245. pX->wChecktype = 0;
  1246. pX->wErrorCnt = 0;
  1247. pX->wPcktErrCnt = 0;
  1248. pX->wLastErrtype = 0;
  1249. pX->lTotalSize = 0L;
  1250. pX->lTotalSoFar = 0L;
  1251. pX->lFileSize = 0L;
  1252. pX->lFileSoFar = 0L;
  1253. pX->lPacketNumber = 0L;
  1254. pX->wTotalCnt = 0;
  1255. pX->wFileCnt = 0;
  1256. pX->wEvent = 0;
  1257. pX->wStatus = 0;
  1258. pX->lElapsedTime = 0L;
  1259. pX->lRemainingTime = 0L;
  1260. pX->lThroughput = 0L;
  1261. pX->uProtocol = 0;
  1262. TCHAR_Fill(pX->acMessage, TEXT('\0'),
  1263. sizeof(pX->acMessage) / sizeof(TCHAR));
  1264. TCHAR_Fill(pX->acOurName, TEXT('\0'),
  1265. sizeof(pX->acOurName) / sizeof(TCHAR));
  1266. TCHAR_Fill(pX->acTheirName, TEXT('\0'),
  1267. sizeof(pX->acTheirName) / sizeof(TCHAR));
  1268. }
  1269. }
  1270. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  1271. * FUNCTION:
  1272. * xfrCleanUpReceive
  1273. *
  1274. * DESCRIPTION:
  1275. * This function is called from xfrDoTransfer after a transfer in order to
  1276. * clean up the stuff that was allocated in order to do the transfer.
  1277. *
  1278. * PARAMETERS:
  1279. *
  1280. * RETURNS:
  1281. * Nothing.
  1282. */
  1283. void xfrCleanUpReceive(HSESSION hSession)
  1284. {
  1285. XD_TYPE *pX;
  1286. XFR_RECEIVE *pR;
  1287. HWND toolbar;
  1288. pX = (XD_TYPE *)sessQueryXferHdl(hSession);
  1289. assert(pX);
  1290. if (pX)
  1291. {
  1292. pR = (XFR_RECEIVE *)pX->pXferStuff;
  1293. assert(pR);
  1294. if (pR)
  1295. {
  1296. if (pR->pszDir != NULL)
  1297. {
  1298. free(pR->pszDir);
  1299. pR->pszDir = NULL;
  1300. }
  1301. if (pR->pszName != NULL)
  1302. {
  1303. free(pR->pszName);
  1304. pR->pszName = NULL;
  1305. }
  1306. free(pR);
  1307. pR = NULL;
  1308. }
  1309. pX->pXferStuff = (void *)0;
  1310. pX->nExpanded = FALSE;
  1311. // Make sure to reset the Transfer direction. REV: 02/14/2001
  1312. pX->nDirection = XFER_NONE;
  1313. toolbar = sessQueryHwndToolbar( hSession );
  1314. ToolbarEnableButton( toolbar, IDM_ACTIONS_SEND, TRUE );
  1315. ToolbarEnableButton( toolbar, IDM_ACTIONS_RCV, TRUE );
  1316. }
  1317. }
  1318. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  1319. * FUNCTION:
  1320. * xfrCleanUpSend
  1321. *
  1322. * DESCRIPTION:
  1323. * This function is called from xfrDoTransfer after a transfer in order to
  1324. * clean up the stuff that was allocated in order to do the transfer.
  1325. *
  1326. * PARAMETERS:
  1327. *
  1328. * RETURNS:
  1329. * Nothing.
  1330. */
  1331. void xfrCleanUpSend(HSESSION hSession)
  1332. {
  1333. XD_TYPE *pX;
  1334. XFR_SEND *pS;
  1335. HWND toolbar;
  1336. /* TODO: finish this thing up */
  1337. pX = (XD_TYPE *)sessQueryXferHdl(hSession);
  1338. assert(pX);
  1339. if (pX)
  1340. {
  1341. pS = (XFR_SEND *)pX->pXferStuff;
  1342. assert(pS);
  1343. if (pS)
  1344. {
  1345. int n;
  1346. if (pS->pList)
  1347. {
  1348. for (n = pS->nCount - 1; n >= 0; n--)
  1349. {
  1350. if (pS->pList[n].pszName)
  1351. {
  1352. free(pS->pList[n].pszName);
  1353. pS->pList[n].pszName = NULL;
  1354. }
  1355. }
  1356. free(pS->pList);
  1357. pS->pList = NULL;
  1358. }
  1359. free(pS);
  1360. pS = NULL;
  1361. }
  1362. pX->pXferStuff = (void *)0;
  1363. pX->nExpanded = FALSE;
  1364. // Make sure to reset the Transfer direction. REV: 02/14/2001
  1365. pX->nDirection = XFER_NONE;
  1366. toolbar = sessQueryHwndToolbar( hSession );
  1367. ToolbarEnableButton( toolbar, IDM_ACTIONS_SEND, TRUE );
  1368. ToolbarEnableButton( toolbar, IDM_ACTIONS_RCV, TRUE );
  1369. }
  1370. }
  1371. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  1372. * FUNCTION:
  1373. * xfrDoTransfer
  1374. *
  1375. * DESCRIPTION:
  1376. * Yes, folks, this is the one you have been waiting for. It runs in the
  1377. * CLOOP thread. It calls the XFER DLL (if there is one). It slices. It
  1378. * dices. It actually does the transfer.
  1379. *
  1380. * PARAMETERS:
  1381. * hSession -- the font of all knowledge
  1382. *
  1383. * RETURNS:
  1384. * Nothing. What can be said after a transfer is done?
  1385. *
  1386. */
  1387. void xfrDoTransfer(HXFER hXfer)
  1388. {
  1389. XD_TYPE *pX;
  1390. HSESSION hSession = (HSESSION)0;
  1391. int nRet = 0;
  1392. int nTitle;
  1393. TCHAR acTitle[64];
  1394. TCHAR acMessage[255];
  1395. // pX = (XD_TYPE *)sessQueryXferHdl(hSession);
  1396. pX = (XD_TYPE *)hXfer;
  1397. if (pX)
  1398. {
  1399. hSession = pX->hSession;
  1400. switch (pX->nDirection)
  1401. {
  1402. case XFER_SEND:
  1403. nTitle = IDS_XD_SEND;
  1404. nRet = xfrSend(hSession, (XFR_SEND *)pX->pXferStuff);
  1405. xfrCleanUpSend(hSession);
  1406. break;
  1407. case XFER_RECV:
  1408. nTitle = IDS_XD_RECEIVE;
  1409. nRet = xfrReceive(hSession, (XFR_RECEIVE *)pX->pXferStuff);
  1410. xfrCleanUpReceive(hSession);
  1411. break;
  1412. default:
  1413. assert(FALSE);
  1414. break;
  1415. }
  1416. }
  1417. if (sessQuerySound(hSession))
  1418. {
  1419. mscMessageBeep(MB_OK);
  1420. }
  1421. switch (nRet)
  1422. {
  1423. case TSC_OK:
  1424. case TSC_COMPLETE:
  1425. case TSC_CANT_START:
  1426. break;
  1427. default:
  1428. LoadString(glblQueryDllHinst(),
  1429. nTitle,
  1430. acTitle,
  1431. sizeof(acTitle) / sizeof(TCHAR));
  1432. LoadString(glblQueryDllHinst(),
  1433. nRet + IDS_TM_XFER_ZERO,
  1434. acMessage,
  1435. sizeof(acMessage) / sizeof(TCHAR));
  1436. if (StrCharGetStrLength(acMessage) > 0)
  1437. {
  1438. TimedMessageBox(sessQueryHwnd(hSession),
  1439. acMessage,
  1440. acTitle,
  1441. MB_OK | MB_ICONINFORMATION,
  1442. sessQueryTimeout(hSession));
  1443. }
  1444. break;
  1445. }
  1446. }
  1447. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  1448. * FUNCTION:
  1449. * xfrSetPercentDone
  1450. *
  1451. * DESCRIPTION:
  1452. * This function is called to set the percent done value for a transfer.
  1453. * This value is only of real use when the program is shown as an icon.
  1454. *
  1455. * PARAMETERS:
  1456. * hSession -- the session handle
  1457. * nPerCent -- the percent done (0 to 100)
  1458. *
  1459. * RETURNS:
  1460. * Nothing.
  1461. *
  1462. */
  1463. void xfrSetPercentDone(HXFER hXfer, int nPerCent)
  1464. {
  1465. XD_TYPE *pX;
  1466. HWND hwnd;
  1467. // pX = (XD_TYPE *)sessQueryXferHdl(hSession);
  1468. pX = (XD_TYPE *)hXfer;
  1469. assert(pX);
  1470. if (pX)
  1471. {
  1472. // DbgOutStr("Set percent %d", nPerCent, 0,0,0,0);
  1473. pX->nPerCent = nPerCent;
  1474. hwnd = sessQueryHwnd(pX->hSession);
  1475. if (IsIconic(hwnd))
  1476. {
  1477. // DbgOutStr(" !!!", 0,0,0,0,0);
  1478. InvalidateRect(hwnd, 0, TRUE);
  1479. }
  1480. // DbgOutStr("\r\n", 0,0,0,0,0);
  1481. }
  1482. }
  1483. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  1484. * FUNCTION:
  1485. * xfrGetPercentDone
  1486. *
  1487. * DESCRIPTION:
  1488. * This function is called to get the stored percentage value for a transfer.
  1489. * This is usually done only to display the value as an icon.
  1490. *
  1491. * PARAMETERS:
  1492. * hSession -- the session handle
  1493. *
  1494. * RETURNS:
  1495. * The percentage (0 to 100).
  1496. *
  1497. */
  1498. int xfrGetPercentDone(HXFER hXfer)
  1499. {
  1500. XD_TYPE *pX;
  1501. // pX = (XD_TYPE *)sessQueryXferHdl(hSession);
  1502. pX = (XD_TYPE *)hXfer;
  1503. if (pX)
  1504. {
  1505. return pX->nPerCent;
  1506. }
  1507. return 0;
  1508. }
  1509. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  1510. * FUNCTION:
  1511. * xfrGetDisplayWindow
  1512. *
  1513. * DESCRIPTION:
  1514. * Returns the window handle of the transfer display window, if any.
  1515. *
  1516. * PARAMETERS:
  1517. * hSession -- the session handle
  1518. *
  1519. * RETURNS:
  1520. * A window handle (HWND) or NULL.
  1521. *
  1522. */
  1523. HWND xfrGetDisplayWindow(HXFER hXfer)
  1524. {
  1525. HWND hRet;
  1526. XD_TYPE *pX;
  1527. hRet = (HWND)0;
  1528. // pX = (XD_TYPE *)sessQueryXferHdl(hSession);
  1529. pX = (XD_TYPE *)hXfer;
  1530. if (pX)
  1531. {
  1532. hRet = pX->hwndXfrDisplay; /* handle of the display window */
  1533. }
  1534. return hRet;
  1535. }
  1536. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  1537. * FUNCTION:
  1538. * xfrDoAutostart
  1539. *
  1540. * DESCRIPTION:
  1541. * This function is called whenever the session proc gets an XFER_REQ event.
  1542. * This usually indicates that somebody wants to do a ZMODEM receive. In
  1543. * UPPER WACKER other protocols will be added, notably CSB and HyperP.
  1544. *
  1545. * PARAMETERS:
  1546. * hSession -- the session handle
  1547. * lProtocol -- which protocol is requested
  1548. *
  1549. * RETURNS:
  1550. * Nothing.
  1551. *
  1552. */
  1553. void xfrDoAutostart(HXFER hXfer, long lProtocol)
  1554. {
  1555. XD_TYPE *pX;
  1556. HSESSION hSession;
  1557. pX = (XD_TYPE *)hXfer;
  1558. assert(pX);
  1559. if (pX == NULL)
  1560. {
  1561. return;
  1562. }
  1563. hSession = pX->hSession;
  1564. assert(hSession);
  1565. if (hSession == NULL)
  1566. {
  1567. return;
  1568. }
  1569. switch (lProtocol)
  1570. {
  1571. case XF_ZMODEM:
  1572. case XF_ZMODEM_CR:
  1573. {
  1574. int nXferRecvReturn;
  1575. int nOldProtocol;
  1576. LPCTSTR pszDir;
  1577. XFR_PARAMS *pP;
  1578. XFR_Z_PARAMS *pZ;
  1579. pP = (XFR_PARAMS *)0;
  1580. xfrQueryParameters(hXfer, (VOID **)&pP);
  1581. assert(pP);
  1582. #if defined(INCL_ZMODEM_CRASH_RECOVERY)
  1583. //
  1584. // For Zmodem autostarts, check to see if the receiver's
  1585. // protocol is set for plain Zmodem. Otherwise use
  1586. // crash recovery.
  1587. //
  1588. if (pP->nRecProtocol == XF_ZMODEM)
  1589. {
  1590. lProtocol = XF_ZMODEM;
  1591. }
  1592. else
  1593. {
  1594. lProtocol = XF_ZMODEM_CR;
  1595. }
  1596. #endif // defined(INCL_ZMODEM_CRASH_RECOVERY)
  1597. pZ = (XFR_Z_PARAMS *)0;
  1598. xfrQueryProtoParams(hXfer,
  1599. (int)lProtocol,
  1600. (void **)&pZ);
  1601. if (pZ)
  1602. {
  1603. //
  1604. // See if autostart is OK.
  1605. //
  1606. if (!pZ->nAutostartOK)
  1607. {
  1608. xferCancelAutoStart(hSession, lProtocol);
  1609. break; /* Not allowed ! */
  1610. }
  1611. }
  1612. //
  1613. // See if we should allow host initiated file transfers.
  1614. //
  1615. if (!sessQueryAllowHostXfers(hSession))
  1616. {
  1617. xferCancelAutoStart(hSession, lProtocol);
  1618. break; /* Not allowed ! */
  1619. }
  1620. nOldProtocol = pP->nRecProtocol;
  1621. pP->nRecProtocol = (int)lProtocol;
  1622. /* Try and start up the transfer */
  1623. pszDir = filesQueryRecvDirectory(sessQueryFilesDirsHdl(hSession));
  1624. nXferRecvReturn = xfrRecvStart(hXfer, pszDir, "");
  1625. //
  1626. // Don't save the settings if a file transfer is in
  1627. // progress otherwise the current file transfer could
  1628. // get corrupted. REV: 08/06/2001.
  1629. //
  1630. if (nXferRecvReturn == XFR_IN_PROGRESS)
  1631. {
  1632. TCHAR acMessage[256];
  1633. if (sessQuerySound(hSession))
  1634. {
  1635. mscMessageBeep(MB_ICONHAND);
  1636. }
  1637. LoadString(glblQueryDllHinst(),
  1638. IDS_ER_XFER_RECV_IN_PROCESS,
  1639. acMessage,
  1640. sizeof(acMessage) / sizeof(TCHAR));
  1641. TimedMessageBox(sessQueryHwnd(hSession),
  1642. acMessage,
  1643. NULL,
  1644. MB_OK | MB_ICONEXCLAMATION,
  1645. sessQueryTimeout(hSession));
  1646. //
  1647. // TODO:REV 08/06/2001 We should send a ZModem cancel
  1648. // back to let the other side know we are not able to
  1649. // recieve the file at this point.
  1650. //
  1651. // Actually a ZCOMPL is the correct responce when we
  1652. // are not to receive an autostart delivery, but that
  1653. // may cause an existing ZModem file transfer to be
  1654. // replied to as complete, so we won't do this until
  1655. // we figure out what to do in this case. REV: 4/25/2002
  1656. //
  1657. // xferCancelAutoStart(hSession, lProtocol);
  1658. }
  1659. /* Restore what we changed up above */
  1660. pP->nRecProtocol = nOldProtocol;
  1661. }
  1662. break;
  1663. default:
  1664. assert(FALSE);
  1665. break;
  1666. }
  1667. }
  1668. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  1669. * FUNCTION:
  1670. * xferCancelAutoStart
  1671. *
  1672. * DESCRIPTION:
  1673. * This function is called whenever the session proc gets an autostart
  1674. * file transfer event.
  1675. *
  1676. * PARAMETERS:
  1677. * hSession -- the session handle
  1678. * lProtocol -- which protocol is requested
  1679. *
  1680. * RETURNS:
  1681. * Nothing.
  1682. *
  1683. */
  1684. void xferCancelAutoStart(HSESSION hSession, long lProtocol)
  1685. {
  1686. #if defined(TODO)
  1687. //
  1688. // Send a ZCOMPL header here to let other end know we
  1689. // we can't accept an autostart delivery. REV: 4/25/2002
  1690. //
  1691. zmdm_rcv(hSession, lProtocol, TRUE, FALSE);
  1692. hXfer->nUserCancel = XFER_NO_AUTOSTART;
  1693. hXfer->
  1694. xfrDoTransfer(hXfer);
  1695. zshhdr(pZ, ZCOMPL, pZ->Txhdr);
  1696. #endif // defined(TODO)
  1697. return;
  1698. }