Source code of Windows XP (NT5)
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.

237 lines
4.7 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995.
  5. //
  6. // File: nw2ods.cxx
  7. //
  8. // Contents: NDS Object to Variant Copy Routines
  9. //
  10. // Functions:
  11. //
  12. // History: 25-Apr-96 KrishnaG Created.
  13. //
  14. //
  15. // Issues: Check null ptrs for AllocADsMem and AllocADsStr
  16. //
  17. //----------------------------------------------------------------------------
  18. #include "winnt.hxx"
  19. #pragma hdrstop
  20. HRESULT
  21. NTTypeToAdsTypeCopyString(
  22. PNTOBJECT lpNtSrcObject,
  23. PADSVALUE lpAdsDestValue
  24. )
  25. {
  26. HRESULT hr = S_OK;
  27. lpAdsDestValue->dwType = ADSTYPE_CASE_IGNORE_STRING;
  28. lpAdsDestValue->DNString =
  29. AllocADsStr(
  30. lpNtSrcObject->NTValue.pszValue
  31. );
  32. RRETURN(hr);
  33. }
  34. HRESULT
  35. NTTypeToAdsTypeCopyBoolean(
  36. PNTOBJECT lpNtSrcObject,
  37. PADSVALUE lpAdsDestValue
  38. )
  39. {
  40. HRESULT hr = S_OK;
  41. lpAdsDestValue->dwType = ADSTYPE_BOOLEAN;
  42. lpAdsDestValue->Boolean =
  43. lpNtSrcObject->NTValue.fValue;
  44. RRETURN(hr);
  45. }
  46. HRESULT
  47. NTTypeToAdsTypeCopyInteger(
  48. PNTOBJECT lpNtSrcObject,
  49. PADSVALUE lpAdsDestValue
  50. )
  51. {
  52. HRESULT hr = S_OK;
  53. lpAdsDestValue->dwType = ADSTYPE_INTEGER;
  54. lpAdsDestValue->Integer =
  55. lpNtSrcObject->NTValue.dwValue;
  56. RRETURN(hr);
  57. }
  58. HRESULT
  59. NTTypeToAdsTypeCopyOctetString(
  60. PNTOBJECT lpNtSrcObject,
  61. PADSVALUE lpAdsDestValue
  62. )
  63. {
  64. HRESULT hr = S_OK;
  65. DWORD dwLen = 0;
  66. lpAdsDestValue->dwType = ADSTYPE_OCTET_STRING;
  67. dwLen = lpNtSrcObject->NTValue.octetstring.dwSize;
  68. lpAdsDestValue->OctetString.dwLength = dwLen;
  69. if (lpNtSrcObject->NTValue.octetstring.pByte) {
  70. lpAdsDestValue->OctetString.lpValue = (LPBYTE) AllocADsMem(dwLen);
  71. if (!lpAdsDestValue->OctetString.lpValue) {
  72. BAIL_ON_FAILURE(hr = E_OUTOFMEMORY);
  73. }
  74. memcpy(
  75. lpAdsDestValue->OctetString.lpValue,
  76. lpNtSrcObject->NTValue.octetstring.pByte,
  77. dwLen
  78. );
  79. }
  80. else {
  81. lpAdsDestValue->OctetString.lpValue = NULL;
  82. }
  83. error:
  84. RRETURN(hr);
  85. }
  86. HRESULT
  87. NTTypeToAdsTypeCopy(
  88. PNTOBJECT lpNtSrcObject,
  89. PADSVALUE lpAdsDestValue
  90. )
  91. {
  92. HRESULT hr = S_OK;
  93. switch (lpNtSrcObject->NTType) {
  94. case NT_SYNTAX_ID_BOOL:
  95. hr = NTTypeToAdsTypeCopyBoolean(
  96. lpNtSrcObject,
  97. lpAdsDestValue
  98. );
  99. break;
  100. case NT_SYNTAX_ID_DWORD:
  101. hr = NTTypeToAdsTypeCopyInteger(
  102. lpNtSrcObject,
  103. lpAdsDestValue
  104. );
  105. break;
  106. case NT_SYNTAX_ID_LPTSTR:
  107. hr = NTTypeToAdsTypeCopyString(
  108. lpNtSrcObject,
  109. lpAdsDestValue
  110. );
  111. break;
  112. case NT_SYNTAX_ID_DelimitedString:
  113. hr = NTTypeToAdsTypeCopyString(
  114. lpNtSrcObject,
  115. lpAdsDestValue
  116. );
  117. break;
  118. case NT_SYNTAX_ID_OCTETSTRING:
  119. hr = NTTypeToAdsTypeCopyOctetString(
  120. lpNtSrcObject,
  121. lpAdsDestValue
  122. );
  123. break;
  124. /*
  125. case NT_SYNTAX_ID_SYSTEMTIME:
  126. case NT_SYNTAX_ID_DATE:
  127. case NT_SYNTAX_ID_NW312TIME:
  128. hr = NTTypeToAdsTypeCopyNDSSynId4(
  129. lpNtSrcObject,
  130. lpAdsDestValue
  131. );
  132. break;
  133. case NT_SYNTAX_ID_NulledString:
  134. hr = NTTypeToAdsTypeCopyNDSSynId5(
  135. lpNtSrcObject,
  136. lpAdsDestValue
  137. );
  138. break;
  139. */
  140. default:
  141. hr = E_FAIL;
  142. break;
  143. }
  144. RRETURN(hr);
  145. }
  146. HRESULT
  147. NTTypeToAdsTypeCopyConstruct(
  148. LPNTOBJECT pNtSrcObjects,
  149. DWORD dwNumObjects,
  150. LPADSVALUE * ppAdsDestValues
  151. )
  152. {
  153. DWORD i = 0;
  154. LPADSVALUE pAdsDestValues = NULL;
  155. HRESULT hr = S_OK;
  156. if (!dwNumObjects) {
  157. *ppAdsDestValues = NULL;
  158. RRETURN(S_OK);
  159. }
  160. pAdsDestValues = (LPADSVALUE)AllocADsMem(
  161. dwNumObjects * sizeof(ADSVALUE)
  162. );
  163. if (!pAdsDestValues) {
  164. RRETURN(E_OUTOFMEMORY);
  165. }
  166. for (i = 0; i < dwNumObjects; i++ ) {
  167. hr = NTTypeToAdsTypeCopy(
  168. pNtSrcObjects + i,
  169. pAdsDestValues + i
  170. );
  171. BAIL_ON_FAILURE(hr);
  172. }
  173. *ppAdsDestValues = pAdsDestValues;
  174. RRETURN(S_OK);
  175. error:
  176. if (pAdsDestValues) {
  177. AdsFreeAdsValues(
  178. pAdsDestValues,
  179. dwNumObjects
  180. );
  181. FreeADsMem(pAdsDestValues);
  182. }
  183. *ppAdsDestValues = NULL;
  184. RRETURN(hr);
  185. }