decrypt_message() return values
authorVolker Birk <vb@pep-project.org>
Fri, 08 May 2015 10:07:08 +0200
changeset 193cfb847e13cd
parent 18 79c848166413
child 20 f77dd13806ff
decrypt_message() return values
CpEpEngine.cpp
CpEpEngine.h
pEpCOMServerAdapter.idl
pEpCOMServerAdapter_i.c
pEpCOMServerAdapter_i.h
     1.1 --- a/CpEpEngine.cpp	Tue May 05 10:27:36 2015 +0200
     1.2 +++ b/CpEpEngine.cpp	Fri May 08 10:07:08 2015 +0200
     1.3 @@ -888,11 +888,12 @@
     1.4      return S_OK;
     1.5  }
     1.6  
     1.7 -STDMETHODIMP CpEpEngine::decrypt_message(ITextMessage * src, ITextMessage ** dst, SAFEARRAY ** keylist)
     1.8 +STDMETHODIMP CpEpEngine::decrypt_message(ITextMessage * src, ITextMessage ** dst, SAFEARRAY ** keylist, pEp_color *rating)
     1.9  {
    1.10      assert(src);
    1.11      assert(dst);
    1.12      assert(keylist);
    1.13 +    assert(rating);
    1.14  
    1.15      CTextMessage *_src = dynamic_cast<CTextMessage *>(src);
    1.16      assert(_src);
    1.17 @@ -902,45 +903,58 @@
    1.18  
    1.19      ::message *msg_dst;
    1.20      ::stringlist_t *_keylist;
    1.21 -    PEP_STATUS status = ::decrypt_message(get_session(), _src->msg, PEP_MIME_none, &msg_dst, &_keylist);
    1.22 -    if (status != PEP_STATUS_OK)
    1.23 -        FAIL(L"cannot decrypt message");
    1.24 +    ::PEP_color _rating;
    1.25  
    1.26 -    assert(msg_dst);
    1.27 +    PEP_STATUS status = ::decrypt_message(get_session(), _src->msg, PEP_MIME_none, &msg_dst, &_keylist, &_rating);
    1.28 +    if (status != PEP_STATUS_OK && (status < PEP_UNENCRYPTED || status > PEP_CANNOT_DECRYPT_UNKNOWN))
    1.29 +        return FAIL(L"decrypt message failed");
    1.30  
    1.31 -    ITextMessage *i_dst;
    1.32 -    HRESULT hr = CTextMessage::CreateInstance(&i_dst);
    1.33 -    assert(hr == S_OK);
    1.34 +    if (msg_dst) {
    1.35 +        ITextMessage *i_dst;
    1.36 +        HRESULT hr = CTextMessage::CreateInstance(&i_dst);
    1.37 +        assert(hr == S_OK);
    1.38  
    1.39 -    if (hr != S_OK) {
    1.40 -        ::free_message(msg_dst);
    1.41 -        ::free_stringlist(_keylist);
    1.42 -        return hr;
    1.43 +        if (hr != S_OK) {
    1.44 +            ::free_message(msg_dst);
    1.45 +            ::free_stringlist(_keylist);
    1.46 +            return hr;
    1.47 +        }
    1.48 +
    1.49 +        CTextMessage *_dst = dynamic_cast<CTextMessage *>(i_dst);
    1.50 +        assert(_dst);
    1.51 +
    1.52 +        ::free_message(_dst->msg);
    1.53 +        _dst->msg = msg_dst;
    1.54 +
    1.55 +        *dst = i_dst;
    1.56 +    }
    1.57 +    else {
    1.58 +        *dst = NULL;
    1.59      }
    1.60  
    1.61 -    CTextMessage *_dst = dynamic_cast<CTextMessage *>(i_dst);
    1.62 -    assert(_dst);
    1.63 +    if (_keylist) {
    1.64 +        ULONG len = ::stringlist_length(_keylist);
    1.65 +        CComSafeArray<BSTR> sa;
    1.66 +        sa.Create(len);
    1.67  
    1.68 -    ::free_message(_dst->msg);
    1.69 -    _dst->msg = msg_dst;
    1.70 +        ::stringlist_t *_kl;
    1.71 +        ULONG i;
    1.72 +        for (_kl = _keylist, i = 0; _kl && _kl->value; _kl = _kl->next, i++)
    1.73 +            sa.SetAt(i, utf16_bstr(_kl->value).Detach(), false);
    1.74 +        ::free_stringlist(_keylist);
    1.75  
    1.76 -    ULONG len = ::stringlist_length(_keylist);
    1.77 -    CComSafeArray<BSTR> sa;
    1.78 -    sa.Create(len);
    1.79 +        *keylist = sa.Detach();
    1.80 +    }
    1.81 +    else {
    1.82 +        *keylist = NULL;
    1.83 +    }
    1.84  
    1.85 -    ::stringlist_t *_kl;
    1.86 -    ULONG i;
    1.87 -    for (_kl = _keylist, i = 0; _kl && _kl->value; _kl = _kl->next, i++)
    1.88 -        sa.SetAt(i, utf16_bstr(_kl->value).Detach(), false);
    1.89 -    ::free_stringlist(_keylist);
    1.90 -
    1.91 -    *dst = i_dst;
    1.92 -    *keylist = sa.Detach();
    1.93 +    *rating = (pEp_color) _rating;
    1.94  
    1.95      return S_OK;
    1.96  }
    1.97  
    1.98 -STDMETHODIMP CpEpEngine::message_color(ITextMessage *msg, pEp_color * pVal)
    1.99 +STDMETHODIMP CpEpEngine::outgoing_message_color(ITextMessage *msg, pEp_color * pVal)
   1.100  {
   1.101      assert(msg);
   1.102      assert(pVal);
   1.103 @@ -948,10 +962,13 @@
   1.104      CTextMessage *_msg = dynamic_cast<CTextMessage *>(msg);
   1.105      assert(_msg);
   1.106  
   1.107 +    if (_msg->msg->dir != PEP_dir_outgoing)
   1.108 +        return E_INVALIDARG;
   1.109 +
   1.110      PEP_color _color;
   1.111 -    PEP_STATUS status = ::message_color(get_session(), _msg->msg, &_color);
   1.112 +    PEP_STATUS status = ::outgoing_message_color(get_session(), _msg->msg, &_color);
   1.113      if (status != PEP_STATUS_OK)
   1.114 -        FAIL(L"cannot get message color");
   1.115 +        return FAIL(L"cannot get message color");
   1.116  
   1.117      *pVal = (pEp_color) _color;
   1.118      return S_OK;
   1.119 @@ -978,7 +995,7 @@
   1.120      PEP_STATUS status = ::identity_color(get_session(), _ident, &_color);
   1.121      free_identity(_ident);
   1.122      if (status != PEP_STATUS_OK)
   1.123 -        FAIL(L"cannot get message color");
   1.124 +        return FAIL(L"cannot get message color");
   1.125  
   1.126      *pVal = (pEp_color) _color;
   1.127      return S_OK;
     2.1 --- a/CpEpEngine.h	Tue May 05 10:27:36 2015 +0200
     2.2 +++ b/CpEpEngine.h	Fri May 08 10:07:08 2015 +0200
     2.3 @@ -147,8 +147,8 @@
     2.4      // Message API
     2.5  
     2.6      STDMETHOD(encrypt_message)(ITextMessage * src, ITextMessage ** dst, SAFEARRAY * extra);
     2.7 -    STDMETHOD(decrypt_message)(ITextMessage * src, ITextMessage ** dst, SAFEARRAY ** keylist);
     2.8 -    STDMETHOD(message_color)(ITextMessage *msg, pEp_color * pVal);
     2.9 +    STDMETHOD(decrypt_message)(ITextMessage * src, ITextMessage ** dst, SAFEARRAY ** keylist, pEp_color *rating);
    2.10 +    STDMETHOD(outgoing_message_color)(ITextMessage *msg, pEp_color * pVal);
    2.11      STDMETHOD(identity_color)(pEp_identity_s * ident, pEp_color * pVal);
    2.12  
    2.13  };
     3.1 --- a/pEpCOMServerAdapter.idl	Tue May 05 10:27:36 2015 +0200
     3.2 +++ b/pEpCOMServerAdapter.idl	Fri May 08 10:07:08 2015 +0200
     3.3 @@ -226,8 +226,8 @@
     3.4      } pEp_color;
     3.5  
     3.6      HRESULT encrypt_message([in] ITextMessage *src, [out] ITextMessage ** dst, [in, optional] SAFEARRAY(BSTR) extra);
     3.7 -    HRESULT decrypt_message([in] ITextMessage *src, [out] ITextMessage ** dst, [out] SAFEARRAY(BSTR) *keylist);
     3.8 -    HRESULT message_color([in] ITextMessage *msg, [out, retval] pEp_color * pVal);
     3.9 +    HRESULT decrypt_message([in] ITextMessage *src, [out] ITextMessage ** dst, [out] SAFEARRAY(BSTR) *keylist, [out] pEp_color *rating);
    3.10 +    HRESULT outgoing_message_color([in] ITextMessage *msg, [out, retval] pEp_color * pVal);
    3.11      HRESULT identity_color([in] struct pEp_identity_s * ident, [out, retval] pEp_color * pVal);
    3.12  };
    3.13  
     4.1 --- a/pEpCOMServerAdapter_i.c	Tue May 05 10:27:36 2015 +0200
     4.2 +++ b/pEpCOMServerAdapter_i.c	Fri May 08 10:07:08 2015 +0200
     4.3 @@ -6,7 +6,7 @@
     4.4  
     4.5  
     4.6   /* File created by MIDL compiler version 8.00.0603 */
     4.7 -/* at Tue May 05 10:27:03 2015
     4.8 +/* at Wed May 06 20:19:27 2015
     4.9   */
    4.10  /* Compiler settings for pEpCOMServerAdapter.idl:
    4.11      Oicf, W1, Zp8, env=Win32 (32b run), target_arch=X86 8.00.0603 
     5.1 --- a/pEpCOMServerAdapter_i.h	Tue May 05 10:27:36 2015 +0200
     5.2 +++ b/pEpCOMServerAdapter_i.h	Fri May 08 10:07:08 2015 +0200
     5.3 @@ -4,7 +4,7 @@
     5.4  
     5.5  
     5.6   /* File created by MIDL compiler version 8.00.0603 */
     5.7 -/* at Tue May 05 10:27:03 2015
     5.8 +/* at Wed May 06 20:19:27 2015
     5.9   */
    5.10  /* Compiler settings for pEpCOMServerAdapter.idl:
    5.11      Oicf, W1, Zp8, env=Win32 (32b run), target_arch=X86 8.00.0603 
    5.12 @@ -767,9 +767,10 @@
    5.13          virtual HRESULT STDMETHODCALLTYPE decrypt_message( 
    5.14              /* [in] */ ITextMessage *src,
    5.15              /* [out] */ ITextMessage **dst,
    5.16 -            /* [out] */ SAFEARRAY * *keylist) = 0;
    5.17 +            /* [out] */ SAFEARRAY * *keylist,
    5.18 +            /* [out] */ pEp_color *rating) = 0;
    5.19          
    5.20 -        virtual HRESULT STDMETHODCALLTYPE message_color( 
    5.21 +        virtual HRESULT STDMETHODCALLTYPE outgoing_message_color( 
    5.22              /* [in] */ ITextMessage *msg,
    5.23              /* [retval][out] */ pEp_color *pVal) = 0;
    5.24          
    5.25 @@ -929,9 +930,10 @@
    5.26              IpEpEngine * This,
    5.27              /* [in] */ ITextMessage *src,
    5.28              /* [out] */ ITextMessage **dst,
    5.29 -            /* [out] */ SAFEARRAY * *keylist);
    5.30 +            /* [out] */ SAFEARRAY * *keylist,
    5.31 +            /* [out] */ pEp_color *rating);
    5.32          
    5.33 -        HRESULT ( STDMETHODCALLTYPE *message_color )( 
    5.34 +        HRESULT ( STDMETHODCALLTYPE *outgoing_message_color )( 
    5.35              IpEpEngine * This,
    5.36              /* [in] */ ITextMessage *msg,
    5.37              /* [retval][out] */ pEp_color *pVal);
    5.38 @@ -1036,11 +1038,11 @@
    5.39  #define IpEpEngine_encrypt_message(This,src,dst,extra)	\
    5.40      ( (This)->lpVtbl -> encrypt_message(This,src,dst,extra) ) 
    5.41  
    5.42 -#define IpEpEngine_decrypt_message(This,src,dst,keylist)	\
    5.43 -    ( (This)->lpVtbl -> decrypt_message(This,src,dst,keylist) ) 
    5.44 +#define IpEpEngine_decrypt_message(This,src,dst,keylist,rating)	\
    5.45 +    ( (This)->lpVtbl -> decrypt_message(This,src,dst,keylist,rating) ) 
    5.46  
    5.47 -#define IpEpEngine_message_color(This,msg,pVal)	\
    5.48 -    ( (This)->lpVtbl -> message_color(This,msg,pVal) ) 
    5.49 +#define IpEpEngine_outgoing_message_color(This,msg,pVal)	\
    5.50 +    ( (This)->lpVtbl -> outgoing_message_color(This,msg,pVal) ) 
    5.51  
    5.52  #define IpEpEngine_identity_color(This,ident,pVal)	\
    5.53      ( (This)->lpVtbl -> identity_color(This,ident,pVal) )