From 8ebc1d4ac17bbc6b373ecdc3bf9ca5b0ac20b263 Mon Sep 17 00:00:00 2001 From: James Booth Date: Thu, 7 May 2015 22:22:28 +0100 Subject: Moved pgp signature verification to sv_ev_contact_online --- src/event/server_events.c | 11 ++++++++++- src/event/server_events.h | 3 +-- src/xmpp/presence.c | 19 ++++++++----------- tests/pgp/stub_gpg.c | 1 + tests/test_server_events.c | 6 +++--- 5 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/event/server_events.c b/src/event/server_events.c index e2e910a3..270e7c98 100644 --- a/src/event/server_events.c +++ b/src/event/server_events.c @@ -47,6 +47,9 @@ #ifdef HAVE_LIBOTR #include "otr/otr.h" #endif +#ifdef HAVE_LIBGPGME +#include "pgp/gpg.h" +#endif #include "ui/ui.h" @@ -280,7 +283,7 @@ sv_ev_contact_offline(char *barejid, char *resource, char *status) } void -sv_ev_contact_online(char *barejid, Resource *resource, GDateTime *last_activity) +sv_ev_contact_online(char *barejid, Resource *resource, GDateTime *last_activity, char *pgpsig) { gboolean updated = roster_update_presence(barejid, resource, last_activity); @@ -288,6 +291,12 @@ sv_ev_contact_online(char *barejid, Resource *resource, GDateTime *last_activity ui_contact_online(barejid, resource, last_activity); } +#ifdef HAVE_LIBGPGME + if (pgpsig) { + p_gpg_verify(barejid, pgpsig); + } +#endif + rosterwin_roster(); chat_session_remove(barejid); } diff --git a/src/event/server_events.h b/src/event/server_events.h index 46d485da..c663cd3a 100644 --- a/src/event/server_events.h +++ b/src/event/server_events.h @@ -62,8 +62,7 @@ void sv_ev_gone(const char * const barejid, const char * const resource); void sv_ev_subscription(const char *from, jabber_subscr_t type); void sv_ev_message_receipt(char *barejid, char *id); void sv_ev_contact_offline(char *contact, char *resource, char *status); -void sv_ev_contact_online(char *contact, Resource *resource, - GDateTime *last_activity); +void sv_ev_contact_online(char *contact, Resource *resource, GDateTime *last_activity, char *pgpkey); void sv_ev_leave_room(const char * const room); void sv_ev_room_destroy(const char * const room); void sv_ev_room_occupant_offline(const char * const room, const char * const nick, diff --git a/src/xmpp/presence.c b/src/xmpp/presence.c index e65b463d..0a7b5c45 100644 --- a/src/xmpp/presence.c +++ b/src/xmpp/presence.c @@ -619,16 +619,6 @@ _available_handler(xmpp_conn_t * const conn, log_debug("Presence available handler fired for: %s", jid); } -#ifdef HAVE_LIBGPGME - xmpp_stanza_t *x = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_SIGNED); - if (x) { - char *sign = xmpp_stanza_get_text(x); - if (sign) { - p_gpg_verify(xmpp_presence->jid->barejid, sign); - } - } -#endif - const char *my_jid_str = xmpp_conn_get_jid(conn); Jid *my_jid = jid_create(my_jid_str); @@ -645,7 +635,14 @@ _available_handler(xmpp_conn_t * const conn, if (g_strcmp0(xmpp_presence->jid->barejid, my_jid->barejid) == 0) { connection_add_available_resource(resource); } else { - sv_ev_contact_online(xmpp_presence->jid->barejid, resource, xmpp_presence->last_activity); + char *pgpsig = NULL; + xmpp_stanza_t *x = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_SIGNED); + if (x) { + pgpsig = xmpp_stanza_get_text(x); + } + sv_ev_contact_online(xmpp_presence->jid->barejid, resource, xmpp_presence->last_activity, pgpsig); + xmpp_ctx_t *ctx = connection_get_ctx(); + xmpp_free(ctx, pgpsig); } jid_destroy(my_jid); diff --git a/tests/pgp/stub_gpg.c b/tests/pgp/stub_gpg.c index 14cdfe96..b8150d0a 100644 --- a/tests/pgp/stub_gpg.c +++ b/tests/pgp/stub_gpg.c @@ -23,3 +23,4 @@ const char* p_gpg_libver(void) void p_gpg_free_key(ProfPGPKey *key) {} +void p_gpg_verify(const char * const barejid, const char *const sign) {} diff --git a/tests/test_server_events.c b/tests/test_server_events.c index 58489807..fac1ac38 100644 --- a/tests/test_server_events.c +++ b/tests/test_server_events.c @@ -26,7 +26,7 @@ void console_shows_online_presence_when_set_online(void **state) expect_memory(ui_contact_online, resource, resource, sizeof(resource)); expect_value(ui_contact_online, last_activity, NULL); - sv_ev_contact_online(barejid, resource, NULL); + sv_ev_contact_online(barejid, resource, NULL, NULL); roster_clear(); } @@ -43,7 +43,7 @@ void console_shows_online_presence_when_set_all(void **state) expect_memory(ui_contact_online, resource, resource, sizeof(resource)); expect_value(ui_contact_online, last_activity, NULL); - sv_ev_contact_online(barejid, resource, NULL); + sv_ev_contact_online(barejid, resource, NULL, NULL); roster_clear(); } @@ -60,7 +60,7 @@ void console_shows_dnd_presence_when_set_all(void **state) expect_memory(ui_contact_online, resource, resource, sizeof(resource)); expect_value(ui_contact_online, last_activity, NULL); - sv_ev_contact_online(barejid, resource, NULL); + sv_ev_contact_online(barejid, resource, NULL, NULL); roster_clear(); } -- cgit 1.4.1-2-gfad0