moving inject_sync_event to init() sync
authorVolker Birk <vb@pep.foundation>
Thu, 23 Aug 2018 10:04:33 +0200
branchsync
changeset 28791b90ffed2d89
parent 2878 6163c699dd69
child 2880 fa5b054aa4b6
moving inject_sync_event to init()
src/pEpEngine.c
src/pEpEngine.h
src/sync_api.c
src/sync_api.h
sync/gen_statemachine.ysl2
test/convenience_scripts/mime_decrypt.cc
test/convenience_scripts/mime_encrypt.cc
test/convenience_scripts/mime_encrypt_decrypt.cc
test/pEpEngineTest.cc
test/src/EngineTestSuite.cc
test/src/engine_tests/SyncTests.cc
     1.1 --- a/src/pEpEngine.c	Thu Aug 23 07:33:29 2018 +0200
     1.2 +++ b/src/pEpEngine.c	Thu Aug 23 10:04:33 2018 +0200
     1.3 @@ -491,7 +491,8 @@
     1.4  
     1.5  DYNAMIC_API PEP_STATUS init(
     1.6          PEP_SESSION *session,
     1.7 -        messageToSend_t messageToSend
     1.8 +        messageToSend_t messageToSend,
     1.9 +        inject_sync_event_t inject_sync_event
    1.10      )
    1.11  {
    1.12      PEP_STATUS status = PEP_STATUS_OK;
    1.13 @@ -540,6 +541,7 @@
    1.14  
    1.15      _session->version = PEP_ENGINE_VERSION;
    1.16      _session->messageToSend = messageToSend;
    1.17 +    _session->inject_sync_event = inject_sync_event;
    1.18  
    1.19  #ifdef DEBUG_ERRORSTACK
    1.20      _session->errorstack = new_stringlist("init()");
     2.1 --- a/src/pEpEngine.h	Thu Aug 23 07:33:29 2018 +0200
     2.2 +++ b/src/pEpEngine.h	Thu Aug 23 10:04:33 2018 +0200
     2.3 @@ -92,6 +92,7 @@
     2.4      PEP_SYNC_ILLEGAL_MESSAGE                        = 0x0902,
     2.5      PEP_SYNC_NO_INJECT_CALLBACK                     = 0x0903,
     2.6      PEP_SYNC_NO_CHANNEL                             = 0x0904,
     2.7 +    PEP_SYNC_CANNOT_ENCRYPT                         = 0x0905,
     2.8  
     2.9      PEP_CANNOT_INCREASE_SEQUENCE                    = 0x0971,
    2.10  
    2.11 @@ -134,24 +135,40 @@
    2.12  typedef PEP_STATUS (*messageToSend_t)(void *obj, struct _message *msg);
    2.13  
    2.14  
    2.15 +struct Sync_event;
    2.16 +typedef struct Sync_event *SYNC_EVENT;
    2.17 +
    2.18 +// inject_sync_event - inject sync protocol message
    2.19 +//
    2.20 +//  parameters:
    2.21 +//      ev (in)             event to inject
    2.22 +//      management (in)     application defined; usually a locked queue
    2.23 +//
    2.24 +//  return value:
    2.25 +//      0 if event could be stored successfully or nonzero otherwise
    2.26 +
    2.27 +typedef int (*inject_sync_event_t)(SYNC_EVENT ev, void *management);
    2.28 +
    2.29 +
    2.30  // INIT_STATUS init() - initialize pEpEngine for a thread
    2.31  //
    2.32  //  parameters:
    2.33 -//        session (out)                     init() allocates session memory and
    2.34 +//      session (out)                       init() allocates session memory and
    2.35  //                                          returns a pointer as a handle
    2.36 -//        messageToSend (in)                callback for sending message by the
    2.37 +//      messageToSend (in)                  callback for sending message by the
    2.38  //                                          application
    2.39 +//      inject_sync_event (in)              callback for injecting a sync event
    2.40  //
    2.41  //  return value:
    2.42 -//        PEP_STATUS_OK = 0                 if init() succeeds
    2.43 -//        PEP_INIT_SQLITE3_WITHOUT_MUTEX    if SQLite3 was compiled with
    2.44 -//                                            SQLITE_THREADSAFE 0
    2.45 -//        PEP_INIT_CANNOT_LOAD_GPGME        if libgpgme.dll cannot be found
    2.46 -//        PEP_INIT_GPGME_INIT_FAILED        if GPGME init fails
    2.47 -//        PEP_INIT_CANNOT_OPEN_DB           if user's management db cannot be
    2.48 -//                                            opened
    2.49 -//        PEP_INIT_CANNOT_OPEN_SYSTEM_DB    if system's management db cannot be
    2.50 -//                                            opened
    2.51 +//      PEP_STATUS_OK = 0                   if init() succeeds
    2.52 +//      PEP_INIT_SQLITE3_WITHOUT_MUTEX      if SQLite3 was compiled with
    2.53 +//                                          SQLITE_THREADSAFE 0
    2.54 +//      PEP_INIT_CANNOT_LOAD_GPGME          if libgpgme.dll cannot be found
    2.55 +//      PEP_INIT_GPGME_INIT_FAILED          if GPGME init fails
    2.56 +//      PEP_INIT_CANNOT_OPEN_DB             if user's management db cannot be
    2.57 +//                                          opened
    2.58 +//      PEP_INIT_CANNOT_OPEN_SYSTEM_DB      if system's management db cannot be
    2.59 +//                                          opened
    2.60  //
    2.61  //  caveat:
    2.62  //      THE CALLER MUST GUARD THIS CALL EXTERNALLY WITH A MUTEX. release()
    2.63 @@ -169,7 +186,8 @@
    2.64  
    2.65  DYNAMIC_API PEP_STATUS init(
    2.66          PEP_SESSION *session,
    2.67 -        messageToSend_t messageToSend
    2.68 +        messageToSend_t messageToSend,
    2.69 +        inject_sync_event_t inject_sync_event
    2.70      );
    2.71  
    2.72  
     3.1 --- a/src/sync_api.c	Thu Aug 23 07:33:29 2018 +0200
     3.2 +++ b/src/sync_api.c	Thu Aug 23 10:04:33 2018 +0200
     3.3 @@ -12,17 +12,15 @@
     3.4          PEP_SESSION session,
     3.5          void *management,
     3.6          notifyHandshake_t notifyHandshake,
     3.7 -        inject_sync_event_t inject_sync_event,
     3.8          retrieve_next_sync_event_t retrieve_next_sync_event
     3.9      )
    3.10  {
    3.11 -    assert(session && management && notifyHandshake && inject_sync_event && retrieve_next_sync_event);
    3.12 -    if (!(session && management && notifyHandshake && inject_sync_event && retrieve_next_sync_event))
    3.13 +    assert(session && management && notifyHandshake && retrieve_next_sync_event);
    3.14 +    if (!(session && management && notifyHandshake && retrieve_next_sync_event))
    3.15          return PEP_ILLEGAL_VALUE;
    3.16  
    3.17      session->sync_management = management;
    3.18      session->notifyHandshake = notifyHandshake;
    3.19 -    session->inject_sync_event = inject_sync_event;
    3.20      session->retrieve_next_sync_event = retrieve_next_sync_event;
    3.21  
    3.22      // start state machine
    3.23 @@ -36,7 +34,6 @@
    3.24      // unregister
    3.25      session->sync_management = NULL;
    3.26      session->notifyHandshake = NULL;
    3.27 -    session->inject_sync_event = NULL;
    3.28      session->retrieve_next_sync_event = NULL;
    3.29  }
    3.30  
     4.1 --- a/src/sync_api.h	Thu Aug 23 07:33:29 2018 +0200
     4.2 +++ b/src/sync_api.h	Thu Aug 23 10:04:33 2018 +0200
     4.3 @@ -74,21 +74,6 @@
     4.4      );
     4.5  
     4.6  
     4.7 -struct Sync_event;
     4.8 -typedef struct Sync_event *SYNC_EVENT;
     4.9 -
    4.10 -// inject_sync_event - inject sync protocol message
    4.11 -//
    4.12 -//  parameters:
    4.13 -//      ev (in)             event to inject
    4.14 -//      management (in)     application defined; usually a locked queue
    4.15 -//
    4.16 -//  return value:
    4.17 -//      0 if event could be stored successfully or nonzero otherwise
    4.18 -
    4.19 -typedef int (*inject_sync_event_t)(SYNC_EVENT ev, void *management);
    4.20 -
    4.21 -
    4.22  // retrieve_next_sync_event - receive next sync event
    4.23  //
    4.24  //  parameters:
    4.25 @@ -118,7 +103,6 @@
    4.26          PEP_SESSION session,
    4.27          void *management,
    4.28          notifyHandshake_t notifyHandshake,
    4.29 -        inject_sync_event_t inject_sync_event,
    4.30          retrieve_next_sync_event_t retrieve_next_sync_event
    4.31      );
    4.32  
     5.1 --- a/sync/gen_statemachine.ysl2	Thu Aug 23 07:33:29 2018 +0200
     5.2 +++ b/sync/gen_statemachine.ysl2	Thu Aug 23 10:04:33 2018 +0200
     5.3 @@ -421,8 +421,10 @@
     5.4  
     5.5                          default:
     5.6                              status = encrypt_message(session, _m, NULL, &m, PEP_enc_PEP, 0);
     5.7 -                            if (status)
     5.8 +                            if (status) {
     5.9 +                                status = PEP_SYNC_CANNOT_ENCRYPT;
    5.10                                  goto the_end;
    5.11 +                            }
    5.12                              free_message(_m);
    5.13                      }
    5.14  
     6.1 --- a/test/convenience_scripts/mime_decrypt.cc	Thu Aug 23 07:33:29 2018 +0200
     6.2 +++ b/test/convenience_scripts/mime_decrypt.cc	Thu Aug 23 10:04:33 2018 +0200
     6.3 @@ -20,7 +20,7 @@
     6.4      PEP_SESSION session;
     6.5      
     6.6      cout << "calling init()\n";
     6.7 -    PEP_STATUS status = init(&session, NULL);
     6.8 +    PEP_STATUS status = init(&session, NULL, NULL);
     6.9      assert(status == PEP_STATUS_OK);
    6.10      assert(session);
    6.11      cout << "init() completed.\n";
     7.1 --- a/test/convenience_scripts/mime_encrypt.cc	Thu Aug 23 07:33:29 2018 +0200
     7.2 +++ b/test/convenience_scripts/mime_encrypt.cc	Thu Aug 23 10:04:33 2018 +0200
     7.3 @@ -20,7 +20,7 @@
     7.4      PEP_SESSION session;
     7.5      
     7.6      cout << "calling init()\n";
     7.7 -    PEP_STATUS status = init(&session);
     7.8 +    PEP_STATUS status = init(&session, NULL, NULL);
     7.9      assert(status == PEP_STATUS_OK);
    7.10      assert(session);
    7.11      cout << "init() completed.\n";
     8.1 --- a/test/convenience_scripts/mime_encrypt_decrypt.cc	Thu Aug 23 07:33:29 2018 +0200
     8.2 +++ b/test/convenience_scripts/mime_encrypt_decrypt.cc	Thu Aug 23 10:04:33 2018 +0200
     8.3 @@ -20,7 +20,7 @@
     8.4      PEP_SESSION session;
     8.5      
     8.6      cout << "calling init()\n";
     8.7 -    PEP_STATUS status = init(&session, NULL);
     8.8 +    PEP_STATUS status = init(&session, NULL, NULL);
     8.9      assert(status == PEP_STATUS_OK);
    8.10      assert(session);
    8.11      cout << "init() completed.\n";
     9.1 --- a/test/pEpEngineTest.cc	Thu Aug 23 07:33:29 2018 +0200
     9.2 +++ b/test/pEpEngineTest.cc	Thu Aug 23 10:04:33 2018 +0200
     9.3 @@ -96,14 +96,14 @@
     9.4      PEP_SESSION session;
     9.5  
     9.6      cout << "calling init()\n";
     9.7 -    PEP_STATUS init_result = init(&session, NULL);
     9.8 +    PEP_STATUS init_result = init(&session, NULL, NULL);
     9.9      
    9.10      cout << "returning from init() with result == " << status(init_result) << endl;
    9.11      assert(init_result == PEP_STATUS_OK);
    9.12  
    9.13      PEP_SESSION second_session;
    9.14      cout << "second session test\n";
    9.15 -    PEP_STATUS second_init_result = init(&second_session, NULL);
    9.16 +    PEP_STATUS second_init_result = init(&second_session, NULL, NULL);
    9.17      cout << "returning from second init() with result == " << status(second_init_result) << endl;
    9.18      assert(second_init_result == PEP_STATUS_OK);
    9.19      assert(second_session);
    10.1 --- a/test/src/EngineTestSuite.cc	Thu Aug 23 07:33:29 2018 +0200
    10.2 +++ b/test/src/EngineTestSuite.cc	Thu Aug 23 10:04:33 2018 +0200
    10.3 @@ -116,7 +116,7 @@
    10.4      gpg_agent_conf(true);
    10.5      
    10.6  //    cout << "calling init()\n";
    10.7 -    PEP_STATUS status = init(&session, NULL);
    10.8 +    PEP_STATUS status = init(&session, NULL, NULL);
    10.9      assert(status == PEP_STATUS_OK);
   10.10      assert(session);
   10.11  //    cout << "init() completed.\n";
    11.1 --- a/test/src/engine_tests/SyncTests.cc	Thu Aug 23 07:33:29 2018 +0200
    11.2 +++ b/test/src/engine_tests/SyncTests.cc	Thu Aug 23 10:04:33 2018 +0200
    11.3 @@ -104,7 +104,7 @@
    11.4      cout << "fpr: " << self->fpr << "\n";
    11.5      free_identity(self);
    11.6  
    11.7 -    status = init(&sync, Sync_Adapter::messageToSend);
    11.8 +    status = init(&sync, Sync_Adapter::messageToSend, Sync_Adapter::inject_sync_event);
    11.9      TEST_ASSERT(status == PEP_STATUS_OK);
   11.10  
   11.11      cout << "initialize sync and start first state machine\n";
   11.12 @@ -112,7 +112,6 @@
   11.13              sync,
   11.14              &adapter.q,
   11.15              Sync_Adapter::notifyHandshake,
   11.16 -            Sync_Adapter::inject_sync_event,
   11.17              Sync_Adapter::retrieve_next_sync_event
   11.18          );
   11.19      TEST_ASSERT(status == PEP_STATUS_OK);