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.

285 lines
8.2 KiB

  1. // --------------------------------------------------------------------------------
  2. // AddressX.cpp
  3. // Copyright (c)1993-1995 Microsoft Corporation, All Rights Reserved
  4. // --------------------------------------------------------------------------------
  5. #include "pch.hxx"
  6. #include "AddressX.h"
  7. #include "dllmain.h"
  8. #include "internat.h"
  9. #include "mimeapi.h"
  10. #include "demand.h"
  11. // --------------------------------------------------------------------------------
  12. // EmptyAddressTokenW - Makes sure the pToken is empty
  13. // --------------------------------------------------------------------------------
  14. void EmptyAddressTokenW(LPADDRESSTOKENW pToken)
  15. {
  16. if (pToken->psz)
  17. *pToken->psz = L'\0';
  18. pToken->cch = 0;
  19. }
  20. // --------------------------------------------------------------------------------
  21. // FreeAddressTokenW
  22. // --------------------------------------------------------------------------------
  23. void FreeAddressTokenW(LPADDRESSTOKENW pToken)
  24. {
  25. if (pToken->psz && pToken->psz != (LPWSTR)pToken->rgbScratch)
  26. g_pMalloc->Free(pToken->psz);
  27. ZeroMemory(pToken, sizeof(ADDRESSTOKENW));
  28. }
  29. // --------------------------------------------------------------------------------
  30. // HrSetAddressTokenW
  31. // --------------------------------------------------------------------------------
  32. HRESULT HrSetAddressTokenW(LPCWSTR psz, ULONG cch, LPADDRESSTOKENW pToken)
  33. {
  34. // Locals
  35. HRESULT hr=S_OK;
  36. ULONG cbAlloc;
  37. LPWSTR pszNew;
  38. // Invalid Arg
  39. Assert(psz && psz[cch] == L'\0' && pToken);
  40. // cbAlloc is big enough
  41. if ((cch + 1) * sizeof(WCHAR) > pToken->cbAlloc)
  42. {
  43. // Use Static
  44. if (NULL == pToken->psz && ((cch + 1) * sizeof(WCHAR)) < sizeof(pToken->rgbScratch))
  45. {
  46. pToken->psz = (LPWSTR)pToken->rgbScratch;
  47. pToken->cbAlloc = sizeof(pToken->rgbScratch);
  48. }
  49. // Otherwise
  50. else
  51. {
  52. // If currently set to scratch, NULL it
  53. if (pToken->psz == (LPWSTR)pToken->rgbScratch)
  54. {
  55. Assert(pToken->cbAlloc == sizeof(pToken->rgbScratch));
  56. pToken->psz = NULL;
  57. }
  58. // Compute Size of new blob
  59. cbAlloc = ((cch + 1) * sizeof(WCHAR));
  60. // Realloc New Blob
  61. CHECKALLOC(pszNew = (LPWSTR)g_pMalloc->Realloc((LPVOID)pToken->psz, cbAlloc));
  62. // Save
  63. pToken->psz = pszNew;
  64. pToken->cbAlloc = cbAlloc;
  65. }
  66. }
  67. // Copy the String
  68. CopyMemory((LPBYTE)pToken->psz, (LPBYTE)psz, ((cch + 1) * sizeof(WCHAR)));
  69. // Save the Size
  70. pToken->cch = cch;
  71. exit:
  72. // Done
  73. return hr;
  74. }
  75. // --------------------------------------------------------------------------------
  76. // MimeAddressFree
  77. // --------------------------------------------------------------------------------
  78. void MimeAddressFree(LPMIMEADDRESS pAddress)
  79. {
  80. Assert(pAddress);
  81. FreeAddressTokenW(&pAddress->rFriendly);
  82. FreeAddressTokenW(&pAddress->rEmail);
  83. SafeMemFree(pAddress->tbSigning.pBlobData);
  84. SafeMemFree(pAddress->tbEncryption.pBlobData);
  85. ZeroMemory(pAddress, sizeof(MIMEADDRESS));
  86. }
  87. // --------------------------------------------------------------------------------
  88. // HrCopyAddressData
  89. // --------------------------------------------------------------------------------
  90. HRESULT HrMimeAddressCopy(LPMIMEADDRESS pSource, LPMIMEADDRESS pDest)
  91. {
  92. // Locals
  93. HRESULT hr=S_OK;
  94. // Friendly
  95. if (!FIsEmptyW(pSource->rFriendly.psz))
  96. {
  97. CHECKHR(hr = HrSetAddressTokenW(pSource->rFriendly.psz, pSource->rFriendly.cch, &pDest->rFriendly));
  98. }
  99. // Email
  100. if (!FIsEmptyW(pSource->rEmail.psz))
  101. {
  102. CHECKHR(hr = HrSetAddressTokenW(pSource->rEmail.psz, pSource->rEmail.cch, &pDest->rEmail));
  103. }
  104. // Copy Signature Blob
  105. if (pSource->tbSigning.pBlobData)
  106. {
  107. CHECKHR(hr = HrCopyBlob(&pSource->tbSigning, &pDest->tbSigning));
  108. }
  109. // Copy Encryption Blob
  110. if (pSource->tbEncryption.pBlobData)
  111. {
  112. CHECKHR(hr = HrCopyBlob(&pSource->tbEncryption, &pDest->tbEncryption));
  113. }
  114. // Save Other Stuff
  115. pDest->pCharset = pSource->pCharset;
  116. pDest->dwCookie = pSource->dwCookie;
  117. pDest->certstate = pSource->certstate;
  118. pDest->dwAdrType = pSource->dwAdrType;
  119. exit:
  120. // Done
  121. return hr;
  122. }
  123. // --------------------------------------------------------------------------------
  124. // HrCopyAddressProps
  125. // --------------------------------------------------------------------------------
  126. HRESULT HrCopyAddressProps(LPADDRESSPROPS pSource, LPADDRESSPROPS pDest)
  127. {
  128. // Locals
  129. HRESULT hr=S_OK;
  130. // IAP_HADDRESS
  131. if (ISFLAGSET(pSource->dwProps, IAP_HANDLE))
  132. {
  133. pDest->hAddress = pSource->hAddress;
  134. FLAGSET(pDest->dwProps, IAP_HANDLE);
  135. }
  136. // IAP_ENCODING
  137. if (ISFLAGSET(pSource->dwProps, IAP_ENCODING))
  138. {
  139. pDest->ietFriendly = pSource->ietFriendly;
  140. FLAGSET(pDest->dwProps, IAP_ENCODING);
  141. }
  142. // IAP_HCHARSET
  143. if (ISFLAGSET(pSource->dwProps, IAP_CHARSET))
  144. {
  145. pDest->hCharset = pSource->hCharset;
  146. FLAGSET(pDest->dwProps, IAP_CHARSET);
  147. }
  148. // IAP_ADRTYPE
  149. if (ISFLAGSET(pSource->dwProps, IAP_ADRTYPE))
  150. {
  151. pDest->dwAdrType = pSource->dwAdrType;
  152. FLAGSET(pDest->dwProps, IAP_ADRTYPE);
  153. }
  154. // IAP_CERTSTATE
  155. if (ISFLAGSET(pSource->dwProps, IAP_CERTSTATE))
  156. {
  157. pDest->certstate = pSource->certstate;
  158. FLAGSET(pDest->dwProps, IAP_CERTSTATE);
  159. }
  160. // IAP_COOKIE
  161. if (ISFLAGSET(pSource->dwProps, IAP_COOKIE))
  162. {
  163. pDest->dwCookie = pSource->dwCookie;
  164. FLAGSET(pDest->dwProps, IAP_COOKIE);
  165. }
  166. // IAP_FRIENDLYW
  167. if (ISFLAGSET(pSource->dwProps, IAP_FRIENDLYW))
  168. {
  169. // Free pDest Current
  170. if (ISFLAGSET(pDest->dwProps, IAP_FRIENDLYW))
  171. {
  172. SafeMemFree(pDest->pszFriendlyW);
  173. FLAGCLEAR(pDest->dwProps, IAP_FRIENDLYW);
  174. }
  175. // Dup
  176. CHECKALLOC(pDest->pszFriendlyW = PszDupW(pSource->pszFriendlyW));
  177. // Set the Falg
  178. FLAGSET(pDest->dwProps, IAP_FRIENDLYW);
  179. }
  180. // IAP_FRIENDLY
  181. if (ISFLAGSET(pSource->dwProps, IAP_FRIENDLY))
  182. {
  183. // Free pDest Current
  184. if (ISFLAGSET(pDest->dwProps, IAP_FRIENDLY))
  185. {
  186. SafeMemFree(pDest->pszFriendly);
  187. FLAGCLEAR(pDest->dwProps, IAP_FRIENDLY);
  188. }
  189. // Dup
  190. CHECKALLOC(pDest->pszFriendly = PszDupA(pSource->pszFriendly));
  191. // Set the Falg
  192. FLAGSET(pDest->dwProps, IAP_FRIENDLY);
  193. }
  194. // IAP_EMAIL
  195. if (ISFLAGSET(pSource->dwProps, IAP_EMAIL))
  196. {
  197. // Free pDest Current
  198. if (ISFLAGSET(pDest->dwProps, IAP_EMAIL))
  199. {
  200. SafeMemFree(pDest->pszEmail);
  201. FLAGCLEAR(pDest->dwProps, IAP_EMAIL);
  202. }
  203. // Dup
  204. CHECKALLOC(pDest->pszEmail = PszDupA(pSource->pszEmail));
  205. // Set the Falg
  206. FLAGSET(pDest->dwProps, IAP_EMAIL);
  207. }
  208. // IAP_SIGNING_PRINT
  209. if (ISFLAGSET(pSource->dwProps, IAP_SIGNING_PRINT))
  210. {
  211. // Free pDest Current
  212. if (ISFLAGSET(pDest->dwProps, IAP_SIGNING_PRINT))
  213. {
  214. SafeMemFree(pDest->tbSigning.pBlobData);
  215. pDest->tbSigning.cbSize = 0;
  216. FLAGCLEAR(pDest->dwProps, IAP_SIGNING_PRINT);
  217. }
  218. // Dup
  219. CHECKHR(hr = HrCopyBlob(&pSource->tbSigning, &pDest->tbSigning));
  220. // Set the Falg
  221. FLAGSET(pDest->dwProps, IAP_SIGNING_PRINT);
  222. }
  223. // IAP_ENCRYPTION_PRINT
  224. if (ISFLAGSET(pSource->dwProps, IAP_ENCRYPTION_PRINT))
  225. {
  226. // Free pDest Current
  227. if (ISFLAGSET(pDest->dwProps, IAP_ENCRYPTION_PRINT))
  228. {
  229. SafeMemFree(pDest->tbEncryption.pBlobData);
  230. pDest->tbEncryption.cbSize = 0;
  231. FLAGCLEAR(pDest->dwProps, IAP_ENCRYPTION_PRINT);
  232. }
  233. // Dup
  234. CHECKHR(hr = HrCopyBlob(&pSource->tbEncryption, &pDest->tbEncryption));
  235. // Set the Falg
  236. FLAGSET(pDest->dwProps, IAP_ENCRYPTION_PRINT);
  237. }
  238. exit:
  239. // Done
  240. return hr;
  241. }