mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Show PGP error strings
This commit is contained in:
parent
482eea4fcf
commit
88fd2a25ee
@ -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)) {
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user