src/keymanagement.c
branchENGINE-293
changeset 2308 b7ef1c9005ae
parent 2305 f617e0acae94
child 2311 688b925c3e73
     1.1 --- a/src/keymanagement.c	Thu Dec 07 09:31:47 2017 +0100
     1.2 +++ b/src/keymanagement.c	Sat Dec 09 13:04:40 2017 +0100
     1.3 @@ -437,6 +437,7 @@
     1.4      char* own_id = NULL;
     1.5      status = get_own_userid(session, &own_id);
     1.6  
     1.7 +
     1.8      assert(EMPTYSTR(identity->user_id) ||
     1.9             (own_id && strcmp(identity->user_id, own_id) == 0) ||
    1.10             !own_id);
    1.11 @@ -447,6 +448,11 @@
    1.12               !own_id)))
    1.13          return ADD_TO_LOG(PEP_ILLEGAL_VALUE);
    1.14  
    1.15 +    if (!own_id) {
    1.16 +        // check to see if we have ANY identity for this address... could have
    1.17 +        // happened due to race condition
    1.18 +    }
    1.19 +    
    1.20      identity->comm_type = PEP_ct_pEp;
    1.21      identity->me = true;
    1.22      if(ignore_flags)
    1.23 @@ -635,6 +641,45 @@
    1.24      return ADD_TO_LOG(PEP_STATUS_OK);
    1.25  }
    1.26  
    1.27 +DYNAMIC_API PEP_STATUS initialise_own_identities(PEP_SESSION session,
    1.28 +                                                 identity_list* my_idents) {
    1.29 +    PEP_STATUS status = PEP_STATUS_OK;
    1.30 +    if (!session)
    1.31 +        return PEP_ILLEGAL_VALUE;
    1.32 +        
    1.33 +    char* stored_own_userid = NULL;
    1.34 +    get_own_userid(session, &stored_own_userid);
    1.35 +    
    1.36 +    identity_list* ident_curr = my_idents;
    1.37 +    while (ident_curr) {
    1.38 +        pEp_identity* ident = ident_curr->ident;
    1.39 +        if (!ident)
    1.40 +            return PEP_ILLEGAL_VALUE;
    1.41 +            
    1.42 +        if (stored_own_userid) {
    1.43 +            if (!ident->user_id) 
    1.44 +                ident->user_id = strdup(stored_own_userid);
    1.45 +            else if (strcmp(stored_own_userid, ident->user_id) != 0)
    1.46 +                return PEP_ILLEGAL_VALUE;
    1.47 +        }
    1.48 +        else if (!ident->user_id) {
    1.49 +            stored_own_userid = PEP_OWN_USERID;
    1.50 +            ident->user_id = strdup(PEP_OWN_USERID);
    1.51 +        }
    1.52 +        
    1.53 +        ident->me = true; // Just in case.
    1.54 +        
    1.55 +        // Ok, do it...
    1.56 +        status = set_identity(session, ident);
    1.57 +        if (status != PEP_STATUS_OK)
    1.58 +            return status;
    1.59 +        
    1.60 +        ident_curr = ident_curr->next;
    1.61 +    }
    1.62 +    
    1.63 +    return status;
    1.64 +}
    1.65 +
    1.66  DYNAMIC_API PEP_STATUS myself(PEP_SESSION session, pEp_identity * identity)
    1.67  {
    1.68      return ADD_TO_LOG(_myself(session, identity, true, false));