CpEpEngine.h
author Dean
Fri, 26 Aug 2016 10:44:26 +0200
changeset 151 432c35b5903c
parent 84 ec2e6174b307
child 154 09f6480a8c41
child 155 0264d4b637a4
permissions -rw-r--r--
Add get_engine_version
vb@0
     1
// CpEpEngine.h : Declaration of the CpEpEngine
vb@0
     2
vb@0
     3
#pragma once
vb@0
     4
#include "resource.h"       // main symbols
vb@0
     5
vb@0
     6
#include "pEpComServerAdapter_i.h"
vb@0
     7
#include "_IpEpEngineEvents_CP.h"
vb@0
     8
#include "locked_queue.hh"
vb@0
     9
#include "utf8_helper.h"
vb@33
    10
#include "pEp_utility.h"
vb@0
    11
vb@0
    12
vb@0
    13
#if defined(_WIN32_WCE) && !defined(_CE_DCOM) && !defined(_CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA)
vb@0
    14
#error "Single-threaded COM objects are not properly supported on Windows CE platform, such as the Windows Mobile platforms that do not include full DCOM support. Define _CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA to force ATL to support creating single-thread COM object's and allow use of it's single-threaded COM object implementations. The threading model in your rgs file was set to 'Free' as that is the only threading model supported in non DCOM Windows CE platforms."
vb@0
    15
#endif
vb@0
    16
vb@0
    17
using namespace ATL;
vb@0
    18
using namespace utility;
vb@10
    19
using namespace pEp::utility;
vb@0
    20
vb@0
    21
// CpEpEngine
vb@0
    22
vb@0
    23
class ATL_NO_VTABLE CpEpEngine :
vb@3
    24
    public CComObjectRootEx<CComObjectThreadModel>,
vb@0
    25
	public CComCoClass<CpEpEngine, &CLSID_pEpEngine>,
vb@0
    26
	public ISupportErrorInfo,
vb@0
    27
	public IConnectionPointContainerImpl<CpEpEngine>,
vb@0
    28
	public CProxy_IpEpEngineEvents<CpEpEngine>,
vb@15
    29
	public IpEpEngine
vb@0
    30
{
vb@28
    31
protected:
vb@28
    32
    static int examine_identity(pEp_identity *ident, void *management);
vb@28
    33
vb@0
    34
public:
vb@51
    35
    CpEpEngine() : keymanagement_thread(NULL), identity_queue(NULL), verbose_mode(false)
vb@0
    36
	{
vb@0
    37
        PEP_STATUS status = ::init(&m_session);
vb@0
    38
        assert(status == PEP_STATUS_OK);
vb@28
    39
        ::register_examine_function(m_session, CpEpEngine::examine_identity, (void *)this);
vb@76
    40
        ::register_sync_callbacks(m_session, (void*)this, messageToSend, showHandshake);
vb@0
    41
        ::log_event(m_session, "Startup", "pEp COM Adapter", NULL, NULL);
vb@0
    42
    }
vb@24
    43
vb@0
    44
    ~CpEpEngine()
vb@0
    45
    {
vb@26
    46
        stop_keyserver_lookup();
vb@77
    47
        ::unregister_sync_callbacks(m_session);
vb@0
    48
        ::log_event(m_session, "Shutdown", "pEp COM Adapter", NULL, NULL);
vb@0
    49
        ::release(m_session);
vb@0
    50
    }
vb@0
    51
vb@0
    52
DECLARE_REGISTRY_RESOURCEID(IDR_PEPENGINE)
vb@0
    53
vb@0
    54
DECLARE_NOT_AGGREGATABLE(CpEpEngine)
vb@0
    55
vb@0
    56
BEGIN_COM_MAP(CpEpEngine)
vb@5
    57
    COM_INTERFACE_ENTRY(IpEpEngine)
vb@5
    58
    COM_INTERFACE_ENTRY(ISupportErrorInfo)
vb@5
    59
    COM_INTERFACE_ENTRY(IConnectionPointContainer)
vb@0
    60
END_COM_MAP()
vb@0
    61
vb@0
    62
BEGIN_CONNECTION_POINT_MAP(CpEpEngine)
vb@0
    63
	CONNECTION_POINT_ENTRY(__uuidof(_IpEpEngineEvents))
vb@0
    64
END_CONNECTION_POINT_MAP()
vb@0
    65
// ISupportsErrorInfo
vb@0
    66
	STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);
vb@0
    67
vb@0
    68
vb@0
    69
	DECLARE_PROTECT_FINAL_CONSTRUCT()
vb@0
    70
vb@0
    71
	HRESULT FinalConstruct()
vb@0
    72
	{
vb@0
    73
		return S_OK;
vb@0
    74
	}
vb@0
    75
vb@0
    76
	void FinalRelease()
vb@0
    77
	{
vb@0
    78
	}
