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.

170 lines
4.7 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 2000
  6. //
  7. // File: nopin.h
  8. //
  9. //--------------------------------------------------------------------------
  10. #ifndef __CSCUI_NOPIN_H
  11. #define __CSCUI_NOPIN_H
  12. const HRESULT NOPIN_E_BADPATH = HRESULT_FROM_WIN32(ERROR_BAD_PATHNAME);
  13. //
  14. // This class contains a tree of nodes, each node representing a file or
  15. // directory. The tree structure mirrors the directory/file structure
  16. // being represented. Each leaf node in the tree specifies a particular file
  17. // or directory for which pinning is disallowed. The tree is initialized
  18. // from the registry using the Initialize() method. Once initialized,
  19. // the tree is queried using the IsPinAllowed() method. This method
  20. // searches the tree given a particular UNC path. If a matching
  21. // traversal ending in a leaf node is found, pinning of that path is
  22. // not allowed.
  23. //
  24. // Since this code is to be used by the Offline Files context menu
  25. // handler, speed is critical. The tree structure was chosen for
  26. // it's fast lookup characteristics for filesystem paths.
  27. //
  28. class CNoPinList
  29. {
  30. public:
  31. CNoPinList(void);
  32. ~CNoPinList(void);
  33. //
  34. // Determines if pinning of a particular path is allowed.
  35. // S_OK == Pinning is allowed.
  36. // S_FALSE == Pinning is not allowed.
  37. //
  38. HRESULT IsPinAllowed(LPCTSTR pszPath);
  39. //
  40. // Determines if there is any pin that would be disallowed.
  41. // Basically, is the tree not empty?
  42. //
  43. HRESULT IsAnyPinDisallowed(void);
  44. #if DBG
  45. //
  46. // Dump tree contents to debugger.
  47. //
  48. void Dump(void);
  49. #endif
  50. private:
  51. //
  52. // Prevent copy.
  53. //
  54. CNoPinList(const CNoPinList& rhs); // not implemented.
  55. CNoPinList& operator = (const CNoPinList& rhs); // not implemented.
  56. #if DBG
  57. //
  58. // This "inspector" class is a trivial thing to allow us to
  59. // see inside a CNode object for debugging purposes. It is a friend
  60. // of CNode. This lets us keep the CNode private information private
  61. // for all bug debugging purposes. See the method CNoPinList::DumpNode
  62. // for it's usage.
  63. //
  64. class CNode; // fwd decl
  65. class CNodeInspector
  66. {
  67. public:
  68. CNodeInspector(const CNode *pNode)
  69. : m_pNode(pNode) { }
  70. LPCTSTR NodeName(void) const
  71. { return m_pNode->m_pszName; }
  72. const CNode *ChildList(void) const
  73. { return m_pNode->m_pChildren; }
  74. const CNode *NextSibling(void) const
  75. { return m_pNode->m_pNext; }
  76. private:
  77. const CNode *m_pNode;
  78. };
  79. #endif
  80. //
  81. // A node in the tree.
  82. //
  83. class CNode
  84. {
  85. public:
  86. CNode(void);
  87. ~CNode(void);
  88. HRESULT Initialize(LPCTSTR pszName);
  89. HRESULT AddPath(LPTSTR pszPath);
  90. HRESULT SubPathExists(LPTSTR pszPath) const;
  91. bool HasChildren(void) const
  92. { return NULL != m_pChildren; }
  93. private:
  94. LPTSTR m_pszName; // Node's name
  95. CNode *m_pChildren; // List of children. NULL for leaf nodes.
  96. CNode *m_pNext; // Next in list of siblings
  97. //
  98. // Prevent copy.
  99. //
  100. CNode(const CNode& rhs); // Not implemented.
  101. CNode& operator = (const CNode& rhs); // Not implemented.
  102. CNode *_FindChild(LPCTSTR pszName) const;
  103. void _AddChild(CNode *pChild);
  104. static LPCTSTR _FindNextPathComponent(LPCTSTR pszPath, int *pcchComponent);
  105. static void _SwapChars(LPTSTR pszA, LPTSTR pszB);
  106. #if DBG
  107. friend class CNodeInspector;
  108. #endif
  109. };
  110. CNode *m_pRoot; // The root of the tree.
  111. HRESULT _Initialize(void);
  112. HRESULT _InitPathFromRegistry(LPCTSTR pszPath);
  113. HRESULT _AddPath(LPCTSTR pszPath);
  114. #if DBG
  115. void _DumpNode(const CNode *pNode, int iIndent);
  116. #endif
  117. };
  118. inline
  119. CNoPinList::CNode::CNode(
  120. void
  121. ) : m_pszName(NULL),
  122. m_pChildren(NULL),
  123. m_pNext(NULL)
  124. {
  125. }
  126. inline void
  127. CNoPinList::CNode::_SwapChars(
  128. LPTSTR pszA,
  129. LPTSTR pszB
  130. )
  131. {
  132. const TCHAR chTemp = *pszA;
  133. *pszA = *pszB;
  134. *pszB = chTemp;
  135. }
  136. #endif // __CSCUI_NOPIN_H