diff options
author | James Booth <boothj5@gmail.com> | 2015-12-15 00:38:16 +0000 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2015-12-15 00:38:16 +0000 |
commit | 88fd2a25ee8fdd9f2f8f36f3a705364800206867 (patch) | |
tree | d49752fd8533c1a4ecc295e6a72750ab78727331 | |
parent | 482eea4fcf68b9f2bd9f8d6f1db98fe313bef141 (diff) | |
download | profani-tty-88fd2a25ee8fdd9f2f8f36f3a705364800206867.tar.gz |
Show PGP error strings
-rw-r--r-- | src/command/commands.c | 13 | ||||
-rw-r--r-- | src/event/server_events.c | 16 | ||||
-rw-r--r-- | src/pgp/gpg.c | 14 | ||||
-rw-r--r-- | src/pgp/gpg.h | 2 | ||||
-rw-r--r-- | tests/unittests/pgp/stub_gpg.c | 2 |
5 files changed, 33 insertions, 14 deletions
diff --git a/src/command/commands.c b/src/command/commands.c index 6db8f5d3..53f06b95 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -651,12 +651,14 @@ cmd_account(ProfWin *window, const char *const command, gchar **args) cons_show(""); } else if (strcmp(property, "pgpkeyid") == 0) { #ifdef HAVE_LIBGPGME - if (!p_gpg_valid_key(value)) { - cons_show("Invalid PGP key ID specified, see /pgp keys"); + char *err_str = NULL; + if (!p_gpg_valid_key(value, &err_str)) { + cons_show("Invalid PGP key ID specified: %s, see /pgp keys", err_str); } else { accounts_set_pgp_keyid(account_name, value); cons_show("Updated PGP key ID for account %s: %s", account_name, value); } + free(err_str); #else cons_show("PGP support is not included in this build."); #endif @@ -5319,11 +5321,14 @@ cmd_pgp(ProfWin *window, const char *const command, gchar **args) } ProfAccount *account = accounts_get_account(jabber_get_account_name()); - if (!p_gpg_valid_key(account->pgp_keyid)) { - ui_current_print_formatted_line('!', 0, "You must specify a valid PGP key ID for this account to start PGP encryption."); + char *err_str = NULL; + if (!p_gpg_valid_key(account->pgp_keyid, &err_str)) { + ui_current_print_formatted_line('!', 0, "Invalid PGP key ID %s: %s, cannot start PGP encryption.", account->pgp_keyid, err_str); + free(err_str); account_free(account); return TRUE; } + free(err_str); account_free(account); if (!p_gpg_available(chatwin->barejid)) { diff --git a/src/event/server_events.c b/src/event/server_events.c index 5b4bed05..555bd9f6 100644 --- a/src/event/server_events.c +++ b/src/event/server_events.c @@ -102,11 +102,21 @@ sv_ev_roster_received(void) ui_show_roster(); } - char *account = jabber_get_account_name(); + char *account_name = jabber_get_account_name(); + + // check pgp key valid if specified + ProfAccount *account = accounts_get_account(account_name); + if (account && account->pgp_keyid) { + char *err_str = NULL; + if (!p_gpg_valid_key(account->pgp_keyid, &err_str)) { + cons_show_error("Invalid PGP key ID specified: %s, %s", account->pgp_keyid, err_str); + } + free(err_str); + } // send initial presence - resource_presence_t conn_presence = accounts_get_login_presence(account); - char *last_activity_str = accounts_get_last_activity(account); + resource_presence_t conn_presence = accounts_get_login_presence(account_name); + char *last_activity_str = accounts_get_last_activity(account_name); if (last_activity_str) { GDateTime *nowdt = g_date_time_new_now_utc(); diff --git a/src/pgp/gpg.c b/src/pgp/gpg.c index 7828c934..b40df96f 100644 --- a/src/pgp/gpg.c +++ b/src/pgp/gpg.c @@ -424,12 +424,13 @@ p_gpg_libver(void) } gboolean -p_gpg_valid_key(const char *const keyid) +p_gpg_valid_key(const char *const keyid, char **err_str) { gpgme_ctx_t ctx; gpgme_error_t error = gpgme_new(&ctx); if (error) { log_error("GPG: Failed to create gpgme context. %s %s", gpgme_strsource(error), gpgme_strerror(error)); + *err_str = strdup(gpgme_strerror(error)); return FALSE; } @@ -438,18 +439,21 @@ p_gpg_valid_key(const char *const keyid) if (error || key == NULL) { log_error("GPG: Failed to get key. %s %s", gpgme_strsource(error), gpgme_strerror(error)); + *err_str = strdup(gpgme_strerror(error)); gpgme_release(ctx); return FALSE; } - if (key) { + if (key == NULL) { + *err_str = strdup("Unknown error"); gpgme_release(ctx); - gpgme_key_unref(key); - return TRUE; + return FALSE; } gpgme_release(ctx); - return FALSE; + gpgme_key_unref(key); + return TRUE; + } gboolean diff --git a/src/pgp/gpg.h b/src/pgp/gpg.h index f699e889..5149343f 100644 --- a/src/pgp/gpg.h +++ b/src/pgp/gpg.h @@ -59,7 +59,7 @@ GHashTable* p_gpg_list_keys(void); void p_gpg_free_keys(GHashTable *keys); gboolean p_gpg_addkey(const char *const jid, const char *const keyid); GHashTable* p_gpg_pubkeys(void); -gboolean p_gpg_valid_key(const char *const keyid); +gboolean p_gpg_valid_key(const char *const keyid, char **err_str); gboolean p_gpg_available(const char *const barejid); const char* p_gpg_libver(void); char* p_gpg_sign(const char *const str, const char *const fp); diff --git a/tests/unittests/pgp/stub_gpg.c b/tests/unittests/pgp/stub_gpg.c index b31dc34c..02ccb4c8 100644 --- a/tests/unittests/pgp/stub_gpg.c +++ b/tests/unittests/pgp/stub_gpg.c @@ -28,7 +28,7 @@ char* p_gpg_sign(const char * const str, const char * const fp) return NULL; } -gboolean p_gpg_valid_key(const char * const keyid) +gboolean p_gpg_valid_key(const char * const keyid, char **err_str) { return FALSE; } |