Browse Source

...

generate_api
Volker Birk 4 years ago
parent
commit
c6c73fef61
8 changed files with 102 additions and 81 deletions
  1. +2
    -1
      src/keymanagement.c
  2. +14
    -5
      src/keymanagement.h
  3. +9
    -9
      src/message_api.c
  4. +39
    -35
      src/pEpEngine.c
  5. +32
    -8
      src/pEpEngine.h
  6. +4
    -3
      src/pEp_internal.h
  7. +2
    -5
      src/sync.c
  8. +0
    -15
      src/sync.h

+ 2
- 1
src/keymanagement.c View File

@ -1095,6 +1095,7 @@ DYNAMIC_API PEP_STATUS register_examine_function(
DYNAMIC_API PEP_STATUS do_keymanagement(
retrieve_next_identity_t retrieve_next_identity,
messageToSend_t messageToSend,
void *management
)
{
@ -1108,7 +1109,7 @@ DYNAMIC_API PEP_STATUS do_keymanagement(
if (!retrieve_next_identity || !management)
return PEP_ILLEGAL_VALUE;
status = init(&session);
status = init(&session, messageToSend);
assert(status == PEP_STATUS_OK);
if (status != PEP_STATUS_OK)
return status;


+ 14
- 5
src/keymanagement.h View File

@ -164,23 +164,32 @@ DYNAMIC_API PEP_STATUS register_examine_function(
// do_keymanagement() - function to be run on an extra thread
//
// parameters:
// retrieve_next_identity pointer to retrieve_next_identity() callback
// which returns at least a valid address field in
// the identity struct
// management management data to give to keymanagement
// (implementation defined)
// retrieve_next_identity (in) pointer to retrieve_next_identity()
// callback which returns at least a valid
// address field in the identity struct
// messageToSend (in) callback for sending message by the
// application
// management (in) management data to give to keymanagement
// (implementation defined)
//
// return value:
// PEP_STATUS_OK if thread has to terminate successfully or any other
// value on failure
//
// caveat:
// this function is creating and releasing a new session
//
// to ensure proper working of this library, a thread has to be started
// with this function immediately after initialization
//
// do_keymanagement() calls retrieve_next_identity(management)
//
// messageToSend can only be null if no transport is application based
// if transport system is not used it must not be NULL
DYNAMIC_API PEP_STATUS do_keymanagement(
retrieve_next_identity_t retrieve_next_identity,
messageToSend_t messageToSend,
void *management
);


+ 9
- 9
src/message_api.c View File

@ -1612,7 +1612,7 @@ DYNAMIC_API PEP_STATUS encrypt_message(
}
bool dest_keys_found = true;
bool has_pep_user = false;
bool has_pEp_user = false;
PEP_comm_type max_comm_type = PEP_ct_pEp;
@ -1658,8 +1658,8 @@ DYNAMIC_API PEP_STATUS encrypt_message(
}
}
}
if (!has_pep_user && !EMPTYSTR(_il->ident->user_id))
is_pep_user(session, _il->ident, &has_pep_user);
if (!has_pEp_user && !EMPTYSTR(_il->ident->user_id))
is_pEp_user(session, _il->ident, &has_pEp_user);
}
else
_status = myself(session, _il->ident);
@ -1710,8 +1710,8 @@ DYNAMIC_API PEP_STATUS encrypt_message(
}
}
}
if (!has_pep_user && !EMPTYSTR(_il->ident->user_id))
is_pep_user(session, _il->ident, &has_pep_user);
if (!has_pEp_user && !EMPTYSTR(_il->ident->user_id))
is_pEp_user(session, _il->ident, &has_pEp_user);
}
else
_status = myself(session, _il->ident);
@ -1761,8 +1761,8 @@ DYNAMIC_API PEP_STATUS encrypt_message(
}
}
}
if (!has_pep_user && !EMPTYSTR(_il->ident->user_id))
is_pep_user(session, _il->ident, &has_pep_user);
if (!has_pEp_user && !EMPTYSTR(_il->ident->user_id))
is_pEp_user(session, _il->ident, &has_pEp_user);
}
else
_status = myself(session, _il->ident);
@ -1791,7 +1791,7 @@ DYNAMIC_API PEP_STATUS encrypt_message(
PEP_rating_undefined) < PEP_rating_reliable)
{
free_stringlist(keys);
if ((has_pep_user || !session->passive_mode) &&
if ((has_pEp_user || !session->passive_mode) &&
!(flags & PEP_encrypt_flag_force_no_attached_key)) {
attach_own_key(session, src);
added_key_to_real_src = true;
@ -3090,7 +3090,7 @@ DYNAMIC_API PEP_STATUS _decrypt_message(
}
if (status == PEP_STATUS_OK) {
// Now set user as PEP (may also create an identity if none existed yet)
status = set_as_pep_user(session, tmp_from);
status = set_as_pEp_user(session, tmp_from);
}
}
}


+ 39
- 35
src/pEpEngine.c View File

@ -152,12 +152,12 @@ static const char *sql_update_person =
" (select device_group from person where id = ?1)"
" where id = ?1 ;";
static const char *sql_set_as_pep_user =
"update person set is_pep_user = 1 "
static const char *sql_set_as_pEp_user =
"update person set is_pEp_user = 1 "
" where id = ?1 ; ";
static const char *sql_is_pep_user =
"select is_pep_user from person "
static const char *sql_is_pEp_user =
"select is_pEp_user from person "
" where id = ?1 ; ";
static const char* sql_exists_person =
@ -489,7 +489,10 @@ void errorLogCallback(void *pArg, int iErrCode, const char *zMsg){
PEP_STATUS pgp_import_ultimately_trusted_keypairs(PEP_SESSION session);
#endif // USE_GPG
DYNAMIC_API PEP_STATUS init(PEP_SESSION *session)
DYNAMIC_API PEP_STATUS init(
PEP_SESSION *session,
messageToSend_t messageToSend
)
{
PEP_STATUS status = PEP_STATUS_OK;
int int_result;
@ -536,6 +539,7 @@ DYNAMIC_API PEP_STATUS init(PEP_SESSION *session)
goto enomem;
_session->version = PEP_ENGINE_VERSION;
_session->messageToSend = messageToSend;
#ifdef DEBUG_ERRORSTACK
_session->errorstack = new_stringlist("init()");
@ -655,7 +659,7 @@ DYNAMIC_API PEP_STATUS init(PEP_SESSION *session)
" lang text,\n"
" comment text,\n"
" device_group text,\n"
" is_pep_user integer default 0\n"
" is_pEp_user integer default 0\n"
");\n"
"create table if not exists identity (\n"
" address text,\n"
@ -758,7 +762,7 @@ DYNAMIC_API PEP_STATUS init(PEP_SESSION *session)
if (table_contains_column(_session, "identity", "timestamp") > 0) {
version = 8;
}
if (table_contains_column(_session, "person", "is_pep_user") > 0) {
if (table_contains_column(_session, "person", "is_pEp_user") > 0) {
version = 7;
}
else if (table_contains_column(_session, "identity", "is_own") > 0) {
@ -926,7 +930,7 @@ DYNAMIC_API PEP_STATUS init(PEP_SESSION *session)
int_result = sqlite3_exec(
_session->db,
"alter table person\n"
" add column is_pep_user integer default 0;\n",
" add column is_pEp_user integer default 0;\n",
NULL,
NULL,
NULL
@ -935,7 +939,7 @@ DYNAMIC_API PEP_STATUS init(PEP_SESSION *session)
int_result = sqlite3_exec(
_session->db,
"update person\n"
" set is_pep_user = 1\n"
" set is_pEp_user = 1\n"
" where id = "
" (select distinct id from person "
" join trust on id = user_id "
@ -1099,12 +1103,12 @@ DYNAMIC_API PEP_STATUS init(PEP_SESSION *session)
(int)strlen(sql_exists_person), &_session->exists_person, NULL);
assert(int_result == SQLITE_OK);
int_result = sqlite3_prepare_v2(_session->db, sql_set_as_pep_user,
(int)strlen(sql_set_as_pep_user), &_session->set_as_pep_user, NULL);
int_result = sqlite3_prepare_v2(_session->db, sql_set_as_pEp_user,
(int)strlen(sql_set_as_pEp_user), &_session->set_as_pEp_user, NULL);
assert(int_result == SQLITE_OK);
int_result = sqlite3_prepare_v2(_session->db, sql_is_pep_user,
(int)strlen(sql_is_pep_user), &_session->is_pep_user, NULL);
int_result = sqlite3_prepare_v2(_session->db, sql_is_pEp_user,
(int)strlen(sql_is_pEp_user), &_session->is_pEp_user, NULL);
assert(int_result == SQLITE_OK);
int_result = sqlite3_prepare_v2(_session->db, sql_set_device_group,
@ -1358,10 +1362,10 @@ DYNAMIC_API void release(PEP_SESSION session)
sqlite3_finalize(session->remove_fpr_as_default);
if (session->set_person)
sqlite3_finalize(session->set_person);
if (session->set_as_pep_user)
sqlite3_finalize(session->set_as_pep_user);
if (session->is_pep_user)
sqlite3_finalize(session->is_pep_user);
if (session->set_as_pEp_user)
sqlite3_finalize(session->set_as_pEp_user);
if (session->is_pEp_user)
sqlite3_finalize(session->is_pEp_user);
if (session->exists_person)
sqlite3_finalize(session->exists_person);
if (session->set_device_group)
@ -2305,7 +2309,7 @@ PEP_STATUS set_trust(PEP_SESSION session, pEp_identity* identity) {
status = _set_trust_internal(session, identity, true);
if (status == PEP_STATUS_OK) {
if ((identity->comm_type | PEP_ct_confirmed) == PEP_ct_pEp)
status = set_as_pep_user(session, identity);
status = set_as_pEp_user(session, identity);
}
return status;
}
@ -2330,7 +2334,7 @@ PEP_STATUS set_identity_entry(PEP_SESSION session, pEp_identity* identity,
guard_transaction);
}
// This will NOT call set_as_pep_user; you have to do that separately.
// This will NOT call set_as_pEp_user; you have to do that separately.
DYNAMIC_API PEP_STATUS set_identity(
PEP_SESSION session, const pEp_identity *identity
)
@ -2408,7 +2412,7 @@ pep_free:
return status;
}
PEP_STATUS update_pep_user_trust_vals(PEP_SESSION session,
PEP_STATUS update_pEp_user_trust_vals(PEP_SESSION session,
pEp_identity* user) {
if (!user->user_id)
return PEP_ILLEGAL_VALUE;
@ -2426,7 +2430,7 @@ PEP_STATUS update_pep_user_trust_vals(PEP_SESSION session,
// This ONLY sets the user flag. Must be called outside of a transaction.
PEP_STATUS set_as_pep_user(PEP_SESSION session, pEp_identity* user) {
PEP_STATUS set_as_pEp_user(PEP_SESSION session, pEp_identity* user) {
assert(session);
assert(user);
@ -2448,16 +2452,16 @@ PEP_STATUS set_as_pep_user(PEP_SESSION session, pEp_identity* user) {
status = set_person(session, user, true);
// Ok, let's set it.
sqlite3_reset(session->set_as_pep_user);
sqlite3_bind_text(session->set_as_pep_user, 1, user->user_id, -1,
sqlite3_reset(session->set_as_pEp_user);
sqlite3_bind_text(session->set_as_pEp_user, 1, user->user_id, -1,
SQLITE_STATIC);
int result = sqlite3_step(session->set_as_pep_user);
sqlite3_reset(session->set_as_pep_user);
int result = sqlite3_step(session->set_as_pEp_user);
sqlite3_reset(session->set_as_pEp_user);
if (result != SQLITE_DONE)
return PEP_CANNOT_SET_PERSON;
status = update_pep_user_trust_vals(session, user);
status = update_pEp_user_trust_vals(session, user);
return status;
}
@ -2512,7 +2516,7 @@ PEP_STATUS exists_person(PEP_SESSION session, pEp_identity* identity,
return status;
}
DYNAMIC_API PEP_STATUS is_pep_user(PEP_SESSION session, pEp_identity *identity, bool* is_pep)
DYNAMIC_API PEP_STATUS is_pEp_user(PEP_SESSION session, pEp_identity *identity, bool* is_pep)
{
assert(session);
assert(is_pep);
@ -2538,23 +2542,23 @@ DYNAMIC_API PEP_STATUS is_pep_user(PEP_SESSION session, pEp_identity *identity,
alias_default = strdup(user_id);
}
sqlite3_reset(session->is_pep_user);
sqlite3_bind_text(session->is_pep_user, 1, user_id, -1,
sqlite3_reset(session->is_pEp_user);
sqlite3_bind_text(session->is_pEp_user, 1, user_id, -1,
SQLITE_STATIC);
int result = sqlite3_step(session->is_pep_user);
int result = sqlite3_step(session->is_pEp_user);
switch (result) {
case SQLITE_ROW: {
// yeah yeah, I know, we could be lazy here, but it looks bad.
*is_pep = (sqlite3_column_int(session->is_pep_user, 0) != 0);
*is_pep = (sqlite3_column_int(session->is_pEp_user, 0) != 0);
break;
}
default:
sqlite3_reset(session->is_pep_user);
sqlite3_reset(session->is_pEp_user);
free(alias_default);
return PEP_CANNOT_FIND_PERSON;
}
sqlite3_reset(session->is_pep_user);
sqlite3_reset(session->is_pEp_user);
return PEP_STATUS_OK;
}
@ -3778,7 +3782,7 @@ DYNAMIC_API const char* get_engine_version() {
}
DYNAMIC_API PEP_STATUS reset_peptest_hack(PEP_SESSION session)
DYNAMIC_API PEP_STATUS reset_pEptest_hack(PEP_SESSION session)
{
assert(session);
@ -3787,7 +3791,7 @@ DYNAMIC_API PEP_STATUS reset_peptest_hack(PEP_SESSION session)
int int_result = sqlite3_exec(
session->db,
"delete from identity where address like '%@peptest.ch' ;",
"delete from identity where address like '%@pEptest.ch' ;",
NULL,
NULL,
NULL


+ 32
- 8
src/pEpEngine.h View File

@ -120,11 +120,29 @@ typedef enum {
} PEP_STATUS;
// messageToSend() - a message needs to be delivered by application
//
// parameters:
// obj (in) object handle (implementation defined)
// msg (in) message struct with message to send
//
// return value:
// PEP_STATUS_OK or any other value on error
//
// caveat:
// the ownership of msg goes to the callee
struct _message;
typedef PEP_STATUS (*messageToSend_t)(void *obj, struct _message *msg);
// INIT_STATUS init() - initialize pEpEngine for a thread
//
// parameters:
// session (out) init() allocates session memory and returns a pointer
// as a handle
// session (out) init() allocates session memory and
// returns a pointer as a handle
// messageToSend (in) callback for sending message by the
// application
//
// return value:
// PEP_STATUS_OK = 0 if init() succeeds
@ -138,8 +156,8 @@ typedef enum {
// opened
//
// caveat:
// THE CALLER MUST GUARD THIS CALL EXTERNALLY WITH A MUTEX. release() should
// be similarly guarded.
// THE CALLER MUST GUARD THIS CALL EXTERNALLY WITH A MUTEX. release()
// should be similarly guarded.
//
// the pointer is valid only if the return value is PEP_STATUS_OK
// in other case a NULL pointer will be returned; a valid handle must
@ -147,8 +165,14 @@ typedef enum {
//
// the caller has to guarantee that the first call to this function
// will succeed before further calls can be done
//
// messageToSend can only be null if no transport is application based
// if transport system is not used it must not be NULL
DYNAMIC_API PEP_STATUS init(PEP_SESSION *session);
DYNAMIC_API PEP_STATUS init(
PEP_SESSION *session,
messageToSend_t messageToSend
);
// void release() - release thread session handle
@ -1210,7 +1234,7 @@ PEP_STATUS find_private_keys(PEP_SESSION session, const char* pattern,
//
DYNAMIC_API const char* get_engine_version();
// is_pep_user() - returns true if the USER corresponding to this identity
// is_pEp_user() - returns true if the USER corresponding to this identity
// has been listed in the *person* table as a pEp user.
//
// parameters:
@ -1226,13 +1250,13 @@ DYNAMIC_API const char* get_engine_version();
//
// caveat: This *does not check comm_type*
//
DYNAMIC_API PEP_STATUS is_pep_user(PEP_SESSION session,
DYNAMIC_API PEP_STATUS is_pEp_user(PEP_SESSION session,
pEp_identity *identity,
bool* is_pep);
DYNAMIC_API PEP_STATUS reset_peptest_hack(PEP_SESSION session);
DYNAMIC_API PEP_STATUS reset_pEptest_hack(PEP_SESSION session);
// This is used internally when there is a temporary identity to be retrieved
// that may not yet have an FPR attached. See get_identity() for functionality,


+ 4
- 3
src/pEp_internal.h View File

@ -115,6 +115,8 @@ struct _pEpSession;
typedef struct _pEpSession pEpSession;
struct _pEpSession {
const char *version;
messageToSend_t messageToSend;
#ifdef USE_GPG
gpgme_ctx_t ctx;
#elif defined(USE_NETPGP)
@ -140,8 +142,8 @@ struct _pEpSession {
sqlite3_stmt *set_person;
sqlite3_stmt *update_person;
sqlite3_stmt *exists_person;
sqlite3_stmt *set_as_pep_user;
sqlite3_stmt *is_pep_user;
sqlite3_stmt *set_as_pEp_user;
sqlite3_stmt *is_pEp_user;
sqlite3_stmt *set_device_group;
sqlite3_stmt *get_device_group;
sqlite3_stmt *set_pgp_keypair;
@ -202,7 +204,6 @@ struct _pEpSession {
void *examine_management;
void *sync_management;
void *sync_obj;
messageToSend_t messageToSend;
notifyHandshake_t notifyHandshake;
inject_sync_msg_t inject_sync_msg;
retrieve_next_sync_msg_t retrieve_next_sync_msg;


+ 2
- 5
src/sync.c View File

@ -20,18 +20,16 @@ PEP_STATUS receive_sync_msg(
DYNAMIC_API PEP_STATUS register_sync_callbacks(
PEP_SESSION session,
void *management,
messageToSend_t messageToSend,
notifyHandshake_t notifyHandshake,
inject_sync_msg_t inject_sync_msg,
retrieve_next_sync_msg_t retrieve_next_sync_msg
)
{
assert(session && management && messageToSend && notifyHandshake && inject_sync_msg && retrieve_next_sync_msg);
if (!(session && management && messageToSend && notifyHandshake && inject_sync_msg && retrieve_next_sync_msg))
assert(session && management && notifyHandshake && inject_sync_msg && retrieve_next_sync_msg);
if (!(session && management && notifyHandshake && inject_sync_msg && retrieve_next_sync_msg))
return PEP_ILLEGAL_VALUE;
session->sync_management = management;
session->messageToSend = messageToSend;
session->notifyHandshake = notifyHandshake;
session->inject_sync_msg = inject_sync_msg;
session->retrieve_next_sync_msg = retrieve_next_sync_msg;
@ -50,7 +48,6 @@ DYNAMIC_API void unregister_sync_callbacks(PEP_SESSION session) {
// unregister
session->sync_management = NULL;
session->messageToSend = NULL;
session->notifyHandshake = NULL;
session->inject_sync_msg = NULL;
session->retrieve_next_sync_msg = NULL;


+ 0
- 15
src/sync.h View File

@ -33,19 +33,6 @@ typedef enum _sync_handshake_signal {
SYNC_NOTIFY_OVERTAKEN
} sync_handshake_signal;
// messageToSend() - send a message
//
// parameters:
// obj (in) object handle (implementation defined)
// msg (in) message struct with message to send
//
// return value:
// PEP_STATUS_OK or any other value on error
//
// caveat:
// the ownership of msg goes to the callee
typedef PEP_STATUS (*messageToSend_t)(void *obj, message *msg);
// notifyHandshake() - notify UI about sync handshaking process
//
@ -122,7 +109,6 @@ typedef void *(*retrieve_next_sync_msg_t)(void *management, time_t *timeout);
// parameters:
// session (in) session where to store obj handle
// management (in) application defined
// messageToSend (in) callback for sending message
// notifyHandshake (in) callback for doing the handshake
// retrieve_next_sync_msg (in) callback for receiving sync messages
//
@ -135,7 +121,6 @@ typedef void *(*retrieve_next_sync_msg_t)(void *management, time_t *timeout);
DYNAMIC_API PEP_STATUS register_sync_callbacks(
PEP_SESSION session,
void *management,
messageToSend_t messageToSend,
notifyHandshake_t notifyHandshake,
inject_sync_msg_t inject_sync_msg,
retrieve_next_sync_msg_t retrieve_next_sync_msg


Loading…
Cancel
Save