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.

315 lines
5.1 KiB

  1. // ActionData.cpp : Implementation of CSsrActionData
  2. #include "stdafx.h"
  3. #include "SSRTE.h"
  4. #include "ActionData.h"
  5. #include "SSRMembership.h"
  6. #include "MemberAccess.h"
  7. #include "global.h"
  8. #include "util.h"
  9. //---------------------------------------------------------------------
  10. // CSsrActionData implementation
  11. //---------------------------------------------------------------------
  12. /*
  13. Routine Description:
  14. Name:
  15. CSsrActionData::CSsrActionData
  16. Functionality:
  17. constructor
  18. Virtual:
  19. no.
  20. Arguments:
  21. none.
  22. Return Value:
  23. none.
  24. Notes:
  25. */
  26. CSsrActionData::CSsrActionData()
  27. : m_pSsrMembership(NULL)
  28. {
  29. }
  30. /*
  31. Routine Description:
  32. Name:
  33. CSsrActionData::~CSsrActionData
  34. Functionality:
  35. destructor
  36. Virtual:
  37. yes.
  38. Arguments:
  39. none.
  40. Return Value:
  41. none.
  42. Notes:
  43. */
  44. CSsrActionData::~CSsrActionData()
  45. {
  46. Reset();
  47. }
  48. /*
  49. Routine Description:
  50. Name:
  51. CSsrActionData::GetProperty
  52. Functionality:
  53. Get the named property
  54. Virtual:
  55. yes.
  56. Arguments:
  57. bstrPropName - The name of the property.
  58. pvarProperty - The output parameter that receives the new property value
  59. Return Value:
  60. S_OK if it succeeded. Otherwise, it returns various error codes.
  61. Notes:
  62. */
  63. STDMETHODIMP
  64. CSsrActionData::GetProperty (
  65. IN BSTR bstrPropName,
  66. OUT VARIANT * pvarProperty //[out, retval]
  67. )
  68. {
  69. if (pvarProperty == NULL)
  70. {
  71. return E_INVALIDARG;
  72. }
  73. ::VariantInit(pvarProperty);
  74. if (bstrPropName == NULL || *bstrPropName == L'\0')
  75. {
  76. return E_INVALIDARG;
  77. }
  78. HRESULT hr = S_OK;
  79. //
  80. // See if the runtime property bag contains that property
  81. //
  82. MapNameValue::iterator it = m_mapRuntimeAD.find(bstrPropName);
  83. MapNameValue::iterator itEnd = m_mapRuntimeAD.end();
  84. if (it != itEnd)
  85. {
  86. VARIANT * pValOld = (*it).second;
  87. hr = ::VariantCopy(pvarProperty, pValOld);
  88. }
  89. else
  90. {
  91. hr = W_SSR_PROPERTY_NOT_FOUND;
  92. }
  93. return hr;
  94. }
  95. /*
  96. Routine Description:
  97. Name:
  98. CSsrActionData::SetProperty
  99. Functionality:
  100. Set the named property
  101. Virtual:
  102. yes.
  103. Arguments:
  104. bstrPropName - The name of the property.
  105. varProperty - The property's value.
  106. Return Value:
  107. S_OK if it succeeded. Otherwise, it returns various error codes.
  108. Notes:
  109. varProperty may be an array
  110. */
  111. STDMETHODIMP
  112. CSsrActionData::SetProperty (
  113. IN BSTR bstrPropName,
  114. IN VARIANT varProperty
  115. )
  116. {
  117. //
  118. // Properties that are dynamically set always goes to the runtime map
  119. // which will be used to search for the named property when requested.
  120. // This implementation fulfills our design that runtime property overwrite
  121. // static registered properties (which are from the CMemberAD object)
  122. //
  123. HRESULT hr = S_OK;
  124. //
  125. // first, let's see if this property has already been set
  126. //
  127. MapNameValue::iterator it = m_mapRuntimeAD.find(bstrPropName);
  128. MapNameValue::iterator itEnd = m_mapRuntimeAD.end();
  129. if (it != itEnd)
  130. {
  131. VARIANT * pValOld = (*it).second;
  132. ::VariantClear(pValOld);
  133. hr = ::VariantCopy(pValOld, &varProperty);
  134. }
  135. else
  136. {
  137. //
  138. // the name property is not present. Then add a new pair
  139. //
  140. BSTR bstrName = ::SysAllocString(bstrPropName);
  141. VARIANT * pNewVal = new VARIANT;
  142. if (bstrName != NULL && pNewVal != NULL)
  143. {
  144. //
  145. // The map will take care of the heap memory
  146. //
  147. ::VariantInit(pNewVal);
  148. hr = ::VariantCopy(pNewVal, &varProperty);
  149. if (SUCCEEDED(hr))
  150. {
  151. m_mapRuntimeAD.insert(MapNameValue::value_type(bstrName, pNewVal));
  152. }
  153. }
  154. else
  155. {
  156. if (bstrName != NULL)
  157. {
  158. ::SysFreeString(bstrName);
  159. }
  160. if (pNewVal != NULL)
  161. {
  162. delete pNewVal;
  163. }
  164. hr = E_OUTOFMEMORY;
  165. }
  166. }
  167. return hr;
  168. }
  169. /*
  170. Routine Description:
  171. Name:
  172. CSsrActionData::Reset
  173. Functionality:
  174. Cleanup the whole property bag
  175. Virtual:
  176. yes.
  177. Arguments:
  178. none.
  179. Return Value:
  180. S_OK.
  181. Notes:
  182. */
  183. STDMETHODIMP
  184. CSsrActionData::Reset ()
  185. {
  186. //
  187. // both items of the map (first and second) are heap allocated
  188. // memories, so we need to release them
  189. //
  190. MapNameValue::iterator it = m_mapRuntimeAD.begin();
  191. MapNameValue::iterator itEnd = m_mapRuntimeAD.end();
  192. while (it != itEnd)
  193. {
  194. BSTR bstrName = (*it).first;
  195. VARIANT * pvarVal = (*it).second;
  196. ::SysFreeString(bstrName);
  197. ::VariantClear(pvarVal);
  198. delete pvarVal;
  199. ++it;
  200. }
  201. m_mapRuntimeAD.clear();
  202. return S_OK;
  203. }