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.

168 lines
5.0 KiB

  1. #ifndef __UTIL_H__
  2. #define __UTIL_H__
  3. #include "resource.h"
  4. extern INT g_iDebugOutputLevel;
  5. void DumpFriendlyName(CIISObject * pObj);
  6. HRESULT DumpAllScopeItems(CComPtr<IConsoleNameSpace> pConsoleNameSpace, IN HSCOPEITEM hParent, IN int iTreeLevel);
  7. HRESULT DumpAllResultItems(IResultData * pResultData);
  8. HRESULT IsValidDomainUser(LPCTSTR szDomainUser,LPTSTR szFullName,DWORD cch);
  9. BOOL IsLocalHost(LPCTSTR szHostName,BOOL* pbIsHost);
  10. #if defined(_DEBUG) || DBG
  11. #define DEBUG_PREPEND_STRING _T("---")
  12. typedef CMap< DWORD_PTR, DWORD_PTR, CString, LPCTSTR> CMyMapPointerToString;
  13. class CDebug_IISObject
  14. {
  15. public:
  16. CDebug_IISObject()
  17. {
  18. m_strClassName = _T("CDebug_IISObject");
  19. };
  20. ~CDebug_IISObject(){};
  21. public:
  22. CString m_strClassName;
  23. void Init()
  24. {
  25. DebugList_IISObject.RemoveAll();
  26. DebugList_PointersToFriendly.RemoveAll();
  27. }
  28. void Add(CIISObject * pItem)
  29. {
  30. if (g_iDebugOutputLevel & DEBUG_FLAG_CIISOBJECT)
  31. {
  32. DebugTrace(_T("%s%s>:Add:[%3d] %p\r\n"),m_strClassName,DEBUG_PREPEND_STRING,DebugList_IISObject.GetCount(),pItem);
  33. }
  34. DebugList_IISObject.AddTail(pItem);
  35. }
  36. void Del(CIISObject * pItem)
  37. {
  38. INT_PTR iCount = DebugList_IISObject.GetCount();
  39. iCount--;
  40. CString strDescription;
  41. // See if we can find this pointer in our list of pointers to friendlynames..
  42. DWORD_PTR dwPtr = (DWORD_PTR) pItem;
  43. DebugList_PointersToFriendly.Lookup(dwPtr,strDescription);
  44. POSITION pos = DebugList_IISObject.Find(pItem);
  45. if (pos)
  46. {
  47. DebugList_IISObject.RemoveAt(pos);
  48. if (g_iDebugOutputLevel & DEBUG_FLAG_CIISOBJECT)
  49. {
  50. DebugTrace(_T("%s<%s:Del:[%3d] %p (%s)\r\n"),m_strClassName,DEBUG_PREPEND_STRING,iCount,pItem,strDescription);
  51. }
  52. }
  53. else
  54. {
  55. if (g_iDebugOutputLevel & DEBUG_FLAG_CIISOBJECT)
  56. {
  57. DebugTrace(_T("%s<%s:Del:[%3d] %p (%s) (not found)\r\n"),m_strClassName,DEBUG_PREPEND_STRING,iCount,pItem,strDescription);
  58. }
  59. }
  60. }
  61. void Dump(INT iVerboseLevel)
  62. {
  63. int iCount = 0;
  64. int iUseCount = 0;
  65. BOOL bPropertySheetOpen = FALSE;
  66. CString strGUIDName;
  67. CString strBigString;
  68. GUID * MyGUID = NULL;
  69. CIISObject * pItemFromList = NULL;
  70. if (!(g_iDebugOutputLevel & DEBUG_FLAG_CIISOBJECT))
  71. {
  72. return;
  73. }
  74. if (iVerboseLevel)
  75. {
  76. DebugTrace(_T("%s%s:Dump: -------------- start (count=%d)\r\n"),m_strClassName,DEBUG_PREPEND_STRING,DebugList_IISObject.GetCount());
  77. }
  78. POSITION pos = DebugList_IISObject.GetHeadPosition();
  79. while (pos)
  80. {
  81. pItemFromList = DebugList_IISObject.GetNext(pos);
  82. if (pItemFromList)
  83. {
  84. iCount++;
  85. // Get GUID Name
  86. MyGUID = (GUID*) pItemFromList->GetNodeType();
  87. if (MyGUID)
  88. {
  89. GetFriendlyGuidName(*MyGUID,strGUIDName);
  90. }
  91. // Get ref count
  92. iUseCount = pItemFromList->UseCount();
  93. // Get Propertysheet open flag
  94. bPropertySheetOpen = FALSE;
  95. if (pItemFromList->IsMyPropertySheetOpen())
  96. {
  97. bPropertySheetOpen = TRUE;
  98. }
  99. // Get FriendlyName
  100. LPOLESTR pTempFriendly = pItemFromList->QueryDisplayName();
  101. if (0 == iVerboseLevel)
  102. {
  103. // Just update the display info
  104. } else if (1 == iVerboseLevel)
  105. {
  106. DebugTrace(_T("%s%s:Dump:[%3d][%3d]%s %p (%s)\r\n"),m_strClassName,DEBUG_PREPEND_STRING,iCount,iUseCount,bPropertySheetOpen ? _T("P") : _T("."),pItemFromList,
  107. strGUIDName);
  108. }
  109. else if (2 >= iVerboseLevel)
  110. {
  111. DebugTrace(_T("%s%s:Dump:[%3d][%3d]%s %p (%s) '%s'\r\n"),m_strClassName,DEBUG_PREPEND_STRING,iCount,iUseCount,bPropertySheetOpen ? _T("P") : _T("."),pItemFromList,
  112. strGUIDName,
  113. pTempFriendly);
  114. }
  115. else
  116. {
  117. DebugTrace(_T("%s%s:Dump:[%3d][%3d]%s %p\r\n"),m_strClassName,DEBUG_PREPEND_STRING,iCount,iUseCount,bPropertySheetOpen ? _T("P") : _T("."),pItemFromList);
  118. }
  119. DWORD_PTR dwPtr = (DWORD_PTR) pItemFromList;
  120. strBigString = strGUIDName;
  121. if (pTempFriendly)
  122. {
  123. strBigString += _T(" '");
  124. strBigString += pTempFriendly;
  125. strBigString += _T("'");
  126. }
  127. DebugList_PointersToFriendly.SetAt(dwPtr,strGUIDName);
  128. }
  129. }
  130. if (iVerboseLevel)
  131. {
  132. DebugTrace(_T("%s%s:Dump: -------------- end\r\n"),m_strClassName,DEBUG_PREPEND_STRING);
  133. }
  134. }
  135. void Dump()
  136. {
  137. Dump(2);
  138. }
  139. private:
  140. CIISObjectList DebugList_IISObject;
  141. CMyMapPointerToString DebugList_PointersToFriendly;
  142. };
  143. #endif // DEBUG
  144. #endif // __UTIL_H__