vb@0
    79
vb@0
    80
vb@0
    81
protected:
vb@0
    82
    class session
vb@0
    83
    {
vb@0
    84
    private:
vb@0
    85
        CpEpEngine *me;
vb@0
    86
vb@0
    87
    public:
vb@0
    88
        session(CpEpEngine *myself)
vb@0
    89
        {
vb@0
    90
            me = myself;
vb@0
    91
            me->session_mutex.lock();
vb@0
    92
        }
vb@0
    93
vb@0
    94
        ~session()
vb@0
    95
        {
vb@0
    96
            me->session_mutex.unlock();
vb@0
    97
        }
vb@0
    98
vb@0
    99
        operator PEP_SESSION const () 
vb@0
   100
        {
vb@0
   101
            return me->m_session;
vb@0
   102
        }
vb@0
   103
    };
vb@0
   104
vb@0
   105
    session get_session()
vb@0
   106
    {
vb@0
   107
        return session(this);
vb@0
   108
    }
vb@0
   109
markus@84
   110
	class callbacks
markus@84
   111
	{
markus@84
   112
	private:
markus@84
   113
		CpEpEngine *me;
markus@84
   114
markus@84
   115
	public:
markus@84
   116
		callbacks(CpEpEngine *myself)
markus@84
   117
		{
markus@84
   118
			me = myself;
markus@84
   119
			me->callback_mutex.lock();
markus@84
   120
		}
markus@84
   121
markus@84
   122
		~callbacks()
markus@84
   123
		{
markus@84
   124
			me->callback_mutex.unlock();
markus@84
   125
		}
markus@84
   126
markus@84
   127
		operator vector<IpEpEngineCallbacks *>& ()
markus@84
   128
		{
markus@84
   129
			return me->callback_vector;
markus@84
   130
		}
markus@84
   131
	};
markus@84
   132
markus@84
   133
	callbacks get_callbacks()
markus@84
   134
	{
markus@84
   135
		return callbacks(this);
markus@84
   136
	}
markus@84
   137
vb@0
   138
    typedef locked_queue<pEp_identity_cpp> identity_queue_t;
vb@0
   139
    static ::pEp_identity * retrieve_next_identity(void *management);
vb@74
   140
    static PEP_STATUS messageToSend(void *obj, const message *msg);
vb@83
   141
    static PEP_STATUS showHandshake(void * obj, const pEp_identity *self, const pEp_identity *partner);
vb@74
   142
vb@0
   143
    HRESULT error(_bstr_t msg);
vb@0
   144
vb@51
   145
    void verbose(string text)
vb@51
   146
    {
vb@51
   147
        if (verbose_mode) {
vb@51
   148
            stringstream ss;
vb@51
   149
            ss << __FILE__ << ":" << __LINE__ << " " << text;
vb@51
   150
            ::log_event(get_session(), "verbose", "pEp COM Server Adapter", ss.str().c_str(), NULL);
vb@51
   151
        }
vb@51
   152
    }
vb@51
   153
vb@0
   154
private:
vb@0
   155
    PEP_SESSION m_session;
vb@0
   156
    mutex session_mutex;
vb@25
   157
    atomic< identity_queue_t * > identity_queue;
vb@0
   158
    thread *keymanagement_thread;
vb@51
   159
    bool verbose_mode;
vb@0
   160
markus@84
   161
	mutex callback_mutex;
markus@84
   162
	vector<IpEpEngineCallbacks*> callback_vector;
markus@84
   163
vb@0
   164
public:
vb@60
   165
    // runtime config of the adapter
vb@60
   166
vb@61
   167
    STDMETHOD(verbose_logging)(VARIANT_BOOL enable);
vb@60
   168
    
vb@60
   169
    // runtime config of the engine
vb@60
   170
vb@61
   171
    STDMETHOD(passive_mode)(VARIANT_BOOL enable);
vb@61
   172
    STDMETHOD(unencrypted_subject)(VARIANT_BOOL enable);
vb@60
   173
vb@60
   174
    // basic API
vb@51
   175
vb@0
   176
    STDMETHOD(log)(BSTR title, BSTR entity, BSTR description, BSTR comment);
vb@0
   177
    STDMETHOD(decrypt)(BSTR ctext, BSTR * ptext, LPSAFEARRAY * key_list, pEp_STATUS * decrypt_status);
vb@0
   178
    STDMETHOD(decrypt_b)(BSTR ctext, LPSAFEARRAY * ptext, LPSAFEARRAY * key_list, pEp_STATUS * decrypt_status);
vb@0
   179
    STDMETHOD(encrypt)(SAFEARRAY * key_list, BSTR ptext, BSTR * ctext, pEp_STATUS * status);
vb@0
   180
    STDMETHOD(encrypt_b)(SAFEARRAY * key_list, SAFEARRAY * ptext, BSTR * ctext, pEp_STATUS * status);
