ECGenericProp.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. #ifndef ECGENERICPROP_H
  18. #define ECGENERICPROP_H
  19. #include <kopano/zcdefs.h>
  20. #include <mutex>
  21. #include <kopano/ECUnknown.h>
  22. #include "IECPropStorage.h"
  23. #include "ECPropertyEntry.h"
  24. #include <kopano/IECSingleInstance.h>
  25. #include <list>
  26. #include <map>
  27. #include <set>
  28. // These are the callback functions called when a software-handled property is requested
  29. typedef HRESULT (*SetPropCallBack)(ULONG ulPropTag, void *lpProvider, const SPropValue *lpsPropValue, void *lpParam);
  30. typedef HRESULT (* GetPropCallBack)(ULONG ulPropTag, void* lpProvider, ULONG ulFlags, LPSPropValue lpsPropValue, void *lpParam, void *lpBase);
  31. struct PROPCALLBACK {
  32. ULONG ulPropTag;
  33. SetPropCallBack lpfnSetProp;
  34. GetPropCallBack lpfnGetProp;
  35. void * lpParam;
  36. BOOL fRemovable;
  37. BOOL fHidden; // hidden from GetPropList
  38. bool operator==(const PROPCALLBACK &callback) const
  39. {
  40. return callback.ulPropTag == this->ulPropTag;
  41. }
  42. };
  43. typedef std::map<short, PROPCALLBACK> ECPropCallBackMap;
  44. typedef ECPropCallBackMap::iterator ECPropCallBackIterator;
  45. typedef std::map<short, ECPropertyEntry> ECPropertyEntryMap;
  46. typedef ECPropertyEntryMap::iterator ECPropertyEntryIterator;
  47. class ECGenericProp : public ECUnknown {
  48. protected:
  49. ECGenericProp(void *lpProvider, ULONG ulObjType, BOOL fModify, const char *szClassName = NULL);
  50. virtual ~ECGenericProp();
  51. public:
  52. virtual HRESULT QueryInterface(REFIID refiid, void **lppInterface) _kc_override;
  53. HRESULT SetProvider(void* lpProvider);
  54. HRESULT SetEntryId(ULONG cbEntryId, LPENTRYID lpEntryId);
  55. static HRESULT DefaultGetPropGetReal(ULONG ulPropTag, void* lpProvider, ULONG ulFlags, LPSPropValue lpsPropValue, void *lpParam, void *lpBase);
  56. static HRESULT DefaultGetPropNotFound(ULONG ulPropTag, void* lpProvider, ULONG ulFlags, LPSPropValue lpsPropValue, void *lpParam, void *lpBase);
  57. static HRESULT DefaultSetPropComputed(ULONG ulPropTag, void *lpProvider, const SPropValue *lpsPropValue, void *lpParam);
  58. static HRESULT DefaultSetPropIgnore(ULONG ulPropTag, void *lpProvider, const SPropValue *lpsPropValue, void *lpParam);
  59. static HRESULT DefaultSetPropSetReal(ULONG ulPropTag, void *lpProvider, const SPropValue *lpsPropValue, void *lpParam);
  60. static HRESULT DefaultGetProp(ULONG ulPropTag, void* lpProvider, ULONG ulFlags, LPSPropValue lpsPropValue, void *lpParam, void *lpBase);
  61. // Our table-row getprop handler (handles client-side generation of table columns)
  62. static HRESULT TableRowGetProp(void* lpProvider, struct propVal *lpsPropValSrc, LPSPropValue lpsPropValDst, void **lpBase, ULONG ulType);
  63. virtual HRESULT HrSetPropStorage(IECPropStorage *lpStorage, BOOL fLoadProps);
  64. virtual HRESULT HrSetRealProp(const SPropValue *lpsPropValue);
  65. virtual HRESULT HrGetRealProp(ULONG ulPropTag, ULONG ulFlags, void *lpBase, LPSPropValue lpsPropValue, ULONG ulMaxSize = 0);
  66. virtual HRESULT HrAddPropHandlers(ULONG ulPropTag, GetPropCallBack lpfnGetProp, SetPropCallBack lpfnSetProp, void *lpParam, BOOL fRemovable = FALSE, BOOL fHidden = FALSE);
  67. virtual HRESULT HrLoadEmptyProps();
  68. bool IsReadOnly() const;
  69. protected: ///?
  70. virtual HRESULT HrLoadProps();
  71. HRESULT HrLoadProp(ULONG ulPropTag);
  72. virtual HRESULT HrDeleteRealProp(ULONG ulPropTag, BOOL fOverwriteRO);
  73. HRESULT HrGetHandler(ULONG ulPropTag, SetPropCallBack *lpfnSetProp, GetPropCallBack *lpfnGetProp, void **lpParam);
  74. HRESULT IsPropDirty(ULONG ulPropTag, BOOL *lpbDirty);
  75. HRESULT HrSetClean();
  76. HRESULT HrSetCleanProperty(ULONG ulPropTag);
  77. /* used by child to save here in it's parent */
  78. friend class ECParentStorage;
  79. virtual HRESULT HrSaveChild(ULONG ulFlags, MAPIOBJECT *lpsMapiObject);
  80. virtual HRESULT HrRemoveModifications(MAPIOBJECT *lpsMapiObject, ULONG ulPropTag);
  81. // For IECSingleInstance
  82. virtual HRESULT GetSingleInstanceId(ULONG *lpcbInstanceID, LPSIEID *lppInstanceID);
  83. virtual HRESULT SetSingleInstanceId(ULONG cbInstanceID, LPSIEID lpInstanceID);
  84. public:
  85. // From IMAPIProp
  86. virtual HRESULT GetLastError(HRESULT hResult, ULONG ulFlags, LPMAPIERROR *lppMAPIError);
  87. virtual HRESULT SaveChanges(ULONG ulFlags);
  88. virtual HRESULT GetProps(const SPropTagArray *lpPropTagArray, ULONG ulFlags, ULONG *lpcValues, LPSPropValue *lppPropArray);
  89. virtual HRESULT GetPropList(ULONG ulFlags, LPSPropTagArray *lppPropTagArray);
  90. /**
  91. * \brief Opens a property.
  92. *
  93. * \param ulPropTag The proptag of the property to open.
  94. * \param lpiid Pointer to the requested interface for the object to be opened.
  95. * \param ulInterfaceOptions Interface options.
  96. * \param ulFlags Flags.
  97. * \param lppUnk Pointer to an IUnknown pointer where the opened object will be stored.
  98. *
  99. * \return hrSuccess on success.
  100. */
  101. virtual HRESULT OpenProperty(ULONG ulPropTag, LPCIID lpiid, ULONG ulInterfaceOptions, ULONG ulFlags, LPUNKNOWN *lppUnk);
  102. virtual HRESULT SetProps(ULONG cValues, const SPropValue *lpPropArray, LPSPropProblemArray *lppProblems);
  103. virtual HRESULT DeleteProps(const SPropTagArray *lpPropTagArray, LPSPropProblemArray *lppProblems);
  104. virtual HRESULT CopyTo(ULONG ciidExclude, LPCIID rgiidExclude, const SPropTagArray *lpExcludeProps, ULONG ulUIParam, LPMAPIPROGRESS lpProgress, LPCIID lpInterface, LPVOID lpDestObj, ULONG ulFlags, LPSPropProblemArray *lppProblems);
  105. virtual HRESULT CopyProps(const SPropTagArray *lpIncludeProps, ULONG ulUIParam, LPMAPIPROGRESS lpProgress, LPCIID lpInterface, LPVOID lpDestObj, ULONG ulFlags, LPSPropProblemArray *lppProblems);
  106. virtual HRESULT GetNamesFromIDs(LPSPropTagArray *lppPropTags, LPGUID lpPropSetGuid, ULONG ulFlags, ULONG *lpcPropNames, LPMAPINAMEID **lpppPropNames);
  107. virtual HRESULT GetIDsFromNames(ULONG cPropNames, LPMAPINAMEID *lppPropNames, ULONG ulFlags, LPSPropTagArray *lppPropTags);
  108. class xMAPIProp _kc_final : public IMAPIProp {
  109. #include <kopano/xclsfrag/IUnknown.hpp>
  110. #include <kopano/xclsfrag/IMAPIProp.hpp>
  111. } m_xMAPIProp;
  112. class xECSingleInstance _kc_final : public IECSingleInstance {
  113. #include <kopano/xclsfrag/IUnknown.hpp>
  114. // <kopano/xclsfrag/IECSingleInstance.hpp>
  115. virtual HRESULT __stdcall GetSingleInstanceId(ULONG *lpcbInstanceID, LPENTRYID *lppInstanceID) _kc_override;
  116. virtual HRESULT __stdcall SetSingleInstanceId(ULONG cbInstanceID, LPENTRYID lpInstanceID) _kc_override;
  117. } m_xECSingleInstance;
  118. protected:
  119. ECPropertyEntryMap *lstProps = nullptr;
  120. std::set<ULONG> m_setDeletedProps;
  121. ECPropCallBackMap lstCallBack;
  122. DWORD dwLastError = hrSuccess;
  123. BOOL fSaved = false; // only 0 if just created, // not saved until we either read or write from/to disk
  124. ULONG ulObjType;
  125. ULONG ulObjFlags = 0; // message: MAPI_ASSOCIATED, folder: FOLDER_SEARCH (last?)
  126. BOOL fModify;
  127. void* lpProvider;
  128. BOOL isTransactedObject = true; // only ECMsgStore and ECMAPIFolder are not transacted
  129. ULONG m_ulMaxPropSize = 8192;
  130. public:
  131. // Current entryid of object
  132. ULONG m_cbEntryId = 0;
  133. ENTRYID *m_lpEntryId = nullptr;
  134. MAPIOBJECT *m_sMapiObject = nullptr;
  135. std::recursive_mutex m_hMutexMAPIObject; /* Mutex for locking the MAPIObject */
  136. BOOL m_bReload = false, m_bLoading = false;
  137. IECPropStorage *lpStorage = nullptr;
  138. };
  139. // Inlines
  140. inline bool ECGenericProp::IsReadOnly() const {
  141. return !fModify;
  142. }
  143. #endif