removed parameter assert checks

test-README.md
parent 1c6289922c
commit a06718c070

@ -538,9 +538,6 @@ static const char *sql_get_last_contacted =
static int user_version(void *_version, int count, char **text, char **name)
{
assert(_version);
assert(count == 1);
assert(text && text[0]);
if (!(_version && count == 1 && text && text[0]))
return -1;
@ -984,7 +981,6 @@ DYNAMIC_API PEP_STATUS init(
// client session, or by using synchronization primitive to protect
// creation/deletion of first/last session from the app.
assert(session);
if (session == NULL)
return PEP_ILLEGAL_VALUE;
@ -1000,10 +996,6 @@ DYNAMIC_API PEP_STATUS init(
_session->inject_sync_event = inject_sync_event;
_session->ensure_passphrase = ensure_passphrase;
#ifdef DEBUG_ERRORSTACK
_session->errorstack = new_stringlist("init()");
#endif
assert(LOCAL_DB);
if (LOCAL_DB == NULL) {
status = PEP_INIT_CANNOT_OPEN_DB;
@ -2130,10 +2122,7 @@ DYNAMIC_API void release(PEP_SESSION session)
bool out_last = false;
int _count = --init_count;
assert(_count >= -1);
assert(session);
if (!((_count >= -1) && session))
if ((_count < -1) || !session)
return;
// a small race condition but still a race condition
@ -2310,9 +2299,6 @@ DYNAMIC_API void release(PEP_SESSION session)
release_transport_system(session, out_last);
release_cryptotech(session, out_last);
#ifdef DEBUG_ERRORSTACK
free_stringlist(session->errorstack);
#endif
free(session);
}
}
@ -2404,11 +2390,7 @@ DYNAMIC_API PEP_STATUS log_event(
session->service_log = true;
int result;
assert(session);
assert(title);
assert(entity);
if (!(session && title && entity))
return PEP_ILLEGAL_VALUE;
@ -2438,7 +2420,6 @@ DYNAMIC_API PEP_STATUS log_service(
const char *comment
)
{
assert(session);
if (!session)
return PEP_ILLEGAL_VALUE;
@ -2455,10 +2436,6 @@ DYNAMIC_API PEP_STATUS trustword(
{
PEP_STATUS status = PEP_STATUS_OK;
assert(session);
assert(word);
assert(wsize);
if (!(session && word && wsize))
return PEP_ILLEGAL_VALUE;
@ -2468,6 +2445,7 @@ DYNAMIC_API PEP_STATUS trustword(
if (lang == NULL)
lang = "en";
// FIXME: should this not be an actual check???
assert((lang[0] >= 'A' && lang[0] <= 'Z')
|| (lang[0] >= 'a' && lang[0] <= 'z'));
assert((lang[1] >= 'A' && lang[1] <= 'Z')
@ -2500,12 +2478,6 @@ DYNAMIC_API PEP_STATUS trustwords(
{
const char *source = fingerprint;
assert(session);
assert(fingerprint);
assert(words);
assert(wsize);
assert(max_words >= 0);
if (!(session && fingerprint && words && wsize && max_words >= 0))
return PEP_ILLEGAL_VALUE;
@ -2523,6 +2495,7 @@ DYNAMIC_API PEP_STATUS trustwords(
if (!lang || !lang[0])
lang = "en";
// FIXME: Should this not be an actual check?
assert((lang[0] >= 'A' && lang[0] <= 'Z')
|| (lang[0] >= 'a' && lang[0] <= 'z'));
assert((lang[1] >= 'A' && lang[1] <= 'Z')
@ -2588,7 +2561,6 @@ pEp_identity *new_identity(
)
{
pEp_identity *result = calloc(1, sizeof(pEp_identity));
assert(result);
if (result) {
if (address) {
result->address = strdup(address);
@ -2628,23 +2600,23 @@ pEp_identity *new_identity(
pEp_identity *identity_dup(const pEp_identity *src)
{
assert(src);
pEp_identity *dup = new_identity(src->address, src->fpr, src->user_id,
src->username);
assert(dup);
if (dup == NULL)
return NULL;
dup->comm_type = src->comm_type;
dup->lang[0] = src->lang[0];
dup->lang[1] = src->lang[1];
dup->lang[2] = 0;
dup->flags = src->flags;
dup->me = src->me;
dup->major_ver = src->major_ver;
dup->minor_ver = src->minor_ver;
pEp_identity* dup = NULL;
if (src) {
dup = new_identity(src->address, src->fpr, src->user_id,
src->username);
assert(dup);
if (dup == NULL)
return NULL;
dup->comm_type = src->comm_type;
dup->lang[0] = src->lang[0];
dup->lang[1] = src->lang[1];
dup->lang[2] = 0;
dup->flags = src->flags;
dup->me = src->me;
dup->major_ver = src->major_ver;
dup->minor_ver = src->minor_ver;
}
return dup;
}
@ -2664,8 +2636,6 @@ DYNAMIC_API PEP_STATUS get_default_own_userid(
char** userid
)
{
assert(session);
assert(userid);
if (!session || !userid)
return PEP_ILLEGAL_VALUE;
@ -2708,11 +2678,6 @@ DYNAMIC_API PEP_STATUS get_userid_alias_default(
const char* alias_id,
char** default_id) {
assert(session);
assert(alias_id);
assert(alias_id[0]);
assert(default_id);
if (!(session && alias_id && alias_id[0] && default_id))
return PEP_ILLEGAL_VALUE;
@ -2753,10 +2718,6 @@ DYNAMIC_API PEP_STATUS set_userid_alias (
int result;
assert(session);
assert(default_id);
assert(alias_id);
if (!(session && default_id && alias_id &&
default_id[0] != '\0' && alias_id[0] != '\0'))
return PEP_ILLEGAL_VALUE;
@ -2792,11 +2753,6 @@ DYNAMIC_API PEP_STATUS get_identity(
PEP_STATUS status = PEP_STATUS_OK;
pEp_identity *_identity = NULL;
assert(session);
assert(address);
assert(address[0]);
assert(identity);
if (!(session && address && address[0] && identity))
return PEP_ILLEGAL_VALUE;
@ -3021,11 +2977,6 @@ PEP_STATUS get_identity_without_trust_check(
PEP_STATUS status = PEP_STATUS_OK;
pEp_identity *_identity = NULL;
assert(session);
assert(address);
assert(address[0]);
assert(identity);
if (!(session && address && address[0] && identity))
return PEP_ILLEGAL_VALUE;
@ -3090,10 +3041,6 @@ PEP_STATUS get_identities_by_address(
identity_list** id_list
)
{
assert(session);
assert(address);
assert(address[0]);
assert(id_list);
if (!(session && address && address[0] && id_list))
return PEP_ILLEGAL_VALUE;
@ -3161,11 +3108,7 @@ PEP_STATUS get_identities_by_address(
PEP_STATUS exists_identity_entry(PEP_SESSION session, pEp_identity* identity,
bool* exists) {
assert(session);
assert(identity);
assert(!EMPTYSTR(identity->user_id));
assert(!EMPTYSTR(identity->address));
if (!session || !exists || EMPTYSTR(identity->user_id) || EMPTYSTR(identity->address))
if (!session || !exists || !identity || EMPTYSTR(identity->user_id) || EMPTYSTR(identity->address))
return PEP_ILLEGAL_VALUE;
*exists = false;
@ -3196,11 +3139,7 @@ PEP_STATUS exists_identity_entry(PEP_SESSION session, pEp_identity* identity,
PEP_STATUS exists_trust_entry(PEP_SESSION session, pEp_identity* identity,
bool* exists) {
assert(session);
assert(identity);
assert(!EMPTYSTR(identity->user_id));
assert(!EMPTYSTR(identity->fpr));
if (!session || !exists || EMPTYSTR(identity->user_id) || EMPTYSTR(identity->fpr))
if (!session || !exists || !identity || EMPTYSTR(identity->user_id) || EMPTYSTR(identity->fpr))
return PEP_ILLEGAL_VALUE;
*exists = false;
@ -3271,11 +3210,6 @@ PEP_STATUS clear_trust_info(PEP_SESSION session,
static PEP_STATUS _set_or_update_trust(PEP_SESSION session,
pEp_identity* identity,
sqlite3_stmt* set_or_update) {
assert(session);
assert(identity);
assert(identity->user_id);
assert(identity->fpr);
if (!session || !identity || EMPTYSTR(identity->user_id) || EMPTYSTR(identity->fpr))
return PEP_ILLEGAL_VALUE;
@ -3304,9 +3238,6 @@ static PEP_STATUS _set_or_update_trust(PEP_SESSION session,
static PEP_STATUS _set_or_update_identity_entry(PEP_SESSION session,
pEp_identity* identity,
sqlite3_stmt* set_or_update) {
assert(session);
assert(identity);
assert(set_or_update);
if (!session || !identity || !identity->user_id || !identity->address)
return PEP_ILLEGAL_VALUE;
@ -3334,9 +3265,6 @@ static PEP_STATUS _set_or_update_identity_entry(PEP_SESSION session,
static PEP_STATUS _set_or_update_person(PEP_SESSION session,
pEp_identity* identity,
sqlite3_stmt* set_or_update) {
assert(session);
assert(identity);
assert(set_or_update);
if (!session || !identity || !identity->user_id || !identity->username)
return PEP_ILLEGAL_VALUE;
@ -3443,12 +3371,6 @@ DYNAMIC_API PEP_STATUS set_identity(
{
int result;
assert(session);
assert(identity);
assert(identity->address);
assert(identity->user_id);
assert(identity->username);
if (!(session && identity && identity->address &&
identity->user_id && identity->username))
return PEP_ILLEGAL_VALUE;
@ -3541,10 +3463,6 @@ PEP_STATUS update_pEp_user_trust_vals(PEP_SESSION session,
// This ONLY sets the user flag. Must be called outside of a transaction.
DYNAMIC_API PEP_STATUS set_as_pEp_user(PEP_SESSION session, pEp_identity* user) {
assert(session);
assert(user);
assert(!EMPTYSTR(user->user_id));
if (!session || !user || EMPTYSTR(user->user_id))
return PEP_ILLEGAL_VALUE;
@ -3578,10 +3496,10 @@ DYNAMIC_API PEP_STATUS set_as_pEp_user(PEP_SESSION session, pEp_identity* user)
// This ONLY sets the version flag. Must be called outside of a transaction.
PEP_STATUS set_pEp_version(PEP_SESSION session, pEp_identity* ident, unsigned int new_ver_major, unsigned int new_ver_minor) {
assert(session);
assert(!EMPTYSTR(ident->user_id));
assert(!EMPTYSTR(ident->address));
if (!session || !ident || EMPTYSTR(ident->user_id) || EMPTYSTR(ident->address))
return PEP_ILLEGAL_VALUE;
sqlite3_reset(session->set_pEp_version);
sqlite3_bind_double(session->set_pEp_version, 1, new_ver_major);
sqlite3_bind_double(session->set_pEp_version, 2, new_ver_minor);
@ -3606,8 +3524,9 @@ PEP_STATUS upgrade_pEp_version_by_user_id(PEP_SESSION session,
unsigned int new_ver_minor
)
{
assert(session);
assert(!EMPTYSTR(ident->user_id));
if (!session || !ident || EMPTYSTR(ident->user_id))
return PEP_ILLEGAL_VALUE;
sqlite3_reset(session->upgrade_pEp_version_by_user_id);
sqlite3_bind_int(session->upgrade_pEp_version_by_user_id, 1, new_ver_major);
@ -3626,14 +3545,7 @@ PEP_STATUS upgrade_pEp_version_by_user_id(PEP_SESSION session,
PEP_STATUS exists_person(PEP_SESSION session, pEp_identity* identity,
bool* exists) {
// const char* user_id,
// char** default_id, bool* exists) {
assert(session);
assert(exists);
assert(identity);
assert(!EMPTYSTR(identity->user_id));
if (!session || !exists || !identity || EMPTYSTR(identity->user_id))
return PEP_ILLEGAL_VALUE;
@ -3675,8 +3587,7 @@ PEP_STATUS exists_person(PEP_SESSION session, pEp_identity* identity,
}
PEP_STATUS delete_person(PEP_SESSION session, const char* user_id) {
assert(session);
assert(!EMPTYSTR(user_id));
if (!session || EMPTYSTR(user_id))
return PEP_ILLEGAL_VALUE;
@ -3697,10 +3608,6 @@ PEP_STATUS delete_person(PEP_SESSION session, const char* user_id) {
DYNAMIC_API PEP_STATUS is_pEp_user(PEP_SESSION session, pEp_identity *identity, bool* is_pEp)
{
assert(session);
assert(is_pEp);
assert(identity);
assert(!EMPTYSTR(identity->user_id));
if (!session || !is_pEp || !identity || EMPTYSTR(identity->user_id))
return PEP_ILLEGAL_VALUE;
@ -3742,9 +3649,6 @@ DYNAMIC_API PEP_STATUS is_pEp_user(PEP_SESSION session, pEp_identity *identity,
PEP_STATUS is_own_address(PEP_SESSION session, const char* address, bool* is_own_addr)
{
assert(session);
assert(is_own_addr);
assert(!EMPTYSTR(address));
if (!session || !is_own_addr || EMPTYSTR(address))
return PEP_ILLEGAL_VALUE;
@ -3802,12 +3706,7 @@ PEP_STATUS bind_own_ident_with_contact_ident(PEP_SESSION session,
// since this could be either way
PEP_STATUS has_partner_contacted_address(PEP_SESSION session, const char* partner_id,
const char* own_address, bool* was_contacted) {
assert(session);
assert(!EMPTYSTR(partner_id));
assert(!EMPTYSTR(own_address));
assert(was_contacted);
if (!session || !was_contacted || EMPTYSTR(partner_id) || EMPTYSTR(own_address))
return PEP_ILLEGAL_VALUE;
@ -3885,7 +3784,6 @@ PEP_STATUS get_own_ident_for_contact_id(PEP_SESSION session,
PEP_STATUS remove_fpr_as_default(PEP_SESSION session,
const char* fpr)
{
assert(fpr);
if (!session || !fpr)
return PEP_ILLEGAL_VALUE;
@ -3918,8 +3816,6 @@ PEP_STATUS replace_identities_fpr(PEP_SESSION session,
const char* old_fpr,
const char* new_fpr)
{
assert(old_fpr);
assert(new_fpr);
if (!old_fpr || !new_fpr)
return PEP_ILLEGAL_VALUE;
@ -3967,11 +3863,6 @@ DYNAMIC_API PEP_STATUS set_identity_flags(
{
int result;
assert(session);
assert(identity);
assert(identity->address);
assert(identity->user_id);
if (!(session && identity && identity->address && identity->user_id))
return PEP_ILLEGAL_VALUE;
@ -4000,11 +3891,6 @@ DYNAMIC_API PEP_STATUS unset_identity_flags(
{
int result;
assert(session);
assert(identity);
assert(identity->address);
assert(identity->user_id);
if (!(session && identity && identity->address && identity->user_id))
return PEP_ILLEGAL_VALUE;
@ -4032,11 +3918,6 @@ DYNAMIC_API PEP_STATUS set_ident_enc_format(
{
int result;
assert(session);
assert(identity);
assert(identity->address);
assert(identity->user_id);
if (!(session && identity && identity->address && identity->user_id))
return PEP_ILLEGAL_VALUE;
@ -4377,9 +4258,6 @@ pEp_free:
PEP_STATUS replace_userid(PEP_SESSION session, const char* old_uid,
const char* new_uid) {
assert(session);
assert(old_uid);
assert(new_uid);
if (!session || !old_uid || !new_uid)
return PEP_ILLEGAL_VALUE;
@ -4416,8 +4294,6 @@ PEP_STATUS replace_userid(PEP_SESSION session, const char* old_uid,
}
PEP_STATUS remove_key(PEP_SESSION session, const char* fpr) {
assert(session);
assert(fpr);
if (!session || EMPTYSTR(fpr))
return PEP_ILLEGAL_VALUE;
@ -4437,8 +4313,6 @@ PEP_STATUS remove_key(PEP_SESSION session, const char* fpr) {
PEP_STATUS refresh_userid_default_key(PEP_SESSION session, const char* user_id) {
assert(session);
assert(user_id);
if (!session || !user_id)
return PEP_ILLEGAL_VALUE;
@ -4458,9 +4332,6 @@ PEP_STATUS refresh_userid_default_key(PEP_SESSION session, const char* user_id)
PEP_STATUS replace_main_user_fpr(PEP_SESSION session, const char* user_id,
const char* new_fpr) {
assert(session);
assert(user_id);
assert(new_fpr);
if (!session || !user_id || !new_fpr)
return PEP_ILLEGAL_VALUE;
@ -4482,9 +4353,6 @@ PEP_STATUS replace_main_user_fpr(PEP_SESSION session, const char* user_id,
PEP_STATUS replace_main_user_fpr_if_equal(PEP_SESSION session, const char* user_id,
const char* new_fpr, const char* compare_fpr) {
assert(session);
assert(user_id);
assert(compare_fpr);
if (!session || !user_id || !compare_fpr)
return PEP_ILLEGAL_VALUE;
@ -4515,11 +4383,7 @@ PEP_STATUS get_main_user_fpr(PEP_SESSION session,
{
PEP_STATUS status = PEP_STATUS_OK;
int result;
assert(session);
assert(user_id);
assert(main_fpr);
if (!(session && user_id && user_id[0] && main_fpr))
return PEP_ILLEGAL_VALUE;
@ -4567,9 +4431,6 @@ DYNAMIC_API PEP_STATUS mark_as_compromised(
{
int result;
assert(session);
assert(fpr && fpr[0]);
if (!(session && fpr && fpr[0]))
return PEP_ILLEGAL_VALUE;
@ -4600,15 +4461,6 @@ DYNAMIC_API PEP_STATUS get_trust(PEP_SESSION session, pEp_identity *identity)
PEP_STATUS status = PEP_STATUS_OK;
int result;
// We need to be able to test that we break correctly without shutting
// asserts off everywhere.
// assert(session);
// assert(identity);
// assert(identity->user_id);
// assert(identity->user_id[0]);
// assert(identity->fpr);
// assert(identity->fpr[0]);
if (!(session && identity && identity->user_id && identity->user_id[0] &&
identity->fpr && identity->fpr[0]))
return PEP_ILLEGAL_VALUE;
@ -4647,10 +4499,6 @@ DYNAMIC_API PEP_STATUS least_trust(
PEP_STATUS status = PEP_STATUS_OK;
int result;
assert(session);
assert(fpr);
assert(comm_type);
if (!(session && fpr && comm_type))
return PEP_ILLEGAL_VALUE;
@ -4702,12 +4550,6 @@ DYNAMIC_API PEP_STATUS decrypt_and_verify(
char** filename_ptr
)
{
assert(session);
assert(ctext);
assert(csize);
assert(ptext);
assert(psize);
assert(keylist);
if (!(session && ctext && csize && ptext && psize && keylist))
return PEP_ILLEGAL_VALUE;
@ -4730,12 +4572,6 @@ DYNAMIC_API PEP_STATUS encrypt_and_sign(
size_t psize, char **ctext, size_t *csize
)
{
assert(session);
assert(keylist);
assert(ptext);
assert(psize);
assert(ctext);
assert(csize);
if (!(session && keylist && ptext && psize && ctext && csize))
return PEP_ILLEGAL_VALUE;
@ -4749,12 +4585,6 @@ PEP_STATUS encrypt_only(
size_t psize, char **ctext, size_t *csize
)
{
assert(session);
assert(keylist);
assert(ptext);
assert(psize);
assert(ctext);
assert(csize);
if (!(session && keylist && ptext && psize && ctext && csize))
return PEP_ILLEGAL_VALUE;
@ -4769,12 +4599,6 @@ PEP_STATUS sign_only(PEP_SESSION session,
const char *fpr,
char **sign,
size_t *sign_size) {
assert(session);
assert(fpr);
assert(data);
assert(data_size);
assert(sign);
assert(sign_size);
if (!(session && fpr && data && data_size && sign && sign_size))
return PEP_ILLEGAL_VALUE;
@ -4791,12 +4615,6 @@ DYNAMIC_API PEP_STATUS verify_text(
const char *signature, size_t sig_size, stringlist_t **keylist
)
{
assert(session);
assert(text);
assert(size);
assert(signature);
assert(sig_size);
assert(keylist);
if (!(session && text && size && signature && sig_size && keylist))
return PEP_ILLEGAL_VALUE;
@ -4807,8 +4625,6 @@ DYNAMIC_API PEP_STATUS verify_text(
DYNAMIC_API PEP_STATUS delete_keypair(PEP_SESSION session, const char *fpr)
{
assert(session);
assert(fpr);
if (!(session && fpr))
return PEP_ILLEGAL_VALUE;
@ -4820,10 +4636,6 @@ DYNAMIC_API PEP_STATUS export_key(
PEP_SESSION session, const char *fpr, char **key_data, size_t *size
)
{
assert(session);
assert(fpr);
assert(key_data);
assert(size);
if (!(session && fpr && key_data && size))
return PEP_ILLEGAL_VALUE;
@ -4836,11 +4648,6 @@ DYNAMIC_API PEP_STATUS export_secret_key(
PEP_SESSION session, const char *fpr, char **key_data, size_t *size
)
{
assert(session);
assert(fpr);
assert(key_data);
assert(size);
if (!(session && fpr && key_data && size))
return PEP_ILLEGAL_VALUE;
@ -4864,10 +4671,6 @@ DYNAMIC_API PEP_STATUS find_keys(
PEP_SESSION session, const char *pattern, stringlist_t **keylist
)
{
assert(session);
assert(pattern);
assert(keylist);
if (!(session && pattern && keylist))
return PEP_ILLEGAL_VALUE;
@ -4888,11 +4691,6 @@ PEP_STATUS _generate_keypair(PEP_SESSION session,
bool suppress_event
)
{
assert(session);
assert(identity);
assert(identity->address);
assert(identity->fpr == NULL || identity->fpr[0] == 0);
// assert(identity->username);
// N.B. We now allow empty usernames, so the underlying layer for
// non-sequoia crypto implementations will have to deal with this.
@ -4951,10 +4749,6 @@ DYNAMIC_API PEP_STATUS get_key_rating(
PEP_comm_type *comm_type
)
{
assert(session);
assert(fpr);
assert(comm_type);
if (!(session && fpr && comm_type))
return PEP_ILLEGAL_VALUE;
@ -4980,9 +4774,6 @@ PEP_STATUS _import_key_with_fpr_return(
uint64_t* changed_public_keys
)
{
assert(session);
assert(key_data);
if (!(session && key_data))
return PEP_ILLEGAL_VALUE;
@ -4994,10 +4785,7 @@ PEP_STATUS _import_key_with_fpr_return(
}
DYNAMIC_API PEP_STATUS recv_key(PEP_SESSION session, const char *pattern)
{
assert(session);
assert(pattern);
{
if (!(session && pattern))
return PEP_ILLEGAL_VALUE;
@ -5006,9 +4794,6 @@ DYNAMIC_API PEP_STATUS recv_key(PEP_SESSION session, const char *pattern)
DYNAMIC_API PEP_STATUS send_key(PEP_SESSION session, const char *pattern)
{
assert(session);
assert(pattern);
if (!(session && pattern))
return PEP_ILLEGAL_VALUE;
@ -5021,9 +4806,6 @@ DYNAMIC_API PEP_STATUS renew_key(
const timestamp *ts
)
{
assert(session);
assert(fpr);
if (!(session && fpr))
return PEP_ILLEGAL_VALUE;
@ -5036,9 +4818,6 @@ DYNAMIC_API PEP_STATUS revoke_key(
const char *reason
)
{
assert(session);
assert(fpr);
if (!(session && fpr))
return PEP_ILLEGAL_VALUE;
@ -5062,10 +4841,6 @@ DYNAMIC_API PEP_STATUS key_expired(
bool *expired
)
{
assert(session);
assert(fpr);
assert(expired);
if (!(session && fpr && expired))
return PEP_ILLEGAL_VALUE;
@ -5078,11 +4853,7 @@ DYNAMIC_API PEP_STATUS key_revoked(
const char *fpr,
bool *revoked
)
{
assert(session);
assert(fpr);
assert(revoked);
{
if (!(session && fpr && revoked))
return PEP_ILLEGAL_VALUE;
@ -5093,7 +4864,6 @@ DYNAMIC_API PEP_STATUS key_revoked(
DYNAMIC_API PEP_STATUS config_cipher_suite(PEP_SESSION session,
PEP_CIPHER_SUITE suite)
{
assert(session);
if (!session)
return PEP_ILLEGAL_VALUE;
@ -5143,10 +4913,6 @@ DYNAMIC_API PEP_STATUS get_crashdump_log(
PEP_STATUS status = PEP_STATUS_OK;
char *_logdata= NULL;
assert(session);
assert(maxlines >= 0 && maxlines <= CRASHDUMP_MAX_LINES);
assert(logdata);
if (!(session && logdata && maxlines >= 0 && maxlines <=
CRASHDUMP_MAX_LINES))
return PEP_ILLEGAL_VALUE;
@ -5241,9 +5007,6 @@ DYNAMIC_API PEP_STATUS get_languagelist(
PEP_STATUS status = PEP_STATUS_OK;
char *_languages= NULL;
assert(session);
assert(languages);
if (!(session && languages))
return PEP_ILLEGAL_VALUE;
@ -5313,7 +5076,6 @@ DYNAMIC_API PEP_STATUS get_phrase(
{
PEP_STATUS status = PEP_STATUS_OK;
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;
@ -5359,7 +5121,6 @@ the_end:
static PEP_STATUS _get_sequence_value(PEP_SESSION session, const char *name,
int32_t *value)
{
assert(session && name && value);
if (!(session && name && value))
return PEP_ILLEGAL_VALUE;
@ -5390,7 +5151,6 @@ static PEP_STATUS _get_sequence_value(PEP_SESSION session, const char *name,
static PEP_STATUS _increment_sequence_value(PEP_SESSION session,
const char *name)
{
assert(session && name);
if (!(session && name))
return PEP_ILLEGAL_VALUE;
@ -5413,9 +5173,6 @@ DYNAMIC_API PEP_STATUS sequence_value(
{
PEP_STATUS status = PEP_STATUS_OK;
assert(session);
assert(name && value);
if (!(session && name && name[0] && value))
return PEP_ILLEGAL_VALUE;
@ -5478,12 +5235,7 @@ DYNAMIC_API PEP_STATUS set_revoked(
)
{
PEP_STATUS status = PEP_STATUS_OK;
assert(session &&
revoked_fpr && revoked_fpr[0] &&
replacement_fpr && replacement_fpr[0]
);
if (!(session &&
revoked_fpr && revoked_fpr[0] &&
replacement_fpr && replacement_fpr[0]
@ -5520,16 +5272,8 @@ DYNAMIC_API PEP_STATUS get_revoked(
)
{
PEP_STATUS status = PEP_STATUS_OK;
assert(session &&
revoked_fpr &&
fpr && fpr[0]
);
if (!(session &&
revoked_fpr &&
fpr && fpr[0]
))
if (!(session && revoked_fpr && fpr && fpr[0]))
return PEP_ILLEGAL_VALUE;
*revoked_fpr = NULL;
@ -5570,8 +5314,6 @@ DYNAMIC_API PEP_STATUS get_replacement_fpr(
)
{
PEP_STATUS status = PEP_STATUS_OK;
assert(session && revoked_fpr && !EMPTYSTR(fpr) && revocation_date);
if (!session || !revoked_fpr || EMPTYSTR(fpr) || !revocation_date)
return PEP_ILLEGAL_VALUE;
@ -5611,9 +5353,6 @@ PEP_STATUS get_last_contacted(
identity_list** id_list
)
{
assert(session);
assert(id_list);
if (!(session && id_list))
return PEP_ILLEGAL_VALUE;
@ -5659,7 +5398,6 @@ PEP_STATUS key_created(
time_t *created
)
{
assert(session && fpr && created);
if (!(session && fpr && created))
return PEP_ILLEGAL_VALUE;
@ -5669,7 +5407,6 @@ PEP_STATUS key_created(
PEP_STATUS find_private_keys(PEP_SESSION session, const char* pattern,
stringlist_t **keylist) {
assert(session && keylist);
if (!(session && keylist))
return PEP_ILLEGAL_VALUE;
@ -5688,7 +5425,6 @@ DYNAMIC_API const char* get_protocol_version() {
DYNAMIC_API PEP_STATUS reset_pEptest_hack(PEP_SESSION session)
{
assert(session);
if (!session)
return PEP_ILLEGAL_VALUE;
@ -5708,55 +5444,6 @@ DYNAMIC_API PEP_STATUS reset_pEptest_hack(PEP_SESSION session)
return PEP_STATUS_OK;
}
#ifdef DEBUG_ERRORSTACK
PEP_STATUS session_add_error(PEP_SESSION session, const char* file, unsigned line, PEP_STATUS status)
{
char logline[48];
if(status>0)
{
snprintf(logline,47, "%.24s:%u status=%u (0x%x)", file, line, status, status);
}else{
snprintf(logline,47, "%.24s:%u status=%i.", file, line, status);
}
stringlist_add(session->errorstack, logline); // logline is copied! :-)
return status;
}
DYNAMIC_API const stringlist_t* get_errorstack(PEP_SESSION session)
{
return session->errorstack;
}
DYNAMIC_API void clear_errorstack(PEP_SESSION session)
{
const int old_len = stringlist_length(session->errorstack);
char buf[48];
free_stringlist(session->errorstack);
snprintf(buf, 47, "(%i elements cleared)", old_len);
session->errorstack = new_stringlist(buf);
}
#else
static stringlist_t* dummy_errorstack = NULL;
DYNAMIC_API const stringlist_t* get_errorstack(PEP_SESSION session)
{
if(dummy_errorstack == NULL)
{
dummy_errorstack = new_stringlist("( Please recompile pEpEngine with -DDEBUG_ERRORSTACK )");
}
return dummy_errorstack;
}
DYNAMIC_API void clear_errorstack(PEP_SESSION session)
{
// nothing to do here
}
#endif
DYNAMIC_API void _service_error_log(PEP_SESSION session, const char *entity,
PEP_STATUS status, const char *where)
{

@ -285,26 +285,6 @@ DYNAMIC_API PEP_STATUS init(
DYNAMIC_API void release(PEP_SESSION session);
// const stringlist_t* get_errorstack(PEP_SESSION) - get the error stack for that session, if any
//
// parameters:
// session (in) session handle
//
// caveat:
// To get a useful error stack you have to compile with -DDEBUG_ERRORSTACK
// The error stack belongs to the session. Do no not change it!
DYNAMIC_API const stringlist_t* get_errorstack(PEP_SESSION session);
// void clear_errorstack(PEP_SESSION) - clear the error stack for that session, if any
//
// parameters:
// session (in) session handle
//
DYNAMIC_API void clear_errorstack(PEP_SESSION session);
// config_passive_mode() - enable passive mode
//
// parameters:

@ -269,9 +269,6 @@ struct _pEpSession {
bool service_log;
#ifndef NDEBUG
# ifdef DEBUG_ERRORSTACK
stringlist_t* errorstack;
# endif
int debug_color;
#endif
};

@ -95,13 +95,6 @@ void Engine::start() {
PEP_STATUS status = init(&session, cached_messageToSend, cached_inject_sync_event, cached_ensure_passphrase);
assert(status == PEP_STATUS_OK);
assert(session);
#ifdef USE_GPG
success = system("gpgconf --create-socketdir");
if (success != 0)
throw std::runtime_error("RESTORE: Error when executing 'gpgconf --create-socketdir'.");
system("gpg-connect-agent /bye 2>/dev/null"); // Just in case - otherwise, we die on MacOS sometimes. Is this enough??
#endif
}
void Engine::copy_conf_file_to_test_dir(const char* dest_path, const char* conf_orig_path, const char* conf_dest_name) {

@ -1,342 +0,0 @@
// This file is under GNU General Public License 3.0
// see LICENSE.txt
#include <stdlib.h>
#include <string>
#include <assert.h>
#include <thread>
#include "locked_queue.hh"
#include "sync_api.h"
#include "Sync_impl.h"
#include "test_util.h"
#include "pEpEngine.h"
#include "pEp_internal.h"
#include "KeySync_fsm.h"
#include "sync_codec.h"
#include "Engine.h"
#include <gtest/gtest.h>
class Sync_Adapter;
// wrappers for static callbacks. Don't ask me about this mess.
PEP_STATUS ST_message_send_callback(message* msg);
int ST_inject_sync_event_callback(SYNC_EVENT ev, void *management);
Sync_event_t* ST_retrieve_next_sync_event_callback(void *management, unsigned threshold);
void ST_sync_thread_callback(PEP_SESSION session, Sync_Adapter *adapter);
PEP_STATUS ST_notifyHandshake_callback(pEp_identity *me, pEp_identity *partner, sync_handshake_signal signal);
static void* ST_fake_this;
class Sync_Adapter {
public:
utility::locked_queue< Sync_event_t * > q;
void processing();
static PEP_STATUS notifyHandshake(
pEp_identity *me,
pEp_identity *partner,
sync_handshake_signal signal
);
static int inject_sync_event(SYNC_EVENT ev, void *management);
static Sync_event_t *retrieve_next_sync_event(void *management, unsigned threshold);
static PEP_STATUS messageToSend(struct _message *msg);
static void sync_thread(PEP_SESSION session, Sync_Adapter *adapter);
};
void Sync_Adapter::processing()
{
output_stream << "waiting for processing\n";
const struct timespec arr[] = {{0, 100000000L}};
while (!q.empty()) {
nanosleep(arr, NULL);
}
}
PEP_STATUS Sync_Adapter::notifyHandshake(
pEp_identity *me,
pEp_identity *partner,
sync_handshake_signal signal
)
{
return PEP_STATUS_OK;
}
PEP_STATUS ST_notifyHandshake_callback(
pEp_identity*me,
pEp_identity *partner,
sync_handshake_signal signal
) {
return ((Sync_Adapter*)ST_fake_this)->notifyHandshake(me, partner, signal);
}
int Sync_Adapter::inject_sync_event(SYNC_EVENT ev, void *management)
{
Sync_event_t *_ev = ev;
switch (_ev->fsm) {
case Sync_PR_keysync:
output_stream << "injecting event " << KeySync_event_name(_ev->event) << "\n";
break;
default:
output_stream << "unknown state machine: " << _ev->fsm << "\n";
assert(0);
}
auto adapter = static_cast< Sync_Adapter *>(management);
adapter->q.push_front(ev);
return 0;
}
int ST_inject_sync_event_callback(SYNC_EVENT ev, void *management) {
return ((Sync_Adapter*)ST_fake_this)->inject_sync_event(ev, management);
}
Sync_event_t *Sync_Adapter::retrieve_next_sync_event(void *management, unsigned threshold)
{
// N.B. I think it's too late by the time you get here.
auto adapter = static_cast< Sync_Adapter *>(management);
time_t started = time(nullptr);
bool timeout = false;
while (adapter->q.empty()) {
int i = 0;
++i;
if (i > 10) {
if (time(nullptr) > started + threshold) {
timeout = true;
break;
}
i = 0;
}
const struct timespec arr[] = {{0, 100000000L}};
nanosleep(arr, NULL);
}
if (timeout)
return SYNC_TIMEOUT_EVENT;
Sync_event_t *ev = adapter->q.pop_front();
if (ev) {
switch (ev->fsm) {
case Sync_PR_keysync:
output_stream << "sync thread: retrieving event " << KeySync_event_name(ev->event) << "\n";
break;
default:
output_stream << "sync thread: unknown state machine: " << ev->fsm << "\n";
assert(0);
}
}
else {
output_stream << "sync thread: retrieving shutdown\n";
}
return ev;
}
Sync_event_t* ST_retrieve_next_sync_event_callback(void *management,
unsigned threshold) {
return ((Sync_Adapter*)ST_fake_this)->retrieve_next_sync_event(management, threshold);
}
PEP_STATUS Sync_Adapter::messageToSend(struct _message *msg)
{
assert(msg && msg->attachments);
output_stream << "sending message:\n";
for (bloblist_t *b = msg->attachments; b && b->value; b = b->next) {
if (b->mime_type && strcasecmp(b->mime_type, "application/pEp.sync") == 0) {
assert(msg->from && msg->from->address && msg->from->username);
output_stream << "<!-- " << msg->from->username << " <" << msg->from->address << "> -->\n";
char *text = NULL;
PEP_STATUS status = PER_to_XER_Sync_msg(msg->attachments->value, msg->attachments->size, &text);
assert(status == PEP_STATUS_OK);
output_stream << text << "\n";
free(text);
}
}
free_message(msg);
return PEP_STATUS_OK;
}
PEP_STATUS ST_message_send_callback(message* msg) {
return ((Sync_Adapter*)ST_fake_this)->messageToSend(msg);
}
void Sync_Adapter::sync_thread(PEP_SESSION session, Sync_Adapter *adapter)
{
output_stream << "sync_thread: startup\n";
do_sync_protocol(session, adapter);
output_stream << "sync_thread: shutdown\n";
}
void ST_sync_thread_callback(PEP_SESSION session, Sync_Adapter *adapter) {
((Sync_Adapter*)ST_fake_this)->sync_thread(session, adapter);
}
namespace {
//The fixture for SyncTest
class SyncTest : public ::testing::Test {
public:
Engine* engine;
PEP_SESSION session;
Sync_Adapter adapter;
PEP_SESSION sync = NULL;
thread *sync_thread;
protected:
// You can remove any or all of the following functions if its body
// is empty.
SyncTest() {
// You can do set-up work for each test here.
test_suite_name = ::testing::UnitTest::GetInstance()->current_test_info()->GTEST_SUITE_SYM();
test_name = ::testing::UnitTest::GetInstance()->current_test_info()->name();
test_path = get_main_test_home_dir() + "/" + test_suite_name + "/" + test_name;
}
~SyncTest() override {
// You can do clean-up work that doesn't throw exceptions here.
}
// If the constructor and destructor are not enough for setting up
// and cleaning up each test, you can define the following methods:
void SetUp() override {
// Code here will be called immediately after the constructor (right
// before each test).
// Leave this empty if there are no files to copy to the home directory path
std::vector<std::pair<std::string, std::string>> init_files = std::vector<std::pair<std::string, std::string>>();
// Get a new test Engine.
engine = new Engine(test_path);
ASSERT_NE(engine, nullptr);
// Ok, let's initialize test directories etc.
engine->prep(NULL, NULL, NULL, init_files);
// Ok, try to start this bugger. Is this totally irrelevant for this case??
engine->start();
ASSERT_NE(engine->session, nullptr);
session = engine->session;
// Engine is up. Keep on truckin'
pEp_identity *self = new_identity("alice@synctests.pEp", nullptr, "23", "Alice Miller");
assert(self);
output_stream << "setting own identity for " << self->address << "\n";
PEP_STATUS status = myself(session, self);
assert(self->me);
assert(self->fpr);
output_stream << "fpr: " << self->fpr << "\n";
free_identity(self);
ST_fake_this = (void*)(&adapter);
status = init(&sync, ST_message_send_callback, ST_inject_sync_event_callback, NULL);
if (status != PEP_STATUS_OK)
throw std::runtime_error((string("init returned ") + tl_status_string(status)).c_str());
output_stream << "initialize sync and start first state machine\n";
status = register_sync_callbacks(
sync,
(void *) &adapter.q,
ST_notifyHandshake_callback,
ST_retrieve_next_sync_event_callback
);
if (status != PEP_STATUS_OK)
throw std::runtime_error((string("register sync status returned ") + tl_status_string(status)).c_str());
if (sync->sync_state.keysync.state != Sole)
throw std::runtime_error((string("keysync.state was supposed to be ") + to_string((int)Sole) + " but was " + to_string((int)(sync->sync_state.keysync.state))).c_str());
output_stream << "creating thread for sync\n";
sync_thread = new thread(ST_sync_thread_callback, sync, &adapter);
}
void TearDown() override {
// Code here will be called immediately after each test (right
// before the destructor).
adapter.processing();
output_stream << "sending shutdown to sync thread\n";
adapter.q.push_front(nullptr);
sync_thread->join();
unregister_sync_callbacks(sync);
release(sync);
engine->shut_down();
delete engine;
</