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.

977 lines
24 KiB

  1. /* File: D:\WACKER\tdll\sessfile.c (Created: 30-Apr-1994)
  2. *
  3. * Copyright 1994 by Hilgraeve Inc. -- Monroe, MI
  4. * All rights reserved
  5. *
  6. * $Revision: 18 $
  7. * $Date: 7/12/02 12:31p $
  8. */
  9. #include <windows.h>
  10. #pragma hdrstop
  11. #include <time.h>
  12. #include "features.h"
  13. #include "stdtyp.h"
  14. #include "sf.h"
  15. #include "mc.h"
  16. #include "term.h"
  17. #include "cnct.h"
  18. #include "print.h"
  19. #include "assert.h"
  20. #include "capture.h"
  21. #include "globals.h"
  22. #include "sess_ids.h"
  23. #include "load_res.h"
  24. #include "open_msc.h"
  25. #include "xfer_msc.h"
  26. #include "file_msc.h"
  27. #include "backscrl.h"
  28. #include "cloop.h"
  29. #include "com.h"
  30. #include <term\res.h>
  31. #include "session.h"
  32. #include "session.hh"
  33. #include "errorbox.h"
  34. #include <emu\emu.h>
  35. #include "tdll.h"
  36. #include "htchar.h"
  37. #include "translat.h"
  38. #include "misc.h"
  39. #if defined(INCL_KEY_MACROS)
  40. #include "keyutil.h"
  41. #endif
  42. STATIC_FUNC void sessSaveHdl(HSESSION hSession);
  43. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  44. * FUNCTION:
  45. * sessLoadSessionStuff
  46. *
  47. * DESCRIPTION:
  48. * This function gets called whenever the user wants to read in the data
  49. * from a session file. If there is a currently opened session file, it
  50. * is open, otherwise we prompt for one.
  51. *
  52. * PARAMETERS:
  53. * hSession -- the session handle
  54. *
  55. * RETURNS:
  56. * BOOL
  57. */
  58. BOOL sessLoadSessionStuff(const HSESSION hSession)
  59. {
  60. BOOL bRet = TRUE;
  61. BOOL fBool = TRUE;
  62. const HHSESSION hhSess = VerifySessionHandle(hSession);
  63. unsigned long lSize;
  64. sessLoadIcons(hSession);
  65. if (bRet)
  66. {
  67. if (hhSess->hXferHdl)
  68. bRet = (LoadXferHdl((HXFER)hhSess->hXferHdl) == 0);
  69. assert(bRet);
  70. }
  71. if (bRet)
  72. {
  73. if (hhSess->hFilesHdl != (HFILES)0)
  74. bRet = (LoadFilesDirsHdl(sessQueryFilesDirsHdl(hSession))==0);
  75. assert(bRet);
  76. }
  77. if (bRet)
  78. {
  79. if (hhSess->hCaptFile)
  80. bRet = (LoadCaptureFileHandle(hhSess->hCaptFile) == 0);
  81. assert(bRet);
  82. }
  83. // Moved to before emulator load. Some emulators like the Minitel
  84. // load fonts if the correct one is not loaded so we need to let
  85. // the terminal load its fonts before loading the emulator so there
  86. // is no conflict. mrw,3/2/95
  87. //
  88. if (bRet)
  89. {
  90. if (SendMessage(hhSess->hwndTerm, WM_TERM_LOAD_SETTINGS, 0, 0))
  91. {
  92. assert(FALSE);
  93. bRet = FALSE;
  94. }
  95. }
  96. if (bRet)
  97. {
  98. if (hhSess->hEmu)
  99. bRet = (emuInitializeHdl(hhSess->hEmu) == 0);
  100. assert(bRet);
  101. }
  102. if (bRet)
  103. {
  104. if (hhSess->hPrint)
  105. bRet = (printInitializeHdl(hhSess->hPrint) == 0);
  106. assert(bRet);
  107. }
  108. #if defined(CHARACTER_TRANSLATION)
  109. if (bRet)
  110. {
  111. if (hhSess->hTranslate)
  112. bRet = (LoadTranslateHandle(hhSess->hTranslate) == 0);
  113. assert(bRet);
  114. }
  115. #endif
  116. if (bRet)
  117. {
  118. if (hhSess->hCLoop)
  119. bRet = (CLoopLoadHdl(hhSess->hCLoop) == 0);
  120. assert(bRet);
  121. }
  122. if (bRet)
  123. {
  124. if (hhSess->hCom)
  125. bRet = (ComLoadHdl(hhSess->hCom) == 0);
  126. assert(bRet);
  127. }
  128. if (bRet)
  129. {
  130. if (hhSess->hCnct)
  131. {
  132. if (cnctLoad(hhSess->hCnct))
  133. {
  134. assert(FALSE);
  135. bRet = FALSE;
  136. }
  137. }
  138. }
  139. if (bRet)
  140. {
  141. lSize = sizeof(hhSess->fSound);
  142. // Initialize... i.e., sound ON.
  143. //
  144. hhSess->fSound = TRUE;
  145. sfGetSessionItem(hhSess->hSysFile,
  146. SFID_SESS_SOUND,
  147. &lSize,
  148. &hhSess->fSound);
  149. }
  150. if (bRet)
  151. {
  152. lSize = sizeof(hhSess->fExit);
  153. // Initialize... i.e., exit OFF.
  154. //
  155. hhSess->fExit = FALSE;
  156. sfGetSessionItem(hhSess->hSysFile,
  157. SFID_SESS_EXIT,
  158. &lSize,
  159. &hhSess->fExit);
  160. }
  161. if (bRet)
  162. {
  163. lSize = sizeof(hhSess->fAllowHostXfers);
  164. // Initialize... i.e., exit OFF.
  165. //
  166. hhSess->fAllowHostXfers = FALSE;
  167. sfGetSessionItem(hhSess->hSysFile,
  168. SFID_SESS_ALLOW_HOST_TRANSFER,
  169. &lSize,
  170. &hhSess->fAllowHostXfers);
  171. }
  172. if (bRet)
  173. {
  174. lSize = sizeof(BOOL);
  175. fBool = TRUE;
  176. sfGetSessionItem(hhSess->hSysFile,
  177. SFID_TLBR_VISIBLE,
  178. &lSize,
  179. &fBool);
  180. sessSetToolbarVisible(hSession, fBool);
  181. }
  182. if (bRet)
  183. {
  184. lSize = sizeof(BOOL);
  185. fBool = TRUE;
  186. sfGetSessionItem(hhSess->hSysFile,
  187. SFID_STBR_VISIBLE,
  188. &lSize,
  189. &fBool);
  190. sessSetStatusbarVisible(hSession, fBool);
  191. }
  192. if (bRet)
  193. {
  194. lSize = sizeof(hhSess->achSessName);
  195. // Initialize...
  196. //
  197. TCHAR_Fill(hhSess->achSessName, TEXT('\0'),
  198. sizeof(hhSess->achSessName) / sizeof(TCHAR));
  199. sfGetSessionFileName(hhSess->hSysFile,
  200. sizeof(hhSess->achSessName) / sizeof(TCHAR), hhSess->achSessName);
  201. // Hold on to just the session name, no path, no extension. It is
  202. // usefull to keep it around.
  203. //
  204. mscStripPath(hhSess->achSessName);
  205. mscStripExt(hhSess->achSessName);
  206. // We should never be storing this internal string in the session file!
  207. // - jac. 10-06-94 03:44pm
  208. // sfGetSessionItem(hhSess->hSysFile,
  209. // SFID_SESS_NAME,
  210. // &lSize,
  211. // hhSess->achSessName);
  212. /* This next line protects against trash in the session file */
  213. hhSess->achSessName[sizeof(hhSess->achSessName)-1] = TEXT('\0');
  214. StrCharCopyN(hhSess->achOldSessName, hhSess->achSessName, FNAME_LEN + 1);
  215. }
  216. if (bRet)
  217. {
  218. if (sessQueryBackscrlHdl(hSession))
  219. {
  220. backscrlRead(sessQueryBackscrlHdl(hSession));
  221. /* Don't check this for now */
  222. sessRestoreBackScroll(hSession);
  223. }
  224. }
  225. if (bRet)
  226. {
  227. lSize = sizeof(LONG);
  228. memset(&hhSess->rcSess, 0, sizeof(RECT));
  229. sfGetSessionItem(hhSess->hSysFile,
  230. SFID_SESS_LEFT,
  231. &lSize,
  232. &hhSess->rcSess.left);
  233. sfGetSessionItem(hhSess->hSysFile,
  234. SFID_SESS_TOP,
  235. &lSize,
  236. &hhSess->rcSess.top);
  237. sfGetSessionItem(hhSess->hSysFile,
  238. SFID_SESS_RIGHT,
  239. &lSize,
  240. &hhSess->rcSess.right);
  241. sfGetSessionItem(hhSess->hSysFile,
  242. SFID_SESS_BOTTOM,
  243. &lSize,
  244. &hhSess->rcSess.bottom);
  245. }
  246. if (bRet)
  247. {
  248. lSize = sizeof(UINT);
  249. hhSess->iShowCmd = SW_SHOWNORMAL;
  250. sfGetSessionItem(hhSess->hSysFile,
  251. SFID_SESS_SHOWCMD,
  252. &lSize,
  253. &hhSess->iShowCmd);
  254. }
  255. //
  256. // load the key macros
  257. //
  258. #ifdef INCL_KEY_MACROS
  259. if (bRet)
  260. {
  261. keysLoadMacroList( hSession );
  262. }
  263. #endif
  264. // Note: if you need to do any resizing, you must POST a message
  265. // to do so. The emulator may have changed size and that won't
  266. // reflected until it processes the pending notification - mrw
  267. //
  268. if (hhSess->achSessCmdLn[0] == TEXT('\0') && IsWindow(hhSess->hwndSess))
  269. {
  270. PostMessage(hhSess->hwndSess, WM_COMMAND,
  271. MAKEWPARAM(IDM_CONTEXT_SNAP, 0), 0);
  272. }
  273. return bRet;
  274. }
  275. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  276. * FUNCTION:
  277. * sessSaveSessionStuff
  278. *
  279. * DESCRIPTION:
  280. * This function is called to call all the functions that save things in
  281. * the session file. If you have stuff to write into the session file, it
  282. * should get called from here. This function also makes sure that the
  283. * user has a chance to specify the name of the session file if there is
  284. * not one currently.
  285. *
  286. * PARAMETERS:
  287. * hSession -- the session handle
  288. *
  289. * RETURNS:
  290. * Nothing.
  291. */
  292. void sessSaveSessionStuff(const HSESSION hSession)
  293. {
  294. const HHSESSION hhSess = VerifySessionHandle(hSession);
  295. /*
  296. * Put in code to make sure we have an open session file handle
  297. */
  298. assert(hhSess->hSysFile); // any suggestions ?
  299. /* This doesn't have a handle since it isn't every used but once */
  300. sessSaveBackScroll(hSession);
  301. // Call this function if you've got to save settings that are stored
  302. // in the session handle itself.
  303. //
  304. sessSaveHdl(hSession);
  305. if (hhSess->hXferHdl != (HXFER)0)
  306. SaveXferHdl((HXFER)hhSess->hXferHdl);
  307. if (hhSess->hFilesHdl != (HFILES)0)
  308. SaveFilesDirsHdl(sessQueryFilesDirsHdl(hSession));
  309. if (hhSess->hCaptFile != (HCAPTUREFILE)0)
  310. SaveCaptureFileHandle(hhSess->hCaptFile);
  311. if (hhSess->hEmu != 0)
  312. emuSaveHdl(hhSess->hEmu);
  313. if (hhSess->hPrint != 0)
  314. printSaveHdl(hhSess->hPrint);
  315. #if defined(CHARACTER_TRANSLATION)
  316. if (hhSess->hTranslate)
  317. SaveTranslateHandle(hhSess->hTranslate);
  318. #endif
  319. if (hhSess->hCLoop)
  320. CLoopSaveHdl(hhSess->hCLoop);
  321. if (hhSess->hCom)
  322. ComSaveHdl(hhSess->hCom);
  323. if (hhSess->hCnct)
  324. cnctSave(hhSess->hCnct);
  325. if (hhSess->hBackscrl)
  326. backscrlSave(hhSess->hBackscrl);
  327. if (hhSess->hwndTerm)
  328. SendMessage(hhSess->hwndTerm, WM_TERM_SAVE_SETTINGS, 0, 0);
  329. #ifdef INCL_KEY_MACROS
  330. keysSaveMacroList(hSession );
  331. #endif
  332. }
  333. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  334. * FUNCTION:
  335. * sessSaveHdl
  336. *
  337. * DESCRIPTION:
  338. * Save items stored in the session handle.
  339. *
  340. * PARAMETERS:
  341. * hSession -- the session handle
  342. *
  343. * RETURNS:
  344. * BOOL
  345. */
  346. STATIC_FUNC void sessSaveHdl(HSESSION hSession)
  347. {
  348. const HHSESSION hhSess = VerifySessionHandle(hSession);
  349. WINDOWPLACEMENT stWP;
  350. sessSaveIcons(hSession);
  351. sfPutSessionItem(hhSess->hSysFile,
  352. SFID_SESS_SOUND,
  353. sizeof(BOOL),
  354. &hhSess->fSound);
  355. sfPutSessionItem(hhSess->hSysFile,
  356. SFID_SESS_EXIT,
  357. sizeof(BOOL),
  358. &hhSess->fExit);
  359. sfPutSessionItem(hhSess->hSysFile,
  360. SFID_SESS_ALLOW_HOST_TRANSFER,
  361. sizeof(BOOL),
  362. &hhSess->fAllowHostXfers);
  363. sfPutSessionItem(hhSess->hSysFile,
  364. SFID_TLBR_VISIBLE,
  365. sizeof(BOOL),
  366. &hhSess->fToolbarVisible);
  367. sfPutSessionItem(hhSess->hSysFile,
  368. SFID_STBR_VISIBLE,
  369. sizeof(BOOL),
  370. &hhSess->fStatusbarVisible);
  371. // We should NEVER put this name into the session file!!!
  372. // -jac. 10-06-94 03:45pm
  373. // sfPutSessionItem(hhSess->hSysFile,
  374. // SFID_SESS_NAME,
  375. // (StrCharGetByteCount(hhSess->achSessName) + 1) * sizeof(TCHAR),
  376. // hhSess->achSessName);
  377. memset(&stWP, 0, sizeof(WINDOWPLACEMENT));
  378. stWP.length = sizeof(WINDOWPLACEMENT);
  379. GetWindowPlacement(hhSess->hwndSess, &stWP);
  380. sfPutSessionItem(hhSess->hSysFile,
  381. SFID_SESS_LEFT,
  382. sizeof(LONG),
  383. &(stWP.rcNormalPosition.left));
  384. sfPutSessionItem(hhSess->hSysFile,
  385. SFID_SESS_TOP,
  386. sizeof(LONG),
  387. &(stWP.rcNormalPosition.top));
  388. sfPutSessionItem(hhSess->hSysFile,
  389. SFID_SESS_RIGHT,
  390. sizeof(LONG),
  391. &(stWP.rcNormalPosition.right));
  392. sfPutSessionItem(hhSess->hSysFile,
  393. SFID_SESS_BOTTOM,
  394. sizeof(LONG),
  395. &(stWP.rcNormalPosition.bottom));
  396. // mrw:4/21/95
  397. //
  398. if (stWP.showCmd == SW_SHOWMINIMIZED || stWP.showCmd == SW_MINIMIZE ||
  399. stWP.showCmd == SW_SHOWMINNOACTIVE)
  400. {
  401. stWP.showCmd = SW_SHOWNORMAL;
  402. }
  403. sfPutSessionItem(hhSess->hSysFile,
  404. SFID_SESS_SHOWCMD,
  405. sizeof(UINT),
  406. &(stWP.showCmd));
  407. }
  408. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  409. * FUNCTION:
  410. * sessSaveBackScroll
  411. *
  412. * DESCRIPTION:
  413. * This function is called to take the stuff that is in the backscroll and
  414. * on the screen and save it away in the session file.
  415. *
  416. * The first attempt to do this will be simply a brute force attack. No
  417. * real attempt to be tricky or cute. Just slam it through. Maybe it will
  418. * need to be changed later. But that is later.
  419. *
  420. * ARGUMENTS:
  421. * hSession -- the session handle
  422. *
  423. * RETURNS:
  424. * TRUE if everything is OK, otherwise FALSE
  425. *
  426. */
  427. BOOL sessSaveBackScroll(const HSESSION hSession)
  428. {
  429. BOOL bRet = TRUE;
  430. int nRet;
  431. POINT pBeg;
  432. POINT pEnd;
  433. ECHAR *pszData;
  434. ECHAR *pszPtr;
  435. ECHAR *pszEnd;
  436. DWORD dwSize;
  437. /* --- Don't bother with this if nothing has changed --- */
  438. if (backscrlChanged(sessQueryBackscrlHdl(hSession)) == FALSE)
  439. return TRUE;
  440. // Also, if there is no session window, don't bother since there
  441. // won't be any terminal window and CopyTextFromTerminal() will
  442. // fault. - mrw
  443. if (!IsWindow(sessQueryHwnd(hSession)))
  444. return TRUE;
  445. pBeg.x = 0;
  446. pBeg.y = -backscrlGetUNumLines(sessQueryBackscrlHdl(hSession)); //-BKSCRL_USERLINES_DEFAULT_MAX;
  447. pEnd.x = 132;
  448. pEnd.y = 50;
  449. pszData = (ECHAR *)0;
  450. dwSize = 0;
  451. CopyTextFromTerminal(hSession,
  452. &pBeg, &pEnd,
  453. (void **)&pszData,
  454. &dwSize,
  455. FALSE);
  456. assert(pszData);
  457. if (pszData != (ECHAR *)0)
  458. {
  459. assert(dwSize);
  460. /*
  461. * We need to do a little work here to make sure that whatever
  462. * trailing blank lines there are don't get put into the saved
  463. * text.
  464. */
  465. pszPtr = pszData;
  466. pszEnd = pszPtr;
  467. while (*pszPtr != ETEXT('\0'))
  468. {
  469. if (*pszPtr != ETEXT('\r'))
  470. pszEnd = pszPtr;
  471. pszPtr = pszPtr++;
  472. }
  473. pszEnd = pszPtr++;
  474. dwSize = (DWORD)((pszEnd - pszData) * sizeof(ECHAR));
  475. nRet = sfPutSessionItem(sessQuerySysFileHdl(hSession),
  476. SFID_BKSC_TEXT,
  477. dwSize,
  478. pszData);
  479. free(pszData);
  480. pszData = NULL;
  481. }
  482. return bRet;
  483. }
  484. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  485. * FUNCTION:
  486. * sessRestoreBackScroll
  487. *
  488. * DESCRIPTION:
  489. * This function is called to read a bunch of stuff (text) from the session
  490. * file and cram it into the backscroll.
  491. *
  492. * The first attempt to do this will be simply a brute force attack. No
  493. * real attempt to be tricky or cute. Just slam it through. Maybe it will
  494. * need to be changed later. But that is later.
  495. *
  496. * ARGUMENTS:
  497. * hSession -- the session handle
  498. *
  499. * RETURNS:
  500. * TRUE if everything is OK, otherwise FALSE
  501. *
  502. */
  503. BOOL sessRestoreBackScroll(const HSESSION hSession)
  504. {
  505. BOOL bRet = TRUE;
  506. unsigned long lSize;
  507. ECHAR * pszData = NULL;
  508. ECHAR * pszPtr = NULL;
  509. ECHAR * pszEnd = NULL;
  510. HBACKSCRL hBS = NULL;
  511. hBS = sessQueryBackscrlHdl(hSession);
  512. assert(hBS);
  513. /* Whenever we load in new session file, get rid of the old BS */
  514. backscrlFlush(hBS);
  515. lSize = 0;
  516. sfGetSessionItem(sessQuerySysFileHdl(hSession), SFID_BKSC_TEXT, &lSize, NULL);
  517. if (lSize > 0)
  518. {
  519. pszData = (ECHAR*)malloc(lSize * sizeof(ECHAR));
  520. if (pszData == NULL)
  521. {
  522. assert(pszData);
  523. return FALSE;
  524. }
  525. ECHAR_Fill(pszData, ETEXT('\0'), lSize);
  526. sfGetSessionItem(sessQuerySysFileHdl(hSession),
  527. SFID_BKSC_TEXT,
  528. &lSize,
  529. pszData);
  530. pszPtr = pszData;
  531. while ((*pszPtr != ETEXT('\0')) && (pszPtr <= (pszData + lSize)))
  532. {
  533. pszEnd = pszPtr;
  534. while ((*pszEnd != ETEXT('\0')) && (*pszEnd != ETEXT('\r')) &&
  535. (pszEnd <= (pszData + lSize)))
  536. pszEnd = pszEnd++;
  537. /* Stuff the line into the backscroll */
  538. backscrlAdd(hBS, pszPtr, (int)(pszEnd - pszPtr));
  539. /* Bump pointer to the beginning of the next line */
  540. pszPtr = pszEnd;
  541. if (*pszPtr == ETEXT('\r'))
  542. pszPtr = pszPtr++;
  543. }
  544. if (pszData)
  545. {
  546. free(pszData);
  547. pszData = NULL;
  548. }
  549. }
  550. backscrlResetChangedFlag(hBS);
  551. return bRet;
  552. }
  553. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  554. * FUNCTION:
  555. * sessCheckAndLoadCmdLn
  556. *
  557. * DESCRIPTION:
  558. * When the programs starts up, we save the command line. If there is
  559. * something on the command line, we check and see if maybe it is the name
  560. * of a session file. If it is, we open the session file. Other command
  561. * line switches are processed here as well.
  562. *
  563. * PARAMETERS:
  564. * hSession -- the session handle
  565. *
  566. * RETURNS:
  567. * 0=OK, else error.
  568. */
  569. int sessCheckAndLoadCmdLn(const HSESSION hSession)
  570. {
  571. int nIdx;
  572. int iRet = -1;
  573. LPTSTR pszStr;
  574. LPTSTR pszTmp;
  575. #if defined(INCL_WINSOCK)
  576. TCHAR* pszTelnet = TEXT("telnet:");
  577. TCHAR* pszPort = NULL;
  578. #endif
  579. TCHAR acPath[FNAME_LEN], acName[FNAME_LEN];
  580. const HHSESSION hhSess = VerifySessionHandle(hSession);
  581. if (hhSess->achSessCmdLn[0] == TEXT('\0'))
  582. return -1;
  583. // Null out the arrays for the path and name. REV: 10/26/2000
  584. //
  585. TCHAR_Fill(acPath, TEXT('\0'), FNAME_LEN);
  586. TCHAR_Fill(acName, TEXT('\0'), FNAME_LEN);
  587. // Assume there's the name of a session file we want to open on the
  588. // command line. We'll accept a prepended /D as well.
  589. //
  590. // We should really only Open the entry here since the dial (/D)
  591. // switch was not passed on the command line. I will leave it like
  592. // this for now, but it should be changed in the future to just
  593. // open the entry since you are not able to just open an entry
  594. // without attempting to dial. REV: 10/26/2000
  595. //
  596. hhSess->iCmdLnDial = CMDLN_DIAL_DIAL;
  597. nIdx = 0;
  598. for (pszStr = hhSess->achSessCmdLn;
  599. (*pszStr != TEXT('\0') && nIdx < FNAME_LEN);
  600. pszStr = StrCharNext(pszStr))
  601. {
  602. /*
  603. * This works because we only allow certain characters as switches
  604. */
  605. if (*pszStr == TEXT('/'))
  606. {
  607. /* Process as a switch */
  608. pszStr = StrCharNext(pszStr);
  609. //jmh 3/24/97 Check for end of string here...
  610. if (*pszStr == TEXT('\0'))
  611. {
  612. break;
  613. }
  614. if ((*pszStr == TEXT('D')) || (*pszStr == TEXT('d')))
  615. {
  616. // The name that follows is a session file
  617. pszTmp = StrCharNext(pszStr);
  618. if (*pszTmp == TEXT('\0'))
  619. {
  620. break;
  621. }
  622. else
  623. {
  624. if (*pszTmp == TEXT(' '))
  625. {
  626. pszStr = pszTmp;
  627. hhSess->iCmdLnDial = CMDLN_DIAL_DIAL;
  628. }
  629. }
  630. }
  631. #if defined(INCL_WINSOCK)
  632. if ((*pszStr == TEXT('T')) || (*pszStr == TEXT('t')))
  633. {
  634. pszTmp = StrCharNext(pszStr);
  635. //jmh 3/24/97 Check for end of string here...
  636. if (*pszTmp == TEXT('\0'))
  637. {
  638. break;
  639. }
  640. else if (*pszTmp == TEXT(' '))
  641. {
  642. pszStr = pszTmp;
  643. // The name that follows is a telnet address
  644. hhSess->iCmdLnDial = CMDLN_DIAL_WINSOCK;
  645. }
  646. }
  647. #endif
  648. }
  649. else
  650. {
  651. /* Copy all non switch stuff to the buffer */
  652. if (IsDBCSLeadByte(*pszStr))
  653. {
  654. MemCopy(&acPath[nIdx], pszStr, (size_t)2 * sizeof(TCHAR));
  655. nIdx += 2;
  656. }
  657. //
  658. // Make sure to strip off the " characters from the
  659. // session filename. REV: 06/13/2001
  660. //
  661. else if (*pszStr != TEXT('\"'))
  662. {
  663. acPath[nIdx++] = *pszStr;
  664. }
  665. }
  666. }
  667. // Removed old logic here and call GetFileNameFromCmdLine() which
  668. // does something similar to this function. On return, we should
  669. // have a fully qualified path name. - mrw,3/2/95
  670. //
  671. acPath[nIdx] = TEXT('\0');
  672. TCHAR_Trim(acPath); // Strip leading spaces
  673. #if defined(INCL_WINSOCK)
  674. // If this is a telnet address from the browser, it will usually be preceeded
  675. // by the string telnet: If so, we must remove it or it will confuse some of
  676. // the code to follow jkh, 03/22/1997
  677. if (*acPath && hhSess->iCmdLnDial == CMDLN_DIAL_WINSOCK)
  678. {
  679. nIdx = StrCharGetStrLength(pszTelnet);
  680. if (StrCharCmpiN(acPath, pszTelnet, nIdx) == 0)
  681. {
  682. // Remove the telnet string from the front of acPath
  683. memmove(acPath, &acPath[nIdx],
  684. (StrCharGetStrLength(acPath) - nIdx) + 1);
  685. }
  686. }
  687. // See if URL contains a port number. This will take the form of
  688. // addr:nnn where nnn is the port number i.e. culine.colorado.edu:860
  689. // or there might be the name of an assigned port like hilgraeve.com:finger.
  690. // We support numeric port right now, may add port names later. jkh, 3/22/1997
  691. pszPort = StrCharFindFirst(acPath, TEXT(':'));
  692. if (pszPort && isdigit(pszPort[1]))
  693. {
  694. hhSess->iTelnetPort = atoi(StrCharNext(pszPort));
  695. }
  696. #endif
  697. GetFileNameFromCmdLine(acPath, acName, FNAME_LEN);
  698. if (acName[0] == TEXT('\0'))
  699. {
  700. // Nothing on the command line
  701. hhSess->iCmdLnDial = CMDLN_DIAL_NEW;
  702. iRet = 0;
  703. }
  704. else
  705. {
  706. // Look for a pre-existing session file. First, the old TRM format
  707. //
  708. if (fTestOpenOldTrmFile(hhSess, acName) != 0)
  709. {
  710. // Next, try the more common HyperTerminal file format
  711. //
  712. if (sfOpenSessionFile(hhSess->hSysFile, acName) < SF_OK)
  713. {
  714. // Command-line argument is not an existing file. Decide
  715. // how to act based on command-line switches.
  716. //
  717. if (hhSess->iCmdLnDial == CMDLN_DIAL_DIAL)
  718. {
  719. // We were asked to open and dial a pre-existing session
  720. // file, and failed.
  721. //
  722. TCHAR acFormat[64];
  723. TCHAR ach[FNAME_LEN];
  724. LoadString(glblQueryDllHinst(),
  725. IDS_ER_BAD_SESSION,
  726. acFormat,
  727. sizeof(acFormat) / sizeof(TCHAR));
  728. wsprintf(ach, acFormat, acName);
  729. TimedMessageBox(sessQueryHwnd(hSession),
  730. ach,
  731. NULL,
  732. MB_OK | MB_ICONEXCLAMATION,
  733. sessQueryTimeout(hSession));
  734. sfSetSessionFileName(hhSess->hSysFile, TEXT(""));
  735. // Go to the Open dialog
  736. hhSess->iCmdLnDial = CMDLN_DIAL_OPEN;
  737. }
  738. #if defined(INCL_WINSOCK)
  739. else if (hhSess->iCmdLnDial == CMDLN_DIAL_WINSOCK)
  740. {
  741. //jmh 3/24/97 For future maintainers: there's some
  742. // skulduggery going on here that's worth explaining. When
  743. // you try to open a non-existent file, the name is still
  744. // stored. The code to do a telnet command-line dial
  745. // depends on this. Honest! I didn't write this...
  746. //
  747. //jmh 3/24/97 Mark this as a new session, so user will be
  748. // prompted to save on exit.
  749. hhSess->fIsNewSession = TRUE;
  750. iRet = 0;
  751. }
  752. #endif
  753. }
  754. else
  755. {
  756. // Command-line argument is an existing HyperTerminal file
  757. //
  758. hhSess->iCmdLnDial = CMDLN_DIAL_DIAL;
  759. iRet = 0;
  760. }
  761. }
  762. else
  763. {
  764. // Command-line argument is an existing TRM file
  765. //
  766. hhSess->iCmdLnDial = CMDLN_DIAL_DIAL;
  767. iRet = 0;
  768. }
  769. }
  770. return iRet;
  771. }
  772. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  773. * FUNCTION:
  774. * fTestOpenOldTrmFile
  775. *
  776. * DESCRIPTION:
  777. * Tests if its an old trm file. If so, it opens it and reads the
  778. * data out.
  779. *
  780. * ARGUMENTS:
  781. * hSession - our friend the public session handle
  782. * ach - name of file.
  783. *
  784. * RETURNS:
  785. * 0=OK, else not trm file
  786. *
  787. */
  788. int fTestOpenOldTrmFile(const HHSESSION hhSess, TCHAR *pachName)
  789. {
  790. int iRet = -1;
  791. HANDLE hFile;
  792. DWORD dw;
  793. LPTSTR pszPtr;
  794. TCHAR ach[80];
  795. TCHAR achName[FNAME_LEN];
  796. StrCharCopyN(achName, pachName, sizeof(achName) / sizeof(TCHAR));
  797. pszPtr = StrCharFindLast(achName, TEXT('.'));
  798. if (pszPtr && (StrCharCmpi(pszPtr, TEXT(".TRM")) == 0))
  799. {
  800. /* Old .TRM files case */
  801. hFile = CreateFile(achName, GENERIC_READ, FILE_SHARE_READ, 0,
  802. OPEN_EXISTING, 0, 0);
  803. if (hFile != INVALID_HANDLE_VALUE)
  804. {
  805. // Phone number is always at offset 0x282 for old .trm files.
  806. //
  807. if (SetFilePointer(hFile, 0x282, 0, FILE_BEGIN) != (DWORD)-1)
  808. {
  809. if (ReadFile(hFile, ach, sizeof(ach), &dw, 0) == TRUE)
  810. {
  811. CloseHandle(hFile);
  812. ach[sizeof(ach)/sizeof(TCHAR)-1] = TEXT('\0');
  813. cnctSetDestination(hhSess->hCnct, ach,
  814. StrCharGetByteCount(ach));
  815. *pszPtr = TEXT('\0');
  816. mscStripExt(mscStripPath(achName));
  817. sessSetName((HSESSION)hhSess, achName);
  818. hhSess->iCmdLnDial = CMDLN_DIAL_OPEN;
  819. hhSess->fIsNewSession = TRUE; // so it asks to save
  820. hhSess->nIconId = IDI_PROG1;
  821. hhSess->hIcon = extLoadIcon(MAKEINTRESOURCE(IDI_PROG1));
  822. iRet = 0;
  823. }
  824. else
  825. {
  826. DbgShowLastError();
  827. CloseHandle(hFile);
  828. }
  829. }
  830. else
  831. {
  832. DbgShowLastError();
  833. CloseHandle(hFile);
  834. }
  835. }
  836. else
  837. {
  838. DbgShowLastError();
  839. }
  840. }
  841. return iRet;
  842. }