CpEpEngine.h
author Volker Birk <vb@pep-project.org>
Wed, 11 May 2016 19:53:47 +0200
changeset 74 f2531096699e
parent 70 000c4f33e0f8
child 76 cb4430fb48f8
permissions -rw-r--r--
connection point, next step :-/
     1 // CpEpEngine.h : Declaration of the CpEpEngine
     2 
     3 #pragma once
     4 #include "resource.h"       // main symbols
     5 
     6 #include "pEpComServerAdapter_i.h"
     7 #include "_IpEpEngineEvents_CP.h"
     8 #include "locked_queue.hh"
     9 #include "utf8_helper.h"
    10 #include "pEp_utility.h"
    11 
    12 
    13 #if defined(_WIN32_WCE) && !defined(_CE_DCOM) && !defined(_CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA)
    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."
    15 #endif
    16 
    17 using namespace ATL;
    18 using namespace utility;
    19 using namespace pEp::utility;
    20 
    21 // CpEpEngine
    22 
    23 class ATL_NO_VTABLE CpEpEngine :
    24     public CComObjectRootEx<CComObjectThreadModel>,
    25 	public CComCoClass<CpEpEngine, &CLSID_pEpEngine>,
    26 	public ISupportErrorInfo,
    27 	public IConnectionPointContainerImpl<CpEpEngine>,
    28 	public CProxy_IpEpEngineEvents<CpEpEngine>,
    29 	public IpEpEngine
    30 {
    31 protected:
    32     static int examine_identity(pEp_identity *ident, void *management);
    33 
    34 public:
    35     CpEpEngine() : keymanagement_thread(NULL), identity_queue(NULL), verbose_mode(false)
    36 	{
    37         PEP_STATUS status = ::init(&m_session);
    38         assert(status == PEP_STATUS_OK);
    39         ::register_examine_function(m_session, CpEpEngine::examine_identity, (void *)this);
    40         ::log_event(m_session, "Startup", "pEp COM Adapter", NULL, NULL);
    41     }
    42 
    43     ~CpEpEngine()
    44     {
    45         stop_keyserver_lookup();
    46         ::log_event(m_session, "Shutdown", "pEp COM Adapter", NULL, NULL);
    47         ::release(m_session);
    48     }
    49 
    50 DECLARE_REGISTRY_RESOURCEID(IDR_PEPENGINE)
    51 
    52 DECLARE_NOT_AGGREGATABLE(CpEpEngine)
    53 
    54 BEGIN_COM_MAP(CpEpEngine)
    55     COM_INTERFACE_ENTRY(IpEpEngine)
    56     COM_INTERFACE_ENTRY(ISupportErrorInfo)
    57     COM_INTERFACE_ENTRY(IConnectionPointContainer)
    58 END_COM_MAP()
    59 
    60 BEGIN_CONNECTION_POINT_MAP(CpEpEngine)
    61 	CONNECTION_POINT_ENTRY(__uuidof(_IpEpEngineEvents))
    62 END_CONNECTION_POINT_MAP()
    63 // ISupportsErrorInfo
    64 	STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);
    65 
    66 
    67 	DECLARE_PROTECT_FINAL_CONSTRUCT()
    68 
    69 	HRESULT FinalConstruct()
    70 	{
    71 		return S_OK;
    72 	}
    73 
    74 	void FinalRelease()
    75 	{
    76 	}
    77 
    78 
    79 protected:
    80     class session
    81     {
    82     private:
    83         CpEpEngine *me;
    84 
    85     public:
    86         session(CpEpEngine *myself)
    87         {
    88             me = myself;
    89             me->session_mutex.lock();
    90         }
    91 
    92         ~session()
    93         {
    94             me->session_mutex.unlock();
    95         }
    96 
    97         operator PEP_SESSION const () 
    98         {
    99             return me->m_session;
   100         }
   101     };
   102 
   103     session get_session()
   104     {
   105         return session(this);
   106     }
   107 
   108     typedef locked_queue<pEp_identity_cpp> identity_queue_t;
   109     static ::pEp_identity * retrieve_next_identity(void *management);
   110     static PEP_STATUS messageToSend(void *obj, const message *msg);
   111     static sync_handshake_result_s showHandshake(void * obj, const pEp_identity *self, const pEp_identity *partner);
   112 
   113     HRESULT error(_bstr_t msg);
   114 
   115     void verbose(string text)
   116     {
   117         if (verbose_mode) {
   118             stringstream ss;
   119             ss << __FILE__ << ":" << __LINE__ << " " << text;
   120             ::log_event(get_session(), "verbose", "pEp COM Server Adapter", ss.str().c_str(), NULL);
   121         }
   122     }
   123 
   124 private:
   125     PEP_SESSION m_session;
   126     mutex session_mutex;
   127     atomic< identity_queue_t * > identity_queue;
   128     thread *keymanagement_thread;
   129     bool verbose_mode;
   130 
   131 public:
   132     // runtime config of the adapter
   133 
   134     STDMETHOD(verbose_logging)(VARIANT_BOOL enable);
   135     
   136     // runtime config of the engine
   137 
   138     STDMETHOD(passive_mode)(VARIANT_BOOL enable);
   139     STDMETHOD(unencrypted_subject)(VARIANT_BOOL enable);
   140 
   141     // basic API
   142 
   143     STDMETHOD(log)(BSTR title, BSTR entity, BSTR description, BSTR comment);
   144     STDMETHOD(decrypt)(BSTR ctext, BSTR * ptext, LPSAFEARRAY * key_list, pEp_STATUS * decrypt_status);
   145     STDMETHOD(decrypt_b)(BSTR ctext, LPSAFEARRAY * ptext, LPSAFEARRAY * key_list, pEp_STATUS * decrypt_status);
   146     STDMETHOD(encrypt)(SAFEARRAY * key_list, BSTR ptext, BSTR * ctext, pEp_STATUS * status);
   147     STDMETHOD(encrypt_b)(SAFEARRAY * key_list, SAFEARRAY * ptext, BSTR * ctext, pEp_STATUS * status);
   148     STDMETHOD(trustword)(LONG value, BSTR lang, BSTR * word);
   149     STDMETHOD(trustwords)(BSTR fpr, BSTR lang, LONG max_words, BSTR * words);
   150     STDMETHOD(get_identity)(BSTR address, BSTR user_id, pEp_identity_s * ident);
   151     STDMETHOD(set_identity)(pEp_identity_s * ident);
   152     STDMETHOD(generate_keypair)(pEp_identity_s * ident, BSTR * fpr);
   153     STDMETHOD(delete_keypair)(BSTR fpr);
   154     STDMETHOD(import_key)(BSTR key_data);
   155     STDMETHOD(import_key_b)(SAFEARRAY * key_data);
   156     STDMETHOD(export_key)(BSTR fpr, BSTR * key_data);
   157     STDMETHOD(recv_key)(BSTR pattern);
   158     STDMETHOD(find_keys)(BSTR pattern, LPSAFEARRAY * key_list);
   159     STDMETHOD(send_key)(BSTR pattern);
   160     STDMETHOD(get_crashdump_log)(LONG maxlines, BSTR * log);
   161     STDMETHOD(get_languagelist)(BSTR * languages);
   162     STDMETHOD(get_phrase)(BSTR lang, LONG phrase_id, BSTR * phrase);
   163 
   164     // keymanagement API
   165 
   166     STDMETHOD(start_keyserver_lookup)();
   167     STDMETHOD(stop_keyserver_lookup)();
   168 
   169     STDMETHOD(examine_identity)(pEp_identity_s * ident);
   170     STDMETHOD(verify)(BSTR text, BSTR signature, LPSAFEARRAY * key_list, pEp_STATUS * verify_status);
   171     STDMETHOD(myself)(struct pEp_identity_s *ident, struct pEp_identity_s *result);
   172     STDMETHOD(update_identity)(struct pEp_identity_s *ident, struct pEp_identity_s *result);
   173     STDMETHOD(key_compromized)(struct pEp_identity_s *ident);
   174     STDMETHOD(key_reset_trust)(struct pEp_identity_s *ident);
   175     STDMETHOD(trust_personal_key)(struct pEp_identity_s *ident, struct pEp_identity_s *result);
   176 
   177     // Blacklist API
   178 
   179     STDMETHOD(blacklist_add)(BSTR fpr);
   180     STDMETHOD(blacklist_delete)(BSTR fpr);
   181     STDMETHOD(blacklist_is_listed)(BSTR fpr, VARIANT_BOOL *listed);
   182     STDMETHOD(blacklist_retrieve)(SAFEARRAY **blacklist);
   183 
   184     // Message API
   185 
   186     STDMETHOD(encrypt_message)(text_message * src, text_message * dst, SAFEARRAY * extra);
   187     STDMETHOD(decrypt_message)(text_message * src, text_message * dst, SAFEARRAY ** keylist, pEp_color *rating);
   188     STDMETHOD(outgoing_message_color)(text_message *msg, pEp_color * pVal);
   189     STDMETHOD(identity_color)(pEp_identity_s * ident, pEp_color * pVal);
   190 
   191 };
   192 
   193 OBJECT_ENTRY_AUTO(__uuidof(pEpEngine), CpEpEngine)