CpEpEngine.h
author Volker Birk <vb@pep-project.org>
Fri, 11 Mar 2016 16:07:00 +0100
changeset 65 4736900394cb
parent 61 d5bf2b6538f8
child 67 6e53205493ef
permissions -rw-r--r--
adding blacklist
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@0
    40
        ::log_event(m_session, "Startup", "pEp COM Adapter", NULL, NULL);
vb@0
    41
    }
vb@24
    42
vb@0
    43
    ~CpEpEngine()
vb@0
    44
    {
vb@26
    45
        stop_keyserver_lookup();
vb@0
    46
        ::log_event(m_session, "Shutdown", "pEp COM Adapter", NULL, NULL);
vb@0
    47
        ::release(m_session);
vb@0
    48
    }
vb@0
    49
vb@0
    50
DECLARE_REGISTRY_RESOURCEID(IDR_PEPENGINE)
vb@0
    51
vb@0
    52
DECLARE_NOT_AGGREGATABLE(CpEpEngine)
vb@0
    53
vb@0
    54
BEGIN_COM_MAP(CpEpEngine)
vb@5
    55
    COM_INTERFACE_ENTRY(IpEpEngine)
vb@5
    56
    COM_INTERFACE_ENTRY(ISupportErrorInfo)
vb@5
    57
    COM_INTERFACE_ENTRY(IConnectionPointContainer)
vb@0
    58
END_COM_MAP()
vb@0
    59
vb@0
    60
BEGIN_CONNECTION_POINT_MAP(CpEpEngine)
vb@0
    61
	CONNECTION_POINT_ENTRY(__uuidof(_IpEpEngineEvents))
vb@0
    62
END_CONNECTION_POINT_MAP()
vb@0
    63
// ISupportsErrorInfo
vb@0
    64
	STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);
vb@0
    65
vb@0
    66
vb@0
    67
	DECLARE_PROTECT_FINAL_CONSTRUCT()
vb@0
    68
vb@0
    69
	HRESULT FinalConstruct()
vb@0
    70
	{
vb@0
    71
		return S_OK;
vb@0
    72
	}
vb@0
    73
vb@0
    74
	void FinalRelease()
vb@0
    75
	{
vb@0
    76
	}
vb@0
    77
vb@0
    78
vb@0
    79
protected:
vb@0
    80
    class session
vb@0
    81
    {
vb@0
    82
    private:
vb@0
    83
        CpEpEngine *me;
vb@0
    84
vb@0
    85
    public:
vb@0
    86
        session(CpEpEngine *myself)
vb@0
    87
        {
vb@0
    88
            me = myself;
vb@0
    89
            me->session_mutex.lock();
vb@0
    90
        }
vb@0
    91
vb@0
    92
        ~session()
vb@0
    93
        {
vb@0
    94
            me->session_mutex.unlock();
vb@0
    95
        }
vb@0
    96
vb@0
    97
        operator PEP_SESSION const () 
vb@0
    98
        {
vb@0
    99
            return me->m_session;
vb@0
   100
        }
vb@0
   101
    };
vb@0
   102
vb@0
   103
    session get_session()
vb@0
   104
    {
vb@0
   105
        return session(this);
vb@0
   106
    }
vb@0
   107
vb@0
   108
    typedef locked_queue<pEp_identity_cpp> identity_queue_t;
vb@0
   109
    static ::pEp_identity * retrieve_next_identity(void *management);
vb@0
   110
    HRESULT error(_bstr_t msg);
vb@0
   111
vb@51
   112
    void verbose(string text)
vb@51
   113
    {
vb@51
   114
        if (verbose_mode) {
vb@51
   115
            stringstream ss;
vb@51
   116
            ss << __FILE__ << ":" << __LINE__ << " " << text;
vb@51
   117
            ::log_event(get_session(), "verbose", "pEp COM Server Adapter", ss.str().c_str(), NULL);
vb@51
   118
        }
vb@51
   119
    }
vb@51
   120
vb@0
   121
private:
vb@0
   122
    PEP_SESSION m_session;
vb@0
   123
    mutex session_mutex;
vb@25
   124
    atomic< identity_queue_t * > identity_queue;
vb@0
   125
    thread *keymanagement_thread;
vb@51
   126
    bool verbose_mode;
vb@0
   127
vb@0
   128
public:
vb@60
   129
    // runtime config of the adapter
vb@60
   130
vb@61
   131
    STDMETHOD(verbose_logging)(VARIANT_BOOL enable);
vb@60
   132
    
vb@60
   133
    // runtime config of the engine
vb@60
   134
vb@61
   135
    STDMETHOD(passive_mode)(VARIANT_BOOL enable);
vb@61
   136
    STDMETHOD(unencrypted_subject)(VARIANT_BOOL enable);
vb@60
   137
