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.

758 lines
19 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. registry.c
  5. Abstract:
  6. Routines for reading registry configuration.
  7. Environment:
  8. User Mode - Win32
  9. --*/
  10. ///////////////////////////////////////////////////////////////////////////////
  11. // //
  12. // Include files //
  13. // //
  14. ///////////////////////////////////////////////////////////////////////////////
  15. #include "globals.h"
  16. #include "registry.h"
  17. #include "termcaps.h"
  18. ///////////////////////////////////////////////////////////////////////////////
  19. // //
  20. // Global variables //
  21. // //
  22. ///////////////////////////////////////////////////////////////////////////////
  23. HKEY g_hKey = NULL;
  24. H323_REGISTRY_SETTINGS g_RegistrySettings;
  25. ///////////////////////////////////////////////////////////////////////////////
  26. // //
  27. // Public procedures //
  28. // //
  29. ///////////////////////////////////////////////////////////////////////////////
  30. BOOL
  31. H323SetDefaultConfig(
  32. )
  33. /*++
  34. Routine Description:
  35. Changes configuration settings back to defaults.
  36. Arguments:
  37. None.
  38. Return Values:
  39. Returns true if successful.
  40. --*/
  41. {
  42. #if DBG
  43. // initialize debug settings to defaults
  44. g_RegistrySettings.dwLogType = H323_DEBUG_LOGTYPE;
  45. g_RegistrySettings.dwLogLevel = H323_DEBUG_LOGLEVEL;
  46. g_RegistrySettings.dwH245LogLevel = g_RegistrySettings.dwLogLevel;
  47. g_RegistrySettings.dwH225LogLevel = g_RegistrySettings.dwLogLevel;
  48. g_RegistrySettings.dwQ931LogLevel = g_RegistrySettings.dwLogLevel;
  49. g_RegistrySettings.dwLinkLogLevel = g_RegistrySettings.dwLogLevel;
  50. // copy default debug log file name
  51. lstrcpy(g_RegistrySettings.szLogFile, H323_DEBUG_LOGFILE);
  52. #endif // DBG
  53. // initialize alerting timeout to default
  54. g_RegistrySettings.dwQ931AlertingTimeout = 0;
  55. // set alerting timeout
  56. CC_SetCallControlTimeout(
  57. CC_Q931_ALERTING_TIMEOUT,
  58. g_RegistrySettings.dwQ931AlertingTimeout
  59. );
  60. // initialize call signalling port to default
  61. g_RegistrySettings.dwQ931CallSignallingPort = CC_H323_HOST_CALL;
  62. // initialize g711 audio codec settings
  63. g_RegistrySettings.dwG711MillisecondsPerPacket =
  64. G711_DEFAULT_MILLISECONDS_PER_PACKET
  65. ;
  66. // initialize g723 audio codec settings
  67. g_RegistrySettings.dwG723MillisecondsPerPacket =
  68. G723_DEFAULT_MILLISECONDS_PER_PACKET
  69. ;
  70. // success
  71. return TRUE;
  72. }
  73. BOOL
  74. H323GetConfigFromRegistry(
  75. )
  76. /*++
  77. Routine Description:
  78. Loads registry settings for service provider.
  79. Arguments:
  80. None.
  81. Return Values:
  82. Returns true if successful.
  83. --*/
  84. {
  85. LONG lStatus = ERROR_SUCCESS;
  86. CHAR szAddr[H323_MAXDESTNAMELEN];
  87. DWORD dwValue;
  88. DWORD dwValueSize;
  89. DWORD dwValueType;
  90. LPSTR pszValue;
  91. // see if key open
  92. if (g_hKey == NULL) {
  93. // open registry subkey
  94. lStatus = RegOpenKeyEx(
  95. HKEY_LOCAL_MACHINE,
  96. H323_REGKEY_ROOT,
  97. 0,
  98. KEY_READ,
  99. &g_hKey
  100. );
  101. }
  102. // validate return code
  103. if (lStatus != ERROR_SUCCESS) {
  104. H323DBG((
  105. DEBUG_LEVEL_WARNING,
  106. "error 0x%08lx opening tsp registry key.\n",
  107. lStatus
  108. ));
  109. // success
  110. return TRUE;
  111. }
  112. #if DBG
  113. // do not support modifying log type via registry
  114. g_RegistrySettings.dwLogType = H323_DEBUG_LOGTYPE;
  115. // initialize value name
  116. pszValue = H323_REGVAL_DEBUGLEVEL;
  117. // initialize type
  118. dwValueType = REG_DWORD;
  119. dwValueSize = sizeof(DWORD);
  120. // query for registry value
  121. lStatus = RegQueryValueEx(
  122. g_hKey,
  123. pszValue,
  124. NULL,
  125. &dwValueType,
  126. (LPBYTE)&g_RegistrySettings.dwLogLevel,
  127. &dwValueSize
  128. );
  129. // validate return code
  130. if (lStatus != ERROR_SUCCESS) {
  131. // copy default value into global settings
  132. g_RegistrySettings.dwLogLevel = H323_DEBUG_LOGLEVEL;
  133. }
  134. // initialize value name
  135. pszValue = H245_REGVAL_DEBUGLEVEL;
  136. // initialize type
  137. dwValueType = REG_DWORD;
  138. dwValueSize = sizeof(DWORD);
  139. // query for registry value
  140. lStatus = RegQueryValueEx(
  141. g_hKey,
  142. pszValue,
  143. NULL,
  144. &dwValueType,
  145. (LPBYTE)&g_RegistrySettings.dwH245LogLevel,
  146. &dwValueSize
  147. );
  148. // validate return code
  149. if (lStatus != ERROR_SUCCESS) {
  150. // copy default value into global settings
  151. g_RegistrySettings.dwH245LogLevel = g_RegistrySettings.dwLogLevel;
  152. }
  153. // initialize value name
  154. pszValue = H225_REGVAL_DEBUGLEVEL;
  155. // initialize type
  156. dwValueType = REG_DWORD;
  157. dwValueSize = sizeof(DWORD);
  158. // query for registry value
  159. lStatus = RegQueryValueEx(
  160. g_hKey,
  161. pszValue,
  162. NULL,
  163. &dwValueType,
  164. (LPBYTE)&g_RegistrySettings.dwH225LogLevel,
  165. &dwValueSize
  166. );
  167. // validate return code
  168. if (lStatus != ERROR_SUCCESS) {
  169. // copy default value into global settings
  170. g_RegistrySettings.dwH225LogLevel = g_RegistrySettings.dwLogLevel;
  171. }
  172. // initialize value name
  173. pszValue = Q931_REGVAL_DEBUGLEVEL;
  174. // initialize type
  175. dwValueType = REG_DWORD;
  176. dwValueSize = sizeof(DWORD);
  177. // query for registry value
  178. lStatus = RegQueryValueEx(
  179. g_hKey,
  180. pszValue,
  181. NULL,
  182. &dwValueType,
  183. (LPBYTE)&g_RegistrySettings.dwQ931LogLevel,
  184. &dwValueSize
  185. );
  186. // validate return code
  187. if (lStatus != ERROR_SUCCESS) {
  188. // copy default value into global settings
  189. g_RegistrySettings.dwQ931LogLevel = g_RegistrySettings.dwLogLevel;
  190. }
  191. // initialize value name
  192. pszValue = LINK_REGVAL_DEBUGLEVEL;
  193. // initialize type
  194. dwValueType = REG_DWORD;
  195. dwValueSize = sizeof(DWORD);
  196. // query for registry value
  197. lStatus = RegQueryValueEx(
  198. g_hKey,
  199. pszValue,
  200. NULL,
  201. &dwValueType,
  202. (LPBYTE)&g_RegistrySettings.dwLinkLogLevel,
  203. &dwValueSize
  204. );
  205. // validate return code
  206. if (lStatus != ERROR_SUCCESS) {
  207. // copy default value into global settings
  208. g_RegistrySettings.dwLinkLogLevel = g_RegistrySettings.dwLogLevel;
  209. }
  210. // initialize value name
  211. pszValue = H323_REGVAL_DEBUGLOG;
  212. // initialize type
  213. dwValueType = REG_SZ;
  214. dwValueSize = sizeof(g_RegistrySettings.szLogFile);
  215. // query for registry value
  216. lStatus = RegQueryValueEx(
  217. g_hKey,
  218. pszValue,
  219. NULL,
  220. &dwValueType,
  221. g_RegistrySettings.szLogFile,
  222. &dwValueSize
  223. );
  224. // validate return code
  225. if (lStatus != ERROR_SUCCESS) {
  226. // copy default value into global settings
  227. lstrcpy(g_RegistrySettings.szLogFile, H323_DEBUG_LOGFILE);
  228. }
  229. #endif // DBG
  230. // initialize value name
  231. pszValue = H323_REGVAL_CALLSIGNALLINGPORT;
  232. // initialize type
  233. dwValueType = REG_DWORD;
  234. dwValueSize = sizeof(DWORD);
  235. // query for registry value
  236. lStatus = RegQueryValueEx(
  237. g_hKey,
  238. pszValue,
  239. NULL,
  240. &dwValueType,
  241. (LPBYTE)&g_RegistrySettings.dwQ931CallSignallingPort,
  242. &dwValueSize
  243. );
  244. // validate return code
  245. if (lStatus != ERROR_SUCCESS) {
  246. // copy default value into global settings
  247. g_RegistrySettings.dwQ931CallSignallingPort = CC_H323_HOST_CALL;
  248. }
  249. H323DBG((
  250. DEBUG_LEVEL_VERBOSE,
  251. "using call signalling port %d.\n",
  252. g_RegistrySettings.dwQ931CallSignallingPort
  253. ));
  254. // initialize value name
  255. pszValue = H323_REGVAL_Q931ALERTINGTIMEOUT;
  256. // initialize type
  257. dwValueType = REG_DWORD;
  258. dwValueSize = sizeof(DWORD);
  259. // query for registry value
  260. lStatus = RegQueryValueEx(
  261. g_hKey,
  262. pszValue,
  263. NULL,
  264. &dwValueType,
  265. (LPBYTE)&g_RegistrySettings.dwQ931AlertingTimeout,
  266. &dwValueSize
  267. );
  268. // validate return code
  269. if (lStatus == ERROR_SUCCESS) {
  270. H323DBG((
  271. DEBUG_LEVEL_VERBOSE,
  272. "using Q931 timeout of %d milliseconds.\n",
  273. g_RegistrySettings.dwQ931AlertingTimeout
  274. ));
  275. } else {
  276. H323DBG((
  277. DEBUG_LEVEL_VERBOSE,
  278. "using default Q931 timeout.\n"
  279. ));
  280. // copy default value into global settings
  281. g_RegistrySettings.dwQ931AlertingTimeout = 0;
  282. }
  283. // set alerting timeout
  284. CC_SetCallControlTimeout(
  285. CC_Q931_ALERTING_TIMEOUT,
  286. g_RegistrySettings.dwQ931AlertingTimeout
  287. );
  288. // initialize value name
  289. pszValue = H323_REGVAL_G711MILLISECONDSPERPACKET;
  290. // initialize type
  291. dwValueType = REG_DWORD;
  292. dwValueSize = sizeof(DWORD);
  293. // query for registry value
  294. lStatus = RegQueryValueEx(
  295. g_hKey,
  296. pszValue,
  297. NULL,
  298. &dwValueType,
  299. (LPBYTE)&g_RegistrySettings.dwG711MillisecondsPerPacket,
  300. &dwValueSize
  301. );
  302. // validate return code
  303. if (lStatus != ERROR_SUCCESS) {
  304. // copy default value into global settings
  305. g_RegistrySettings.dwG711MillisecondsPerPacket =
  306. G711_DEFAULT_MILLISECONDS_PER_PACKET
  307. ;
  308. }
  309. H323DBG((
  310. DEBUG_LEVEL_VERBOSE,
  311. "using G.711 setting of %d milliseconds per packet.\n",
  312. g_RegistrySettings.dwG711MillisecondsPerPacket
  313. ));
  314. // initialize value name
  315. pszValue = H323_REGVAL_G723MILLISECONDSPERPACKET;
  316. // initialize type
  317. dwValueType = REG_DWORD;
  318. dwValueSize = sizeof(DWORD);
  319. // query for registry value
  320. lStatus = RegQueryValueEx(
  321. g_hKey,
  322. pszValue,
  323. NULL,
  324. &dwValueType,
  325. (LPBYTE)&g_RegistrySettings.dwG723MillisecondsPerPacket,
  326. &dwValueSize
  327. );
  328. // validate return code
  329. if (lStatus != ERROR_SUCCESS) {
  330. // copy default value into global settings
  331. g_RegistrySettings.dwG723MillisecondsPerPacket =
  332. G723_DEFAULT_MILLISECONDS_PER_PACKET
  333. ;
  334. }
  335. H323DBG((
  336. DEBUG_LEVEL_VERBOSE,
  337. "using G.723 setting of %d milliseconds per packet.\n",
  338. g_RegistrySettings.dwG723MillisecondsPerPacket
  339. ));
  340. // initialize value name
  341. pszValue = H323_REGVAL_GATEWAYADDR;
  342. // initialize type
  343. dwValueType = REG_SZ;
  344. dwValueSize = sizeof(szAddr);
  345. // initialize ip address
  346. dwValue = UNINITIALIZED;
  347. // query for registry value
  348. lStatus = RegQueryValueEx(
  349. g_hKey,
  350. pszValue,
  351. NULL,
  352. &dwValueType,
  353. szAddr,
  354. &dwValueSize
  355. );
  356. // validate return code
  357. if (lStatus == ERROR_SUCCESS) {
  358. // convert ip address
  359. dwValue = inet_addr(szAddr);
  360. // see if address converted
  361. if (dwValue == UNINITIALIZED) {
  362. struct hostent * pHost;
  363. // attempt to lookup hostname
  364. pHost = gethostbyname(szAddr);
  365. // validate pointer
  366. if (pHost != NULL) {
  367. // retrieve host address from structure
  368. dwValue = *(unsigned long *)pHost->h_addr;
  369. }
  370. }
  371. }
  372. // see if address converted and check for null
  373. if ((dwValue > 0) && (dwValue != UNINITIALIZED)) {
  374. // save new gateway address in registry structure
  375. g_RegistrySettings.ccGatewayAddr.nAddrType = CC_IP_BINARY;
  376. g_RegistrySettings.ccGatewayAddr.Addr.IP_Binary.dwAddr = ntohl(dwValue);
  377. g_RegistrySettings.ccGatewayAddr.Addr.IP_Binary.wPort =
  378. LOWORD(g_RegistrySettings.dwQ931CallSignallingPort);
  379. g_RegistrySettings.ccGatewayAddr.bMulticast =
  380. IN_MULTICAST(g_RegistrySettings.ccGatewayAddr.Addr.IP_Binary.dwAddr);
  381. H323DBG((
  382. DEBUG_LEVEL_TRACE,
  383. "gateway address resolved to %s.\n",
  384. H323AddrToString(dwValue)
  385. ));
  386. } else {
  387. // clear memory used for gateway address
  388. memset(&g_RegistrySettings.ccGatewayAddr,0,sizeof(CC_ADDR));
  389. }
  390. // initialize value name
  391. pszValue = H323_REGVAL_GATEWAYENABLED;
  392. // initialize type
  393. dwValueType = REG_DWORD;
  394. dwValueSize = sizeof(DWORD);
  395. // query for registry value
  396. lStatus = RegQueryValueEx(
  397. g_hKey,
  398. pszValue,
  399. NULL,
  400. &dwValueType,
  401. (LPBYTE)&dwValue,
  402. &dwValueSize
  403. );
  404. // validate return code
  405. if (lStatus == ERROR_SUCCESS) {
  406. // if value non-zero then gateway address enabled
  407. g_RegistrySettings.fIsGatewayEnabled = (dwValue != 0);
  408. } else {
  409. // copy default value into settings
  410. g_RegistrySettings.fIsGatewayEnabled = FALSE;
  411. }
  412. // initialize value name
  413. pszValue = H323_REGVAL_PROXYADDR;
  414. // initialize type
  415. dwValueType = REG_SZ;
  416. dwValueSize = sizeof(szAddr);
  417. // initialize ip address
  418. dwValue = UNINITIALIZED;
  419. // query for registry value
  420. lStatus = RegQueryValueEx(
  421. g_hKey,
  422. pszValue,
  423. NULL,
  424. &dwValueType,
  425. szAddr,
  426. &dwValueSize
  427. );
  428. // validate return code
  429. if (lStatus == ERROR_SUCCESS) {
  430. // convert ip address
  431. dwValue = inet_addr(szAddr);
  432. // see if address converted
  433. if (dwValue == UNINITIALIZED) {
  434. struct hostent * pHost;
  435. // attempt to lookup hostname
  436. pHost = gethostbyname(szAddr);
  437. // validate pointer
  438. if (pHost != NULL) {
  439. // retrieve host address from structure
  440. dwValue = *(unsigned long *)pHost->h_addr;
  441. }
  442. }
  443. }
  444. // see if address converted
  445. if ((dwValue > 0) && (dwValue != UNINITIALIZED)) {
  446. // save new gateway address in registry structure
  447. g_RegistrySettings.ccProxyAddr.nAddrType = CC_IP_BINARY;
  448. g_RegistrySettings.ccProxyAddr.Addr.IP_Binary.dwAddr = ntohl(dwValue);
  449. g_RegistrySettings.ccProxyAddr.Addr.IP_Binary.wPort =
  450. LOWORD(g_RegistrySettings.dwQ931CallSignallingPort);
  451. g_RegistrySettings.ccProxyAddr.bMulticast =
  452. IN_MULTICAST(g_RegistrySettings.ccProxyAddr.Addr.IP_Binary.dwAddr);
  453. H323DBG((
  454. DEBUG_LEVEL_TRACE,
  455. "proxy address resolved to %s.\n",
  456. H323AddrToString(dwValue)
  457. ));
  458. } else {
  459. // clear memory used for gateway address
  460. memset(&g_RegistrySettings.ccProxyAddr,0,sizeof(CC_ADDR));
  461. }
  462. // initialize value name
  463. pszValue = H323_REGVAL_PROXYENABLED;
  464. // initialize type
  465. dwValueType = REG_DWORD;
  466. dwValueSize = sizeof(DWORD);
  467. // query for registry value
  468. lStatus = RegQueryValueEx(
  469. g_hKey,
  470. pszValue,
  471. NULL,
  472. &dwValueType,
  473. (LPBYTE)&dwValue,
  474. &dwValueSize
  475. );
  476. // validate return code
  477. if (lStatus == ERROR_SUCCESS) {
  478. // if value non-zero then gateway address enabled
  479. g_RegistrySettings.fIsProxyEnabled = (dwValue != 0);
  480. } else {
  481. // copy default value into settings
  482. g_RegistrySettings.fIsProxyEnabled = FALSE;
  483. }
  484. // success
  485. return TRUE;
  486. }
  487. BOOL
  488. H323ListenForRegistryChanges(
  489. HANDLE hEvent
  490. )
  491. /*++
  492. Routine Description:
  493. Initializes registry key change notification.
  494. Arguments:
  495. hEvent - event to associate with registry key.
  496. Return Values:
  497. Returns true if successful.
  498. --*/
  499. {
  500. LONG lStatus = ERROR_SUCCESS;
  501. // see if key open
  502. if (g_hKey == NULL) {
  503. // open registry subkey
  504. lStatus = RegOpenKeyEx(
  505. HKEY_LOCAL_MACHINE,
  506. H323_REGKEY_ROOT,
  507. 0,
  508. KEY_READ,
  509. &g_hKey
  510. );
  511. }
  512. // validate return code
  513. if (lStatus != ERROR_SUCCESS) {
  514. H323DBG((
  515. DEBUG_LEVEL_WARNING,
  516. "error 0x%08lx opening tsp registry key.\n",
  517. lStatus
  518. ));
  519. // failure
  520. return FALSE;
  521. }
  522. // registry event with registry key
  523. lStatus = RegNotifyChangeKeyValue(
  524. g_hKey, // hKey
  525. FALSE, // bWatchSubTree
  526. REG_NOTIFY_CHANGE_ATTRIBUTES | // dwNotifyFilter
  527. REG_NOTIFY_CHANGE_LAST_SET |
  528. REG_NOTIFY_CHANGE_SECURITY,
  529. hEvent, // hEvent
  530. TRUE // fAsychnronous
  531. );
  532. // validate return code
  533. if (lStatus != ERROR_SUCCESS) {
  534. H323DBG((
  535. DEBUG_LEVEL_WARNING,
  536. "error 0x%08lx associating event with registry key.\n",
  537. lStatus
  538. ));
  539. // failure
  540. return FALSE;
  541. }
  542. // success
  543. return TRUE;
  544. }
  545. BOOL
  546. H323StopListeningForRegistryChanges(
  547. )
  548. /*++
  549. Routine Description:
  550. Closes registry key.
  551. Arguments:
  552. None.
  553. Return Values:
  554. Returns true if successful.
  555. --*/
  556. {
  557. // see if key open
  558. if (g_hKey != NULL) {
  559. // close key
  560. RegCloseKey(g_hKey);
  561. // re-init
  562. g_hKey = NULL;
  563. }
  564. // success
  565. return TRUE;
  566. }