WSMessageStreamImporter.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 WSMessageStreamImporter_INCLUDED
  18. #define WSMessageStreamImporter_INCLUDED
  19. #include <kopano/zcdefs.h>
  20. #include <kopano/ECUnknown.h>
  21. #include <kopano/memory.hpp>
  22. #include "soapStub.h"
  23. #include "ECFifoBuffer.h"
  24. #include <kopano/ECThreadPool.h>
  25. #include "WSTransport.h"
  26. class ECMAPIFolder;
  27. typedef KCHL::object_ptr<WSTransport> WSTransportPtr;
  28. class WSMessageStreamImporter;
  29. /**
  30. * This class represents the data sink into which the stream data can be written.
  31. * It is returned from WSMessageStreamImporter::StartTransfer.
  32. */
  33. class WSMessageStreamSink _kc_final : public ECUnknown {
  34. public:
  35. static HRESULT Create(ECFifoBuffer *lpFifoBuffer, ULONG ulTimeout, WSMessageStreamImporter *lpImporter, WSMessageStreamSink **lppSink);
  36. HRESULT Write(LPVOID lpData, ULONG cbData);
  37. private:
  38. WSMessageStreamSink(ECFifoBuffer *lpFifoBuffer, ULONG ulTimeout, WSMessageStreamImporter *lpImporter);
  39. ~WSMessageStreamSink();
  40. ECFifoBuffer *m_lpFifoBuffer;
  41. WSMessageStreamImporter *m_lpImporter;
  42. };
  43. typedef KCHL::object_ptr<WSMessageStreamSink> WSMessageStreamSinkPtr;
  44. /**
  45. * This class is used to perform a message stream import to the server.
  46. * The actual import call to the server is deferred until StartTransfer is called. When that
  47. * happens, the actual transfer is done on a worker thread so the calling thread can start writing
  48. * data in the returned WSMessageStreamSink. Once the returned stream is deleted, GetAsyncResult can
  49. * be used to wait for the worker and obtain its return values.
  50. */
  51. class WSMessageStreamImporter _kc_final :
  52. public ECUnknown, private ECWaitableTask {
  53. public:
  54. static HRESULT Create(ULONG ulFlags, ULONG ulSyncId, ULONG cbEntryID, LPENTRYID lpEntryID, ULONG cbFolderEntryID, LPENTRYID lpFolderEntryID, bool bNewMessage, LPSPropValue lpConflictItems, WSTransport *lpTransport, WSMessageStreamImporter **lppStreamImporter);
  55. HRESULT StartTransfer(WSMessageStreamSink **lppSink);
  56. HRESULT GetAsyncResult(HRESULT *lphrResult);
  57. private:
  58. WSMessageStreamImporter(ULONG ulFlags, ULONG ulSyncId, const entryId &sEntryId, const entryId &sFolderEntryId, bool bNewMessage, const propVal &sConflictItems, WSTransport *lpTransport, ULONG ulBufferSize, ULONG ulTimeout);
  59. ~WSMessageStreamImporter();
  60. void run();
  61. static void *StaticMTOMReadOpen(struct soap *soap, void *handle, const char *id, const char *type, const char *description);
  62. static size_t StaticMTOMRead(struct soap *soap, void *handle, char *buf, size_t len);
  63. static void StaticMTOMReadClose(struct soap *soap, void *handle);
  64. void *MTOMReadOpen(struct soap *soap, void *handle, const char *id, const char *type, const char *description);
  65. size_t MTOMRead(struct soap *soap, void *handle, char *buf, size_t len);
  66. void MTOMReadClose(struct soap *soap, void *handle);
  67. ULONG m_ulFlags;
  68. ULONG m_ulSyncId;
  69. entryId m_sEntryId;
  70. entryId m_sFolderEntryId;
  71. bool m_bNewMessage;
  72. propVal m_sConflictItems;
  73. WSTransportPtr m_ptrTransport;
  74. HRESULT m_hr = hrSuccess;
  75. ECFifoBuffer m_fifoBuffer;
  76. ECThreadPool m_threadPool;
  77. ULONG m_ulTimeout;
  78. };
  79. typedef KCHL::object_ptr<WSMessageStreamImporter> WSMessageStreamImporterPtr;
  80. #endif // ndef WSMessageStreamImporter_INCLUDED