vb@60
   138
    // basic API
vb@51
   139
vb@0
   140
    STDMETHOD(log)(BSTR title, BSTR entity, BSTR description, BSTR comment);
vb@0
   141
    STDMETHOD(decrypt)(BSTR ctext, BSTR * ptext, LPSAFEARRAY * key_list, pEp_STATUS * decrypt_status);
vb@0
   142
    STDMETHOD(decrypt_b)(BSTR ctext, LPSAFEARRAY * ptext, LPSAFEARRAY * key_list, pEp_STATUS * decrypt_status);
vb@0
   143
    STDMETHOD(encrypt)(SAFEARRAY * key_list, BSTR ptext, BSTR * ctext, pEp_STATUS * status);
vb@0
   144
    STDMETHOD(encrypt_b)(SAFEARRAY * key_list, SAFEARRAY * ptext, BSTR * ctext, pEp_STATUS * status);
vb@17
   145
    STDMETHOD(trustword)(LONG value, BSTR lang, BSTR * word);
vb@17
   146
    STDMETHOD(trustwords)(BSTR fpr, BSTR lang, LONG max_words, BSTR * words);
vb@0
   147
    STDMETHOD(get_identity)(BSTR address, pEp_identity_s * ident);
vb@0
   148
    STDMETHOD(set_identity)(pEp_identity_s * ident);
vb@0
   149
    STDMETHOD(generate_keypair)(pEp_identity_s * ident, BSTR * fpr);
vb@0
   150
    STDMETHOD(delete_keypair)(BSTR fpr);
vb@0
   151
    STDMETHOD(import_key)(BSTR key_data);
vb@0
   152
    STDMETHOD(import_key_b)(SAFEARRAY * key_data);
vb@0
   153
    STDMETHOD(export_key)(BSTR fpr, BSTR * key_data);
vb@0
   154
    STDMETHOD(recv_key)(BSTR pattern);
vb@0
   155
    STDMETHOD(find_keys)(BSTR pattern, LPSAFEARRAY * key_list);
vb@0
   156
    STDMETHOD(send_key)(BSTR pattern);
vb@57
   157
    STDMETHOD(get_crashdump_log)(LONG maxlines, BSTR * log);
vb@59
   158
    STDMETHOD(get_languagelist)(BSTR * languages);
vb@59
   159
    STDMETHOD(get_phrase)(BSTR lang, LONG phrase_id, BSTR * phrase);
vb@11
   160
vb@11
   161
    // keymanagement API
vb@11
   162
vb@24
   163
    STDMETHOD(start_keyserver_lookup)();
vb@24
   164
    STDMETHOD(stop_keyserver_lookup)();
vb@24
   165
vb@0
   166
    STDMETHOD(examine_identity)(pEp_identity_s * ident);
vb@0
   167
    STDMETHOD(verify)(BSTR text, BSTR signature, LPSAFEARRAY * key_list, pEp_STATUS * verify_status);
vb@0
   168
    STDMETHOD(myself)(struct pEp_identity_s *ident, struct pEp_identity_s *result);
vb@0
   169
    STDMETHOD(update_identity)(struct pEp_identity_s *ident, struct pEp_identity_s *result);
vb@49
   170
    STDMETHOD(key_compromized)(struct pEp_identity_s *ident);
Edouard@55
   171
    STDMETHOD(key_reset_trust)(struct pEp_identity_s *ident);
vb@50
   172
    STDMETHOD(trust_personal_key)(struct pEp_identity_s *ident, struct pEp_identity_s *result);
vb@48
   173
vb@65
   174
    // Blacklist API
vb@65
   175
vb@65
   176
    STDMETHOD(blacklist_add)(BSTR fpr);
vb@65
   177
    STDMETHOD(blacklist_delete)(BSTR fpr);
vb@65
   178
    STDMETHOD(blacklist_is_listed)(BSTR fpr, VARIANT_BOOL *listed);
vb@65
   179
    STDMETHOD(blacklist_retrieve)(SAFEARRAY **blacklist);
vb@65
   180
vb@12
   181
    // Message API
vb@12
   182
vb@37
   183
    STDMETHOD(encrypt_message)(text_message * src, text_message * dst, SAFEARRAY * extra);
vb@37
   184
    STDMETHOD(decrypt_message)(text_message * src, text_message * dst, SAFEARRAY ** keylist, pEp_color *rating);
vb@33
   185
    STDMETHOD(outgoing_message_color)(text_message *msg, pEp_color * pVal);
vb@18
   186
    STDMETHOD(identity_color)(pEp_identity_s * ident, pEp_color * pVal);
vb@18
   187
vb@0
   188
};
vb@0
   189
vb@0
   190
OBJECT_ENTRY_AUTO(__uuidof(pEpEngine), CpEpEngine)