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.

1190 lines
32 KiB

  1. #define STRICT
  2. #include <windows.h>
  3. #include <windowsx.h>
  4. #include "location.h"
  5. #if DBG
  6. #define DBGOUT(arg) DbgPrt arg
  7. void
  8. DbgPrt(
  9. DWORD dwDbgLevel,
  10. PSTR DbgMessage,
  11. ...
  12. );
  13. #else
  14. #define DBGOUT(_x_)
  15. #endif
  16. const TCHAR gszName[] = "Name";
  17. const TCHAR gszID[] = "ID";
  18. const TCHAR gszAreaCode[] = "AreaCode";
  19. const TCHAR gszCountry[] = "Country";
  20. const TCHAR gszOutsideAccess[] = "OutsideAccess";
  21. const TCHAR gszLongDistanceAccess[] = "LongDistanceAccess";
  22. const TCHAR gszFlags[] = "Flags";
  23. const TCHAR gszCallingCard[] = "CallingCard";
  24. const TCHAR gszDisableCallWaiting[] = "DisableCallWaiting";
  25. const TCHAR gszTollList[] = "TollList";
  26. //const TCHAR gszNumLocations[] = "NumLocations";
  27. //const TCHAR gszCurrLocation[] = "CurrLocation";
  28. //const TCHAR gszNextLocationID[] = "NextLocationID";
  29. const TCHAR gszCard[] = "Card";
  30. const TCHAR gszPin[] = "Pin";
  31. const TCHAR gszCards[] = "Cards";
  32. //const TCHAR gszNumCards[] = "NumCards";
  33. //const TCHAR gszCurrCard[] = "CurrCard";
  34. const TCHAR gszLocalRule[] = "LocalRule";
  35. const TCHAR gszLDRule[] = "LDRule";
  36. const TCHAR gszInternationalRule[] = "InternationalRule";
  37. const TCHAR gszNumEntries[] = "NumEntries";
  38. const TCHAR gszCurrentID[] = "CurrentID";
  39. const TCHAR gszNextID[] = "NextID";
  40. const TCHAR gszEmpty[] = "";
  41. const TCHAR gszLocations[] = "Locations";
  42. const TCHAR gszLocation[] = "Location";
  43. const TCHAR gszCurrentLocation[] = "CurrentLocation";
  44. const TCHAR gszHandoffPriorities[] = "HandoffPriorities";
  45. const TCHAR gszProviders[] = "Providers";
  46. const TCHAR gszProvider[] = "Provider%d";
  47. const TCHAR gszTelephonIni[] = "Telephon.ini";
  48. const TCHAR gszTelephony[] = "Software\\Microsoft\\Windows\\"
  49. "CurrentVersion\\Telephony";
  50. const CHAR *gaszMediaModes[] =
  51. {
  52. "",
  53. "unknown",
  54. "interactivevoice",
  55. "automatedvoice",
  56. "datamodem",
  57. "g3fax",
  58. "tdd",
  59. "g4fax",
  60. "digitaldata",
  61. "teletex",
  62. "videotex",
  63. "telex",
  64. "mixed",
  65. "adsi",
  66. "voiceview",
  67. NULL
  68. };
  69. const CHAR *gszRequestMakeCallW = "RequestMakeCall";
  70. const CHAR *gszRequestMediaCallW = "RequestMediaCall";
  71. const CHAR *gszRegKeyHandoffPriorities = "Software\\Microsoft\\Windows\\CurrentVersion\\Telephony\\HandoffPriorities";
  72. const CHAR *gszRegKeyHandoffPrioritiesMediaModes = "MediaModes";
  73. void FixPriorityList(HKEY hKeyHandoffPriorities,
  74. LPCSTR pszListName);
  75. void FixMediaModesPriorityLists();
  76. #pragma check_stack ( off )
  77. //***************************************************************************
  78. //***************************************************************************
  79. //***************************************************************************
  80. BOOL ParseSomething( LPCSTR pFormat, LPCSTR pInputString, LPVOID pOutputPtr )
  81. {
  82. BYTE c;
  83. LPBYTE pOutput = (LPBYTE)pOutputPtr;
  84. LPBYTE pInput = (LPBYTE)pInputString;
  85. while ( (c = *pFormat) && *pInput )
  86. {
  87. #if DBG
  88. DBGOUT((11, "Inputstring[%s]\r\n Format[%s]\r\n",
  89. pInput, pFormat));
  90. #endif
  91. switch ( c )
  92. {
  93. case 'n':
  94. {
  95. DWORD dwValue = 0;
  96. BYTE bDigit;
  97. //
  98. // Parse value from the string
  99. //
  100. while ( ((bDigit = *pInput) != '\0') && bDigit != ',' )
  101. {
  102. dwValue = (dwValue * 10) + ( bDigit - '0' );
  103. #if DBG
  104. DBGOUT((11, "val of bDigit=%d dwValue=%ld\r\n", (int)bDigit, dwValue));
  105. #endif
  106. bDigit = *(++pInput);
  107. }
  108. *(LPDWORD)pOutput = dwValue;
  109. pOutput += sizeof(DWORD);
  110. }
  111. break;
  112. case 's':
  113. {
  114. //
  115. // If the caller is looking for a string, the first char
  116. // MUST be a quotes. So, just step past it.
  117. //
  118. pInput++;
  119. //
  120. // Ok, _now_ we're into the meat of the string (if there _is_
  121. // any...)
  122. //
  123. while ( *pInput != '\0' && *pInput != '"' )
  124. {
  125. *pOutput = *pInput;
  126. pOutput++;
  127. pInput++;
  128. }
  129. //
  130. // Don't forget to put a cap on that thing.
  131. //
  132. *pOutput = '\0';
  133. pOutput++;
  134. // The input should now be at a ->"<- if it's not, the ini
  135. // file was hosed, and I'm not fixing it.
  136. // So, we step past it, and we're done
  137. //
  138. if ( *pInput == '"' )
  139. {
  140. pInput++;
  141. }
  142. }
  143. break;
  144. }
  145. //
  146. // Step past the comma...
  147. //
  148. //
  149. if ( *pInput == ',' )
  150. {
  151. pInput++;
  152. }
  153. pFormat++;
  154. }
  155. return TRUE;
  156. }
  157. //***************************************************************************
  158. //***************************************************************************
  159. //***************************************************************************
  160. //VOID __cdecl main( void )
  161. void __cdecl main( void )
  162. {
  163. DWORD dw;
  164. DWORD dwNumEntries;
  165. DWORD dwCurrentID;
  166. DWORD dwNextID;
  167. DWORD dwSize;
  168. DWORD dwType;
  169. DWORD dwValue;
  170. DWORD dwArray[10];
  171. BYTE *bBigArray;
  172. BYTE *Buffer;
  173. LPBYTE pSource;
  174. HKEY hKey3;
  175. HKEY hKey2;
  176. HKEY hKey;
  177. DWORD dwDisposition;
  178. #define BUFFER_SIZE (5120)
  179. bBigArray = LocalAlloc( LPTR, BUFFER_SIZE );
  180. if ( !bBigArray )
  181. {
  182. return;
  183. }
  184. Buffer = LocalAlloc( LPTR, BUFFER_SIZE ); //Might needs tons of room for tolllist
  185. if ( !Buffer )
  186. {
  187. return;
  188. }
  189. dw = GetPrivateProfileString(
  190. gszCards,
  191. gszCards,
  192. gszEmpty,
  193. Buffer,
  194. BUFFER_SIZE,
  195. gszTelephonIni
  196. );
  197. //
  198. // Is there an existing AND valid TELEPHON.INI file?
  199. // There would HAVE TO be at least one card. The SYSTEM cards cannot
  200. // be deleted, only hidden.
  201. //
  202. if ( 0 != dw )
  203. {
  204. //[Cards]
  205. //Cards=23,23
  206. //Card0=0,"None (Direct Dial)","","","","",1
  207. //Card1=1,"AT&T Direct Dial via 10ATT1","","G","102881FG","10288011EFG",1
  208. #define CARD_INI_ID (0)
  209. #define CARD_INI_NAME (1)
  210. #define CARD_INI_SNUMBER (2)
  211. #define CARD_INI_SARULE (3)
  212. #define CARD_INI_LDRULE (4)
  213. #define CARD_INI_INTNLRULE (5)
  214. #define CARD_INI_HIDDEN (6)
  215. #define PC_INI_ID (0)
  216. #define PC_INI_NEXTID (1)
  217. #define PC_INI_NAME (2)
  218. #define PC_INI_SARULE (3)
  219. #define PC_INI_LDRULE (4)
  220. #define PC_INI_INTNLRULE (5)
  221. //
  222. // Move CARDS entries to registry
  223. //
  224. ParseSomething( "nn", Buffer, &dwArray);
  225. dwNumEntries = dwArray[0];
  226. dwNextID = dwArray[1];
  227. RegCreateKeyEx(
  228. HKEY_CURRENT_USER,
  229. gszTelephony,
  230. 0,
  231. "", //Class? What class?
  232. REG_OPTION_NON_VOLATILE,
  233. KEY_ALL_ACCESS,
  234. 0,
  235. &hKey3,
  236. &dwDisposition
  237. );
  238. RegCreateKeyEx(
  239. hKey3,
  240. gszCards,
  241. 0,
  242. "", //Class? What class?
  243. REG_OPTION_NON_VOLATILE,
  244. KEY_ALL_ACCESS,
  245. 0,
  246. &hKey2,
  247. &dwDisposition
  248. );
  249. //
  250. // Don't wipe out an existing card section
  251. //
  252. dwSize = sizeof(dwValue);
  253. dw = RegQueryValueEx(
  254. hKey2,
  255. gszNumEntries,
  256. 0,
  257. &dwType,
  258. (LPBYTE)&dwValue,
  259. &dwSize
  260. );
  261. if ( 0 != dw )
  262. {
  263. RegSetValueEx(
  264. hKey2,
  265. gszNumEntries,
  266. 0,
  267. REG_DWORD,
  268. (LPBYTE)&dwNumEntries,
  269. sizeof(DWORD)
  270. );
  271. RegSetValueEx(
  272. hKey2,
  273. gszNextID,
  274. 0,
  275. REG_DWORD,
  276. (LPBYTE)&dwNextID,
  277. sizeof(DWORD)
  278. );
  279. for ( dw=0; dw<dwNumEntries; dw++ )
  280. {
  281. TCHAR Temp[18];
  282. wsprintf(Temp, "%s%d", gszCard, dw);
  283. //
  284. // Create the key for this Card
  285. //
  286. RegCreateKeyEx(
  287. hKey2,
  288. Temp,
  289. 0,
  290. "", //Class? What class?
  291. REG_OPTION_NON_VOLATILE,
  292. KEY_ALL_ACCESS,
  293. 0,
  294. &hKey,
  295. &dwDisposition
  296. );
  297. GetPrivateProfileString(
  298. gszCards,
  299. Temp,
  300. gszEmpty,
  301. Buffer,
  302. BUFFER_SIZE,
  303. gszTelephonIni
  304. );
  305. ParseSomething("nsssssn", Buffer, bBigArray);
  306. pSource = bBigArray;
  307. RegSetValueEx(
  308. hKey,
  309. gszID,
  310. 0,
  311. REG_DWORD,
  312. pSource,
  313. sizeof(DWORD)
  314. );
  315. pSource += sizeof(DWORD);
  316. RegSetValueEx(
  317. hKey,
  318. gszName,
  319. 0,
  320. REG_SZ,
  321. pSource,
  322. lstrlen(pSource)+1
  323. );
  324. pSource += lstrlen(pSource)+1;
  325. RegSetValueEx(
  326. hKey,
  327. gszPin,
  328. 0,
  329. REG_SZ,
  330. pSource,
  331. lstrlen(pSource)+1
  332. );
  333. pSource += lstrlen(pSource)+1;
  334. RegSetValueEx(
  335. hKey,
  336. gszLocalRule,
  337. 0,
  338. REG_SZ,
  339. pSource,
  340. lstrlen(pSource)+1
  341. );
  342. pSource += lstrlen(pSource)+1;
  343. RegSetValueEx(
  344. hKey,
  345. gszLDRule,
  346. 0,
  347. REG_SZ,
  348. pSource,
  349. lstrlen(pSource)+1
  350. );
  351. pSource += lstrlen(pSource)+1;
  352. RegSetValueEx(
  353. hKey,
  354. gszInternationalRule,
  355. 0,
  356. REG_SZ,
  357. pSource,
  358. lstrlen(pSource)+1
  359. );
  360. pSource += lstrlen(pSource)+1;
  361. RegSetValueEx(
  362. hKey,
  363. gszFlags,
  364. 0,
  365. REG_DWORD,
  366. pSource,
  367. sizeof(DWORD)
  368. );
  369. pSource += sizeof(DWORD);
  370. RegCloseKey( hKey );
  371. }
  372. }
  373. RegCloseKey( hKey2 );
  374. RegCloseKey( hKey3 );
  375. //---------------------------------------------------------------------------
  376. GetPrivateProfileString(
  377. gszLocations,
  378. gszCurrentLocation,
  379. gszEmpty,
  380. Buffer,
  381. BUFFER_SIZE,
  382. gszTelephonIni
  383. );
  384. ParseSomething( "nn", Buffer, &dwArray);
  385. dwCurrentID = dwArray[0];
  386. GetPrivateProfileString(
  387. gszLocations,
  388. gszLocations,
  389. gszEmpty,
  390. Buffer,
  391. BUFFER_SIZE,
  392. gszTelephonIni
  393. );
  394. ParseSomething( "nn", Buffer, &dwArray);
  395. dwNumEntries = dwArray[0];
  396. dwNextID = dwArray[1];
  397. RegCreateKeyEx(
  398. HKEY_LOCAL_MACHINE,
  399. gszTelephony,
  400. 0,
  401. "", //Class? What class?
  402. REG_OPTION_NON_VOLATILE,
  403. KEY_ALL_ACCESS,
  404. 0,
  405. &hKey3,
  406. &dwDisposition
  407. );
  408. RegCreateKeyEx(
  409. hKey3,
  410. gszLocations,
  411. 0,
  412. "", //Class? What class?
  413. REG_OPTION_NON_VOLATILE,
  414. KEY_ALL_ACCESS,
  415. 0,
  416. &hKey2,
  417. &dwDisposition
  418. );
  419. //
  420. // Don't wipe out an existing card section
  421. //
  422. dwSize = sizeof(dwValue);
  423. dw = RegQueryValueEx(
  424. hKey2,
  425. gszNumEntries,
  426. 0,
  427. &dwType,
  428. (LPBYTE)&dwValue,
  429. &dwSize
  430. );
  431. if ( 0 != dw )
  432. {
  433. RegSetValueEx(
  434. hKey2,
  435. gszCurrentID,
  436. 0,
  437. REG_DWORD,
  438. (LPBYTE)&dwCurrentID,
  439. sizeof(DWORD)
  440. );
  441. RegSetValueEx(
  442. hKey2,
  443. gszNumEntries,
  444. 0,
  445. REG_DWORD,
  446. (LPBYTE)&dwNumEntries,
  447. sizeof(DWORD)
  448. );
  449. RegSetValueEx(
  450. hKey2,
  451. gszNextID,
  452. 0,
  453. REG_DWORD,
  454. (LPBYTE)&dwNextID,
  455. sizeof(DWORD)
  456. );
  457. for ( dw=0; dw<dwNumEntries; dw++ )
  458. {
  459. TCHAR Temp[18];
  460. DWORD dwFlags = 0;
  461. wsprintf(Temp, "%s%d", gszLocation, dw);
  462. //
  463. // Create the key for this Location
  464. //
  465. RegCreateKeyEx(
  466. hKey2,
  467. Temp,
  468. 0,
  469. "", //Class? What class?
  470. REG_OPTION_NON_VOLATILE,
  471. KEY_ALL_ACCESS,
  472. 0,
  473. &hKey,
  474. &dwDisposition
  475. );
  476. GetPrivateProfileString(
  477. gszLocations,
  478. Temp,
  479. gszEmpty,
  480. Buffer,
  481. BUFFER_SIZE,
  482. gszTelephonIni
  483. );
  484. ParseSomething("nssssnnnnsns", Buffer, bBigArray);
  485. //NOTE if this is upgrade over 3.1, the last 2 fields don't exist
  486. //[Locations]
  487. //CurrentLocation=1,2
  488. //Locations=3,4
  489. //Location0=0,"Work","9","9","206",1,0,0,1,"",0,""
  490. //Location1=3,"RoadHouse","","","215",1,0,0,0,"",0,""
  491. //Location2=1,"Home","","","206",1,0,0,0,"",0," "
  492. // Positions in ini file entries for locations,cards,countries
  493. // NOTE: dialing rules are in same positions for locations and cards!
  494. //#define LOC_INI_ID (0)
  495. //#define LOC_INI_NAME (1)
  496. //#define LOC_INI_LPREFIX (2)
  497. //#define LOC_INI_LDPREFIX (3)
  498. //#define LOC_INI_AREACODE (4)
  499. //#define LOC_INI_COUNTRYCODE (5)
  500. //#define LOC_INI_CARDID (6)
  501. //#define LOC_INI_CARDHINT (7)
  502. //#define LOC_INI_INSERTAC (8)
  503. //#define LOC_INI_TOLLLIST (9)
  504. //
  505. //#define LOC_INI_PULSE (10)
  506. //#define LOC_INI_CALLWAITING (11)
  507. pSource = bBigArray;
  508. RegSetValueEx(
  509. hKey,
  510. gszID,
  511. 0,
  512. REG_DWORD,
  513. pSource,
  514. sizeof(DWORD)
  515. );
  516. pSource += sizeof(DWORD);
  517. RegSetValueEx(
  518. hKey,
  519. gszName,
  520. 0,
  521. REG_SZ,
  522. pSource,
  523. lstrlen(pSource)+1
  524. );
  525. pSource += lstrlen(pSource)+1;
  526. RegSetValueEx(
  527. hKey,
  528. gszOutsideAccess,
  529. 0,
  530. REG_SZ,
  531. pSource,
  532. lstrlen(pSource)+1
  533. );
  534. pSource += lstrlen(pSource)+1;
  535. RegSetValueEx(
  536. hKey,
  537. gszLongDistanceAccess,
  538. 0,
  539. REG_SZ,
  540. pSource,
  541. lstrlen(pSource)+1
  542. );
  543. pSource += lstrlen(pSource)+1;
  544. RegSetValueEx(
  545. hKey,
  546. gszAreaCode,
  547. 0,
  548. REG_SZ,
  549. pSource,
  550. lstrlen(pSource)+1
  551. );
  552. pSource += lstrlen(pSource)+1;
  553. RegSetValueEx(
  554. hKey,
  555. gszCountry,
  556. 0,
  557. REG_DWORD,
  558. pSource,
  559. sizeof(DWORD)
  560. );
  561. pSource += sizeof(DWORD);
  562. //
  563. // If the callingcard == 0, it means this location does not
  564. // use a calling card.
  565. //
  566. if ( *(LPDWORD)pSource != 0 )
  567. {
  568. dwFlags |= LOCATION_USECALLINGCARD;
  569. }
  570. RegSetValueEx(
  571. hKey,
  572. gszCallingCard,
  573. 0,
  574. REG_DWORD,
  575. pSource,
  576. sizeof(DWORD)
  577. );
  578. pSource += sizeof(DWORD);
  579. pSource += sizeof(DWORD);
  580. pSource += sizeof(DWORD);
  581. RegSetValueEx(
  582. hKey,
  583. gszTollList,
  584. 0,
  585. REG_SZ,
  586. pSource,
  587. lstrlen(pSource)+1
  588. );
  589. pSource += lstrlen(pSource)+1;
  590. //
  591. // pSource is currently pointing to the old dwFlags. However,
  592. // the only flag that was used was bit 1 which indicated
  593. // tone dialing. As luck (yeah, right) would have it, we
  594. // use bit 1 to indicate tone dialing as well.
  595. //
  596. dwFlags |= !((*(LPDWORD)pSource) & 1);
  597. pSource += sizeof(DWORD);
  598. //
  599. // Is there a disablecallwaiting string
  600. //
  601. dwFlags |= ( lstrlen( pSource ) == 0 ) ?
  602. 0 :
  603. LOCATION_HASCALLWAITING;
  604. RegSetValueEx(
  605. hKey,
  606. gszDisableCallWaiting,
  607. 0,
  608. REG_SZ,
  609. pSource,
  610. lstrlen(pSource)+1
  611. );
  612. pSource += lstrlen(pSource)+1;
  613. RegSetValueEx(
  614. hKey,
  615. gszFlags,
  616. 0,
  617. REG_DWORD,
  618. (LPBYTE)&dwFlags,
  619. sizeof(DWORD)
  620. );
  621. pSource += sizeof(DWORD);
  622. RegCloseKey( hKey );
  623. }
  624. }
  625. //
  626. // Q: How do we update COUNTRY OVERRIDES?
  627. // A: We don't. We assume we've corrected everything by now...
  628. //
  629. // RegCloseKey( hKey );
  630. RegCloseKey( hKey2 );
  631. RegCloseKey( hKey3 );
  632. }
  633. {
  634. int i;
  635. HKEY hKeyHandoffPriorities;
  636. if (RegOpenKeyEx(
  637. HKEY_CURRENT_USER,
  638. gszRegKeyHandoffPriorities,
  639. 0,
  640. KEY_ALL_ACCESS,
  641. &hKeyHandoffPriorities
  642. ) == ERROR_SUCCESS)
  643. {
  644. for (i = 1; gaszMediaModes[i] != NULL; i++)
  645. {
  646. FixPriorityList(
  647. hKeyHandoffPriorities,
  648. (LPCSTR)gaszMediaModes[i]
  649. );
  650. }
  651. FixPriorityList(
  652. hKeyHandoffPriorities,
  653. (LPCSTR)gszRequestMakeCallW
  654. );
  655. FixPriorityList(
  656. hKeyHandoffPriorities,
  657. (LPCSTR)gszRequestMediaCallW
  658. );
  659. RegCloseKey (hKeyHandoffPriorities);
  660. }
  661. }
  662. FixMediaModesPriorityLists();
  663. #ifdef TAPI_NT
  664. {
  665. //----------------------------------------------------------------------
  666. //----------------------------------------------------------------------
  667. //----------------------------------------------------------------------
  668. //
  669. // Now we discuss someone who is upgrading from beta 2 to RTM. They have
  670. // "EVERYONE:FULL CONTROL" access on the LOCATIONS key. Let's change that
  671. // to have the same security as the TELEPHONY key.
  672. //
  673. SECURITY_INFORMATION SecInf;
  674. PSECURITY_DESCRIPTOR pSecDesc;
  675. DWORD cbSecDesc = 65535;
  676. pSecDesc = LocalAlloc( LPTR, cbSecDesc );
  677. if ( pSecDesc )
  678. {
  679. RegOpenKeyEx(
  680. HKEY_LOCAL_MACHINE,
  681. gszTelephony,
  682. 0,
  683. KEY_ALL_ACCESS,
  684. &hKey
  685. );
  686. RegCreateKeyEx(
  687. hKey,
  688. gszLocations,
  689. 0,
  690. "", //Class? What class?
  691. REG_OPTION_NON_VOLATILE,
  692. KEY_ALL_ACCESS,
  693. 0,
  694. &hKey2,
  695. &dwDisposition
  696. );
  697. cbSecDesc = 65535;
  698. dw = RegGetKeySecurity( hKey,
  699. OWNER_SECURITY_INFORMATION,
  700. pSecDesc,
  701. &cbSecDesc
  702. );
  703. if ( ERROR_SUCCESS == dw )
  704. RegSetKeySecurity( hKey2,
  705. OWNER_SECURITY_INFORMATION,
  706. pSecDesc
  707. );
  708. cbSecDesc = 65535;
  709. dw = RegGetKeySecurity( hKey,
  710. GROUP_SECURITY_INFORMATION,
  711. pSecDesc,
  712. &cbSecDesc
  713. );
  714. if ( ERROR_SUCCESS == dw )
  715. RegSetKeySecurity( hKey2,
  716. GROUP_SECURITY_INFORMATION,
  717. pSecDesc
  718. );
  719. cbSecDesc = 65535;
  720. dw = RegGetKeySecurity( hKey,
  721. DACL_SECURITY_INFORMATION,
  722. pSecDesc,
  723. &cbSecDesc
  724. );
  725. if ( ERROR_SUCCESS == dw )
  726. RegSetKeySecurity( hKey2,
  727. DACL_SECURITY_INFORMATION,
  728. pSecDesc
  729. );
  730. cbSecDesc = 65535;
  731. dw = RegGetKeySecurity( hKey,
  732. SACL_SECURITY_INFORMATION,
  733. pSecDesc,
  734. &cbSecDesc
  735. );
  736. if ( ERROR_SUCCESS == dw )
  737. RegSetKeySecurity( hKey2,
  738. SACL_SECURITY_INFORMATION,
  739. pSecDesc
  740. );
  741. RegCloseKey( hKey );
  742. RegCloseKey( hKey2);
  743. LocalFree( pSecDesc );
  744. }
  745. }
  746. #endif
  747. LocalFree( bBigArray );
  748. LocalFree( Buffer );
  749. return;
  750. }
  751. void FixPriorityList(HKEY hKeyHandoffPriorities,
  752. LPCSTR pszListName)
  753. {
  754. DWORD dwType, dwNumBytes;
  755. LPSTR pszPriorityList, pszHold;
  756. if (RegQueryValueEx(
  757. hKeyHandoffPriorities,
  758. pszListName,
  759. NULL,
  760. &dwType,
  761. NULL,
  762. &dwNumBytes
  763. ) == ERROR_SUCCESS &&
  764. (dwNumBytes != 0))
  765. {
  766. pszPriorityList = (LPSTR) GlobalAlloc ( GPTR, dwNumBytes );
  767. if (pszPriorityList)
  768. {
  769. pszHold = pszPriorityList;
  770. if ( RegQueryValueEx(
  771. hKeyHandoffPriorities,
  772. pszListName,
  773. NULL,
  774. &dwType,
  775. (LPBYTE)(pszPriorityList),
  776. &dwNumBytes
  777. ) == ERROR_SUCCESS)
  778. {
  779. while (*pszPriorityList != '\0')
  780. {
  781. if (*pszPriorityList == ',')
  782. {
  783. *pszPriorityList = '"';
  784. }
  785. pszPriorityList++;
  786. }
  787. pszPriorityList = pszHold;
  788. RegSetValueEx(
  789. hKeyHandoffPriorities,
  790. pszListName,
  791. 0,
  792. REG_SZ,
  793. (LPBYTE)pszPriorityList,
  794. (lstrlen(pszPriorityList) + 1) * sizeof(CHAR));
  795. }
  796. GlobalFree(pszPriorityList);
  797. }
  798. }
  799. }
  800. void FixMediaModesPriorityLists()
  801. {
  802. HKEY hKeyHandoffPriorities;
  803. HKEY hKeyMediaModes;
  804. DWORD dwDisp;
  805. // open the handoff priorities key
  806. if (RegOpenKeyEx(
  807. HKEY_CURRENT_USER,
  808. gszRegKeyHandoffPriorities,
  809. 0,
  810. KEY_ALL_ACCESS,
  811. &hKeyHandoffPriorities
  812. ) == ERROR_SUCCESS)
  813. {
  814. if (RegOpenKeyEx(
  815. hKeyHandoffPriorities,
  816. gszRegKeyHandoffPrioritiesMediaModes,
  817. 0,
  818. KEY_ALL_ACCESS,
  819. &hKeyMediaModes
  820. ) == ERROR_SUCCESS)
  821. {
  822. // key already exists, so don't do anything
  823. RegCloseKey( hKeyHandoffPriorities );
  824. RegCloseKey( hKeyMediaModes );
  825. return;
  826. }
  827. // create the mediamodes priority key
  828. if (RegCreateKeyEx(
  829. hKeyHandoffPriorities,
  830. gszRegKeyHandoffPrioritiesMediaModes,
  831. 0,
  832. "",
  833. REG_OPTION_NON_VOLATILE,
  834. KEY_ALL_ACCESS,
  835. NULL,
  836. &hKeyMediaModes,
  837. &dwDisp
  838. ) == ERROR_SUCCESS)
  839. {
  840. // go through all the
  841. // media modes
  842. int i;
  843. int j = 2; //LINEMEDIAMODE_UNKNOWN;
  844. for (i = 1; gaszMediaModes[i] != NULL; i++)
  845. {
  846. CHAR szName[64];
  847. LPSTR pszPriorityList;
  848. DWORD dwNumBytes, dwType;
  849. // query for the priority list
  850. if ( (RegQueryValueEx(
  851. hKeyHandoffPriorities,
  852. gaszMediaModes[i],
  853. NULL,
  854. &dwType,
  855. NULL,
  856. &dwNumBytes
  857. ) == ERROR_SUCCESS) && (dwNumBytes != 0))
  858. {
  859. pszPriorityList = (LPSTR) GlobalAlloc ( GPTR, dwNumBytes );
  860. if (NULL != pszPriorityList)
  861. {
  862. if ( RegQueryValueEx(
  863. hKeyHandoffPriorities,
  864. gaszMediaModes[i],
  865. NULL,
  866. &dwType,
  867. (LPBYTE)(pszPriorityList),
  868. &dwNumBytes
  869. ) == ERROR_SUCCESS)
  870. {
  871. // if it exists, write out the new one
  872. wsprintf(szName, "%d", j);
  873. RegSetValueEx(
  874. hKeyMediaModes,
  875. szName,
  876. 0,
  877. REG_SZ,
  878. pszPriorityList,
  879. lstrlen(pszPriorityList)+1
  880. );
  881. // delete the old one
  882. RegDeleteValue(
  883. hKeyHandoffPriorities,
  884. gaszMediaModes[i]
  885. );
  886. }
  887. GlobalFree( pszPriorityList );
  888. }
  889. }
  890. j<<=1; // shift to next media mode
  891. }
  892. RegCloseKey(hKeyMediaModes);
  893. }
  894. RegCloseKey(hKeyHandoffPriorities);
  895. }
  896. }
  897. #if DBG
  898. #include "stdarg.h"
  899. #include "stdio.h"
  900. VOID
  901. DbgPrt(
  902. DWORD dwDbgLevel,
  903. PSTR lpszFormat,
  904. ...
  905. )
  906. /*++
  907. Routine Description:
  908. Formats the incoming debug message & calls DbgPrint
  909. Arguments:
  910. DbgLevel - level of message verboseness
  911. DbgMessage - printf-style format string, followed by appropriate
  912. list of arguments
  913. Return Value:
  914. --*/
  915. {
  916. static DWORD gdwDebugLevel = 0; //HACKHACK
  917. if (dwDbgLevel <= gdwDebugLevel)
  918. {
  919. char buf[256] = "TAPIUPR: ";
  920. va_list ap;
  921. va_start(ap, lpszFormat);
  922. wvsprintf (&buf[8],
  923. lpszFormat,
  924. ap
  925. );
  926. lstrcat (buf, "\n");
  927. OutputDebugStringA (buf);
  928. va_end(ap);
  929. }
  930. }
  931. #endif