...
1 // This file is under GNU General Public License 3.0
4 #include "pEp_internal.h"
10 #include "identity_list.h"
12 DYNAMIC_API identity_list *new_identity_list(pEp_identity *ident)
14 identity_list *id_list = calloc(1, sizeof(identity_list));
19 id_list->ident = ident;
24 DYNAMIC_API identity_list *identity_list_dup(const identity_list *src)
30 if (src->ident == NULL)
31 return new_identity_list(NULL);
33 pEp_identity *_ident = identity_dup(src->ident);
37 identity_list *id_list = new_identity_list(_ident);
38 if (id_list == NULL) {
39 free_identity(_ident);
43 identity_list* src_curr = src->next;
44 identity_list** dst_curr_ptr = &id_list->next;
47 _ident = identity_dup(src_curr->ident);
49 free_identity_list(id_list);
53 *dst_curr_ptr = new_identity_list(_ident);
54 if (*dst_curr_ptr == NULL) {
55 free_identity(_ident);
56 free_identity_list(id_list);
60 src_curr = src_curr->next;
61 dst_curr_ptr = &((*dst_curr_ptr)->next);
68 DYNAMIC_API void free_identity_list(identity_list *id_list)
70 identity_list *curr = id_list;
73 identity_list *next = curr->next;
74 free_identity(curr->ident);
80 DYNAMIC_API identity_list *identity_list_add(identity_list *id_list, pEp_identity *ident)
87 return new_identity_list(ident);
90 if (id_list->ident == NULL) {
92 return NULL; // invalid list
94 id_list->ident = ident;
96 if (id_list->ident == NULL)
102 identity_list* list_curr = id_list;
103 while (list_curr->next)
104 list_curr = list_curr->next;
106 list_curr->next = new_identity_list(ident);
108 return list_curr->next;
111 DYNAMIC_API int identity_list_length(const identity_list *id_list)
115 for (; id_list && id_list->ident; id_list = id_list->next)