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.

322 lines
7.4 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright(C) 1997-1998 Microsoft Corporation all rights reserved.
  4. //
  5. // Module: sdoproperty.cpp
  6. //
  7. // Project: Everest
  8. //
  9. // Description: IAS Server Data Object Property Implementation
  10. //
  11. // Author: TLP 1/23/98
  12. //
  13. /////////////////////////////////////////////////////////////////////////////
  14. #include "stdafx.h"
  15. #include "sdoproperty.h"
  16. #include <varvec.h>
  17. //////////////////////////////////////////////////////////////////////////////
  18. CSdoProperty::CSdoProperty(
  19. ISdoPropertyInfo* pSdoPropertyInfo,
  20. DWORD dwFlags
  21. ) throw (_com_error)
  22. : m_alias(PROPERTY_SDO_RESERVED),
  23. m_flags(0),
  24. m_dirty(FALSE),
  25. m_type(VT_EMPTY),
  26. m_index(0),
  27. m_dfa(NULL)
  28. {
  29. HRESULT hr;
  30. hr = pSdoPropertyInfo->get_DisplayName(&m_name);
  31. if ( FAILED(hr) )
  32. throw _com_error(hr);
  33. LONG type;
  34. hr = pSdoPropertyInfo->get_Type(&type);
  35. if ( FAILED(hr) )
  36. throw _com_error(hr);
  37. m_type = (VARTYPE)type;
  38. hr = pSdoPropertyInfo->get_Alias(&m_alias);
  39. if ( FAILED(hr) )
  40. throw _com_error(hr);
  41. hr = pSdoPropertyInfo->get_Flags((LONG*)&m_flags);
  42. if ( FAILED(hr) )
  43. throw _com_error(hr);
  44. m_flags |= dwFlags;
  45. if ( m_flags & SDO_PROPERTY_MIN_LENGTH )
  46. {
  47. hr = pSdoPropertyInfo->get_MinLength((LONG*)&m_minLength);
  48. if ( FAILED(hr) )
  49. throw _com_error(hr);
  50. }
  51. if ( m_flags & SDO_PROPERTY_MAX_LENGTH )
  52. {
  53. hr = pSdoPropertyInfo->get_MaxLength((LONG*)&m_maxLength);
  54. if ( FAILED(hr) )
  55. throw _com_error(hr);
  56. }
  57. if ( m_flags & SDO_PROPERTY_MIN_VALUE )
  58. {
  59. hr = pSdoPropertyInfo->get_MinValue(&m_minValue);
  60. if ( FAILED(hr) )
  61. throw _com_error(hr);
  62. }
  63. if ( m_flags & SDO_PROPERTY_MAX_VALUE )
  64. {
  65. hr = pSdoPropertyInfo->get_MaxValue(&m_maxValue);
  66. if ( FAILED(hr) )
  67. throw _com_error(hr);
  68. }
  69. if ( m_flags & SDO_PROPERTY_HAS_DEFAULT )
  70. {
  71. hr = pSdoPropertyInfo->get_DefaultValue(&m_defaultValue);
  72. if ( FAILED(hr) )
  73. throw _com_error(hr);
  74. m_value[m_index] = m_defaultValue;
  75. }
  76. if ( m_flags & SDO_PROPERTY_FORMAT )
  77. {
  78. BSTR format;
  79. hr = pSdoPropertyInfo->get_Format (&format);
  80. if ( FAILED(hr) )
  81. throw _com_error(hr);
  82. m_dfa = new CDFA(format, FALSE);
  83. SysFreeString(format);
  84. }
  85. m_pSdoPropertyInfo = pSdoPropertyInfo;
  86. }
  87. //////////////////////////////////////////////////////////////////////////////
  88. CSdoProperty::~CSdoProperty()
  89. {
  90. if ( m_dfa )
  91. delete m_dfa;
  92. }
  93. //////////////////////////////////////////////////////////////////////////////
  94. void CSdoProperty::Reset(void) throw(_com_error)
  95. {
  96. if ( m_flags & SDO_PROPERTY_HAS_DEFAULT )
  97. {
  98. _ASSERT( ! (m_flags & (SDO_PROPERTY_POINTER | SDO_PROPERTY_COLLECTION)) ) ;
  99. if ( ! (m_flags & (SDO_PROPERTY_POINTER | SDO_PROPERTY_COLLECTION)) )
  100. {
  101. if ( FAILED(VariantCopy(GetUpdateValue(), &m_defaultValue)) )
  102. throw _com_error(E_FAIL);
  103. }
  104. }
  105. }
  106. //////////////////////////////////////////////////////////////////////////////
  107. HRESULT CSdoProperty::Validate(VARIANT *pValue)
  108. {
  109. // We'll always allow an empty property. If it turns out to be mandator this
  110. // will be caught during Apply.
  111. if (V_VT(pValue) == VT_EMPTY) { return S_OK; }
  112. HRESULT hr = S_OK;
  113. if ( m_flags & SDO_PROPERTY_MULTIVALUED )
  114. {
  115. _ASSERT( (VT_ARRAY | VT_VARIANT) == V_VT(pValue) );
  116. if ( (VT_ARRAY | VT_VARIANT) != V_VT(pValue) )
  117. {
  118. hr = E_INVALIDARG;
  119. }
  120. else
  121. {
  122. CVariantVector<VARIANT> property(pValue);
  123. DWORD count = 0;
  124. while ( count < property.size() )
  125. {
  126. hr = ValidateIt(&property[count]);
  127. if ( FAILED(hr) )
  128. break;
  129. count++;
  130. }
  131. }
  132. }
  133. else
  134. {
  135. hr = ValidateIt(pValue);
  136. }
  137. return hr;
  138. }
  139. //////////////////////////////////////////////////////////////////////////////
  140. HRESULT CSdoProperty::ValidateIt(VARIANT* pValue)
  141. {
  142. // Validate type
  143. //
  144. if ( m_type != V_VT(pValue) &&
  145. !(m_type == (VT_ARRAY | VT_UI1) && V_VT(pValue) == VT_BSTR))
  146. {
  147. IASTracePrintf("SDO Property Error - Validate() - type mismatch...");
  148. return E_INVALIDARG;
  149. }
  150. // Make sure a VT_BOOL is a VT_BOOL
  151. //
  152. if ( VT_BOOL == V_VT(pValue) )
  153. {
  154. _ASSERTE ( VARIANT_TRUE == V_BOOL(pValue) || VARIANT_FALSE == V_BOOL(pValue) );
  155. if ( VARIANT_TRUE != V_BOOL(pValue) && VARIANT_FALSE != V_BOOL(pValue) )
  156. {
  157. IASTracePrintf("SDO Property Error - Validate() - VT_BOOL not set to VARIANT_TRUE or VARIANT_FALSE...");
  158. return E_INVALIDARG;
  159. }
  160. return S_OK;
  161. }
  162. // Validate format
  163. //
  164. if ( m_flags & SDO_PROPERTY_FORMAT )
  165. {
  166. _ASSERT( V_VT(pValue) == VT_BSTR );
  167. if ( V_VT(pValue) == VT_BSTR )
  168. {
  169. if ( ! m_dfa->Recognize(V_BSTR(pValue)) )
  170. return E_INVALIDARG;
  171. }
  172. else
  173. {
  174. return E_INVALIDARG;
  175. }
  176. }
  177. // Min Value
  178. //
  179. if ( m_flags & SDO_PROPERTY_MIN_VALUE )
  180. {
  181. if ( V_VT(pValue) == VT_I4 || V_VT(pValue) == VT_I2 )
  182. {
  183. if ( V_VT(pValue) == VT_I4 )
  184. {
  185. if ( V_I4(&m_minValue) > V_I4(pValue) )
  186. {
  187. IASTracePrintf("SDO Property Error - Validate() - I4 Value too small for property '%ls'...",m_name);
  188. return E_INVALIDARG;
  189. }
  190. }
  191. else
  192. {
  193. if ( V_I2(&m_minValue) > V_I2(pValue) )
  194. {
  195. IASTracePrintf("SDO Property Error - Validate() - I2 Value too small for property '%ls'...",m_name);
  196. return E_INVALIDARG;
  197. }
  198. }
  199. }
  200. }
  201. // Max Value
  202. //
  203. if ( m_flags & SDO_PROPERTY_MAX_VALUE )
  204. {
  205. if ( V_VT(pValue) == VT_I4 || V_VT(pValue) == VT_I2 )
  206. {
  207. if ( V_VT(pValue) == VT_I4 )
  208. {
  209. if ( V_I4(&m_maxValue) < V_I4(pValue) )
  210. {
  211. IASTracePrintf("SDO Property Error - Validate() - I4 Value too big for property '%ls'...",m_name);
  212. return E_INVALIDARG;
  213. }
  214. }
  215. else
  216. {
  217. if ( V_I2(&m_maxValue) < V_I2(pValue) )
  218. {
  219. IASTracePrintf("SDO Property Error - Validate() - I2 Value too big for property '%ls'...",m_name);
  220. return E_INVALIDARG;
  221. }
  222. }
  223. }
  224. }
  225. // Min Length
  226. //
  227. if ( m_flags & SDO_PROPERTY_MIN_LENGTH )
  228. {
  229. _ASSERT( VT_BSTR == V_VT(pValue) || (VT_ARRAY | VT_UI1) == V_VT(pValue) );
  230. if ( VT_BSTR == V_VT(pValue) )
  231. {
  232. if ( NULL == V_BSTR(pValue) )
  233. {
  234. return E_INVALIDARG;
  235. }
  236. else
  237. {
  238. if ( m_minLength > SysStringLen(V_BSTR(pValue)) )
  239. {
  240. IASTracePrintf("SDO Property Error - Validate() - Min length for property '%ls'...",m_name);
  241. return E_INVALIDARG;
  242. }
  243. }
  244. }
  245. else
  246. {
  247. CVariantVector<BYTE> OctetString(pValue);
  248. if ( m_minLength > OctetString.size() )
  249. {
  250. IASTracePrintf("SDO Property Error - Validate() - Min length for property '%ls'...",m_name);
  251. return E_INVALIDARG;
  252. }
  253. }
  254. }
  255. // Max Length
  256. //
  257. if ( m_flags & SDO_PROPERTY_MAX_LENGTH )
  258. {
  259. _ASSERT( VT_BSTR == V_VT(pValue) || (VT_ARRAY | VT_UI1) == V_VT(pValue) );
  260. if ( VT_BSTR == V_VT(pValue) )
  261. {
  262. if ( NULL == V_BSTR(pValue) )
  263. {
  264. return E_INVALIDARG;
  265. }
  266. else
  267. {
  268. if ( m_maxLength < SysStringLen(V_BSTR(pValue)) )
  269. {
  270. IASTracePrintf("SDO Property Error - Validate() - Max length for property '%ls'...",m_name);
  271. return E_INVALIDARG;
  272. }
  273. }
  274. }
  275. else
  276. {
  277. CVariantVector<BYTE> OctetString(pValue);
  278. if ( m_maxLength < OctetString.size() )
  279. {
  280. IASTracePrintf("SDO Property Error - Validate() - Max length for property '%ls'...",m_name);
  281. return E_INVALIDARG;
  282. }
  283. }
  284. }
  285. return S_OK;
  286. }