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.

358 lines
11 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997 - 1998.
  5. //
  6. // File: lgplist.hxx
  7. //
  8. // Contents: Local/Global property list classes
  9. //
  10. // History: 05 May 1997 Alanw Created
  11. // 27 Aug 1997 KrishnaN Moved from ixsso to querylib
  12. //
  13. //----------------------------------------------------------------------------
  14. #pragma once
  15. #include "plist.hxx"
  16. #include <regevent.hxx>
  17. #include <regacc.hxx>
  18. #include <ciregkey.hxx>
  19. class CPropListFile;
  20. class CLocalGlobalPropertyList;
  21. #define REFRESH_INTERVAL 5000
  22. //
  23. // A few Ref counting rules to remember.
  24. //
  25. // 1. GetGlobalPropListFile and GetGlobalStaticList will AddRef the pointer
  26. // they return.
  27. // 2. SetDefaultList will AddRef the pointer it receives (and later releases
  28. // it).
  29. // 3. Anyone calling GetGlobalPropListFile and GetGlobalStaticList should
  30. // be aware that they are AddRef'ing.
  31. // 4. Anyone calling SetDefaultList should be aware that it will AddRef the
  32. // pointer it receives.
  33. //
  34. // 5. The global prop list file returned by GetGlobalPropListFile should
  35. // have a refcount of 0 when the last consumer releases it. This is so
  36. // that it will be cleaned up when the service shuts down.
  37. //
  38. //+---------------------------------------------------------------------------
  39. //
  40. // Class: CDefColumnRegEntry
  41. //
  42. // Purpose: Registry variables used by IColumnMapper implementation.
  43. //
  44. // History 17-Sep-97 KrishnaN Created
  45. //
  46. //----------------------------------------------------------------------------
  47. class CDefColumnRegEntry
  48. {
  49. public :
  50. CDefColumnRegEntry();
  51. void Refresh( BOOL fUseDefaultOnFailure = FALSE );
  52. const ULONG GetDefaultColumnFile( WCHAR *pwc, ULONG cwc )
  53. {
  54. Refresh( TRUE );
  55. ULONG cwcBuf = wcslen( _awcDefaultColumnFile );
  56. if ( cwc > cwcBuf )
  57. wcscpy( pwc, _awcDefaultColumnFile );
  58. return cwcBuf;
  59. }
  60. private:
  61. WCHAR _awcDefaultColumnFile[_MAX_PATH]; // default column definitions
  62. };
  63. //+---------------------------------------------------------------------------
  64. //
  65. // Class: CCombinedPropertyList
  66. //
  67. // Purpose: This encapsulates a default property list and an overriding
  68. // property list. All search and iteration will first target the
  69. // default list, and on failure, targets the overriding list.
  70. //
  71. // Notes: This class is intended to be shared among multiple threads.
  72. //
  73. // History: 11 Sep 1997 KrishnaN Created
  74. //
  75. //----------------------------------------------------------------------------
  76. class CCombinedPropertyList : public CEmptyPropertyList
  77. {
  78. public:
  79. CCombinedPropertyList(ULONG ulCodePage = CP_ACP)
  80. : CEmptyPropertyList(),
  81. _ulCodePage( ulCodePage ),
  82. _fOverrides( FALSE )
  83. {
  84. // We were not passed in a prop list. You should use SetDefaultList to
  85. // set the default.
  86. }
  87. CCombinedPropertyList(CEmptyPropertyList *pDefaultList, ULONG ulCodePage = CP_ACP)
  88. : CEmptyPropertyList(),
  89. _ulCodePage( ulCodePage ),
  90. _fOverrides( FALSE )
  91. {
  92. // NOTE : pDefaultList was already addref'd by caller, so it will be
  93. // released by the smart ptr.
  94. XInterface<CEmptyPropertyList> xPropList(pDefaultList);
  95. SetDefaultList(xPropList.GetPointer());
  96. }
  97. virtual CPropEntry const * Find( WCHAR const * wcsName );
  98. virtual CPropEntry const * Find( CDbColId const & prop )
  99. {
  100. return CEmptyPropertyList::Find(prop);
  101. }
  102. virtual CPropEntry const * Next();
  103. virtual void InitIterator();
  104. virtual void AddEntry( CPropEntry * ppentry, int iLine );
  105. virtual ULONG GetCount();
  106. virtual SCODE GetAllEntries(CPropEntry **ppPropEntries, ULONG ulMaxCount);
  107. void ClearList(); // q.exe accesses this, so it has to be public for now.
  108. STDMETHOD(IsMapUpToDate)()
  109. {
  110. // return the IsMapUpToDate of the default list.
  111. return GetDefaultList().IsMapUpToDate();
  112. }
  113. protected:
  114. virtual ~CCombinedPropertyList() {};
  115. CEmptyPropertyList & GetDefaultList() const
  116. {
  117. return _xDefaultList.GetReference();
  118. }
  119. void SetDefaultList(CEmptyPropertyList *pDefaultList);
  120. CPropertyList & GetOverrideList() const
  121. {
  122. return _xOverrideList.GetReference();
  123. }
  124. private:
  125. // CPropertyList is a XInterface so it does not have to know about the
  126. // protected destructor of CPropertyList.
  127. XInterface<CPropertyList> _xOverrideList;
  128. XInterface<CEmptyPropertyList> _xDefaultList;
  129. CMutexSem _mtxAdd;
  130. BOOL _fOverrides;
  131. ULONG _ulCodePage;
  132. };
  133. //+---------------------------------------------------------------------------
  134. //
  135. // Class: CPropListFile
  136. //
  137. // Purpose: Property list file. Contains a property list obtained from
  138. // column definition file.
  139. //
  140. // Notes: This class is intended to be shared among multiple threads.
  141. //
  142. // History: 06 May 1997 AlanW Created
  143. // 29 Aug 1997 KrishnaN Modified
  144. //
  145. //----------------------------------------------------------------------------
  146. class CPropListFile : public CCombinedPropertyList
  147. {
  148. public:
  149. CPropListFile( CEmptyPropertyList *pDefaultList,
  150. BOOL fDynamicRefresh,
  151. WCHAR const * pwcsPropFile = 0,
  152. ULONG ulCodePage = CP_ACP );
  153. SCODE CheckError( ULONG & iLine, WCHAR ** ppFile );
  154. STDMETHOD(IsMapUpToDate)();
  155. ~CPropListFile();
  156. //
  157. // Before accessing the file based list, check to see
  158. // if the list needs to be updated.
  159. //
  160. virtual CPropEntry const * Find( WCHAR const * wcsName )
  161. {
  162. Refresh();
  163. return CCombinedPropertyList::Find(wcsName);
  164. }
  165. virtual CPropEntry const * Find( CDbColId const & prop )
  166. {
  167. Refresh();
  168. return CCombinedPropertyList::Find(prop);
  169. }
  170. virtual void InitIterator()
  171. {
  172. Refresh();
  173. CCombinedPropertyList::InitIterator();
  174. }
  175. private:
  176. friend CLocalGlobalPropertyList;
  177. // load the property list from the file
  178. void Load( WCHAR const * const pwszFile );
  179. SCODE ParseNameFile( WCHAR const * wcsFileName );
  180. static SCODE GetLastWriteTime( WCHAR const * pwszFileName, FILETIME & ft );
  181. void Refresh();
  182. // return property list file name
  183. WCHAR const * const GetFileName() const
  184. {
  185. return _xFileName.GetPointer();
  186. }
  187. FILETIME _ftFile; // file modification time
  188. CMutexSem _mtx;
  189. XPtrST<WCHAR> _xFileName;
  190. DWORD _dwLastCheckMoment;
  191. ULONG _ulCodePage;
  192. ULONG _iErrorLine;
  193. SCODE _scError;
  194. BOOL _fDynamicRefresh; // want dynamic refresh of list?
  195. XPtrST<WCHAR> _xErrorFile;
  196. CDefColumnRegEntry _RegParams; // registry params
  197. };
  198. //+---------------------------------------------------------------------------
  199. //
  200. // Class: CLocalGlobalPropertyList
  201. //
  202. // Purpose: A property list that includes a global portion, and a set of
  203. // local override definitions. If the user wants to use their own
  204. // file, they can provide one and specify how that should be used.
  205. // Or they can simply have the registry based prop list file.
  206. //
  207. // Notes:
  208. //
  209. // History: 06 May 1997 AlanW Created
  210. // 27 Aug 1997 KrishnaN Modified to use/expose schema i/fs.
  211. //
  212. //----------------------------------------------------------------------------
  213. class CLocalGlobalPropertyList : public CCombinedPropertyList
  214. {
  215. public:
  216. CLocalGlobalPropertyList( ULONG ulCodePage = CP_ACP );
  217. CLocalGlobalPropertyList( CEmptyPropertyList *pDefaultList,
  218. BOOL fDynamicRefresh,
  219. WCHAR const * pwcsPropFile = 0,
  220. ULONG ulCodePage = CP_ACP );
  221. STDMETHOD(IsMapUpToDate)();
  222. SCODE CheckError( ULONG & iLine, WCHAR ** ppFile );
  223. void Load( WCHAR const * const wcsFileName );
  224. private:
  225. friend CPropListFile * GetGlobalPropListFile();
  226. friend CEmptyPropertyList;
  227. friend void CreateNewGlobalPropFileList(WCHAR CONST *wcsFileName);
  228. ULONG _ulCodePage;
  229. CDefColumnRegEntry _RegParams; // registry params
  230. DWORD _dwLastCheckMoment;
  231. CMutexSem _mtx;
  232. XPtrST<WCHAR> _xFileName;
  233. static CPropListFile * _pGlobalPropListFile;
  234. static void InitGlobalPropertyList();
  235. };
  236. class CGlobalPropFileRefresher
  237. {
  238. public:
  239. CGlobalPropFileRefresher()
  240. {
  241. _dwLastCheckMoment = GetTickCount();
  242. // Init to an error condition. The most reasonable is can't open
  243. _lRegReturn = ERROR_CANTOPEN;
  244. }
  245. void Init();
  246. void GetDefaultColumnFile(WCHAR *wcsFileName)
  247. {
  248. wcsFileName[0] = 0;
  249. if (ERROR_SUCCESS == _lRegReturn)
  250. {
  251. DWORD dwType = REG_SZ;
  252. DWORD dwSize = MAX_PATH * sizeof(WCHAR);
  253. // If we successfully read the value, the full path name will be read in
  254. RegQueryValueEx(_hKey,
  255. wcsDefaultColumnFile,
  256. 0,
  257. &dwType,
  258. (LPBYTE)wcsFileName,
  259. &dwSize
  260. );
  261. }
  262. }
  263. BOOL DoIt();
  264. ~CGlobalPropFileRefresher()
  265. {
  266. if (ERROR_SUCCESS == _lRegReturn)
  267. {
  268. Win4Assert(_fInited);
  269. RegCloseKey(_hKey);
  270. }
  271. }
  272. private:
  273. void GetLastWriteTime(FILETIME & ftLastWrite)
  274. {
  275. WIN32_FIND_DATA ffData;
  276. if ( !_wcsFileName[0] ||
  277. !GetFileAttributesEx( _wcsFileName, GetFileExInfoStandard, &ffData ) )
  278. {
  279. RtlZeroMemory(&ftLastWrite, sizeof(FILETIME));
  280. return;
  281. }
  282. ftLastWrite = ffData.ftLastWriteTime;
  283. }
  284. static CRegChangeEvent _regChangeEvent;
  285. static WCHAR _wcsFileName[MAX_PATH];
  286. static FILETIME _ftFile; // file modification time
  287. static DWORD _dwLastCheckMoment;
  288. static BOOL _fInited;
  289. static HKEY _hKey;
  290. static LONG _lRegReturn;
  291. };
  292. CStaticPropertyList * GetGlobalStaticPropertyList();
  293. CPropListFile * GetGlobalPropListFile();
  294. void CreateNewGlobalPropFileList(WCHAR CONST *wcsFileName);