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.

897 lines
19 KiB

  1. /* File: D:\WACKER\tdll\cncthdl.c (Created: 10-Jan-1994)
  2. *
  3. * Copyright 1994 by Hilgraeve Inc. -- Monroe, MI
  4. * All rights reserved
  5. *
  6. * $Revision: 10 $
  7. * $Date: 7/08/02 6:40p $
  8. */
  9. #define TAPI_CURRENT_VERSION 0x00010004 // cab:11/14/96 - required!
  10. #include <tapi.h>
  11. #pragma hdrstop
  12. #include <time.h>
  13. #include "stdtyp.h"
  14. #include "session.h"
  15. #include "mc.h"
  16. #include "globals.h"
  17. #include "assert.h"
  18. #include "errorbox.h"
  19. #include <term\res.h>
  20. #include "cnct.h"
  21. #include "cnct.hh"
  22. #include <cncttapi\cncttapi.hh>
  23. #include <emu\emu.h>
  24. #include "htchar.h"
  25. #include "tdll.h"
  26. static int cnctLoadDriver(const HHCNCT hhCnct);
  27. #define USE_FORMATMSG
  28. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  29. * FUNCTION:
  30. * cnctCreateHdl
  31. *
  32. * DESCRIPTION:
  33. * Creates a connection handle which is used to perform a connection
  34. * activity.
  35. *
  36. * ARGUMENTS:
  37. * hSession - public session handle
  38. *
  39. * RETURNS:
  40. * Connection handle or zero on error.
  41. *
  42. */
  43. HCNCT cnctCreateHdl(const HSESSION hSession)
  44. {
  45. HHCNCT hhCnct = 0;
  46. hhCnct = malloc(sizeof(*hhCnct));
  47. if (hhCnct == 0)
  48. {
  49. assert(FALSE);
  50. return FALSE;
  51. }
  52. memset(hhCnct, 0, sizeof(*hhCnct));
  53. hhCnct->hSession = hSession;
  54. InitializeCriticalSection(&hhCnct->csCnct);
  55. cnctStubAll(hhCnct);
  56. /* Lower Wacker is hardwired to this */
  57. cnctSetDevice((HCNCT)hhCnct, 0);
  58. return (HCNCT)hhCnct;
  59. }
  60. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  61. * FUNCTION:
  62. * cnctDestroyHdl
  63. *
  64. * DESCRIPTION:
  65. * Destroys a valid connection handle.
  66. *
  67. * ARGUMENTS:
  68. * hCnct - public connection handle.
  69. *
  70. * RETURNS:
  71. * void
  72. *
  73. */
  74. void cnctDestroyHdl(const HCNCT hCnct)
  75. {
  76. const HHCNCT hhCnct = (HHCNCT)hCnct;
  77. if (hhCnct == 0)
  78. return;
  79. DeleteCriticalSection(&hhCnct->csCnct);
  80. if (hhCnct->hDriver)
  81. {
  82. (*hhCnct->pfDestroy)(hhCnct->hDriver);
  83. }
  84. if (hhCnct->hModule)
  85. {
  86. FreeLibrary(hhCnct->hModule);
  87. }
  88. free(hhCnct);
  89. return;
  90. }
  91. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  92. * FUNCTION:
  93. * cnctLock
  94. *
  95. * DESCRIPTION:
  96. * Locks the connection handle critical section semaphore
  97. *
  98. * ARGUMENTS:
  99. * hhCnct - private connection handle
  100. *
  101. * RETURNS:
  102. * void
  103. *
  104. */
  105. void cnctLock(const HHCNCT hhCnct)
  106. {
  107. EnterCriticalSection(&hhCnct->csCnct);
  108. }
  109. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  110. * FUNCTION:
  111. * cnctUnlock
  112. *
  113. * DESCRIPTION:
  114. * Unlocks the connection handle critical section semaphore
  115. *
  116. * ARGUMENTS:
  117. * hhCnct - private connection handle
  118. *
  119. * RETURNS:
  120. * void
  121. *
  122. */
  123. void cnctUnlock(const HHCNCT hhCnct)
  124. {
  125. LeaveCriticalSection(&hhCnct->csCnct);
  126. }
  127. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  128. * FUNCTION:
  129. * cnctSetDevice
  130. *
  131. * DESCRIPTION:
  132. * Sets the connection device
  133. *
  134. * ARGUMENTS:
  135. * hCnct - public connection handle
  136. *
  137. * RETURNS:
  138. * 0=success, else error code
  139. *
  140. */
  141. int cnctSetDevice(const HCNCT hCnct, const LPTSTR pachDevice)
  142. {
  143. int iRet;
  144. const HHCNCT hhCnct = (HHCNCT)hCnct;
  145. if (hhCnct == 0)
  146. {
  147. assert(FALSE);
  148. return CNCT_BAD_HANDLE;
  149. }
  150. /* --- Can't set a device while we're connected --- */
  151. cnctLock(hhCnct);
  152. iRet = cnctQueryStatus(hCnct);
  153. if (iRet != CNCT_STATUS_FALSE && iRet != CNCT_NOT_SUPPORTED)
  154. {
  155. assert(FALSE);
  156. return CNCT_ERROR;
  157. }
  158. /* --- Wacker has only one driver (TAPI) so hard code it here --- */
  159. iRet = cnctLoadDriver(hhCnct); // driver reports errors
  160. cnctUnlock(hhCnct);
  161. return iRet;
  162. }
  163. #if 0 // mcc 01/06/95 -- hacked in to test Winsock
  164. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  165. * FUNCTION:
  166. * cnctLoadDriver
  167. *
  168. * DESCRIPTION:
  169. * staticly binds to Winsock connection code
  170. *
  171. * ARGUMENTS:
  172. * hhCnct - private connection handle
  173. *
  174. * RETURNS:
  175. * 0=success, else error code
  176. *
  177. */
  178. static int cnctLoadDriver(const HHCNCT hhCnct)
  179. {
  180. if (cnctLoadWinsockDriver(hhCnct) != 0)
  181. {
  182. assert(FALSE);
  183. return CNCT_LOAD_DLL_FAILED;
  184. }
  185. return 0;
  186. }
  187. #endif
  188. #if 1 // mcc 01/05/95 -- this is the "real" Wacker one
  189. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  190. * FUNCTION:
  191. * cnctLoadDriver
  192. *
  193. * DESCRIPTION:
  194. * staticly binds to TAPI connection code
  195. *
  196. * ARGUMENTS:
  197. * hhCnct - private connection handle
  198. *
  199. * RETURNS:
  200. * 0=success, else error code
  201. *
  202. */
  203. static int cnctLoadDriver(const HHCNCT hhCnct)
  204. {
  205. if (hhCnct->hDriver)
  206. return 0;
  207. hhCnct->hDriver = cnctdrvCreate((HCNCT)hhCnct, hhCnct->hSession);
  208. if (hhCnct->hDriver == 0)
  209. {
  210. assert(FALSE);
  211. return CNCT_LOAD_DLL_FAILED;
  212. }
  213. cnctStubAll(hhCnct);
  214. hhCnct->pfDestroy = (int (WINAPI *)(const HDRIVER))cnctdrvDestroy;
  215. hhCnct->pfQueryStatus = (int (WINAPI *)(const HDRIVER))cnctdrvQueryStatus;
  216. hhCnct->pfConnect = (int (WINAPI *)(const HDRIVER, const unsigned int))
  217. cnctdrvConnect;
  218. hhCnct->pfDisconnect = (int (WINAPI *)(const HDRIVER, const unsigned int))
  219. cnctdrvDisconnect;
  220. hhCnct->pfComEvent = (int (WINAPI *)(const HDRIVER, const enum COM_EVENTS))
  221. cnctdrvComEvent;
  222. hhCnct->pfInit = (int (WINAPI *)(const HDRIVER))cnctdrvInit;
  223. hhCnct->pfLoad = (int (WINAPI *)(const HDRIVER))cnctdrvLoad;
  224. hhCnct->pfSave = (int (WINAPI *)(const HDRIVER))cnctdrvSave;
  225. hhCnct->pfSetDestination =
  226. (int (WINAPI *)(const HDRIVER, TCHAR *const, const size_t))
  227. cnctdrvSetDestination;
  228. hhCnct->pfGetComSettingsString = (int (WINAPI *)(const HDRIVER,
  229. LPTSTR pachStr, const size_t cb))cnctdrvGetComSettingsString;
  230. return 0;
  231. }
  232. #endif
  233. #if 0
  234. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  235. * FUNCTION:
  236. * cnctLoadDriver
  237. *
  238. * DESCRIPTION:
  239. * Tries to load the given dll
  240. *
  241. * ARGUMENTS:
  242. * hhCnct - private connection handle
  243. * pachDllName - name of dll to load
  244. *
  245. * RETURNS:
  246. * 0=success, else error code
  247. *
  248. */
  249. static int cnctLoadDriver(const HHCNCT hhCnct, const LPTSTR pachDllName)
  250. {
  251. #define LOADPROC(x,y) \
  252. (FARPROC)x = (fp = GetProcAddress(hhCnct->hModule, y)) ? fp : x
  253. HMODULE hModule;
  254. HDRIVER hDriver;
  255. FARPROC fp;
  256. HDRIVER (WINAPI *pfCreate)(const HCNCT hCnct, const HSESSION hSession);
  257. /* --- Check to see if we've loaded the driver already --- */
  258. if (hhCnct->hDriver && StrCharCmp(hhCnct->achDllName, pachDllName) == 0)
  259. return 0;
  260. /* --- Try to load the given library name --- */
  261. hModule = LoadLibrary(pachDllName);
  262. if (hModule == 0)
  263. {
  264. assert(FALSE);
  265. return CNCT_FIND_DLL_FAILED;
  266. }
  267. /* --- Get the create function --- */
  268. (FARPROC)pfCreate = GetProcAddress(hModule, "cnctwsCreate@8");
  269. if (pfCreate == 0)
  270. {
  271. assert(FALSE);
  272. FreeLibrary(hModule);
  273. return CNCT_LOAD_DLL_FAILED;
  274. }
  275. /* --- Call the init function --- */
  276. hDriver = (*pfCreate)((HCNCT)hhCnct, hhCnct->hSession);
  277. if (hDriver == 0)
  278. {
  279. assert(FALSE);
  280. FreeLibrary(hModule);
  281. return CNCT_LOAD_DLL_FAILED;
  282. }
  283. /* --- If driver initialized, then we can commit to this handle ---*/
  284. if (hhCnct->hModule)
  285. FreeLibrary(hhCnct->hModule);
  286. cnctStubAll(hhCnct);
  287. hhCnct->hModule = hModule;
  288. hhCnct->hDriver = hDriver;
  289. StrCharCopyN(hhCnct->achDllName, pachDllName, MAX_PATH);
  290. /* --- Drivers only required to support a Create function --- */
  291. LOADPROC(hhCnct->pfDestroy, "cnctwsDestroy@4");
  292. LOADPROC(hhCnct->pfQueryStatus, "cnctwsQueryStatus@4");
  293. LOADPROC(hhCnct->pfConnect, "cnctwsConnect@8");
  294. LOADPROC(hhCnct->pfDisconnect, "cnctwsDisconnect@8");
  295. LOADPROC(hhCnct->pfComEvent, "cnctwsComEvent@4");
  296. return 0;
  297. #undef LOADPROC
  298. }
  299. #endif
  300. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  301. * FUNCTION:
  302. * cnctQueryStatus
  303. *
  304. * DESCRIPTION:
  305. * Returns the status of the connection.
  306. *
  307. * ARGUMENTS:
  308. * hCnct - public connection handle
  309. *
  310. * RETURNS:
  311. * status of connection or error code.
  312. *
  313. */
  314. int cnctQueryStatus(const HCNCT hCnct)
  315. {
  316. int iStatus;
  317. const HHCNCT hhCnct = (HHCNCT)hCnct;
  318. if (hhCnct == 0 || hhCnct->pfQueryStatus == NULL)
  319. {
  320. assert(FALSE);
  321. iStatus = CNCT_BAD_HANDLE;
  322. }
  323. else
  324. {
  325. cnctLock(hhCnct);
  326. iStatus = (*hhCnct->pfQueryStatus)(hhCnct->hDriver);
  327. cnctUnlock(hhCnct);
  328. }
  329. return iStatus;
  330. }
  331. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  332. * FUNCTION:
  333. * cnctIsModemConnection
  334. *
  335. * DESCRIPTION:
  336. * Returns if the connection type is a TAPI device.
  337. *
  338. * ARGUMENTS:
  339. * hCnct - public connection handle
  340. *
  341. * RETURNS:
  342. * 1 if the connection is a Modem, 0 if not a modem or error.
  343. *
  344. */
  345. int cnctIsModemConnection(const HCNCT hCnct)
  346. {
  347. int nReturn = 0;
  348. HHDRIVER hhDriver = (HHDRIVER)cnctQueryDriverHdl(hCnct);
  349. //
  350. // See if this connection is with a TAPI device
  351. // (not DIRECT_COM1-DIRECT_COM4, DIRECT_COM_DEVICE,
  352. // or DIRECT_COMWINSOCK)
  353. //
  354. if (!hhDriver)
  355. {
  356. nReturn = -1;
  357. }
  358. else if (!IN_RANGE(hhDriver->dwPermanentLineId, DIRECT_COM1, DIRECT_COM4) &&
  359. hhDriver->dwPermanentLineId != DIRECT_COM_DEVICE &&
  360. hhDriver->dwPermanentLineId != DIRECT_COMWINSOCK)
  361. {
  362. nReturn = 1;
  363. }
  364. return nReturn;
  365. }
  366. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  367. * FUNCTION:
  368. * cnctConnect
  369. *
  370. * DESCRIPTION:
  371. * Establishes a connection.
  372. *
  373. * ARGUMENTS:
  374. * hCnct - public connect handle
  375. * uCnctFlags - how to connect
  376. *
  377. * RETURNS:
  378. * 0=success, or error-code.
  379. *
  380. */
  381. int cnctConnect(const HCNCT hCnct, const unsigned int uCnctFlags)
  382. {
  383. int iStatus;
  384. const HHCNCT hhCnct = (HHCNCT)hCnct;
  385. if (hhCnct == 0)
  386. {
  387. assert(FALSE);
  388. return CNCT_BAD_HANDLE;
  389. }
  390. cnctLock(hhCnct);
  391. iStatus = (*hhCnct->pfConnect)(hhCnct->hDriver, uCnctFlags);
  392. cnctUnlock(hhCnct);
  393. return iStatus;
  394. }
  395. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  396. * FUNCTION:
  397. * cnctDisconnect
  398. *
  399. * DESCRIPTION:
  400. * Terminates a connection
  401. *
  402. * ARGUMENTS:
  403. * hCnct - public connect handle
  404. * uCnctFlags - how to connect
  405. *
  406. * RETURNS:
  407. * 0=success, or error-code.
  408. *
  409. */
  410. int cnctDisconnect(const HCNCT hCnct, const unsigned int uCnctFlags)
  411. {
  412. static BOOL inDisconnect = FALSE;
  413. int iStatus = CNCT_IN_DISCONNECT;
  414. const HHCNCT hhCnct = (HHCNCT)hCnct;
  415. if (hhCnct == 0 || hhCnct->pfDisconnect == NULL)
  416. {
  417. assert(FALSE);
  418. iStatus = CNCT_BAD_HANDLE;
  419. }
  420. else if (!((uCnctFlags & CNCT_XFERABORTCONFIRM) && inDisconnect == TRUE))
  421. {
  422. cnctLock(hhCnct);
  423. inDisconnect = TRUE;
  424. iStatus = (*hhCnct->pfDisconnect)(hhCnct->hDriver, uCnctFlags);
  425. inDisconnect = FALSE;
  426. cnctUnlock(hhCnct);
  427. }
  428. return iStatus;
  429. }
  430. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  431. * FUNCTION:
  432. * cnctInit
  433. *
  434. * DESCRIPTION:
  435. * Initializes the connection driver to a base state
  436. *
  437. * ARGUMENTS:
  438. * hCnct - public connection handle
  439. *
  440. * RETURNS:
  441. * 0=OK
  442. *
  443. */
  444. int cnctInit(const HCNCT hCnct)
  445. {
  446. int iRet;
  447. const HHCNCT hhCnct = (HHCNCT)hCnct;
  448. cnctLock(hhCnct);
  449. iRet = (*hhCnct->pfInit)(hhCnct->hDriver);
  450. cnctUnlock(hhCnct);
  451. return iRet;
  452. }
  453. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  454. * FUNCTION:
  455. * cnctLoad
  456. *
  457. * DESCRIPTION:
  458. * Reads session file values.
  459. *
  460. * ARGUMENTS:
  461. * hCnct - public connection handle
  462. *
  463. * RETURNS:
  464. * 0=OK
  465. *
  466. */
  467. int cnctLoad(const HCNCT hCnct)
  468. {
  469. int iRet;
  470. const HHCNCT hhCnct = (HHCNCT)hCnct;
  471. cnctLock(hhCnct);
  472. iRet = (*hhCnct->pfLoad)(hhCnct->hDriver);
  473. cnctUnlock(hhCnct);
  474. return iRet;
  475. }
  476. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  477. * FUNCTION:
  478. * cnctSave
  479. *
  480. * DESCRIPTION:
  481. * Saves connection stuff to session file.
  482. *
  483. * ARGUMENTS:
  484. * hCnct - public connection handle
  485. *
  486. * RETURNS:
  487. * 0=OK
  488. *
  489. */
  490. int cnctSave(const HCNCT hCnct)
  491. {
  492. int iRet;
  493. const HHCNCT hhCnct = (HHCNCT)hCnct;
  494. cnctLock(hhCnct);
  495. iRet = (*hhCnct->pfSave)(hhCnct->hDriver);
  496. cnctUnlock(hhCnct);
  497. return iRet;
  498. }
  499. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  500. * FUNCTION:
  501. * cnctQueryDriverHdl
  502. *
  503. * DESCRIPTION:
  504. * Return the driver handle.
  505. *
  506. * ARGUMENTS:
  507. * hCnct - public connection handle
  508. *
  509. * RETURNS:
  510. * 0 or error
  511. *
  512. */
  513. HDRIVER cnctQueryDriverHdl(const HCNCT hCnct)
  514. {
  515. const HHCNCT hhCnct = (HHCNCT)hCnct;
  516. return hhCnct->hDriver;
  517. }
  518. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  519. * FUNCTION:
  520. * cnctSetStartTime
  521. *
  522. * DESCRIPTION:
  523. * This function should only be called by the connection driver. It
  524. * records the current system time when the connection is estabalished
  525. * which only the driver really knows.
  526. *
  527. * ARGUMENTS:
  528. * HCNCT hCnct - exteranl connection handle.
  529. *
  530. * RETURNS:
  531. * 0 if everything is OK.
  532. *
  533. */
  534. int cnctSetStartTime(HCNCT hCnct)
  535. {
  536. time_t t;
  537. HHCNCT hhCnct = (HHCNCT)hCnct;
  538. assert(hCnct);
  539. if (hCnct == (HCNCT)0)
  540. return -1;
  541. time(&t);
  542. hhCnct->tStartTime = t;
  543. return 0;
  544. }
  545. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  546. * FUNCTION:
  547. * cnctQueryStartTime
  548. *
  549. * DESCRIPTION:
  550. * Returns the time in C standard time_t format of when the connection
  551. * was established.
  552. *
  553. * ARGUMENTS:
  554. * HCNCT hCnct - external connection handle
  555. * time_t FAR *pTime - pointer to time_t variable for time.
  556. *
  557. * RETURNS:
  558. *
  559. */
  560. int cnctQueryStartTime(const HCNCT hCnct, time_t *pTime)
  561. {
  562. HHCNCT hhCnct;
  563. assert(hCnct && pTime);
  564. if (hCnct == (HCNCT)0)
  565. return -1;
  566. hhCnct = (HHCNCT)hCnct;
  567. *pTime = hhCnct->tStartTime;
  568. return 0;
  569. }
  570. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  571. * FUNCTION:
  572. * cnctQueryElapsedTime
  573. *
  574. * DESCRIPTION:
  575. * Returns the number of seconds since the connection was established.
  576. * This function set *pTime to zero of a connection is not established.
  577. *
  578. * ARGUMENTS:
  579. * HCNCT hCnct - external connection handle
  580. * time_t FAR *pTime - pointer to time_t variable for time.
  581. *
  582. * RETURNS:
  583. * 0 if everything is OK.
  584. *
  585. */
  586. int cnctQueryElapsedTime(HCNCT hCnct, time_t *pTime)
  587. {
  588. int iRet, iStatus;
  589. time_t tTime, tStartTime;
  590. assert(hCnct && pTime);
  591. if (hCnct == (HCNCT)0)
  592. return -1;
  593. if ((iStatus = cnctQueryStatus(hCnct)) != CNCT_STATUS_TRUE)
  594. {
  595. *pTime = (time_t)0;
  596. return 0;
  597. }
  598. iRet = cnctQueryStartTime(hCnct, &tStartTime);
  599. time(&tTime);
  600. *pTime = tTime - tStartTime;
  601. if (*pTime < 0 || *pTime >= 86400) // rollover after 24 hours
  602. {
  603. cnctSetStartTime(hCnct);
  604. *pTime = 0;
  605. }
  606. return 0;
  607. }
  608. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  609. * FUNCTION:
  610. * cnctMessage
  611. *
  612. * DESCRIPTION:
  613. * Calls emuDataIn and gives it the requested string. Useful for
  614. * displaying connected, disconnected message
  615. *
  616. * ARGUMENTS:
  617. * hCnct - public connection handle
  618. * idMsg - rc identifier of message
  619. *
  620. * RETURNS:
  621. * void
  622. *
  623. */
  624. #if FALSE
  625. void cnctMessage(const HCNCT hCnct, const int idMsg)
  626. {
  627. TCHAR ach[256], achFormat[256];
  628. TCHAR *pach, *pachTime, *pachDate;
  629. int i, nSize;
  630. const HHCNCT hhCnct = (HHCNCT)hCnct;
  631. const HEMU hEmu = sessQueryEmuHdl(hhCnct->hSession);
  632. LCID lcId = GetSystemDefaultLCID();
  633. SYSTEMTIME stSysTimeDate;
  634. LPTSTR acPtrs[3];
  635. TCHAR acArg1[100], acArg2[100];
  636. // Load the "====> Connected %1, %2" or "====> Disconnected %1, %2" msg
  637. // from the resource...
  638. //
  639. TCHAR_Fill(ach, TEXT('\0'), sizeof(ach) / sizeof(TCHAR));
  640. if (LoadString(glblQueryDllHinst(), idMsg, achFormat,
  641. sizeof(achFormat) / sizeof(TCHAR)) == 0)
  642. {
  643. assert(FALSE);
  644. return;
  645. }
  646. // Get formats appropriate for the given locale...
  647. //
  648. nSize = GetTimeFormat(lcId, 0, NULL, NULL, NULL, 0);
  649. pachTime = malloc((unsigned int)(nSize+1) * sizeof(TCHAR));
  650. TCHAR_Fill(pachTime, TEXT('\0'), (unsigned int)(nSize+1));
  651. GetLocalTime(&stSysTimeDate);
  652. GetTimeFormat(lcId, 0, &stSysTimeDate, NULL, pachTime, nSize+1);
  653. // NOTE: The 2nd parameter to GetDateFormat() should be DATE_LONGDATE but
  654. // right now that causes the function to return garbage, so for now use
  655. // what works!
  656. //
  657. nSize = GetDateFormat(lcId, 0, NULL, NULL, NULL, 0);
  658. pachDate = malloc((unsigned int)(nSize+1) * sizeof(TCHAR));
  659. TCHAR_Fill(pachDate, TEXT('\0'), (unsigned int)(nSize+1));
  660. GetDateFormat(lcId, 0, &stSysTimeDate, NULL, pachDate, nSize+1);
  661. // Format the string...
  662. //
  663. wsprintf(acArg1, "%s", pachTime);
  664. wsprintf(acArg2, "%s", pachDate);
  665. acPtrs[0] = acArg1;
  666. acPtrs[1] = acArg2;
  667. acPtrs[2] = NULL;
  668. #if defined(USE_FORMATMSG)
  669. FormatMessage(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ARGUMENT_ARRAY,
  670. achFormat, 0, 0, ach, sizeof(ach) / sizeof(TCHAR), acPtrs);
  671. #else
  672. // Hard code until FormatMessage() works!
  673. //
  674. if (idMsg == IDS_CNCT_CLOSE)
  675. wsprintf(ach, "\r\n=====> Disconnected %s, %s", acPtrs[0], acPtrs[1]);
  676. else
  677. wsprintf(ach, "\r\n=====> Connected %s, %s\r\n", acPtrs[0], acPtrs[1]);
  678. #endif
  679. free(pachTime);
  680. pachTime = NULL;
  681. free(pachDate);
  682. pachDate = NULL;
  683. // Display the message on terminal window...
  684. //
  685. pach = ach;
  686. for (i = StrCharGetStrLength(ach); i > 0; --i, pach = StrCharNext(pach))
  687. emuDataIn(hEmu, *pach);
  688. return;
  689. }
  690. #endif
  691. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  692. * FUNCTION:
  693. * cnctSetDestination
  694. *
  695. * DESCRIPTION:
  696. * Sets the destination to be dialed
  697. *
  698. * ARGUMENTS:
  699. * HCNCT hCnct - external connection handle
  700. * char *ach - destination
  701. * size_t cb - sizeof of buffer
  702. *
  703. * RETURNS:
  704. * 0=OK, else error
  705. *
  706. */
  707. int cnctSetDestination(const HCNCT hCnct, TCHAR *const ach, const size_t cb)
  708. {
  709. int iRet;
  710. const HHCNCT hhCnct = (HHCNCT)hCnct;
  711. cnctLock(hhCnct);
  712. iRet = (*hhCnct->pfSetDestination)(hhCnct->hDriver, ach, cb);
  713. cnctUnlock(hhCnct);
  714. return iRet;
  715. }
  716. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  717. * FUNCTION:
  718. * cnctGetComSettingsString
  719. *
  720. * DESCRIPTION:
  721. * Returns a string suitable for use in the com settings portion of the
  722. * status bar.
  723. *
  724. * ARGUMENTS:
  725. * hCnct - public connection handle
  726. * pach - buffer to store string
  727. * cb - max size of buffer
  728. *
  729. * RETURNS:
  730. * 0=OK, else error
  731. *
  732. */
  733. int cnctGetComSettingsString(const HCNCT hCnct, LPTSTR pach, const size_t cb)
  734. {
  735. int iRet;
  736. const HHCNCT hhCnct = (HHCNCT)hCnct;
  737. cnctLock(hhCnct);
  738. iRet = (*hhCnct->pfGetComSettingsString)(hhCnct->hDriver, pach, cb);
  739. cnctUnlock(hhCnct);
  740. return iRet;
  741. }
  742. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  743. * FUNCTION:
  744. * cnctComEvent
  745. *
  746. * DESCRIPTION:
  747. * Calls the driver-specific function to handle notifications from the COM
  748. * driver
  749. *
  750. * ARGUMENTS:
  751. * HCNCT hCnct - external connection handle
  752. *
  753. * RETURNS:
  754. * 0=OK, else error
  755. *
  756. */
  757. int cnctComEvent(const HCNCT hCnct, const enum COM_EVENTS event)
  758. {
  759. int iRet;
  760. const HHCNCT hhCnct = (HHCNCT)hCnct;
  761. cnctLock(hhCnct);
  762. iRet = (*hhCnct->pfComEvent)(hhCnct->hDriver, event);
  763. cnctUnlock(hhCnct);
  764. return iRet;
  765. }