...
1 // This file is under GNU General Public License 3.0
4 #include "pEp_internal.h"
7 Identity_t *Identity_from_Struct(
8 const pEp_identity *ident,
12 bool allocated = !result;
19 result = (Identity_t *) calloc(1, sizeof(Identity_t));
26 int r = OCTET_STRING_fromBuf(&result->address, ident->address, -1);
32 if (OCTET_STRING_fromString(&result->fpr, ident->fpr))
37 int r = OCTET_STRING_fromBuf(&result->user_id, ident->user_id, -1);
42 if (ident->username) {
43 int r = OCTET_STRING_fromBuf(&result->username, ident->username, -1);
48 if (ident->comm_type != PEP_ct_unknown) {
49 result->comm_type = ident->comm_type;
53 int r = OCTET_STRING_fromBuf(&result->lang, ident->lang, 2);
59 int r = OCTET_STRING_fromBuf(&result->lang, "en", 2);
69 ASN_STRUCT_FREE(asn_DEF_Identity, result);
74 pEp_identity *Identity_to_Struct(Identity_t *ident, pEp_identity *result)
76 bool allocated = !result;
83 result = new_identity(NULL, NULL, NULL, NULL);
87 result->address = strndup((char *) ident->address.buf,
89 assert(result->address);
93 result->fpr = strndup((char *) ident->fpr.buf, ident->fpr.size);
98 result->user_id = strndup((char *) ident->user_id.buf,
100 assert(result->user_id);
101 if (!result->user_id)
104 result->username = strndup((char *) ident->username.buf,
105 ident->username.size);
106 assert(result->username);
107 if (!result->username)
110 result->comm_type = (PEP_comm_type) ident->comm_type;
112 if (ident->lang.size == 2) {
113 result->lang[0] = ident->lang.buf[0];
114 result->lang[1] = ident->lang.buf[1];
122 free_identity(result);
126 IdentityList_t *IdentityList_from_identity_list(
127 const identity_list *list,
128 IdentityList_t *result
131 bool allocated = !result;
138 result = (IdentityList_t *) calloc(1, sizeof(IdentityList_t));
143 for (const identity_list *l = list; l && l->ident; l=l->next) {
144 Identity_t *ident = Identity_from_Struct(l->ident, NULL);
145 if (ASN_SEQUENCE_ADD(&result->list, ident)) {
146 ASN_STRUCT_FREE(asn_DEF_Identity, ident);
155 ASN_STRUCT_FREE(asn_DEF_IdentityList, result);
159 identity_list *IdentityList_to_identity_list(IdentityList_t *list, identity_list *result)
161 bool allocated = !result;
168 result = new_identity_list(NULL);
172 identity_list *r = result;
173 for (int i=0; i<list->list.count; i++) {
174 pEp_identity *ident = Identity_to_Struct(list->list.array[i], NULL);
175 r = identity_list_add(r, ident);
184 free_identity_list(result);