locking
authorVolker Birk <vb@pep-project.org>
Sat, 30 May 2015 19:36:36 +0200
changeset 32b9e23540d7fd
parent 31 83a083fb4810
child 33 39c7fbbbe028
locking
CpEpEngine.cpp
CpEpEngine.h
TextMessage.cpp
TextMessage.h
pEpCOMServerAdapter.idl
pEpCOMServerAdapter_i.c
pEpCOMServerAdapter_i.h
     1.1 --- a/CpEpEngine.cpp	Sat May 30 15:53:25 2015 +0200
     1.2 +++ b/CpEpEngine.cpp	Sat May 30 19:36:36 2015 +0200
     1.3 @@ -866,15 +866,17 @@
     1.4      return E_FAIL;
     1.5  }
     1.6  
     1.7 -STDMETHODIMP CpEpEngine::encrypt_message(ITextMessage * src, ITextMessage ** dst, SAFEARRAY * extra)
     1.8 +STDMETHODIMP CpEpEngine::encrypt_message(ITextMessage * src, ITextMessage * dst, SAFEARRAY * extra)
     1.9  {
    1.10      assert(src);
    1.11      assert(dst);
    1.12  
    1.13      CTextMessage *_src = dynamic_cast<CTextMessage *>(src);
    1.14      assert(_src);
    1.15 +    CTextMessage *_dst = dynamic_cast<CTextMessage *>(dst);
    1.16 +    assert(_dst);
    1.17  
    1.18 -    if (_src->msg->enc_format != PEP_enc_none)
    1.19 +    if (_src->msg()->enc_format != PEP_enc_none)
    1.20          return E_INVALIDARG;
    1.21  
    1.22      ::stringlist_t * _extra = NULL;
    1.23 @@ -891,35 +893,20 @@
    1.24      }
    1.25  
    1.26      ::message *msg_dst;
    1.27 -    PEP_STATUS status = ::encrypt_message(get_session(), _src->msg, _extra, &msg_dst, PEP_enc_pieces);
    1.28 +    PEP_STATUS status = ::encrypt_message(get_session(), _src->msg(), _extra, &msg_dst, PEP_enc_pieces);
    1.29      if (status != PEP_STATUS_OK)
    1.30          FAIL(L"cannot encrypt message");
    1.31  
    1.32      ::free_stringlist(_extra);
    1.33  
    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 -            return hr;
    1.42 -        }
    1.43 -
    1.44 -        CTextMessage *_dst = dynamic_cast<CTextMessage *>(i_dst);
    1.45 -        assert(_dst);
    1.46 -
    1.47 -        ::free_message(_dst->msg);
    1.48 -        _dst->msg = msg_dst;
    1.49 -
    1.50 -        *dst = i_dst;
    1.51 +        _dst->msg(msg_dst);
    1.52      }
    1.53  
    1.54      return S_OK;
    1.55  }
    1.56  
    1.57 -STDMETHODIMP CpEpEngine::decrypt_message(ITextMessage * src, ITextMessage ** dst, SAFEARRAY ** keylist, pEp_color *rating)
    1.58 +STDMETHODIMP CpEpEngine::decrypt_message(ITextMessage * src, ITextMessage * dst, SAFEARRAY ** keylist, pEp_color *rating)
    1.59  {
    1.60      assert(src);
    1.61      assert(dst);
    1.62 @@ -928,39 +915,22 @@
    1.63  
    1.64      CTextMessage *_src = dynamic_cast<CTextMessage *>(src);
    1.65      assert(_src);
    1.66 +    CTextMessage *_dst = dynamic_cast<CTextMessage *>(dst);
    1.67 +    assert(_dst);
    1.68  
    1.69 -    if (_src->msg->enc_format != PEP_enc_none)
    1.70 +    if (_src->msg()->enc_format != PEP_enc_none)
    1.71          return E_INVALIDARG;
    1.72  
    1.73      ::message *msg_dst;
    1.74      ::stringlist_t *_keylist;
    1.75      ::PEP_color _rating;
    1.76  
    1.77 -    PEP_STATUS status = ::decrypt_message(get_session(), _src->msg, &msg_dst, &_keylist, &_rating);
    1.78 +    PEP_STATUS status = ::decrypt_message(get_session(), _src->msg(), &msg_dst, &_keylist, &_rating);
    1.79      if (status != PEP_STATUS_OK)
    1.80          return FAIL(L"decrypt message failed");
    1.81  
    1.82      if (msg_dst) {
    1.83 -        ITextMessage *i_dst;
    1.84 -        HRESULT hr = CTextMessage::CreateInstance(&i_dst);
    1.85 -        assert(hr == S_OK);
    1.86 -
    1.87 -        if (hr != S_OK) {
    1.88 -            ::free_message(msg_dst);
    1.89 -            ::free_stringlist(_keylist);
    1.90 -            return hr;
    1.91 -        }
    1.92 -
    1.93 -        CTextMessage *_dst = dynamic_cast<CTextMessage *>(i_dst);
    1.94 -        assert(_dst);
    1.95 -
    1.96 -        ::free_message(_dst->msg);
    1.97 -        _dst->msg = msg_dst;
    1.98 -
    1.99 -        *dst = i_dst;
   1.100 -    }
   1.101 -    else {
   1.102 -        *dst = NULL;
   1.103 +        _dst->msg(msg_dst);
   1.104      }
   1.105  
   1.106      if (_keylist) {
   1.107 @@ -993,11 +963,11 @@
   1.108      CTextMessage *_msg = dynamic_cast<CTextMessage *>(msg);
   1.109      assert(_msg);
   1.110  
   1.111 -    if (_msg->msg->dir != PEP_dir_outgoing)
   1.112 +    if (_msg->msg()->dir != PEP_dir_outgoing)
   1.113          return E_INVALIDARG;
   1.114  
   1.115      PEP_color _color;
   1.116 -    PEP_STATUS status = ::outgoing_message_color(get_session(), _msg->msg, &_color);
   1.117 +    PEP_STATUS status = ::outgoing_message_color(get_session(), _msg->msg(), &_color);
   1.118      if (status != PEP_STATUS_OK)
   1.119          return FAIL(L"cannot get message color");
   1.120  
     2.1 --- a/CpEpEngine.h	Sat May 30 15:53:25 2015 +0200
     2.2 +++ b/CpEpEngine.h	Sat May 30 19:36:36 2015 +0200
     2.3 @@ -147,8 +147,8 @@
     2.4      
     2.5      // Message API
     2.6  
     2.7 -    STDMETHOD(encrypt_message)(ITextMessage * src, ITextMessage ** dst, SAFEARRAY * extra);
     2.8 -    STDMETHOD(decrypt_message)(ITextMessage * src, ITextMessage ** dst, SAFEARRAY ** keylist, pEp_color *rating);
     2.9 +    STDMETHOD(encrypt_message)(ITextMessage * src, ITextMessage * dst, SAFEARRAY * extra);
    2.10 +    STDMETHOD(decrypt_message)(ITextMessage * src, ITextMessage * dst, SAFEARRAY ** keylist, pEp_color *rating);
    2.11      STDMETHOD(outgoing_message_color)(ITextMessage *msg, pEp_color * pVal);
    2.12      STDMETHOD(identity_color)(pEp_identity_s * ident, pEp_color * pVal);
    2.13  
     3.1 --- a/TextMessage.cpp	Sat May 30 15:53:25 2015 +0200
     3.2 +++ b/TextMessage.cpp	Sat May 30 19:36:36 2015 +0200
     3.3 @@ -28,7 +28,7 @@
     3.4      assert(pVal);
     3.5  
     3.6      try {
     3.7 -        copy_identity(pVal, msg->from);
     3.8 +        copy_identity(pVal, msg()->from);
     3.9      }
    3.10      catch (bad_alloc&) {
    3.11          return E_OUTOFMEMORY;
    3.12 @@ -58,8 +58,8 @@
    3.13          return E_FAIL;
    3.14      }
    3.15  
    3.16 -    ::free_identity(msg->from);
    3.17 -    msg->from = _from;
    3.18 +    ::free_identity(msg()->from);
    3.19 +    msg()->from = _from;
    3.20      return S_OK;
    3.21  }
    3.22  
    3.23 @@ -164,12 +164,12 @@
    3.24  
    3.25  STDMETHODIMP CTextMessage::get_to(LPSAFEARRAY * pVal)
    3.26  {
    3.27 -    return il_get(msg->to, pVal);
    3.28 +    return il_get(msg()->to, pVal);
    3.29  }
    3.30  
    3.31  STDMETHODIMP CTextMessage::put_to(SAFEARRAY * newVal)
    3.32  {
    3.33 -    return il_put(&msg->to, newVal);
    3.34 +    return il_put(&msg()->to, newVal);
    3.35  }
    3.36  
    3.37  STDMETHODIMP CTextMessage::get_recv_by(pEp_identity_s* pVal)
    3.38 @@ -177,7 +177,7 @@
    3.39      assert(pVal);
    3.40  
    3.41      try {
    3.42 -        copy_identity(pVal, msg->recv_by);
    3.43 +        copy_identity(pVal, msg()->recv_by);
    3.44      }
    3.45      catch (bad_alloc&) {
    3.46          return E_OUTOFMEMORY;
    3.47 @@ -206,53 +206,53 @@
    3.48          return E_FAIL;
    3.49      }
    3.50  
    3.51 -    ::free_identity(msg->recv_by);
    3.52 -    msg->recv_by = _recv_by;
    3.53 +    ::free_identity(msg()->recv_by);
    3.54 +    msg()->recv_by = _recv_by;
    3.55      return S_OK;
    3.56  }
    3.57  
    3.58  STDMETHODIMP CTextMessage::get_cc(LPSAFEARRAY * pVal)
    3.59  {
    3.60 -    return il_get(msg->cc, pVal);
    3.61 +    return il_get(msg()->cc, pVal);
    3.62  }
    3.63  
    3.64  STDMETHODIMP CTextMessage::put_cc(SAFEARRAY * newVal)
    3.65  {
    3.66 -    return il_put(&msg->cc, newVal);
    3.67 +    return il_put(&msg()->cc, newVal);
    3.68  }
    3.69  
    3.70  STDMETHODIMP CTextMessage::get_bcc(LPSAFEARRAY * pVal)
    3.71  {
    3.72 -    return il_get(msg->bcc, pVal);
    3.73 +    return il_get(msg()->bcc, pVal);
    3.74  }
    3.75  
    3.76  STDMETHODIMP CTextMessage::put_bcc(SAFEARRAY * newVal)
    3.77  {
    3.78 -    return il_put(&msg->bcc, newVal);
    3.79 +    return il_put(&msg()->bcc, newVal);
    3.80  }
    3.81  
    3.82  STDMETHODIMP CTextMessage::get_reply_to(LPSAFEARRAY * pVal)
    3.83  {
    3.84 -    return il_get(msg->reply_to, pVal);
    3.85 +    return il_get(msg()->reply_to, pVal);
    3.86  }
    3.87  
    3.88  STDMETHODIMP CTextMessage::put_reply_to(SAFEARRAY * newVal)
    3.89  {
    3.90 -    return il_put(&msg->reply_to, newVal);
    3.91 +    return il_put(&msg()->reply_to, newVal);
    3.92  }
    3.93  
    3.94  STDMETHODIMP CTextMessage::get_dir(pEp_msg_direction *pVal)
    3.95  {
    3.96      assert(pVal);
    3.97  
    3.98 -    *pVal = (pEp_msg_direction) msg->dir;
    3.99 +    *pVal = (pEp_msg_direction) msg()->dir;
   3.100  
   3.101      return S_OK;
   3.102  }
   3.103  
   3.104  STDMETHODIMP CTextMessage::put_dir(pEp_msg_direction newVal)
   3.105  {
   3.106 -    msg->dir = (PEP_msg_direction) newVal;
   3.107 +    msg()->dir = (PEP_msg_direction) newVal;
   3.108  
   3.109      return S_OK;
   3.110  }
   3.111 @@ -263,9 +263,9 @@
   3.112  
   3.113      _bstr_t val;
   3.114  
   3.115 -    if (msg->id) {
   3.116 +    if (msg()->id) {
   3.117          try {
   3.118 -            val = utf16_bstr(msg->id);
   3.119 +            val = utf16_bstr(msg()->id);
   3.120          }
   3.121          catch (bad_alloc&) {
   3.122              return E_OUTOFMEMORY;
   3.123 @@ -300,10 +300,10 @@
   3.124              return E_OUTOFMEMORY;
   3.125      }
   3.126  
   3.127 -    if (msg->id)
   3.128 -        free(msg->id);
   3.129 +    if (msg()->id)
   3.130 +        free(msg()->id);
   3.131  
   3.132 -    msg->id = _val;
   3.133 +    msg()->id = _val;
   3.134      return S_OK;
   3.135  }
   3.136  
   3.137 @@ -313,9 +313,9 @@
   3.138  
   3.139      _bstr_t val;
   3.140  
   3.141 -    if (msg->shortmsg) {
   3.142 +    if (msg()->shortmsg) {
   3.143          try {
   3.144 -            val = utf16_bstr(msg->shortmsg);
   3.145 +            val = utf16_bstr(msg()->shortmsg);
   3.146          }
   3.147          catch (bad_alloc&) {
   3.148              return E_OUTOFMEMORY;
   3.149 @@ -351,10 +351,10 @@
   3.150              return E_OUTOFMEMORY;
   3.151      }
   3.152  
   3.153 -    if (msg->shortmsg)
   3.154 -        free(msg->shortmsg);
   3.155 +    if (msg()->shortmsg)
   3.156 +        free(msg()->shortmsg);
   3.157  
   3.158 -    msg->shortmsg = _val;
   3.159 +    msg()->shortmsg = _val;
   3.160      return S_OK;
   3.161  }
   3.162  
   3.163 @@ -364,9 +364,9 @@
   3.164  
   3.165      _bstr_t val;
   3.166  
   3.167 -    if (msg->longmsg) {
   3.168 +    if (msg()->longmsg) {
   3.169          try {
   3.170 -            val = utf16_bstr(msg->longmsg);
   3.171 +            val = utf16_bstr(msg()->longmsg);
   3.172          }
   3.173          catch (bad_alloc&) {
   3.174              return E_OUTOFMEMORY;
   3.175 @@ -402,10 +402,10 @@
   3.176              return E_OUTOFMEMORY;
   3.177      }
   3.178  
   3.179 -    if (msg->longmsg)
   3.180 -        free(msg->longmsg);
   3.181 +    if (msg()->longmsg)
   3.182 +        free(msg()->longmsg);
   3.183  
   3.184 -    msg->longmsg = _val;
   3.185 +    msg()->longmsg = _val;
   3.186      return S_OK;
   3.187  }
   3.188  
   3.189 @@ -415,9 +415,9 @@
   3.190  
   3.191      _bstr_t val;
   3.192  
   3.193 -    if (msg->longmsg_formatted) {
   3.194 +    if (msg()->longmsg_formatted) {
   3.195          try {
   3.196 -            val = utf16_bstr(msg->longmsg_formatted);
   3.197 +            val = utf16_bstr(msg()->longmsg_formatted);
   3.198          }
   3.199          catch (bad_alloc&) {
   3.200              return E_OUTOFMEMORY;
   3.201 @@ -453,10 +453,10 @@
   3.202              return E_OUTOFMEMORY;
   3.203      }
   3.204  
   3.205 -    if (msg->longmsg_formatted)
   3.206 -        free(msg->longmsg_formatted);
   3.207 +    if (msg()->longmsg_formatted)
   3.208 +        free(msg()->longmsg_formatted);
   3.209  
   3.210 -    msg->longmsg_formatted = _val;
   3.211 +    msg()->longmsg_formatted = _val;
   3.212      return S_OK;
   3.213  }
   3.214  
   3.215 @@ -508,14 +508,14 @@
   3.216          }
   3.217      }
   3.218  
   3.219 -    bloblist_t *blob = bloblist_add(msg->attachments, _data, len, _mime_type.c_str(), _filename.c_str());
   3.220 +    bloblist_t *blob = bloblist_add(msg()->attachments, _data, len, _mime_type.c_str(), _filename.c_str());
   3.221      if (blob == NULL) {
   3.222          free(_data);
   3.223          return E_OUTOFMEMORY;
   3.224      }
   3.225  
   3.226 -    if (msg->attachments == NULL)
   3.227 -        msg->attachments = blob;
   3.228 +    if (msg()->attachments == NULL)
   3.229 +        msg()->attachments = blob;
   3.230  
   3.231      return S_OK;
   3.232  }
   3.233 @@ -524,13 +524,13 @@
   3.234  {
   3.235      assert(result);
   3.236  
   3.237 -    if (msg->attachments == NULL || msg->attachments->data == NULL) {
   3.238 +    if (msg()->attachments == NULL || msg()->attachments->data == NULL) {
   3.239          m_next_attachment = NULL;
   3.240          *result = false;
   3.241          return S_OK;
   3.242      }
   3.243  
   3.244 -    m_next_attachment = msg->attachments;
   3.245 +    m_next_attachment = msg()->attachments;
   3.246      *result = true;
   3.247  
   3.248      return S_OK;
   3.249 @@ -596,10 +596,10 @@
   3.250  {
   3.251      assert(result);
   3.252  
   3.253 -    if (msg->sent == NULL)
   3.254 +    if (msg()->sent == NULL)
   3.255          return E_NOT_SET;
   3.256  
   3.257 -    *result = mktime(msg->sent);
   3.258 +    *result = mktime(msg()->sent);
   3.259      return S_OK;
   3.260  }
   3.261  
   3.262 @@ -609,9 +609,9 @@
   3.263      if (ts == NULL)
   3.264          return E_OUTOFMEMORY;
   3.265  
   3.266 -    if (msg->sent)
   3.267 -        free_timestamp(msg->sent);
   3.268 -    msg->sent = ts;
   3.269 +    if (msg()->sent)
   3.270 +        free_timestamp(msg()->sent);
   3.271 +    msg()->sent = ts;
   3.272  
   3.273      return S_OK;
   3.274  }
   3.275 @@ -620,10 +620,10 @@
   3.276  {
   3.277      assert(result);
   3.278  
   3.279 -    if (msg->recv == NULL)
   3.280 +    if (msg()->recv == NULL)
   3.281          return E_NOT_SET;
   3.282  
   3.283 -    *result = mktime(msg->recv);
   3.284 +    *result = mktime(msg()->recv);
   3.285      return S_OK;
   3.286  }
   3.287  
   3.288 @@ -633,9 +633,9 @@
   3.289      if (ts == NULL)
   3.290          return E_OUTOFMEMORY;
   3.291  
   3.292 -    if (msg->recv)
   3.293 -        free_timestamp(msg->recv);
   3.294 -    msg->recv = ts;
   3.295 +    if (msg()->recv)
   3.296 +        free_timestamp(msg()->recv);
   3.297 +    msg()->recv = ts;
   3.298  
   3.299      return S_OK;
   3.300  }
   3.301 @@ -646,8 +646,8 @@
   3.302  
   3.303      CComSafeArray<BSTR> sa;
   3.304      try {
   3.305 -        if (msg->references) {
   3.306 -            sa = string_array(msg->references);
   3.307 +        if (msg()->references) {
   3.308 +            sa = string_array(msg()->references);
   3.309          }
   3.310          else {
   3.311              sa.Create(0UL);
   3.312 @@ -680,10 +680,10 @@
   3.313          return E_FAIL;
   3.314      }
   3.315  
   3.316 -    if (msg->references)
   3.317 -        free_stringlist(msg->references);
   3.318 +    if (msg()->references)
   3.319 +        free_stringlist(msg()->references);
   3.320  
   3.321 -    msg->references = sl;
   3.322 +    msg()->references = sl;
   3.323  
   3.324      return S_OK;
   3.325  }
   3.326 @@ -694,8 +694,8 @@
   3.327  
   3.328      CComSafeArray<BSTR> sa;
   3.329      try {
   3.330 -        if (msg->keywords) {
   3.331 -            sa = string_array(msg->keywords);
   3.332 +        if (msg()->keywords) {
   3.333 +            sa = string_array(msg()->keywords);
   3.334          }
   3.335          else {
   3.336              sa.Create(0UL);
   3.337 @@ -728,10 +728,10 @@
   3.338          return E_FAIL;
   3.339      }
   3.340  
   3.341 -    if (msg->keywords)
   3.342 -        free_stringlist(msg->keywords);
   3.343 +    if (msg()->keywords)
   3.344 +        free_stringlist(msg()->keywords);
   3.345  
   3.346 -    msg->keywords = sl;
   3.347 +    msg()->keywords = sl;
   3.348  
   3.349      return S_OK;
   3.350  }
   3.351 @@ -742,9 +742,9 @@
   3.352  
   3.353      _bstr_t val;
   3.354  
   3.355 -    if (msg->comments) {
   3.356 +    if (msg()->comments) {
   3.357          try {
   3.358 -            val = utf16_bstr(msg->comments);
   3.359 +            val = utf16_bstr(msg()->comments);
   3.360          }
   3.361          catch (bad_alloc&) {
   3.362              return E_OUTOFMEMORY;
   3.363 @@ -780,10 +780,10 @@
   3.364              return E_OUTOFMEMORY;
   3.365      }
   3.366  
   3.367 -    if (msg->comments)
   3.368 -        free(msg->comments);
   3.369 +    if (msg()->comments)
   3.370 +        free(msg()->comments);
   3.371  
   3.372 -    msg->comments = _val;
   3.373 +    msg()->comments = _val;
   3.374      return S_OK;
   3.375  }
   3.376  
   3.377 @@ -791,10 +791,10 @@
   3.378  {
   3.379      assert(pVal);
   3.380  
   3.381 -    if (msg->opt_fields == NULL)
   3.382 +    if (msg()->opt_fields == NULL)
   3.383          return S_OK;
   3.384  
   3.385 -    int len = stringpair_list_length(msg->opt_fields);
   3.386 +    int len = stringpair_list_length(msg()->opt_fields);
   3.387  
   3.388      LPSAFEARRAY sa = newSafeArray<struct opt_field>(len);
   3.389      if (sa == NULL)
   3.390 @@ -802,7 +802,7 @@
   3.391  
   3.392      stringpair_list_t *il;
   3.393      LONG i;
   3.394 -    for (i = 0, il = msg->opt_fields; il && il->value; il = il->next, i++) {
   3.395 +    for (i = 0, il = msg()->opt_fields; il && il->value; il = il->next, i++) {
   3.396          opt_field fld;
   3.397          memset(&fld, 0, sizeof(opt_field));
   3.398  
   3.399 @@ -875,8 +875,8 @@
   3.400          }
   3.401      }
   3.402  
   3.403 -    free_stringpair_list(msg->opt_fields);
   3.404 -    msg->opt_fields = il;
   3.405 +    free_stringpair_list(msg()->opt_fields);
   3.406 +    msg()->opt_fields = il;
   3.407  
   3.408      return S_OK;
   3.409  }
     4.1 --- a/TextMessage.h	Sat May 30 15:53:25 2015 +0200
     4.2 +++ b/TextMessage.h	Sat May 30 19:36:36 2015 +0200
     4.3 @@ -28,16 +28,57 @@
     4.4  {
     4.5  private:
     4.6      ::bloblist_t *m_next_attachment;
     4.7 +    mutex message_mutex;
     4.8 +    ::message *_msg;
     4.9 +
    4.10 +protected:
    4.11 +    class Msg {
    4.12 +    private:
    4.13 +        CTextMessage *me;
    4.14 +
    4.15 +    public:
    4.16 +        Msg(CTextMessage *myself)
    4.17 +        {
    4.18 +            me = myself;
    4.19 +            me->message_mutex.lock();
    4.20 +        }
    4.21 +
    4.22 +        ~Msg()
    4.23 +        {
    4.24 +            me->message_mutex.unlock();
    4.25 +        }
    4.26 +
    4.27 +        ::message * operator->()
    4.28 +        {
    4.29 +            return me->_msg;
    4.30 +        }
    4.31 +
    4.32 +        operator ::message *()
    4.33 +        {
    4.34 +            return me->_msg;
    4.35 +        }
    4.36 +    };
    4.37  
    4.38  public:
    4.39 -    ::message *msg;
    4.40 +    Msg msg()
    4.41 +    {
    4.42 +        return Msg(this);
    4.43 +    }
    4.44 +
    4.45 +    void msg(::message *new_msg)
    4.46 +    {
    4.47 +        lock_guard<mutex> lg(message_mutex);
    4.48 +
    4.49 +        ::free_message(_msg);
    4.50 +        _msg = new_msg;
    4.51 +    }
    4.52  
    4.53      CTextMessage()
    4.54          : m_next_attachment(NULL)
    4.55  	{
    4.56 -        msg = (::message *) calloc(1, sizeof(::message));
    4.57 -        assert(msg);
    4.58 -        if (msg == NULL)
    4.59 +        _msg = (::message *) calloc(1, sizeof(::message));
    4.60 +        assert(_msg);
    4.61 +        if (_msg == NULL)
    4.62              throw bad_alloc();
    4.63  	}
    4.64  
    4.65 @@ -46,15 +87,15 @@
    4.66      CTextMessage(const CTextMessage& second)
    4.67          : m_next_attachment(NULL)
    4.68      {
    4.69 -        msg = (::message *) calloc(1, sizeof(::message));
    4.70 -        assert(msg);
    4.71 -        if (msg == NULL)
    4.72 +        _msg = (::message *) calloc(1, sizeof(::message));
    4.73 +        assert(_msg);
    4.74 +        if (_msg == NULL)
    4.75              throw bad_alloc();
    4.76      }
    4.77  
    4.78      virtual ~CTextMessage()
    4.79      {
    4.80 -        ::free_message(msg);
    4.81 +        ::free_message(_msg);
    4.82      }
    4.83  
    4.84  DECLARE_REGISTRY_RESOURCEID(IDR_TEXTMESSAGE)
     5.1 --- a/pEpCOMServerAdapter.idl	Sat May 30 15:53:25 2015 +0200
     5.2 +++ b/pEpCOMServerAdapter.idl	Sat May 30 19:36:36 2015 +0200
     5.3 @@ -236,8 +236,8 @@
     5.4          pEp_rating_b0rken = -2
     5.5      } pEp_color;
     5.6  
     5.7 -    HRESULT encrypt_message([in] ITextMessage *src, [out] ITextMessage ** dst, [in] SAFEARRAY(BSTR) extra);
     5.8 -    HRESULT decrypt_message([in] ITextMessage *src, [out] ITextMessage ** dst, [out] SAFEARRAY(BSTR) *keylist, [out, retval] pEp_color *rating);
     5.9 +    HRESULT encrypt_message([in,ref] ITextMessage *src, [in,ref] ITextMessage * dst, [in] SAFEARRAY(BSTR) extra);
    5.10 +    HRESULT decrypt_message([in,ref] ITextMessage *src, [in,ref] ITextMessage * dst, [out] SAFEARRAY(BSTR) *keylist, [out, retval] pEp_color *rating);
    5.11      HRESULT outgoing_message_color([in] ITextMessage *msg, [out, retval] pEp_color * pVal);
    5.12      HRESULT identity_color([in] struct pEp_identity_s * ident, [out, retval] pEp_color * pVal);
    5.13  };
     6.1 --- a/pEpCOMServerAdapter_i.c	Sat May 30 15:53:25 2015 +0200
     6.2 +++ b/pEpCOMServerAdapter_i.c	Sat May 30 19:36:36 2015 +0200
     6.3 @@ -6,7 +6,7 @@
     6.4  
     6.5  
     6.6   /* File created by MIDL compiler version 8.00.0603 */
     6.7 -/* at Sat May 30 12:51:56 2015
     6.8 +/* at Sat May 30 18:16:12 2015
     6.9   */
    6.10  /* Compiler settings for pEpCOMServerAdapter.idl:
    6.11      Oicf, W1, Zp8, env=Win32 (32b run), target_arch=X86 8.00.0603 
     7.1 --- a/pEpCOMServerAdapter_i.h	Sat May 30 15:53:25 2015 +0200
     7.2 +++ b/pEpCOMServerAdapter_i.h	Sat May 30 19:36:36 2015 +0200
     7.3 @@ -4,7 +4,7 @@
     7.4  
     7.5  
     7.6   /* File created by MIDL compiler version 8.00.0603 */
     7.7 -/* at Sat May 30 12:51:56 2015
     7.8 +/* at Sat May 30 18:16:12 2015
     7.9   */
    7.10  /* Compiler settings for pEpCOMServerAdapter.idl:
    7.11      Oicf, W1, Zp8, env=Win32 (32b run), target_arch=X86 8.00.0603 
    7.12 @@ -787,13 +787,13 @@
    7.13              /* [in] */ BSTR fpr) = 0;
    7.14          
    7.15          virtual HRESULT STDMETHODCALLTYPE encrypt_message( 
    7.16 -            /* [in] */ ITextMessage *src,
    7.17 -            /* [out] */ ITextMessage **dst,
    7.18 +            /* [ref][in] */ ITextMessage *src,
    7.19 +            /* [ref][in] */ ITextMessage *dst,
    7.20              /* [in] */ SAFEARRAY * extra) = 0;
    7.21          
    7.22          virtual HRESULT STDMETHODCALLTYPE decrypt_message( 
    7.23 -            /* [in] */ ITextMessage *src,
    7.24 -            /* [out] */ ITextMessage **dst,
    7.25 +            /* [ref][in] */ ITextMessage *src,
    7.26 +            /* [ref][in] */ ITextMessage *dst,
    7.27              /* [out] */ SAFEARRAY * *keylist,
    7.28              /* [retval][out] */ pEp_color *rating) = 0;
    7.29          
    7.30 @@ -951,14 +951,14 @@
    7.31          
    7.32          HRESULT ( STDMETHODCALLTYPE *encrypt_message )( 
    7.33              IpEpEngine * This,
    7.34 -            /* [in] */ ITextMessage *src,
    7.35 -            /* [out] */ ITextMessage **dst,
    7.36 +            /* [ref][in] */ ITextMessage *src,
    7.37 +            /* [ref][in] */ ITextMessage *dst,
    7.38              /* [in] */ SAFEARRAY * extra);
    7.39          
    7.40          HRESULT ( STDMETHODCALLTYPE *decrypt_message )( 
    7.41              IpEpEngine * This,
    7.42 -            /* [in] */ ITextMessage *src,
    7.43 -            /* [out] */ ITextMessage **dst,
    7.44 +            /* [ref][in] */ ITextMessage *src,
    7.45 +            /* [ref][in] */ ITextMessage *dst,
    7.46              /* [out] */ SAFEARRAY * *keylist,
    7.47              /* [retval][out] */ pEp_color *rating);
    7.48