1 #include "pEp_internal.h"
7 #include "identity_list.h"
9 DYNAMIC_API identity_list *new_identity_list(pEp_identity *ident)
11 identity_list *id_list = calloc(1, sizeof(identity_list));
16 id_list->ident = ident;
21 DYNAMIC_API identity_list *identity_list_dup(const identity_list *src)
27 pEp_identity *_ident = identity_dup(src->ident);
31 identity_list *id_list = new_identity_list(_ident);
32 if (id_list == NULL) {
33 free_identity(_ident);
37 identity_list* src_curr = src->next;
38 identity_list** dst_curr_ptr = &id_list->next;
41 _ident = identity_dup(src_curr->ident);
43 free_identity_list(id_list);
47 *dst_curr_ptr = new_identity_list(_ident);
48 if (*dst_curr_ptr == NULL) {
49 free_identity(_ident);
50 free_identity_list(id_list);
54 src_curr = src_curr->next;
55 dst_curr_ptr = &((*dst_curr_ptr)->next);
62 DYNAMIC_API void free_identity_list(identity_list *id_list)
71 free_identity(curr->ident);
77 DYNAMIC_API identity_list *identity_list_add(identity_list *id_list, pEp_identity *ident)
84 return new_identity_list(ident);
87 if (id_list->ident == NULL) {
89 return NULL; // invalid list
91 id_list->ident = ident;
93 if (id_list->ident == NULL)
99 identity_list* list_curr = id_list;
100 while (list_curr->next)
101 list_curr = list_curr->next;
103 list_curr->next = new_identity_list(ident);
105 return list_curr->next;
108 DYNAMIC_API int identity_list_length(const identity_list *id_list)
112 for (; id_list && id_list->ident; id_list = id_list->next)