ECParentStorage.cpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*
  2. * Copyright 2005 - 2016 Zarafa and its licensors
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU Affero General Public License, version 3,
  6. * as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU Affero General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU Affero General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. *
  16. */
  17. #include <new>
  18. #include <kopano/platform.h>
  19. #include <kopano/lockhelper.hpp>
  20. #include "ECParentStorage.h"
  21. #include "Mem.h"
  22. #include <kopano/ECGuid.h>
  23. #include <kopano/ECInterfaceDefs.h>
  24. #include <mapiutil.h>
  25. #include "SOAPUtils.h"
  26. #include "WSUtil.h"
  27. #include <kopano/Util.h>
  28. ECParentStorage::ECParentStorage(ECGenericProp *lpParentObject,
  29. ULONG ulUniqueId, ULONG ulObjId, IECPropStorage *lpServerStorage) :
  30. m_lpParentObject(lpParentObject), m_ulObjId(ulObjId),
  31. m_ulUniqueId(ulUniqueId), m_lpServerStorage(lpServerStorage)
  32. {
  33. if (m_lpParentObject)
  34. m_lpParentObject->AddRef();
  35. if (m_lpServerStorage)
  36. m_lpServerStorage->AddRef();
  37. }
  38. ECParentStorage::~ECParentStorage()
  39. {
  40. if (m_lpParentObject)
  41. m_lpParentObject->Release();
  42. if (m_lpServerStorage)
  43. m_lpServerStorage->Release();
  44. }
  45. HRESULT ECParentStorage::QueryInterface(REFIID refiid, void **lppInterface)
  46. {
  47. REGISTER_INTERFACE2(ECParentStorage, this);
  48. REGISTER_INTERFACE2(IECPropStorage, &this->m_xECPropStorage);
  49. return MAPI_E_INTERFACE_NOT_SUPPORTED;
  50. }
  51. HRESULT ECParentStorage::Create(ECGenericProp *lpParentObject, ULONG ulUniqueId, ULONG ulObjId, IECPropStorage *lpServerStorage, ECParentStorage **lppParentStorage)
  52. {
  53. auto lpParentStorage = new(std::nothrow) ECParentStorage(lpParentObject,
  54. ulUniqueId, ulObjId, lpServerStorage);
  55. if (lpParentStorage == nullptr)
  56. return MAPI_E_NOT_ENOUGH_MEMORY;
  57. auto ret = lpParentStorage->QueryInterface(IID_ECParentStorage,
  58. reinterpret_cast<void **>(lppParentStorage)); //FIXME: Use other interface
  59. if (ret != hrSuccess)
  60. delete lpParentStorage;
  61. return ret;
  62. }
  63. HRESULT ECParentStorage::HrReadProps(LPSPropTagArray *lppPropTags, ULONG *lpcValues, LPSPropValue *lppValues)
  64. {
  65. // this call should disappear
  66. return MAPI_E_NO_SUPPORT;
  67. }
  68. HRESULT ECParentStorage::HrLoadProp(ULONG ulObjId, ULONG ulPropTag, LPSPropValue *lppsPropValue)
  69. {
  70. if (m_lpServerStorage == NULL)
  71. return MAPI_E_NOT_FOUND;
  72. return m_lpServerStorage->HrLoadProp(ulObjId, ulPropTag, lppsPropValue);
  73. }
  74. HRESULT ECParentStorage::HrWriteProps(ULONG cValues, LPSPropValue pValues, ULONG ulFlags)
  75. {
  76. // this call should disappear
  77. return MAPI_E_NO_SUPPORT;
  78. }
  79. HRESULT ECParentStorage::HrDeleteProps(const SPropTagArray *lpsPropTagArray)
  80. {
  81. // this call should disappear
  82. return MAPI_E_NO_SUPPORT;
  83. }
  84. HRESULT ECParentStorage::HrSaveObject(ULONG ulFlags, MAPIOBJECT *lpsMapiObject)
  85. {
  86. if (m_lpParentObject == NULL)
  87. return MAPI_E_INVALID_OBJECT;
  88. lpsMapiObject->ulUniqueId = m_ulUniqueId;
  89. lpsMapiObject->ulObjId = m_ulObjId;
  90. return m_lpParentObject->HrSaveChild(ulFlags, lpsMapiObject);
  91. }
  92. HRESULT ECParentStorage::HrLoadObject(MAPIOBJECT **lppsMapiObject)
  93. {
  94. HRESULT hr = hrSuccess;
  95. ECMapiObjects::const_iterator iterSObj;
  96. if (!m_lpParentObject)
  97. return MAPI_E_INVALID_OBJECT;
  98. scoped_rlock lock(m_lpParentObject->m_hMutexMAPIObject);
  99. if (m_lpParentObject->m_sMapiObject == NULL)
  100. return MAPI_E_INVALID_OBJECT;
  101. // type is either attachment or message-in-message
  102. {
  103. MAPIOBJECT find(MAPI_MESSAGE, m_ulUniqueId);
  104. MAPIOBJECT findAtt(MAPI_ATTACH, m_ulUniqueId);
  105. iterSObj = m_lpParentObject->m_sMapiObject->lstChildren.find(&find);
  106. if (iterSObj == m_lpParentObject->m_sMapiObject->lstChildren.cend())
  107. iterSObj = m_lpParentObject->m_sMapiObject->lstChildren.find(&findAtt);
  108. }
  109. if (iterSObj == m_lpParentObject->m_sMapiObject->lstChildren.cend())
  110. return MAPI_E_NOT_FOUND;
  111. // make a complete copy of the object, because of close / re-open
  112. *lppsMapiObject = new MAPIOBJECT(*iterSObj);
  113. return hr;
  114. }
  115. IECPropStorage* ECParentStorage::GetServerStorage() {
  116. return m_lpServerStorage;
  117. }
  118. // Interface IECPropStorage
  119. DEF_ULONGMETHOD0(ECParentStorage, ECPropStorage, AddRef, (void))
  120. DEF_ULONGMETHOD0(ECParentStorage, ECPropStorage, Release, (void))
  121. DEF_HRMETHOD0(ECParentStorage, ECPropStorage, QueryInterface, (REFIID, refiid), (void**, lppInterface))
  122. DEF_HRMETHOD0(ECParentStorage, ECPropStorage, HrReadProps, (LPSPropTagArray *, lppPropTags), (ULONG *, cValues), (LPSPropValue *, lppValues))
  123. DEF_HRMETHOD0(ECParentStorage, ECPropStorage, HrLoadProp, (ULONG, ulObjId), (ULONG, ulPropTag), (LPSPropValue *, lppsPropValue))
  124. DEF_HRMETHOD0(ECParentStorage, ECPropStorage, HrWriteProps, (ULONG, cValues), (LPSPropValue, lpValues), (ULONG, ulFlags))
  125. DEF_HRMETHOD0(ECParentStorage, ECPropStorage, HrDeleteProps, (const SPropTagArray *, lpsPropTagArray))
  126. DEF_HRMETHOD0(ECParentStorage, ECPropStorage, HrSaveObject, (ULONG, ulFlags), (MAPIOBJECT *, lpsMapiObject))
  127. DEF_HRMETHOD0(ECParentStorage, ECPropStorage, HrLoadObject, (MAPIOBJECT **, lppsMapiObject))
  128. IECPropStorage* ECParentStorage::xECPropStorage::GetServerStorage() {
  129. METHOD_PROLOGUE_(ECParentStorage, ECPropStorage);
  130. return pThis->GetServerStorage();
  131. }