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.

419 lines
10 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996 - 1997.
  5. //
  6. // File: iismrshl.cxx
  7. //
  8. // Contents: IIS marshalling code
  9. //
  10. // Functions:
  11. //
  12. // History: 27-Feb-97 Sophiac Created.
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "iis.hxx"
  16. #define MAX_PATH_MULTISZ_STRING 256
  17. #define MAX_PATH_MIMEMAP_STRING 100
  18. PMETADATA_RECORD
  19. CopyIISSynIdDWORD_To_IISDWORD(
  20. IIsSchema *pSchema,
  21. DWORD dwMetaId,
  22. PMETADATA_RECORD pMetaDataRec,
  23. PIISOBJECT lpIISObject
  24. )
  25. {
  26. DWORD dwAttribute = ALL_METADATA;
  27. DWORD dwUserType = ALL_METADATA;
  28. pSchema->LookupMDFlags(dwMetaId, &dwAttribute, &dwUserType);
  29. pMetaDataRec->dwMDIdentifier = dwMetaId;
  30. pMetaDataRec->dwMDAttributes = dwAttribute;
  31. pMetaDataRec->dwMDUserType = dwUserType;
  32. pMetaDataRec->dwMDDataType = DWORD_METADATA;
  33. pMetaDataRec->dwMDDataLen = sizeof(DWORD);
  34. pMetaDataRec->pbMDData = (LPBYTE)&(lpIISObject->IISValue.value_1.dwDWORD);
  35. return(pMetaDataRec);
  36. }
  37. PMETADATA_RECORD
  38. CopyIISSynIdSTRING_To_IISSTRING(
  39. IIsSchema *pSchema,
  40. DWORD dwMetaId,
  41. PMETADATA_RECORD pMetaDataRec,
  42. PIISOBJECT lpIISObject
  43. )
  44. {
  45. DWORD dwStatus = 0;
  46. DWORD dwAttribute = ALL_METADATA;
  47. DWORD dwUserType = ALL_METADATA;
  48. LPWSTR pszData = NULL;
  49. pSchema->LookupMDFlags(dwMetaId, &dwAttribute, &dwUserType);
  50. pMetaDataRec->dwMDIdentifier = dwMetaId;
  51. pMetaDataRec->dwMDAttributes = dwAttribute;
  52. pMetaDataRec->dwMDUserType = dwUserType;
  53. pMetaDataRec->dwMDDataType = STRING_METADATA;
  54. pMetaDataRec->dwMDDataLen = 0;
  55. if (lpIISObject) {
  56. pszData = AllocADsStr((LPWSTR)lpIISObject->IISValue.value_2.String);
  57. if (!pszData) {
  58. return(pMetaDataRec);
  59. }
  60. pMetaDataRec->dwMDDataLen = ((DWORD)wcslen(pszData) + 1)*2;
  61. }
  62. pMetaDataRec->pbMDData = (LPBYTE)pszData;
  63. return(pMetaDataRec);
  64. }
  65. PMETADATA_RECORD
  66. CopyIISSynIdEXPANDSZ_To_IISEXPANDSZ(
  67. IIsSchema *pSchema,
  68. DWORD dwMetaId,
  69. PMETADATA_RECORD pMetaDataRec,
  70. PIISOBJECT lpIISObject
  71. )
  72. {
  73. DWORD dwStatus = 0;
  74. DWORD dwAttribute = ALL_METADATA;
  75. DWORD dwUserType = ALL_METADATA;
  76. LPWSTR pszData = NULL;
  77. pSchema->LookupMDFlags(dwMetaId, &dwAttribute, &dwUserType);
  78. pMetaDataRec->dwMDIdentifier = dwMetaId;
  79. pMetaDataRec->dwMDAttributes = dwAttribute;
  80. pMetaDataRec->dwMDUserType = dwUserType;
  81. pMetaDataRec->dwMDDataType = EXPANDSZ_METADATA;
  82. pMetaDataRec->dwMDDataLen = 0;
  83. if (lpIISObject) {
  84. pszData = AllocADsStr((LPWSTR)lpIISObject->IISValue.value_3.ExpandSz);
  85. if (!pszData) {
  86. return(pMetaDataRec);
  87. }
  88. pMetaDataRec->dwMDDataLen = ((DWORD)wcslen(pszData) + 1)*2;
  89. }
  90. pMetaDataRec->pbMDData = (LPBYTE)pszData;
  91. return(pMetaDataRec);
  92. }
  93. PMETADATA_RECORD
  94. CopyIISSynIdMULTISZ_To_IISMULTISZ(
  95. IIsSchema *pSchema,
  96. DWORD dwMetaId,
  97. PMETADATA_RECORD pMetaDataRec,
  98. PIISOBJECT lpIISObject,
  99. DWORD dwNumValues
  100. )
  101. {
  102. DWORD dwStatus = 0;
  103. DWORD i;
  104. DWORD dwAttribute = ALL_METADATA;
  105. DWORD dwUserType = ALL_METADATA;
  106. LPWSTR pszStr = NULL;
  107. LPWSTR pszData = NULL;
  108. pSchema->LookupMDFlags(dwMetaId, &dwAttribute, &dwUserType);
  109. pMetaDataRec->dwMDIdentifier = dwMetaId;
  110. pMetaDataRec->dwMDAttributes = dwAttribute;
  111. pMetaDataRec->dwMDUserType = dwUserType;
  112. pMetaDataRec->dwMDDataType = MULTISZ_METADATA;
  113. pMetaDataRec->dwMDDataLen = 0;
  114. //
  115. // Calculate buffer length to allocate
  116. //
  117. for (i = 0; i < dwNumValues; i++) {
  118. pszData = (LPWSTR)lpIISObject[i].IISValue.value_4.MultiSz;
  119. pMetaDataRec->dwMDDataLen += ((DWORD)wcslen(pszData) + 1)*2;
  120. }
  121. //
  122. // +2 for the extra null terminator
  123. //
  124. pszStr = (LPWSTR) AllocADsMem(pMetaDataRec->dwMDDataLen + 2);
  125. if (pszStr == NULL) {
  126. return(pMetaDataRec);
  127. }
  128. //
  129. // empty contents
  130. //
  131. wcscpy(pszStr, L"");
  132. pMetaDataRec->pbMDData = (LPBYTE)pszStr;
  133. for (i = 0; i < dwNumValues; i++) {
  134. pszData = (LPWSTR)lpIISObject[i].IISValue.value_4.MultiSz;
  135. wcscat(pszStr, pszData);
  136. pszStr += wcslen(pszData);
  137. *pszStr = L'\0';
  138. pszStr++;
  139. }
  140. *pszStr = L'\0';
  141. pMetaDataRec->dwMDDataLen += 2;
  142. return(pMetaDataRec);
  143. }
  144. PMETADATA_RECORD
  145. CopyIISSynIdBINARY_To_IISBINARY(
  146. IIsSchema *pSchema,
  147. DWORD dwMetaId,
  148. PMETADATA_RECORD pMetaDataRec,
  149. PIISOBJECT lpIISObject
  150. )
  151. {
  152. DWORD dwStatus = 0;
  153. DWORD dwAttribute = ALL_METADATA;
  154. DWORD dwUserType = ALL_METADATA;
  155. LPBYTE pBuffer = NULL;
  156. pSchema->LookupMDFlags(dwMetaId, &dwAttribute, &dwUserType);
  157. pMetaDataRec->dwMDIdentifier = dwMetaId;
  158. pMetaDataRec->dwMDAttributes = dwAttribute;
  159. pMetaDataRec->dwMDUserType = dwUserType;
  160. pMetaDataRec->dwMDDataType = BINARY_METADATA;
  161. pMetaDataRec->dwMDDataLen = 0;
  162. pBuffer = (LPBYTE) AllocADsMem(
  163. lpIISObject->IISValue.value_5.Length);
  164. if (!pBuffer) {
  165. return(pMetaDataRec);
  166. }
  167. memcpy(pBuffer,
  168. lpIISObject->IISValue.value_5.Binary,
  169. lpIISObject->IISValue.value_5.Length);
  170. pMetaDataRec->pbMDData = (LPBYTE)pBuffer;
  171. pMetaDataRec->dwMDDataLen = lpIISObject->IISValue.value_5.Length;
  172. return(pMetaDataRec);
  173. }
  174. PMETADATA_RECORD
  175. CopyIISSynIdMIMEMAP_To_IISMIMEMAP(
  176. IIsSchema *pSchema,
  177. DWORD dwMetaId,
  178. PMETADATA_RECORD pMetaDataRec,
  179. PIISOBJECT lpIISObject,
  180. DWORD dwNumValues
  181. )
  182. {
  183. DWORD dwStatus = 0;
  184. DWORD i;
  185. DWORD dwAttribute = ALL_METADATA;
  186. DWORD dwUserType = ALL_METADATA;
  187. LPWSTR pszData = NULL;
  188. LPWSTR pszStr = NULL;
  189. pSchema->LookupMDFlags(dwMetaId, &dwAttribute, &dwUserType);
  190. pMetaDataRec->dwMDIdentifier = dwMetaId;
  191. pMetaDataRec->dwMDAttributes = dwAttribute;
  192. pMetaDataRec->dwMDUserType = dwUserType;
  193. pMetaDataRec->dwMDDataType = MULTISZ_METADATA;
  194. pMetaDataRec->dwMDDataLen = 0;
  195. //
  196. // Calculate buffer length to allocate
  197. //
  198. for (i = 0; i < dwNumValues; i++) {
  199. pszData = (LPWSTR)lpIISObject[i].IISValue.value_4.MultiSz;
  200. pMetaDataRec->dwMDDataLen += ((DWORD)wcslen(pszData) + 1)*2;
  201. }
  202. //
  203. // +2 for the extra null terminator
  204. //
  205. pszStr = (LPWSTR) AllocADsMem(pMetaDataRec->dwMDDataLen + 2);
  206. if (pszStr == NULL) {
  207. return(pMetaDataRec);
  208. }
  209. //
  210. // empty contents
  211. //
  212. wcscpy(pszStr, L"");
  213. pMetaDataRec->pbMDData = (LPBYTE)pszStr;
  214. for (i = 0; i < dwNumValues; i++) {
  215. pszData = (LPWSTR)lpIISObject[i].IISValue.value_4.MultiSz;
  216. wcscat(pszStr, pszData);
  217. pszStr += wcslen(pszData);
  218. *pszStr = L'\0';
  219. pszStr++;
  220. }
  221. *pszStr = L'\0';
  222. pMetaDataRec->dwMDDataLen += 2;
  223. return(pMetaDataRec);
  224. }
  225. PMETADATA_RECORD
  226. CopyIISSynIdBOOL_To_IISBOOL(
  227. IIsSchema *pSchema,
  228. DWORD dwMetaId,
  229. PMETADATA_RECORD pMetaDataRec,
  230. PIISOBJECT lpIISObject
  231. )
  232. {
  233. DWORD dwAttribute = ALL_METADATA;
  234. DWORD dwUserType = ALL_METADATA;
  235. pSchema->LookupMDFlags(dwMetaId, &dwAttribute, &dwUserType);
  236. pMetaDataRec->dwMDIdentifier = dwMetaId;
  237. pMetaDataRec->dwMDAttributes = dwAttribute;
  238. pMetaDataRec->dwMDUserType = dwUserType;
  239. pMetaDataRec->dwMDDataType = DWORD_METADATA;
  240. pMetaDataRec->dwMDDataLen = sizeof(DWORD);
  241. pMetaDataRec->pbMDData = (LPBYTE)&(lpIISObject->IISValue.value_1.dwDWORD);
  242. return(pMetaDataRec);
  243. }
  244. PMETADATA_RECORD
  245. CopyIISSynIdToIIS(
  246. IIsSchema *pSchema,
  247. DWORD dwSyntaxId,
  248. DWORD dwMetaId,
  249. PMETADATA_RECORD pMetaDataRec,
  250. PIISOBJECT lpIISObject,
  251. DWORD dwNumValues
  252. )
  253. {
  254. switch (dwSyntaxId) {
  255. case IIS_SYNTAX_ID_DWORD:
  256. pMetaDataRec = CopyIISSynIdDWORD_To_IISDWORD(
  257. pSchema,
  258. dwMetaId,
  259. pMetaDataRec,
  260. lpIISObject
  261. );
  262. break;
  263. case IIS_SYNTAX_ID_STRING:
  264. pMetaDataRec = CopyIISSynIdSTRING_To_IISSTRING(
  265. pSchema,
  266. dwMetaId,
  267. pMetaDataRec,
  268. lpIISObject
  269. );
  270. break;
  271. case IIS_SYNTAX_ID_EXPANDSZ:
  272. pMetaDataRec = CopyIISSynIdEXPANDSZ_To_IISEXPANDSZ(
  273. pSchema,
  274. dwMetaId,
  275. pMetaDataRec,
  276. lpIISObject
  277. );
  278. break;
  279. case IIS_SYNTAX_ID_MULTISZ:
  280. pMetaDataRec = CopyIISSynIdMULTISZ_To_IISMULTISZ(
  281. pSchema,
  282. dwMetaId,
  283. pMetaDataRec,
  284. lpIISObject,
  285. dwNumValues
  286. );
  287. break;
  288. case IIS_SYNTAX_ID_BINARY:
  289. case IIS_SYNTAX_ID_IPSECLIST:
  290. case IIS_SYNTAX_ID_NTACL:
  291. pMetaDataRec = CopyIISSynIdBINARY_To_IISBINARY(
  292. pSchema,
  293. dwMetaId,
  294. pMetaDataRec,
  295. lpIISObject
  296. );
  297. break;
  298. case IIS_SYNTAX_ID_MIMEMAP:
  299. pMetaDataRec = CopyIISSynIdMIMEMAP_To_IISMIMEMAP(
  300. pSchema,
  301. dwMetaId,
  302. pMetaDataRec,
  303. lpIISObject,
  304. dwNumValues
  305. );
  306. break;
  307. case IIS_SYNTAX_ID_BOOL:
  308. case IIS_SYNTAX_ID_BOOL_BITMASK:
  309. pMetaDataRec = CopyIISSynIdBOOL_To_IISBOOL(
  310. pSchema,
  311. dwMetaId,
  312. pMetaDataRec,
  313. lpIISObject
  314. );
  315. break;
  316. default:
  317. break;
  318. }
  319. return(pMetaDataRec);
  320. }
  321. HRESULT
  322. MarshallIISSynIdToIIS(
  323. IIsSchema *pSchema,
  324. DWORD dwSyntaxId,
  325. DWORD dwMDIdentifier,
  326. PIISOBJECT pIISObject,
  327. DWORD dwNumValues,
  328. PMETADATA_RECORD pMetaDataRecord
  329. )
  330. {
  331. CopyIISSynIdToIIS(
  332. pSchema,
  333. dwSyntaxId,
  334. dwMDIdentifier,
  335. pMetaDataRecord,
  336. pIISObject,
  337. dwNumValues
  338. );
  339. RRETURN(S_OK);
  340. }