...
authorVolker Birk <vb@pep-project.org>
Wed, 18 May 2016 12:54:22 +0200
changeset 6540aa96447e38f
parent 653 a9752fd8d54c
child 655 8413f45947e8
...
src/map_asn1.c
src/map_asn1.h
src/sync_actions.c
sync/gen_actions_skeleton.ysl2
sync/gen_statemachine.ysl2
test/map_asn1_test.cc
test/sequence_test.cc
     1.1 --- a/src/map_asn1.c	Wed May 18 12:22:02 2016 +0200
     1.2 +++ b/src/map_asn1.c	Wed May 18 12:54:22 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 12:22:02 2016 +0200
     2.2 +++ b/src/map_asn1.h	Wed May 18 12:54:22 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/sync_actions.c	Wed May 18 12:22:02 2016 +0200
     3.2 +++ b/src/sync_actions.c	Wed May 18 12:54:22 2016 +0200
     3.3 @@ -1,6 +1,7 @@
     3.4  // Actions for DeviceState state machine
     3.5  
     3.6  #include <assert.h>
     3.7 +#include "keymanagement.h"
     3.8  #include "sync_fsm.h"
     3.9  #include "map_asn1.h"
    3.10  #include "../asn.1/Beacon.h"
    3.11 @@ -35,9 +36,15 @@
    3.12      status = sequence_value(session, "DeviceGroup", &seq);
    3.13      if (status != PEP_STATUS_OK)
    3.14          goto error;
    3.15 +    msg->header.sequence = (long) seq;
    3.16  
    3.17 -    msg->header.sequence = seq;
    3.18 -
    3.19 +    pEp_identity *me = new_identity(NULL, NULL, NULL, NULL);
    3.20 +    if (!me)
    3.21 +        goto enomem;
    3.22 +    status = myself(session, me);
    3.23 +    if (status != PEP_STATUS_OK)
    3.24 +        goto error;
    3.25 +    
    3.26      return status;
    3.27  
    3.28  enomem:
    3.29 @@ -75,9 +82,15 @@
    3.30      status = sequence_value(session, "DeviceGroup", &seq);
    3.31      if (status != PEP_STATUS_OK)
    3.32          goto error;
    3.33 +    msg->header.sequence = (long) seq;
    3.34  
    3.35 -    msg->header.sequence = seq;
    3.36 -
    3.37 +    pEp_identity *me = new_identity(NULL, NULL, NULL, NULL);
    3.38 +    if (!me)
    3.39 +        goto enomem;
    3.40 +    status = myself(session, me);
    3.41 +    if (status != PEP_STATUS_OK)
    3.42 +        goto error;
    3.43 +    
    3.44      return status;
    3.45  
    3.46  enomem:
    3.47 @@ -208,9 +221,15 @@
    3.48      status = sequence_value(session, "DeviceGroup", &seq);
    3.49      if (status != PEP_STATUS_OK)
    3.50          goto error;
    3.51 +    msg->header.sequence = (long) seq;
    3.52  
    3.53 -    msg->header.sequence = seq;
    3.54 -
    3.55 +    pEp_identity *me = new_identity(NULL, NULL, NULL, NULL);
    3.56 +    if (!me)
    3.57 +        goto enomem;
    3.58 +    status = myself(session, me);
    3.59 +    if (status != PEP_STATUS_OK)
    3.60 +        goto error;
    3.61 +    
    3.62      return status;
    3.63  
    3.64  enomem:
     4.1 --- a/sync/gen_actions_skeleton.ysl2	Wed May 18 12:22:02 2016 +0200
     4.2 +++ b/sync/gen_actions_skeleton.ysl2	Wed May 18 12:54:22 2016 +0200
     4.3 @@ -34,6 +34,7 @@
     4.4      // Actions for «@name» state machine
     4.5  
     4.6      #include <assert.h>
     4.7 +    #include "keymanagement.h"
     4.8      #include "sync_fsm.h"
     4.9      #include "map_asn1.h"
    4.10      `` for "func:distinctName(//action)" if "substring(@name, 1, 4) = 'send'" | #include "../asn.1/«substring(@name, 5, 255)».h"
    4.11 @@ -132,8 +133,17 @@
    4.12              status = sequence_value(session, "DeviceGroup", &seq);
    4.13              if (status != PEP_STATUS_OK)
    4.14                  goto error;
    4.15 +            msg->header.sequence = (long) seq;
    4.16  
    4.17 -            msg->header.sequence = seq;
    4.18 +            pEp_identity *me = new_identity(NULL, NULL, NULL, NULL);
    4.19 +            if (!me)
    4.20 +                goto enomem;
    4.21 +            status = myself(session, me);
    4.22 +            if (status != PEP_STATUS_OK)
    4.23 +                goto error;
    4.24 +            
    4.25 +            // payload
    4.26 +
    4.27  
    4.28              return status;
    4.29  
     5.1 --- a/sync/gen_statemachine.ysl2	Wed May 18 12:22:02 2016 +0200
     5.2 +++ b/sync/gen_statemachine.ysl2	Wed May 18 12:54:22 2016 +0200
     5.3 @@ -17,6 +17,10 @@
     5.4          // state machine for «@name»
     5.5  
     5.6          #include "pEpEngine.h"
     5.7 +        
     5.8 +        #ifdef __cplusplus
     5.9 +        extern "C" {
    5.10 +        #endif
    5.11  
    5.12          // types
    5.13  
    5.14 @@ -59,6 +63,10 @@
    5.15  
    5.16          PEP_STATUS fsm_«@name»_inject(PEP_SESSION session, «@name»_event event);
    5.17  
    5.18 +        #ifdef __cplusplus
    5.19 +        }
    5.20 +        #endif
    5.21 +
    5.22          ||
    5.23          ||
    5.24          #include "sync_fsm.h"
     6.1 --- a/test/map_asn1_test.cc	Wed May 18 12:22:02 2016 +0200
     6.2 +++ b/test/map_asn1_test.cc	Wed May 18 12:54:22 2016 +0200
     6.3 @@ -20,12 +20,12 @@
     6.4  
     6.5      cout << "converting identity to ASN.1...\n";
     6.6  
     6.7 -    Identity_t *ident_asn1 = Identity_from_Struct(ident1);
     6.8 +    Identity_t *ident_asn1 = Identity_from_Struct(ident1, NULL);
     6.9      assert(ident_asn1);
    6.10  
    6.11      cout << "converting identity from ASN.1...\n";
    6.12  
    6.13 -    pEp_identity *ident2 = Identity_to_Struct(ident_asn1);
    6.14 +    pEp_identity *ident2 = Identity_to_Struct(ident_asn1, NULL);
    6.15      assert(ident2);
    6.16  
    6.17      assert(strcmp(ident1->address, ident2->address) == 0);
    6.18 @@ -50,12 +50,12 @@
    6.19  
    6.20      cout << "converting stringlist to keylist...\n";
    6.21  
    6.22 -    KeyList_t *kl = KeyList_from_stringlist(sl);
    6.23 +    KeyList_t *kl = KeyList_from_stringlist(sl, NULL);
    6.24      assert(kl);
    6.25  
    6.26      cout << "converting keylist to stringlist...\n";
    6.27  
    6.28 -    stringlist_t *sl2 = KeyList_to_stringlist(kl);
    6.29 +    stringlist_t *sl2 = KeyList_to_stringlist(kl, NULL);
    6.30      assert(sl2);
    6.31  
    6.32      stringlist_t *_sl2;
     7.1 --- a/test/sequence_test.cc	Wed May 18 12:22:02 2016 +0200
     7.2 +++ b/test/sequence_test.cc	Wed May 18 12:54:22 2016 +0200
     7.3 @@ -18,13 +18,13 @@
     7.4  
     7.5      // sequence test code
     7.6  
     7.7 -    int64_t value1;
     7.8 +    int32_t value1;
     7.9      PEP_STATUS status2 = sequence_value(session, "test", &value1);
    7.10      assert(status2 == PEP_STATUS_OK);
    7.11  
    7.12      cout << "test sequence: " << value1 << "\n";
    7.13  
    7.14 -    int64_t value2;
    7.15 +    int32_t value2;
    7.16      PEP_STATUS status3 = sequence_value(session, "test", &value2);
    7.17      assert(status3 == PEP_STATUS_OK);
    7.18