1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Merge branch 'master' into osx-functional

This commit is contained in:
James Booth 2015-12-15 00:46:52 +00:00
commit 904b13a994
7 changed files with 65 additions and 40 deletions

View File

@ -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)) {

View File

@ -48,6 +48,7 @@
#include "window_list.h"
#include "config/tlscerts.h"
#include "profanity.h"
#include "event/client_events.h"
#ifdef HAVE_LIBOTR
#include "otr/otr.h"
@ -100,6 +101,46 @@ sv_ev_roster_received(void)
if (prefs_get_boolean(PREF_ROSTER)) {
ui_show_roster();
}
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_name);
char *last_activity_str = accounts_get_last_activity(account_name);
if (last_activity_str) {
GDateTime *nowdt = g_date_time_new_now_utc();
GTimeVal lasttv;
gboolean res = g_time_val_from_iso8601(last_activity_str, &lasttv);
if (res) {
GDateTime *lastdt = g_date_time_new_from_timeval_utc(&lasttv);
GTimeSpan diff_micros = g_date_time_difference(nowdt, lastdt);
int diff_secs = (diff_micros / 1000) / 1000;
if (prefs_get_boolean(PREF_LASTACTIVITY)) {
cl_ev_presence_send(conn_presence, NULL, diff_secs);
} else {
cl_ev_presence_send(conn_presence, NULL, 0);
}
g_date_time_unref(lastdt);
} else {
cl_ev_presence_send(conn_presence, NULL, 0);
}
free(last_activity_str);
g_date_time_unref(nowdt);
} else {
cl_ev_presence_send(conn_presence, NULL, 0);
}
}
void

View File

@ -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

View File

@ -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);

View File

@ -336,35 +336,6 @@ _roster_result_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, voi
sv_ev_roster_received();
char *account = jabber_get_account_name();
resource_presence_t conn_presence = accounts_get_login_presence(account);
char *last_activity_str = accounts_get_last_activity(account);
if (last_activity_str) {
GDateTime *nowdt = g_date_time_new_now_utc();
GTimeVal lasttv;
gboolean res = g_time_val_from_iso8601(last_activity_str, &lasttv);
if (res) {
GDateTime *lastdt = g_date_time_new_from_timeval_utc(&lasttv);
GTimeSpan diff_micros = g_date_time_difference(nowdt, lastdt);
int diff_secs = (diff_micros / 1000) / 1000;
if (prefs_get_boolean(PREF_LASTACTIVITY)) {
cl_ev_presence_send(conn_presence, NULL, diff_secs);
} else {
cl_ev_presence_send(conn_presence, NULL, 0);
}
g_date_time_unref(lastdt);
} else {
cl_ev_presence_send(conn_presence, NULL, 0);
}
free(last_activity_str);
g_date_time_unref(nowdt);
} else {
cl_ev_presence_send(conn_presence, NULL, 0);
}
return 1;
}

View File

@ -195,3 +195,7 @@ void accounts_clear_otr(const char * const account_name) {}
void accounts_clear_pgp_keyid(const char * const account_name) {}
void accounts_clear_script_start(const char * const account_name) {}
void accounts_add_otr_policy(const char * const account_name, const char * const contact_jid, const char * const policy) {}
char* accounts_get_last_activity(const char *const account_name)
{
return NULL;
}

View File

@ -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;
}