... sync
authorVolker Birk <vb@pep.foundation>
Fri, 10 Aug 2018 11:03:28 +0200
branchsync
changeset 28360172fc10599f
parent 2835 20d73101227c
child 2837 f3f3e42f5358
...
src/sync.c
src/sync.h
src/sync_impl.c
src/sync_impl.h
sync/gen_statemachine.ysl2
     1.1 --- a/src/sync.c	Thu Aug 09 17:41:22 2018 +0200
     1.2 +++ b/src/sync.c	Fri Aug 10 11:03:28 2018 +0200
     1.3 @@ -7,16 +7,11 @@
     1.4  #include <assert.h>
     1.5  
     1.6  #include "asn1_helper.h"
     1.7 +#include "../asn.1/Sync.h"
     1.8  #include "KeySync_fsm.h"
     1.9  
    1.10  // receive_sync_msg is defined in the sync_impl
    1.11  
    1.12 -PEP_STATUS receive_sync_msg(
    1.13 -        PEP_SESSION session,
    1.14 -        sync_msg_t *sync_msg,
    1.15 -        time_t *timeout
    1.16 -    );
    1.17 -
    1.18  DYNAMIC_API PEP_STATUS register_sync_callbacks(
    1.19          PEP_SESSION session,
    1.20          void *management,
    1.21 @@ -102,7 +97,7 @@
    1.22          void *obj
    1.23      )
    1.24  {
    1.25 -    sync_msg_t *msg = NULL;
    1.26 +    Sync_t *msg = NULL;
    1.27      PEP_STATUS status = PEP_STATUS_OK;
    1.28      time_t timeout = 0;
    1.29  
    1.30 @@ -115,11 +110,11 @@
    1.31      session->sync_obj = obj;
    1.32      while (true) 
    1.33      {
    1.34 -        msg = (sync_msg_t *) session->retrieve_next_sync_msg(session->sync_management, &timeout);
    1.35 +        msg = session->retrieve_next_sync_msg(session->sync_management, &timeout);
    1.36          if (msg == NULL)
    1.37              break;
    1.38  
    1.39 -        status = receive_sync_msg(session, msg, &timeout);
    1.40 +        status = recv_Sync_event(session, msg);
    1.41          if (status != PEP_STATUS_OK && status != PEP_MESSAGE_IGNORE) {
    1.42              char buffer[MAX_LINELENGTH];
    1.43              memset(buffer, 0, MAX_LINELENGTH);
     2.1 --- a/src/sync.h	Thu Aug 09 17:41:22 2018 +0200
     2.2 +++ b/src/sync.h	Fri Aug 10 11:03:28 2018 +0200
     2.3 @@ -1,9 +1,6 @@
     2.4  // This file is under GNU General Public License 3.0
     2.5  // see LICENSE.txt
     2.6  
     2.7 -// this module is for being used WITHOUT the Transport API in transport.h
     2.8 -// DO NOT USE IT WHEN USING Transport API!
     2.9 -
    2.10  #pragma once
    2.11  
    2.12  #include "message.h"
    2.13 @@ -12,6 +9,10 @@
    2.14  extern "C" {
    2.15  #endif
    2.16  
    2.17 +
    2.18 +struct Sync;
    2.19 +
    2.20 +
    2.21  typedef enum _sync_handshake_signal {
    2.22      SYNC_NOTIFY_UNDEFINED = 0,
    2.23  
    2.24 @@ -73,8 +74,6 @@
    2.25          sync_handshake_result result
    2.26      );
    2.27  
    2.28 -// sync_msg_t - items queued for serialized handling by protocol engine
    2.29 -typedef struct _sync_msg_t sync_msg_t;
    2.30  
    2.31  // inject_sync_msg - inject sync protocol message
    2.32  //
    2.33 @@ -85,7 +84,7 @@
    2.34  //  return value:
    2.35  //      0 if msg could be stored successfully or nonzero otherwise
    2.36  
    2.37 -typedef int (*inject_sync_msg_t)(void *msg, void *management);
    2.38 +typedef int (*inject_sync_msg_t)(struct Sync *msg, void *management);
    2.39  
    2.40  
    2.41  // retrieve_next_sync_msg - receive next sync message
    2.42 @@ -100,7 +99,7 @@
    2.43  //      NULL and timeout[out] != 0 for timeout occurence
    2.44  //      NULL and timeout[out] == 0 for termination
    2.45  
    2.46 -typedef void *(*retrieve_next_sync_msg_t)(void *management, time_t *timeout);
    2.47 +typedef struct Sync *(*retrieve_next_sync_msg_t)(void *management, time_t *timeout);
    2.48  
    2.49  
    2.50  // register_sync_callbacks() - register adapter's callbacks
    2.51 @@ -149,13 +148,6 @@
    2.52          void *obj
    2.53      );
    2.54  
    2.55 -// free_sync_msg() - free sync_msg_t struct when not passed to do_sync_protocol  
    2.56 -//
    2.57 -//  parameters:
    2.58 -//      sync_msg (in)            pointer to sync_msg_t struct to free.
    2.59 -//                               pointer can be NULL.
    2.60 -
    2.61 -DYNAMIC_API void free_sync_msg(sync_msg_t *sync_msg);
    2.62  
    2.63  // decode_sync_msg() - decode sync message from PER into XER
    2.64  //
     3.1 --- a/src/sync_impl.c	Thu Aug 09 17:41:22 2018 +0200
     3.2 +++ b/src/sync_impl.c	Fri Aug 10 11:03:28 2018 +0200
     3.3 @@ -127,18 +127,14 @@
     3.4  }
     3.5  
     3.6  PEP_STATUS recv_Sync_event(
     3.7 -        PEP_SESSION session, 
     3.8 -        Sync_event_t *ev
     3.9 +        PEP_SESSION session,
    3.10 +        Sync_t *ev
    3.11      )
    3.12  {
    3.13      assert(session && ev);
    3.14      if (!(session && ev))
    3.15          return PEP_ILLEGAL_VALUE;
    3.16  
    3.17 -    assert(ev->fsm >= None && ev->event >= None);
    3.18 -    if (!(ev->fsm >= None && ev->event >= None))
    3.19 -        return PEP_ILLEGAL_VALUE;
    3.20 -
    3.21      PEP_STATUS status = PEP_STATUS_OK;
    3.22  
    3.23      if (ev->event < Extra) {
     4.1 --- a/src/sync_impl.h	Thu Aug 09 17:41:22 2018 +0200
     4.2 +++ b/src/sync_impl.h	Fri Aug 10 11:03:28 2018 +0200
     4.3 @@ -49,7 +49,7 @@
     4.4          int message_type
     4.5      );
     4.6  
     4.7 -// send message to partners
     4.8 +// send message about an event to partners using state
     4.9  
    4.10  PEP_STATUS send_Sync_message(
    4.11          PEP_SESSION session, 
    4.12 @@ -57,11 +57,10 @@
    4.13          int event
    4.14      );
    4.15  
    4.16 -// receive event, free Sync_event_t structure if call does not fail
    4.17 -// with PEP_ILLEGAL_VALUE
    4.18 +// receive event and store it in state
    4.19  
    4.20  PEP_STATUS recv_Sync_event(
    4.21 -        PEP_SESSION session, 
    4.22 +        PEP_SESSION session,
    4.23          Sync_event_t *ev
    4.24      );
    4.25  
     5.1 --- a/sync/gen_statemachine.ysl2	Thu Aug 09 17:41:22 2018 +0200
     5.2 +++ b/sync/gen_statemachine.ysl2	Fri Aug 10 11:03:28 2018 +0200
     5.3 @@ -61,7 +61,7 @@
     5.4                  int message_type
     5.5              );
     5.6  
     5.7 -        // send message to partners
     5.8 +        // send message about an event to partners using state
     5.9  
    5.10          PEP_STATUS send_«@name»_message(
    5.11                  PEP_SESSION session, 
    5.12 @@ -69,11 +69,10 @@
    5.13                  int event
    5.14              );
    5.15  
    5.16 -        // receive event, free «@name»_event_t structure if call does not fail
    5.17 -        // with PEP_ILLEGAL_VALUE
    5.18 +        // receive event and store it in state
    5.19  
    5.20          PEP_STATUS recv_«@name»_event(
    5.21 -                PEP_SESSION session, 
    5.22 +                PEP_SESSION session,
    5.23                  «@name»_event_t *ev
    5.24              );
    5.25      
    5.26 @@ -222,18 +221,14 @@
    5.27          }
    5.28  
    5.29          PEP_STATUS recv_«@name»_event(
    5.30 -                PEP_SESSION session, 
    5.31 -                «@name»_event_t *ev
    5.32 +                PEP_SESSION session,
    5.33 +                «@name»_t *ev
    5.34              )
    5.35          {
    5.36              assert(session && ev);
    5.37              if (!(session && ev))
    5.38                  return PEP_ILLEGAL_VALUE;
    5.39  
    5.40 -            assert(ev->fsm >= None && ev->event >= None);
    5.41 -            if (!(ev->fsm >= None && ev->event >= None))
    5.42 -                return PEP_ILLEGAL_VALUE;
    5.43 -
    5.44              PEP_STATUS status = PEP_STATUS_OK;
    5.45  
    5.46              if (ev->event < Extra) {