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.

360 lines
7.1 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 "nwcompat.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 dwLength = 0;
  66. LPBYTE lpByte = NULL;
  67. // sanity check the pointers
  68. if(!lpAdsDestValue){
  69. RRETURN(E_POINTER);
  70. }
  71. if(!lpNtSrcObject){
  72. RRETURN(E_POINTER);
  73. }
  74. lpAdsDestValue->dwType = ADSTYPE_OCTET_STRING;
  75. dwLength = lpNtSrcObject->NTValue.octetstring.dwSize;
  76. if (dwLength) {
  77. lpByte = (LPBYTE)AllocADsMem(dwLength);
  78. if (!lpByte) {
  79. hr = E_OUTOFMEMORY;
  80. BAIL_ON_FAILURE(hr);
  81. }
  82. if (lpNtSrcObject->NTValue.octetstring.pByte) {
  83. memcpy(lpByte, lpNtSrcObject->NTValue.octetstring.pByte, dwLength);
  84. }
  85. lpAdsDestValue->OctetString.dwLength = dwLength;
  86. lpAdsDestValue->OctetString.lpValue = lpByte;
  87. }
  88. else
  89. {
  90. lpAdsDestValue->OctetString.dwLength = 0;
  91. lpAdsDestValue->OctetString.lpValue = NULL;
  92. }
  93. error:
  94. RRETURN(hr);
  95. }
  96. HRESULT
  97. NTTypeToAdsTypeCopyNW312Date(
  98. PNTOBJECT pNTSrcValue,
  99. PADSVALUE lpAdsDestValue
  100. )
  101. {
  102. HRESULT hr = S_OK;
  103. // sanity check the pointers
  104. if(!lpAdsDestValue){
  105. RRETURN(E_POINTER);
  106. }
  107. if(!pNTSrcValue){
  108. RRETURN(E_POINTER);
  109. }
  110. lpAdsDestValue->dwType = ADSTYPE_UTC_TIME;
  111. hr = ConvertNW312DateToSYSTEMTIME(
  112. pNTSrcValue->NTValue.Nw312Date,
  113. static_cast<SYSTEMTIME*>(&lpAdsDestValue->UTCTime)
  114. );
  115. BAIL_ON_FAILURE(hr);
  116. error:
  117. RRETURN(hr);
  118. }
  119. HRESULT
  120. NTTypeToAdsTypeCopyDATE(
  121. PNTOBJECT pNTSrcValue,
  122. PADSVALUE lpAdsDestValue
  123. )
  124. {
  125. HRESULT hr = S_OK;
  126. SYSTEMTIME stSystemTime;
  127. // sanity check the pointers
  128. if(!lpAdsDestValue){
  129. RRETURN(E_POINTER);
  130. }
  131. if(!pNTSrcValue){
  132. RRETURN(E_POINTER);
  133. }
  134. GetSystemTime( &stSystemTime);
  135. // The date is a DWORD containing the number of minutes elapsed
  136. // since 12:00 AM GMT. We get the current system time for the
  137. // current date. Current date + DWORD time = the date relative
  138. // to today.
  139. stSystemTime.wHour = (WORD)(pNTSrcValue->NTValue.dwValue)/60;
  140. stSystemTime.wMinute = (WORD)(pNTSrcValue->NTValue.dwValue)%60;
  141. stSystemTime.wSecond =0;
  142. stSystemTime.wMilliseconds = 0;
  143. lpAdsDestValue->dwType = ADSTYPE_UTC_TIME;
  144. lpAdsDestValue->UTCTime = static_cast<ADS_UTC_TIME>(stSystemTime);
  145. RRETURN(hr);
  146. }
  147. #if 0
  148. // We never seem to actually get a NT_SYNTAX_ID_SYSTEMTIME.
  149. // This code is untested as a result.
  150. HRESULT
  151. NTTypeToAdsTypeCopySYSTEMTIME(
  152. PNTOBJECT pNTSrcValue,
  153. PADSVALUE lpAdsDestValue
  154. )
  155. {
  156. HRESULT hr = S_OK;
  157. if(!pNTSrcValue){
  158. RRETURN(E_POINTER);
  159. }
  160. if(!lpAdsDestValue){
  161. RRETURN(E_POINTER);
  162. }
  163. lpAdsDestValue->dwType = ADSTYPE_UTC_TIME;
  164. lpAdsDestValue->UTCTime = static_cast<ADS_UTC_TIME>
  165. (pNTSrcValue->NTValue.stSystemTimeValue);
  166. RRETURN(hr);
  167. }
  168. #endif
  169. HRESULT
  170. NTTypeToAdsTypeCopy(
  171. PNTOBJECT lpNtSrcObject,
  172. PADSVALUE lpAdsDestValue
  173. )
  174. {
  175. HRESULT hr = S_OK;
  176. switch (lpNtSrcObject->NTType) {
  177. case NT_SYNTAX_ID_BOOL:
  178. hr = NTTypeToAdsTypeCopyBoolean(
  179. lpNtSrcObject,
  180. lpAdsDestValue
  181. );
  182. break;
  183. case NT_SYNTAX_ID_DWORD:
  184. hr = NTTypeToAdsTypeCopyInteger(
  185. lpNtSrcObject,
  186. lpAdsDestValue
  187. );
  188. break;
  189. case NT_SYNTAX_ID_LPTSTR:
  190. hr = NTTypeToAdsTypeCopyString(
  191. lpNtSrcObject,
  192. lpAdsDestValue
  193. );
  194. break;
  195. /*
  196. case NT_SYNTAX_ID_SYSTEMTIME:
  197. hr = NTTypeToAdsTypeCopySYSTEMTIME(
  198. lpNtSrcObject,
  199. lpAdsDestValue
  200. );
  201. break;
  202. case NT_SYNTAX_ID_NulledString:
  203. hr = NTTypeToAdsTypeCopyNDSSynId5(
  204. lpNtSrcObject,
  205. lpAdsDestValue
  206. );
  207. break;
  208. case NT_SYNTAX_ID_DelimitedString:
  209. hr = NTTypeToAdsTypeCopyNDSSynId6(
  210. lpNtSrcObject,
  211. lpAdsDestValue
  212. );
  213. break;
  214. */
  215. case NT_SYNTAX_ID_DATE:
  216. hr = NTTypeToAdsTypeCopyDATE(
  217. lpNtSrcObject,
  218. lpAdsDestValue
  219. );
  220. break;
  221. case NT_SYNTAX_ID_NW312DATE:
  222. hr = NTTypeToAdsTypeCopyNW312Date(
  223. lpNtSrcObject,
  224. lpAdsDestValue
  225. );
  226. break;
  227. case NT_SYNTAX_ID_OCTETSTRING:
  228. hr = NTTypeToAdsTypeCopyOctetString(
  229. lpNtSrcObject,
  230. lpAdsDestValue
  231. );
  232. break;
  233. default:
  234. hr = E_FAIL;
  235. break;
  236. }
  237. RRETURN(hr);
  238. }
  239. HRESULT
  240. NTTypeToAdsTypeCopyConstruct(
  241. LPNTOBJECT pNtSrcObjects,
  242. DWORD dwNumObjects,
  243. LPADSVALUE * ppAdsDestValues
  244. )
  245. {
  246. DWORD i = 0;
  247. LPADSVALUE pAdsDestValues = NULL;
  248. HRESULT hr = S_OK;
  249. if (!dwNumObjects) {
  250. *ppAdsDestValues =0;
  251. RRETURN(S_OK);
  252. }
  253. pAdsDestValues = (LPADSVALUE)AllocADsMem(
  254. dwNumObjects * sizeof(ADSVALUE)
  255. );
  256. if (!pAdsDestValues) {
  257. RRETURN(E_OUTOFMEMORY);
  258. }
  259. for (i = 0; i < dwNumObjects; i++ ) {
  260. hr = NTTypeToAdsTypeCopy(
  261. pNtSrcObjects + i,
  262. pAdsDestValues + i
  263. );
  264. BAIL_ON_FAILURE(hr);
  265. }
  266. *ppAdsDestValues = pAdsDestValues;
  267. RRETURN(S_OK);
  268. error:
  269. if (pAdsDestValues) {
  270. AdsFreeAdsValues(
  271. pAdsDestValues,
  272. dwNumObjects
  273. );
  274. FreeADsMem(pAdsDestValues);
  275. }
  276. *ppAdsDestValues = NULL;
  277. RRETURN(hr);
  278. }