Don't fail on invalid characters during conversion and catch errors sync
authorThomas
Tue, 22 Oct 2019 12:41:11 +0200
branchsync
changeset 3642259aa4c6a64
parent 363 4527e87ee120
child 365 afa3b4763d5d
Don't fail on invalid characters during conversion and catch errors
CpEpEngine.cpp
GateKeeper.cpp
utf8_helper.cpp
     1.1 --- a/CpEpEngine.cpp	Mon Oct 21 10:56:57 2019 +0200
     1.2 +++ b/CpEpEngine.cpp	Tue Oct 22 12:41:11 2019 +0200
     1.3 @@ -60,54 +60,54 @@
     1.4  
     1.5  STDMETHODIMP CpEpEngine::ConfigCipherSuite(pEpCipherSuite cipherSuite)
     1.6  {
     1.7 -	PEP_STATUS status = ::config_cipher_suite(session(), (PEP_CIPHER_SUITE)cipherSuite);
     1.8 +    PEP_STATUS status = ::config_cipher_suite(session(), (PEP_CIPHER_SUITE)cipherSuite);
     1.9  
    1.10 -	if (status)
    1.11 -		return FAIL(L"config_cipher_suite", status);
    1.12 -	
    1.13 -	return S_OK;
    1.14 +    if (status)
    1.15 +        return FAIL(L"config_cipher_suite", status);
    1.16 +    
    1.17 +    return S_OK;
    1.18  }
    1.19  
    1.20  STDMETHODIMP CpEpEngine::ImportKey(BSTR keyData, LPSAFEARRAY * privateKeys)
    1.21  {
    1.22 -	assert(keyData);
    1.23 +    assert(keyData);
    1.24  
    1.25 -	if (!keyData)
    1.26 -		return E_INVALIDARG;
    1.27 +    if (!keyData)
    1.28 +        return E_INVALIDARG;
    1.29  
    1.30 -	string key_data = utf8_string(keyData);
    1.31 -	size_t size = SysStringLen(keyData);
    1.32 -	::identity_list *private_keys = nullptr;
    1.33 +    string key_data = utf8_string(keyData);
    1.34 +    size_t size = SysStringLen(keyData);
    1.35 +    ::identity_list *private_keys = nullptr;
    1.36  
    1.37 -	PEP_STATUS status = ::import_key(session(), key_data.c_str(), size, &private_keys);
    1.38 -	assert(status != ::PEP_OUT_OF_MEMORY);
    1.39 -	if (status == ::PEP_OUT_OF_MEMORY)
    1.40 -		return E_OUTOFMEMORY;
    1.41 +    PEP_STATUS status = ::import_key(session(), key_data.c_str(), size, &private_keys);
    1.42 +    assert(status != ::PEP_OUT_OF_MEMORY);
    1.43 +    if (status == ::PEP_OUT_OF_MEMORY)
    1.44 +        return E_OUTOFMEMORY;
    1.45  
    1.46 -	if ((status != PEP_STATUS_OK) && (status != PEP_KEY_IMPORTED))
    1.47 -		return FAIL(L"import_key", status);
    1.48 +    if ((status != PEP_STATUS_OK) && (status != PEP_KEY_IMPORTED))
    1.49 +        return FAIL(L"import_key", status);
    1.50  
    1.51 -	SAFEARRAY * _privateKeys = nullptr;
    1.52 -	try {
    1.53 -		_privateKeys = array_from_C<pEpIdentity, identity_list>(private_keys);
    1.54 -	}
    1.55 -	catch (exception& ex)
    1.56 -	{
    1.57 -		::free_identity_list(private_keys);
    1.58 -		try {
    1.59 -			dynamic_cast<bad_alloc&>(ex);
    1.60 -		}
    1.61 -		catch (bad_cast&)
    1.62 -		{
    1.63 -			return FAIL(ex.what());
    1.64 -		}
    1.65 -		return E_OUTOFMEMORY;
    1.66 -	}
    1.67 -	free_identity_list(private_keys);
    1.68 +    SAFEARRAY * _privateKeys = nullptr;
    1.69 +    try {
    1.70 +        _privateKeys = array_from_C<pEpIdentity, identity_list>(private_keys);
    1.71 +    }
    1.72 +    catch (exception& ex)
    1.73 +    {
    1.74 +        ::free_identity_list(private_keys);
    1.75 +        try {
    1.76 +            dynamic_cast<bad_alloc&>(ex);
    1.77 +        }
    1.78 +        catch (bad_cast&)
    1.79 +        {
    1.80 +            return FAIL(ex.what());
    1.81 +        }
    1.82 +        return E_OUTOFMEMORY;
    1.83 +    }
    1.84 +    free_identity_list(private_keys);
    1.85  
    1.86 -	*privateKeys = _privateKeys;
    1.87 +    *privateKeys = _privateKeys;
    1.88  
    1.89 -	return status;
    1.90 +    return status;
    1.91  }
    1.92  
    1.93  
    1.94 @@ -140,15 +140,15 @@
    1.95  
    1.96  STDMETHODIMP CpEpEngine::LeaveDeviceGroup()
    1.97  {
    1.98 -	PEP_STATUS status = ::leave_device_group(session());
    1.99 +    PEP_STATUS status = ::leave_device_group(session());
   1.100  
   1.101 -	if (status == PEP_OUT_OF_MEMORY)
   1.102 -		return E_OUTOFMEMORY;
   1.103 +    if (status == PEP_OUT_OF_MEMORY)
   1.104 +        return E_OUTOFMEMORY;
   1.105  
   1.106 -	if (status != PEP_STATUS_OK)
   1.107 -		return FAIL(L"cannot leave device group", status);
   1.108 +    if (status != PEP_STATUS_OK)
   1.109 +        return FAIL(L"cannot leave device group", status);
   1.110  
   1.111 -	return S_OK;
   1.112 +    return S_OK;
   1.113  }
   1.114  
   1.115  STDMETHODIMP CpEpEngine::Log(BSTR title, BSTR entity, BSTR description, BSTR comment)
   1.116 @@ -245,67 +245,67 @@
   1.117  
   1.118  STDMETHODIMP CpEpEngine::GetTrustwordsForFprs(BSTR fpr1, BSTR fpr2, BSTR lang, VARIANT_BOOL full, BSTR *words)
   1.119  {
   1.120 -	assert(fpr1);
   1.121 -	assert(fpr2);
   1.122 -	assert(words);
   1.123 +    assert(fpr1);
   1.124 +    assert(fpr2);
   1.125 +    assert(words);
   1.126  
   1.127 -	if (!(fpr1 && fpr2 && words))
   1.128 -	{
   1.129 -		return E_INVALIDARG;
   1.130 -	}
   1.131 +    if (!(fpr1 && fpr2 && words))
   1.132 +    {
   1.133 +        return E_INVALIDARG;
   1.134 +    }
   1.135  
   1.136 -	HRESULT result = S_OK;
   1.137 -	string _fpr1;
   1.138 -	string _fpr2;
   1.139 -	string _lang;
   1.140 -	*words = NULL;
   1.141 +    HRESULT result = S_OK;
   1.142 +    string _fpr1;
   1.143 +    string _fpr2;
   1.144 +    string _lang;
   1.145 +    *words = NULL;
   1.146  
   1.147 -	try {
   1.148 +    try {
   1.149  
   1.150 -		_fpr1 = utf8_string(fpr1);
   1.151 -		_fpr2 = utf8_string(fpr2);
   1.152 -		
   1.153 -		if (lang) {
   1.154 -			_lang = utf8_string(lang);
   1.155 -			if (_lang.length() == 0) {
   1.156 -				_lang = "en";
   1.157 -			}
   1.158 -			else if (_lang.length() != 2) {
   1.159 -				result = E_INVALIDARG;
   1.160 -			}
   1.161 -		}
   1.162 -		else {
   1.163 -			_lang = "en";
   1.164 -		}
   1.165 -	}
   1.166 -	catch (bad_alloc&) {
   1.167 -		result = E_OUTOFMEMORY;
   1.168 -	}
   1.169 -	catch (exception& ex) {
   1.170 -		result = FAIL(ex.what());
   1.171 -	}
   1.172 +        _fpr1 = utf8_string(fpr1);
   1.173 +        _fpr2 = utf8_string(fpr2);
   1.174 +        
   1.175 +        if (lang) {
   1.176 +            _lang = utf8_string(lang);
   1.177 +            if (_lang.length() == 0) {
   1.178 +                _lang = "en";
   1.179 +            }
   1.180 +            else if (_lang.length() != 2) {
   1.181 +                result = E_INVALIDARG;
   1.182 +            }
   1.183 +        }
   1.184 +        else {
   1.185 +            _lang = "en";
   1.186 +        }
   1.187 +    }
   1.188 +    catch (bad_alloc&) {
   1.189 +        result = E_OUTOFMEMORY;
   1.190 +    }
   1.191 +    catch (exception& ex) {
   1.192 +        result = FAIL(ex.what());
   1.193 +    }
   1.194  
   1.195 -	char* _words;
   1.196 -	size_t _size;
   1.197 -	if (result == S_OK) {
   1.198 -		auto status = ::get_trustwords_for_fprs(session(), _fpr1.c_str(), _fpr2.c_str(), _lang.c_str(), &_words, &_size, full != 0 /* convert variant bool to C bool */);
   1.199 +    char* _words;
   1.200 +    size_t _size;
   1.201 +    if (result == S_OK) {
   1.202 +        auto status = ::get_trustwords_for_fprs(session(), _fpr1.c_str(), _fpr2.c_str(), _lang.c_str(), &_words, &_size, full != 0 /* convert variant bool to C bool */);
   1.203  
   1.204 -		if (status == PEP_OUT_OF_MEMORY) {
   1.205 -			result = E_OUTOFMEMORY;
   1.206 -		}
   1.207 -		else if (status == PEP_TRUSTWORD_NOT_FOUND) {
   1.208 -			result = FAIL(L"GetTrustwords: Trustword not found", status);
   1.209 -		}
   1.210 -		else if (!words) {
   1.211 -			result = FAIL(L"GetTrustwords: _words == NULL", status);
   1.212 -		}
   1.213 -		else {
   1.214 -			*words = utf16_bstr(_words);
   1.215 -			pEp_free(_words);
   1.216 -		}
   1.217 -	}
   1.218 +        if (status == PEP_OUT_OF_MEMORY) {
   1.219 +            result = E_OUTOFMEMORY;
   1.220 +        }
   1.221 +        else if (status == PEP_TRUSTWORD_NOT_FOUND) {
   1.222 +            result = FAIL(L"GetTrustwords: Trustword not found", status);
   1.223 +        }
   1.224 +        else if (!words) {
   1.225 +            result = FAIL(L"GetTrustwords: _words == NULL", status);
   1.226 +        }
   1.227 +        else {
   1.228 +            *words = utf16_bstr(_words);
   1.229 +            pEp_free(_words);
   1.230 +        }
   1.231 +    }
   1.232  
   1.233 -	return result;
   1.234 +    return result;
   1.235  }
   1.236  
   1.237  STDMETHODIMP CpEpEngine::GetTrustwords(struct pEpIdentity *id1, struct pEpIdentity *id2, BSTR lang, VARIANT_BOOL full, BSTR *words)
   1.238 @@ -775,66 +775,66 @@
   1.239  
   1.240  STDMETHODIMP CpEpEngine::KeyResetIdentity(struct pEpIdentity ident, BSTR fpr)
   1.241  {
   1.242 -	::pEp_identity *_ident;
   1.243 +    ::pEp_identity *_ident;
   1.244  
   1.245 -	try {
   1.246 -		_ident = new_identity(&ident);
   1.247 -	}
   1.248 -	catch (bad_alloc&) {
   1.249 -		return E_OUTOFMEMORY;
   1.250 -	}
   1.251 -	catch (exception& ex) {
   1.252 -		return FAIL(ex.what());;
   1.253 -	}
   1.254 +    try {
   1.255 +        _ident = new_identity(&ident);
   1.256 +    }
   1.257 +    catch (bad_alloc&) {
   1.258 +        return E_OUTOFMEMORY;
   1.259 +    }
   1.260 +    catch (exception& ex) {
   1.261 +        return FAIL(ex.what());;
   1.262 +    }
   1.263  
   1.264 -	string _fpr = utf8_string(fpr);
   1.265 +    string _fpr = utf8_string(fpr);
   1.266  
   1.267 -	PEP_STATUS status = ::key_reset_identity(session(), _ident, _fpr.c_str());
   1.268 +    PEP_STATUS status = ::key_reset_identity(session(), _ident, _fpr.c_str());
   1.269  
   1.270 -	free_identity(_ident);
   1.271 +    free_identity(_ident);
   1.272  
   1.273 -	if (status == PEP_OUT_OF_MEMORY)
   1.274 -		return E_OUTOFMEMORY;
   1.275 +    if (status == PEP_OUT_OF_MEMORY)
   1.276 +        return E_OUTOFMEMORY;
   1.277  
   1.278 -	if (status == PEP_KEY_NOT_FOUND)
   1.279 -		return FAIL(L"key not found");
   1.280 +    if (status == PEP_KEY_NOT_FOUND)
   1.281 +        return FAIL(L"key not found");
   1.282  
   1.283 -	if (status != PEP_STATUS_OK)
   1.284 -		return FAIL(L"cannot reset identity", status);
   1.285 +    if (status != PEP_STATUS_OK)
   1.286 +        return FAIL(L"cannot reset identity", status);
   1.287  
   1.288 -	return S_OK;
   1.289 +    return S_OK;
   1.290  }
   1.291  
   1.292  STDMETHODIMP CpEpEngine::KeyResetUser(BSTR userId, BSTR fpr)
   1.293  {
   1.294 -	string _userId = utf8_string(userId);
   1.295 -	string _fpr = utf8_string(fpr);
   1.296 +    string _userId = utf8_string(userId);
   1.297 +    string _fpr = utf8_string(fpr);
   1.298  
   1.299 -	PEP_STATUS status = ::key_reset_user(session(), _userId.c_str(), _fpr.c_str());
   1.300 +    PEP_STATUS status = ::key_reset_user(session(), _userId.c_str(), _fpr.c_str());
   1.301  
   1.302 -	if (status == PEP_OUT_OF_MEMORY)
   1.303 -		return E_OUTOFMEMORY;
   1.304 +    if (status == PEP_OUT_OF_MEMORY)
   1.305 +        return E_OUTOFMEMORY;
   1.306  
   1.307 -	if (status == PEP_KEY_NOT_FOUND)
   1.308 -		return FAIL(L"key not found");
   1.309 +    if (status == PEP_KEY_NOT_FOUND)
   1.310 +        return FAIL(L"key not found");
   1.311  
   1.312 -	if (status != PEP_STATUS_OK)
   1.313 -		return FAIL(L"cannot reset user", status);
   1.314 +    if (status != PEP_STATUS_OK)
   1.315 +        return FAIL(L"cannot reset user", status);
   1.316  
   1.317 -	return S_OK;
   1.318 +    return S_OK;
   1.319  }
   1.320  
   1.321  STDMETHODIMP CpEpEngine::KeyResetAllOwnKeys()
   1.322  {
   1.323 -	PEP_STATUS status = ::key_reset_all_own_keys(session());
   1.324 +    PEP_STATUS status = ::key_reset_all_own_keys(session());
   1.325  
   1.326 -	if (status == PEP_OUT_OF_MEMORY)
   1.327 -		return E_OUTOFMEMORY;
   1.328 +    if (status == PEP_OUT_OF_MEMORY)
   1.329 +        return E_OUTOFMEMORY;
   1.330  
   1.331 -	if (status != PEP_STATUS_OK)
   1.332 -		return FAIL(L"cannot reset all own keys", status);
   1.333 +    if (status != PEP_STATUS_OK)
   1.334 +        return FAIL(L"cannot reset all own keys", status);
   1.335  
   1.336 -	return S_OK;
   1.337 +    return S_OK;
   1.338  }
   1.339  
   1.340  STDMETHODIMP CpEpEngine::KeyResetTrust(struct pEpIdentity *ident)
   1.341 @@ -1114,7 +1114,16 @@
   1.342      if (!(src && dst))
   1.343          return E_INVALIDARG;
   1.344  
   1.345 -    ::message *_src = text_message_to_C(src);
   1.346 +    ::message *_src = NULL;
   1.347 +    try {
   1.348 +        _src = text_message_to_C(src);
   1.349 +    }
   1.350 +    catch (bad_alloc&) {
   1.351 +        return E_OUTOFMEMORY;
   1.352 +    }
   1.353 +    catch (exception& ex) {
   1.354 +        return FAIL(ex.what());
   1.355 +    }
   1.356  
   1.357      _PEP_enc_format _encFormat = (_PEP_enc_format)encFormat;
   1.358  
   1.359 @@ -1166,7 +1175,16 @@
   1.360      if (!(src && dst))
   1.361          return E_INVALIDARG;
   1.362  
   1.363 -    ::message *_src = text_message_to_C(src);
   1.364 +    ::message *_src = NULL;
   1.365 +    try {
   1.366 +        _src = text_message_to_C(src);
   1.367 +    }
   1.368 +    catch (bad_alloc&) {
   1.369 +        return E_OUTOFMEMORY;
   1.370 +    }
   1.371 +    catch (exception& ex) {
   1.372 +        return FAIL(ex.what());
   1.373 +    }
   1.374  
   1.375      _PEP_enc_format _encFormat = (_PEP_enc_format)encFormat;
   1.376  
   1.377 @@ -1222,7 +1240,16 @@
   1.378  
   1.379      ::pEp_identity *_target_id = new_identity(targetId);
   1.380  
   1.381 -    ::message *_src = text_message_to_C(src);
   1.382 +    ::message *_src = NULL;
   1.383 +    try {
   1.384 +        _src = text_message_to_C(src);
   1.385 +    }
   1.386 +    catch (bad_alloc&) {
   1.387 +        return E_OUTOFMEMORY;
   1.388 +    }
   1.389 +    catch (exception& ex) {
   1.390 +        return FAIL(ex.what());
   1.391 +    }
   1.392  
   1.393      ::stringlist_t* _extra = NULL;
   1.394      HRESULT result = S_OK;
   1.395 @@ -1279,7 +1306,16 @@
   1.396  
   1.397      *rating = pEpRatingUndefined;
   1.398  
   1.399 -    ::message *_src = text_message_to_C(src);
   1.400 +    ::message *_src = NULL;
   1.401 +    try {
   1.402 +        _src = text_message_to_C(src);
   1.403 +    }
   1.404 +    catch (bad_alloc&) {
   1.405 +        return E_OUTOFMEMORY;
   1.406 +    }
   1.407 +    catch (exception& ex) {
   1.408 +        return FAIL(ex.what());
   1.409 +    }
   1.410      ::message *msg_dst = NULL;
   1.411      ::stringlist_t *_keylist = new_stringlist(*keylist);
   1.412      ::PEP_rating _rating;
   1.413 @@ -1319,7 +1355,17 @@
   1.414  
   1.415      *rating = pEpRatingUndefined;
   1.416  
   1.417 -    ::message *_msg = text_message_to_C(msg);
   1.418 +    ::message *_msg = NULL;
   1.419 +    try {
   1.420 +        _msg = text_message_to_C(msg);
   1.421 +    }
   1.422 +    catch (bad_alloc&) {
   1.423 +        return E_OUTOFMEMORY;
   1.424 +    }
   1.425 +    catch (exception& ex) {
   1.426 +        return FAIL(ex.what());
   1.427 +    }
   1.428 +
   1.429      ::stringlist_t *_keylist = new_stringlist(x_KeyList);
   1.430      ::PEP_rating _rating = PEP_rating_undefined;
   1.431  
   1.432 @@ -1341,7 +1387,16 @@
   1.433      if (!(msg  && pVal))
   1.434          return E_INVALIDARG;
   1.435  
   1.436 -    ::message *_msg = text_message_to_C(msg);
   1.437 +    ::message *_msg = NULL;
   1.438 +    try {
   1.439 +        _msg = text_message_to_C(msg);
   1.440 +    }
   1.441 +    catch (bad_alloc&) {
   1.442 +        return E_OUTOFMEMORY;
   1.443 +    }
   1.444 +    catch (exception& ex) {
   1.445 +        return FAIL(ex.what());
   1.446 +    }
   1.447  
   1.448      PEP_rating _rating;
   1.449      PEP_STATUS status = ::outgoing_message_rating(session(), _msg, &_rating);
   1.450 @@ -1354,21 +1409,30 @@
   1.451  
   1.452  STDMETHODIMP CpEpEngine::OutgoingMessageRatingPreview(TextMessage *msg, pEpRating * pVal)
   1.453  {
   1.454 -	assert(msg);
   1.455 -	assert(pVal);
   1.456 +    assert(msg);
   1.457 +    assert(pVal);
   1.458  
   1.459 -	if (!(msg  && pVal))
   1.460 -		return E_INVALIDARG;
   1.461 +    if (!(msg  && pVal))
   1.462 +        return E_INVALIDARG;
   1.463  
   1.464 -	::message *_msg = text_message_to_C(msg);
   1.465 +    ::message *_msg = NULL;
   1.466 +    try {
   1.467 +        _msg = text_message_to_C(msg);
   1.468 +    }
   1.469 +    catch (bad_alloc&) {
   1.470 +        return E_OUTOFMEMORY;
   1.471 +    }
   1.472 +    catch (exception& ex) {
   1.473 +        return FAIL(ex.what());
   1.474 +    }
   1.475  
   1.476 -	PEP_rating _rating;
   1.477 -	PEP_STATUS status = ::outgoing_message_rating_preview(session(), _msg, &_rating);
   1.478 -	if (status != PEP_STATUS_OK)
   1.479 -		return FAIL(L"cannot get message rating", status);
   1.480 +    PEP_rating _rating;
   1.481 +    PEP_STATUS status = ::outgoing_message_rating_preview(session(), _msg, &_rating);
   1.482 +    if (status != PEP_STATUS_OK)
   1.483 +        return FAIL(L"cannot get message rating", status);
   1.484  
   1.485 -	*pVal = (pEpRating)_rating;
   1.486 -	return S_OK;
   1.487 +    *pVal = (pEpRating)_rating;
   1.488 +    return S_OK;
   1.489  }
   1.490  
   1.491  STDMETHODIMP CpEpEngine::IdentityRating(struct pEpIdentity *ident, pEpRating * pVal)
   1.492 @@ -1413,7 +1477,7 @@
   1.493      PEP_color _color = ::color_from_rating(engineRating);
   1.494  
   1.495      *pVal = (pEpColor)_color;
   1.496 -	 
   1.497 +     
   1.498      return S_OK;
   1.499  }
   1.500  
   1.501 @@ -1612,286 +1676,296 @@
   1.502  
   1.503  STDMETHODIMP CpEpEngine::SetOwnKey(pEpIdentity * ident, BSTR fpr, struct pEpIdentity *result)
   1.504  {
   1.505 -	assert(ident);
   1.506 -	assert(result);
   1.507 -	assert(fpr);
   1.508 +    assert(ident);
   1.509 +    assert(result);
   1.510 +    assert(fpr);
   1.511  
   1.512 -	if (!(ident && result))
   1.513 -		return E_INVALIDARG;
   1.514 +    if (!(ident && result))
   1.515 +        return E_INVALIDARG;
   1.516  
   1.517 -	::pEp_identity *_ident;
   1.518 -	try {
   1.519 -		_ident = new_identity(ident);
   1.520 -	}
   1.521 -	catch (bad_alloc&) {
   1.522 -		return E_OUTOFMEMORY;
   1.523 -	}
   1.524 -	catch (exception& ex) {
   1.525 -		return FAIL(ex.what());
   1.526 -	}
   1.527 +    ::pEp_identity *_ident;
   1.528 +    try {
   1.529 +        _ident = new_identity(ident);
   1.530 +    }
   1.531 +    catch (bad_alloc&) {
   1.532 +        return E_OUTOFMEMORY;
   1.533 +    }
   1.534 +    catch (exception& ex) {
   1.535 +        return FAIL(ex.what());
   1.536 +    }
   1.537  
   1.538 -	assert(_ident);
   1.539 -	if (_ident == NULL)
   1.540 -		return E_OUTOFMEMORY;
   1.541 +    assert(_ident);
   1.542 +    if (_ident == NULL)
   1.543 +        return E_OUTOFMEMORY;
   1.544  
   1.545 -	string _fpr = utf8_string(fpr);
   1.546 -	PEP_STATUS status = ::set_own_key(session(), _ident, _fpr.c_str());
   1.547 +    string _fpr = utf8_string(fpr);
   1.548 +    PEP_STATUS status = ::set_own_key(session(), _ident, _fpr.c_str());
   1.549  
   1.550 -	if (status == PEP_STATUS_OK) {
   1.551 -		copy_identity(result, _ident);
   1.552 -		::free_identity(_ident);
   1.553 -		return S_OK;
   1.554 -	}
   1.555 -	else {
   1.556 -		::free_identity(_ident);
   1.557 -		if (status == PEP_OUT_OF_MEMORY)
   1.558 -			return E_OUTOFMEMORY;
   1.559 -		else
   1.560 -			return FAIL(L"SetOwnKey", status);
   1.561 -	}
   1.562 +    if (status == PEP_STATUS_OK) {
   1.563 +        copy_identity(result, _ident);
   1.564 +        ::free_identity(_ident);
   1.565 +        return S_OK;
   1.566 +    }
   1.567 +    else {
   1.568 +        ::free_identity(_ident);
   1.569 +        if (status == PEP_OUT_OF_MEMORY)
   1.570 +            return E_OUTOFMEMORY;
   1.571 +        else
   1.572 +            return FAIL(L"SetOwnKey", status);
   1.573 +    }
   1.574  
   1.575 -	return S_OK;
   1.576 +    return S_OK;
   1.577  }
   1.578  
   1.579  STDMETHODIMP CpEpEngine::TrustOwnKey(pEpIdentity * ident)
   1.580  {
   1.581 -	assert(ident);
   1.582 +    assert(ident);
   1.583  
   1.584 -	if (!ident)
   1.585 -		return E_INVALIDARG;
   1.586 +    if (!ident)
   1.587 +        return E_INVALIDARG;
   1.588  
   1.589 -	::pEp_identity *_ident;
   1.590 -	try {
   1.591 -		_ident = new_identity(ident);
   1.592 -	}
   1.593 -	catch (bad_alloc&) {
   1.594 -		return E_OUTOFMEMORY;
   1.595 -	}
   1.596 -	catch (exception& ex) {
   1.597 -		return FAIL(ex.what());
   1.598 -	}
   1.599 +    ::pEp_identity *_ident;
   1.600 +    try {
   1.601 +        _ident = new_identity(ident);
   1.602 +    }
   1.603 +    catch (bad_alloc&) {
   1.604 +        return E_OUTOFMEMORY;
   1.605 +    }
   1.606 +    catch (exception& ex) {
   1.607 +        return FAIL(ex.what());
   1.608 +    }
   1.609  
   1.610 -	assert(_ident);
   1.611 -	if (_ident == NULL)
   1.612 -		return E_OUTOFMEMORY;
   1.613 +    assert(_ident);
   1.614 +    if (_ident == NULL)
   1.615 +        return E_OUTOFMEMORY;
   1.616  
   1.617 -	PEP_STATUS status = ::trust_own_key(session(), _ident);
   1.618 +    PEP_STATUS status = ::trust_own_key(session(), _ident);
   1.619  
   1.620 -	::free_identity(_ident);
   1.621 +    ::free_identity(_ident);
   1.622  
   1.623 -	if (status == PEP_STATUS_OK)
   1.624 -		return S_OK;
   1.625 -	else if (status == PEP_OUT_OF_MEMORY)
   1.626 -		return E_OUTOFMEMORY;
   1.627 -	else
   1.628 -		return FAIL(L"TrustOwnKey", status);
   1.629 +    if (status == PEP_STATUS_OK)
   1.630 +        return S_OK;
   1.631 +    else if (status == PEP_OUT_OF_MEMORY)
   1.632 +        return E_OUTOFMEMORY;
   1.633 +    else
   1.634 +        return FAIL(L"TrustOwnKey", status);
   1.635  }
   1.636  
   1.637  STDMETHODIMP CpEpEngine::Startup()
   1.638  {
   1.639 -	try
   1.640 -	{
   1.641 -		startup<CpEpEngine>(messageToSend, notifyHandshake, this, &CpEpEngine::Startup_sync, &CpEpEngine::Shutdown_sync);
   1.642 -	}
   1.643 -	catch (bad_alloc&) {
   1.644 -		return E_OUTOFMEMORY;
   1.645 -	}
   1.646 -	catch (exception& ex) {
   1.647 -		return FAIL(ex.what());
   1.648 -	}
   1.649 +    try
   1.650 +    {
   1.651 +        startup<CpEpEngine>(messageToSend, notifyHandshake, this, &CpEpEngine::Startup_sync, &CpEpEngine::Shutdown_sync);
   1.652 +    }
   1.653 +    catch (bad_alloc&) {
   1.654 +        return E_OUTOFMEMORY;
   1.655 +    }
   1.656 +    catch (exception& ex) {
   1.657 +        return FAIL(ex.what());
   1.658 +    }
   1.659  
   1.660 -	return S_OK;
   1.661 +    return S_OK;
   1.662  }
   1.663  
   1.664  STDMETHODIMP CpEpEngine::GetKeyRating(BSTR fpr, pEpComType *commType)
   1.665  {
   1.666 -	assert(fpr);
   1.667 +    assert(fpr);
   1.668  
   1.669 -	if (!fpr)
   1.670 -		return E_INVALIDARG;
   1.671 +    if (!fpr)
   1.672 +        return E_INVALIDARG;
   1.673  
   1.674 -	string _fpr = utf8_string(fpr);
   1.675 +    string _fpr = utf8_string(fpr);
   1.676  
   1.677 -	PEP_comm_type _commType;
   1.678 -	PEP_STATUS status = ::get_key_rating(session(), _fpr.c_str(), &_commType);
   1.679 -	if (status != PEP_STATUS_OK)
   1.680 -		return FAIL(L"cannot get key rating", status);
   1.681 +    PEP_comm_type _commType;
   1.682 +    PEP_STATUS status = ::get_key_rating(session(), _fpr.c_str(), &_commType);
   1.683 +    if (status != PEP_STATUS_OK)
   1.684 +        return FAIL(L"cannot get key rating", status);
   1.685  
   1.686 -	*commType = (pEpComType)_commType;
   1.687 +    *commType = (pEpComType)_commType;
   1.688  
   1.689 -	return S_OK;
   1.690 +    return S_OK;
   1.691  }
   1.692  
   1.693  STDMETHODIMP CpEpEngine::GetKeyRatingForUser(BSTR userId, BSTR fpr, pEpRating *rating)
   1.694  {
   1.695 -	assert(userId);
   1.696 -	assert(fpr);
   1.697 +    assert(userId);
   1.698 +    assert(fpr);
   1.699  
   1.700 -	if (!(userId && fpr))
   1.701 -		return E_INVALIDARG;
   1.702 +    if (!(userId && fpr))
   1.703 +        return E_INVALIDARG;
   1.704  
   1.705 -	string user_id = utf8_string(userId);
   1.706 -	string _fpr = utf8_string(fpr);
   1.707 +    string user_id = utf8_string(userId);
   1.708 +    string _fpr = utf8_string(fpr);
   1.709  
   1.710 -	PEP_rating _rating;
   1.711 -	PEP_STATUS status = ::get_key_rating_for_user(session(), user_id.c_str(), _fpr.c_str(), &_rating);
   1.712 -	if (status != PEP_STATUS_OK)
   1.713 -		return FAIL(L"cannot get key rating for user", status);
   1.714 +    PEP_rating _rating;
   1.715 +    PEP_STATUS status = ::get_key_rating_for_user(session(), user_id.c_str(), _fpr.c_str(), &_rating);
   1.716 +    if (status != PEP_STATUS_OK)
   1.717 +        return FAIL(L"cannot get key rating for user", status);
   1.718  
   1.719 -	*rating = (pEpRating)_rating;
   1.720 +    *rating = (pEpRating)_rating;
   1.721  
   1.722 -	return S_OK;
   1.723 +    return S_OK;
   1.724  }
   1.725  
   1.726  STDMETHODIMP CpEpEngine::DeliverHandshakeResult(enum SyncHandshakeResult result, SAFEARRAY *identities_sharing)
   1.727  {
   1.728 -	sync_handshake_result _result = (sync_handshake_result)result;
   1.729 -	identity_list *_identities_sharing = NULL;
   1.730 -	if (identities_sharing)
   1.731 -	{
   1.732 -		try {
   1.733 -			_identities_sharing = identities(identities_sharing);
   1.734 -		}
   1.735 -		catch (bad_alloc&) {
   1.736 -			return E_OUTOFMEMORY;
   1.737 -		}
   1.738 -	}
   1.739 +    sync_handshake_result _result = (sync_handshake_result)result;
   1.740 +    identity_list *_identities_sharing = NULL;
   1.741 +    if (identities_sharing)
   1.742 +    {
   1.743 +        try {
   1.744 +            _identities_sharing = identities(identities_sharing);
   1.745 +        }
   1.746 +        catch (bad_alloc&) {
   1.747 +            return E_OUTOFMEMORY;
   1.748 +        }
   1.749 +    }
   1.750  
   1.751 -	PEP_STATUS status = ::deliverHandshakeResult(session(), _result, _identities_sharing);
   1.752 -	free_identity_list(_identities_sharing);
   1.753 -	switch (status) {
   1.754 -	case PEP_STATUS_OK:
   1.755 -		break;
   1.756 -	case PEP_OUT_OF_MEMORY:
   1.757 -		return E_OUTOFMEMORY;
   1.758 -	default:
   1.759 -		return FAIL(L"deliverHandshakeResult is reporting an error", status);
   1.760 -	}
   1.761 +    PEP_STATUS status = ::deliverHandshakeResult(session(), _result, _identities_sharing);
   1.762 +    free_identity_list(_identities_sharing);
   1.763 +    switch (status) {
   1.764 +    case PEP_STATUS_OK:
   1.765 +        break;
   1.766 +    case PEP_OUT_OF_MEMORY:
   1.767 +        return E_OUTOFMEMORY;
   1.768 +    default:
   1.769 +        return FAIL(L"deliverHandshakeResult is reporting an error", status);
   1.770 +    }
   1.771  
   1.772 -	return S_OK;
   1.773 +    return S_OK;
   1.774  }
   1.775  
   1.776  STDMETHODIMP CpEpEngine::PERToXERSyncMessage(TextMessage *msg, BSTR * xer)
   1.777  {
   1.778 -	assert(msg);
   1.779 +    assert(msg);
   1.780  
   1.781 -	if (!msg)
   1.782 -		return E_INVALIDARG;
   1.783 +    if (!msg)
   1.784 +        return E_INVALIDARG;
   1.785  
   1.786 -	char* text;
   1.787 -	::message *_msg = text_message_to_C(msg);
   1.788 -	char* val = _msg->attachments->value;
   1.789 +    ::message *_msg = NULL;
   1.790 +    try {
   1.791 +        _msg = text_message_to_C(msg);
   1.792 +    }
   1.793 +    catch (bad_alloc&) {
   1.794 +        return E_OUTOFMEMORY;
   1.795 +    }
   1.796 +    catch (exception& ex) {
   1.797 +        return FAIL(ex.what());
   1.798 +    }
   1.799  
   1.800 -	PEP_STATUS status = ::PER_to_XER_Sync_msg(val, strlen(val), &text);
   1.801 -	free_message(_msg);
   1.802 +    char* text;
   1.803 +    char* val = _msg->attachments->value;
   1.804  
   1.805 -	if (status != PEP_STATUS_OK)
   1.806 -		return FAIL(L"cannot get XER", status);
   1.807 +    PEP_STATUS status = ::PER_to_XER_Sync_msg(val, strlen(val), &text);
   1.808 +    free_message(_msg);
   1.809  
   1.810 -	*xer = utf16_bstr(text);
   1.811 -	pEp_free(text);
   1.812 +    if (status != PEP_STATUS_OK)
   1.813 +        return FAIL(L"cannot get XER", status);
   1.814  
   1.815 -	return S_OK;
   1.816 +    *xer = utf16_bstr(text);
   1.817 +    pEp_free(text);
   1.818 +
   1.819 +    return S_OK;
   1.820  }
   1.821  
   1.822  STDMETHODIMP CpEpEngine::DisableIdentityForSync(struct pEpIdentity * ident)
   1.823  {
   1.824 -	assert(ident);
   1.825 +    assert(ident);
   1.826  
   1.827 -	if (!ident)
   1.828 -		return E_INVALIDARG;
   1.829 +    if (!ident)
   1.830 +        return E_INVALIDARG;
   1.831  
   1.832 -	::pEp_identity *_ident;
   1.833 -	try {
   1.834 -		_ident = new_identity(ident);
   1.835 -	}
   1.836 -	catch (bad_alloc&) {
   1.837 -		return E_OUTOFMEMORY;
   1.838 -	}
   1.839 -	catch (exception& ex) {
   1.840 -		return FAIL(ex.what());
   1.841 -	}
   1.842 +    ::pEp_identity *_ident;
   1.843 +    try {
   1.844 +        _ident = new_identity(ident);
   1.845 +    }
   1.846 +    catch (bad_alloc&) {
   1.847 +        return E_OUTOFMEMORY;
   1.848 +    }
   1.849 +    catch (exception& ex) {
   1.850 +        return FAIL(ex.what());
   1.851 +    }
   1.852  
   1.853 -	assert(_ident);
   1.854 -	if (_ident == NULL)
   1.855 -		return E_OUTOFMEMORY;
   1.856 +    assert(_ident);
   1.857 +    if (_ident == NULL)
   1.858 +        return E_OUTOFMEMORY;
   1.859  
   1.860 -	PEP_STATUS status = ::disable_identity_for_sync(session(), _ident);
   1.861 +    PEP_STATUS status = ::disable_identity_for_sync(session(), _ident);
   1.862  
   1.863 -	::free_identity(_ident);
   1.864 +    ::free_identity(_ident);
   1.865  
   1.866 -	if (status == PEP_STATUS_OK)
   1.867 -		return S_OK;
   1.868 -	else if (status == PEP_OUT_OF_MEMORY)
   1.869 -		return E_OUTOFMEMORY;
   1.870 -	else
   1.871 -		return FAIL(L"DisableIdentityForSync", status);
   1.872 +    if (status == PEP_STATUS_OK)
   1.873 +        return S_OK;
   1.874 +    else if (status == PEP_OUT_OF_MEMORY)
   1.875 +        return E_OUTOFMEMORY;
   1.876 +    else
   1.877 +        return FAIL(L"DisableIdentityForSync", status);
   1.878  }
   1.879  
   1.880  STDMETHODIMP CpEpEngine::EnableIdentityForSync(struct pEpIdentity * ident)
   1.881  {
   1.882 -	assert(ident);
   1.883 +    assert(ident);
   1.884  
   1.885 -	if (!ident)
   1.886 -		return E_INVALIDARG;
   1.887 +    if (!ident)
   1.888 +        return E_INVALIDARG;
   1.889  
   1.890 -	::pEp_identity *_ident;
   1.891 -	try {
   1.892 -		_ident = new_identity(ident);
   1.893 -	}
   1.894 -	catch (bad_alloc&) {
   1.895 -		return E_OUTOFMEMORY;
   1.896 -	}
   1.897 -	catch (exception& ex) {
   1.898 -		return FAIL(ex.what());
   1.899 -	}
   1.900 +    ::pEp_identity *_ident;
   1.901 +    try {
   1.902 +        _ident = new_identity(ident);
   1.903 +    }
   1.904 +    catch (bad_alloc&) {
   1.905 +        return E_OUTOFMEMORY;
   1.906 +    }
   1.907 +    catch (exception& ex) {
   1.908 +        return FAIL(ex.what());
   1.909 +    }
   1.910  
   1.911 -	assert(_ident);
   1.912 -	if (_ident == NULL)
   1.913 -		return E_OUTOFMEMORY;
   1.914 +    assert(_ident);
   1.915 +    if (_ident == NULL)
   1.916 +        return E_OUTOFMEMORY;
   1.917  
   1.918 -	PEP_STATUS status = ::enable_identity_for_sync(session(), _ident);
   1.919 +    PEP_STATUS status = ::enable_identity_for_sync(session(), _ident);
   1.920  
   1.921 -	::free_identity(_ident);
   1.922 +    ::free_identity(_ident);
   1.923  
   1.924 -	if (status == PEP_STATUS_OK)
   1.925 -		return S_OK;
   1.926 -	else if (status == PEP_OUT_OF_MEMORY)
   1.927 -		return E_OUTOFMEMORY;
   1.928 -	else
   1.929 -		return FAIL(L"EnableIdentityForSync", status);
   1.930 +    if (status == PEP_STATUS_OK)
   1.931 +        return S_OK;
   1.932 +    else if (status == PEP_OUT_OF_MEMORY)
   1.933 +        return E_OUTOFMEMORY;
   1.934 +    else
   1.935 +        return FAIL(L"EnableIdentityForSync", status);
   1.936  }
   1.937  
   1.938  STDMETHODIMP CpEpEngine::PerMachineDirectory(BSTR * directory)
   1.939  {
   1.940 -	assert(directory);
   1.941 +    assert(directory);
   1.942  
   1.943 -	if (!directory)
   1.944 -		return E_INVALIDARG;
   1.945 +    if (!directory)
   1.946 +        return E_INVALIDARG;
   1.947  
   1.948 -	const char *_directory = ::per_machine_directory();
   1.949 +    const char *_directory = ::per_machine_directory();
   1.950  
   1.951 -	if (_directory == NULL)
   1.952 -		return FAIL(L"PerMachineDirectory: _directory is NULL");
   1.953 +    if (_directory == NULL)
   1.954 +        return FAIL(L"PerMachineDirectory: _directory is NULL");
   1.955  
   1.956 -	*directory = utf16_bstr(_directory);
   1.957 +    *directory = utf16_bstr(_directory);
   1.958  
   1.959 -	return S_OK;
   1.960 +    return S_OK;
   1.961  }
   1.962  
   1.963  STDMETHODIMP CpEpEngine::PerUserDirectory(BSTR * directory)
   1.964  {
   1.965 -	assert(directory);
   1.966 +    assert(directory);
   1.967  
   1.968 -	if (!directory)
   1.969 -		return E_INVALIDARG;
   1.970 +    if (!directory)
   1.971 +        return E_INVALIDARG;
   1.972  
   1.973 -	const char *_directory = ::per_user_directory();
   1.974 +    const char *_directory = ::per_user_directory();
   1.975  
   1.976 -	if (_directory == NULL)
   1.977 -		return FAIL(L"PerUserDirectory: _directory is NULL");
   1.978 +    if (_directory == NULL)
   1.979 +        return FAIL(L"PerUserDirectory: _directory is NULL");
   1.980  
   1.981 -	*directory = utf16_bstr(_directory);
   1.982 +    *directory = utf16_bstr(_directory);
   1.983  
   1.984 -	return S_OK;
   1.985 +    return S_OK;
   1.986  }
     2.1 --- a/GateKeeper.cpp	Mon Oct 21 10:56:57 2019 +0200
     2.2 +++ b/GateKeeper.cpp	Tue Oct 22 12:41:11 2019 +0200
     2.3 @@ -406,52 +406,52 @@
     2.4          return fileName;
     2.5      }
     2.6  
     2.7 -	// Retrieving Headers Using HTTP_QUERY_CUSTOM
     2.8 -	static tstring httpQueryCustom(HINTERNET hHttp, tstring header)
     2.9 -	{
    2.10 -		DWORD dwResult = 0;
    2.11 -		LPTSTR lpOutBuffer = StrDup(header.c_str());
    2.12 +    // Retrieving Headers Using HTTP_QUERY_CUSTOM
    2.13 +    static tstring httpQueryCustom(HINTERNET hHttp, tstring header)
    2.14 +    {
    2.15 +        DWORD dwResult = 0;
    2.16 +        LPTSTR lpOutBuffer = StrDup(header.c_str());
    2.17  
    2.18 -	retry:
    2.19 +    retry:
    2.20  
    2.21 -		if (!HttpQueryInfo(hHttp, HTTP_QUERY_CUSTOM, (LPVOID)lpOutBuffer, &dwResult, NULL))
    2.22 -		{
    2.23 -			if (GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND)
    2.24 -			{
    2.25 -				// Code to handle the case where the header isn't available.
    2.26 -				LocalFree(lpOutBuffer);
    2.27 -				throw(runtime_error("ERROR_HTTP_HEADER_NOT_FOUND"));
    2.28 -			}
    2.29 -			else
    2.30 -			{
    2.31 -				// Check for an insufficient buffer.
    2.32 -				if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
    2.33 -				{
    2.34 -					// Allocate the necessary buffer.
    2.35 -					LocalFree(lpOutBuffer);
    2.36 -					lpOutBuffer = (LPTSTR)LocalAlloc(LMEM_FIXED, dwResult + 1);
    2.37 +        if (!HttpQueryInfo(hHttp, HTTP_QUERY_CUSTOM, (LPVOID)lpOutBuffer, &dwResult, NULL))
    2.38 +        {
    2.39 +            if (GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND)
    2.40 +            {
    2.41 +                // Code to handle the case where the header isn't available.
    2.42 +                LocalFree(lpOutBuffer);
    2.43 +                throw(runtime_error("ERROR_HTTP_HEADER_NOT_FOUND"));
    2.44 +            }
    2.45 +            else
    2.46 +            {
    2.47 +                // Check for an insufficient buffer.
    2.48 +                if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
    2.49 +                {
    2.50 +                    // Allocate the necessary buffer.
    2.51 +                    LocalFree(lpOutBuffer);
    2.52 +                    lpOutBuffer = (LPTSTR)LocalAlloc(LMEM_FIXED, dwResult + 1);
    2.53  
    2.54 -					// Rewrite the header name in the buffer.
    2.55 -					StringCchPrintf(lpOutBuffer, dwResult, header.c_str());
    2.56 +                    // Rewrite the header name in the buffer.
    2.57 +                    StringCchPrintf(lpOutBuffer, dwResult, header.c_str());
    2.58  
    2.59 -					// Retry the call.
    2.60 -					goto retry;
    2.61 -				}
    2.62 -				else
    2.63 -				{
    2.64 -					// Error handling code.
    2.65 -					LocalFree(lpOutBuffer);
    2.66 -					// FIXME: Add GetLastError()
    2.67 -					throw(runtime_error("Unknown"));
    2.68 -				}
    2.69 -			}
    2.70 -		}
    2.71 +                    // Retry the call.
    2.72 +                    goto retry;
    2.73 +                }
    2.74 +                else
    2.75 +                {
    2.76 +                    // Error handling code.
    2.77 +                    LocalFree(lpOutBuffer);
    2.78 +                    // FIXME: Add GetLastError()
    2.79 +                    throw(runtime_error("Unknown"));
    2.80 +                }
    2.81 +            }
    2.82 +        }
    2.83  
    2.84 -		tstring result(lpOutBuffer);
    2.85 -		LocalFree(lpOutBuffer);
    2.86 +        tstring result(lpOutBuffer);
    2.87 +        LocalFree(lpOutBuffer);
    2.88  
    2.89 -		return result;
    2.90 -	}
    2.91 +        return result;
    2.92 +    }
    2.93  
    2.94      bool GateKeeper::update_product(product p, DWORD context)
    2.95      {
    2.96 @@ -489,7 +489,7 @@
    2.97          tstring filename;
    2.98          HANDLE hFile = NULL;
    2.99          char *unencrypted_buffer = NULL;
   2.100 -		bool result = false;
   2.101 +        bool result = false;
   2.102  
   2.103          try {
   2.104  
   2.105 @@ -504,14 +504,14 @@
   2.106                  crypted += string(buffer, reading);
   2.107              } while (1);
   2.108  
   2.109 -			tstring contentDisposition = httpQueryCustom(hUrl, _T("Content-Disposition"));
   2.110 +            tstring contentDisposition = httpQueryCustom(hUrl, _T("Content-Disposition"));
   2.111  
   2.112 -			tregex filenameRegex(_T("filename=.([^\"]*)"), regex::extended); //FIXME: case insensitive
   2.113 -			tsmatch match;
   2.114 +            tregex filenameRegex(_T("filename=.([^\"]*)"), regex::extended); //FIXME: case insensitive
   2.115 +            tsmatch match;
   2.116  
   2.117 -			if (regex_search(contentDisposition, match, filenameRegex)) {
   2.118 -				filename = match[1];
   2.119 -			}
   2.120 +            if (regex_search(contentDisposition, match, filenameRegex)) {
   2.121 +                filename = match[1];
   2.122 +            }
   2.123  
   2.124              InternetCloseHandle(hUrl);
   2.125              hUrl = NULL;
   2.126 @@ -547,15 +547,15 @@
   2.127              TCHAR temp_path[MAX_PATH + 1];
   2.128              GetTempPath(MAX_PATH, temp_path);
   2.129  
   2.130 -			if (filename == _T("")) {
   2.131 -				filename = temp_path;
   2.132 -				filename += _T("\\pEp_");
   2.133 -				filename += delivery.substr(0, 32);
   2.134 -				filename += _T(".msi");
   2.135 -			}
   2.136 -			else {
   2.137 -				filename = tstring(temp_path) + _T("\\") + filename;
   2.138 -			}
   2.139 +            if (filename == _T("")) {
   2.140 +                filename = temp_path;
   2.141 +                filename += _T("\\pEp_");
   2.142 +                filename += delivery.substr(0, 32);
   2.143 +                filename += _T(".msi");
   2.144 +            }
   2.145 +            else {
   2.146 +                filename = tstring(temp_path) + _T("\\") + filename;
   2.147 +            }
   2.148  
   2.149              hFile = CreateFile(filename.c_str(), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
   2.150              if (!hFile)
   2.151 @@ -563,7 +563,7 @@
   2.152              DWORD writing;
   2.153              WriteFile(hFile, unencrypted_buffer, unencrypted_size, &writing, NULL);
   2.154              CloseHandle(hFile);
   2.155 -			hFile = NULL;
   2.156 +            hFile = NULL;
   2.157              delete[] unencrypted_buffer;
   2.158              unencrypted_buffer = nullptr;
   2.159          }
   2.160 @@ -572,7 +572,7 @@
   2.161          }
   2.162  
   2.163          execute_file(filename);
   2.164 -		result = true;
   2.165 +        result = true;
   2.166  
   2.167      closing:
   2.168          if (unencrypted_buffer)
   2.169 @@ -583,7 +583,7 @@
   2.170              InternetCloseHandle(hUrl);
   2.171          BCryptDestroyKey(dk);
   2.172  
   2.173 -		return result;
   2.174 +        return result;
   2.175      }
   2.176  
   2.177      void GateKeeper::keep_updated()
     3.1 --- a/utf8_helper.cpp	Mon Oct 21 10:56:57 2019 +0200
     3.2 +++ b/utf8_helper.cpp	Tue Oct 22 12:41:11 2019 +0200
     3.3 @@ -30,11 +30,11 @@
     3.4              }
     3.5              string result;
     3.6  
     3.7 -            int size = WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, _wstr_normalized.c_str(), -1, NULL, 0, NULL, NULL);
     3.8 +            int size = WideCharToMultiByte(CP_UTF8, WC_NO_BEST_FIT_CHARS, _wstr_normalized.c_str(), -1, NULL, 0, NULL, NULL);
     3.9              assert(size);
    3.10              if (size) {
    3.11                  char *buf = new char[size];
    3.12 -                WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, _wstr_normalized.c_str(), -1, buf, size, NULL, NULL);
    3.13 +                WideCharToMultiByte(CP_UTF8, WC_NO_BEST_FIT_CHARS, _wstr_normalized.c_str(), -1, buf, size, NULL, NULL);
    3.14                  result = buf;
    3.15                  delete[] buf;
    3.16              }