From dd206ef637e8f29d5b78f2b72ff27badaec1b14e Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 29 Jun 2015 23:48:41 +0100 Subject: WIP fix for #516, needs memory cleanup --- src/xmpp/message.c | 24 ++++++++++-------------- src/xmpp/stanza.c | 19 ++++++++++++------- src/xmpp/stanza.h | 2 +- 3 files changed, 23 insertions(+), 22 deletions(-) (limited to 'src/xmpp') diff --git a/src/xmpp/message.c b/src/xmpp/message.c index 863c2d87..0d305496 100644 --- a/src/xmpp/message.c +++ b/src/xmpp/message.c @@ -559,10 +559,9 @@ _groupchat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void } // determine if the notifications happened whilst offline - GTimeVal tv_stamp; - gboolean delayed = stanza_get_delay(stanza, &tv_stamp); - if (delayed) { - sv_ev_room_history(jid->barejid, jid->resourcepart, tv_stamp, message); + GDateTime *timestamp = stanza_get_delay(stanza); + if (timestamp) { + sv_ev_room_history(jid->barejid, jid->resourcepart, timestamp, message); } else { sv_ev_room_message(jid->barejid, jid->resourcepart, message); } @@ -663,10 +662,9 @@ _private_chat_handler(xmpp_stanza_t * const stanza, const char * const fulljid) return; } - GTimeVal tv_stamp; - gboolean delayed = stanza_get_delay(stanza, &tv_stamp); - if (delayed) { - sv_ev_delayed_private_message(fulljid, message, tv_stamp); + GDateTime *timestamp = stanza_get_delay(stanza); + if (timestamp) { + sv_ev_delayed_private_message(fulljid, message, timestamp); } else { sv_ev_incoming_private_message(fulljid, message); } @@ -761,15 +759,13 @@ _chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * con } // standard chat message, use jid without resource - GTimeVal tv_stamp; - gboolean delayed = stanza_get_delay(stanza, &tv_stamp); - + GDateTime *timestamp = stanza_get_delay(stanza); xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_BODY); if (body) { char *message = xmpp_stanza_get_text(body); if (message) { - if (delayed) { - sv_ev_delayed_message(jid->barejid, message, tv_stamp); + if (timestamp) { + sv_ev_delayed_message(jid->barejid, message, timestamp); } else { char *enc_message = NULL; xmpp_stanza_t *x = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_ENCRYPTED); @@ -787,7 +783,7 @@ _chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * con } // handle chat sessions and states - if (!delayed && jid->resourcepart) { + if (!timestamp && jid->resourcepart) { gboolean gone = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_GONE) != NULL; gboolean typing = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_COMPOSING) != NULL; gboolean paused = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_PAUSED) != NULL; diff --git a/src/xmpp/stanza.c b/src/xmpp/stanza.c index 1f25239b..4999c81b 100644 --- a/src/xmpp/stanza.c +++ b/src/xmpp/stanza.c @@ -982,17 +982,20 @@ stanza_create_ping_iq(xmpp_ctx_t *ctx, const char * const target) return iq; } -gboolean -stanza_get_delay(xmpp_stanza_t * const stanza, GTimeVal *tv_stamp) +GDateTime* +stanza_get_delay(xmpp_stanza_t * const stanza) { + GTimeVal utc_stamp; // first check for XEP-0203 delayed delivery xmpp_stanza_t *delay = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_DELAY); if (delay) { char *xmlns = xmpp_stanza_get_attribute(delay, STANZA_ATTR_XMLNS); if (xmlns && (strcmp(xmlns, "urn:xmpp:delay") == 0)) { char *stamp = xmpp_stanza_get_attribute(delay, STANZA_ATTR_STAMP); - if (stamp && (g_time_val_from_iso8601(stamp, tv_stamp))) { - return TRUE; + if (stamp && (g_time_val_from_iso8601(stamp, &utc_stamp))) { + GDateTime *utc_datetime = g_date_time_new_from_timeval_utc(&utc_stamp); + GDateTime *local_datetime = g_date_time_to_local(utc_datetime); + return local_datetime; } } } @@ -1004,13 +1007,15 @@ stanza_get_delay(xmpp_stanza_t * const stanza, GTimeVal *tv_stamp) char *xmlns = xmpp_stanza_get_attribute(x, STANZA_ATTR_XMLNS); if (xmlns && (strcmp(xmlns, "jabber:x:delay") == 0)) { char *stamp = xmpp_stanza_get_attribute(x, STANZA_ATTR_STAMP); - if (stamp && (g_time_val_from_iso8601(stamp, tv_stamp))) { - return TRUE; + if (stamp && (g_time_val_from_iso8601(stamp, &utc_stamp))) { + GDateTime *utc_datetime = g_date_time_new_from_timeval_utc(&utc_stamp); + GDateTime *local_datetime = g_date_time_to_local(utc_datetime); + return local_datetime; } } } - return FALSE; + return NULL; } char * diff --git a/src/xmpp/stanza.h b/src/xmpp/stanza.h index 042b6aea..2dd1a141 100644 --- a/src/xmpp/stanza.h +++ b/src/xmpp/stanza.h @@ -223,7 +223,7 @@ xmpp_stanza_t* stanza_create_mediated_invite(xmpp_ctx_t *ctx, const char * const gboolean stanza_contains_chat_state(xmpp_stanza_t *stanza); -gboolean stanza_get_delay(xmpp_stanza_t * const stanza, GTimeVal *tv_stamp); +GDateTime* stanza_get_delay(xmpp_stanza_t * const stanza); gboolean stanza_is_muc_presence(xmpp_stanza_t * const stanza); gboolean stanza_is_muc_self_presence(xmpp_stanza_t * const stanza, -- cgit 1.4.1-2-gfad0