...
authorVolker Birk <vb@pep-project.org>
Wed, 18 May 2016 00:05:39 +0200
changeset 650accc0ad7d32c
parent 649 46b19a439575
child 651 3543ea5e8b02
...
asn.1/devicegroup.asn1
src/sync_actions.c
sync/gen_actions_skeleton.ysl2
     1.1 --- a/asn.1/devicegroup.asn1	Tue May 17 21:48:49 2016 +0200
     1.2 +++ b/asn.1/devicegroup.asn1	Wed May 18 00:05:39 2016 +0200
     1.3 @@ -13,8 +13,8 @@
     1.4  
     1.5  HandshakeRequest ::= SEQUENCE {
     1.6      header Header,
     1.7 -    you Identity,
     1.8 -    me Identity
     1.9 +    me Identity,
    1.10 +    you Identity
    1.11  }
    1.12  
    1.13  OwnKeys ::= SEQUENCE {
     2.1 --- a/src/sync_actions.c	Tue May 17 21:48:49 2016 +0200
     2.2 +++ b/src/sync_actions.c	Wed May 18 00:05:39 2016 +0200
     2.3 @@ -2,9 +2,13 @@
     2.4  
     2.5  #include <assert.h>
     2.6  #include "sync_fsm.h"
     2.7 +#include "map_asn1.h"
     2.8 +#include "../asn.1/Beacon.h"
     2.9 +#include "../asn.1/HandshakeRequest.h"
    2.10 +#include "../asn.1/OwnKeys.h"
    2.11  
    2.12  
    2.13 -// sendBeacon() - 
    2.14 +// sendBeacon() - send Beacon message
    2.15  //
    2.16  //  params:
    2.17  //      session (in)        session handle
    2.18 @@ -17,17 +21,28 @@
    2.19  {
    2.20      PEP_STATUS status = PEP_STATUS_OK;
    2.21  
    2.22 -    assert(partner == NULL);
    2.23 -    if (partner)
    2.24 +    assert(session);
    2.25 +    assert(!partner);
    2.26 +    if (!(session && !partner))
    2.27          return PEP_ILLEGAL_VALUE;
    2.28  
    2.29 -    // working code
    2.30 +    Beacon_t *msg = (Beacon_t *) calloc(1, sizeof(Beacon_t));
    2.31 +    assert(msg);
    2.32 +    if (!msg)
    2.33 +        goto enomem;
    2.34  
    2.35 +    
    2.36 +    return status;
    2.37  
    2.38 +enomem:
    2.39 +    status = PEP_OUT_OF_MEMORY;
    2.40 +error:
    2.41 +    ASN_STRUCT_FREE(asn_DEF_Beacon, msg);
    2.42      return status;
    2.43  }
    2.44  
    2.45 -// sendHandshakeRequest() - 
    2.46 +
    2.47 +// sendHandshakeRequest() - send HandshakeRequest message
    2.48  //
    2.49  //  params:
    2.50  //      session (in)        session handle
    2.51 @@ -40,17 +55,28 @@
    2.52  {
    2.53      PEP_STATUS status = PEP_STATUS_OK;
    2.54  
    2.55 +    assert(session);
    2.56      assert(partner);
    2.57 -    if (!partner)
    2.58 +    if (!(session && partner))
    2.59          return PEP_ILLEGAL_VALUE;
    2.60  
    2.61 -    // working code
    2.62 +    HandshakeRequest_t *msg = (HandshakeRequest_t *) calloc(1, sizeof(HandshakeRequest_t));
    2.63 +    assert(msg);
    2.64 +    if (!msg)
    2.65 +        goto enomem;
    2.66  
    2.67 +    
    2.68 +    return status;
    2.69  
    2.70 +enomem:
    2.71 +    status = PEP_OUT_OF_MEMORY;
    2.72 +error:
    2.73 +    ASN_STRUCT_FREE(asn_DEF_HandshakeRequest, msg);
    2.74      return status;
    2.75  }
    2.76  
    2.77 -// showHandshake() - 
    2.78 +
    2.79 +// showHandshake() - send
    2.80  //
    2.81  //  params:
    2.82  //      session (in)        session handle
    2.83 @@ -63,17 +89,25 @@
    2.84  {
    2.85      PEP_STATUS status = PEP_STATUS_OK;
    2.86  
    2.87 +    assert(session);
    2.88      assert(partner);
    2.89 -    if (!partner)
    2.90 +    if (!(session && partner))
    2.91          return PEP_ILLEGAL_VALUE;
    2.92  
    2.93      // working code
    2.94  
    2.95  
    2.96      return status;
    2.97 +
    2.98 +enomem:
    2.99 +    status = PEP_OUT_OF_MEMORY;
   2.100 +error:
   2.101 +    // free...
   2.102 +    return status;
   2.103  }
   2.104  
   2.105 -// reject() - 
   2.106 +
   2.107 +// reject() - send
   2.108  //
   2.109  //  params:
   2.110  //      session (in)        session handle
   2.111 @@ -86,17 +120,25 @@
   2.112  {
   2.113      PEP_STATUS status = PEP_STATUS_OK;
   2.114  
   2.115 +    assert(session);
   2.116      assert(partner);
   2.117 -    if (!partner)
   2.118 +    if (!(session && partner))
   2.119          return PEP_ILLEGAL_VALUE;
   2.120  
   2.121      // working code
   2.122  
   2.123  
   2.124      return status;
   2.125 +
   2.126 +enomem:
   2.127 +    status = PEP_OUT_OF_MEMORY;
   2.128 +error:
   2.129 +    // free...
   2.130 +    return status;
   2.131  }
   2.132  
   2.133 -// storeGroupKeys() - 
   2.134 +
   2.135 +// storeGroupKeys() - send
   2.136  //
   2.137  //  params:
   2.138  //      session (in)        session handle
   2.139 @@ -109,17 +151,25 @@
   2.140  {
   2.141      PEP_STATUS status = PEP_STATUS_OK;
   2.142  
   2.143 +    assert(session);
   2.144      assert(partner);
   2.145 -    if (!partner)
   2.146 +    if (!(session && partner))
   2.147          return PEP_ILLEGAL_VALUE;
   2.148  
   2.149      // working code
   2.150  
   2.151  
   2.152      return status;
   2.153 +
   2.154 +enomem:
   2.155 +    status = PEP_OUT_OF_MEMORY;
   2.156 +error:
   2.157 +    // free...
   2.158 +    return status;
   2.159  }
   2.160  
   2.161 -// sendOwnKeys() - 
   2.162 +
   2.163 +// sendOwnKeys() - send OwnKeys message
   2.164  //
   2.165  //  params:
   2.166  //      session (in)        session handle
   2.167 @@ -132,17 +182,28 @@
   2.168  {
   2.169      PEP_STATUS status = PEP_STATUS_OK;
   2.170  
   2.171 -    assert(partner == NULL);
   2.172 -    if (partner)
   2.173 +    assert(session);
   2.174 +    assert(!partner);
   2.175 +    if (!(session && !partner))
   2.176          return PEP_ILLEGAL_VALUE;
   2.177  
   2.178 -    // working code
   2.179 +    OwnKeys_t *msg = (OwnKeys_t *) calloc(1, sizeof(OwnKeys_t));
   2.180 +    assert(msg);
   2.181 +    if (!msg)
   2.182 +        goto enomem;
   2.183  
   2.184 +    
   2.185 +    return status;
   2.186  
   2.187 +enomem:
   2.188 +    status = PEP_OUT_OF_MEMORY;
   2.189 +error:
   2.190 +    ASN_STRUCT_FREE(asn_DEF_OwnKeys, msg);
   2.191      return status;
   2.192  }
   2.193  
   2.194 -// transmitGroupKeys() - 
   2.195 +
   2.196 +// transmitGroupKeys() - send
   2.197  //
   2.198  //  params:
   2.199  //      session (in)        session handle
   2.200 @@ -155,13 +216,20 @@
   2.201  {
   2.202      PEP_STATUS status = PEP_STATUS_OK;
   2.203  
   2.204 +    assert(session);
   2.205      assert(partner);
   2.206 -    if (!partner)
   2.207 +    if (!(session && partner))
   2.208          return PEP_ILLEGAL_VALUE;
   2.209  
   2.210      // working code
   2.211  
   2.212  
   2.213      return status;
   2.214 +
   2.215 +enomem:
   2.216 +    status = PEP_OUT_OF_MEMORY;
   2.217 +error:
   2.218 +    // free...
   2.219 +    return status;
   2.220  }
   2.221  
     3.1 --- a/sync/gen_actions_skeleton.ysl2	Tue May 17 21:48:49 2016 +0200
     3.2 +++ b/sync/gen_actions_skeleton.ysl2	Wed May 18 00:05:39 2016 +0200
     3.3 @@ -35,7 +35,8 @@
     3.4  
     3.5      #include <assert.h>
     3.6      #include "sync_fsm.h"
     3.7 -
     3.8 +    #include "map_asn1.h"
     3.9 +    `` for "func:distinctName(//action)" if "substring(@name, 0, 5) = 'send'" | #include "../asn.1/«substring(@name, 5, 255)».h"
    3.10  
    3.11      `` for "func:distinctName(//action)" call "action" with "action", ".";
    3.12  
    3.13 @@ -44,9 +45,20 @@
    3.14  
    3.15      function "action" {
    3.16          param "action";
    3.17 +        choose {
    3.18 +            when "substring($action/@name, 0, 5) = 'send'"
    3.19 +                call "send_action" with "action", "$action";
    3.20 +            otherwise
    3.21 +                call "other_action" with "action", "$action";
    3.22 +        }
    3.23 +    }
    3.24 +
    3.25 +    function "other_action" {
    3.26 +        param "action";
    3.27  
    3.28          ||
    3.29 -        // «$action/@name»() - 
    3.30 +
    3.31 +        // «$action/@name»() - send
    3.32          //
    3.33          //  params:
    3.34          //      session (in)        session handle
    3.35 @@ -60,17 +72,70 @@
    3.36          {
    3.37              PEP_STATUS status = PEP_STATUS_OK;
    3.38  
    3.39 +            assert(session);
    3.40          `` if "parm"        |> assert(partner);
    3.41 -        `` if "parm"        |> if (!partner)
    3.42 +        `` if "parm"        |> if (!(session && partner))
    3.43          `` if "parm"        |>> return PEP_ILLEGAL_VALUE;
    3.44 -        `` if "not(parm)"   |> assert(partner == NULL);
    3.45 -        `` if "not(parm)"   |> if (partner)
    3.46 +        `` if "not(parm)"   |> assert(!partner);
    3.47 +        `` if "not(parm)"   |> if (!(session && !partner))
    3.48          `` if "not(parm)"   |>> return PEP_ILLEGAL_VALUE;
    3.49  
    3.50              // working code
    3.51  
    3.52  
    3.53              return status;
    3.54 +
    3.55 +        enomem:
    3.56 +            status = PEP_OUT_OF_MEMORY;
    3.57 +        error:
    3.58 +            // free...
    3.59 +            return status;
    3.60 +        }
    3.61 +
    3.62 +        ||
    3.63 +    }
    3.64 +
    3.65 +    function "send_action" {
    3.66 +        param "action";
    3.67 +        const "name", "substring($action/@name, 5, 255)";
    3.68 +
    3.69 +        ||
    3.70 +
    3.71 +        // «$action/@name»() - send «$name» message
    3.72 +        //
    3.73 +        //  params:
    3.74 +        //      session (in)        session handle
    3.75 +        `` if "parm"        | //      partner (in)        partner in sync
    3.76 +        `` if "not(parm)"   | //      partner (in)        (must be NULL)
    3.77 +        //
    3.78 +        //  returns:
    3.79 +        //      PEP_STATUS_OK or any other value on error
    3.80 +
    3.81 +        PEP_STATUS «$action/@name»(PEP_SESSION session, const Identity partner)
    3.82 +        {
    3.83 +            PEP_STATUS status = PEP_STATUS_OK;
    3.84 +
    3.85 +            assert(session);
    3.86 +        `` if "parm"        |> assert(partner);
    3.87 +        `` if "parm"        |> if (!(session && partner))
    3.88 +        `` if "parm"        |>> return PEP_ILLEGAL_VALUE;
    3.89 +        `` if "not(parm)"   |> assert(!partner);
    3.90 +        `` if "not(parm)"   |> if (!(session && !partner))
    3.91 +        `` if "not(parm)"   |>> return PEP_ILLEGAL_VALUE;
    3.92 +
    3.93 +            «$name»_t *msg = («$name»_t *) calloc(1, sizeof(«$name»_t));
    3.94 +            assert(msg);
    3.95 +            if (!msg)
    3.96 +                goto enomem;
    3.97 +
    3.98 +            
    3.99 +            return status;
   3.100 +
   3.101 +        enomem:
   3.102 +            status = PEP_OUT_OF_MEMORY;
   3.103 +        error:
   3.104 +            ASN_STRUCT_FREE(asn_DEF_«$name», msg);
   3.105 +            return status;
   3.106          }
   3.107  
   3.108          ||