start/stop semantics for keyserver lookup
authorVolker Birk <vb@pep-project.org>
Fri, 29 May 2015 13:08:51 +0200
changeset 24ef134b3fa18a
parent 23 720af5e728bc
child 25 dfedbea089a3
start/stop semantics for keyserver lookup
CpEpEngine.cpp
CpEpEngine.h
pEpCOMServerAdapter.idl
pEpCOMServerAdapter_i.c
pEpCOMServerAdapter_i.h
     1.1 --- a/CpEpEngine.cpp	Sun May 24 11:04:36 2015 +0200
     1.2 +++ b/CpEpEngine.cpp	Fri May 29 13:08:51 2015 +0200
     1.3 @@ -664,17 +664,50 @@
     1.4          return S_OK;
     1.5  }
     1.6  
     1.7 +STDMETHODIMP CpEpEngine::start_keyserver_lookup()
     1.8 +{
     1.9 +    if (keymanagement_thread)
    1.10 +        return S_OK;
    1.11 +
    1.12 +    identity_queue = new identity_queue_t();
    1.13 +
    1.14 +    keymanagement_thread = new thread(::do_keymanagement, retrieve_next_identity, (void *) identity_queue);
    1.15 +    keymanagement_thread->detach();
    1.16 +
    1.17 +    return S_OK;
    1.18 +}
    1.19 +
    1.20 +STDMETHODIMP CpEpEngine::stop_keyserver_lookup()
    1.21 +{
    1.22 +    if (keymanagement_thread == NULL)
    1.23 +        return S_OK;
    1.24 +
    1.25 +    pEp_identity_cpp shutdown;
    1.26 +    identity_queue->push_front(shutdown);
    1.27 +
    1.28 +    keymanagement_thread->join();
    1.29 +    delete keymanagement_thread;
    1.30 +    keymanagement_thread = NULL;
    1.31 +
    1.32 +    delete identity_queue;
    1.33 +    identity_queue = NULL;
    1.34 +
    1.35 +    return S_OK;
    1.36 +}
    1.37 +
    1.38  STDMETHODIMP CpEpEngine::examine_identity(pEp_identity_s * ident)
    1.39  {
    1.40      assert(ident);
    1.41      if (ident == NULL)
    1.42          return E_INVALIDARG;
    1.43  
    1.44 -    try {
    1.45 -        identity_queue->push_back(ident);
    1.46 -    }
    1.47 -    catch (bad_alloc) {
    1.48 -        return E_OUTOFMEMORY;
    1.49 +    if (identity_queue) {
    1.50 +        try {
    1.51 +            identity_queue->push_back(ident);
    1.52 +        }
    1.53 +        catch (bad_alloc) {
    1.54 +            return E_OUTOFMEMORY;
    1.55 +        }
    1.56      }
    1.57  
    1.58      return S_OK;
    1.59 @@ -689,12 +722,13 @@
    1.60      pEp_identity_cpp _ident(myself);
    1.61      _ident.me = true;
    1.62  
    1.63 -    ::log_event(get_session(), "examine_myself", "debug", _ident.address.c_str(), NULL);
    1.64 -    try {
    1.65 -        identity_queue->push_front(_ident);
    1.66 -    }
    1.67 -    catch (bad_alloc) {
    1.68 -        return E_OUTOFMEMORY;
    1.69 +    if (identity_queue) {
    1.70 +        try {
    1.71 +            identity_queue->push_front(_ident);
    1.72 +        }
    1.73 +        catch (bad_alloc) {
    1.74 +            return E_OUTOFMEMORY;
    1.75 +        }
    1.76      }
    1.77  
    1.78      return S_OK;
    1.79 @@ -749,8 +783,10 @@
    1.80          assert(_ident->fpr);
    1.81          copy_identity(result, _ident);
    1.82          if (_ident->comm_type == PEP_ct_unknown || _ident->comm_type == PEP_ct_key_expired) {
    1.83 -            pEp_identity_cpp _ident_cpp(_ident);
    1.84 -            identity_queue->push_back(_ident_cpp);
    1.85 +            if (identity_queue) {
    1.86 +                pEp_identity_cpp _ident_cpp(_ident);
    1.87 +                identity_queue->push_back(_ident_cpp);
    1.88 +            }
    1.89          }
    1.90          ::free_identity(_ident);
    1.91          return S_OK;
     2.1 --- a/CpEpEngine.h	Sun May 24 11:04:36 2015 +0200
     2.2 +++ b/CpEpEngine.h	Fri May 29 13:08:51 2015 +0200
     2.3 @@ -31,19 +31,15 @@
     2.4  	public IpEpEngine
     2.5  {
     2.6  public:
     2.7 -	CpEpEngine()
     2.8 +    CpEpEngine() : keymanagement_thread(NULL), identity_queue(NULL)
     2.9  	{
    2.10          PEP_STATUS status = ::init(&m_session);
    2.11          assert(status == PEP_STATUS_OK);
    2.12          ::log_event(m_session, "Startup", "pEp COM Adapter", NULL, NULL);
    2.13 -        identity_queue = new identity_queue_t();
    2.14 -        keymanagement_thread = new thread(::do_keymanagement, retrieve_next_identity, (void *) identity_queue);
    2.15 -        keymanagement_thread->detach();
    2.16      }
    2.17 +
    2.18      ~CpEpEngine()
    2.19      {
    2.20 -        pEp_identity_cpp shutdown;
    2.21 -        identity_queue->push_front(shutdown);
    2.22          ::log_event(m_session, "Shutdown", "pEp COM Adapter", NULL, NULL);
    2.23          ::release(m_session);
    2.24      }
    2.25 @@ -137,6 +133,9 @@
    2.26  
    2.27      // keymanagement API
    2.28  
    2.29 +    STDMETHOD(start_keyserver_lookup)();
    2.30 +    STDMETHOD(stop_keyserver_lookup)();
    2.31 +
    2.32      STDMETHOD(examine_identity)(pEp_identity_s * ident);
    2.33      STDMETHOD(examine_myself)(pEp_identity_s * myself);
    2.34      STDMETHOD(verify)(BSTR text, BSTR signature, LPSAFEARRAY * key_list, pEp_STATUS * verify_status);
     3.1 --- a/pEpCOMServerAdapter.idl	Sun May 24 11:04:36 2015 +0200
     3.2 +++ b/pEpCOMServerAdapter.idl	Fri May 29 13:08:51 2015 +0200
     3.3 @@ -208,6 +208,9 @@
     3.4      HRESULT find_keys([in] BSTR pattern, [out, retval] SAFEARRAY(BSTR) * key_list);
     3.5      HRESULT send_key([in] BSTR pattern);
     3.6  
     3.7 +    HRESULT start_keyserver_lookup();
     3.8 +    HRESULT stop_keyserver_lookup();
     3.9 +
    3.10      HRESULT examine_identity([in] struct pEp_identity_s * ident);
    3.11      HRESULT examine_myself([in] struct pEp_identity_s * myself);
    3.12      HRESULT myself([in] struct pEp_identity_s *ident, [out, retval] struct pEp_identity_s *result);
     4.1 --- a/pEpCOMServerAdapter_i.c	Sun May 24 11:04:36 2015 +0200
     4.2 +++ b/pEpCOMServerAdapter_i.c	Fri May 29 13:08:51 2015 +0200
     4.3 @@ -6,7 +6,7 @@
     4.4  
     4.5  
     4.6   /* File created by MIDL compiler version 8.00.0603 */
     4.7 -/* at Fri May 22 14:25:56 2015
     4.8 +/* at Fri May 29 13:07:51 2015
     4.9   */
    4.10  /* Compiler settings for pEpCOMServerAdapter.idl:
    4.11      Oicf, W1, Zp8, env=Win32 (32b run), target_arch=X86 8.00.0603 
     5.1 --- a/pEpCOMServerAdapter_i.h	Sun May 24 11:04:36 2015 +0200
     5.2 +++ b/pEpCOMServerAdapter_i.h	Fri May 29 13:08:51 2015 +0200
     5.3 @@ -4,7 +4,7 @@
     5.4  
     5.5  
     5.6   /* File created by MIDL compiler version 8.00.0603 */
     5.7 -/* at Fri May 22 14:25:56 2015
     5.8 +/* at Fri May 29 13:07:51 2015
     5.9   */
    5.10  /* Compiler settings for pEpCOMServerAdapter.idl:
    5.11      Oicf, W1, Zp8, env=Win32 (32b run), target_arch=X86 8.00.0603 
    5.12 @@ -768,6 +768,10 @@
    5.13          virtual HRESULT STDMETHODCALLTYPE send_key( 
    5.14              /* [in] */ BSTR pattern) = 0;
    5.15          
    5.16 +        virtual HRESULT STDMETHODCALLTYPE start_keyserver_lookup( void) = 0;
    5.17 +        
    5.18 +        virtual HRESULT STDMETHODCALLTYPE stop_keyserver_lookup( void) = 0;
    5.19 +        
    5.20          virtual HRESULT STDMETHODCALLTYPE examine_identity( 
    5.21              /* [in] */ struct pEp_identity_s *ident) = 0;
    5.22          
    5.23 @@ -924,6 +928,12 @@
    5.24              IpEpEngine * This,
    5.25              /* [in] */ BSTR pattern);
    5.26          
    5.27 +        HRESULT ( STDMETHODCALLTYPE *start_keyserver_lookup )( 
    5.28 +            IpEpEngine * This);
    5.29 +        
    5.30 +        HRESULT ( STDMETHODCALLTYPE *stop_keyserver_lookup )( 
    5.31 +            IpEpEngine * This);
    5.32 +        
    5.33          HRESULT ( STDMETHODCALLTYPE *examine_identity )( 
    5.34              IpEpEngine * This,
    5.35              /* [in] */ struct pEp_identity_s *ident);
    5.36 @@ -1046,6 +1056,12 @@
    5.37  #define IpEpEngine_send_key(This,pattern)	\
    5.38      ( (This)->lpVtbl -> send_key(This,pattern) ) 
    5.39  
    5.40 +#define IpEpEngine_start_keyserver_lookup(This)	\
    5.41 +    ( (This)->lpVtbl -> start_keyserver_lookup(This) ) 
    5.42 +
    5.43 +#define IpEpEngine_stop_keyserver_lookup(This)	\
    5.44 +    ( (This)->lpVtbl -> stop_keyserver_lookup(This) ) 
    5.45 +
    5.46  #define IpEpEngine_examine_identity(This,ident)	\
    5.47      ( (This)->lpVtbl -> examine_identity(This,ident) ) 
    5.48