CpEpEngine.h
author Volker Birk <vb@pep-project.org>
Wed, 25 May 2016 13:04:50 +0200
changeset 83 9b7371990473
parent 80 3862a304c0a9
child 84 ec2e6174b307
permissions -rw-r--r--
correcting signatures
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
vb@0
   110
    typedef locked_queue<pEp_identity_cpp> identity_queue_t;
vb@0
   111
    static ::pEp_identity * retrieve_next_identity(void *management);
vb@74
   112
    static PEP_STATUS messageToSend(void *obj, const message *msg);
vb@83
   113
    static PEP_STATUS showHandshake(void * obj, const pEp_identity *self, const pEp_identity *partner);
vb@74
   114
vb@0
   115
    HRESULT error(_bstr_t msg);
vb@0
   116
vb@51
   117
    void verbose(string text)
vb@51
   118
    {
vb@51
   119
        if (verbose_mode) {
vb@51
   120
            stringstream ss;
vb@51
   121
            ss << __FILE__ << ":" << __LINE__ << " " << text;
vb@51
   122
            ::log_event(get_session(), "verbose", "pEp COM Server Adapter", ss.str().c_str(), NULL);
vb@51
   123
        }
vb@51
   124
    }
vb@51
   125
vb@0
   126
private:
vb@0
   127
    PEP_SESSION m_session;
vb@0
   128
    mutex session_mutex;
vb@25
   129
    atomic< identity_queue_t * > identity_queue;
vb@0
   130
    thread *keymanagement_thread;
vb@51
   131
    bool verbose_mode;
vb@0
   132
vb@0
   133
public:
vb@60
   134
    // runtime config of the adapter
vb@60
   135
vb@61
   136
    STDMETHOD(verbose_logging)(VARIANT_BOOL enable);
vb@60
   137
    
vb@60
   138
    // runtime config of the engine
vb@60
   139
vb@61
   140
    STDMETHOD(passive_mode)(VARIANT_BOOL enable);
vb@61
   141
    STDMETHOD(unencrypted_subject)(VARIANT_BOOL enable);
vb@60
   142
vb@60
   143
    // basic API
vb@51
   144
vb@0
   145
    STDMETHOD(log)(BSTR title, BSTR entity, BSTR description, BSTR comment);
vb@0
   146
    STDMETHOD(decrypt)(BSTR ctext, BSTR * ptext, LPSAFEARRAY * key_list, pEp_STATUS * decrypt_status);
vb@0
   147
    STDMETHOD(decrypt_b)(BSTR ctext, LPSAFEARRAY * ptext, LPSAFEARRAY * key_list, pEp_STATUS * decrypt_status);
vb@0
   148
    STDMETHOD(encrypt)(SAFEARRAY * key_list, BSTR ptext, BSTR * ctext, pEp_STATUS * status);
vb@0
   149
    STDMETHOD(encrypt_b)(SAFEARRAY * key_list, SAFEARRAY * ptext, BSTR * ctext, pEp_STATUS * status);
vb@17
   150
    STDMETHOD(trustword)(LONG value, BSTR lang, BSTR * word);
vb@17
   151
    STDMETHOD(trustwords)(BSTR fpr, BSTR lang, LONG max_words, BSTR * words);
vb@70
   152
    STDMETHOD(get_identity)(BSTR address, BSTR user_id, pEp_identity_s * ident);
vb@0
   153
    STDMETHOD(set_identity)(pEp_identity_s * ident);
vb@0
   154
    STDMETHOD(generate_keypair)(pEp_identity_s * ident, BSTR * fpr);
vb@0
   155
    STDMETHOD(delete_keypair)(BSTR fpr);
vb@0
   156
    STDMETHOD(import_key)(BSTR key_data);
vb@0
   157
    STDMETHOD(import_key_b)(SAFEARRAY * key_data);
vb@0
   158
    STDMETHOD(export_key)(BSTR fpr, BSTR * key_data);
vb@0
   159
    STDMETHOD(recv_key)(BSTR pattern);
vb@0
   160
    STDMETHOD(find_keys)(BSTR pattern, LPSAFEARRAY * key_list);
vb@0
   161
    STDMETHOD(send_key)(BSTR pattern);
vb@57
   162
    STDMETHOD(get_crashdump_log)(LONG maxlines, BSTR * log);
vb@59
   163
    STDMETHOD(get_languagelist)(BSTR * languages);
vb@59
   164
    STDMETHOD(get_phrase)(BSTR lang, LONG phrase_id, BSTR * phrase);
vb@11
   165
vb@11
   166
    // keymanagement API
vb@11
   167
vb@24
   168
    STDMETHOD(start_keyserver_lookup)();
vb@24
   169
    STDMETHOD(stop_keyserver_lookup)();
vb@24
   170
vb@0
   171
    STDMETHOD(examine_identity)(pEp_identity_s * ident);
vb@0
   172
    STDMETHOD(verify)(BSTR text, BSTR signature, LPSAFEARRAY * key_list, pEp_STATUS * verify_status);
vb@0
   173
    STDMETHOD(myself)(struct pEp_identity_s *ident, struct pEp_identity_s *result);
vb@0
   174
    STDMETHOD(update_identity)(struct pEp_identity_s *ident, struct pEp_identity_s *result);
vb@49
   175
    STDMETHOD(key_compromized)(struct pEp_identity_s *ident);
Edouard@55
   176
    STDMETHOD(key_reset_trust)(struct pEp_identity_s *ident);
vb@50
   177
    STDMETHOD(trust_personal_key)(struct pEp_identity_s *ident, struct pEp_identity_s *result);
vb@48
   178
vb@65
   179
    // Blacklist API
vb@65
   180
vb@65
   181
    STDMETHOD(blacklist_add)(BSTR fpr);
vb@65
   182
    STDMETHOD(blacklist_delete)(BSTR fpr);
vb@65
   183
    STDMETHOD(blacklist_is_listed)(BSTR fpr, VARIANT_BOOL *listed);
vb@65
   184
    STDMETHOD(blacklist_retrieve)(SAFEARRAY **blacklist);
vb@65
   185
vb@12
   186
    // Message API
vb@12
   187
vb@37
   188
    STDMETHOD(encrypt_message)(text_message * src, text_message * dst, SAFEARRAY * extra);
vb@37
   189
    STDMETHOD(decrypt_message)(text_message * src, text_message * dst, SAFEARRAY ** keylist, pEp_color *rating);
vb@33
   190
    STDMETHOD(outgoing_message_color)(text_message *msg, pEp_color * pVal);
vb@18
   191
    STDMETHOD(identity_color)(pEp_identity_s * ident, pEp_color * pVal);
vb@18
   192
vb@0
   193
};
vb@0
   194
vb@0
   195
OBJECT_ENTRY_AUTO(__uuidof(pEpEngine), CpEpEngine)