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.

211 lines
5.2 KiB

  1. /*
  2. * V R E N U M . H
  3. *
  4. * Vritual root enumeration
  5. *
  6. * Copyright 1986-1997 Microsoft Corporation, All Rights Reserved
  7. */
  8. #ifndef _VRENUM_H_
  9. #define _VRENUM_H_
  10. #include <winsock2.h>
  11. #include <crc.h>
  12. #include <autoptr.h>
  13. #include <buffer.h>
  14. #include <davmb.h>
  15. #include <gencache.h>
  16. #include <cvroot.h>
  17. #include <davimpl.h>
  18. #include <singlton.h>
  19. // CChildVRCache ---------------------------------------------------------------
  20. //
  21. typedef CCache<CRCWsz, auto_ref_ptr<CVRoot> > CVRCache;
  22. class CChildVRCache : public CAccInv,
  23. private Singleton<CChildVRCache>
  24. {
  25. // Friend declarations required by Singleton template
  26. //
  27. friend class Singleton<CChildVRCache>;
  28. // Cache
  29. //
  30. CVRCache m_cache;
  31. ChainedStringBuffer<WCHAR> m_sb;
  32. // Server default values
  33. //
  34. enum { MAX_SERVER_NAME_LENGTH = 64 };
  35. WCHAR m_wszServerDefault[MAX_SERVER_NAME_LENGTH];
  36. UINT m_cchServerDefault;
  37. // CAccInv access/modification methods
  38. //
  39. void RefreshOp(const IEcb& ecb);
  40. // CFindChildren ---------------------------------------------------------
  41. //
  42. // Functional classes to find all applicible child vroots
  43. //
  44. class CFindChildren : public CVRCache::IOp, public CAccInv::IAccCtx
  45. {
  46. CVRCache& m_cache; // Cache
  47. ChainedStringBuffer<WCHAR>& m_sb; // Return set of child
  48. CVRList& m_vrl; // virtual roots
  49. LPCWSTR m_pwsz; // Metadata path to find
  50. UINT m_cch; // children for
  51. // NOT IMPLEMENTED
  52. //
  53. CFindChildren& operator=(const CFindChildren&);
  54. CFindChildren(const CFindChildren&);
  55. public:
  56. CFindChildren(CVRCache& cache,
  57. LPCWSTR pwszMetaPath,
  58. ChainedStringBuffer<WCHAR>& sb,
  59. CVRList& vrl)
  60. : m_cache(cache),
  61. m_sb(sb),
  62. m_vrl(vrl),
  63. m_pwsz(pwszMetaPath),
  64. m_cch(static_cast<UINT>(wcslen(pwszMetaPath)))
  65. {
  66. }
  67. virtual BOOL operator()(const CRCWsz&, const auto_ref_ptr<CVRoot>&);
  68. virtual void AccessOp (CAccInv& cache)
  69. {
  70. m_cache.ForEach(*this);
  71. }
  72. BOOL FFound() const { return !m_vrl.empty(); }
  73. };
  74. // CLookupChild ----------------------------------------------------------
  75. //
  76. // Functional classes to find a given child vroot
  77. //
  78. class CLookupChild : public CAccInv::IAccCtx
  79. {
  80. CVRCache& m_cache; // Cache
  81. LPCWSTR m_pwsz; // Metadata path to lookup
  82. auto_ref_ptr<CVRoot>& m_cvr; // CVRoot for path
  83. // NOT IMPLEMENTED
  84. //
  85. CLookupChild& operator=(const CLookupChild&);
  86. CLookupChild(const CLookupChild&);
  87. public:
  88. CLookupChild(CVRCache& cache,
  89. LPCWSTR pwszMetaPath,
  90. auto_ref_ptr<CVRoot>& cvr)
  91. : m_cache(cache),
  92. m_pwsz(pwszMetaPath),
  93. m_cvr(cvr)
  94. {
  95. }
  96. virtual void AccessOp (CAccInv& cache)
  97. {
  98. m_cache.FFetch(CRCWsz(m_pwsz), &m_cvr);
  99. }
  100. BOOL FFound() const { return m_cvr.get() != NULL; }
  101. };
  102. // NOT IMPLEMENTED
  103. //
  104. CChildVRCache& operator=(const CChildVRCache&);
  105. CChildVRCache(const CChildVRCache&);
  106. // Cache construction
  107. //
  108. SCODE ScCacheVroots (const IEcb& ecb);
  109. // CONSTRUCTOR
  110. //
  111. // Declared private to ensure that arbitrary instances
  112. // of this class cannot be created. The Singleton template
  113. // (declared as a friend above) controls the sole instance
  114. // of this class.
  115. //
  116. CChildVRCache()
  117. {
  118. CHAR rgchServerDefault[MAX_SERVER_NAME_LENGTH] = {0};
  119. UINT cbServerDefault;
  120. // Call the WinSock api to learn our default host name
  121. //
  122. gethostname (rgchServerDefault, sizeof(rgchServerDefault));
  123. cbServerDefault = static_cast<UINT>(strlen(rgchServerDefault));
  124. // It actually does not mater what codepage we will
  125. // select for conversion. Server names are not allowed
  126. // to contain funky characters.
  127. //
  128. m_cchServerDefault = MultiByteToWideChar(CP_ACP,
  129. 0,
  130. rgchServerDefault,
  131. cbServerDefault + 1,
  132. m_wszServerDefault,
  133. MAX_SERVER_NAME_LENGTH);
  134. // There is no reason to fail and we would be converting at least
  135. // termination character
  136. //
  137. Assert(1 <= m_cchServerDefault);
  138. m_cchServerDefault--;
  139. DebugTrace ("Dav: CVRoot: gethostname(): '%S'\n", m_wszServerDefault);
  140. // If this fails, our allocators will throw for us.
  141. //
  142. (void) m_cache.FInit();
  143. }
  144. public:
  145. // Instance creating/destroying routines provided
  146. // by the Singleton template.
  147. //
  148. using Singleton<CChildVRCache>::CreateInstance;
  149. using Singleton<CChildVRCache>::DestroyInstance;
  150. using Singleton<CChildVRCache>::Instance;
  151. // Metabase notification methods
  152. //
  153. void OnNotify( DWORD dwElements,
  154. MD_CHANGE_OBJECT_W pcoList[] );
  155. // Access ----------------------------------------------------------------
  156. //
  157. static BOOL FFindVroot( const IEcb& ecb, LPCWSTR pwszMetaPath, auto_ref_ptr<CVRoot>& cvr )
  158. {
  159. CLookupChild clc(Instance().m_cache, pwszMetaPath, cvr);
  160. Instance().Access(ecb, clc);
  161. return clc.FFound();
  162. }
  163. static SCODE ScFindChildren( const IEcb& ecb,
  164. LPCWSTR pwszMetaPath,
  165. ChainedStringBuffer<WCHAR>& sb,
  166. CVRList& vrl )
  167. {
  168. CFindChildren cfc(Instance().m_cache, pwszMetaPath, sb, vrl);
  169. Instance().Access(ecb, cfc);
  170. return cfc.FFound() ? S_FALSE : S_OK;
  171. }
  172. };
  173. #endif // _VRENUM_H_