device group changes sync
authorVolker Birk <vb@pep-project.org>
Wed, 27 Mar 2019 17:16:44 +0100
branchsync
changeset 3406c7540a618a4c
parent 3404 8b7d693bebfe
child 3407 dabc9c3b13e6
device group changes
src/sync_api.c
src/sync_api.h
sync/cond_act_sync.yml2
sync/sync.fsm
     1.1 --- a/src/sync_api.c	Wed Mar 27 17:03:31 2019 +0100
     1.2 +++ b/src/sync_api.c	Wed Mar 27 17:16:44 2019 +0100
     1.3 @@ -135,3 +135,86 @@
     1.4      return SYNC_TIMEOUT_EVENT;
     1.5  }
     1.6  
     1.7 +DYNAMIC_API PEP_STATUS enter_device_group(
     1.8 +        PEP_SESSION session,
     1.9 +        const identity_list *identities_sharing
    1.10 +    )
    1.11 +{
    1.12 +    assert(session);
    1.13 +    if (!session)
    1.14 +        return PEP_ILLEGAL_VALUE;
    1.15 +
    1.16 +    for (const identity_list *_il = identities_sharing; _il && _il->ident;
    1.17 +            _il = _il->next) {
    1.18 +        if (!_il->ident->me || !_il->ident->user_id || !_il->ident->user_id[0]
    1.19 +                || !_il->ident->address || !_il->ident->address[0])
    1.20 +            return PEP_ILLEGAL_VALUE;
    1.21 +    }
    1.22 +
    1.23 +    identity_list *own_identities = NULL;
    1.24 +    PEP_STATUS status = own_identities_retrieve(session, &own_identities);
    1.25 +    if (status)
    1.26 +        goto the_end;
    1.27 +
    1.28 +    if (identities_sharing) {
    1.29 +        for (identity_list *_il = own_identities; _il && _il->ident;
    1.30 +                _il = _il->next) {
    1.31 +            bool found = false;
    1.32 +
    1.33 +            for (const identity_list *_is = identities_sharing;
    1.34 +                    _is && _is->ident; _is = _is->next) {
    1.35 +                // FIXME: "john@doe.com" and "mailto:john@doe.com" should be equal
    1.36 +                if (strcmp(_il->ident->address, _is->ident->address) == 0
    1.37 +                        && strcmp(_il->ident->user_id, _is->ident->user_id) == 0) {
    1.38 +                    found = true;
    1.39 +
    1.40 +                    status = set_identity_flags(session, _il->ident, PEP_idf_devicegroup);
    1.41 +                    if (status)
    1.42 +                        goto the_end;
    1.43 +
    1.44 +                    break;
    1.45 +                }
    1.46 +            }
    1.47 +            if (!found) {
    1.48 +                status = unset_identity_flags(session, _il->ident, PEP_idf_devicegroup);
    1.49 +                if (status)
    1.50 +                    goto the_end;
    1.51 +            }
    1.52 +        }
    1.53 +    }
    1.54 +    else {
    1.55 +        for (identity_list *_il = own_identities; _il && _il->ident;
    1.56 +                _il = _il->next) {
    1.57 +            status = set_identity_flags(session, _il->ident, PEP_idf_devicegroup);
    1.58 +            if (status)
    1.59 +                goto the_end;
    1.60 +        }
    1.61 +    }
    1.62 +
    1.63 +the_end:
    1.64 +    free_identity_list(own_identities);
    1.65 +    return status;
    1.66 +}
    1.67 +
    1.68 +DYNAMIC_API PEP_STATUS leave_device_group(PEP_SESSION session)
    1.69 +{
    1.70 +    assert(session);
    1.71 +    if (!session)
    1.72 +        return PEP_ILLEGAL_VALUE;
    1.73 +
    1.74 +    identity_list *il = NULL;
    1.75 +    PEP_STATUS status = own_identities_retrieve(session, &il);
    1.76 +    if (status)
    1.77 +        goto the_end;
    1.78 +
    1.79 +    for (identity_list *_il = il; _il && _il->ident ; _il = _il->next) {
    1.80 +        status = unset_identity_flags(session, _il->ident, PEP_idf_devicegroup);
    1.81 +        if (status)
    1.82 +            goto the_end;
    1.83 +    }
    1.84 +
    1.85 +the_end:
    1.86 +    free_identity_list(il);
    1.87 +    return status;
    1.88 +}
    1.89 +
     2.1 --- a/src/sync_api.h	Wed Mar 27 17:03:31 2019 +0100
     2.2 +++ b/src/sync_api.h	Wed Mar 27 17:16:44 2019 +0100
     2.3 @@ -152,7 +152,7 @@
     2.4  // is_sync_thread() - determine if this is sync thread's session
     2.5  //
     2.6  //  paramters:
     2.7 -//      session                 pEp session to test
     2.8 +//      session (in)            pEp session to test
     2.9  //
    2.10  //  return value:
    2.11  //      true if this is sync thread's session, false otherwise
    2.12 @@ -168,6 +168,33 @@
    2.13  DYNAMIC_API SYNC_EVENT new_sync_timeout_event();
    2.14  
    2.15  
    2.16 +// enter_device_group() - enter a device group
    2.17 +//
    2.18 +//  parameters:
    2.19 +//      session (in)            pEp session
    2.20 +//      identities_sharing (in) own_identities sharing data in this group
    2.21 +//
    2.22 +//  caveat:
    2.23 +//      identities_sharing may be NULL; in this case all identities are sharing
    2.24 +//      data in the group
    2.25 +//      identities_sharing may only contain own identities
    2.26 +//
    2.27 +//      this call can be repeated if sharing information changes
    2.28 +
    2.29 +DYNAMIC_API PEP_STATUS enter_device_group(
    2.30 +        PEP_SESSION session,
    2.31 +        const identity_list *identities_sharing
    2.32 +    );
    2.33 +
    2.34 +
    2.35 +// leave_device_group() - leave a device group
    2.36 +//
    2.37 +//  parameters:
    2.38 +//      session                 pEp session
    2.39 +
    2.40 +DYNAMIC_API PEP_STATUS leave_device_group(PEP_SESSION session);
    2.41 +
    2.42 +
    2.43  #ifdef __cplusplus
    2.44  }
    2.45  #endif
     3.1 --- a/sync/cond_act_sync.yml2	Wed Mar 27 17:03:31 2019 +0100
     3.2 +++ b/sync/cond_act_sync.yml2	Wed Mar 27 17:16:44 2019 +0100
     3.3 @@ -280,5 +280,7 @@
     3.4      ||
     3.5  }
     3.6  
     3.7 +action receivedKeysAreGroupKeys;
     3.8 +
     3.9  action disable;
    3.10  
     4.1 --- a/sync/sync.fsm	Wed Mar 27 17:03:31 2019 +0100
     4.2 +++ b/sync/sync.fsm	Wed Mar 27 17:16:44 2019 +0100
     4.3 @@ -134,12 +134,10 @@
     4.4              }
     4.5  
     4.6              on GroupKeysAndClose {
     4.7 -                do saveGroupKeys;
     4.8 -                if keyElectionWon {
     4.9 +                if keyElectionWon
    4.10                      do ownKeysAreGroupKeys;
    4.11 -                    go Grouped;
    4.12 -                }
    4.13 -                // do receivedKeysAreGroupKeys; -- implicit
    4.14 +                else
    4.15 +                    do receivedKeysAreGroupKeys;
    4.16                  go Grouped;
    4.17              }
    4.18          }