Expose get_trustwords_for_fprs sync
authorThomas
Fri, 14 Jun 2019 08:38:59 +0200
branchsync
changeset 3484a3be892c28a
parent 347 ae275a12a133
child 349 a81c488dcd3a
Expose get_trustwords_for_fprs
CpEpEngine.cpp
CpEpEngine.h
pEpCOMServerAdapter.idl
     1.1 --- a/CpEpEngine.cpp	Tue Jun 04 11:19:49 2019 +0200
     1.2 +++ b/CpEpEngine.cpp	Fri Jun 14 08:38:59 2019 +0200
     1.3 @@ -243,6 +243,71 @@
     1.4      }
     1.5  }
     1.6  
     1.7 +STDMETHODIMP CpEpEngine::GetTrustwordsForFprs(BSTR fpr1, BSTR fpr2, BSTR lang, VARIANT_BOOL full, BSTR *words)
     1.8 +{
     1.9 +	assert(fpr1);
    1.10 +	assert(fpr2);
    1.11 +	assert(words);
    1.12 +
    1.13 +	if (!(fpr1 && fpr2 && words))
    1.14 +	{
    1.15 +		return E_INVALIDARG;
    1.16 +	}
    1.17 +
    1.18 +	HRESULT result = S_OK;
    1.19 +	string _fpr1;
    1.20 +	string _fpr2;
    1.21 +	string _lang;
    1.22 +	*words = NULL;
    1.23 +
    1.24 +	try {
    1.25 +
    1.26 +		_fpr1 = utf8_string(fpr1);
    1.27 +		_fpr2 = utf8_string(fpr2);
    1.28 +		
    1.29 +		if (lang) {
    1.30 +			_lang = utf8_string(lang);
    1.31 +			if (_lang.length() == 0) {
    1.32 +				_lang = "en";
    1.33 +			}
    1.34 +			else if (_lang.length() != 2) {
    1.35 +				result = E_INVALIDARG;
    1.36 +			}
    1.37 +		}
    1.38 +		else {
    1.39 +			_lang = "en";
    1.40 +		}
    1.41 +	}
    1.42 +	catch (bad_alloc&) {
    1.43 +		result = E_OUTOFMEMORY;
    1.44 +	}
    1.45 +	catch (exception& ex) {
    1.46 +		result = FAIL(ex.what());
    1.47 +	}
    1.48 +
    1.49 +	char* _words;
    1.50 +	size_t _size;
    1.51 +	if (result == S_OK) {
    1.52 +		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.53 +
    1.54 +		if (status == PEP_OUT_OF_MEMORY) {
    1.55 +			result = E_OUTOFMEMORY;
    1.56 +		}
    1.57 +		else if (status == PEP_TRUSTWORD_NOT_FOUND) {
    1.58 +			result = FAIL(L"GetTrustwords: Trustword not found", status);
    1.59 +		}
    1.60 +		else if (!words) {
    1.61 +			result = FAIL(L"GetTrustwords: _words == NULL", status);
    1.62 +		}
    1.63 +		else {
    1.64 +			*words = utf16_bstr(_words);
    1.65 +			pEp_free(_words);
    1.66 +		}
    1.67 +	}
    1.68 +
    1.69 +	return result;
    1.70 +}
    1.71 +
    1.72  STDMETHODIMP CpEpEngine::GetTrustwords(struct pEpIdentity *id1, struct pEpIdentity *id2, BSTR lang, VARIANT_BOOL full, BSTR *words)
    1.73  {
    1.74      assert(id1);
     2.1 --- a/CpEpEngine.h	Tue Jun 04 11:19:49 2019 +0200
     2.2 +++ b/CpEpEngine.h	Fri Jun 14 08:38:59 2019 +0200
     2.3 @@ -180,6 +180,7 @@
     2.4      STDMETHOD(Log)(BSTR title, BSTR entity, BSTR description, BSTR comment);
     2.5      STDMETHOD(Trustwords)(BSTR fpr, BSTR lang, LONG max_words, BSTR * words);
     2.6      STDMETHOD(GetTrustwords)(struct pEpIdentity *id1, struct pEpIdentity *id2, BSTR lang, VARIANT_BOOL full, BSTR *words);
     2.7 +    STDMETHOD(GetTrustwordsForFprs)(BSTR fpr1, BSTR fpr2, BSTR lang, VARIANT_BOOL full, BSTR *words);
     2.8      STDMETHOD(GetMessageTrustwords)(
     2.9          /* [in] */ struct TextMessage *msg,
    2.10          /* [in] */ struct pEpIdentity *receivedBy,
     3.1 --- a/pEpCOMServerAdapter.idl	Tue Jun 04 11:19:49 2019 +0200
     3.2 +++ b/pEpCOMServerAdapter.idl	Fri Jun 14 08:38:59 2019 +0200
     3.3 @@ -487,6 +487,9 @@
     3.4  
     3.5  	// Leave the device group
     3.6  	[id(51)] HRESULT LeaveDeviceGroup();
     3.7 +
     3.8 +	// Get Trustwords for a pair of fprs
     3.9 +	[id(52)] HRESULT GetTrustwordsForFprs([in] BSTR fpr1, [in] BSTR fpr2, [in, defaultvalue("en")] BSTR lang, [in, defaultvalue(0)] VARIANT_BOOL full, [out, retval] BSTR * words);
    3.10  };
    3.11  
    3.12  [