...
authorVolker Birk <vb@pep-project.org>
Sun, 31 May 2015 17:03:40 +0200
changeset 37863fc3ccd19d
parent 36 8ba5eb4b8daa
child 38 d314ed57180c
...
CpEpEngine.cpp
CpEpEngine.h
pEpCOMServerAdapter.idl
pEpCOMServerAdapter_i.c
pEpCOMServerAdapter_i.h
pEp_utility.h
pEp_utitlity.cpp
utf8_helper.cpp
     1.1 --- a/CpEpEngine.cpp	Sun May 31 13:30:25 2015 +0200
     1.2 +++ b/CpEpEngine.cpp	Sun May 31 17:03:40 2015 +0200
     1.3 @@ -865,7 +865,7 @@
     1.4      return E_FAIL;
     1.5  }
     1.6  
     1.7 -STDMETHODIMP CpEpEngine::encrypt_message(text_message * src, text_message ** dst, SAFEARRAY * extra)
     1.8 +STDMETHODIMP CpEpEngine::encrypt_message(text_message * src, text_message * dst, SAFEARRAY * extra)
     1.9  {
    1.10      assert(src);
    1.11      assert(dst);
    1.12 @@ -881,14 +881,14 @@
    1.13          FAIL(L"cannot encrypt message");
    1.14  
    1.15      if (msg_dst) {
    1.16 -        *dst = text_message_from_C(msg_dst);
    1.17 +        text_message_from_C(dst, msg_dst);
    1.18          free_message(msg_dst);
    1.19      }
    1.20  
    1.21      return S_OK;
    1.22  }
    1.23  
    1.24 -STDMETHODIMP CpEpEngine::decrypt_message(text_message * src, text_message ** dst, SAFEARRAY ** keylist, pEp_color *rating)
    1.25 +STDMETHODIMP CpEpEngine::decrypt_message(text_message * src, text_message * dst, SAFEARRAY ** keylist, pEp_color *rating)
    1.26  {
    1.27      assert(src);
    1.28      assert(dst);
    1.29 @@ -906,7 +906,7 @@
    1.30          return FAIL(L"decrypt message failed");
    1.31  
    1.32      if (msg_dst) {
    1.33 -        *dst = text_message_from_C(msg_dst);
    1.34 +        text_message_from_C(dst, msg_dst);
    1.35      }
    1.36  
    1.37      if (_keylist) {
     2.1 --- a/CpEpEngine.h	Sun May 31 13:30:25 2015 +0200
     2.2 +++ b/CpEpEngine.h	Sun May 31 17:03:40 2015 +0200
     2.3 @@ -147,8 +147,8 @@
     2.4      
     2.5      // Message API
     2.6  
     2.7 -    STDMETHOD(encrypt_message)(text_message * src, text_message ** dst, SAFEARRAY * extra);
     2.8 -    STDMETHOD(decrypt_message)(text_message * src, text_message ** dst, SAFEARRAY ** keylist, pEp_color *rating);
     2.9 +    STDMETHOD(encrypt_message)(text_message * src, text_message * dst, SAFEARRAY * extra);
    2.10 +    STDMETHOD(decrypt_message)(text_message * src, text_message * dst, SAFEARRAY ** keylist, pEp_color *rating);
    2.11      STDMETHOD(outgoing_message_color)(text_message *msg, pEp_color * pVal);
    2.12      STDMETHOD(identity_color)(pEp_identity_s * ident, pEp_color * pVal);
    2.13  
     3.1 --- a/pEpCOMServerAdapter.idl	Sun May 31 13:30:25 2015 +0200
     3.2 +++ b/pEpCOMServerAdapter.idl	Sun May 31 17:03:40 2015 +0200
     3.3 @@ -198,8 +198,8 @@
     3.4          SAFEARRAY(struct opt_field) opt_fields;
     3.5      };
     3.6  
     3.7 -    HRESULT encrypt_message([in] struct text_message *src, [out] struct text_message ** dst, [in] SAFEARRAY(BSTR) extra);
     3.8 -    HRESULT decrypt_message([in] struct text_message *src, [out] struct text_message ** dst, [out] SAFEARRAY(BSTR) *keylist, [out, retval] pEp_color *rating);
     3.9 +    HRESULT encrypt_message([in] struct text_message *src, [out] struct text_message * dst, [in] SAFEARRAY(BSTR) extra);
    3.10 +    HRESULT decrypt_message([in] struct text_message *src, [out] struct text_message * dst, [out] SAFEARRAY(BSTR) *keylist, [out, retval] pEp_color *rating);
    3.11      HRESULT outgoing_message_color([in] struct text_message *msg, [out, retval] pEp_color * pVal);
    3.12      HRESULT identity_color([in] struct pEp_identity_s * ident, [out, retval] pEp_color * pVal);
    3.13  };
     4.1 --- a/pEpCOMServerAdapter_i.c	Sun May 31 13:30:25 2015 +0200
     4.2 +++ b/pEpCOMServerAdapter_i.c	Sun May 31 17:03:40 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 Sun May 31 10:51:32 2015
     4.8 +/* at Sun May 31 16:53:30 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	Sun May 31 13:30:25 2015 +0200
     5.2 +++ b/pEpCOMServerAdapter_i.h	Sun May 31 17:03:40 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 Sun May 31 10:51:32 2015
     5.8 +/* at Sun May 31 16:53:30 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 @@ -339,12 +339,12 @@
    5.13          
    5.14          virtual HRESULT STDMETHODCALLTYPE encrypt_message( 
    5.15              /* [in] */ struct text_message *src,
    5.16 -            /* [out] */ struct text_message **dst,
    5.17 +            /* [out] */ struct text_message *dst,
    5.18              /* [in] */ SAFEARRAY * extra) = 0;
    5.19          
    5.20          virtual HRESULT STDMETHODCALLTYPE decrypt_message( 
    5.21              /* [in] */ struct text_message *src,
    5.22 -            /* [out] */ struct text_message **dst,
    5.23 +            /* [out] */ struct text_message *dst,
    5.24              /* [out] */ SAFEARRAY * *keylist,
    5.25              /* [retval][out] */ pEp_color *rating) = 0;
    5.26          
    5.27 @@ -503,13 +503,13 @@
    5.28          HRESULT ( STDMETHODCALLTYPE *encrypt_message )( 
    5.29              IpEpEngine * This,
    5.30              /* [in] */ struct text_message *src,
    5.31 -            /* [out] */ struct text_message **dst,
    5.32 +            /* [out] */ struct text_message *dst,
    5.33              /* [in] */ SAFEARRAY * extra);
    5.34          
    5.35          HRESULT ( STDMETHODCALLTYPE *decrypt_message )( 
    5.36              IpEpEngine * This,
    5.37              /* [in] */ struct text_message *src,
    5.38 -            /* [out] */ struct text_message **dst,
    5.39 +            /* [out] */ struct text_message *dst,
    5.40              /* [out] */ SAFEARRAY * *keylist,
    5.41              /* [retval][out] */ pEp_color *rating);
    5.42          
     6.1 --- a/pEp_utility.h	Sun May 31 13:30:25 2015 +0200
     6.2 +++ b/pEp_utility.h	Sun May 31 17:03:40 2015 +0200
     6.3 @@ -70,7 +70,7 @@
     6.4              return psaUDType;
     6.5          }
     6.6  
     6.7 -        text_message *text_message_from_C(::message *msg);
     6.8          ::message * text_message_to_C(text_message *msg);
     6.9 +        void text_message_from_C(text_message *msg2, ::message *msg);
    6.10      }
    6.11  }
     7.1 --- a/pEp_utitlity.cpp	Sun May 31 13:30:25 2015 +0200
     7.2 +++ b/pEp_utitlity.cpp	Sun May 31 17:03:40 2015 +0200
     7.3 @@ -95,6 +95,9 @@
     7.4  
     7.5          ::pEp_identity *new_identity(const pEp_identity_s * ident)
     7.6          {
     7.7 +            if (ident == NULL)
     7.8 +                return NULL;
     7.9 +
    7.10              ::pEp_identity *_ident;
    7.11  
    7.12              string _address;
    7.13 @@ -242,12 +245,11 @@
    7.14              return stringpair_list_length(tl);
    7.15          }
    7.16  
    7.17 -        text_message *text_message_from_C(::message *msg)
    7.18 +        void text_message_from_C(text_message *msg2, ::message *msg)
    7.19          {
    7.20 +            assert(msg2);
    7.21              assert(msg);
    7.22  
    7.23 -            text_message *msg2 = new text_message();
    7.24 -
    7.25              msg2->dir = (pEp_msg_direction) msg->dir;
    7.26              msg2->id = bstr(msg->id);
    7.27              msg2->shortmsg = bstr(msg->shortmsg);
    7.28 @@ -266,21 +268,23 @@
    7.29              msg2->keywords = string_array(msg->keywords).Detach();
    7.30              msg2->comments = bstr(msg->comments);
    7.31              msg2->opt_fields = array_from_C<opt_field, stringpair_list_t>(msg->opt_fields);
    7.32 -
    7.33 -            return msg2;
    7.34          }
    7.35  
    7.36 -        char * str(_bstr_t s)
    7.37 +        char * str(BSTR s)
    7.38          {
    7.39 -            char *_s = _strdup(utf8_string(s).c_str());
    7.40 +            string str = utf8_string(s);
    7.41 +            char *_s = _strdup(str.c_str());
    7.42              if (_s == NULL)
    7.43                  throw bad_alloc();
    7.44  
    7.45 -            return s;
    7.46 +            return _s;
    7.47          }
    7.48  
    7.49          bloblist_t *bloblist(SAFEARRAY *sa)
    7.50          {
    7.51 +            if (sa == NULL)
    7.52 +                return NULL;
    7.53 +
    7.54              LONG lbound, ubound;
    7.55              SafeArrayGetLBound(sa, 1, &lbound);
    7.56              SafeArrayGetUBound(sa, 1, &ubound);
    7.57 @@ -327,6 +331,9 @@
    7.58  
    7.59          identity_list *identities(SAFEARRAY * sa)
    7.60          {
    7.61 +            if (sa == NULL)
    7.62 +                return NULL;
    7.63 +
    7.64              LONG lbound, ubound;
    7.65              SafeArrayGetLBound(sa, 1, &lbound);
    7.66              SafeArrayGetUBound(sa, 1, &ubound);
    7.67 @@ -340,6 +347,7 @@
    7.68              identity_list *_il = il;
    7.69              for (LONG i = lbound; i <= ubound; i++) {
    7.70                  pEp_identity_s s;
    7.71 +                memset(&s, 0, sizeof(s));
    7.72                  SafeArrayGetElement(sa, &i, &s);
    7.73  
    7.74                  pEp_identity *ident;
    7.75 @@ -377,6 +385,9 @@
    7.76  
    7.77          stringpair_list_t *stringpair_list(SAFEARRAY * sa)
    7.78          {
    7.79 +            if (sa == NULL)
    7.80 +                return NULL;
    7.81 +
    7.82              LONG lbound, ubound;
    7.83              SafeArrayGetLBound(sa, 1, &lbound);
    7.84              SafeArrayGetUBound(sa, 1, &ubound);
    7.85 @@ -390,6 +401,7 @@
    7.86              stringpair_list_t *_il = il;
    7.87              for (LONG i = lbound; i <= ubound; i++) {
    7.88                  opt_field s;
    7.89 +                memset(&s, 0, sizeof(opt_field));
    7.90                  SafeArrayGetElement(sa, &i, &s);
    7.91  
    7.92                  stringpair_t *pair;
    7.93 @@ -421,6 +433,8 @@
    7.94              assert(msg);
    7.95  
    7.96              ::message * msg2 = new_message((PEP_msg_direction) msg->dir, NULL, NULL, NULL);
    7.97 +            if (msg2 == NULL)
    7.98 +                throw bad_alloc();
    7.99  
   7.100              msg2->id = str(msg->id);
   7.101              msg2->shortmsg = str(msg->shortmsg);
     8.1 --- a/utf8_helper.cpp	Sun May 31 13:30:25 2015 +0200
     8.2 +++ b/utf8_helper.cpp	Sun May 31 17:03:40 2015 +0200
     8.3 @@ -46,6 +46,9 @@
     8.4  
     8.5          string utf8_string(BSTR bstr, NORM_FORM norm)
     8.6          {
     8.7 +            if (bstr == NULL)
     8.8 +                return "";
     8.9 +
    8.10              return utf8_string((wstring) (wchar_t *) _bstr_t(bstr, true), norm);
    8.11          }
    8.12  
    8.13 @@ -77,6 +80,9 @@
    8.14  
    8.15          CComSafeArray<BSTR> string_array(const ::stringlist_t *stringlist)
    8.16          {
    8.17 +            if (stringlist == NULL)
    8.18 +                return CComSafeArray<BSTR>((ULONG)0);
    8.19 +
    8.20              CComSafeArray<BSTR> sa_string_list;
    8.21              int n = 0;
    8.22              for (const ::stringlist_t *k = stringlist; k != NULL; k = k->next) {
    8.23 @@ -94,6 +100,9 @@
    8.24  
    8.25          ::stringlist_t * new_stringlist(const SAFEARRAY * safearray)
    8.26          {
    8.27 +            if (safearray == NULL)
    8.28 +                return NULL;
    8.29 +
    8.30              CComSafeArray<BSTR> sa(safearray);
    8.31              int n_strings = 0;
    8.32              ::stringlist_t *_stringlist = ::new_stringlist((const char *) NULL);