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.

541 lines
13 KiB

  1. /*
  2. * D A V M B . H
  3. *
  4. * DAV metabase
  5. *
  6. * Copyright 1986-1997 Microsoft Corporation, All Rights Reserved
  7. */
  8. #ifndef _DAVMB_H_
  9. #define _DAVMB_H_
  10. #include <initguid.h>
  11. #include <exguid.h>
  12. #include <iadmw.h>
  13. #include <iwamreg.h>
  14. #include <iiscnfg.h>
  15. #include <autoptr.h>
  16. #include <exo.h>
  17. #include <malloc.h>
  18. #include <szsrc.h>
  19. #include <ex\refcnt.h>
  20. // Advising the notification sink --------------------------------------------
  21. //
  22. HRESULT
  23. HrAdviseSink( IMSAdminBase& msAdminBase,
  24. IMSAdminBaseSink * pMSAdminBaseSink,
  25. DWORD * pdwCookie );
  26. // Unadvising the notification sink ------------------------------------------
  27. //
  28. VOID
  29. UnadviseSink( IMSAdminBase& msAdminBase,
  30. DWORD dwCookie );
  31. // Constructing metabase change object ---------------------------------
  32. //
  33. inline
  34. SCODE ScBuildChangeObject(LPCWSTR pwszBase,
  35. UINT cchBase,
  36. LPCWSTR pwszPath,
  37. UINT cchPath,
  38. DWORD dwMDChangeType,
  39. const DWORD * pdwMDDataId,
  40. LPWSTR pwszBuf,
  41. UINT * pcchBuf,
  42. PMD_CHANGE_OBJECT_W pMdChObjW)
  43. {
  44. SCODE sc = S_OK;
  45. UINT cchT;
  46. Assert(0 == cchBase || pwszBase);
  47. Assert(0 == cchPath || pwszPath);
  48. Assert(pdwMDDataId);
  49. Assert(pcchBuf);
  50. Assert(0 == *pcchBuf || pwszBuf);
  51. Assert(pMdChObjW);
  52. // Ambiguous trace. I am comenting it out...
  53. //
  54. /* DebugTrace( "ScBuildChangeObject() called:\n"
  55. " Base path: '%S'\n"
  56. " Remaining path: '%S'\n"
  57. " Change type: 0x%08lX\n"
  58. " Data ID: 0x%08lX\n",
  59. pwszBase ? pwszBase : L"NONE",
  60. pwszPath ? pwszPath : L"NONE",
  61. dwMDChangeType,
  62. *pdwMDDataId );*/
  63. // Construct the path change is occuring on.
  64. //
  65. BOOL fNeedSeparator = FALSE;
  66. BOOL fNeedTerminator = FALSE;
  67. // Make sure that we do not assemble the path with
  68. // double '/' in the middle.
  69. //
  70. if (cchBase &&
  71. cchPath &&
  72. L'/' == pwszBase[cchBase - 1] &&
  73. L'/' == pwszPath[0])
  74. {
  75. // Get rid of one '/'
  76. //
  77. cchBase--;
  78. }
  79. else if ((0 == cchBase || L'/' != pwszBase[cchBase - 1]) &&
  80. (0 == cchPath || L'/' != pwszPath[0]))
  81. {
  82. // We need a separator
  83. //
  84. fNeedSeparator = TRUE;
  85. }
  86. // Check out if we need terminating '/' at the end.
  87. //
  88. if (cchPath && L'/' != pwszPath[cchPath - 1])
  89. {
  90. fNeedTerminator = TRUE;
  91. }
  92. cchT = cchBase + cchPath + 1;
  93. if (fNeedSeparator)
  94. {
  95. cchT++;
  96. }
  97. if (fNeedTerminator)
  98. {
  99. cchT++;
  100. }
  101. if (*pcchBuf < cchT)
  102. {
  103. *pcchBuf = cchT;
  104. sc = S_FALSE;
  105. }
  106. else
  107. {
  108. cchT = 0;
  109. if (cchBase)
  110. {
  111. memcpy(pwszBuf, pwszBase, cchBase * sizeof(WCHAR));
  112. cchT += cchBase;
  113. }
  114. if (fNeedSeparator)
  115. {
  116. pwszBuf[cchT] = L'/';
  117. cchT++;
  118. }
  119. if (cchPath)
  120. {
  121. memcpy(pwszBuf + cchT, pwszPath, cchPath * sizeof(WCHAR));
  122. cchT += cchPath;
  123. }
  124. if (fNeedTerminator)
  125. {
  126. pwszBuf[cchT] = L'/';
  127. cchT++;
  128. }
  129. pwszBuf[cchT] = L'\0';
  130. pMdChObjW->pszMDPath = pwszBuf;
  131. pMdChObjW->dwMDChangeType = dwMDChangeType;
  132. pMdChObjW->dwMDNumDataIDs = 1;
  133. pMdChObjW->pdwMDDataIDs = const_cast<DWORD *>(pdwMDDataId);
  134. }
  135. return sc;
  136. }
  137. class LFUData
  138. {
  139. // Approximate number of hits via Touch()
  140. //
  141. DWORD m_dwcHits;
  142. // NOT IMPLEMENTED
  143. //
  144. LFUData& operator=(const LFUData&);
  145. LFUData(const LFUData&);
  146. public:
  147. // CREATORS
  148. //
  149. LFUData() : m_dwcHits(0) {}
  150. // MANIPULATORS
  151. //
  152. // --------------------------------------------------------------------
  153. //
  154. // Touch()
  155. //
  156. // Increments the hit count. Note that this is done without an
  157. // interlocked operation. The expectation is that the actual count
  158. // value is just a hint and as such, it is not critical that it be
  159. // exactly accurate.
  160. //
  161. VOID Touch()
  162. {
  163. ++m_dwcHits;
  164. }
  165. // --------------------------------------------------------------------
  166. //
  167. // DwGatherAndResetHitCount()
  168. //
  169. // Fetches and resets the hit count. Again, the actual value is
  170. // unimportant, so there is no interlocked operation.
  171. //
  172. DWORD DwGatherAndResetHitCount()
  173. {
  174. DWORD dwcHits = m_dwcHits;
  175. m_dwcHits = 0;
  176. return dwcHits;
  177. }
  178. };
  179. class IContentTypeMap;
  180. class ICustomErrorMap;
  181. class IScriptMap;
  182. class IMDData : public IRefCounted
  183. {
  184. // LFU data
  185. //
  186. LFUData m_lfudata;
  187. // NOT IMPLEMENTED
  188. //
  189. IMDData& operator=(const IMDData&);
  190. IMDData(const IMDData&);
  191. protected:
  192. // CREATORS
  193. // Only create this object through it's descendents!
  194. //
  195. IMDData() {}
  196. public:
  197. // CREATORS
  198. //
  199. virtual ~IMDData() {}
  200. // MANIPULATORS
  201. //
  202. LFUData& LFUData() { return m_lfudata; }
  203. // ACCESSORS
  204. //
  205. virtual LPCWSTR PwszMDPathDataSet() const = 0;
  206. virtual IContentTypeMap * GetContentTypeMap() const = 0;
  207. virtual const ICustomErrorMap * GetCustomErrorMap() const = 0;
  208. virtual const IScriptMap * GetScriptMap() const = 0;
  209. virtual LPCWSTR PwszDefaultDocList() const = 0;
  210. virtual LPCWSTR PwszVRUserName() const = 0;
  211. virtual LPCWSTR PwszVRPassword() const = 0;
  212. virtual LPCWSTR PwszExpires() const = 0;
  213. virtual LPCWSTR PwszBindings() const = 0;
  214. virtual LPCWSTR PwszVRPath() const = 0;
  215. virtual DWORD DwDirBrowsing() const = 0;
  216. virtual DWORD DwAccessPerms() const = 0;
  217. virtual BOOL FAuthorViaFrontPage() const = 0;
  218. virtual BOOL FHasIPRestriction() const = 0;
  219. virtual BOOL FSameIPRestriction(const IMDData* prhs) const = 0;
  220. virtual BOOL FHasApp() const = 0;
  221. virtual DWORD DwAuthorization() const = 0;
  222. virtual BOOL FIsIndexed() const = 0;
  223. virtual BOOL FSameStarScriptmapping(const IMDData* prhs) const = 0;
  224. //
  225. // Any new metadata accessor should be added here and
  226. // an implementation provided in \cal\src\_davprs\davmb.cpp.
  227. //
  228. };
  229. class IEcb;
  230. // ========================================================================
  231. //
  232. // CLASS CMDObjectHandle
  233. //
  234. // Encapsulates access to a metabase object through an open handle,
  235. // ensuring that the handle is always propery closed.
  236. //
  237. class CMDObjectHandle
  238. {
  239. enum { METADATA_TIMEOUT = 5000 };
  240. //
  241. // Reference to ECB for security switching
  242. //
  243. const IEcb& m_ecb;
  244. //
  245. // COM interface to the metabase
  246. //
  247. IMSAdminBase * m_pMSAdminBase;
  248. //
  249. // Raw metabase handle
  250. //
  251. METADATA_HANDLE m_hMDObject;
  252. //
  253. // The path for which the handle was opened
  254. //
  255. LPCWSTR m_pwszPath;
  256. // NOT IMPLEMENTED
  257. //
  258. CMDObjectHandle(const CMDObjectHandle&);
  259. CMDObjectHandle& operator=(CMDObjectHandle&);
  260. public:
  261. // CREATORS
  262. //
  263. CMDObjectHandle(const IEcb& ecb, IMSAdminBase * pMSAdminBase = NULL) :
  264. m_ecb(ecb),
  265. m_pMSAdminBase(pMSAdminBase),
  266. m_hMDObject(METADATA_MASTER_ROOT_HANDLE),
  267. m_pwszPath(NULL)
  268. {
  269. }
  270. ~CMDObjectHandle();
  271. // MANIPULATORS
  272. //
  273. HRESULT HrOpen( IMSAdminBase * pMSAdminBase,
  274. LPCWSTR pwszPath,
  275. DWORD dwAccess,
  276. DWORD dwMsecTimeout );
  277. HRESULT HrOpenLowestNode( IMSAdminBase * pMSAdminBase,
  278. LPWSTR pwszPath,
  279. DWORD dwAccess,
  280. LPWSTR * ppwszPath );
  281. HRESULT HrEnumKeys( LPCWSTR pwszPath,
  282. LPWSTR pwszChild,
  283. DWORD dwIndex ) const;
  284. HRESULT HrGetDataPaths( LPCWSTR pwszPath,
  285. DWORD dwPropID,
  286. DWORD dwDataType,
  287. LPWSTR pwszDataPaths,
  288. DWORD * pcchDataPaths ) const;
  289. HRESULT HrGetMetaData( LPCWSTR pwszPath,
  290. METADATA_RECORD * pmdrec,
  291. DWORD * pcbBufRequired ) const;
  292. HRESULT HrGetAllMetaData( LPCWSTR pwszPath,
  293. DWORD dwAttributes,
  294. DWORD dwUserType,
  295. DWORD dwDataType,
  296. DWORD * pdwcRecords,
  297. DWORD * pdwDataSet,
  298. DWORD cbBuf,
  299. LPBYTE pbBuf,
  300. DWORD * pcbBufRequired ) const;
  301. HRESULT HrSetMetaData( LPCWSTR pwszPath,
  302. const METADATA_RECORD * pmdrec ) const;
  303. HRESULT HrDeleteMetaData( LPCWSTR pwszPath,
  304. DWORD dwPropID,
  305. DWORD dwDataType ) const;
  306. VOID Close();
  307. };
  308. // Initialize the metabase
  309. //
  310. BOOL FMDInitialize();
  311. // Deinit the metabase
  312. //
  313. VOID MDDeinitialize();
  314. // Fetch the metadata for a specific URI.
  315. //
  316. // Note: If you need data for the request URI you
  317. // should use the MetaData() accessor on the IEcb
  318. // instead of this function.
  319. //
  320. HRESULT HrMDGetData( const IEcb& ecb,
  321. LPCWSTR pwszURI,
  322. IMDData ** ppMDData );
  323. // Fetch the metadata for a specific metabase path
  324. // which may not exist -- e.g. paths to objects
  325. // whose metadata is entirely inherited.
  326. //
  327. // When fetching metadata for a path that may not
  328. // exist pszMDPathOpen must be set to a path that
  329. // is known to exist and is a proper prefix of
  330. // the desired access path -- typically the path
  331. // to the vroot.
  332. //
  333. HRESULT HrMDGetData( const IEcb& ecb,
  334. LPCWSTR pwszMDPathAccess,
  335. LPCWSTR pwszMDPathOpen,
  336. IMDData ** ppMDData );
  337. // Get metabase change number
  338. //
  339. DWORD DwMDChangeNumber(const IEcb * pecb);
  340. // Open a metadata handle
  341. //
  342. HRESULT HrMDOpenMetaObject( LPCWSTR pwszMDPath,
  343. DWORD dwAccess,
  344. DWORD dwMsecTimeout,
  345. CMDObjectHandle * pmdoh );
  346. HRESULT HrMDOpenLowestNodeMetaObject( LPWSTR pwszMDPath,
  347. DWORD dwAccess,
  348. LPWSTR * ppwszMDPath,
  349. CMDObjectHandle * pmdoh );
  350. HRESULT
  351. HrMDIsAuthorViaFrontPageNeeded(const IEcb& ecb,
  352. LPCWSTR pwszURI,
  353. BOOL * pfFrontPageWeb);
  354. // ------------------------------------------------------------------------
  355. //
  356. // FParseMDData()
  357. //
  358. // Parses a comma-delimited metadata string into fields. Any whitespace
  359. // around the delimiters is considered insignificant and removed.
  360. //
  361. // Returns TRUE if the data parsed into the expected number of fields
  362. // and FALSE otherwise.
  363. //
  364. // Pointers to the parsed are returned in rgpszFields. If a string
  365. // parses into fewer than the expected number of fields, NULLs are
  366. // returned for all of the fields beyond the last one parsed.
  367. //
  368. // If a string parses into the expected number of fields then
  369. // the last field is always just the remainder of the string beyond
  370. // the second to last field, regardless whether the string could be
  371. // parsed into additional fields. For example " foo , bar , baz "
  372. // parses into three fields as "foo", "bar" and "baz", but parses
  373. // into two fields as "foo" and "bar , baz"
  374. //
  375. // The total number of characters in pszData, including the null
  376. // terminator, is also returned in *pcchzData.
  377. //
  378. // Note: this function MODIFIES pszData.
  379. //
  380. BOOL
  381. FParseMDData( LPWSTR pwszData,
  382. LPWSTR rgpwszFields[],
  383. UINT cFields,
  384. UINT * pcchData );
  385. // ------------------------------------------------------------------------
  386. //
  387. // FCopyStringToBuf()
  388. //
  389. // Copies a string (pszSource) to a buffer (pszBuf) if the size of the
  390. // buffer is large enough to hold the string. The size of the string is
  391. // returned in *pchBuf. A return value of TRUE indicates that the buffer
  392. // was large enough and string was successfully copied.
  393. //
  394. // This function is primarily intended for use in copying string return
  395. // values from IMDData accessors into buffers so that they can be used
  396. // after the IMDData object from which they were obtained is gone.
  397. //
  398. inline BOOL
  399. FCopyStringToBuf( LPCWSTR pwszSrc,
  400. LPWSTR pwszBuf,
  401. UINT * pcchBuf )
  402. {
  403. Assert( pwszSrc );
  404. Assert( pwszBuf );
  405. Assert( pcchBuf );
  406. UINT cchSrc = static_cast<UINT>(wcslen(pwszSrc) + 1);
  407. //
  408. // If the supplied buffer isn't big enough to copy the
  409. // string type into, then fill in the required size and
  410. // return an error.
  411. //
  412. if ( *pcchBuf < cchSrc )
  413. {
  414. *pcchBuf = cchSrc;
  415. return FALSE;
  416. }
  417. //
  418. // The buffer was large enough so copy the string.
  419. //
  420. memcpy( pwszBuf, pwszSrc, cchSrc * sizeof(WCHAR) );
  421. *pcchBuf = cchSrc;
  422. return TRUE;
  423. }
  424. // Metabase operations -------------------------------------------------------
  425. //
  426. // class CMetaOp -------------------------------------------------------------
  427. //
  428. class CMetaOp
  429. {
  430. // Enumeration of metabase nodes
  431. //
  432. enum { CCH_BUFFER_SIZE = 4096 };
  433. SCODE __fastcall ScEnumOp (LPWSTR pwszMetaPath, UINT cch);
  434. // non-implemented
  435. //
  436. CMetaOp& operator=(const CMetaOp&);
  437. CMetaOp(const CMetaOp&);
  438. protected:
  439. const IEcb * m_pecb;
  440. CMDObjectHandle m_mdoh;
  441. DWORD m_dwId;
  442. DWORD m_dwType;
  443. LPCWSTR m_pwszMetaPath;
  444. BOOL m_fWrite;
  445. // Subclass' operation to perform for each node where
  446. // a value is explicitly set.
  447. //
  448. virtual SCODE __fastcall ScOp(LPCWSTR pwszMbPath, UINT cch) = 0;
  449. public:
  450. virtual ~CMetaOp() {}
  451. CMetaOp ( const IEcb * pecb, LPCWSTR pwszPath, DWORD dwID, DWORD dwType, BOOL fWrite)
  452. : m_pecb(pecb),
  453. m_mdoh(*pecb),
  454. m_dwId(dwID),
  455. m_dwType(dwType),
  456. m_pwszMetaPath(pwszPath),
  457. m_fWrite(fWrite)
  458. {
  459. }
  460. // Interface use by MOVE/COPY, etc.
  461. //
  462. // NOTE: these operations do not go through the metabase cache
  463. // for a very specific reason -- the resource is either being
  464. // moved, copied or deleted. Just because an item was a part
  465. // of a large tree operation, does not mean it needs to be added
  466. // into the cache.
  467. //
  468. SCODE __fastcall ScMetaOp();
  469. };
  470. #endif // _DAVMB_H