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.

220 lines
5.7 KiB

  1. // TSNameValueMgr.cpp: implementation of the CTSNameValueMgr class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "TSNameValueMgr.h"
  6. #include "apgtsassert.h"
  7. #include "functions.h"
  8. //////////////////////////////////////////////////////////////////////
  9. // Construction/Destruction
  10. //////////////////////////////////////////////////////////////////////
  11. CTSNameValueMgr::CTSNameValueMgr(const VARIANT& name, const VARIANT& value, int count)
  12. : m_bIsValid(true),
  13. m_pvarNames(NULL),
  14. m_pvarValues(NULL),
  15. m_nCount(count)
  16. {
  17. try {
  18. Initialize(name, value, count);
  19. FormDataFromArray();
  20. }
  21. catch (exception& /*x*/)
  22. {
  23. // catch custom exception (our custon exceptions are normally inherited from STL exception class
  24. m_bIsValid = false;
  25. /*
  26. CString str;
  27. CBuildSrcFileLinenoStr SrcLoc( __FILE__, __LINE__ );
  28. CEvent::ReportWFEvent( SrcLoc.GetSrcFileLineStr(),
  29. SrcLoc.GetSrcFileLineStr(),
  30. CCharConversion::ConvertACharToString(x.what(), str),
  31. _T(""),
  32. EV_GTS_STL_EXCEPTION );
  33. */
  34. }
  35. }
  36. CTSNameValueMgr::CTSNameValueMgr(const CArrNameValue& arr)
  37. : m_bIsValid(true),
  38. m_pvarNames(NULL),
  39. m_pvarValues(NULL),
  40. m_nCount(arr.size()),
  41. m_arrNameValue(arr)
  42. {
  43. FormDataFromArray();
  44. }
  45. CTSNameValueMgr::CTSNameValueMgr()
  46. : m_bIsValid(true),
  47. m_pvarNames(NULL),
  48. m_pvarValues(NULL),
  49. m_nCount(0)
  50. {
  51. }
  52. CTSNameValueMgr::~CTSNameValueMgr()
  53. {
  54. }
  55. void CTSNameValueMgr::Initialize(const VARIANT& varCmds, const VARIANT& varVals, int size)
  56. {
  57. USES_CONVERSION;
  58. const VARIANT* pVarCmds;
  59. const VARIANT* pVarVals;
  60. if (VT_BYREF == (VT_BYREF & varCmds.vt) && // ???
  61. VT_VARIANT == (VT_VARIANT & varCmds.vt))
  62. {
  63. if (VT_ARRAY == (VT_ARRAY & varCmds.vt))
  64. pVarCmds = &varCmds;
  65. else
  66. pVarCmds = varCmds.pvarVal;
  67. }
  68. else
  69. {
  70. pVarCmds = NULL;
  71. CString str = _T("Cmd parameters from VB were not a variant or not by ref.");
  72. ASSERT(FALSE);
  73. throw exception((const char*)str);
  74. }
  75. if (VT_BYREF == (VT_BYREF & varVals.vt) && // ???
  76. VT_VARIANT == (VT_VARIANT & varVals.vt))
  77. {
  78. if (VT_ARRAY == (VT_ARRAY & varVals.vt))
  79. pVarVals = &varVals;
  80. else
  81. pVarVals = varVals.pvarVal;
  82. }
  83. else
  84. {
  85. pVarVals = NULL;
  86. CString str = _T("Cmd parameters from VB were not a variant or not by ref.");
  87. ASSERT(FALSE);
  88. throw exception((const char*)str);
  89. }
  90. if (VT_BYREF != (VT_BYREF & pVarCmds->vt) ||
  91. VT_ARRAY != (VT_ARRAY & pVarCmds->vt) ||
  92. VT_VARIANT != (0xFFF & pVarCmds->vt))
  93. {
  94. CString str = _T("Wrong Cmd parameters passed from VB.");
  95. ASSERT(FALSE);
  96. throw exception((const char*)str);
  97. }
  98. if (VT_BYREF != (VT_BYREF & pVarVals->vt) ||
  99. VT_ARRAY != (VT_ARRAY & pVarVals->vt) ||
  100. VT_VARIANT != (0xFFF & pVarVals->vt))
  101. {
  102. CString str = _T("Wrong Cmd parameters passed from VB.");
  103. ASSERT(FALSE);
  104. throw exception((const char*)str);
  105. }
  106. SAFEARRAY *pArrCmds = *(pVarCmds->pparray);
  107. SAFEARRAY *pArrVals = *(pVarVals->pparray);
  108. if (0 != pArrCmds->rgsabound[0].lLbound || 0 != pArrVals->rgsabound[0].lLbound)
  109. {
  110. CString str = _T("Wrong Cmd parameters passed from VB. Lower bounds are wrong.");
  111. ASSERT(FALSE);
  112. throw exception((const char*)str);
  113. }
  114. if (pArrCmds->rgsabound[0].cElements != pArrVals->rgsabound[0].cElements)
  115. {
  116. CString str = _T("Wrong Cmd parameters passed from VB. Cmds upperbound != Vals upperbound.");
  117. ASSERT(FALSE);
  118. throw exception((const char*)str);
  119. }
  120. m_nCount = size;
  121. m_pvarNames = (VARIANT *) pArrCmds->pvData;
  122. m_pvarValues = (VARIANT *) pArrVals->pvData;
  123. if (0 != m_nCount)
  124. {
  125. if (m_pvarNames->vt != VT_BSTR || m_pvarValues->vt != VT_BSTR)
  126. {
  127. CString str;
  128. str.Format(_T("Wrong Cmd parameters passed from VB. Array of unexpected type.\n\n")
  129. _T("Cmd Type: %s\nVal Type: %s"),
  130. (LPCTSTR) DecodeVariantTypes(m_pvarNames->vt),
  131. (LPCTSTR) DecodeVariantTypes(m_pvarValues->vt));
  132. ASSERT(FALSE);
  133. throw exception((const char*)str);
  134. }
  135. }
  136. m_arrNameValue.clear();
  137. m_strData = _T("");
  138. // Extract the last name in order to check and remove any previous references to that name.
  139. // If there is only one name, there is no need to extract the name.
  140. CString strLastName;
  141. if (m_nCount > 1)
  142. strLastName= W2T( m_pvarNames[ m_nCount - 1 ].bstrVal );
  143. for (int i = 0; i < m_nCount; i++)
  144. {
  145. CString name = W2T(m_pvarNames[i].bstrVal);
  146. CString value = W2T(m_pvarValues[i].bstrVal);
  147. if (0 == _tcsicmp(name, _T("TShootProblem")))
  148. name = _T("ProblemAsk");
  149. if (i == 0) // "value" contains network name
  150. value.MakeLower(); // for compatibility with Online TS, where network name
  151. // is forced lower case
  152. // Check if we need to remove any previous reference to the last name.
  153. if ((i == (m_nCount - 1)) || (strLastName != name))
  154. {
  155. CNameValue name_value;
  156. name_value.strName = name;
  157. name_value.strValue = value;
  158. m_arrNameValue.push_back(name_value);
  159. }
  160. }
  161. }
  162. bool CTSNameValueMgr::IsValid() const
  163. {
  164. return m_bIsValid;
  165. }
  166. const CString& CTSNameValueMgr::GetData() const
  167. {
  168. return m_strData;
  169. }
  170. int CTSNameValueMgr::GetCount() const
  171. {
  172. return m_nCount;
  173. }
  174. CNameValue CTSNameValueMgr::GetNameValue(int i) const
  175. {
  176. if (i < 0 || i >= m_arrNameValue.size())
  177. return CNameValue();
  178. return m_arrNameValue[i];
  179. }
  180. void CTSNameValueMgr::FormDataFromArray()
  181. {
  182. m_strData = _T("");
  183. for (CArrNameValue::iterator i = m_arrNameValue.begin(); i != m_arrNameValue.end(); i++)
  184. {
  185. m_strData += (*i).strName;
  186. m_strData += _T("=");
  187. m_strData += (*i).strValue;
  188. if (i != m_arrNameValue.end() - 1/*??? or decrement???*/) // it is not last pass through the loop
  189. m_strData += _T("&");
  190. }
  191. }