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.

336 lines
9.9 KiB

  1. // --------------------------------------------------------------------------------
  2. // Olealloc.cpp
  3. // Copyright (c)1993-1995 Microsoft Corporation, All Rights Reserved
  4. // Steven J. Bailey
  5. // --------------------------------------------------------------------------------
  6. #include "pch.hxx"
  7. #include "dllmain.h"
  8. #include "olealloc.h"
  9. #include "smime.h"
  10. // --------------------------------------------------------------------------------
  11. // CMimeAllocator::CMimeAllocator
  12. // --------------------------------------------------------------------------------
  13. CMimeAllocator::CMimeAllocator(void)
  14. {
  15. if (NULL != g_pMoleAlloc)
  16. DllAddRef();
  17. m_cRef = 1;
  18. }
  19. // --------------------------------------------------------------------------------
  20. // CMimeAllocator::~CMimeAllocator
  21. // --------------------------------------------------------------------------------
  22. CMimeAllocator::~CMimeAllocator(void)
  23. {
  24. if (this != g_pMoleAlloc)
  25. DllRelease();
  26. }
  27. // --------------------------------------------------------------------------------
  28. // CMimeAllocator::QueryInterface
  29. // --------------------------------------------------------------------------------
  30. STDMETHODIMP CMimeAllocator::QueryInterface(REFIID riid, LPVOID *ppv)
  31. {
  32. // check params
  33. if (ppv == NULL)
  34. return TrapError(E_INVALIDARG);
  35. // Find IID
  36. if (IID_IUnknown == riid)
  37. *ppv = (IUnknown *)(IMimeAllocator *)this;
  38. else if (IID_IMimeAllocator == riid)
  39. *ppv = (IMimeAllocator *)this;
  40. else
  41. {
  42. *ppv = NULL;
  43. return TrapError(E_NOINTERFACE);
  44. }
  45. // AddRef It
  46. ((IUnknown *)*ppv)->AddRef();
  47. // Done
  48. return S_OK;
  49. }
  50. // --------------------------------------------------------------------------------
  51. // CMimeAllocator::AddRef
  52. // --------------------------------------------------------------------------------
  53. STDMETHODIMP_(ULONG) CMimeAllocator::AddRef(void)
  54. {
  55. return (ULONG)InterlockedIncrement(&m_cRef);
  56. }
  57. // --------------------------------------------------------------------------------
  58. // CMimeAllocator::Release
  59. // --------------------------------------------------------------------------------
  60. STDMETHODIMP_(ULONG) CMimeAllocator::Release(void)
  61. {
  62. LONG cRef = InterlockedDecrement(&m_cRef);
  63. if (0 == cRef)
  64. delete this;
  65. return (ULONG)cRef;
  66. }
  67. // --------------------------------------------------------------------------------
  68. // CMimeAllocator::Alloc
  69. // --------------------------------------------------------------------------------
  70. STDMETHODIMP_(LPVOID) CMimeAllocator::Alloc(SIZE_T cb)
  71. {
  72. // Locals
  73. LPVOID pv;
  74. // Do I have a global Allocator
  75. Assert(g_pMalloc);
  76. // Allocate it
  77. pv = g_pMalloc->Alloc(cb);
  78. if (NULL == pv)
  79. {
  80. TrapError(E_OUTOFMEMORY);
  81. return NULL;
  82. }
  83. // Done
  84. return pv;
  85. }
  86. // --------------------------------------------------------------------------------
  87. // CMimeAllocator::Realloc
  88. // --------------------------------------------------------------------------------
  89. STDMETHODIMP_(LPVOID) CMimeAllocator::Realloc(void *pv, SIZE_T cb)
  90. {
  91. // Locals
  92. LPVOID pvNew;
  93. // Do I have a global Allocator
  94. Assert(g_pMalloc);
  95. // Realloc
  96. pvNew = g_pMalloc->Realloc(pv, cb);
  97. if (NULL == pvNew)
  98. {
  99. TrapError(E_OUTOFMEMORY);
  100. return NULL;
  101. }
  102. // Done
  103. return pvNew;
  104. }
  105. // --------------------------------------------------------------------------------
  106. // CMimeAllocator::Free
  107. // --------------------------------------------------------------------------------
  108. STDMETHODIMP_(void) CMimeAllocator::Free(void * pv)
  109. {
  110. // Better have pv
  111. Assert(pv && g_pMalloc);
  112. // If Not NULL
  113. if (pv)
  114. {
  115. // Free It
  116. g_pMalloc->Free(pv);
  117. }
  118. }
  119. // --------------------------------------------------------------------------------
  120. // CMimeAllocator::GetSize
  121. // --------------------------------------------------------------------------------
  122. STDMETHODIMP_(SIZE_T) CMimeAllocator::GetSize(void *pv)
  123. {
  124. return g_pMalloc->GetSize(pv);
  125. }
  126. // --------------------------------------------------------------------------------
  127. // CMimeAllocator::DidAlloc
  128. // --------------------------------------------------------------------------------
  129. STDMETHODIMP_(int) CMimeAllocator::DidAlloc(void *pv)
  130. {
  131. return g_pMalloc->DidAlloc(pv);
  132. }
  133. // --------------------------------------------------------------------------------
  134. // CMimeAllocator::HeapMinimize
  135. // --------------------------------------------------------------------------------
  136. STDMETHODIMP_(void) CMimeAllocator::HeapMinimize(void)
  137. {
  138. g_pMalloc->HeapMinimize();
  139. }
  140. // --------------------------------------------------------------------------------
  141. // CMimeAllocator::FreeParamInfoArray
  142. // --------------------------------------------------------------------------------
  143. STDMETHODIMP CMimeAllocator::FreeParamInfoArray(ULONG cParams, LPMIMEPARAMINFO prgParam, boolean fFreeArray)
  144. {
  145. // Nothing to Free
  146. if (0 == cParams || NULL == prgParam)
  147. return S_OK;
  148. // Loop
  149. for (ULONG i=0; i<cParams; i++)
  150. {
  151. SafeMemFree(prgParam[i].pszName);
  152. SafeMemFree(prgParam[i].pszData);
  153. }
  154. // Free the Array
  155. if (fFreeArray)
  156. {
  157. SafeMemFree(prgParam);
  158. }
  159. // Done
  160. return S_OK;
  161. }
  162. // --------------------------------------------------------------------------------
  163. // CMimeAllocator::ReleaseObjects
  164. // --------------------------------------------------------------------------------
  165. STDMETHODIMP CMimeAllocator::ReleaseObjects(ULONG cObjects, IUnknown **prgpUnknown, boolean fFreeArray)
  166. {
  167. // Nothing to Free
  168. if (0 == cObjects || NULL == prgpUnknown)
  169. return S_OK;
  170. // Loop
  171. for (ULONG i=0; i<cObjects; i++)
  172. {
  173. SafeRelease(prgpUnknown[i]);
  174. }
  175. // Free Array
  176. if (fFreeArray)
  177. {
  178. SafeMemFree(prgpUnknown);
  179. }
  180. // Done
  181. return S_OK;
  182. }
  183. // --------------------------------------------------------------------------------
  184. // CMimeAllocator::FreeHeaderLineArray
  185. // --------------------------------------------------------------------------------
  186. STDMETHODIMP CMimeAllocator::FreeEnumHeaderRowArray(ULONG cRows, LPENUMHEADERROW prgRow, boolean fFreeArray)
  187. {
  188. // Nothing to Free
  189. if (0 == cRows || NULL == prgRow)
  190. return S_OK;
  191. // Loop the cells
  192. for (ULONG i=0; i<cRows; i++)
  193. {
  194. SafeMemFree(prgRow[i].pszHeader);
  195. SafeMemFree(prgRow[i].pszData);
  196. }
  197. // Free Array
  198. if (fFreeArray)
  199. SafeMemFree(prgRow);
  200. // Done
  201. return S_OK;
  202. }
  203. // --------------------------------------------------------------------------------
  204. // CMimeAllocator::FreeEnumPropertyArray
  205. // --------------------------------------------------------------------------------
  206. STDMETHODIMP CMimeAllocator::FreeEnumPropertyArray(ULONG cProps, LPENUMPROPERTY prgProp, boolean fFreeArray)
  207. {
  208. // Nothing to Free
  209. if (0 == cProps || NULL == prgProp)
  210. return S_OK;
  211. // Loop the cells
  212. for (ULONG i=0; i<cProps; i++)
  213. SafeMemFree(prgProp[i].pszName);
  214. // Free Array
  215. if (fFreeArray)
  216. SafeMemFree(prgProp);
  217. // Done
  218. return S_OK;
  219. }
  220. // --------------------------------------------------------------------------------
  221. // CMimeAllocator::FreeAddressProps
  222. // --------------------------------------------------------------------------------
  223. STDMETHODIMP CMimeAllocator::FreeAddressProps(LPADDRESSPROPS pAddress)
  224. {
  225. // Invalid Arg
  226. if (NULL == pAddress)
  227. return TrapError(E_INVALIDARG);
  228. // IAP_FRIENDLY
  229. if (ISFLAGSET(pAddress->dwProps, IAP_FRIENDLY) && pAddress->pszFriendly)
  230. g_pMalloc->Free(pAddress->pszFriendly);
  231. // IAP_FRIENDLYW
  232. if (ISFLAGSET(pAddress->dwProps, IAP_FRIENDLYW) && pAddress->pszFriendlyW)
  233. g_pMalloc->Free(pAddress->pszFriendlyW);
  234. // IAP_EMAIL
  235. if (ISFLAGSET(pAddress->dwProps, IAP_EMAIL) && pAddress->pszEmail)
  236. g_pMalloc->Free(pAddress->pszEmail);
  237. // IAP_SIGNING_PRINT
  238. if (ISFLAGSET(pAddress->dwProps, IAP_SIGNING_PRINT) && pAddress->tbSigning.pBlobData)
  239. g_pMalloc->Free(pAddress->tbSigning.pBlobData);
  240. // IAP_ENCRYPTION_PRINT
  241. if (ISFLAGSET(pAddress->dwProps, IAP_ENCRYPTION_PRINT) && pAddress->tbEncryption.pBlobData)
  242. g_pMalloc->Free(pAddress->tbEncryption.pBlobData);
  243. // No legal props
  244. ZeroMemory(pAddress, sizeof(ADDRESSPROPS));
  245. // Done
  246. return S_OK;
  247. }
  248. // --------------------------------------------------------------------------------
  249. // CMimeAllocator::FreeAddressList
  250. // --------------------------------------------------------------------------------
  251. STDMETHODIMP CMimeAllocator::FreeAddressList(LPADDRESSLIST pList)
  252. {
  253. // Invalid Arg
  254. if (NULL == pList || (pList->cAdrs > 0 && NULL == pList->prgAdr))
  255. return TrapError(E_INVALIDARG);
  256. // Free Each Item
  257. for (ULONG i=0; i<pList->cAdrs; i++)
  258. FreeAddressProps(&pList->prgAdr[i]);
  259. // Free the list
  260. SafeMemFree(pList->prgAdr);
  261. // Zero It
  262. ZeroMemory(pList, sizeof(ADDRESSLIST));
  263. // Done
  264. return S_OK;
  265. }
  266. // --------------------------------------------------------------------------------
  267. // CMimeAllocator::PropVariantClear
  268. // --------------------------------------------------------------------------------
  269. STDMETHODIMP CMimeAllocator::PropVariantClear(LPPROPVARIANT pProp)
  270. {
  271. return MimeOleVariantFree(pProp);
  272. }
  273. // ---------------------------------------------------------------------------
  274. // CMimeAllocator::FreeThumbprint
  275. // ---------------------------------------------------------------------------
  276. STDMETHODIMP CMimeAllocator::FreeThumbprint(THUMBBLOB *pthumbprint)
  277. {
  278. if (pthumbprint->pBlobData)
  279. {
  280. Assert(0 != g_pMalloc->DidAlloc(pthumbprint->pBlobData));
  281. MemFree(pthumbprint->pBlobData);
  282. }
  283. return S_OK;
  284. }