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.

1145 lines
36 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1991 - 2000.
  5. //
  6. // File: VQuery.Cxx
  7. //
  8. // Contents: Query interface functions
  9. //
  10. // Functions: ProxyErrorToCIError
  11. // EvalQuery
  12. // EvalMetadataQuery
  13. // ForceMasterMerge
  14. // AbortMerges
  15. // CiState
  16. // AddScopeToCI
  17. // RemoveScopeFromCI
  18. // BeginCacheTransaction
  19. // SetupCacheEx
  20. // SetupCache
  21. // EndCacheTransaction
  22. // DumpWorkId
  23. // SetCatalogState
  24. //
  25. // History: 18-Aug-91 KyleP Created.
  26. // 16-Sep-96 dlee made it work with cisvc
  27. //
  28. //----------------------------------------------------------------------------
  29. #include <pch.cxx>
  30. #pragma hdrstop
  31. #include "svcquery.hxx"
  32. #include <isearch.hxx>
  33. #include <svccatpx.hxx>
  34. #include <cidbprop.hxx>
  35. #include <dbprputl.hxx>
  36. #include <fsciclnt.h>
  37. #include <ciframe.hxx>
  38. #include <fsci.hxx>
  39. #include <cifwexp.hxx>
  40. #include <ciregkey.hxx>
  41. #include <fsciexps.hxx>
  42. typedef SCODE (* T_FsCiShutdown)(void);
  43. static GUID clsidStorageDocStoreLocator = CLSID_StorageDocStoreLocator;
  44. static XLibHandle gxCiFrmWrk;
  45. static T_MakeGenericQueryForDocStore gprocMakeGenericQuery = 0;
  46. extern CStaticMutexSem g_mtxCommandCreator;
  47. void SetIDbProperties( IDBProperties * pIDbProp,
  48. WCHAR const * pwcCatalog,
  49. WCHAR const * pwcMachine,
  50. GUID & clientGuid,
  51. WCHAR const * pwcScope = 0,
  52. CiMetaData eType = CiAdminOp);
  53. //+-------------------------------------------------------------------------
  54. //
  55. // Function: ProxyErrorToCIError, public
  56. //
  57. // Synopsis: Attempt to translate an error code from the proxy into
  58. // a CI error code.
  59. //
  60. // Arguments: [sc] -- source error
  61. //
  62. // Returns: The translated or original error
  63. //
  64. // History: 06-Jan-98 dlee Created
  65. //
  66. //--------------------------------------------------------------------------
  67. SCODE ProxyErrorToCIError( CException & e )
  68. {
  69. SCODE sc = GetScodeError( e );
  70. if ( HRESULT_FROM_WIN32( ERROR_FILE_NOT_FOUND ) == sc )
  71. sc = CI_E_NOT_RUNNING;
  72. else if ( STATUS_NOT_FOUND == sc )
  73. sc = CI_E_NOT_FOUND;
  74. else if ( sc == HRESULT_FROM_WIN32( ERROR_SEM_TIMEOUT ) ||
  75. sc == HRESULT_FROM_WIN32( ERROR_PIPE_BUSY ) )
  76. sc = CI_E_TIMEOUT;
  77. return sc;
  78. } //ProxyErrorToCIError
  79. //+---------------------------------------------------------------------------
  80. //
  81. // Function: CreateDbProperties
  82. //
  83. // Synopsis: Helper function to create an IDBProperties and set the
  84. // given parameters as DBPROPS in the IDBProperties.
  85. //
  86. // Arguments: [pwcCatalog] - Name or location of the catalog.
  87. // [pwcMachine] - Name of the machine to connect to.
  88. // [pwcScopes ] - (first scope) directory.
  89. // [eType] - query type
  90. //
  91. // Returns: Pointer to an initilized IDBProperties interface.
  92. //
  93. // History: 1-15-97 srikants Created
  94. // 5-14-97 mohamedn use SetIDbProperties
  95. //
  96. //----------------------------------------------------------------------------
  97. IDBProperties * CreateDbProperties( WCHAR const * pwcCatalog,
  98. WCHAR const * pwcMachine,
  99. WCHAR const * pwcScopes = 0,
  100. CiMetaData eType = CiAdminOp )
  101. {
  102. XInterface<IDBProperties> xdbp( new CDbProperties );
  103. if ( xdbp.IsNull() )
  104. THROW( CException( E_OUTOFMEMORY ) );
  105. SetIDbProperties( xdbp.GetPointer(),
  106. pwcCatalog,
  107. pwcMachine,
  108. clsidStorageDocStoreLocator,
  109. pwcScopes,
  110. eType );
  111. return xdbp.Acquire();
  112. }
  113. //+-------------------------------------------------------------------------
  114. //
  115. // Function: LoadCiFrmWrkLibrary, private
  116. //
  117. // Synopsis: Loads the appropriate framework library
  118. //
  119. // Arguments: None
  120. //
  121. // Returns: Handle to library
  122. //
  123. // History: 22-Apr-97 KrishnaN Created
  124. // 02-Jun-97 KrishnaN Decide between olympus/ci version
  125. // based on registry entry.
  126. //
  127. //--------------------------------------------------------------------------
  128. inline HINSTANCE LoadCiFrmWrkLibrary()
  129. {
  130. HINSTANCE hLib;
  131. WCHAR awszLibName[MAX_PATH];
  132. //
  133. // We want to be able to load the right version of the framework dll.
  134. // The olympus and ci versions are for the most part similar, but not
  135. // identical. So when Olympus is installed, we should lookup in the
  136. // registry to find out what dll to use. If that registry entry is
  137. // not found, we default to query.dll.
  138. //
  139. wcscpy(awszLibName, L"QUERY.DLL");
  140. HKEY hKey;
  141. long sc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, // Root
  142. wcsRegCommonAdminSubKey, // key
  143. 0, // Reserved
  144. KEY_READ, // Access
  145. &hKey); // Handle
  146. // For a smoother transition, if we don't find it in the
  147. // newly defined commonadminsubkey, look for it in the old place
  148. if (ERROR_SUCCESS != sc)
  149. sc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, // Root
  150. L"Software\\Microsoft\\Site Server\\3.0\\Search\\CiFramework",
  151. 0, // Reserved
  152. KEY_READ, // Access
  153. &hKey); // Handle
  154. if (ERROR_SUCCESS == sc)
  155. {
  156. DWORD dwType = REG_SZ;
  157. DWORD dwSize = MAX_PATH * sizeof(WCHAR);
  158. // If we successfully read the value, the full path name will be read in
  159. sc = RegQueryValueEx(hKey,
  160. L"CiFrmWrkDll",
  161. 0,
  162. &dwType,
  163. (LPBYTE)awszLibName,
  164. &dwSize
  165. );
  166. RegCloseKey(hKey);
  167. }
  168. hLib = LoadLibraryW(awszLibName);
  169. if ( 0 == hLib )
  170. {
  171. ciDebugOut(( DEB_ERROR, "Error %d occurred in LoadLibrary on %ws\n",
  172. GetLastError(), awszLibName ));
  173. THROW(CException( E_UNEXPECTED ));
  174. }
  175. gprocMakeGenericQuery = (T_MakeGenericQueryForDocStore)
  176. GetProcAddress( hLib, "MakeGenericQueryForDocStore" );
  177. if (0 == gprocMakeGenericQuery)
  178. {
  179. ciDebugOut((DEB_ERROR, "Failed to locate MakeGenericQueryForDocStore"
  180. " in the framework dll\n"));
  181. THROW(CException( E_UNEXPECTED ));
  182. }
  183. return hLib;
  184. }
  185. //+-------------------------------------------------------------------------
  186. //
  187. // Function: EvalQuery, public
  188. //
  189. // Synopsis: Simulates bind to to ci object store
  190. //
  191. // Arguments: [ppQuery] -- returns the PIInternalQuery
  192. // [idbProps] -- object exposing IDBProperties
  193. // [pDocStore] -- doc store interface pointer
  194. //
  195. // Returns: SCODE result
  196. //
  197. // History: 12 Dec 95 AlanW Created
  198. // 08-Feb-96 KyleP Add virtual path support
  199. // 01-Nov-96 dlee Add multi-scope support, return scode
  200. // 14-May-97 mohamedn hidden fs/core property set details.
  201. //
  202. //--------------------------------------------------------------------------
  203. SCODE EvalQuery(
  204. PIInternalQuery ** ppQuery,
  205. CDbProperties & idbProps,
  206. ICiCDocStore * pDocStore)
  207. {
  208. SCODE sc = S_OK;
  209. PIInternalQuery * pQuery = 0;
  210. CTranslateSystemExceptions xlate;
  211. TRY
  212. {
  213. if ( pDocStore )
  214. {
  215. //
  216. // If the framework library is not loaded, load it and get the
  217. // generic query
  218. //
  219. if ( 0 == gxCiFrmWrk.Get() )
  220. {
  221. //
  222. // we don't want to go through this crit sect for each
  223. // invocation of EvalQuery. So first check for the handle
  224. // to be null, and then take a lock.
  225. // Multiple threads running simultaeneously could get past
  226. // the check for null handle, but only the first one that gets
  227. // the lock will have the chance to set the gxCiFrmWrk variable.
  228. // The remaining will find that the second check for null
  229. // handle doesn't hold and will do nothing.
  230. //
  231. CLock lock(g_mtxCommandCreator);
  232. if (0 == gxCiFrmWrk.Get())
  233. {
  234. Win4Assert( 0 == gprocMakeGenericQuery);
  235. gxCiFrmWrk.Set(LoadCiFrmWrkLibrary());
  236. }
  237. }
  238. sc = gprocMakeGenericQuery( &idbProps, pDocStore, &pQuery);
  239. }
  240. else
  241. {
  242. CGetDbProps dbProp;
  243. dbProp.GetProperties( &idbProps , CGetDbProps::eMachine );
  244. WCHAR const *pwcMachine = dbProp.GetMachine();
  245. if ( 0 != pwcMachine )
  246. {
  247. pQuery = new CSvcQuery( pwcMachine,
  248. &idbProps );
  249. }
  250. else
  251. {
  252. THROW( CException(E_INVALIDARG) );
  253. }
  254. }
  255. }
  256. CATCH( CException, e )
  257. {
  258. vqDebugOut(( DEB_ERROR,
  259. "Catastrophic error 0x%x in EvalQuery\n",
  260. e.GetErrorCode() ));
  261. pQuery = 0;
  262. //
  263. // NOTE: Fix for bug 86178. This is a lower level routine and it should
  264. // propogate errors untranslated to the upper layer (ICommand::Execute).
  265. //
  266. sc = e.GetErrorCode();
  267. }
  268. END_CATCH;
  269. *ppQuery = pQuery;
  270. return sc;
  271. } //EvalQuery
  272. //+-------------------------------------------------------------------------
  273. //
  274. // Function: EvalMetadataQuery, public
  275. //
  276. // Synopsis: Simulates bind to PIInternalQuery for ci object store
  277. //
  278. // Arguments: [ppQuery] - returns the PIInternalQuery
  279. // [eType] - Type of metadata
  280. // [wcsCat] - Catalog location
  281. // [pwcsMachine] - Machine on which catalog resides
  282. //
  283. // Returns: SCODE result
  284. //
  285. // History: 12 Dec 95 AlanW Created
  286. // 08-Feb-96 KyleP Add virtual path support
  287. //
  288. //--------------------------------------------------------------------------
  289. SCODE EvalMetadataQuery(
  290. PIInternalQuery ** ppQuery,
  291. CiMetaData eType,
  292. WCHAR const * wcsCat,
  293. WCHAR const * wcsMachine )
  294. {
  295. *ppQuery = 0;
  296. PIInternalQuery * pQuery = 0;
  297. SCODE sc = S_OK;
  298. CTranslateSystemExceptions xlate;
  299. TRY
  300. {
  301. XInterface<IDBProperties> xDbProps( CreateDbProperties( wcsCat,
  302. wcsMachine,
  303. 0,
  304. eType ) );
  305. Win4Assert( 0 != wcsMachine );
  306. pQuery = new CSvcQuery( wcsMachine, xDbProps.GetPointer() );
  307. }
  308. CATCH( CException, e )
  309. {
  310. vqDebugOut(( DEB_ERROR,
  311. "Catastrophic error 0x%x in EvalMetadataQuery\n",
  312. e.GetErrorCode() ));
  313. pQuery = 0;
  314. //
  315. // NOTE: Fix for bug 86178. This is a lower level routine and it should
  316. // propogate errors untranslated to the upper layer (ICommand::Execute).
  317. //
  318. sc = e.GetErrorCode();
  319. }
  320. END_CATCH;
  321. *ppQuery = pQuery;
  322. return sc;
  323. } //EvalMetadataQuery
  324. //+-------------------------------------------------------------------------
  325. //
  326. // Function: ForceMasterMerge, public
  327. //
  328. // Synopsis: Forces a master merge on the partition ID specified
  329. //
  330. // Arguments: [wcsDrive] - Drive to force merge on
  331. // [pwcsCat] - Catalog name
  332. // [pwcsMachine] - Machine on which catalog resides
  333. // [partId] - PartitionID to force merge on
  334. //
  335. // History: 01-Nov-95 DwightKr Created
  336. //
  337. //--------------------------------------------------------------------------
  338. SCODE ForceMasterMerge(
  339. WCHAR const * wcsDrive,
  340. WCHAR const * pwcsCat,
  341. WCHAR const * pwcsMachine,
  342. ULONG partId )
  343. {
  344. SCODE status = S_OK;
  345. //
  346. // Verify that we have legal parameters
  347. //
  348. if ( (0==wcsDrive) || (1!=partId) )
  349. return E_INVALIDARG;
  350. CTranslateSystemExceptions xlate;
  351. TRY
  352. {
  353. XInterface<IDBProperties> xDbProps( CreateDbProperties( pwcsCat,
  354. pwcsMachine,
  355. wcsDrive ) );
  356. Win4Assert( 0 != pwcsMachine );
  357. CSvcCatProxy cat( pwcsMachine, xDbProps.GetPointer() );
  358. cat.ForceMerge( partId );
  359. }
  360. CATCH( CException, e )
  361. {
  362. status = ProxyErrorToCIError( e );
  363. }
  364. END_CATCH
  365. return status;
  366. } //ForceMasterMerge
  367. //+-------------------------------------------------------------------------
  368. //
  369. // Function: AbortMerges, public
  370. //
  371. // Synopsis: Aborts any merge in progress in the specified partid.
  372. //
  373. // Arguments: [wcsDrive] -- Drive to force merge on
  374. // [partId] -- PartitionID to force merge on
  375. //
  376. // History: 01-Nov-95 DwightKr Created
  377. //
  378. //--------------------------------------------------------------------------
  379. SCODE AbortMerges(
  380. WCHAR const * wcsDrive,
  381. WCHAR const * pwcsCat,
  382. WCHAR const * pwcsMachine,
  383. ULONG partId )
  384. {
  385. SCODE status = S_OK;
  386. //
  387. // Verify that we have legal parameters
  388. //
  389. if ( (0==wcsDrive) || (1!=partId) )
  390. return E_INVALIDARG;
  391. CTranslateSystemExceptions xlate;
  392. TRY
  393. {
  394. XInterface<IDBProperties> xDbProps( CreateDbProperties( pwcsCat,
  395. pwcsMachine,
  396. wcsDrive ) );
  397. Win4Assert( 0 != pwcsMachine );
  398. CSvcCatProxy cat( pwcsMachine, xDbProps.GetPointer() );
  399. cat.AbortMerge( partId );
  400. }
  401. CATCH( CException, e )
  402. {
  403. status = ProxyErrorToCIError( e );
  404. }
  405. END_CATCH
  406. return status;
  407. } //AbortMerges
  408. //+-------------------------------------------------------------------------
  409. //
  410. // Function: CIState, public
  411. //
  412. // Synopsis: Returns the state of the CI for the drive specified.
  413. //
  414. // Arguments: [pwcsCat] -- Catalog
  415. // [pwcsMachine] -- Machine name
  416. // [pCiState] -- Current state of the CI
  417. //
  418. // History: 01-Nov-95 DwightKr Created
  419. //
  420. //--------------------------------------------------------------------------
  421. SCODE CIState( WCHAR const * pwcsCat,
  422. WCHAR const * pwcsMachine,
  423. CI_STATE * pCiState )
  424. {
  425. // Verify that we have legal parameters
  426. if ( 0 == pCiState ||
  427. 0 == pwcsCat ||
  428. pCiState->cbStruct < sizeof pCiState->cbStruct )
  429. return E_INVALIDARG;
  430. if ( 0 == pwcsMachine )
  431. pwcsMachine = L".";
  432. SCODE status = S_OK;
  433. CTranslateSystemExceptions xlate;
  434. TRY
  435. {
  436. XInterface<IDBProperties> xDbProps( CreateDbProperties( pwcsCat, pwcsMachine ) );
  437. CSvcCatProxy cat( pwcsMachine, xDbProps.GetPointer() );
  438. cat.CiState( *pCiState );
  439. }
  440. CATCH( CException, e )
  441. {
  442. status = ProxyErrorToCIError( e );
  443. }
  444. END_CATCH
  445. return status;
  446. } //CiState
  447. //+-------------------------------------------------------------------------
  448. //
  449. // Function: UpdateContentIndex, public
  450. //
  451. // Synopsis: Registers documents for indexing.
  452. //
  453. // Arguments: [wcsRoot] -- Root of scope to scan for updates
  454. // [wcsCat] -- Override for catalog location
  455. //
  456. // Returns:
  457. //
  458. // History: 23-Jun-93 KyleP Added header
  459. //
  460. //--------------------------------------------------------------------------
  461. ULONG UpdateContentIndex(
  462. WCHAR const * wcsRoot,
  463. WCHAR const * wcsCat,
  464. WCHAR const * wcsMachine,
  465. BOOL fFull )
  466. {
  467. SCODE status = S_OK;
  468. CTranslateSystemExceptions xlate;
  469. TRY
  470. {
  471. IDBProperties * pDbProps = CreateDbProperties( wcsCat, wcsMachine );
  472. XInterface<IDBProperties> xProps( pDbProps );
  473. CSvcCatProxy cat( wcsMachine, pDbProps );
  474. cat.UpdateDocuments( wcsRoot, fFull ? UPD_FULL : UPD_INCREM );
  475. }
  476. CATCH( CException, e )
  477. {
  478. status = ProxyErrorToCIError( e );
  479. }
  480. END_CATCH
  481. return (ULONG) status;
  482. } //UpdateContentIndex
  483. //+---------------------------------------------------------------------------
  484. //
  485. // Member: AddScopeToCI
  486. //
  487. // Synopsis: Adds a scope for down level ContentIndex. All documents in
  488. // the specified scope will be indexed.
  489. //
  490. // Arguments: [wcsRoot] - Scope to add
  491. // [wcsCat] - Alternate location for catalog
  492. // [wcsMachine] - Machine on which catalog resides, L"." for
  493. // the local machine
  494. //
  495. // Returns: Status code
  496. //
  497. // History: 1-21-96 srikants Created
  498. //
  499. //----------------------------------------------------------------------------
  500. SCODE AddScopeToCI (
  501. WCHAR const * wcsRoot,
  502. WCHAR const * wcsCat,
  503. WCHAR const * wcsMachine )
  504. {
  505. SCODE sc = S_OK;
  506. CTranslateSystemExceptions xlate;
  507. TRY
  508. {
  509. IDBProperties * pDbProps = CreateDbProperties( wcsCat, wcsMachine );
  510. XInterface<IDBProperties> xProps( pDbProps );
  511. CSvcCatProxy cat( wcsMachine, pDbProps );
  512. cat.AddScopeToCI( wcsRoot );
  513. }
  514. CATCH( CException, e )
  515. {
  516. sc = GetOleError( e );
  517. }
  518. END_CATCH
  519. return sc;
  520. } //AddScopeToCI
  521. //+---------------------------------------------------------------------------
  522. //
  523. // Member: RemoveScopeFromCI
  524. //
  525. // Synopsis: Removes a scope for down level ContentIndex. All documents in
  526. // the specified scope will be deleted.
  527. //
  528. // Arguments: [wcsRoot] - Scope to remove
  529. // [wcsCat] - Alternate location for catalog
  530. // [wcsMachine] - Machine on which catalog resides, L"." for
  531. // the local machine
  532. //
  533. // Returns: Status code
  534. //
  535. // History: 1-21-96 srikants Created
  536. //
  537. //----------------------------------------------------------------------------
  538. SCODE RemoveScopeFromCI(
  539. WCHAR const * wcsRoot,
  540. WCHAR const * wcsCat,
  541. WCHAR const * wcsMachine )
  542. {
  543. SCODE sc = S_OK;
  544. CTranslateSystemExceptions xlate;
  545. TRY
  546. {
  547. IDBProperties * pDbProps = CreateDbProperties( wcsCat, wcsMachine );
  548. XInterface<IDBProperties> xProps( pDbProps );
  549. CSvcCatProxy cat( wcsMachine, pDbProps );
  550. cat.RemoveScopeFromCI( wcsRoot );
  551. }
  552. CATCH( CException, e )
  553. {
  554. sc = GetOleError( e );
  555. }
  556. END_CATCH
  557. return sc;
  558. } //RemoveScopeFromCI
  559. //+---------------------------------------------------------------------------
  560. //
  561. // Function: BeginCacheTransaction, public
  562. //
  563. // Synopsis: Begin a cache update session.
  564. //
  565. // Arguments: [pulToken] - Token representing transaction returned here.
  566. // [wcsRoot] - Root of scope to scan for updates
  567. // [wcsCat] - Override for catalog location
  568. // [wcsMachine] - Machine on which catalog resides, L"." for
  569. // the local machine
  570. //
  571. // History: 20-Jun-96 KyleP Created.
  572. //
  573. //----------------------------------------------------------------------------
  574. SCODE BeginCacheTransaction(
  575. ULONG_PTR * pulToken,
  576. WCHAR const * wcsRoot,
  577. WCHAR const * wcsCat,
  578. WCHAR const * wcsMachine )
  579. {
  580. SCODE sc = S_OK;
  581. CTranslateSystemExceptions xlate;
  582. TRY
  583. {
  584. XInterface<IDBProperties> xDbProps( CreateDbProperties( wcsCat,
  585. wcsMachine ) );
  586. CSvcCatProxy cat( wcsMachine, xDbProps.GetPointer() );
  587. *pulToken = 0; // Catch access violation
  588. *pulToken = cat.BeginCacheTransaction();
  589. }
  590. CATCH( CException, e )
  591. {
  592. sc = ProxyErrorToCIError( e );
  593. }
  594. END_CATCH
  595. return sc;
  596. } //BeginCacheTransaction
  597. //+---------------------------------------------------------------------------
  598. //
  599. // Function: SetupCacheEx, public
  600. //
  601. // Synopsis: Modify cache to store (or not store) property.
  602. //
  603. // Arguments: [ps] - Property to cache.
  604. // [vt] - Datatype of property. VT_VARIANT if unknown.
  605. // [cbMaxLen] - Soft-maximum length for variable length
  606. // properties. This much space is pre-allocated
  607. // in original record. A length of 0 will remove
  608. // property from cache.
  609. // [ulToken] - Token indentifying open transaction
  610. // [fModifiable]- Is meta info modifiable?
  611. // [dwLevel] - Primary or secondary store?
  612. // [wcsRoot] - Root of scope to scan for updates
  613. // [wcsCat] - Override for catalog location
  614. // [wcsMachine] - Machine on which catalog resides, L"." for
  615. // the local machine
  616. //
  617. // History: 18-Nov-97 KrishnaN Created.
  618. //
  619. //----------------------------------------------------------------------------
  620. SCODE SetupCacheEx(
  621. FULLPROPSPEC const * ps,
  622. ULONG vt,
  623. ULONG cbMaxLen,
  624. ULONG_PTR ulToken,
  625. BOOL fModifiable,
  626. DWORD dwStoreLevel,
  627. WCHAR const * wcsRoot,
  628. WCHAR const * wcsCat,
  629. WCHAR const * wcsMachine )
  630. {
  631. Win4Assert(PRIMARY_STORE == dwStoreLevel ||
  632. SECONDARY_STORE == dwStoreLevel);
  633. SCODE sc = S_OK;
  634. CTranslateSystemExceptions xlate;
  635. TRY
  636. {
  637. XInterface<IDBProperties> xDbProps( CreateDbProperties( wcsCat,
  638. wcsMachine ) );
  639. CSvcCatProxy cat( wcsMachine, xDbProps.GetPointer() );
  640. cat.SetupCache( *(CFullPropSpec const *)(ULONG_PTR)ps,
  641. vt,
  642. cbMaxLen,
  643. ulToken,
  644. fModifiable,
  645. dwStoreLevel );
  646. }
  647. CATCH( CException, e )
  648. {
  649. sc = ProxyErrorToCIError( e );
  650. }
  651. END_CATCH
  652. return sc;
  653. } //SetupCacheEx
  654. //+---------------------------------------------------------------------------
  655. //
  656. // Function: SetupCache, public
  657. //
  658. // Synopsis: Modify cache to store (or not store) property.
  659. //
  660. // Arguments: [ps] - Property to cache.
  661. // [vt] - Datatype of property. VT_VARIANT if unknown.
  662. // [cbMaxLen] - Soft-maximum length for variable length
  663. // properties. This much space is pre-allocated
  664. // in original record. A length of 0 will remove
  665. // property from cache.
  666. // [ulToken] - Token indentifying open transaction
  667. // [wcsRoot] - Root of scope to scan for updates
  668. // [wcsCat] - Override for catalog location
  669. // [wcsMachine] - Machine on which catalog resides, L"." for
  670. // the local machine
  671. //
  672. // History: 20-Jun-96 KyleP Created.
  673. // 18-Nov-97 KrishnaN Used SetupCacheEx.
  674. //
  675. //----------------------------------------------------------------------------
  676. SCODE SetupCache(
  677. FULLPROPSPEC const * ps,
  678. ULONG vt,
  679. ULONG cbMaxLen,
  680. ULONG_PTR ulToken,
  681. WCHAR const * wcsRoot,
  682. WCHAR const * wcsCat,
  683. WCHAR const * wcsMachine )
  684. {
  685. // Default fModifiable = TRUE and storeLevel = PRIMARY
  686. return SetupCacheEx(ps, vt, cbMaxLen, ulToken, TRUE,
  687. PRIMARY_STORE, wcsRoot, wcsCat, wcsMachine);
  688. } //SetupCache
  689. //+---------------------------------------------------------------------------
  690. //
  691. // Function: EndCacheTransaction, public
  692. //
  693. // Synopsis: Ends a cache update session.
  694. //
  695. // Arguments: [ulToken] - Token representing transaction.
  696. // [fCommit] - TRUE if transaction should be commited.
  697. // [wcsRoot] - Root of scope to scan for updates
  698. // [wcsCat] - Override for catalog location
  699. // [wcsMachine] - Machine on which catalog resides, L"." for
  700. // the local machine
  701. //
  702. // History: 20-Jun-96 KyleP Created.
  703. //
  704. //----------------------------------------------------------------------------
  705. SCODE EndCacheTransaction(
  706. ULONG_PTR ulToken,
  707. BOOL fCommit,
  708. WCHAR const * wcsRoot,
  709. WCHAR const * wcsCat,
  710. WCHAR const * wcsMachine )
  711. {
  712. SCODE sc = S_OK;
  713. CTranslateSystemExceptions xlate;
  714. TRY
  715. {
  716. XInterface<IDBProperties> xDbProps( CreateDbProperties( wcsCat,
  717. wcsMachine ) );
  718. CSvcCatProxy cat( wcsMachine, xDbProps.GetPointer() );
  719. cat.EndCacheTransaction( ulToken, fCommit );
  720. }
  721. CATCH( CException, e )
  722. {
  723. sc = ProxyErrorToCIError( e );
  724. }
  725. END_CATCH
  726. return sc;
  727. } //EndCacheTransaction
  728. //+-------------------------------------------------------------------------
  729. //
  730. // Function: DumpWorkId, public
  731. //
  732. // Synopsis: Dump all data for a particular workid
  733. //
  734. // Arguments: [wcsDrive] - Drive to query
  735. // [wid] - Wid to search for
  736. // [pb] - Buffer provided for writing results
  737. // [cb] - Size of [pb]
  738. // [pwcsCat] - Override for catalog location
  739. // [wcsMachine] - Machine on which catalog resides, L"." for
  740. // the local machine
  741. //
  742. // History: 03-Apr-95 KyleP Created
  743. //
  744. //--------------------------------------------------------------------------
  745. SCODE DumpWorkId(
  746. WCHAR const * wcsDrive,
  747. ULONG wid,
  748. BYTE * pb,
  749. ULONG & cb,
  750. WCHAR const * pwcsCat,
  751. WCHAR const * pwcsMachine,
  752. ULONG iid )
  753. {
  754. #if 0
  755. #if CIDBG == 1
  756. SCODE status = S_OK;
  757. BYTE * pbStart = pb;
  758. CTranslateSystemExceptions xlate;
  759. TRY
  760. {
  761. PCatalog * pCat = GetOne( wcsDrive, pwcsCat );
  762. if ( 0 != pCat )
  763. {
  764. ULONG UNALIGNED * pul = (ULONG *)pb;
  765. pul += 2;
  766. *pul = 0; // Initial bookmark of zero
  767. unsigned const cbBuffer = 1024 * 32;
  768. while ( cb >= cbBuffer )
  769. {
  770. pCat->DumpWorkId( wid, iid, pb, cbBuffer );
  771. //
  772. // Find end of buffer.
  773. //
  774. for ( char * psz = (char *)pb; *psz; psz++ )
  775. continue;
  776. //
  777. // Check for null ulong
  778. //
  779. psz++;
  780. pul = (ULONG UNALIGNED *)psz;
  781. if ( *pul == 0 )
  782. {
  783. pb = (BYTE *)psz;
  784. break;
  785. }
  786. else
  787. {
  788. psz--;
  789. unsigned const cbBookmark = sizeof(ULONG) + sizeof(WORKID) + sizeof(CKeyBuf);
  790. memmove( psz, psz+1, cbBookmark );
  791. cb -= (BYTE *)psz - pb;;
  792. pb = (BYTE *)psz;
  793. }
  794. }
  795. }
  796. else
  797. {
  798. status = STATUS_NOT_FOUND;
  799. }
  800. }
  801. CATCH( CException, e )
  802. {
  803. status = e.GetErrorCode();
  804. }
  805. END_CATCH
  806. cb = pb - pbStart;
  807. return( status );
  808. #else // CIDBG == 1
  809. return( STATUS_NOT_IMPLEMENTED );
  810. #endif // CIDBG == 1
  811. #endif // 0
  812. return STATUS_NOT_IMPLEMENTED;
  813. } //DumpWorkId
  814. //+---------------------------------------------------------------------------
  815. //
  816. // Member: CIShutdown
  817. //
  818. // Synopsis: Calls through to FsCiShutdown
  819. //
  820. // History: 3-06-97 srikants Created
  821. //
  822. //----------------------------------------------------------------------------
  823. void CIShutdown()
  824. {
  825. FsCiShutdown();
  826. } //CIShutdown
  827. //+---------------------------------------------------------------------------
  828. //
  829. // Function: SetIDbProperties
  830. //
  831. // Synopsis: Sets scope properties on IDBProperties
  832. //
  833. // Arguments: [pIDbProp] -- IDBProperties interface to set scope props on.
  834. // [pwcCatalog] -- catalog name
  835. // [pwcMachine] -- machine name
  836. // [clientGuid] -- client guid
  837. // [pwcScope] -- scope path
  838. // [eType] -- query type
  839. //
  840. // History: 14-May-97 mohamedn created
  841. //
  842. //----------------------------------------------------------------------------
  843. void SetIDbProperties( IDBProperties * pIDbProp,
  844. WCHAR const * pwcCatalog,
  845. WCHAR const * pwcMachine,
  846. CLSID & clientGuid,
  847. WCHAR const * pwcScope,
  848. CiMetaData eType )
  849. {
  850. const unsigned cElements = 1;
  851. XBStr pxMachines[cElements];
  852. XBStr pxCatalogs[cElements];
  853. XBStr pxScopes [cElements];
  854. DWORD aDepths [cElements];
  855. //
  856. // set machine name in a BSTR
  857. //
  858. if ( 0 != pwcMachine )
  859. pxMachines[0].SetText( (WCHAR *)pwcMachine);
  860. else
  861. pxMachines[0].SetText(L".");
  862. //
  863. // set catalog name in a BSTR
  864. //
  865. if ( pwcCatalog )
  866. {
  867. pxCatalogs[0].SetText( (WCHAR *)pwcCatalog);
  868. }
  869. else
  870. {
  871. Win4Assert( !"No-Catalog set. Fatal Error" );
  872. THROW ( CException(E_INVALIDARG) );
  873. }
  874. //
  875. // set scope name in a BSTR
  876. //
  877. if ( pwcScope )
  878. pxScopes[0].SetText( (WCHAR *)pwcScope );
  879. else
  880. pxScopes[0].SetText( L"\\" );
  881. //
  882. // set client guid
  883. //
  884. WCHAR awcClientGuid[ 40 ]; // 39 is all we need
  885. int cb = StringFromGUID2( clientGuid,
  886. awcClientGuid,
  887. sizeof awcClientGuid / sizeof WCHAR );
  888. Win4Assert( 0 != cb );
  889. XBStr xbstrClientGuid;
  890. xbstrClientGuid.SetText( awcClientGuid );
  891. //
  892. // set query type and defualt Depth
  893. //
  894. aDepths[0] = QUERY_DEEP;
  895. //
  896. // assemble safe arrays of the properties to set
  897. //
  898. SAFEARRAY saScope = { 1, // Dimension
  899. FADF_AUTO | FADF_BSTR, // Flags: on stack, contains BSTRs
  900. sizeof(BSTR), // Size of an element
  901. 1, // Lock count. 1 for safety.
  902. (void *)pxScopes, // The data
  903. { cElements, 0 } }; // Bounds (element count, low bound)
  904. SAFEARRAY saDepth = { 1, // Dimension
  905. FADF_AUTO, // Flags: on stack
  906. sizeof(LONG), // Size of an element
  907. 1, // Lock count. 1 for safety.
  908. (void *)aDepths, // The data
  909. { cElements, 0 } }; // Bounds (element count, low bound)
  910. SAFEARRAY saCatalog = { 1, // Dimension
  911. FADF_AUTO | FADF_BSTR,// Flags: on stack, contains BSTRs
  912. sizeof(BSTR), // Size of an element
  913. 1, // Lock count. 1 for safety.
  914. (void *)pxCatalogs, // The data
  915. { cElements, 0 } }; // Bounds (element count, low bound)
  916. SAFEARRAY saMachine = { 1, // Dimension
  917. FADF_AUTO | FADF_BSTR,// Flags: on stack, contains BSTRs
  918. sizeof(BSTR), // Size of an element
  919. 1, // Lock count. 1 for safety.
  920. (void *)pxMachines, // The data
  921. { cElements, 0 } }; // Bounds (element count, low bound)
  922. SAFEARRAY saClientGuid = { 1, // Dimension
  923. FADF_AUTO | FADF_BSTR,// Flags: on stack, contains BSTRs
  924. sizeof(BSTR), // Size of an element
  925. 1, // Lock count. 1 for safety.
  926. (void *)&xbstrClientGuid, // The data
  927. { 1, 0 } }; // Bounds (element count, low bound)
  928. //
  929. // assemble property sets
  930. //
  931. DBPROP aQueryProps[4] = { { DBPROP_CI_INCLUDE_SCOPES, 0, DBPROPSTATUS_OK, {0, 0, 0}, { VT_BSTR | VT_ARRAY, 0, 0, 0, (ULONG_PTR)&saScope } },
  932. { DBPROP_CI_DEPTHS , 0, DBPROPSTATUS_OK, {0, 0, 0}, { VT_I4 | VT_ARRAY, 0, 0, 0, (ULONG_PTR)&saDepth } },
  933. { DBPROP_CI_CATALOG_NAME , 0, DBPROPSTATUS_OK, {0, 0, 0}, { VT_BSTR | VT_ARRAY, 0, 0, 0, (ULONG_PTR)&saCatalog } },
  934. { DBPROP_CI_QUERY_TYPE , 0, DBPROPSTATUS_OK, {0, 0, 0}, { VT_I4 , 0, 0, 0, eType } } };
  935. DBPROP aCoreProps[2] = { { DBPROP_MACHINE , 0, DBPROPSTATUS_OK, {0, 0, 0}, { VT_BSTR | VT_ARRAY, 0, 0, 0, (ULONG_PTR)&saMachine } },
  936. { DBPROP_CLIENT_CLSID , 0, DBPROPSTATUS_OK, {0, 0, 0}, { VT_BSTR | VT_ARRAY, 0, 0, 0, (ULONG_PTR)&saClientGuid } } };
  937. DBPROPSET aAllPropsets[2] = { {aQueryProps, 4, DBPROPSET_FSCIFRMWRK_EXT } ,
  938. {aCoreProps , 2, DBPROPSET_CIFRMWRKCORE_EXT } };
  939. //
  940. // set property sets
  941. //
  942. SCODE sc = pIDbProp->SetProperties( 2, aAllPropsets );
  943. if ( FAILED( sc ) )
  944. THROW( CException( sc ) );
  945. } //SetIDbProperties
  946. //+-------------------------------------------------------------------------
  947. //
  948. // Function: SetCatalogState, public
  949. //
  950. // Synopsis: Change the catalog's state on the partition ID specified
  951. //
  952. // Arguments: [pwcsCat] - passed in as ADMINISTRATOR for connection
  953. // without docstore assocication
  954. // [pwcsMachine] - Machine on which catalog resides
  955. // [dwNewState] - The state which catalog's going to be
  956. // changed into
  957. // [pdwOldState] - Output, catalog's original state
  958. //
  959. // History: 06-May-98 KitmanH Created
  960. //
  961. //--------------------------------------------------------------------------
  962. SCODE SetCatalogState( WCHAR const * pwcsCat,
  963. WCHAR const * pwcsMachine,
  964. DWORD dwNewState,
  965. DWORD * pdwOldState )
  966. {
  967. SCODE status = S_OK;
  968. if ( 0 == pdwOldState )
  969. return E_INVALIDARG;
  970. if ( 0 == pwcsMachine )
  971. pwcsMachine = L".";
  972. //
  973. // Verify that we have legal parameters
  974. //
  975. CTranslateSystemExceptions xlate;
  976. TRY
  977. {
  978. XInterface<IDBProperties> xDbProps( CreateDbProperties( CIADMIN,
  979. pwcsMachine ) );
  980. CSvcCatProxy cat( pwcsMachine, xDbProps.GetPointer() );
  981. cat.SetCatState( 1, pwcsCat, dwNewState, pdwOldState );
  982. }
  983. CATCH( CException, e )
  984. {
  985. status = ProxyErrorToCIError( e );
  986. }
  987. END_CATCH
  988. return status;
  989. } //SetCatalogState