correct triggering of sync events on enable_key_reset_for_identity and key_reset on disable_... - also will now NOT generate a sync event in generate_keypair if the incoming identity's flags do not indicate the identity is grouped. sync
authorKrista 'DarthMama' Bennett <krista@pep.foundation>
Tue, 28 Jan 2020 17:11:17 +0100
branchsync
changeset 4366a3c264375e16
parent 4365 cccf17941b9d
child 4367 6901d467848c
correct triggering of sync events on enable_key_reset_for_identity and key_reset on disable_... - also will now NOT generate a sync event in generate_keypair if the incoming identity's flags do not indicate the identity is grouped.
src/keymanagement.c
src/pEpEngine.c
src/sync_api.c
     1.1 --- a/src/keymanagement.c	Tue Jan 28 13:57:06 2020 +0100
     1.2 +++ b/src/keymanagement.c	Tue Jan 28 17:11:17 2020 +0100
     1.3 @@ -1118,6 +1118,7 @@
     1.4      // this user_id + address
     1.5  //    DEBUG_LOG("myself", "debug", identity->address);
     1.6   
     1.7 +    // This will grab the actual flags from the db
     1.8      status = get_identity(session,
     1.9                            identity->address,
    1.10                            identity->user_id,
     2.1 --- a/src/pEpEngine.c	Tue Jan 28 13:57:06 2020 +0100
     2.2 +++ b/src/pEpEngine.c	Tue Jan 28 17:11:17 2020 +0100
     2.3 @@ -4729,7 +4729,7 @@
     2.4      if (identity->fpr)
     2.5          status = set_pgp_keypair(session, identity->fpr);
     2.6  
     2.7 -    if (!suppress_event)
     2.8 +    if ((!suppress_event) && (identity->flags & PEP_idf_devicegroup))
     2.9          signal_Sync_event(session, Sync_PR_keysync, KeyGen, NULL);
    2.10  
    2.11      // add to known keypair DB, as this might not end up being a default
     3.1 --- a/src/sync_api.c	Tue Jan 28 13:57:06 2020 +0100
     3.2 +++ b/src/sync_api.c	Tue Jan 28 17:11:17 2020 +0100
     3.3 @@ -264,23 +264,38 @@
     3.4      if (!(session && ident))
     3.5          return PEP_ILLEGAL_VALUE;
     3.6  
     3.7 -    // create the identity in the database if it is not yet there
     3.8 +    // create the identity in the database if it is not yet there.
     3.9 +    // This generates no events.
    3.10      PEP_STATUS status = _myself(session, ident, false, true, false);
    3.11 -    if (status)
    3.12 +    if (status != PEP_STATUS_OK)
    3.13          return status;
    3.14  
    3.15      status = unset_identity_flags(session, ident, PEP_idf_not_for_sync);
    3.16 -    if (status)
    3.17 +    if (status != PEP_STATUS_OK) // explicit. sorry, but lazy makes mistakes in C
    3.18          return status;
    3.19  
    3.20 -    bool grouped;
    3.21 -    status = deviceGrouped(session, &grouped);
    3.22 -    if (status)
    3.23 +    status = set_identity_flags(session, ident, PEP_idf_devicegroup);    
    3.24 +    if (status != PEP_STATUS_OK)
    3.25          return status;
    3.26  
    3.27 -    if (grouped)
    3.28 -        status = set_identity_flags(session, ident, PEP_idf_devicegroup);
    3.29 -    return status;
    3.30 +    // Let's make sure whatever flags are on the retval are at least correct
    3.31 +    // so as to unnecessary reduce dev freakout.
    3.32 +    ident->flags = (ident->flags | PEP_idf_devicegroup) & ~PEP_idf_not_for_sync;
    3.33 +
    3.34 +    // If no key was actually in the DB, make one now.
    3.35 +    // This will trigger a sync event. 
    3.36 +    if (EMPTYSTR(ident->fpr)) {
    3.37 +        status = _myself(session, ident, true, true, false);
    3.38 +        if (status != PEP_STATUS_OK)
    3.39 +            return status;
    3.40 +    }
    3.41 +    else {
    3.42 +        // Ok, we actually had a key. We pretend we generated one to make 
    3.43 +        // sync play nice.
    3.44 +        signal_Sync_event(session, Sync_PR_keysync, KeyGen, NULL);
    3.45 +    }        
    3.46 +
    3.47 +    return PEP_STATUS_OK;
    3.48  }
    3.49  
    3.50  DYNAMIC_API PEP_STATUS disable_identity_for_sync(PEP_SESSION session,
    3.51 @@ -300,5 +315,11 @@
    3.52          return status;
    3.53  
    3.54      status = set_identity_flags(session, ident, PEP_idf_not_for_sync);
    3.55 +    if (status)
    3.56 +        return status;
    3.57 +        
    3.58 +    ident->flags = (ident->flags | PEP_idf_not_for_sync) & ~PEP_idf_devicegroup;   
    3.59 +
    3.60 +    status = key_reset_identity(session, ident, NULL);
    3.61      return status;
    3.62  }