Browse Source

sequence

doc_update_sequoia
Volker Birk 6 years ago
parent
commit
b4fd263a22
4 changed files with 80 additions and 7 deletions
  1. +62
    -6
      src/pEpEngine.c
  2. +14
    -0
      src/pEpEngine.h
  3. +3
    -0
      src/pEp_internal.h
  4. +1
    -1
      test/pEpEngineTest.cc

+ 62
- 6
src/pEpEngine.c View File

@ -35,6 +35,8 @@ DYNAMIC_API PEP_STATUS init(PEP_SESSION *session)
static const char *sql_own_key_is_listed;
static const char *sql_own_key_retrieve;
static const char *sql_sequence_value;
bool in_first = false;
assert(sqlite3_threadsafe());
@ -179,6 +181,11 @@ DYNAMIC_API PEP_STATUS init(PEP_SESSION *session)
" references pgp_keypair (fpr)\n"
" on delete cascade\n"
");\n"
// sequences
"create table if not exists sequences(\n"
" name text primary key,\n"
" value integer default 0\n"
");\n"
,
NULL,
NULL,
@ -256,7 +263,12 @@ DYNAMIC_API PEP_STATUS init(PEP_SESSION *session)
sql_own_key_is_listed = "select count(*) from own_keys where fpr = upper(replace(?1,' ','')) ;";
sql_own_key_retrieve = "select * from own_keys ;";
sql_sequence_value = "insert or replace into sequences (name, value) "
"values (?1, "
"(select coalesce((select value + 1 from sequences "
"where name = ?1), 1 ))) ; "
"select value from sequences where name = ?1 ;";
}
int_result = sqlite3_prepare_v2(_session->db, sql_log, (int)strlen(sql_log),
@ -716,10 +728,13 @@ DYNAMIC_API PEP_STATUS get_identity(
assert(session);
assert(address);
assert(address[0]);
assert(identity);
if (!(session && address && address[0]))
if (!(session && address && address[0] && identity))
return PEP_ILLEGAL_VALUE;
*identity = NULL;
sqlite3_reset(session->get_identity);
sqlite3_bind_text(session->get_identity, 1, address, -1, SQLITE_STATIC);
sqlite3_bind_text(session->get_identity, 2, user_id, -1, SQLITE_STATIC);
@ -928,11 +943,11 @@ DYNAMIC_API PEP_STATUS least_trust(
assert(fpr);
assert(comm_type);
*comm_type = PEP_ct_unknown;
if (!(session && fpr && comm_type))
return PEP_ILLEGAL_VALUE;
*comm_type = PEP_ct_unknown;
sqlite3_reset(session->least_trust);
sqlite3_bind_text(session->least_trust, 1, fpr, -1, SQLITE_STATIC);
@ -1211,6 +1226,8 @@ DYNAMIC_API PEP_STATUS get_crashdump_log(
CRASHDUMP_MAX_LINES))
return PEP_ILLEGAL_VALUE;
*logdata = NULL;
int limit = maxlines ? maxlines : CRASHDUMP_DEFAULT_LINES;
const char *timestamp = NULL;
const char *title = NULL;
@ -1291,6 +1308,8 @@ DYNAMIC_API PEP_STATUS get_languagelist(
if (!(session && languages))
return PEP_ILLEGAL_VALUE;
*languages = NULL;
const char *lang = NULL;
const char *name = NULL;
const char *phrase = NULL;
@ -1351,13 +1370,13 @@ DYNAMIC_API PEP_STATUS get_phrase(
)
{
PEP_STATUS status = PEP_STATUS_OK;
*phrase = NULL;
assert(session && lang && lang[0] && lang[1] && lang[2] == 0 && phrase);
if (!(session && lang && lang[0] && lang[1] && lang[2] == 0 && phrase))
return PEP_ILLEGAL_VALUE;
*phrase = NULL;
sqlite3_reset(session->i18n_token);
sqlite3_bind_text(session->i18n_token, 1, lang, -1, SQLITE_STATIC);
sqlite3_bind_int(session->i18n_token, 2, phrase_id);
@ -1395,6 +1414,43 @@ the_end:
return status;
}
DYNAMIC_API PEP_STATUS sequence_value(
PEP_SESSION session,
const char *name,
int64_t *value
)
{
PEP_STATUS status = PEP_STATUS_OK;
int result;
assert(session);
assert(name);
assert(value);
if (!(session && name && value))
return PEP_ILLEGAL_VALUE;
*value = 0;
sqlite3_reset(session->sequence_value);
sqlite3_bind_text(session->sequence_value, 1, name, -1, SQLITE_STATIC);
result = sqlite3_step(session->sequence_value);
switch (result) {
case SQLITE_ROW: {
int64_t _value = (int64_t)
sqlite3_column_int64(session->sequence_value, 0);
*value = _value;
break;
}
default:
status = PEP_CANNOT_FIND_IDENTITY;
}
sqlite3_reset(session->sequence_value);
return status;
}
DYNAMIC_API PEP_STATUS reset_peptest_hack(PEP_SESSION session)
{
assert(session);


+ 14
- 0
src/pEpEngine.h View File

@ -766,6 +766,20 @@ DYNAMIC_API PEP_STATUS get_phrase(
);
// sequence_value() - raise the value of a named sequence and retrieve it
//
// parameters:
// session (in) session handle
// name (in) name of sequence
// value (out) value of sequence
DYNAMIC_API PEP_STATUS sequence_value(
PEP_SESSION session,
const char *name,
int64_t *value
);
DYNAMIC_API PEP_STATUS reset_peptest_hack(PEP_SESSION session);
#ifdef __cplusplus


+ 3
- 0
src/pEp_internal.h View File

@ -112,6 +112,9 @@ typedef struct _pEpSession {
sqlite3_stmt *own_key_is_listed;
sqlite3_stmt *own_key_retrieve;
// sequence value
sqlite3_stmt *sequence_value;
// callbacks
examine_identity_t examine_identity;
void *examine_management;


+ 1
- 1
test/pEpEngineTest.cc View File

@ -203,7 +203,7 @@ int main(int argc, char* argv[])
PEP_STATUS pep_set_result = set_identity(session, identity);
assert(pep_set_result == PEP_STATUS_OK);
free_identity(identity);
get_identity(session, "leon.schumacher@digitalekho.com", &identity);
get_identity(session, "leon.schumacher@digitalekho.com", "23", &identity);
assert(identity);
cout << "set: " << identity->address << ", " << identity->fpr << ", " << identity->user_id << ", " << identity->username << "\n";


Loading…
Cancel
Save