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.

457 lines
13 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (c) Microsoft Corporation, 1997 - 1998.
  5. //
  6. // File: CatAdmin.hxx
  7. //
  8. // Contents: Catalog administration API
  9. //
  10. // History: 28-Jan-97 KyleP Created
  11. //
  12. //----------------------------------------------------------------------------
  13. #pragma once
  14. #include <fsciexps.hxx>
  15. #include <smartsvc.hxx>
  16. //
  17. // Constants used for performance tuning
  18. //
  19. const WORD wDedicatedServer = 0;
  20. const WORD wUsedOften = 1;
  21. const WORD wUsedOccasionally = 2;
  22. const WORD wNeverUsed = 3;
  23. const WORD wCustom = 4;
  24. const WORD wLowPos = 1;
  25. const WORD wMidPos = 2;
  26. const WORD wHighPos = 3;
  27. //
  28. // Forward declarations
  29. //
  30. class CCatalogAdmin;
  31. class CCatalogEnum;
  32. class CScopeEnum;
  33. class CScopeAdmin;
  34. //
  35. // Utility routines
  36. //
  37. void AssembleScopeValueString( WCHAR const * pwszAlias,
  38. BOOL fExclude,
  39. WCHAR const * pwszLogon,
  40. XGrowable<WCHAR> & xLine );
  41. SCODE IsScopeValid( WCHAR const * pwszScope, unsigned len, BOOL fLocal );
  42. //+---------------------------------------------------------------------------
  43. //
  44. // Class: CMachineAdmin
  45. //
  46. // Purpose: Administer CI on a given machine
  47. //
  48. // History: 28-Jan-97 KyleP Created.
  49. //
  50. //----------------------------------------------------------------------------
  51. class CMachineAdmin
  52. {
  53. public:
  54. CMachineAdmin( WCHAR const * pwszMachine = 0, // NULL --> Current machine
  55. BOOL fWrite = TRUE );
  56. ~CMachineAdmin();
  57. //
  58. // Service manipulation
  59. //
  60. BOOL IsCIStarted();
  61. BOOL IsCIStopped();
  62. BOOL IsCIPaused();
  63. BOOL StartCI();
  64. BOOL StopCI();
  65. BOOL PauseCI();
  66. BOOL IsCIEnabled();
  67. BOOL EnableCI();
  68. BOOL DisableCI();
  69. //
  70. // Catalog manipulation
  71. //
  72. void AddCatalog( WCHAR const * pwszCatalog,
  73. WCHAR const * pwszDataLocation );
  74. void RemoveCatalog( WCHAR const * pwszCatalog,
  75. BOOL fRemoveData = TRUE ); // FALSE --> Don't delete directory
  76. void RemoveCatalogFiles( WCHAR const * pwszCatalog );
  77. CCatalogEnum * QueryCatalogEnum();
  78. CCatalogAdmin * QueryCatalogAdmin( WCHAR const * pwszCatalog );
  79. BOOL GetDWORDParam( WCHAR const * pwszParam, DWORD & dwValue );
  80. void SetDWORDParam( WCHAR const * pwszParam, DWORD dwValue );
  81. void SetSZParam( WCHAR const * pwszParam, WCHAR const * pwszVal, DWORD cbLen );
  82. BOOL GetSZParam( WCHAR const * pwszParam, WCHAR * pwszVal, DWORD cbLen );
  83. BOOL RegisterForNotification( HANDLE hEvent );
  84. BOOL IsLocal()
  85. {
  86. return ( (HKEY_LOCAL_MACHINE == _hkeyLM) ||
  87. (_xwcsMachName[0] == L'.' && _xwcsMachName[1] == 0) );
  88. }
  89. void CreateSubdirs( WCHAR const * pwszPath );
  90. // Performance Tuning
  91. void TunePerformance(BOOL fServer, WORD wIndexingPerf, WORD wQueryingPerf);
  92. private:
  93. BOOL OpenSCM();
  94. void TuneFilteringParameters(BOOL fServer, WORD wIndexingPerf, WORD wQueryingPerf);
  95. void TuneMergeParameters(BOOL fServer, WORD wIndexingPerf, WORD wQueryingPerf);
  96. void TunePropCacheParameters(BOOL fServer, WORD wIndexingPerf, WORD wQueryingPerf);
  97. void TuneMiscellaneousParameters(BOOL fServer, WORD wIndexingPerf, WORD wQueryingPerf);
  98. // Wait on service
  99. BOOL WaitForSvcStateChange( SERVICE_STATUS *pss, int iSecs = 120);
  100. HKEY _hkeyLM; // HKEY_LOCAL_MACHINE (may be remote)
  101. HKEY _hkeyContentIndex; // Content Index key (top level)
  102. BOOL _fWrite; // Writable access to the registry
  103. //
  104. // Service handles (for start and stop)
  105. //
  106. CServiceHandle _xSCRoot;
  107. CServiceHandle _xSCCI;
  108. XGrowable<WCHAR,MAX_COMPUTERNAME_LENGTH> _xwcsMachName; // Name of machine
  109. };
  110. //+---------------------------------------------------------------------------
  111. //
  112. // Class: CCatStateInfo
  113. //
  114. // Purpose: maintains catalog state information
  115. //
  116. // History: 4-3-98 mohamedn created
  117. //
  118. //----------------------------------------------------------------------------
  119. class CCatStateInfo
  120. {
  121. public:
  122. CCatStateInfo(CCatalogAdmin &catAdmin) : _catAdmin(catAdmin), _sc(S_OK)
  123. {
  124. RtlZeroMemory( &_state, sizeof(CI_STATE) );
  125. }
  126. BOOL LokUpdate(void);
  127. BOOL IsValid(void) { return ( S_OK == _sc ); }
  128. SCODE GetErrorCode(void) { return _sc; }
  129. DWORD GetWordListCount(void) { return _state.cWordList; }
  130. DWORD GetPersistentIndexCount(void) { return _state.cPersistentIndex; }
  131. DWORD GetQueryCount(void) { return _state.cQueries; }
  132. DWORD GetDocumentsToFilter(void) { return _state.cDocuments; }
  133. DWORD GetFreshTestCount(void) { return _state.cFreshTest; }
  134. DWORD PctMergeComplete(void) { return _state.dwMergeProgress; }
  135. DWORD GetStateInfo(void) { return _state.eState; }
  136. DWORD GetFilteredDocumentCount(void){ return _state.cFilteredDocuments; }
  137. DWORD GetTotalDocumentCount(void) { return _state.cTotalDocuments; }
  138. DWORD GetPendingScanCount(void) { return _state.cPendingScans; }
  139. DWORD GetIndexSize(void) { return _state.dwIndexSize; }
  140. DWORD GetUniqueKeyCount(void) { return _state.cUniqueKeys; }
  141. DWORD GetDelayedFilterCount(void) { return _state.cSecQDocuments; }
  142. private:
  143. CCatalogAdmin & _catAdmin;
  144. CI_STATE _state;
  145. SCODE _sc;
  146. };
  147. //+---------------------------------------------------------------------------
  148. //
  149. // Class: CCatalogAdmin
  150. //
  151. // Purpose: Administer a catalog
  152. //
  153. // History: 28-Jan-97 KyleP Created.
  154. //
  155. //----------------------------------------------------------------------------
  156. class CCatalogAdmin
  157. {
  158. public:
  159. ~CCatalogAdmin();
  160. //
  161. // Service manipulation
  162. //
  163. BOOL IsStarted();
  164. BOOL IsStopped();
  165. BOOL IsPaused();
  166. BOOL Start();
  167. BOOL Stop();
  168. BOOL Pause();
  169. //
  170. // Scope manipulation
  171. //
  172. void AddScope( WCHAR const * pwszScope,
  173. WCHAR const * pwszAlias = 0,
  174. BOOL fExclude = FALSE,
  175. WCHAR const * pwszLogon = 0,
  176. WCHAR const * pwszPassword = 0 );
  177. void RemoveScope( WCHAR const * pwszScope );
  178. BOOL IsPathInScope( WCHAR const * pwszPath );
  179. //
  180. // Properties
  181. //
  182. void AddCachedProperty(CFullPropSpec const & fps,
  183. ULONG vt,
  184. ULONG cb,
  185. DWORD dwStoreLevel = SECONDARY_STORE,
  186. BOOL fModifiable = TRUE);
  187. //
  188. // Parameters
  189. //
  190. void TrackIIS( BOOL fTrackIIS );
  191. BOOL IsTrackingIIS();
  192. BOOL IsCatalogInactive();
  193. CScopeEnum * QueryScopeEnum();
  194. CScopeAdmin* QueryScopeAdmin( WCHAR const * pwszPath);
  195. void DeleteRegistryParamNoThrow( WCHAR const * pwszParam );
  196. BOOL GetDWORDParam( WCHAR const * pwszParam, DWORD & dwValue );
  197. void SetDWORDParam( WCHAR const * pwszParam, DWORD dwValue );
  198. WCHAR const * GetMachName() { return _xwcsMachName.Get(); }
  199. WCHAR const * GetName() { return _wcsCatName; }
  200. WCHAR const * GetLocation();
  201. BOOL IsLocal() const
  202. {
  203. return ( L'.' == _xwcsMachName[0] && 0 == _xwcsMachName[1] );
  204. }
  205. void AddOrReplaceSecret( WCHAR const * pwcUser, WCHAR const * pwcPW );
  206. CCatStateInfo & State(void) { return _catStateInfo; }
  207. private:
  208. friend class CMachineAdmin;
  209. friend class CCatalogEnum;
  210. CCatalogAdmin( HKEY hkeyLM,
  211. WCHAR const * pwszMachine,
  212. WCHAR const * pwszCatalog,
  213. BOOL fWrite );
  214. HKEY _hkeyCatalog; // Root of catalog
  215. BOOL _fWrite; // Write access
  216. CCatStateInfo _catStateInfo; // catalog state info
  217. XGrowable<WCHAR,MAX_COMPUTERNAME_LENGTH> _xwcsMachName; // Name of machine
  218. WCHAR _wcsCatName[MAX_PATH]; // Name of catalog
  219. WCHAR _wcsLocation[MAX_PATH]; // Catalog location
  220. WCHAR _wcsDriveOfLocation[_MAX_DRIVE]; // Drive where catalog is located
  221. };
  222. //+---------------------------------------------------------------------------
  223. //
  224. // Class: CCatalogEnum
  225. //
  226. // Purpose: Enumerates available catalogs
  227. //
  228. // History: 28-Jan-97 KyleP Created.
  229. //
  230. //----------------------------------------------------------------------------
  231. class CCatalogEnum
  232. {
  233. public:
  234. WCHAR const * Name() { return _awcCurrentCatalog; }
  235. CCatalogAdmin * QueryCatalogAdmin();
  236. BOOL Next();
  237. ~CCatalogEnum();
  238. private:
  239. friend class CMachineAdmin;
  240. CCatalogEnum( HKEY hkeyLM, WCHAR const * pwcsMachine, BOOL fWrite );
  241. HKEY _hkeyLM; // Root of machine (not owned)
  242. HKEY _hkeyCatalogs; // Root of catalog area
  243. DWORD _dwIndex; // Index of NEXT entry
  244. BOOL _fWrite; // TRUE for writable access
  245. XGrowable<WCHAR,MAX_COMPUTERNAME_LENGTH> _xawcCurrentMachine;
  246. WCHAR _awcCurrentCatalog[MAX_PATH];
  247. };
  248. //+---------------------------------------------------------------------------
  249. //
  250. // Class: CScopeEnum
  251. //
  252. // Purpose: Enumerates available scopes
  253. //
  254. // History: 28-Jan-97 KyleP Created.
  255. //
  256. //----------------------------------------------------------------------------
  257. class CScopeEnum
  258. {
  259. public:
  260. ~CScopeEnum();
  261. WCHAR const * Path() { return _awcCurrentScope; }
  262. CScopeAdmin * QueryScopeAdmin();
  263. BOOL Next();
  264. private:
  265. friend class CCatalogAdmin;
  266. CScopeEnum( HKEY hkeyCatalog, BOOL fIsLocal, BOOL fWrite );
  267. SRegKey _xkeyCatalog;
  268. SRegKey _xkeyScopes; // Root of scope area
  269. DWORD _dwIndex; // Index of NEXT entry
  270. WCHAR * _pwcsAlias; // Points into Data at alias
  271. WCHAR * _pwcsLogon; // Points into Data at logon
  272. BOOL _fExclude; // TRUE for exclude scope
  273. BOOL _fVirtual; // TRUE for virtual place-holder
  274. BOOL _fShadowAlias; // TRUE for shadow alias place-holder
  275. BOOL _fIsLocal; // TRUE if the local machine
  276. BOOL _fWrite; // TRUE for writable access
  277. WCHAR _awcCurrentScope[MAX_PATH];
  278. };
  279. //+---------------------------------------------------------------------------
  280. //
  281. // Class: CScopeAdmin
  282. //
  283. // Purpose: Set/Get scope properties
  284. //
  285. // History: 12-10-97 mohamedn created
  286. //
  287. //----------------------------------------------------------------------------
  288. class CScopeAdmin
  289. {
  290. public:
  291. WCHAR const * GetPath() { return _awcScope; }
  292. WCHAR const * GetAlias();
  293. WCHAR const * GetLogon() { return _awcLogon; }
  294. BOOL IsExclude() { return _fExclude; }
  295. BOOL IsVirtual() { return _fVirtual; }
  296. BOOL IsShadowAlias() { return _fShadowAlias; }
  297. BOOL IsLocal() { return _fIsLocal; }
  298. void SetPath (WCHAR const *pwszPath);
  299. void SetAlias (WCHAR const *pwszAlias);
  300. void SetExclude (BOOL fExclude);
  301. void SetLogonInfo(WCHAR const *pwszLogon,
  302. WCHAR const *pwszPassword,
  303. CCatalogAdmin & pCatAdmin);
  304. private:
  305. friend class CScopeEnum;
  306. void SetScopeValueString();
  307. CScopeAdmin( HKEY hkeyCatalog,
  308. WCHAR const * pwszScope,
  309. WCHAR const * pwszAlias,
  310. WCHAR const * pwszLogon,
  311. BOOL fExclude,
  312. BOOL fVirtual,
  313. BOOL fShadowAlias,
  314. BOOL fIsLocal,
  315. BOOL fWrite,
  316. BOOL fValidityCheck = TRUE );
  317. SRegKey _xkeyScopes;
  318. BOOL _fExclude; // TRUE for exclude scope
  319. BOOL _fVirtual; // TRUE for virtual place-holder
  320. BOOL _fShadowAlias; // TRUE for shadow alias place-holder
  321. BOOL _fWrite; // TRUE if writable access
  322. BOOL _fIsLocal; // TRUE if the scope is on the local machine
  323. WCHAR _awcScope[MAX_PATH];
  324. WCHAR _awcAlias[MAX_PATH]; // Points into Data at alias
  325. WCHAR _awcLogon[MAX_PATH]; // Points into Data at logon
  326. };
  327. //+---------------------------------------------------------------------------
  328. //
  329. // Member: CScopeAdmin::GetAlias, public
  330. //
  331. // Returns: Alias to scope (or scope itself if it is a UNC path)
  332. //
  333. // History: 9-May-97 KyleP Created
  334. //
  335. //----------------------------------------------------------------------------
  336. inline WCHAR const * CScopeAdmin::GetAlias()
  337. {
  338. return _awcAlias;
  339. }