COM-49: When system.db is missing, adapter keeps restaring in a loop with no error message.
authorMarkus Schaber <markus@pep-security.net>
Fri, 02 Feb 2018 22:03:16 +0100
changeset 26926c8597fe860
parent 268 4d41410af9a0
child 273 30be98685afa
COM-49: When system.db is missing, adapter keeps restaring in a loop with no error message.

- Code Reformat (whitespace only changes)
CpEpEngine.cpp
CpEpEngine.h
GateKeeper.cpp
GateKeeper.h
locked_queue.hh
pEpCOMServerAdapter.cpp
pEpCOMServerAdapter.idl
pEp_utility.cpp
pEp_utility.h
utf8_helper.cpp
xdlldata.h
     1.1 --- a/CpEpEngine.cpp	Thu Feb 01 23:30:55 2018 +0100
     1.2 +++ b/CpEpEngine.cpp	Fri Feb 02 22:03:16 2018 +0100
     1.3 @@ -611,15 +611,15 @@
     1.4  
     1.5  STDMETHODIMP CpEpEngine::UndoLastMistrust()
     1.6  {
     1.7 -	PEP_STATUS status = ::undo_last_mistrust(get_session());
     1.8 +    PEP_STATUS status = ::undo_last_mistrust(get_session());
     1.9  
    1.10 -	if (status == PEP_CANNOT_FIND_IDENTITY)
    1.11 -		return FAIL(L"Cannot find identity!", status);
    1.12 +    if (status == PEP_CANNOT_FIND_IDENTITY)
    1.13 +        return FAIL(L"Cannot find identity!", status);
    1.14  
    1.15 -	if (status != ::PEP_STATUS_OK)
    1.16 -		return FAIL(L"cannot revoke compromized key", status);
    1.17 +    if (status != ::PEP_STATUS_OK)
    1.18 +        return FAIL(L"cannot revoke compromized key", status);
    1.19  
    1.20 -	return S_OK;
    1.21 +    return S_OK;
    1.22  }
    1.23  
    1.24  STDMETHODIMP CpEpEngine::KeyResetTrust(struct pEpIdentity *ident)
    1.25 @@ -1162,12 +1162,12 @@
    1.26      keysync_abort_requested = false;
    1.27  
    1.28      // Init our keysync session
    1.29 -	{ // begin lock scope
    1.30 -		std::lock_guard<std::mutex> lock(init_mutex);
    1.31 -		PEP_STATUS status = ::init(&keysync_session);
    1.32 -		::register_sync_callbacks(keysync_session, (void*)this, messageToSend, notifyHandshake, inject_sync_msg, retrieve_next_sync_msg);
    1.33 -		assert(status == PEP_STATUS_OK);
    1.34 -	} // end lock scope
    1.35 +    { // begin lock scope
    1.36 +        std::lock_guard<std::mutex> lock(init_mutex);
    1.37 +        PEP_STATUS status = ::init(&keysync_session);
    1.38 +        ::register_sync_callbacks(keysync_session, (void*)this, messageToSend, notifyHandshake, inject_sync_msg, retrieve_next_sync_msg);
    1.39 +        assert(status == PEP_STATUS_OK);
    1.40 +    } // end lock scope
    1.41  
    1.42      attach_sync_session(get_session(), keysync_session);
    1.43  
    1.44 @@ -1248,7 +1248,7 @@
    1.45      ::detach_sync_session(get_session());
    1.46      ::unregister_sync_callbacks(keysync_session);
    1.47  
    1.48 -	std::lock_guard<std::mutex> releaselock(init_mutex);
    1.49 +    std::lock_guard<std::mutex> releaselock(init_mutex);
    1.50      release(keysync_session);
    1.51      keysync_session = NULL;
    1.52  }
    1.53 @@ -1326,16 +1326,16 @@
    1.54              {
    1.55                  *timeout = 1; // Signal timeout
    1.56                  return NULL;
    1.57 -            } 
    1.58 -            else 
    1.59 +            }
    1.60 +            else
    1.61              {
    1.62                  std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now();
    1.63  
    1.64 -                if (now < end_time) 
    1.65 +                if (now < end_time)
    1.66                  {
    1.67                      *timeout = std::chrono::duration_cast<std::chrono::seconds>(end_time - now).count();
    1.68 -                } 
    1.69 -                else 
    1.70 +                }
    1.71 +                else
    1.72                  {
    1.73                      *timeout = 0;
    1.74                  }
    1.75 @@ -1522,7 +1522,7 @@
    1.76  
    1.77              if (res != S_OK)
    1.78  
    1.79 -            return PEP_STATUS_OK;
    1.80 +                return PEP_STATUS_OK;
    1.81          }
    1.82  
    1.83          ::log_event(me->keysync_session, "Reentrant notify_handshake call!", "pEp COM Adapter", NULL, NULL);
     2.1 --- a/CpEpEngine.h	Thu Feb 01 23:30:55 2018 +0100
     2.2 +++ b/CpEpEngine.h	Fri Feb 02 22:03:16 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 IpEpEngine2
    2.13  {
    2.14  
    2.15  protected:
    2.16 @@ -32,62 +32,62 @@
    2.17  
    2.18  public:
    2.19      CpEpEngine() : keymanagement_thread(NULL), identity_queue(NULL), verbose_mode(false)
    2.20 -	{
    2.21 -		// See FinalConstruct() below for most initialization work, and an
    2.22 -		// explanation why it had to be moved there...
    2.23 -    }	
    2.24 +    {
    2.25 +        // See FinalConstruct() below for most initialization work, and an
    2.26 +        // explanation why it had to be moved there...
    2.27 +    }
    2.28  
    2.29      ~CpEpEngine()
    2.30      {
    2.31          stop_keysync();
    2.32          StopKeyserverLookup();
    2.33 -		if (m_session) // may be zero when FinalConstruct failed to initialize the engine
    2.34 -		{
    2.35 -			::log_event(m_session, "Shutdown", "pEp COM Adapter", NULL, NULL);
    2.36 -			std::lock_guard<std::mutex> lock(init_mutex);
    2.37 -			::release(m_session);
    2.38 -		}
    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(IpEpEngine2)
    2.61 +        COM_INTERFACE_ENTRY(ISupportErrorInfo)
    2.62 +    END_COM_MAP()
    2.63  
    2.64 -// ISupportsErrorInfo
    2.65 -	STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);
    2.66 +    // ISupportsErrorInfo
    2.67 +    STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);
    2.68  
    2.69 -	DECLARE_PROTECT_FINAL_CONSTRUCT()
    2.70 +    DECLARE_PROTECT_FINAL_CONSTRUCT()
    2.71  
    2.72 -	// Unfortunately, neither FAIL nor error() work in the constructor, as 
    2.73 -	// CreateErrorInfo/SetErrorInfo cannot work when the instance is not constructed.
    2.74 -	// AtlThrow works, but the exception is caught in CComCreator.CreateInstance, and
    2.75 -	// unconditionally turned into E_OUTOFMEMORY. Thus, we need to do most constructor
    2.76 -	// work in FinalConstruct. CreateErrorInfo/SetErrorInfo still won't work, but at least,
    2.77 -	// we can return a meaningful HRESULT. Thus, we pack our PEP_STATUS into a custom HRESULT.	
    2.78 -	HRESULT FinalConstruct()
    2.79 -	{
    2.80 -		std::lock_guard<std::mutex> lock(init_mutex);
    2.81 -		PEP_STATUS status = ::init(&m_session);
    2.82 -		assert(status == PEP_STATUS_OK);
    2.83 -		if (status != PEP_STATUS_OK) {
    2.84 -			HRESULT res = MAKE_HRESULT(1, FACILITY_ITF, (0xFFFF & status));
    2.85 -			return res;
    2.86 -		}
    2.87 +    // Unfortunately, neither FAIL nor error() work in the constructor, as 
    2.88 +    // CreateErrorInfo/SetErrorInfo cannot work when the instance is not constructed.
    2.89 +    // AtlThrow works, but the exception is caught in CComCreator.CreateInstance, and
    2.90 +    // unconditionally turned into E_OUTOFMEMORY. Thus, we need to do most constructor
    2.91 +    // work in FinalConstruct. CreateErrorInfo/SetErrorInfo still won't work, but at least,
    2.92 +    // we can return a meaningful HRESULT. Thus, we pack our PEP_STATUS into a custom HRESULT.	
    2.93 +    HRESULT FinalConstruct()
    2.94 +    {
    2.95 +        std::lock_guard<std::mutex> lock(init_mutex);
    2.96 +        PEP_STATUS status = ::init(&m_session);
    2.97 +        assert(status == PEP_STATUS_OK);
    2.98 +        if (status != PEP_STATUS_OK) {
    2.99 +            HRESULT res = MAKE_HRESULT(1, FACILITY_ITF, (0xFFFF & status));
   2.100 +            return res;
   2.101 +        }
   2.102  
   2.103 -		::register_examine_function(m_session, CpEpEngine::examine_identity, (void *)this);
   2.104 -		::log_event(m_session, "Startup", "pEp COM Adapter", NULL, NULL);
   2.105 -		return S_OK;
   2.106 -	}
   2.107 +        ::register_examine_function(m_session, CpEpEngine::examine_identity, (void *)this);
   2.108 +        ::log_event(m_session, "Startup", "pEp COM Adapter", NULL, NULL);
   2.109 +        return S_OK;
   2.110 +    }
   2.111  
   2.112 -	void FinalRelease()
   2.113 -	{
   2.114 -	}
   2.115 +    void FinalRelease()
   2.116 +    {
   2.117 +    }
   2.118  
   2.119  
   2.120  protected:
   2.121 @@ -145,19 +145,19 @@
   2.122      bool verbose_mode;
   2.123  
   2.124  
   2.125 -	IpEpEngineCallbacks* client_callbacks = NULL;
   2.126 +    IpEpEngineCallbacks* client_callbacks = NULL;
   2.127      IpEpEngineCallbacks* client_callbacks_on_sync_thread = NULL;
   2.128      IpEpEngineCallbacks2* client_callbacks2_on_sync_thread = NULL;
   2.129      bool client_last_signalled_polling_state = true;
   2.130  
   2.131 -	// Keysync members
   2.132 +    // Keysync members
   2.133      static int inject_sync_msg(void *msg, void* management);
   2.134      static void* retrieve_next_sync_msg(void* management, time_t *timeout);
   2.135      void start_keysync();
   2.136      static void do_keysync_in_thread(CpEpEngine* self, LPSTREAM marshaled_callbacks);
   2.137      void stop_keysync();
   2.138  
   2.139 -	static std::mutex init_mutex;
   2.140 +    static std::mutex init_mutex;
   2.141  
   2.142      std::recursive_mutex keysync_mutex;
   2.143      std::condition_variable_any keysync_condition;
   2.144 @@ -205,8 +205,8 @@
   2.145      STDMETHOD(GetCrashdumpLog)(LONG maxlines, BSTR * log);
   2.146      STDMETHOD(GetEngineVersion)(BSTR * engineVersion);
   2.147      STDMETHOD(GetLanguageList)(BSTR * languages);
   2.148 -	STDMETHOD(SetIdentityFlags)(struct pEpIdentity *identity, pEpIdentityFlags flags);
   2.149 -	STDMETHOD(UnsetIdentityFlags)(struct pEpIdentity *identity, pEpIdentityFlags flags);
   2.150 +    STDMETHOD(SetIdentityFlags)(struct pEpIdentity *identity, pEpIdentityFlags flags);
   2.151 +    STDMETHOD(UnsetIdentityFlags)(struct pEpIdentity *identity, pEpIdentityFlags flags);
   2.152  
   2.153      // keymanagement API
   2.154  
   2.155 @@ -218,7 +218,7 @@
   2.156      STDMETHOD(KeyMistrusted)(struct pEpIdentity *ident);
   2.157      STDMETHOD(KeyResetTrust)(struct pEpIdentity *ident);
   2.158      STDMETHOD(TrustPersonalKey)(struct pEpIdentity *ident, struct pEpIdentity *result);
   2.159 -	STDMETHOD(OwnIdentitiesRetrieve)(LPSAFEARRAY* ownIdentities);
   2.160 +    STDMETHOD(OwnIdentitiesRetrieve)(LPSAFEARRAY* ownIdentities);
   2.161  
   2.162      // Blacklist API
   2.163  
   2.164 @@ -234,28 +234,28 @@
   2.165      STDMETHOD(ReEvaluateMessageRating)(TextMessage * msg, SAFEARRAY * x_KeyList, pEpRating x_EncStatus, pEpRating *rating);
   2.166      STDMETHOD(OutgoingMessageRating)(TextMessage *msg, pEpRating * pVal);
   2.167      STDMETHOD(IdentityRating)(pEpIdentity * ident, pEpRating * pVal);
   2.168 -	STDMETHOD(ColorFromRating)(pEpRating rating, pEpColor * pVal);
   2.169 +    STDMETHOD(ColorFromRating)(pEpRating rating, pEpColor * pVal);
   2.170  
   2.171      STDMETHOD(EncryptMessageForSelf)(
   2.172 -        pEpIdentity * targetId, 
   2.173 +        pEpIdentity * targetId,
   2.174          TextMessage* src,
   2.175          TextMessage *dst,
   2.176          pEpEncryptFlags flags
   2.177          );
   2.178  
   2.179 -	// Event callbacks
   2.180 +    // Event callbacks
   2.181  
   2.182 -	STDMETHOD(RegisterCallbacks)(IpEpEngineCallbacks *new_callback);
   2.183 -	STDMETHOD(UnregisterCallbacks)();
   2.184 +    STDMETHOD(RegisterCallbacks)(IpEpEngineCallbacks *new_callback);
   2.185 +    STDMETHOD(UnregisterCallbacks)();
   2.186  
   2.187      // PGP compatibility functions
   2.188      STDMETHOD(OpenPGPListKeyinfo)(BSTR search_pattern, LPSAFEARRAY* keyinfo_list);
   2.189  
   2.190 -	STDMETHOD(UndoLastMistrust)();
   2.191 +    STDMETHOD(UndoLastMistrust)();
   2.192  
   2.193  protected:
   2.194 -	HRESULT Fire_MessageToSend(
   2.195 -		/* [in] */ struct TextMessage *msg);
   2.196 +    HRESULT Fire_MessageToSend(
   2.197 +        /* [in] */ struct TextMessage *msg);
   2.198  };
   2.199  
   2.200  OBJECT_ENTRY_AUTO(__uuidof(pEpEngine), CpEpEngine)
     3.1 --- a/GateKeeper.cpp	Thu Feb 01 23:30:55 2018 +0100
     3.2 +++ b/GateKeeper.cpp	Fri Feb 02 22:03:16 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	Thu Feb 01 23:30:55 2018 +0100
     4.2 +++ b/GateKeeper.h	Fri Feb 02 22:03:16 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	Thu Feb 01 23:30:55 2018 +0100
     5.2 +++ b/locked_queue.hh	Fri Feb 02 22:03:16 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	Thu Feb 01 23:30:55 2018 +0100
     6.2 +++ b/pEpCOMServerAdapter.cpp	Fri Feb 02 22:03:16 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	Thu Feb 01 23:30:55 2018 +0100
     7.2 +++ b/pEpCOMServerAdapter.idl	Fri Feb 02 22:03:16 2018 +0100
     7.3 @@ -53,7 +53,7 @@
     7.4      nonextensible,
     7.5      pointer_default(unique)
     7.6  ]
     7.7 -interface IpEpEngineCallbacks2 : IpEpEngineCallbacks 
     7.8 +interface IpEpEngineCallbacks2 : IpEpEngineCallbacks
     7.9  {
    7.10      [id(3)] HRESULT NeedFastPolling([in] VARIANT_BOOL enableFastPolling);
    7.11  };
    7.12 @@ -146,93 +146,93 @@
    7.13          pEpCtpEp = 0xff
    7.14      } pEpComType;
    7.15  
    7.16 -        typedef enum pEpStatus {
    7.17 -                pEpStatusOk = 0,
    7.18 +    typedef enum pEpStatus {
    7.19 +        pEpStatusOk = 0,
    7.20  
    7.21 -                pEpInitCannotLoadGpgme = 0x0110,
    7.22 -                pEpInitGpgmeInitFailed = 0x0111,
    7.23 -                pEpInitNoGpgHome = 0x0112,
    7.24 -                pEpInitNetpgpInitFailed = 0x0113,
    7.25 -                pEpInitCannotDetermineGpgVersion = 0x0114,
    7.26 -                pEpInitUnsupportedGpgVersion = 0x0115,
    7.27 -                pEpInitCannotConfigGpgAgent = 0x0116,
    7.28 +        pEpInitCannotLoadGpgme = 0x0110,
    7.29 +        pEpInitGpgmeInitFailed = 0x0111,
    7.30 +        pEpInitNoGpgHome = 0x0112,
    7.31 +        pEpInitNetpgpInitFailed = 0x0113,
    7.32 +        pEpInitCannotDetermineGpgVersion = 0x0114,
    7.33 +        pEpInitUnsupportedGpgVersion = 0x0115,
    7.34 +        pEpInitCannotConfigGpgAgent = 0x0116,
    7.35  
    7.36 -                pEpInitSqlite3WithoutMutex = 0x0120,
    7.37 -                pEpInitCannotOpenDb = 0x0121,
    7.38 -                pEpInitCannotOpenSystemDb = 0x0122,
    7.39 +        pEpInitSqlite3WithoutMutex = 0x0120,
    7.40 +        pEpInitCannotOpenDb = 0x0121,
    7.41 +        pEpInitCannotOpenSystemDb = 0x0122,
    7.42  
    7.43 -                pEpKeyNotFound = 0x0201,
    7.44 -                pEpKeyHasAmbigName = 0x0202,
    7.45 -                pEpGetKeyFailed = 0x0203,
    7.46 -                pEpCannotExportKey = 0x0204,
    7.47 -                pEpCannotEditKey = 0x0205,
    7.48 -                pEpKeyUnsuitable = 0x0206,
    7.49 +        pEpKeyNotFound = 0x0201,
    7.50 +        pEpKeyHasAmbigName = 0x0202,
    7.51 +        pEpGetKeyFailed = 0x0203,
    7.52 +        pEpCannotExportKey = 0x0204,
    7.53 +        pEpCannotEditKey = 0x0205,
    7.54 +        pEpKeyUnsuitable = 0x0206,
    7.55  
    7.56 -                pEpCannotFindIdentity = 0x0301,
    7.57 -                pEpCannotSetPerson = 0x0381,
    7.58 -                pEpCannotSetPgpKeypair = 0x0382,
    7.59 -                pEpCannotSetIdentity = 0x0383,
    7.60 -                pEpCannotSetTrust = 0x0384,
    7.61 -                pEpKeyBlacklisted = 0x0385,
    7.62 -                pEpCannotFindPerson = 0x0386,
    7.63 +        pEpCannotFindIdentity = 0x0301,
    7.64 +        pEpCannotSetPerson = 0x0381,
    7.65 +        pEpCannotSetPgpKeypair = 0x0382,
    7.66 +        pEpCannotSetIdentity = 0x0383,
    7.67 +        pEpCannotSetTrust = 0x0384,
    7.68 +        pEpKeyBlacklisted = 0x0385,
    7.69 +        pEpCannotFindPerson = 0x0386,
    7.70  
    7.71 -                pEpCannotFindAlias = 0x0391,
    7.72 -                pEpCannotSetAlias = 0x0392,
    7.73 +        pEpCannotFindAlias = 0x0391,
    7.74 +        pEpCannotSetAlias = 0x0392,
    7.75  
    7.76 -                pEpUnencrypted = 0x0400,
    7.77 -                pEpVerified = 0x0401,
    7.78 -                pEpDecrypted = 0x0402,
    7.79 -                pEpDecryptedAndVerified = 0x0403,
    7.80 -                pEpDecryptWrongFormat = 0x0404,
    7.81 -                pEpDecryptNoKey = 0x0405,
    7.82 -                pEpDecryptSignatureDoesNotMatch = 0x0406,
    7.83 -                pEpVerifyNoKey = 0x0407,
    7.84 -                pEpVerifiedAndTrusted = 0x0408,
    7.85 -                pEpCannotDecryptUnknown = 0x04ff,
    7.86 +        pEpUnencrypted = 0x0400,
    7.87 +        pEpVerified = 0x0401,
    7.88 +        pEpDecrypted = 0x0402,
    7.89 +        pEpDecryptedAndVerified = 0x0403,
    7.90 +        pEpDecryptWrongFormat = 0x0404,
    7.91 +        pEpDecryptNoKey = 0x0405,
    7.92 +        pEpDecryptSignatureDoesNotMatch = 0x0406,
    7.93 +        pEpVerifyNoKey = 0x0407,
    7.94 +        pEpVerifiedAndTrusted = 0x0408,
    7.95 +        pEpCannotDecryptUnknown = 0x04ff,
    7.96  
    7.97 -                pEpTrustwordNotFound = 0x0501,
    7.98 -                pEpTrustwordsFprWrongLength = 0x0502,
    7.99 -                pEpTrustwordsDuplicateFpr = 0x0503,
   7.100 +        pEpTrustwordNotFound = 0x0501,
   7.101 +        pEpTrustwordsFprWrongLength = 0x0502,
   7.102 +        pEpTrustwordsDuplicateFpr = 0x0503,
   7.103  
   7.104 -                pEpCannotCreateKey = 0x0601,
   7.105 -                pEpCannotSendKey = 0x0602,
   7.106 +        pEpCannotCreateKey = 0x0601,
   7.107 +        pEpCannotSendKey = 0x0602,
   7.108  
   7.109 -                pEpPhraseNotFound = 0x0701,
   7.110 +        pEpPhraseNotFound = 0x0701,
   7.111  
   7.112 -                pEpSendFunctionNotRegistered = 0x0801,
   7.113 -                pEpContraintsViolated = 0x0802,
   7.114 -                pEpCannotEncode = 0x0803,
   7.115 +        pEpSendFunctionNotRegistered = 0x0801,
   7.116 +        pEpContraintsViolated = 0x0802,
   7.117 +        pEpCannotEncode = 0x0803,
   7.118  
   7.119 -                pEpSyncNoNotifyCallback = 0x0901,
   7.120 -                pEpSyncIllegalMessage = 0x0902,
   7.121 -                pEpSyncNoInjectCallback = 0x0903,
   7.122 +        pEpSyncNoNotifyCallback = 0x0901,
   7.123 +        pEpSyncIllegalMessage = 0x0902,
   7.124 +        pEpSyncNoInjectCallback = 0x0903,
   7.125  
   7.126 -                pEpSequenceViolated = 0x0970,
   7.127 -                pEpCannotIncreaseSequence = 0x0971,
   7.128 -                pEpCannotSetSequenceValue = 0x0972,
   7.129 -                pEpOwnSequence = 0x097f,
   7.130 +        pEpSequenceViolated = 0x0970,
   7.131 +        pEpCannotIncreaseSequence = 0x0971,
   7.132 +        pEpCannotSetSequenceValue = 0x0972,
   7.133 +        pEpOwnSequence = 0x097f,
   7.134  
   7.135 -                pEpSyncStatemachineError = 0x0980,
   7.136 -                pEpSyncNoTrust = 0x0981,
   7.137 -                pEpStatemachineInvalidState = 0x0982,
   7.138 -                pEpStatemachineInvalidEvent = 0x0983,
   7.139 -                pEpStatemachineInvalidCondition = 0x0984,
   7.140 -                pEpStatemachineInvalidAction = 0x0985,
   7.141 -                pEpStatemachineInhibitedEvent = 0x0986,
   7.142 +        pEpSyncStatemachineError = 0x0980,
   7.143 +        pEpSyncNoTrust = 0x0981,
   7.144 +        pEpStatemachineInvalidState = 0x0982,
   7.145 +        pEpStatemachineInvalidEvent = 0x0983,
   7.146 +        pEpStatemachineInvalidCondition = 0x0984,
   7.147 +        pEpStatemachineInvalidAction = 0x0985,
   7.148 +        pEpStatemachineInhibitedEvent = 0x0986,
   7.149  
   7.150 -                pEpCommitFailed = 0xff01,
   7.151 -                pEpMessageConsume = 0xff02,
   7.152 -                pEpMessageIgnore = 0xff03,
   7.153 +        pEpCommitFailed = 0xff01,
   7.154 +        pEpMessageConsume = 0xff02,
   7.155 +        pEpMessageIgnore = 0xff03,
   7.156  
   7.157 -                pEpRecordNotFound = -6,
   7.158 -                pEpCannotCreateTempFile = -5,
   7.159 -                pEpIllegalValue = -4,
   7.160 -                pEpBufferTooSmall = -3,
   7.161 -                pEpOutOfMemory = -2,
   7.162 -                pEpUnknownError = -1,
   7.163 +        pEpRecordNotFound = -6,
   7.164 +        pEpCannotCreateTempFile = -5,
   7.165 +        pEpIllegalValue = -4,
   7.166 +        pEpBufferTooSmall = -3,
   7.167 +        pEpOutOfMemory = -2,
   7.168 +        pEpUnknownError = -1,
   7.169  
   7.170 -                pEpVersionMismatch = -7,
   7.171 -        } pEpStatus;
   7.172 +        pEpVersionMismatch = -7,
   7.173 +    } pEpStatus;
   7.174  
   7.175      typedef [v1_enum] enum pEpIdentityFlags {
   7.176          pEpIdfNone = 0,
   7.177 @@ -403,7 +403,7 @@
   7.178  
   7.179      HRESULT EncryptMessageForSelf(
   7.180          [in] struct pEpIdentity* targetId,
   7.181 -        [in] struct TextMessage* src, 
   7.182 +        [in] struct TextMessage* src,
   7.183          [out] struct TextMessage* dst,
   7.184          [in, defaultvalue(pEpEncryptFlagDefault)] pEpEncryptFlags flags
   7.185      );
   7.186 @@ -415,7 +415,7 @@
   7.187          [out, retval] pEpRating *rating
   7.188      );
   7.189  
   7.190 -        HRESULT UndoLastMistrust();
   7.191 +    HRESULT UndoLastMistrust();
   7.192  };
   7.193  
   7.194  [
     8.1 --- a/pEp_utility.cpp	Thu Feb 01 23:30:55 2018 +0100
     8.2 +++ b/pEp_utility.cpp	Fri Feb 02 22:03:16 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	Thu Feb 01 23:30:55 2018 +0100
     9.2 +++ b/pEp_utility.h	Fri Feb 02 22:03:16 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	Thu Feb 01 23:30:55 2018 +0100
    10.2 +++ b/utf8_helper.cpp	Fri Feb 02 22:03:16 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	Thu Feb 01 23:30:55 2018 +0100
    11.2 +++ b/xdlldata.h	Fri Feb 02 22:03:16 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