... sync
authorVolker Birk <vb@pep.foundation>
Mon, 13 Aug 2018 16:29:38 +0200
branchsync
changeset 28413b56e21206cd
parent 2840 b881c48c9e9d
child 2842 585f6f0e1a66
...
src/sync_impl.c
src/sync_impl.h
sync/gen_codec.ysl2
sync/gen_message_func.ysl2
sync/gen_statemachine.ysl2
     1.1 --- a/src/sync_impl.c	Mon Aug 13 15:33:42 2018 +0200
     1.2 +++ b/src/sync_impl.c	Mon Aug 13 16:29:38 2018 +0200
     1.3 @@ -4,6 +4,8 @@
     1.4  #include "Sync_impl.h"
     1.5  #include "pEp_internal.h"
     1.6  #include "Sync_event.h"
     1.7 +#include "Sync_codec.h"
     1.8 +#include "baseprotocol.h"
     1.9  #include "KeySync_fsm.h"
    1.10  
    1.11  PEP_STATUS Sync_driver(
    1.12 @@ -134,16 +136,47 @@
    1.13  PEP_STATUS send_Sync_message(
    1.14          PEP_SESSION session, 
    1.15          Sync_PR fsm,
    1.16 -        int event
    1.17 +        int message_type
    1.18      )
    1.19  {
    1.20      PEP_STATUS status = PEP_STATUS_OK;
    1.21  
    1.22 -    assert(session && fsm > None && event > None);
    1.23 -    if (!(session && fsm > None && event > None))
    1.24 +    assert(session && fsm > None && message_type > None);
    1.25 +    if (!(session && fsm > None && message_type > None))
    1.26          return PEP_ILLEGAL_VALUE;
    1.27      
    1.28 +    Sync_t *msg = new_Sync_message(None, None);
    1.29 +    if (!msg)
    1.30 +        return PEP_OUT_OF_MEMORY;
    1.31  
    1.32 +    char *data = NULL;
    1.33 +    message *m = NULL;
    1.34 +
    1.35 +    status = update_Sync_message(session, fsm, message_type, msg);
    1.36 +    if (status)
    1.37 +        goto the_end;
    1.38 +
    1.39 +    size_t size = 0;
    1.40 +    status = encode_Sync_message(msg, &data, &size);
    1.41 +    if (status)
    1.42 +        goto the_end;
    1.43 +
    1.44 +    status = prepare_message(
    1.45 +            session->sync_state.common.from,
    1.46 +            session->sync_state.common.from,
    1.47 +            data,
    1.48 +            size,
    1.49 +            &m
    1.50 +        );
    1.51 +    if (status)
    1.52 +        goto the_end;
    1.53 +    
    1.54 +    session->messageToSend(session->sync_obj, m);
    1.55 +
    1.56 +the_end:
    1.57 +    free_message(m);
    1.58 +    free(data);
    1.59 +    free_Sync_message(msg);
    1.60      return status;
    1.61  }
    1.62  
     2.1 --- a/src/sync_impl.h	Mon Aug 13 15:33:42 2018 +0200
     2.2 +++ b/src/sync_impl.h	Mon Aug 13 16:29:38 2018 +0200
     2.3 @@ -46,7 +46,7 @@
     2.4  PEP_STATUS send_Sync_message(
     2.5          PEP_SESSION session, 
     2.6          Sync_PR fsm,
     2.7 -        int event
     2.8 +        int message_type
     2.9      );
    2.10  
    2.11  // receive message and store it in state
     3.1 --- a/sync/gen_codec.ysl2	Mon Aug 13 15:33:42 2018 +0200
     3.2 +++ b/sync/gen_codec.ysl2	Mon Aug 13 16:29:38 2018 +0200
     3.3 @@ -30,7 +30,7 @@
     3.4          #endif
     3.5  
     3.6  
     3.7 -        // decode_«@name»_msg() - decode PER encoded «@name» message
     3.8 +        // decode_«@name»_message() - decode PER encoded «@name» message
     3.9          //
    3.10          //  parameters:
    3.11          //      data (in)               PER encoded data
    3.12 @@ -40,14 +40,14 @@
    3.13          //  caveat:
    3.14          //      msg goes into the ownership of the caller
    3.15  
    3.16 -        DYNAMIC_API PEP_STATUS decode_«@name»_msg(
    3.17 +        DYNAMIC_API PEP_STATUS decode_«@name»_message(
    3.18                  const char *data,
    3.19                  size_t size,
    3.20                  «@name»_t **msg
    3.21              );
    3.22  
    3.23  
    3.24 -        // encode_«@name»_msg() - encode «@name» message into PER encoded data
    3.25 +        // encode_«@name»_message() - encode «@name» message into PER encoded data
    3.26          //
    3.27          //  parameters:
    3.28          //      msg (in)                «@name» message
    3.29 @@ -57,7 +57,7 @@
    3.30          //  caveat:
    3.31          //      data goes to the ownership of the caller
    3.32  
    3.33 -        DYNAMIC_API PEP_STATUS encode_«@name»_msg(
    3.34 +        DYNAMIC_API PEP_STATUS encode_«@name»_message(
    3.35                  «@name»_t *msg,
    3.36                  char **data,
    3.37                  size_t *size
    3.38 @@ -106,7 +106,7 @@
    3.39          #include "pEp_internal.h"
    3.40          #include "growing_buf.h"
    3.41  
    3.42 -        DYNAMIC_API PEP_STATUS decode_«@name»_msg(
    3.43 +        DYNAMIC_API PEP_STATUS decode_«@name»_message(
    3.44                  const char *data,
    3.45                  size_t size,
    3.46                  «@name»_t **msg
    3.47 @@ -124,7 +124,7 @@
    3.48              return PEP_STATUS_OK;
    3.49          }
    3.50  
    3.51 -        DYNAMIC_API PEP_STATUS encode_«@name»_msg(
    3.52 +        DYNAMIC_API PEP_STATUS encode_«@name»_message(
    3.53                  «@name»_t *msg,
    3.54                  char **data,
    3.55                  size_t *size
    3.56 @@ -165,7 +165,7 @@
    3.57              *text = NULL;
    3.58  
    3.59              «@name»_t *msg = NULL;
    3.60 -            status = decode_«@name»_msg(data, size, &msg);
    3.61 +            status = decode_«@name»_message(data, size, &msg);
    3.62              if (status)
    3.63                  goto the_end;
    3.64  
    3.65 @@ -216,7 +216,7 @@
    3.66  
    3.67              char *_data = NULL;
    3.68              size_t _size = 0;
    3.69 -            status = encode_«@name»_msg(msg, &_data, &_size);
    3.70 +            status = encode_«@name»_message(msg, &_data, &_size);
    3.71              if (status)
    3.72                  goto the_end;
    3.73  
     4.1 --- a/sync/gen_message_func.ysl2	Mon Aug 13 15:33:42 2018 +0200
     4.2 +++ b/sync/gen_message_func.ysl2	Mon Aug 13 16:29:38 2018 +0200
     4.3 @@ -110,21 +110,21 @@
     4.4  
     4.5  «@name»_t *new_«@name»_message(«@name»_PR fsm, int message_type)
     4.6  {
     4.7 -    assert(fsm && message_type);
     4.8 -    if (!(fsm && message_type))
     4.9 -        return NULL;
    4.10 -
    4.11      «@name»_t *msg = calloc(sizeof(«@name»_t), 1);
    4.12      assert(msg);
    4.13      if (!msg)
    4.14          return NULL;
    4.15  
    4.16 -    msg->present = fsm;
    4.17 -    switch (fsm) {
    4.18 -        `` apply "fsm", mode=impl
    4.19 -        default:
    4.20 -            free(msg);
    4.21 -            return NULL;
    4.22 +    if (fsm) {
    4.23 +        msg->present = fsm;
    4.24 +        if (message_type) {
    4.25 +            switch (fsm) {
    4.26 +                `` apply "fsm", 4, mode=impl
    4.27 +                default:
    4.28 +                    free(msg);
    4.29 +                    return NULL;
    4.30 +            }
    4.31 +        }
    4.32      }
    4.33  
    4.34      return msg;
     5.1 --- a/sync/gen_statemachine.ysl2	Mon Aug 13 15:33:42 2018 +0200
     5.2 +++ b/sync/gen_statemachine.ysl2	Mon Aug 13 16:29:38 2018 +0200
     5.3 @@ -160,7 +160,7 @@
     5.4          PEP_STATUS send_«@name»_message(
     5.5                  PEP_SESSION session, 
     5.6                  «@name»_PR fsm,
     5.7 -                int event
     5.8 +                int message_type
     5.9              );
    5.10  
    5.11          // receive message and store it in state
    5.12 @@ -201,6 +201,8 @@
    5.13          #include "«@name»_impl.h"
    5.14          #include "pEp_internal.h"
    5.15          #include "«@name»_event.h"
    5.16 +        #include "«@name»_codec.h"
    5.17 +        #include "baseprotocol.h"
    5.18          `` for "fsm" | #include "«@name»_fsm.h"
    5.19  
    5.20          PEP_STATUS «@name»_driver(
    5.21 @@ -319,16 +321,47 @@
    5.22          PEP_STATUS send_«@name»_message(
    5.23                  PEP_SESSION session, 
    5.24                  «@name»_PR fsm,
    5.25 -                int event
    5.26 +                int message_type
    5.27              )
    5.28          {
    5.29              PEP_STATUS status = PEP_STATUS_OK;
    5.30  
    5.31 -            assert(session && fsm > None && event > None);
    5.32 -            if (!(session && fsm > None && event > None))
    5.33 +            assert(session && fsm > None && message_type > None);
    5.34 +            if (!(session && fsm > None && message_type > None))
    5.35                  return PEP_ILLEGAL_VALUE;
    5.36              
    5.37 +            Sync_t *msg = new_«@name»_message(None, None);
    5.38 +            if (!msg)
    5.39 +                return PEP_OUT_OF_MEMORY;
    5.40  
    5.41 +            char *data = NULL;
    5.42 +            message *m = NULL;
    5.43 +
    5.44 +            status = update_Sync_message(session, fsm, message_type, msg);
    5.45 +            if (status)
    5.46 +                goto the_end;
    5.47 +
    5.48 +            size_t size = 0;
    5.49 +            status = encode_«@name»_message(msg, &data, &size);
    5.50 +            if (status)
    5.51 +                goto the_end;
    5.52 +
    5.53 +            status = prepare_message(
    5.54 +                    session->sync_state.common.from,
    5.55 +                    session->sync_state.common.from,
    5.56 +                    data,
    5.57 +                    size,
    5.58 +                    &m
    5.59 +                );
    5.60 +            if (status)
    5.61 +                goto the_end;
    5.62 +            
    5.63 +            session->messageToSend(session->sync_obj, m);
    5.64 +
    5.65 +        the_end:
    5.66 +            free_message(m);
    5.67 +            free(data);
    5.68 +            free_«@name»_message(msg);
    5.69              return status;
    5.70          }
    5.71