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.

164 lines
4.3 KiB

  1. /*++
  2. Copyright (c) 2000-2001 Microsoft Corporation
  3. Module Name:
  4. AssocSameLevel.cpp
  5. Abstract:
  6. Implementation of:
  7. CAssocSameLevel
  8. Author:
  9. Mohit Srivastava 22-Mar-2001
  10. Revision History:
  11. --*/
  12. extern "C" {
  13. #include <nt.h>
  14. #include <ntrtl.h>
  15. #include <nturtl.h>
  16. }
  17. #include <mdmsg.h>
  18. #include <dbgutil.h>
  19. #include "AssocSameLevel.h"
  20. #include "utils.h"
  21. #include "instancehelper.h"
  22. #include "metabase.h"
  23. #include "SmartPointer.h"
  24. CAssocSameLevel::CAssocSameLevel(
  25. CWbemServices* i_pNamespace,
  26. IWbemObjectSink* i_pResponseHandler,
  27. WMI_ASSOCIATION* i_pWmiAssoc) :
  28. CAssocBase(i_pNamespace, i_pResponseHandler, i_pWmiAssoc)
  29. {
  30. }
  31. void CAssocSameLevel::GetInstances(
  32. SQL_LEVEL_1_RPN_EXPRESSION_EXT* i_pExp) //defaultvalue(NULL)
  33. {
  34. DBG_ASSERT(i_pExp);
  35. SQL_LEVEL_1_TOKEN* pTokenLeft = NULL; // left part of assoc
  36. SQL_LEVEL_1_TOKEN* pTokenRight = NULL; // right part of assoc
  37. //
  38. // Walk thru tokens
  39. // Don't do query if we find OR or NOT
  40. // Record match for left and/or right part of association.
  41. //
  42. bool bDoQuery = true;
  43. ProcessQuery(
  44. i_pExp,
  45. m_pWmiAssoc,
  46. &pTokenLeft,
  47. &pTokenRight,
  48. &bDoQuery);
  49. if( !bDoQuery || (pTokenLeft == NULL && pTokenRight == NULL) )
  50. {
  51. GetAllInstances(
  52. m_pWmiAssoc);
  53. return;
  54. }
  55. //
  56. // We need to get just a single association instance. If we were provided
  57. // at least a left or a right part, we have enough information.
  58. //
  59. DBG_ASSERT(pTokenLeft != NULL || pTokenRight != NULL);
  60. VARIANT vtLeft;
  61. VARIANT vtRight;
  62. VariantInit(&vtLeft);
  63. VariantInit(&vtRight);
  64. CComBSTR sbstr;
  65. if(pTokenLeft && pTokenRight)
  66. {
  67. vtLeft.vt = VT_BSTR;
  68. vtLeft.bstrVal = pTokenLeft->vConstValue.bstrVal;
  69. vtRight.vt = VT_BSTR;
  70. vtRight.bstrVal = pTokenRight->vConstValue.bstrVal;
  71. }
  72. else
  73. {
  74. //
  75. // An association contains two object paths. We are going to construct
  76. // the missing one by simply replacing the class.
  77. //
  78. // Eg. IIsWebServer='w3svc/1' => IIsWebServerSetting='w3svc/1'
  79. //
  80. CObjectPathParser PathParser(e_ParserAcceptRelativeNamespace);
  81. SQL_LEVEL_1_TOKEN* pTokenCur = (pTokenLeft) ? pTokenLeft : pTokenRight;
  82. WMI_CLASS* pWmiClass =
  83. (pTokenLeft) ? m_pWmiAssoc->pcLeft : m_pWmiAssoc->pcRight;
  84. WMI_CLASS* pWmiClassOpposite =
  85. (pTokenLeft) ? m_pWmiAssoc->pcRight : m_pWmiAssoc->pcLeft;
  86. TSmartPointer<ParsedObjectPath> spParsedObject;
  87. if (PathParser.Parse(pTokenCur->vConstValue.bstrVal, &spParsedObject)
  88. != CObjectPathParser::NoError)
  89. {
  90. THROW_ON_ERROR(WBEM_E_INVALID_QUERY);
  91. }
  92. KeyRef* pkr = CUtils::GetKey(spParsedObject, pWmiClass->pszKeyName);
  93. if( !LookupKeytypeInMb(pkr->m_vValue.bstrVal, pWmiClass) &&
  94. !LookupKeytypeInMb(pkr->m_vValue.bstrVal, pWmiClassOpposite) )
  95. {
  96. //
  97. // One of the two classes in the assoc must be an element.
  98. //
  99. return;
  100. }
  101. if(!spParsedObject->SetClassName(pWmiClassOpposite->pszClassName))
  102. {
  103. THROW_ON_ERROR(WBEM_E_FAILED);
  104. }
  105. LPWSTR wszUnparsed = NULL;
  106. if (PathParser.Unparse(spParsedObject, &wszUnparsed)
  107. != CObjectPathParser::NoError)
  108. {
  109. THROW_ON_ERROR(WBEM_E_FAILED);
  110. }
  111. sbstr = wszUnparsed;
  112. delete [] wszUnparsed;
  113. wszUnparsed = NULL;
  114. if(sbstr.m_str == NULL)
  115. {
  116. THROW_ON_ERROR(WBEM_E_OUT_OF_MEMORY);
  117. }
  118. if(pTokenLeft)
  119. {
  120. vtLeft.vt = VT_BSTR;
  121. vtLeft.bstrVal = pTokenLeft->vConstValue.bstrVal;
  122. vtRight.vt = VT_BSTR;
  123. vtRight.bstrVal = sbstr;
  124. }
  125. else
  126. {
  127. vtRight.vt = VT_BSTR;
  128. vtRight.bstrVal = pTokenRight->vConstValue.bstrVal;
  129. vtLeft.vt = VT_BSTR;
  130. vtLeft.bstrVal = sbstr;
  131. }
  132. }
  133. Indicate(
  134. vtLeft.bstrVal,
  135. vtRight.bstrVal);
  136. }