bugfix: when identity is not stored yet, update_identity failes

doc_update_sequoia
vb 9 years ago
parent c542e631b9
commit 5abda13db7

@ -30,7 +30,7 @@ DYNAMIC_API PEP_STATUS update_identity(
assert(session);
assert(identity);
assert(identity->address);
assert(!EMPTY(identity->address));
status = get_identity(session, identity->address, &stored_identity);
assert(status != PEP_OUT_OF_MEMORY);
@ -78,24 +78,6 @@ DYNAMIC_API PEP_STATUS update_identity(
identity->comm_type = PEP_ct_unknown;
}
if (EMPTY(identity->username)) {
free(identity->username);
identity->username = strdup(stored_identity->username);
assert(identity->username);
if (identity->username == NULL)
return PEP_OUT_OF_MEMORY;
identity->username_size = stored_identity->username_size;
}
if (EMPTY(identity->user_id)) {
free(identity->user_id);
identity->user_id = strdup(stored_identity->user_id);
assert(identity->user_id);
if (identity->user_id == NULL)
return PEP_OUT_OF_MEMORY;
identity->user_id_size = stored_identity->user_id_size;
}
if (identity->lang[0] == 0) {
identity->lang[0] = stored_identity->lang[0];
identity->lang[1] = stored_identity->lang[1];
@ -103,12 +85,80 @@ DYNAMIC_API PEP_STATUS update_identity(
}
}
else /* stored_identity == NULL */ {
identity->comm_type = PEP_ct_unknown;
if (!EMPTY(identity->fpr)) {
PEP_comm_type _comm_type_key;
status = get_key_rating(session, identity->fpr, &_comm_type_key);
assert(status != PEP_OUT_OF_MEMORY);
if (status == PEP_OUT_OF_MEMORY)
return PEP_OUT_OF_MEMORY;
identity->comm_type = _comm_type_key;
}
else /* EMPTY(identity->fpr) */ {
PEP_STATUS status;
stringlist_t *keylist;
char *_fpr = NULL;
identity->comm_type = PEP_ct_unknown;
status = find_keys(session, identity->address, &keylist);
assert(status != PEP_OUT_OF_MEMORY);
if (status == PEP_OUT_OF_MEMORY)
return PEP_OUT_OF_MEMORY;
stringlist_t *_keylist;
for (_keylist = keylist; _keylist && _keylist->value; _keylist = _keylist->next) {
PEP_comm_type _comm_type_key;
status = get_key_rating(session, _keylist->value, &_comm_type_key);
assert(status != PEP_OUT_OF_MEMORY);
if (status == PEP_OUT_OF_MEMORY) {
free_stringlist(keylist);
return PEP_OUT_OF_MEMORY;
}
if (identity->comm_type == PEP_ct_unknown) {
if (_comm_type_key != PEP_ct_compromized && _comm_type_key != PEP_ct_unknown) {
identity->comm_type = _comm_type_key;
_fpr = _keylist->value;
}
}
else {
if (_comm_type_key != PEP_ct_compromized && _comm_type_key != PEP_ct_unknown) {
if (_comm_type_key > identity->comm_type) {
identity->comm_type = _comm_type_key;
_fpr = _keylist->value;
}
}
}
}
if (_fpr) {
free(identity->fpr);
identity->fpr = strdup(_fpr);
if (identity->fpr == NULL) {
free_stringlist(keylist);
return PEP_OUT_OF_MEMORY;
}
identity->fpr_size = strlen(identity->fpr);
}
free_stringlist(keylist);
}
}
status = PEP_STATUS_OK;
if (identity->comm_type != PEP_ct_unknown) {
if (identity->comm_type != PEP_ct_unknown && !EMPTY(identity->user_id)) {
if (EMPTY(identity->username)) {
free(identity->username);
identity->username = strdup(stored_identity->username);
assert(identity->username);
if (identity->username == NULL)
return PEP_OUT_OF_MEMORY;
identity->username_size = stored_identity->username_size;
}
status = set_identity(session, identity);
assert(status == PEP_STATUS_OK);
}

@ -13,7 +13,7 @@ extern "C" {
// identity->comm_type, the caller must insert the identity into the
// asynchronous management implementation, so retrieve_next_identity()
// will return this identity later
// at least identity->address must be a valid UTF-8 string as input
// at least identity->address must be a non-empty UTF-8 string as input
DYNAMIC_API PEP_STATUS update_identity(
PEP_SESSION session, pEp_identity * identity

Loading…
Cancel
Save