Removed get_best_user, leading to unexpected behaviour when user_id is made null again, for example when corresponding app contact is deleted
parent
c2a2542fd4
commit
1f5fd47a86
|
@ -76,26 +76,14 @@ DYNAMIC_API PEP_STATUS update_identity(
|
|||
{
|
||||
free(identity->user_id);
|
||||
|
||||
status = get_best_user(session,
|
||||
identity->address,
|
||||
&identity->user_id);
|
||||
identity->user_id = calloc(1, identity->address_size + 6);
|
||||
if (!identity->user_id)
|
||||
{
|
||||
return PEP_OUT_OF_MEMORY;
|
||||
}
|
||||
snprintf(identity->user_id, identity->address_size + 5,
|
||||
"TOFU_%s", identity->address);
|
||||
|
||||
// Default user_id, aka Virtual user_id
|
||||
if (status == PEP_CANNOT_FIND_IDENTITY)
|
||||
{
|
||||
identity->user_id = calloc(1, identity->address_size + 5);
|
||||
if (!identity->user_id)
|
||||
{
|
||||
return PEP_OUT_OF_MEMORY;
|
||||
}
|
||||
snprintf(identity->user_id, identity->address_size + 5,
|
||||
"TOFU_%s", identity->address);
|
||||
}
|
||||
else if (status != PEP_STATUS_OK)
|
||||
{
|
||||
return status;
|
||||
}
|
||||
|
||||
if(identity->user_id)
|
||||
{
|
||||
identity->user_id_size = strlen(identity->user_id);
|
||||
|
|
|
@ -13,7 +13,6 @@ DYNAMIC_API PEP_STATUS init(PEP_SESSION *session)
|
|||
static const char *sql_log;
|
||||
static const char *sql_trustword;
|
||||
static const char *sql_get_identity;
|
||||
static const char *sql_get_best_user;
|
||||
static const char *sql_set_person;
|
||||
static const char *sql_set_pgp_keypair;
|
||||
static const char *sql_set_identity;
|
||||
|
@ -196,14 +195,6 @@ DYNAMIC_API PEP_STATUS init(PEP_SESSION *session)
|
|||
" and pgp_keypair_fpr = identity.main_key_id"
|
||||
" where address = ?1 and identity.user_id = ?2;";
|
||||
|
||||
sql_get_best_user = "select identity.user_id"
|
||||
" from identity"
|
||||
" join trust on trust.user_id = identity.user_id"
|
||||
" and pgp_keypair_fpr = identity.main_key_id"
|
||||
" where address = ?1"
|
||||
" order by comm_type DESC, identity.rowid DESC"
|
||||
" limit 1;";
|
||||
|
||||
sql_trustword = "select id, word from wordlist where lang = lower(?1) "
|
||||
"and id = ?2 ;";
|
||||
|
||||
|
@ -259,10 +250,6 @@ DYNAMIC_API PEP_STATUS init(PEP_SESSION *session)
|
|||
(int)strlen(sql_get_identity), &_session->get_identity, NULL);
|
||||
assert(int_result == SQLITE_OK);
|
||||
|
||||
int_result = sqlite3_prepare_v2(_session->db, sql_get_best_user,
|
||||
(int)strlen(sql_get_best_user), &_session->get_best_user, NULL);
|
||||
assert(int_result == SQLITE_OK);
|
||||
|
||||
int_result = sqlite3_prepare_v2(_session->db, sql_set_person,
|
||||
(int)strlen(sql_set_person), &_session->set_person, NULL);
|
||||
assert(int_result == SQLITE_OK);
|
||||
|
@ -374,8 +361,6 @@ DYNAMIC_API void release(PEP_SESSION session)
|
|||
sqlite3_finalize(session->trustword);
|
||||
if (session->get_identity)
|
||||
sqlite3_finalize(session->get_identity);
|
||||
if (session->get_best_user)
|
||||
sqlite3_finalize(session->get_best_user);
|
||||
if (session->set_person)
|
||||
sqlite3_finalize(session->set_person);
|
||||
if (session->set_pgp_keypair)
|
||||
|
@ -743,41 +728,6 @@ DYNAMIC_API PEP_STATUS get_identity(
|
|||
return status;
|
||||
}
|
||||
|
||||
DYNAMIC_API PEP_STATUS get_best_user(
|
||||
PEP_SESSION session,
|
||||
const char *address,
|
||||
char **user_id
|
||||
)
|
||||
{
|
||||
PEP_STATUS status = PEP_STATUS_OK;
|
||||
int result;
|
||||
|
||||
assert(session);
|
||||
assert(address);
|
||||
assert(user_id);
|
||||
|
||||
*user_id = NULL;
|
||||
|
||||
if (!(session && address && user_id))
|
||||
return PEP_ILLEGAL_VALUE;
|
||||
|
||||
sqlite3_reset(session->get_best_user);
|
||||
sqlite3_bind_text(session->get_best_user, 1, address, -1, SQLITE_STATIC);
|
||||
|
||||
result = sqlite3_step(session->get_best_user);
|
||||
switch (result) {
|
||||
case SQLITE_ROW: {
|
||||
*user_id = strdup((const char *)sqlite3_column_text(session->get_best_user, 0));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
status = PEP_CANNOT_FIND_IDENTITY;
|
||||
}
|
||||
|
||||
sqlite3_reset(session->get_best_user);
|
||||
return status;
|
||||
}
|
||||
|
||||
DYNAMIC_API PEP_STATUS set_identity(
|
||||
PEP_SESSION session, const pEp_identity *identity
|
||||
)
|
||||
|
|
|
@ -432,7 +432,8 @@ DYNAMIC_API void free_identity(pEp_identity *identity);
|
|||
// parameters:
|
||||
// session (in) session handle
|
||||
// address (in) C string with communication address, UTF-8 encoded
|
||||
// user_id (in) ???
|
||||
// user_id (in) unique C string to identify person that identity
|
||||
// is refering to
|
||||
// identity (out) pointer to pEp_identity structure with results or
|
||||
// NULL if failure
|
||||
//
|
||||
|
@ -450,27 +451,6 @@ DYNAMIC_API PEP_STATUS get_identity(
|
|||
pEp_identity **identity
|
||||
);
|
||||
|
||||
// get_best_user() - get best user_id candidate for a given address
|
||||
//
|
||||
// parameters:
|
||||
// session (in) session handle
|
||||
// address (in) C string with communication address, UTF-8 encoded
|
||||
// user_id (out) pointer to user_id string
|
||||
//
|
||||
// caveat:
|
||||
// the address string is being copied; the original string remains in the
|
||||
// ownership of the caller
|
||||
// the resulting user_id string goes to the ownership of the
|
||||
// caller and has to be freed with free() when not in use any
|
||||
// more
|
||||
|
||||
DYNAMIC_API PEP_STATUS get_best_user(
|
||||
PEP_SESSION session,
|
||||
const char *address,
|
||||
char **user_id
|
||||
);
|
||||
|
||||
|
||||
// set_identity() - set identity information
|
||||
//
|
||||
// parameters:
|
||||
|
|
|
@ -88,7 +88,6 @@ typedef struct _pEpSession {
|
|||
sqlite3_stmt *log;
|
||||
sqlite3_stmt *trustword;
|
||||
sqlite3_stmt *get_identity;
|
||||
sqlite3_stmt *get_best_user;
|
||||
sqlite3_stmt *set_person;
|
||||
sqlite3_stmt *set_pgp_keypair;
|
||||
sqlite3_stmt *set_identity;
|
||||
|
|
Loading…
Reference in New Issue