Merge / remove
authorVolker Birk <vb@pep.foundation>
Sat, 24 Feb 2018 21:04:09 +0100
changeset 2776d26da1671b3
parent 276 35af9f35a9af
parent 274 b4f390f0a123
child 278 ae41fbcb1fd6
Merge / remove
CpEpEngine.cpp
CpEpEngine.h
pEpCOMServerAdapter.idl
     1.1 --- a/CpEpEngine.cpp	Sat Feb 24 20:59:45 2018 +0100
     1.2 +++ b/CpEpEngine.cpp	Sat Feb 24 21:04:09 2018 +0100
     1.3 @@ -8,6 +8,10 @@
     1.4  using namespace pEp::utility;
     1.5  
     1.6  // CpEpEngine
     1.7 +
     1.8 +// the init_mutex protects our initialization and destruction
     1.9 +// against a running keysync thread, and it ensures that the
    1.10 +// keysync thread actually has finished before we're destructed.
    1.11  std::mutex CpEpEngine::init_mutex;
    1.12  
    1.13  STDMETHODIMP CpEpEngine::InterfaceSupportsErrorInfo(REFIID riid)
    1.14 @@ -15,7 +19,6 @@
    1.15      static const IID* const arr[] =
    1.16      {
    1.17          &IID_IpEpEngine,
    1.18 -        &IID_IpEpEngine2,
    1.19      };
    1.20  
    1.21      for (int i = 0; i < sizeof(arr) / sizeof(arr[0]); i++)
    1.22 @@ -548,12 +551,11 @@
    1.23      PEP_STATUS status = ::update_identity(get_session(), _ident);
    1.24  
    1.25      if (status == PEP_STATUS_OK) {
    1.26 -        assert(_ident->fpr); // Guaranteed not NULL, but possibly empty string.
    1.27          copy_identity(result, _ident);
    1.28          ::free_identity(_ident);
    1.29          return S_OK;
    1.30      }
    1.31 -    else if (status == PEP_GET_KEY_FAILED) {
    1.32 +    else if (status == PEP_GET_KEY_FAILED || status == PEP_KEY_NOT_FOUND) {
    1.33          if (_ident->fpr) {
    1.34              pEp_free(_ident->fpr);
    1.35              _ident->fpr = NULL;
    1.36 @@ -607,69 +609,50 @@
    1.37  
    1.38  STDMETHODIMP CpEpEngine::UndoLastMistrust()
    1.39  {
    1.40 -	PEP_STATUS status = ::undo_last_mistrust(get_session());
    1.41 +    PEP_STATUS status = ::undo_last_mistrust(get_session());
    1.42  
    1.43 -	if (status == PEP_CANNOT_FIND_IDENTITY)
    1.44 -		return FAIL(L"Cannot find identity!", status);
    1.45 +    if (status == PEP_CANNOT_FIND_IDENTITY)
    1.46 +        return FAIL(L"Cannot find identity!", status);
    1.47  
    1.48 -	if (status != ::PEP_STATUS_OK)
    1.49 -		return FAIL(L"cannot revoke compromized key", status);
    1.50 +    if (status != ::PEP_STATUS_OK)
    1.51 +        return FAIL(L"cannot revoke compromized key", status);
    1.52  
    1.53 -	return S_OK;
    1.54 +    return S_OK;
    1.55  }
    1.56  
    1.57 -STDMETHODIMP CpEpEngine::SetOwnKey(pEpIdentity * ident, BSTR fpr, struct pEpIdentity *result)
    1.58 +STDMETHODIMP CpEpEngine::IsPepUser(/* [in] */ struct pEpIdentity *ident, /* [retval][out] */ VARIANT_BOOL *ispEp) 
    1.59  {
    1.60 -	assert(ident);
    1.61 -	assert(result);
    1.62 -	assert(fpr);
    1.63 +    ::pEp_identity *_ident;
    1.64  
    1.65 -	if (!(ident && result))
    1.66 -		return E_INVALIDARG;
    1.67 +    assert(ident);
    1.68 +    if (!ident)
    1.69 +        return E_INVALIDARG;
    1.70  
    1.71 -	::pEp_identity *_ident;
    1.72 -	try {
    1.73 -		_ident = new_identity(ident);
    1.74 -	}
    1.75 -	catch (bad_alloc&) {
    1.76 -		return E_OUTOFMEMORY;
    1.77 -	}
    1.78 -	catch (exception& ex) {
    1.79 -		return FAIL(ex.what());
    1.80 -	}
    1.81 +    try {
    1.82 +        _ident = new_identity(ident);
    1.83 +    }
    1.84 +    catch (bad_alloc&) {
    1.85 +        return E_OUTOFMEMORY;
    1.86 +    }
    1.87 +    catch (exception& ex) {
    1.88 +        return FAIL(ex.what());;
    1.89 +    }
    1.90  
    1.91 -	assert(_ident);
    1.92 -	if (_ident == NULL)
    1.93 -		return E_OUTOFMEMORY;
    1.94 +    bool is_pep = FALSE;
    1.95 +    PEP_STATUS status = ::is_pep_user(get_session(), _ident, &is_pep);
    1.96  
    1.97 -	string _fpr = utf8_string(fpr);
    1.98 -	PEP_STATUS status = ::set_own_key(get_session(), _fpr.c_str(), _ident);
    1.99 +    *ispEp = is_pep;
   1.100  
   1.101 -	if (status == PEP_STATUS_OK) {
   1.102 -		assert(_ident->fpr); // Guaranteed not NULL, but possibly empty string.
   1.103 -		copy_identity(result, _ident);
   1.104 -		::free_identity(_ident);
   1.105 -		return S_OK;
   1.106 -	}
   1.107 -	else if (status == PEP_GET_KEY_FAILED) {
   1.108 -		if (_ident->fpr) {
   1.109 -			pEp_free(_ident->fpr);
   1.110 -			_ident->fpr = NULL;
   1.111 -		}
   1.112 -		copy_identity(result, _ident);
   1.113 -		result->Fpr = NULL;
   1.114 -		::free_identity(_ident);
   1.115 -		return S_OK;
   1.116 -	}
   1.117 -	else {
   1.118 -		::free_identity(_ident);
   1.119 -		if (status == PEP_OUT_OF_MEMORY)
   1.120 -			return E_OUTOFMEMORY;
   1.121 -		else
   1.122 -			return FAIL(L"UpdateIdentity", status);
   1.123 -	}
   1.124 +    if (status == PEP_CANNOT_FIND_PERSON)
   1.125 +        return FAIL(L"Cannot find identity!", status);
   1.126  
   1.127 -	return S_OK;
   1.128 +    if (status == PEP_ILLEGAL_VALUE)
   1.129 +        return E_INVALIDARG;
   1.130 +
   1.131 +    if (status != ::PEP_STATUS_OK)
   1.132 +        return FAIL(L"Engine is_pep_user returned error", status);
   1.133 +
   1.134 +    return S_OK;
   1.135  }
   1.136  
   1.137  STDMETHODIMP CpEpEngine::KeyResetTrust(struct pEpIdentity *ident)
   1.138 @@ -880,10 +863,10 @@
   1.139      if (status == ::PEP_OUT_OF_MEMORY)
   1.140          return E_OUTOFMEMORY;
   1.141  
   1.142 -    return E_FAIL;
   1.143 +    return MAKE_HRESULT(1, FACILITY_ITF, (0xFFFF & status));
   1.144  }
   1.145  
   1.146 -STDMETHODIMP CpEpEngine::EncryptMessage(TextMessage * src, TextMessage * dst, SAFEARRAY * extra, pEpEncryptFlags flags)
   1.147 +STDMETHODIMP CpEpEngine::EncryptMessage(TextMessage * src, TextMessage * dst, SAFEARRAY * extra, pEpEncryptFlags flags, pEpEncFormat encFormat)
   1.148  {
   1.149      assert(src);
   1.150      assert(dst);
   1.151 @@ -893,16 +876,19 @@
   1.152  
   1.153      ::message *_src = text_message_to_C(src);
   1.154  
   1.155 +    _PEP_enc_format _encFormat = (_PEP_enc_format)encFormat;
   1.156 +
   1.157      // COM-19: Initialize msg_dst to NULL, or we end up calling
   1.158      // free_message() below with a pointer to random garbage in
   1.159      // case of an error in encrypt_message().
   1.160      ::message *msg_dst = NULL;
   1.161      ::stringlist_t *_extra = new_stringlist(extra); // can cope with NULL
   1.162  
   1.163 -    // _PEP_enc_format is intentionally hardcoded to PEP_enc_PEP:
   1.164 -    // 2016-10-02 14:10 < fdik> schabi: actually, all adapters now must use PEP_enc_PEP
   1.165 +    // _PEP_enc_format used to be intentionally hardcoded to PEP_enc_PEP:
   1.166 +    // Since COM-74, this has been changed to an explicit parameter, to allow the engine to attach
   1.167 +    // the keys and headers to outgoing, unencrypted messages.
   1.168      PEP_encrypt_flags_t engineFlags = (PEP_encrypt_flags_t)flags;
   1.169 -    PEP_STATUS status = ::encrypt_message(get_session(), _src, _extra, &msg_dst, PEP_enc_PEP, engineFlags);
   1.170 +    PEP_STATUS status = ::encrypt_message(get_session(), _src, _extra, &msg_dst, _encFormat, engineFlags);
   1.171      ::free_stringlist(_extra);
   1.172  
   1.173      if (status == PEP_STATUS_OK)
   1.174 @@ -1212,12 +1198,12 @@
   1.175      keysync_abort_requested = false;
   1.176  
   1.177      // Init our keysync session
   1.178 -	{ // begin lock scope
   1.179 -		std::lock_guard<std::mutex> lock(init_mutex);
   1.180 -		PEP_STATUS status = ::init(&keysync_session);
   1.181 -		::register_sync_callbacks(keysync_session, (void*)this, messageToSend, notifyHandshake, inject_sync_msg, retrieve_next_sync_msg);
   1.182 -		assert(status == PEP_STATUS_OK);
   1.183 -	} // end lock scope
   1.184 +    { // begin lock scope
   1.185 +        std::lock_guard<std::mutex> lock(init_mutex);
   1.186 +        PEP_STATUS status = ::init(&keysync_session);
   1.187 +        ::register_sync_callbacks(keysync_session, (void*)this, messageToSend, notifyHandshake, inject_sync_msg, retrieve_next_sync_msg);
   1.188 +        assert(status == PEP_STATUS_OK);
   1.189 +    } // end lock scope
   1.190  
   1.191      attach_sync_session(get_session(), keysync_session);
   1.192  
   1.193 @@ -1250,21 +1236,12 @@
   1.194      self->client_last_signalled_polling_state = false;
   1.195      self->client_callbacks_on_sync_thread = static_cast<IpEpEngineCallbacks*>(vp);
   1.196  
   1.197 -    res = self->client_callbacks_on_sync_thread->QueryInterface(
   1.198 -        &self->client_callbacks2_on_sync_thread);
   1.199 -    if (res != S_OK)
   1.200 -        self->client_callbacks2_on_sync_thread = NULL;
   1.201 -
   1.202      ::do_sync_protocol(self->keysync_session, self);
   1.203  
   1.204      self->client_callbacks_on_sync_thread->Release();
   1.205  
   1.206      self->client_callbacks_on_sync_thread = NULL;
   1.207  
   1.208 -    if (self->client_callbacks2_on_sync_thread)
   1.209 -        self->client_callbacks2_on_sync_thread->Release();
   1.210 -    self->client_callbacks2_on_sync_thread = NULL;
   1.211 -
   1.212      CoUninitialize();
   1.213  }
   1.214  
   1.215 @@ -1298,7 +1275,7 @@
   1.216      ::detach_sync_session(get_session());
   1.217      ::unregister_sync_callbacks(keysync_session);
   1.218  
   1.219 -	std::lock_guard<std::mutex> releaselock(init_mutex);
   1.220 +    std::lock_guard<std::mutex> releaselock(init_mutex);
   1.221      release(keysync_session);
   1.222      keysync_session = NULL;
   1.223  }
   1.224 @@ -1341,17 +1318,17 @@
   1.225      CpEpEngine* me = (CpEpEngine*)management;
   1.226  
   1.227      if ((timeout && *timeout)
   1.228 -        && me->client_callbacks2_on_sync_thread
   1.229 +        && me->client_callbacks_on_sync_thread
   1.230          && me->client_last_signalled_polling_state == false)
   1.231      {
   1.232 -        me->client_callbacks2_on_sync_thread->NeedFastPolling(VARIANT_TRUE);
   1.233 +        me->client_callbacks_on_sync_thread->NeedFastPolling(VARIANT_TRUE);
   1.234          me->client_last_signalled_polling_state = true;
   1.235      }
   1.236      else if (!(timeout && *timeout)
   1.237 -        && me->client_callbacks2_on_sync_thread
   1.238 +        && me->client_callbacks_on_sync_thread
   1.239          && me->client_last_signalled_polling_state == true)
   1.240      {
   1.241 -        me->client_callbacks2_on_sync_thread->NeedFastPolling(VARIANT_FALSE);
   1.242 +        me->client_callbacks_on_sync_thread->NeedFastPolling(VARIANT_FALSE);
   1.243          me->client_last_signalled_polling_state = false;
   1.244      }
   1.245  
   1.246 @@ -1376,16 +1353,16 @@
   1.247              {
   1.248                  *timeout = 1; // Signal timeout
   1.249                  return NULL;
   1.250 -            } 
   1.251 -            else 
   1.252 +            }
   1.253 +            else
   1.254              {
   1.255                  std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now();
   1.256  
   1.257 -                if (now < end_time) 
   1.258 +                if (now < end_time)
   1.259                  {
   1.260                      *timeout = std::chrono::duration_cast<std::chrono::seconds>(end_time - now).count();
   1.261 -                } 
   1.262 -                else 
   1.263 +                }
   1.264 +                else
   1.265                  {
   1.266                      *timeout = 0;
   1.267                  }
   1.268 @@ -1572,7 +1549,7 @@
   1.269  
   1.270              if (res != S_OK)
   1.271  
   1.272 -            return PEP_STATUS_OK;
   1.273 +                return PEP_STATUS_OK;
   1.274          }
   1.275  
   1.276          ::log_event(me->keysync_session, "Reentrant notify_handshake call!", "pEp COM Adapter", NULL, NULL);
     2.1 --- a/CpEpEngine.h	Sat Feb 24 20:59:45 2018 +0100
     2.2 +++ b/CpEpEngine.h	Sat Feb 24 21:04:09 2018 +0100
     2.3 @@ -22,9 +22,9 @@
     2.4  
     2.5  class ATL_NO_VTABLE CpEpEngine :
     2.6      public CComObjectRootEx<CComObjectThreadModel>,
     2.7 -	public CComCoClass<CpEpEngine, &CLSID_pEpEngine>,
     2.8 -	public ISupportErrorInfo,
     2.9 -	public IpEpEngine2
    2.10 +    public CComCoClass<CpEpEngine, &CLSID_pEpEngine>,
    2.11 +    public ISupportErrorInfo,
    2.12 +    public IpEpEngine
    2.13  {
    2.14  
    2.15  protected:
    2.16 @@ -32,48 +32,61 @@
    2.17  
    2.18  public:
    2.19      CpEpEngine() : keymanagement_thread(NULL), identity_queue(NULL), verbose_mode(false)
    2.20 -	{
    2.21 -		std::lock_guard<std::mutex> lock(init_mutex);
    2.22 -		PEP_STATUS status = ::init(&m_session);
    2.23 -		assert(status == PEP_STATUS_OK);
    2.24 -
    2.25 -        ::register_examine_function(m_session, CpEpEngine::examine_identity, (void *)this);
    2.26 -        ::log_event(m_session, "Startup", "pEp COM Adapter", NULL, NULL);
    2.27 +    {
    2.28 +        // See FinalConstruct() below for most initialization work, and an
    2.29 +        // explanation why it had to be moved there...
    2.30      }
    2.31  
    2.32      ~CpEpEngine()
    2.33      {
    2.34          stop_keysync();
    2.35          StopKeyserverLookup();
    2.36 -        ::log_event(m_session, "Shutdown", "pEp COM Adapter", NULL, NULL);
    2.37 -		std::lock_guard<std::mutex> lock(init_mutex);
    2.38 -		::release(m_session);
    2.39 +        if (m_session) // may be zero when FinalConstruct failed to initialize the engine
    2.40 +        {
    2.41 +            ::log_event(m_session, "Shutdown", "pEp COM Adapter", NULL, NULL);
    2.42 +            std::lock_guard<std::mutex> lock(init_mutex);
    2.43 +            ::release(m_session);
    2.44 +        }
    2.45      }
    2.46  
    2.47 -DECLARE_REGISTRY_RESOURCEID(IDR_PEPENGINE)
    2.48 +    DECLARE_REGISTRY_RESOURCEID(IDR_PEPENGINE)
    2.49  
    2.50 -DECLARE_NOT_AGGREGATABLE(CpEpEngine)
    2.51 +    DECLARE_NOT_AGGREGATABLE(CpEpEngine)
    2.52  
    2.53 -BEGIN_COM_MAP(CpEpEngine)
    2.54 -    COM_INTERFACE_ENTRY(IpEpEngine)
    2.55 -    COM_INTERFACE_ENTRY(IpEpEngine2)
    2.56 -    COM_INTERFACE_ENTRY(ISupportErrorInfo)
    2.57 -END_COM_MAP()
    2.58 +    BEGIN_COM_MAP(CpEpEngine)
    2.59 +        COM_INTERFACE_ENTRY(IpEpEngine)
    2.60 +        COM_INTERFACE_ENTRY(ISupportErrorInfo)
    2.61 +    END_COM_MAP()
    2.62  
    2.63 -// ISupportsErrorInfo
    2.64 -	STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);
    2.65 +    // ISupportsErrorInfo
    2.66 +    STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);
    2.67  
    2.68 +    DECLARE_PROTECT_FINAL_CONSTRUCT()
    2.69  
    2.70 -	DECLARE_PROTECT_FINAL_CONSTRUCT()
    2.71 +    // Unfortunately, neither FAIL nor error() work in the constructor, as 
    2.72 +    // CreateErrorInfo/SetErrorInfo cannot work when the instance is not constructed.
    2.73 +    // AtlThrow works, but the exception is caught in CComCreator.CreateInstance, and
    2.74 +    // unconditionally turned into E_OUTOFMEMORY. Thus, we need to do most constructor
    2.75 +    // work in FinalConstruct. CreateErrorInfo/SetErrorInfo still won't work, but at least,
    2.76 +    // we can return a meaningful HRESULT. Thus, we pack our PEP_STATUS into a custom HRESULT.	
    2.77 +    HRESULT FinalConstruct()
    2.78 +    {
    2.79 +        std::lock_guard<std::mutex> lock(init_mutex);
    2.80 +        PEP_STATUS status = ::init(&m_session);
    2.81 +        assert(status == PEP_STATUS_OK);
    2.82 +        if (status != PEP_STATUS_OK) {
    2.83 +            HRESULT res = MAKE_HRESULT(1, FACILITY_ITF, (0xFFFF & status));
    2.84 +            return res;
    2.85 +        }
    2.86  
    2.87 -	HRESULT FinalConstruct()
    2.88 -	{
    2.89 -		return S_OK;
    2.90 -	}
    2.91 +        ::register_examine_function(m_session, CpEpEngine::examine_identity, (void *)this);
    2.92 +        ::log_event(m_session, "Startup", "pEp COM Adapter", NULL, NULL);
    2.93 +        return S_OK;
    2.94 +    }
    2.95  
    2.96 -	void FinalRelease()
    2.97 -	{
    2.98 -	}
    2.99 +    void FinalRelease()
   2.100 +    {
   2.101 +    }
   2.102  
   2.103  
   2.104  protected:
   2.105 @@ -131,19 +144,18 @@
   2.106      bool verbose_mode;
   2.107  
   2.108  
   2.109 -	IpEpEngineCallbacks* client_callbacks = NULL;
   2.110 +    IpEpEngineCallbacks* client_callbacks = NULL;
   2.111      IpEpEngineCallbacks* client_callbacks_on_sync_thread = NULL;
   2.112 -    IpEpEngineCallbacks2* client_callbacks2_on_sync_thread = NULL;
   2.113      bool client_last_signalled_polling_state = true;
   2.114  
   2.115 -	// Keysync members
   2.116 +    // Keysync members
   2.117      static int inject_sync_msg(void *msg, void* management);
   2.118      static void* retrieve_next_sync_msg(void* management, time_t *timeout);
   2.119      void start_keysync();
   2.120      static void do_keysync_in_thread(CpEpEngine* self, LPSTREAM marshaled_callbacks);
   2.121      void stop_keysync();
   2.122  
   2.123 -	static std::mutex init_mutex;
   2.124 +    static std::mutex init_mutex;
   2.125  
   2.126      std::recursive_mutex keysync_mutex;
   2.127      std::condition_variable_any keysync_condition;
   2.128 @@ -191,8 +203,8 @@
   2.129      STDMETHOD(GetCrashdumpLog)(LONG maxlines, BSTR * log);
   2.130      STDMETHOD(GetEngineVersion)(BSTR * engineVersion);
   2.131      STDMETHOD(GetLanguageList)(BSTR * languages);
   2.132 -	STDMETHOD(SetIdentityFlags)(struct pEpIdentity *identity, pEpIdentityFlags flags);
   2.133 -	STDMETHOD(UnsetIdentityFlags)(struct pEpIdentity *identity, pEpIdentityFlags flags);
   2.134 +    STDMETHOD(SetIdentityFlags)(struct pEpIdentity *identity, pEpIdentityFlags flags);
   2.135 +    STDMETHOD(UnsetIdentityFlags)(struct pEpIdentity *identity, pEpIdentityFlags flags);
   2.136  
   2.137      // keymanagement API
   2.138  
   2.139 @@ -204,7 +216,13 @@
   2.140      STDMETHOD(KeyMistrusted)(struct pEpIdentity *ident);
   2.141      STDMETHOD(KeyResetTrust)(struct pEpIdentity *ident);
   2.142      STDMETHOD(TrustPersonalKey)(struct pEpIdentity *ident, struct pEpIdentity *result);
   2.143 -	STDMETHOD(OwnIdentitiesRetrieve)(LPSAFEARRAY* ownIdentities);
   2.144 +    STDMETHOD(OwnIdentitiesRetrieve)(LPSAFEARRAY* ownIdentities);
   2.145 +
   2.146 +    STDMETHOD(UndoLastMistrust)(); 
   2.147 +    
   2.148 +    STDMETHOD(IsPepUser)(
   2.149 +        /* [in] */ struct pEpIdentity *ident,
   2.150 +        /* [retval][out] */ VARIANT_BOOL *ispEp);
   2.151  
   2.152      // Blacklist API
   2.153  
   2.154 @@ -215,34 +233,38 @@
   2.155  
   2.156      // Message API
   2.157  
   2.158 -    STDMETHOD(EncryptMessage)(TextMessage * src, TextMessage * dst, SAFEARRAY * extra, pEpEncryptFlags flags);
   2.159 +    STDMETHOD(EncryptMessage)(
   2.160 +        /* [in] */ struct TextMessage *src,
   2.161 +        /* [out] */ struct TextMessage *dst,
   2.162 +        /* [in] */ SAFEARRAY * extra,
   2.163 +        /* [defaultvalue][in] */ pEpEncryptFlags flags = pEpEncryptFlagDefault,
   2.164 +        /* [defaultvalue][in] */ pEpEncFormat encFormat = pEpEncPep);
   2.165 +
   2.166      STDMETHOD(DecryptMessage)(TextMessage * src, TextMessage * dst, SAFEARRAY ** keylist, pEpDecryptFlags* flags, pEpRating *rating);
   2.167      STDMETHOD(ReEvaluateMessageRating)(TextMessage * msg, SAFEARRAY * x_KeyList, pEpRating x_EncStatus, pEpRating *rating);
   2.168      STDMETHOD(OutgoingMessageRating)(TextMessage *msg, pEpRating * pVal);
   2.169      STDMETHOD(IdentityRating)(pEpIdentity * ident, pEpRating * pVal);
   2.170 -	STDMETHOD(ColorFromRating)(pEpRating rating, pEpColor * pVal);
   2.171 +    STDMETHOD(ColorFromRating)(pEpRating rating, pEpColor * pVal);
   2.172  
   2.173      STDMETHOD(EncryptMessageForSelf)(
   2.174 -        pEpIdentity * targetId, 
   2.175 +        pEpIdentity * targetId,
   2.176          TextMessage* src,
   2.177          TextMessage *dst,
   2.178          pEpEncryptFlags flags
   2.179          );
   2.180  
   2.181 -	// Event callbacks
   2.182 +    // Event callbacks
   2.183  
   2.184 -	STDMETHOD(RegisterCallbacks)(IpEpEngineCallbacks *new_callback);
   2.185 -	STDMETHOD(UnregisterCallbacks)();
   2.186 +    STDMETHOD(RegisterCallbacks)(IpEpEngineCallbacks *new_callback);
   2.187 +    STDMETHOD(UnregisterCallbacks)();
   2.188  
   2.189      // PGP compatibility functions
   2.190      STDMETHOD(OpenPGPListKeyinfo)(BSTR search_pattern, LPSAFEARRAY* keyinfo_list);
   2.191  
   2.192 -	STDMETHOD(UndoLastMistrust)();
   2.193 -	STDMETHOD(SetOwnKey)(pEpIdentity * ident, BSTR fpr, struct pEpIdentity *result);
   2.194  
   2.195  protected:
   2.196 -	HRESULT Fire_MessageToSend(
   2.197 -		/* [in] */ struct TextMessage *msg);
   2.198 +    HRESULT Fire_MessageToSend(
   2.199 +        /* [in] */ struct TextMessage *msg);
   2.200  };
   2.201  
   2.202  OBJECT_ENTRY_AUTO(__uuidof(pEpEngine), CpEpEngine)
     3.1 --- a/GateKeeper.cpp	Sat Feb 24 20:59:45 2018 +0100
     3.2 +++ b/GateKeeper.cpp	Sat Feb 24 21:04:09 2018 +0100
     3.3 @@ -18,7 +18,7 @@
     3.4      _Out_ BYTE       *pbDest,
     3.5      _In_  BYTE const *pbSource,
     3.6      _In_  DWORD       cb
     3.7 -    )
     3.8 +)
     3.9  {
    3.10      for (DWORD i = 0; i < cb; i++) {
    3.11          pbDest[cb - 1 - i] = pbSource[i];
    3.12 @@ -29,7 +29,7 @@
    3.13      _In_ BCRYPT_ALG_HANDLE  hAlg,    // CNG provider
    3.14      _In_ PUBLIC_KEY_VALUES *pKey,    // Pointer to the RSAPUBKEY blob.
    3.15      _In_ BCRYPT_KEY_HANDLE *phKey    // Receives a handle the imported public key.
    3.16 -    )
    3.17 +)
    3.18  {
    3.19      NTSTATUS hr = 0;
    3.20  
    3.21 @@ -62,14 +62,14 @@
    3.22  
    3.23      cbKey += cbExp;
    3.24  
    3.25 -    pbPublicKey = (PBYTE) CoTaskMemAlloc(cbKey);
    3.26 +    pbPublicKey = (PBYTE)CoTaskMemAlloc(cbKey);
    3.27      if (pbPublicKey == NULL) {
    3.28          hr = E_OUTOFMEMORY;
    3.29          goto cleanup;
    3.30      }
    3.31  
    3.32      ZeroMemory(pbPublicKey, cbKey);
    3.33 -    pRsaBlob = (BCRYPT_RSAKEY_BLOB *) (pbPublicKey);
    3.34 +    pRsaBlob = (BCRYPT_RSAKEY_BLOB *)(pbPublicKey);
    3.35  
    3.36      //
    3.37      // Make the Public Key Blob Header
    3.38 @@ -82,13 +82,13 @@
    3.39      pRsaBlob->cbPrime1 = 0;
    3.40      pRsaBlob->cbPrime2 = 0;
    3.41  
    3.42 -    pbCurrent = (PBYTE) (pRsaBlob + 1);
    3.43 +    pbCurrent = (PBYTE)(pRsaBlob + 1);
    3.44  
    3.45      //
    3.46      // Copy pubExp Big Endian 
    3.47      //
    3.48  
    3.49 -    ReverseMemCopy(pbCurrent, (PBYTE) &dwExp, cbExp);
    3.50 +    ReverseMemCopy(pbCurrent, (PBYTE)&dwExp, cbExp);
    3.51      pbCurrent += cbExp;
    3.52  
    3.53      //
    3.54 @@ -101,7 +101,7 @@
    3.55      // Import the public key
    3.56      //
    3.57  
    3.58 -    hr = BCryptImportKeyPair(hAlg, NULL, BCRYPT_RSAPUBLIC_BLOB, phKey, (PUCHAR) pbPublicKey, cbKey, 0);
    3.59 +    hr = BCryptImportKeyPair(hAlg, NULL, BCRYPT_RSAPUBLIC_BLOB, phKey, (PUCHAR)pbPublicKey, cbKey, 0);
    3.60  
    3.61  cleanup:
    3.62      CoTaskMemFree(pbPublicKey);
    3.63 @@ -120,9 +120,9 @@
    3.64  
    3.65      GateKeeper::GateKeeper(CpEpCOMServerAdapterModule * self)
    3.66          : _self(self), now(time(NULL)), next(now /*+ time_diff()*/), hkUpdater(NULL),
    3.67 -            internet(NULL), hAES(NULL), hRSA(NULL)
    3.68 +        internet(NULL), hAES(NULL), hRSA(NULL)
    3.69      {
    3.70 -		DeleteFile(get_lockFile().c_str());
    3.71 +        DeleteFile(get_lockFile().c_str());
    3.72  
    3.73          LONG lResult = RegOpenCurrentUser(KEY_READ, &cu);
    3.74          assert(lResult == ERROR_SUCCESS);
    3.75 @@ -133,11 +133,11 @@
    3.76  
    3.77          if (cu_open) {
    3.78              LONG lResult = RegOpenKeyEx(cu, updater_reg_path, 0, KEY_READ, &hkUpdater);
    3.79 -			if (lResult != ERROR_SUCCESS)
    3.80 -				RegCreateKeyEx(cu, updater_reg_path, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_READ, NULL, &hkUpdater, NULL);
    3.81 -		}
    3.82 +            if (lResult != ERROR_SUCCESS)
    3.83 +                RegCreateKeyEx(cu, updater_reg_path, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_READ, NULL, &hkUpdater, NULL);
    3.84 +        }
    3.85      }
    3.86 -    
    3.87 +
    3.88      GateKeeper::~GateKeeper()
    3.89      {
    3.90          if (cu_open) {
    3.91 @@ -153,7 +153,7 @@
    3.92              static random_device rd;
    3.93              static mt19937 gen(rd());
    3.94  
    3.95 -            uniform_int_distribution<time_t> dist(0, cycle/fraction);
    3.96 +            uniform_int_distribution<time_t> dist(0, cycle / fraction);
    3.97  
    3.98              return dist(gen);
    3.99          }
   3.100 @@ -185,14 +185,14 @@
   3.101  
   3.102      void GateKeeper::keep_plugin()
   3.103      {
   3.104 -		HKEY hkPluginStart = NULL;
   3.105 +        HKEY hkPluginStart = NULL;
   3.106  
   3.107          LONG lResult = RegOpenKeyEx(cu, plugin_reg_path, 0, KEY_WRITE, &hkPluginStart);
   3.108          if (lResult != ERROR_SUCCESS)
   3.109              return;
   3.110  
   3.111          DWORD v = 3;
   3.112 -        lResult = RegSetValueEx(hkPluginStart, plugin_reg_value_name, 0, REG_DWORD, (const BYTE *) &v, sizeof(DWORD));
   3.113 +        lResult = RegSetValueEx(hkPluginStart, plugin_reg_value_name, 0, REG_DWORD, (const BYTE *)&v, sizeof(DWORD));
   3.114          assert(lResult == ERROR_SUCCESS);
   3.115  
   3.116          RegCloseKey(hkPluginStart);
   3.117 @@ -230,11 +230,11 @@
   3.118          uniform_int_distribution<int64_t> dist(0, UINT32_MAX);
   3.119  
   3.120          for (int i = 0; i < 8; i++)
   3.121 -            key.dw_key[i] = (uint32_t) dist(gen);
   3.122 +            key.dw_key[i] = (uint32_t)dist(gen);
   3.123  
   3.124          BCRYPT_KEY_HANDLE hKey;
   3.125  
   3.126 -        NTSTATUS status = BCryptGenerateSymmetricKey(hAES, &hKey, NULL, 0, (PUCHAR) &key, (ULONG) sizeof(aeskey_t), 0);
   3.127 +        NTSTATUS status = BCryptGenerateSymmetricKey(hAES, &hKey, NULL, 0, (PUCHAR)&key, (ULONG) sizeof(aeskey_t), 0);
   3.128          assert(status == 0);
   3.129          if (status)
   3.130              throw runtime_error("BCryptGenerateSymmetricKey");
   3.131 @@ -242,7 +242,7 @@
   3.132  #ifndef NDEBUG
   3.133          DWORD keylength = 0;
   3.134          ULONG copied = 0;
   3.135 -        status = BCryptGetProperty(hKey, BCRYPT_KEY_LENGTH, (PUCHAR) &keylength, sizeof(DWORD), &copied, 0);
   3.136 +        status = BCryptGetProperty(hKey, BCRYPT_KEY_LENGTH, (PUCHAR)&keylength, sizeof(DWORD), &copied, 0);
   3.137          assert(keylength == 256);
   3.138  #endif
   3.139  
   3.140 @@ -260,7 +260,7 @@
   3.141          DWORD uk_size;
   3.142  
   3.143          BOOL bResult = CryptDecodeObjectEx(X509_ASN_ENCODING, X509_PUBLIC_KEY_INFO,
   3.144 -                (const BYTE *) _update_key.data(), _update_key.size(), CRYPT_DECODE_ALLOC_FLAG, NULL, &uk, &uk_size);
   3.145 +            (const BYTE *)_update_key.data(), _update_key.size(), CRYPT_DECODE_ALLOC_FLAG, NULL, &uk, &uk_size);
   3.146          if (!bResult)
   3.147              throw runtime_error("CryptDecodeObjectEx: X509_PUBLIC_KEY_INFO");
   3.148  
   3.149 @@ -281,8 +281,8 @@
   3.150          ULONG psize;
   3.151          NTSTATUS status = BCryptGetProperty(hUpdateKey, BCRYPT_ALGORITHM_NAME, NULL, 0, &psize, 0);
   3.152          char *prop = new char[psize];
   3.153 -        TCHAR *_prop = (TCHAR *) prop;
   3.154 -        BCryptGetProperty(hUpdateKey, BCRYPT_ALGORITHM_NAME, (PUCHAR) prop, psize, &psize, 0);
   3.155 +        TCHAR *_prop = (TCHAR *)prop;
   3.156 +        BCryptGetProperty(hUpdateKey, BCRYPT_ALGORITHM_NAME, (PUCHAR)prop, psize, &psize, 0);
   3.157  
   3.158          ULONG export_size;
   3.159          status = BCryptExportKey(hDeliveryKey, NULL, BCRYPT_KEY_DATA_BLOB, NULL, NULL,
   3.160 @@ -293,7 +293,7 @@
   3.161          PUCHAR _delivery_key = new UCHAR[export_size];
   3.162          ULONG copied;
   3.163          status = BCryptExportKey(hDeliveryKey, NULL, BCRYPT_KEY_DATA_BLOB, _delivery_key, export_size,
   3.164 -                &copied, 0);
   3.165 +            &copied, 0);
   3.166          if (status) {
   3.167              delete[] _delivery_key;
   3.168              throw runtime_error("BCryptExportKey: delivery_key");
   3.169 @@ -328,7 +328,7 @@
   3.170          stringstream s;
   3.171          for (ULONG i = 0; i < copied; i++) {
   3.172              s << hex << setw(2) << setfill('0');
   3.173 -            s << (int) _result[i];
   3.174 +            s << (int)_result[i];
   3.175          }
   3.176          delete[] _result;
   3.177          s >> result;
   3.178 @@ -350,7 +350,7 @@
   3.179          for (DWORD i = 0; lResult == ERROR_SUCCESS; i++) {
   3.180              value_name_size = 16383;
   3.181              value_size = L_MAX_URL_LENGTH + 1;
   3.182 -            lResult = RegEnumValue(hkUpdater, i, value_name, &value_name_size, NULL, NULL, (LPBYTE) value, &value_size);
   3.183 +            lResult = RegEnumValue(hkUpdater, i, value_name, &value_name_size, NULL, NULL, (LPBYTE)value, &value_size);
   3.184              if (lResult == ERROR_SUCCESS) {
   3.185                  products.push_back({ value_name, value });
   3.186              }
   3.187 @@ -361,43 +361,43 @@
   3.188  
   3.189      void GateKeeper::install_msi(tstring filename)
   3.190      {
   3.191 -		HANDLE hMutex = CreateMutex(NULL, TRUE, _T("PEPINSTALLERMUTEX"));
   3.192 -		if (hMutex) {
   3.193 -			CloseHandle(hMutex);
   3.194 -			ShellExecute(NULL, _T("open"), filename.c_str(), NULL, NULL, SW_SHOW);
   3.195 -		}
   3.196 +        HANDLE hMutex = CreateMutex(NULL, TRUE, _T("PEPINSTALLERMUTEX"));
   3.197 +        if (hMutex) {
   3.198 +            CloseHandle(hMutex);
   3.199 +            ShellExecute(NULL, _T("open"), filename.c_str(), NULL, NULL, SW_SHOW);
   3.200 +        }
   3.201      }
   3.202  
   3.203 -	tstring GateKeeper::get_lockFile()
   3.204 -	{
   3.205 -		static const tstring _fileName = _T("\\pEpSetup.lck");
   3.206 -		static tstring fileName;
   3.207 +    tstring GateKeeper::get_lockFile()
   3.208 +    {
   3.209 +        static const tstring _fileName = _T("\\pEpSetup.lck");
   3.210 +        static tstring fileName;
   3.211  
   3.212 -		if (fileName.length() == 0) {
   3.213 -			unique_ptr < TCHAR[] > _pathName(new TCHAR[MAX_PATH + 1]);
   3.214 -			DWORD size = GetTempPath(MAX_PATH, _pathName.get());
   3.215 -			if (size > MAX_PATH - _fileName.size())
   3.216 -				throw runtime_error("TEMP path too long");
   3.217 +        if (fileName.length() == 0) {
   3.218 +            unique_ptr < TCHAR[] > _pathName(new TCHAR[MAX_PATH + 1]);
   3.219 +            DWORD size = GetTempPath(MAX_PATH, _pathName.get());
   3.220 +            if (size > MAX_PATH - _fileName.size())
   3.221 +                throw runtime_error("TEMP path too long");
   3.222  
   3.223 -			fileName = _pathName.get();
   3.224 -			fileName += _fileName;
   3.225 -		}
   3.226 +            fileName = _pathName.get();
   3.227 +            fileName += _fileName;
   3.228 +        }
   3.229  
   3.230 -		return fileName;
   3.231 -	}
   3.232 +        return fileName;
   3.233 +    }
   3.234  
   3.235      void GateKeeper::update_product(product p, DWORD context)
   3.236      {
   3.237 -		{
   3.238 -			HANDLE file = CreateFile(get_lockFile().c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
   3.239 -			if (file == INVALID_HANDLE_VALUE) {
   3.240 -				return;
   3.241 -			}
   3.242 -			else {
   3.243 -				CloseHandle(file);
   3.244 -				DeleteFile(get_lockFile().c_str());
   3.245 -			}
   3.246 -		}
   3.247 +        {
   3.248 +            HANDLE file = CreateFile(get_lockFile().c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
   3.249 +            if (file == INVALID_HANDLE_VALUE) {
   3.250 +                return;
   3.251 +            }
   3.252 +            else {
   3.253 +                CloseHandle(file);
   3.254 +                DeleteFile(get_lockFile().c_str());
   3.255 +            }
   3.256 +        }
   3.257  
   3.258          BCRYPT_KEY_HANDLE dk = delivery_key();
   3.259  #ifdef UNICODE
   3.260 @@ -410,7 +410,7 @@
   3.261          url += delivery;
   3.262          tstring headers;
   3.263          HINTERNET hUrl = InternetOpenUrl(internet, url.c_str(), headers.c_str(), headers.length(),
   3.264 -                INTERNET_FLAG_EXISTING_CONNECT | INTERNET_FLAG_NO_UI | INTERNET_FLAG_SECURE, context);
   3.265 +            INTERNET_FLAG_EXISTING_CONNECT | INTERNET_FLAG_NO_UI | INTERNET_FLAG_SECURE, context);
   3.266          if (hUrl == NULL)
   3.267              return;
   3.268  
   3.269 @@ -428,8 +428,8 @@
   3.270              InternetReadFile(hUrl, iv, sizeof(iv), &reading);
   3.271  
   3.272              if (reading) do {
   3.273 -                static char buffer[1024*1024];
   3.274 -                BOOL bResult = InternetReadFile(hUrl, buffer, 1024*1024, &reading);
   3.275 +                static char buffer[1024 * 1024];
   3.276 +                BOOL bResult = InternetReadFile(hUrl, buffer, 1024 * 1024, &reading);
   3.277                  if (!bResult || !reading)
   3.278                      break;
   3.279                  crypted += string(buffer, reading);
   3.280 @@ -452,18 +452,18 @@
   3.281          authInfo.cbTag = sizeof(tag);
   3.282  
   3.283          ULONG unencrypted_size;
   3.284 -        NTSTATUS status = BCryptDecrypt(dk, (PUCHAR) crypted.data(), crypted.size(),
   3.285 -                &authInfo, iv, sizeof(iv), NULL, 0, &unencrypted_size, 0);
   3.286 +        NTSTATUS status = BCryptDecrypt(dk, (PUCHAR)crypted.data(), crypted.size(),
   3.287 +            &authInfo, iv, sizeof(iv), NULL, 0, &unencrypted_size, 0);
   3.288          if (status)
   3.289              goto closing;
   3.290 -        
   3.291 +
   3.292          unencrypted_buffer = new char[unencrypted_size];
   3.293 -        PUCHAR crypted_data = (PUCHAR) crypted.data();
   3.294 -        ULONG crypted_size = (ULONG) crypted.size() - sizeof(tag);
   3.295 +        PUCHAR crypted_data = (PUCHAR)crypted.data();
   3.296 +        ULONG crypted_size = (ULONG)crypted.size() - sizeof(tag);
   3.297          memcpy(tag, crypted_data + crypted_size, sizeof(tag));
   3.298  
   3.299          status = BCryptDecrypt(dk, crypted_data, crypted_size,
   3.300 -            &authInfo, iv, sizeof(iv), (PUCHAR) unencrypted_buffer, unencrypted_size, &unencrypted_size, 0);
   3.301 +            &authInfo, iv, sizeof(iv), (PUCHAR)unencrypted_buffer, unencrypted_size, &unencrypted_size, 0);
   3.302          if (status)
   3.303              goto closing;
   3.304  
   3.305 @@ -503,7 +503,7 @@
   3.306          assert(status == 0);
   3.307          if (status)
   3.308              goto closing;
   3.309 -        status = BCryptSetProperty(hAES, BCRYPT_CHAINING_MODE, (PUCHAR) BCRYPT_CHAIN_MODE_GCM, sizeof(BCRYPT_CHAIN_MODE_GCM), 0);
   3.310 +        status = BCryptSetProperty(hAES, BCRYPT_CHAINING_MODE, (PUCHAR)BCRYPT_CHAIN_MODE_GCM, sizeof(BCRYPT_CHAIN_MODE_GCM), 0);
   3.311          if (status)
   3.312              goto closing;
   3.313  
   3.314 @@ -516,19 +516,19 @@
   3.315          if (!internet)
   3.316              goto closing;
   3.317  
   3.318 -		{
   3.319 -			product_list products = registered_products();
   3.320 -			DWORD context = 0;
   3.321 +        {
   3.322 +            product_list products = registered_products();
   3.323 +            DWORD context = 0;
   3.324  
   3.325 -			for (auto i = products.begin(); i != products.end(); i++) {
   3.326 -				try {
   3.327 -					update_product(*i, context++);
   3.328 -				}
   3.329 -				catch (exception&) {
   3.330 +            for (auto i = products.begin(); i != products.end(); i++) {
   3.331 +                try {
   3.332 +                    update_product(*i, context++);
   3.333 +                }
   3.334 +                catch (exception&) {
   3.335  
   3.336 -				}
   3.337 -			}
   3.338 -		}
   3.339 +                }
   3.340 +            }
   3.341 +        }
   3.342  
   3.343      closing:
   3.344          if (internet)
     4.1 --- a/GateKeeper.h	Sat Feb 24 20:59:45 2018 +0100
     4.2 +++ b/GateKeeper.h	Sat Feb 24 21:04:09 2018 +0100
     4.3 @@ -52,7 +52,7 @@
     4.4          void update_product(product p, DWORD context);
     4.5          product_list registered_products();
     4.6          void keep_updated();
     4.7 -		static tstring get_lockFile();
     4.8 +        static tstring get_lockFile();
     4.9  
    4.10      private:
    4.11          time_t now;
     5.1 --- a/locked_queue.hh	Sat Feb 24 20:59:45 2018 +0100
     5.2 +++ b/locked_queue.hh	Sat Feb 24 21:04:09 2018 +0100
     5.3 @@ -5,48 +5,48 @@
     5.4  
     5.5  namespace utility
     5.6  {
     5.7 -	using namespace std;
     5.8 +    using namespace std;
     5.9  
    5.10 -	template<class T> class locked_queue
    5.11 -	{
    5.12 -		mutex _mtx;
    5.13 -		list<T> _q;
    5.14 +    template<class T> class locked_queue
    5.15 +    {
    5.16 +        mutex _mtx;
    5.17 +        list<T> _q;
    5.18  
    5.19 -	public:
    5.20 -		T& back()
    5.21 -		{
    5.22 -			lock_guard<mutex> lg(_mtx);
    5.23 -			return _q.back();
    5.24 -		}
    5.25 -		T& front()
    5.26 -		{
    5.27 -			lock_guard<mutex> lg(_mtx);
    5.28 -			return _q.front();
    5.29 -		}
    5.30 -		void pop_back()
    5.31 -		{
    5.32 -			lock_guard<mutex> lg(_mtx);
    5.33 -			_q.pop_back();
    5.34 -		}
    5.35 -		void pop_front()
    5.36 -		{
    5.37 -			lock_guard<mutex> lg(_mtx);
    5.38 -			_q.pop_front();
    5.39 -		}
    5.40 -		void push_back(const T& data)
    5.41 -		{
    5.42 -			lock_guard<mutex> lg(_mtx);
    5.43 -			_q.push_back(data);
    5.44 -		}
    5.45 -		void push_front(const T& data)
    5.46 -		{
    5.47 -			lock_guard<mutex> lg(_mtx);
    5.48 -			_q.push_front(data);
    5.49 -		}
    5.50 -		size_t size()
    5.51 -		{
    5.52 -			lock_guard<mutex> lg(_mtx);
    5.53 -			return _q.size();
    5.54 -		}
    5.55 -	};
    5.56 +    public:
    5.57 +        T& back()
    5.58 +        {
    5.59 +            lock_guard<mutex> lg(_mtx);
    5.60 +            return _q.back();
    5.61 +        }
    5.62 +        T& front()
    5.63 +        {
    5.64 +            lock_guard<mutex> lg(_mtx);
    5.65 +            return _q.front();
    5.66 +        }
    5.67 +        void pop_back()
    5.68 +        {
    5.69 +            lock_guard<mutex> lg(_mtx);
    5.70 +            _q.pop_back();
    5.71 +        }
    5.72 +        void pop_front()
    5.73 +        {
    5.74 +            lock_guard<mutex> lg(_mtx);
    5.75 +            _q.pop_front();
    5.76 +        }
    5.77 +        void push_back(const T& data)
    5.78 +        {
    5.79 +            lock_guard<mutex> lg(_mtx);
    5.80 +            _q.push_back(data);
    5.81 +        }
    5.82 +        void push_front(const T& data)
    5.83 +        {
    5.84 +            lock_guard<mutex> lg(_mtx);
    5.85 +            _q.push_front(data);
    5.86 +        }
    5.87 +        size_t size()
    5.88 +        {
    5.89 +            lock_guard<mutex> lg(_mtx);
    5.90 +            return _q.size();
    5.91 +        }
    5.92 +    };
    5.93  };
     6.1 --- a/pEpCOMServerAdapter.cpp	Sat Feb 24 20:59:45 2018 +0100
     6.2 +++ b/pEpCOMServerAdapter.cpp	Sat Feb 24 21:04:09 2018 +0100
     6.3 @@ -21,7 +21,7 @@
     6.4  
     6.5  //
     6.6  extern "C" int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, 
     6.7 -								LPTSTR /*lpCmdLine*/, int nShowCmd)
     6.8 +                                LPTSTR /*lpCmdLine*/, int nShowCmd)
     6.9  {
    6.10      _AtlModule.hModule(hInstance);
    6.11      _AtlModule.start_gatekeeper();
     7.1 --- a/pEpCOMServerAdapter.idl	Sat Feb 24 20:59:45 2018 +0100
     7.2 +++ b/pEpCOMServerAdapter.idl	Sat Feb 24 21:04:09 2018 +0100
     7.3 @@ -43,18 +43,9 @@
     7.4      } SyncHandshakeResult;
     7.5  
     7.6      [id(1)] HRESULT MessageToSend([in] struct TextMessage * msg);
     7.7 +
     7.8      [id(2)] HRESULT NotifyHandshake([in] struct pEpIdentity * self, [in] struct pEpIdentity * partner, [in] SyncHandshakeSignal signal, [out, retval] SyncHandshakeResult * result);
     7.9 -};
    7.10  
    7.11 -[
    7.12 -    object,
    7.13 -    uuid(64E964B2-880A-4E92-B0B5-66FF4286A3B3),
    7.14 -    oleautomation,
    7.15 -    nonextensible,
    7.16 -    pointer_default(unique)
    7.17 -]
    7.18 -interface IpEpEngineCallbacks2 : IpEpEngineCallbacks 
    7.19 -{
    7.20      [id(3)] HRESULT NeedFastPolling([in] VARIANT_BOOL enableFastPolling);
    7.21  };
    7.22  
    7.23 @@ -69,22 +60,22 @@
    7.24  
    7.25      // runtime config of the adapter
    7.26  
    7.27 -    HRESULT VerboseLogging([in] VARIANT_BOOL enable);
    7.28 +    [id(1)] HRESULT VerboseLogging([in] VARIANT_BOOL enable);
    7.29  
    7.30      // runtime config of the engine
    7.31  
    7.32 -    HRESULT PassiveMode([in] VARIANT_BOOL enable);
    7.33 -    HRESULT UnencryptedSubject([in] VARIANT_BOOL enable);
    7.34 +    [id(2)] HRESULT PassiveMode([in] VARIANT_BOOL enable);
    7.35 +    [id(3)] HRESULT UnencryptedSubject([in] VARIANT_BOOL enable);
    7.36  
    7.37      // basic API
    7.38  
    7.39 -    HRESULT ExportKey([in] BSTR fpr, [out, retval] BSTR * keyData);
    7.40 -    HRESULT Log([in] BSTR title, [in] BSTR entity, [in, defaultvalue("")] BSTR description, [in, defaultvalue("")] BSTR comment);
    7.41 -    HRESULT Trustwords([in] BSTR fpr, [in, defaultvalue("en")] BSTR lang, [in, defaultvalue(0)] LONG maxWords, [out, retval] BSTR * words);
    7.42 -    HRESULT GetTrustwords([in] struct pEpIdentity * id1, [in] struct pEpIdentity * id2, [in, defaultvalue("en")] BSTR lang, [in, defaultvalue(0)] VARIANT_BOOL full, [out, retval] BSTR * words);
    7.43 -    HRESULT GetCrashdumpLog([in, defaultvalue(0)] LONG maxlines, [out, retval] BSTR * log);
    7.44 -    HRESULT GetEngineVersion([out, retval] BSTR * engineVersion);
    7.45 -    HRESULT GetLanguageList([out, retval] BSTR * languages);
    7.46 +    [id(4)] HRESULT ExportKey([in] BSTR fpr, [out, retval] BSTR * keyData);
    7.47 +    [id(5)] HRESULT Log([in] BSTR title, [in] BSTR entity, [in, defaultvalue("")] BSTR description, [in, defaultvalue("")] BSTR comment);
    7.48 +    [id(6)] HRESULT Trustwords([in] BSTR fpr, [in, defaultvalue("en")] BSTR lang, [in, defaultvalue(0)] LONG maxWords, [out, retval] BSTR * words);
    7.49 +    [id(7)] HRESULT GetTrustwords([in] struct pEpIdentity * id1, [in] struct pEpIdentity * id2, [in, defaultvalue("en")] BSTR lang, [in, defaultvalue(0)] VARIANT_BOOL full, [out, retval] BSTR * words);
    7.50 +    [id(8)] HRESULT GetCrashdumpLog([in, defaultvalue(0)] LONG maxlines, [out, retval] BSTR * log);
    7.51 +    [id(9)] HRESULT GetEngineVersion([out, retval] BSTR * engineVersion);
    7.52 +    [id(10)] HRESULT GetLanguageList([out, retval] BSTR * languages);
    7.53  
    7.54      typedef [v1_enum] enum pEpComType {
    7.55          pEpCtUnknown = 0,
    7.56 @@ -146,6 +137,94 @@
    7.57          pEpCtpEp = 0xff
    7.58      } pEpComType;
    7.59  
    7.60 +    typedef enum pEpStatus {
    7.61 +        pEpStatusOk = 0,
    7.62 +
    7.63 +        pEpInitCannotLoadGpgme = 0x0110,
    7.64 +        pEpInitGpgmeInitFailed = 0x0111,
    7.65 +        pEpInitNoGpgHome = 0x0112,
    7.66 +        pEpInitNetpgpInitFailed = 0x0113,
    7.67 +        pEpInitCannotDetermineGpgVersion = 0x0114,
    7.68 +        pEpInitUnsupportedGpgVersion = 0x0115,
    7.69 +        pEpInitCannotConfigGpgAgent = 0x0116,
    7.70 +
    7.71 +        pEpInitSqlite3WithoutMutex = 0x0120,
    7.72 +        pEpInitCannotOpenDb = 0x0121,
    7.73 +        pEpInitCannotOpenSystemDb = 0x0122,
    7.74 +
    7.75 +        pEpKeyNotFound = 0x0201,
    7.76 +        pEpKeyHasAmbigName = 0x0202,
    7.77 +        pEpGetKeyFailed = 0x0203,
    7.78 +        pEpCannotExportKey = 0x0204,
    7.79 +        pEpCannotEditKey = 0x0205,
    7.80 +        pEpKeyUnsuitable = 0x0206,
    7.81 +
    7.82 +        pEpCannotFindIdentity = 0x0301,
    7.83 +        pEpCannotSetPerson = 0x0381,
    7.84 +        pEpCannotSetPgpKeypair = 0x0382,
    7.85 +        pEpCannotSetIdentity = 0x0383,
    7.86 +        pEpCannotSetTrust = 0x0384,
    7.87 +        pEpKeyBlacklisted = 0x0385,
    7.88 +        pEpCannotFindPerson = 0x0386,
    7.89 +
    7.90 +        pEpCannotFindAlias = 0x0391,
    7.91 +        pEpCannotSetAlias = 0x0392,
    7.92 +
    7.93 +        pEpUnencrypted = 0x0400,
    7.94 +        pEpVerified = 0x0401,
    7.95 +        pEpDecrypted = 0x0402,
    7.96 +        pEpDecryptedAndVerified = 0x0403,
    7.97 +        pEpDecryptWrongFormat = 0x0404,
    7.98 +        pEpDecryptNoKey = 0x0405,
    7.99 +        pEpDecryptSignatureDoesNotMatch = 0x0406,
   7.100 +        pEpVerifyNoKey = 0x0407,
   7.101 +        pEpVerifiedAndTrusted = 0x0408,
   7.102 +        pEpCannotDecryptUnknown = 0x04ff,
   7.103 +
   7.104 +        pEpTrustwordNotFound = 0x0501,
   7.105 +        pEpTrustwordsFprWrongLength = 0x0502,
   7.106 +        pEpTrustwordsDuplicateFpr = 0x0503,
   7.107 +
   7.108 +        pEpCannotCreateKey = 0x0601,
   7.109 +        pEpCannotSendKey = 0x0602,
   7.110 +
   7.111 +        pEpPhraseNotFound = 0x0701,
   7.112 +
   7.113 +        pEpSendFunctionNotRegistered = 0x0801,
   7.114 +        pEpContraintsViolated = 0x0802,
   7.115 +        pEpCannotEncode = 0x0803,
   7.116 +
   7.117 +        pEpSyncNoNotifyCallback = 0x0901,
   7.118 +        pEpSyncIllegalMessage = 0x0902,
   7.119 +        pEpSyncNoInjectCallback = 0x0903,
   7.120 +
   7.121 +        pEpSequenceViolated = 0x0970,
   7.122 +        pEpCannotIncreaseSequence = 0x0971,
   7.123 +        pEpCannotSetSequenceValue = 0x0972,
   7.124 +        pEpOwnSequence = 0x097f,
   7.125 +
   7.126 +        pEpSyncStatemachineError = 0x0980,
   7.127 +        pEpSyncNoTrust = 0x0981,
   7.128 +        pEpStatemachineInvalidState = 0x0982,
   7.129 +        pEpStatemachineInvalidEvent = 0x0983,
   7.130 +        pEpStatemachineInvalidCondition = 0x0984,
   7.131 +        pEpStatemachineInvalidAction = 0x0985,
   7.132 +        pEpStatemachineInhibitedEvent = 0x0986,
   7.133 +
   7.134 +        pEpCommitFailed = 0xff01,
   7.135 +        pEpMessageConsume = 0xff02,
   7.136 +        pEpMessageIgnore = 0xff03,
   7.137 +
   7.138 +        pEpRecordNotFound = -6,
   7.139 +        pEpCannotCreateTempFile = -5,
   7.140 +        pEpIllegalValue = -4,
   7.141 +        pEpBufferTooSmall = -3,
   7.142 +        pEpOutOfMemory = -2,
   7.143 +        pEpUnknownError = -1,
   7.144 +
   7.145 +        pEpVersionMismatch = -7,
   7.146 +    } pEpStatus;
   7.147 +
   7.148      typedef [v1_enum] enum pEpIdentityFlags {
   7.149          pEpIdfNone = 0,
   7.150          pEpIdfNotForSync = 0x0001,
   7.151 @@ -163,31 +242,33 @@
   7.152          pEpIdentityFlags Flags;
   7.153      };
   7.154  
   7.155 -    HRESULT SetIdentityFlags([in] struct pEpIdentity *identity, [in] pEpIdentityFlags flags);
   7.156 -    HRESULT UnsetIdentityFlags([in] struct pEpIdentity *identity, [in] pEpIdentityFlags flags);
   7.157 +    [id(11)] HRESULT SetIdentityFlags([in] struct pEpIdentity *identity, [in] pEpIdentityFlags flags);
   7.158 +    [id(12)] HRESULT UnsetIdentityFlags([in] struct pEpIdentity *identity, [in] pEpIdentityFlags flags);
   7.159  
   7.160      // Keymanagement API
   7.161  
   7.162 -    HRESULT StartKeyserverLookup();
   7.163 -    HRESULT StopKeyserverLookup();
   7.164 +    [id(13)] HRESULT StartKeyserverLookup();
   7.165 +    [id(14)] HRESULT StopKeyserverLookup();
   7.166  
   7.167 -    HRESULT Myself([in] struct pEpIdentity *ident, [out, retval] struct pEpIdentity *result);
   7.168 -    HRESULT UpdateIdentity([in] struct pEpIdentity *ident, [out, retval] struct pEpIdentity *result);
   7.169 -    HRESULT KeyMistrusted([in] struct pEpIdentity *ident);
   7.170 -    HRESULT KeyResetTrust([in] struct pEpIdentity *ident);
   7.171 -    HRESULT TrustPersonalKey([in] struct pEpIdentity *ident, [out, retval] struct pEpIdentity *result);
   7.172 -    HRESULT OwnIdentitiesRetrieve([out, retval] SAFEARRAY(struct pEpIdentity)* ownIdentities);
   7.173 +    [id(15)] HRESULT Myself([in] struct pEpIdentity *ident, [out, retval] struct pEpIdentity *result);
   7.174 +    [id(16)] HRESULT UpdateIdentity([in] struct pEpIdentity *ident, [out, retval] struct pEpIdentity *result);
   7.175 +    [id(17)] HRESULT KeyMistrusted([in] struct pEpIdentity *ident);
   7.176 +    [id(18)] HRESULT KeyResetTrust([in] struct pEpIdentity *ident);
   7.177 +    [id(19)] HRESULT TrustPersonalKey([in] struct pEpIdentity *ident, [out, retval] struct pEpIdentity *result);
   7.178 +    [id(20)] HRESULT OwnIdentitiesRetrieve([out, retval] SAFEARRAY(struct pEpIdentity)* ownIdentities);
   7.179 +    [id(21)] HRESULT UndoLastMistrust();
   7.180 +    [id(22)] HRESULT IsPepUser([in] struct pEpIdentity *ident, [out, retval] VARIANT_BOOL *ispEp);
   7.181  
   7.182      // Blacklist API
   7.183  
   7.184 -    HRESULT BlacklistAdd([in] BSTR fpr);
   7.185 -    HRESULT BlacklistDelete([in] BSTR fpr);
   7.186 -    HRESULT BlacklistIsListed([in] BSTR fpr, [out, retval] VARIANT_BOOL *listed);
   7.187 -    HRESULT BlacklistRetrieve([out, retval] SAFEARRAY(BSTR) *blacklist);
   7.188 +    [id(23)] HRESULT BlacklistAdd([in] BSTR fpr);
   7.189 +    [id(24)] HRESULT BlacklistDelete([in] BSTR fpr);
   7.190 +    [id(25)] HRESULT BlacklistIsListed([in] BSTR fpr, [out, retval] VARIANT_BOOL *listed);
   7.191 +    [id(26)] HRESULT BlacklistRetrieve([out, retval] SAFEARRAY(BSTR) *blacklist);
   7.192  
   7.193      // PGP compatibility functions
   7.194  
   7.195 -    HRESULT OpenPGPListKeyinfo([in] BSTR searchPattern, [out, retval] SAFEARRAY(struct StringPair)* keyinfoList);
   7.196 +    [id(27)] HRESULT OpenPGPListKeyinfo([in] BSTR searchPattern, [out, retval] SAFEARRAY(struct StringPair)* keyinfoList);
   7.197  
   7.198      // Message API
   7.199  
   7.200 @@ -241,6 +322,15 @@
   7.201          pEpDirOutgoing
   7.202      } pEpMsgDirection;
   7.203  
   7.204 +    typedef [v1_enum] enum pEpEncFormat {
   7.205 +        pEpEncNone = 0,                       // message is not encrypted
   7.206 +        pEpEncPieces,                         // inline PGP + PGP extensions
   7.207 +        pEpEncSMime,                          // RFC5751
   7.208 +        pEpEncPgpMime,                        // RFC3156
   7.209 +        pEpEncPep,                            // pEp encryption format
   7.210 +        pEpEncPgpMimeOutlook1                 // Message B0rken by Outlook type 1
   7.211 +    } pEpEncFormat;
   7.212 +
   7.213      [uuid(47FB0795-6B64-455C-BB0E-54998CAB8ACB)] struct StringPair {
   7.214          BSTR Name;
   7.215          BSTR Value;
   7.216 @@ -273,38 +363,28 @@
   7.217          SAFEARRAY(struct StringPair) OptFields;
   7.218      };
   7.219  
   7.220 -    HRESULT EncryptMessage(
   7.221 +    [id(28)] HRESULT EncryptMessage(
   7.222          [in] struct TextMessage *src,
   7.223          [out] struct TextMessage * dst,
   7.224          [in] SAFEARRAY(BSTR) extra,
   7.225 -        [in, defaultvalue(pEpEncryptFlagDefault)] pEpEncryptFlags flags);
   7.226 +        [in, defaultvalue(pEpEncryptFlagDefault)] pEpEncryptFlags flags,
   7.227 +        // Use pEpEncFormat.pEpEncNone for unencrypted, outgoing messages.
   7.228 +        // Default is pEpEncFormat.pEpEncPep, all other formats are only 
   7.229 +        // for compatibility and not intended for normal use.
   7.230 +        [in, defaultvalue(pEpEncPep)] pEpEncFormat encFormat);
   7.231  
   7.232 -    HRESULT DecryptMessage(
   7.233 +    [id(29)] HRESULT DecryptMessage(
   7.234          [in] struct TextMessage *src,
   7.235          [out] struct TextMessage * dst,
   7.236          [out] SAFEARRAY(BSTR) *keylist,
   7.237          [out] pEpDecryptFlags* flags,
   7.238          [out, retval] pEpRating *rating);
   7.239  
   7.240 -    HRESULT OutgoingMessageRating([in] struct TextMessage *msg, [out, retval] pEpRating * pVal);
   7.241 -    HRESULT IdentityRating([in] struct pEpIdentity * ident, [out, retval] pEpRating * pVal);
   7.242 -    HRESULT ColorFromRating([in] pEpRating rating, [out, retval] pEpColor* pVal);
   7.243 +    [id(30)] HRESULT OutgoingMessageRating([in] struct TextMessage *msg, [out, retval] pEpRating * pVal);
   7.244 +    [id(31)] HRESULT IdentityRating([in] struct pEpIdentity * ident, [out, retval] pEpRating * pVal);
   7.245 +    [id(32)] HRESULT ColorFromRating([in] pEpRating rating, [out, retval] pEpColor* pVal);
   7.246  
   7.247 -    // callback / keysync API
   7.248 -    HRESULT RegisterCallbacks([in] IpEpEngineCallbacks* newCallback);
   7.249 -    HRESULT UnregisterCallbacks();
   7.250 -};
   7.251 -
   7.252 -[
   7.253 -    object,
   7.254 -    uuid(8A042123-D433-4DEA-ADA2-2E5E61A00292),
   7.255 -    oleautomation,
   7.256 -    nonextensible,
   7.257 -    pointer_default(unique)
   7.258 -]
   7.259 -interface IpEpEngine2 : IpEpEngine
   7.260 -{
   7.261 -    HRESULT GetMessageTrustwords(
   7.262 +    [id(33)] HRESULT GetMessageTrustwords(
   7.263          [in] struct TextMessage *msg,
   7.264          [in] struct pEpIdentity * receivedBy,
   7.265          [in] SAFEARRAY(BSTR) keylist,
   7.266 @@ -313,27 +393,23 @@
   7.267          [out, retval] BSTR * words
   7.268      );
   7.269  
   7.270 -    HRESULT EncryptMessageForSelf(
   7.271 +    [id(34)] HRESULT EncryptMessageForSelf(
   7.272          [in] struct pEpIdentity* targetId,
   7.273 -        [in] struct TextMessage* src, 
   7.274 +        [in] struct TextMessage* src,
   7.275          [out] struct TextMessage* dst,
   7.276          [in, defaultvalue(pEpEncryptFlagDefault)] pEpEncryptFlags flags
   7.277      );
   7.278  
   7.279 -    HRESULT ReEvaluateMessageRating(
   7.280 +    [id(35)] HRESULT ReEvaluateMessageRating(
   7.281          [in] struct TextMessage *src,
   7.282          [in] SAFEARRAY(BSTR) x_KeyList, // referring to X-KeyList mail header
   7.283          [in] pEpRating x_EncStatus, // referring to X-EncStatus mail header
   7.284          [out, retval] pEpRating *rating
   7.285      );
   7.286  
   7.287 -	HRESULT UndoLastMistrust();
   7.288 -
   7.289 -	HRESULT SetOwnKey(
   7.290 -		[in] struct pEpIdentity * ident,
   7.291 -		[in] BSTR fpr,
   7.292 -		[out, retval] struct pEpIdentity * result
   7.293 -	);
   7.294 +    // callback / keysync API
   7.295 +    [id(36)] HRESULT RegisterCallbacks([in] IpEpEngineCallbacks* newCallback);
   7.296 +    [id(37)] HRESULT UnregisterCallbacks();
   7.297  };
   7.298  
   7.299  [
   7.300 @@ -348,8 +424,7 @@
   7.301          uuid(5FF6682B-727B-4DFE-A68D-28982874C0C7)
   7.302      ]
   7.303      coclass pEpEngine {
   7.304 -        [default] interface IpEpEngine2;
   7.305 -        interface IpEpEngine;
   7.306 -        interface IpEpEngineCallbacks2;
   7.307 +        [default] interface IpEpEngine;
   7.308 +        interface IpEpEngineCallbacks;
   7.309      };
   7.310  };
     8.1 --- a/pEp_utility.cpp	Sat Feb 24 20:59:45 2018 +0100
     8.2 +++ b/pEp_utility.cpp	Sat Feb 24 21:04:09 2018 +0100
     8.3 @@ -7,8 +7,8 @@
     8.4      namespace utility {
     8.5          pEp_identity_cpp::pEp_identity_cpp(const ::pEp_identity *_ident)
     8.6          {
     8.7 -			if (!_ident)
     8.8 -				return;
     8.9 +            if (!_ident)
    8.10 +                return;
    8.11  
    8.12              if (_ident->address)
    8.13                  address = _ident->address;
    8.14 @@ -18,17 +18,17 @@
    8.15                  user_id = _ident->user_id;
    8.16              if (_ident->username)
    8.17                  username = _ident->username;
    8.18 -            comm_type = (pEpComType) _ident->comm_type;
    8.19 +            comm_type = (pEpComType)_ident->comm_type;
    8.20              lang = _ident->lang;
    8.21 -			flags = (int) _ident->flags;
    8.22 +            flags = (int)_ident->flags;
    8.23          }
    8.24  
    8.25          pEp_identity_cpp::pEp_identity_cpp(const pEpIdentity *_ident)
    8.26          {
    8.27 -			if (!_ident)
    8.28 -				return;
    8.29 +            if (!_ident)
    8.30 +                return;
    8.31  
    8.32 -			if (_ident->Address)
    8.33 +            if (_ident->Address)
    8.34                  address = utf8_string(_ident->Address);
    8.35              if (_ident->Fpr)
    8.36                  fpr = utf8_string(_ident->Fpr);
    8.37 @@ -39,7 +39,7 @@
    8.38              comm_type = _ident->CommType;
    8.39              if (_ident->Lang)
    8.40                  lang = utf8_string(_ident->Lang);
    8.41 -			flags = (int)_ident->Flags;
    8.42 +            flags = (int)_ident->Flags;
    8.43          }
    8.44  
    8.45          pEp_identity * pEp_identity_cpp::to_pEp_identity()
    8.46 @@ -58,14 +58,14 @@
    8.47                  _ident->lang[1] = this->lang[1];
    8.48              }
    8.49  
    8.50 -			_ident->flags = (identity_flags) this->flags;
    8.51 +            _ident->flags = (identity_flags) this->flags;
    8.52  
    8.53              return _ident;
    8.54          }
    8.55  
    8.56          pEpIdentity * pEp_identity_cpp::to_pEp_identity_s()
    8.57          {
    8.58 -            pEpIdentity *_ident = (pEpIdentity *) calloc(1, sizeof(pEpIdentity));
    8.59 +            pEpIdentity *_ident = (pEpIdentity *)calloc(1, sizeof(pEpIdentity));
    8.60              assert(_ident);
    8.61              if (_ident == NULL)
    8.62                  throw bad_alloc();
    8.63 @@ -76,7 +76,7 @@
    8.64              _ident->Lang = utf16_bstr(this->lang);
    8.65              _ident->UserName = utf16_bstr(this->username);
    8.66              _ident->UserId = utf16_bstr(this->user_id);
    8.67 -			_ident->Flags = (pEpIdentityFlags) this->flags;
    8.68 +            _ident->Flags = (pEpIdentityFlags) this->flags;
    8.69  
    8.70              return _ident;
    8.71          }
    8.72 @@ -84,8 +84,8 @@
    8.73          void copy_identity(pEpIdentity * ident_s, const pEp_identity * ident)
    8.74          {
    8.75              assert(ident_s);
    8.76 -			if (!ident_s)
    8.77 -				throw invalid_argument("ident_s");
    8.78 +            if (!ident_s)
    8.79 +                throw invalid_argument("ident_s");
    8.80  
    8.81              ::memset(ident_s, 0, sizeof(pEpIdentity));
    8.82              if (ident) {
    8.83 @@ -97,10 +97,10 @@
    8.84                      ident_s->UserId = utf16_bstr(ident->user_id);
    8.85                  if (ident->username)
    8.86                      ident_s->UserName = utf16_bstr(ident->username);
    8.87 -                ident_s->CommType = (pEpComType) ident->comm_type;
    8.88 +                ident_s->CommType = (pEpComType)ident->comm_type;
    8.89                  if (ident->lang)
    8.90                      ident_s->Lang = utf16_bstr(ident->lang);
    8.91 -				ident_s->Flags = (pEpIdentityFlags) ident->flags;
    8.92 +                ident_s->Flags = (pEpIdentityFlags)ident->flags;
    8.93              }
    8.94          }
    8.95  
    8.96 @@ -138,7 +138,7 @@
    8.97              if (_ident == NULL)
    8.98                  throw bad_alloc();
    8.99  
   8.100 -            _ident->comm_type = (PEP_comm_type) ident->CommType;
   8.101 +            _ident->comm_type = (PEP_comm_type)ident->CommType;
   8.102  
   8.103              if (ident->Lang) {
   8.104                  string _lang = utf8_string(ident->Lang);
   8.105 @@ -160,7 +160,7 @@
   8.106                  }
   8.107              }
   8.108  
   8.109 -			_ident->flags = (identity_flags_t)ident->Flags;
   8.110 +            _ident->flags = (identity_flags_t)ident->Flags;
   8.111  
   8.112              return _ident;
   8.113          }
   8.114 @@ -177,21 +177,21 @@
   8.115  
   8.116          template<> Blob *from_C< Blob *, bloblist_t >(bloblist_t *tl)
   8.117          {
   8.118 -			assert(tl);
   8.119 +            assert(tl);
   8.120  
   8.121              CComSafeArray<BYTE> sa;
   8.122 -			if (tl) {
   8.123 -				sa.Create(tl->size);
   8.124 -				if (tl->size) {
   8.125 -					char *data;
   8.126 -					SafeArrayAccessData(sa, (void **)&data);
   8.127 -					memcpy(data, tl->value, tl->size);
   8.128 -					SafeArrayUnaccessData(sa);
   8.129 -				}
   8.130 -			}
   8.131 -			else {
   8.132 -				sa.Create((ULONG)0);
   8.133 -			}
   8.134 +            if (tl) {
   8.135 +                sa.Create(tl->size);
   8.136 +                if (tl->size) {
   8.137 +                    char *data;
   8.138 +                    SafeArrayAccessData(sa, (void **)&data);
   8.139 +                    memcpy(data, tl->value, tl->size);
   8.140 +                    SafeArrayUnaccessData(sa);
   8.141 +                }
   8.142 +            }
   8.143 +            else {
   8.144 +                sa.Create((ULONG)0);
   8.145 +            }
   8.146  
   8.147              Blob *_blob = new Blob();
   8.148  
   8.149 @@ -286,9 +286,9 @@
   8.150  
   8.151          void clear_text_message(TextMessage *msg)
   8.152          {
   8.153 -			assert(msg);
   8.154 -			if (!msg)
   8.155 -				return;
   8.156 +            assert(msg);
   8.157 +            if (!msg)
   8.158 +                return;
   8.159  
   8.160              SysFreeString(msg->Id);
   8.161              SysFreeString(msg->ShortMsg);
   8.162 @@ -314,20 +314,20 @@
   8.163              assert(msg2);
   8.164              assert(msg);
   8.165  
   8.166 -			if (!msg2) {
   8.167 -				msg2 = (TextMessage *)calloc(1, sizeof(TextMessage));
   8.168 -				assert(msg2);
   8.169 -				if (!msg2)
   8.170 -					throw bad_alloc();
   8.171 -			}
   8.172 -			else {
   8.173 -				clear_text_message(msg2);
   8.174 -			}
   8.175 +            if (!msg2) {
   8.176 +                msg2 = (TextMessage *)calloc(1, sizeof(TextMessage));
   8.177 +                assert(msg2);
   8.178 +                if (!msg2)
   8.179 +                    throw bad_alloc();
   8.180 +            }
   8.181 +            else {
   8.182 +                clear_text_message(msg2);
   8.183 +            }
   8.184  
   8.185 -			if (!msg)
   8.186 -				return;
   8.187 +            if (!msg)
   8.188 +                return;
   8.189  
   8.190 -            msg2->Dir = (pEpMsgDirection) msg->dir;
   8.191 +            msg2->Dir = (pEpMsgDirection)msg->dir;
   8.192              msg2->Id = bstr(msg->id);
   8.193              msg2->ShortMsg = bstr(msg->shortmsg);
   8.194              msg2->LongMsg = bstr(msg->longmsg);
   8.195 @@ -397,15 +397,15 @@
   8.196  
   8.197                  char *buffer;
   8.198                  if (size) {
   8.199 -                    buffer = (char *) malloc(size + 1);
   8.200 +                    buffer = (char *)malloc(size + 1);
   8.201                      if (buffer == NULL)
   8.202                          throw bad_alloc();
   8.203  
   8.204                      char *data;
   8.205  
   8.206 -                    SafeArrayAccessData(b.value, (void **) &data);
   8.207 +                    SafeArrayAccessData(b.value, (void **)&data);
   8.208                      memcpy(buffer, data, size);
   8.209 -					buffer[size] = 0; // safeguard
   8.210 +                    buffer[size] = 0; // safeguard
   8.211                      SafeArrayUnaccessData(sa);
   8.212                  }
   8.213                  else {
   8.214 @@ -472,14 +472,14 @@
   8.215  
   8.216          stringpair_t *new_stringpair(StringPair *fld)
   8.217          {
   8.218 -			stringpair_t *pair;
   8.219 +            stringpair_t *pair;
   8.220  
   8.221 -			if (!fld) {
   8.222 -				pair = ::new_stringpair(NULL, NULL);
   8.223 -			}
   8.224 -			else {
   8.225 -				pair = ::new_stringpair(str(fld->Name), str(fld->Value));
   8.226 -			}
   8.227 +            if (!fld) {
   8.228 +                pair = ::new_stringpair(NULL, NULL);
   8.229 +            }
   8.230 +            else {
   8.231 +                pair = ::new_stringpair(str(fld->Name), str(fld->Value));
   8.232 +            }
   8.233              if (pair == NULL)
   8.234                  throw bad_alloc();
   8.235  
   8.236 @@ -534,14 +534,14 @@
   8.237  
   8.238              return il;
   8.239          }
   8.240 -        
   8.241 +
   8.242          ::message * text_message_to_C(TextMessage *msg)
   8.243          {
   8.244              assert(msg);
   8.245 -			if (!msg)
   8.246 -				throw invalid_argument("msg");
   8.247 +            if (!msg)
   8.248 +                throw invalid_argument("msg");
   8.249  
   8.250 -            ::message * msg2 = new_message((PEP_msg_direction) msg->Dir);
   8.251 +            ::message * msg2 = new_message((PEP_msg_direction)msg->Dir);
   8.252              if (msg2 == NULL)
   8.253                  throw bad_alloc();
   8.254  
   8.255 @@ -566,21 +566,21 @@
   8.256              return msg2;
   8.257          }
   8.258  
   8.259 -		void opt_field_array_from_C(stringpair_list_t* spair_list, LPSAFEARRAY* pair_list_out) {
   8.260 -			assert(spair_list);
   8.261 -			assert(pair_list_out);
   8.262 -			
   8.263 -			if (!spair_list)
   8.264 -				return;
   8.265 +        void opt_field_array_from_C(stringpair_list_t* spair_list, LPSAFEARRAY* pair_list_out) {
   8.266 +            assert(spair_list);
   8.267 +            assert(pair_list_out);
   8.268  
   8.269 -			*pair_list_out = array_from_C<StringPair, stringpair_list_t>(spair_list);
   8.270 -		}
   8.271 +            if (!spair_list)
   8.272 +                return;
   8.273  
   8.274 -		void clear_opt_field_array(LPSAFEARRAY* opt_field_array) {
   8.275 -			if (opt_field_array){
   8.276 -				SafeArrayDestroy(*opt_field_array);
   8.277 -				*opt_field_array = NULL;
   8.278 -			}
   8.279 -		}
   8.280 +            *pair_list_out = array_from_C<StringPair, stringpair_list_t>(spair_list);
   8.281 +        }
   8.282 +
   8.283 +        void clear_opt_field_array(LPSAFEARRAY* opt_field_array) {
   8.284 +            if (opt_field_array) {
   8.285 +                SafeArrayDestroy(*opt_field_array);
   8.286 +                *opt_field_array = NULL;
   8.287 +            }
   8.288 +        }
   8.289      }
   8.290  }
     9.1 --- a/pEp_utility.h	Sat Feb 24 20:59:45 2018 +0100
     9.2 +++ b/pEp_utility.h	Sat Feb 24 21:04:09 2018 +0100
     9.3 @@ -16,7 +16,7 @@
     9.4              string username;
     9.5              pEpComType comm_type;
     9.6              string lang;
     9.7 -			int flags;
     9.8 +            int flags;
     9.9  
    9.10              pEp_identity_cpp(
    9.11                  string _address = string(),
    9.12 @@ -25,7 +25,7 @@
    9.13                  string _username = string(),
    9.14                  pEpComType _comm_type = pEpCtUnknown,
    9.15                  string _lang = string()
    9.16 -                ) : address(_address), fpr(_fpr), user_id(_user_id), username(_username), comm_type(_comm_type), lang(_lang)
    9.17 +            ) : address(_address), fpr(_fpr), user_id(_user_id), username(_username), comm_type(_comm_type), lang(_lang)
    9.18              { }
    9.19  
    9.20              pEp_identity_cpp(const ::pEp_identity *_ident);
    9.21 @@ -41,9 +41,9 @@
    9.22          void clear_text_message(TextMessage *msg);
    9.23          ::pEp_identity *new_identity(const pEpIdentity * ident);
    9.24  
    9.25 -		void opt_field_array_from_C(stringpair_list_t* spair_list, LPSAFEARRAY* pair_list_out);
    9.26 -		void clear_opt_field_array(LPSAFEARRAY* pair_list);
    9.27 -		template< class T2, class T > SAFEARRAY * array_from_C(T *tl);
    9.28 +        void opt_field_array_from_C(stringpair_list_t* spair_list, LPSAFEARRAY* pair_list_out);
    9.29 +        void clear_opt_field_array(LPSAFEARRAY* pair_list);
    9.30 +        template< class T2, class T > SAFEARRAY * array_from_C(T *tl);
    9.31  
    9.32          static LPTYPELIB pTypelib = NULL;
    9.33  
    10.1 --- a/utf8_helper.cpp	Sat Feb 24 20:59:45 2018 +0100
    10.2 +++ b/utf8_helper.cpp	Sat Feb 24 21:04:09 2018 +0100
    10.3 @@ -48,9 +48,9 @@
    10.4          {
    10.5              if (bstr == NULL)
    10.6                  return "";
    10.7 -            
    10.8 +
    10.9              _bstr_t _bstr(bstr);
   10.10 -            wstring wstr = (wchar_t *) _bstr;
   10.11 +            wstring wstr = (wchar_t *)_bstr;
   10.12              _bstr.Detach();
   10.13  
   10.14              return utf8_string(wstr, norm);
   10.15 @@ -90,7 +90,7 @@
   10.16              if (len == 0)
   10.17                  return NULL;
   10.18  
   10.19 -            CComSafeArray<BSTR> sa_string_list((LONG) len);
   10.20 +            CComSafeArray<BSTR> sa_string_list((LONG)len);
   10.21              LONG n = 0;
   10.22              for (const ::stringlist_t *k = stringlist; k && k->value; k = k->next) {
   10.23                  if (k->value) {
   10.24 @@ -112,7 +112,7 @@
   10.25  
   10.26              CComSafeArray<BSTR> sa(safearray);
   10.27              int n_strings = 0;
   10.28 -            ::stringlist_t *_stringlist = ::new_stringlist((const char *) NULL);
   10.29 +            ::stringlist_t *_stringlist = ::new_stringlist((const char *)NULL);
   10.30              assert(_stringlist);
   10.31              if (_stringlist == NULL)
   10.32                  throw std::bad_alloc();
    11.1 --- a/xdlldata.h	Sat Feb 24 20:59:45 2018 +0100
    11.2 +++ b/xdlldata.h	Sat Feb 24 21:04:09 2018 +0100
    11.3 @@ -2,14 +2,14 @@
    11.4  
    11.5  #ifdef _MERGE_PROXYSTUB
    11.6  
    11.7 -extern "C" 
    11.8 +extern "C"
    11.9  {
   11.10 -BOOL WINAPI PrxDllMain(HINSTANCE hInstance, DWORD dwReason, 
   11.11 -	LPVOID lpReserved);
   11.12 -STDAPI PrxDllCanUnloadNow(void);
   11.13 -STDAPI PrxDllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv);
   11.14 -STDAPI PrxDllRegisterServer(void);
   11.15 -STDAPI PrxDllUnregisterServer(void);
   11.16 +    BOOL WINAPI PrxDllMain(HINSTANCE hInstance, DWORD dwReason,
   11.17 +        LPVOID lpReserved);
   11.18 +    STDAPI PrxDllCanUnloadNow(void);
   11.19 +    STDAPI PrxDllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv);
   11.20 +    STDAPI PrxDllRegisterServer(void);
   11.21 +    STDAPI PrxDllUnregisterServer(void);
   11.22  }
   11.23  
   11.24  #endif