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.

149 lines
3.7 KiB

  1. /*++
  2. Copyright (C) 2000-2001 Microsoft Corporation
  3. Module Name:
  4. Abstract:
  5. History:
  6. --*/
  7. //***************************************************************************
  8. //
  9. // DYNASTY.H
  10. //
  11. // raymcc 24-Apr-00 Created
  12. //
  13. //***************************************************************************
  14. #include "precomp.h"
  15. #include <windows.h>
  16. #include <stdio.h>
  17. #include <wbemcore.h>
  18. CDynasty * CDynasty::Create(IWbemClassObject * pObj)
  19. {
  20. try
  21. {
  22. return new CDynasty(pObj);
  23. }
  24. catch(CX_Exception &)
  25. {
  26. return 0;
  27. }
  28. }
  29. //***************************************************************************
  30. //
  31. //***************************************************************************
  32. // ok
  33. CDynasty::CDynasty(IWbemClassObject* pClassObj)
  34. {
  35. m_wszClassName = 0;
  36. m_pClassObj = 0;
  37. m_bKeyed = 0;
  38. m_bDynamic = 0;
  39. m_bAbstract = 0;
  40. m_bAmendment = 0;
  41. m_wszKeyScope = 0;
  42. if (pClassObj)
  43. {
  44. // Get class name from the object
  45. CVar v;
  46. HRESULT hres = ((CWbemObject *) pClassObj)->GetClassName(&v);
  47. if (hres == WBEM_E_OUT_OF_MEMORY)
  48. throw CX_MemoryException();
  49. else if(FAILED(hres) || v.GetType() != VT_BSTR)
  50. {
  51. m_wszClassName = NULL;
  52. m_pClassObj = NULL;
  53. return;
  54. }
  55. size_t tmpLength = wcslen(v.GetLPWSTR())+1; // SEC:REVIEWED 2002-03-22 : unbounded
  56. m_wszClassName = new WCHAR[tmpLength];
  57. if (m_wszClassName == 0)
  58. {
  59. throw CX_MemoryException();
  60. }
  61. StringCchCopyW(m_wszClassName, tmpLength, v.GetLPWSTR());
  62. // from now on, no throw
  63. m_pClassObj = pClassObj;
  64. m_pClassObj->AddRef();
  65. // Get Dynamic and Keyed bits
  66. // ==========================
  67. m_bKeyed = ((CWbemClass *) m_pClassObj)->IsKeyed();
  68. m_bDynamic = ((CWbemClass*)m_pClassObj)->IsDynamic();
  69. m_bAbstract = ((CWbemClass*)m_pClassObj)->IsAbstract();
  70. m_bAmendment = ((CWbemClass*)m_pClassObj)->IsAmendment();
  71. }
  72. }
  73. //***************************************************************************
  74. //
  75. //***************************************************************************
  76. // ok
  77. CDynasty::~CDynasty()
  78. {
  79. delete m_wszClassName;
  80. if (m_pClassObj)
  81. m_pClassObj->Release();
  82. for (int i = 0; i < m_Children.Size(); i++)
  83. delete (CDynasty *) m_Children.GetAt(i);
  84. if (m_wszKeyScope)
  85. delete m_wszKeyScope;
  86. }
  87. //***************************************************************************
  88. //
  89. //***************************************************************************
  90. // ok
  91. void CDynasty::AddChild(CDynasty* pChild)
  92. {
  93. if (m_Children.Add(pChild) == CFlexArray::out_of_memory)
  94. throw CX_MemoryException();
  95. }
  96. //***************************************************************************
  97. //
  98. //***************************************************************************
  99. // ok
  100. void CDynasty::SetKeyScope(LPCWSTR wszKeyScope)
  101. {
  102. // If no key scope is provided and we are keyed, we are it.
  103. // ========================================================
  104. if (wszKeyScope == NULL && m_bKeyed)
  105. {
  106. wszKeyScope = m_wszClassName; // aliasing!
  107. }
  108. size_t tmpLength = wcslen(wszKeyScope)+1; // SEC:REVIEWED 2002-03-22 : unbounded
  109. m_wszKeyScope = new WCHAR[tmpLength];
  110. if (m_wszKeyScope == 0)
  111. throw CX_MemoryException();
  112. StringCchCopyW(m_wszKeyScope, tmpLength, wszKeyScope);
  113. for (int i = 0; i < m_Children.Size(); i++)
  114. ((CDynasty *) m_Children.GetAt(i))->SetKeyScope(wszKeyScope);
  115. }