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.

1094 lines
29 KiB

  1. /*++
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. provider.cpp
  5. Abstract:
  6. TAPI Service Provider functions related to provider info.
  7. TSPI_providerConfig
  8. TSPI_providerEnumDevices
  9. TSPI_providerFreeDialogInstance
  10. TSPI_providerGenericDialogData
  11. TSPI_providerInit
  12. TSPI_providerInstall
  13. TSPI_providerRemove
  14. TSPI_providerShutdown
  15. TSPI_providerUIIdentify
  16. TUISPI_providerConfig
  17. TUISPI_providerInstall
  18. TUISPI_providerRemove
  19. Author:
  20. Nikhil Bobde (NikhilB)
  21. Revision History:
  22. --*/
  23. //
  24. // Include files
  25. //
  26. #include "globals.h"
  27. #include "line.h"
  28. #include "config.h"
  29. #include "q931obj.h"
  30. #include "ras.h"
  31. //
  32. // Global variables
  33. //
  34. DWORD g_dwLineDeviceIDBase = -1;
  35. DWORD g_dwPermanentProviderID = -1;
  36. LINEEVENT g_pfnLineEventProc = NULL;
  37. HANDLE g_hCanUnloadDll = NULL;
  38. HANDLE g_hEventLogSource = NULL;
  39. static HPROVIDER g_hProvider = NULL;
  40. ASYNC_COMPLETION g_pfnCompletionProc = NULL;
  41. // //
  42. // Public procedures //
  43. // //
  44. BOOL
  45. H323IsTSPAlreadyInstalled(void)
  46. /*++
  47. Routine Description:
  48. Searchs registry for previous instance of H323.TSP.
  49. Arguments:
  50. None.
  51. Return Values:
  52. Returns true if TSP already installed.
  53. --*/
  54. {
  55. DWORD i;
  56. HKEY hKey;
  57. LONG lStatus;
  58. DWORD dwNumProviders = 0;
  59. DWORD dwDataSize = sizeof(DWORD);
  60. DWORD dwDataType = REG_DWORD;
  61. LPTSTR pszProvidersKey = TAPI_REGKEY_PROVIDERS;
  62. LPTSTR pszNumProvidersValue = TAPI_REGVAL_NUMPROVIDERS;
  63. TCHAR szName[H323_MAXPATHNAMELEN+1];
  64. TCHAR szPath[H323_MAXPATHNAMELEN+1];
  65. // attempt to open key
  66. lStatus = RegOpenKeyEx(
  67. HKEY_LOCAL_MACHINE,
  68. pszProvidersKey,
  69. 0,
  70. KEY_READ,
  71. &hKey
  72. );
  73. // validate status
  74. if (lStatus != NOERROR)
  75. {
  76. H323DBG(( DEBUG_LEVEL_WARNING,
  77. "error 0x%08lx opening tapi providers key.", lStatus ));
  78. // done
  79. return FALSE;
  80. }
  81. // see if installed bit set
  82. lStatus = RegQueryValueEx(
  83. hKey,
  84. pszNumProvidersValue,
  85. 0,
  86. &dwDataType,
  87. (LPBYTE) &dwNumProviders,
  88. &dwDataSize
  89. );
  90. // validate status
  91. if( lStatus != NOERROR )
  92. {
  93. H323DBG(( DEBUG_LEVEL_WARNING,
  94. "error 0x%08lx determining number of providers.", lStatus ));
  95. // release handle
  96. RegCloseKey(hKey);
  97. // done
  98. return FALSE;
  99. }
  100. // loop through each provider
  101. for (i = 0; i < dwNumProviders; i++)
  102. {
  103. // construct path to provider name
  104. wsprintf(szName, _T("ProviderFileName%d"), i);
  105. // reinitialize size
  106. dwDataSize = sizeof(szPath);
  107. // query the next name
  108. lStatus = RegQueryValueEx(
  109. hKey,
  110. szName,
  111. 0,
  112. &dwDataType,
  113. (unsigned char*)szPath,
  114. &dwDataSize
  115. );
  116. // validate status
  117. if (lStatus == NOERROR)
  118. {
  119. // upper case
  120. _tcsupr(szPath);
  121. // compare path string to h323 provider
  122. if (_tcsstr(szPath, H323_TSPDLL) != NULL)
  123. {
  124. // release handle
  125. RegCloseKey(hKey);
  126. // done
  127. return TRUE;
  128. }
  129. } else {
  130. H323DBG((
  131. DEBUG_LEVEL_WARNING,
  132. "error 0x%08lx loading %s.",
  133. lStatus,
  134. szName
  135. ));
  136. }
  137. }
  138. // release handle
  139. RegCloseKey(hKey);
  140. // done
  141. return FALSE;
  142. }
  143. //
  144. // TSPI procedures
  145. //
  146. /*++
  147. Routine Description:
  148. This function is called by TAPI in response to receipt of a LINE_CREATE
  149. message from the service provider, which allows the dynamic creation of
  150. a new line device.
  151. Arguments:
  152. dwTempID - The temporary device identifier that the service provider
  153. passed to TAPI in the LINE_CREATE message.
  154. dwDeviceID - The device identifier that TAPI assigns to this device if
  155. this function succeeds.
  156. Return Values:
  157. Returns zero if the request is successful or a negative error number if
  158. an error has occurred. Possible return values are:
  159. LINEERR_BADDEVICEID - The specified line device ID is out of range.
  160. LINEERR_NOMEM - Unable to allocate or lock memory.
  161. LINEERR_OPERATIONFAILED - The specified operation failed for unknown
  162. reasons.
  163. --*/
  164. LONG
  165. TSPIAPI
  166. TSPI_providerCreateLineDevice(
  167. DWORD_PTR dwTempID,
  168. DWORD dwDeviceID
  169. )
  170. {
  171. //in the new TSP we don't support creating multiple H323 lines.
  172. //So return success silently but assert in the debug version
  173. _ASSERTE(0);
  174. /*H323DBG(( DEBUG_LEVEL_TRACE,
  175. "creating new device %d (hdLine=0x%08lx).",
  176. dwDeviceID, dwTempID ));
  177. // lock line device using temporary device id
  178. if (!H323GetLineFromIDAndLock(&pLine, (DWORD)dwTempID))
  179. {
  180. H323DBG(( DEBUG_LEVEL_ERROR,
  181. "invalid temp device id 0x%08lx.", dwTempID ));
  182. // failure
  183. return LINEERR_BADDEVICEID;
  184. }
  185. // initialize new line device
  186. H323InitializeLine(pLine, dwDeviceID);
  187. // unlock line
  188. H323UnlockLine(pLine);*/
  189. // success
  190. return NOERROR;
  191. }
  192. /*++
  193. Routine Description:
  194. TAPI.DLL calls this function before TSPI_providerInit to determine the
  195. number of line and phone devices supported by the service provider.
  196. Arguments:
  197. dwPermanentProviderID - Specifies the permanent ID, unique within the
  198. service providers on this system, of the service provider being
  199. initialized.
  200. pdwNumLines - Specifies a far pointer to a DWORD-sized memory location
  201. into which the service provider must write the number of line devices
  202. it is configured to support. TAPI.DLL initializes the value to zero,
  203. so if the service provider fails to write a different value, the
  204. value 0 is assumed.
  205. pdwNumPhones - Specifies a far pointer to a DWORD-sized memory location
  206. into which the service provider must write the number of phone devices
  207. it is configured to support. TAPI.DLL initializes the value to zero,
  208. so if the service provider fails to write a different value, the
  209. value 0 is assumed.
  210. hProvider - Specifies an opaque DWORD-sized value which uniquely identifies
  211. this instance of this service provider during this execution of the
  212. Windows Telephony environment.
  213. pfnLineCreateProc - Specifies a far pointer to the LINEEVENT callback
  214. procedure supplied by TAPI.DLL. The service provider will use this
  215. function to send LINE_CREATE messages when a new line device needs to
  216. be created. This function should not be called to send a LINE_CREATE
  217. message until after the service provider has returned from the
  218. TSPI_providerInit procedure.
  219. pfnPhoneCreateProc - Specifies a far pointer to the PHONEEVENT callback
  220. procedure supplied by TAPI.DLL. The service provider will use this
  221. function to send PHONE_CREATE messages when a new phone device needs
  222. to be created. This function should not be called to send a
  223. PHONE_CREATE message until after the service provider has returned
  224. from the TSPI_providerInit procedure.
  225. Return Values:
  226. Returns zero if the request is successful or a negative error number if
  227. an error has occurred. Possible return values are:
  228. LINEERR_NOMEM - Unable to allocate or lock memory.
  229. LINEERR_OPERATIONFAILED - The specified operation failed for unknown
  230. reasons.
  231. --*/
  232. LONG
  233. TSPIAPI
  234. TSPI_providerEnumDevices(
  235. DWORD dwPermanentProviderID,
  236. PDWORD pdwNumLines,
  237. PDWORD pdwNumPhones,
  238. HPROVIDER hProvider,
  239. LINEEVENT pfnLineCreateProc,
  240. PHONEEVENT pfnPhoneCreateProc
  241. )
  242. {
  243. WSADATA wsaData;
  244. WORD wVersionRequested = H323_WINSOCKVERSION;
  245. UNREFERENCED_PARAMETER(pdwNumPhones); // no phone support
  246. UNREFERENCED_PARAMETER(pfnPhoneCreateProc); // no dynamic phones
  247. UNREFERENCED_PARAMETER(dwPermanentProviderID); // legacy parameter
  248. H323DBG(( DEBUG_LEVEL_TRACE, "TSPI_providerEnumDevices - Entered." ));
  249. // initialize winsock stack
  250. WSAStartup(wVersionRequested, &wsaData);
  251. // save provider handle
  252. g_hProvider = hProvider;
  253. // save line create tapi callback
  254. g_pfnLineEventProc = pfnLineCreateProc;
  255. _ASSERTE(g_pfnLineEventProc);
  256. H323DBG(( DEBUG_LEVEL_VERBOSE, "service provider supports 1 line."));
  257. // report number of interfaces
  258. *pdwNumLines = 1;
  259. H323DBG(( DEBUG_LEVEL_TRACE, "TSPI_providerEnumdevices - Exited." ));
  260. // success
  261. return NOERROR;
  262. }
  263. static LONG H323Initialize (
  264. IN DWORD LineDeviceIDBase)
  265. {
  266. HRESULT hr;
  267. H323DBG(( DEBUG_LEVEL_TRACE, "H323Initialize - Entered." ));
  268. if (!g_pH323Line -> Initialize (LineDeviceIDBase))
  269. {
  270. H323DBG(( DEBUG_LEVEL_ERROR, "init failed for h323 line." ));
  271. return ERROR_GEN_FAILURE;
  272. }
  273. RegistryStart();
  274. g_hCanUnloadDll = H323CreateEvent( NULL, TRUE, TRUE,
  275. _T( "H323TSP_DLLUnloadEvent" ) );
  276. if( g_hCanUnloadDll == NULL )
  277. {
  278. H323DBG(( DEBUG_LEVEL_ERROR, "could not create unloadDLL handle." ));
  279. return ERROR_GEN_FAILURE;
  280. }
  281. #if H323_USE_PRIVATE_IO_THREAD
  282. hr = H323IoThreadStart();
  283. if (hr != S_OK)
  284. return ERROR_GEN_FAILURE;
  285. #endif
  286. H323DBG(( DEBUG_LEVEL_TRACE, "H323Initialize - Exited." ));
  287. return ERROR_SUCCESS;
  288. }
  289. void ReportTSPEvent(
  290. LPCTSTR wszErrorMessage )
  291. {
  292. if( g_hEventLogSource )
  293. {
  294. ReportEvent(
  295. g_hEventLogSource, // handle of event source
  296. EVENTLOG_ERROR_TYPE,// event type
  297. 0, // event category
  298. 0x80000001, // event ID
  299. NULL, // user SID
  300. 1, // string count
  301. 0, // no bytes of raw data
  302. &wszErrorMessage, // array of error strings
  303. NULL); // no raw data
  304. }
  305. }
  306. static
  307. VOID H323Shutdown (void)
  308. {
  309. g_pH323Line -> Shutdown();
  310. RegistryStop();
  311. if( g_hCanUnloadDll != NULL )
  312. {
  313. H323DBG(( DEBUG_LEVEL_WARNING, "waiting for i/o refcount to get 0..." ));
  314. //wait until all the calls have been deleted
  315. WaitForSingleObject(
  316. g_hCanUnloadDll,
  317. 300 * 1000 // Wait for 5 minutes to let everything shutdown.
  318. );
  319. H323DBG ((DEBUG_LEVEL_WARNING, "i/o refcount is 0..."));
  320. CloseHandle( g_hCanUnloadDll );
  321. g_hCanUnloadDll = NULL;
  322. //sleep for 500 ms
  323. Sleep( 500 );
  324. }
  325. #if H323_USE_PRIVATE_IO_THREAD
  326. H323IoThreadStop();
  327. #endif
  328. if( g_hEventLogSource )
  329. {
  330. DeregisterEventSource( g_hEventLogSource );
  331. g_hEventLogSource = NULL;
  332. }
  333. // shutdown
  334. WSACleanup();
  335. }
  336. /*++
  337. Routine Description:
  338. Initializes the service provider, also giving it parameters required for
  339. subsequent operation.
  340. This function is guaranteed to be called before any of the other functions
  341. prefixed with TSPI_line or TSPI_phone except TSPI_lineNegotiateTSPIVersion.
  342. It is strictly paired with a subsequent call to TSPI_providerShutdown. It
  343. is the caller's reponsibility to ensure proper pairing.
  344. Note that a service provider should perform as many consistency checks as
  345. is practical at the time TSPI_providerInit is called to ensure that it is
  346. ready to run. Some consistency or installation errors, however, may not be
  347. detectable until the operation is attempted. The error LINEERR_NODRIVER can
  348. be used to report such non-specific errors at the time they are detected.
  349. There is no directly corresponding function at the TAPI level. At that
  350. level, multiple different usage instances can be outstanding, with an
  351. "application handle" returned to identify the instance in subsequent
  352. operations. At the TSPI level, the interface architecture supports only a
  353. single usage instance for each distinct service provider.
  354. A new parameter, lpdwTSPIOptions, is added to this function. This parameter
  355. allows the service provider to return bits indicating optional behaviors
  356. desired of TAPI. TAPI sets the options DWORD to 0 before calling
  357. TSPI_providerInit, so if the service provider doesn't want any of these
  358. options, it can just leave the DWORD set to 0.
  359. At this time, only one bit is defined to be returned through this pointer:
  360. LINETSPIOPTION_NONREENTRANT. The service provider sets this bit if it is
  361. not designed for fully pre-emptive, multithreaded, multitasking,
  362. multiprocessor operation (e.g., updating of global data protected by
  363. mutexes). When this bit is set, TAPI will only make one call at a time to
  364. the service provider; it will not call any other entry point, nor that
  365. entry point again, until the service provider returns from the original
  366. function call. Without this bit set, TAPI may call into multiple service
  367. provider entry points, including multiple times to the same entry point,
  368. simultaneously (actually simultaneously in a multiprocessor system). Note:
  369. TAPI will not serialize access to TSPI functions that display a dialog
  370. (TUISPI_lineConfigDialog, TUISPI_lineConfigDialogEdit,
  371. TUISPI_phoneConfigDialog, TUISPI_providerConfig, TUISPI_providerInstall,
  372. TUISPI_providerRemove) so that they do not block other TSPI functions
  373. from being called; the service provider must include internal protection
  374. on these functions.
  375. Arguments:
  376. dwTSPIVersion - Specifies the version of the TSPI definition under which
  377. this function must operate. The caller may use
  378. TSPI_lineNegotiateTSPIVersion with the special dwDeviceID
  379. INITIALIZE_NEGOTIATION to negotiate a version that is guaranteed to be
  380. acceptible to the service provider.
  381. dwPermanentProviderID - Specifies the permanent ID, unique within the
  382. service providers on this system, of the service provider being
  383. initialized.
  384. dwLineDeviceIDBase - Specifies the lowest device ID for the line devices
  385. supported by this service provider.
  386. dwPhoneDeviceIDBase - Specifies the lowest device ID for the phone devices
  387. supported by this service provider.
  388. dwNumLines - Specifies how many line devices this service provider
  389. supports.
  390. dwNumPhones - Specifies how many line devices this service provider
  391. supports.
  392. pfnCompletionProc - Specifies the procedure the service provider calls to
  393. report completion of all asynchronously operating procedures on line
  394. and phone devices.
  395. pdwTSPIOptions - A pointer to a DWORD-sized memory location, into which
  396. the service provider may write a value specifying LINETSPIOPTIONS_
  397. values.
  398. Return Values:
  399. Returns zero if the function is successful, or a negative error number if
  400. an error has occurred. Possible return values are as follows:
  401. LINEERR_INCOMPATIBLEAPIVERSION - The application requested an API
  402. version or version range that is either incompatible or cannot be
  403. supported by the Telephony API implementation and/or corresponding
  404. service provider.
  405. LINEERR_NOMEM - Unable to allocate or lock memory.
  406. LINEERR_OPERATIONFAILED - The specified operation failed for unknown
  407. reasons.
  408. LINEERR_RESOURCEUNAVAIL - Insufficient resources to complete the
  409. operation.
  410. --*/
  411. LONG
  412. TSPIAPI
  413. TSPI_providerInit(
  414. DWORD dwTSPIVersion,
  415. DWORD dwPermanentProviderID,
  416. DWORD dwLineDeviceIDBase,
  417. DWORD dwPhoneDeviceIDBase,
  418. DWORD_PTR dwNumLines,
  419. DWORD_PTR dwNumPhones,
  420. ASYNC_COMPLETION pfnCompletionProc,
  421. LPDWORD pdwTSPIOptions
  422. )
  423. {
  424. LONG dwStatus;
  425. UNREFERENCED_PARAMETER (dwNumLines); // legacy parameter
  426. UNREFERENCED_PARAMETER (dwNumPhones); // legacy parameter
  427. UNREFERENCED_PARAMETER (dwPhoneDeviceIDBase); // no phone support
  428. UNREFERENCED_PARAMETER (pdwTSPIOptions); // already thread-safe
  429. #if DBG
  430. // Register for trace output.
  431. TRACELogRegister(_T("h323tsp"));
  432. #else
  433. OpenLogFile();
  434. #endif
  435. // make sure this is a version we support
  436. if (!H323ValidateTSPIVersion(dwTSPIVersion))
  437. {
  438. H323DBG(( DEBUG_LEVEL_ERROR,
  439. "provider init::incompatible tspi version." ));
  440. // incompatible api version
  441. return LINEERR_INCOMPATIBLEAPIVERSION;
  442. }
  443. dwStatus = H323Initialize (dwLineDeviceIDBase);
  444. if (dwStatus == ERROR_SUCCESS)
  445. {
  446. // save global service provider info
  447. // we don't store dwTSPIVersion, because our behavior does not change based
  448. // on any negotiated version.
  449. // if this changes in the future, then we will record the negotiated version.
  450. g_pfnCompletionProc = pfnCompletionProc;
  451. _ASSERTE( g_pfnCompletionProc );
  452. g_dwLineDeviceIDBase = dwLineDeviceIDBase;
  453. g_dwPermanentProviderID = dwPermanentProviderID;
  454. }
  455. else
  456. {
  457. H323Shutdown();
  458. }
  459. return dwStatus;
  460. }
  461. LONG
  462. TSPIAPI
  463. TSPI_providerShutdown(
  464. DWORD dwTSPIVersion,
  465. DWORD dwPermanentProviderID
  466. )
  467. /*++
  468. Routine Description:
  469. Shuts down the service provider. The service provider should terminate
  470. any activities it has in progress and release any resources it has
  471. allocated.
  472. Arguments:
  473. dwTSPIVersion - Specifies the version of the TSPI definition under which
  474. this function must operate. The caller may use
  475. TSPI_lineNegotiateTSPIVersion or TSPI_phoneNegotiateTSPIVersion with
  476. the special dwDeviceID INITIALIZE_NEGOTIATION to negotiate a version
  477. that is guaranteed to be acceptible to the service provider.
  478. dwPermanentProviderID - Specifies the permanent ID, unique within the
  479. service providers on this system, of the service provider being
  480. shut down.
  481. Return Values:
  482. Returns zero if the function is successful, or a negative error number
  483. if an error has occurred. Possible return values are as follows:
  484. LINEERR_INCOMPATIBLEAPIVERSION - The application requested an API
  485. version or version range that is either incompatible or cannot be
  486. supported by the Telephony API implementation and/or corresponding
  487. service provider.
  488. LINEERR_NOMEM - Unable to allocate or lock memory.
  489. LINEERR_OPERATIONFAILED - The specified operation failed for unknown
  490. reasons.
  491. --*/
  492. {
  493. UNREFERENCED_PARAMETER(dwPermanentProviderID); // legacy parameter
  494. H323DBG(( DEBUG_LEVEL_TRACE, "TSPI_providerShutdown - Entered." ));
  495. // make sure this is a version we support
  496. if (!H323ValidateTSPIVersion(dwTSPIVersion))
  497. {
  498. H323DBG(( DEBUG_LEVEL_ERROR, "invalid tspi version." ));
  499. // failure
  500. return LINEERR_INCOMPATIBLEAPIVERSION;
  501. }
  502. H323Shutdown();
  503. H323DBG(( DEBUG_LEVEL_TRACE, "TSPI_providerShutdown - Exited." ));
  504. return ERROR_SUCCESS;
  505. }
  506. LONG
  507. TSPIAPI
  508. TSPI_providerInstall(
  509. HWND hwndOwner,
  510. DWORD dwPermanentProviderID
  511. )
  512. /*++
  513. Routine Description:
  514. The TSPI_providerInstall function is obsolete. TAPI version 1.4
  515. or earlier service providers can implement this TSPI function.
  516. TAPI version 2.0 or later TSPs implement TUISPI_providerInstall.
  517. Arguments:
  518. hwndOwner - The handle of the parent window in which the function
  519. can create any dialog box windows that are required during
  520. installation.
  521. dwPermanentProviderID - The service provider's permanent provider
  522. identifier.
  523. Return Values:
  524. Always returns NOERROR.
  525. --*/
  526. {
  527. UNREFERENCED_PARAMETER(hwndOwner);
  528. UNREFERENCED_PARAMETER(dwPermanentProviderID);
  529. // success
  530. return NOERROR;
  531. }
  532. LONG
  533. TSPIAPI
  534. TSPI_providerRemove(
  535. HWND hwndOwner,
  536. DWORD dwPermanentProviderID
  537. )
  538. /*++
  539. Routine Description:
  540. The TSPI_providerRemove function is obsolete. TAPI version 1.4 or
  541. earlier service providers can implement this TSPI function. TAPI
  542. version 2.0 or later TSPs implement TUISPI_providerRemove.
  543. Arguments:
  544. hwndOwner - The handle of the parent window in which the function
  545. can create any dialog box windows that are required during
  546. installation.
  547. dwPermanentProviderID - The service provider's permanent provider
  548. identifier.
  549. Return Values:
  550. Always returns NOERROR.
  551. --*/
  552. {
  553. UNREFERENCED_PARAMETER(hwndOwner);
  554. UNREFERENCED_PARAMETER(dwPermanentProviderID);
  555. H323DBG(( DEBUG_LEVEL_TRACE, "TSPI_lineTSPIProviderRemove - Entered." ));
  556. H323DBG(( DEBUG_LEVEL_TRACE, "TSPI_lineTSPIProviderRemove - Exited." ));
  557. // success
  558. return NOERROR;
  559. }
  560. LONG
  561. TSPIAPI
  562. TSPI_providerUIIdentify(
  563. LPWSTR pwszUIDLLName
  564. )
  565. /*++
  566. Routine Description:
  567. The TSPI_providerUIIdentify function extracts from the service
  568. provider the fully qualified path to load the service provider's
  569. UI DLL component.
  570. Implementation is mandatory if the service provider implements
  571. any UI DLL functions.
  572. Arguments:
  573. pwszUIDLLName - Pointer to a block of memory at least MAX_PATH
  574. in length, into which the service provider must copy a NULL-
  575. terminated string specifying the fully-qualified path for the
  576. DLL containing the service provider functions which must execute
  577. in the process of the calling application.
  578. Return Values:
  579. Always returns NOERROR.
  580. --*/
  581. {
  582. H323DBG(( DEBUG_LEVEL_TRACE, "TSPI_ProviderUIIdentify - Entered." ));
  583. // copy name of our dll as ui dll
  584. lstrcpyW(pwszUIDLLName,H323_UIDLL);
  585. H323DBG(( DEBUG_LEVEL_TRACE, "TSPI_ProviderUIIdentify - Exited." ));
  586. // success
  587. return NOERROR;
  588. }
  589. /*++
  590. Routine Description:
  591. Implementation of the TUISPI_providerInstall function is the
  592. service provider's opportunity to install any additional
  593. "pieces" of the provider into the right directories (or at
  594. least verifying that they're there) and set up registry entries
  595. the provider needs.
  596. Arguments:
  597. pfnUIDLLCallback - Pointer to a function the UI DLL can call to
  598. communicate with the service provider DLL to obtain information
  599. needed to display the dialog box.
  600. hwndOwner - The handle of the parent window in which the function
  601. can create any dialog box windows that are required during
  602. installation.
  603. dwPermanentProviderID - The service provider's permanent provider
  604. identifier.
  605. Return Values:
  606. Returns zero if the function is successful, or a negative error number
  607. if an error has occurred. Possible return values are as follows:
  608. LINEERR_NOMEM - Unable to allocate or lock memory.
  609. LINEERR_NOMULTIPLEINSTANCE - A telephony service provider which
  610. does not support multiple instances is listed more than once
  611. in the [Providers] section in the registry. The application
  612. LINEERR_OPERATIONFAILED - The specified operation failed for unknown
  613. reasons.
  614. --*/
  615. LONG
  616. TSPIAPI
  617. TUISPI_providerInstall(
  618. TUISPIDLLCALLBACK pfnUIDLLCallback,
  619. HWND hwndOwner,
  620. DWORD dwPermanentProviderID
  621. )
  622. {
  623. HKEY hKey;
  624. HKEY hKeyTSP;
  625. LONG lStatus;
  626. LPTSTR pszKey;
  627. UNREFERENCED_PARAMETER(pfnUIDLLCallback);
  628. UNREFERENCED_PARAMETER(hwndOwner);
  629. UNREFERENCED_PARAMETER(dwPermanentProviderID);
  630. H323DBG(( DEBUG_LEVEL_TRACE, "TUISPI_providerInstall - Entered." ));
  631. // check for previous instance
  632. if (H323IsTSPAlreadyInstalled())
  633. {
  634. // cannot be installed twice
  635. return LINEERR_NOMULTIPLEINSTANCE;
  636. }
  637. // set key to h323
  638. pszKey = H323_REGKEY_ROOT;
  639. // attempt to open key
  640. lStatus = RegOpenKeyEx(
  641. HKEY_LOCAL_MACHINE,
  642. pszKey,
  643. 0,
  644. KEY_READ,
  645. &hKey
  646. );
  647. // validate status
  648. if( lStatus == NOERROR )
  649. {
  650. H323DBG((DEBUG_LEVEL_TRACE,
  651. "successfully installed H.323 provider." ));
  652. // release handle
  653. RegCloseKey(hKey);
  654. H323DBG(( DEBUG_LEVEL_TRACE, "TUISPI_providerInstall - Exited." ));
  655. // success
  656. return NOERROR;
  657. }
  658. // set key to windows
  659. pszKey = REGSTR_PATH_WINDOWS_CURRENTVERSION;
  660. // attempt to open key
  661. lStatus = RegOpenKeyEx(
  662. HKEY_LOCAL_MACHINE,
  663. pszKey,
  664. 0,
  665. KEY_WRITE,
  666. &hKey
  667. );
  668. // validate status
  669. if( lStatus != NOERROR )
  670. {
  671. H323DBG(( DEBUG_LEVEL_ERROR,
  672. "error 0x%08lx opening windows registry key.", lStatus ));
  673. // operation failed
  674. return LINEERR_OPERATIONFAILED;
  675. }
  676. // attempt to create key
  677. lStatus = RegCreateKey(
  678. hKey,
  679. H323_SUBKEY,
  680. &hKeyTSP
  681. );
  682. // validate status
  683. if (lStatus != NOERROR)
  684. {
  685. H323DBG(( DEBUG_LEVEL_ERROR,
  686. "error 0x%08lx creating tsp registry key.", lStatus ));
  687. // release handle
  688. RegCloseKey(hKey);
  689. // operation failed
  690. return LINEERR_OPERATIONFAILED;
  691. }
  692. H323DBG(( DEBUG_LEVEL_TRACE, "successfully installed H.323 provider." ));
  693. // release handle
  694. RegCloseKey(hKeyTSP);
  695. // release handle
  696. RegCloseKey(hKey);
  697. H323DBG(( DEBUG_LEVEL_TRACE, "TUISPI_providerInstall - Exited." ));
  698. // success
  699. return NOERROR;
  700. }
  701. LONG
  702. TSPIAPI
  703. TUISPI_providerRemove(
  704. TUISPIDLLCALLBACK pfnUIDLLCallback,
  705. HWND hwndOwner,
  706. DWORD dwPermanentProviderID
  707. )
  708. /*++
  709. Routine Description:
  710. The TUISPI_providerRemove function asks the user to confirm
  711. elimination of the service provider.
  712. It is the responsibility of the service provider to remove any
  713. registry entries that the service provider added at addProvider
  714. time, as well as any other modules and files that are no longer
  715. needed.
  716. Arguments:
  717. pfnUIDLLCallback - Pointer to a function the UI DLL can call to
  718. communicate with the service provider DLL to obtain information
  719. needed to display the dialog box.
  720. hwndOwner - The handle of the parent window in which the function
  721. can create any dialog box windows that are required during
  722. removal.
  723. dwPermanentProviderID - The service provider's permanent provider
  724. identifier.
  725. Return Values:
  726. Returns zero if the function is successful, or a negative error number
  727. if an error has occurred. Possible return values are as follows:
  728. LINEERR_NOMEM - Unable to allocate or lock memory.
  729. LINEERR_OPERATIONFAILED - The specified operation failed for unknown
  730. reasons.
  731. --*/
  732. {
  733. HKEY hKey;
  734. LONG lStatus;
  735. LPTSTR pszKey;
  736. UNREFERENCED_PARAMETER(pfnUIDLLCallback);
  737. UNREFERENCED_PARAMETER(hwndOwner);
  738. UNREFERENCED_PARAMETER(dwPermanentProviderID);
  739. // set key to h323
  740. pszKey = H323_REGKEY_ROOT;
  741. H323DBG(( DEBUG_LEVEL_FORCE, "TUISPI_providerRemove - Entered." ));
  742. // attempt to open key
  743. lStatus = RegOpenKeyEx(
  744. HKEY_LOCAL_MACHINE,
  745. pszKey,
  746. 0,
  747. KEY_READ,
  748. &hKey
  749. );
  750. // validate status
  751. if (lStatus != NOERROR)
  752. {
  753. H323DBG ((DEBUG_LEVEL_TRACE, "successfully removed H.323 provider."));
  754. H323DBG ((DEBUG_LEVEL_TRACE, "TUISPI_providerRemove - Exited."));
  755. // success
  756. return NOERROR;
  757. }
  758. // release handle
  759. RegCloseKey(hKey);
  760. // set key to windows
  761. pszKey = REGSTR_PATH_WINDOWS_CURRENTVERSION;
  762. // attempt to open key
  763. lStatus = RegOpenKeyEx(
  764. HKEY_LOCAL_MACHINE,
  765. pszKey,
  766. 0,
  767. KEY_WRITE,
  768. &hKey
  769. );
  770. // validate status
  771. if (lStatus != NOERROR)
  772. {
  773. H323DBG(( DEBUG_LEVEL_ERROR,
  774. "error 0x%08lx opening windows registry key.", lStatus ));
  775. // operation failed
  776. return LINEERR_OPERATIONFAILED;
  777. }
  778. // attempt to delete key
  779. lStatus = RegDeleteKey(
  780. hKey,
  781. H323_SUBKEY
  782. );
  783. // validate status
  784. if (lStatus != NOERROR)
  785. {
  786. H323DBG(( DEBUG_LEVEL_ERROR,
  787. "error 0x%08lx deleting tsp registry key.", lStatus ));
  788. // release handle
  789. RegCloseKey(hKey);
  790. // operation failed
  791. return LINEERR_OPERATIONFAILED;
  792. }
  793. H323DBG(( DEBUG_LEVEL_FORCE, "successfully removed H.323 provider." ));
  794. // release handle
  795. RegCloseKey(hKey);
  796. H323DBG(( DEBUG_LEVEL_TRACE, "TUISPI_providerRemove - Exited." ));
  797. // success
  798. return NOERROR;
  799. }