Browse Source

Wrap mime_encode_message() and mime_decode_message()

COM-121
Thomas 3 years ago
parent
commit
7b7247c455
3 changed files with 86 additions and 12 deletions
  1. +76
    -11
      CpEpEngine.cpp
  2. +4
    -1
      CpEpEngine.h
  3. +6
    -0
      pEpCOMServerAdapter.idl

+ 76
- 11
CpEpEngine.cpp View File

@ -64,7 +64,7 @@ STDMETHODIMP CpEpEngine::ConfigCipherSuite(pEpCipherSuite cipherSuite)
if (status)
return FAIL(L"config_cipher_suite", status);
return S_OK;
}
@ -264,7 +264,7 @@ STDMETHODIMP CpEpEngine::GetTrustwordsForFprs(BSTR fpr1, BSTR fpr2, BSTR lang, V
_fpr1 = utf8_string(fpr1);
_fpr2 = utf8_string(fpr2);
if (lang) {
_lang = utf8_string(lang);
if (_lang.length() == 0) {
@ -616,6 +616,70 @@ STDMETHODIMP CpEpEngine::StopKeyserverLookup()
return S_OK;
}
STDMETHODIMP CpEpEngine::MIMEDecodeMessage(BSTR mimeText, TextMessage *msg)
{
assert(mimeText);
if (!mimeText)
return E_INVALIDARG;
string _mimeText = utf8_string(mimeText);
size_t size = SysStringLen(mimeText);
::message *_msg = NULL;
PEP_STATUS status = mime_decode_message(_mimeText.c_str(), size, &_msg);
assert(status != ::PEP_OUT_OF_MEMORY);
if (status == ::PEP_OUT_OF_MEMORY)
return E_OUTOFMEMORY;
if (status != PEP_STATUS_OK)
return FAIL(L"mime_decode_message", status);
if (_msg)
text_message_from_C(msg, _msg);
free_message(_msg);
return status;
}
STDMETHODIMP CpEpEngine::MIMEEncodeMessage(TextMessage *msg, VARIANT_BOOL omitFields, BSTR *mimeText)
{
assert(msg);
if (!msg)
return E_INVALIDARG;
::message *_msg = NULL;
try {
_msg = text_message_to_C(msg);
}
catch (bad_alloc&) {
return E_OUTOFMEMORY;
}
catch (exception& ex) {
return FAIL(ex.what());
}
char *_mimeText;
PEP_STATUS status = mime_encode_message(_msg, omitFields != 0, &_mimeText);
free_message(_msg);
assert(status != ::PEP_OUT_OF_MEMORY);
if (status == ::PEP_OUT_OF_MEMORY)
return E_OUTOFMEMORY;
if (status != PEP_STATUS_OK)
return FAIL(L"mime_encode_message", status);
*mimeText = utf16_bstr(_mimeText);
pEp_free(_mimeText);
return status;
}
STDMETHODIMP CpEpEngine::Myself(struct pEpIdentity *ident, struct pEpIdentity *result)
{
assert(ident);
@ -738,7 +802,7 @@ STDMETHODIMP CpEpEngine::KeyMistrusted(struct pEpIdentity *ident)
return S_OK;
}
STDMETHODIMP CpEpEngine::IspEpUser(/* [in] */ struct pEpIdentity *ident, /* [retval][out] */ VARIANT_BOOL *ispEp)
STDMETHODIMP CpEpEngine::IspEpUser(/* [in] */ struct pEpIdentity *ident, /* [retval][out] */ VARIANT_BOOL *ispEp)
{
::pEp_identity *_ident;
@ -943,7 +1007,7 @@ int CpEpEngine::examine_identity(pEp_identity *ident, void *management)
static IpEpEngineCallbacks * _unmarshaled_consumer(CpEpEngine::callback_container::Container::iterator p)
{
if (!p->cdata && p->pdata && p->pdata->marshaled) {
HRESULT r = CoGetInterfaceAndReleaseStream(p->pdata->marshaled, IID_IpEpEngineCallbacks, (LPVOID*) &p->cdata);
HRESULT r = CoGetInterfaceAndReleaseStream(p->pdata->marshaled, IID_IpEpEngineCallbacks, (LPVOID*)&p->cdata);
if (!SUCCEEDED(r))
throw runtime_error("_unmarshaled_consumer(): CoGetInterfaceAndReleaseStream() failed");
p->pdata->marshaled = nullptr;
@ -1215,9 +1279,9 @@ STDMETHODIMP CpEpEngine::EncryptMessageAndAddPrivKey(TextMessage * src, TextMess
::message *msg_dst = NULL;
string _to_fpr = utf8_string(to_fpr);
// _PEP_enc_format used to be intentionally hardcoded to PEP_enc_PEP:
// Since COM-74, this has been changed to an explicit parameter, to allow the engine to attach
// the keys and headers to outgoing, unencrypted messages.
// _PEP_enc_format used to be intentionally hardcoded to PEP_enc_PEP:
// Since COM-74, this has been changed to an explicit parameter, to allow the engine to attach
// the keys and headers to outgoing, unencrypted messages.
PEP_encrypt_flags_t engineFlags = (PEP_encrypt_flags_t)flags;
PEP_STATUS status = ::encrypt_message_and_add_priv_key(session(), _src, &msg_dst, _to_fpr.c_str(), _encFormat, engineFlags);
@ -1291,7 +1355,8 @@ STDMETHODIMP CpEpEngine::EncryptMessageForSelf(pEpIdentity * targetId, TextMessa
text_message_from_C(dst, msg_dst);
else
text_message_from_C(dst, _src);
} catch (bad_alloc&) {
}
catch (bad_alloc&) {
result = E_OUTOFMEMORY;
}
catch (exception& ex) {
@ -1341,7 +1406,7 @@ STDMETHODIMP CpEpEngine::DecryptMessage(TextMessage * src, TextMessage * dst, SA
::stringlist_t *_keylist = new_stringlist(*keylist);
::PEP_rating _rating;
PEP_decrypt_flags_t engineflags = (PEP_decrypt_flags_t) *flags;
PEP_decrypt_flags_t engineflags = (PEP_decrypt_flags_t)*flags;
PEP_STATUS status = ::decrypt_message(session(), _src, &msg_dst, &_keylist, &_rating, &engineflags);
*flags = (pEpDecryptFlags)engineflags;
@ -1498,7 +1563,7 @@ STDMETHODIMP CpEpEngine::ColorFromRating(pEpRating rating, pEpColor * pVal)
PEP_color _color = ::color_from_rating(engineRating);
*pVal = (pEpColor)_color;
return S_OK;
}
@ -2003,7 +2068,7 @@ STDMETHODIMP CpEpEngine::PerUserDirectory(BSTR * directory)
return S_OK;
}
STDMETHODIMP CpEpEngine::RatingFromCommType(pEpComType commType, pEpRating * rating)
STDMETHODIMP CpEpEngine::RatingFromCommType(pEpComType commType, pEpRating * rating)
{
PEP_comm_type _comm_type = (PEP_comm_type)commType;
PEP_rating _rating = ::rating_from_comm_type(_comm_type);


+ 4
- 1
CpEpEngine.h View File

@ -13,6 +13,7 @@
#include <vector>
#include "..\libpEpAdapter\pc_container.hh"
#include "..\pEp\sync_codec.h"
#include "..\pEp\mime.h"
#if defined(_WIN32_WCE) && !defined(_CE_DCOM) && !defined(_CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA)
#error "Single-threaded COM objects are not properly supported on Windows CE platform, such as the Windows Mobile platforms that do not include full DCOM support. Define _CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA to force ATL to support creating single-thread COM object's and allow use of it's single-threaded COM object implementations. The threading model in your rgs file was set to 'Free' as that is the only threading model supported in non DCOM Windows CE platforms."
@ -280,7 +281,9 @@ public:
STDMETHOD(GetIsSyncRunning)(VARIANT_BOOL *running);
STDMETHOD(ShutDownSync)();
STDMETHOD(PERToXERSyncMessage)(TextMessage *msg, BSTR * xer);
STDMETHOD(PERToXERSyncMessage)(TextMessage *msg, BSTR *xer);
STDMETHOD(MIMEDecodeMessage)(BSTR mimeText, TextMessage *msg);
STDMETHOD(MIMEEncodeMessage)(TextMessage *msg, VARIANT_BOOL omitFields, BSTR *mimeText);
STDMETHOD(PerMachineDirectory)(BSTR * directory);
STDMETHOD(PerUserDirectory)(BSTR * directory);


+ 6
- 0
pEpCOMServerAdapter.idl View File

@ -521,6 +521,12 @@ interface IpEpEngine : IUnknown {
// Shuts down sync
[id(61)] HRESULT ShutDownSync();
// Decodes a MIME message
[id(62)] HRESULT MIMEDecodeMessage([in] BSTR mimeText, [out, retval] struct TextMessage *msg);
// Encodes a MIME message
[id(63)] HRESULT MIMEEncodeMessage([in] struct TextMessage *msg, [in] VARIANT_BOOL omitFields, [out, retval] BSTR *mimeText);
};
[


Loading…
Cancel
Save