static int autocrypt_dir_init(int can_create)
{
- int rv = 0;
+ int rc = 0;
struct stat sb;
struct Buffer *prompt = NULL;
error message returned by libc
*/
mutt_error(_("Can't create %s: %s."), C_AutocryptDir, strerror(errno));
- rv = -1;
+ rc = -1;
}
}
mutt_buffer_pool_release(&prompt);
- return rv;
+ return rc;
}
int mutt_autocrypt_init(int can_create)
struct AutocryptPeerHistory *peerhist = NULL;
struct Buffer *keyid = NULL;
int update_db = 0, insert_db = 0, insert_db_history = 0, import_gpg = 0;
- int rv = -1;
+ int rc = -1;
if (!C_Autocrypt)
return 0;
{
if (e->date_sent <= peer->autocrypt_timestamp)
{
- rv = 0;
+ rc = 0;
goto cleanup;
}
if (!(import_gpg || insert_db || update_db))
{
- rv = 0;
+ rc = 0;
goto cleanup;
}
goto cleanup;
}
- rv = 0;
+ rc = 0;
cleanup:
mutt_autocrypt_db_peer_free(&peer);
mutt_autocrypt_db_peer_history_free(&peerhist);
mutt_buffer_pool_release(&keyid);
- return rv;
+ return rc;
}
int mutt_autocrypt_process_gossip_header(struct Email *hdr, struct Envelope *prot_headers)
struct Address ac_hdr_addr = { 0 };
struct Buffer *keyid = NULL;
int update_db = 0, insert_db = 0, insert_db_history = 0, import_gpg = 0;
- int rv = -1;
+ int rc = -1;
if (!C_Autocrypt)
return 0;
update_db = insert_db = insert_db_history = import_gpg = 0;
}
- rv = 0;
+ rc = 0;
cleanup:
FREE(&ac_hdr_addr.mailbox);
mutt_autocrypt_db_gossip_history_free(&gossip_hist);
mutt_buffer_pool_release(&keyid);
- return rv;
+ return rc;
}
/* Returns the recommendation. If the recommendataion is > NO and
*/
enum AutocryptRec mutt_autocrypt_ui_recommendation(struct Email *hdr, char **keylist)
{
- enum AutocryptRec rv = AUTOCRYPT_REC_OFF;
+ enum AutocryptRec rc = AUTOCRYPT_REC_OFF;
struct AutocryptAccount *account = NULL;
struct AutocryptPeer *peer = NULL;
struct Address *recip = NULL;
mutt_addrlist_copy(&recips, &hdr->env->cc, false);
mutt_addrlist_copy(&recips, &hdr->env->bcc, false);
- rv = AUTOCRYPT_REC_NO;
+ rc = AUTOCRYPT_REC_NO;
if (TAILQ_EMPTY(&recips))
goto cleanup;
}
if (all_encrypt)
- rv = AUTOCRYPT_REC_YES;
+ rc = AUTOCRYPT_REC_YES;
else if (has_discourage)
- rv = AUTOCRYPT_REC_DISCOURAGE;
+ rc = AUTOCRYPT_REC_DISCOURAGE;
else
- rv = AUTOCRYPT_REC_AVAILABLE;
+ rc = AUTOCRYPT_REC_AVAILABLE;
if (keylist)
mutt_str_replace(keylist, mutt_b2s(keylist_buf));
mutt_addrlist_clear(&recips);
mutt_autocrypt_db_peer_free(&peer);
mutt_buffer_pool_release(&keylist_buf);
- return rv;
+ return rc;
}
int mutt_autocrypt_set_sign_as_default_key(struct Email *hdr)
{
- int rv = -1;
+ int rc = -1;
struct AutocryptAccount *account = NULL;
if (!C_Autocrypt || mutt_autocrypt_init(0) || !hdr)
mutt_str_replace(&AutocryptSignAs, account->keyid);
mutt_str_replace(&AutocryptDefaultKey, account->keyid);
- rv = 0;
+ rc = 0;
cleanup:
mutt_autocrypt_db_account_free(&account);
- return rv;
+ return rc;
}
static void write_autocrypt_header_line(FILE *fp, const char *addr,
int mutt_autocrypt_write_autocrypt_header(struct Envelope *env, FILE *fp)
{
- int rv = -1;
+ int rc = -1;
struct AutocryptAccount *account = NULL;
if (!C_Autocrypt || mutt_autocrypt_init(0) || !env)
write_autocrypt_header_line(fp, account->email_addr, account->prefer_encrypt,
account->keydata);
- rv = 0;
+ rc = 0;
cleanup:
mutt_autocrypt_db_account_free(&account);
- return rv;
+ return rc;
}
int mutt_autocrypt_write_gossip_headers(struct Envelope *env, FILE *fp)
int mutt_autocrypt_generate_gossip_list(struct Email *hdr)
{
- int rv = -1;
+ int rc = -1;
struct AutocryptPeer *peer = NULL;
struct AutocryptAccount *account = NULL;
struct Address *recip = NULL;
mutt_addrlist_clear(&recips);
mutt_autocrypt_db_account_free(&account);
mutt_autocrypt_db_peer_free(&peer);
- return rv;
+ return rc;
}
/* This is invoked during the first autocrypt initialization,
int mutt_autocrypt_db_init(int can_create)
{
- int rv = -1;
+ int rc = -1;
struct Buffer *db_path = NULL;
struct stat sb;
goto cleanup;
}
- rv = 0;
+ rc = 0;
cleanup:
mutt_buffer_pool_release(&db_path);
- return rv;
+ return rc;
}
void mutt_autocrypt_db_close(void)
int mutt_autocrypt_db_account_get(struct Address *addr, struct AutocryptAccount **account)
{
- int rv = -1, result;
+ int rc = -1, result;
struct Address *norm_addr = NULL;
norm_addr = copy_normalize_addr(addr);
if (result != SQLITE_ROW)
{
if (result == SQLITE_DONE)
- rv = 0;
+ rc = 0;
goto cleanup;
}
(*account)->prefer_encrypt = sqlite3_column_int(AccountGetStmt, 3);
(*account)->enabled = sqlite3_column_int(AccountGetStmt, 4);
- rv = 1;
+ rc = 1;
cleanup:
mutt_addr_free(&norm_addr);
sqlite3_reset(AccountGetStmt);
- return rv;
+ return rc;
}
int mutt_autocrypt_db_account_insert(struct Address *addr, const char *keyid,
const char *keydata, int prefer_encrypt)
{
- int rv = -1;
+ int rc = -1;
struct Address *norm_addr = NULL;
norm_addr = copy_normalize_addr(addr);
if (sqlite3_step(AccountInsertStmt) != SQLITE_DONE)
goto cleanup;
- rv = 0;
+ rc = 0;
cleanup:
mutt_addr_free(&norm_addr);
sqlite3_reset(AccountInsertStmt);
- return rv;
+ return rc;
}
int mutt_autocrypt_db_account_update(struct AutocryptAccount *acct)
{
- int rv = -1;
+ int rc = -1;
if (!AccountUpdateStmt)
{
if (sqlite3_step(AccountUpdateStmt) != SQLITE_DONE)
goto cleanup;
- rv = 0;
+ rc = 0;
cleanup:
sqlite3_reset(AccountUpdateStmt);
- return rv;
+ return rc;
}
int mutt_autocrypt_db_account_delete(struct AutocryptAccount *acct)
{
- int rv = -1;
+ int rc = -1;
if (!AccountDeleteStmt)
{
if (sqlite3_step(AccountDeleteStmt) != SQLITE_DONE)
goto cleanup;
- rv = 0;
+ rc = 0;
cleanup:
sqlite3_reset(AccountDeleteStmt);
- return rv;
+ return rc;
}
int mutt_autocrypt_db_account_get_all(struct AutocryptAccount ***accounts, int *num_accounts)
{
- int rv = -1, result;
+ int rc = -1, result;
sqlite3_stmt *stmt = NULL;
struct AutocryptAccount **results = NULL, *account;
int results_len = 0, results_count = 0;
if (result == SQLITE_DONE)
{
*accounts = results;
- rv = *num_accounts = results_count;
+ rc = *num_accounts = results_count;
}
else
{
cleanup:
sqlite3_finalize(stmt);
- return rv;
+ return rc;
}
struct AutocryptPeer *mutt_autocrypt_db_peer_new(void)
int mutt_autocrypt_db_peer_get(struct Address *addr, struct AutocryptPeer **peer)
{
- int rv = -1, result;
+ int rc = -1, result;
struct Address *norm_addr = NULL;
norm_addr = copy_normalize_addr(addr);
if (result != SQLITE_ROW)
{
if (result == SQLITE_DONE)
- rv = 0;
+ rc = 0;
goto cleanup;
}
(*peer)->gossip_keyid = strdup_column_text(PeerGetStmt, 7);
(*peer)->gossip_keydata = strdup_column_text(PeerGetStmt, 8);
- rv = 1;
+ rc = 1;
cleanup:
mutt_addr_free(&norm_addr);
sqlite3_reset(PeerGetStmt);
- return rv;
+ return rc;
}
int mutt_autocrypt_db_peer_insert(struct Address *addr, struct AutocryptPeer *peer)
{
- int rv = -1;
+ int rc = -1;
struct Address *norm_addr = NULL;
norm_addr = copy_normalize_addr(addr);
if (sqlite3_step(PeerInsertStmt) != SQLITE_DONE)
goto cleanup;
- rv = 0;
+ rc = 0;
cleanup:
mutt_addr_free(&norm_addr);
sqlite3_reset(PeerInsertStmt);
- return rv;
+ return rc;
}
int mutt_autocrypt_db_peer_update(struct AutocryptPeer *peer)
{
- int rv = -1;
+ int rc = -1;
if (!PeerUpdateStmt)
{
if (sqlite3_step(PeerUpdateStmt) != SQLITE_DONE)
goto cleanup;
- rv = 0;
+ rc = 0;
cleanup:
sqlite3_reset(PeerUpdateStmt);
- return rv;
+ return rc;
}
struct AutocryptPeerHistory *mutt_autocrypt_db_peer_history_new(void)
int mutt_autocrypt_db_peer_history_insert(struct Address *addr,
struct AutocryptPeerHistory *peerhist)
{
- int rv = -1;
+ int rc = -1;
struct Address *norm_addr = NULL;
norm_addr = copy_normalize_addr(addr);
if (sqlite3_step(PeerHistoryInsertStmt) != SQLITE_DONE)
goto cleanup;
- rv = 0;
+ rc = 0;
cleanup:
mutt_addr_free(&norm_addr);
sqlite3_reset(PeerHistoryInsertStmt);
- return rv;
+ return rc;
}
struct AutocryptGossipHistory *mutt_autocrypt_db_gossip_history_new(void)
int mutt_autocrypt_db_gossip_history_insert(struct Address *addr,
struct AutocryptGossipHistory *gossip_hist)
{
- int rv = -1;
+ int rc = -1;
struct Address *norm_addr = NULL;
norm_addr = copy_normalize_addr(addr);
if (sqlite3_step(GossipHistoryInsertStmt) != SQLITE_DONE)
goto cleanup;
- rv = 0;
+ rc = 0;
cleanup:
mutt_addr_free(&norm_addr);
sqlite3_reset(GossipHistoryInsertStmt);
- return rv;
+ return rc;
}
static int export_keydata(gpgme_ctx_t ctx, gpgme_key_t key, struct Buffer *keydata)
{
- int rv = -1;
+ int rc = -1;
gpgme_data_t dh = NULL;
gpgme_key_t export_keys[2];
size_t export_data_len;
gpgme_free(export_data);
export_data = NULL;
- rv = 0;
+ rc = 0;
cleanup:
gpgme_data_release(dh);
- return rv;
+ return rc;
}
/* TODO: not sure if this function will be useful in the future. */
int mutt_autocrypt_gpgme_export_key(const char *keyid, struct Buffer *keydata)
{
- int rv = -1;
+ int rc = -1;
gpgme_ctx_t ctx = NULL;
gpgme_key_t key = NULL;
if (export_keydata(ctx, key, keydata))
goto cleanup;
- rv = 0;
+ rc = 0;
cleanup:
gpgme_key_unref(key);
gpgme_release(ctx);
- return rv;
+ return rc;
}
int mutt_autocrypt_gpgme_create_key(struct Address *addr, struct Buffer *keyid,
struct Buffer *keydata)
{
- int rv = -1;
+ int rc = -1;
gpgme_ctx_t ctx = NULL;
gpgme_error_t err;
gpgme_genkey_result_t keyresult;
goto cleanup;
mutt_debug(LL_DEBUG1, "key has keydata *%s*\n", mutt_b2s(keydata));
- rv = 0;
+ rc = 0;
cleanup:
gpgme_key_unref(primary_key);
gpgme_release(ctx);
- return rv;
+ return rc;
}
int mutt_autocrypt_gpgme_import_key(const char *keydata, struct Buffer *keyid)
{
- int rv = -1;
+ int rc = -1;
gpgme_ctx_t ctx = NULL;
struct Buffer *raw_keydata = NULL;
gpgme_data_t dh = NULL;
goto cleanup;
mutt_buffer_strcpy(keyid, result->imports->fpr);
- rv = 0;
+ rc = 0;
cleanup:
gpgme_data_release(dh);
gpgme_release(ctx);
mutt_buffer_pool_release(&raw_keydata);
- return rv;
+ return rc;
}
int mutt_autocrypt_gpgme_is_valid_key(const char *keyid)
{
- int rv = 0;
+ int rc = 0;
gpgme_ctx_t ctx = NULL;
gpgme_key_t key = NULL;
if (gpgme_get_key(ctx, keyid, &key, 0))
goto cleanup;
- rv = 1;
+ rc = 1;
if (key->revoked || key->expired || key->disabled || key->invalid || !key->can_encrypt)
- rv = 0;
+ rc = 0;
cleanup:
gpgme_key_unref(key);
gpgme_release(ctx);
- return rv;
+ return rc;
}
int mutt_autocrypt_schema_update(void)
{
sqlite3_stmt *stmt = NULL;
- int rv = -1, version;
+ int rc = -1, version;
if (sqlite3_prepare_v2(AutocryptDB, "SELECT version FROM schema;", -1, &stmt, NULL) != SQLITE_OK)
goto cleanup;
/* TODO: schema version upgrades go here.
* Bump one by one, each update inside a transaction. */
- rv = 0;
+ rc = 0;
cleanup:
sqlite3_finalize(stmt);
- return rv;
+ return rc;
}