... sync
authorVolker Birk <vb@pep.foundation>
Wed, 15 Aug 2018 18:31:02 +0200
branchsync
changeset 2847930626fcac04
parent 2846 7444832c5c6e
child 2848 641d523b9c0f
...
src/Makefile
src/pEp_internal.h
src/sync.c
src/sync.h
src/sync_api.c
src/sync_api.h
sync/gen_statemachine.ysl2
test/convenience_scripts/mime_decrypt.cc
test/convenience_scripts/mime_encrypt_decrypt.cc
test/pEpEngineTest.cc
test/src/EngineTestSuite.cc
test/src/util/test_util.cc
     1.1 --- a/src/Makefile	Mon Aug 13 20:39:25 2018 +0200
     1.2 +++ b/src/Makefile	Wed Aug 15 18:31:02 2018 +0200
     1.3 @@ -89,8 +89,8 @@
     1.4  	mkdir -p $(PREFIX)/include/pEp
     1.5  	cp -v pEpEngine.h keymanagement.h message_api.h dynamic_api.h stringlist.h \
     1.6  	      timestamp.h identity_list.h bloblist.h stringpair.h message.h mime.h \
     1.7 -	      cryptotech.h sync.h sync_fsm.h sync_app.h blacklist.h pEp_string.h \
     1.8 -	      openpgp_compat.h $(PREFIX)/include/pEp/
     1.9 +	      cryptotech.h sync_api.h blacklist.h pEp_string.h openpgp_compat.h \
    1.10 +		  ../asn.1/*.h $(PREFIX)/include/pEp/
    1.11  
    1.12  .PHONY: uninstall
    1.13  uninstall:
     2.1 --- a/src/pEp_internal.h	Mon Aug 13 20:39:25 2018 +0200
     2.2 +++ b/src/pEp_internal.h	Wed Aug 15 18:31:02 2018 +0200
     2.3 @@ -106,7 +106,7 @@
     2.4  #include "keymanagement.h"
     2.5  #include "cryptotech.h"
     2.6  #include "transport.h"
     2.7 -#include "sync.h"
     2.8 +#include "sync_api.h"
     2.9  #include "Sync_func.h"
    2.10  
    2.11  #define NOT_IMPLEMENTED assert(0); return PEP_UNKNOWN_ERROR;
     3.1 --- a/src/sync.c	Mon Aug 13 20:39:25 2018 +0200
     3.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.3 @@ -1,121 +0,0 @@
     3.4 -// This file is under GNU General Public License 3.0
     3.5 -// see LICENSE.txt
     3.6 -
     3.7 -#include "pEp_internal.h"
     3.8 -
     3.9 -#include <memory.h>
    3.10 -#include <assert.h>
    3.11 -
    3.12 -#include "KeySync_fsm.h"
    3.13 -
    3.14 -DYNAMIC_API PEP_STATUS register_sync_callbacks(
    3.15 -        PEP_SESSION session,
    3.16 -        void *management,
    3.17 -        notifyHandshake_t notifyHandshake,
    3.18 -        inject_sync_event_t inject_sync_event,
    3.19 -        retrieve_next_sync_event_t retrieve_next_sync_event
    3.20 -    )
    3.21 -{
    3.22 -    assert(session && management && notifyHandshake && inject_sync_event && retrieve_next_sync_event);
    3.23 -    if (!(session && management && notifyHandshake && inject_sync_event && retrieve_next_sync_event))
    3.24 -        return PEP_ILLEGAL_VALUE;
    3.25 -
    3.26 -    session->sync_management = management;
    3.27 -    session->notifyHandshake = notifyHandshake;
    3.28 -    session->inject_sync_event = inject_sync_event;
    3.29 -    session->retrieve_next_sync_event = retrieve_next_sync_event;
    3.30 -
    3.31 -    return PEP_STATUS_OK;
    3.32 -}
    3.33 -
    3.34 -DYNAMIC_API void unregister_sync_callbacks(PEP_SESSION session) {
    3.35 -    // stop state machine
    3.36 -    free_Sync_state(session);
    3.37 -
    3.38 -    // unregister
    3.39 -    session->sync_management = NULL;
    3.40 -    session->notifyHandshake = NULL;
    3.41 -    session->inject_sync_event = NULL;
    3.42 -    session->retrieve_next_sync_event = NULL;
    3.43 -}
    3.44 -
    3.45 -DYNAMIC_API PEP_STATUS deliverHandshakeResult(
    3.46 -        PEP_SESSION session,
    3.47 -        pEp_identity *partner,
    3.48 -        sync_handshake_result result
    3.49 -    )
    3.50 -{
    3.51 -    assert(session);
    3.52 -    if (!session)
    3.53 -        return PEP_ILLEGAL_VALUE;
    3.54 -
    3.55 -    PEP_STATUS status = PEP_STATUS_OK;
    3.56 -
    3.57 -    int event;
    3.58 -    bool need_partner = false;
    3.59 -
    3.60 -    switch (result) {
    3.61 -        case SYNC_HANDSHAKE_CANCEL:
    3.62 -            event = Cancel;
    3.63 -            break;
    3.64 -        case SYNC_HANDSHAKE_ACCEPTED:
    3.65 -        {
    3.66 -            event = Accept;
    3.67 -            break;
    3.68 -        }
    3.69 -        case SYNC_HANDSHAKE_REJECTED:
    3.70 -        {
    3.71 -            event = Reject;
    3.72 -            break;
    3.73 -        }
    3.74 -        default:
    3.75 -            return PEP_ILLEGAL_VALUE;
    3.76 -    }
    3.77 -
    3.78 -    pEp_identity *_partner = NULL;
    3.79 -    if(need_partner){
    3.80 -        _partner = identity_dup(partner);
    3.81 -        if (_partner == NULL)
    3.82 -            return PEP_OUT_OF_MEMORY;
    3.83 -    }
    3.84 -    status = send_Sync_message(session, Sync_PR_keysync, event);
    3.85 -
    3.86 -    return status;
    3.87 -}
    3.88 -
    3.89 -DYNAMIC_API PEP_STATUS do_sync_protocol(
    3.90 -        PEP_SESSION session,
    3.91 -        void *obj
    3.92 -    )
    3.93 -{
    3.94 -    Sync_event_t *event= NULL;
    3.95 -    PEP_STATUS status = PEP_STATUS_OK;
    3.96 -
    3.97 -    assert(session && session->retrieve_next_sync_event);
    3.98 -    if (!(session && session->retrieve_next_sync_event))
    3.99 -        return PEP_ILLEGAL_VALUE;
   3.100 -
   3.101 -    log_event(session, "sync_protocol thread started", "pEp sync protocol", NULL, NULL);
   3.102 -
   3.103 -    session->sync_obj = obj;
   3.104 -    while (true) 
   3.105 -    {
   3.106 -        event = session->retrieve_next_sync_event(session->sync_management);
   3.107 -        if (!event)
   3.108 -            break;
   3.109 -
   3.110 -        status = recv_Sync_event(session, event);
   3.111 -        if (status != PEP_STATUS_OK && status != PEP_MESSAGE_IGNORE) {
   3.112 -            char buffer[MAX_LINELENGTH];
   3.113 -            memset(buffer, 0, MAX_LINELENGTH);
   3.114 -            snprintf(buffer, MAX_LINELENGTH, "problem with msg received: %d\n", (int) status);
   3.115 -            log_event(session, buffer, "pEp sync protocol", NULL, NULL);
   3.116 -        }
   3.117 -    }
   3.118 -    session->sync_obj = NULL;
   3.119 -
   3.120 -    log_event(session, "sync_protocol thread shutdown", "pEp sync protocol", NULL, NULL);
   3.121 -
   3.122 -    return PEP_STATUS_OK;
   3.123 -}
   3.124 -
     4.1 --- a/src/sync.h	Mon Aug 13 20:39:25 2018 +0200
     4.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.3 @@ -1,152 +0,0 @@
     4.4 -// This file is under GNU General Public License 3.0
     4.5 -// see LICENSE.txt
     4.6 -
     4.7 -#pragma once
     4.8 -
     4.9 -
    4.10 -#include "message.h"
    4.11 -#include "Sync_event.h"
    4.12 -
    4.13 -
    4.14 -#ifdef __cplusplus
    4.15 -extern "C" {
    4.16 -#endif
    4.17 -
    4.18 -
    4.19 -typedef enum _sync_handshake_signal {
    4.20 -    SYNC_NOTIFY_UNDEFINED = 0,
    4.21 -
    4.22 -    // request show handshake dialog
    4.23 -    SYNC_NOTIFY_INIT_ADD_OUR_DEVICE,
    4.24 -    SYNC_NOTIFY_INIT_ADD_OTHER_DEVICE,
    4.25 -    SYNC_NOTIFY_INIT_FORM_GROUP,
    4.26 -    SYNC_NOTIFY_INIT_MOVE_OUR_DEVICE,
    4.27 -
    4.28 -    // handshake process timed out
    4.29 -    SYNC_NOTIFY_TIMEOUT,
    4.30 -
    4.31 -    // handshake accepted by user
    4.32 -    SYNC_NOTIFY_ACCEPTED_DEVICE_ADDED,
    4.33 -    SYNC_NOTIFY_ACCEPTED_GROUP_CREATED,
    4.34 -    SYNC_NOTIFY_ACCEPTED_DEVICE_MOVED,
    4.35 -
    4.36 -    // handshake dialog must be closed
    4.37 -    SYNC_NOTIFY_OVERTAKEN
    4.38 -} sync_handshake_signal;
    4.39 -
    4.40 -
    4.41 -// notifyHandshake() - notify UI about sync handshaking process
    4.42 -//
    4.43 -//  parameters:
    4.44 -//      obj (in)        object handle (implementation defined)
    4.45 -//      me (in)         own identity
    4.46 -//      partner (in)    identity of partner
    4.47 -//      signal (in)     reason of the notification
    4.48 -//
    4.49 -//  return value:
    4.50 -//      PEP_STATUS_OK or any other value on error
    4.51 -//
    4.52 -//  caveat:
    4.53 -//      ownership of self and partner go to the callee
    4.54 -
    4.55 -typedef PEP_STATUS (*notifyHandshake_t)(
    4.56 -        void *obj,
    4.57 -        pEp_identity *me,
    4.58 -        pEp_identity *partner,
    4.59 -        sync_handshake_signal signal
    4.60 -    );
    4.61 -
    4.62 -typedef enum _sync_handshake_result {
    4.63 -    SYNC_HANDSHAKE_CANCEL = -1,
    4.64 -    SYNC_HANDSHAKE_ACCEPTED = 0,
    4.65 -    SYNC_HANDSHAKE_REJECTED = 1
    4.66 -} sync_handshake_result;
    4.67 -
    4.68 -// deliverHandshakeResult() - give the result of the handshake dialog
    4.69 -//
    4.70 -//  parameters:
    4.71 -//      session (in)        session handle
    4.72 -//      result (in)         handshake result
    4.73 -
    4.74 -DYNAMIC_API PEP_STATUS deliverHandshakeResult(
    4.75 -        PEP_SESSION session,
    4.76 -        pEp_identity *partner,
    4.77 -        sync_handshake_result result
    4.78 -    );
    4.79 -
    4.80 -
    4.81 -// inject_sync_event - inject sync protocol message
    4.82 -//
    4.83 -//  parameters:
    4.84 -//      ev (in)             event to inject
    4.85 -//      management (in)     application defined
    4.86 -//
    4.87 -//  return value:
    4.88 -//      0 if event could be stored successfully or nonzero otherwise
    4.89 -
    4.90 -typedef int (*inject_sync_event_t)(Sync_event_t *ev, void *management);
    4.91 -
    4.92 -
    4.93 -// retrieve_next_sync_event - receive next sync event
    4.94 -//
    4.95 -//  parameters:
    4.96 -//      management (in)     application defined
    4.97 -//
    4.98 -//  return value:
    4.99 -//      next event
   4.100 -
   4.101 -typedef Sync_event_t *(*retrieve_next_sync_event_t)(void *management);
   4.102 -
   4.103 -
   4.104 -// register_sync_callbacks() - register adapter's callbacks
   4.105 -//
   4.106 -//  parameters:
   4.107 -//      session (in)                    session where to store obj handle
   4.108 -//      management (in)                 application defined
   4.109 -//      notifyHandshake (in)            callback for doing the handshake
   4.110 -//      retrieve_next_sync_event (in)   callback for receiving sync event
   4.111 -//
   4.112 -//  return value:
   4.113 -//      PEP_STATUS_OK or any other value on errror
   4.114 -//
   4.115 -//  caveat:
   4.116 -//      call that BEFORE you're using any other part of the engine
   4.117 -
   4.118 -DYNAMIC_API PEP_STATUS register_sync_callbacks(
   4.119 -        PEP_SESSION session,
   4.120 -        void *management,
   4.121 -        notifyHandshake_t notifyHandshake,
   4.122 -        inject_sync_event_t inject_sync_event,
   4.123 -        retrieve_next_sync_event_t retrieve_next_sync_event
   4.124 -    );
   4.125 -
   4.126 -DYNAMIC_API void unregister_sync_callbacks(PEP_SESSION session);
   4.127 -
   4.128 -
   4.129 -// do_sync_protocol() - function to be run on an extra thread
   4.130 -//
   4.131 -//  parameters:
   4.132 -//      session                 pEp session to use
   4.133 -//      retrieve_next_sync_msg  pointer to retrieve_next_identity() callback
   4.134 -//                              which returns at least a valid address field in
   4.135 -//                              the identity struct
   4.136 -//      obj                     application defined sync object
   4.137 -//
   4.138 -//  return value:
   4.139 -//      PEP_STATUS_OK if thread has to terminate successfully or any other
   4.140 -//      value on failure
   4.141 -//
   4.142 -//  caveat:
   4.143 -//      to ensure proper working of this library, a thread has to be started
   4.144 -//      with this function immediately after initialization
   4.145 -
   4.146 -DYNAMIC_API PEP_STATUS do_sync_protocol(
   4.147 -        PEP_SESSION session,
   4.148 -        void *obj
   4.149 -    );
   4.150 -
   4.151 -
   4.152 -#ifdef __cplusplus
   4.153 -}
   4.154 -#endif
   4.155 -
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/src/sync_api.c	Wed Aug 15 18:31:02 2018 +0200
     5.3 @@ -0,0 +1,121 @@
     5.4 +// This file is under GNU General Public License 3.0
     5.5 +// see LICENSE.txt
     5.6 +
     5.7 +#include "pEp_internal.h"
     5.8 +
     5.9 +#include <memory.h>
    5.10 +#include <assert.h>
    5.11 +
    5.12 +#include "KeySync_fsm.h"
    5.13 +
    5.14 +DYNAMIC_API PEP_STATUS register_sync_callbacks(
    5.15 +        PEP_SESSION session,
    5.16 +        void *management,
    5.17 +        notifyHandshake_t notifyHandshake,
    5.18 +        inject_sync_event_t inject_sync_event,
    5.19 +        retrieve_next_sync_event_t retrieve_next_sync_event
    5.20 +    )
    5.21 +{
    5.22 +    assert(session && management && notifyHandshake && inject_sync_event && retrieve_next_sync_event);
    5.23 +    if (!(session && management && notifyHandshake && inject_sync_event && retrieve_next_sync_event))
    5.24 +        return PEP_ILLEGAL_VALUE;
    5.25 +
    5.26 +    session->sync_management = management;
    5.27 +    session->notifyHandshake = notifyHandshake;
    5.28 +    session->inject_sync_event = inject_sync_event;
    5.29 +    session->retrieve_next_sync_event = retrieve_next_sync_event;
    5.30 +
    5.31 +    return PEP_STATUS_OK;
    5.32 +}
    5.33 +
    5.34 +DYNAMIC_API void unregister_sync_callbacks(PEP_SESSION session) {
    5.35 +    // stop state machine
    5.36 +    free_Sync_state(session);
    5.37 +
    5.38 +    // unregister
    5.39 +    session->sync_management = NULL;
    5.40 +    session->notifyHandshake = NULL;
    5.41 +    session->inject_sync_event = NULL;
    5.42 +    session->retrieve_next_sync_event = NULL;
    5.43 +}
    5.44 +
    5.45 +DYNAMIC_API PEP_STATUS deliverHandshakeResult(
    5.46 +        PEP_SESSION session,
    5.47 +        pEp_identity *partner,
    5.48 +        sync_handshake_result result
    5.49 +    )
    5.50 +{
    5.51 +    assert(session);
    5.52 +    if (!session)
    5.53 +        return PEP_ILLEGAL_VALUE;
    5.54 +
    5.55 +    PEP_STATUS status = PEP_STATUS_OK;
    5.56 +
    5.57 +    int event;
    5.58 +    bool need_partner = false;
    5.59 +
    5.60 +    switch (result) {
    5.61 +        case SYNC_HANDSHAKE_CANCEL:
    5.62 +            event = Cancel;
    5.63 +            break;
    5.64 +        case SYNC_HANDSHAKE_ACCEPTED:
    5.65 +        {
    5.66 +            event = Accept;
    5.67 +            break;
    5.68 +        }
    5.69 +        case SYNC_HANDSHAKE_REJECTED:
    5.70 +        {
    5.71 +            event = Reject;
    5.72 +            break;
    5.73 +        }
    5.74 +        default:
    5.75 +            return PEP_ILLEGAL_VALUE;
    5.76 +    }
    5.77 +
    5.78 +    pEp_identity *_partner = NULL;
    5.79 +    if(need_partner){
    5.80 +        _partner = identity_dup(partner);
    5.81 +        if (_partner == NULL)
    5.82 +            return PEP_OUT_OF_MEMORY;
    5.83 +    }
    5.84 +    status = send_Sync_message(session, Sync_PR_keysync, event);
    5.85 +
    5.86 +    return status;
    5.87 +}
    5.88 +
    5.89 +DYNAMIC_API PEP_STATUS do_sync_protocol(
    5.90 +        PEP_SESSION session,
    5.91 +        void *obj
    5.92 +    )
    5.93 +{
    5.94 +    Sync_event_t *event= NULL;
    5.95 +    PEP_STATUS status = PEP_STATUS_OK;
    5.96 +
    5.97 +    assert(session && session->retrieve_next_sync_event);
    5.98 +    if (!(session && session->retrieve_next_sync_event))
    5.99 +        return PEP_ILLEGAL_VALUE;
   5.100 +
   5.101 +    log_event(session, "sync_protocol thread started", "pEp sync protocol", NULL, NULL);
   5.102 +
   5.103 +    session->sync_obj = obj;
   5.104 +    while (true) 
   5.105 +    {
   5.106 +        event = session->retrieve_next_sync_event(session->sync_management);
   5.107 +        if (!event)
   5.108 +            break;
   5.109 +
   5.110 +        status = recv_Sync_event(session, event);
   5.111 +        if (status != PEP_STATUS_OK && status != PEP_MESSAGE_IGNORE) {
   5.112 +            char buffer[MAX_LINELENGTH];
   5.113 +            memset(buffer, 0, MAX_LINELENGTH);
   5.114 +            snprintf(buffer, MAX_LINELENGTH, "problem with msg received: %d\n", (int) status);
   5.115 +            log_event(session, buffer, "pEp sync protocol", NULL, NULL);
   5.116 +        }
   5.117 +    }
   5.118 +    session->sync_obj = NULL;
   5.119 +
   5.120 +    log_event(session, "sync_protocol thread shutdown", "pEp sync protocol", NULL, NULL);
   5.121 +
   5.122 +    return PEP_STATUS_OK;
   5.123 +}
   5.124 +
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/src/sync_api.h	Wed Aug 15 18:31:02 2018 +0200
     6.3 @@ -0,0 +1,154 @@
     6.4 +// This file is under GNU General Public License 3.0
     6.5 +// see LICENSE.txt
     6.6 +
     6.7 +#pragma once
     6.8 +
     6.9 +
    6.10 +#include "message.h"
    6.11 +
    6.12 +
    6.13 +#ifdef __cplusplus
    6.14 +extern "C" {
    6.15 +#endif
    6.16 +
    6.17 +
    6.18 +typedef enum _sync_handshake_signal {
    6.19 +    SYNC_NOTIFY_UNDEFINED = 0,
    6.20 +
    6.21 +    // request show handshake dialog
    6.22 +    SYNC_NOTIFY_INIT_ADD_OUR_DEVICE,
    6.23 +    SYNC_NOTIFY_INIT_ADD_OTHER_DEVICE,
    6.24 +    SYNC_NOTIFY_INIT_FORM_GROUP,
    6.25 +    SYNC_NOTIFY_INIT_MOVE_OUR_DEVICE,
    6.26 +
    6.27 +    // handshake process timed out
    6.28 +    SYNC_NOTIFY_TIMEOUT,
    6.29 +
    6.30 +    // handshake accepted by user
    6.31 +    SYNC_NOTIFY_ACCEPTED_DEVICE_ADDED,
    6.32 +    SYNC_NOTIFY_ACCEPTED_GROUP_CREATED,
    6.33 +    SYNC_NOTIFY_ACCEPTED_DEVICE_MOVED,
    6.34 +
    6.35 +    // handshake dialog must be closed
    6.36 +    SYNC_NOTIFY_OVERTAKEN
    6.37 +} sync_handshake_signal;
    6.38 +
    6.39 +
    6.40 +// notifyHandshake() - notify UI about sync handshaking process
    6.41 +//
    6.42 +//  parameters:
    6.43 +//      obj (in)        object handle (implementation defined)
    6.44 +//      me (in)         own identity
    6.45 +//      partner (in)    identity of partner
    6.46 +//      signal (in)     reason of the notification
    6.47 +//
    6.48 +//  return value:
    6.49 +//      PEP_STATUS_OK or any other value on error
    6.50 +//
    6.51 +//  caveat:
    6.52 +//      ownership of self and partner go to the callee
    6.53 +
    6.54 +typedef PEP_STATUS (*notifyHandshake_t)(
    6.55 +        void *obj,
    6.56 +        pEp_identity *me,
    6.57 +        pEp_identity *partner,
    6.58 +        sync_handshake_signal signal
    6.59 +    );
    6.60 +
    6.61 +typedef enum _sync_handshake_result {
    6.62 +    SYNC_HANDSHAKE_CANCEL = -1,
    6.63 +    SYNC_HANDSHAKE_ACCEPTED = 0,
    6.64 +    SYNC_HANDSHAKE_REJECTED = 1
    6.65 +} sync_handshake_result;
    6.66 +
    6.67 +// deliverHandshakeResult() - give the result of the handshake dialog
    6.68 +//
    6.69 +//  parameters:
    6.70 +//      session (in)        session handle
    6.71 +//      result (in)         handshake result
    6.72 +
    6.73 +DYNAMIC_API PEP_STATUS deliverHandshakeResult(
    6.74 +        PEP_SESSION session,
    6.75 +        pEp_identity *partner,
    6.76 +        sync_handshake_result result
    6.77 +    );
    6.78 +
    6.79 +
    6.80 +struct Sync_event;
    6.81 +typedef struct Sync_event *SYNC_EVENT;
    6.82 +
    6.83 +// inject_sync_event - inject sync protocol message
    6.84 +//
    6.85 +//  parameters:
    6.86 +//      ev (in)             event to inject
    6.87 +//      management (in)     application defined
    6.88 +//
    6.89 +//  return value:
    6.90 +//      0 if event could be stored successfully or nonzero otherwise
    6.91 +
    6.92 +typedef int (*inject_sync_event_t)(SYNC_EVENT ev, void *management);
    6.93 +
    6.94 +
    6.95 +// retrieve_next_sync_event - receive next sync event
    6.96 +//
    6.97 +//  parameters:
    6.98 +//      management (in)     application defined
    6.99 +//
   6.100 +//  return value:
   6.101 +//      next event
   6.102 +
   6.103 +typedef SYNC_EVENT (*retrieve_next_sync_event_t)(void *management);
   6.104 +
   6.105 +
   6.106 +// register_sync_callbacks() - register adapter's callbacks
   6.107 +//
   6.108 +//  parameters:
   6.109 +//      session (in)                    session where to store obj handle
   6.110 +//      management (in)                 application defined
   6.111 +//      notifyHandshake (in)            callback for doing the handshake
   6.112 +//      retrieve_next_sync_event (in)   callback for receiving sync event
   6.113 +//
   6.114 +//  return value:
   6.115 +//      PEP_STATUS_OK or any other value on errror
   6.116 +//
   6.117 +//  caveat:
   6.118 +//      call that BEFORE you're using any other part of the engine
   6.119 +
   6.120 +DYNAMIC_API PEP_STATUS register_sync_callbacks(
   6.121 +        PEP_SESSION session,
   6.122 +        void *management,
   6.123 +        notifyHandshake_t notifyHandshake,
   6.124 +        inject_sync_event_t inject_sync_event,
   6.125 +        retrieve_next_sync_event_t retrieve_next_sync_event
   6.126 +    );
   6.127 +
   6.128 +DYNAMIC_API void unregister_sync_callbacks(PEP_SESSION session);
   6.129 +
   6.130 +
   6.131 +// do_sync_protocol() - function to be run on an extra thread
   6.132 +//
   6.133 +//  parameters:
   6.134 +//      session                 pEp session to use
   6.135 +//      retrieve_next_sync_msg  pointer to retrieve_next_identity() callback
   6.136 +//                              which returns at least a valid address field in
   6.137 +//                              the identity struct
   6.138 +//      obj                     application defined sync object
   6.139 +//
   6.140 +//  return value:
   6.141 +//      PEP_STATUS_OK if thread has to terminate successfully or any other
   6.142 +//      value on failure
   6.143 +//
   6.144 +//  caveat:
   6.145 +//      to ensure proper working of this library, a thread has to be started
   6.146 +//      with this function immediately after initialization
   6.147 +
   6.148 +DYNAMIC_API PEP_STATUS do_sync_protocol(
   6.149 +        PEP_SESSION session,
   6.150 +        void *obj
   6.151 +    );
   6.152 +
   6.153 +
   6.154 +#ifdef __cplusplus
   6.155 +}
   6.156 +#endif
   6.157 +
     7.1 --- a/sync/gen_statemachine.ysl2	Mon Aug 13 20:39:25 2018 +0200
     7.2 +++ b/sync/gen_statemachine.ysl2	Wed Aug 15 18:31:02 2018 +0200
     7.3 @@ -27,10 +27,10 @@
     7.4          extern "C" {
     7.5          #endif
     7.6  
     7.7 -        #include "../asn.1/«@name».h"
     7.8 +        #include "«@name».h"
     7.9  
    7.10  
    7.11 -        typedef struct _«@name»_event {
    7.12 +        typedef struct «@name»_event {
    7.13              «@name»_PR fsm;
    7.14              int event;
    7.15              «@name»_t *msg;
    7.16 @@ -532,6 +532,7 @@
    7.17          // see LICENSE.txt
    7.18  
    7.19          #include "«@name»_fsm.h"
    7.20 +        #include <stdlib.h>
    7.21  
    7.22          const char *«@name»_state_name(int state)
    7.23          {
     8.1 --- a/test/convenience_scripts/mime_decrypt.cc	Mon Aug 13 20:39:25 2018 +0200
     8.2 +++ b/test/convenience_scripts/mime_decrypt.cc	Wed Aug 15 18:31:02 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);
     8.8 +    PEP_STATUS status = init(&session, NULL);
     8.9      assert(status == PEP_STATUS_OK);
    8.10      assert(session);
    8.11      cout << "init() completed.\n";
     9.1 --- a/test/convenience_scripts/mime_encrypt_decrypt.cc	Mon Aug 13 20:39:25 2018 +0200
     9.2 +++ b/test/convenience_scripts/mime_encrypt_decrypt.cc	Wed Aug 15 18:31:02 2018 +0200
     9.3 @@ -20,7 +20,7 @@
     9.4      PEP_SESSION session;
     9.5      
     9.6      cout << "calling init()\n";
     9.7 -    PEP_STATUS status = init(&session);
     9.8 +    PEP_STATUS status = init(&session, NULL);
     9.9      assert(status == PEP_STATUS_OK);
    9.10      assert(session);
    9.11      cout << "init() completed.\n";
    10.1 --- a/test/pEpEngineTest.cc	Mon Aug 13 20:39:25 2018 +0200
    10.2 +++ b/test/pEpEngineTest.cc	Wed Aug 15 18:31:02 2018 +0200
    10.3 @@ -96,14 +96,14 @@
    10.4      PEP_SESSION session;
    10.5  
    10.6      cout << "calling init()\n";
    10.7 -    PEP_STATUS init_result = init(&session);
    10.8 +    PEP_STATUS init_result = init(&session, NULL);
    10.9      
   10.10      cout << "returning from init() with result == " << status(init_result) << endl;
   10.11      assert(init_result == PEP_STATUS_OK);
   10.12  
   10.13      PEP_SESSION second_session;
   10.14      cout << "second session test\n";
   10.15 -    PEP_STATUS second_init_result = init(&second_session);
   10.16 +    PEP_STATUS second_init_result = init(&second_session, NULL);
   10.17      cout << "returning from second init() with result == " << status(second_init_result) << endl;
   10.18      assert(second_init_result == PEP_STATUS_OK);
   10.19      assert(second_session);
    11.1 --- a/test/src/EngineTestSuite.cc	Mon Aug 13 20:39:25 2018 +0200
    11.2 +++ b/test/src/EngineTestSuite.cc	Wed Aug 15 18:31:02 2018 +0200
    11.3 @@ -116,7 +116,7 @@
    11.4      gpg_agent_conf(true);
    11.5      
    11.6  //    cout << "calling init()\n";
    11.7 -    PEP_STATUS status = init(&session);
    11.8 +    PEP_STATUS status = init(&session, NULL);
    11.9      assert(status == PEP_STATUS_OK);
   11.10      assert(session);
   11.11  //    cout << "init() completed.\n";
    12.1 --- a/test/src/util/test_util.cc	Mon Aug 13 20:39:25 2018 +0200
    12.2 +++ b/test/src/util/test_util.cc	Wed Aug 15 18:31:02 2018 +0200
    12.3 @@ -186,10 +186,10 @@
    12.4              return "PEP_CANNOT_SET_SEQUENCE_VALUE";
    12.5          case PEP_OWN_SEQUENCE:
    12.6              return "PEP_OWN_SEQUENCE";
    12.7 -        case PEP_SYNC_STATEMACHINE_ERROR:
    12.8 -            return "PEP_SYNC_STATEMACHINE_ERROR";
    12.9 -        case PEP_SYNC_NO_TRUST:
   12.10 -            return "PEP_SYNC_NO_TRUST";
   12.11 +        case PEP_STATEMACHINE_ERROR:
   12.12 +            return "PEP_STATEMACHINE_ERROR";
   12.13 +        case PEP_NO_TRUST:
   12.14 +            return "PEP_NO_TRUST";
   12.15          case PEP_STATEMACHINE_INVALID_STATE:
   12.16              return "PEP_STATEMACHINE_INVALID_STATE";
   12.17          case PEP_STATEMACHINE_INVALID_EVENT: