set own ids in sync identity lists ENGINE-596
authorKrista 'DarthMama' Bennett <krista@pep.foundation>
Fri, 15 Nov 2019 11:03:23 +0100
branchENGINE-596
changeset 41869fbd6672b600
parent 4180 1ac7c4673540
child 4187 93e419537f55
set own ids in sync identity lists
src/identity_list.c
src/identity_list.h
src/map_asn1.h
src/pEpEngine.c
src/pEpEngine.h
sync/cond_act_sync.yml2
sync/gen_message_func.ysl2
     1.1 --- a/src/identity_list.c	Thu Nov 14 23:26:51 2019 +0100
     1.2 +++ b/src/identity_list.c	Fri Nov 15 11:03:23 2019 +0100
     1.3 @@ -134,3 +134,20 @@
     1.4  
     1.5      return len;
     1.6  }
     1.7 +
     1.8 +PEP_STATUS set_all_userids_in_list(identity_list* id_list, const char* user_id) {
     1.9 +    identity_list* curr_list = id_list;
    1.10 +    
    1.11 +    while (curr_list) {
    1.12 +        if (curr_list->ident) {
    1.13 +            free(curr_list->ident->user_id);
    1.14 +            curr_list->ident->user_id = NULL;
    1.15 +            char* dup_userid = strdup(user_id);
    1.16 +            if (dup_userid == NULL)
    1.17 +                return PEP_OUT_OF_MEMORY;
    1.18 +            curr_list->ident->user_id = dup_userid;    
    1.19 +        }    
    1.20 +        curr_list = id_list->next;
    1.21 +    }
    1.22 +    return PEP_STATUS_OK;
    1.23 +}
     2.1 --- a/src/identity_list.h	Thu Nov 14 23:26:51 2019 +0100
     2.2 +++ b/src/identity_list.h	Fri Nov 15 11:03:23 2019 +0100
     2.3 @@ -83,7 +83,10 @@
     2.4  //      length of identity_list in number of elements
     2.5  
     2.6  DYNAMIC_API int identity_list_length(const identity_list *id_list);
     2.7 -    
     2.8 +
     2.9 +// Internal
    2.10 +PEP_STATUS set_all_userids_in_list(identity_list* id_list, const char* user_id);
    2.11 +
    2.12  #ifdef __cplusplus
    2.13  }
    2.14  #endif
     3.1 --- a/src/map_asn1.h	Thu Nov 14 23:26:51 2019 +0100
     3.2 +++ b/src/map_asn1.h	Fri Nov 15 11:03:23 2019 +0100
     3.3 @@ -80,4 +80,3 @@
     3.4  #ifdef __cplusplus
     3.5  }
     3.6  #endif
     3.7 -
     4.1 --- a/src/pEpEngine.c	Thu Nov 14 23:26:51 2019 +0100
     4.2 +++ b/src/pEpEngine.c	Fri Nov 15 11:03:23 2019 +0100
     4.3 @@ -5382,3 +5382,20 @@
     4.4      session->debug_color = ansi_color;
     4.5  #endif
     4.6  }
     4.7 +
     4.8 +PEP_STATUS set_all_userids_to_own(PEP_SESSION session, identity_list* id_list) {
     4.9 +    static char* ownid = NULL;
    4.10 +    PEP_STATUS status = PEP_STATUS_OK;
    4.11 +    if (!ownid) {
    4.12 +        status = get_default_own_userid(session, &ownid);
    4.13 +    }    
    4.14 +    if (status == PEP_STATUS_OK) {
    4.15 +        if (ownid) {
    4.16 +            status = set_all_userids_in_list(id_list, ownid);
    4.17 +        }
    4.18 +        else {
    4.19 +            status = PEP_UNKNOWN_ERROR;
    4.20 +        }
    4.21 +    }
    4.22 +    return status;    
    4.23 +}
     5.1 --- a/src/pEpEngine.h	Thu Nov 14 23:26:51 2019 +0100
     5.2 +++ b/src/pEpEngine.h	Fri Nov 15 11:03:23 2019 +0100
     5.3 @@ -1418,6 +1418,9 @@
     5.4                       const char *fpr, 
     5.5                       char **sign, 
     5.6                       size_t *sign_size);
     5.7 +                     
     5.8 +PEP_STATUS set_all_userids_to_own(PEP_SESSION session, 
     5.9 +                                  identity_list* id_list);
    5.10  
    5.11  #ifdef __cplusplus
    5.12  }
     6.1 --- a/sync/cond_act_sync.yml2	Thu Nov 14 23:26:51 2019 +0100
     6.2 +++ b/sync/cond_act_sync.yml2	Fri Nov 15 11:03:23 2019 +0100
     6.3 @@ -368,6 +368,11 @@
     6.4          free(user_id);
     6.5          return PEP_OUT_OF_MEMORY;
     6.6      }
     6.7 +    status = set_all_userids_to_own(session, il);
     6.8 +    if (status != PEP_STATUS_OK) {
     6.9 +        free(user_id);
    6.10 +        return status;
    6.11 +    }
    6.12      
    6.13      identity_list *oil = session->sync_state.own.identities;
    6.14  
    6.15 @@ -452,6 +457,12 @@
    6.16      if (!il)
    6.17          return PEP_OUT_OF_MEMORY;
    6.18  
    6.19 +    status = set_all_userids_to_own(session, il);
    6.20 +    if (status != PEP_STATUS_OK) {
    6.21 +        free(user_id);
    6.22 +        return status;
    6.23 +    }
    6.24 +
    6.25      for (identity_list *_il = il; _il && _il->ident ; _il = _il->next) {
    6.26          // replace partner's user_id with own user_id
    6.27          free(_il->ident->user_id);
     7.1 --- a/sync/gen_message_func.ysl2	Thu Nov 14 23:26:51 2019 +0100
     7.2 +++ b/sync/gen_message_func.ysl2	Fri Nov 15 11:03:23 2019 +0100
     7.3 @@ -318,6 +318,11 @@
     7.4                      &session->«$state».«@name», NULL);
     7.5              if (!il)
     7.6                  return PEP_OUT_OF_MEMORY;
     7.7 +
     7.8 +            PEP_STATUS own_idents_status = set_all_userids_to_own(session, il);
     7.9 +            if (own_idents_status != PEP_STATUS_OK)
    7.10 +                return own_idents_status;
    7.11 +                
    7.12              IdentityList_t *_il = IdentityList_from_identity_list(il,
    7.13                      &msg->choice.«yml:lcase(../../@name)».choice.«$message_name».«@name»);
    7.14              free_identity_list(il);
    7.15 @@ -398,6 +403,11 @@
    7.16                      &msg->choice.«yml:lcase(../../@name)».choice.«$message_name».«@name», NULL);
    7.17              if (!il)
    7.18                  return PEP_OUT_OF_MEMORY;
    7.19 +                
    7.20 +            PEP_STATUS own_idents_status = set_all_userids_to_own(session, il);
    7.21 +            if (own_idents_status != PEP_STATUS_OK)
    7.22 +                return own_idents_status;
    7.23 +                
    7.24              IdentityList_t *_il = IdentityList_from_identity_list(il,
    7.25                      &session->«yml:lcase(../../../@name)»_state.«yml:lcase(../../@name)».«@name»);
    7.26              free_identity_list(il);
    7.27 @@ -427,4 +437,3 @@
    7.28  ||
    7.29  
    7.30  }
    7.31 -