COM-38: Trustwords Function with Identities
authorMarkus Schaber <markus@pep-security.net>
Wed, 02 Nov 2016 23:30:50 +0100
changeset 1908d1c4f057dea
parent 189 5361d677afdb
child 191 e6e934d5b62d
COM-38: Trustwords Function with Identities

Expose the get_trustwords function from ENGINE-109 via COM interface
as GetTrustWords().
CpEpEngine.cpp
CpEpEngine.h
pEpCOMServerAdapter.idl
     1.1 --- a/CpEpEngine.cpp	Tue Oct 25 22:12:19 2016 +0200
     1.2 +++ b/CpEpEngine.cpp	Wed Nov 02 23:30:50 2016 +0100
     1.3 @@ -163,6 +163,71 @@
     1.4  	}
     1.5  }
     1.6  
     1.7 +STDMETHODIMP CpEpEngine::GetTrustWords(struct pEpIdentity *id1, struct pEpIdentity *id2, BSTR lang, VARIANT_BOOL full, BSTR *words)
     1.8 +{
     1.9 +    assert(id1);
    1.10 +    assert(id2);
    1.11 +    assert(words);
    1.12 +
    1.13 +    if (id1 == NULL || id2 == NULL || words == NULL)
    1.14 +    {
    1.15 +        return E_INVALIDARG;
    1.16 +    }
    1.17 +
    1.18 +    HRESULT result = S_OK;
    1.19 +
    1.20 +    pEp_identity* _id1 = NULL;
    1.21 +    pEp_identity* _id2 = NULL;
    1.22 +    string _lang;
    1.23 +    *words = NULL;
    1.24 +
    1.25 +    try {
    1.26 +        _id1 = new_identity(id1);
    1.27 +        _id2 = new_identity(id2);
    1.28 +
    1.29 +        if (!lang) {
    1.30 +            _lang = utf8_string(lang);
    1.31 +            if (_lang.length() == 0) {
    1.32 +                _lang = "en";
    1.33 +            } else if (_lang.length() != 2) {
    1.34 +                result = E_INVALIDARG;
    1.35 +            }
    1.36 +        } else {
    1.37 +            _lang = "en";
    1.38 +        }
    1.39 +    } catch (bad_alloc&) {
    1.40 +        result = E_OUTOFMEMORY;
    1.41 +    } catch (exception& ex) {
    1.42 +        result = FAIL(ex.what());
    1.43 +    }
    1.44 +
    1.45 +    char* _words;
    1.46 +    size_t _size;
    1.47 +    if (result = S_OK) {
    1.48 +        auto status = ::get_trustwords(get_session(), _id1, _id2, _lang.c_str(), &_words, &_size, full != 0 /* convert variant bool to C bool */);
    1.49 +
    1.50 +        if (status == PEP_OUT_OF_MEMORY) {
    1.51 +            result = E_OUTOFMEMORY;
    1.52 +        }
    1.53 +        else if (status == PEP_TRUSTWORD_NOT_FOUND) {
    1.54 +            result = FAIL(L"GetTrustWords: Trustword not found", status);
    1.55 +        }
    1.56 +        else if (!words) {
    1.57 +            result = FAIL(L"GetTrustWords: _words == NULL", status);
    1.58 +        }
    1.59 +        else {
    1.60 +            *words = utf16_bstr(_words);
    1.61 +            pEp_free(_words);
    1.62 +        }
    1.63 +    }
    1.64 +
    1.65 +    free_identity(_id1);
    1.66 +    free_identity(_id2);
    1.67 +
    1.68 +    return result;
    1.69 +}
    1.70 +
    1.71 +
    1.72  STDMETHODIMP CpEpEngine::GetCrashdumpLog(LONG maxlines, BSTR * log)
    1.73  {
    1.74  	assert(maxlines >= 0);
     2.1 --- a/CpEpEngine.h	Tue Oct 25 22:12:19 2016 +0200
     2.2 +++ b/CpEpEngine.h	Wed Nov 02 23:30:50 2016 +0100
     2.3 @@ -157,6 +157,7 @@
     2.4      STDMETHOD(ExportKey)(BSTR fpr, BSTR * keyData);
     2.5      STDMETHOD(Log)(BSTR title, BSTR entity, BSTR description, BSTR comment);
     2.6      STDMETHOD(TrustWords)(BSTR fpr, BSTR lang, LONG max_words, BSTR * words);
     2.7 +    STDMETHOD(GetTrustWords)(struct pEpIdentity *id1, struct pEpIdentity *id2, BSTR lang, VARIANT_BOOL full, BSTR *words);
     2.8      STDMETHOD(GetCrashdumpLog)(LONG maxlines, BSTR * log);
     2.9      STDMETHOD(GetEngineVersion)(BSTR * engineVersion);
    2.10      STDMETHOD(GetLanguageList)(BSTR * languages);
     3.1 --- a/pEpCOMServerAdapter.idl	Tue Oct 25 22:12:19 2016 +0200
     3.2 +++ b/pEpCOMServerAdapter.idl	Wed Nov 02 23:30:50 2016 +0100
     3.3 @@ -50,6 +50,7 @@
     3.4      HRESULT ExportKey([in] BSTR fpr, [out, retval] BSTR * keyData);
     3.5      HRESULT Log([in] BSTR title, [in] BSTR entity, [in, defaultvalue("")] BSTR description, [in, defaultvalue("")] BSTR comment);
     3.6      HRESULT TrustWords([in] BSTR fpr, [in, defaultvalue("en")] BSTR lang, [in, defaultvalue(0)] LONG maxWords, [out, retval] BSTR * words);
     3.7 +    HRESULT GetTrustWords([in] struct pEpIdentity * id1, [in] struct pEpIdentity * id2, [in, defaultvalue("en")] BSTR lang, [in, defaultvalue(0)] VARIANT_BOOL full, [out, retval] BSTR * words);
     3.8      HRESULT GetCrashdumpLog([in, defaultvalue(0)] LONG maxlines, [out, retval] BSTR * log);
     3.9      HRESULT GetEngineVersion([out, retval] BSTR * engineVersion);
    3.10      HRESULT GetLanguageList([out, retval] BSTR * languages);