CpEpEngine.h
author Volker Birk <vb@pep-project.org>
Sat, 30 May 2015 19:36:36 +0200
changeset 32 b9e23540d7fd
parent 30 5c5f423e79e6
child 33 39c7fbbbe028
permissions -rw-r--r--
locking
     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_identity_helper.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)
    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     HRESULT error(_bstr_t msg);
   111 
   112 private:
   113     PEP_SESSION m_session;
   114     mutex session_mutex;
   115     atomic< identity_queue_t * > identity_queue;
   116     thread *keymanagement_thread;
   117 
   118 public:
   119     STDMETHOD(log)(BSTR title, BSTR entity, BSTR description, BSTR comment);
   120     STDMETHOD(decrypt)(BSTR ctext, BSTR * ptext, LPSAFEARRAY * key_list, pEp_STATUS * decrypt_status);
   121     STDMETHOD(decrypt_b)(BSTR ctext, LPSAFEARRAY * ptext, LPSAFEARRAY * key_list, pEp_STATUS * decrypt_status);
   122     STDMETHOD(encrypt)(SAFEARRAY * key_list, BSTR ptext, BSTR * ctext, pEp_STATUS * status);
   123     STDMETHOD(encrypt_b)(SAFEARRAY * key_list, SAFEARRAY * ptext, BSTR * ctext, pEp_STATUS * status);
   124     STDMETHOD(trustword)(LONG value, BSTR lang, BSTR * word);
   125     STDMETHOD(trustwords)(BSTR fpr, BSTR lang, LONG max_words, BSTR * words);
   126     STDMETHOD(get_identity)(BSTR address, pEp_identity_s * ident);
   127     STDMETHOD(set_identity)(pEp_identity_s * ident);
   128     STDMETHOD(generate_keypair)(pEp_identity_s * ident, BSTR * fpr);
   129     STDMETHOD(delete_keypair)(BSTR fpr);
   130     STDMETHOD(import_key)(BSTR key_data);
   131     STDMETHOD(import_key_b)(SAFEARRAY * key_data);
   132     STDMETHOD(export_key)(BSTR fpr, BSTR * key_data);
   133     STDMETHOD(recv_key)(BSTR pattern);
   134     STDMETHOD(find_keys)(BSTR pattern, LPSAFEARRAY * key_list);
   135     STDMETHOD(send_key)(BSTR pattern);
   136 
   137     // keymanagement API
   138 
   139     STDMETHOD(start_keyserver_lookup)();
   140     STDMETHOD(stop_keyserver_lookup)();
   141 
   142     STDMETHOD(examine_identity)(pEp_identity_s * ident);
   143     STDMETHOD(verify)(BSTR text, BSTR signature, LPSAFEARRAY * key_list, pEp_STATUS * verify_status);
   144     STDMETHOD(myself)(struct pEp_identity_s *ident, struct pEp_identity_s *result);
   145     STDMETHOD(update_identity)(struct pEp_identity_s *ident, struct pEp_identity_s *result);
   146     STDMETHOD(key_compromized)(BSTR fpr);
   147     
   148     // Message API
   149 
   150     STDMETHOD(encrypt_message)(ITextMessage * src, ITextMessage * dst, SAFEARRAY * extra);
   151     STDMETHOD(decrypt_message)(ITextMessage * src, ITextMessage * dst, SAFEARRAY ** keylist, pEp_color *rating);
   152     STDMETHOD(outgoing_message_color)(ITextMessage *msg, pEp_color * pVal);
   153     STDMETHOD(identity_color)(pEp_identity_s * ident, pEp_color * pVal);
   154 
   155 };
   156 
   157 OBJECT_ENTRY_AUTO(__uuidof(pEpEngine), CpEpEngine)