keysync ...
authorVolker Birk <vb@pep-project.org>
Thu, 16 Jun 2016 14:20:26 +0200
changeset 743e4b613ebac2f
parent 742 f30c0071ef5c
child 744 60d550ce6031
keysync ...
asn.1/Makefile
asn.1/devicegroup.asn1
asn.1/protocols.asn1
src/pEp_internal.h
src/sync_actions.c
src/sync_driver.c
src/sync_fsm.c
src/sync_fsm.h
sync/gen_actions_skeleton.ysl2
sync/gen_statemachine.ysl2
sync/sync.fsm
     1.1 --- a/asn.1/Makefile	Tue Jun 14 10:42:07 2016 +0200
     1.2 +++ b/asn.1/Makefile	Thu Jun 16 14:20:26 2016 +0200
     1.3 @@ -16,14 +16,14 @@
     1.4  libasn1.a: $(ALL_OBJECTS)
     1.5  	ar -rc $@ $(ALL_OBJECTS)
     1.6  
     1.7 -generate: DeviceGroup-Protocol.c
     1.8 +generate: Sync-Protocols.c
     1.9  	rm -f converter-sample.c
    1.10  
    1.11  %.o: %.c %.h
    1.12  	$(CC) $(CFLAGS) $(OPTIMIZE) -I. -I$(ASN1C_INCLUDE) -c $< -o $@
    1.13  
    1.14 -DeviceGroup-Protocol.c: devicegroup.asn1
    1.15 -	$(ASN1C) -gen-PER -fincludes-quoted -fcompound-names -pdu=PEP.Message pEp.asn1 $<
    1.16 +Sync-Protocols.c: protocols.asn1 devicegroup.asn1 pEp.asn1
    1.17 +	$(ASN1C) -gen-PER -fincludes-quoted -fcompound-names -pdu=PEP.Message pEp.asn1 devicegroup.asn1 $<
    1.18  
    1.19  .PHONY: clean
    1.20  
     2.1 --- a/asn.1/devicegroup.asn1	Tue Jun 14 10:42:07 2016 +0200
     2.2 +++ b/asn.1/devicegroup.asn1	Thu Jun 16 14:20:26 2016 +0200
     2.3 @@ -4,6 +4,7 @@
     2.4  
     2.5  BEGIN
     2.6  
     2.7 +EXPORTS DeviceGroup-Protocol;
     2.8  IMPORTS Identity, KeyList, Header FROM PEP;
     2.9  
    2.10  Beacon ::= SEQUENCE {
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/asn.1/protocols.asn1	Thu Jun 16 14:20:26 2016 +0200
     3.3 @@ -0,0 +1,14 @@
     3.4 +SYNC
     3.5 +
     3.6 +DEFINITIONS AUTOMATIC TAGS EXTENSIBILITY IMPLIED ::=
     3.7 +
     3.8 +BEGIN
     3.9 +
    3.10 +IMPORTS DeviceGroup-Protocol FROM DEVICEGROUP;
    3.11 +
    3.12 +Sync-Protocols ::= CHOICE {
    3.13 +    deviceGroup [APPLICATION 1] DeviceGroup-Protocol
    3.14 +}
    3.15 +
    3.16 +END
    3.17 +
     4.1 --- a/src/pEp_internal.h	Tue Jun 14 10:42:07 2016 +0200
     4.2 +++ b/src/pEp_internal.h	Thu Jun 16 14:20:26 2016 +0200
     4.3 @@ -126,7 +126,7 @@
     4.4      messageToSend_t messageToSend;
     4.5      showHandshake_t showHandshake;
     4.6  
     4.7 -    // sync state machine
     4.8 +    // state machines
     4.9      DeviceState_state sync_state;
    4.10  
    4.11      // runtime config
     5.1 --- a/src/sync_actions.c	Tue Jun 14 10:42:07 2016 +0200
     5.2 +++ b/src/sync_actions.c	Thu Jun 16 14:20:26 2016 +0200
     5.3 @@ -32,6 +32,7 @@
     5.4      Beacon_t *msg = NULL;
     5.5      char *payload = NULL;
     5.6      message *_message = NULL;
     5.7 +    pEp_identity *me = NULL;
     5.8  
     5.9      assert(session);
    5.10      assert(!partner);
    5.11 @@ -55,7 +56,7 @@
    5.12  
    5.13      msg->state = (long) state;
    5.14  
    5.15 -    pEp_identity *me = new_identity(NULL, NULL, NULL, NULL);
    5.16 +    me = new_identity(NULL, NULL, NULL, NULL);
    5.17      if (!me)
    5.18          goto enomem;
    5.19      status = myself(session, me);
    5.20 @@ -81,6 +82,9 @@
    5.21          goto error;
    5.22      payload = NULL;
    5.23  
    5.24 +    free_identity(me);
    5.25 +    me = NULL;
    5.26 +
    5.27      status = session->messageToSend(session->sync_obj, _message);
    5.28  
    5.29      free_message(_message);
    5.30 @@ -94,6 +98,7 @@
    5.31      ASN_STRUCT_FREE(asn_DEF_Beacon, msg);
    5.32      free(payload);
    5.33      free_message(_message);
    5.34 +    free_identity(me);
    5.35      return status;
    5.36  }
    5.37  
    5.38 @@ -118,6 +123,7 @@
    5.39      HandshakeRequest_t *msg = NULL;
    5.40      char *payload = NULL;
    5.41      message *_message = NULL;
    5.42 +    pEp_identity *me = NULL;
    5.43  
    5.44      assert(session);
    5.45      assert(partner);
    5.46 @@ -141,7 +147,7 @@
    5.47  
    5.48      msg->state = (long) state;
    5.49  
    5.50 -    pEp_identity *me = new_identity(NULL, NULL, NULL, NULL);
    5.51 +    me = new_identity(NULL, NULL, NULL, NULL);
    5.52      if (!me)
    5.53          goto enomem;
    5.54      status = myself(session, me);
    5.55 @@ -170,6 +176,9 @@
    5.56          goto error;
    5.57      payload = NULL;
    5.58  
    5.59 +    free_identity(me);
    5.60 +    me = NULL;
    5.61 +
    5.62      status = session->messageToSend(session->sync_obj, _message);
    5.63  
    5.64      free_message(_message);
    5.65 @@ -183,6 +192,7 @@
    5.66      ASN_STRUCT_FREE(asn_DEF_HandshakeRequest, msg);
    5.67      free(payload);
    5.68      free_message(_message);
    5.69 +    free_identity(me);
    5.70      return status;
    5.71  }
    5.72  
    5.73 @@ -315,6 +325,7 @@
    5.74      GroupKeys_t *msg = NULL;
    5.75      char *payload = NULL;
    5.76      message *_message = NULL;
    5.77 +    pEp_identity *me = NULL;
    5.78  
    5.79      assert(session);
    5.80      assert(!partner);
    5.81 @@ -338,7 +349,7 @@
    5.82  
    5.83      msg->state = (long) state;
    5.84  
    5.85 -    pEp_identity *me = new_identity(NULL, NULL, NULL, NULL);
    5.86 +    me = new_identity(NULL, NULL, NULL, NULL);
    5.87      if (!me)
    5.88          goto enomem;
    5.89      status = myself(session, me);
    5.90 @@ -364,6 +375,9 @@
    5.91          goto error;
    5.92      payload = NULL;
    5.93  
    5.94 +    free_identity(me);
    5.95 +    me = NULL;
    5.96 +
    5.97      status = session->messageToSend(session->sync_obj, _message);
    5.98  
    5.99      free_message(_message);
   5.100 @@ -377,6 +391,7 @@
   5.101      ASN_STRUCT_FREE(asn_DEF_GroupKeys, msg);
   5.102      free(payload);
   5.103      free_message(_message);
   5.104 +    free_identity(me);
   5.105      return status;
   5.106  }
   5.107  
     6.1 --- a/src/sync_driver.c	Tue Jun 14 10:42:07 2016 +0200
     6.2 +++ b/src/sync_driver.c	Thu Jun 16 14:20:26 2016 +0200
     6.3 @@ -4,7 +4,7 @@
     6.4  #include "pEp_internal.h"
     6.5  
     6.6  
     6.7 -PEP_STATUS fsm_DeviceState_inject(
     6.8 +DYNAMIC_API PEP_STATUS fsm_DeviceState_inject(
     6.9          PEP_SESSION session,
    6.10          DeviceState_event event,
    6.11          Identity partner,
    6.12 @@ -13,7 +13,6 @@
    6.13  {
    6.14      PEP_STATUS status = PEP_STATUS_OK;
    6.15  
    6.16 -    session->sync_state = InitState;
    6.17      session->sync_state = fsm_DeviceState(session, session->sync_state,
    6.18              event, partner, state_partner);
    6.19  
     7.1 --- a/src/sync_fsm.c	Tue Jun 14 10:42:07 2016 +0200
     7.2 +++ b/src/sync_fsm.c	Thu Jun 16 14:20:26 2016 +0200
     7.3 @@ -16,7 +16,7 @@
     7.4              case Init:
     7.5                  return Sole;
     7.6          default:
     7.7 -            return invalid_event;
     7.8 +            return (DeviceState_state) invalid_event;
     7.9          }
    7.10          break;
    7.11      
    7.12 @@ -35,7 +35,7 @@
    7.13                  sendHandshakeRequest(session, state, partner);
    7.14                  return HandshakingSole;
    7.15          default:
    7.16 -            return invalid_event;
    7.17 +            return (DeviceState_state) invalid_event;
    7.18          }
    7.19          break;
    7.20      
    7.21 @@ -50,7 +50,7 @@
    7.22              case HandshakeAccepted:
    7.23                  return WaitForGroupKeys;
    7.24          default:
    7.25 -            return invalid_event;
    7.26 +            return (DeviceState_state) invalid_event;
    7.27          }
    7.28          break;
    7.29      
    7.30 @@ -65,7 +65,7 @@
    7.31                  reject(session, state, partner);
    7.32                  return Sole;
    7.33          default:
    7.34 -            return invalid_event;
    7.35 +            return (DeviceState_state) invalid_event;
    7.36          }
    7.37          break;
    7.38      
    7.39 @@ -88,12 +88,12 @@
    7.40                  reject(session, state, NULL);
    7.41                  break;
    7.42          default:
    7.43 -            return invalid_event;
    7.44 +            return (DeviceState_state) invalid_event;
    7.45          }
    7.46          break;
    7.47      
    7.48          default:
    7.49 -            return invalid_state;
    7.50 +            return (DeviceState_state) invalid_state;
    7.51      }
    7.52  
    7.53      return state;
     8.1 --- a/src/sync_fsm.h	Tue Jun 14 10:42:07 2016 +0200
     8.2 +++ b/src/sync_fsm.h	Thu Jun 16 14:20:26 2016 +0200
     8.3 @@ -16,14 +16,14 @@
     8.4  // error values
     8.5  
     8.6  typedef enum _fsm_error {
     8.7 -    invalid_state = -1,
     8.8 -    invalid_event = -2
     8.9 +    invalid_state = -2,
    8.10 +    invalid_event = -3
    8.11  } fsm_error;
    8.12  
    8.13  // states
    8.14  
    8.15  typedef enum _DeviceState_state {
    8.16 -    DeviceState_state_NONE = 0,
    8.17 +    DeviceState_state_NONE = -1,
    8.18      InitState, 
    8.19      Sole, 
    8.20      HandshakingSole, 
    8.21 @@ -34,7 +34,7 @@
    8.22  // events
    8.23  
    8.24  typedef enum _DeviceState_event {
    8.25 -    DeviceState_event_NONE = 0,
    8.26 +    DeviceState_event_NONE = -1,
    8.27      Beacon = 1,
    8.28      HandshakeRequest = 2,
    8.29      GroupKeys = 3,
     9.1 --- a/sync/gen_actions_skeleton.ysl2	Tue Jun 14 10:42:07 2016 +0200
     9.2 +++ b/sync/gen_actions_skeleton.ysl2	Thu Jun 16 14:20:26 2016 +0200
     9.3 @@ -130,6 +130,7 @@
     9.4              «$name»_t *msg = NULL;
     9.5              char *payload = NULL;
     9.6              message *_message = NULL;
     9.7 +            pEp_identity *me = NULL;
     9.8  
     9.9              `` call "paramcheck" with "partner", "parm/partner";
    9.10  
    9.11 @@ -150,7 +151,7 @@
    9.12  
    9.13              msg->state = (long) state;
    9.14  
    9.15 -            pEp_identity *me = new_identity(NULL, NULL, NULL, NULL);
    9.16 +            me = new_identity(NULL, NULL, NULL, NULL);
    9.17              if (!me)
    9.18                  goto enomem;
    9.19              status = myself(session, me);
    9.20 @@ -185,6 +186,9 @@
    9.21                  goto error;
    9.22              payload = NULL;
    9.23  
    9.24 +            free_identity(me);
    9.25 +            me = NULL;
    9.26 +
    9.27              status = session->messageToSend(session->sync_obj, _message);
    9.28  
    9.29              free_message(_message);
    9.30 @@ -198,6 +202,7 @@
    9.31              ASN_STRUCT_FREE(asn_DEF_«$name», msg);
    9.32              free(payload);
    9.33              free_message(_message);
    9.34 +            free_identity(me);
    9.35              return status;
    9.36          }
    9.37  
    10.1 --- a/sync/gen_statemachine.ysl2	Tue Jun 14 10:42:07 2016 +0200
    10.2 +++ b/sync/gen_statemachine.ysl2	Thu Jun 16 14:20:26 2016 +0200
    10.3 @@ -30,21 +30,21 @@
    10.4          // error values
    10.5  
    10.6          typedef enum _fsm_error {
    10.7 -            invalid_state = -1,
    10.8 -            invalid_event = -2
    10.9 +            invalid_state = -2,
   10.10 +            invalid_event = -3
   10.11          } fsm_error;
   10.12  
   10.13          // states
   10.14  
   10.15          typedef enum _«@name»_state {
   10.16 -            «@name»_state_NONE = 0,
   10.17 +            «@name»_state_NONE = -1,
   10.18          `` for "func:distinctName(state)" |> «@name»`if "position()!=last()" > , `
   10.19          } «@name»_state;
   10.20  
   10.21          // events
   10.22  
   10.23          typedef enum _«@name»_event {
   10.24 -            «@name»_event_NONE = 0,
   10.25 +            «@name»_event_NONE = -1,
   10.26          ||
   10.27          for "func:distinctName(state/event[not(not(/protocol/fsm/tag/@name=@name))])" {
   10.28              const "name", "@name";
   10.29 @@ -93,7 +93,7 @@
   10.30          #include "pEp_internal.h"
   10.31  
   10.32  
   10.33 -        PEP_STATUS fsm_«@name»_inject(
   10.34 +        DYNAMIC_API PEP_STATUS fsm_«@name»_inject(
   10.35                  PEP_SESSION session,
   10.36                  «@name»_event event,
   10.37                  Identity partner,
   10.38 @@ -102,7 +102,6 @@
   10.39          {
   10.40              PEP_STATUS status = PEP_STATUS_OK;
   10.41  
   10.42 -            session->sync_state = InitState;
   10.43              session->sync_state = fsm_«@name»(session, session->sync_state,
   10.44                      event, partner, state_partner);
   10.45  
   10.46 @@ -126,7 +125,7 @@
   10.47              switch (state) {
   10.48                  `` apply "state"
   10.49                  default:
   10.50 -                    return invalid_state;
   10.51 +                    return («@name»_state) invalid_state;
   10.52              }
   10.53  
   10.54              return state;
   10.55 @@ -141,7 +140,7 @@
   10.56          switch (event) {
   10.57          `` apply "event", 2
   10.58          default:
   10.59 -            return invalid_event;
   10.60 +            return («../@name»_state) invalid_event;
   10.61          }
   10.62          break;
   10.63  
    11.1 --- a/sync/sync.fsm	Tue Jun 14 10:42:07 2016 +0200
    11.2 +++ b/sync/sync.fsm	Thu Jun 16 14:20:26 2016 +0200
    11.3 @@ -78,6 +78,7 @@
    11.4                  do reject partner;
    11.5          }
    11.6  
    11.7 +        tag InitState 0;
    11.8          tag Beacon 1;
    11.9          tag HandshakeRequest 2;
   11.10          tag GroupKeys 3;