Browse Source

Report GPGME initialization errors.

Error out if an issue occurs either when initializing GPGME or
when building the list of public keys.
master
Damien Goutte-Gattat 2 years ago
parent
commit
944fe26a47
  1. 36
      src/yki.c

36
src/yki.c

@ -40,45 +40,43 @@ typedef struct {
} yorkie_ctx_t;
static gpgme_ctx_t
initialize_gpgme(void)
static gpgme_error_t
initialize_gpgme(gpgme_ctx_t *ctx)
{
gpgme_ctx_t ctx;
gpgme_error_t gerr;
gpgme_check_version(NULL);
gpgme_set_locale(NULL, LC_CTYPE, setlocale(LC_CTYPE, NULL));
gpgme_set_locale(NULL, LC_MESSAGES, setlocale(LC_MESSAGES, NULL));
if ( (gerr = gpgme_new(&ctx)) != GPG_ERR_NO_ERROR )
g_error("cannot initialize GPGME: %s", gpgme_strerror(gerr));
return ctx;
return gpgme_new(ctx);
}
static void
populate_public_key_list(yorkie_ctx_t *yki)
static gpgme_error_t
populate_public_key_list(gpgme_ctx_t ctx, GtkListStore *key_list)
{
GtkTreeIter iter;
gpgme_key_t key;
gpgme_error_t gerr;
gerr = gpgme_op_keylist_start(yki->gpgme, NULL, 0);
gerr = gpgme_op_keylist_start(ctx, NULL, 0);
while ( ! gerr ) {
gerr = gpgme_op_keylist_next(yki->gpgme, &key);
gerr = gpgme_op_keylist_next(ctx, &key);
if ( ! gerr ) {
if ( key->revoked || key->expired || key->disabled || key->invalid || ! key->can_encrypt )
continue;
gtk_list_store_append(yki->public_keys, &iter);
gtk_list_store_set(yki->public_keys, &iter,
gtk_list_store_append(key_list, &iter);
gtk_list_store_set(key_list, &iter,
0, FALSE,
1, key->uids[0].uid,
2, key,
-1);
}
}
if ( gpgme_err_code(gerr) == GPG_ERR_EOF )
gerr = 0;
return gerr;
}
static gpgme_key_t *
@ -199,9 +197,13 @@ main(int argc, char **argv)
if ( argc != 2 )
return 1;
yki.gpgme = initialize_gpgme();
dlg = create_encrypt_dialog(&yki);
populate_public_key_list(&yki);
if ( (gerr = initialize_gpgme(&yki.gpgme)) )
g_error("Cannot initialize GPGME: %s", gpgme_strerror(gerr));
if ( (gerr = populate_public_key_list(yki.gpgme, yki.public_keys)) )
g_error("Cannot get public keys; %s", gpgme_strerror(gerr));
if ( gtk_dialog_run(dlg) == GTK_RESPONSE_OK && can_proceed(yki) ) {
FILE *in, *out;

Loading…
Cancel
Save