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.

163 lines
3.6 KiB

  1. /******************************************************************************
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. WMIParser_Value.cpp
  5. Abstract:
  6. This file contains the implementation of the WMIParser::Value class,
  7. which is used to hold the data of an value inside a CIM schema.
  8. Revision History:
  9. Davide Massarenti (Dmassare) 07/01/99
  10. created
  11. ******************************************************************************/
  12. #include "stdafx.h"
  13. WMIParser::Value::Value()
  14. {
  15. __HCP_FUNC_ENTRY( "WMIParser::Value::Value" );
  16. m_lData = 0; // long m_lData;
  17. m_rgData = NULL; // BYTE* m_rgData;
  18. // MPC::wstring m_szData;
  19. }
  20. WMIParser::Value::~Value()
  21. {
  22. __HCP_FUNC_ENTRY( "WMIParser::Value::~Value" );
  23. if(m_rgData)
  24. {
  25. delete [] m_rgData;
  26. m_rgData = NULL;
  27. }
  28. }
  29. ////////////////////////////////////////////////
  30. bool WMIParser::Value::operator==( /*[in]*/ Value const &wmipv ) const
  31. {
  32. __HCP_FUNC_ENTRY( "WMIParser::Value::operator==" );
  33. bool fRes = true;
  34. MPC::NocaseCompare cmp;
  35. bool leftBinary = ( m_rgData != NULL);
  36. bool rightBinary = (wmipv.m_rgData != NULL);
  37. if(leftBinary != rightBinary)
  38. {
  39. fRes = false; // Different kind of data, not comparable.
  40. }
  41. else
  42. {
  43. if(leftBinary)
  44. {
  45. // Binary Data, do byte-to-byte comparison.
  46. if( m_lData != wmipv.m_lData ) fRes = false;
  47. if(::memcmp( m_rgData , wmipv.m_rgData, m_lData )) fRes = false;
  48. }
  49. else
  50. {
  51. // Text Data, do string comparison.
  52. if(m_szData != wmipv.m_szData) fRes = false;
  53. }
  54. }
  55. __HCP_FUNC_EXIT(fRes);
  56. }
  57. ////////////////////////////////////////////////
  58. HRESULT WMIParser::Value::Parse( /*[in] */ IXMLDOMNode* pxdnNode ,
  59. /*[in]*/ LPCWSTR szTag )
  60. {
  61. __HCP_FUNC_ENTRY( "WMIParser::Value::Parse" );
  62. HRESULT hr;
  63. MPC::XmlUtil xmlNode( pxdnNode );
  64. CComVariant vValue;
  65. bool fFound;
  66. __MPC_PARAMCHECK_BEGIN(hr)
  67. __MPC_PARAMCHECK_NOTNULL(pxdnNode);
  68. __MPC_PARAMCHECK_END();
  69. //
  70. // Analize the node...
  71. //
  72. __MPC_EXIT_IF_METHOD_FAILS(hr, xmlNode.GetValue( szTag, vValue, fFound ));
  73. if(fFound)
  74. {
  75. if(vValue.vt == VT_BSTR)
  76. {
  77. m_szData = OLE2W( vValue.bstrVal );
  78. }
  79. else if(SUCCEEDED(vValue.ChangeType( VT_ARRAY | VT_UI1 )))
  80. {
  81. long lLBound;
  82. long lUBound;
  83. BYTE* rgData;
  84. __MPC_EXIT_IF_METHOD_FAILS(hr, SafeArrayGetLBound( vValue.parray, 1, &lLBound ));
  85. __MPC_EXIT_IF_METHOD_FAILS(hr, SafeArrayGetUBound( vValue.parray, 1, &lUBound ));
  86. m_lData = lUBound - lLBound + 1;
  87. __MPC_EXIT_IF_ALLOC_FAILS(hr, m_rgData, new BYTE[m_lData]);
  88. __MPC_EXIT_IF_METHOD_FAILS(hr, SafeArrayAccessData( vValue.parray, (void **)&rgData ));
  89. CopyMemory( m_rgData, rgData, m_lData );
  90. __MPC_EXIT_IF_METHOD_FAILS(hr, SafeArrayUnaccessData( vValue.parray ));
  91. }
  92. }
  93. hr = S_OK;
  94. __HCP_FUNC_CLEANUP;
  95. __HCP_FUNC_EXIT(hr);
  96. }
  97. ////////////////////////////////////////////////
  98. HRESULT WMIParser::Value::get_Data( /*[out]*/ long& lData ,
  99. /*[out]*/ BYTE*& rgData )
  100. {
  101. __HCP_FUNC_ENTRY( "WMIParser::Value::get_Data" );
  102. HRESULT hr;
  103. lData = m_lData;
  104. rgData = m_rgData;
  105. hr = S_OK;
  106. __HCP_FUNC_EXIT(hr);
  107. }
  108. HRESULT WMIParser::Value::get_Data( /*[out]*/ MPC::wstring& szData )
  109. {
  110. __HCP_FUNC_ENTRY( "WMIParser::Value::get_Data" );
  111. HRESULT hr;
  112. szData = m_szData;
  113. hr = S_OK;
  114. __HCP_FUNC_EXIT(hr);
  115. }