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.

487 lines
13 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1994-2000.
  5. //
  6. // File: PLIST.HXX
  7. //
  8. // Contents: Property List class
  9. //
  10. // Classes: CPropertyList
  11. // CPropEntry
  12. // CPListException
  13. //
  14. // History: 17-May-94 t-jeffc Created.
  15. //
  16. //----------------------------------------------------------------------------
  17. #pragma once
  18. const MAX_LINE_LENGTH = 512;
  19. const MAX_PROPNAME_LENGTH = 200;
  20. unsigned const PLIST_DEFAULT_WIDTH = 10;
  21. // forward decls
  22. class CQueryScanner;
  23. class CEmptyPropertyList;
  24. class CPropEntry;
  25. //+---------------------------------------------------------------------------
  26. //
  27. // Class: CPropEntryIter
  28. //
  29. // Purpose: Iterates over CPropEntry items in a CPropertyList
  30. //
  31. // History: 28-Feb-96 dlee Created.
  32. //
  33. //----------------------------------------------------------------------------
  34. class CPropEntryIter
  35. {
  36. public:
  37. CPropEntryIter( CEmptyPropertyList & list );
  38. CPropEntry const * Next();
  39. private:
  40. CEmptyPropertyList & _list;
  41. };
  42. //+---------------------------------------------------------------------------
  43. //
  44. // Class: CPropEntry
  45. //
  46. // Purpose: One entry in the 'friendly' to 'ugly' property name
  47. // mapping. A list of these is managed by CPropertyList.
  48. //
  49. // History: 17-May-94 t-jeffc Created.
  50. //
  51. //----------------------------------------------------------------------------
  52. class CPropEntry
  53. {
  54. public:
  55. CPropEntry( XPtrST<WCHAR> & wcsDisplayName,
  56. XPtrST<WCHAR> & wcsName )
  57. : _szFriendlyName( wcsName.Acquire() ),
  58. _szDisplayName( wcsDisplayName.Acquire() ),
  59. _ppentryNext( 0 ),
  60. _ptype(0),
  61. _uWidth(0),
  62. _fIsDisplayed( TRUE ),
  63. _fStaticStrings( FALSE )
  64. {
  65. }
  66. CPropEntry( XPtrST<WCHAR> & wcsName,
  67. DBTYPE dbType,
  68. const GUID & guid,
  69. PROPID propId )
  70. : _szFriendlyName( wcsName.Acquire() ),
  71. _szDisplayName( 0 ),
  72. _ppentryNext( 0 ),
  73. _ptype(dbType),
  74. _uWidth(0),
  75. _fIsDisplayed( TRUE ),
  76. _fStaticStrings( FALSE )
  77. {
  78. _prop.SetPropSet(guid);
  79. _prop.SetProperty(propId);
  80. }
  81. CPropEntry( XPtrST<WCHAR> & wcsName,
  82. DBTYPE dbType,
  83. const GUID & guid,
  84. const WCHAR * wcsPropName )
  85. : _szFriendlyName( wcsName.Acquire() ),
  86. _szDisplayName( 0 ),
  87. _ppentryNext( 0 ),
  88. _ptype(dbType),
  89. _uWidth(0),
  90. _fIsDisplayed( TRUE ),
  91. _fStaticStrings( FALSE )
  92. {
  93. _prop.SetPropSet(guid);
  94. if ( !_prop.SetProperty(wcsPropName) )
  95. THROW( CException(E_OUTOFMEMORY) );
  96. }
  97. CPropEntry( XPtrST<WCHAR> & wcsName,
  98. DBTYPE dbType,
  99. const DBID dbCol )
  100. : _szFriendlyName( wcsName.Acquire() ),
  101. _szDisplayName( 0 ),
  102. _ppentryNext( 0 ),
  103. _ptype(dbType),
  104. _uWidth(0),
  105. _fIsDisplayed( TRUE ),
  106. _fStaticStrings( FALSE ),
  107. _prop( dbCol )
  108. {
  109. }
  110. CPropEntry( LPWSTR wcsName,
  111. LPWSTR wcsDisplayName,
  112. DBTYPE dbType,
  113. const DBID dbCol )
  114. : _szFriendlyName( wcsName ),
  115. _szDisplayName( wcsDisplayName ),
  116. _ppentryNext( 0 ),
  117. _ptype(dbType),
  118. _uWidth(0),
  119. _fIsDisplayed( TRUE ),
  120. _fStaticStrings( TRUE ),
  121. _prop( dbCol )
  122. {
  123. }
  124. ~CPropEntry()
  125. {
  126. if (! _fStaticStrings)
  127. {
  128. delete _szFriendlyName;
  129. delete _szDisplayName;
  130. }
  131. }
  132. BOOL NameMatch( WCHAR const * wcsName ) const
  133. {
  134. return !wcscmp( wcsName, _szFriendlyName );
  135. }
  136. BOOL DisplayNameMatch( WCHAR const * wcsName ) const
  137. {
  138. return !_wcsicmp( wcsName, _szDisplayName );
  139. }
  140. // getters/setters
  141. CPropEntry * Next() const { return _ppentryNext; }
  142. void SetNext( CPropEntry * ppentry ) { _ppentryNext = ppentry; }
  143. DBTYPE GetPropType() const { return _ptype; }
  144. void SetPropType( DBTYPE ptype ) { _ptype = ptype; }
  145. unsigned int GetWidth() const { return _uWidth; }
  146. void SetWidth( unsigned int uWidth ) { _uWidth = uWidth; }
  147. CDbColId & PropSpec() { return _prop; }
  148. CDbColId const & PropSpec() const { return _prop; }
  149. WCHAR const * GetName() const { return _szFriendlyName; }
  150. WCHAR const * GetDisplayName() const { return _szDisplayName; }
  151. BOOL IsDisplayed() const { return _fIsDisplayed; }
  152. void SetDisplayed( BOOL fDisplayed ) { _fIsDisplayed = fDisplayed; }
  153. private:
  154. CPropEntry * _ppentryNext;
  155. WCHAR * _szFriendlyName;
  156. WCHAR * _szDisplayName;
  157. CDbColId _prop;
  158. unsigned int _uWidth;
  159. BOOL _fIsDisplayed;
  160. BOOL _fStaticStrings;
  161. DBTYPE _ptype;
  162. };
  163. // Keep this in sync with CPropEntry. Can't use CPropEntry because
  164. // CDbColId can't be initialized with static initializer, and it's
  165. // too painful to use DBID in CPropEntry.
  166. struct SPropEntry
  167. {
  168. CPropEntry * _ppentryNext;
  169. WCHAR * _szFriendlyName;
  170. WCHAR * _szDisplayName;
  171. DBID _prop;
  172. unsigned int _uWidth;
  173. BOOL _fIsDisplayed;
  174. BOOL _fStaticStrings;
  175. DBTYPE _ptype;
  176. };
  177. //+---------------------------------------------------------------------------
  178. //
  179. // Class: CEmptyPropertyList
  180. //
  181. // Purpose: Base class implementing common functionality.
  182. //
  183. // History: 28-Aug-97 krishnan Created.
  184. //
  185. //----------------------------------------------------------------------------
  186. class CEmptyPropertyList : public IColumnMapper
  187. {
  188. public:
  189. CEmptyPropertyList()
  190. : _cRefs( 1 ),
  191. _iLastEntryPos( 0 ),
  192. _pPropIterator( 0 )
  193. {
  194. }
  195. static unsigned GetPropTypeCount();
  196. static WCHAR const * GetPropTypeName( unsigned i );
  197. static DBTYPE GetPropType( unsigned i );
  198. BOOL GetPropInfo( WCHAR const * wcsPropName,
  199. CDbColId ** ppprop,
  200. DBTYPE * pproptype,
  201. unsigned int * puWidth );
  202. BOOL GetPropInfo( CDbColId const & prop,
  203. WCHAR const ** pwcsName,
  204. DBTYPE * pproptype,
  205. unsigned int * puWidth );
  206. //
  207. // This is the same for all property lists, since it only
  208. // itetarates through the list of entries using proplist
  209. // specific iterators.
  210. //
  211. CPropEntry const * Find( CDbColId const & prop );
  212. //
  213. // These are only meaningful where there is a list.
  214. //
  215. virtual CPropEntry const * Find( WCHAR const * wcsName ) = 0;
  216. virtual void AddEntry( CPropEntry * ppentry, int iLine ) = 0;
  217. virtual CPropEntry const * Next() = 0;
  218. virtual void InitIterator() = 0;
  219. virtual ULONG GetCount() = 0;
  220. virtual SCODE GetAllEntries(CPropEntry **ppPropEntries, ULONG ulMaxCount) = 0;
  221. //
  222. // IUnknown methods.
  223. //
  224. STDMETHOD(QueryInterface) (THIS_ REFIID riid, void ** ppvObj);
  225. STDMETHOD_(ULONG, AddRef) (THIS);
  226. STDMETHOD_(ULONG, Release) (THIS);
  227. //
  228. // IColumnMapper methods
  229. //
  230. STDMETHOD(GetPropInfoFromName) (
  231. const WCHAR *wcsPropName,
  232. DBID * *ppPropId,
  233. DBTYPE *pPropType,
  234. unsigned int *puiWidth);
  235. STDMETHOD(GetPropInfoFromId) (
  236. const DBID *pPropId,
  237. WCHAR * *pwcsName,
  238. DBTYPE *pPropType,
  239. unsigned int *puiWidth);
  240. STDMETHOD(EnumPropInfo) (
  241. ULONG iEntry,
  242. const WCHAR * *pwcsName,
  243. DBID * *ppPropId,
  244. DBTYPE *pPropType,
  245. unsigned int *puiWidth);
  246. STDMETHOD(IsMapUpToDate) () = 0;
  247. protected:
  248. // this should be virtual so the derived classes's destructor will always
  249. // be called.
  250. virtual ~CEmptyPropertyList()
  251. {
  252. delete _pPropIterator;
  253. }
  254. private:
  255. LONG _cRefs; // ref counting
  256. // Variables to support EnumPropInfo
  257. ULONG _iLastEntryPos; // last retrieved entry position.
  258. CPropEntryIter * _pPropIterator; // the enumerator
  259. };
  260. //+---------------------------------------------------------------------------
  261. //
  262. // Class: CStaticPropertyList
  263. //
  264. // Purpose: Static list of 'friendly' to 'ugly' property name mapping.
  265. // It also holds an array of "file" based property mapping, which
  266. // will be used only when file based entries are used to override
  267. // the static entries (as in CPropListFile)
  268. //
  269. // History: 17-May-94 t-jeffc Created.
  270. // 28-Aug-97 krishnan IColumnMapper replaces PPropertyList.
  271. //
  272. //----------------------------------------------------------------------------
  273. class CStaticPropertyList : public CEmptyPropertyList
  274. {
  275. public:
  276. CStaticPropertyList(ULONG ulCodePage = CP_ACP)
  277. : CEmptyPropertyList(),
  278. _ulCodePage( ulCodePage ),
  279. _icur( 0 ),
  280. _pcur( 0 )
  281. {
  282. }
  283. virtual void AddEntry( CPropEntry * ppentry, int iLine )
  284. {
  285. Win4Assert(!"Should not have been called.");
  286. }
  287. virtual CPropEntry const * Find( WCHAR const * wcsName );
  288. virtual CPropEntry const * Find( CDbColId const & prop )
  289. {
  290. return CEmptyPropertyList::Find(prop);
  291. }
  292. virtual CPropEntry const * Next();
  293. virtual void InitIterator();
  294. STDMETHOD(IsMapUpToDate) ()
  295. {
  296. // the static property list is always up to date.
  297. return S_OK;
  298. };
  299. virtual ULONG GetCount() {return cStaticPropEntries;};
  300. virtual SCODE GetAllEntries(CPropEntry **ppPropEntries, ULONG ulMaxCount);
  301. protected:
  302. enum { cStaticPropHash = 1311 };
  303. // Static (system-defined) properties, like path and filename
  304. static const CPropEntry * _aStaticEntries[ cStaticPropHash ];
  305. static const unsigned cStaticPropEntries;
  306. private:
  307. ULONG _ulCodePage;
  308. CPropEntry const * _pcur;
  309. unsigned _icur;
  310. };
  311. //+---------------------------------------------------------------------------
  312. //
  313. // Class: CPropertyList
  314. //
  315. // Purpose: Parses and manages a 'friendly' to 'ugly' property name
  316. // mapping.
  317. //
  318. // History: 17-May-94 t-jeffc Created.
  319. // 28-Aug-97 krishnan IColumnMapper replaces PPropertyList.
  320. //
  321. //----------------------------------------------------------------------------
  322. class CPropertyList : public CEmptyPropertyList
  323. {
  324. public:
  325. CPropertyList(ULONG ulCodePage = CP_ACP)
  326. : CEmptyPropertyList(),
  327. _ulCodePage( ulCodePage ),
  328. _icur( 0 ),
  329. _pcur( 0 ),
  330. _ulCount( 0 )
  331. {
  332. RtlZeroMemory( _aEntries, sizeof _aEntries );
  333. }
  334. void ClearList();
  335. virtual void AddEntry( CPropEntry * ppentry, int iLine );
  336. virtual CPropEntry const * Find( WCHAR const * wcsName );
  337. virtual CPropEntry const * Find( CDbColId const & prop )
  338. {
  339. return CEmptyPropertyList::Find(prop);
  340. }
  341. virtual CPropEntry const * Next();
  342. virtual void InitIterator();
  343. virtual ULONG GetCount();
  344. virtual SCODE GetAllEntries(CPropEntry **ppPropEntries, ULONG ulMaxCount);
  345. static void ParseOneLine( CQueryScanner & scan, int iLine,
  346. XPtr<CPropEntry> & propentry );
  347. STDMETHOD(IsMapUpToDate) ()
  348. {
  349. //
  350. // The local list is always considered up to date because it can't
  351. // go get new items even if it knew there were new ones. The
  352. // owner adds them.
  353. //
  354. return S_OK;
  355. };
  356. ~CPropertyList();
  357. private:
  358. CPropEntry * FindDynamic( WCHAR const * wcsName );
  359. enum { cPropHash = 13};
  360. // Dynamic (user-defined) properties
  361. CPropEntry * _aEntries[ cPropHash ];
  362. ULONG _ulCodePage;
  363. CMutexSem _mtxList;
  364. CPropEntry const * _pcur;
  365. unsigned _icur;
  366. ULONG _ulCount;
  367. };
  368. inline ULONG CPropertyList::GetCount()
  369. {
  370. return _ulCount;
  371. }
  372. //+---------------------------------------------------------------------------
  373. //
  374. // Class: CPListException
  375. //
  376. // Purpose: Exception class for property list errors
  377. //
  378. // History: 17-May-94 t-jeffc Created.
  379. //
  380. //----------------------------------------------------------------------------
  381. class CPListException : public CException
  382. {
  383. public:
  384. CPListException( SCODE ple, int iLine )
  385. : CException( ple ),
  386. _iLine( iLine )
  387. {
  388. }
  389. SCODE GetPListError() { return GetErrorCode(); }
  390. int GetLine() { return _iLine; }
  391. private:
  392. int _iLine;
  393. };
  394. inline CPropEntryIter::CPropEntryIter( CEmptyPropertyList & list )
  395. : _list( list )
  396. {
  397. _list.InitIterator();
  398. }
  399. inline CPropEntry const * CPropEntryIter::Next()
  400. {
  401. return _list.Next();
  402. }
  403. ULONG HashFun( WCHAR const * pwcName );