vb@17
   181
    STDMETHOD(trustword)(LONG value, BSTR lang, BSTR * word);
vb@17
   182
    STDMETHOD(trustwords)(BSTR fpr, BSTR lang, LONG max_words, BSTR * words);
vb@70
   183
    STDMETHOD(get_identity)(BSTR address, BSTR user_id, pEp_identity_s * ident);
vb@0
   184
    STDMETHOD(set_identity)(pEp_identity_s * ident);
vb@0
   185
    STDMETHOD(generate_keypair)(pEp_identity_s * ident, BSTR * fpr);
vb@0
   186
    STDMETHOD(delete_keypair)(BSTR fpr);
vb@0
   187
    STDMETHOD(import_key)(BSTR key_data);
vb@0
   188
    STDMETHOD(import_key_b)(SAFEARRAY * key_data);
vb@0
   189
    STDMETHOD(export_key)(BSTR fpr, BSTR * key_data);
vb@0
   190
    STDMETHOD(recv_key)(BSTR pattern);
vb@0
   191
    STDMETHOD(find_keys)(BSTR pattern, LPSAFEARRAY * key_list);
vb@0
   192
    STDMETHOD(send_key)(BSTR pattern);
vb@57
   193
    STDMETHOD(get_crashdump_log)(LONG maxlines, BSTR * log);
Dean@151
   194
    STDMETHOD(get_engine_version)(BSTR * engine_version);
vb@59
   195
    STDMETHOD(get_languagelist)(BSTR * languages);
vb@59
   196
    STDMETHOD(get_phrase)(BSTR lang, LONG phrase_id, BSTR * phrase);
vb@11
   197
vb@11
   198
    // keymanagement API
vb@11
   199
vb@24
   200
    STDMETHOD(start_keyserver_lookup)();
vb@24
   201
    STDMETHOD(stop_keyserver_lookup)();
vb@24
   202
vb@0
   203
    STDMETHOD(examine_identity)(pEp_identity_s * ident);
vb@0
   204
    STDMETHOD(verify)(BSTR text, BSTR signature, LPSAFEARRAY * key_list, pEp_STATUS * verify_status);
vb@0
   205
    STDMETHOD(myself)(struct pEp_identity_s *ident, struct pEp_identity_s *result);
vb@0
   206
    STDMETHOD(update_identity)(struct pEp_identity_s *ident, struct pEp_identity_s *result);
vb@49
   207
    STDMETHOD(key_compromized)(struct pEp_identity_s *ident);
Edouard@55
   208
    STDMETHOD(key_reset_trust)(struct pEp_identity_s *ident);
vb@50
   209
    STDMETHOD(trust_personal_key)(struct pEp_identity_s *ident, struct pEp_identity_s *result);
vb@48
   210
vb@65
   211
    // Blacklist API
vb@65
   212
vb@65
   213
    STDMETHOD(blacklist_add)(BSTR fpr);
vb@65
   214
    STDMETHOD(blacklist_delete)(BSTR fpr);
vb@65
   215
    STDMETHOD(blacklist_is_listed)(BSTR fpr, VARIANT_BOOL *listed);
vb@65
   216
    STDMETHOD(blacklist_retrieve)(SAFEARRAY **blacklist);
vb@65
   217
vb@12
   218
    // Message API
vb@12
   219
vb@37
   220
    STDMETHOD(encrypt_message)(text_message * src, text_message * dst, SAFEARRAY * extra);
vb@37
   221
    STDMETHOD(decrypt_message)(text_message * src, text_message * dst, SAFEARRAY ** keylist, pEp_color *rating);
vb@33
   222
    STDMETHOD(outgoing_message_color)(text_message *msg, pEp_color * pVal);
vb@18
   223
    STDMETHOD(identity_color)(pEp_identity_s * ident, pEp_color * pVal);
vb@18
   224
markus@84
   225
	// Event callbacks
markus@84
   226
markus@84
   227
	STDMETHOD(register_callbacks)(IpEpEngineCallbacks *new_callback);
markus@84
   228
	STDMETHOD(unregister_callbacks)(IpEpEngineCallbacks *obsolete_callback);
markus@84
   229
markus@84
   230
protected:
markus@84
   231
	HRESULT Fire_MessageToSend(
markus@84
   232
		/* [in] */ struct text_message *msg);
markus@84
   233
markus@84
   234
	HRESULT Fire_ShowHandshake(
markus@84
   235
		/* [in] */ struct pEp_identity_s *self,
markus@84
   236
		/* [in] */ struct pEp_identity_s *partner,
markus@84
   237
		/* [retval][out] */ sync_handshake_result_s *result);
vb@0
   238
};
vb@0
   239
vb@0
   240
OBJECT_ENTRY_AUTO(__uuidof(pEpEngine), CpEpEngine)