src/sync_send_actions.c
branchkeysync
changeset 951 dec407deb10e
parent 939 ed7dfdae3031
child 955 060272dfaaeb
     1.1 --- a/src/sync_send_actions.c	Sun Jul 31 09:04:42 2016 +0200
     1.2 +++ b/src/sync_send_actions.c	Sun Jul 31 19:38:23 2016 +0200
     1.3 @@ -41,8 +41,10 @@
     1.4          return PEP_ILLEGAL_VALUE;
     1.5  
     1.6      assert(session->messageToSend);
     1.7 -    if (!session->messageToSend)
     1.8 -        return PEP_SEND_FUNCTION_NOT_REGISTERED;
     1.9 +    if (!session->messageToSend) {
    1.10 +        status = PEP_SEND_FUNCTION_NOT_REGISTERED;
    1.11 +        goto error;
    1.12 +    }
    1.13  
    1.14      msg = (Beacon_t *) calloc(1, sizeof(Beacon_t));
    1.15      assert(msg);
    1.16 @@ -55,7 +57,18 @@
    1.17          goto error;
    1.18      msg->header.sequence = (long) seq;
    1.19  
    1.20 -    msg->state = (long) state;
    1.21 +    bool devicegroup = storedGroupKeys(session);
    1.22 +    if (devicegroup) { // default is FALSE
    1.23 +        BOOLEAN_t *dg = malloc(sizeof(BOOLEAN_t));
    1.24 +        assert(dg);
    1.25 +        if (!dg)
    1.26 +            goto enomem;
    1.27 +
    1.28 +        *dg = 1;
    1.29 +        msg->header.devicegroup = dg;
    1.30 +    }
    1.31 +
    1.32 +    msg->header.state = (long) state;
    1.33  
    1.34      me = new_identity(NULL, NULL, NULL, NULL);
    1.35      if (!me)
    1.36 @@ -63,7 +76,7 @@
    1.37      status = myself(session, me);
    1.38      if (status != PEP_STATUS_OK)
    1.39          goto error;
    1.40 -    if (Identity_from_Struct(me, &msg->me) == NULL)
    1.41 +    if (Identity_from_Struct(me, &msg->header.me) == NULL)
    1.42          goto enomem;
    1.43  
    1.44      if (asn_check_constraints(&asn_DEF_Beacon, msg, NULL, NULL)) {
    1.45 @@ -90,7 +103,7 @@
    1.46  
    1.47      free_message(_message);
    1.48      ASN_STRUCT_FREE(asn_DEF_Beacon, msg);
    1.49 -
    1.50 +    free_identity(partner);
    1.51      return status;
    1.52  
    1.53  enomem:
    1.54 @@ -133,8 +146,10 @@
    1.55          return PEP_ILLEGAL_VALUE;
    1.56  
    1.57      assert(session->messageToSend);
    1.58 -    if (!session->messageToSend)
    1.59 -        return PEP_SEND_FUNCTION_NOT_REGISTERED;
    1.60 +    if (!session->messageToSend) {
    1.61 +        status = PEP_SEND_FUNCTION_NOT_REGISTERED;
    1.62 +        goto error;
    1.63 +    }
    1.64  
    1.65      msg = (HandshakeRequest_t *) calloc(1, sizeof(HandshakeRequest_t));
    1.66      assert(msg);
    1.67 @@ -147,7 +162,18 @@
    1.68          goto error;
    1.69      msg->header.sequence = (long) seq;
    1.70  
    1.71 -    msg->state = (long) state;
    1.72 +    bool devicegroup = storedGroupKeys(session);
    1.73 +    if (devicegroup) { // default is FALSE
    1.74 +        BOOLEAN_t *dg = malloc(sizeof(BOOLEAN_t));
    1.75 +        assert(dg);
    1.76 +        if (!dg)
    1.77 +            goto enomem;
    1.78 +
    1.79 +        *dg = 1;
    1.80 +        msg->header.devicegroup = dg;
    1.81 +    }
    1.82 +
    1.83 +    msg->header.state = (long) state;
    1.84  
    1.85      me = new_identity(NULL, NULL, NULL, NULL);
    1.86      if (!me)
    1.87 @@ -155,10 +181,7 @@
    1.88      status = myself(session, me);
    1.89      if (status != PEP_STATUS_OK)
    1.90          goto error;
    1.91 -    if (Identity_from_Struct(me, &msg->me) == NULL)
    1.92 -        goto enomem;
    1.93 -
    1.94 -    if (Identity_from_Struct(partner, &msg->partner) == NULL)
    1.95 +    if (Identity_from_Struct(me, &msg->header.me) == NULL)
    1.96          goto enomem;
    1.97  
    1.98      if (asn_check_constraints(&asn_DEF_HandshakeRequest, msg, NULL, NULL)) {
    1.99 @@ -185,7 +208,7 @@
   1.100  
   1.101      free_message(_message);
   1.102      ASN_STRUCT_FREE(asn_DEF_HandshakeRequest, msg);
   1.103 -
   1.104 +    free_identity(partner);
   1.105      return status;
   1.106  
   1.107  enomem:
   1.108 @@ -228,8 +251,10 @@
   1.109          return PEP_ILLEGAL_VALUE;
   1.110  
   1.111      assert(session->messageToSend);
   1.112 -    if (!session->messageToSend)
   1.113 -        return PEP_SEND_FUNCTION_NOT_REGISTERED;
   1.114 +    if (!session->messageToSend) {
   1.115 +        status = PEP_SEND_FUNCTION_NOT_REGISTERED;
   1.116 +        goto error;
   1.117 +    }
   1.118  
   1.119      msg = (GroupKeys_t *) calloc(1, sizeof(GroupKeys_t));
   1.120      assert(msg);
   1.121 @@ -242,7 +267,18 @@
   1.122          goto error;
   1.123      msg->header.sequence = (long) seq;
   1.124  
   1.125 -    msg->state = (long) state;
   1.126 +    bool devicegroup = storedGroupKeys(session);
   1.127 +    if (devicegroup) { // default is FALSE
   1.128 +        BOOLEAN_t *dg = malloc(sizeof(BOOLEAN_t));
   1.129 +        assert(dg);
   1.130 +        if (!dg)
   1.131 +            goto enomem;
   1.132 +
   1.133 +        *dg = 1;
   1.134 +        msg->header.devicegroup = dg;
   1.135 +    }
   1.136 +
   1.137 +    msg->header.state = (long) state;
   1.138  
   1.139      me = new_identity(NULL, NULL, NULL, NULL);
   1.140      if (!me)
   1.141 @@ -250,7 +286,7 @@
   1.142      status = myself(session, me);
   1.143      if (status != PEP_STATUS_OK)
   1.144          goto error;
   1.145 -    if (Identity_from_Struct(me, &msg->me) == NULL)
   1.146 +    if (Identity_from_Struct(me, &msg->header.me) == NULL)
   1.147          goto enomem;
   1.148  
   1.149      if (asn_check_constraints(&asn_DEF_GroupKeys, msg, NULL, NULL)) {
   1.150 @@ -277,7 +313,7 @@
   1.151  
   1.152      free_message(_message);
   1.153      ASN_STRUCT_FREE(asn_DEF_GroupKeys, msg);
   1.154 -
   1.155 +    free_identity(partner);
   1.156      return status;
   1.157  
   1.158  enomem: