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.

515 lines
16 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (c) Microsoft Corporation, 1991 - 1999.
  5. //
  6. // File: catalog.hxx
  7. //
  8. // Contents: Catalog abstraction
  9. //
  10. // Classes: PCatalog -- The catalog abstraction
  11. //
  12. // History: 30-May-91 SethuR Created.
  13. // 14-Sep-92 AmyA Added AddSubObject().
  14. // 08-Apr-98 KitmanH Added SetCatState().
  15. //
  16. // Notes: For each of the classes defined in this file two methods
  17. // have been defined but not implemented. These methods are
  18. // declared as private methods of the class. In general for a
  19. // class CFoo the signatures of these methods are as follows.
  20. //
  21. // CFoo(const CFoo& foo);
  22. // CFoo& operator = (const CFoo& foo);
  23. //
  24. // This effectively implies that these classes cannot be copied
  25. // or references to this class cannot be used as a lvalue in a
  26. // assignment statement. If we desire to change this behaviour
  27. // for a specific class these methods should be made public for
  28. // those classes.
  29. //
  30. //----------------------------------------------------------------------------
  31. #pragma once
  32. typedef ULONG SDID;
  33. const SDID sdidNull = 0;
  34. const SDID sdidInvalid = 0xFFFFFFFF;
  35. class PStorage;
  36. class CFullPropSpec;
  37. class CStorageVariant;
  38. class CRWStore;
  39. class CPidMapper;
  40. class CPidRemapper;
  41. class CCompositePropRecord;
  42. class CCiScopeTable;
  43. class CImpersonationTokenCache;
  44. class CScopeFixup;
  45. class CFunnyPath;
  46. #define CI_UPDATE_OBJ 0x0001
  47. #define CI_UPDATE_PROPS 0x0002
  48. #define CI_DELETE_OBJ 0x0004
  49. #define CI_SCAN_UPDATE 0x8000
  50. #define UPD_INCREM 0
  51. #define UPD_FULL 1
  52. #define UPD_INIT 2
  53. class PCatalog
  54. {
  55. public:
  56. PCatalog() {}
  57. virtual ~PCatalog() {}
  58. virtual unsigned WorkIdToPath ( WORKID wid, CFunnyPath& funnyPath ) = 0;
  59. virtual unsigned WorkIdToAccuratePath ( WORKID wid, CLowerFunnyPath& funnyPath );
  60. virtual WORKID PathToWorkId ( const CLowerFunnyPath & lcaseFunnyPath, const BOOL fCreate ) = 0;
  61. virtual PROPID PropertyToPropId ( CFullPropSpec const & ps,
  62. BOOL fCreate = FALSE ) = 0;
  63. virtual BOOL EnumerateProperty( CFullPropSpec & ps,
  64. unsigned & cbInCache,
  65. ULONG & type,
  66. DWORD & dwStoreLevel,
  67. BOOL & fModifiable,
  68. unsigned & iBmk );
  69. virtual ULONG_PTR BeginCacheTransaction();
  70. virtual void SetupCache( CFullPropSpec const & ps,
  71. ULONG vt,
  72. ULONG cbMaxLen,
  73. ULONG_PTR ulToken,
  74. DWORD dwStoreLevel );
  75. virtual void EndCacheTransaction( ULONG_PTR ulToken, BOOL fCommit );
  76. virtual BOOL StoreValue( WORKID wid,
  77. CFullPropSpec const & ps,
  78. CStorageVariant const & var );
  79. virtual BOOL FetchValue( WORKID wid,
  80. PROPID pid,
  81. PROPVARIANT * pbData,
  82. unsigned * pcb );
  83. virtual BOOL FetchValue( CCompositePropRecord & Rec,
  84. PROPID pid,
  85. PROPVARIANT * pbData,
  86. BYTE * pbExtra,
  87. unsigned * pcb ) { return FALSE; }
  88. virtual BOOL FetchValue( WORKID wid,
  89. CFullPropSpec const & ps,
  90. PROPVARIANT & var );
  91. virtual BOOL FetchValue( CCompositePropRecord * pRec,
  92. PROPID pid,
  93. PROPVARIANT * pbData,
  94. unsigned * pcb );
  95. virtual BOOL FetchValue( CCompositePropRecord * pRec,
  96. PROPID pid,
  97. PROPVARIANT & var ) { return FALSE; }
  98. virtual CCompositePropRecord * OpenValueRecord( WORKID wid, BYTE * pb );
  99. virtual void CloseValueRecord( CCompositePropRecord * pRec );
  100. virtual BOOL StoreSecurity( WORKID wid,
  101. PSECURITY_DESCRIPTOR pSD,
  102. ULONG cbSD );
  103. virtual SDID FetchSDID( CCompositePropRecord * pRec,
  104. WORKID wid );
  105. virtual BOOL AccessCheck( SDID sdid,
  106. HANDLE hToken,
  107. ACCESS_MASK am,
  108. BOOL & fGranted );
  109. virtual void MarkUnReachable( WORKID wid ) {}
  110. virtual CRWStore * ComputeRelevantWords(ULONG cRows,ULONG cRW,
  111. WORKID *pwid,
  112. PARTITIONID partid) = 0;
  113. virtual CRWStore * RetrieveRelevantWords(BOOL fAcquire,
  114. PARTITIONID partid) = 0;
  115. virtual PStorage& GetStorage() = 0;
  116. virtual unsigned ReserveUpdate( WORKID wid ) = 0;
  117. virtual void Update( unsigned iHint,
  118. WORKID wid,
  119. PARTITIONID partid,
  120. USN usn,
  121. ULONG flags ) = 0;
  122. virtual void CatalogState( ULONG & cDocuments, ULONG & cPendingScans, ULONG & fState );
  123. virtual void UpdateDocuments( WCHAR const* rootPath=0,
  124. ULONG flag=UPD_FULL ) = 0;
  125. virtual void AddScopeToCI( WCHAR const * rootPath ) {}
  126. virtual void RemoveScopeFromCI( WCHAR const * rootPath ) {}
  127. //
  128. // Centralized error handling during queries
  129. //
  130. virtual void HandleError( NTSTATUS status ) {}
  131. virtual unsigned WorkIdToVirtualPath( WORKID wid,
  132. unsigned cSkip,
  133. XGrowable<WCHAR> & xBuf );
  134. virtual unsigned WorkIdToVirtualPath( CCompositePropRecord & propRec,
  135. unsigned cSkip,
  136. XGrowable<WCHAR> & xBuf )
  137. {
  138. if ( 0 != xBuf.Count() )
  139. xBuf[0] = 0;
  140. return 0;
  141. }
  142. virtual BOOL VirtualToPhysicalRoot( WCHAR const * pwcVPath,
  143. unsigned ccVPath,
  144. XGrowable<WCHAR> & xwcsVRoot,
  145. unsigned & ccVRoot,
  146. CLowerFunnyPath & lcaseFunnyPRoot,
  147. unsigned & ccPRoot,
  148. unsigned & iBmk );
  149. virtual BOOL VirtualToAllPhysicalRoots( WCHAR const * pwcVPath,
  150. unsigned ccVPath,
  151. XGrowable<WCHAR> & xwcsVRoot,
  152. unsigned & ccVRoot,
  153. CLowerFunnyPath & lcaseFunnyPRoot,
  154. unsigned & ccPRoot,
  155. ULONG & ulType,
  156. unsigned & iBmk );
  157. enum RootType
  158. {
  159. ManualRoot = 1, // Root added manually
  160. AutomaticRoot = 2, // Root in Gibraltar
  161. UsedRoot = 4, // Root in use for mapping
  162. NNTPRoot = 8, // Root from NNTP, not W3SVC
  163. NonIndexedVDir = 0x10, // Virtual Directory, not indexed
  164. IMAPRoot = 0x20, // Root from IMAP, not nntp or w3
  165. EndRoot = 0xFFFFFFFF // End of iteration
  166. };
  167. virtual ULONG EnumerateVRoot( XGrowable<WCHAR> & xwcVRoot,
  168. unsigned & ccVRoot,
  169. CLowerFunnyPath & lcaseFunnyPRoot,
  170. unsigned & ccPRoot,
  171. unsigned & iBmk );
  172. //
  173. // Partition support.
  174. //
  175. virtual void SetPartition( PARTITIONID PartId ) = 0;
  176. virtual PARTITIONID GetPartition() const = 0;
  177. virtual SCODE CreateContentIndex() = 0;
  178. virtual void EmptyContentIndex() = 0;
  179. virtual void ShutdownPhase1() {}
  180. virtual void ShutdownPhase2() {}
  181. virtual NTSTATUS ForceMerge( PARTITIONID partID )
  182. {
  183. Win4Assert( !"Must be overriden" );
  184. return 0;
  185. }
  186. virtual NTSTATUS AbortMerge( PARTITIONID partID )
  187. {
  188. Win4Assert( !"Must be overriden" );
  189. return 0;
  190. }
  191. virtual NTSTATUS SetCatState( PARTITIONID partID,
  192. DWORD dwNewState,
  193. DWORD * pdwOldState )
  194. {
  195. Win4Assert( !"Must be overriden" );
  196. return 0;
  197. }
  198. #if CIDBG == 1
  199. virtual void DumpWorkId( WORKID wid, ULONG iid, BYTE * pb, ULONG cb ) {}
  200. #endif
  201. // Get the drive letter of the catalog path
  202. virtual WCHAR * GetDriveName() = 0;
  203. virtual void PidMapToPidRemap( const CPidMapper & pidMap,
  204. CPidRemapper & pidRemap ) = 0;
  205. virtual NTSTATUS CiState( CI_STATE & state ) = 0;
  206. virtual void FlushScanStatus() = 0;
  207. virtual BOOL IsEligibleForFiltering( WCHAR const* wcsDirPath );
  208. virtual CCiRegParams * GetRegParams() = 0;
  209. virtual CScopeFixup * GetScopeFixup() = 0;
  210. virtual unsigned FixupPath( WCHAR const * pwcOriginal,
  211. WCHAR * pwcResult,
  212. unsigned cwcResult,
  213. unsigned cSkip )
  214. {
  215. // default behavior -- just copy if there is room
  216. unsigned cwc = 1 + wcslen( pwcOriginal );
  217. if ( cwcResult >= cwc )
  218. {
  219. RtlCopyMemory( pwcResult, pwcOriginal, cwc * sizeof WCHAR );
  220. return cwc;
  221. }
  222. return cwc;
  223. }
  224. virtual void InverseFixupPath( CLowerFunnyPath & lcaseFunnyPath )
  225. {
  226. // do nothing
  227. }
  228. virtual CCiScopeTable * GetScopeTable()
  229. { Win4Assert( 0 && "not implemented" ); return 0; }
  230. virtual CImpersonationTokenCache * GetImpersonationTokenCache()
  231. { Win4Assert( 0 && "not implemented" ); return 0; }
  232. virtual WCHAR const * GetCatalogName() { return 0; }
  233. virtual BOOL IsNullCatalog() = 0;
  234. };
  235. inline unsigned PCatalog::WorkIdToAccuratePath( WORKID wid, CLowerFunnyPath& funnyPath )
  236. {
  237. // Default: Can't accurately translate wid to path.
  238. return WorkIdToPath( wid, funnyPath );
  239. }
  240. inline void PCatalog::CatalogState( ULONG & cDocuments, ULONG & cPendingScans, ULONG & fState )
  241. {
  242. // Default: Can't count.
  243. cDocuments = 0;
  244. cPendingScans = 0;
  245. fState = 0;
  246. }
  247. inline BOOL PCatalog::EnumerateProperty( CFullPropSpec & ps, unsigned & cbInCache,
  248. ULONG & type, DWORD & dwStoreLevel,
  249. BOOL & fModifiable, unsigned & iBmk )
  250. {
  251. // Default: Can't enumerate
  252. return FALSE;
  253. }
  254. inline ULONG_PTR PCatalog::BeginCacheTransaction()
  255. {
  256. THROW( CException( STATUS_NOT_IMPLEMENTED ) );
  257. return 0;
  258. }
  259. inline void PCatalog::SetupCache( CFullPropSpec const & ps,
  260. ULONG vt,
  261. ULONG cbMaxLen,
  262. ULONG_PTR ulToken,
  263. DWORD dwStoreLevel )
  264. {
  265. THROW( CException( STATUS_NOT_IMPLEMENTED ) );
  266. }
  267. inline void PCatalog::EndCacheTransaction( ULONG_PTR ulToken, BOOL fCommit )
  268. {
  269. THROW( CException( STATUS_NOT_IMPLEMENTED ) );
  270. }
  271. inline BOOL PCatalog::StoreValue( WORKID wid,
  272. CFullPropSpec const & ps,
  273. CStorageVariant const & var )
  274. {
  275. // Default: Don't store values.
  276. return FALSE;
  277. }
  278. inline BOOL PCatalog::FetchValue( WORKID wid,
  279. PROPID pid,
  280. PROPVARIANT * pbData,
  281. unsigned * pcb )
  282. {
  283. // Default: No property cache.
  284. return FALSE;
  285. }
  286. inline BOOL PCatalog::FetchValue( WORKID wid,
  287. CFullPropSpec const & ps,
  288. PROPVARIANT & var )
  289. {
  290. // Default: No property cache.
  291. return FALSE;
  292. }
  293. inline BOOL PCatalog::FetchValue( CCompositePropRecord * pRec,
  294. PROPID pid,
  295. PROPVARIANT * pbData,
  296. unsigned * pcb )
  297. {
  298. // Default: No property cache.
  299. return FALSE;
  300. }
  301. inline CCompositePropRecord * PCatalog::OpenValueRecord( WORKID wid, BYTE * pb )
  302. {
  303. // Default: No property cache.
  304. return 0;
  305. }
  306. inline void PCatalog::CloseValueRecord( CCompositePropRecord * pRec )
  307. {
  308. // Default: No property cache.
  309. }
  310. inline unsigned PCatalog::WorkIdToVirtualPath( WORKID wid,
  311. unsigned cSkip,
  312. XGrowable<WCHAR> & xBuf )
  313. {
  314. // Default: No support for virtual paths
  315. return 0;
  316. }
  317. inline BOOL PCatalog::VirtualToPhysicalRoot( WCHAR const * pwcVPath,
  318. unsigned ccVPath,
  319. XGrowable<WCHAR> & xwcsVRoot,
  320. unsigned & ccVRoot,
  321. CLowerFunnyPath & lcaseFunnyPRoot,
  322. unsigned & ccPRoot,
  323. unsigned & iBmk )
  324. {
  325. // Default: No support for virtual paths
  326. return FALSE;
  327. }
  328. inline BOOL PCatalog::VirtualToAllPhysicalRoots( WCHAR const * pwcVPath,
  329. unsigned ccVPath,
  330. XGrowable<WCHAR> & xwcsVRoot,
  331. unsigned & ccVRoot,
  332. CLowerFunnyPath & lcaseFunnyPRoot,
  333. unsigned & ccPRoot,
  334. ULONG & ulType,
  335. unsigned & iBmk )
  336. {
  337. // Default: No support for virtual paths
  338. return FALSE;
  339. }
  340. inline ULONG PCatalog::EnumerateVRoot( XGrowable<WCHAR> & xwcVRoot,
  341. unsigned & ccVRoot,
  342. CLowerFunnyPath & lcaseFunnyPRoot,
  343. unsigned & ccPRoot,
  344. unsigned & iBmk )
  345. {
  346. // Default: No support for virtual paths
  347. return (ULONG) PCatalog::EndRoot;
  348. }
  349. inline BOOL PCatalog::StoreSecurity( WORKID wid,
  350. PSECURITY_DESCRIPTOR pSD,
  351. ULONG cbSD )
  352. {
  353. // Default: Don't store security information.
  354. return FALSE;
  355. }
  356. inline SDID PCatalog::FetchSDID( CCompositePropRecord * pRec,
  357. WORKID wid )
  358. {
  359. // Default: No cached security descriptor.
  360. return sdidNull;
  361. }
  362. inline BOOL PCatalog::AccessCheck( SDID sdid,
  363. HANDLE hToken,
  364. ACCESS_MASK am,
  365. BOOL & fGranted )
  366. {
  367. // Default: No cached security descriptor.
  368. return FALSE;
  369. }
  370. inline BOOL PCatalog::IsEligibleForFiltering( WCHAR const* wcsDirPath )
  371. {
  372. // Default: All files eligible for filtering
  373. return TRUE;
  374. }
  375. class XCompositeRecord
  376. {
  377. public:
  378. XCompositeRecord( PCatalog & cat,
  379. CCompositePropRecord * pPropRec = 0 ) :
  380. _cat( cat ),
  381. _pPropRec( pPropRec ) {}
  382. XCompositeRecord( PCatalog & cat, WORKID wid, BYTE * pBuf ) :
  383. _cat( cat )
  384. {
  385. _pPropRec = _cat.OpenValueRecord( wid, pBuf );
  386. }
  387. ~XCompositeRecord()
  388. {
  389. Free();
  390. }
  391. void Free()
  392. {
  393. if ( 0 != _pPropRec )
  394. {
  395. _cat.CloseValueRecord( _pPropRec );
  396. _pPropRec = 0;
  397. }
  398. }
  399. void Set( CCompositePropRecord * pPropRec )
  400. {
  401. Win4Assert( 0 == _pPropRec );
  402. _pPropRec = pPropRec;
  403. }
  404. CCompositePropRecord * Acquire()
  405. {
  406. CCompositePropRecord * p = _pPropRec;
  407. _pPropRec = 0;
  408. return p;
  409. }
  410. CCompositePropRecord * Get() { return _pPropRec; }
  411. private:
  412. CCompositePropRecord * _pPropRec;
  413. PCatalog & _cat;
  414. };