Wrap mime_encode_message() and mime_decode_message() sync
authorThomas
Tue, 24 Dec 2019 13:44:31 +0100
branchsync
changeset 383eecca51a4ff0
parent 381 c653508fb454
child 384 b22401805ef0
Wrap mime_encode_message() and mime_decode_message()
CpEpEngine.cpp
CpEpEngine.h
pEpCOMServerAdapter.idl
     1.1 --- a/CpEpEngine.cpp	Mon Dec 02 17:23:05 2019 +0100
     1.2 +++ b/CpEpEngine.cpp	Tue Dec 24 13:44:31 2019 +0100
     1.3 @@ -64,7 +64,7 @@
     1.4  
     1.5      if (status)
     1.6          return FAIL(L"config_cipher_suite", status);
     1.7 -    
     1.8 +
     1.9      return S_OK;
    1.10  }
    1.11  
    1.12 @@ -264,7 +264,7 @@
    1.13  
    1.14          _fpr1 = utf8_string(fpr1);
    1.15          _fpr2 = utf8_string(fpr2);
    1.16 -        
    1.17 +
    1.18          if (lang) {
    1.19              _lang = utf8_string(lang);
    1.20              if (_lang.length() == 0) {
    1.21 @@ -616,6 +616,70 @@
    1.22      return S_OK;
    1.23  }
    1.24  
    1.25 +STDMETHODIMP CpEpEngine::MIMEDecodeMessage(BSTR mimeText, TextMessage *msg)
    1.26 +{
    1.27 +    assert(mimeText);
    1.28 +
    1.29 +    if (!mimeText)
    1.30 +        return E_INVALIDARG;
    1.31 +
    1.32 +    string _mimeText = utf8_string(mimeText);
    1.33 +    size_t size = SysStringLen(mimeText);
    1.34 +    ::message *_msg = NULL;
    1.35 +
    1.36 +    PEP_STATUS status = mime_decode_message(_mimeText.c_str(), size, &_msg);
    1.37 +    assert(status != ::PEP_OUT_OF_MEMORY);
    1.38 +    if (status == ::PEP_OUT_OF_MEMORY)
    1.39 +        return E_OUTOFMEMORY;
    1.40 +
    1.41 +    if (status != PEP_STATUS_OK)
    1.42 +        return FAIL(L"mime_decode_message", status);
    1.43 +
    1.44 +    if (_msg)
    1.45 +        text_message_from_C(msg, _msg);
    1.46 +
    1.47 +    free_message(_msg);
    1.48 +
    1.49 +    return status;
    1.50 +}
    1.51 +
    1.52 +
    1.53 +STDMETHODIMP CpEpEngine::MIMEEncodeMessage(TextMessage *msg, VARIANT_BOOL omitFields, BSTR *mimeText)
    1.54 +{
    1.55 +    assert(msg);
    1.56 +
    1.57 +    if (!msg)
    1.58 +        return E_INVALIDARG;
    1.59 +
    1.60 +    ::message *_msg = NULL;
    1.61 +    try {
    1.62 +        _msg = text_message_to_C(msg);
    1.63 +    }
    1.64 +    catch (bad_alloc&) {
    1.65 +        return E_OUTOFMEMORY;
    1.66 +    }
    1.67 +    catch (exception& ex) {
    1.68 +        return FAIL(ex.what());
    1.69 +    }
    1.70 +
    1.71 +    char *_mimeText;
    1.72 +
    1.73 +    PEP_STATUS status = mime_encode_message(_msg, omitFields != 0, &_mimeText);
    1.74 +    free_message(_msg);
    1.75 +
    1.76 +    assert(status != ::PEP_OUT_OF_MEMORY);
    1.77 +    if (status == ::PEP_OUT_OF_MEMORY)
    1.78 +        return E_OUTOFMEMORY;
    1.79 +
    1.80 +    if (status != PEP_STATUS_OK)
    1.81 +        return FAIL(L"mime_encode_message", status);
    1.82 +
    1.83 +    *mimeText = utf16_bstr(_mimeText);
    1.84 +    pEp_free(_mimeText);
    1.85 +
    1.86 +    return status;
    1.87 +}
    1.88 +
    1.89  STDMETHODIMP CpEpEngine::Myself(struct pEpIdentity *ident, struct pEpIdentity *result)
    1.90  {
    1.91      assert(ident);
    1.92 @@ -738,7 +802,7 @@
    1.93      return S_OK;
    1.94  }
    1.95  
    1.96 -STDMETHODIMP CpEpEngine::IspEpUser(/* [in] */ struct pEpIdentity *ident, /* [retval][out] */ VARIANT_BOOL *ispEp) 
    1.97 +STDMETHODIMP CpEpEngine::IspEpUser(/* [in] */ struct pEpIdentity *ident, /* [retval][out] */ VARIANT_BOOL *ispEp)
    1.98  {
    1.99      ::pEp_identity *_ident;
   1.100  
   1.101 @@ -943,7 +1007,7 @@
   1.102  static IpEpEngineCallbacks * _unmarshaled_consumer(CpEpEngine::callback_container::Container::iterator p)
   1.103  {
   1.104      if (!p->cdata && p->pdata && p->pdata->marshaled) {
   1.105 -        HRESULT r = CoGetInterfaceAndReleaseStream(p->pdata->marshaled, IID_IpEpEngineCallbacks, (LPVOID*) &p->cdata);
   1.106 +        HRESULT r = CoGetInterfaceAndReleaseStream(p->pdata->marshaled, IID_IpEpEngineCallbacks, (LPVOID*)&p->cdata);
   1.107          if (!SUCCEEDED(r))
   1.108              throw runtime_error("_unmarshaled_consumer(): CoGetInterfaceAndReleaseStream() failed");
   1.109          p->pdata->marshaled = nullptr;
   1.110 @@ -1215,9 +1279,9 @@
   1.111      ::message *msg_dst = NULL;
   1.112  
   1.113      string _to_fpr = utf8_string(to_fpr);
   1.114 -                                                    // _PEP_enc_format used to be intentionally hardcoded to PEP_enc_PEP:
   1.115 -                                                    // Since COM-74, this has been changed to an explicit parameter, to allow the engine to attach
   1.116 -                                                    // the keys and headers to outgoing, unencrypted messages.
   1.117 +    // _PEP_enc_format used to be intentionally hardcoded to PEP_enc_PEP:
   1.118 +    // Since COM-74, this has been changed to an explicit parameter, to allow the engine to attach
   1.119 +    // the keys and headers to outgoing, unencrypted messages.
   1.120      PEP_encrypt_flags_t engineFlags = (PEP_encrypt_flags_t)flags;
   1.121      PEP_STATUS status = ::encrypt_message_and_add_priv_key(session(), _src, &msg_dst, _to_fpr.c_str(), _encFormat, engineFlags);
   1.122  
   1.123 @@ -1291,7 +1355,8 @@
   1.124              text_message_from_C(dst, msg_dst);
   1.125          else
   1.126              text_message_from_C(dst, _src);
   1.127 -    } catch (bad_alloc&) {
   1.128 +    }
   1.129 +    catch (bad_alloc&) {
   1.130          result = E_OUTOFMEMORY;
   1.131      }
   1.132      catch (exception& ex) {
   1.133 @@ -1341,7 +1406,7 @@
   1.134      ::stringlist_t *_keylist = new_stringlist(*keylist);
   1.135      ::PEP_rating _rating;
   1.136  
   1.137 -    PEP_decrypt_flags_t engineflags = (PEP_decrypt_flags_t) *flags;
   1.138 +    PEP_decrypt_flags_t engineflags = (PEP_decrypt_flags_t)*flags;
   1.139      PEP_STATUS status = ::decrypt_message(session(), _src, &msg_dst, &_keylist, &_rating, &engineflags);
   1.140  
   1.141      *flags = (pEpDecryptFlags)engineflags;
   1.142 @@ -1498,7 +1563,7 @@
   1.143      PEP_color _color = ::color_from_rating(engineRating);
   1.144  
   1.145      *pVal = (pEpColor)_color;
   1.146 -     
   1.147 +
   1.148      return S_OK;
   1.149  }
   1.150  
   1.151 @@ -2003,7 +2068,7 @@
   1.152      return S_OK;
   1.153  }
   1.154  
   1.155 -STDMETHODIMP CpEpEngine::RatingFromCommType(pEpComType commType, pEpRating * rating) 
   1.156 +STDMETHODIMP CpEpEngine::RatingFromCommType(pEpComType commType, pEpRating * rating)
   1.157  {
   1.158      PEP_comm_type _comm_type = (PEP_comm_type)commType;
   1.159      PEP_rating _rating = ::rating_from_comm_type(_comm_type);
     2.1 --- a/CpEpEngine.h	Mon Dec 02 17:23:05 2019 +0100
     2.2 +++ b/CpEpEngine.h	Tue Dec 24 13:44:31 2019 +0100
     2.3 @@ -13,6 +13,7 @@
     2.4  #include <vector>
     2.5  #include "..\libpEpAdapter\pc_container.hh"
     2.6  #include "..\pEp\sync_codec.h"
     2.7 +#include "..\pEp\mime.h"
     2.8  
     2.9  #if defined(_WIN32_WCE) && !defined(_CE_DCOM) && !defined(_CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA)
    2.10  #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."
    2.11 @@ -280,7 +281,9 @@
    2.12      STDMETHOD(GetIsSyncRunning)(VARIANT_BOOL *running);
    2.13      STDMETHOD(ShutDownSync)();
    2.14  
    2.15 -    STDMETHOD(PERToXERSyncMessage)(TextMessage *msg, BSTR * xer);
    2.16 +    STDMETHOD(PERToXERSyncMessage)(TextMessage *msg, BSTR *xer);
    2.17 +    STDMETHOD(MIMEDecodeMessage)(BSTR mimeText, TextMessage *msg);
    2.18 +    STDMETHOD(MIMEEncodeMessage)(TextMessage *msg, VARIANT_BOOL omitFields, BSTR *mimeText);
    2.19  
    2.20      STDMETHOD(PerMachineDirectory)(BSTR * directory);
    2.21      STDMETHOD(PerUserDirectory)(BSTR * directory);
     3.1 --- a/pEpCOMServerAdapter.idl	Mon Dec 02 17:23:05 2019 +0100
     3.2 +++ b/pEpCOMServerAdapter.idl	Tue Dec 24 13:44:31 2019 +0100
     3.3 @@ -521,6 +521,12 @@
     3.4  
     3.5      // Shuts down sync
     3.6      [id(61)] HRESULT ShutDownSync();
     3.7 +
     3.8 +    // Decodes a MIME message
     3.9 +    [id(62)] HRESULT MIMEDecodeMessage([in] BSTR mimeText, [out, retval] struct TextMessage *msg);
    3.10 +
    3.11 +    // Encodes a MIME message
    3.12 +    [id(63)] HRESULT MIMEEncodeMessage([in] struct TextMessage *msg, [in] VARIANT_BOOL omitFields, [out, retval] BSTR *mimeText);
    3.13  };
    3.14  
    3.15  [