Browse Source

ENGINE-532 (ENGINE-531): Removed device_group from DDL

pEpMIME_windows archive/ENGINE-531
parent
commit
6854550467
3 changed files with 179 additions and 152 deletions
  1. +145
    -118
      src/pEpEngine.c
  2. +32
    -32
      src/pEpEngine.h
  3. +2
    -2
      src/pEp_internal.h

+ 145
- 118
src/pEpEngine.c View File

@ -163,9 +163,8 @@ static const char *sql_remove_fpr_as_default =
// Set person, but if already exist, only update.
// if main_key_id already set, don't touch.
static const char *sql_set_person =
"insert into person (id, username, lang, main_key_id, device_group)"
" values (?1, ?2, ?3, ?4, "
" (select device_group from person where id = ?1)) ;";
"insert into person (id, username, lang, main_key_id)"
" values (?1, ?2, ?3, ?4) ;";
static const char *sql_update_person =
"update person "
@ -174,9 +173,7 @@ static const char *sql_update_person =
" main_key_id = "
" (select coalesce( "
" (select main_key_id from person where id = ?1), "
" upper(replace(?4,' ','')))),"
" device_group = "
" (select device_group from person where id = ?1)"
" upper(replace(?4,' ',''))))"
" where id = ?1 ;";
// Will cascade.
@ -195,10 +192,6 @@ static const char* sql_exists_person =
"select count(*) from person "
" where id = ?1 ;";
static const char *sql_set_device_group =
"update person set device_group = ?1 "
" where id = ?2;";
// This will cascade to identity and trust
static const char* sql_replace_userid =
"update person set id = ?1 "
@ -230,10 +223,6 @@ static const char *sql_refresh_userid_default_key =
" limit 1) "
"where id = ?1 ; ";
static const char *sql_get_device_group =
"select device_group from person "
"where id = ?1;";
static const char *sql_set_pgp_keypair =
"insert or ignore into pgp_keypair (fpr) "
"values (upper(replace(?1,' ',''))) ;";
@ -737,7 +726,7 @@ DYNAMIC_API PEP_STATUS init(
sqlite3_busy_timeout(_session->system_db, 1000);
// increment this when patching DDL
#define _DDL_USER_VERSION "9"
#define _DDL_USER_VERSION "10"
if (in_first) {
@ -784,7 +773,7 @@ DYNAMIC_API PEP_STATUS init(
" on delete set null,\n"
" lang text,\n"
" comment text,\n"
" device_group text,\n"
// " device_group text,\n"
" is_pEp_user integer default 0\n"
");\n"
"create table if not exists identity (\n"
@ -904,7 +893,10 @@ DYNAMIC_API PEP_STATUS init(
if (version == 1) {
bool version_changed = true;
if (db_contains_table(_session, "social_graph") > 0) {
version = 9;
if (!table_contains_column(_session, "person", "device_group"))
version = 10;
else
version = 9;
}
else if (table_contains_column(_session, "identity", "timestamp") > 0) {
version = 8;
@ -967,12 +959,13 @@ DYNAMIC_API PEP_STATUS init(
// }
if (version < 2) {
// N.B. addition of device_group column removed in DDL v10
int_result = sqlite3_exec(
_session->db,
"alter table pgp_keypair\n"
" add column flags integer default 0;\n"
"alter table person\n"
" add column device_group text;\n",
" add column flags integer default 0;\n",
// "alter table person\n"
// " add column device_group text;\n",
NULL,
NULL,
NULL
@ -1176,6 +1169,40 @@ DYNAMIC_API PEP_STATUS init(
);
assert(int_result == SQLITE_OK);
}
if (version < 10 && version > 1) {
int_result = sqlite3_exec(
_session->db,
"PRAGMA foreign_keys=off;\n"
"BEGIN TRANSACTION;\n"
"ALTER TABLE person RENAME TO _person_old;\n"
"create table if not exists person (\n"
" id text primary key,\n"
" username text not null,\n"
" main_key_id text\n"
" references pgp_keypair (fpr)\n"
" on delete set null,\n"
" lang text,\n"
" comment text,\n"
" is_pEp_user integer default 0\n"
");\n"
"INSERT INTO person (id, username, main_key_id, "
" lang, comment, is_pEp_user) "
" SELECT _person_old.id, _person_old.username, "
" _person_old.main_key_id, _person_old.lang, "
" _person_old.comment, _person_old.is_pEp_user "
" FROM _person_old "
" WHERE 1;\n"
"DROP TABLE _person_old;\n"
"COMMIT;\n"
"\n"
"PRAGMA foreign_keys=on;\n"
,
NULL,
NULL,
NULL
);
assert(int_result == SQLITE_OK);
}
}
else {
// Version from DB was 0, it means this is initial setup.
@ -1347,13 +1374,13 @@ DYNAMIC_API PEP_STATUS init(
&_session->get_own_address_binding_from_contact, NULL);
assert(int_result == SQLITE_OK);
int_result = sqlite3_prepare_v2(_session->db, sql_set_device_group,
(int)strlen(sql_set_device_group), &_session->set_device_group, NULL);
assert(int_result == SQLITE_OK);
int_result = sqlite3_prepare_v2(_session->db, sql_get_device_group,
(int)strlen(sql_get_device_group), &_session->get_device_group, NULL);
assert(int_result == SQLITE_OK);
// int_result = sqlite3_prepare_v2(_session->db, sql_set_device_group,
// (int)strlen(sql_set_device_group), &_session->set_device_group, NULL);
// assert(int_result == SQLITE_OK);
//
// int_result = sqlite3_prepare_v2(_session->db, sql_get_device_group,
// (int)strlen(sql_get_device_group), &_session->get_device_group, NULL);
// assert(int_result == SQLITE_OK);
int_result = sqlite3_prepare_v2(_session->db, sql_set_pgp_keypair,
(int)strlen(sql_set_pgp_keypair), &_session->set_pgp_keypair,
@ -1638,10 +1665,10 @@ DYNAMIC_API void release(PEP_SESSION session)
sqlite3_finalize(session->was_id_for_revoke_contacted);
if (session->get_last_contacted)
sqlite3_finalize(session->get_last_contacted);
if (session->set_device_group)
sqlite3_finalize(session->set_device_group);
if (session->get_device_group)
sqlite3_finalize(session->get_device_group);
// if (session->set_device_group)
// sqlite3_finalize(session->set_device_group);
// if (session->get_device_group)
// sqlite3_finalize(session->get_device_group);
if (session->set_pgp_keypair)
sqlite3_finalize(session->set_pgp_keypair);
if (session->exists_identity_entry)
@ -3169,93 +3196,93 @@ PEP_STATUS update_trust_for_fpr(PEP_SESSION session,
return PEP_STATUS_OK;
}
DYNAMIC_API PEP_STATUS set_device_group(
PEP_SESSION session,
const char *group_name
)
{
int result;
assert(session);
if (!(session && group_name))
return PEP_ILLEGAL_VALUE;
// 1. Get own user_id
char* user_id = NULL;
PEP_STATUS status = get_default_own_userid(session, &user_id);
// No user_id is returned in this case, no need to free;
if (status != PEP_STATUS_OK)
return status;
// 2. Set device group
sqlite3_reset(session->set_device_group);
if(group_name){
sqlite3_bind_text(session->set_device_group, 1, group_name, -1,
SQLITE_STATIC);
} else {
sqlite3_bind_null(session->set_device_group, 1);
}
sqlite3_bind_text(session->set_device_group, 2, user_id, -1,
SQLITE_STATIC);
result = sqlite3_step(session->set_device_group);
sqlite3_reset(session->set_device_group);
free(user_id);
if (result != SQLITE_DONE)
return PEP_CANNOT_SET_PERSON;
return PEP_STATUS_OK;
}
DYNAMIC_API PEP_STATUS get_device_group(PEP_SESSION session, char **group_name)
{
PEP_STATUS status = PEP_STATUS_OK;
int result;
assert(session);
assert(group_name);
if (!(session && group_name))
return PEP_ILLEGAL_VALUE;
// 1. Get own user_id
char* user_id = NULL;
status = get_default_own_userid(session, &user_id);
// No user_id is returned in this case, no need to free;
if (status != PEP_STATUS_OK)
return status;
// 2. get device group
sqlite3_reset(session->get_device_group);
sqlite3_bind_text(session->get_device_group, 1, user_id, -1,
SQLITE_STATIC);
result = sqlite3_step(session->get_device_group);
switch (result) {
case SQLITE_ROW: {
const char *_group_name = (const char *)sqlite3_column_text(session->get_device_group, 0);
if(_group_name){
*group_name = strdup(_group_name);
if(*group_name == NULL)
status = PEP_OUT_OF_MEMORY;
}
break;
}
default:
status = PEP_RECORD_NOT_FOUND;
}
free(user_id);
sqlite3_reset(session->get_device_group);
return status;
}
// DYNAMIC_API PEP_STATUS set_device_group(
// PEP_SESSION session,
// const char *group_name
// )
// {
// int result;
//
// assert(session);
//
// if (!(session && group_name))
// return PEP_ILLEGAL_VALUE;
//
// // 1. Get own user_id
// char* user_id = NULL;
// PEP_STATUS status = get_default_own_userid(session, &user_id);
//
// // No user_id is returned in this case, no need to free;
// if (status != PEP_STATUS_OK)
// return status;
//
// // 2. Set device group
// sqlite3_reset(session->set_device_group);
// if(group_name){
// sqlite3_bind_text(session->set_device_group, 1, group_name, -1,
// SQLITE_STATIC);
// } else {
// sqlite3_bind_null(session->set_device_group, 1);
// }
//
// sqlite3_bind_text(session->set_device_group, 2, user_id, -1,
// SQLITE_STATIC);
//
// result = sqlite3_step(session->set_device_group);
// sqlite3_reset(session->set_device_group);
//
// free(user_id);
//
// if (result != SQLITE_DONE)
// return PEP_CANNOT_SET_PERSON;
//
// return PEP_STATUS_OK;
// }
//
// DYNAMIC_API PEP_STATUS get_device_group(PEP_SESSION session, char **group_name)
// {
// PEP_STATUS status = PEP_STATUS_OK;
// int result;
//
// assert(session);
// assert(group_name);
//
// if (!(session && group_name))
// return PEP_ILLEGAL_VALUE;
//
// // 1. Get own user_id
// char* user_id = NULL;
// status = get_default_own_userid(session, &user_id);
//
// // No user_id is returned in this case, no need to free;
// if (status != PEP_STATUS_OK)
// return status;
//
// // 2. get device group
// sqlite3_reset(session->get_device_group);
// sqlite3_bind_text(session->get_device_group, 1, user_id, -1,
// SQLITE_STATIC);
//
// result = sqlite3_step(session->get_device_group);
// switch (result) {
// case SQLITE_ROW: {
// const char *_group_name = (const char *)sqlite3_column_text(session->get_device_group, 0);
// if(_group_name){
// *group_name = strdup(_group_name);
// if(*group_name == NULL)
// status = PEP_OUT_OF_MEMORY;
// }
// break;
// }
//
// default:
// status = PEP_RECORD_NOT_FOUND;
// }
//
// free(user_id);
// sqlite3_reset(session->get_device_group);
// return status;
// }
DYNAMIC_API PEP_STATUS set_identity_flags(
PEP_SESSION session,


+ 32
- 32
src/pEpEngine.h View File

@ -865,38 +865,38 @@ DYNAMIC_API PEP_STATUS set_userid_alias (
const char* alias_id);
// set_device_group() - update own person's device group
//
// parameters:
// session (in) session handle
// group_name (in) new group name
//
// return value:
// PEP_STATUS_OK = 0 device group was updated
// PEP_CANNOT_SET_PERSON update failed
DYNAMIC_API PEP_STATUS set_device_group(
PEP_SESSION session,
const char *group_name
);
// get_device_group() - get own person's device group
//
// parameters:
// session (in) session handle
// group_name (in) new group name
//
// return value:
// PEP_STATUS_OK = 0 couldn't get device group
// PEP_RECORD_NOT_FOUND update failed
//
// caveat:
// the ownerships of group_name is going to the caller
DYNAMIC_API PEP_STATUS get_device_group(
PEP_SESSION session,
char **group_name
);
// // set_device_group() - update own person's device group
// //
// // parameters:
// // session (in) session handle
// // group_name (in) new group name
// //
// // return value:
// // PEP_STATUS_OK = 0 device group was updated
// // PEP_CANNOT_SET_PERSON update failed
//
// DYNAMIC_API PEP_STATUS set_device_group(
// PEP_SESSION session,
// const char *group_name
// );
//
// // get_device_group() - get own person's device group
// //
// // parameters:
// // session (in) session handle
// // group_name (in) new group name
// //
// // return value:
// // PEP_STATUS_OK = 0 couldn't get device group
// // PEP_RECORD_NOT_FOUND update failed
// //
// // caveat:
// // the ownerships of group_name is going to the caller
//
// DYNAMIC_API PEP_STATUS get_device_group(
// PEP_SESSION session,
// char **group_name
// );
// set_identity_flags() - update identity flags on existing identity
//


+ 2
- 2
src/pEp_internal.h View File

@ -178,8 +178,8 @@ struct _pEpSession {
sqlite3_stmt *get_contacted_ids_from_revoke_fpr;
sqlite3_stmt *was_id_for_revoke_contacted;
sqlite3_stmt *get_last_contacted;
sqlite3_stmt *set_device_group;
sqlite3_stmt *get_device_group;
// sqlite3_stmt *set_device_group;
// sqlite3_stmt *get_device_group;
sqlite3_stmt *set_pgp_keypair;
sqlite3_stmt *set_identity_entry;
sqlite3_stmt *update_identity_entry;


Loading…
Cancel
Save