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.

1722 lines
52 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1991 - 2000.
  5. //
  6. // File: CI.CXX
  7. //
  8. // Contents: Main Content Index class methods
  9. //
  10. // Classes: CContentIndex - Main content index class
  11. // CCI - Exports content index
  12. //
  13. // History: 21-Aug-91 KyleP Added CCI
  14. // 26-Feb-91 KyleP Created stubs
  15. // 25-Mar-91 BartoszM Implemented
  16. // 03-Nov-93 w-PatG Added KeyList methods
  17. // 03-Jan-95 BartoszM Separated Filter Manager
  18. //
  19. //----------------------------------------------------------------------------
  20. #include <pch.cxx>
  21. #pragma hdrstop
  22. #include <cci.hxx>
  23. #include <curstk.hxx>
  24. #include <convert.hxx>
  25. #include <qparse.hxx>
  26. #include <heap.hxx>
  27. #include <pidmap.hxx>
  28. #include <pidxtbl.hxx>
  29. #include <eventlog.hxx>
  30. #include <cievtmsg.h>
  31. #include "ci.hxx"
  32. #include "partn.hxx"
  33. #include "fretest.hxx"
  34. #include "freshcur.hxx"
  35. #include "unioncur.hxx"
  36. #include "widarr.hxx"
  37. #include "index.hxx"
  38. #if CIDBG == 1
  39. void SetGlobalInfoLevel ( ULONG level )
  40. {
  41. _SetWin4InfoLevel(level);
  42. }
  43. #endif // CIDBG == 1
  44. #define AssertOnNotFound(status) Win4Assert((status) != STATUS_NOT_FOUND)
  45. ULONG ciDebugGlobalFlags = 0;
  46. //+---------------------------------------------------------------------------
  47. //
  48. // Member: CContentIndex::CContentIndex, public
  49. //
  50. // Synopsis: Content index constructor.
  51. //
  52. // Effects: Creates a content index object.
  53. //
  54. // Arguments: [storage] -- Storage object
  55. // [xact] -- startup transaction
  56. // [xIndexNotifTable] -- Table of notifications in push filtering
  57. //
  58. // History: 21-Aug-91 KyleP Removed unused path member
  59. // 26-Feb-91 KyleP Created.
  60. // 01-Apr-91 BartoszM Implemented
  61. //
  62. //----------------------------------------------------------------------------
  63. CContentIndex::CContentIndex( PStorage &storage,
  64. CCiFrameworkParams & params,
  65. ICiCDocStore * pICiCDocStore,
  66. CI_STARTUP_INFO const & startupInfo,
  67. IPropertyMapper * pIPropertyMapper,
  68. CTransaction& xact,
  69. XInterface<CIndexNotificationTable> & xIndexNotifTable )
  70. : _storage (storage),
  71. _resman ( storage,
  72. params,
  73. pICiCDocStore,
  74. startupInfo,
  75. pIPropertyMapper,
  76. xact,
  77. xIndexNotifTable ),
  78. _filterMan ( _resman )
  79. {
  80. }
  81. //+---------------------------------------------------------------------------
  82. //
  83. // Member: CContentIndex::ReserveUpdate, public
  84. //
  85. // Synopsis: Reserves slot for pending update.
  86. //
  87. // Arguments: [wid] -- work id. Used for confirmation of hint.
  88. //
  89. // Returns: Hint. Used in CConentIndex::Update to speed processing.
  90. //
  91. // History: 30-Aug-95 KyleP Created
  92. //
  93. //----------------------------------------------------------------------------
  94. unsigned CContentIndex::ReserveUpdate( WORKID wid )
  95. {
  96. return _resman.ReserveUpdate( wid );
  97. }
  98. //+---------------------------------------------------------------------------
  99. //
  100. // Member: CContentIndex::Update, public
  101. //
  102. // Synopsis: Notifies the content index of document update/deletion.
  103. //
  104. // Effects: Schedules document for
  105. // indexing. This method is also called to add new documents
  106. // (a special case of update).
  107. //
  108. // Arguments: [iHint] -- Cookie representing unique position in queue.
  109. // [wid] -- work id
  110. // [partid] -- Partition id
  111. // [usn] -- unique sequence number
  112. // [volumeId] -- Volume id
  113. // [action] -- update/delete
  114. //
  115. // History: 08-Oct-93 BartoszM Created
  116. //
  117. //----------------------------------------------------------------------------
  118. SCODE CContentIndex::Update( unsigned iHint,
  119. WORKID wid,
  120. PARTITIONID partid,
  121. USN usn,
  122. VOLUMEID volumeId,
  123. ULONG action )
  124. {
  125. return _resman.UpdateDocument ( iHint, wid, partid, usn, volumeId, action );
  126. }
  127. //+---------------------------------------------------------------------------
  128. //
  129. // Member: CContentIndex::Query, public
  130. //
  131. // Synopsis: Resolves a free-text query.
  132. //
  133. // Effects: Parses a free text query and creates a tree of cursors to
  134. // resolve the query.
  135. //
  136. // Arguments: [pRst] -- Pointer to tree of query restriction(s)
  137. //
  138. // [pFlags] -- Holds information about the status of the query
  139. //
  140. // [cPartitions] -- The number of partitions in aPartID.
  141. //
  142. // [aPartID] -- Array of partitionIDs specifying partitions
  143. // to be searched.
  144. //
  145. // [cPendingUpdates] -- A non-zero value here will return pending
  146. // updates in addition to whatever values match the query.
  147. // If more than cPendingUpdates exist in any single partition,
  148. // then the CI_NOT_UP_TO_DATE flag will be set.
  149. //
  150. // [cMaxNodes] -- Maximum expansion for query. Roughly counted
  151. // in terms of leaf query nodes.
  152. //
  153. // Requires: All partitions in aPartID are valid.
  154. //
  155. // Returns: A cursor to iterate over the results
  156. //
  157. // Modifies: pFlags will be modified to reflect the status of the query
  158. //
  159. // History: 19-Sep-91 BartoszM Created.
  160. // 08-Sep-92 AmyA Added pFlags functionality
  161. //
  162. //----------------------------------------------------------------------------
  163. CCursor* CContentIndex::Query( CRestriction const * pRst,
  164. ULONG* pFlags,
  165. UINT cPartitions,
  166. PARTITIONID aPartId[],
  167. ULONG cPendingUpdates,
  168. ULONG cMaxNodes )
  169. {
  170. CCursor* pCurResult = 0;
  171. ciDebugOut (( DEB_ITRACE, "CContentIndex::Query\n" ));
  172. *pFlags = 0; // any incoming information should have been obtained already
  173. if ( pRst == 0 )
  174. {
  175. *pFlags |= CI_NOISE_PHRASE;
  176. }
  177. //
  178. // Acquire resources from resman
  179. //
  180. CIndexSnapshot indSnap ( _resman );
  181. indSnap.Init ( cPartitions, aPartId, cPendingUpdates, pFlags );
  182. unsigned cInd = indSnap.Count();
  183. CCurStack curStack(cInd);
  184. //
  185. // If all the cursors against all persistent indexes only have unfiltered files,
  186. // mark the resulting cursor as only containing unfiltered files.
  187. //
  188. BOOL fUnfilteredOnly = TRUE;
  189. for ( unsigned i = 0; i < cInd; i++ )
  190. {
  191. CConverter convert ( indSnap.Get(i), cMaxNodes );
  192. XCursor xCur( convert.QueryCursor ( pRst ) );
  193. if ( !xCur.IsNull() )
  194. {
  195. if( !xCur->IsUnfilteredOnly() )
  196. {
  197. fUnfilteredOnly = FALSE;
  198. }
  199. curStack.Push( xCur.GetPointer() );
  200. xCur.Acquire();
  201. }
  202. else if ( convert.TooManyNodes() )
  203. {
  204. *pFlags |= CI_TOO_MANY_NODES;
  205. return 0;
  206. }
  207. }
  208. XCursor curResult;
  209. unsigned cCur = curStack.Count();
  210. ciDebugOut((DEB_FILTERWIDS,
  211. "cCur == %d, indSnap.Count() == %d\n",
  212. cCur, indSnap.Count() ));
  213. if ( cCur > 1 )
  214. {
  215. curResult.Set( new CUnionCursor ( cCur, curStack ) );
  216. }
  217. else if ( cCur == 1 )
  218. {
  219. curResult.Set( curStack.Pop() );
  220. }
  221. // Acquires resources from index snapshot
  222. if ( !curResult.IsNull() )
  223. {
  224. curResult.Set( new CFreshCursor ( curResult, indSnap ) );
  225. //
  226. // OR in cursors for pending updates, but only if we have some real updates
  227. // to augment. Performing this action in the absence of real updates will
  228. // make a query over an unindexed property appear to be indexed.
  229. //
  230. if ( cPendingUpdates > 0 )
  231. {
  232. indSnap.AppendPendingUpdates( curResult );
  233. Win4Assert( curStack.Count() == 0 );
  234. }
  235. curResult->SetUnfilteredOnly( fUnfilteredOnly );
  236. }
  237. return( curResult.Acquire() );
  238. }
  239. NTSTATUS CContentIndex::Dismount()
  240. {
  241. _resman.Dismount();
  242. return _filterMan.Dismount();
  243. }
  244. //+---------------------------------------------------------------------------
  245. //
  246. // Member: CContentIndex::FilterReady, public
  247. //
  248. // Synopsis: Retrieves list of documents to be filtered. Blocks thread if
  249. // resources are not available or if there are no documents to
  250. // be filtered.
  251. //
  252. // Arguments: [docBuffer] -- (in, out) buffer for paths and properties of
  253. // documents to be filtered.
  254. // [cwc] -- (in) count of WCHAR's in docBuffer
  255. // [cMaxDocs] -- (in) the maximum number of docs that can be
  256. // filtered at once by the filter daemon.
  257. //
  258. // History: 18-Apr-93 AmyA Created.
  259. //
  260. //----------------------------------------------------------------------------
  261. SCODE CContentIndex::FilterReady ( BYTE * docBuffer,
  262. ULONG & cb,
  263. ULONG cMaxDocs )
  264. {
  265. return _filterMan.FilterReady( docBuffer, cb, cMaxDocs );
  266. }
  267. //+---------------------------------------------------------------------------
  268. //
  269. // Member: CContentIndex::FilterDataReady, public
  270. //
  271. // Synopsis: Adds the contents of entry buffer to the current word list.
  272. //
  273. // Returns: Whether Word List is full
  274. //
  275. // Arguments: [pEntryBuf] -- pointer to data to be added to word list
  276. // [cb] -- count of bytes in buffer
  277. //
  278. // History: 22-Mar-93 AmyA Created.
  279. //
  280. //----------------------------------------------------------------------------
  281. SCODE CContentIndex::FilterDataReady( const BYTE * pEntryBuf, ULONG cb )
  282. {
  283. return _filterMan.FilterDataReady( pEntryBuf, cb );
  284. }
  285. //+---------------------------------------------------------------------------
  286. //
  287. // Member: CContentIndex::FilterMore, public
  288. //
  289. // Synopsis: Commits the current word list and initializes a new one.
  290. //
  291. // Arguments: [aStatus] -- array of STATUS for the resource manager
  292. // [count] -- count for array
  293. //
  294. // History: 03-May-93 AmyA Created.
  295. //
  296. //----------------------------------------------------------------------------
  297. SCODE CContentIndex::FilterMore( const STATUS * aStatus, ULONG count )
  298. {
  299. return( _filterMan.FilterMore( aStatus, count ) );
  300. }
  301. SCODE CContentIndex::FilterStoreValue(
  302. WORKID widFake,
  303. CFullPropSpec const & ps,
  304. CStorageVariant const & var,
  305. BOOL & fStored )
  306. {
  307. return _filterMan.FilterStoreValue( widFake, ps, var, fStored );
  308. }
  309. SCODE CContentIndex::FilterStoreSecurity(
  310. WORKID widFake,
  311. PSECURITY_DESCRIPTOR pSD,
  312. ULONG cbSD,
  313. BOOL & fStored )
  314. {
  315. return _filterMan.FilterStoreSecurity( widFake, pSD, cbSD, fStored );
  316. }
  317. //+---------------------------------------------------------------------------
  318. //
  319. // Member: CContentIndex::FilterDone, public
  320. //
  321. // Synopsis: Commits the current word list.
  322. //
  323. // Arguments: [aStatus] -- array of STATUS for the resource manager
  324. // [count] -- count for array
  325. //
  326. // History: 26-Mar-93 AmyA Created.
  327. //
  328. //----------------------------------------------------------------------------
  329. SCODE CContentIndex::FilterDone( const STATUS * aStatus, ULONG count )
  330. {
  331. return( _filterMan.FilterDone( aStatus, count ) );
  332. }
  333. //+---------------------------------------------------------------------------
  334. //
  335. // Member: CContentIndex::FPSToPROPID, public
  336. //
  337. // Synopsis: Converts FULLPROPSPEC property to PROPID
  338. //
  339. // Arguments: [fps] -- FULLPROPSPEC representation of property
  340. // [pid] -- PROPID written here on success
  341. //
  342. // Returns: S_OK on success
  343. //
  344. // History: 29-Dec-1997 KyleP Created.
  345. //
  346. //----------------------------------------------------------------------------
  347. SCODE CContentIndex::FPSToPROPID( CFullPropSpec const & fps, PROPID & pid )
  348. {
  349. return _filterMan.FPSToPROPID( fps, pid );
  350. }
  351. //+---------------------------------------------------------------------------
  352. //
  353. // Member: CContentIndex::CreatePartition, public
  354. //
  355. // Synopsis: Create a new partition in the content index.
  356. //
  357. // Effects: Stores persistent information about the new partition and
  358. // creates a new partition object.
  359. //
  360. // Arguments: [partID] -- ID of new partition. Further references to the new
  361. // partition must use [partID].
  362. //
  363. // Requires: [partID] is not the ID of any existing partition.
  364. //
  365. // Signals: CPartitionException
  366. //
  367. // History: 26-Feb-91 KyleP Created.
  368. //
  369. //----------------------------------------------------------------------------
  370. void CContentIndex::CreatePartition( PARTITIONID partID )
  371. {
  372. }
  373. //+---------------------------------------------------------------------------
  374. //
  375. // Member: CContentIndex::DestroyPartition, public
  376. //
  377. // Synopsis: Destroys a content index partition and all data within it.
  378. //
  379. // Effects: This is a very powerful call. All document data stored in
  380. // the destroyed partition is permanently lost. The MergePartitions
  381. // method is a more common method of getting rid of a partition.
  382. //
  383. // Arguments: [partID] -- ID of partition to be destroyed.
  384. //
  385. // Signals: CPartitionException
  386. //
  387. // History: 26-Feb-91 KyleP Created.
  388. //
  389. //----------------------------------------------------------------------------
  390. void CContentIndex::DestroyPartition(PARTITIONID partID)
  391. {
  392. }
  393. //+---------------------------------------------------------------------------
  394. //
  395. // Member: CContentIndex::MergePartitions, public
  396. //
  397. // Synopsis: Merges one partition into another.
  398. //
  399. // Effects: Merges all documents in [partSrc] into [partDest] and then
  400. // deletes [partSrc]. Note that although the merge may be
  401. // carried out asyncronously the effects of the merge are
  402. // immediately visible (references to [partDest] will map to
  403. // [partDest] and [partSrc]).
  404. //
  405. // Arguments: [partDest] -- Partition into which [partSrc] is merged.
  406. //
  407. // [partSrc] -- Partition which is merged into [partDest].
  408. //
  409. // Requires: [partDest] and [partSrc] exist.
  410. //
  411. // Signals: CPartitionException
  412. //
  413. // Modifies: [partSrc] is no longer a valid reference in the content index.
  414. //
  415. // Notes: From the point of view of the content index, a partition is just
  416. // a collection of documents. The translation of partitions to
  417. // filesystem scope is performed at a higher level. Thus any
  418. // partition manipulation more complicated than a merge (such as
  419. // changing the scope of a partition) must be performed at a
  420. // higher level.
  421. //
  422. // The content index must be notified about documents which move
  423. // from one partition to another as the result of rescoping but the
  424. // scope change must be translated at a higher level into
  425. // DeleteDocument and UpdateDocument calls.
  426. //
  427. // History: 26-Feb-91 KyleP Created.
  428. //
  429. //----------------------------------------------------------------------------
  430. void CContentIndex::MergePartitions(
  431. PARTITIONID partDest,
  432. PARTITIONID partSrc)
  433. {
  434. }
  435. #if CIDBG == 1
  436. //+---------------------------------------------------------------------------
  437. //
  438. // Member: CContentIndex::DebugStats, public
  439. //
  440. // Synopsis: Returns statistics on the use and composition of the CI.
  441. //
  442. // Arguments: [pciDebStats] -- Pointer to debug statistics structure.
  443. //
  444. // Modifies: The structure pointed at by pciDebStats is filled in with
  445. // the statistical information.
  446. //
  447. // History: 26-Feb-91 KyleP Created.
  448. //
  449. // Notes: This function is only avaliable in the debug version of the
  450. // content index.
  451. //
  452. //----------------------------------------------------------------------------
  453. void CContentIndex::DebugStats(/* CIDEBSTATS *pciDebStats */)
  454. {
  455. }
  456. //+---------------------------------------------------------------------------
  457. //
  458. // Member: CContentIndex::DebugDump, public
  459. //
  460. // Synopsis: Dumps a plain text representation of the content index.
  461. //
  462. // Arguments: [sOut] -- Output stream. A formatted representation of the
  463. // content index is sent here.
  464. //
  465. // Modifies: Text is written to [sOut].
  466. //
  467. // History: 26-Feb-91 KyleP Created.
  468. //
  469. // Notes: This function is only avaliable in the debug version of the
  470. // content index.
  471. //
  472. //----------------------------------------------------------------------------
  473. void CContentIndex::DumpIndexes( FILE * pf, INDEXID iid, ULONG fSummaryOnly )
  474. {
  475. PARTITIONID partid = 1;
  476. CFreshTest * pfresh;
  477. unsigned cind;
  478. ULONG pFlags = 0;
  479. CIndex ** ppIndex =
  480. _resman.QueryIndexes( 1, // One partition
  481. &partid, // The partition
  482. &pfresh, // Fresh test (unused)
  483. cind, // # indexes.
  484. 0, // # pending updates
  485. 0, // curPending
  486. &pFlags ); // Still changes to do?
  487. for (int i = cind-1; i >= 0; i-- )
  488. {
  489. if ( 0 == iid || ppIndex[i]->GetId() == iid )
  490. {
  491. fprintf( pf, "\n\nIndex %lx:\n", ppIndex[i]->GetId() );
  492. ppIndex[i]->DebugDump( pf, fSummaryOnly );
  493. }
  494. }
  495. _resman.ReleaseIndexes( cind, ppIndex, pfresh );
  496. delete ppIndex;
  497. }
  498. //+---------------------------------------------------------------------------
  499. //
  500. // Member: CContentIndex::DumpWorkId, public
  501. //
  502. // Synopsis: Dumps a plain text representation of the content index for
  503. // a single wid.
  504. //
  505. // Arguments: [pb] -- Buffer has bookmark on input, text on output.
  506. // [cb] -- Size of [pb]
  507. //
  508. // History: 30-Mar-95 KyleP Created.
  509. //
  510. //----------------------------------------------------------------------------
  511. void CContentIndex::DumpWorkId( BYTE * pb, ULONG cb )
  512. {
  513. #if 0
  514. //
  515. // Set up for iteration.
  516. //
  517. BYTE * pbTemp = pb;
  518. pbTemp += sizeof(ULONG); // Skip command
  519. WORKID widLocate = *(WORKID UNALIGNED *)pbTemp;
  520. pbTemp += sizeof(WORKID); // Skip workid
  521. ULONG iidRequested = *(WORKID UNALIGNED *) pbTemp;
  522. pbTemp += sizeof(ULONG);
  523. //
  524. // This copy is "safe" because I know CKeyBuf doesn't contain
  525. // any data members that are pointers.
  526. //
  527. CKeyBuf keyStart;
  528. memcpy( &keyStart, pbTemp, sizeof(keyStart) );
  529. CKey * pkeyStart = 0;
  530. if ( keyStart.Count() != 0 ) // On initial call, count is zero
  531. pkeyStart = new CKey( keyStart );
  532. //
  533. // Compute space to write text. Save enough to write bookmark (and "...\n")
  534. //
  535. char const szContinued[] = "... \n";
  536. char * psz = (char *)pb;
  537. int cc = cb - sizeof(ULONG) - sizeof(WORKID) - sizeof(CKeyBuf) - sizeof(szContinued);
  538. if ( cc <= 0 )
  539. {
  540. ciDebugOut(( DEB_ERROR,
  541. "Buffer passed to CContentIndex::DumpWorkId too small for bookmark!\n" ));
  542. return;
  543. }
  544. //
  545. // Snapshot indices
  546. //
  547. PARTITIONID partid = 1;
  548. CFreshTest * pfresh;
  549. unsigned cind;
  550. ULONG pFlags = 0;
  551. CIndex ** ppIndex = _resman.QueryIndexes( 1, // One partition
  552. &partid, // The partition
  553. &pfresh, // Fresh test (unused)
  554. cind, // # indexes.
  555. 0, // # pending updates
  556. 0, // curPending
  557. &pFlags ); // Still changes to do?
  558. //
  559. // Loop through indices, looking for freshest.
  560. //
  561. int cbWritten = 0;
  562. for ( int i = cind-1; i >= 0; i-- )
  563. {
  564. if ( ( (0 == iidRequested) && pfresh->IsCorrectIndex( ppIndex[i]->GetId(), widLocate ) ) ||
  565. ( ppIndex[i]->GetId() == iidRequested )
  566. )
  567. {
  568. //
  569. // Header
  570. //
  571. if ( pkeyStart == 0 )
  572. {
  573. cbWritten = _snprintf( psz,
  574. cc,
  575. "Dump of wid %d (0x%x)\n"
  576. "Using index 0x%x\n\n",
  577. widLocate,
  578. widLocate,
  579. ppIndex[i]->GetId() );
  580. if ( cbWritten != -1 )
  581. {
  582. psz += cbWritten;
  583. cc -= cbWritten;
  584. }
  585. }
  586. //
  587. // pszStart is where we started writing the last key. A key must
  588. // be written completely or we will try again in the next pass.
  589. //
  590. char * pszStart = psz;
  591. //
  592. // Get cursor, either from beginning or from bookmark.
  593. //
  594. CKeyCursor * pcur;
  595. CKeyBuf const * pkey = 0;
  596. if ( pkeyStart == 0 )
  597. {
  598. pcur = ppIndex[i]->QueryCursor();
  599. pkeyStart = new CKey( *pcur->GetKey() );
  600. }
  601. else
  602. pcur = ppIndex[i]->QueryKeyCursor( pkeyStart );
  603. //
  604. // I think pcur can be null, if indexes / keys shifted beneath us.
  605. //
  606. if ( pcur != 0 )
  607. {
  608. ciDebugOut(( DEB_ITRACE, "Scan on letter: " ));
  609. WCHAR FirstLetter = '@';
  610. for ( pkey = pcur->GetKey();
  611. cbWritten != -1 && pkey != 0;
  612. pkey = pcur->GetNextKey() )
  613. {
  614. if ( *(pkey->GetStr()) != FirstLetter )
  615. {
  616. FirstLetter = *(pkey->GetStr());
  617. ciDebugOut (( DEB_NOCOMPNAME | DEB_ITRACE, "%c", FirstLetter ));
  618. }
  619. //
  620. // Search for specified wid.
  621. //
  622. for ( WORKID wid = pcur->WorkId(); wid < widLocate; wid = pcur->NextWorkId() )
  623. continue;
  624. //
  625. // Print data for the key.
  626. //
  627. if ( wid == widLocate )
  628. {
  629. cbWritten = _snprintf( psz, cc, "Key: %.*ws -- (PID = %lx)\n",
  630. pkey->StrLen(), pkey->GetStr(), pkey->Pid() );
  631. if ( cbWritten != -1 )
  632. {
  633. psz += cbWritten;
  634. cc -= cbWritten;
  635. }
  636. int i = 1;
  637. for ( OCCURRENCE occ = pcur->Occurrence();
  638. cbWritten != 0xFFFFFFFF && occ != OCC_INVALID;
  639. occ = pcur->NextOccurrence(), i++ )
  640. {
  641. cbWritten = _snprintf( psz, cc, " %6ld", occ );
  642. if ( cbWritten != -1 )
  643. {
  644. psz += cbWritten;
  645. cc -= cbWritten;
  646. }
  647. if ( i % 10 == 0 )
  648. {
  649. cbWritten = _snprintf( psz, cc, "\n" );
  650. if ( cbWritten != -1 )
  651. {
  652. psz += cbWritten;
  653. cc -= cbWritten;
  654. }
  655. }
  656. }
  657. if ( cbWritten != -1 )
  658. cbWritten = _snprintf( psz, cc, "\n" );
  659. if ( cbWritten != -1 )
  660. {
  661. psz += cbWritten;
  662. cc -= cbWritten;
  663. pszStart = psz;
  664. }
  665. else
  666. break;
  667. }
  668. } // for
  669. delete pcur;
  670. } // pcur != 0
  671. //
  672. // What if we didn't write any key?
  673. //
  674. if ( pkey && pkey->Compare( *pkeyStart ) == 0 )
  675. {
  676. cbWritten = _snprintf( psz, sizeof(szContinued), szContinued);
  677. psz += cbWritten;
  678. pkey = pcur->GetNextKey();
  679. }
  680. else
  681. {
  682. psz = pszStart;
  683. }
  684. *psz = 0;
  685. psz++; // For final null
  686. //
  687. // Either buffer is full, or we ran out of keys.
  688. //
  689. if ( pkey != 0 )
  690. {
  691. //
  692. // Write bookmark
  693. //
  694. *((ULONG UNALIGNED *)psz) = CiDumpWorkId;
  695. psz += sizeof(ULONG);
  696. *((WORKID UNALIGNED *)psz) = widLocate;
  697. psz += sizeof(WORKID);
  698. *((ULONG UNALIGNED *)psz) = iidRequested;
  699. psz += sizeof(ULONG);
  700. keyStart = *pkey;
  701. memcpy( psz, &keyStart, sizeof(keyStart) );
  702. }
  703. else
  704. {
  705. //
  706. // Write end-of-iteration signature
  707. //
  708. *((ULONG UNALIGNED *)psz) = 0;
  709. }
  710. break;
  711. }
  712. }
  713. //
  714. // We may not have found any data.
  715. //
  716. if ( i < 0 )
  717. {
  718. unsigned cbWritten = _snprintf( psz, cc, "No index contains data for wid %d (0x%x)\n", widLocate, widLocate );
  719. psz += cbWritten;
  720. cc -= cbWritten;
  721. psz++; // For final null
  722. *((ULONG UNALIGNED *)psz) = 0;
  723. }
  724. //
  725. // Cleanup
  726. //
  727. delete pkeyStart;
  728. _resman.ReleaseIndexes( cind, ppIndex, pfresh );
  729. delete ppIndex;
  730. #endif
  731. }
  732. #endif // CIDBG == 1
  733. //+---------------------------------------------------------------------------
  734. //
  735. // Member: CContentIndex::KeyToId, public
  736. //
  737. // Synopsis: Maps from a key to an id.
  738. //
  739. // Arguments: [pkey] -- pointer to the key to be mapped to ULONG
  740. //
  741. // Returns: key id - a ULONG
  742. //
  743. // History: 03-Nov-93 w-Patg Created.
  744. //
  745. //----------------------------------------------------------------------------
  746. ULONG CContentIndex::KeyToId( CKey const * pkey )
  747. {
  748. return _resman.KeyToId( pkey );
  749. }
  750. //+---------------------------------------------------------------------------
  751. //
  752. // Member: CContentIndex::IdToKey, public
  753. //
  754. // Synopsis: Maps from an id to a key.
  755. //
  756. // Arguments: [ulKid] -- key id to be mapped to a key
  757. // [rkey] -- reference to the returned key
  758. //
  759. // Returns: void
  760. //
  761. // History: 03-Nov-93 w-Patg Created.
  762. //
  763. //----------------------------------------------------------------------------
  764. void CContentIndex::IdToKey( ULONG ulKid, CKey & rkey )
  765. {
  766. _resman.IdToKey( ulKid, rkey );
  767. return;
  768. }
  769. //+---------------------------------------------------------------------------
  770. //
  771. // Member: CCI::CCI, public
  772. //
  773. // Synopsis: Creates a content index object.
  774. //
  775. // Arguments: [storage] -- Storage
  776. // [xIndexNotifTable] -- Table of notifications in push filtering
  777. //
  778. // History: 21-Aug-91 KyleP Created.
  779. //
  780. //----------------------------------------------------------------------------
  781. CCI::CCI( PStorage & storage,
  782. CCiFrameworkParams & params,
  783. ICiCDocStore * pICiCDocStore,
  784. CI_STARTUP_INFO const & startupInfo,
  785. IPropertyMapper * pIPropertyMapper,
  786. XInterface<CIndexNotificationTable> & xIndexNotifTable )
  787. : _storage(storage),
  788. _pci(0),
  789. _createStatus(STATUS_INTERNAL_ERROR)
  790. {
  791. Win4Assert( 0 != pIPropertyMapper );
  792. if ( startupInfo.startupFlags & CI_CONFIG_EMPTY_DATA )
  793. {
  794. ciDebugOut(( DEB_WARN,
  795. "**** CI_CONFIG_EMPTY_DATA is true. Emptying contents of contentIndex.\n" ));
  796. Empty();
  797. }
  798. _xPropMapper.Set( pIPropertyMapper );
  799. pIPropertyMapper->AddRef();
  800. _createStatus = Create( pICiCDocStore, startupInfo, params, xIndexNotifTable );
  801. if ( STATUS_SUCCESS != _createStatus )
  802. THROW( CException( _createStatus ) );
  803. }
  804. //+---------------------------------------------------------------------------
  805. //
  806. // Member: CCI::~CCI, public
  807. //
  808. // Synopsis: Destroys the content index.
  809. //
  810. // Signals: ???
  811. //
  812. // History: 21-Aug-91 KyleP Created.
  813. //
  814. //----------------------------------------------------------------------------
  815. CCI::~CCI()
  816. {
  817. delete _pci;
  818. }
  819. //+---------------------------------------------------------------------------
  820. //
  821. // Member: CCI::IsCiCorrupt, public
  822. //
  823. // Synopsis: Returns TRUE if the index is corrupt or FALSE otherwise
  824. //
  825. // History: 5-Oct-98 dlee Created.
  826. //
  827. //----------------------------------------------------------------------------
  828. BOOL CCI::IsCiCorrupt()
  829. {
  830. if ( 0 == _pci )
  831. return FALSE;
  832. return _pci->IsCiCorrupt();
  833. } //IsCiCorrupt
  834. SCODE CCI::FilterStoreValue(
  835. WORKID widFake,
  836. CFullPropSpec const & ps,
  837. CStorageVariant const & var,
  838. BOOL & fStored )
  839. {
  840. fStored = FALSE;
  841. if ( 0 != _pci )
  842. return _pci->FilterStoreValue( widFake, ps, var, fStored );
  843. return S_OK;
  844. }
  845. SCODE CCI::FilterStoreSecurity(
  846. WORKID widFake,
  847. PSECURITY_DESCRIPTOR pSD,
  848. ULONG cbSD,
  849. BOOL & fStored )
  850. {
  851. fStored = FALSE;
  852. if ( 0 != _pci )
  853. return _pci->FilterStoreSecurity( widFake, pSD, cbSD, fStored );
  854. return S_OK;
  855. }
  856. //+---------------------------------------------------------------------------
  857. //----------------------------------------------------------------------------
  858. CRWStore * CCI::ComputeRelevantWords(ULONG cRows,ULONG cRW,
  859. WORKID *pwid,PARTITIONID partid)
  860. {
  861. if ( 0 != _pci )
  862. return _pci->ComputeRelevantWords(cRows,cRW,pwid,partid);
  863. return 0;
  864. } //ComputeRelevantWords
  865. //+---------------------------------------------------------------------------
  866. //----------------------------------------------------------------------------
  867. CRWStore * CCI::RetrieveRelevantWords(BOOL fAcquire,PARTITIONID partid)
  868. {
  869. if ( 0 != _pci )
  870. return _pci->RetrieveRelevantWords(fAcquire,partid);
  871. return 0;
  872. } //RetrieveRelevantWords
  873. //+---------------------------------------------------------------------------
  874. //----------------------------------------------------------------------------
  875. unsigned CCI::ReserveUpdate ( WORKID wid )
  876. {
  877. if ( 0 != _pci )
  878. return _pci->ReserveUpdate ( wid );
  879. else
  880. return 0;
  881. }
  882. //+---------------------------------------------------------------------------
  883. //----------------------------------------------------------------------------
  884. SCODE CCI::Update ( unsigned iHint,
  885. WORKID wid,
  886. PARTITIONID partid,
  887. USN usn,
  888. VOLUMEID volumeId,
  889. ULONG action )
  890. {
  891. if ( 0 == _pci )
  892. return CI_E_NOT_INITIALIZED;
  893. return _pci->Update ( iHint, wid, partid, usn, volumeId, action );
  894. }
  895. //+---------------------------------------------------------------------------
  896. //----------------------------------------------------------------------------
  897. void CCI::FlushUpdates()
  898. {
  899. if ( 0 != _pci )
  900. _pci->FlushUpdates();
  901. }
  902. //+---------------------------------------------------------------------------
  903. //----------------------------------------------------------------------------
  904. void CCI::MarkOutOfDate()
  905. {
  906. if ( 0 != _pci )
  907. _pci->MarkOutOfDate();
  908. }
  909. //+---------------------------------------------------------------------------
  910. //----------------------------------------------------------------------------
  911. void CCI::MarkUpToDate()
  912. {
  913. if ( 0 != _pci )
  914. _pci->MarkUpToDate();
  915. }
  916. //+---------------------------------------------------------------------------
  917. //----------------------------------------------------------------------------
  918. NTSTATUS CCI::CiState(CIF_STATE & state)
  919. {
  920. if ( 0 != _pci )
  921. return _pci->CiState(state);
  922. AssertOnNotFound(STATUS_NOT_FOUND);
  923. return STATUS_NOT_FOUND;
  924. }
  925. //+---------------------------------------------------------------------------
  926. //
  927. // Member: CCI::BackupCiData
  928. //
  929. // Synopsis: Backups Content Index data using the storage provided.
  930. //
  931. // Arguments: [storage] - Destination storage.
  932. // [fFull] - In/Out Set to TRUE if a full save is needed
  933. // On output, set to TRUE if a full save was done because CI
  934. // decided to do a FULL save.
  935. // [xEnumWorkids] - On output, will have the workid enumerator.
  936. // [progressTracker] - Progress feedback and out-of-band abort
  937. // signalling.
  938. //
  939. // History: 3-21-97 srikants Created
  940. //
  941. //----------------------------------------------------------------------------
  942. SCODE CCI::BackupCiData( PStorage & storage,
  943. BOOL & fFull,
  944. XInterface<ICiEnumWorkids> & xEnumWorkids,
  945. PSaveProgressTracker & progressTracker )
  946. {
  947. SCODE sc = CI_E_INVALID_STATE;
  948. if ( 0 != _pci )
  949. {
  950. sc = _pci->BackupCiData( storage, fFull, xEnumWorkids, progressTracker );
  951. if ( !SUCCEEDED(sc) )
  952. {
  953. //
  954. // Cleanup any partially created files.
  955. //
  956. storage.DeleteAllCiFiles();
  957. }
  958. }
  959. return sc;
  960. }
  961. NTSTATUS CCI::IndexSize( ULONG & mbIndex )
  962. {
  963. if ( 0 != _pci )
  964. {
  965. _pci->IndexSize( mbIndex );
  966. return S_OK;
  967. }
  968. AssertOnNotFound(STATUS_NOT_FOUND);
  969. mbIndex = 0;
  970. return STATUS_NOT_FOUND;
  971. }
  972. NTSTATUS CCI::IsLowOnDiskSpace( BOOL & fLow )
  973. {
  974. if ( 0 != _pci )
  975. {
  976. fLow = _pci->IsLowOnDiskSpace();
  977. return S_OK;
  978. }
  979. AssertOnNotFound(STATUS_NOT_FOUND);
  980. fLow = FALSE;
  981. return STATUS_NOT_FOUND;
  982. }
  983. NTSTATUS CCI::VerifyIfLowOnDiskSpace( BOOL & fLow )
  984. {
  985. if ( 0 != _pci )
  986. {
  987. fLow = _pci->VerifyIfLowOnDiskSpace();
  988. return S_OK;
  989. }
  990. AssertOnNotFound(STATUS_NOT_FOUND);
  991. fLow = FALSE;
  992. return STATUS_NOT_FOUND;
  993. }
  994. //+---------------------------------------------------------------------------
  995. //
  996. // Member: CCI::Query, public
  997. //
  998. // Synopsis: Resolves a free-text query.
  999. //
  1000. // Effects: Parses a free text query and creates a tree of cursors to
  1001. // resolve the query.
  1002. //
  1003. // Arguments: [pRst] -- Pointer to tree of query restriction(s)
  1004. // [pFlags] -- Holds information about the status of the query
  1005. // [cPartitions] -- The number of partitions in aPartID.
  1006. // [aPartID] -- Array of partitionIDs specifying partitions
  1007. // to be searched.
  1008. // [cPendingUpdates] -- The number of pending updates that
  1009. // should be allowed before using enumeration on
  1010. // property queries.
  1011. // [cMaxNodes] -- Maximum query expansion.
  1012. //
  1013. // Requires: All partitions in aPartID are valid.
  1014. //
  1015. // Returns: A cursor to iterate over the results
  1016. //
  1017. // Modifies: pFlags may be modified to reflect the status of the query
  1018. //
  1019. // History: 19-Sep-91 BartoszM Created.
  1020. //
  1021. //----------------------------------------------------------------------------
  1022. CCursor* CCI::Query( CRestriction const * pRst,
  1023. ULONG* pFlags,
  1024. UINT cPartitions,
  1025. PARTITIONID aPartID[],
  1026. ULONG cPendingUpdates,
  1027. ULONG cMaxNodes )
  1028. {
  1029. if ( _pci )
  1030. return _pci->Query( pRst,
  1031. pFlags,
  1032. cPartitions,
  1033. aPartID,
  1034. cPendingUpdates,
  1035. cMaxNodes );
  1036. return 0;
  1037. }
  1038. //+---------------------------------------------------------------------------
  1039. //----------------------------------------------------------------------------
  1040. NTSTATUS CCI::Dismount()
  1041. {
  1042. if ( 0 != _pci )
  1043. {
  1044. _pci->Dismount();
  1045. _xPropMapper.Free();
  1046. return S_OK;
  1047. }
  1048. return STATUS_NOT_FOUND;
  1049. }
  1050. //+---------------------------------------------------------------------------
  1051. //
  1052. // Member: CCI::FilterReady, public
  1053. //
  1054. // Synopsis: Retrieves list of documents to be filtered. Blocks thread if
  1055. // resources are not available or if there are no documents to
  1056. // be filtered.
  1057. //
  1058. // Arguments: [docBuffer] -- (in, out) buffer for paths and properties of
  1059. // documents to be filtered.
  1060. // [cwc] -- (in) count of BYTES in docBuffer
  1061. // [cMaxDocs] -- (in) the maximum number of docs that can be
  1062. // filtered at once by the filter daemon.
  1063. //
  1064. // History: 18-Apr-93 AmyA Created.
  1065. // 21-Jan-97 SrikantS Changed to BYTE buffers for framework
  1066. //
  1067. //----------------------------------------------------------------------------
  1068. SCODE CCI::FilterReady ( BYTE * docBuffer, ULONG & cb, ULONG cMaxDocs )
  1069. {
  1070. if ( 0 != _pci )
  1071. return( _pci->FilterReady( docBuffer, cb, cMaxDocs ) );
  1072. AssertOnNotFound(STATUS_NOT_FOUND);
  1073. return STATUS_NOT_FOUND;
  1074. }
  1075. //+---------------------------------------------------------------------------
  1076. //
  1077. // Member: CCI::FilterDataReady, public
  1078. //
  1079. // Synopsis: Adds the contents of entry buffer to the current word list.
  1080. //
  1081. // Returns: Whether the word list is full
  1082. //
  1083. // Arguments: [pEntryBuf] -- pointer to data to be added to word list
  1084. // [cb] -- count of bytes in buffer
  1085. //
  1086. // History: 22-Mar-93 AmyA Created.
  1087. //
  1088. //----------------------------------------------------------------------------
  1089. SCODE CCI::FilterDataReady( const BYTE * pEntryBuf, ULONG cb )
  1090. {
  1091. Win4Assert( _pci );
  1092. if ( 0 != _pci )
  1093. return( _pci->FilterDataReady( pEntryBuf, cb ) );
  1094. AssertOnNotFound(STATUS_NOT_FOUND);
  1095. return(STATUS_NOT_FOUND);
  1096. }
  1097. //+---------------------------------------------------------------------------
  1098. //
  1099. // Member: CCI::FilterMore, public
  1100. //
  1101. // Synopsis: Commits the current word list and initializes a new one.
  1102. //
  1103. // Arguments: [aStatus] -- array of STATUS for the resource manager
  1104. // [count] -- count for array
  1105. //
  1106. // History: 03-May-93 AmyA Created.
  1107. //
  1108. //----------------------------------------------------------------------------
  1109. SCODE CCI::FilterMore( const STATUS * aStatus, ULONG count )
  1110. {
  1111. if ( 0 != _pci )
  1112. return( _pci->FilterMore( aStatus, count ) );
  1113. AssertOnNotFound(STATUS_NOT_FOUND);
  1114. return(STATUS_NOT_FOUND);
  1115. }
  1116. //+---------------------------------------------------------------------------
  1117. //
  1118. // Member: CCI::FilterDone, public
  1119. //
  1120. // Synopsis: Commits the current word list.
  1121. //
  1122. // Arguments: [aStatus] -- array of STATUS for the resource manager
  1123. // [count] -- count for array
  1124. //
  1125. // History: 22-Mar-93 AmyA Created.
  1126. //
  1127. //----------------------------------------------------------------------------
  1128. SCODE CCI::FilterDone( const STATUS * aStatus, ULONG count )
  1129. {
  1130. if ( 0 != _pci )
  1131. return( _pci->FilterDone( aStatus, count ) );
  1132. AssertOnNotFound(STATUS_NOT_FOUND);
  1133. return(STATUS_NOT_FOUND);
  1134. }
  1135. //+---------------------------------------------------------------------------
  1136. //
  1137. // Member: CCI::FPSToPROPID, public
  1138. //
  1139. // Synopsis: Converts FULLPROPSPEC property to PROPID
  1140. //
  1141. // Arguments: [fps] -- FULLPROPSPEC representation of property
  1142. // [pid] -- PROPID written here on success
  1143. //
  1144. // Returns: S_OK on success
  1145. //
  1146. // History: 29-Dec-1997 KyleP Created.
  1147. //
  1148. //----------------------------------------------------------------------------
  1149. SCODE CCI::FPSToPROPID( CFullPropSpec const & fps, PROPID & pid )
  1150. {
  1151. if ( 0 != _pci )
  1152. return _pci->FPSToPROPID( fps, pid );
  1153. AssertOnNotFound(STATUS_NOT_FOUND);
  1154. return(STATUS_NOT_FOUND);
  1155. }
  1156. //+---------------------------------------------------------------------------
  1157. //
  1158. // Member: CCI::GetFilterProxy
  1159. //
  1160. // Synopsis: Returns the pointer of the filter proxy for use in
  1161. // in-process filtering.
  1162. //
  1163. // History: 2-13-97 srikants Created
  1164. //
  1165. //----------------------------------------------------------------------------
  1166. CiProxy * CCI::GetFilterProxy()
  1167. {
  1168. Win4Assert( _pci );
  1169. if ( 0 != _pci )
  1170. {
  1171. return( &(_pci->GetFilterProxy()) );
  1172. }
  1173. else
  1174. {
  1175. return 0;
  1176. }
  1177. }
  1178. //+---------------------------------------------------------------------------
  1179. //----------------------------------------------------------------------------
  1180. NTSTATUS CCI::ForceMerge( PARTITIONID partid, CI_MERGE_TYPE mt )
  1181. {
  1182. if ( _pci )
  1183. return _pci->ForceMerge( partid, mt );
  1184. return(STATUS_NOT_FOUND);
  1185. }
  1186. //+---------------------------------------------------------------------------
  1187. //----------------------------------------------------------------------------
  1188. NTSTATUS CCI::AbortMerge( PARTITIONID partid )
  1189. {
  1190. if ( _pci )
  1191. return _pci->AbortMerge( partid );
  1192. return(STATUS_NOT_FOUND);
  1193. }
  1194. //+---------------------------------------------------------------------------
  1195. //----------------------------------------------------------------------------
  1196. void CCI::CreatePartition(PARTITIONID partID)
  1197. {
  1198. if ( _pci )
  1199. _pci->CreatePartition ( partID );
  1200. }
  1201. //+---------------------------------------------------------------------------
  1202. //----------------------------------------------------------------------------
  1203. void CCI::DestroyPartition(PARTITIONID partID)
  1204. {
  1205. if ( _pci )
  1206. _pci->DestroyPartition ( partID );
  1207. }
  1208. //+---------------------------------------------------------------------------
  1209. //----------------------------------------------------------------------------
  1210. void CCI::MergePartitions(PARTITIONID partDest,
  1211. PARTITIONID partSrc)
  1212. {
  1213. if ( _pci )
  1214. _pci->MergePartitions(partDest, partSrc);
  1215. }
  1216. //+---------------------------------------------------------------------------
  1217. //----------------------------------------------------------------------------
  1218. class CBufScanner
  1219. {
  1220. public:
  1221. CBufScanner ( int cb, BYTE UNALIGNED * buf )
  1222. {
  1223. _buf = buf;
  1224. _end = &buf[cb];
  1225. _cur = buf;
  1226. }
  1227. ULONG GetUlong()
  1228. {
  1229. ULONG x = 0;
  1230. if (_end - _cur >= sizeof(ULONG))
  1231. {
  1232. x = *((ULONG UNALIGNED *)_cur );
  1233. _cur += sizeof(ULONG);
  1234. }
  1235. return(x);
  1236. }
  1237. private:
  1238. BYTE UNALIGNED * _buf;
  1239. BYTE UNALIGNED * _end;
  1240. BYTE UNALIGNED * _cur;
  1241. };
  1242. #if CIDBG == 1
  1243. ULONG CCI::SetInfoLevel ( ULONG level )
  1244. {
  1245. ULONG tmp = ciInfoLevel;
  1246. ciInfoLevel = level;
  1247. return tmp;
  1248. }
  1249. #endif // CIDBG == 1
  1250. //+---------------------------------------------------------------------------
  1251. //
  1252. // Member: CCI::KeyToId, public
  1253. //
  1254. // Synopsis: Maps from a key to an id.
  1255. //
  1256. // Arguments: [pkey] -- pointer to the key to be mapped to ULONG
  1257. //
  1258. // Returns: key id - a ULONG
  1259. //
  1260. // History: 03-Nov-93 w-Patg Created.
  1261. //
  1262. //----------------------------------------------------------------------------
  1263. ULONG CCI::KeyToId( CKey const * pkey )
  1264. {
  1265. if ( 0 != _pci )
  1266. {
  1267. return _pci->KeyToId( pkey );
  1268. }
  1269. else
  1270. return(kidInvalid);
  1271. }
  1272. //+---------------------------------------------------------------------------
  1273. //
  1274. // Member: CCI::IdToKey, public
  1275. //
  1276. // Synopsis: Maps from an id to a key.
  1277. //
  1278. // Arguments: [ulKid] -- key id to be mapped to a key
  1279. // [rkey] -- reference to the returned key
  1280. //
  1281. // Returns: void
  1282. //
  1283. // History: 03-Nov-93 w-Patg Created.
  1284. //
  1285. //----------------------------------------------------------------------------
  1286. void CCI::IdToKey( ULONG ulKid, CKey & rkey )
  1287. {
  1288. if ( 0 != _pci )
  1289. _pci->IdToKey( ulKid, rkey );
  1290. }
  1291. //+---------------------------------------------------------------------------
  1292. //----------------------------------------------------------------------------
  1293. inline void CCI::SetPartition( PARTITIONID PartId )
  1294. {
  1295. if ( 0 != _pci )
  1296. {
  1297. _pci->SetPartition( PartId );
  1298. }
  1299. }
  1300. //+---------------------------------------------------------------------------
  1301. //----------------------------------------------------------------------------
  1302. inline PARTITIONID CCI::GetPartition() const
  1303. {
  1304. if ( 0 != _pci )
  1305. {
  1306. return _pci->GetPartition();
  1307. }
  1308. else
  1309. return( partidInvalid );
  1310. }
  1311. //+---------------------------------------------------------------------------
  1312. //
  1313. // Member: CCI::Create, public
  1314. //
  1315. // Synopsis: Sets up a new content index. If there is a partially deleted
  1316. // one, it deletes it if there are no outstanding queries.
  1317. //
  1318. // Returns: [STATUS_SUCCESS] -- a new content index was created
  1319. // [CI_CORRUPT_DATABASE] -- CI corrupt, rescan required
  1320. // [ERROR_ALREADY_EXISTS] -- catalog already exists
  1321. // [ERROR_BUSY] -- one or more queries are outstanding on
  1322. // the partially deleted content index
  1323. //
  1324. // History: 16-Aug-94 DwightKr Created
  1325. //
  1326. //----------------------------------------------------------------------------
  1327. SCODE CCI::Create( ICiCDocStore * pICiCDocStore,
  1328. CI_STARTUP_INFO const & startupInfo,
  1329. CCiFrameworkParams & params,
  1330. XInterface<CIndexNotificationTable> & xIndexNotifTable )
  1331. {
  1332. CLock lock( _mutex );
  1333. if ( (0 != _pci) && (!_pci->IsEmpty()) && (_pci->GetQueryCount() != 0) )
  1334. {
  1335. #if CIDBG==1
  1336. if ( 0 != _pci )
  1337. ciDebugOut ((DEB_ERROR, "Can not create a new content index because one already exists\n" ));
  1338. if ( !_pci->IsEmpty() )
  1339. ciDebugOut ((DEB_ERROR, "Can not create a new content index because the current one is not empty\n" ));
  1340. if ( _pci->GetQueryCount() != 0 )
  1341. ciDebugOut ((DEB_ERROR, "Can not create a new content index because query are outstanding on the current index\n" ));
  1342. #endif // CIDBG==1
  1343. return ERROR_ALREADY_EXISTS;
  1344. }
  1345. CContentIndex * pciNew = 0;
  1346. CContentIndex * pciOld = _pci;
  1347. NTSTATUS status = STATUS_SUCCESS;
  1348. CTransaction xact;
  1349. TRY
  1350. {
  1351. pciNew = new CContentIndex( _storage,
  1352. params,
  1353. pICiCDocStore,
  1354. startupInfo,
  1355. _xPropMapper.GetPointer(),
  1356. xact,
  1357. xIndexNotifTable );
  1358. }
  1359. CATCH( CException, e )
  1360. {
  1361. status = e.GetErrorCode();
  1362. ciDebugOut(( DEB_ERROR, "No content index found\n" ));
  1363. if ( STATUS_NO_MEMORY == e.GetErrorCode() ||
  1364. STATUS_INSUFFICIENT_RESOURCES == e.GetErrorCode() )
  1365. {
  1366. ciDebugOut(( DEB_ERROR, "**** CI Low On Resources **** \n" ));
  1367. }
  1368. else if ( CI_CORRUPT_DATABASE == e.GetErrorCode() ||
  1369. CI_CORRUPT_CATALOG == e.GetErrorCode() ||
  1370. STATUS_NOT_FOUND == e.GetErrorCode() )
  1371. {
  1372. AssertOnNotFound(e.GetErrorCode());
  1373. ciDebugOut(( DEB_ERROR,
  1374. "**** INCONSISTENCY IN CI. NEED COMPLETE RESCAN ****\n"));
  1375. status = CI_CORRUPT_DATABASE;
  1376. }
  1377. else
  1378. {
  1379. ciDebugOut(( DEB_ERROR,
  1380. "**** Error Code 0x%X ****\n", e.GetErrorCode() ));
  1381. }
  1382. }
  1383. END_CATCH
  1384. if ( STATUS_SUCCESS == status )
  1385. {
  1386. xact.Commit();
  1387. //
  1388. // If there is anyone using the old index, we assume they will be
  1389. // done with it in 15 seconds. If they are not, they get an error
  1390. // telling them the CI disappeared from under them.
  1391. _pci = pciNew;
  1392. if ( pciOld )
  1393. {
  1394. Sleep(15 * 1000);
  1395. delete pciOld;
  1396. pciOld = 0;
  1397. }
  1398. }
  1399. return status;
  1400. }
  1401. //+---------------------------------------------------------------------------
  1402. //
  1403. // Member: CCI::Empty, public
  1404. //
  1405. // Synopsis: Deletes all persistent structures from the content index.
  1406. //
  1407. // History: 16-Aug-94 DwightKr Created
  1408. //
  1409. //----------------------------------------------------------------------------
  1410. void CCI::Empty()
  1411. {
  1412. CLock lock( _mutex );
  1413. if ( 0 != _pci )
  1414. {
  1415. _pci->Empty();
  1416. Win4Assert ( _pci->IsEmpty() );
  1417. if ( _pci->GetQueryCount() == 0 )
  1418. {
  1419. delete _pci;
  1420. _pci = 0;
  1421. }
  1422. }
  1423. else
  1424. {
  1425. ciDebugOut(( DEB_ITRACE, "Disabling CI without CI mounted\n" ));
  1426. _storage.DeleteAllCiFiles();
  1427. }
  1428. }
  1429. //+---------------------------------------------------------------------------
  1430. //----------------------------------------------------------------------------
  1431. NTSTATUS CCI::MarkCorruptIndex()
  1432. {
  1433. if ( _pci )
  1434. return _pci->MarkCorruptIndex();
  1435. return(STATUS_NOT_FOUND);
  1436. }
  1437. #if 0
  1438. //+---------------------------------------------------------------------------
  1439. //
  1440. // Member: CCI::FilterPidRemapper, public
  1441. //
  1442. // Synopsis: Maps a pidMapper into a array of real pids
  1443. //
  1444. // Arguments: [pbBuffer] - serialized pidMap buffer
  1445. // [cbBuffer] - size of the serialized buffer in bytes
  1446. // [aPids] - resulting array of real pids
  1447. // [cPids] - number of valid entries in the pidRemapArray
  1448. //
  1449. // Returns: STATUS_SUCCESS
  1450. // STATUS_BUFFER_TOO_SMALL - pidRemapArray to small
  1451. //
  1452. // History: 01-Mar-95 DwightKr Created
  1453. //
  1454. // Note: The pbBuffer must be used before the aPids is written
  1455. // since they may point to the same address.
  1456. //----------------------------------------------------------------------------
  1457. NTSTATUS CCI::FilterPidRemapper( BYTE * pbBuffer,
  1458. unsigned cbBuffer,
  1459. PROPID * aPids,
  1460. unsigned & cPids )
  1461. {
  1462. if ( 0 == _pci )
  1463. return CI_E_SHUTDOWN;
  1464. CMemDeSerStream pidMapDeSerStream( pbBuffer, cbBuffer );
  1465. CPidMapper pidMap( pidMapDeSerStream );
  1466. //
  1467. // We're finished with pbBuffer, it is therefore safe to use aPids
  1468. //
  1469. //
  1470. // If the output buffer is too small, then return an appropriate error
  1471. //
  1472. if ( cPids < pidMap.Count() )
  1473. {
  1474. cPids = pidMap.Count();
  1475. return STATUS_BUFFER_TOO_SMALL;
  1476. }
  1477. CSimplePidRemapper pidRemap;
  1478. _pci->PidMapToPidRemap( pidMap, pidRemap );
  1479. Win4Assert( pidMap.Count() == pidRemap.GetCount() );
  1480. cPids = pidMap.Count();
  1481. RtlCopyMemory( aPids, pidRemap.GetPropidArray(), cPids * sizeof PROPID );
  1482. return STATUS_SUCCESS;
  1483. }
  1484. #endif