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.

250 lines
5.8 KiB

  1. //***************************************************************************
  2. //
  3. // VPTASKSU.CPP
  4. //
  5. // Module: WBEM VIEW PROVIDER
  6. //
  7. // Purpose: Contains the union methods taskobject implementation
  8. //
  9. // Copyright (c) 1998-2001 Microsoft Corporation, All Rights Reserved
  10. //
  11. //***************************************************************************
  12. //need the following three lines
  13. //to get the security stuff to work
  14. #include "precomp.h"
  15. #include <provexpt.h>
  16. #include <provcoll.h>
  17. #include <provtempl.h>
  18. #include <provmt.h>
  19. #include <typeinfo.h>
  20. #include <process.h>
  21. #include <objbase.h>
  22. #include <objidl.h>
  23. #include <stdio.h>
  24. #include <wbemidl.h>
  25. #include <provcont.h>
  26. #include <provevt.h>
  27. #include <provthrd.h>
  28. #include <provlog.h>
  29. #include <cominit.h>
  30. #include <dsgetdc.h>
  31. #include <lmcons.h>
  32. #include <lmapibuf.h>
  33. #include <instpath.h>
  34. #include <genlex.h>
  35. #include <sql_1.h>
  36. #include <objpath.h>
  37. #include <vpdefs.h>
  38. #include <vpcfac.h>
  39. #include <vpquals.h>
  40. #include <vpserv.h>
  41. #include <vptasks.h>
  42. BOOL WbemTaskObject::CreateAndIndicateUnions(WbemProvErrorObject &a_ErrorObject, int index)
  43. {
  44. BOOL retVal = TRUE;
  45. if (index != -1)
  46. {
  47. retVal = CreateAndIndicate(a_ErrorObject, m_ObjSinkArray[index]);
  48. for (int x = 0; x < m_ObjSinkArray.GetSize(); x++)
  49. {
  50. if (m_ObjSinkArray[x] != NULL)
  51. {
  52. m_ObjSinkArray[x]->Release();
  53. }
  54. }
  55. }
  56. else
  57. {
  58. for (int x = 0; x < m_ObjSinkArray.GetSize(); x++)
  59. {
  60. if ((m_ObjSinkArray[x] != NULL) && SUCCEEDED(m_ObjSinkArray[x]->GetResult()))
  61. {
  62. BOOL t_bRes = CreateAndIndicate(a_ErrorObject, m_ObjSinkArray[x]);
  63. retVal = retVal && t_bRes;
  64. }
  65. else if (retVal)
  66. {
  67. retVal = FALSE;
  68. a_ErrorObject.SetStatus ( WBEM_PROV_E_UNEXPECTED ) ;
  69. if ( FAILED ( m_ObjSinkArray[x]->GetResult() ) )
  70. {
  71. a_ErrorObject.SetWbemStatus ( ( WBEMSTATUS ) m_ObjSinkArray[x]->GetResult() ) ;
  72. }
  73. else
  74. {
  75. a_ErrorObject.SetWbemStatus ( WBEM_E_FAILED ) ;
  76. }
  77. a_ErrorObject.SetMessage ( L"A source query failed." );
  78. }
  79. if (m_ObjSinkArray[x] != NULL)
  80. {
  81. m_ObjSinkArray[x]->Release();
  82. }
  83. }
  84. }
  85. m_ObjSinkArray.RemoveAll();
  86. return retVal;
  87. }
  88. //for unions and associations
  89. BOOL WbemTaskObject::CreateAndIndicate(WbemProvErrorObject &a_ErrorObject, CObjectSinkResults* pSrcs)
  90. {
  91. BOOL retVal = TRUE;
  92. for (int x = 0; x < pSrcs->m_ObjArray.GetSize(); x++)
  93. {
  94. BOOL bIndicate = TRUE;
  95. IWbemClassObject* srcObj = pSrcs->m_ObjArray[x]->GetWrappedObject();
  96. IWbemClassObject* viewObj = NULL;
  97. if ( SUCCEEDED(m_ClassObject->SpawnInstance(0, &viewObj)) )
  98. {
  99. POSITION propPos = m_PropertyMap.GetStartPosition();
  100. while ((propPos != NULL) && bIndicate)
  101. {
  102. CStringW propName;
  103. CPropertyQualifierItem* propProps;
  104. m_PropertyMap.GetNextAssoc(propPos, propName, propProps);
  105. VARIANT v;
  106. CIMTYPE c;
  107. if (propProps->m_SrcPropertyNames[pSrcs->GetIndex()].IsEmpty())
  108. {
  109. if (propProps->IsKey())
  110. {
  111. if (retVal)
  112. {
  113. retVal = FALSE;
  114. a_ErrorObject.SetStatus ( WBEM_PROV_E_UNEXPECTED ) ;
  115. a_ErrorObject.SetWbemStatus ( WBEM_E_FAILED ) ;
  116. a_ErrorObject.SetMessage ( L"Failed to set key value for union view instance." );
  117. }
  118. bIndicate = FALSE;
  119. }
  120. }
  121. else
  122. {
  123. if ( SUCCEEDED(srcObj->Get(propProps->m_SrcPropertyNames[pSrcs->GetIndex()], 0, &v, &c, NULL)) )
  124. {
  125. if (((v.vt == VT_NULL) || (v.vt == VT_EMPTY)) && propProps->IsKey())
  126. {
  127. if (retVal)
  128. {
  129. retVal = FALSE;
  130. }
  131. bIndicate = FALSE;
  132. }
  133. else
  134. {
  135. //transpose reference if necessary
  136. //=================================
  137. BOOL bPut = TRUE;
  138. if (m_bAssoc && (propProps->GetCimType() == CIM_REFERENCE))
  139. {
  140. VARIANT vTmp;
  141. DWORD dwNSIndx = pSrcs->m_ObjArray[x]->GetIndex();
  142. CWbemServerWrap** pSrvs = m_NSpaceArray[pSrcs->GetIndex()]->GetServerPtrs();
  143. if (TransposeReference(propProps, v, &vTmp, TRUE, &pSrvs[dwNSIndx]))
  144. {
  145. VariantClear(&v);
  146. VariantInit(&v);
  147. if (FAILED(VariantCopy(&v, &vTmp)))
  148. {
  149. throw Heap_Exception(Heap_Exception::HEAP_ERROR::E_ALLOCATION_ERROR);
  150. }
  151. }
  152. else
  153. {
  154. if (propProps->IsKey())
  155. {
  156. if (retVal)
  157. {
  158. retVal = FALSE;
  159. }
  160. bIndicate = FALSE;
  161. }
  162. bPut = FALSE;
  163. }
  164. VariantClear(&vTmp);
  165. }
  166. if (bPut && FAILED(viewObj->Put(propName, 0, &v, c)) )
  167. {
  168. if (retVal)
  169. {
  170. retVal = FALSE;
  171. a_ErrorObject.SetStatus ( WBEM_PROV_E_UNEXPECTED ) ;
  172. a_ErrorObject.SetWbemStatus ( WBEM_E_FAILED ) ;
  173. a_ErrorObject.SetMessage ( L"Failed to put property" );
  174. }
  175. if (propProps->IsKey())
  176. {
  177. bIndicate = FALSE;
  178. }
  179. }
  180. }
  181. VariantClear(&v);
  182. }
  183. else
  184. {
  185. if (retVal)
  186. {
  187. retVal = FALSE;
  188. a_ErrorObject.SetStatus ( WBEM_PROV_E_UNEXPECTED ) ;
  189. a_ErrorObject.SetWbemStatus ( WBEM_E_FAILED ) ;
  190. a_ErrorObject.SetMessage ( L"Failed to get property from Source." ) ;
  191. }
  192. }
  193. }
  194. }
  195. if (bIndicate && m_bIndicate)
  196. {
  197. m_NotificationHandler->Indicate(1, &viewObj);
  198. }
  199. viewObj->Release();
  200. }
  201. else
  202. {
  203. retVal = FALSE;
  204. a_ErrorObject.SetStatus ( WBEM_PROV_E_UNEXPECTED ) ;
  205. a_ErrorObject.SetWbemStatus ( WBEM_E_FAILED ) ;
  206. a_ErrorObject.SetMessage ( L"WBEM API FAILURE:- Failed to spawn an instance of the view class." ) ;
  207. break;
  208. }
  209. }
  210. return retVal;
  211. }