structs instead of TextMessage objects
authorVolker Birk <vb@pep-project.org>
Sun, 31 May 2015 13:25:37 +0200
changeset 3339c7fbbbe028
parent 32 b9e23540d7fd
child 34 2ee6d426c3a9
structs instead of TextMessage objects
CpEpEngine.cpp
CpEpEngine.h
TextMessage.cpp
pEpCOMServerAdapter.idl
pEpCOMServerAdapter.rc
pEpCOMServerAdapter.vcxproj
pEpCOMServerAdapter.vcxproj.filters
pEpCOMServerAdapter_i.c
pEpCOMServerAdapter_i.h
pEp_identity_helper.cpp
pEp_identity_helper.h
pEp_utility.h
pEp_utitlity.cpp
utf8_helper.h
     1.1 --- a/CpEpEngine.cpp	Sat May 30 19:36:36 2015 +0200
     1.2 +++ b/CpEpEngine.cpp	Sun May 31 13:25:37 2015 +0200
     1.3 @@ -2,7 +2,6 @@
     1.4  
     1.5  #include "stdafx.h"
     1.6  #include "CpEpEngine.h"
     1.7 -#include "TextMessage.h"
     1.8  
     1.9  using namespace std;
    1.10  using namespace pEp::utility;
    1.11 @@ -866,88 +865,53 @@
    1.12      return E_FAIL;
    1.13  }
    1.14  
    1.15 -STDMETHODIMP CpEpEngine::encrypt_message(ITextMessage * src, ITextMessage * dst, SAFEARRAY * extra)
    1.16 +STDMETHODIMP CpEpEngine::encrypt_message(text_message * src, text_message ** dst, SAFEARRAY * extra)
    1.17  {
    1.18      assert(src);
    1.19      assert(dst);
    1.20  
    1.21 -    CTextMessage *_src = dynamic_cast<CTextMessage *>(src);
    1.22 -    assert(_src);
    1.23 -    CTextMessage *_dst = dynamic_cast<CTextMessage *>(dst);
    1.24 -    assert(_dst);
    1.25 +    ::message *_src = text_message_to_C(src);
    1.26 +    ::message *msg_dst;
    1.27 +    ::stringlist_t *_extra = new_stringlist(extra);
    1.28  
    1.29 -    if (_src->msg()->enc_format != PEP_enc_none)
    1.30 -        return E_INVALIDARG;
    1.31 -
    1.32 -    ::stringlist_t * _extra = NULL;
    1.33 -    if (extra) {
    1.34 -        try {
    1.35 -            _extra = new_stringlist(extra);
    1.36 -        }
    1.37 -        catch (bad_alloc&) {
    1.38 -            return E_OUTOFMEMORY;
    1.39 -        }
    1.40 -        catch (exception&) {
    1.41 -            return E_FAIL;
    1.42 -        }
    1.43 -    }
    1.44 -
    1.45 -    ::message *msg_dst;
    1.46 -    PEP_STATUS status = ::encrypt_message(get_session(), _src->msg(), _extra, &msg_dst, PEP_enc_pieces);
    1.47 +    PEP_STATUS status = ::encrypt_message(get_session(), _src, _extra, &msg_dst, PEP_enc_pieces);
    1.48 +    free_message(_src);
    1.49 +    free_stringlist(_extra);
    1.50      if (status != PEP_STATUS_OK)
    1.51          FAIL(L"cannot encrypt message");
    1.52  
    1.53 -    ::free_stringlist(_extra);
    1.54 -
    1.55      if (msg_dst) {
    1.56 -        _dst->msg(msg_dst);
    1.57 +        *dst = text_message_from_C(msg_dst);
    1.58 +        free_message(msg_dst);
    1.59      }
    1.60  
    1.61      return S_OK;
    1.62  }
    1.63  
    1.64 -STDMETHODIMP CpEpEngine::decrypt_message(ITextMessage * src, ITextMessage * dst, SAFEARRAY ** keylist, pEp_color *rating)
    1.65 +STDMETHODIMP CpEpEngine::decrypt_message(text_message * src, text_message ** dst, SAFEARRAY ** keylist, pEp_color *rating)
    1.66  {
    1.67      assert(src);
    1.68      assert(dst);
    1.69      assert(keylist);
    1.70      assert(rating);
    1.71  
    1.72 -    CTextMessage *_src = dynamic_cast<CTextMessage *>(src);
    1.73 -    assert(_src);
    1.74 -    CTextMessage *_dst = dynamic_cast<CTextMessage *>(dst);
    1.75 -    assert(_dst);
    1.76 -
    1.77 -    if (_src->msg()->enc_format != PEP_enc_none)
    1.78 -        return E_INVALIDARG;
    1.79 -
    1.80 +    ::message *_src = text_message_to_C(src);
    1.81      ::message *msg_dst;
    1.82      ::stringlist_t *_keylist;
    1.83      ::PEP_color _rating;
    1.84  
    1.85 -    PEP_STATUS status = ::decrypt_message(get_session(), _src->msg(), &msg_dst, &_keylist, &_rating);
    1.86 +    PEP_STATUS status = ::decrypt_message(get_session(), _src, &msg_dst, &_keylist, &_rating);
    1.87 +    free_message(_src);
    1.88      if (status != PEP_STATUS_OK)
    1.89          return FAIL(L"decrypt message failed");
    1.90  
    1.91      if (msg_dst) {
    1.92 -        _dst->msg(msg_dst);
    1.93 +        *dst = text_message_from_C(msg_dst);
    1.94      }
    1.95  
    1.96      if (_keylist) {
    1.97 -        ULONG len = ::stringlist_length(_keylist);
    1.98 -        CComSafeArray<BSTR> sa;
    1.99 -        sa.Create(len);
   1.100 -
   1.101 -        ::stringlist_t *_kl;
   1.102 -        ULONG i;
   1.103 -        for (_kl = _keylist, i = 0; _kl && _kl->value; _kl = _kl->next, i++)
   1.104 -            sa.SetAt(i, utf16_bstr(_kl->value).Detach(), false);
   1.105 -        ::free_stringlist(_keylist);
   1.106 -
   1.107 -        *keylist = sa.Detach();
   1.108 -    }
   1.109 -    else {
   1.110 -        *keylist = NULL;
   1.111 +        *keylist = string_array(_keylist).Detach();
   1.112 +        free_stringlist(_keylist);
   1.113      }
   1.114  
   1.115      *rating = (pEp_color) _rating;
   1.116 @@ -955,19 +919,15 @@
   1.117      return S_OK;
   1.118  }
   1.119  
   1.120 -STDMETHODIMP CpEpEngine::outgoing_message_color(ITextMessage *msg, pEp_color * pVal)
   1.121 +STDMETHODIMP CpEpEngine::outgoing_message_color(text_message *msg, pEp_color * pVal)
   1.122  {
   1.123      assert(msg);
   1.124      assert(pVal);
   1.125  
   1.126 -    CTextMessage *_msg = dynamic_cast<CTextMessage *>(msg);
   1.127 -    assert(_msg);
   1.128 -
   1.129 -    if (_msg->msg()->dir != PEP_dir_outgoing)
   1.130 -        return E_INVALIDARG;
   1.131 +    ::message *_msg = text_message_to_C(msg);
   1.132  
   1.133      PEP_color _color;
   1.134 -    PEP_STATUS status = ::outgoing_message_color(get_session(), _msg->msg(), &_color);
   1.135 +    PEP_STATUS status = ::outgoing_message_color(get_session(), _msg, &_color);
   1.136      if (status != PEP_STATUS_OK)
   1.137          return FAIL(L"cannot get message color");
   1.138  
     2.1 --- a/CpEpEngine.h	Sat May 30 19:36:36 2015 +0200
     2.2 +++ b/CpEpEngine.h	Sun May 31 13:25:37 2015 +0200
     2.3 @@ -7,7 +7,7 @@
     2.4  #include "_IpEpEngineEvents_CP.h"
     2.5  #include "locked_queue.hh"
     2.6  #include "utf8_helper.h"
     2.7 -#include "pEp_identity_helper.h"
     2.8 +#include "pEp_utility.h"
     2.9  
    2.10  
    2.11  #if defined(_WIN32_WCE) && !defined(_CE_DCOM) && !defined(_CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA)
    2.12 @@ -147,9 +147,9 @@
    2.13      
    2.14      // Message API
    2.15  
    2.16 -    STDMETHOD(encrypt_message)(ITextMessage * src, ITextMessage * dst, SAFEARRAY * extra);
    2.17 -    STDMETHOD(decrypt_message)(ITextMessage * src, ITextMessage * dst, SAFEARRAY ** keylist, pEp_color *rating);
    2.18 -    STDMETHOD(outgoing_message_color)(ITextMessage *msg, pEp_color * pVal);
    2.19 +    STDMETHOD(encrypt_message)(text_message * src, text_message ** dst, SAFEARRAY * extra);
    2.20 +    STDMETHOD(decrypt_message)(text_message * src, text_message ** dst, SAFEARRAY ** keylist, pEp_color *rating);
    2.21 +    STDMETHOD(outgoing_message_color)(text_message *msg, pEp_color * pVal);
    2.22      STDMETHOD(identity_color)(pEp_identity_s * ident, pEp_color * pVal);
    2.23  
    2.24  };
     3.1 --- a/TextMessage.cpp	Sat May 30 19:36:36 2015 +0200
     3.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.3 @@ -1,882 +0,0 @@
     3.4 -// TextMessage.cpp : Implementation of CTextMessage
     3.5 -
     3.6 -#include "stdafx.h"
     3.7 -#include "TextMessage.h"
     3.8 -
     3.9 -using namespace pEp::utility;
    3.10 -
    3.11 -// CTextMessage
    3.12 -
    3.13 -STDMETHODIMP CTextMessage::InterfaceSupportsErrorInfo(REFIID riid)
    3.14 -{
    3.15 -	static const IID* const arr[] = 
    3.16 -	{
    3.17 -		&IID_ITextMessage
    3.18 -	};
    3.19 -
    3.20 -	for (int i=0; i < sizeof(arr) / sizeof(arr[0]); i++)
    3.21 -	{
    3.22 -		if (InlineIsEqualGUID(*arr[i],riid))
    3.23 -			return S_OK;
    3.24 -	}
    3.25 -	return S_FALSE;
    3.26 -}
    3.27 -
    3.28 -
    3.29 -STDMETHODIMP CTextMessage::get_from(pEp_identity_s* pVal)
    3.30 -{
    3.31 -    assert(pVal);
    3.32 -
    3.33 -    try {
    3.34 -        copy_identity(pVal, msg()->from);
    3.35 -    }
    3.36 -    catch (bad_alloc&) {
    3.37 -        return E_OUTOFMEMORY;
    3.38 -    }
    3.39 -    catch (exception&) {
    3.40 -        return E_FAIL;
    3.41 -    }
    3.42 -
    3.43 -    return S_OK;
    3.44 -}
    3.45 -
    3.46 -
    3.47 -STDMETHODIMP CTextMessage::put_from(pEp_identity_s* newVal)
    3.48 -{
    3.49 -    assert(newVal);
    3.50 -
    3.51 -    ::pEp_identity *_from;
    3.52 -    
    3.53 -    try {
    3.54 -        _from = new_identity(newVal);
    3.55 -    }
    3.56 -    catch (bad_alloc&) {
    3.57 -        return E_OUTOFMEMORY;
    3.58 -    }
    3.59 -    catch (exception&)
    3.60 -    {
    3.61 -        return E_FAIL;
    3.62 -    }
    3.63 -
    3.64 -    ::free_identity(msg()->from);
    3.65 -    msg()->from = _from;
    3.66 -    return S_OK;
    3.67 -}
    3.68 -
    3.69 -static HRESULT il_get(const identity_list *il, LPSAFEARRAY * sa)
    3.70 -{
    3.71 -    assert(sa);
    3.72 -    int len = identity_list_length(il);
    3.73 -
    3.74 -    LPSAFEARRAY _sa = newSafeArray<pEp_identity_s>(len);
    3.75 -    if (_sa == NULL)
    3.76 -        return E_OUTOFMEMORY;
    3.77 -
    3.78 -    const identity_list *_il;
    3.79 -    LONG i;
    3.80 -    for (i = 0, _il = il; _il && _il->ident; _il = _il->next, i++) {
    3.81 -        pEp_identity_s cs;
    3.82 -        
    3.83 -        try {
    3.84 -            copy_identity(&cs, _il->ident);
    3.85 -
    3.86 -            ::SafeArrayPutElement(_sa, &i, &cs);
    3.87 -
    3.88 -            IRecordInfo *ir = getRecordInfo<pEp_identity_s>();
    3.89 -            ir->RecordClear(&cs);
    3.90 -        }
    3.91 -        catch (bad_alloc&) {
    3.92 -            IRecordInfo *ir = getRecordInfo<pEp_identity_s>();
    3.93 -            ir->RecordClear(&cs);
    3.94 -            SafeArrayDestroy(_sa);
    3.95 -            return E_OUTOFMEMORY;
    3.96 -        }
    3.97 -        catch (exception&) {
    3.98 -            IRecordInfo *ir = getRecordInfo<pEp_identity_s>();
    3.99 -            ir->RecordClear(&cs);
   3.100 -            SafeArrayDestroy(_sa);
   3.101 -            return E_FAIL;
   3.102 -        }
   3.103 -    }
   3.104 -
   3.105 -    *sa = _sa;
   3.106 -    return S_OK;
   3.107 -}
   3.108 -
   3.109 -static HRESULT il_put(identity_list **target, SAFEARRAY * newVal)
   3.110 -{
   3.111 -    assert(newVal);
   3.112 -    if (newVal == NULL)
   3.113 -        return E_INVALIDARG;
   3.114 -
   3.115 -    identity_list *il = new_identity_list(NULL);
   3.116 -    if (il == NULL)
   3.117 -        return E_OUTOFMEMORY;
   3.118 -
   3.119 -    identity_list *_il;
   3.120 -    LONG lbound, ubound;
   3.121 -    LONG i;
   3.122 -    SafeArrayGetLBound(newVal, 1, &lbound);
   3.123 -    SafeArrayGetUBound(newVal, 1, &ubound);
   3.124 -
   3.125 -    for (i = lbound, _il = il; i <= ubound; i++) {
   3.126 -        pEp_identity * ident;
   3.127 -        pEp_identity_s cs;
   3.128 -        memset(&cs, 0, sizeof(pEp_identity_s));
   3.129 -
   3.130 -        try {
   3.131 -            HRESULT hr = ::SafeArrayGetElement(newVal, &i, &cs);
   3.132 -            if (hr != S_OK) {
   3.133 -                IRecordInfo *ri = getRecordInfo<pEp_identity_s>();
   3.134 -                ri->RecordClear(&cs);
   3.135 -                free_identity_list(il);
   3.136 -                return hr;
   3.137 -            }
   3.138 -            ident = new_identity(&cs);
   3.139 -
   3.140 -            IRecordInfo *ri = getRecordInfo<pEp_identity_s>();
   3.141 -            ri->RecordClear(&cs);
   3.142 -        }
   3.143 -        catch (bad_alloc&) {
   3.144 -            IRecordInfo *ri = getRecordInfo<pEp_identity_s>();
   3.145 -            ri->RecordClear(&cs);
   3.146 -            free_identity_list(il);
   3.147 -            return E_OUTOFMEMORY;
   3.148 -        }
   3.149 -        catch (exception&) {
   3.150 -            IRecordInfo *ri = getRecordInfo<pEp_identity_s>();
   3.151 -            ri->RecordClear(&cs);
   3.152 -            free_identity_list(il);
   3.153 -            return E_FAIL;
   3.154 -        }
   3.155 -        _il = identity_list_add(_il, ident);
   3.156 -        if (_il == NULL) {
   3.157 -            free_identity_list(il);
   3.158 -            return E_OUTOFMEMORY;
   3.159 -        }
   3.160 -    }
   3.161 -
   3.162 -    free_identity_list(*target);
   3.163 -    *target = il;
   3.164 -
   3.165 -    return S_OK;
   3.166 -}
   3.167 -
   3.168 -STDMETHODIMP CTextMessage::get_to(LPSAFEARRAY * pVal)
   3.169 -{
   3.170 -    return il_get(msg()->to, pVal);
   3.171 -}
   3.172 -
   3.173 -STDMETHODIMP CTextMessage::put_to(SAFEARRAY * newVal)
   3.174 -{
   3.175 -    return il_put(&msg()->to, newVal);
   3.176 -}
   3.177 -
   3.178 -STDMETHODIMP CTextMessage::get_recv_by(pEp_identity_s* pVal)
   3.179 -{
   3.180 -    assert(pVal);
   3.181 -
   3.182 -    try {
   3.183 -        copy_identity(pVal, msg()->recv_by);
   3.184 -    }
   3.185 -    catch (bad_alloc&) {
   3.186 -        return E_OUTOFMEMORY;
   3.187 -    }
   3.188 -    catch (exception&) {
   3.189 -        return E_FAIL;
   3.190 -    }
   3.191 -
   3.192 -    return S_OK;
   3.193 -}
   3.194 -
   3.195 -
   3.196 -STDMETHODIMP CTextMessage::put_recv_by(pEp_identity_s* newVal)
   3.197 -{
   3.198 -    assert(newVal);
   3.199 -
   3.200 -    ::pEp_identity *_recv_by;
   3.201 -
   3.202 -    try {
   3.203 -        _recv_by = new_identity(newVal);
   3.204 -    }
   3.205 -    catch (bad_alloc&) {
   3.206 -        return E_OUTOFMEMORY;
   3.207 -    }
   3.208 -    catch (exception&) {
   3.209 -        return E_FAIL;
   3.210 -    }
   3.211 -
   3.212 -    ::free_identity(msg()->recv_by);
   3.213 -    msg()->recv_by = _recv_by;
   3.214 -    return S_OK;
   3.215 -}
   3.216 -
   3.217 -STDMETHODIMP CTextMessage::get_cc(LPSAFEARRAY * pVal)
   3.218 -{
   3.219 -    return il_get(msg()->cc, pVal);
   3.220 -}
   3.221 -
   3.222 -STDMETHODIMP CTextMessage::put_cc(SAFEARRAY * newVal)
   3.223 -{
   3.224 -    return il_put(&msg()->cc, newVal);
   3.225 -}
   3.226 -
   3.227 -STDMETHODIMP CTextMessage::get_bcc(LPSAFEARRAY * pVal)
   3.228 -{
   3.229 -    return il_get(msg()->bcc, pVal);
   3.230 -}
   3.231 -
   3.232 -STDMETHODIMP CTextMessage::put_bcc(SAFEARRAY * newVal)
   3.233 -{
   3.234 -    return il_put(&msg()->bcc, newVal);
   3.235 -}
   3.236 -
   3.237 -STDMETHODIMP CTextMessage::get_reply_to(LPSAFEARRAY * pVal)
   3.238 -{
   3.239 -    return il_get(msg()->reply_to, pVal);
   3.240 -}
   3.241 -
   3.242 -STDMETHODIMP CTextMessage::put_reply_to(SAFEARRAY * newVal)
   3.243 -{
   3.244 -    return il_put(&msg()->reply_to, newVal);
   3.245 -}
   3.246 -
   3.247 -STDMETHODIMP CTextMessage::get_dir(pEp_msg_direction *pVal)
   3.248 -{
   3.249 -    assert(pVal);
   3.250 -
   3.251 -    *pVal = (pEp_msg_direction) msg()->dir;
   3.252 -
   3.253 -    return S_OK;
   3.254 -}
   3.255 -
   3.256 -STDMETHODIMP CTextMessage::put_dir(pEp_msg_direction newVal)
   3.257 -{
   3.258 -    msg()->dir = (PEP_msg_direction) newVal;
   3.259 -
   3.260 -    return S_OK;
   3.261 -}
   3.262 -
   3.263 -STDMETHODIMP CTextMessage::get_id(BSTR * pVal)
   3.264 -{
   3.265 -    assert(pVal);
   3.266 -
   3.267 -    _bstr_t val;
   3.268 -
   3.269 -    if (msg()->id) {
   3.270 -        try {
   3.271 -            val = utf16_bstr(msg()->id);
   3.272 -        }
   3.273 -        catch (bad_alloc&) {
   3.274 -            return E_OUTOFMEMORY;
   3.275 -        }
   3.276 -        catch (exception&) {
   3.277 -            return E_FAIL;
   3.278 -        }
   3.279 -        *pVal = val.Detach();
   3.280 -    }
   3.281 -
   3.282 -    return S_OK;
   3.283 -}
   3.284 -
   3.285 -STDMETHODIMP CTextMessage::put_id(BSTR newVal)
   3.286 -{
   3.287 -    char *_val = NULL;
   3.288 -    string val;
   3.289 -
   3.290 -    if (newVal) {
   3.291 -        try {
   3.292 -            val = utf8_string(newVal);
   3.293 -        }
   3.294 -        catch (bad_alloc&) {
   3.295 -            return E_OUTOFMEMORY;
   3.296 -        }
   3.297 -        catch (exception&) {
   3.298 -            return E_FAIL;
   3.299 -        }
   3.300 -
   3.301 -        _val = _strdup(val.c_str());
   3.302 -        if (_val == NULL)
   3.303 -            return E_OUTOFMEMORY;
   3.304 -    }
   3.305 -
   3.306 -    if (msg()->id)
   3.307 -        free(msg()->id);
   3.308 -
   3.309 -    msg()->id = _val;
   3.310 -    return S_OK;
   3.311 -}
   3.312 -
   3.313 -STDMETHODIMP CTextMessage::get_shortmsg(BSTR * pVal)
   3.314 -{
   3.315 -    assert(pVal);
   3.316 -
   3.317 -    _bstr_t val;
   3.318 -
   3.319 -    if (msg()->shortmsg) {
   3.320 -        try {
   3.321 -            val = utf16_bstr(msg()->shortmsg);
   3.322 -        }
   3.323 -        catch (bad_alloc&) {
   3.324 -            return E_OUTOFMEMORY;
   3.325 -        }
   3.326 -        catch (exception&) {
   3.327 -            return E_FAIL;
   3.328 -        }
   3.329 -        *pVal = val.Detach();
   3.330 -    }
   3.331 -
   3.332 -    return S_OK;
   3.333 -}
   3.334 -
   3.335 -STDMETHODIMP CTextMessage::put_shortmsg(BSTR newVal)
   3.336 -{
   3.337 -    char *_val = NULL;
   3.338 -
   3.339 -    if (newVal) {
   3.340 -        string val;
   3.341 -
   3.342 -        try {
   3.343 -            val = utf8_string(newVal);
   3.344 -        }
   3.345 -        catch (bad_alloc&) {
   3.346 -            return E_OUTOFMEMORY;
   3.347 -        }
   3.348 -        catch (exception&) {
   3.349 -            return E_FAIL;
   3.350 -        }
   3.351 -
   3.352 -        _val = _strdup(val.c_str());
   3.353 -        if (_val == NULL)
   3.354 -            return E_OUTOFMEMORY;
   3.355 -    }
   3.356 -
   3.357 -    if (msg()->shortmsg)
   3.358 -        free(msg()->shortmsg);
   3.359 -
   3.360 -    msg()->shortmsg = _val;
   3.361 -    return S_OK;
   3.362 -}
   3.363 -
   3.364 -STDMETHODIMP CTextMessage::get_longmsg(BSTR * pVal)
   3.365 -{
   3.366 -    assert(pVal);
   3.367 -
   3.368 -    _bstr_t val;
   3.369 -
   3.370 -    if (msg()->longmsg) {
   3.371 -        try {
   3.372 -            val = utf16_bstr(msg()->longmsg);
   3.373 -        }
   3.374 -        catch (bad_alloc&) {
   3.375 -            return E_OUTOFMEMORY;
   3.376 -        }
   3.377 -        catch (exception&) {
   3.378 -            return E_FAIL;
   3.379 -        }
   3.380 -        *pVal = val.Detach();
   3.381 -    }
   3.382 -
   3.383 -    return S_OK;
   3.384 -}
   3.385 -
   3.386 -STDMETHODIMP CTextMessage::put_longmsg(BSTR newVal)
   3.387 -{
   3.388 -    char * _val = NULL;
   3.389 -
   3.390 -    if (newVal) {
   3.391 -        string val;
   3.392 -
   3.393 -        try {
   3.394 -            val = utf8_string(newVal);
   3.395 -        }
   3.396 -        catch (bad_alloc&) {
   3.397 -            return E_OUTOFMEMORY;
   3.398 -        }
   3.399 -        catch (exception&) {
   3.400 -            return E_FAIL;
   3.401 -        }
   3.402 -
   3.403 -        _val = _strdup(val.c_str());
   3.404 -        if (_val == NULL)
   3.405 -            return E_OUTOFMEMORY;
   3.406 -    }
   3.407 -
   3.408 -    if (msg()->longmsg)
   3.409 -        free(msg()->longmsg);
   3.410 -
   3.411 -    msg()->longmsg = _val;
   3.412 -    return S_OK;
   3.413 -}
   3.414 -
   3.415 -STDMETHODIMP CTextMessage::get_longmsg_formatted(BSTR * pVal)
   3.416 -{
   3.417 -    assert(pVal);
   3.418 -
   3.419 -    _bstr_t val;
   3.420 -
   3.421 -    if (msg()->longmsg_formatted) {
   3.422 -        try {
   3.423 -            val = utf16_bstr(msg()->longmsg_formatted);
   3.424 -        }
   3.425 -        catch (bad_alloc&) {
   3.426 -            return E_OUTOFMEMORY;
   3.427 -        }
   3.428 -        catch (exception&) {
   3.429 -            return E_FAIL;
   3.430 -        }
   3.431 -        *pVal = val.Detach();
   3.432 -    }
   3.433 -
   3.434 -    return S_OK;
   3.435 -}
   3.436 -
   3.437 -STDMETHODIMP CTextMessage::put_longmsg_formatted(BSTR newVal)
   3.438 -{
   3.439 -    char *_val = NULL;
   3.440 -
   3.441 -    if (newVal) {
   3.442 -        string val;
   3.443 -
   3.444 -        try {
   3.445 -            val = utf8_string(newVal);
   3.446 -        }
   3.447 -        catch (bad_alloc&) {
   3.448 -            return E_OUTOFMEMORY;
   3.449 -        }
   3.450 -        catch (exception&) {
   3.451 -            return E_FAIL;
   3.452 -        }
   3.453 -
   3.454 -        _val = _strdup(val.c_str());
   3.455 -        if (_val == NULL)
   3.456 -            return E_OUTOFMEMORY;
   3.457 -    }
   3.458 -
   3.459 -    if (msg()->longmsg_formatted)
   3.460 -        free(msg()->longmsg_formatted);
   3.461 -
   3.462 -    msg()->longmsg_formatted = _val;
   3.463 -    return S_OK;
   3.464 -}
   3.465 -
   3.466 -STDMETHODIMP CTextMessage::add_attachment(SAFEARRAY * data, BSTR mime_type, BSTR filename)
   3.467 -{
   3.468 -    assert(data);
   3.469 -    if (data == NULL)
   3.470 -        return E_INVALIDARG;
   3.471 -
   3.472 -    CComSafeArray<BYTE> sa_data(data);
   3.473 -    size_t len = sa_data.GetCount();
   3.474 -
   3.475 -    char *_data = (char *) malloc(sa_data.GetCount() + 1);
   3.476 -    assert(_data);
   3.477 -    if (_data == NULL)
   3.478 -        return E_OUTOFMEMORY;
   3.479 -
   3.480 -    memcpy(_data, sa_data.m_psa->pvData, len);
   3.481 -    _data[len] = 0;
   3.482 -    sa_data.Detach();
   3.483 -
   3.484 -    string _mime_type;
   3.485 -    if (mime_type) {
   3.486 -        try {
   3.487 -            _mime_type = utf8_string(mime_type);
   3.488 -        }
   3.489 -        catch (bad_alloc&) {
   3.490 -            free(_data);
   3.491 -            return E_OUTOFMEMORY;
   3.492 -        }
   3.493 -        catch (exception&) {
   3.494 -            free(_data);
   3.495 -            return E_FAIL;
   3.496 -        }
   3.497 -    }
   3.498 -
   3.499 -    string _filename;
   3.500 -    if (filename) {
   3.501 -        try {
   3.502 -            _filename = utf8_string(filename);
   3.503 -        }
   3.504 -        catch (bad_alloc&) {
   3.505 -            free(_data);
   3.506 -            return E_OUTOFMEMORY;
   3.507 -        }
   3.508 -        catch (exception&) {
   3.509 -            free(_data);
   3.510 -            return E_FAIL;
   3.511 -        }
   3.512 -    }
   3.513 -
   3.514 -    bloblist_t *blob = bloblist_add(msg()->attachments, _data, len, _mime_type.c_str(), _filename.c_str());
   3.515 -    if (blob == NULL) {
   3.516 -        free(_data);
   3.517 -        return E_OUTOFMEMORY;
   3.518 -    }
   3.519 -
   3.520 -    if (msg()->attachments == NULL)
   3.521 -        msg()->attachments = blob;
   3.522 -
   3.523 -    return S_OK;
   3.524 -}
   3.525 -
   3.526 -STDMETHODIMP CTextMessage::has_attachments(boolean *result)
   3.527 -{
   3.528 -    assert(result);
   3.529 -
   3.530 -    if (msg()->attachments == NULL || msg()->attachments->data == NULL) {
   3.531 -        m_next_attachment = NULL;
   3.532 -        *result = false;
   3.533 -        return S_OK;
   3.534 -    }
   3.535 -
   3.536 -    m_next_attachment = msg()->attachments;
   3.537 -    *result = true;
   3.538 -
   3.539 -    return S_OK;
   3.540 -}
   3.541 -
   3.542 -STDMETHODIMP CTextMessage::next_attachment(SAFEARRAY ** data, BSTR * mime_type, BSTR * filename, boolean *result)
   3.543 -{
   3.544 -    assert(data);
   3.545 -    assert(mime_type);
   3.546 -    assert(filename);
   3.547 -    assert(result);
   3.548 -
   3.549 -    if (m_next_attachment == NULL)
   3.550 -        return E_ILLEGAL_METHOD_CALL;
   3.551 -
   3.552 -    CComSafeArray<BYTE> sa;
   3.553 -    try {
   3.554 -        sa.Create(m_next_attachment->size);
   3.555 -    }
   3.556 -    catch (bad_alloc&) {
   3.557 -        return E_OUTOFMEMORY;
   3.558 -    }
   3.559 -
   3.560 -    memcpy(sa.m_psa->pvData, m_next_attachment->data, m_next_attachment->size);
   3.561 -
   3.562 -    _bstr_t _mime_type;
   3.563 -    if (m_next_attachment->mime_type) {
   3.564 -        try {
   3.565 -            _mime_type = utf16_bstr(m_next_attachment->mime_type);
   3.566 -        }
   3.567 -        catch (bad_alloc&) {
   3.568 -            return E_OUTOFMEMORY;
   3.569 -        }
   3.570 -        catch (exception&) {
   3.571 -            return E_FAIL;
   3.572 -        }
   3.573 -    }
   3.574 -
   3.575 -    _bstr_t _filename;
   3.576 -    if (m_next_attachment->filename) {
   3.577 -        try {
   3.578 -            _filename = utf16_bstr(m_next_attachment->filename);
   3.579 -        }
   3.580 -        catch (bad_alloc&) {
   3.581 -            return E_OUTOFMEMORY;
   3.582 -        }
   3.583 -        catch (exception&) {
   3.584 -            return E_FAIL;
   3.585 -        }
   3.586 -    }
   3.587 -
   3.588 -    *data = sa.Detach();
   3.589 -    *mime_type = _mime_type.Detach();
   3.590 -    *filename = _filename.Detach();
   3.591 -
   3.592 -    m_next_attachment = m_next_attachment->next;
   3.593 -    *result = m_next_attachment != NULL;
   3.594 -
   3.595 -    return S_OK;
   3.596 -}
   3.597 -
   3.598 -STDMETHODIMP CTextMessage::get_sent(hyper * result)
   3.599 -{
   3.600 -    assert(result);
   3.601 -
   3.602 -    if (msg()->sent == NULL)
   3.603 -        return E_NOT_SET;
   3.604 -
   3.605 -    *result = mktime(msg()->sent);
   3.606 -    return S_OK;
   3.607 -}
   3.608 -
   3.609 -STDMETHODIMP CTextMessage::put_sent(hyper val)
   3.610 -{
   3.611 -    ::timestamp * ts = new_timestamp(val);
   3.612 -    if (ts == NULL)
   3.613 -        return E_OUTOFMEMORY;
   3.614 -
   3.615 -    if (msg()->sent)
   3.616 -        free_timestamp(msg()->sent);
   3.617 -    msg()->sent = ts;
   3.618 -
   3.619 -    return S_OK;
   3.620 -}
   3.621 -
   3.622 -STDMETHODIMP CTextMessage::get_recv(hyper * result)
   3.623 -{
   3.624 -    assert(result);
   3.625 -
   3.626 -    if (msg()->recv == NULL)
   3.627 -        return E_NOT_SET;
   3.628 -
   3.629 -    *result = mktime(msg()->recv);
   3.630 -    return S_OK;
   3.631 -}
   3.632 -
   3.633 -STDMETHODIMP CTextMessage::put_recv(hyper val)
   3.634 -{
   3.635 -    ::timestamp * ts = new_timestamp(val);
   3.636 -    if (ts == NULL)
   3.637 -        return E_OUTOFMEMORY;
   3.638 -
   3.639 -    if (msg()->recv)
   3.640 -        free_timestamp(msg()->recv);
   3.641 -    msg()->recv = ts;
   3.642 -
   3.643 -    return S_OK;
   3.644 -}
   3.645 -
   3.646 -STDMETHODIMP CTextMessage::get_references(SAFEARRAY ** pVal)
   3.647 -{
   3.648 -    assert(pVal);
   3.649 -
   3.650 -    CComSafeArray<BSTR> sa;
   3.651 -    try {
   3.652 -        if (msg()->references) {
   3.653 -            sa = string_array(msg()->references);
   3.654 -        }
   3.655 -        else {
   3.656 -            sa.Create(0UL);
   3.657 -        }
   3.658 -    }
   3.659 -    catch (bad_alloc&) {
   3.660 -        return E_OUTOFMEMORY;
   3.661 -    }
   3.662 -    catch (exception&) {
   3.663 -        return E_FAIL;
   3.664 -    }
   3.665 -    
   3.666 -    *pVal = sa.Detach();
   3.667 -    return S_OK;
   3.668 -}
   3.669 -
   3.670 -STDMETHODIMP CTextMessage::put_references(SAFEARRAY * newVal)
   3.671 -{
   3.672 -    assert(newVal);
   3.673 -
   3.674 -    stringlist_t *sl;
   3.675 -    
   3.676 -    try {
   3.677 -        sl = new_stringlist(newVal);
   3.678 -    }
   3.679 -    catch (bad_alloc&) {
   3.680 -        return E_OUTOFMEMORY;
   3.681 -    }
   3.682 -    catch (exception&) {
   3.683 -        return E_FAIL;
   3.684 -    }
   3.685 -
   3.686 -    if (msg()->references)
   3.687 -        free_stringlist(msg()->references);
   3.688 -
   3.689 -    msg()->references = sl;
   3.690 -
   3.691 -    return S_OK;
   3.692 -}
   3.693 -
   3.694 -STDMETHODIMP CTextMessage::get_keywords(SAFEARRAY ** pVal)
   3.695 -{
   3.696 -    assert(pVal);
   3.697 -
   3.698 -    CComSafeArray<BSTR> sa;
   3.699 -    try {
   3.700 -        if (msg()->keywords) {
   3.701 -            sa = string_array(msg()->keywords);
   3.702 -        }
   3.703 -        else {
   3.704 -            sa.Create(0UL);
   3.705 -        }
   3.706 -    }
   3.707 -    catch (bad_alloc&) {
   3.708 -        return E_OUTOFMEMORY;
   3.709 -    }
   3.710 -    catch (exception&) {
   3.711 -        return E_FAIL;
   3.712 -    }
   3.713 -
   3.714 -    *pVal = sa.Detach();
   3.715 -    return S_OK;
   3.716 -}
   3.717 -
   3.718 -STDMETHODIMP CTextMessage::put_keywords(SAFEARRAY * newVal)
   3.719 -{
   3.720 -    assert(newVal);
   3.721 -
   3.722 -    stringlist_t *sl;
   3.723 -
   3.724 -    try {
   3.725 -        sl = new_stringlist(newVal);
   3.726 -    }
   3.727 -    catch (bad_alloc&) {
   3.728 -        return E_OUTOFMEMORY;
   3.729 -    }
   3.730 -    catch (exception&) {
   3.731 -        return E_FAIL;
   3.732 -    }
   3.733 -
   3.734 -    if (msg()->keywords)
   3.735 -        free_stringlist(msg()->keywords);
   3.736 -
   3.737 -    msg()->keywords = sl;
   3.738 -
   3.739 -    return S_OK;
   3.740 -}
   3.741 -
   3.742 -STDMETHODIMP CTextMessage::get_comments(BSTR * pVal)
   3.743 -{
   3.744 -    assert(pVal);
   3.745 -
   3.746 -    _bstr_t val;
   3.747 -
   3.748 -    if (msg()->comments) {
   3.749 -        try {
   3.750 -            val = utf16_bstr(msg()->comments);
   3.751 -        }
   3.752 -        catch (bad_alloc&) {
   3.753 -            return E_OUTOFMEMORY;
   3.754 -        }
   3.755 -        catch (exception&) {
   3.756 -            return E_FAIL;
   3.757 -        }
   3.758 -        *pVal = val.Detach();
   3.759 -    }
   3.760 -
   3.761 -    return S_OK;
   3.762 -}
   3.763 -
   3.764 -STDMETHODIMP CTextMessage::put_comments(BSTR newVal)
   3.765 -{
   3.766 -    char * _val = NULL;
   3.767 -
   3.768 -    if (newVal) {
   3.769 -        string val;
   3.770 -
   3.771 -        try {
   3.772 -            val = utf8_string(newVal);
   3.773 -        }
   3.774 -        catch (bad_alloc&) {
   3.775 -            return E_OUTOFMEMORY;
   3.776 -        }
   3.777 -        catch (exception&) {
   3.778 -            return E_FAIL;
   3.779 -        }
   3.780 -
   3.781 -        _val = _strdup(val.c_str());
   3.782 -        if (_val == NULL)
   3.783 -            return E_OUTOFMEMORY;
   3.784 -    }
   3.785 -
   3.786 -    if (msg()->comments)
   3.787 -        free(msg()->comments);
   3.788 -
   3.789 -    msg()->comments = _val;
   3.790 -    return S_OK;
   3.791 -}
   3.792 -
   3.793 -STDMETHODIMP CTextMessage::get_opt_fields(LPSAFEARRAY * pVal)
   3.794 -{
   3.795 -    assert(pVal);
   3.796 -
   3.797 -    if (msg()->opt_fields == NULL)
   3.798 -        return S_OK;
   3.799 -
   3.800 -    int len = stringpair_list_length(msg()->opt_fields);
   3.801 -
   3.802 -    LPSAFEARRAY sa = newSafeArray<struct opt_field>(len);
   3.803 -    if (sa == NULL)
   3.804 -        return E_OUTOFMEMORY;
   3.805 -
   3.806 -    stringpair_list_t *il;
   3.807 -    LONG i;
   3.808 -    for (i = 0, il = msg()->opt_fields; il && il->value; il = il->next, i++) {
   3.809 -        opt_field fld;
   3.810 -        memset(&fld, 0, sizeof(opt_field));
   3.811 -
   3.812 -        try {
   3.813 -            fld.name = utf16_bstr(il->value->key).Detach();
   3.814 -            fld.value = utf16_bstr(il->value->value).Detach();
   3.815 -
   3.816 -            ::SafeArrayPutElement(sa, &i, &fld);
   3.817 -
   3.818 -            IRecordInfo *ir = getRecordInfo<opt_field>();
   3.819 -            ir->RecordClear(&fld);
   3.820 -        }
   3.821 -        catch (bad_alloc&) {
   3.822 -            IRecordInfo *ir = getRecordInfo<opt_field>();
   3.823 -            ir->RecordClear(&fld);
   3.824 -            SafeArrayDestroy(sa);
   3.825 -            return E_OUTOFMEMORY;
   3.826 -        }
   3.827 -        catch (exception&) {
   3.828 -            IRecordInfo *ir = getRecordInfo<opt_field>();
   3.829 -            ir->RecordClear(&fld);
   3.830 -            SafeArrayDestroy(sa);
   3.831 -            return E_FAIL;
   3.832 -        }
   3.833 -    }
   3.834 -
   3.835 -    *pVal = sa;
   3.836 -    return S_OK;
   3.837 -}
   3.838 -
   3.839 -STDMETHODIMP CTextMessage::put_opt_fields(SAFEARRAY * newVal)
   3.840 -{
   3.841 -    assert(newVal);
   3.842 -
   3.843 -    if (newVal == NULL)
   3.844 -        return E_INVALIDARG;
   3.845 -
   3.846 -    stringpair_list_t *il = new_stringpair_list(NULL);
   3.847 -    if (il == NULL)
   3.848 -        return E_OUTOFMEMORY;
   3.849 -
   3.850 -    stringpair_list_t *_il;
   3.851 -    LONG lbound, ubound;
   3.852 -    LONG i;
   3.853 -    SafeArrayGetLBound(newVal, 1, &lbound);
   3.854 -    SafeArrayGetUBound(newVal, 1, &ubound);
   3.855 -
   3.856 -    for (i = lbound, _il = il; i <= ubound; i++) {
   3.857 -        stringpair_t * pair;
   3.858 -        try {
   3.859 -            struct opt_field cs;
   3.860 -            memset(&cs, 0, sizeof(opt_field));
   3.861 -            HRESULT hr = ::SafeArrayGetElement(newVal, &i, &cs);
   3.862 -            pair = new_stringpair(utf8_string(cs.name).c_str(), utf8_string(cs.value).c_str());
   3.863 -            IRecordInfo *ri = getRecordInfo<opt_field>();
   3.864 -            ri->RecordClear(&cs);
   3.865 -        }
   3.866 -        catch (bad_alloc&) {
   3.867 -            free_stringpair_list(il);
   3.868 -            return E_OUTOFMEMORY;
   3.869 -        }
   3.870 -        catch (exception&) {
   3.871 -            free_stringpair_list(il);
   3.872 -            return E_FAIL;
   3.873 -        }
   3.874 -        _il = stringpair_list_add(_il, pair);
   3.875 -        if (_il == NULL) {
   3.876 -            free_stringpair_list(il);
   3.877 -            return E_OUTOFMEMORY;
   3.878 -        }
   3.879 -    }
   3.880 -
   3.881 -    free_stringpair_list(msg()->opt_fields);
   3.882 -    msg()->opt_fields = il;
   3.883 -
   3.884 -    return S_OK;
   3.885 -}
     4.1 --- a/pEpCOMServerAdapter.idl	Sat May 30 19:36:36 2015 +0200
     4.2 +++ b/pEpCOMServerAdapter.idl	Sun May 31 13:25:37 2015 +0200
     4.3 @@ -7,101 +7,6 @@
     4.4  import "oaidl.idl";
     4.5  import "ocidl.idl";
     4.6  
     4.7 -
     4.8 -[
     4.9 -    object,
    4.10 -    uuid(161538F9-53C8-4D9C-8BA4-0FB43AEC7106),
    4.11 -    oleautomation,
    4.12 -    nonextensible,
    4.13 -    pointer_default(unique)
    4.14 -]
    4.15 -interface ITextMessage : IUnknown {
    4.16 -    typedef enum _pEp_text_format {
    4.17 -        pEp_text_format_plain = 0,
    4.18 -        pEp_text_format_html,
    4.19 -        pEp_text_format_other = 0xff
    4.20 -    } pEp_text_format;
    4.21 -
    4.22 -    typedef enum _pEp_msg_direction {
    4.23 -        pEp_dir_incoming = 0,
    4.24 -        pEp_dir_outgoing
    4.25 -    } pEp_msg_direction;
    4.26 -
    4.27 -    typedef enum _pEp_MIME_format {
    4.28 -        pEp_MIME_none = 0,                      // message is not MIME encoded
    4.29 -        pEp_MIME_fields_omitted,                // message content but no fields
    4.30 -        pEp_MIME                                // message is fully MIME encoded
    4.31 -    } pEp_MIME_format;
    4.32 -
    4.33 -    typedef enum _pEp_enc_format {
    4.34 -        pEp_enc_none = 0,                       // message is not encrypted
    4.35 -        pEp_enc_pieces,                         // inline PGP + PGP extensions
    4.36 -        pEp_enc_S_MIME,                         // RFC5751
    4.37 -        pEp_enc_PGP_MIME,                       // RFC3156
    4.38 -        pEp_enc_pEp                             // pEp encryption format
    4.39 -    } pEp_enc_format;
    4.40 -
    4.41 -    [uuid(1292C31A-6486-427F-B29F-7F03607836DC)] struct opt_field {
    4.42 -        BSTR name;
    4.43 -        BSTR value;
    4.44 -    };
    4.45 -
    4.46 -    [propget] HRESULT dir([out, retval] pEp_msg_direction *pVal);
    4.47 -    [propput] HRESULT dir([in] pEp_msg_direction newVal);
    4.48 -
    4.49 -    [propget] HRESULT id([out, retval] BSTR *pVal);
    4.50 -    [propput] HRESULT id([in] BSTR newVal);
    4.51 -
    4.52 -    [propget] HRESULT shortmsg([out, retval] BSTR *pVal);
    4.53 -    [propput] HRESULT shortmsg([in] BSTR newVal);
    4.54 -
    4.55 -    [propget] HRESULT longmsg([out, retval] BSTR *pVal);
    4.56 -    [propput] HRESULT longmsg([in] BSTR newVal);
    4.57 -
    4.58 -    [propget] HRESULT longmsg_formatted([out, retval] BSTR *pVal);
    4.59 -    [propput] HRESULT longmsg_formatted([in] BSTR newVal);
    4.60 -
    4.61 -    HRESULT add_attachment([in] SAFEARRAY(BYTE) data, [in] BSTR mime_type, [in] BSTR filename);
    4.62 -    HRESULT has_attachments([out, retval] boolean *result);
    4.63 -    HRESULT next_attachment([out] SAFEARRAY(BYTE) * data, [out] BSTR * mime_type, [out] BSTR * filename, [out, retval] boolean *result);
    4.64 -
    4.65 -    [propget] HRESULT sent([out, retval] hyper * result);
    4.66 -    [propput] HRESULT sent([in] hyper val);
    4.67 -
    4.68 -    [propget] HRESULT recv([out, retval] hyper * result);
    4.69 -    [propput] HRESULT recv([in] hyper val);
    4.70 -
    4.71 -    [propget] HRESULT from([out, retval] struct pEp_identity_s *pVal);
    4.72 -    [propput] HRESULT from([in] struct pEp_identity_s *newVal);
    4.73 -
    4.74 -    [propget] HRESULT to([out, retval] SAFEARRAY(struct pEp_identity_s) *pVal);
    4.75 -    [propput] HRESULT to([in] SAFEARRAY(struct pEp_identity_s) newVal);
    4.76 -
    4.77 -    [propget] HRESULT recv_by([out, retval] struct pEp_identity_s *pVal);
    4.78 -    [propput] HRESULT recv_by([in] struct pEp_identity_s *newVal);
    4.79 -
    4.80 -    [propget] HRESULT cc([out, retval] SAFEARRAY(struct pEp_identity_s) *pVal);
    4.81 -    [propput] HRESULT cc([in] SAFEARRAY(struct pEp_identity_s) newVal);
    4.82 -
    4.83 -    [propget] HRESULT bcc([out, retval] SAFEARRAY(struct pEp_identity_s) *pVal);
    4.84 -    [propput] HRESULT bcc([in] SAFEARRAY(struct pEp_identity_s) newVal);
    4.85 -
    4.86 -    [propget] HRESULT reply_to([out, retval] SAFEARRAY(struct pEp_identity_s) *pVal);
    4.87 -    [propput] HRESULT reply_to([in] SAFEARRAY(struct pEp_identity_s) newVal);
    4.88 -
    4.89 -    [propget] HRESULT references([out, retval] SAFEARRAY(BSTR) *pVal);
    4.90 -    [propput] HRESULT references([in] SAFEARRAY(BSTR) newVal);
    4.91 -
    4.92 -    [propget] HRESULT keywords([out, retval] SAFEARRAY(BSTR) *pVal);
    4.93 -    [propput] HRESULT keywords([in] SAFEARRAY(BSTR) newVal);
    4.94 -
    4.95 -    [propget] HRESULT comments([out, retval] BSTR *pVal);
    4.96 -    [propput] HRESULT comments([in] BSTR newVal);
    4.97 -
    4.98 -    [propget] HRESULT opt_fields([out, retval] SAFEARRAY(struct opt_field) *pVal);
    4.99 -    [propput] HRESULT opt_fields([in] SAFEARRAY(struct opt_field) newVal);
   4.100 -};
   4.101 -
   4.102  [
   4.103      object,
   4.104      uuid(9A9F4422-CF0A-45D7-90CD-1D1B7B2A4540),
   4.105 @@ -236,9 +141,66 @@
   4.106          pEp_rating_b0rken = -2
   4.107      } pEp_color;
   4.108  
   4.109 -    HRESULT encrypt_message([in,ref] ITextMessage *src, [in,ref] ITextMessage * dst, [in] SAFEARRAY(BSTR) extra);
   4.110 -    HRESULT decrypt_message([in,ref] ITextMessage *src, [in,ref] ITextMessage * dst, [out] SAFEARRAY(BSTR) *keylist, [out, retval] pEp_color *rating);
   4.111 -    HRESULT outgoing_message_color([in] ITextMessage *msg, [out, retval] pEp_color * pVal);
   4.112 +    typedef enum _pEp_text_format {
   4.113 +        pEp_text_format_plain = 0,
   4.114 +        pEp_text_format_html,
   4.115 +        pEp_text_format_other = 0xff
   4.116 +    } pEp_text_format;
   4.117 +
   4.118 +    typedef enum _pEp_msg_direction {
   4.119 +        pEp_dir_incoming = 0,
   4.120 +        pEp_dir_outgoing
   4.121 +    } pEp_msg_direction;
   4.122 +
   4.123 +    typedef enum _pEp_MIME_format {
   4.124 +        pEp_MIME_none = 0,                      // message is not MIME encoded
   4.125 +        pEp_MIME_fields_omitted,                // message content but no fields
   4.126 +        pEp_MIME                                // message is fully MIME encoded
   4.127 +    } pEp_MIME_format;
   4.128 +
   4.129 +    typedef enum _pEp_enc_format {
   4.130 +        pEp_enc_none = 0,                       // message is not encrypted
   4.131 +        pEp_enc_pieces,                         // inline PGP + PGP extensions
   4.132 +        pEp_enc_S_MIME,                         // RFC5751
   4.133 +        pEp_enc_PGP_MIME,                       // RFC3156
   4.134 +        pEp_enc_pEp                             // pEp encryption format
   4.135 +    } pEp_enc_format;
   4.136 +
   4.137 +    [uuid(3A8A4F13-3402-4C4C-94AB-598D87869380)] struct opt_field {
   4.138 +        BSTR name;
   4.139 +        BSTR value;
   4.140 +    };
   4.141 +
   4.142 +    [uuid(61DA7AD4-192E-4616-8678-B19AEFB45B45)] struct blob {
   4.143 +        SAFEARRAY(BYTE) value;
   4.144 +        BSTR mime_type;
   4.145 +        BSTR filename;
   4.146 +    };
   4.147 +
   4.148 +    [uuid(D763A8F3-BA23-4229-A037-1BB7BDC3E0C8)] struct text_message {
   4.149 +        pEp_msg_direction dir;
   4.150 +        BSTR id;
   4.151 +        BSTR shortmsg;
   4.152 +        BSTR longmsg;
   4.153 +        BSTR longmsg_formatted;
   4.154 +        SAFEARRAY(struct blob) attachments;
   4.155 +        hyper sent;
   4.156 +        hyper recv;
   4.157 +        struct pEp_identity_s from;
   4.158 +        SAFEARRAY(struct pEp_identity_s) to;
   4.159 +        struct pEp_identity_s recv_by;
   4.160 +        SAFEARRAY(struct pEp_identity_s) cc;
   4.161 +        SAFEARRAY(struct pEp_identity_s) bcc;
   4.162 +        SAFEARRAY(struct pEp_identity_s) reply_to;
   4.163 +        SAFEARRAY(BSTR) references;
   4.164 +        SAFEARRAY(BSTR) keywords;
   4.165 +        BSTR comments;
   4.166 +        SAFEARRAY(struct opt_field) opt_fields;
   4.167 +    };
   4.168 +
   4.169 +    HRESULT encrypt_message([in] struct text_message *src, [out] struct text_message ** dst, [in] SAFEARRAY(BSTR) extra);
   4.170 +    HRESULT decrypt_message([in] struct text_message *src, [out] struct text_message ** dst, [out] SAFEARRAY(BSTR) *keylist, [out, retval] pEp_color *rating);
   4.171 +    HRESULT outgoing_message_color([in] struct text_message *msg, [out, retval] pEp_color * pVal);
   4.172      HRESULT identity_color([in] struct pEp_identity_s * ident, [out, retval] pEp_color * pVal);
   4.173  };
   4.174  
   4.175 @@ -264,20 +226,4 @@
   4.176          [default] interface IpEpEngine;
   4.177          [default, source] dispinterface _IpEpEngineEvents;
   4.178      };
   4.179 -	[
   4.180 -		uuid(844B5363-4EF4-4A39-A030-16452783A6F7)		
   4.181 -	]
   4.182 -	dispinterface _ITextMessageEvents
   4.183 -	{
   4.184 -		properties:
   4.185 -		methods:
   4.186 -	};
   4.187 -	[
   4.188 -		uuid(B6CC444F-FE14-4DFE-8315-81E4EA16C1CC)		
   4.189 -	]
   4.190 -	coclass TextMessage
   4.191 -	{
   4.192 -		[default] interface ITextMessage;
   4.193 -		[default, source] dispinterface _ITextMessageEvents;
   4.194 -	};
   4.195  };
     5.1 Binary file pEpCOMServerAdapter.rc has changed
     6.1 --- a/pEpCOMServerAdapter.vcxproj	Sat May 30 19:36:36 2015 +0200
     6.2 +++ b/pEpCOMServerAdapter.vcxproj	Sun May 31 13:25:37 2015 +0200
     6.3 @@ -123,12 +123,11 @@
     6.4        <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
     6.5        </PrecompiledHeader>
     6.6      </ClCompile>
     6.7 -    <ClCompile Include="pEp_identity_helper.cpp" />
     6.8 +    <ClCompile Include="pEp_utitlity.cpp" />
     6.9      <ClCompile Include="stdafx.cpp">
    6.10        <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
    6.11        <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
    6.12      </ClCompile>
    6.13 -    <ClCompile Include="TextMessage.cpp" />
    6.14      <ClCompile Include="utf8_helper.cpp" />
    6.15      <ClCompile Include="xdlldata.c">
    6.16        <CompileAsManaged Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</CompileAsManaged>
    6.17 @@ -143,15 +142,13 @@
    6.18      <ClInclude Include="CpEpEngine.h" />
    6.19      <ClInclude Include="locked_queue.hh" />
    6.20      <ClInclude Include="pEpCOMServerAdapter_i.h" />
    6.21 -    <ClInclude Include="pEp_identity_helper.h" />
    6.22 +    <ClInclude Include="pEp_utility.h" />
    6.23      <ClInclude Include="Resource.h" />
    6.24      <ClInclude Include="stdafx.h" />
    6.25      <ClInclude Include="targetver.h" />
    6.26 -    <ClInclude Include="TextMessage.h" />
    6.27      <ClInclude Include="utf8_helper.h" />
    6.28      <ClInclude Include="xdlldata.h" />
    6.29      <ClInclude Include="_IpEpEngineEvents_CP.h" />
    6.30 -    <ClInclude Include="_ITextMessageEvents_CP.h" />
    6.31    </ItemGroup>
    6.32    <ItemGroup>
    6.33      <ResourceCompile Include="pEpCOMServerAdapter.rc" />
    6.34 @@ -162,7 +159,6 @@
    6.35    <ItemGroup>
    6.36      <None Include="pEpCOMServerAdapter.rgs" />
    6.37      <None Include="pEpEngine.rgs" />
    6.38 -    <None Include="TextMessage.rgs" />
    6.39    </ItemGroup>
    6.40    <ItemGroup>
    6.41      <Midl Include="pEpCOMServerAdapter.idl" />
     7.1 --- a/pEpCOMServerAdapter.vcxproj.filters	Sat May 30 19:36:36 2015 +0200
     7.2 +++ b/pEpCOMServerAdapter.vcxproj.filters	Sun May 31 13:25:37 2015 +0200
     7.3 @@ -37,10 +37,7 @@
     7.4      <ClCompile Include="utf8_helper.cpp">
     7.5        <Filter>Source Files</Filter>
     7.6      </ClCompile>
     7.7 -    <ClCompile Include="TextMessage.cpp">
     7.8 -      <Filter>Source Files</Filter>
     7.9 -    </ClCompile>
    7.10 -    <ClCompile Include="pEp_identity_helper.cpp">
    7.11 +    <ClCompile Include="pEp_utitlity.cpp">
    7.12        <Filter>Source Files</Filter>
    7.13      </ClCompile>
    7.14    </ItemGroup>
    7.15 @@ -72,13 +69,7 @@
    7.16      <ClInclude Include="_IpEpEngineEvents_CP.h">
    7.17        <Filter>Header Files</Filter>
    7.18      </ClInclude>
    7.19 -    <ClInclude Include="_ITextMessageEvents_CP.h">
    7.20 -      <Filter>Header Files</Filter>
    7.21 -    </ClInclude>
    7.22 -    <ClInclude Include="TextMessage.h">
    7.23 -      <Filter>Header Files</Filter>
    7.24 -    </ClInclude>
    7.25 -    <ClInclude Include="pEp_identity_helper.h">
    7.26 +    <ClInclude Include="pEp_utility.h">
    7.27        <Filter>Header Files</Filter>
    7.28      </ClInclude>
    7.29    </ItemGroup>
    7.30 @@ -97,9 +88,6 @@
    7.31      <None Include="pEpEngine.rgs">
    7.32        <Filter>Resource Files</Filter>
    7.33      </None>
    7.34 -    <None Include="TextMessage.rgs">
    7.35 -      <Filter>Resource Files</Filter>
    7.36 -    </None>
    7.37    </ItemGroup>
    7.38    <ItemGroup>
    7.39      <Midl Include="pEpCOMServerAdapter.idl">
     8.1 --- a/pEpCOMServerAdapter_i.c	Sat May 30 19:36:36 2015 +0200
     8.2 +++ b/pEpCOMServerAdapter_i.c	Sun May 31 13:25:37 2015 +0200
     8.3 @@ -6,7 +6,7 @@
     8.4  
     8.5  
     8.6   /* File created by MIDL compiler version 8.00.0603 */
     8.7 -/* at Sat May 30 18:16:12 2015
     8.8 +/* at Sun May 31 10:51:32 2015
     8.9   */
    8.10  /* Compiler settings for pEpCOMServerAdapter.idl:
    8.11      Oicf, W1, Zp8, env=Win32 (32b run), target_arch=X86 8.00.0603 
    8.12 @@ -67,9 +67,6 @@
    8.13  
    8.14  #endif !_MIDL_USE_GUIDDEF_
    8.15  
    8.16 -MIDL_DEFINE_GUID(IID, IID_ITextMessage,0x161538F9,0x53C8,0x4D9C,0x8B,0xA4,0x0F,0xB4,0x3A,0xEC,0x71,0x06);
    8.17 -
    8.18 -
    8.19  MIDL_DEFINE_GUID(IID, IID_IpEpEngine,0x9A9F4422,0xCF0A,0x45D7,0x90,0xCD,0x1D,0x1B,0x7B,0x2A,0x45,0x40);
    8.20  
    8.21  
    8.22 @@ -81,12 +78,6 @@
    8.23  
    8.24  MIDL_DEFINE_GUID(CLSID, CLSID_pEpEngine,0xEF1B073D,0x5058,0x4E0E,0x82,0x9E,0xB4,0xD2,0x2C,0xA2,0x1E,0xA2);
    8.25  
    8.26 -
    8.27 -MIDL_DEFINE_GUID(IID, DIID__ITextMessageEvents,0x844B5363,0x4EF4,0x4A39,0xA0,0x30,0x16,0x45,0x27,0x83,0xA6,0xF7);
    8.28 -
    8.29 -
    8.30 -MIDL_DEFINE_GUID(CLSID, CLSID_TextMessage,0xB6CC444F,0xFE14,0x4DFE,0x83,0x15,0x81,0xE4,0xEA,0x16,0xC1,0xCC);
    8.31 -
    8.32  #undef MIDL_DEFINE_GUID
    8.33  
    8.34  #ifdef __cplusplus
     9.1 --- a/pEpCOMServerAdapter_i.h	Sat May 30 19:36:36 2015 +0200
     9.2 +++ b/pEpCOMServerAdapter_i.h	Sun May 31 13:25:37 2015 +0200
     9.3 @@ -4,7 +4,7 @@
     9.4  
     9.5  
     9.6   /* File created by MIDL compiler version 8.00.0603 */
     9.7 -/* at Sat May 30 18:16:12 2015
     9.8 +/* at Sun May 31 10:51:32 2015
     9.9   */
    9.10  /* Compiler settings for pEpCOMServerAdapter.idl:
    9.11      Oicf, W1, Zp8, env=Win32 (32b run), target_arch=X86 8.00.0603 
    9.12 @@ -45,13 +45,6 @@
    9.13  
    9.14  /* Forward Declarations */ 
    9.15  
    9.16 -#ifndef __ITextMessage_FWD_DEFINED__
    9.17 -#define __ITextMessage_FWD_DEFINED__
    9.18 -typedef interface ITextMessage ITextMessage;
    9.19 -
    9.20 -#endif 	/* __ITextMessage_FWD_DEFINED__ */
    9.21 -
    9.22 -
    9.23  #ifndef __IpEpEngine_FWD_DEFINED__
    9.24  #define __IpEpEngine_FWD_DEFINED__
    9.25  typedef interface IpEpEngine IpEpEngine;
    9.26 @@ -78,25 +71,6 @@
    9.27  #endif 	/* __pEpEngine_FWD_DEFINED__ */
    9.28  
    9.29  
    9.30 -#ifndef ___ITextMessageEvents_FWD_DEFINED__
    9.31 -#define ___ITextMessageEvents_FWD_DEFINED__
    9.32 -typedef interface _ITextMessageEvents _ITextMessageEvents;
    9.33 -
    9.34 -#endif 	/* ___ITextMessageEvents_FWD_DEFINED__ */
    9.35 -
    9.36 -
    9.37 -#ifndef __TextMessage_FWD_DEFINED__
    9.38 -#define __TextMessage_FWD_DEFINED__
    9.39 -
    9.40 -#ifdef __cplusplus
    9.41 -typedef class TextMessage TextMessage;
    9.42 -#else
    9.43 -typedef struct TextMessage TextMessage;
    9.44 -#endif /* __cplusplus */
    9.45 -
    9.46 -#endif 	/* __TextMessage_FWD_DEFINED__ */
    9.47 -
    9.48 -
    9.49  /* header files for imported files */
    9.50  #include "oaidl.h"
    9.51  #include "ocidl.h"
    9.52 @@ -106,494 +80,6 @@
    9.53  #endif 
    9.54  
    9.55  
    9.56 -#ifndef __ITextMessage_INTERFACE_DEFINED__
    9.57 -#define __ITextMessage_INTERFACE_DEFINED__
    9.58 -
    9.59 -/* interface ITextMessage */
    9.60 -/* [unique][nonextensible][oleautomation][uuid][object] */ 
    9.61 -
    9.62 -typedef 
    9.63 -enum _pEp_text_format
    9.64 -    {
    9.65 -        pEp_text_format_plain	= 0,
    9.66 -        pEp_text_format_html	= ( pEp_text_format_plain + 1 ) ,
    9.67 -        pEp_text_format_other	= 0xff
    9.68 -    } 	pEp_text_format;
    9.69 -
    9.70 -typedef 
    9.71 -enum _pEp_msg_direction
    9.72 -    {
    9.73 -        pEp_dir_incoming	= 0,
    9.74 -        pEp_dir_outgoing	= ( pEp_dir_incoming + 1 ) 
    9.75 -    } 	pEp_msg_direction;
    9.76 -
    9.77 -typedef 
    9.78 -enum _pEp_MIME_format
    9.79 -    {
    9.80 -        pEp_MIME_none	= 0,
    9.81 -        pEp_MIME_fields_omitted	= ( pEp_MIME_none + 1 ) ,
    9.82 -        pEp_MIME	= ( pEp_MIME_fields_omitted + 1 ) 
    9.83 -    } 	pEp_MIME_format;
    9.84 -
    9.85 -typedef 
    9.86 -enum _pEp_enc_format
    9.87 -    {
    9.88 -        pEp_enc_none	= 0,
    9.89 -        pEp_enc_pieces	= ( pEp_enc_none + 1 ) ,
    9.90 -        pEp_enc_S_MIME	= ( pEp_enc_pieces + 1 ) ,
    9.91 -        pEp_enc_PGP_MIME	= ( pEp_enc_S_MIME + 1 ) ,
    9.92 -        pEp_enc_pEp	= ( pEp_enc_PGP_MIME + 1 ) 
    9.93 -    } 	pEp_enc_format;
    9.94 -
    9.95 -/* [uuid] */ struct  DECLSPEC_UUID("1292C31A-6486-427F-B29F-7F03607836DC") opt_field
    9.96 -    {
    9.97 -    BSTR name;
    9.98 -    BSTR value;
    9.99 -    } ;
   9.100 -
   9.101 -EXTERN_C const IID IID_ITextMessage;
   9.102 -
   9.103 -#if defined(__cplusplus) && !defined(CINTERFACE)
   9.104 -    
   9.105 -    MIDL_INTERFACE("161538F9-53C8-4D9C-8BA4-0FB43AEC7106")
   9.106 -    ITextMessage : public IUnknown
   9.107 -    {
   9.108 -    public:
   9.109 -        virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_dir( 
   9.110 -            /* [retval][out] */ pEp_msg_direction *pVal) = 0;
   9.111 -        
   9.112 -        virtual /* [propput] */ HRESULT STDMETHODCALLTYPE put_dir( 
   9.113 -            /* [in] */ pEp_msg_direction newVal) = 0;
   9.114 -        
   9.115 -        virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_id( 
   9.116 -            /* [retval][out] */ BSTR *pVal) = 0;
   9.117 -        
   9.118 -        virtual /* [propput] */ HRESULT STDMETHODCALLTYPE put_id( 
   9.119 -            /* [in] */ BSTR newVal) = 0;
   9.120 -        
   9.121 -        virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_shortmsg( 
   9.122 -            /* [retval][out] */ BSTR *pVal) = 0;
   9.123 -        
   9.124 -        virtual /* [propput] */ HRESULT STDMETHODCALLTYPE put_shortmsg( 
   9.125 -            /* [in] */ BSTR newVal) = 0;
   9.126 -        
   9.127 -        virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_longmsg( 
   9.128 -            /* [retval][out] */ BSTR *pVal) = 0;
   9.129 -        
   9.130 -        virtual /* [propput] */ HRESULT STDMETHODCALLTYPE put_longmsg( 
   9.131 -            /* [in] */ BSTR newVal) = 0;
   9.132 -        
   9.133 -        virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_longmsg_formatted( 
   9.134 -            /* [retval][out] */ BSTR *pVal) = 0;
   9.135 -        
   9.136 -        virtual /* [propput] */ HRESULT STDMETHODCALLTYPE put_longmsg_formatted( 
   9.137 -            /* [in] */ BSTR newVal) = 0;
   9.138 -        
   9.139 -        virtual HRESULT STDMETHODCALLTYPE add_attachment( 
   9.140 -            /* [in] */ SAFEARRAY * data,
   9.141 -            /* [in] */ BSTR mime_type,
   9.142 -            /* [in] */ BSTR filename) = 0;
   9.143 -        
   9.144 -        virtual HRESULT STDMETHODCALLTYPE has_attachments( 
   9.145 -            /* [retval][out] */ boolean *result) = 0;
   9.146 -        
   9.147 -        virtual HRESULT STDMETHODCALLTYPE next_attachment( 
   9.148 -            /* [out] */ SAFEARRAY * *data,
   9.149 -            /* [out] */ BSTR *mime_type,
   9.150 -            /* [out] */ BSTR *filename,
   9.151 -            /* [retval][out] */ boolean *result) = 0;
   9.152 -        
   9.153 -        virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_sent( 
   9.154 -            /* [retval][out] */ hyper *result) = 0;
   9.155 -        
   9.156 -        virtual /* [propput] */ HRESULT STDMETHODCALLTYPE put_sent( 
   9.157 -            /* [in] */ hyper val) = 0;
   9.158 -        
   9.159 -        virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_recv( 
   9.160 -            /* [retval][out] */ hyper *result) = 0;
   9.161 -        
   9.162 -        virtual /* [propput] */ HRESULT STDMETHODCALLTYPE put_recv( 
   9.163 -            /* [in] */ hyper val) = 0;
   9.164 -        
   9.165 -        virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_from( 
   9.166 -            /* [retval][out] */ struct pEp_identity_s *pVal) = 0;
   9.167 -        
   9.168 -        virtual /* [propput] */ HRESULT STDMETHODCALLTYPE put_from( 
   9.169 -            /* [in] */ struct pEp_identity_s *newVal) = 0;
   9.170 -        
   9.171 -        virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_to( 
   9.172 -            /* [retval][out] */ SAFEARRAY * *pVal) = 0;
   9.173 -        
   9.174 -        virtual /* [propput] */ HRESULT STDMETHODCALLTYPE put_to( 
   9.175 -            /* [in] */ SAFEARRAY * newVal) = 0;
   9.176 -        
   9.177 -        virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_recv_by( 
   9.178 -            /* [retval][out] */ struct pEp_identity_s *pVal) = 0;
   9.179 -        
   9.180 -        virtual /* [propput] */ HRESULT STDMETHODCALLTYPE put_recv_by( 
   9.181 -            /* [in] */ struct pEp_identity_s *newVal) = 0;
   9.182 -        
   9.183 -        virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_cc( 
   9.184 -            /* [retval][out] */ SAFEARRAY * *pVal) = 0;
   9.185 -        
   9.186 -        virtual /* [propput] */ HRESULT STDMETHODCALLTYPE put_cc( 
   9.187 -            /* [in] */ SAFEARRAY * newVal) = 0;
   9.188 -        
   9.189 -        virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_bcc( 
   9.190 -            /* [retval][out] */ SAFEARRAY * *pVal) = 0;
   9.191 -        
   9.192 -        virtual /* [propput] */ HRESULT STDMETHODCALLTYPE put_bcc( 
   9.193 -            /* [in] */ SAFEARRAY * newVal) = 0;
   9.194 -        
   9.195 -        virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_reply_to( 
   9.196 -            /* [retval][out] */ SAFEARRAY * *pVal) = 0;
   9.197 -        
   9.198 -        virtual /* [propput] */ HRESULT STDMETHODCALLTYPE put_reply_to( 
   9.199 -            /* [in] */ SAFEARRAY * newVal) = 0;
   9.200 -        
   9.201 -        virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_references( 
   9.202 -            /* [retval][out] */ SAFEARRAY * *pVal) = 0;
   9.203 -        
   9.204 -        virtual /* [propput] */ HRESULT STDMETHODCALLTYPE put_references( 
   9.205 -            /* [in] */ SAFEARRAY * newVal) = 0;
   9.206 -        
   9.207 -        virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_keywords( 
   9.208 -            /* [retval][out] */ SAFEARRAY * *pVal) = 0;
   9.209 -        
   9.210 -        virtual /* [propput] */ HRESULT STDMETHODCALLTYPE put_keywords( 
   9.211 -            /* [in] */ SAFEARRAY * newVal) = 0;
   9.212 -        
   9.213 -        virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_comments( 
   9.214 -            /* [retval][out] */ BSTR *pVal) = 0;
   9.215 -        
   9.216 -        virtual /* [propput] */ HRESULT STDMETHODCALLTYPE put_comments( 
   9.217 -            /* [in] */ BSTR newVal) = 0;
   9.218 -        
   9.219 -        virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_opt_fields( 
   9.220 -            /* [retval][out] */ SAFEARRAY * *pVal) = 0;
   9.221 -        
   9.222 -        virtual /* [propput] */ HRESULT STDMETHODCALLTYPE put_opt_fields( 
   9.223 -            /* [in] */ SAFEARRAY * newVal) = 0;
   9.224 -        
   9.225 -    };
   9.226 -    
   9.227 -    
   9.228 -#else 	/* C style interface */
   9.229 -
   9.230 -    typedef struct ITextMessageVtbl
   9.231 -    {
   9.232 -        BEGIN_INTERFACE
   9.233 -        
   9.234 -        HRESULT ( STDMETHODCALLTYPE *QueryInterface )( 
   9.235 -            ITextMessage * This,
   9.236 -            /* [in] */ REFIID riid,
   9.237 -            /* [annotation][iid_is][out] */ 
   9.238 -            _COM_Outptr_  void **ppvObject);
   9.239 -        
   9.240 -        ULONG ( STDMETHODCALLTYPE *AddRef )( 
   9.241 -            ITextMessage * This);
   9.242 -        
   9.243 -        ULONG ( STDMETHODCALLTYPE *Release )( 
   9.244 -            ITextMessage * This);
   9.245 -        
   9.246 -        /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_dir )( 
   9.247 -            ITextMessage * This,
   9.248 -            /* [retval][out] */ pEp_msg_direction *pVal);
   9.249 -        
   9.250 -        /* [propput] */ HRESULT ( STDMETHODCALLTYPE *put_dir )( 
   9.251 -            ITextMessage * This,
   9.252 -            /* [in] */ pEp_msg_direction newVal);
   9.253 -        
   9.254 -        /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_id )( 
   9.255 -            ITextMessage * This,
   9.256 -            /* [retval][out] */ BSTR *pVal);
   9.257 -        
   9.258 -        /* [propput] */ HRESULT ( STDMETHODCALLTYPE *put_id )( 
   9.259 -            ITextMessage * This,
   9.260 -            /* [in] */ BSTR newVal);
   9.261 -        
   9.262 -        /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_shortmsg )( 
   9.263 -            ITextMessage * This,
   9.264 -            /* [retval][out] */ BSTR *pVal);
   9.265 -        
   9.266 -        /* [propput] */ HRESULT ( STDMETHODCALLTYPE *put_shortmsg )( 
   9.267 -            ITextMessage * This,
   9.268 -            /* [in] */ BSTR newVal);
   9.269 -        
   9.270 -        /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_longmsg )( 
   9.271 -            ITextMessage * This,
   9.272 -            /* [retval][out] */ BSTR *pVal);
   9.273 -        
   9.274 -        /* [propput] */ HRESULT ( STDMETHODCALLTYPE *put_longmsg )( 
   9.275 -            ITextMessage * This,
   9.276 -            /* [in] */ BSTR newVal);
   9.277 -        
   9.278 -        /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_longmsg_formatted )( 
   9.279 -            ITextMessage * This,
   9.280 -            /* [retval][out] */ BSTR *pVal);
   9.281 -        
   9.282 -        /* [propput] */ HRESULT ( STDMETHODCALLTYPE *put_longmsg_formatted )( 
   9.283 -            ITextMessage * This,
   9.284 -            /* [in] */ BSTR newVal);
   9.285 -        
   9.286 -        HRESULT ( STDMETHODCALLTYPE *add_attachment )( 
   9.287 -            ITextMessage * This,
   9.288 -            /* [in] */ SAFEARRAY * data,
   9.289 -            /* [in] */ BSTR mime_type,
   9.290 -            /* [in] */ BSTR filename);
   9.291 -        
   9.292 -        HRESULT ( STDMETHODCALLTYPE *has_attachments )( 
   9.293 -            ITextMessage * This,
   9.294 -            /* [retval][out] */ boolean *result);
   9.295 -        
   9.296 -        HRESULT ( STDMETHODCALLTYPE *next_attachment )( 
   9.297 -            ITextMessage * This,
   9.298 -            /* [out] */ SAFEARRAY * *data,
   9.299 -            /* [out] */ BSTR *mime_type,
   9.300 -            /* [out] */ BSTR *filename,
   9.301 -            /* [retval][out] */ boolean *result);
   9.302 -        
   9.303 -        /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_sent )( 
   9.304 -            ITextMessage * This,
   9.305 -            /* [retval][out] */ hyper *result);
   9.306 -        
   9.307 -        /* [propput] */ HRESULT ( STDMETHODCALLTYPE *put_sent )( 
   9.308 -            ITextMessage * This,
   9.309 -            /* [in] */ hyper val);
   9.310 -        
   9.311 -        /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_recv )( 
   9.312 -            ITextMessage * This,
   9.313 -            /* [retval][out] */ hyper *result);
   9.314 -        
   9.315 -        /* [propput] */ HRESULT ( STDMETHODCALLTYPE *put_recv )( 
   9.316 -            ITextMessage * This,
   9.317 -            /* [in] */ hyper val);
   9.318 -        
   9.319 -        /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_from )( 
   9.320 -            ITextMessage * This,
   9.321 -            /* [retval][out] */ struct pEp_identity_s *pVal);
   9.322 -        
   9.323 -        /* [propput] */ HRESULT ( STDMETHODCALLTYPE *put_from )( 
   9.324 -            ITextMessage * This,
   9.325 -            /* [in] */ struct pEp_identity_s *newVal);
   9.326 -        
   9.327 -        /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_to )( 
   9.328 -            ITextMessage * This,
   9.329 -            /* [retval][out] */ SAFEARRAY * *pVal);
   9.330 -        
   9.331 -        /* [propput] */ HRESULT ( STDMETHODCALLTYPE *put_to )( 
   9.332 -            ITextMessage * This,
   9.333 -            /* [in] */ SAFEARRAY * newVal);
   9.334 -        
   9.335 -        /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_recv_by )( 
   9.336 -            ITextMessage * This,
   9.337 -            /* [retval][out] */ struct pEp_identity_s *pVal);
   9.338 -        
   9.339 -        /* [propput] */ HRESULT ( STDMETHODCALLTYPE *put_recv_by )( 
   9.340 -            ITextMessage * This,
   9.341 -            /* [in] */ struct pEp_identity_s *newVal);
   9.342 -        
   9.343 -        /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_cc )( 
   9.344 -            ITextMessage * This,
   9.345 -            /* [retval][out] */ SAFEARRAY * *pVal);
   9.346 -        
   9.347 -        /* [propput] */ HRESULT ( STDMETHODCALLTYPE *put_cc )( 
   9.348 -            ITextMessage * This,
   9.349 -            /* [in] */ SAFEARRAY * newVal);
   9.350 -        
   9.351 -        /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_bcc )( 
   9.352 -            ITextMessage * This,
   9.353 -            /* [retval][out] */ SAFEARRAY * *pVal);
   9.354 -        
   9.355 -        /* [propput] */ HRESULT ( STDMETHODCALLTYPE *put_bcc )( 
   9.356 -            ITextMessage * This,
   9.357 -            /* [in] */ SAFEARRAY * newVal);
   9.358 -        
   9.359 -        /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_reply_to )( 
   9.360 -            ITextMessage * This,
   9.361 -            /* [retval][out] */ SAFEARRAY * *pVal);
   9.362 -        
   9.363 -        /* [propput] */ HRESULT ( STDMETHODCALLTYPE *put_reply_to )( 
   9.364 -            ITextMessage * This,
   9.365 -            /* [in] */ SAFEARRAY * newVal);
   9.366 -        
   9.367 -        /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_references )( 
   9.368 -            ITextMessage * This,
   9.369 -            /* [retval][out] */ SAFEARRAY * *pVal);
   9.370 -        
   9.371 -        /* [propput] */ HRESULT ( STDMETHODCALLTYPE *put_references )( 
   9.372 -            ITextMessage * This,
   9.373 -            /* [in] */ SAFEARRAY * newVal);
   9.374 -        
   9.375 -        /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_keywords )( 
   9.376 -            ITextMessage * This,
   9.377 -            /* [retval][out] */ SAFEARRAY * *pVal);
   9.378 -        
   9.379 -        /* [propput] */ HRESULT ( STDMETHODCALLTYPE *put_keywords )( 
   9.380 -            ITextMessage * This,
   9.381 -            /* [in] */ SAFEARRAY * newVal);
   9.382 -        
   9.383 -        /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_comments )( 
   9.384 -            ITextMessage * This,
   9.385 -            /* [retval][out] */ BSTR *pVal);
   9.386 -        
   9.387 -        /* [propput] */ HRESULT ( STDMETHODCALLTYPE *put_comments )( 
   9.388 -            ITextMessage * This,
   9.389 -            /* [in] */ BSTR newVal);
   9.390 -        
   9.391 -        /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_opt_fields )( 
   9.392 -            ITextMessage * This,
   9.393 -            /* [retval][out] */ SAFEARRAY * *pVal);
   9.394 -        
   9.395 -        /* [propput] */ HRESULT ( STDMETHODCALLTYPE *put_opt_fields )( 
   9.396 -            ITextMessage * This,
   9.397 -            /* [in] */ SAFEARRAY * newVal);
   9.398 -        
   9.399 -        END_INTERFACE
   9.400 -    } ITextMessageVtbl;
   9.401 -
   9.402 -    interface ITextMessage
   9.403 -    {
   9.404 -        CONST_VTBL struct ITextMessageVtbl *lpVtbl;
   9.405 -    };
   9.406 -
   9.407 -    
   9.408 -
   9.409 -#ifdef COBJMACROS
   9.410 -
   9.411 -
   9.412 -#define ITextMessage_QueryInterface(This,riid,ppvObject)	\
   9.413 -    ( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) ) 
   9.414 -
   9.415 -#define ITextMessage_AddRef(This)	\
   9.416 -    ( (This)->lpVtbl -> AddRef(This) ) 
   9.417 -
   9.418 -#define ITextMessage_Release(This)	\
   9.419 -    ( (This)->lpVtbl -> Release(This) ) 
   9.420 -
   9.421 -
   9.422 -#define ITextMessage_get_dir(This,pVal)	\
   9.423 -    ( (This)->lpVtbl -> get_dir(This,pVal) ) 
   9.424 -
   9.425 -#define ITextMessage_put_dir(This,newVal)	\
   9.426 -    ( (This)->lpVtbl -> put_dir(This,newVal) ) 
   9.427 -
   9.428 -#define ITextMessage_get_id(This,pVal)	\
   9.429 -    ( (This)->lpVtbl -> get_id(This,pVal) ) 
   9.430 -
   9.431 -#define ITextMessage_put_id(This,newVal)	\
   9.432 -    ( (This)->lpVtbl -> put_id(This,newVal) ) 
   9.433 -
   9.434 -#define ITextMessage_get_shortmsg(This,pVal)	\
   9.435 -    ( (This)->lpVtbl -> get_shortmsg(This,pVal) ) 
   9.436 -
   9.437 -#define ITextMessage_put_shortmsg(This,newVal)	\
   9.438 -    ( (This)->lpVtbl -> put_shortmsg(This,newVal) ) 
   9.439 -
   9.440 -#define ITextMessage_get_longmsg(This,pVal)	\
   9.441 -    ( (This)->lpVtbl -> get_longmsg(This,pVal) ) 
   9.442 -
   9.443 -#define ITextMessage_put_longmsg(This,newVal)	\
   9.444 -    ( (This)->lpVtbl -> put_longmsg(This,newVal) ) 
   9.445 -
   9.446 -#define ITextMessage_get_longmsg_formatted(This,pVal)	\
   9.447 -    ( (This)->lpVtbl -> get_longmsg_formatted(This,pVal) ) 
   9.448 -
   9.449 -#define ITextMessage_put_longmsg_formatted(This,newVal)	\
   9.450 -    ( (This)->lpVtbl -> put_longmsg_formatted(This,newVal) ) 
   9.451 -
   9.452 -#define ITextMessage_add_attachment(This,data,mime_type,filename)	\
   9.453 -    ( (This)->lpVtbl -> add_attachment(This,data,mime_type,filename) ) 
   9.454 -
   9.455 -#define ITextMessage_has_attachments(This,result)	\
   9.456 -    ( (This)->lpVtbl -> has_attachments(This,result) ) 
   9.457 -
   9.458 -#define ITextMessage_next_attachment(This,data,mime_type,filename,result)	\
   9.459 -    ( (This)->lpVtbl -> next_attachment(This,data,mime_type,filename,result) ) 
   9.460 -
   9.461 -#define ITextMessage_get_sent(This,result)	\
   9.462 -    ( (This)->lpVtbl -> get_sent(This,result) ) 
   9.463 -
   9.464 -#define ITextMessage_put_sent(This,val)	\
   9.465 -    ( (This)->lpVtbl -> put_sent(This,val) ) 
   9.466 -
   9.467 -#define ITextMessage_get_recv(This,result)	\
   9.468 -    ( (This)->lpVtbl -> get_recv(This,result) ) 
   9.469 -
   9.470 -#define ITextMessage_put_recv(This,val)	\
   9.471 -    ( (This)->lpVtbl -> put_recv(This,val) ) 
   9.472 -
   9.473 -#define ITextMessage_get_from(This,pVal)	\
   9.474 -    ( (This)->lpVtbl -> get_from(This,pVal) ) 
   9.475 -
   9.476 -#define ITextMessage_put_from(This,newVal)	\
   9.477 -    ( (This)->lpVtbl -> put_from(This,newVal) ) 
   9.478 -
   9.479 -#define ITextMessage_get_to(This,pVal)	\
   9.480 -    ( (This)->lpVtbl -> get_to(This,pVal) ) 
   9.481 -
   9.482 -#define ITextMessage_put_to(This,newVal)	\
   9.483 -    ( (This)->lpVtbl -> put_to(This,newVal) ) 
   9.484 -
   9.485 -#define ITextMessage_get_recv_by(This,pVal)	\
   9.486 -    ( (This)->lpVtbl -> get_recv_by(This,pVal) ) 
   9.487 -
   9.488 -#define ITextMessage_put_recv_by(This,newVal)	\
   9.489 -    ( (This)->lpVtbl -> put_recv_by(This,newVal) ) 
   9.490 -
   9.491 -#define ITextMessage_get_cc(This,pVal)	\
   9.492 -    ( (This)->lpVtbl -> get_cc(This,pVal) ) 
   9.493 -
   9.494 -#define ITextMessage_put_cc(This,newVal)	\
   9.495 -    ( (This)->lpVtbl -> put_cc(This,newVal) ) 
   9.496 -
   9.497 -#define ITextMessage_get_bcc(This,pVal)	\
   9.498 -    ( (This)->lpVtbl -> get_bcc(This,pVal) ) 
   9.499 -
   9.500 -#define ITextMessage_put_bcc(This,newVal)	\
   9.501 -    ( (This)->lpVtbl -> put_bcc(This,newVal) ) 
   9.502 -
   9.503 -#define ITextMessage_get_reply_to(This,pVal)	\
   9.504 -    ( (This)->lpVtbl -> get_reply_to(This,pVal) ) 
   9.505 -
   9.506 -#define ITextMessage_put_reply_to(This,newVal)	\
   9.507 -    ( (This)->lpVtbl -> put_reply_to(This,newVal) ) 
   9.508 -
   9.509 -#define ITextMessage_get_references(This,pVal)	\
   9.510 -    ( (This)->lpVtbl -> get_references(This,pVal) ) 
   9.511 -
   9.512 -#define ITextMessage_put_references(This,newVal)	\
   9.513 -    ( (This)->lpVtbl -> put_references(This,newVal) ) 
   9.514 -
   9.515 -#define ITextMessage_get_keywords(This,pVal)	\
   9.516 -    ( (This)->lpVtbl -> get_keywords(This,pVal) ) 
   9.517 -
   9.518 -#define ITextMessage_put_keywords(This,newVal)	\
   9.519 -    ( (This)->lpVtbl -> put_keywords(This,newVal) ) 
   9.520 -
   9.521 -#define ITextMessage_get_comments(This,pVal)	\
   9.522 -    ( (This)->lpVtbl -> get_comments(This,pVal) ) 
   9.523 -
   9.524 -#define ITextMessage_put_comments(This,newVal)	\
   9.525 -    ( (This)->lpVtbl -> put_comments(This,newVal) ) 
   9.526 -
   9.527 -#define ITextMessage_get_opt_fields(This,pVal)	\
   9.528 -    ( (This)->lpVtbl -> get_opt_fields(This,pVal) ) 
   9.529 -
   9.530 -#define ITextMessage_put_opt_fields(This,newVal)	\
   9.531 -    ( (This)->lpVtbl -> put_opt_fields(This,newVal) ) 
   9.532 -
   9.533 -#endif /* COBJMACROS */
   9.534 -
   9.535 -
   9.536 -#endif 	/* C style interface */
   9.537 -
   9.538 -
   9.539 -
   9.540 -
   9.541 -#endif 	/* __ITextMessage_INTERFACE_DEFINED__ */
   9.542 -
   9.543 -
   9.544  #ifndef __IpEpEngine_INTERFACE_DEFINED__
   9.545  #define __IpEpEngine_INTERFACE_DEFINED__
   9.546  
   9.547 @@ -678,6 +164,71 @@
   9.548          pEp_rating_b0rken	= -2
   9.549      } 	pEp_color;
   9.550  
   9.551 +typedef 
   9.552 +enum _pEp_text_format
   9.553 +    {
   9.554 +        pEp_text_format_plain	= 0,
   9.555 +        pEp_text_format_html	= ( pEp_text_format_plain + 1 ) ,
   9.556 +        pEp_text_format_other	= 0xff
   9.557 +    } 	pEp_text_format;
   9.558 +
   9.559 +typedef 
   9.560 +enum _pEp_msg_direction
   9.561 +    {
   9.562 +        pEp_dir_incoming	= 0,
   9.563 +        pEp_dir_outgoing	= ( pEp_dir_incoming + 1 ) 
   9.564 +    } 	pEp_msg_direction;
   9.565 +
   9.566 +typedef 
   9.567 +enum _pEp_MIME_format
   9.568 +    {
   9.569 +        pEp_MIME_none	= 0,
   9.570 +        pEp_MIME_fields_omitted	= ( pEp_MIME_none + 1 ) ,
   9.571 +        pEp_MIME	= ( pEp_MIME_fields_omitted + 1 ) 
   9.572 +    } 	pEp_MIME_format;
   9.573 +
   9.574 +typedef 
   9.575 +enum _pEp_enc_format
   9.576 +    {
   9.577 +        pEp_enc_none	= 0,
   9.578 +        pEp_enc_pieces	= ( pEp_enc_none + 1 ) ,
   9.579 +        pEp_enc_S_MIME	= ( pEp_enc_pieces + 1 ) ,
   9.580 +        pEp_enc_PGP_MIME	= ( pEp_enc_S_MIME + 1 ) ,
   9.581 +        pEp_enc_pEp	= ( pEp_enc_PGP_MIME + 1 ) 
   9.582 +    } 	pEp_enc_format;
   9.583 +
   9.584 +/* [uuid] */ struct  DECLSPEC_UUID("3A8A4F13-3402-4C4C-94AB-598D87869380") opt_field
   9.585 +    {
   9.586 +    BSTR name;
   9.587 +    BSTR value;
   9.588 +    } ;
   9.589 +/* [uuid] */ struct  DECLSPEC_UUID("61DA7AD4-192E-4616-8678-B19AEFB45B45") blob
   9.590 +    {
   9.591 +    SAFEARRAY * value;
   9.592 +    BSTR mime_type;
   9.593 +    BSTR filename;
   9.594 +    } ;
   9.595 +/* [uuid] */ struct  DECLSPEC_UUID("D763A8F3-BA23-4229-A037-1BB7BDC3E0C8") text_message
   9.596 +    {
   9.597 +    pEp_msg_direction dir;
   9.598 +    BSTR id;
   9.599 +    BSTR shortmsg;
   9.600 +    BSTR longmsg;
   9.601 +    BSTR longmsg_formatted;
   9.602 +    SAFEARRAY * attachments;
   9.603 +    hyper sent;
   9.604 +    hyper recv;
   9.605 +    struct pEp_identity_s from;
   9.606 +    SAFEARRAY * to;
   9.607 +    struct pEp_identity_s recv_by;
   9.608 +    SAFEARRAY * cc;
   9.609 +    SAFEARRAY * bcc;
   9.610 +    SAFEARRAY * reply_to;
   9.611 +    SAFEARRAY * references;
   9.612 +    SAFEARRAY * keywords;
   9.613 +    BSTR comments;
   9.614 +    SAFEARRAY * opt_fields;
   9.615 +    } ;
   9.616  
   9.617  EXTERN_C const IID IID_IpEpEngine;
   9.618  
   9.619 @@ -787,18 +338,18 @@
   9.620              /* [in] */ BSTR fpr) = 0;
   9.621          
   9.622          virtual HRESULT STDMETHODCALLTYPE encrypt_message( 
   9.623 -            /* [ref][in] */ ITextMessage *src,
   9.624 -            /* [ref][in] */ ITextMessage *dst,
   9.625 +            /* [in] */ struct text_message *src,
   9.626 +            /* [out] */ struct text_message **dst,
   9.627              /* [in] */ SAFEARRAY * extra) = 0;
   9.628          
   9.629          virtual HRESULT STDMETHODCALLTYPE decrypt_message( 
   9.630 -            /* [ref][in] */ ITextMessage *src,
   9.631 -            /* [ref][in] */ ITextMessage *dst,
   9.632 +            /* [in] */ struct text_message *src,
   9.633 +            /* [out] */ struct text_message **dst,
   9.634              /* [out] */ SAFEARRAY * *keylist,
   9.635              /* [retval][out] */ pEp_color *rating) = 0;
   9.636          
   9.637          virtual HRESULT STDMETHODCALLTYPE outgoing_message_color( 
   9.638 -            /* [in] */ ITextMessage *msg,
   9.639 +            /* [in] */ struct text_message *msg,
   9.640              /* [retval][out] */ pEp_color *pVal) = 0;
   9.641          
   9.642          virtual HRESULT STDMETHODCALLTYPE identity_color( 
   9.643 @@ -951,20 +502,20 @@
   9.644          
   9.645          HRESULT ( STDMETHODCALLTYPE *encrypt_message )( 
   9.646              IpEpEngine * This,
   9.647 -            /* [ref][in] */ ITextMessage *src,
   9.648 -            /* [ref][in] */ ITextMessage *dst,
   9.649 +            /* [in] */ struct text_message *src,
   9.650 +            /* [out] */ struct text_message **dst,
   9.651              /* [in] */ SAFEARRAY * extra);
   9.652          
   9.653          HRESULT ( STDMETHODCALLTYPE *decrypt_message )( 
   9.654              IpEpEngine * This,
   9.655 -            /* [ref][in] */ ITextMessage *src,
   9.656 -            /* [ref][in] */ ITextMessage *dst,
   9.657 +            /* [in] */ struct text_message *src,
   9.658 +            /* [out] */ struct text_message **dst,
   9.659              /* [out] */ SAFEARRAY * *keylist,
   9.660              /* [retval][out] */ pEp_color *rating);
   9.661          
   9.662          HRESULT ( STDMETHODCALLTYPE *outgoing_message_color )( 
   9.663              IpEpEngine * This,
   9.664 -            /* [in] */ ITextMessage *msg,
   9.665 +            /* [in] */ struct text_message *msg,
   9.666              /* [retval][out] */ pEp_color *pVal);
   9.667          
   9.668          HRESULT ( STDMETHODCALLTYPE *identity_color )( 
   9.669 @@ -1222,129 +773,6 @@
   9.670  class DECLSPEC_UUID("EF1B073D-5058-4E0E-829E-B4D22CA21EA2")
   9.671  pEpEngine;
   9.672  #endif
   9.673 -
   9.674 -#ifndef ___ITextMessageEvents_DISPINTERFACE_DEFINED__
   9.675 -#define ___ITextMessageEvents_DISPINTERFACE_DEFINED__
   9.676 -
   9.677 -/* dispinterface _ITextMessageEvents */
   9.678 -/* [uuid] */ 
   9.679 -
   9.680 -
   9.681 -EXTERN_C const IID DIID__ITextMessageEvents;
   9.682 -
   9.683 -#if defined(__cplusplus) && !defined(CINTERFACE)
   9.684 -
   9.685 -    MIDL_INTERFACE("844B5363-4EF4-4A39-A030-16452783A6F7")
   9.686 -    _ITextMessageEvents : public IDispatch
   9.687 -    {
   9.688 -    };
   9.689 -    
   9.690 -#else 	/* C style interface */
   9.691 -
   9.692 -    typedef struct _ITextMessageEventsVtbl
   9.693 -    {
   9.694 -        BEGIN_INTERFACE
   9.695 -        
   9.696 -        HRESULT ( STDMETHODCALLTYPE *QueryInterface )( 
   9.697 -            _ITextMessageEvents * This,
   9.698 -            /* [in] */ REFIID riid,
   9.699 -            /* [annotation][iid_is][out] */ 
   9.700 -            _COM_Outptr_  void **ppvObject);
   9.701 -        
   9.702 -        ULONG ( STDMETHODCALLTYPE *AddRef )( 
   9.703 -            _ITextMessageEvents * This);
   9.704 -        
   9.705 -        ULONG ( STDMETHODCALLTYPE *Release )( 
   9.706 -            _ITextMessageEvents * This);
   9.707 -        
   9.708 -        HRESULT ( STDMETHODCALLTYPE *GetTypeInfoCount )( 
   9.709 -            _ITextMessageEvents * This,
   9.710 -            /* [out] */ UINT *pctinfo);
   9.711 -        
   9.712 -        HRESULT ( STDMETHODCALLTYPE *GetTypeInfo )( 
   9.713 -            _ITextMessageEvents * This,
   9.714 -            /* [in] */ UINT iTInfo,
   9.715 -            /* [in] */ LCID lcid,
   9.716 -            /* [out] */ ITypeInfo **ppTInfo);
   9.717 -        
   9.718 -        HRESULT ( STDMETHODCALLTYPE *GetIDsOfNames )( 
   9.719 -            _ITextMessageEvents * This,
   9.720 -            /* [in] */ REFIID riid,
   9.721 -            /* [size_is][in] */ LPOLESTR *rgszNames,
   9.722 -            /* [range][in] */ UINT cNames,
   9.723 -            /* [in] */ LCID lcid,
   9.724 -            /* [size_is][out] */ DISPID *rgDispId);
   9.725 -        
   9.726 -        /* [local] */ HRESULT ( STDMETHODCALLTYPE *Invoke )( 
   9.727 -            _ITextMessageEvents * This,
   9.728 -            /* [annotation][in] */ 
   9.729 -            _In_  DISPID dispIdMember,
   9.730 -            /* [annotation][in] */ 
   9.731 -            _In_  REFIID riid,
   9.732 -            /* [annotation][in] */ 
   9.733 -            _In_  LCID lcid,
   9.734 -            /* [annotation][in] */ 
   9.735 -            _In_  WORD wFlags,
   9.736 -            /* [annotation][out][in] */ 
   9.737 -            _In_  DISPPARAMS *pDispParams,
   9.738 -            /* [annotation][out] */ 
   9.739 -            _Out_opt_  VARIANT *pVarResult,
   9.740 -            /* [annotation][out] */ 
   9.741 -            _Out_opt_  EXCEPINFO *pExcepInfo,
   9.742 -            /* [annotation][out] */ 
   9.743 -            _Out_opt_  UINT *puArgErr);
   9.744 -        
   9.745 -        END_INTERFACE
   9.746 -    } _ITextMessageEventsVtbl;
   9.747 -
   9.748 -    interface _ITextMessageEvents
   9.749 -    {
   9.750 -        CONST_VTBL struct _ITextMessageEventsVtbl *lpVtbl;
   9.751 -    };
   9.752 -
   9.753 -    
   9.754 -
   9.755 -#ifdef COBJMACROS
   9.756 -
   9.757 -
   9.758 -#define _ITextMessageEvents_QueryInterface(This,riid,ppvObject)	\
   9.759 -    ( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) ) 
   9.760 -
   9.761 -#define _ITextMessageEvents_AddRef(This)	\
   9.762 -    ( (This)->lpVtbl -> AddRef(This) ) 
   9.763 -
   9.764 -#define _ITextMessageEvents_Release(This)	\
   9.765 -    ( (This)->lpVtbl -> Release(This) ) 
   9.766 -
   9.767 -
   9.768 -#define _ITextMessageEvents_GetTypeInfoCount(This,pctinfo)	\
   9.769 -    ( (This)->lpVtbl -> GetTypeInfoCount(This,pctinfo) ) 
   9.770 -
   9.771 -#define _ITextMessageEvents_GetTypeInfo(This,iTInfo,lcid,ppTInfo)	\
   9.772 -    ( (This)->lpVtbl -> GetTypeInfo(This,iTInfo,lcid,ppTInfo) ) 
   9.773 -
   9.774 -#define _ITextMessageEvents_GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId)	\
   9.775 -    ( (This)->lpVtbl -> GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId) ) 
   9.776 -
   9.777 -#define _ITextMessageEvents_Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr)	\
   9.778 -    ( (This)->lpVtbl -> Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr) ) 
   9.779 -
   9.780 -#endif /* COBJMACROS */
   9.781 -
   9.782 -
   9.783 -#endif 	/* C style interface */
   9.784 -
   9.785 -
   9.786 -#endif 	/* ___ITextMessageEvents_DISPINTERFACE_DEFINED__ */
   9.787 -
   9.788 -
   9.789 -EXTERN_C const CLSID CLSID_TextMessage;
   9.790 -
   9.791 -#ifdef __cplusplus
   9.792 -
   9.793 -class DECLSPEC_UUID("B6CC444F-FE14-4DFE-8315-81E4EA16C1CC")
   9.794 -TextMessage;
   9.795 -#endif
   9.796  #endif /* __pEpCOMServerAdapterLib_LIBRARY_DEFINED__ */
   9.797  
   9.798  /* Additional Prototypes for ALL interfaces */
    10.1 --- a/pEp_identity_helper.cpp	Sat May 30 19:36:36 2015 +0200
    10.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.3 @@ -1,150 +0,0 @@
    10.4 -#include "stdafx.h"
    10.5 -#include "pEp_identity_helper.h"
    10.6 -
    10.7 -namespace pEp {
    10.8 -    namespace utility {
    10.9 -        pEp_identity_cpp::pEp_identity_cpp(const ::pEp_identity *_ident)
   10.10 -            : me(false)
   10.11 -        {
   10.12 -            if (_ident->address)
   10.13 -                address = _ident->address;
   10.14 -            if (_ident->fpr)
   10.15 -                fpr = _ident->fpr;
   10.16 -            if (_ident->user_id)
   10.17 -                user_id = _ident->user_id;
   10.18 -            if (_ident->username)
   10.19 -                username = _ident->username;
   10.20 -            comm_type = (pEp_comm_type) _ident->comm_type;
   10.21 -            lang = _ident->lang;
   10.22 -        }
   10.23 -
   10.24 -        pEp_identity_cpp::pEp_identity_cpp(const pEp_identity_s *_ident)
   10.25 -            : me(false)
   10.26 -        {
   10.27 -            if (_ident->address)
   10.28 -                address = utf8_string(_ident->address);
   10.29 -            if (_ident->fpr)
   10.30 -                fpr = utf8_string(_ident->fpr);
   10.31 -            if (_ident->user_id)
   10.32 -                user_id = utf8_string(_ident->user_id);
   10.33 -            if (_ident->username)
   10.34 -                username = utf8_string(_ident->username);
   10.35 -            comm_type = _ident->comm_type;
   10.36 -            if (_ident->lang)
   10.37 -                lang = utf8_string(_ident->lang);
   10.38 -        }
   10.39 -
   10.40 -        pEp_identity * pEp_identity_cpp::to_pEp_identity()
   10.41 -        {
   10.42 -            ::pEp_identity *_ident = ::new_identity(this->address.c_str(), this->fpr.c_str(), this->user_id.c_str(), this->username.c_str());
   10.43 -            assert(_ident);
   10.44 -            if (_ident == NULL)
   10.45 -                throw bad_alloc();
   10.46 -
   10.47 -            _ident->comm_type = (::PEP_comm_type) this->comm_type;
   10.48 -            _ident->me = this->me;
   10.49 -
   10.50 -            assert(this->lang.size() == 0 || this->lang.size() == 2);
   10.51 -
   10.52 -            if (this->lang.size()) {
   10.53 -                _ident->lang[0] = this->lang[0];
   10.54 -                _ident->lang[1] = this->lang[1];
   10.55 -            }
   10.56 -
   10.57 -            return _ident;
   10.58 -        }
   10.59 -
   10.60 -        pEp_identity_s * pEp_identity_cpp::to_pEp_identity_s()
   10.61 -        {
   10.62 -            pEp_identity_s *_ident = (pEp_identity_s *) calloc(1, sizeof(pEp_identity_s));
   10.63 -            assert(_ident);
   10.64 -            if (_ident == NULL)
   10.65 -                throw bad_alloc();
   10.66 -
   10.67 -            _ident->address = utf16_bstr(this->address).Detach();
   10.68 -            _ident->comm_type = this->comm_type;
   10.69 -            _ident->fpr = utf16_bstr(this->fpr).Detach();
   10.70 -            _ident->lang = utf16_bstr(this->lang).Detach();
   10.71 -            _ident->username = utf16_bstr(this->username).Detach();
   10.72 -            _ident->user_id = utf16_bstr(this->user_id).Detach();
   10.73 -
   10.74 -            return _ident;
   10.75 -        }
   10.76 -
   10.77 -        void copy_identity(pEp_identity_s * ident_s, const pEp_identity * ident)
   10.78 -        {
   10.79 -            assert(ident_s);
   10.80 -
   10.81 -            ::memset(ident_s, 0, sizeof(pEp_identity_s));
   10.82 -            if (ident) {
   10.83 -                if (ident->address)
   10.84 -                    ident_s->address = utf16_bstr(ident->address).Detach();
   10.85 -                if (ident->fpr)
   10.86 -                    ident_s->fpr = utf16_bstr(ident->fpr).Detach();
   10.87 -                if (ident->user_id)
   10.88 -                    ident_s->user_id = utf16_bstr(ident->user_id).Detach();
   10.89 -                if (ident->username)
   10.90 -                    ident_s->username = utf16_bstr(ident->username).Detach();
   10.91 -                ident_s->comm_type = (pEp_comm_type) ident->comm_type;
   10.92 -                if (ident->lang)
   10.93 -                    ident_s->lang = utf16_bstr(ident->lang).Detach();
   10.94 -            }
   10.95 -        }
   10.96 -
   10.97 -        ::pEp_identity *new_identity(const pEp_identity_s * ident)
   10.98 -        {
   10.99 -            ::pEp_identity *_ident;
  10.100 -
  10.101 -            string _address;
  10.102 -            string _fpr;
  10.103 -            string _user_id;
  10.104 -            string _username;
  10.105 -
  10.106 -            if (ident->address)
  10.107 -                _address = utf8_string(ident->address);
  10.108 -            if (ident->fpr) {
  10.109 -                _fpr = utf8_string(ident->fpr);
  10.110 -                for (auto p = _fpr.begin(); p != _fpr.end(); ++p) {
  10.111 -                    if (*p >= 'A' && *p <= 'Z')
  10.112 -                        continue;
  10.113 -                    if (*p >= '0' && *p <= '9')
  10.114 -                        continue;
  10.115 -                    throw invalid_argument("invalid hex digits in fingerprint");
  10.116 -                }
  10.117 -            }
  10.118 -            if (ident->user_id)
  10.119 -                _user_id = utf8_string(ident->user_id);
  10.120 -            if (ident->username)
  10.121 -                _username = utf8_string(ident->username);
  10.122 -
  10.123 -            _ident = ::new_identity(_address.c_str(), _fpr.c_str(), _user_id.c_str(), _username.c_str());
  10.124 -            assert(_ident);
  10.125 -            if (_ident == NULL)
  10.126 -                throw bad_alloc();
  10.127 -
  10.128 -            _ident->comm_type = (PEP_comm_type) ident->comm_type;
  10.129 -
  10.130 -            if (ident->lang) {
  10.131 -                string _lang = utf8_string(ident->lang);
  10.132 -                if (_lang.length() != 0) {
  10.133 -                    if (_lang.length() != 2) {
  10.134 -                        ::free_identity(_ident);
  10.135 -                        throw invalid_argument("invalid language code");
  10.136 -                    }
  10.137 -                    if (_lang[0] < 'a' || _lang[0] > 'z') {
  10.138 -                        ::free_identity(_ident);
  10.139 -                        throw invalid_argument("invalid language code");
  10.140 -                    }
  10.141 -                    if (_lang[1] < 'a' || _lang[1] > 'z') {
  10.142 -                        ::free_identity(_ident);
  10.143 -                        throw invalid_argument("invalid language code");
  10.144 -                    }
  10.145 -                    _ident->lang[0] = _lang[0];
  10.146 -                    _ident->lang[1] = _lang[1];
  10.147 -                }
  10.148 -            }
  10.149 -
  10.150 -            return _ident;
  10.151 -        }
  10.152 -    }
  10.153 -}
    11.1 --- a/pEp_identity_helper.h	Sat May 30 19:36:36 2015 +0200
    11.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.3 @@ -1,82 +0,0 @@
    11.4 -#pragma once
    11.5 -
    11.6 -#include "stdafx.h"
    11.7 -#include "pEpComServerAdapter_i.h"
    11.8 -#include "utf8_helper.h"
    11.9 -
   11.10 -using namespace std;
   11.11 -
   11.12 -namespace pEp {
   11.13 -    namespace utility {
   11.14 -
   11.15 -        struct pEp_identity_cpp {
   11.16 -            string address;
   11.17 -            string fpr;
   11.18 -            string user_id;
   11.19 -            string username;
   11.20 -            pEp_comm_type comm_type;
   11.21 -            string lang;
   11.22 -            bool me;
   11.23 -
   11.24 -            pEp_identity_cpp(
   11.25 -                string _address = string(),
   11.26 -                string _fpr = string(),
   11.27 -                string _user_id = string(),
   11.28 -                string _username = string(),
   11.29 -                pEp_comm_type _comm_type = pEp_ct_unknown,
   11.30 -                string _lang = string()
   11.31 -                ) : address(_address), fpr(_fpr), user_id(_user_id), username(_username), comm_type(_comm_type), lang(_lang), me(false)
   11.32 -            { }
   11.33 -
   11.34 -            pEp_identity_cpp(const ::pEp_identity *_ident);
   11.35 -            pEp_identity_cpp(const pEp_identity_s *_ident);
   11.36 -
   11.37 -            pEp_identity * to_pEp_identity();
   11.38 -            pEp_identity_s * to_pEp_identity_s();
   11.39 -        };
   11.40 -
   11.41 -        void copy_identity(pEp_identity_s * ident_s, const pEp_identity * ident);
   11.42 -        ::pEp_identity *new_identity(const pEp_identity_s * ident);
   11.43 -
   11.44 -        template< class UDType > static IRecordInfo *getRecordInfo()
   11.45 -        {
   11.46 -            LPTYPEINFO pTypeInfo = NULL;
   11.47 -            LPTYPELIB pTypelib = NULL;
   11.48 -            LPSAFEARRAY psaUDType = NULL;
   11.49 -            IRecordInfo* pRecInfo = NULL;
   11.50 -
   11.51 -            // Fetch the IRecordInfo interface describing the UDT
   11.52 -            HRESULT hr = LoadRegTypeLib(LIBID_pEpCOMServerAdapterLib, 1, 0, GetUserDefaultLCID(), &pTypelib);
   11.53 -            assert(SUCCEEDED(hr) && pTypelib);
   11.54 -
   11.55 -            hr = pTypelib->GetTypeInfoOfGuid(__uuidof(UDType), &pTypeInfo);
   11.56 -            assert(SUCCEEDED(hr) && pTypeInfo);
   11.57 -            hr = GetRecordInfoFromTypeInfo(pTypeInfo, &pRecInfo);
   11.58 -            assert(SUCCEEDED(hr) && pRecInfo);
   11.59 -            pTypeInfo->Release();
   11.60 -            pTypelib->Release();
   11.61 -
   11.62 -            return pRecInfo;
   11.63 -        }
   11.64 -
   11.65 -        template< class UDType > LPSAFEARRAY newSafeArray(ULONG cElements)
   11.66 -        {
   11.67 -            IRecordInfo *pRecInfo = getRecordInfo< UDType >();
   11.68 -            SAFEARRAYBOUND rgbounds = { cElements, 0 };
   11.69 -            LPSAFEARRAY psaUDType = SafeArrayCreateEx(VT_RECORD, 1, &rgbounds, pRecInfo);
   11.70 -            pRecInfo->Release();
   11.71 -            assert(psaUDType);
   11.72 -
   11.73 -            return psaUDType;
   11.74 -        }
   11.75 -
   11.76 -        template< class UDType > UDType * accessData(LPSAFEARRAY psaUDType)
   11.77 -        {
   11.78 -            UDType *pUDTypeStruct = NULL;
   11.79 -            HRESULT hr = SafeArrayAccessData(psaUDType, reinterpret_cast<PVOID*>(&pUDTypeStruct));
   11.80 -            assert(SUCCEEDED(hr) && pUDTypeStruct);
   11.81 -
   11.82 -            return pUDTypeStruct;
   11.83 -        }
   11.84 -    }
   11.85 -}
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/pEp_utility.h	Sun May 31 13:25:37 2015 +0200
    12.3 @@ -0,0 +1,76 @@
    12.4 +#pragma once
    12.5 +
    12.6 +#include "stdafx.h"
    12.7 +#include "pEpComServerAdapter_i.h"
    12.8 +#include "utf8_helper.h"
    12.9 +
   12.10 +using namespace std;
   12.11 +
   12.12 +namespace pEp {
   12.13 +    namespace utility {
   12.14 +
   12.15 +        struct pEp_identity_cpp {
   12.16 +            string address;
   12.17 +            string fpr;
   12.18 +            string user_id;
   12.19 +            string username;
   12.20 +            pEp_comm_type comm_type;
   12.21 +            string lang;
   12.22 +            bool me;
   12.23 +
   12.24 +            pEp_identity_cpp(
   12.25 +                string _address = string(),
   12.26 +                string _fpr = string(),
   12.27 +                string _user_id = string(),
   12.28 +                string _username = string(),
   12.29 +                pEp_comm_type _comm_type = pEp_ct_unknown,
   12.30 +                string _lang = string()
   12.31 +                ) : address(_address), fpr(_fpr), user_id(_user_id), username(_username), comm_type(_comm_type), lang(_lang), me(false)
   12.32 +            { }
   12.33 +
   12.34 +            pEp_identity_cpp(const ::pEp_identity *_ident);
   12.35 +            pEp_identity_cpp(const pEp_identity_s *_ident);
   12.36 +
   12.37 +            pEp_identity * to_pEp_identity();
   12.38 +            pEp_identity_s * to_pEp_identity_s();
   12.39 +        };
   12.40 +
   12.41 +        void copy_identity(pEp_identity_s * ident_s, const pEp_identity * ident);
   12.42 +        ::pEp_identity *new_identity(const pEp_identity_s * ident);
   12.43 +
   12.44 +        template< class UDType > static IRecordInfo *getRecordInfo()
   12.45 +        {
   12.46 +            LPTYPEINFO pTypeInfo = NULL;
   12.47 +            LPTYPELIB pTypelib = NULL;
   12.48 +            LPSAFEARRAY psaUDType = NULL;
   12.49 +            IRecordInfo* pRecInfo = NULL;
   12.50 +
   12.51 +            // Fetch the IRecordInfo interface describing the UDT
   12.52 +            HRESULT hr = LoadRegTypeLib(LIBID_pEpCOMServerAdapterLib, 1, 0, GetUserDefaultLCID(), &pTypelib);
   12.53 +            assert(SUCCEEDED(hr) && pTypelib);
   12.54 +
   12.55 +            hr = pTypelib->GetTypeInfoOfGuid(__uuidof(UDType), &pTypeInfo);
   12.56 +            assert(SUCCEEDED(hr) && pTypeInfo);
   12.57 +            hr = GetRecordInfoFromTypeInfo(pTypeInfo, &pRecInfo);
   12.58 +            assert(SUCCEEDED(hr) && pRecInfo);
   12.59 +            pTypeInfo->Release();
   12.60 +            pTypelib->Release();
   12.61 +
   12.62 +            return pRecInfo;
   12.63 +        }
   12.64 +
   12.65 +        template< class UDType > LPSAFEARRAY newSafeArray(ULONG cElements)
   12.66 +        {
   12.67 +            IRecordInfo *pRecInfo = getRecordInfo< UDType >();
   12.68 +            SAFEARRAYBOUND rgbounds = { cElements, 0 };
   12.69 +            LPSAFEARRAY psaUDType = SafeArrayCreateEx(VT_RECORD, 1, &rgbounds, pRecInfo);
   12.70 +            pRecInfo->Release();
   12.71 +            assert(psaUDType);
   12.72 +
   12.73 +            return psaUDType;
   12.74 +        }
   12.75 +
   12.76 +        text_message *text_message_from_C(::message *msg);
   12.77 +        ::message * text_message_to_C(text_message *msg);
   12.78 +    }
   12.79 +}
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/pEp_utitlity.cpp	Sun May 31 13:25:37 2015 +0200
    13.3 @@ -0,0 +1,446 @@
    13.4 +#include "stdafx.h"
    13.5 +#include "pEp_utility.h"
    13.6 +
    13.7 +using namespace ATL;
    13.8 +
    13.9 +namespace pEp {
   13.10 +    namespace utility {
   13.11 +        pEp_identity_cpp::pEp_identity_cpp(const ::pEp_identity *_ident)
   13.12 +            : me(false)
   13.13 +        {
   13.14 +            if (_ident->address)
   13.15 +                address = _ident->address;
   13.16 +            if (_ident->fpr)
   13.17 +                fpr = _ident->fpr;
   13.18 +            if (_ident->user_id)
   13.19 +                user_id = _ident->user_id;
   13.20 +            if (_ident->username)
   13.21 +                username = _ident->username;
   13.22 +            comm_type = (pEp_comm_type) _ident->comm_type;
   13.23 +            lang = _ident->lang;
   13.24 +        }
   13.25 +
   13.26 +        pEp_identity_cpp::pEp_identity_cpp(const pEp_identity_s *_ident)
   13.27 +            : me(false)
   13.28 +        {
   13.29 +            if (_ident->address)
   13.30 +                address = utf8_string(_ident->address);
   13.31 +            if (_ident->fpr)
   13.32 +                fpr = utf8_string(_ident->fpr);
   13.33 +            if (_ident->user_id)
   13.34 +                user_id = utf8_string(_ident->user_id);
   13.35 +            if (_ident->username)
   13.36 +                username = utf8_string(_ident->username);
   13.37 +            comm_type = _ident->comm_type;
   13.38 +            if (_ident->lang)
   13.39 +                lang = utf8_string(_ident->lang);
   13.40 +        }
   13.41 +
   13.42 +        pEp_identity * pEp_identity_cpp::to_pEp_identity()
   13.43 +        {
   13.44 +            ::pEp_identity *_ident = ::new_identity(this->address.c_str(), this->fpr.c_str(), this->user_id.c_str(), this->username.c_str());
   13.45 +            assert(_ident);
   13.46 +            if (_ident == NULL)
   13.47 +                throw bad_alloc();
   13.48 +
   13.49 +            _ident->comm_type = (::PEP_comm_type) this->comm_type;
   13.50 +            _ident->me = this->me;
   13.51 +
   13.52 +            assert(this->lang.size() == 0 || this->lang.size() == 2);
   13.53 +
   13.54 +            if (this->lang.size()) {
   13.55 +                _ident->lang[0] = this->lang[0];
   13.56 +                _ident->lang[1] = this->lang[1];
   13.57 +            }
   13.58 +
   13.59 +            return _ident;
   13.60 +        }
   13.61 +
   13.62 +        pEp_identity_s * pEp_identity_cpp::to_pEp_identity_s()
   13.63 +        {
   13.64 +            pEp_identity_s *_ident = (pEp_identity_s *) calloc(1, sizeof(pEp_identity_s));
   13.65 +            assert(_ident);
   13.66 +            if (_ident == NULL)
   13.67 +                throw bad_alloc();
   13.68 +
   13.69 +            _ident->address = utf16_bstr(this->address).Detach();
   13.70 +            _ident->comm_type = this->comm_type;
   13.71 +            _ident->fpr = utf16_bstr(this->fpr).Detach();
   13.72 +            _ident->lang = utf16_bstr(this->lang).Detach();
   13.73 +            _ident->username = utf16_bstr(this->username).Detach();
   13.74 +            _ident->user_id = utf16_bstr(this->user_id).Detach();
   13.75 +
   13.76 +            return _ident;
   13.77 +        }
   13.78 +
   13.79 +        void copy_identity(pEp_identity_s * ident_s, const pEp_identity * ident)
   13.80 +        {
   13.81 +            assert(ident_s);
   13.82 +
   13.83 +            ::memset(ident_s, 0, sizeof(pEp_identity_s));
   13.84 +            if (ident) {
   13.85 +                if (ident->address)
   13.86 +                    ident_s->address = utf16_bstr(ident->address).Detach();
   13.87 +                if (ident->fpr)
   13.88 +                    ident_s->fpr = utf16_bstr(ident->fpr).Detach();
   13.89 +                if (ident->user_id)
   13.90 +                    ident_s->user_id = utf16_bstr(ident->user_id).Detach();
   13.91 +                if (ident->username)
   13.92 +                    ident_s->username = utf16_bstr(ident->username).Detach();
   13.93 +                ident_s->comm_type = (pEp_comm_type) ident->comm_type;
   13.94 +                if (ident->lang)
   13.95 +                    ident_s->lang = utf16_bstr(ident->lang).Detach();
   13.96 +            }
   13.97 +        }
   13.98 +
   13.99 +        ::pEp_identity *new_identity(const pEp_identity_s * ident)
  13.100 +        {
  13.101 +            ::pEp_identity *_ident;
  13.102 +
  13.103 +            string _address;
  13.104 +            string _fpr;
  13.105 +            string _user_id;
  13.106 +            string _username;
  13.107 +
  13.108 +            if (ident->address)
  13.109 +                _address = utf8_string(ident->address);
  13.110 +            if (ident->fpr) {
  13.111 +                _fpr = utf8_string(ident->fpr);
  13.112 +                for (auto p = _fpr.begin(); p != _fpr.end(); ++p) {
  13.113 +                    if (*p >= 'A' && *p <= 'Z')
  13.114 +                        continue;
  13.115 +                    if (*p >= '0' && *p <= '9')
  13.116 +                        continue;
  13.117 +                    throw invalid_argument("invalid hex digits in fingerprint");
  13.118 +                }
  13.119 +            }
  13.120 +            if (ident->user_id)
  13.121 +                _user_id = utf8_string(ident->user_id);
  13.122 +            if (ident->username)
  13.123 +                _username = utf8_string(ident->username);
  13.124 +
  13.125 +            _ident = ::new_identity(_address.c_str(), _fpr.c_str(), _user_id.c_str(), _username.c_str());
  13.126 +            assert(_ident);
  13.127 +            if (_ident == NULL)
  13.128 +                throw bad_alloc();
  13.129 +
  13.130 +            _ident->comm_type = (PEP_comm_type) ident->comm_type;
  13.131 +
  13.132 +            if (ident->lang) {
  13.133 +                string _lang = utf8_string(ident->lang);
  13.134 +                if (_lang.length() != 0) {
  13.135 +                    if (_lang.length() != 2) {
  13.136 +                        ::free_identity(_ident);
  13.137 +                        throw invalid_argument("invalid language code");
  13.138 +                    }
  13.139 +                    if (_lang[0] < 'a' || _lang[0] > 'z') {
  13.140 +                        ::free_identity(_ident);
  13.141 +                        throw invalid_argument("invalid language code");
  13.142 +                    }
  13.143 +                    if (_lang[1] < 'a' || _lang[1] > 'z') {
  13.144 +                        ::free_identity(_ident);
  13.145 +                        throw invalid_argument("invalid language code");
  13.146 +                    }
  13.147 +                    _ident->lang[0] = _lang[0];
  13.148 +                    _ident->lang[1] = _lang[1];
  13.149 +                }
  13.150 +            }
  13.151 +
  13.152 +            return _ident;
  13.153 +        }
  13.154 +
  13.155 +        template< class T2, class T > T2 from_C(T *tl);
  13.156 +
  13.157 +        template<> BSTR from_C< BSTR, char >(char *s)
  13.158 +        {
  13.159 +            if (s)
  13.160 +                return utf16_bstr(s).Detach();
  13.161 +            else
  13.162 +                return _bstr_t(L"").Detach();
  13.163 +        }
  13.164 +
  13.165 +        inline BSTR bstr(char *s)
  13.166 +        {
  13.167 +            return from_C< BSTR, char >(s);
  13.168 +        }
  13.169 +
  13.170 +        template<> blob *from_C< blob *, bloblist_t >(bloblist_t *tl)
  13.171 +        {
  13.172 +            assert(tl && tl->value);
  13.173 +
  13.174 +            CComSafeArray<BYTE> sa;
  13.175 +            sa.Create(tl->size);
  13.176 +
  13.177 +            memcpy(sa.m_psa->pvData, tl->value, tl->size);
  13.178 +
  13.179 +            blob *_blob = new blob();
  13.180 +
  13.181 +            _blob->value = sa.Detach();
  13.182 +            _blob->mime_type = bstr(tl->mime_type);
  13.183 +            _blob->filename = bstr(tl->filename);
  13.184 +
  13.185 +            return _blob;
  13.186 +        }
  13.187 +
  13.188 +        template< class T > int length(T *);
  13.189 +
  13.190 +        template< class T2, class T > SAFEARRAY * array_from_C(T *tl)
  13.191 +        {
  13.192 +            int len = length<T>(tl);
  13.193 +
  13.194 +            LPSAFEARRAY sa = newSafeArray<T2>(len);
  13.195 +            LONG lbound, ubound;
  13.196 +            SafeArrayGetLBound(sa, 1, &lbound);
  13.197 +            SafeArrayGetUBound(sa, 1, &ubound);
  13.198 +
  13.199 +            T *_tl = tl;
  13.200 +            for (LONG i = lbound; i <= ubound; _tl = tl->next, i++)
  13.201 +                SafeArrayPutElement(sa, &i, from_C<T2 *, T>(_tl));
  13.202 +
  13.203 +            return sa;
  13.204 +        }
  13.205 +
  13.206 +        template<> pEp_identity_s from_C< pEp_identity_s, pEp_identity >(pEp_identity *tl)
  13.207 +        {
  13.208 +            pEp_identity_s _ident;
  13.209 +            copy_identity(&_ident, tl);
  13.210 +            return _ident;
  13.211 +        }
  13.212 +
  13.213 +        pEp_identity_s identity_s(pEp_identity *ident)
  13.214 +        {
  13.215 +            return from_C< pEp_identity_s, pEp_identity >(ident);
  13.216 +        }
  13.217 +
  13.218 +        template<> pEp_identity_s *from_C< pEp_identity_s *, identity_list >(identity_list *il)
  13.219 +        {
  13.220 +            pEp_identity_s *ident = new pEp_identity_s();
  13.221 +            copy_identity(ident, il->ident);
  13.222 +            return ident;
  13.223 +        }
  13.224 +
  13.225 +        template<> opt_field *from_C< opt_field *, stringpair_list_t >(stringpair_list_t * sp)
  13.226 +        {
  13.227 +            opt_field *fld = new opt_field();
  13.228 +            fld->name = bstr(sp->value->key);
  13.229 +            fld->value = bstr(sp->value->value);
  13.230 +            return fld;
  13.231 +        }
  13.232 +
  13.233 +        template<> int length<identity_list>(identity_list *tl)
  13.234 +        {
  13.235 +            return identity_list_length(tl);
  13.236 +        }
  13.237 +
  13.238 +        template<> int length<bloblist_t>(bloblist_t *tl)
  13.239 +        {
  13.240 +            return bloblist_length(tl);
  13.241 +        }
  13.242 +
  13.243 +        template<> int length<stringpair_list_t>(stringpair_list_t *tl)
  13.244 +        {
  13.245 +            return stringpair_list_length(tl);
  13.246 +        }
  13.247 +
  13.248 +        text_message *text_message_from_C(::message *msg)
  13.249 +        {
  13.250 +            assert(msg);
  13.251 +
  13.252 +            text_message *msg2 = new text_message();
  13.253 +
  13.254 +            msg2->dir = (pEp_msg_direction) msg->dir;
  13.255 +            msg2->id = bstr(msg->id);
  13.256 +            msg2->shortmsg = bstr(msg->shortmsg);
  13.257 +            msg2->longmsg = bstr(msg->longmsg);
  13.258 +            msg2->longmsg_formatted = bstr(msg->longmsg_formatted);
  13.259 +            msg2->attachments = array_from_C<blob, bloblist_t>(msg->attachments);
  13.260 +            msg2->sent = mktime(msg->sent);
  13.261 +            msg2->recv = mktime(msg->recv);
  13.262 +            msg2->from = identity_s(msg->from);
  13.263 +            msg2->to = array_from_C<pEp_identity_s, identity_list>(msg->to);
  13.264 +            msg2->recv_by = identity_s(msg->recv_by);
  13.265 +            msg2->cc = array_from_C<pEp_identity_s, identity_list>(msg->cc);
  13.266 +            msg2->bcc = array_from_C<pEp_identity_s, identity_list>(msg->bcc);
  13.267 +            msg2->reply_to = array_from_C<pEp_identity_s, identity_list>(msg->reply_to);
  13.268 +            msg2->references = string_array(msg->references).Detach();
  13.269 +            msg2->keywords = string_array(msg->keywords).Detach();
  13.270 +            msg2->comments = bstr(msg->comments);
  13.271 +            msg2->opt_fields = array_from_C<opt_field, stringpair_list_t>(msg->opt_fields);
  13.272 +
  13.273 +            return msg2;
  13.274 +        }
  13.275 +
  13.276 +        char * str(_bstr_t s)
  13.277 +        {
  13.278 +            char *_s = _strdup(utf8_string(s).c_str());
  13.279 +            if (_s == NULL)
  13.280 +                throw bad_alloc();
  13.281 +
  13.282 +            return s;
  13.283 +        }
  13.284 +
  13.285 +        bloblist_t *bloblist(SAFEARRAY *sa)
  13.286 +        {
  13.287 +            LONG lbound, ubound;
  13.288 +            SafeArrayGetLBound(sa, 1, &lbound);
  13.289 +            SafeArrayGetUBound(sa, 1, &ubound);
  13.290 +
  13.291 +            size_t size = ubound - lbound + 1;
  13.292 +            if (size <= 0)
  13.293 +                return NULL;
  13.294 +
  13.295 +            bloblist_t *bl = new_bloblist(NULL, 0, NULL, NULL);
  13.296 +            if (bl == NULL)
  13.297 +                throw bad_alloc();
  13.298 +
  13.299 +            bloblist_t *_bl = bl;
  13.300 +            for (LONG i = lbound; i <= ubound; i++) {
  13.301 +                blob b;
  13.302 +                SafeArrayGetElement(sa, &i, &b);
  13.303 +
  13.304 +                char *buffer = (char *) malloc(size);
  13.305 +                if (buffer == NULL)
  13.306 +                    throw bad_alloc();
  13.307 +
  13.308 +                char *data;
  13.309 +
  13.310 +                SafeArrayAccessData(b.value, (void **) &data);
  13.311 +                memcpy(buffer, data, size);
  13.312 +                SafeArrayUnaccessData(sa);
  13.313 +
  13.314 +                _bl = bloblist_add(_bl, buffer, ubound - lbound + 1, str(b.mime_type), str(b.filename));
  13.315 +                if (_bl == NULL) {
  13.316 +                    IRecordInfo *ri = getRecordInfo<blob>();
  13.317 +                    ri->RecordClear(&b);
  13.318 +
  13.319 +                    free_bloblist(bl);
  13.320 +                    free(buffer);
  13.321 +                    throw bad_alloc();
  13.322 +                }
  13.323 +
  13.324 +                IRecordInfo *ri = getRecordInfo<blob>();
  13.325 +                ri->RecordClear(&b);
  13.326 +            }
  13.327 +
  13.328 +            return bl;
  13.329 +        }
  13.330 +
  13.331 +        identity_list *identities(SAFEARRAY * sa)
  13.332 +        {
  13.333 +            LONG lbound, ubound;
  13.334 +            SafeArrayGetLBound(sa, 1, &lbound);
  13.335 +            SafeArrayGetUBound(sa, 1, &ubound);
  13.336 +
  13.337 +            size_t size = ubound - lbound + 1;
  13.338 +            if (size <= 0)
  13.339 +                return NULL;
  13.340 +
  13.341 +            identity_list *il = new_identity_list(NULL);
  13.342 +
  13.343 +            identity_list *_il = il;
  13.344 +            for (LONG i = lbound; i <= ubound; i++) {
  13.345 +                pEp_identity_s s;
  13.346 +                SafeArrayGetElement(sa, &i, &s);
  13.347 +
  13.348 +                pEp_identity *ident;
  13.349 +                try {
  13.350 +                    ident = new_identity(&s);
  13.351 +                }
  13.352 +                catch (bad_alloc&) {
  13.353 +                    IRecordInfo *ri = getRecordInfo<pEp_identity_s>();
  13.354 +                    ri->RecordClear(&s);
  13.355 +
  13.356 +                    throw bad_alloc();
  13.357 +                }
  13.358 +
  13.359 +                IRecordInfo *ri = getRecordInfo<pEp_identity_s>();
  13.360 +                ri->RecordClear(&s);
  13.361 +
  13.362 +                _il = identity_list_add(_il, ident);
  13.363 +                if (_il == NULL) {
  13.364 +                    free_identity_list(il);
  13.365 +                    throw bad_alloc();
  13.366 +                }
  13.367 +            }
  13.368 +
  13.369 +            return il;
  13.370 +        }
  13.371 +
  13.372 +        stringpair_t *new_stringpair(opt_field *fld)
  13.373 +        {
  13.374 +            stringpair_t *pair = ::new_stringpair(str(fld->name), str(fld->value));
  13.375 +            if (pair == NULL)
  13.376 +                throw bad_alloc();
  13.377 +
  13.378 +            return pair;
  13.379 +        }
  13.380 +
  13.381 +        stringpair_list_t *stringpair_list(SAFEARRAY * sa)
  13.382 +        {
  13.383 +            LONG lbound, ubound;
  13.384 +            SafeArrayGetLBound(sa, 1, &lbound);
  13.385 +            SafeArrayGetUBound(sa, 1, &ubound);
  13.386 +
  13.387 +            size_t size = ubound - lbound + 1;
  13.388 +            if (size <= 0)
  13.389 +                return NULL;
  13.390 +
  13.391 +            stringpair_list_t *il = new_stringpair_list(NULL);
  13.392 +
  13.393 +            stringpair_list_t *_il = il;
  13.394 +            for (LONG i = lbound; i <= ubound; i++) {
  13.395 +                opt_field s;
  13.396 +                SafeArrayGetElement(sa, &i, &s);
  13.397 +
  13.398 +                stringpair_t *pair;
  13.399 +                try {
  13.400 +                    pair = new_stringpair(&s);
  13.401 +                }
  13.402 +                catch (bad_alloc&) {
  13.403 +                    IRecordInfo *ri = getRecordInfo<opt_field>();
  13.404 +                    ri->RecordClear(&s);
  13.405 +
  13.406 +                    throw bad_alloc();
  13.407 +                }
  13.408 +
  13.409 +                IRecordInfo *ri = getRecordInfo<opt_field>();
  13.410 +                ri->RecordClear(&s);
  13.411 +
  13.412 +                _il = stringpair_list_add(_il, pair);
  13.413 +                if (_il == NULL) {
  13.414 +                    free_stringpair_list(il);
  13.415 +                    throw bad_alloc();
  13.416 +                }
  13.417 +            }
  13.418 +
  13.419 +            return il;
  13.420 +        }
  13.421 +        
  13.422 +        ::message * text_message_to_C(text_message *msg)
  13.423 +        {
  13.424 +            assert(msg);
  13.425 +
  13.426 +            ::message * msg2 = new_message((PEP_msg_direction) msg->dir, NULL, NULL, NULL);
  13.427 +
  13.428 +            msg2->id = str(msg->id);
  13.429 +            msg2->shortmsg = str(msg->shortmsg);
  13.430 +            msg2->longmsg = str(msg->longmsg);
  13.431 +            msg2->longmsg_formatted = str(msg->longmsg_formatted);
  13.432 +            msg2->attachments = bloblist(msg->attachments);
  13.433 +            msg2->sent = new_timestamp(msg->sent);
  13.434 +            msg2->recv = new_timestamp(msg->recv);
  13.435 +            msg2->from = new_identity(&msg->from);
  13.436 +            msg2->to = identities(msg->to);
  13.437 +            msg2->recv_by = new_identity(&msg->recv_by);
  13.438 +            msg2->cc = identities(msg->cc);
  13.439 +            msg2->bcc = identities(msg->bcc);
  13.440 +            msg2->reply_to = identities(msg->reply_to);
  13.441 +            msg2->references = new_stringlist(msg->references);
  13.442 +            msg2->keywords = new_stringlist(msg->keywords);
  13.443 +            msg2->comments = str(msg->comments);
  13.444 +            msg2->opt_fields = stringpair_list(msg->opt_fields);
  13.445 +
  13.446 +            return msg2;
  13.447 +        }
  13.448 +    }
  13.449 +}
    14.1 --- a/utf8_helper.h	Sat May 30 19:36:36 2015 +0200
    14.2 +++ b/utf8_helper.h	Sun May 31 13:25:37 2015 +0200
    14.3 @@ -9,6 +9,5 @@
    14.4          _bstr_t utf16_bstr(std::string str);
    14.5          ATL::CComSafeArray<BSTR> string_array(const ::stringlist_t *stringlist);
    14.6          ::stringlist_t * new_stringlist(const SAFEARRAY * safearray);
    14.7 -
    14.8      }
    14.9  }