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

790 lines
15 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. espui.c
  5. Abstract:
  6. This module contains
  7. Author:
  8. Dan Knudson (DanKn) 30-Sep-1995
  9. Revision History:
  10. Notes:
  11. --*/
  12. #include "windows.h"
  13. #include "tapi.h"
  14. #include "tspi.h"
  15. #include "stdarg.h"
  16. #include "stdio.h"
  17. #include "stdlib.h"
  18. #include "malloc.h"
  19. #include "string.h"
  20. typedef struct _MYDIALOGPARAMS
  21. {
  22. char *pszTitle;
  23. char *pszDataIn;
  24. TUISPIDLLCALLBACK lpfnUIDLLCallback;
  25. ULONG_PTR ObjectID;
  26. DWORD dwObjectType;
  27. LONG lResult;
  28. } MYDIALOGPARAMS, *PMYDIALOGPARAMS;
  29. HINSTANCE ghInstance;
  30. char szMySection[] = "ESP32";
  31. char szShowProviderXxxDlgs[] = "ShowProviderXxxDlgs";
  32. #if DBG
  33. #define DBGOUT(arg) DbgPrt arg
  34. VOID
  35. DbgPrt(
  36. IN DWORD dwDbgLevel,
  37. IN PUCHAR DbgMessage,
  38. IN ...
  39. );
  40. DWORD gdwDebugLevel;
  41. #else
  42. #define DBGOUT(arg)
  43. #endif
  44. INT_PTR
  45. CALLBACK
  46. GenericDlgProc(
  47. HWND hwnd,
  48. UINT msg,
  49. WPARAM wParam,
  50. LPARAM lParam
  51. );
  52. BOOL
  53. WINAPI
  54. _CRT_INIT(
  55. HINSTANCE hDLL,
  56. DWORD dwReason,
  57. LPVOID lpReserved
  58. );
  59. LONG
  60. PASCAL
  61. ProviderInstall(
  62. char *pszProviderName,
  63. BOOL bNoMultipleInstance
  64. );
  65. BOOL
  66. WINAPI
  67. DllMain(
  68. HANDLE hDLL,
  69. DWORD dwReason,
  70. LPVOID lpReserved
  71. )
  72. {
  73. static HANDLE hInitEvent;
  74. if (!_CRT_INIT (hDLL, dwReason, lpReserved))
  75. {
  76. OutputDebugString ("ESPUI: DllMain: _CRT_INIT() failed\n\r");
  77. }
  78. switch (dwReason)
  79. {
  80. case DLL_PROCESS_ATTACH:
  81. #if DBG
  82. {
  83. HKEY hKey;
  84. DWORD dwDataSize, dwDataType;
  85. TCHAR szTelephonyKey[] =
  86. "Software\\Microsoft\\Windows\\CurrentVersion\\Telephony",
  87. szEsp32DebugLevel[] = "Esp32DebugLevel";
  88. RegOpenKeyEx(
  89. HKEY_LOCAL_MACHINE,
  90. szTelephonyKey,
  91. 0,
  92. KEY_ALL_ACCESS,
  93. &hKey
  94. );
  95. dwDataSize = sizeof (DWORD);
  96. gdwDebugLevel=0;
  97. RegQueryValueEx(
  98. hKey,
  99. szEsp32DebugLevel,
  100. 0,
  101. &dwDataType,
  102. (LPBYTE) &gdwDebugLevel,
  103. &dwDataSize
  104. );
  105. RegCloseKey (hKey);
  106. }
  107. #endif
  108. ghInstance = hDLL;
  109. break;
  110. case DLL_PROCESS_DETACH:
  111. break;
  112. }
  113. return TRUE;
  114. }
  115. LONG
  116. TSPIAPI
  117. TUISPI_lineConfigDialog(
  118. TUISPIDLLCALLBACK lpfnUIDLLCallback,
  119. DWORD dwDeviceID,
  120. HWND hwndOwner,
  121. LPCWSTR lpszDeviceClass
  122. )
  123. {
  124. char buf[64];
  125. MYDIALOGPARAMS params =
  126. {
  127. "TUISPI_lineConfigDialog",
  128. buf,
  129. lpfnUIDLLCallback,
  130. dwDeviceID,
  131. TUISPIDLL_OBJECT_LINEID,
  132. 0
  133. };
  134. wsprintf(
  135. buf,
  136. "devID=%d, devClass='%ws'",
  137. dwDeviceID,
  138. (lpszDeviceClass ? lpszDeviceClass : L"")
  139. );
  140. DialogBoxParam(
  141. ghInstance,
  142. MAKEINTRESOURCE(100),
  143. hwndOwner,
  144. (DLGPROC) GenericDlgProc,
  145. (LPARAM) &params
  146. );
  147. return params.lResult;
  148. }
  149. LONG
  150. TSPIAPI
  151. TUISPI_lineConfigDialogEdit(
  152. TUISPIDLLCALLBACK lpfnUIDLLCallback,
  153. DWORD dwDeviceID,
  154. HWND hwndOwner,
  155. LPCWSTR lpszDeviceClass,
  156. LPVOID const lpDeviceConfigIn,
  157. DWORD dwSize,
  158. LPVARSTRING lpDeviceConfigOut
  159. )
  160. {
  161. char buf[64];
  162. MYDIALOGPARAMS params =
  163. {
  164. "TUISPI_lineConfigDialogEdit",
  165. buf,
  166. lpfnUIDLLCallback,
  167. dwDeviceID,
  168. TUISPIDLL_OBJECT_LINEID,
  169. 0
  170. };
  171. wsprintf(
  172. buf,
  173. "devID=%d, devClass='%ws'",
  174. dwDeviceID,
  175. (lpszDeviceClass ? lpszDeviceClass : L"")
  176. );
  177. DialogBoxParam(
  178. ghInstance,
  179. MAKEINTRESOURCE(100),
  180. hwndOwner,
  181. (DLGPROC) GenericDlgProc,
  182. (LPARAM) &params
  183. );
  184. return params.lResult;
  185. }
  186. LONG
  187. TSPIAPI
  188. TUISPI_phoneConfigDialog(
  189. TUISPIDLLCALLBACK lpfnUIDLLCallback,
  190. DWORD dwDeviceID,
  191. HWND hwndOwner,
  192. LPCWSTR lpszDeviceClass
  193. )
  194. {
  195. char buf[64];
  196. MYDIALOGPARAMS params =
  197. {
  198. "TUISPI_phoneConfigDialog",
  199. buf,
  200. lpfnUIDLLCallback,
  201. dwDeviceID,
  202. TUISPIDLL_OBJECT_PHONEID,
  203. 0
  204. };
  205. wsprintf(
  206. buf,
  207. "devID=%d, devClass='%ws'",
  208. dwDeviceID,
  209. (lpszDeviceClass ? lpszDeviceClass : L"")
  210. );
  211. DialogBoxParam(
  212. ghInstance,
  213. MAKEINTRESOURCE(100),
  214. hwndOwner,
  215. (DLGPROC) GenericDlgProc,
  216. (LPARAM) &params
  217. );
  218. if (params.lResult)
  219. {
  220. params.lResult = PHONEERR_OPERATIONFAILED;
  221. }
  222. return params.lResult;
  223. }
  224. LONG
  225. TSPIAPI
  226. TUISPI_providerConfig(
  227. TUISPIDLLCALLBACK lpfnUIDLLCallback,
  228. HWND hwndOwner,
  229. DWORD dwPermanentProviderID
  230. )
  231. {
  232. char buf[64];
  233. MYDIALOGPARAMS params =
  234. {
  235. "TUISPI_providerConfig",
  236. buf,
  237. lpfnUIDLLCallback,
  238. dwPermanentProviderID,
  239. TUISPIDLL_OBJECT_PROVIDERID,
  240. 0
  241. };
  242. wsprintf (buf, "providerID=%d", dwPermanentProviderID);
  243. DialogBoxParam(
  244. ghInstance,
  245. MAKEINTRESOURCE(100),
  246. hwndOwner,
  247. (DLGPROC) GenericDlgProc,
  248. (LPARAM) &params
  249. );
  250. return params.lResult;
  251. }
  252. LONG
  253. TSPIAPI
  254. TUISPI_providerGenericDialog(
  255. TUISPIDLLCALLBACK lpfnUIDLLCallback,
  256. HTAPIDIALOGINSTANCE htDlgInst,
  257. LPVOID lpParams,
  258. DWORD dwSize,
  259. HANDLE hEvent
  260. )
  261. {
  262. char buf[80];
  263. MYDIALOGPARAMS params =
  264. {
  265. "TUISPI_providerGenericDialog",
  266. buf,
  267. lpfnUIDLLCallback,
  268. (ULONG_PTR) htDlgInst,
  269. TUISPIDLL_OBJECT_DIALOGINSTANCE
  270. };
  271. SetEvent (hEvent);
  272. wsprintf(
  273. buf,
  274. "htDlgInst=x%x, lpParams='%s', dwSize=x%x",
  275. htDlgInst,
  276. lpParams,
  277. dwSize
  278. );
  279. DialogBoxParam(
  280. ghInstance,
  281. MAKEINTRESOURCE(100),
  282. NULL,
  283. (DLGPROC) GenericDlgProc,
  284. (LPARAM) &params
  285. );
  286. return 0;
  287. }
  288. LONG
  289. TSPIAPI
  290. TUISPI_providerGenericDialogData(
  291. HTAPIDIALOGINSTANCE htDlgInst,
  292. LPVOID lpParams,
  293. DWORD dwSize
  294. )
  295. {
  296. DBGOUT((3, "TUISPI_providerGenericDialogData: enter"));
  297. DBGOUT((
  298. 3,
  299. "\thtDlgInst=x%x, lpParams='%s', dwSize=x%x",
  300. htDlgInst,
  301. lpParams,
  302. dwSize
  303. ));
  304. return 0;
  305. }
  306. LONG
  307. TSPIAPI
  308. TUISPI_providerInstall(
  309. TUISPIDLLCALLBACK lpfnUIDLLCallback,
  310. HWND hwndOwner,
  311. DWORD dwPermanentProviderID
  312. )
  313. {
  314. char buf[64];
  315. LONG lResult;
  316. MYDIALOGPARAMS params =
  317. {
  318. "TUISPI_providerInstall",
  319. buf,
  320. lpfnUIDLLCallback,
  321. dwPermanentProviderID,
  322. TUISPIDLL_OBJECT_PROVIDERID,
  323. 0
  324. };
  325. BOOL bShowDlgs = (BOOL) GetProfileInt(
  326. szMySection,
  327. szShowProviderXxxDlgs,
  328. 0
  329. );
  330. if ((lResult = ProviderInstall ("esp32.tsp", TRUE)) == 0)
  331. {
  332. if (bShowDlgs)
  333. {
  334. wsprintf (buf, "providerID=%d", dwPermanentProviderID);
  335. DialogBoxParam(
  336. ghInstance,
  337. MAKEINTRESOURCE(100),
  338. hwndOwner,
  339. (DLGPROC) GenericDlgProc,
  340. (LPARAM) &params
  341. );
  342. lResult = params.lResult;
  343. }
  344. }
  345. else
  346. {
  347. if (bShowDlgs)
  348. {
  349. MessageBox(
  350. hwndOwner,
  351. "ESP32 already installed",
  352. "ESP32.TSP",
  353. MB_OK
  354. );
  355. }
  356. }
  357. return lResult;
  358. }
  359. LONG
  360. TSPIAPI
  361. TUISPI_providerRemove(
  362. TUISPIDLLCALLBACK lpfnUIDLLCallback,
  363. HWND hwndOwner,
  364. DWORD dwPermanentProviderID
  365. )
  366. {
  367. LONG lResult = 0;
  368. if (GetProfileInt (szMySection, szShowProviderXxxDlgs, 0) != 0)
  369. {
  370. char buf[64];
  371. MYDIALOGPARAMS params =
  372. {
  373. "TUISPI_providerRemove",
  374. buf,
  375. lpfnUIDLLCallback,
  376. dwPermanentProviderID,
  377. TUISPIDLL_OBJECT_PROVIDERID,
  378. 0
  379. };
  380. wsprintf (buf, "providerID=%d", dwPermanentProviderID);
  381. DialogBoxParam(
  382. ghInstance,
  383. MAKEINTRESOURCE(100),
  384. hwndOwner,
  385. (DLGPROC) GenericDlgProc,
  386. (LPARAM) &params
  387. );
  388. lResult = params.lResult;
  389. }
  390. return lResult;
  391. }
  392. INT_PTR
  393. CALLBACK
  394. GenericDlgProc(
  395. HWND hwnd,
  396. UINT msg,
  397. WPARAM wParam,
  398. LPARAM lParam
  399. )
  400. {
  401. switch (msg)
  402. {
  403. case WM_INITDIALOG:
  404. {
  405. PMYDIALOGPARAMS pParams = (PMYDIALOGPARAMS) lParam;
  406. SetWindowText (hwnd, pParams->pszTitle);
  407. SetDlgItemText (hwnd, 104, pParams->pszDataIn);
  408. SetWindowLongPtr (hwnd, GWLP_USERDATA, (LONG_PTR) pParams);
  409. break;
  410. }
  411. case WM_COMMAND:
  412. switch (LOWORD(wParam))
  413. {
  414. case IDOK:
  415. case IDCANCEL: // closing by clicking on the standard X on the right hand top corner
  416. case 105: // Error Button
  417. {
  418. PMYDIALOGPARAMS pParams;
  419. pParams = (PMYDIALOGPARAMS) GetWindowLongPtr (hwnd, GWLP_USERDATA);
  420. // return LINEERR_OPERATIONFAILED if "Error" is clicked
  421. // else, return 0
  422. pParams->lResult = (LOWORD(wParam) == 105 ? LINEERR_OPERATIONFAILED : 0);
  423. EndDialog (hwnd, 0);
  424. break;
  425. }
  426. case 102: // send data
  427. {
  428. #define BUFSIZE 32
  429. char buf[BUFSIZE] = "espui data";
  430. PMYDIALOGPARAMS pParams;
  431. pParams = (PMYDIALOGPARAMS) GetWindowLongPtr (hwnd, GWLP_USERDATA);
  432. (*pParams->lpfnUIDLLCallback)(
  433. pParams->ObjectID,
  434. pParams->dwObjectType,
  435. (LPVOID) buf,
  436. BUFSIZE
  437. );
  438. DBGOUT((3, buf));
  439. break;
  440. }
  441. }
  442. break;
  443. case WM_CTLCOLORSTATIC:
  444. SetBkColor ((HDC) wParam, RGB (192,192,192));
  445. return (INT_PTR) GetStockObject (LTGRAY_BRUSH);
  446. case WM_PAINT:
  447. {
  448. PAINTSTRUCT ps;
  449. BeginPaint (hwnd, &ps);
  450. FillRect (ps.hdc, &ps.rcPaint, GetStockObject (LTGRAY_BRUSH));
  451. EndPaint (hwnd, &ps);
  452. break;
  453. }
  454. }
  455. return FALSE;
  456. }
  457. LONG
  458. PASCAL
  459. ProviderInstall(
  460. char *pszProviderName,
  461. BOOL bNoMultipleInstance
  462. )
  463. {
  464. LONG lResult;
  465. //
  466. // If only one installation instance of this provider is
  467. // allowed then we want to check the provider list to see
  468. // if the provider is already installed
  469. //
  470. if (bNoMultipleInstance)
  471. {
  472. LONG (WINAPI *pfnGetProviderList)();
  473. DWORD dwTotalSize, i;
  474. HINSTANCE hTapi32;
  475. LPLINEPROVIDERLIST pProviderList;
  476. LPLINEPROVIDERENTRY pProviderEntry;
  477. //
  478. // Load Tapi32.dll & get a pointer to the lineGetProviderList
  479. // func. We could just statically link with Tapi32.lib and
  480. // avoid the hassle (and this wouldn't have any adverse
  481. // performance effects because of the fact that this
  482. // implementation has a separate ui dll that runs only on the
  483. // client context), but a provider who implemented these funcs
  484. // in it's TSP module would want to do an explicit load like
  485. // we do here to prevent the performance hit of Tapi32.dll
  486. // always getting loaded in Tapisrv.exe's context.
  487. //
  488. if (!(hTapi32 = LoadLibrary ("tapi32.dll")))
  489. {
  490. DBGOUT((
  491. 1,
  492. "LoadLibrary(tapi32.dll) failed, err=%d",
  493. GetLastError()
  494. ));
  495. lResult = LINEERR_OPERATIONFAILED;
  496. goto ProviderInstall_return;
  497. }
  498. if (!((FARPROC) pfnGetProviderList = GetProcAddress(
  499. hTapi32,
  500. (LPCSTR) "lineGetProviderList"
  501. )))
  502. {
  503. DBGOUT((
  504. 1,
  505. "GetProcAddr(lineGetProviderList) failed, err=%d",
  506. GetLastError()
  507. ));
  508. lResult = LINEERR_OPERATIONFAILED;
  509. goto ProviderInstall_unloadTapi32;
  510. }
  511. //
  512. // Loop until we get the full provider list
  513. //
  514. dwTotalSize = sizeof (LINEPROVIDERLIST);
  515. goto ProviderInstall_allocProviderList;
  516. ProviderInstall_getProviderList:
  517. if ((lResult = (*pfnGetProviderList)(0x00020000, pProviderList)) != 0)
  518. {
  519. goto ProviderInstall_freeProviderList;
  520. }
  521. if (pProviderList->dwNeededSize > pProviderList->dwTotalSize)
  522. {
  523. dwTotalSize = pProviderList->dwNeededSize;
  524. LocalFree (pProviderList);
  525. ProviderInstall_allocProviderList:
  526. if (!(pProviderList = LocalAlloc (LPTR, dwTotalSize)))
  527. {
  528. lResult = LINEERR_NOMEM;
  529. goto ProviderInstall_unloadTapi32;
  530. }
  531. pProviderList->dwTotalSize = dwTotalSize;
  532. goto ProviderInstall_getProviderList;
  533. }
  534. //
  535. // Inspect the provider list entries to see if this provider
  536. // is already installed
  537. //
  538. pProviderEntry = (LPLINEPROVIDERENTRY) (((LPBYTE) pProviderList) +
  539. pProviderList->dwProviderListOffset);
  540. for (i = 0; i < pProviderList->dwNumProviders; i++)
  541. {
  542. char *pszInstalledProviderName = ((char *) pProviderList) +
  543. pProviderEntry->dwProviderFilenameOffset,
  544. *psz;
  545. if ((psz = strrchr (pszInstalledProviderName, '\\')))
  546. {
  547. pszInstalledProviderName = psz + 1;
  548. }
  549. if (lstrcmpi (pszInstalledProviderName, pszProviderName) == 0)
  550. {
  551. lResult = LINEERR_NOMULTIPLEINSTANCE;
  552. goto ProviderInstall_freeProviderList;
  553. }
  554. pProviderEntry++;
  555. }
  556. //
  557. // If here then the provider isn't currently installed,
  558. // so do whatever configuration stuff is necessary and
  559. // indicate SUCCESS
  560. //
  561. lResult = 0;
  562. ProviderInstall_freeProviderList:
  563. LocalFree (pProviderList);
  564. ProviderInstall_unloadTapi32:
  565. FreeLibrary (hTapi32);
  566. }
  567. else
  568. {
  569. //
  570. // Do whatever configuration stuff is necessary and return SUCCESS
  571. //
  572. lResult = 0;
  573. }
  574. ProviderInstall_return:
  575. return lResult;
  576. }
  577. #if DBG
  578. VOID
  579. DbgPrt(
  580. IN DWORD dwDbgLevel,
  581. IN PUCHAR lpszFormat,
  582. IN ...
  583. )
  584. /*++
  585. Routine Description:
  586. Formats the incoming debug message & calls DbgPrint
  587. Arguments:
  588. DbgLevel - level of message verboseness
  589. DbgMessage - printf-style format string, followed by appropriate
  590. list of arguments
  591. Return Value:
  592. --*/
  593. {
  594. if (dwDbgLevel <= gdwDebugLevel)
  595. {
  596. char buf[128] = "ESPUI: ";
  597. va_list ap;
  598. va_start(ap, lpszFormat);
  599. vsprintf (&buf[7],
  600. lpszFormat,
  601. ap
  602. );
  603. strcat (buf, "\n");
  604. OutputDebugStringA (buf);
  605. va_end(ap);
  606. }
  607. }
  608. #endif