src/sync_impl.c
branchAllGroupDevicesShowHandshake
changeset 1605 54bb3990a70f
parent 1603 f954f77387f1
child 1606 c3f8396acee4
     1.1 --- a/src/sync_impl.c	Mon Feb 27 15:28:20 2017 +0100
     1.2 +++ b/src/sync_impl.c	Wed Mar 01 15:08:55 2017 +0100
     1.3 @@ -31,6 +31,25 @@
     1.4      } u;
     1.5  };
     1.6  
     1.7 +static bool _is_own_uuid( PEP_SESSION session, UTF8String_t *uuid)
     1.8 +{
     1.9 +    return strncmp(session->sync_session->sync_uuid,
    1.10 +                   (const char*)uuid->buf, uuid->size) != 0;
    1.11 +}
    1.12 +
    1.13 +static bool _is_own_group_uuid( PEP_SESSION session, UTF8String_t *uuid)
    1.14 +{
    1.15 +    PEP_STATUS status;
    1.16 +    char *devgrp = NULL;
    1.17 +
    1.18 +    status = get_device_group(session, &devgrp);
    1.19 +
    1.20 +    bool res = (status == PEP_STATUS_OK && devgrp && devgrp[0] &&
    1.21 +        strncmp(devgrp,(const char*)uuid->buf, uuid->size) == 0);
    1.22 +    free(devgrp);
    1.23 +    return res;
    1.24 +}
    1.25 +
    1.26  PEP_STATUS receive_sync_msg(
    1.27          PEP_SESSION session,
    1.28          sync_msg_t *sync_msg,
    1.29 @@ -54,6 +73,13 @@
    1.30              goto error;
    1.31          }
    1.32  
    1.33 +        partner = Identity_to_Struct(&msg->header.me, NULL);
    1.34 +        if (!partner){
    1.35 +            status = PEP_OUT_OF_MEMORY;
    1.36 +            ASN_STRUCT_FREE(asn_DEF_DeviceGroup_Protocol, msg);
    1.37 +            goto error;
    1.38 +        }
    1.39 +
    1.40          msgIsFromGroup = msg->header.devicegroup;
    1.41  
    1.42          switch (msg->payload.present) {
    1.43 @@ -63,6 +89,9 @@
    1.44  
    1.45              case DeviceGroup_Protocol__payload_PR_handshakeRequest:
    1.46                  // re-check uuid in case sync_uuid changed while in the queue
    1.47 +
    1.48 +// TODO check matching group-ID as well
    1.49 +
    1.50                  if (strncmp(session->sync_session->sync_uuid,
    1.51                              (const char *)msg->payload.choice.handshakeRequest.partner_id->buf,
    1.52                              msg->payload.choice.handshakeRequest.partner_id->size) != 0){
    1.53 @@ -74,16 +103,19 @@
    1.54                      char *devgrp = NULL;
    1.55                      status = get_device_group(session, &devgrp);
    1.56  
    1.57 -                    // if handshake request comes from same group ignore, ignore it
    1.58 +                    // if handshake request comes from same group, ignore it
    1.59                      if (status == PEP_STATUS_OK && devgrp && devgrp[0] &&
    1.60                          strncmp(devgrp,
    1.61                                  (const char *)msg->payload.choice.handshakeRequest.group_id->buf,
    1.62 -                                msg->payload.choice.handshakeRequest.group_id->size) != 0){
    1.63 +                                msg->payload.choice.handshakeRequest.group_id->size) == 0){
    1.64                          status = PEP_SYNC_ILLEGAL_MESSAGE;
    1.65                          goto error;
    1.66                      }
    1.67                      free(devgrp);
    1.68                      // if it comes from another group, then this is groupmerge
    1.69 +                    
    1.70 +// TODO insert handshake request's group id into partner's id
    1.71 +
    1.72                  }
    1.73  
    1.74                  event = HandshakeRequest;
    1.75 @@ -159,12 +191,6 @@
    1.76                  goto error;
    1.77          }
    1.78  
    1.79 -        partner = Identity_to_Struct(&msg->header.me, NULL);
    1.80 -        if (!partner){
    1.81 -            status = PEP_OUT_OF_MEMORY;
    1.82 -            ASN_STRUCT_FREE(asn_DEF_DeviceGroup_Protocol, msg);
    1.83 -            goto error;
    1.84 -        }
    1.85      }
    1.86      else{
    1.87          partner = sync_msg->u.event.partner;
    1.88 @@ -437,6 +463,9 @@
    1.89                          // HandshakeRequest needs encryption
    1.90                          case DeviceGroup_Protocol__payload_PR_handshakeRequest:
    1.91                              if (rating < PEP_rating_reliable ||
    1.92 +
    1.93 +// TODO check matching group-ID as well
    1.94 +
    1.95                                  strncmp(session->sync_session->sync_uuid,
    1.96                                          (const char *)msg->payload.choice.handshakeRequest.partner_id->buf,
    1.97                                          msg->payload.choice.handshakeRequest.partner_id->size) != 0){