sync: documentation, moved generated code, updated .hgignore, cleaning
authorEdouard Tisserant <edouard@pep-project.org>
Thu, 08 Dec 2016 00:51:41 +0100
changeset 1467ff7c60d14af0
parent 1463 be664aafb70e
child 1468 e477af887032
sync: documentation, moved generated code, updated .hgignore, cleaning
.hgignore
src/pEpEngine.h
src/sync.h
src/sync_driver.c
src/sync_fsm.h
src/sync_send_actions.c
sync/Makefile
sync/gen_actions.ysl2
sync/gen_actions_skeleton.ysl2
sync/gen_statemachine.ysl2
sync/generated/README
sync/generated/sync_driver.c
sync/generated/sync_fsm.c
sync/generated/sync_fsm.h
sync/generated/sync_send_actions.c
sync/skeletons/sync_actions.c
     1.1 --- a/.hgignore	Wed Dec 07 15:41:29 2016 +0100
     1.2 +++ b/.hgignore	Thu Dec 08 00:51:41 2016 +0100
     1.3 @@ -33,14 +33,17 @@
     1.4  msg4.asc
     1.5  pep_Dokument_Titel.pdf
     1.6  pEpEngine.vcxproj.user
     1.7 -*.skeleton
     1.8 -.skeletons
     1.9 -.statemachines
    1.10  Makefile.protocols
    1.11  test/msg_encrypt_for_self.asc
    1.12  tags
    1.13  asn.1/pEpEngineASN1/pEpEngineASN1.vcxproj.user
    1.14  src/sync_fsm.c
    1.15 +src/sync_fsm.h
    1.16 +src/sync_driver.c
    1.17 +src/sync_send_actions.c
    1.18 +sync/.actions
    1.19 +sync/.codegen
    1.20 +sync/.statemachines
    1.21  *.xml
    1.22  *.dot
    1.23  *.svg
     2.1 --- a/src/pEpEngine.h	Wed Dec 07 15:41:29 2016 +0100
     2.2 +++ b/src/pEpEngine.h	Thu Dec 08 00:51:41 2016 +0100
     2.3 @@ -74,7 +74,7 @@
     2.4      PEP_CONTRAINTS_VIOLATED                         = 0x0802,
     2.5      PEP_CANNOT_ENCODE                               = 0x0803,
     2.6  
     2.7 -    PEP_SYNC_NO_NOTIFY_CALLBACK                 = 0x0901,
     2.8 +    PEP_SYNC_NO_NOTIFY_CALLBACK                     = 0x0901,
     2.9      PEP_SYNC_ILLEGAL_MESSAGE                        = 0x0902,
    2.10      PEP_SYNC_NO_INJECT_CALLBACK                     = 0x0903,
    2.11  
     3.1 --- a/src/sync.h	Wed Dec 07 15:41:29 2016 +0100
     3.2 +++ b/src/sync.h	Thu Dec 08 00:51:41 2016 +0100
     3.3 @@ -1,13 +1,60 @@
     3.4 +/*
     3.5 +====================================
     3.6 +Engine/adapter/app KeySync interface 
     3.7 +====================================
     3.8 +
     3.9 +In the engine, KeySync is implemented through a state machine [1]. KeySync
    3.10 +state machine is driven [2] by events, triggering actions [3] and transitions
    3.11 +to new states. Events happens on decryption of email messages, on key
    3.12 +generation, on user interaction through the app and in case of timeout when
    3.13 +staying too long in some particular states.
    3.14 +
    3.15 +To use KeySync, the adapter has to create a session dedicated to handle the
    3.16 +protocol, register some callbacks [4] to the engine, and then call protocol's
    3.17 +event consumer loop [5] in a dedicated thread. KeySync actions are executed
    3.18 +as callback invoked from that loop : send pEp messages through app's transport
    3.19 +and display KeySync status and handshake to the user.
    3.20 +
    3.21 +When a session is attached [6] to a KeySync session, decryption of pEp (email)
    3.22 +messages in that session may trigger operations in attached KeySync session. In
    3.23 +case of an adapter capable to serve multiple apps, each app is associated to a
    3.24 +different KeySync session, and sessions created for use in that app are
    3.25 +attached to that session.
    3.26 +
    3.27 +KeySync messages [7], not to be confused with pEp (email) messages, are either
    3.28 +directly events to be processed by the state machine or KeySync payloads
    3.29 +collected from decrypted messages. They are jobs to be processed by the state
    3.30 +machine.
    3.31 +
    3.32 +KeySync messages can be emitted by multiple session, and could naturally come
    3.33 +from different threads. They must be serialized in a locked queue. Attached
    3.34 +sessions inject [8] KeySync messages in the queue. Protocol loop retrieves [9]
    3.35 +them from the queue. KeySync message is received [10] by the state machine,
    3.36 +where event eventually deduced from payload.
    3.37 +
    3.38 +A state timeout event is a particular case. It doesn't traverse the queue, and
    3.39 +isn't emitted by a session. It is triggered by a timeout on the retrieve
    3.40 +operation. Value of the timeout is determined when entering a new state, and is
    3.41 +passed as a parameter of the call to the blocking queue retrieve operation on 
    3.42 +next protocol loop iteraton.
    3.43 +
    3.44 +[1] sync/device_group.fsm , src/sync_fsm.c (generated)
    3.45 +[2] src/sync_driver.c (generated)
    3.46 +[3] src/sync_actions.c , src/sync_send_actions.c (generated)
    3.47 +[4] register_sync_callbacks()
    3.48 +[5] do_sync_protocol()
    3.49 +[6] attach_sync_session()
    3.50 +[7] type sync_msg_t
    3.51 +[8] callback inject_sync_msg
    3.52 +[9] callback retrieve_next_sync_msg
    3.53 +[10] receive_sync_msg() (src/sync_impl.c)
    3.54 +
    3.55 +*/
    3.56  #pragma once
    3.57  
    3.58  #include "message.h"
    3.59  #include "sync_fsm.h"
    3.60  
    3.61 -
    3.62 -// this module is for being used WITHOUT the Transport API in transport.h
    3.63 -// DO NOT USE IT WHEN USING Transport API!
    3.64 -
    3.65 -
    3.66  #ifdef __cplusplus
    3.67  extern "C" {
    3.68  #endif
    3.69 @@ -89,16 +136,16 @@
    3.70  typedef int (*inject_sync_msg_t)(void *msg, void *management);
    3.71  
    3.72  
    3.73 -// retrieve_next_sync_msg - receive next sync message
    3.74 +// retrieve_next_sync_msg - retrieve next sync message
    3.75  //
    3.76  //  parameters:
    3.77  //      management (in)     application defined
    3.78 -//      timeout (in,out)    do not wait longer than timeout for message
    3.79 +//      timeout (in,out)    do not wait longer than timeout for message (seconds)
    3.80  //
    3.81  //  return value:
    3.82  //      next message or :
    3.83 -//      NULL + timeout == 0 for termination
    3.84 -//      NULL + timeout != 0 for timeout occurence
    3.85 +//      NULL and timeout == 0 for termination
    3.86 +//      NULL and timeout != 0 for timeout occurence
    3.87  
    3.88  typedef void *(*retrieve_next_sync_msg_t)(void *management, time_t *timeout);
    3.89  
     4.1 --- a/src/sync_driver.c	Wed Dec 07 15:41:29 2016 +0100
     4.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.3 @@ -1,40 +0,0 @@
     4.4 -// Driver for DeviceState state machine
     4.5 -
     4.6 -#include <assert.h>
     4.7 -#include "pEp_internal.h"
     4.8 -
     4.9 -
    4.10 -DYNAMIC_API PEP_STATUS fsm_DeviceState_inject(
    4.11 -        PEP_SESSION session,
    4.12 -        DeviceState_event event,
    4.13 -        Identity partner,
    4.14 -        void *extra,
    4.15 -        time_t *timeout
    4.16 -    )
    4.17 -{
    4.18 -    assert(session);
    4.19 -    if (!session)
    4.20 -        return PEP_ILLEGAL_VALUE;
    4.21 -
    4.22 -    while(true)
    4.23 -    {
    4.24 -        DeviceState_state new_state = fsm_DeviceState(session,
    4.25 -            session->sync_state, event, partner, extra, timeout);
    4.26 -
    4.27 -        if (new_state == DeviceState_state_invalid_out_of_memory)
    4.28 -            return PEP_OUT_OF_MEMORY;
    4.29 -
    4.30 -        if (new_state < 0)
    4.31 -            return PEP_SYNC_STATEMACHINE_ERROR - new_state;
    4.32 -        
    4.33 -        if (new_state == session->sync_state)
    4.34 -            break;
    4.35 -
    4.36 -        event = Init;
    4.37 -        extra = NULL;
    4.38 -        session->sync_state = new_state;
    4.39 -    } 
    4.40 -
    4.41 -    return PEP_STATUS_OK;
    4.42 -}
    4.43 -
     5.1 --- a/src/sync_fsm.h	Wed Dec 07 15:41:29 2016 +0100
     5.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.3 @@ -1,132 +0,0 @@
     5.4 -#pragma once
     5.5 -
     5.6 -// state machine for DeviceState
     5.7 -
     5.8 -#include "message_api.h"
     5.9 -
    5.10 -#ifdef __cplusplus
    5.11 -extern "C" {
    5.12 -#endif
    5.13 -
    5.14 -// types
    5.15 -
    5.16 -typedef pEp_identity * Identity;
    5.17 -typedef stringlist_t * Stringlist;
    5.18 -typedef union _param { Identity partner; stringlist_t *keylist; } param_t;
    5.19 -
    5.20 -// error values
    5.21 -
    5.22 -typedef enum _fsm_error {
    5.23 -    // these error values are corresponding to
    5.24 -    // PEP_SYNC_STATEMACHINE_ERROR - value
    5.25 -    invalid_state = -2,
    5.26 -    invalid_event = -3,
    5.27 -    invalid_condition = -4,
    5.28 -    invalid_action = -5,
    5.29 -
    5.30 -    // out of memory condition
    5.31 -    invalid_out_of_memory = -128
    5.32 -} fsm_error;
    5.33 -
    5.34 -// conditions
    5.35 -
    5.36 -int storedGroupKeys(PEP_SESSION session);
    5.37 -int keyElectionWon(PEP_SESSION session, Identity partner);
    5.38 -
    5.39 -// states
    5.40 -
    5.41 -typedef enum _DeviceState_state {
    5.42 -    // error values also in this namespace
    5.43 -    DeviceState_state_invalid_state = (int) invalid_state,
    5.44 -    DeviceState_state_invalid_event = (int) invalid_event,
    5.45 -    DeviceState_state_invalid_condition = (int) invalid_condition,
    5.46 -    DeviceState_state_invalid_action = (int) invalid_action,
    5.47 -    DeviceState_state_invalid_out_of_memory = (int) invalid_out_of_memory,
    5.48 -
    5.49 -    DeviceState_state_NONE = 0,
    5.50 -    InitState, 
    5.51 -    Sole, 
    5.52 -    HandshakingSole, 
    5.53 -    WaitForGroupKeysSole, 
    5.54 -    Grouped, 
    5.55 -    HandshakingGrouped
    5.56 -} DeviceState_state;
    5.57 -
    5.58 -// events
    5.59 -
    5.60 -typedef enum _DeviceState_event {
    5.61 -    DeviceState_event_NONE = 0,
    5.62 -    Init = 1,
    5.63 -    Beacon = 2,
    5.64 -    HandshakeRequest = 3,
    5.65 -    GroupKeys = 4,
    5.66 -    KeyGen, 
    5.67 -    CannotDecrypt, 
    5.68 -    HandshakeRejected, 
    5.69 -    HandshakeAccepted, 
    5.70 -    Cancel, 
    5.71 -    Timeout, 
    5.72 -    UpdateRequest, 
    5.73 -    GroupUpdate
    5.74 -} DeviceState_event;
    5.75 -
    5.76 -// actions
    5.77 -
    5.78 -PEP_STATUS sendBeacon(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
    5.79 -PEP_STATUS sendHandshakeRequest(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
    5.80 -PEP_STATUS showHandshake(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
    5.81 -PEP_STATUS rejectHandshake(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
    5.82 -PEP_STATUS acceptHandshake(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
    5.83 -PEP_STATUS sendGroupKeys(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
    5.84 -PEP_STATUS handshakeGroupCreated(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
    5.85 -PEP_STATUS dismissHandshake(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
    5.86 -PEP_STATUS storeGroupKeys(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
    5.87 -PEP_STATUS handshakeSuccess(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
    5.88 -PEP_STATUS handshakeFailure(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
    5.89 -PEP_STATUS enterGroup(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
    5.90 -PEP_STATUS sendGroupUpdate(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
    5.91 -PEP_STATUS sendUpdateRequest(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
    5.92 -PEP_STATUS handshakeDeviceAdded(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
    5.93 -
    5.94 -// event injector
    5.95 -
    5.96 -PEP_STATUS inject_DeviceState_event(
    5.97 -    PEP_SESSION session, 
    5.98 -    DeviceState_event event,
    5.99 -    Identity partner,
   5.100 -    void *extra);
   5.101 -
   5.102 -// message receiver
   5.103 -
   5.104 -PEP_STATUS receive_DeviceState_msg(
   5.105 -        PEP_SESSION session, 
   5.106 -        message *src, 
   5.107 -        PEP_rating rating, 
   5.108 -        stringlist_t *keylist
   5.109 -    );
   5.110 -
   5.111 -// state machine
   5.112 -
   5.113 -DeviceState_state fsm_DeviceState(
   5.114 -        PEP_SESSION session,
   5.115 -        DeviceState_state state,
   5.116 -        DeviceState_event event,
   5.117 -        Identity partner,
   5.118 -        void *extra,
   5.119 -        time_t *timeout
   5.120 -    );
   5.121 -
   5.122 -// driver
   5.123 -
   5.124 -DYNAMIC_API PEP_STATUS fsm_DeviceState_inject(
   5.125 -        PEP_SESSION session,
   5.126 -        DeviceState_event event,
   5.127 -        Identity partner,
   5.128 -        void *extra,
   5.129 -        time_t *timeout
   5.130 -    );
   5.131 -
   5.132 -#ifdef __cplusplus
   5.133 -}
   5.134 -#endif
   5.135 -
     6.1 --- a/src/sync_send_actions.c	Wed Dec 07 15:41:29 2016 +0100
     6.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.3 @@ -1,257 +0,0 @@
     6.4 -// Send Actions for DeviceState state machine
     6.5 -
     6.6 -#include <assert.h>
     6.7 -#include "pEp_internal.h"
     6.8 -#include "keymanagement.h"
     6.9 -#include "message.h"
    6.10 -#include "sync_fsm.h"
    6.11 -#include "baseprotocol.h"
    6.12 -#include "map_asn1.h"
    6.13 -#include "../asn.1/DeviceGroup-Protocol.h"
    6.14 -#include "sync_impl.h"
    6.15 -#include "../asn.1/Beacon.h"
    6.16 -#include "../asn.1/HandshakeRequest.h"
    6.17 -#include "../asn.1/GroupKeys.h"
    6.18 -#include "../asn.1/GroupUpdate.h"
    6.19 -#include "../asn.1/UpdateRequest.h"
    6.20 -
    6.21 -
    6.22 -// sendBeacon() - send Beacon message
    6.23 -//
    6.24 -//  params:
    6.25 -//      session (in)        session handle
    6.26 -//      state (in)          state the state machine is in
    6.27 -//      partner (in)        (must be NULL)
    6.28 -//
    6.29 -//  returns:
    6.30 -//      PEP_STATUS_OK or any other value on error
    6.31 -
    6.32 -PEP_STATUS sendBeacon(
    6.33 -        PEP_SESSION session,
    6.34 -        DeviceState_state state,
    6.35 -        Identity partner,
    6.36 -        void *extra
    6.37 -    )
    6.38 -{
    6.39 -    assert(session && state);
    6.40 -    if (!(session && state))
    6.41 -        return PEP_ILLEGAL_VALUE;
    6.42 -
    6.43 -    PEP_STATUS status = PEP_STATUS_OK;
    6.44 -
    6.45 -    DeviceGroup_Protocol_t *msg = new_DeviceGroup_Protocol_msg(DeviceGroup_Protocol__payload_PR_beacon);
    6.46 -    if (!msg)
    6.47 -        goto enomem;
    6.48 -
    6.49 -    bool encrypted = false;
    6.50 -    status = multicast_self_msg(session, state, msg, encrypted);
    6.51 -    if (status != PEP_STATUS_OK)
    6.52 -        goto error;
    6.53 -
    6.54 -    free_DeviceGroup_Protocol_msg(msg);
    6.55 -    return PEP_STATUS_OK;
    6.56 -
    6.57 -enomem:
    6.58 -    status = PEP_OUT_OF_MEMORY;
    6.59 -error:
    6.60 -    free_DeviceGroup_Protocol_msg(msg);
    6.61 -    return status;
    6.62 -}
    6.63 -
    6.64 -
    6.65 -// sendHandshakeRequest() - send HandshakeRequest message
    6.66 -//
    6.67 -//  params:
    6.68 -//      session (in)        session handle
    6.69 -//      state (in)          state the state machine is in
    6.70 -//      partner (in)        partner to communicate with
    6.71 -//
    6.72 -//  returns:
    6.73 -//      PEP_STATUS_OK or any other value on error
    6.74 -
    6.75 -PEP_STATUS sendHandshakeRequest(
    6.76 -        PEP_SESSION session,
    6.77 -        DeviceState_state state,
    6.78 -        Identity partner,
    6.79 -        void *extra
    6.80 -    )
    6.81 -{
    6.82 -    assert(session && state);
    6.83 -    if (!(session && state))
    6.84 -        return PEP_ILLEGAL_VALUE;
    6.85 -
    6.86 -    PEP_STATUS status = PEP_STATUS_OK;
    6.87 -
    6.88 -    DeviceGroup_Protocol_t *msg = new_DeviceGroup_Protocol_msg(DeviceGroup_Protocol__payload_PR_handshakeRequest);
    6.89 -    if (!msg)
    6.90 -        goto enomem;
    6.91 -
    6.92 -    if (Identity_from_Struct(partner,
    6.93 -                             &msg->payload.choice.handshakeRequest.partner) == NULL)
    6.94 -        goto enomem;
    6.95 -
    6.96 -    bool encrypted = true;
    6.97 -    status = unicast_msg(session, partner, state, msg, encrypted);
    6.98 -    if (status != PEP_STATUS_OK)
    6.99 -        goto error;
   6.100 -
   6.101 -    free_DeviceGroup_Protocol_msg(msg);
   6.102 -    return PEP_STATUS_OK;
   6.103 -
   6.104 -enomem:
   6.105 -    status = PEP_OUT_OF_MEMORY;
   6.106 -error:
   6.107 -    free_DeviceGroup_Protocol_msg(msg);
   6.108 -    return status;
   6.109 -}
   6.110 -
   6.111 -
   6.112 -// sendGroupKeys() - send GroupKeys message
   6.113 -//
   6.114 -//  params:
   6.115 -//      session (in)        session handle
   6.116 -//      state (in)          state the state machine is in
   6.117 -//      partner (in)        partner to communicate with
   6.118 -//
   6.119 -//  returns:
   6.120 -//      PEP_STATUS_OK or any other value on error
   6.121 -
   6.122 -PEP_STATUS sendGroupKeys(
   6.123 -        PEP_SESSION session,
   6.124 -        DeviceState_state state,
   6.125 -        Identity partner,
   6.126 -        void *extra
   6.127 -    )
   6.128 -{
   6.129 -    assert(session && state);
   6.130 -    if (!(session && state))
   6.131 -        return PEP_ILLEGAL_VALUE;
   6.132 -
   6.133 -    PEP_STATUS status = PEP_STATUS_OK;
   6.134 -    identity_list *kl = new_identity_list(NULL);
   6.135 -
   6.136 -    DeviceGroup_Protocol_t *msg = new_DeviceGroup_Protocol_msg(DeviceGroup_Protocol__payload_PR_groupKeys);
   6.137 -    if (!msg)
   6.138 -        goto enomem;
   6.139 -
   6.140 -    status = _own_identities_retrieve(session, &kl, PEP_idf_not_for_sync);
   6.141 -    if (status != PEP_STATUS_OK)
   6.142 -        goto error;
   6.143 -    if (IdentityList_from_identity_list(kl, &msg->payload.choice.groupKeys.ownIdentities) == NULL)
   6.144 -        goto enomem;
   6.145 -
   6.146 -    if (Identity_from_Struct(partner,
   6.147 -                             &msg->payload.choice.groupKeys.partner) == NULL)
   6.148 -        goto enomem;
   6.149 -
   6.150 -    bool encrypted = true;
   6.151 -    status = unicast_msg(session, partner, state, msg, encrypted);
   6.152 -    if (status != PEP_STATUS_OK)
   6.153 -        goto error;
   6.154 -
   6.155 -    free_identity_list(kl);
   6.156 -    free_DeviceGroup_Protocol_msg(msg);
   6.157 -    return PEP_STATUS_OK;
   6.158 -
   6.159 -enomem:
   6.160 -    status = PEP_OUT_OF_MEMORY;
   6.161 -error:
   6.162 -    free_DeviceGroup_Protocol_msg(msg);
   6.163 -    free_identity_list(kl);
   6.164 -    return status;
   6.165 -}
   6.166 -
   6.167 -
   6.168 -// sendGroupUpdate() - send GroupUpdate message
   6.169 -//
   6.170 -//  params:
   6.171 -//      session (in)        session handle
   6.172 -//      state (in)          state the state machine is in
   6.173 -//      partner (in)        (must be NULL)
   6.174 -//
   6.175 -//  returns:
   6.176 -//      PEP_STATUS_OK or any other value on error
   6.177 -
   6.178 -PEP_STATUS sendGroupUpdate(
   6.179 -        PEP_SESSION session,
   6.180 -        DeviceState_state state,
   6.181 -        Identity partner,
   6.182 -        void *extra
   6.183 -    )
   6.184 -{
   6.185 -    assert(session && state);
   6.186 -    if (!(session && state))
   6.187 -        return PEP_ILLEGAL_VALUE;
   6.188 -
   6.189 -    PEP_STATUS status = PEP_STATUS_OK;
   6.190 -    identity_list *kl = new_identity_list(NULL);
   6.191 -
   6.192 -    DeviceGroup_Protocol_t *msg = new_DeviceGroup_Protocol_msg(DeviceGroup_Protocol__payload_PR_groupUpdate);
   6.193 -    if (!msg)
   6.194 -        goto enomem;
   6.195 -
   6.196 -    status = _own_identities_retrieve(session, &kl, PEP_idf_not_for_sync);
   6.197 -    if (status != PEP_STATUS_OK)
   6.198 -        goto error;
   6.199 -    if (IdentityList_from_identity_list(kl, &msg->payload.choice.groupUpdate.ownIdentities) == NULL)
   6.200 -        goto enomem;
   6.201 -
   6.202 -    bool encrypted = true;
   6.203 -    status = multicast_self_msg(session, state, msg, encrypted);
   6.204 -    if (status != PEP_STATUS_OK)
   6.205 -        goto error;
   6.206 -
   6.207 -    free_identity_list(kl);
   6.208 -    free_DeviceGroup_Protocol_msg(msg);
   6.209 -    return PEP_STATUS_OK;
   6.210 -
   6.211 -enomem:
   6.212 -    status = PEP_OUT_OF_MEMORY;
   6.213 -error:
   6.214 -    free_DeviceGroup_Protocol_msg(msg);
   6.215 -    return status;
   6.216 -}
   6.217 -
   6.218 -
   6.219 -// sendUpdateRequest() - send UpdateRequest message
   6.220 -//
   6.221 -//  params:
   6.222 -//      session (in)        session handle
   6.223 -//      state (in)          state the state machine is in
   6.224 -//      partner (in)        (must be NULL)
   6.225 -//
   6.226 -//  returns:
   6.227 -//      PEP_STATUS_OK or any other value on error
   6.228 -
   6.229 -PEP_STATUS sendUpdateRequest(
   6.230 -        PEP_SESSION session,
   6.231 -        DeviceState_state state,
   6.232 -        Identity partner,
   6.233 -        void *extra
   6.234 -    )
   6.235 -{
   6.236 -    assert(session && state);
   6.237 -    if (!(session && state))
   6.238 -        return PEP_ILLEGAL_VALUE;
   6.239 -
   6.240 -    PEP_STATUS status = PEP_STATUS_OK;
   6.241 -
   6.242 -    DeviceGroup_Protocol_t *msg = new_DeviceGroup_Protocol_msg(DeviceGroup_Protocol__payload_PR_updateRequest);
   6.243 -    if (!msg)
   6.244 -        goto enomem;
   6.245 -
   6.246 -    bool encrypted = true;
   6.247 -    status = multicast_self_msg(session, state, msg, encrypted);
   6.248 -    if (status != PEP_STATUS_OK)
   6.249 -        goto error;
   6.250 -
   6.251 -    free_DeviceGroup_Protocol_msg(msg);
   6.252 -    return PEP_STATUS_OK;
   6.253 -
   6.254 -enomem:
   6.255 -    status = PEP_OUT_OF_MEMORY;
   6.256 -error:
   6.257 -    free_DeviceGroup_Protocol_msg(msg);
   6.258 -    return status;
   6.259 -}
   6.260 -
     7.1 --- a/sync/Makefile	Wed Dec 07 15:41:29 2016 +0100
     7.2 +++ b/sync/Makefile	Thu Dec 08 00:51:41 2016 +0100
     7.3 @@ -1,11 +1,15 @@
     7.4  include ../Makefile.conf
     7.5  
     7.6 -all: .statemachines .skeletons
     7.7 +all: .codegen
     7.8  
     7.9 -skeleton: .skeletons
    7.10 +skeleton: .actions
    7.11  
    7.12 -.skeletons: devicegroup.fsm gen_actions_skeleton.ysl2 fsm.yml2 functions.ysl2
    7.13 -	$(YML2PROC) -y gen_actions_skeleton.ysl2 $< -o $@
    7.14 +.codegen: .statemachines .actions
    7.15 +	cp -f generated/*.* ../src
    7.16 +	touch .codegen
    7.17 +
    7.18 +.actions: devicegroup.fsm gen_actions.ysl2 fsm.yml2 functions.ysl2
    7.19 +	$(YML2PROC) -y gen_actions.ysl2 $< -o $@
    7.20  
    7.21  .statemachines: devicegroup.fsm gen_statemachine.ysl2 fsm.yml2 functions.ysl2
    7.22  	$(YML2PROC) -y gen_statemachine.ysl2 $< -o $@
    7.23 @@ -13,7 +17,9 @@
    7.24  .PHONY: clean
    7.25  
    7.26  clean:
    7.27 -	rm -f *.xml *.xsl ../src/sync_fsm.* ../src/*.skeleton .statemachines .skeletons *.dot *.svg
    7.28 +	rm -f *.xml *.xsl \
    7.29 +    $(pathsub generated/%, ../src/% $(wildcard generated/*.*)) \
    7.30 +    ../generated/* ../skeletons/* .statemachines .actions *.dot *.svg
    7.31  
    7.32  %.xml: %.fsm
    7.33  	yml2c $< -o $@
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/sync/gen_actions.ysl2	Thu Dec 08 00:51:41 2016 +0100
     8.3 @@ -0,0 +1,221 @@
     8.4 +// generate actions skeleton
     8.5 +
     8.6 +// Copyleft (c) 2016, p≡p foundation
     8.7 +
     8.8 +// Written by Volker Birk
     8.9 +
    8.10 +include yslt.yml2
    8.11 +
    8.12 +tstylesheet {
    8.13 +    include standardlib.ysl2
    8.14 +    include ./functions.ysl2
    8.15 +
    8.16 +    template "/protocol" {
    8.17 +        apply "fsm", mode=send, 0;
    8.18 +        apply "fsm", mode=other, 0;
    8.19 +    }
    8.20 +
    8.21 +    template "fsm", mode=send document "generated/{@filename}_send_actions.c", "text" {
    8.22 +        const "name", "@name";
    8.23 +        const "filename", "@filename";
    8.24 +        ||
    8.25 +        // Send Actions for «@name» state machine
    8.26 +
    8.27 +        #include <assert.h>
    8.28 +        #include "pEp_internal.h"
    8.29 +        #include "keymanagement.h"
    8.30 +        #include "message.h"
    8.31 +        #include "«@filename»_fsm.h"
    8.32 +        #include "baseprotocol.h"
    8.33 +        #include "map_asn1.h"
    8.34 +        #include "../asn.1/DeviceGroup-Protocol.h"
    8.35 +        #include "sync_impl.h"
    8.36 +        ||
    8.37 +        for "func:distinctName(//action)"
    8.38 +            if "substring(@name, 1, 4) = 'send'"
    8.39 +                | #include "../asn.1/«substring(@name, 5, 255)».h"
    8.40 +        |
    8.41 +        for "func:distinctName(//action)"
    8.42 +            if "substring(@name, 1, 4) = 'send'"
    8.43 +                call "send_action"
    8.44 +                    with "action", ".",
    8.45 +                    with "fsm", "$name",
    8.46 +                    with "filename", "$filename";
    8.47 +    }
    8.48 +
    8.49 +    template "fsm", mode=other document "skeletons/{@filename}_actions.c", "text" {
    8.50 +        const "name", "@name";
    8.51 +        const "filename", "@filename";
    8.52 +        ||
    8.53 +        // Actions for «@name» state machine
    8.54 +
    8.55 +        #include <assert.h>
    8.56 +        #include "pEp_internal.h"
    8.57 +        #include "keymanagement.h"
    8.58 +        #include "message.h"
    8.59 +        #include "«@filename»_fsm.h"
    8.60 +        #include "../asn.1/DeviceGroup-Protocol.h"
    8.61 +
    8.62 +        ||
    8.63 +        for "func:distinctName(//action)"
    8.64 +            if "substring(@name, 1, 4) != 'send'"
    8.65 +                call "other_action"
    8.66 +                    with "action", ".",
    8.67 +                    with "fsm", "$name",
    8.68 +                    with "filename", "$filename";
    8.69 +    }
    8.70 +
    8.71 +    function "paramcheck" {
    8.72 +        param "partner";
    8.73 +        |> assert(session);
    8.74 +        choose {
    8.75 +            when "$partner"
    8.76 +            ||
    8.77 +                assert(partner);
    8.78 +                if (!(session && partner))
    8.79 +                    return PEP_ILLEGAL_VALUE;
    8.80 +            ||
    8.81 +            otherwise
    8.82 +            ||
    8.83 +                assert(!partner);
    8.84 +                if (!(session && !partner))
    8.85 +                    return PEP_ILLEGAL_VALUE;
    8.86 +            ||
    8.87 +        }
    8.88 +    }
    8.89 +
    8.90 +    function "other_action" {
    8.91 +        param "action";
    8.92 +        param "fsm";
    8.93 +        param "filename", "'###'";
    8.94 +
    8.95 +        ||
    8.96 +
    8.97 +        // «$action/@name»() - 
    8.98 +        //
    8.99 +        //  params:
   8.100 +        //      session (in)        session handle
   8.101 +        //      state (in)          state the state machine is in
   8.102 +        `` if "parm"        | //      partner (in)        partner to communicate with
   8.103 +        `` if "not(parm)"   | //      partner (in)        (must be NULL)
   8.104 +        //
   8.105 +        //  returns:
   8.106 +        //      PEP_STATUS_OK or any other value on error
   8.107 +
   8.108 +        PEP_STATUS «$action/@name»(
   8.109 +                PEP_SESSION session,
   8.110 +                «$fsm»_state state,
   8.111 +                Identity partner,
   8.112 +                void *extra
   8.113 +            )
   8.114 +        {
   8.115 +            PEP_STATUS status = PEP_STATUS_OK;
   8.116 +
   8.117 +            `` call "paramcheck" with "partner", "parm/partner";
   8.118 +
   8.119 +            // working code
   8.120 +
   8.121 +            // free extra
   8.122 +            return status;
   8.123 +
   8.124 +        enomem:
   8.125 +            status = PEP_OUT_OF_MEMORY;
   8.126 +        error:
   8.127 +            // free extra
   8.128 +            return status;
   8.129 +        }
   8.130 +
   8.131 +        ||
   8.132 +    }
   8.133 +
   8.134 +    function "send_action" {
   8.135 +        param "action";
   8.136 +        param "fsm";
   8.137 +        param "filename", "'###'";
   8.138 +        const "name", "substring($action/@name, 5, 255)";
   8.139 +        const "lname", "concat(yml:lcase(substring($name, 1, 1)), substring($name, 2))";
   8.140 +
   8.141 +        ||
   8.142 +
   8.143 +        // «$action/@name»() - send «$name» message
   8.144 +        //
   8.145 +        //  params:
   8.146 +        //      session (in)        session handle
   8.147 +        //      state (in)          state the state machine is in
   8.148 +        `` if "parm"        | //      partner (in)        partner to communicate with
   8.149 +        `` if "not(parm)"   | //      partner (in)        (must be NULL)
   8.150 +        //
   8.151 +        //  returns:
   8.152 +        //      PEP_STATUS_OK or any other value on error
   8.153 +
   8.154 +        PEP_STATUS «$action/@name»(
   8.155 +                PEP_SESSION session,
   8.156 +                «$fsm»_state state,
   8.157 +                Identity partner,
   8.158 +                void *extra
   8.159 +            )
   8.160 +        {
   8.161 +            assert(session && state);
   8.162 +            if (!(session && state))
   8.163 +                return PEP_ILLEGAL_VALUE;
   8.164 +
   8.165 +            PEP_STATUS status = PEP_STATUS_OK;
   8.166 +            `` if "$name='GroupKeys' or $name='GroupUpdate'" |> identity_list *kl = new_identity_list(NULL);
   8.167 +
   8.168 +            DeviceGroup_Protocol_t *msg = new_DeviceGroup_Protocol_msg(DeviceGroup_Protocol__payload_PR_«$lname»);
   8.169 +            if (!msg)
   8.170 +                goto enomem;
   8.171 +        ||
   8.172 +        choose {
   8.173 +            when "$name='GroupKeys' or $name='GroupUpdate'" {
   8.174 +                |
   8.175 +                |> status = _own_identities_retrieve(session, &kl, PEP_idf_not_for_sync);
   8.176 +                |> if (status != PEP_STATUS_OK)
   8.177 +                |>> goto error;
   8.178 +                |> if (IdentityList_from_identity_list(kl, &msg->payload.choice.«$lname».ownIdentities) == NULL)
   8.179 +                |>> goto enomem;
   8.180 +            }
   8.181 +        }
   8.182 +        choose {
   8.183 +            when "$name='GroupKeys' or $name='HandshakeRequest'" {
   8.184 +                |
   8.185 +                |> if (Identity_from_Struct(partner,
   8.186 +                |>                          &msg->payload.choice.«$lname».partner) == NULL)
   8.187 +                |>> goto enomem;
   8.188 +            }
   8.189 +        }
   8.190 +        ||
   8.191 +
   8.192 +        ||
   8.193 +        choose {
   8.194 +            when "count(/protocol/unencrypted/*[name()=$action/@name]) = 0"
   8.195 +                |> bool encrypted = true;
   8.196 +            otherwise
   8.197 +                |> bool encrypted = false;
   8.198 +        }
   8.199 +        choose {
   8.200 +            when "count(/protocol/broadcast/*[name()=$action/@name]) = 0"
   8.201 +                |> status = unicast_msg(session, partner, state, msg, encrypted);
   8.202 +            otherwise
   8.203 +                |> status = multicast_self_msg(session, state, msg, encrypted);
   8.204 +        }
   8.205 +        ||
   8.206 +            if (status != PEP_STATUS_OK)
   8.207 +                goto error;
   8.208 +
   8.209 +            `` if "$name='GroupKeys' or $name='GroupUpdate'" |> free_identity_list(kl);
   8.210 +            free_DeviceGroup_Protocol_msg(msg);
   8.211 +            return PEP_STATUS_OK;
   8.212 +
   8.213 +        enomem:
   8.214 +            status = PEP_OUT_OF_MEMORY;
   8.215 +        error:
   8.216 +            free_DeviceGroup_Protocol_msg(msg);
   8.217 +            `` if "$name='GroupKeys'" |> free_identity_list(kl);
   8.218 +            return status;
   8.219 +        }
   8.220 +
   8.221 +        ||
   8.222 +    }
   8.223 +}
   8.224 +
     9.1 --- a/sync/gen_actions_skeleton.ysl2	Wed Dec 07 15:41:29 2016 +0100
     9.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.3 @@ -1,221 +0,0 @@
     9.4 -// generate actions skeleton
     9.5 -
     9.6 -// Copyleft (c) 2016, p≡p foundation
     9.7 -
     9.8 -// Written by Volker Birk
     9.9 -
    9.10 -include yslt.yml2
    9.11 -
    9.12 -tstylesheet {
    9.13 -    include standardlib.ysl2
    9.14 -    include ./functions.ysl2
    9.15 -
    9.16 -    template "/protocol" {
    9.17 -        apply "fsm", mode=send, 0;
    9.18 -        apply "fsm", mode=other, 0;
    9.19 -    }
    9.20 -
    9.21 -    template "fsm", mode=send document "../src/{@filename}_send_actions.c", "text" {
    9.22 -        const "name", "@name";
    9.23 -        const "filename", "@filename";
    9.24 -        ||
    9.25 -        // Send Actions for «@name» state machine
    9.26 -
    9.27 -        #include <assert.h>
    9.28 -        #include "pEp_internal.h"
    9.29 -        #include "keymanagement.h"
    9.30 -        #include "message.h"
    9.31 -        #include "«@filename»_fsm.h"
    9.32 -        #include "baseprotocol.h"
    9.33 -        #include "map_asn1.h"
    9.34 -        #include "../asn.1/DeviceGroup-Protocol.h"
    9.35 -        #include "sync_impl.h"
    9.36 -        ||
    9.37 -        for "func:distinctName(//action)"
    9.38 -            if "substring(@name, 1, 4) = 'send'"
    9.39 -                | #include "../asn.1/«substring(@name, 5, 255)».h"
    9.40 -        |
    9.41 -        for "func:distinctName(//action)"
    9.42 -            if "substring(@name, 1, 4) = 'send'"
    9.43 -                call "send_action"
    9.44 -                    with "action", ".",
    9.45 -                    with "fsm", "$name",
    9.46 -                    with "filename", "$filename";
    9.47 -    }
    9.48 -
    9.49 -    template "fsm", mode=other document "../src/{@filename}_actions.c.skeleton", "text" {
    9.50 -        const "name", "@name";
    9.51 -        const "filename", "@filename";
    9.52 -        ||
    9.53 -        // Actions for «@name» state machine
    9.54 -
    9.55 -        #include <assert.h>
    9.56 -        #include "pEp_internal.h"
    9.57 -        #include "keymanagement.h"
    9.58 -        #include "message.h"
    9.59 -        #include "«@filename»_fsm.h"
    9.60 -        #include "../asn.1/DeviceGroup-Protocol.h"
    9.61 -
    9.62 -        ||
    9.63 -        for "func:distinctName(//action)"
    9.64 -            if "substring(@name, 1, 4) != 'send'"
    9.65 -                call "other_action"
    9.66 -                    with "action", ".",
    9.67 -                    with "fsm", "$name",
    9.68 -                    with "filename", "$filename";
    9.69 -    }
    9.70 -
    9.71 -    function "paramcheck" {
    9.72 -        param "partner";
    9.73 -        |> assert(session);
    9.74 -        choose {
    9.75 -            when "$partner"
    9.76 -            ||
    9.77 -                assert(partner);
    9.78 -                if (!(session && partner))
    9.79 -                    return PEP_ILLEGAL_VALUE;
    9.80 -            ||
    9.81 -            otherwise
    9.82 -            ||
    9.83 -                assert(!partner);
    9.84 -                if (!(session && !partner))
    9.85 -                    return PEP_ILLEGAL_VALUE;
    9.86 -            ||
    9.87 -        }
    9.88 -    }
    9.89 -
    9.90 -    function "other_action" {
    9.91 -        param "action";
    9.92 -        param "fsm";
    9.93 -        param "filename", "'###'";
    9.94 -
    9.95 -        ||
    9.96 -
    9.97 -        // «$action/@name»() - 
    9.98 -        //
    9.99 -        //  params:
   9.100 -        //      session (in)        session handle
   9.101 -        //      state (in)          state the state machine is in
   9.102 -        `` if "parm"        | //      partner (in)        partner to communicate with
   9.103 -        `` if "not(parm)"   | //      partner (in)        (must be NULL)
   9.104 -        //
   9.105 -        //  returns:
   9.106 -        //      PEP_STATUS_OK or any other value on error
   9.107 -
   9.108 -        PEP_STATUS «$action/@name»(
   9.109 -                PEP_SESSION session,
   9.110 -                «$fsm»_state state,
   9.111 -                Identity partner,
   9.112 -                void *extra
   9.113 -            )
   9.114 -        {
   9.115 -            PEP_STATUS status = PEP_STATUS_OK;
   9.116 -
   9.117 -            `` call "paramcheck" with "partner", "parm/partner";
   9.118 -
   9.119 -            // working code
   9.120 -
   9.121 -            // free extra
   9.122 -            return status;
   9.123 -
   9.124 -        enomem:
   9.125 -            status = PEP_OUT_OF_MEMORY;
   9.126 -        error:
   9.127 -            // free extra
   9.128 -            return status;
   9.129 -        }
   9.130 -
   9.131 -        ||
   9.132 -    }
   9.133 -
   9.134 -    function "send_action" {
   9.135 -        param "action";
   9.136 -        param "fsm";
   9.137 -        param "filename", "'###'";
   9.138 -        const "name", "substring($action/@name, 5, 255)";
   9.139 -        const "lname", "concat(yml:lcase(substring($name, 1, 1)), substring($name, 2))";
   9.140 -
   9.141 -        ||
   9.142 -
   9.143 -        // «$action/@name»() - send «$name» message
   9.144 -        //
   9.145 -        //  params:
   9.146 -        //      session (in)        session handle
   9.147 -        //      state (in)          state the state machine is in
   9.148 -        `` if "parm"        | //      partner (in)        partner to communicate with
   9.149 -        `` if "not(parm)"   | //      partner (in)        (must be NULL)
   9.150 -        //
   9.151 -        //  returns:
   9.152 -        //      PEP_STATUS_OK or any other value on error
   9.153 -
   9.154 -        PEP_STATUS «$action/@name»(
   9.155 -                PEP_SESSION session,
   9.156 -                «$fsm»_state state,
   9.157 -                Identity partner,
   9.158 -                void *extra
   9.159 -            )
   9.160 -        {
   9.161 -            assert(session && state);
   9.162 -            if (!(session && state))
   9.163 -                return PEP_ILLEGAL_VALUE;
   9.164 -
   9.165 -            PEP_STATUS status = PEP_STATUS_OK;
   9.166 -            `` if "$name='GroupKeys' or $name='GroupUpdate'" |> identity_list *kl = new_identity_list(NULL);
   9.167 -
   9.168 -            DeviceGroup_Protocol_t *msg = new_DeviceGroup_Protocol_msg(DeviceGroup_Protocol__payload_PR_«$lname»);
   9.169 -            if (!msg)
   9.170 -                goto enomem;
   9.171 -        ||
   9.172 -        choose {
   9.173 -            when "$name='GroupKeys' or $name='GroupUpdate'" {
   9.174 -                |
   9.175 -                |> status = _own_identities_retrieve(session, &kl, PEP_idf_not_for_sync);
   9.176 -                |> if (status != PEP_STATUS_OK)
   9.177 -                |>> goto error;
   9.178 -                |> if (IdentityList_from_identity_list(kl, &msg->payload.choice.«$lname».ownIdentities) == NULL)
   9.179 -                |>> goto enomem;
   9.180 -            }
   9.181 -        }
   9.182 -        choose {
   9.183 -            when "$name='GroupKeys' or $name='HandshakeRequest'" {
   9.184 -                |
   9.185 -                |> if (Identity_from_Struct(partner,
   9.186 -                |>                          &msg->payload.choice.«$lname».partner) == NULL)
   9.187 -                |>> goto enomem;
   9.188 -            }
   9.189 -        }
   9.190 -        ||
   9.191 -
   9.192 -        ||
   9.193 -        choose {
   9.194 -            when "count(/protocol/unencrypted/*[name()=$action/@name]) = 0"
   9.195 -                |> bool encrypted = true;
   9.196 -            otherwise
   9.197 -                |> bool encrypted = false;
   9.198 -        }
   9.199 -        choose {
   9.200 -            when "count(/protocol/broadcast/*[name()=$action/@name]) = 0"
   9.201 -                |> status = unicast_msg(session, partner, state, msg, encrypted);
   9.202 -            otherwise
   9.203 -                |> status = multicast_self_msg(session, state, msg, encrypted);
   9.204 -        }
   9.205 -        ||
   9.206 -            if (status != PEP_STATUS_OK)
   9.207 -                goto error;
   9.208 -
   9.209 -            `` if "$name='GroupKeys' or $name='GroupUpdate'" |> free_identity_list(kl);
   9.210 -            free_DeviceGroup_Protocol_msg(msg);
   9.211 -            return PEP_STATUS_OK;
   9.212 -
   9.213 -        enomem:
   9.214 -            status = PEP_OUT_OF_MEMORY;
   9.215 -        error:
   9.216 -            free_DeviceGroup_Protocol_msg(msg);
   9.217 -            `` if "$name='GroupKeys'" |> free_identity_list(kl);
   9.218 -            return status;
   9.219 -        }
   9.220 -
   9.221 -        ||
   9.222 -    }
   9.223 -}
   9.224 -
    10.1 --- a/sync/gen_statemachine.ysl2	Wed Dec 07 15:41:29 2016 +0100
    10.2 +++ b/sync/gen_statemachine.ysl2	Thu Dec 08 00:51:41 2016 +0100
    10.3 @@ -11,7 +11,7 @@
    10.4      include ./functions.ysl2
    10.5  
    10.6      template "/protocol" {
    10.7 -        document "../src/Makefile.protocols", "text"
    10.8 +        document "generated/Makefile.protocols", "text"
    10.9              apply "fsm", 0, mode="make";
   10.10          apply "fsm", 0, mode=gen;
   10.11      }
   10.12 @@ -23,7 +23,7 @@
   10.13      ||
   10.14  
   10.15      template "fsm", mode=gen {
   10.16 -        document "../src/{@filename}_fsm.h", "text" {
   10.17 +        document "generated/{@filename}_fsm.h", "text" {
   10.18          ||
   10.19          #pragma once
   10.20  
   10.21 @@ -136,7 +136,7 @@
   10.22  
   10.23          ||
   10.24          }
   10.25 -        document "../src/{@filename}_driver.c", "text"
   10.26 +        document "generated/{@filename}_driver.c", "text"
   10.27          ||
   10.28          // Driver for «@name» state machine
   10.29  
   10.30 @@ -179,7 +179,7 @@
   10.31          }
   10.32  
   10.33          ||
   10.34 -        document "../src/{@filename}_fsm.c", "text"
   10.35 +        document "generated/{@filename}_fsm.c", "text"
   10.36          ||
   10.37          #include "«@filename»_fsm.h"
   10.38          #include "pEp_internal.h"
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/sync/generated/README	Thu Dec 08 00:51:41 2016 +0100
    11.3 @@ -0,0 +1,11 @@
    11.4 +Code is generated here before beeing copied to /src during build process.
    11.5 +
    11.6 +This code is intended to be commited and reviewed, while the original files 
    11.7 +in src/ aren't tracked in mercurial (.hgignore). 
    11.8 +
    11.9 +Generated code must be generated out of source code systematically at build,
   11.10 +since generation could be influenced by build environment and parameters.
   11.11 +
   11.12 +Depending on build host, version control tool or unharchiving tool, generated
   11.13 +files timestamp may prevent re-generation. They must then be excluded from repo.
   11.14 +
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/sync/generated/sync_driver.c	Thu Dec 08 00:51:41 2016 +0100
    12.3 @@ -0,0 +1,40 @@
    12.4 +// Driver for DeviceState state machine
    12.5 +
    12.6 +#include <assert.h>
    12.7 +#include "pEp_internal.h"
    12.8 +
    12.9 +
   12.10 +DYNAMIC_API PEP_STATUS fsm_DeviceState_inject(
   12.11 +        PEP_SESSION session,
   12.12 +        DeviceState_event event,
   12.13 +        Identity partner,
   12.14 +        void *extra,
   12.15 +        time_t *timeout
   12.16 +    )
   12.17 +{
   12.18 +    assert(session);
   12.19 +    if (!session)
   12.20 +        return PEP_ILLEGAL_VALUE;
   12.21 +
   12.22 +    while(true)
   12.23 +    {
   12.24 +        DeviceState_state new_state = fsm_DeviceState(session,
   12.25 +            session->sync_state, event, partner, extra, timeout);
   12.26 +
   12.27 +        if (new_state == DeviceState_state_invalid_out_of_memory)
   12.28 +            return PEP_OUT_OF_MEMORY;
   12.29 +
   12.30 +        if (new_state < 0)
   12.31 +            return PEP_SYNC_STATEMACHINE_ERROR - new_state;
   12.32 +        
   12.33 +        if (new_state == session->sync_state)
   12.34 +            break;
   12.35 +
   12.36 +        event = Init;
   12.37 +        extra = NULL;
   12.38 +        session->sync_state = new_state;
   12.39 +    } 
   12.40 +
   12.41 +    return PEP_STATUS_OK;
   12.42 +}
   12.43 +
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/sync/generated/sync_fsm.c	Thu Dec 08 00:51:41 2016 +0100
    13.3 @@ -0,0 +1,361 @@
    13.4 +#include "sync_fsm.h"
    13.5 +#include "pEp_internal.h"
    13.6 +
    13.7 +// state machine for DeviceState
    13.8 +
    13.9 +DeviceState_state fsm_DeviceState(
   13.10 +        PEP_SESSION session,
   13.11 +        DeviceState_state state,
   13.12 +        DeviceState_event event,
   13.13 +        Identity partner,
   13.14 +        void *extra,
   13.15 +        time_t *timeout
   13.16 +    )
   13.17 +{
   13.18 +    int cond_result;
   13.19 +    PEP_STATUS status = PEP_STATUS_OK;
   13.20 +
   13.21 +    switch (state) {
   13.22 +        case InitState:
   13.23 +        {
   13.24 +            *timeout = 0;
   13.25 +            switch (event) {
   13.26 +                case Init:
   13.27 +                {
   13.28 +                    cond_result = storedGroupKeys(session);
   13.29 +                    if (cond_result < 0)
   13.30 +                        return cond_result;
   13.31 +                    if (cond_result) {
   13.32 +                        return Grouped;
   13.33 +                    }
   13.34 +                    return Sole;
   13.35 +                }
   13.36 +                default:
   13.37 +                    return (DeviceState_state) invalid_event;
   13.38 +            }
   13.39 +            break;
   13.40 +        }
   13.41 +        case Sole:
   13.42 +        {
   13.43 +            *timeout = 0;
   13.44 +            switch (event) {
   13.45 +                case Init: break;
   13.46 +                case KeyGen:
   13.47 +                {
   13.48 +                    status = sendBeacon(session, state, NULL, NULL);
   13.49 +                    if (status == PEP_OUT_OF_MEMORY)
   13.50 +                        return (int) invalid_out_of_memory;
   13.51 +                    if (status != PEP_STATUS_OK)
   13.52 +                        return (int) invalid_action;
   13.53 +                    break;
   13.54 +                }
   13.55 +                case CannotDecrypt:
   13.56 +                {
   13.57 +                    status = sendBeacon(session, state, NULL, NULL);
   13.58 +                    if (status == PEP_OUT_OF_MEMORY)
   13.59 +                        return (int) invalid_out_of_memory;
   13.60 +                    if (status != PEP_STATUS_OK)
   13.61 +                        return (int) invalid_action;
   13.62 +                    break;
   13.63 +                }
   13.64 +                case Beacon:
   13.65 +                {
   13.66 +                    status = sendHandshakeRequest(session, state, partner, NULL);
   13.67 +                    if (status == PEP_OUT_OF_MEMORY)
   13.68 +                        return (int) invalid_out_of_memory;
   13.69 +                    if (status != PEP_STATUS_OK)
   13.70 +                        return (int) invalid_action;
   13.71 +                    break;
   13.72 +                }
   13.73 +                case HandshakeRequest:
   13.74 +                {
   13.75 +                    status = sendHandshakeRequest(session, state, partner, NULL);
   13.76 +                    if (status == PEP_OUT_OF_MEMORY)
   13.77 +                        return (int) invalid_out_of_memory;
   13.78 +                    if (status != PEP_STATUS_OK)
   13.79 +                        return (int) invalid_action;
   13.80 +                    session->sync_state_payload = identity_dup(partner);
   13.81 +                    return HandshakingSole;
   13.82 +                }
   13.83 +                default:
   13.84 +                    return (DeviceState_state) invalid_event;
   13.85 +            }
   13.86 +            break;
   13.87 +        }
   13.88 +        case HandshakingSole:
   13.89 +        {
   13.90 +            Identity expected = (Identity)session->sync_state_payload;
   13.91 +            *timeout = 600;
   13.92 +            switch (event) {
   13.93 +                case Init:
   13.94 +                {
   13.95 +                    status = showHandshake(session, state, partner, NULL);
   13.96 +                    if (status == PEP_OUT_OF_MEMORY)
   13.97 +                        return (int) invalid_out_of_memory;
   13.98 +                    if (status != PEP_STATUS_OK)
   13.99 +                        return (int) invalid_action;
  13.100 +                    break;
  13.101 +                }
  13.102 +                case HandshakeRejected:
  13.103 +                {
  13.104 +                    status = rejectHandshake(session, state, partner, NULL);
  13.105 +                    if (status == PEP_OUT_OF_MEMORY)
  13.106 +                        return (int) invalid_out_of_memory;
  13.107 +                    if (status != PEP_STATUS_OK)
  13.108 +                        return (int) invalid_action;
  13.109 +                    if(session->sync_state_payload){
  13.110 +                        free_identity((Identity)session->sync_state_payload);
  13.111 +                        session->sync_state_payload = NULL;
  13.112 +                    }
  13.113 +                    return Sole;
  13.114 +                }
  13.115 +                case HandshakeAccepted:
  13.116 +                {
  13.117 +                    status = acceptHandshake(session, state, partner, NULL);
  13.118 +                    if (status == PEP_OUT_OF_MEMORY)
  13.119 +                        return (int) invalid_out_of_memory;
  13.120 +                    if (status != PEP_STATUS_OK)
  13.121 +                        return (int) invalid_action;
  13.122 +                    cond_result = keyElectionWon(session, partner);
  13.123 +                    if (cond_result < 0)
  13.124 +                        return cond_result;
  13.125 +                    if (cond_result) {
  13.126 +                        status = sendGroupKeys(session, state, partner, NULL);
  13.127 +                        if (status == PEP_OUT_OF_MEMORY)
  13.128 +                            return (int) invalid_out_of_memory;
  13.129 +                        if (status != PEP_STATUS_OK)
  13.130 +                            return (int) invalid_action;
  13.131 +                        status = handshakeGroupCreated(session, state, partner, NULL);
  13.132 +                        if (status == PEP_OUT_OF_MEMORY)
  13.133 +                            return (int) invalid_out_of_memory;
  13.134 +                        if (status != PEP_STATUS_OK)
  13.135 +                            return (int) invalid_action;
  13.136 +                        if(session->sync_state_payload){
  13.137 +                            free_identity((Identity)session->sync_state_payload);
  13.138 +                            session->sync_state_payload = NULL;
  13.139 +                        }
  13.140 +                        return Grouped;
  13.141 +                    }
  13.142 +                    if(session->sync_state_payload){
  13.143 +                        free_identity((Identity)session->sync_state_payload);
  13.144 +                        session->sync_state_payload = NULL;
  13.145 +                    }
  13.146 +                    session->sync_state_payload = identity_dup(partner);
  13.147 +                    return WaitForGroupKeysSole;
  13.148 +                }
  13.149 +                case Cancel:
  13.150 +                {
  13.151 +                    if(session->sync_state_payload){
  13.152 +                        free_identity((Identity)session->sync_state_payload);
  13.153 +                        session->sync_state_payload = NULL;
  13.154 +                    }
  13.155 +                    return Sole;
  13.156 +                }
  13.157 +                case Timeout:
  13.158 +                {
  13.159 +                    status = dismissHandshake(session, state, expected, NULL);
  13.160 +                    if (status == PEP_OUT_OF_MEMORY)
  13.161 +                        return (int) invalid_out_of_memory;
  13.162 +                    if (status != PEP_STATUS_OK)
  13.163 +                        return (int) invalid_action;
  13.164 +                    if(session->sync_state_payload){
  13.165 +                        free_identity((Identity)session->sync_state_payload);
  13.166 +                        session->sync_state_payload = NULL;
  13.167 +                    }
  13.168 +                    return Sole;
  13.169 +                }
  13.170 +                default:
  13.171 +                    return (DeviceState_state) invalid_event;
  13.172 +            }
  13.173 +            break;
  13.174 +        }
  13.175 +        case WaitForGroupKeysSole:
  13.176 +        {
  13.177 +            Identity expected = (Identity)session->sync_state_payload;
  13.178 +            *timeout = 600;
  13.179 +            switch (event) {
  13.180 +                case Init: break;
  13.181 +                case GroupKeys:
  13.182 +                {
  13.183 +                    status = storeGroupKeys(session, state, partner, extra /*keys*/);
  13.184 +                    if (status == PEP_OUT_OF_MEMORY)
  13.185 +                        return (int) invalid_out_of_memory;
  13.186 +                    if (status != PEP_STATUS_OK)
  13.187 +                        return (int) invalid_action;
  13.188 +                    status = handshakeSuccess(session, state, partner, NULL);
  13.189 +                    if (status == PEP_OUT_OF_MEMORY)
  13.190 +                        return (int) invalid_out_of_memory;
  13.191 +                    if (status != PEP_STATUS_OK)
  13.192 +                        return (int) invalid_action;
  13.193 +                    if(session->sync_state_payload){
  13.194 +                        free_identity((Identity)session->sync_state_payload);
  13.195 +                        session->sync_state_payload = NULL;
  13.196 +                    }
  13.197 +                    return Grouped;
  13.198 +                }
  13.199 +                case Timeout:
  13.200 +                {
  13.201 +                    status = handshakeFailure(session, state, expected, NULL);
  13.202 +                    if (status == PEP_OUT_OF_MEMORY)
  13.203 +                        return (int) invalid_out_of_memory;
  13.204 +                    if (status != PEP_STATUS_OK)
  13.205 +                        return (int) invalid_action;
  13.206 +                    if(session->sync_state_payload){
  13.207 +                        free_identity((Identity)session->sync_state_payload);
  13.208 +                        session->sync_state_payload = NULL;
  13.209 +                    }
  13.210 +                    return Sole;
  13.211 +                }
  13.212 +                default:
  13.213 +                    return (DeviceState_state) invalid_event;
  13.214 +            }
  13.215 +            break;
  13.216 +        }
  13.217 +        case Grouped:
  13.218 +        {
  13.219 +            *timeout = 0;
  13.220 +            switch (event) {
  13.221 +                case Init:
  13.222 +                {
  13.223 +                    status = enterGroup(session, state, NULL, NULL);
  13.224 +                    if (status == PEP_OUT_OF_MEMORY)
  13.225 +                        return (int) invalid_out_of_memory;
  13.226 +                    if (status != PEP_STATUS_OK)
  13.227 +                        return (int) invalid_action;
  13.228 +                    break;
  13.229 +                }
  13.230 +                case KeyGen:
  13.231 +                {
  13.232 +                    status = sendGroupUpdate(session, state, NULL, NULL);
  13.233 +                    if (status == PEP_OUT_OF_MEMORY)
  13.234 +                        return (int) invalid_out_of_memory;
  13.235 +                    if (status != PEP_STATUS_OK)
  13.236 +                        return (int) invalid_action;
  13.237 +                    break;
  13.238 +                }
  13.239 +                case CannotDecrypt:
  13.240 +                {
  13.241 +                    status = sendUpdateRequest(session, state, NULL, NULL);
  13.242 +                    if (status == PEP_OUT_OF_MEMORY)
  13.243 +                        return (int) invalid_out_of_memory;
  13.244 +                    if (status != PEP_STATUS_OK)
  13.245 +                        return (int) invalid_action;
  13.246 +                    break;
  13.247 +                }
  13.248 +                case UpdateRequest:
  13.249 +                {
  13.250 +                    status = sendGroupUpdate(session, state, NULL, NULL);
  13.251 +                    if (status == PEP_OUT_OF_MEMORY)
  13.252 +                        return (int) invalid_out_of_memory;
  13.253 +                    if (status != PEP_STATUS_OK)
  13.254 +                        return (int) invalid_action;
  13.255 +                    break;
  13.256 +                }
  13.257 +                case Beacon:
  13.258 +                {
  13.259 +                    status = sendHandshakeRequest(session, state, partner, NULL);
  13.260 +                    if (status == PEP_OUT_OF_MEMORY)
  13.261 +                        return (int) invalid_out_of_memory;
  13.262 +                    if (status != PEP_STATUS_OK)
  13.263 +                        return (int) invalid_action;
  13.264 +                    break;
  13.265 +                }
  13.266 +                case HandshakeRequest:
  13.267 +                {
  13.268 +                    status = sendHandshakeRequest(session, state, partner, NULL);
  13.269 +                    if (status == PEP_OUT_OF_MEMORY)
  13.270 +                        return (int) invalid_out_of_memory;
  13.271 +                    if (status != PEP_STATUS_OK)
  13.272 +                        return (int) invalid_action;
  13.273 +                    session->sync_state_payload = identity_dup(partner);
  13.274 +                    return HandshakingGrouped;
  13.275 +                }
  13.276 +                case GroupUpdate:
  13.277 +                {
  13.278 +                    status = storeGroupKeys(session, state, partner, extra /*keys*/);
  13.279 +                    if (status == PEP_OUT_OF_MEMORY)
  13.280 +                        return (int) invalid_out_of_memory;
  13.281 +                    if (status != PEP_STATUS_OK)
  13.282 +                        return (int) invalid_action;
  13.283 +                    break;
  13.284 +                }
  13.285 +                default:
  13.286 +                    return (DeviceState_state) invalid_event;
  13.287 +            }
  13.288 +            break;
  13.289 +        }
  13.290 +        case HandshakingGrouped:
  13.291 +        {
  13.292 +            Identity expected = (Identity)session->sync_state_payload;
  13.293 +            *timeout = 600;
  13.294 +            switch (event) {
  13.295 +                case Init:
  13.296 +                {
  13.297 +                    status = showHandshake(session, state, partner, NULL);
  13.298 +                    if (status == PEP_OUT_OF_MEMORY)
  13.299 +                        return (int) invalid_out_of_memory;
  13.300 +                    if (status != PEP_STATUS_OK)
  13.301 +                        return (int) invalid_action;
  13.302 +                    break;
  13.303 +                }
  13.304 +                case HandshakeRejected:
  13.305 +                {
  13.306 +                    status = rejectHandshake(session, state, partner, NULL);
  13.307 +                    if (status == PEP_OUT_OF_MEMORY)
  13.308 +                        return (int) invalid_out_of_memory;
  13.309 +                    if (status != PEP_STATUS_OK)
  13.310 +                        return (int) invalid_action;
  13.311 +                    if(session->sync_state_payload){
  13.312 +                        free_identity((Identity)session->sync_state_payload);
  13.313 +                        session->sync_state_payload = NULL;
  13.314 +                    }
  13.315 +                    return Grouped;
  13.316 +                }
  13.317 +                case HandshakeAccepted:
  13.318 +                {
  13.319 +                    status = acceptHandshake(session, state, partner, NULL);
  13.320 +                    if (status == PEP_OUT_OF_MEMORY)
  13.321 +                        return (int) invalid_out_of_memory;
  13.322 +                    if (status != PEP_STATUS_OK)
  13.323 +                        return (int) invalid_action;
  13.324 +                    status = sendGroupKeys(session, state, partner, NULL);
  13.325 +                    if (status == PEP_OUT_OF_MEMORY)
  13.326 +                        return (int) invalid_out_of_memory;
  13.327 +                    if (status != PEP_STATUS_OK)
  13.328 +                        return (int) invalid_action;
  13.329 +                    status = handshakeDeviceAdded(session, state, partner, NULL);
  13.330 +                    if (status == PEP_OUT_OF_MEMORY)
  13.331 +                        return (int) invalid_out_of_memory;
  13.332 +                    if (status != PEP_STATUS_OK)
  13.333 +                        return (int) invalid_action;
  13.334 +                    if(session->sync_state_payload){
  13.335 +                        free_identity((Identity)session->sync_state_payload);
  13.336 +                        session->sync_state_payload = NULL;
  13.337 +                    }
  13.338 +                    return Grouped;
  13.339 +                }
  13.340 +                case Timeout:
  13.341 +                {
  13.342 +                    status = handshakeFailure(session, state, expected, NULL);
  13.343 +                    if (status == PEP_OUT_OF_MEMORY)
  13.344 +                        return (int) invalid_out_of_memory;
  13.345 +                    if (status != PEP_STATUS_OK)
  13.346 +                        return (int) invalid_action;
  13.347 +                    if(session->sync_state_payload){
  13.348 +                        free_identity((Identity)session->sync_state_payload);
  13.349 +                        session->sync_state_payload = NULL;
  13.350 +                    }
  13.351 +                    return Grouped;
  13.352 +                }
  13.353 +                default:
  13.354 +                    return (DeviceState_state) invalid_event;
  13.355 +            }
  13.356 +            break;
  13.357 +        }
  13.358 +        default:
  13.359 +            return (DeviceState_state) invalid_state;
  13.360 +    }
  13.361 +
  13.362 +    return state;
  13.363 +}
  13.364 +
    14.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.2 +++ b/sync/generated/sync_fsm.h	Thu Dec 08 00:51:41 2016 +0100
    14.3 @@ -0,0 +1,132 @@
    14.4 +#pragma once
    14.5 +
    14.6 +// state machine for DeviceState
    14.7 +
    14.8 +#include "message_api.h"
    14.9 +
   14.10 +#ifdef __cplusplus
   14.11 +extern "C" {
   14.12 +#endif
   14.13 +
   14.14 +// types
   14.15 +
   14.16 +typedef pEp_identity * Identity;
   14.17 +typedef stringlist_t * Stringlist;
   14.18 +typedef union _param { Identity partner; stringlist_t *keylist; } param_t;
   14.19 +
   14.20 +// error values
   14.21 +
   14.22 +typedef enum _fsm_error {
   14.23 +    // these error values are corresponding to
   14.24 +    // PEP_SYNC_STATEMACHINE_ERROR - value
   14.25 +    invalid_state = -2,
   14.26 +    invalid_event = -3,
   14.27 +    invalid_condition = -4,
   14.28 +    invalid_action = -5,
   14.29 +
   14.30 +    // out of memory condition
   14.31 +    invalid_out_of_memory = -128
   14.32 +} fsm_error;
   14.33 +
   14.34 +// conditions
   14.35 +
   14.36 +int storedGroupKeys(PEP_SESSION session);
   14.37 +int keyElectionWon(PEP_SESSION session, Identity partner);
   14.38 +
   14.39 +// states
   14.40 +
   14.41 +typedef enum _DeviceState_state {
   14.42 +    // error values also in this namespace
   14.43 +    DeviceState_state_invalid_state = (int) invalid_state,
   14.44 +    DeviceState_state_invalid_event = (int) invalid_event,
   14.45 +    DeviceState_state_invalid_condition = (int) invalid_condition,
   14.46 +    DeviceState_state_invalid_action = (int) invalid_action,
   14.47 +    DeviceState_state_invalid_out_of_memory = (int) invalid_out_of_memory,
   14.48 +
   14.49 +    DeviceState_state_NONE = 0,
   14.50 +    InitState, 
   14.51 +    Sole, 
   14.52 +    HandshakingSole, 
   14.53 +    WaitForGroupKeysSole, 
   14.54 +    Grouped, 
   14.55 +    HandshakingGrouped
   14.56 +} DeviceState_state;
   14.57 +
   14.58 +// events
   14.59 +
   14.60 +typedef enum _DeviceState_event {
   14.61 +    DeviceState_event_NONE = 0,
   14.62 +    Init = 1,
   14.63 +    Beacon = 2,
   14.64 +    HandshakeRequest = 3,
   14.65 +    GroupKeys = 4,
   14.66 +    KeyGen, 
   14.67 +    CannotDecrypt, 
   14.68 +    HandshakeRejected, 
   14.69 +    HandshakeAccepted, 
   14.70 +    Cancel, 
   14.71 +    Timeout, 
   14.72 +    UpdateRequest, 
   14.73 +    GroupUpdate
   14.74 +} DeviceState_event;
   14.75 +
   14.76 +// actions
   14.77 +
   14.78 +PEP_STATUS sendBeacon(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
   14.79 +PEP_STATUS sendHandshakeRequest(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
   14.80 +PEP_STATUS showHandshake(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
   14.81 +PEP_STATUS rejectHandshake(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
   14.82 +PEP_STATUS acceptHandshake(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
   14.83 +PEP_STATUS sendGroupKeys(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
   14.84 +PEP_STATUS handshakeGroupCreated(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
   14.85 +PEP_STATUS dismissHandshake(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
   14.86 +PEP_STATUS storeGroupKeys(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
   14.87 +PEP_STATUS handshakeSuccess(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
   14.88 +PEP_STATUS handshakeFailure(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
   14.89 +PEP_STATUS enterGroup(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
   14.90 +PEP_STATUS sendGroupUpdate(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
   14.91 +PEP_STATUS sendUpdateRequest(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
   14.92 +PEP_STATUS handshakeDeviceAdded(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
   14.93 +
   14.94 +// event injector
   14.95 +
   14.96 +PEP_STATUS inject_DeviceState_event(
   14.97 +    PEP_SESSION session, 
   14.98 +    DeviceState_event event,
   14.99 +    Identity partner,
  14.100 +    void *extra);
  14.101 +
  14.102 +// message receiver
  14.103 +
  14.104 +PEP_STATUS receive_DeviceState_msg(
  14.105 +        PEP_SESSION session, 
  14.106 +        message *src, 
  14.107 +        PEP_rating rating, 
  14.108 +        stringlist_t *keylist
  14.109 +    );
  14.110 +
  14.111 +// state machine
  14.112 +
  14.113 +DeviceState_state fsm_DeviceState(
  14.114 +        PEP_SESSION session,
  14.115 +        DeviceState_state state,
  14.116 +        DeviceState_event event,
  14.117 +        Identity partner,
  14.118 +        void *extra,
  14.119 +        time_t *timeout
  14.120 +    );
  14.121 +
  14.122 +// driver
  14.123 +
  14.124 +DYNAMIC_API PEP_STATUS fsm_DeviceState_inject(
  14.125 +        PEP_SESSION session,
  14.126 +        DeviceState_event event,
  14.127 +        Identity partner,
  14.128 +        void *extra,
  14.129 +        time_t *timeout
  14.130 +    );
  14.131 +
  14.132 +#ifdef __cplusplus
  14.133 +}
  14.134 +#endif
  14.135 +
    15.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.2 +++ b/sync/generated/sync_send_actions.c	Thu Dec 08 00:51:41 2016 +0100
    15.3 @@ -0,0 +1,257 @@
    15.4 +// Send Actions for DeviceState state machine
    15.5 +
    15.6 +#include <assert.h>
    15.7 +#include "pEp_internal.h"
    15.8 +#include "keymanagement.h"
    15.9 +#include "message.h"
   15.10 +#include "sync_fsm.h"
   15.11 +#include "baseprotocol.h"
   15.12 +#include "map_asn1.h"
   15.13 +#include "../asn.1/DeviceGroup-Protocol.h"
   15.14 +#include "sync_impl.h"
   15.15 +#include "../asn.1/Beacon.h"
   15.16 +#include "../asn.1/HandshakeRequest.h"
   15.17 +#include "../asn.1/GroupKeys.h"
   15.18 +#include "../asn.1/GroupUpdate.h"
   15.19 +#include "../asn.1/UpdateRequest.h"
   15.20 +
   15.21 +
   15.22 +// sendBeacon() - send Beacon message
   15.23 +//
   15.24 +//  params:
   15.25 +//      session (in)        session handle
   15.26 +//      state (in)          state the state machine is in
   15.27 +//      partner (in)        (must be NULL)
   15.28 +//
   15.29 +//  returns:
   15.30 +//      PEP_STATUS_OK or any other value on error
   15.31 +
   15.32 +PEP_STATUS sendBeacon(
   15.33 +        PEP_SESSION session,
   15.34 +        DeviceState_state state,
   15.35 +        Identity partner,
   15.36 +        void *extra
   15.37 +    )
   15.38 +{
   15.39 +    assert(session && state);
   15.40 +    if (!(session && state))
   15.41 +        return PEP_ILLEGAL_VALUE;
   15.42 +
   15.43 +    PEP_STATUS status = PEP_STATUS_OK;
   15.44 +
   15.45 +    DeviceGroup_Protocol_t *msg = new_DeviceGroup_Protocol_msg(DeviceGroup_Protocol__payload_PR_beacon);
   15.46 +    if (!msg)
   15.47 +        goto enomem;
   15.48 +
   15.49 +    bool encrypted = false;
   15.50 +    status = multicast_self_msg(session, state, msg, encrypted);
   15.51 +    if (status != PEP_STATUS_OK)
   15.52 +        goto error;
   15.53 +
   15.54 +    free_DeviceGroup_Protocol_msg(msg);
   15.55 +    return PEP_STATUS_OK;
   15.56 +
   15.57 +enomem:
   15.58 +    status = PEP_OUT_OF_MEMORY;
   15.59 +error:
   15.60 +    free_DeviceGroup_Protocol_msg(msg);
   15.61 +    return status;
   15.62 +}
   15.63 +
   15.64 +
   15.65 +// sendHandshakeRequest() - send HandshakeRequest message
   15.66 +//
   15.67 +//  params:
   15.68 +//      session (in)        session handle
   15.69 +//      state (in)          state the state machine is in
   15.70 +//      partner (in)        partner to communicate with
   15.71 +//
   15.72 +//  returns:
   15.73 +//      PEP_STATUS_OK or any other value on error
   15.74 +
   15.75 +PEP_STATUS sendHandshakeRequest(
   15.76 +        PEP_SESSION session,
   15.77 +        DeviceState_state state,
   15.78 +        Identity partner,
   15.79 +        void *extra
   15.80 +    )
   15.81 +{
   15.82 +    assert(session && state);
   15.83 +    if (!(session && state))
   15.84 +        return PEP_ILLEGAL_VALUE;
   15.85 +
   15.86 +    PEP_STATUS status = PEP_STATUS_OK;
   15.87 +
   15.88 +    DeviceGroup_Protocol_t *msg = new_DeviceGroup_Protocol_msg(DeviceGroup_Protocol__payload_PR_handshakeRequest);
   15.89 +    if (!msg)
   15.90 +        goto enomem;
   15.91 +
   15.92 +    if (Identity_from_Struct(partner,
   15.93 +                             &msg->payload.choice.handshakeRequest.partner) == NULL)
   15.94 +        goto enomem;
   15.95 +
   15.96 +    bool encrypted = true;
   15.97 +    status = unicast_msg(session, partner, state, msg, encrypted);
   15.98 +    if (status != PEP_STATUS_OK)
   15.99 +        goto error;
  15.100 +
  15.101 +    free_DeviceGroup_Protocol_msg(msg);
  15.102 +    return PEP_STATUS_OK;
  15.103 +
  15.104 +enomem:
  15.105 +    status = PEP_OUT_OF_MEMORY;
  15.106 +error:
  15.107 +    free_DeviceGroup_Protocol_msg(msg);
  15.108 +    return status;
  15.109 +}
  15.110 +
  15.111 +
  15.112 +// sendGroupKeys() - send GroupKeys message
  15.113 +//
  15.114 +//  params:
  15.115 +//      session (in)        session handle
  15.116 +//      state (in)          state the state machine is in
  15.117 +//      partner (in)        partner to communicate with
  15.118 +//
  15.119 +//  returns:
  15.120 +//      PEP_STATUS_OK or any other value on error
  15.121 +
  15.122 +PEP_STATUS sendGroupKeys(
  15.123 +        PEP_SESSION session,
  15.124 +        DeviceState_state state,
  15.125 +        Identity partner,
  15.126 +        void *extra
  15.127 +    )
  15.128 +{
  15.129 +    assert(session && state);
  15.130 +    if (!(session && state))
  15.131 +        return PEP_ILLEGAL_VALUE;
  15.132 +
  15.133 +    PEP_STATUS status = PEP_STATUS_OK;
  15.134 +    identity_list *kl = new_identity_list(NULL);
  15.135 +
  15.136 +    DeviceGroup_Protocol_t *msg = new_DeviceGroup_Protocol_msg(DeviceGroup_Protocol__payload_PR_groupKeys);
  15.137 +    if (!msg)
  15.138 +        goto enomem;
  15.139 +
  15.140 +    status = _own_identities_retrieve(session, &kl, PEP_idf_not_for_sync);
  15.141 +    if (status != PEP_STATUS_OK)
  15.142 +        goto error;
  15.143 +    if (IdentityList_from_identity_list(kl, &msg->payload.choice.groupKeys.ownIdentities) == NULL)
  15.144 +        goto enomem;
  15.145 +
  15.146 +    if (Identity_from_Struct(partner,
  15.147 +                             &msg->payload.choice.groupKeys.partner) == NULL)
  15.148 +        goto enomem;
  15.149 +
  15.150 +    bool encrypted = true;
  15.151 +    status = unicast_msg(session, partner, state, msg, encrypted);
  15.152 +    if (status != PEP_STATUS_OK)
  15.153 +        goto error;
  15.154 +
  15.155 +    free_identity_list(kl);
  15.156 +    free_DeviceGroup_Protocol_msg(msg);
  15.157 +    return PEP_STATUS_OK;
  15.158 +
  15.159 +enomem:
  15.160 +    status = PEP_OUT_OF_MEMORY;
  15.161 +error:
  15.162 +    free_DeviceGroup_Protocol_msg(msg);
  15.163 +    free_identity_list(kl);
  15.164 +    return status;
  15.165 +}
  15.166 +
  15.167 +
  15.168 +// sendGroupUpdate() - send GroupUpdate message
  15.169 +//
  15.170 +//  params:
  15.171 +//      session (in)        session handle
  15.172 +//      state (in)          state the state machine is in
  15.173 +//      partner (in)        (must be NULL)
  15.174 +//
  15.175 +//  returns:
  15.176 +//      PEP_STATUS_OK or any other value on error
  15.177 +
  15.178 +PEP_STATUS sendGroupUpdate(
  15.179 +        PEP_SESSION session,
  15.180 +        DeviceState_state state,
  15.181 +        Identity partner,
  15.182 +        void *extra
  15.183 +    )
  15.184 +{
  15.185 +    assert(session && state);
  15.186 +    if (!(session && state))
  15.187 +        return PEP_ILLEGAL_VALUE;
  15.188 +
  15.189 +    PEP_STATUS status = PEP_STATUS_OK;
  15.190 +    identity_list *kl = new_identity_list(NULL);
  15.191 +
  15.192 +    DeviceGroup_Protocol_t *msg = new_DeviceGroup_Protocol_msg(DeviceGroup_Protocol__payload_PR_groupUpdate);
  15.193 +    if (!msg)
  15.194 +        goto enomem;
  15.195 +
  15.196 +    status = _own_identities_retrieve(session, &kl, PEP_idf_not_for_sync);
  15.197 +    if (status != PEP_STATUS_OK)
  15.198 +        goto error;
  15.199 +    if (IdentityList_from_identity_list(kl, &msg->payload.choice.groupUpdate.ownIdentities) == NULL)
  15.200 +        goto enomem;
  15.201 +
  15.202 +    bool encrypted = true;
  15.203 +    status = multicast_self_msg(session, state, msg, encrypted);
  15.204 +    if (status != PEP_STATUS_OK)
  15.205 +        goto error;
  15.206 +
  15.207 +    free_identity_list(kl);
  15.208 +    free_DeviceGroup_Protocol_msg(msg);
  15.209 +    return PEP_STATUS_OK;
  15.210 +
  15.211 +enomem:
  15.212 +    status = PEP_OUT_OF_MEMORY;
  15.213 +error:
  15.214 +    free_DeviceGroup_Protocol_msg(msg);
  15.215 +    return status;
  15.216 +}
  15.217 +
  15.218 +
  15.219 +// sendUpdateRequest() - send UpdateRequest message
  15.220 +//
  15.221 +//  params:
  15.222 +//      session (in)        session handle
  15.223 +//      state (in)          state the state machine is in
  15.224 +//      partner (in)        (must be NULL)
  15.225 +//
  15.226 +//  returns:
  15.227 +//      PEP_STATUS_OK or any other value on error
  15.228 +
  15.229 +PEP_STATUS sendUpdateRequest(
  15.230 +        PEP_SESSION session,
  15.231 +        DeviceState_state state,
  15.232 +        Identity partner,
  15.233 +        void *extra
  15.234 +    )
  15.235 +{
  15.236 +    assert(session && state);
  15.237 +    if (!(session && state))
  15.238 +        return PEP_ILLEGAL_VALUE;
  15.239 +
  15.240 +    PEP_STATUS status = PEP_STATUS_OK;
  15.241 +
  15.242 +    DeviceGroup_Protocol_t *msg = new_DeviceGroup_Protocol_msg(DeviceGroup_Protocol__payload_PR_updateRequest);
  15.243 +    if (!msg)
  15.244 +        goto enomem;
  15.245 +
  15.246 +    bool encrypted = true;
  15.247 +    status = multicast_self_msg(session, state, msg, encrypted);
  15.248 +    if (status != PEP_STATUS_OK)
  15.249 +        goto error;
  15.250 +
  15.251 +    free_DeviceGroup_Protocol_msg(msg);
  15.252 +    return PEP_STATUS_OK;
  15.253 +
  15.254 +enomem:
  15.255 +    status = PEP_OUT_OF_MEMORY;
  15.256 +error:
  15.257 +    free_DeviceGroup_Protocol_msg(msg);
  15.258 +    return status;
  15.259 +}
  15.260 +
    16.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.2 +++ b/sync/skeletons/sync_actions.c	Thu Dec 08 00:51:41 2016 +0100
    16.3 @@ -0,0 +1,379 @@
    16.4 +// Actions for DeviceState state machine
    16.5 +
    16.6 +#include <assert.h>
    16.7 +#include "pEp_internal.h"
    16.8 +#include "keymanagement.h"
    16.9 +#include "message.h"
   16.10 +#include "sync_fsm.h"
   16.11 +#include "../asn.1/DeviceGroup-Protocol.h"
   16.12 +
   16.13 +
   16.14 +// showHandshake() - 
   16.15 +//
   16.16 +//  params:
   16.17 +//      session (in)        session handle
   16.18 +//      state (in)          state the state machine is in
   16.19 +//      partner (in)        partner to communicate with
   16.20 +//
   16.21 +//  returns:
   16.22 +//      PEP_STATUS_OK or any other value on error
   16.23 +
   16.24 +PEP_STATUS showHandshake(
   16.25 +        PEP_SESSION session,
   16.26 +        DeviceState_state state,
   16.27 +        Identity partner,
   16.28 +        void *extra
   16.29 +    )
   16.30 +{
   16.31 +    PEP_STATUS status = PEP_STATUS_OK;
   16.32 +
   16.33 +    assert(session);
   16.34 +    assert(partner);
   16.35 +    if (!(session && partner))
   16.36 +        return PEP_ILLEGAL_VALUE;
   16.37 +
   16.38 +    // working code
   16.39 +
   16.40 +    // free extra
   16.41 +    return status;
   16.42 +
   16.43 +enomem:
   16.44 +    status = PEP_OUT_OF_MEMORY;
   16.45 +error:
   16.46 +    // free extra
   16.47 +    return status;
   16.48 +}
   16.49 +
   16.50 +
   16.51 +// rejectHandshake() - 
   16.52 +//
   16.53 +//  params:
   16.54 +//      session (in)        session handle
   16.55 +//      state (in)          state the state machine is in
   16.56 +//      partner (in)        partner to communicate with
   16.57 +//
   16.58 +//  returns:
   16.59 +//      PEP_STATUS_OK or any other value on error
   16.60 +
   16.61 +PEP_STATUS rejectHandshake(
   16.62 +        PEP_SESSION session,
   16.63 +        DeviceState_state state,
   16.64 +        Identity partner,
   16.65 +        void *extra
   16.66 +    )
   16.67 +{
   16.68 +    PEP_STATUS status = PEP_STATUS_OK;
   16.69 +
   16.70 +    assert(session);
   16.71 +    assert(partner);
   16.72 +    if (!(session && partner))
   16.73 +        return PEP_ILLEGAL_VALUE;
   16.74 +
   16.75 +    // working code
   16.76 +
   16.77 +    // free extra
   16.78 +    return status;
   16.79 +
   16.80 +enomem:
   16.81 +    status = PEP_OUT_OF_MEMORY;
   16.82 +error:
   16.83 +    // free extra
   16.84 +    return status;
   16.85 +}
   16.86 +
   16.87 +
   16.88 +// acceptHandshake() - 
   16.89 +//
   16.90 +//  params:
   16.91 +//      session (in)        session handle
   16.92 +//      state (in)          state the state machine is in
   16.93 +//      partner (in)        partner to communicate with
   16.94 +//
   16.95 +//  returns:
   16.96 +//      PEP_STATUS_OK or any other value on error
   16.97 +
   16.98 +PEP_STATUS acceptHandshake(
   16.99 +        PEP_SESSION session,
  16.100 +        DeviceState_state state,
  16.101 +        Identity partner,
  16.102 +        void *extra
  16.103 +    )
  16.104 +{
  16.105 +    PEP_STATUS status = PEP_STATUS_OK;
  16.106 +
  16.107 +    assert(session);
  16.108 +    assert(partner);
  16.109 +    if (!(session && partner))
  16.110 +        return PEP_ILLEGAL_VALUE;
  16.111 +
  16.112 +    // working code
  16.113 +
  16.114 +    // free extra
  16.115 +    return status;
  16.116 +
  16.117 +enomem:
  16.118 +    status = PEP_OUT_OF_MEMORY;
  16.119 +error:
  16.120 +    // free extra
  16.121 +    return status;
  16.122 +}
  16.123 +
  16.124 +
  16.125 +// handshakeGroupCreated() - 
  16.126 +//
  16.127 +//  params:
  16.128 +//      session (in)        session handle
  16.129 +//      state (in)          state the state machine is in
  16.130 +//      partner (in)        partner to communicate with
  16.131 +//
  16.132 +//  returns:
  16.133 +//      PEP_STATUS_OK or any other value on error
  16.134 +
  16.135 +PEP_STATUS handshakeGroupCreated(
  16.136 +        PEP_SESSION session,
  16.137 +        DeviceState_state state,
  16.138 +        Identity partner,
  16.139 +        void *extra
  16.140 +    )
  16.141 +{
  16.142 +    PEP_STATUS status = PEP_STATUS_OK;
  16.143 +
  16.144 +    assert(session);
  16.145 +    assert(partner);
  16.146 +    if (!(session && partner))
  16.147 +        return PEP_ILLEGAL_VALUE;
  16.148 +
  16.149 +    // working code
  16.150 +
  16.151 +    // free extra
  16.152 +    return status;
  16.153 +
  16.154 +enomem:
  16.155 +    status = PEP_OUT_OF_MEMORY;
  16.156 +error:
  16.157 +    // free extra
  16.158 +    return status;
  16.159 +}
  16.160 +
  16.161 +
  16.162 +// dismissHandshake() - 
  16.163 +//
  16.164 +//  params:
  16.165 +//      session (in)        session handle
  16.166 +//      state (in)          state the state machine is in
  16.167 +//      partner (in)        partner to communicate with
  16.168 +//
  16.169 +//  returns:
  16.170 +//      PEP_STATUS_OK or any other value on error
  16.171 +
  16.172 +PEP_STATUS dismissHandshake(
  16.173 +        PEP_SESSION session,
  16.174 +        DeviceState_state state,
  16.175 +        Identity partner,
  16.176 +        void *extra
  16.177 +    )
  16.178 +{
  16.179 +    PEP_STATUS status = PEP_STATUS_OK;
  16.180 +
  16.181 +    assert(session);
  16.182 +    assert(!partner);
  16.183 +    if (!(session && !partner))
  16.184 +        return PEP_ILLEGAL_VALUE;
  16.185 +
  16.186 +    // working code
  16.187 +
  16.188 +    // free extra
  16.189 +    return status;
  16.190 +
  16.191 +enomem:
  16.192 +    status = PEP_OUT_OF_MEMORY;
  16.193 +error:
  16.194 +    // free extra
  16.195 +    return status;
  16.196 +}
  16.197 +
  16.198 +
  16.199 +// storeGroupKeys() - 
  16.200 +//
  16.201 +//  params:
  16.202 +//      session (in)        session handle
  16.203 +//      state (in)          state the state machine is in
  16.204 +//      partner (in)        partner to communicate with
  16.205 +//
  16.206 +//  returns:
  16.207 +//      PEP_STATUS_OK or any other value on error
  16.208 +
  16.209 +PEP_STATUS storeGroupKeys(
  16.210 +        PEP_SESSION session,
  16.211 +        DeviceState_state state,
  16.212 +        Identity partner,
  16.213 +        void *extra
  16.214 +    )
  16.215 +{
  16.216 +    PEP_STATUS status = PEP_STATUS_OK;
  16.217 +
  16.218 +    assert(session);
  16.219 +    assert(partner);
  16.220 +    if (!(session && partner))
  16.221 +        return PEP_ILLEGAL_VALUE;
  16.222 +
  16.223 +    // working code
  16.224 +
  16.225 +    // free extra
  16.226 +    return status;
  16.227 +
  16.228 +enomem:
  16.229 +    status = PEP_OUT_OF_MEMORY;
  16.230 +error:
  16.231 +    // free extra
  16.232 +    return status;
  16.233 +}
  16.234 +
  16.235 +
  16.236 +// handshakeSuccess() - 
  16.237 +//
  16.238 +//  params:
  16.239 +//      session (in)        session handle
  16.240 +//      state (in)          state the state machine is in
  16.241 +//      partner (in)        partner to communicate with
  16.242 +//
  16.243 +//  returns:
  16.244 +//      PEP_STATUS_OK or any other value on error
  16.245 +
  16.246 +PEP_STATUS handshakeSuccess(
  16.247 +        PEP_SESSION session,
  16.248 +        DeviceState_state state,
  16.249 +        Identity partner,
  16.250 +        void *extra
  16.251 +    )
  16.252 +{
  16.253 +    PEP_STATUS status = PEP_STATUS_OK;
  16.254 +
  16.255 +    assert(session);
  16.256 +    assert(partner);
  16.257 +    if (!(session && partner))
  16.258 +        return PEP_ILLEGAL_VALUE;
  16.259 +
  16.260 +    // working code
  16.261 +
  16.262 +    // free extra
  16.263 +    return status;
  16.264 +
  16.265 +enomem:
  16.266 +    status = PEP_OUT_OF_MEMORY;
  16.267 +error:
  16.268 +    // free extra
  16.269 +    return status;
  16.270 +}
  16.271 +
  16.272 +
  16.273 +// handshakeFailure() - 
  16.274 +//
  16.275 +//  params:
  16.276 +//      session (in)        session handle
  16.277 +//      state (in)          state the state machine is in
  16.278 +//      partner (in)        partner to communicate with
  16.279 +//
  16.280 +//  returns:
  16.281 +//      PEP_STATUS_OK or any other value on error
  16.282 +
  16.283 +PEP_STATUS handshakeFailure(
  16.284 +        PEP_SESSION session,
  16.285 +        DeviceState_state state,
  16.286 +        Identity partner,
  16.287 +        void *extra
  16.288 +    )
  16.289 +{
  16.290 +    PEP_STATUS status = PEP_STATUS_OK;
  16.291 +
  16.292 +    assert(session);
  16.293 +    assert(!partner);
  16.294 +    if (!(session && !partner))
  16.295 +        return PEP_ILLEGAL_VALUE;
  16.296 +
  16.297 +    // working code
  16.298 +
  16.299 +    // free extra
  16.300 +    return status;
  16.301 +
  16.302 +enomem:
  16.303 +    status = PEP_OUT_OF_MEMORY;
  16.304 +error:
  16.305 +    // free extra
  16.306 +    return status;
  16.307 +}
  16.308 +
  16.309 +
  16.310 +// enterGroup() - 
  16.311 +//
  16.312 +//  params:
  16.313 +//      session (in)        session handle
  16.314 +//      state (in)          state the state machine is in
  16.315 +//      partner (in)        (must be NULL)
  16.316 +//
  16.317 +//  returns:
  16.318 +//      PEP_STATUS_OK or any other value on error
  16.319 +
  16.320 +PEP_STATUS enterGroup(
  16.321 +        PEP_SESSION session,
  16.322 +        DeviceState_state state,
  16.323 +        Identity partner,
  16.324 +        void *extra
  16.325 +    )
  16.326 +{
  16.327 +    PEP_STATUS status = PEP_STATUS_OK;
  16.328 +
  16.329 +    assert(session);
  16.330 +    assert(!partner);
  16.331 +    if (!(session && !partner))
  16.332 +        return PEP_ILLEGAL_VALUE;
  16.333 +
  16.334 +    // working code
  16.335 +
  16.336 +    // free extra
  16.337 +    return status;
  16.338 +
  16.339 +enomem:
  16.340 +    status = PEP_OUT_OF_MEMORY;
  16.341 +error:
  16.342 +    // free extra
  16.343 +    return status;
  16.344 +}
  16.345 +
  16.346 +
  16.347 +// handshakeDeviceAdded() - 
  16.348 +//
  16.349 +//  params:
  16.350 +//      session (in)        session handle
  16.351 +//      state (in)          state the state machine is in
  16.352 +//      partner (in)        partner to communicate with
  16.353 +//
  16.354 +//  returns:
  16.355 +//      PEP_STATUS_OK or any other value on error
  16.356 +
  16.357 +PEP_STATUS handshakeDeviceAdded(
  16.358 +        PEP_SESSION session,
  16.359 +        DeviceState_state state,
  16.360 +        Identity partner,
  16.361 +        void *extra
  16.362 +    )
  16.363 +{
  16.364 +    PEP_STATUS status = PEP_STATUS_OK;
  16.365 +
  16.366 +    assert(session);
  16.367 +    assert(partner);
  16.368 +    if (!(session && partner))
  16.369 +        return PEP_ILLEGAL_VALUE;
  16.370 +
  16.371 +    // working code
  16.372 +
  16.373 +    // free extra
  16.374 +    return status;
  16.375 +
  16.376 +enomem:
  16.377 +    status = PEP_OUT_OF_MEMORY;
  16.378 +error:
  16.379 +    // free extra
  16.380 +    return status;
  16.381 +}
  16.382 +