... sync
authorVolker Birk <vb@pep.foundation>
Sat, 11 Aug 2018 21:45:50 +0200
branchsync
changeset 2839d9f7cb22f1d1
parent 2838 7eef15a2c61e
child 2840 b881c48c9e9d
...
src/Sync_helper.c
src/Sync_helper.h
src/asn1_helper.c
src/asn1_helper.h
src/pEp_internal.h
src/sync.c
src/sync.h
src/sync_impl.c
src/sync_impl.h
sync/gen_statemachine.ysl2
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/Sync_helper.c	Sat Aug 11 21:45:50 2018 +0200
     1.3 @@ -0,0 +1,124 @@
     1.4 +// This file is under GNU General Public License 3.0
     1.5 +// see LICENSE.txt
     1.6 +
     1.7 +#include "Sync_helper.h"
     1.8 +#include "pEp_internal.h"
     1.9 +
    1.10 +typedef struct growing_buf {
    1.11 +    char *data;
    1.12 +    size_t size;
    1.13 +} growing_buf_t;
    1.14 +
    1.15 +growing_buf_t *new_growing_buf(void)
    1.16 +{
    1.17 +    growing_buf_t *result = calloc(1, sizeof(growing_buf_t));
    1.18 +    assert(result);
    1.19 +    return result;
    1.20 +}
    1.21 +
    1.22 +void free_growing_buf(growing_buf_t *buf)
    1.23 +{
    1.24 +    if (buf) {
    1.25 +        free(buf->data);
    1.26 +        free(buf);
    1.27 +    }
    1.28 +}
    1.29 +
    1.30 +int consume_bytes(const void *src, size_t size, growing_buf_t *dst)
    1.31 +{
    1.32 +    assert(src && dst);
    1.33 +    if (!(src && dst))
    1.34 +        return -1;
    1.35 +
    1.36 +    char *new_data = realloc(dst->data, dst->size + size + 1);
    1.37 +    assert(new_data);
    1.38 +    if (!new_data)
    1.39 +        return -1;
    1.40 +    dst->data = new_data;
    1.41 +    memcpy(dst->data + dst->size, src, size);
    1.42 +    dst->size += size;
    1.43 +    dst->data[dst->size] = 0; // safeguard
    1.44 +
    1.45 +    return 1;
    1.46 +}
    1.47 +
    1.48 +DYNAMIC_API PEP_STATUS decode_sync_msg(
    1.49 +        const char *data,
    1.50 +        size_t size,
    1.51 +        char **text
    1.52 +    )
    1.53 +{
    1.54 +    PEP_STATUS status = PEP_STATUS_OK;
    1.55 +
    1.56 +    assert(data && text);
    1.57 +    if (!(data && text))
    1.58 +        return PEP_ILLEGAL_VALUE;
    1.59 +
    1.60 +    *text = NULL;
    1.61 +
    1.62 +    Sync_t *msg = NULL;
    1.63 +    uper_decode_complete(NULL, &asn_DEF_Sync, (void **) &msg, data, size);
    1.64 +    if (!msg)
    1.65 +        return PEP_SYNC_ILLEGAL_MESSAGE;
    1.66 +
    1.67 +    growing_buf_t *dst = new_growing_buf();
    1.68 +    if (!dst) {
    1.69 +        status = PEP_OUT_OF_MEMORY;
    1.70 +        goto the_end;
    1.71 +    }
    1.72 +
    1.73 +    asn_enc_rval_t er = xer_encode(&asn_DEF_Sync, msg, XER_F_BASIC,
    1.74 +            (asn_app_consume_bytes_f *) consume_bytes, (void *) dst);
    1.75 +    if (er.encoded == -1) {
    1.76 +        status = PEP_CANNOT_ENCODE;
    1.77 +        goto the_end;
    1.78 +    }
    1.79 +
    1.80 +    *text = dst->data;
    1.81 +    dst->data = NULL;
    1.82 +
    1.83 +the_end:
    1.84 +    free_growing_buf(dst);
    1.85 +    ASN_STRUCT_FREE(asn_DEF_Sync, msg);
    1.86 +    return status;
    1.87 +}
    1.88 +
    1.89 +DYNAMIC_API PEP_STATUS encode_sync_msg(
    1.90 +        const char *text,
    1.91 +        char **data,
    1.92 +        size_t *size
    1.93 +    )
    1.94 +{
    1.95 +    PEP_STATUS status = PEP_STATUS_OK;
    1.96 +
    1.97 +    assert(text && data && size);
    1.98 +    if (!(text && data && size))
    1.99 +        return PEP_ILLEGAL_VALUE;
   1.100 +
   1.101 +    *data = NULL;
   1.102 +    *size = 0;
   1.103 +
   1.104 +    Sync_t *msg = NULL;
   1.105 +    asn_dec_rval_t dr = xer_decode(NULL, &asn_DEF_Sync, (void **) &msg,
   1.106 +            (const void *) text, strlen(text));
   1.107 +    if (dr.code != RC_OK) {
   1.108 +        status = PEP_SYNC_ILLEGAL_MESSAGE;
   1.109 +        goto the_end;
   1.110 +    }
   1.111 +
   1.112 +    char *payload = NULL;
   1.113 +    ssize_t _size = uper_encode_to_new_buffer(&asn_DEF_Sync, NULL, msg,
   1.114 +            (void **) &payload);
   1.115 +    if (_size == -1) {
   1.116 +        status = PEP_CANNOT_ENCODE;
   1.117 +        goto the_end;
   1.118 +    }
   1.119 +
   1.120 +    *data = payload;
   1.121 +    *size = (size_t) _size;
   1.122 +
   1.123 +the_end:
   1.124 +    ASN_STRUCT_FREE(asn_DEF_Sync, msg);
   1.125 +    return status;
   1.126 +}
   1.127 +
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/src/Sync_helper.h	Sat Aug 11 21:45:50 2018 +0200
     2.3 @@ -0,0 +1,45 @@
     2.4 +// This file is under GNU General Public License 3.0
     2.5 +// see LICENSE.txt
     2.6 +
     2.7 +#pragma once
     2.8 +
     2.9 +
    2.10 +#include "pEpEngine.h"
    2.11 +
    2.12 +
    2.13 +#ifdef __cplusplus
    2.14 +extern "C" {
    2.15 +#endif
    2.16 +
    2.17 +// decode_sync_msg() - decode sync message from PER into XER
    2.18 +//
    2.19 +//  parameters:
    2.20 +//      data (in)               PER encoded data
    2.21 +//      size (in)               size of PER encoded data
    2.22 +//      text (out)              XER text of the same sync message
    2.23 +
    2.24 +DYNAMIC_API PEP_STATUS decode_sync_msg(
    2.25 +        const char *data,
    2.26 +        size_t size,
    2.27 +        char **text
    2.28 +    );
    2.29 +
    2.30 +
    2.31 +// encode_sync_msg() - encode sync message from XER into PER
    2.32 +//
    2.33 +//  parameters:
    2.34 +//      text (in)               string with XER text of the sync message
    2.35 +//      data (out)              PER encoded data
    2.36 +//      size (out)              size of PER encoded data
    2.37 +
    2.38 +DYNAMIC_API PEP_STATUS encode_sync_msg(
    2.39 +        const char *text,
    2.40 +        char **data,
    2.41 +        size_t *size
    2.42 +    );
    2.43 +
    2.44 +
    2.45 +#ifdef __cplusplus
    2.46 +}
    2.47 +#endif
    2.48 +
     3.1 --- a/src/asn1_helper.c	Sat Aug 11 00:46:58 2018 +0200
     3.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.3 @@ -1,40 +0,0 @@
     3.4 -// This file is under GNU General Public License 3.0
     3.5 -// see LICENSE.txt
     3.6 -
     3.7 -#include "asn1_helper.h"
     3.8 -#include <assert.h>
     3.9 -#include <stdlib.h>
    3.10 -
    3.11 -growing_buf_t *new_growing_buf(void)
    3.12 -{
    3.13 -    growing_buf_t *result = calloc(1, sizeof(growing_buf_t));
    3.14 -    assert(result);
    3.15 -    return result;
    3.16 -}
    3.17 -
    3.18 -void free_growing_buf(growing_buf_t *buf)
    3.19 -{
    3.20 -    if (buf) {
    3.21 -        free(buf->data);
    3.22 -        free(buf);
    3.23 -    }
    3.24 -}
    3.25 -
    3.26 -int consume_bytes(const void *src, size_t size, growing_buf_t *dst)
    3.27 -{
    3.28 -    assert(src && dst);
    3.29 -    if (!(src && dst))
    3.30 -        return -1;
    3.31 -
    3.32 -    char *new_data = realloc(dst->data, dst->size + size + 1);
    3.33 -    assert(new_data);
    3.34 -    if (!new_data)
    3.35 -        return -1;
    3.36 -    dst->data = new_data;
    3.37 -    memcpy(dst->data + dst->size, src, size);
    3.38 -    dst->size += size;
    3.39 -    dst->data[dst->size] = 0; // safeguard
    3.40 -
    3.41 -    return 1;
    3.42 -}
    3.43 -
     4.1 --- a/src/asn1_helper.h	Sat Aug 11 00:46:58 2018 +0200
     4.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.3 @@ -1,16 +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 -#include <string.h>
    4.10 -
    4.11 -typedef struct growing_buf {
    4.12 -    char *data;
    4.13 -    size_t size;
    4.14 -} growing_buf_t;
    4.15 -
    4.16 -growing_buf_t *new_growing_buf(void);
    4.17 -void free_growing_buf(growing_buf_t *buf);
    4.18 -int consume_bytes(const void *src, size_t size, growing_buf_t *dst);
    4.19 -
     5.1 --- a/src/pEp_internal.h	Sat Aug 11 00:46:58 2018 +0200
     5.2 +++ b/src/pEp_internal.h	Sat Aug 11 21:45:50 2018 +0200
     5.3 @@ -205,8 +205,8 @@
     5.4      void *sync_management;
     5.5      void *sync_obj;
     5.6      notifyHandshake_t notifyHandshake;
     5.7 -    inject_sync_msg_t inject_sync_msg;
     5.8 -    retrieve_next_sync_msg_t retrieve_next_sync_msg;
     5.9 +    inject_sync_event_t inject_sync_event;
    5.10 +    retrieve_next_sync_event_t retrieve_next_sync_event;
    5.11  
    5.12      // pEp Sync
    5.13      struct Sync_state_s sync_state;
     6.1 --- a/src/sync.c	Sat Aug 11 00:46:58 2018 +0200
     6.2 +++ b/src/sync.c	Sat Aug 11 21:45:50 2018 +0200
     6.3 @@ -6,30 +6,26 @@
     6.4  #include <memory.h>
     6.5  #include <assert.h>
     6.6  
     6.7 -#include "asn1_helper.h"
     6.8 -#include "../asn.1/Sync.h"
     6.9  #include "KeySync_fsm.h"
    6.10  
    6.11 -// receive_sync_msg is defined in the sync_impl
    6.12 -
    6.13  DYNAMIC_API PEP_STATUS register_sync_callbacks(
    6.14          PEP_SESSION session,
    6.15          void *management,
    6.16          notifyHandshake_t notifyHandshake,
    6.17 -        inject_sync_msg_t inject_sync_msg,
    6.18 -        retrieve_next_sync_msg_t retrieve_next_sync_msg
    6.19 +        inject_sync_event_t inject_sync_event,
    6.20 +        retrieve_next_sync_event_t retrieve_next_sync_event
    6.21      )
    6.22  {
    6.23 -    assert(session && management && notifyHandshake && inject_sync_msg && retrieve_next_sync_msg);
    6.24 -    if (!(session && management && notifyHandshake && inject_sync_msg && retrieve_next_sync_msg))
    6.25 +    assert(session && management && notifyHandshake && inject_sync_event && retrieve_next_sync_event);
    6.26 +    if (!(session && management && notifyHandshake && inject_sync_event && retrieve_next_sync_event))
    6.27          return PEP_ILLEGAL_VALUE;
    6.28  
    6.29      session->sync_management = management;
    6.30      session->notifyHandshake = notifyHandshake;
    6.31 -    session->inject_sync_msg = inject_sync_msg;
    6.32 -    session->retrieve_next_sync_msg = retrieve_next_sync_msg;
    6.33 +    session->inject_sync_event = inject_sync_event;
    6.34 +    session->retrieve_next_sync_event = retrieve_next_sync_event;
    6.35  
    6.36 -    return status;
    6.37 +    return PEP_STATUS_OK;
    6.38  }
    6.39  
    6.40  DYNAMIC_API void unregister_sync_callbacks(PEP_SESSION session) {
    6.41 @@ -39,8 +35,8 @@
    6.42      // unregister
    6.43      session->sync_management = NULL;
    6.44      session->notifyHandshake = NULL;
    6.45 -    session->inject_sync_msg = NULL;
    6.46 -    session->retrieve_next_sync_msg = NULL;
    6.47 +    session->inject_sync_event = NULL;
    6.48 +    session->retrieve_next_sync_event = NULL;
    6.49  }
    6.50  
    6.51  DYNAMIC_API PEP_STATUS deliverHandshakeResult(
    6.52 @@ -94,10 +90,9 @@
    6.53  {
    6.54      Sync_t *msg = NULL;
    6.55      PEP_STATUS status = PEP_STATUS_OK;
    6.56 -    time_t timeout = 0;
    6.57  
    6.58 -    assert(session && session->retrieve_next_sync_msg);
    6.59 -    if (!(session && session->retrieve_next_sync_msg))
    6.60 +    assert(session && session->retrieve_next_sync_event);
    6.61 +    if (!(session && session->retrieve_next_sync_event))
    6.62          return PEP_ILLEGAL_VALUE;
    6.63  
    6.64      log_event(session, "sync_protocol thread started", "pEp sync protocol", NULL, NULL);
    6.65 @@ -105,7 +100,7 @@
    6.66      session->sync_obj = obj;
    6.67      while (true) 
    6.68      {
    6.69 -        msg = session->retrieve_next_sync_msg(session->sync_management, &timeout);
    6.70 +        event = session->retrieve_next_sync_event(session->sync_management);
    6.71          if (msg == NULL)
    6.72              break;
    6.73  
    6.74 @@ -124,83 +119,3 @@
    6.75      return PEP_STATUS_OK;
    6.76  }
    6.77  
    6.78 -DYNAMIC_API PEP_STATUS decode_sync_msg(
    6.79 -        const char *data,
    6.80 -        size_t size,
    6.81 -        char **text
    6.82 -    )
    6.83 -{
    6.84 -    PEP_STATUS status = PEP_STATUS_OK;
    6.85 -
    6.86 -    assert(data && text);
    6.87 -    if (!(data && text))
    6.88 -        return PEP_ILLEGAL_VALUE;
    6.89 -
    6.90 -    *text = NULL;
    6.91 -
    6.92 -    Sync_t *msg = NULL;
    6.93 -    uper_decode_complete(NULL, &asn_DEF_Sync, (void **) &msg, data, size);
    6.94 -    if (!msg)
    6.95 -        return PEP_SYNC_ILLEGAL_MESSAGE;
    6.96 -
    6.97 -    growing_buf_t *dst = new_growing_buf();
    6.98 -    if (!dst) {
    6.99 -        status = PEP_OUT_OF_MEMORY;
   6.100 -        goto the_end;
   6.101 -    }
   6.102 -
   6.103 -    asn_enc_rval_t er = xer_encode(&asn_DEF_Sync, msg, XER_F_BASIC,
   6.104 -            (asn_app_consume_bytes_f *) consume_bytes, (void *) dst);
   6.105 -    if (er.encoded == -1) {
   6.106 -        status = PEP_CANNOT_ENCODE;
   6.107 -        goto the_end;
   6.108 -    }
   6.109 -
   6.110 -    *text = dst->data;
   6.111 -    dst->data = NULL;
   6.112 -
   6.113 -the_end:
   6.114 -    free_growing_buf(dst);
   6.115 -    ASN_STRUCT_FREE(asn_DEF_Sync, msg);
   6.116 -    return status;
   6.117 -}
   6.118 -
   6.119 -DYNAMIC_API PEP_STATUS encode_sync_msg(
   6.120 -        const char *text,
   6.121 -        char **data,
   6.122 -        size_t *size
   6.123 -    )
   6.124 -{
   6.125 -    PEP_STATUS status = PEP_STATUS_OK;
   6.126 -
   6.127 -    assert(text && data && size);
   6.128 -    if (!(text && data && size))
   6.129 -        return PEP_ILLEGAL_VALUE;
   6.130 -
   6.131 -    *data = NULL;
   6.132 -    *size = 0;
   6.133 -
   6.134 -    Sync_t *msg = NULL;
   6.135 -    asn_dec_rval_t dr = xer_decode(NULL, &asn_DEF_Sync, (void **) &msg,
   6.136 -            (const void *) text, strlen(text));
   6.137 -    if (dr.code != RC_OK) {
   6.138 -        status = PEP_SYNC_ILLEGAL_MESSAGE;
   6.139 -        goto the_end;
   6.140 -    }
   6.141 -
   6.142 -    char *payload = NULL;
   6.143 -    ssize_t _size = uper_encode_to_new_buffer(&asn_DEF_Sync, NULL, msg,
   6.144 -            (void **) &payload);
   6.145 -    if (_size == -1) {
   6.146 -        status = PEP_CANNOT_ENCODE;
   6.147 -        goto the_end;
   6.148 -    }
   6.149 -
   6.150 -    *data = payload;
   6.151 -    *size = (size_t) _size;
   6.152 -
   6.153 -the_end:
   6.154 -    ASN_STRUCT_FREE(asn_DEF_Sync, msg);
   6.155 -    return status;
   6.156 -}
   6.157 -
     7.1 --- a/src/sync.h	Sat Aug 11 00:46:58 2018 +0200
     7.2 +++ b/src/sync.h	Sat Aug 11 21:45:50 2018 +0200
     7.3 @@ -3,16 +3,16 @@
     7.4  
     7.5  #pragma once
     7.6  
     7.7 +
     7.8  #include "message.h"
     7.9 +#include "Sync_event.h"
    7.10 +
    7.11  
    7.12  #ifdef __cplusplus
    7.13  extern "C" {
    7.14  #endif
    7.15  
    7.16  
    7.17 -struct Sync;
    7.18 -
    7.19 -
    7.20  typedef enum _sync_handshake_signal {
    7.21      SYNC_NOTIFY_UNDEFINED = 0,
    7.22  
    7.23 @@ -75,40 +75,36 @@
    7.24      );
    7.25  
    7.26  
    7.27 -// inject_sync_msg - inject sync protocol message
    7.28 +// inject_sync_event - inject sync protocol message
    7.29  //
    7.30  //  parameters:
    7.31 -//      msg (in)            message to inject
    7.32 +//      ev (in)             event to inject
    7.33  //      management (in)     application defined
    7.34  //
    7.35  //  return value:
    7.36 -//      0 if msg could be stored successfully or nonzero otherwise
    7.37 +//      0 if event could be stored successfully or nonzero otherwise
    7.38  
    7.39 -typedef int (*inject_sync_msg_t)(struct Sync *msg, void *management);
    7.40 +typedef int (*inject_sync_event_t)(Sync_event_t *ev, void *management);
    7.41  
    7.42  
    7.43 -// retrieve_next_sync_msg - receive next sync message
    7.44 +// retrieve_next_sync_event - receive next sync event
    7.45  //
    7.46  //  parameters:
    7.47  //      management (in)     application defined
    7.48 -//      timeout (in,out)    do not wait longer than timeout for message
    7.49 -//                          timeout == NULL or *timeout == 0 is blocking
    7.50  //
    7.51  //  return value:
    7.52 -//      next message, then timeout[out] == remaining time
    7.53 -//      NULL and timeout[out] != 0 for timeout occurence
    7.54 -//      NULL and timeout[out] == 0 for termination
    7.55 +//      next event
    7.56  
    7.57 -typedef struct Sync *(*retrieve_next_sync_msg_t)(void *management, time_t *timeout);
    7.58 +typedef struct Sync_event_t *(*retrieve_next_sync_event_t)(void *management);
    7.59  
    7.60  
    7.61  // register_sync_callbacks() - register adapter's callbacks
    7.62  //
    7.63  //  parameters:
    7.64 -//      session (in)                session where to store obj handle
    7.65 -//      management (in)             application defined
    7.66 -//      notifyHandshake (in)        callback for doing the handshake
    7.67 -//      retrieve_next_sync_msg (in) callback for receiving sync messages
    7.68 +//      session (in)                    session where to store obj handle
    7.69 +//      management (in)                 application defined
    7.70 +//      notifyHandshake (in)            callback for doing the handshake
    7.71 +//      retrieve_next_sync_event (in)   callback for receiving sync event
    7.72  //
    7.73  //  return value:
    7.74  //      PEP_STATUS_OK or any other value on errror
    7.75 @@ -120,12 +116,13 @@
    7.76          PEP_SESSION session,
    7.77          void *management,
    7.78          notifyHandshake_t notifyHandshake,
    7.79 -        inject_sync_msg_t inject_sync_msg,
    7.80 -        retrieve_next_sync_msg_t retrieve_next_sync_msg
    7.81 +        inject_sync_event_t inject_sync_event,
    7.82 +        retrieve_next_sync_event_t retrieve_next_sync_event
    7.83      );
    7.84  
    7.85  DYNAMIC_API void unregister_sync_callbacks(PEP_SESSION session);
    7.86  
    7.87 +
    7.88  // do_sync_protocol() - function to be run on an extra thread
    7.89  //
    7.90  //  parameters:
    7.91 @@ -149,34 +146,6 @@
    7.92      );
    7.93  
    7.94  
    7.95 -// decode_sync_msg() - decode sync message from PER into XER
    7.96 -//
    7.97 -//  parameters:
    7.98 -//      data (in)               PER encoded data
    7.99 -//      size (in)               size of PER encoded data
   7.100 -//      text (out)              XER text of the same sync message
   7.101 -
   7.102 -DYNAMIC_API PEP_STATUS decode_sync_msg(
   7.103 -        const char *data,
   7.104 -        size_t size,
   7.105 -        char **text
   7.106 -    );
   7.107 -
   7.108 -
   7.109 -// encode_sync_msg() - encode sync message from XER into PER
   7.110 -//
   7.111 -//  parameters:
   7.112 -//      text (in)               string with XER text of the sync message
   7.113 -//      data (out)              PER encoded data
   7.114 -//      size (out)              size of PER encoded data
   7.115 -
   7.116 -DYNAMIC_API PEP_STATUS encode_sync_msg(
   7.117 -        const char *text,
   7.118 -        char **data,
   7.119 -        size_t *size
   7.120 -    );
   7.121 -
   7.122 -
   7.123  #ifdef __cplusplus
   7.124  }
   7.125  #endif
     8.1 --- a/src/sync_impl.c	Sat Aug 11 00:46:58 2018 +0200
     8.2 +++ b/src/sync_impl.c	Sat Aug 11 21:45:50 2018 +0200
     8.3 @@ -3,6 +3,7 @@
     8.4  
     8.5  #include "Sync_impl.h"
     8.6  #include "pEp_internal.h"
     8.7 +#include "Sync_event.h"
     8.8  #include "KeySync_fsm.h"
     8.9  
    8.10  PEP_STATUS Sync_driver(
    8.11 @@ -19,7 +20,8 @@
    8.12      do {
    8.13          switch (fsm) {
    8.14              case Sync_PR_keysync: {
    8.15 -                next_state = fsm_KeySync(session, session->sync_state.keysync.state, event);
    8.16 +                int state = session->sync_state.keysync.state;
    8.17 +                next_state = fsm_KeySync(session, state, event);
    8.18                  if (next_state > None) {
    8.19                      session->sync_state.keysync.state = next_state;
    8.20                      event = Init;
    8.21 @@ -53,14 +55,13 @@
    8.22  
    8.23      PEP_STATUS status = PEP_STATUS_OK;
    8.24  
    8.25 -    if (!session->inject_sync_msg) {
    8.26 +    if (!session->inject_sync_event) {
    8.27         status = PEP_SYNC_NO_INJECT_CALLBACK;
    8.28         goto error;
    8.29      }
    8.30  
    8.31      if (event < Extra) {
    8.32          msg = new_Sync_message(fsm, event);
    8.33 -        assert(msg);
    8.34          if (!msg) {
    8.35              status = PEP_OUT_OF_MEMORY;
    8.36              goto error;
    8.37 @@ -82,7 +83,7 @@
    8.38      ev->event = event;
    8.39      ev->msg = msg;
    8.40  
    8.41 -    int result = session->inject_sync_msg(ev,
    8.42 +    int result = session->inject_sync_event(ev,
    8.43              session->sync_management);
    8.44      if (result) {
    8.45          status = PEP_STATEMACHINE_ERROR;
    8.46 @@ -112,7 +113,6 @@
    8.47      PEP_STATUS status = PEP_STATUS_OK;
    8.48  
    8.49      Sync_t *msg = new_Sync_message(fsm, message_type);
    8.50 -    assert(msg);
    8.51      if (!msg) {
    8.52          status = PEP_OUT_OF_MEMORY;
    8.53          goto error;
    8.54 @@ -133,7 +133,7 @@
    8.55  
    8.56  PEP_STATUS recv_Sync_event(
    8.57          PEP_SESSION session,
    8.58 -        Sync_t *ev
    8.59 +        Sync_event_t *ev
    8.60      )
    8.61  {
    8.62      assert(session && ev);
     9.1 --- a/src/sync_impl.h	Sat Aug 11 00:46:58 2018 +0200
     9.2 +++ b/src/sync_impl.h	Sat Aug 11 21:45:50 2018 +0200
     9.3 @@ -5,7 +5,7 @@
     9.4  
     9.5  #include "fsm_common.h"
     9.6  #include "message_api.h"
     9.7 -#include "../asn.1/Sync.h"
     9.8 +#include "Sync_event.h"
     9.9  
    9.10  #ifdef __cplusplus
    9.11  extern "C" {
    9.12 @@ -41,7 +41,7 @@
    9.13          int message_type
    9.14      );
    9.15  
    9.16 -// send message about an event to partners using state
    9.17 +// send message about an event to communication partners using state
    9.18  
    9.19  PEP_STATUS send_Sync_message(
    9.20          PEP_SESSION session, 
    9.21 @@ -51,9 +51,9 @@
    9.22  
    9.23  // receive message and store it in state
    9.24  
    9.25 -PEP_STATUS recv_Sync_message(
    9.26 +PEP_STATUS recv_Sync_event(
    9.27          PEP_SESSION session,
    9.28 -        Sync_t *msg
    9.29 +        Sync_event_t *ev
    9.30      );
    9.31  
    9.32  // state machine driver
    10.1 --- a/sync/gen_statemachine.ysl2	Sat Aug 11 00:46:58 2018 +0200
    10.2 +++ b/sync/gen_statemachine.ysl2	Sat Aug 11 21:45:50 2018 +0200
    10.3 @@ -76,6 +76,7 @@
    10.4          #include "pEp_internal.h"
    10.5          #include "«@name»_event.h"
    10.6          #include "«@name»_func.h"
    10.7 +        `` for "fsm" | #include "«@name»_fsm.h"
    10.8  
    10.9          DYNAMIC_API «@name»_event_t *new_«@name»_event(«@name»_PR fsm, int event, «@name»_t *msg)
   10.10          {
   10.11 @@ -124,7 +125,7 @@
   10.12  
   10.13          #include "fsm_common.h"
   10.14          #include "message_api.h"
   10.15 -        #include "../asn.1/Sync.h"
   10.16 +        #include "«@name»_event.h"
   10.17          
   10.18          #ifdef __cplusplus
   10.19          extern "C" {
   10.20 @@ -154,7 +155,7 @@
   10.21                  int message_type
   10.22              );
   10.23  
   10.24 -        // send message about an event to partners using state
   10.25 +        // send message about an event to communication partners using state
   10.26  
   10.27          PEP_STATUS send_«@name»_message(
   10.28                  PEP_SESSION session, 
   10.29 @@ -164,9 +165,9 @@
   10.30  
   10.31          // receive message and store it in state
   10.32  
   10.33 -        PEP_STATUS recv_«@name»_message(
   10.34 +        PEP_STATUS recv_«@name»_event(
   10.35                  PEP_SESSION session,
   10.36 -                «@name»_t *msg
   10.37 +                «@name»_event_t *ev
   10.38              );
   10.39      
   10.40          // state machine driver
   10.41 @@ -199,6 +200,7 @@
   10.42      
   10.43          #include "«@name»_impl.h"
   10.44          #include "pEp_internal.h"
   10.45 +        #include "«@name»_event.h"
   10.46          `` for "fsm" | #include "«@name»_fsm.h"
   10.47  
   10.48          PEP_STATUS «@name»_driver(
   10.49 @@ -238,14 +240,13 @@
   10.50  
   10.51              PEP_STATUS status = PEP_STATUS_OK;
   10.52  
   10.53 -            if (!session->inject_«yml:lcase(@name)»_msg) {
   10.54 +            if (!session->inject_«yml:lcase(@name)»_event) {
   10.55                 status = PEP_«yml:ucase(@name)»_NO_INJECT_CALLBACK;
   10.56                 goto error;
   10.57              }
   10.58  
   10.59              if (event < Extra) {
   10.60                  msg = new_«@name»_message(fsm, event);
   10.61 -                assert(msg);
   10.62                  if (!msg) {
   10.63                      status = PEP_OUT_OF_MEMORY;
   10.64                      goto error;
   10.65 @@ -267,7 +268,7 @@
   10.66              ev->event = event;
   10.67              ev->msg = msg;
   10.68  
   10.69 -            int result = session->inject_«yml:lcase(@name)»_msg(ev,
   10.70 +            int result = session->inject_«yml:lcase(@name)»_event(ev,
   10.71                      session->«yml:lcase(@name)»_management);
   10.72              if (result) {
   10.73                  status = PEP_STATEMACHINE_ERROR;
   10.74 @@ -297,7 +298,6 @@
   10.75              PEP_STATUS status = PEP_STATUS_OK;
   10.76  
   10.77              «@name»_t *msg = new_«@name»_message(fsm, message_type);
   10.78 -            assert(msg);
   10.79              if (!msg) {
   10.80                  status = PEP_OUT_OF_MEMORY;
   10.81                  goto error;
   10.82 @@ -318,7 +318,7 @@
   10.83  
   10.84          PEP_STATUS recv_«@name»_event(
   10.85                  PEP_SESSION session,
   10.86 -                «@name»_t *ev
   10.87 +                «@name»_event_t *ev
   10.88              )
   10.89          {
   10.90              assert(session && ev);
   10.91 @@ -371,7 +371,7 @@
   10.92      {
   10.93      ||
   10.94      case Sync_PR_«yml:lcase(@name)»: {
   10.95 -        switch (msg->choice.keysync.choice.present) {
   10.96 +        switch (msg->choice.«yml:lcase(@name)».payload.present) {
   10.97      ||
   10.98      for "message"
   10.99      ||
  10.100 @@ -394,7 +394,8 @@
  10.101      template "fsm", mode=driver
  10.102      ||
  10.103      case Sync_PR_«yml:lcase(@name)»: {
  10.104 -        next_state = fsm_«@name»(session, session->«yml:lcase(../@name)»_state.«yml:lcase(@name)».state, event);
  10.105 +        int state = session->«yml:lcase(../@name)»_state.«yml:lcase(@name)».state;
  10.106 +        next_state = fsm_«@name»(session, state, event);
  10.107          if (next_state > None) {
  10.108              session->«yml:lcase(../@name)»_state.«yml:lcase(@name)».state = next_state;
  10.109              event = Init;
  10.110 @@ -637,7 +638,7 @@
  10.111                  ||
  10.112  
  10.113                  «$fsm/@name»_SERVICE_LOG("send message", "«$name»");
  10.114 -                status = «$protocol/@name»_notify(session, «$fsm/@id», «$name»);
  10.115 +                status = send_«$protocol/@name»_message(session, «$fsm/@id», «$name»);
  10.116                  ||
  10.117              }
  10.118              otherwise