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.

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