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.

1353 lines
31 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995.
  5. //
  6. // File: ndscopy.cxx
  7. //
  8. // Contents: NDS Object to Variant Copy Routines
  9. //
  10. // Functions:
  11. //
  12. // History: 25-Apr-96 KrishnaG Created.
  13. //
  14. //
  15. //
  16. //
  17. // The following conversions are not supported
  18. //
  19. // NDS_ASN1_TYPE_1
  20. //
  21. // NDS_ASN1_TYPE_2
  22. //
  23. // NDS_ASN1_TYPE_3
  24. //
  25. // NDS_ASN1_TYPE_4
  26. //
  27. // NDS_ASN1_TYPE_5
  28. //
  29. // NDS_ASN1_TYPE_6
  30. //
  31. // NDS_ASN1_TYPE_7
  32. //
  33. // NDS_ASN1_TYPE_8
  34. //
  35. // NDS_ASN1_TYPE_9
  36. //
  37. // NDS_ASN1_TYPE_10
  38. //
  39. // NDS_ASN1_TYPE_11
  40. //
  41. // NDS_ASN1_TYPE_12
  42. //
  43. // NDS_ASN1_TYPE_13
  44. //
  45. // NDS_ASN1_TYPE_14
  46. //
  47. // NDS_ASN1_TYPE_15
  48. //
  49. // NDS_ASN1_TYPE_16
  50. //
  51. // NDS_ASN1_TYPE_17
  52. //
  53. // NDS_ASN1_TYPE_18
  54. //
  55. // NDS_ASN1_TYPE_19
  56. //
  57. // NDS_ASN1_TYPE_20
  58. //
  59. // NDS_ASN1_TYPE_21
  60. //
  61. // NDS_ASN1_TYPE_22
  62. //
  63. // NDS_ASN1_TYPE_23
  64. //
  65. // NDS_ASN1_TYPE_24
  66. //
  67. // NDS_ASN1_TYPE_25
  68. //
  69. // NDS_ASN1_TYPE_26
  70. //
  71. // NDS_ASN1_TYPE_27
  72. //
  73. //
  74. //----------------------------------------------------------------------------
  75. #include "nds.hxx"
  76. //
  77. // NdsType objects copy code
  78. //
  79. void
  80. VarTypeFreeVarObjects(
  81. PVARIANT pVarObject,
  82. DWORD dwNumValues
  83. )
  84. {
  85. DWORD i = 0;
  86. for (i = 0; i < dwNumValues; i++ ) {
  87. VariantClear(pVarObject + i);
  88. }
  89. FreeADsMem(pVarObject);
  90. return;
  91. }
  92. HRESULT
  93. NdsTypeToVarTypeCopyNDSSynId1(
  94. PNDSOBJECT lpNdsSrcObject,
  95. PVARIANT lpVarDestObject
  96. )
  97. {
  98. HRESULT hr = S_OK;
  99. lpVarDestObject->vt = VT_BSTR;
  100. hr = ADsAllocString(
  101. lpNdsSrcObject->NdsValue.value_1.DNString,
  102. &(lpVarDestObject->bstrVal)
  103. );
  104. RRETURN(hr);
  105. }
  106. HRESULT
  107. NdsTypeToVarTypeCopyNDSSynId2(
  108. PNDSOBJECT lpNdsSrcObject,
  109. PVARIANT lpVarDestObject
  110. )
  111. {
  112. HRESULT hr = S_OK;
  113. lpVarDestObject->vt = VT_BSTR;
  114. hr = ADsAllocString(
  115. lpNdsSrcObject->NdsValue.value_1.DNString,
  116. &(lpVarDestObject->bstrVal)
  117. );
  118. RRETURN(hr);
  119. }
  120. HRESULT
  121. NdsTypeToVarTypeCopyNDSSynId3(
  122. PNDSOBJECT lpNdsSrcObject,
  123. PVARIANT lpVarDestObject
  124. )
  125. {
  126. HRESULT hr = S_OK;
  127. VariantInit(lpVarDestObject);
  128. lpVarDestObject->vt = VT_BSTR;
  129. hr = ADsAllocString(
  130. lpNdsSrcObject->NdsValue.value_1.DNString,
  131. &(lpVarDestObject->bstrVal)
  132. );
  133. RRETURN(hr);
  134. }
  135. HRESULT
  136. NdsTypeToVarTypeCopyNDSSynId4(
  137. PNDSOBJECT lpNdsSrcObject,
  138. PVARIANT lpVarDestObject
  139. )
  140. {
  141. HRESULT hr = S_OK;
  142. lpVarDestObject->vt = VT_BSTR;
  143. hr = ADsAllocString(
  144. lpNdsSrcObject->NdsValue.value_1.DNString,
  145. &(lpVarDestObject->bstrVal)
  146. );
  147. RRETURN(hr);
  148. }
  149. HRESULT
  150. NdsTypeToVarTypeCopyNDSSynId5(
  151. PNDSOBJECT lpNdsSrcObject,
  152. PVARIANT lpVarDestObject
  153. )
  154. {
  155. HRESULT hr = S_OK;
  156. lpVarDestObject->vt = VT_BSTR;
  157. hr = ADsAllocString(
  158. lpNdsSrcObject->NdsValue.value_1.DNString,
  159. &(lpVarDestObject->bstrVal)
  160. );
  161. RRETURN(hr);
  162. }
  163. HRESULT
  164. NdsTypeToVarTypeCopyNDSSynId6(
  165. PNDSOBJECT lpNdsSrcObject,
  166. PVARIANT lpVarDestObject
  167. )
  168. {
  169. HRESULT hr = S_OK;
  170. SAFEARRAY *aList = NULL;
  171. SAFEARRAYBOUND aBound;
  172. long i;
  173. BSTR bstrAddress;
  174. DWORD cElements = 0;
  175. IADsCaseIgnoreList* pCaseIgnoreList = NULL;
  176. IDispatch * pDispatch = NULL;
  177. VARIANT VarDestObject;
  178. struct _NDS_CI_LIST *pCurrent = NULL;
  179. VARIANT varElement;
  180. hr = CCaseIgnoreList::CreateCaseIgnoreList(
  181. IID_IADsCaseIgnoreList,
  182. (void **)&pCaseIgnoreList
  183. );
  184. BAIL_ON_FAILURE(hr);
  185. pCurrent = &(lpNdsSrcObject->NdsValue.value_6);
  186. while (pCurrent) {
  187. cElements++;
  188. pCurrent = pCurrent->Next;
  189. }
  190. aBound.lLbound = 0;
  191. aBound.cElements = cElements;
  192. aList = SafeArrayCreate( VT_VARIANT, 1, &aBound );
  193. if ( aList == NULL ) {
  194. hr = E_OUTOFMEMORY;
  195. BAIL_ON_FAILURE(hr);
  196. }
  197. pCurrent = &(lpNdsSrcObject->NdsValue.value_6);
  198. for ( i = 0; i < (long)cElements; i++ ) {
  199. VariantInit(&varElement);
  200. varElement.vt = VT_BSTR;
  201. hr = ADsAllocString(
  202. pCurrent->String,
  203. &varElement.bstrVal
  204. );
  205. BAIL_ON_FAILURE(hr);
  206. hr = SafeArrayPutElement( aList, &i, &varElement);
  207. BAIL_ON_FAILURE(hr);
  208. pCurrent = pCurrent->Next;
  209. VariantClear(&varElement);
  210. }
  211. VariantInit(&VarDestObject);
  212. V_VT(&VarDestObject) = VT_ARRAY | VT_VARIANT;
  213. V_ARRAY(&VarDestObject) = aList;
  214. hr = pCaseIgnoreList->put_CaseIgnoreList(VarDestObject);
  215. BAIL_ON_FAILURE(hr);
  216. VariantClear(&VarDestObject);
  217. aList = NULL;
  218. hr = pCaseIgnoreList->QueryInterface(IID_IDispatch, (void**)&pDispatch);
  219. BAIL_ON_FAILURE(hr);
  220. VariantInit(lpVarDestObject);
  221. V_VT(lpVarDestObject) = VT_DISPATCH;
  222. V_DISPATCH(lpVarDestObject) = pDispatch;
  223. error:
  224. if ( aList ) {
  225. SafeArrayDestroy( aList );
  226. }
  227. if (pCaseIgnoreList) {
  228. pCaseIgnoreList->Release();
  229. }
  230. RRETURN(hr);
  231. }
  232. HRESULT
  233. NdsTypeToVarTypeCopyNDSSynId7(
  234. PNDSOBJECT lpNdsSrcObject,
  235. PVARIANT lpVarDestObject
  236. )
  237. {
  238. HRESULT hr = S_OK;
  239. lpVarDestObject->vt = VT_BOOL;
  240. lpVarDestObject->boolVal =
  241. (lpNdsSrcObject->NdsValue.value_7.Boolean)?
  242. VARIANT_TRUE: VARIANT_FALSE;
  243. RRETURN(hr);
  244. }
  245. HRESULT
  246. NdsTypeToVarTypeCopyNDSSynId8(
  247. PNDSOBJECT lpNdsSrcObject,
  248. PVARIANT lpVarDestObject
  249. )
  250. {
  251. HRESULT hr = S_OK;
  252. lpVarDestObject->vt = VT_I4;
  253. lpVarDestObject->lVal =
  254. lpNdsSrcObject->NdsValue.value_8.Integer;
  255. RRETURN(hr);
  256. }
  257. HRESULT
  258. NdsTypeToVarTypeCopyNDSSynId9(
  259. PNDSOBJECT lpNdsSrcObject,
  260. PVARIANT lpVarDestObject
  261. )
  262. {
  263. HRESULT hr = S_OK;
  264. VariantInit(lpVarDestObject);
  265. hr = BinaryToVariant(
  266. lpNdsSrcObject->NdsValue.value_9.Length,
  267. lpNdsSrcObject->NdsValue.value_9.OctetString,
  268. lpVarDestObject);
  269. RRETURN(hr);
  270. }
  271. HRESULT
  272. NdsTypeToVarTypeCopyNDSSynId10(
  273. PNDSOBJECT lpNdsSrcObject,
  274. PVARIANT lpVarDestObject
  275. )
  276. {
  277. HRESULT hr = S_OK;
  278. lpVarDestObject->vt = VT_BSTR;
  279. hr = ADsAllocString(
  280. lpNdsSrcObject->NdsValue.value_10.TelephoneNumber,
  281. &(lpVarDestObject->bstrVal)
  282. );
  283. RRETURN(hr);
  284. }
  285. HRESULT
  286. NdsTypeToVarTypeCopyNDSSynId11(
  287. PNDSOBJECT lpNdsSrcObject,
  288. PVARIANT lpVarDestObject
  289. )
  290. {
  291. HRESULT hr = S_OK;
  292. IADsFaxNumber * pFaxNumber= NULL;
  293. IDispatch * pDispatch = NULL;
  294. VARIANT VarDestObject;
  295. VariantInit(lpVarDestObject);
  296. hr = CFaxNumber::CreateFaxNumber(
  297. IID_IADsFaxNumber,
  298. (void **)&pFaxNumber
  299. );
  300. BAIL_ON_FAILURE(hr);
  301. hr = pFaxNumber->put_TelephoneNumber(lpNdsSrcObject->NdsValue.value_11.TelephoneNumber);
  302. BAIL_ON_FAILURE(hr);
  303. VariantInit(&VarDestObject);
  304. hr = BinaryToVariant(
  305. lpNdsSrcObject->NdsValue.value_11.NumberOfBits,
  306. lpNdsSrcObject->NdsValue.value_11.Parameters,
  307. &VarDestObject);
  308. BAIL_ON_FAILURE(hr);
  309. hr = pFaxNumber->put_Parameters(VarDestObject);
  310. BAIL_ON_FAILURE(hr);
  311. VariantClear(&VarDestObject);
  312. hr = pFaxNumber->QueryInterface(IID_IDispatch, (void**)&pDispatch);
  313. BAIL_ON_FAILURE(hr);
  314. VariantInit(lpVarDestObject);
  315. V_VT(lpVarDestObject) = VT_DISPATCH;
  316. V_DISPATCH(lpVarDestObject) = pDispatch;
  317. error:
  318. if (pFaxNumber) {
  319. pFaxNumber->Release();
  320. }
  321. RRETURN(hr);
  322. }
  323. HRESULT
  324. NdsTypeToVarTypeCopyNDSSynId12(
  325. PNDSOBJECT lpNdsSrcObject,
  326. PVARIANT lpVarDestObject
  327. )
  328. {
  329. IADsNetAddress * pNetAddress = NULL;
  330. IDispatch * pDispatch = NULL;
  331. HRESULT hr = S_OK;
  332. VARIANT VarDestObject;
  333. VariantInit(lpVarDestObject);
  334. hr = CNetAddress::CreateNetAddress(
  335. IID_IADsNetAddress,
  336. (void **)&pNetAddress
  337. );
  338. BAIL_ON_FAILURE(hr);
  339. hr = pNetAddress->put_AddressType(lpNdsSrcObject->NdsValue.value_12.AddressType);
  340. BAIL_ON_FAILURE(hr);
  341. VariantInit(&VarDestObject);
  342. hr = BinaryToVariant(
  343. lpNdsSrcObject->NdsValue.value_12.AddressLength,
  344. lpNdsSrcObject->NdsValue.value_12.Address,
  345. &VarDestObject);
  346. BAIL_ON_FAILURE(hr);
  347. hr = pNetAddress->put_Address(VarDestObject);
  348. BAIL_ON_FAILURE(hr);
  349. VariantClear(&VarDestObject);
  350. hr = pNetAddress->QueryInterface(IID_IDispatch, (void**)&pDispatch);
  351. BAIL_ON_FAILURE(hr);
  352. VariantInit(lpVarDestObject);
  353. V_VT(lpVarDestObject) = VT_DISPATCH;
  354. V_DISPATCH(lpVarDestObject) = pDispatch;
  355. error:
  356. if (pNetAddress) {
  357. pNetAddress->Release();
  358. }
  359. RRETURN(hr);
  360. }
  361. HRESULT
  362. NdsTypeToVarTypeCopyNDSSynId13(
  363. PNDSOBJECT lpNdsSrcObject,
  364. PVARIANT lpVarDestObject
  365. )
  366. {
  367. HRESULT hr = S_OK;
  368. SAFEARRAY *aList = NULL;
  369. SAFEARRAYBOUND aBound;
  370. CHAR HUGEP *pArray = NULL;
  371. long i;
  372. struct _NDS_OCTET_LIST *pCurrent = NULL;
  373. DWORD cElements = 0;
  374. IADsOctetList* pOctetList = NULL;
  375. IDispatch * pDispatch = NULL;
  376. VARIANT VarDestObject;
  377. VARIANT VarElement;
  378. hr = COctetList::CreateOctetList(
  379. IID_IADsOctetList,
  380. (void **)&pOctetList
  381. );
  382. BAIL_ON_FAILURE(hr);
  383. pCurrent = &(lpNdsSrcObject->NdsValue.value_13);
  384. while (pCurrent) {
  385. cElements++;
  386. pCurrent = pCurrent->Next;
  387. }
  388. aBound.lLbound = 0;
  389. aBound.cElements = cElements;
  390. aList = SafeArrayCreate( VT_VARIANT, 1, &aBound );
  391. if ( aList == NULL ) {
  392. hr = E_OUTOFMEMORY;
  393. BAIL_ON_FAILURE(hr);
  394. }
  395. pCurrent = &(lpNdsSrcObject->NdsValue.value_13);
  396. for ( i = 0; i < (long)cElements; i++ ) {
  397. VariantInit(&VarElement);
  398. hr = BinaryToVariant(
  399. pCurrent->Length,
  400. pCurrent->Data,
  401. &VarElement);
  402. BAIL_ON_FAILURE(hr);
  403. hr = SafeArrayPutElement( aList, &i, &VarElement);
  404. BAIL_ON_FAILURE(hr);
  405. pCurrent = pCurrent->Next;
  406. }
  407. VariantInit(&VarDestObject);
  408. V_VT(&VarDestObject) = VT_ARRAY | VT_BSTR;
  409. V_ARRAY(&VarDestObject) = aList;
  410. hr = pOctetList->put_OctetList(VarDestObject);
  411. BAIL_ON_FAILURE(hr);
  412. VariantClear(&VarDestObject);
  413. aList = NULL;
  414. hr = pOctetList->QueryInterface(IID_IDispatch, (void**)&pDispatch);
  415. BAIL_ON_FAILURE(hr);
  416. VariantInit(lpVarDestObject);
  417. V_VT(lpVarDestObject) = VT_DISPATCH;
  418. V_DISPATCH(lpVarDestObject) = pDispatch;
  419. error:
  420. if ( aList ) {
  421. SafeArrayDestroy( aList );
  422. }
  423. if (pOctetList) {
  424. pOctetList->Release();
  425. }
  426. RRETURN(hr);
  427. }
  428. HRESULT
  429. NdsTypeToVarTypeCopyNDSSynId14(
  430. PNDSOBJECT lpNdsSrcObject,
  431. PVARIANT lpVarDestObject
  432. )
  433. {
  434. HRESULT hr = S_OK;
  435. IADsEmail * pEmail= NULL;
  436. IDispatch * pDispatch = NULL;
  437. VARIANT VarDestObject;
  438. VariantInit(lpVarDestObject);
  439. hr = CEmail::CreateEmail(
  440. IID_IADsEmail,
  441. (void **)&pEmail
  442. );
  443. BAIL_ON_FAILURE(hr);
  444. hr = pEmail->put_Address(lpNdsSrcObject->NdsValue.value_14.Address);
  445. BAIL_ON_FAILURE(hr);
  446. hr = pEmail->put_Type(lpNdsSrcObject->NdsValue.value_14.Type);
  447. BAIL_ON_FAILURE(hr);
  448. hr = pEmail->QueryInterface(IID_IDispatch, (void**)&pDispatch);
  449. BAIL_ON_FAILURE(hr);
  450. VariantInit(lpVarDestObject);
  451. V_VT(lpVarDestObject) = VT_DISPATCH;
  452. V_DISPATCH(lpVarDestObject) = pDispatch;
  453. error:
  454. if (pEmail) {
  455. pEmail->Release();
  456. }
  457. RRETURN(hr);
  458. }
  459. HRESULT
  460. NdsTypeToVarTypeCopyNDSSynId15(
  461. PNDSOBJECT lpNdsSrcObject,
  462. PVARIANT lpVarDestObject
  463. )
  464. {
  465. IADsPath * pPath = NULL;
  466. IDispatch * pDispatch = NULL;
  467. HRESULT hr = S_OK;
  468. VariantInit(lpVarDestObject);
  469. hr = CPath::CreatePath(
  470. IID_IADsPath,
  471. (void **)&pPath
  472. );
  473. BAIL_ON_FAILURE(hr);
  474. hr = pPath->put_Type(lpNdsSrcObject->NdsValue.value_15.Type);
  475. BAIL_ON_FAILURE(hr);
  476. hr = pPath->put_VolumeName(lpNdsSrcObject->NdsValue.value_15.VolumeName);
  477. BAIL_ON_FAILURE(hr);
  478. hr = pPath->put_Path(lpNdsSrcObject->NdsValue.value_15.Path);
  479. BAIL_ON_FAILURE(hr);
  480. hr = pPath->QueryInterface(IID_IDispatch, (void**)&pDispatch);
  481. BAIL_ON_FAILURE(hr);
  482. VariantInit(lpVarDestObject);
  483. V_VT(lpVarDestObject) = VT_DISPATCH;
  484. V_DISPATCH(lpVarDestObject) = pDispatch;
  485. error:
  486. if (pPath) {
  487. pPath->Release();
  488. }
  489. RRETURN(hr);
  490. }
  491. HRESULT
  492. NdsTypeToVarTypeCopyNDSSynId16(
  493. PNDSOBJECT lpNdsSrcObject,
  494. PVARIANT lpVarDestObject
  495. )
  496. {
  497. IADsReplicaPointer * pReplicaPointer = NULL;
  498. IDispatch * pDispatch = NULL;
  499. HRESULT hr = S_OK;
  500. LPWSTR ServerName = NULL;
  501. DWORD ReplicaType = 0;
  502. DWORD ReplicaNumber = 0;
  503. DWORD Count = 0;
  504. NDSOBJECT object;
  505. VARIANT varDestObject;
  506. VariantInit(lpVarDestObject);
  507. hr = CReplicaPointer::CreateReplicaPointer(
  508. IID_IADsReplicaPointer,
  509. (void **)&pReplicaPointer
  510. );
  511. BAIL_ON_FAILURE(hr);
  512. hr = pReplicaPointer->put_ServerName(lpNdsSrcObject->NdsValue.value_16.ServerName);
  513. BAIL_ON_FAILURE(hr);
  514. hr = pReplicaPointer->put_ReplicaType(lpNdsSrcObject->NdsValue.value_16.ReplicaType);
  515. BAIL_ON_FAILURE(hr);
  516. hr = pReplicaPointer->put_ReplicaNumber(lpNdsSrcObject->NdsValue.value_16.ReplicaNumber);
  517. BAIL_ON_FAILURE(hr);
  518. if (lpNdsSrcObject->NdsValue.value_16.Count > 0) {
  519. //
  520. // We only support the retrieval of 1 ReplicaAddressHints in the
  521. // ReplicaPointer. Supporting more than 1 requires the support
  522. // of marshalling an array variant which is more complex.
  523. // Judging that there is no real usage of this interface since
  524. // the Replica Pointer is for NDS internal use only. We have
  525. // decided that we'll postpone this to post W2K and will fix it
  526. // only if there is a need.
  527. //
  528. hr = pReplicaPointer->put_Count(1);
  529. BAIL_ON_FAILURE(hr);
  530. VariantInit(&varDestObject);
  531. memcpy(&object.NdsValue.value_12,
  532. lpNdsSrcObject->NdsValue.value_16.ReplicaAddressHints,
  533. sizeof(NDS_ASN1_TYPE_12));
  534. hr = NdsTypeToVarTypeCopyNDSSynId12(
  535. &object,
  536. &varDestObject
  537. );
  538. BAIL_ON_FAILURE(hr);
  539. hr = pReplicaPointer->put_ReplicaAddressHints(varDestObject);
  540. BAIL_ON_FAILURE(hr);
  541. VariantClear(&varDestObject);
  542. }
  543. hr = pReplicaPointer->QueryInterface(IID_IDispatch, (void**)&pDispatch);
  544. BAIL_ON_FAILURE(hr);
  545. VariantInit(lpVarDestObject);
  546. V_VT(lpVarDestObject) = VT_DISPATCH;
  547. V_DISPATCH(lpVarDestObject) = pDispatch;
  548. error:
  549. if (pReplicaPointer) {
  550. pReplicaPointer->Release();
  551. }
  552. RRETURN(hr);
  553. }
  554. HRESULT
  555. NdsTypeToVarTypeCopyNDSSynId17(
  556. PNDSOBJECT lpNdsSrcObject,
  557. PVARIANT lpVarDestObject
  558. )
  559. {
  560. IADsAcl * pSecDes = NULL;
  561. IDispatch * pDispatch = NULL;
  562. HRESULT hr = S_OK;
  563. hr = CAcl::CreateSecurityDescriptor(
  564. IID_IADsAcl,
  565. (void **)&pSecDes
  566. );
  567. BAIL_ON_FAILURE(hr);
  568. hr = pSecDes->put_SubjectName(lpNdsSrcObject->NdsValue.value_17.SubjectName);
  569. BAIL_ON_FAILURE(hr);
  570. hr = pSecDes->put_ProtectedAttrName(lpNdsSrcObject->NdsValue.value_17.ProtectedAttrName);
  571. BAIL_ON_FAILURE(hr);
  572. hr = pSecDes->put_Privileges(lpNdsSrcObject->NdsValue.value_17.Privileges);
  573. BAIL_ON_FAILURE(hr);
  574. hr = pSecDes->QueryInterface(IID_IDispatch, (void**)&pDispatch);
  575. BAIL_ON_FAILURE(hr);
  576. VariantInit(lpVarDestObject);
  577. V_VT(lpVarDestObject) = VT_DISPATCH;
  578. V_DISPATCH(lpVarDestObject) = pDispatch;
  579. error:
  580. if (pSecDes) {
  581. pSecDes->Release();
  582. }
  583. RRETURN(hr);
  584. }
  585. HRESULT
  586. NdsTypeToVarTypeCopyNDSSynId18(
  587. PNDSOBJECT lpNdsSrcObject,
  588. PVARIANT lpVarDestObject
  589. )
  590. {
  591. HRESULT hr = S_OK;
  592. SAFEARRAY *aList = NULL;
  593. SAFEARRAYBOUND aBound;
  594. CHAR HUGEP *pArray = NULL;
  595. long i;
  596. BSTR bstrAddress;
  597. IADsPostalAddress* pPostalAddress = NULL;
  598. IDispatch * pDispatch = NULL;
  599. VARIANT VarDestObject;
  600. VARIANT varElement;
  601. VariantInit(&VarDestObject);
  602. hr = CPostalAddress::CreatePostalAddress(
  603. IID_IADsPostalAddress,
  604. (void **)&pPostalAddress
  605. );
  606. BAIL_ON_FAILURE(hr);
  607. aBound.lLbound = 0;
  608. aBound.cElements = 6;
  609. aList = SafeArrayCreate( VT_VARIANT, 1, &aBound );
  610. if ( aList == NULL ) {
  611. hr = E_OUTOFMEMORY;
  612. BAIL_ON_FAILURE(hr);
  613. }
  614. for ( i = 0; i < (long) 6; i++ ) {
  615. VariantInit(&varElement);
  616. varElement.vt = VT_BSTR;
  617. hr = ADsAllocString(
  618. lpNdsSrcObject->NdsValue.value_18.PostalAddress[i],
  619. &varElement.bstrVal
  620. );
  621. BAIL_ON_FAILURE(hr);
  622. hr = SafeArrayPutElement( aList, &i, &varElement);
  623. BAIL_ON_FAILURE(hr);
  624. VariantClear(&varElement);
  625. }
  626. V_VT(&VarDestObject) = VT_ARRAY | VT_VARIANT;
  627. V_ARRAY(&VarDestObject) = aList;
  628. hr = pPostalAddress->put_PostalAddress(VarDestObject);
  629. BAIL_ON_FAILURE(hr);
  630. hr = pPostalAddress->QueryInterface(IID_IDispatch, (void**)&pDispatch);
  631. BAIL_ON_FAILURE(hr);
  632. VariantInit(lpVarDestObject);
  633. V_VT(lpVarDestObject) = VT_DISPATCH;
  634. V_DISPATCH(lpVarDestObject) = pDispatch;
  635. error:
  636. if (aList)
  637. SafeArrayDestroy(aList);
  638. if (pPostalAddress) {
  639. pPostalAddress->Release();
  640. }
  641. RRETURN(hr);
  642. }
  643. HRESULT
  644. NdsTypeToVarTypeCopyNDSSynId19(
  645. PNDSOBJECT lpNdsSrcObject,
  646. PVARIANT lpVarDestObject
  647. )
  648. {
  649. IADsTimestamp * pTime = NULL;
  650. IDispatch * pDispatch = NULL;
  651. HRESULT hr = S_OK;
  652. hr = CTimestamp::CreateTimestamp(
  653. IID_IADsTimestamp,
  654. (void **)&pTime
  655. );
  656. BAIL_ON_FAILURE(hr);
  657. hr = pTime->put_WholeSeconds(lpNdsSrcObject->NdsValue.value_19.WholeSeconds);
  658. BAIL_ON_FAILURE(hr);
  659. hr = pTime->put_EventID(lpNdsSrcObject->NdsValue.value_19.EventID);
  660. BAIL_ON_FAILURE(hr);
  661. hr = pTime->QueryInterface(IID_IDispatch, (void**)&pDispatch);
  662. BAIL_ON_FAILURE(hr);
  663. VariantInit(lpVarDestObject);
  664. V_VT(lpVarDestObject) = VT_DISPATCH;
  665. V_DISPATCH(lpVarDestObject) = pDispatch;
  666. error:
  667. if (pTime) {
  668. pTime->Release();
  669. }
  670. RRETURN(hr);
  671. }
  672. HRESULT
  673. NdsTypeToVarTypeCopyNDSSynId20(
  674. PNDSOBJECT lpNdsSrcObject,
  675. PVARIANT lpVarDestObject
  676. )
  677. {
  678. HRESULT hr = S_OK;
  679. lpVarDestObject->vt = VT_BSTR;
  680. hr = ADsAllocString(
  681. lpNdsSrcObject->NdsValue.value_20.ClassName,
  682. &(lpVarDestObject->bstrVal)
  683. );
  684. RRETURN(hr);
  685. }
  686. HRESULT
  687. NdsTypeToVarTypeCopyNDSSynId21(
  688. PNDSOBJECT lpNdsSrcObject,
  689. PVARIANT lpVarDestObject
  690. )
  691. {
  692. HRESULT hr = S_OK;
  693. VariantInit(lpVarDestObject);
  694. hr = BinaryToVariant(
  695. lpNdsSrcObject->NdsValue.value_21.Length,
  696. lpNdsSrcObject->NdsValue.value_21.Data,
  697. lpVarDestObject);
  698. RRETURN(hr);
  699. }
  700. HRESULT
  701. NdsTypeToVarTypeCopyNDSSynId22(
  702. PNDSOBJECT lpNdsSrcObject,
  703. PVARIANT lpVarDestObject
  704. )
  705. {
  706. HRESULT hr = S_OK;
  707. lpVarDestObject->vt = VT_I4;
  708. lpVarDestObject->lVal =
  709. lpNdsSrcObject->NdsValue.value_22.Counter;
  710. RRETURN(hr);
  711. }
  712. HRESULT
  713. NdsTypeToVarTypeCopyNDSSynId23(
  714. PNDSOBJECT lpNdsSrcObject,
  715. PVARIANT lpVarDestObject
  716. )
  717. {
  718. IADsBackLink * pBackLink = NULL;
  719. IDispatch * pDispatch = NULL;
  720. HRESULT hr = S_OK;
  721. hr = CBackLink::CreateBackLink(
  722. IID_IADsBackLink,
  723. (void **)&pBackLink
  724. );
  725. BAIL_ON_FAILURE(hr);
  726. hr = pBackLink->put_ObjectName(lpNdsSrcObject->NdsValue.value_23.ObjectName);
  727. BAIL_ON_FAILURE(hr);
  728. hr = pBackLink->put_RemoteID(lpNdsSrcObject->NdsValue.value_23.RemoteID);
  729. BAIL_ON_FAILURE(hr);
  730. hr = pBackLink->QueryInterface(IID_IDispatch, (void**)&pDispatch);
  731. BAIL_ON_FAILURE(hr);
  732. VariantInit(lpVarDestObject);
  733. V_VT(lpVarDestObject) = VT_DISPATCH;
  734. V_DISPATCH(lpVarDestObject) = pDispatch;
  735. error:
  736. if (pBackLink) {
  737. pBackLink->Release();
  738. }
  739. RRETURN(hr);
  740. }
  741. HRESULT
  742. NdsTypeToVarTypeCopyNDSSynId24(
  743. PNDSOBJECT lpNdsSrcObject,
  744. PVARIANT lpVarDestObject
  745. )
  746. {
  747. HRESULT hr = S_OK;
  748. lpVarDestObject->vt = VT_DATE;
  749. hr = ConvertDWORDtoDATE(
  750. lpNdsSrcObject->NdsValue.value_24.Time,
  751. &(lpVarDestObject->date),
  752. TRUE
  753. );
  754. RRETURN(hr);
  755. }
  756. HRESULT
  757. NdsTypeToVarTypeCopyNDSSynId25(
  758. PNDSOBJECT lpNdsSrcObject,
  759. PVARIANT lpVarDestObject
  760. )
  761. {
  762. IADsTypedName * pTypedName = NULL;
  763. IDispatch * pDispatch = NULL;
  764. HRESULT hr = S_OK;
  765. hr = CTypedName::CreateTypedName(
  766. IID_IADsTypedName,
  767. (void **)&pTypedName
  768. );
  769. BAIL_ON_FAILURE(hr);
  770. hr = pTypedName->put_ObjectName(lpNdsSrcObject->NdsValue.value_25.ObjectName);
  771. BAIL_ON_FAILURE(hr);
  772. hr = pTypedName->put_Level(lpNdsSrcObject->NdsValue.value_25.Level);
  773. BAIL_ON_FAILURE(hr);
  774. hr = pTypedName->put_Interval(lpNdsSrcObject->NdsValue.value_25.Interval);
  775. BAIL_ON_FAILURE(hr);
  776. hr = pTypedName->QueryInterface(IID_IDispatch, (void**)&pDispatch);
  777. BAIL_ON_FAILURE(hr);
  778. VariantInit(lpVarDestObject);
  779. V_VT(lpVarDestObject) = VT_DISPATCH;
  780. V_DISPATCH(lpVarDestObject) = pDispatch;
  781. error:
  782. if (pTypedName) {
  783. pTypedName->Release();
  784. }
  785. RRETURN(hr);
  786. }
  787. HRESULT
  788. NdsTypeToVarTypeCopyNDSSynId26(
  789. PNDSOBJECT lpNdsSrcObject,
  790. PVARIANT lpVarDestObject
  791. )
  792. {
  793. IADsHold * pHold = NULL;
  794. IDispatch * pDispatch = NULL;
  795. HRESULT hr = S_OK;
  796. hr = CHold::CreateHold(
  797. IID_IADsHold,
  798. (void **)&pHold
  799. );
  800. BAIL_ON_FAILURE(hr);
  801. hr = pHold->put_ObjectName(lpNdsSrcObject->NdsValue.value_26.ObjectName);
  802. BAIL_ON_FAILURE(hr);
  803. hr = pHold->put_Amount(lpNdsSrcObject->NdsValue.value_26.Amount);
  804. BAIL_ON_FAILURE(hr);
  805. hr = pHold->QueryInterface(IID_IDispatch, (void**)&pDispatch);
  806. BAIL_ON_FAILURE(hr);
  807. VariantInit(lpVarDestObject);
  808. V_VT(lpVarDestObject) = VT_DISPATCH;
  809. V_DISPATCH(lpVarDestObject) = pDispatch;
  810. error:
  811. if (pHold) {
  812. pHold->Release();
  813. }
  814. RRETURN(hr);
  815. }
  816. HRESULT
  817. NdsTypeToVarTypeCopyNDSSynId27(
  818. PNDSOBJECT lpNdsSrcObject,
  819. PVARIANT lpVarDestObject
  820. )
  821. {
  822. HRESULT hr = S_OK;
  823. lpVarDestObject->vt = VT_I4;
  824. lpVarDestObject->lVal =
  825. lpNdsSrcObject->NdsValue.value_27.Interval;
  826. RRETURN(hr);
  827. }
  828. HRESULT
  829. NdsTypeToVarTypeCopy(
  830. PNDSOBJECT lpNdsSrcObject,
  831. PVARIANT lpVarDestObject
  832. )
  833. {
  834. HRESULT hr = S_OK;
  835. switch (lpNdsSrcObject->NdsType) {
  836. case 1:
  837. hr = NdsTypeToVarTypeCopyNDSSynId1(
  838. lpNdsSrcObject,
  839. lpVarDestObject
  840. );
  841. break;
  842. case 2:
  843. hr = NdsTypeToVarTypeCopyNDSSynId2(
  844. lpNdsSrcObject,
  845. lpVarDestObject
  846. );
  847. break;
  848. case 3:
  849. hr = NdsTypeToVarTypeCopyNDSSynId3(
  850. lpNdsSrcObject,
  851. lpVarDestObject
  852. );
  853. break;
  854. case 4:
  855. hr = NdsTypeToVarTypeCopyNDSSynId4(
  856. lpNdsSrcObject,
  857. lpVarDestObject
  858. );
  859. break;
  860. case 5:
  861. hr = NdsTypeToVarTypeCopyNDSSynId5(
  862. lpNdsSrcObject,
  863. lpVarDestObject
  864. );
  865. break;
  866. case 6:
  867. hr = NdsTypeToVarTypeCopyNDSSynId6(
  868. lpNdsSrcObject,
  869. lpVarDestObject
  870. );
  871. break;
  872. case 7:
  873. hr = NdsTypeToVarTypeCopyNDSSynId7(
  874. lpNdsSrcObject,
  875. lpVarDestObject
  876. );
  877. break;
  878. case 8:
  879. hr = NdsTypeToVarTypeCopyNDSSynId8(
  880. lpNdsSrcObject,
  881. lpVarDestObject
  882. );
  883. break;
  884. case 9:
  885. hr = NdsTypeToVarTypeCopyNDSSynId9(
  886. lpNdsSrcObject,
  887. lpVarDestObject
  888. );
  889. break;
  890. case 10:
  891. hr = NdsTypeToVarTypeCopyNDSSynId10(
  892. lpNdsSrcObject,
  893. lpVarDestObject
  894. );
  895. break;
  896. case 11:
  897. hr = NdsTypeToVarTypeCopyNDSSynId11(
  898. lpNdsSrcObject,
  899. lpVarDestObject
  900. );
  901. break;
  902. case 12:
  903. hr = NdsTypeToVarTypeCopyNDSSynId12(
  904. lpNdsSrcObject,
  905. lpVarDestObject
  906. );
  907. break;
  908. case 13:
  909. hr = NdsTypeToVarTypeCopyNDSSynId13(
  910. lpNdsSrcObject,
  911. lpVarDestObject
  912. );
  913. break;
  914. case 14:
  915. hr = NdsTypeToVarTypeCopyNDSSynId14(
  916. lpNdsSrcObject,
  917. lpVarDestObject
  918. );
  919. break;
  920. case 15:
  921. hr = NdsTypeToVarTypeCopyNDSSynId15(
  922. lpNdsSrcObject,
  923. lpVarDestObject
  924. );
  925. break;
  926. case 16:
  927. hr = NdsTypeToVarTypeCopyNDSSynId16(
  928. lpNdsSrcObject,
  929. lpVarDestObject
  930. );
  931. break;
  932. case 17:
  933. hr = NdsTypeToVarTypeCopyNDSSynId17(
  934. lpNdsSrcObject,
  935. lpVarDestObject
  936. );
  937. break;
  938. case 18:
  939. hr = NdsTypeToVarTypeCopyNDSSynId18(
  940. lpNdsSrcObject,
  941. lpVarDestObject
  942. );
  943. break;
  944. case 19:
  945. hr = NdsTypeToVarTypeCopyNDSSynId19(
  946. lpNdsSrcObject,
  947. lpVarDestObject
  948. );
  949. break;
  950. case 20:
  951. hr = NdsTypeToVarTypeCopyNDSSynId20(
  952. lpNdsSrcObject,
  953. lpVarDestObject
  954. );
  955. break;
  956. case 21:
  957. hr = NdsTypeToVarTypeCopyNDSSynId21(
  958. lpNdsSrcObject,
  959. lpVarDestObject
  960. );
  961. break;
  962. case 22:
  963. hr = NdsTypeToVarTypeCopyNDSSynId22(
  964. lpNdsSrcObject,
  965. lpVarDestObject
  966. );
  967. break;
  968. case 23:
  969. hr = NdsTypeToVarTypeCopyNDSSynId23(
  970. lpNdsSrcObject,
  971. lpVarDestObject
  972. );
  973. break;
  974. case 24:
  975. hr = NdsTypeToVarTypeCopyNDSSynId24(
  976. lpNdsSrcObject,
  977. lpVarDestObject
  978. );
  979. break;
  980. case 25:
  981. hr = NdsTypeToVarTypeCopyNDSSynId25(
  982. lpNdsSrcObject,
  983. lpVarDestObject
  984. );
  985. break;
  986. case 26:
  987. hr = NdsTypeToVarTypeCopyNDSSynId26(
  988. lpNdsSrcObject,
  989. lpVarDestObject
  990. );
  991. break;
  992. case 27:
  993. hr = NdsTypeToVarTypeCopyNDSSynId27(
  994. lpNdsSrcObject,
  995. lpVarDestObject
  996. );
  997. break;
  998. default:
  999. hr = E_FAIL;
  1000. break;
  1001. }
  1002. RRETURN(hr);
  1003. }
  1004. HRESULT
  1005. NdsTypeToVarTypeCopyConstruct(
  1006. LPNDSOBJECT pNdsSrcObjects,
  1007. DWORD dwNumObjects,
  1008. PVARIANT pVarDestObjects,
  1009. BOOLEAN bReturnArrayAlways
  1010. )
  1011. {
  1012. long i = 0;
  1013. HRESULT hr = S_OK;
  1014. VARIANT VarDestObjectsTemp;
  1015. SAFEARRAY *aList = NULL;
  1016. SAFEARRAY *aListTmp = NULL;
  1017. if ((pNdsSrcObjects->NdsType == 17) || (dwNumObjects > 1) || bReturnArrayAlways) {
  1018. VariantInit(pVarDestObjects);
  1019. //
  1020. // The following are for handling are multi-value properties
  1021. //
  1022. SAFEARRAYBOUND aBound;
  1023. aBound.lLbound = 0;
  1024. aBound.cElements = dwNumObjects;
  1025. aList = SafeArrayCreate( VT_VARIANT, 1, &aBound );
  1026. if ( aList == NULL )
  1027. {
  1028. hr = E_OUTOFMEMORY;
  1029. BAIL_ON_FAILURE(hr);
  1030. }
  1031. for ( i = 0; i < (long) dwNumObjects; i++ )
  1032. {
  1033. VARIANT v;
  1034. VariantInit(&v);
  1035. hr = NdsTypeToVarTypeCopy( pNdsSrcObjects + i,
  1036. &v );
  1037. BAIL_ON_FAILURE(hr);
  1038. hr = SafeArrayPutElement( aList, &i, &v );
  1039. VariantClear(&v);
  1040. BAIL_ON_FAILURE(hr);
  1041. }
  1042. V_VT(pVarDestObjects) = VT_ARRAY | VT_VARIANT;
  1043. V_ARRAY(pVarDestObjects) = aList;
  1044. //
  1045. // If it is an NDS ACL, we will convert it into an
  1046. // NT Security Descriptor
  1047. //
  1048. if (pNdsSrcObjects->NdsType == 17) {
  1049. hr = ConvertNDSAclVArrayToSecDesVar(pVarDestObjects,
  1050. &VarDestObjectsTemp);
  1051. SafeArrayDestroy( aList );
  1052. aList = NULL;
  1053. if (!bReturnArrayAlways) {
  1054. V_VT(pVarDestObjects) = V_VT(&VarDestObjectsTemp);
  1055. V_DISPATCH(pVarDestObjects) = V_DISPATCH(&VarDestObjectsTemp);
  1056. }
  1057. else {
  1058. //
  1059. // Pack SecDescriptor into a one-element array
  1060. //
  1061. SAFEARRAYBOUND aBoundTmp;
  1062. long j = 0;
  1063. aBoundTmp.lLbound = 0;
  1064. aBoundTmp.cElements = 1;
  1065. aListTmp = SafeArrayCreate( VT_VARIANT, 1, &aBoundTmp);
  1066. if ( aListTmp == NULL )
  1067. {
  1068. hr = E_OUTOFMEMORY;
  1069. BAIL_ON_FAILURE(hr);
  1070. }
  1071. hr = SafeArrayPutElement( aListTmp, &j, &VarDestObjectsTemp);
  1072. BAIL_ON_FAILURE(hr);
  1073. V_VT(pVarDestObjects) = VT_ARRAY | VT_VARIANT;
  1074. V_ARRAY(pVarDestObjects) = aListTmp;
  1075. }
  1076. }
  1077. }
  1078. else {
  1079. hr = NdsTypeToVarTypeCopy(
  1080. pNdsSrcObjects,
  1081. pVarDestObjects
  1082. );
  1083. }
  1084. BAIL_ON_FAILURE(hr);
  1085. RRETURN(hr);
  1086. error:
  1087. if ( aList ) {
  1088. SafeArrayDestroy( aList );
  1089. }
  1090. if ( aListTmp ) {
  1091. SafeArrayDestroy( aListTmp );
  1092. }
  1093. RRETURN(hr);
  1094. }