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.

472 lines
8.8 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995.
  5. //
  6. // File: nw2var.cxx
  7. //
  8. // Contents: Nw312 Object to Variant Copy Routines
  9. //
  10. // Functions:
  11. //
  12. // History: 06/12/96 KrishnaG created.
  13. // cloned off NDS conversion code.
  14. //
  15. //
  16. //----------------------------------------------------------------------------
  17. //
  18. // NTType objects copy code
  19. //
  20. #include "nwcompat.hxx"
  21. #pragma hdrstop
  22. void
  23. VarTypeFreeVarObjects(
  24. PVARIANT pVarObject,
  25. DWORD dwNumValues
  26. )
  27. {
  28. DWORD i = 0;
  29. if( !pVarObject){
  30. return;
  31. }
  32. for (i = 0; i < dwNumValues; i++ ) {
  33. VariantClear(pVarObject + i);
  34. }
  35. FreeADsMem(pVarObject);
  36. return;
  37. }
  38. HRESULT
  39. NTTypeToVarTypeCopyBOOL(
  40. PNTOBJECT pNTSrcValue,
  41. PVARIANT lpVarDestObject
  42. )
  43. {
  44. HRESULT hr = S_OK;
  45. if(!lpVarDestObject){
  46. RRETURN(E_POINTER);
  47. }
  48. if(!pNTSrcValue){
  49. RRETURN(E_POINTER);
  50. }
  51. lpVarDestObject->vt = VT_BOOL;
  52. if((pNTSrcValue->NTValue).fValue){
  53. lpVarDestObject->boolVal = VARIANT_TRUE; // notation for TRUE in V_BOOL
  54. } else {
  55. lpVarDestObject->boolVal = VARIANT_FALSE;
  56. }
  57. RRETURN(hr);
  58. }
  59. HRESULT
  60. NTTypeToVarTypeCopySYSTEMTIME(
  61. PNTOBJECT pNTSrcValue,
  62. PVARIANT lpVarDestObject
  63. )
  64. {
  65. HRESULT hr = S_OK;
  66. if(!pNTSrcValue){
  67. RRETURN(E_POINTER);
  68. }
  69. if(!lpVarDestObject){
  70. RRETURN(E_POINTER);
  71. }
  72. lpVarDestObject->vt = VT_DATE;
  73. hr = ConvertSystemTimeToDATE (pNTSrcValue->NTValue.stSystemTimeValue,
  74. &lpVarDestObject->date );
  75. RRETURN(hr);
  76. }
  77. HRESULT
  78. NTTypeToVarTypeCopyDWORD(
  79. PNTOBJECT pNTSrcValue,
  80. PVARIANT lpVarDestObject
  81. )
  82. {
  83. //
  84. // we cast the DWORD to a LONG
  85. //
  86. HRESULT hr = S_OK;
  87. if(!lpVarDestObject){
  88. RRETURN(E_POINTER);
  89. }
  90. if(!pNTSrcValue){
  91. RRETURN(E_POINTER);
  92. }
  93. lpVarDestObject->vt = VT_I4;
  94. lpVarDestObject->lVal = (LONG)(pNTSrcValue->NTValue).dwValue;
  95. RRETURN(hr);
  96. }
  97. HRESULT
  98. NTTypeToVarTypeCopyDATE(
  99. PNTOBJECT pNTSrcValue,
  100. PVARIANT lpVarDestObject
  101. )
  102. {
  103. HRESULT hr = S_OK;
  104. SYSTEMTIME stSystemTime;
  105. SYSTEMTIME LocalTime;
  106. DATE date ;
  107. BOOL fRetval;
  108. GetSystemTime( &stSystemTime);
  109. fRetval = SystemTimeToTzSpecificLocalTime(
  110. NULL,
  111. &stSystemTime,
  112. &LocalTime
  113. );
  114. if(!fRetval){
  115. RRETURN(HRESULT_FROM_WIN32(GetLastError()));
  116. }
  117. stSystemTime.wHour = (WORD)(pNTSrcValue->NTValue.dwValue)/60;
  118. stSystemTime.wMinute = (WORD)(pNTSrcValue->NTValue.dwValue)%60;
  119. stSystemTime.wSecond =0;
  120. stSystemTime.wMilliseconds = 0;
  121. if(!lpVarDestObject){
  122. RRETURN(E_POINTER);
  123. }
  124. if(!pNTSrcValue){
  125. RRETURN(E_POINTER);
  126. }
  127. lpVarDestObject->vt = VT_DATE;
  128. hr = ConvertSystemTimeToDATE (stSystemTime,
  129. &date );
  130. BAIL_ON_FAILURE(hr);
  131. lpVarDestObject->date = date - (DWORD)date;
  132. error:
  133. RRETURN(hr);
  134. }
  135. HRESULT
  136. NTTypeToVarTypeCopyNW312DATE(
  137. PNTOBJECT pNTSrcValue,
  138. PVARIANT lpVarDestObject
  139. )
  140. {
  141. HRESULT hr = S_OK;
  142. SYSTEMTIME stSystemTime;
  143. SYSTEMTIME LocalTime;
  144. DATE date ;
  145. BOOL fRetval;
  146. if(!lpVarDestObject){
  147. RRETURN(E_POINTER);
  148. }
  149. if(!pNTSrcValue){
  150. RRETURN(E_POINTER);
  151. }
  152. lpVarDestObject->vt = VT_DATE;
  153. hr = ConvertNW312DateToVariant(
  154. pNTSrcValue->NTValue.Nw312Date,
  155. &lpVarDestObject->date
  156. );
  157. BAIL_ON_FAILURE(hr);
  158. error:
  159. RRETURN(hr);
  160. }
  161. HRESULT
  162. NTTypeToVarTypeCopyOctetString(
  163. PNTOBJECT pNTSrcValue,
  164. PVARIANT lpVarDestObject
  165. )
  166. {
  167. HRESULT hr = S_OK;
  168. if(!lpVarDestObject){
  169. RRETURN(E_POINTER);
  170. }
  171. hr = BinaryToVariant(
  172. (pNTSrcValue->NTValue).octetstring.dwSize,
  173. (pNTSrcValue->NTValue).octetstring.pByte,
  174. lpVarDestObject
  175. );
  176. RRETURN(hr);
  177. }
  178. HRESULT
  179. NTTypeToVarTypeCopyLPTSTR(
  180. PNTOBJECT pNTSrcValue,
  181. PVARIANT lpVarDestObject
  182. )
  183. {
  184. HRESULT hr = S_OK;
  185. if(!lpVarDestObject){
  186. RRETURN(E_POINTER);
  187. }
  188. lpVarDestObject->vt = VT_BSTR;
  189. if(!(pNTSrcValue->NTValue).pszValue){
  190. lpVarDestObject->bstrVal = NULL;
  191. hr = S_OK;
  192. goto error;
  193. }
  194. if(!pNTSrcValue){
  195. lpVarDestObject->bstrVal = NULL;
  196. } else {
  197. hr = ADsAllocString((pNTSrcValue->NTValue).pszValue,
  198. &(lpVarDestObject->bstrVal));
  199. }
  200. error:
  201. RRETURN(hr);
  202. }
  203. HRESULT
  204. NTTypeToVarTypeCopyDelimitedString(
  205. PNTOBJECT pNTSrcValue,
  206. PVARIANT lpVarDestObject
  207. )
  208. {
  209. HRESULT hr = S_OK;
  210. if(!lpVarDestObject){
  211. RRETURN(E_POINTER);
  212. }
  213. if(!pNTSrcValue){
  214. RRETURN(E_POINTER);
  215. } else {
  216. hr = DelimitedStringToVariant((pNTSrcValue->NTValue).pszValue,
  217. lpVarDestObject,
  218. TEXT(',') );
  219. }
  220. RRETURN(hr);
  221. }
  222. HRESULT
  223. NTTypeToVarTypeCopyNulledString(
  224. PNTOBJECT pNTSrcValue,
  225. PVARIANT lpVarDestObject
  226. )
  227. {
  228. HRESULT hr = S_OK;
  229. if(!pNTSrcValue){
  230. RRETURN(E_POINTER);
  231. }
  232. if(!lpVarDestObject){
  233. RRETURN(E_POINTER);
  234. }
  235. if(!(pNTSrcValue->NTValue).pszValue){
  236. RRETURN(E_POINTER);
  237. }
  238. hr = NulledStringToVariant((pNTSrcValue->NTValue).pszValue,
  239. lpVarDestObject );
  240. RRETURN(hr);
  241. }
  242. HRESULT
  243. NtTypeToVarTypeCopy(
  244. PNTOBJECT lpNtSrcObject,
  245. PVARIANT lpVarDestObject
  246. )
  247. {
  248. HRESULT hr = S_OK;
  249. switch (lpNtSrcObject->NTType) {
  250. case NT_SYNTAX_ID_BOOL:
  251. hr = NTTypeToVarTypeCopyBOOL(
  252. lpNtSrcObject,
  253. lpVarDestObject
  254. );
  255. break;
  256. case NT_SYNTAX_ID_SYSTEMTIME:
  257. hr = NTTypeToVarTypeCopySYSTEMTIME(
  258. lpNtSrcObject,
  259. lpVarDestObject
  260. );
  261. break;
  262. case NT_SYNTAX_ID_DWORD:
  263. hr = NTTypeToVarTypeCopyDWORD(
  264. lpNtSrcObject,
  265. lpVarDestObject
  266. );
  267. break;
  268. case NT_SYNTAX_ID_DATE:
  269. hr = NTTypeToVarTypeCopyDATE(
  270. lpNtSrcObject,
  271. lpVarDestObject
  272. );
  273. break;
  274. case NT_SYNTAX_ID_NW312DATE:
  275. hr = NTTypeToVarTypeCopyNW312DATE(
  276. lpNtSrcObject,
  277. lpVarDestObject
  278. );
  279. break;
  280. case NT_SYNTAX_ID_LPTSTR:
  281. hr = NTTypeToVarTypeCopyLPTSTR(
  282. lpNtSrcObject,
  283. lpVarDestObject
  284. );
  285. break;
  286. case NT_SYNTAX_ID_DelimitedString:
  287. hr = NTTypeToVarTypeCopyDelimitedString(
  288. lpNtSrcObject,
  289. lpVarDestObject
  290. );
  291. break;
  292. case NT_SYNTAX_ID_NulledString :
  293. hr = NTTypeToVarTypeCopyNulledString(
  294. lpNtSrcObject,
  295. lpVarDestObject
  296. );
  297. break;
  298. case NT_SYNTAX_ID_OCTETSTRING :
  299. hr = NTTypeToVarTypeCopyOctetString(
  300. lpNtSrcObject,
  301. lpVarDestObject
  302. );
  303. break;
  304. default:
  305. hr = E_FAIL;
  306. break;
  307. }
  308. RRETURN(hr);
  309. }
  310. HRESULT
  311. NtTypeToVarTypeCopyConstruct(
  312. LPNTOBJECT pNtSrcObjects,
  313. DWORD dwNumObjects,
  314. PVARIANT pVarDestObjects
  315. )
  316. {
  317. long i = 0;
  318. HRESULT hr = S_OK;
  319. VariantInit(pVarDestObjects);
  320. //
  321. // The following are for handling are multi-value properties
  322. //
  323. SAFEARRAY *aList = NULL;
  324. SAFEARRAYBOUND aBound;
  325. aBound.lLbound = 0;
  326. aBound.cElements = dwNumObjects;
  327. aList = SafeArrayCreate( VT_VARIANT, 1, &aBound );
  328. if ( aList == NULL )
  329. {
  330. hr = E_OUTOFMEMORY;
  331. BAIL_ON_FAILURE(hr);
  332. }
  333. for ( i = 0; i < (long) dwNumObjects; i++ )
  334. {
  335. VARIANT v;
  336. VariantInit(&v);
  337. hr = NtTypeToVarTypeCopy( pNtSrcObjects + i,
  338. &v );
  339. BAIL_ON_FAILURE(hr);
  340. hr = SafeArrayPutElement( aList, &i, &v );
  341. VariantClear(&v);
  342. BAIL_ON_FAILURE(hr);
  343. }
  344. V_VT(pVarDestObjects) = VT_ARRAY | VT_VARIANT;
  345. V_ARRAY(pVarDestObjects) = aList;
  346. RRETURN(S_OK);
  347. error:
  348. if ( aList )
  349. SafeArrayDestroy( aList );
  350. RRETURN(hr);
  351. }