123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- #include <kopano/platform.h>
- #include <kopano/Util.h>
- #include "WSSerializedMessage.h"
- WSSerializedMessage::WSSerializedMessage(soap *lpSoap, const std::string strStreamId, ULONG cbProps, LPSPropValue lpProps)
- : m_lpSoap(lpSoap)
- , m_strStreamId(strStreamId)
- , m_cbProps(cbProps)
- , m_lpProps(lpProps)
- {
- }
- HRESULT WSSerializedMessage::GetProps(ULONG *lpcbProps, LPSPropValue *lppProps)
- {
- if (lpcbProps == NULL || lppProps == NULL)
- return MAPI_E_INVALID_PARAMETER;
- return Util::HrCopyPropertyArray(m_lpProps, m_cbProps, lppProps, lpcbProps);
- }
- HRESULT WSSerializedMessage::CopyData(LPSTREAM lpDestStream)
- {
- HRESULT hr;
- if (lpDestStream == NULL)
- return MAPI_E_INVALID_PARAMETER;
- hr = DoCopyData(lpDestStream);
- if (hr != hrSuccess)
- return hr;
- return lpDestStream->Commit(0);
- }
- HRESULT WSSerializedMessage::DiscardData()
- {
-
- return DoCopyData(NULL);
- }
- HRESULT WSSerializedMessage::DoCopyData(LPSTREAM lpDestStream)
- {
- if (m_bUsed)
- return MAPI_E_UNCONFIGURED;
- m_bUsed = true;
- m_hr = hrSuccess;
- m_ptrDestStream.reset(lpDestStream);
- m_lpSoap->fmimewriteopen = StaticMTOMWriteOpen;
- m_lpSoap->fmimewrite = StaticMTOMWrite;
- m_lpSoap->fmimewriteclose = StaticMTOMWriteClose;
- soap_get_mime_attachment(m_lpSoap, (void*)this);
- if (m_lpSoap->error != 0)
- return MAPI_E_NETWORK_ERROR;
- return m_hr;
- }
- void* WSSerializedMessage::StaticMTOMWriteOpen(struct soap *soap, void *handle, const char *id, const char *type, const char *description, enum soap_mime_encoding encoding)
- {
- return static_cast<WSSerializedMessage *>(handle)->MTOMWriteOpen(soap, handle, id, type, description, encoding);
- }
- int WSSerializedMessage::StaticMTOMWrite(struct soap *soap, void *handle, const char *buf, size_t len)
- {
- return static_cast<WSSerializedMessage *>(handle)->MTOMWrite(soap, handle, buf, len);
- }
- void WSSerializedMessage::StaticMTOMWriteClose(struct soap *soap, void *handle)
- {
- static_cast<WSSerializedMessage *>(handle)->MTOMWriteClose(soap, handle);
- }
- void* WSSerializedMessage::MTOMWriteOpen(struct soap *soap, void *handle, const char *id, const char* , const char* , enum soap_mime_encoding encoding)
- {
- if (encoding != SOAP_MIME_BINARY || id == NULL ||
- m_strStreamId.compare(id) != 0) {
- soap->error = SOAP_ERR;
- m_hr = MAPI_E_INVALID_TYPE;
- m_ptrDestStream.reset();
- }
- return handle;
- }
- int WSSerializedMessage::MTOMWrite(struct soap *soap, void* , const char *buf, size_t len)
- {
- HRESULT hr = hrSuccess;
- ULONG cbWritten = 0;
- if (!m_ptrDestStream)
- return SOAP_OK;
- hr = m_ptrDestStream->Write(buf, (ULONG)len, &cbWritten);
- if (hr != hrSuccess) {
- soap->error = SOAP_ERR;
- m_hr = hr;
- m_ptrDestStream.reset();
- }
-
- return SOAP_OK;
- }
- void WSSerializedMessage::MTOMWriteClose(struct soap *soap, void *handle)
- {
- m_ptrDestStream.reset();
- }
|