merge
authorEdouard Tisserant
Wed, 18 May 2016 15:12:19 +0200
changeset 65937bdde68b914
parent 658 244734164566
parent 657 224eeaf88a65
child 660 e1905543313b
merge
src/pEpEngine.c
src/pEpEngine.h
     1.1 --- a/src/map_asn1.c	Wed May 18 15:11:39 2016 +0200
     1.2 +++ b/src/map_asn1.c	Wed May 18 15:12:19 2016 +0200
     1.3 @@ -1,13 +1,14 @@
     1.4  #include "pEp_internal.h"
     1.5  #include "map_asn1.h"
     1.6  
     1.7 -Identity_t *Identity_from_Struct(const pEp_identity *ident)
     1.8 +Identity_t *Identity_from_Struct(const pEp_identity *ident, Identity_t *result)
     1.9  {
    1.10      assert(ident);
    1.11      if (!ident)
    1.12          return NULL;
    1.13  
    1.14 -    Identity_t *result = (Identity_t *) calloc(1, sizeof(Identity_t));
    1.15 +    if (!result)
    1.16 +        result = (Identity_t *) calloc(1, sizeof(Identity_t));
    1.17      assert(result);
    1.18      if (!result)
    1.19          return NULL;
    1.20 @@ -60,13 +61,14 @@
    1.21      return NULL;
    1.22  }
    1.23  
    1.24 -pEp_identity *Identity_to_Struct(Identity_t *ident)
    1.25 +pEp_identity *Identity_to_Struct(Identity_t *ident, pEp_identity *result)
    1.26  {
    1.27      assert(ident);
    1.28      if (!ident)
    1.29          return NULL;
    1.30      
    1.31 -    pEp_identity *result = new_identity(NULL, NULL, NULL, NULL);
    1.32 +    if (!result)
    1.33 +        result = new_identity(NULL, NULL, NULL, NULL);
    1.34      if (!result)
    1.35          return NULL;
    1.36  
    1.37 @@ -114,13 +116,14 @@
    1.38      return NULL;
    1.39  }
    1.40  
    1.41 -KeyList_t *KeyList_from_stringlist(const stringlist_t *list)
    1.42 +KeyList_t *KeyList_from_stringlist(const stringlist_t *list, KeyList_t *result)
    1.43  {
    1.44      assert(list);
    1.45      if (!list)
    1.46          return NULL;
    1.47  
    1.48 -    KeyList_t *result = (KeyList_t *) calloc(1, sizeof(KeyList_t));
    1.49 +    if (!result)
    1.50 +        result = (KeyList_t *) calloc(1, sizeof(KeyList_t));
    1.51      assert(result);
    1.52      if (!result)
    1.53          return NULL;
    1.54 @@ -143,13 +146,14 @@
    1.55      return NULL;
    1.56  }
    1.57  
    1.58 -stringlist_t *KeyList_to_stringlist(KeyList_t *list)
    1.59 +stringlist_t *KeyList_to_stringlist(KeyList_t *list, stringlist_t *result)
    1.60  {
    1.61      assert(list);
    1.62      if (!list)
    1.63          return NULL;
    1.64  
    1.65 -    stringlist_t *result = new_stringlist(NULL);
    1.66 +    if (!result)
    1.67 +        result = new_stringlist(NULL);
    1.68      if (!result)
    1.69          return NULL;
    1.70  
     2.1 --- a/src/map_asn1.h	Wed May 18 15:11:39 2016 +0200
     2.2 +++ b/src/map_asn1.h	Wed May 18 15:12:19 2016 +0200
     2.3 @@ -9,10 +9,10 @@
     2.4  extern "C" {
     2.5  #endif
     2.6  
     2.7 -Identity_t *Identity_from_Struct(const pEp_identity *ident);
     2.8 -pEp_identity *Identity_to_Struct(Identity_t *ident);
     2.9 -KeyList_t *KeyList_from_stringlist(const stringlist_t *list);
    2.10 -stringlist_t *KeyList_to_stringlist(KeyList_t *list);
    2.11 +Identity_t *Identity_from_Struct(const pEp_identity *ident, Identity_t *result);
    2.12 +pEp_identity *Identity_to_Struct(Identity_t *ident, pEp_identity *result);
    2.13 +KeyList_t *KeyList_from_stringlist(const stringlist_t *list, KeyList_t *result);
    2.14 +stringlist_t *KeyList_to_stringlist(KeyList_t *list, stringlist_t *result);
    2.15  
    2.16  #ifdef __cplusplus
    2.17  }
     3.1 --- a/src/pEpEngine.c	Wed May 18 15:11:39 2016 +0200
     3.2 +++ b/src/pEpEngine.c	Wed May 18 15:12:19 2016 +0200
     3.3 @@ -1434,7 +1434,7 @@
     3.4  DYNAMIC_API PEP_STATUS sequence_value(
     3.5          PEP_SESSION session,
     3.6          const char *name,
     3.7 -        int64_t *value
     3.8 +        int32_t *value
     3.9      )
    3.10  {
    3.11      PEP_STATUS status = PEP_STATUS_OK;
    3.12 @@ -1463,7 +1463,7 @@
    3.13          result = sqlite3_step(session->sequence_value2);
    3.14          switch (result) {
    3.15              case SQLITE_ROW: {
    3.16 -                int64_t _value = (int64_t)
    3.17 +                int32_t _value = (int32_t)
    3.18                          sqlite3_column_int64(session->sequence_value2, 0);
    3.19                  *value = _value;
    3.20                  break;
     4.1 --- a/src/pEpEngine.h	Wed May 18 15:11:39 2016 +0200
     4.2 +++ b/src/pEpEngine.h	Wed May 18 15:12:19 2016 +0200
     4.3 @@ -778,7 +778,7 @@
     4.4  DYNAMIC_API PEP_STATUS sequence_value(
     4.5          PEP_SESSION session,
     4.6          const char *name,
     4.7 -        int64_t *value
     4.8 +        int32_t *value
     4.9      );
    4.10  
    4.11  
     5.1 --- a/src/sync_actions.c	Wed May 18 15:11:39 2016 +0200
     5.2 +++ b/src/sync_actions.c	Wed May 18 15:12:19 2016 +0200
     5.3 @@ -1,6 +1,7 @@
     5.4  // Actions for DeviceState state machine
     5.5  
     5.6  #include <assert.h>
     5.7 +#include "keymanagement.h"
     5.8  #include "sync_fsm.h"
     5.9  #include "map_asn1.h"
    5.10  #include "../asn.1/Beacon.h"
    5.11 @@ -22,16 +23,30 @@
    5.12      PEP_STATUS status = PEP_STATUS_OK;
    5.13  
    5.14      assert(session);
    5.15 -    assert(!partner);
    5.16 -    if (!(session && !partner))
    5.17 -        return PEP_ILLEGAL_VALUE;
    5.18 +assert(!partner);
    5.19 +if (!(session && !partner))
    5.20 +    return PEP_ILLEGAL_VALUE;
    5.21  
    5.22      Beacon_t *msg = (Beacon_t *) calloc(1, sizeof(Beacon_t));
    5.23      assert(msg);
    5.24      if (!msg)
    5.25          goto enomem;
    5.26  
    5.27 -    
    5.28 +    int32_t seq;
    5.29 +    status = sequence_value(session, "DeviceGroup", &seq);
    5.30 +    if (status != PEP_STATUS_OK)
    5.31 +        goto error;
    5.32 +    msg->header.sequence = (long) seq;
    5.33 +
    5.34 +    pEp_identity *me = new_identity(NULL, NULL, NULL, NULL);
    5.35 +    if (!me)
    5.36 +        goto enomem;
    5.37 +    status = myself(session, me);
    5.38 +    if (status != PEP_STATUS_OK)
    5.39 +        goto error;
    5.40 +    if (Identity_from_Struct(me, &msg->me) == NULL)
    5.41 +        goto enomem;
    5.42 +
    5.43      return status;
    5.44  
    5.45  enomem:
    5.46 @@ -56,16 +71,33 @@
    5.47      PEP_STATUS status = PEP_STATUS_OK;
    5.48  
    5.49      assert(session);
    5.50 -    assert(partner);
    5.51 -    if (!(session && partner))
    5.52 -        return PEP_ILLEGAL_VALUE;
    5.53 +assert(partner);
    5.54 +if (!(session && partner))
    5.55 +    return PEP_ILLEGAL_VALUE;
    5.56  
    5.57      HandshakeRequest_t *msg = (HandshakeRequest_t *) calloc(1, sizeof(HandshakeRequest_t));
    5.58      assert(msg);
    5.59      if (!msg)
    5.60          goto enomem;
    5.61  
    5.62 -    
    5.63 +    int32_t seq;
    5.64 +    status = sequence_value(session, "DeviceGroup", &seq);
    5.65 +    if (status != PEP_STATUS_OK)
    5.66 +        goto error;
    5.67 +    msg->header.sequence = (long) seq;
    5.68 +
    5.69 +    pEp_identity *me = new_identity(NULL, NULL, NULL, NULL);
    5.70 +    if (!me)
    5.71 +        goto enomem;
    5.72 +    status = myself(session, me);
    5.73 +    if (status != PEP_STATUS_OK)
    5.74 +        goto error;
    5.75 +    if (Identity_from_Struct(me, &msg->me) == NULL)
    5.76 +        goto enomem;
    5.77 +
    5.78 +    if (Identity_from_Struct(partner, &msg->partner) == NULL)
    5.79 +        goto enomem;
    5.80 +
    5.81      return status;
    5.82  
    5.83  enomem:
    5.84 @@ -76,7 +108,7 @@
    5.85  }
    5.86  
    5.87  
    5.88 -// showHandshake() - send
    5.89 +// showHandshake() - 
    5.90  //
    5.91  //  params:
    5.92  //      session (in)        session handle
    5.93 @@ -90,9 +122,9 @@
    5.94      PEP_STATUS status = PEP_STATUS_OK;
    5.95  
    5.96      assert(session);
    5.97 -    assert(partner);
    5.98 -    if (!(session && partner))
    5.99 -        return PEP_ILLEGAL_VALUE;
   5.100 +assert(partner);
   5.101 +if (!(session && partner))
   5.102 +    return PEP_ILLEGAL_VALUE;
   5.103  
   5.104      // working code
   5.105  
   5.106 @@ -107,7 +139,7 @@
   5.107  }
   5.108  
   5.109  
   5.110 -// reject() - send
   5.111 +// reject() - 
   5.112  //
   5.113  //  params:
   5.114  //      session (in)        session handle
   5.115 @@ -121,9 +153,9 @@
   5.116      PEP_STATUS status = PEP_STATUS_OK;
   5.117  
   5.118      assert(session);
   5.119 -    assert(partner);
   5.120 -    if (!(session && partner))
   5.121 -        return PEP_ILLEGAL_VALUE;
   5.122 +assert(partner);
   5.123 +if (!(session && partner))
   5.124 +    return PEP_ILLEGAL_VALUE;
   5.125  
   5.126      // working code
   5.127  
   5.128 @@ -138,7 +170,7 @@
   5.129  }
   5.130  
   5.131  
   5.132 -// storeGroupKeys() - send
   5.133 +// storeGroupKeys() - 
   5.134  //
   5.135  //  params:
   5.136  //      session (in)        session handle
   5.137 @@ -152,9 +184,9 @@
   5.138      PEP_STATUS status = PEP_STATUS_OK;
   5.139  
   5.140      assert(session);
   5.141 -    assert(partner);
   5.142 -    if (!(session && partner))
   5.143 -        return PEP_ILLEGAL_VALUE;
   5.144 +assert(partner);
   5.145 +if (!(session && partner))
   5.146 +    return PEP_ILLEGAL_VALUE;
   5.147  
   5.148      // working code
   5.149  
   5.150 @@ -183,16 +215,37 @@
   5.151      PEP_STATUS status = PEP_STATUS_OK;
   5.152  
   5.153      assert(session);
   5.154 -    assert(!partner);
   5.155 -    if (!(session && !partner))
   5.156 -        return PEP_ILLEGAL_VALUE;
   5.157 +assert(!partner);
   5.158 +if (!(session && !partner))
   5.159 +    return PEP_ILLEGAL_VALUE;
   5.160  
   5.161      OwnKeys_t *msg = (OwnKeys_t *) calloc(1, sizeof(OwnKeys_t));
   5.162      assert(msg);
   5.163      if (!msg)
   5.164          goto enomem;
   5.165  
   5.166 -    
   5.167 +    int32_t seq;
   5.168 +    status = sequence_value(session, "DeviceGroup", &seq);
   5.169 +    if (status != PEP_STATUS_OK)
   5.170 +        goto error;
   5.171 +    msg->header.sequence = (long) seq;
   5.172 +
   5.173 +    pEp_identity *me = new_identity(NULL, NULL, NULL, NULL);
   5.174 +    if (!me)
   5.175 +        goto enomem;
   5.176 +    status = myself(session, me);
   5.177 +    if (status != PEP_STATUS_OK)
   5.178 +        goto error;
   5.179 +    if (Identity_from_Struct(me, &msg->me) == NULL)
   5.180 +        goto enomem;
   5.181 +
   5.182 +    stringlist_t *sl;
   5.183 +    status = own_key_retrieve(session, &sl);
   5.184 +    if (status != PEP_STATUS_OK)
   5.185 +        goto error;
   5.186 +    if (KeyList_from_stringlist(sl, &msg->keylist) == NULL)
   5.187 +        goto enomem;
   5.188 +
   5.189      return status;
   5.190  
   5.191  enomem:
   5.192 @@ -203,7 +256,7 @@
   5.193  }
   5.194  
   5.195  
   5.196 -// transmitGroupKeys() - send
   5.197 +// transmitGroupKeys() - 
   5.198  //
   5.199  //  params:
   5.200  //      session (in)        session handle
   5.201 @@ -217,9 +270,9 @@
   5.202      PEP_STATUS status = PEP_STATUS_OK;
   5.203  
   5.204      assert(session);
   5.205 -    assert(partner);
   5.206 -    if (!(session && partner))
   5.207 -        return PEP_ILLEGAL_VALUE;
   5.208 +assert(partner);
   5.209 +if (!(session && partner))
   5.210 +    return PEP_ILLEGAL_VALUE;
   5.211  
   5.212      // working code
   5.213  
     6.1 --- a/sync/gen_actions_skeleton.ysl2	Wed May 18 15:11:39 2016 +0200
     6.2 +++ b/sync/gen_actions_skeleton.ysl2	Wed May 18 15:12:19 2016 +0200
     6.3 @@ -34,6 +34,7 @@
     6.4      // Actions for «@name» state machine
     6.5  
     6.6      #include <assert.h>
     6.7 +    #include "keymanagement.h"
     6.8      #include "sync_fsm.h"
     6.9      #include "map_asn1.h"
    6.10      `` for "func:distinctName(//action)" if "substring(@name, 1, 4) = 'send'" | #include "../asn.1/«substring(@name, 5, 255)».h"
    6.11 @@ -53,12 +54,30 @@
    6.12          }
    6.13      }
    6.14  
    6.15 +    function "paramcheck" {
    6.16 +        param "partner";
    6.17 +        choose {
    6.18 +            when "$partner"
    6.19 +            ||
    6.20 +            assert(partner);
    6.21 +            if (!(session && partner))
    6.22 +                return PEP_ILLEGAL_VALUE;
    6.23 +            ||
    6.24 +            otherwise
    6.25 +            ||
    6.26 +            assert(!partner);
    6.27 +            if (!(session && !partner))
    6.28 +                return PEP_ILLEGAL_VALUE;
    6.29 +            ||
    6.30 +        }
    6.31 +    }
    6.32 +
    6.33      function "other_action" {
    6.34          param "action";
    6.35  
    6.36          ||
    6.37  
    6.38 -        // «$action/@name»() - send
    6.39 +        // «$action/@name»() - 
    6.40          //
    6.41          //  params:
    6.42          //      session (in)        session handle
    6.43 @@ -73,12 +92,7 @@
    6.44              PEP_STATUS status = PEP_STATUS_OK;
    6.45  
    6.46              assert(session);
    6.47 -        `` if "parm"        |> assert(partner);
    6.48 -        `` if "parm"        |> if (!(session && partner))
    6.49 -        `` if "parm"        |>> return PEP_ILLEGAL_VALUE;
    6.50 -        `` if "not(parm)"   |> assert(!partner);
    6.51 -        `` if "not(parm)"   |> if (!(session && !partner))
    6.52 -        `` if "not(parm)"   |>> return PEP_ILLEGAL_VALUE;
    6.53 +            `` call "paramcheck" with "partner", "parm/partner";
    6.54  
    6.55              // working code
    6.56  
    6.57 @@ -116,19 +130,37 @@
    6.58              PEP_STATUS status = PEP_STATUS_OK;
    6.59  
    6.60              assert(session);
    6.61 -        `` if "parm"        |> assert(partner);
    6.62 -        `` if "parm"        |> if (!(session && partner))
    6.63 -        `` if "parm"        |>> return PEP_ILLEGAL_VALUE;
    6.64 -        `` if "not(parm)"   |> assert(!partner);
    6.65 -        `` if "not(parm)"   |> if (!(session && !partner))
    6.66 -        `` if "not(parm)"   |>> return PEP_ILLEGAL_VALUE;
    6.67 +            `` call "paramcheck" with "partner", "parm/partner";
    6.68  
    6.69              «$name»_t *msg = («$name»_t *) calloc(1, sizeof(«$name»_t));
    6.70              assert(msg);
    6.71              if (!msg)
    6.72                  goto enomem;
    6.73  
    6.74 -            
    6.75 +            int32_t seq;
    6.76 +            status = sequence_value(session, "DeviceGroup", &seq);
    6.77 +            if (status != PEP_STATUS_OK)
    6.78 +                goto error;
    6.79 +            msg->header.sequence = (long) seq;
    6.80 +
    6.81 +            pEp_identity *me = new_identity(NULL, NULL, NULL, NULL);
    6.82 +            if (!me)
    6.83 +                goto enomem;
    6.84 +            status = myself(session, me);
    6.85 +            if (status != PEP_STATUS_OK)
    6.86 +                goto error;
    6.87 +            if (Identity_from_Struct(me, &msg->me) == NULL)
    6.88 +                goto enomem;
    6.89 +
    6.90 +         `` if "parm/partner"   |> if (Identity_from_Struct(partner, &msg->partner) == NULL)
    6.91 +         `` if "parm/partner"   |>> goto enomem;
    6.92 +         `` if "$name='OwnKeys'"|> stringlist_t *sl;
    6.93 +         `` if "$name='OwnKeys'"|> status = own_key_retrieve(session, &sl);
    6.94 +         `` if "$name='OwnKeys'"|> if (status != PEP_STATUS_OK)
    6.95 +         `` if "$name='OwnKeys'"|>> goto error;
    6.96 +         `` if "$name='OwnKeys'"|> if (KeyList_from_stringlist(sl, &msg->keylist) == NULL)
    6.97 +         `` if "$name='OwnKeys'"|>> goto enomem;
    6.98 +         `` if "parm or $name='OwnKeys'" |
    6.99              return status;
   6.100  
   6.101          enomem:
     7.1 --- a/sync/gen_statemachine.ysl2	Wed May 18 15:11:39 2016 +0200
     7.2 +++ b/sync/gen_statemachine.ysl2	Wed May 18 15:12:19 2016 +0200
     7.3 @@ -17,6 +17,10 @@
     7.4          // state machine for «@name»
     7.5  
     7.6          #include "pEpEngine.h"
     7.7 +        
     7.8 +        #ifdef __cplusplus
     7.9 +        extern "C" {
    7.10 +        #endif
    7.11  
    7.12          // types
    7.13  
    7.14 @@ -59,6 +63,10 @@
    7.15  
    7.16          PEP_STATUS fsm_«@name»_inject(PEP_SESSION session, «@name»_event event);
    7.17  
    7.18 +        #ifdef __cplusplus
    7.19 +        }
    7.20 +        #endif
    7.21 +
    7.22          ||
    7.23          ||
    7.24          #include "sync_fsm.h"
     8.1 --- a/test/map_asn1_test.cc	Wed May 18 15:11:39 2016 +0200
     8.2 +++ b/test/map_asn1_test.cc	Wed May 18 15:12:19 2016 +0200
     8.3 @@ -20,12 +20,12 @@
     8.4  
     8.5      cout << "converting identity to ASN.1...\n";
     8.6  
     8.7 -    Identity_t *ident_asn1 = Identity_from_Struct(ident1);
     8.8 +    Identity_t *ident_asn1 = Identity_from_Struct(ident1, NULL);
     8.9      assert(ident_asn1);
    8.10  
    8.11      cout << "converting identity from ASN.1...\n";
    8.12  
    8.13 -    pEp_identity *ident2 = Identity_to_Struct(ident_asn1);
    8.14 +    pEp_identity *ident2 = Identity_to_Struct(ident_asn1, NULL);
    8.15      assert(ident2);
    8.16  
    8.17      assert(strcmp(ident1->address, ident2->address) == 0);
    8.18 @@ -50,12 +50,12 @@
    8.19  
    8.20      cout << "converting stringlist to keylist...\n";
    8.21  
    8.22 -    KeyList_t *kl = KeyList_from_stringlist(sl);
    8.23 +    KeyList_t *kl = KeyList_from_stringlist(sl, NULL);
    8.24      assert(kl);
    8.25  
    8.26      cout << "converting keylist to stringlist...\n";
    8.27  
    8.28 -    stringlist_t *sl2 = KeyList_to_stringlist(kl);
    8.29 +    stringlist_t *sl2 = KeyList_to_stringlist(kl, NULL);
    8.30      assert(sl2);
    8.31  
    8.32      stringlist_t *_sl2;
     9.1 --- a/test/sequence_test.cc	Wed May 18 15:11:39 2016 +0200
     9.2 +++ b/test/sequence_test.cc	Wed May 18 15:12:19 2016 +0200
     9.3 @@ -18,13 +18,13 @@
     9.4  
     9.5      // sequence test code
     9.6  
     9.7 -    int64_t value1;
     9.8 +    int32_t value1;
     9.9      PEP_STATUS status2 = sequence_value(session, "test", &value1);
    9.10      assert(status2 == PEP_STATUS_OK);
    9.11  
    9.12      cout << "test sequence: " << value1 << "\n";
    9.13  
    9.14 -    int64_t value2;
    9.15 +    int32_t value2;
    9.16      PEP_STATUS status3 = sequence_value(session, "test", &value2);
    9.17      assert(status3 == PEP_STATUS_OK);
    9.18