/pidgin/main: 752eea995e11: we're already receiving iChat idle t...
Nathan Walp
nwalp at pidgin.im
Fri Sep 21 18:30:10 EDT 2012
Changeset: 752eea995e118066b002bf84373431de5a2a47d4
Author: Nathan Walp <nwalp at pidgin.im>
Date: 2012-09-21 18:30 -0400
Branch: default
URL: http://hg.pidgin.im/pidgin/main/rev/752eea995e11
Description:
we're already receiving iChat idle time info, may as well parse it
diffstat:
libpurple/protocols/jabber/namespaces.h | 3 +++
libpurple/protocols/jabber/presence.c | 27 ++++++++++++++++++++++++++-
libpurple/protocols/jabber/presence.h | 3 +++
3 files changed, 32 insertions(+), 1 deletions(-)
diffs (80 lines):
diff --git a/libpurple/protocols/jabber/namespaces.h b/libpurple/protocols/jabber/namespaces.h
--- a/libpurple/protocols/jabber/namespaces.h
+++ b/libpurple/protocols/jabber/namespaces.h
@@ -109,4 +109,7 @@
#define NS_GOOGLE_SESSION_PHONE "http://www.google.com/session/phone"
#define NS_GOOGLE_SESSION_VIDEO "http://www.google.com/session/video"
+/* Apple extension(s) */
+#define NS_APPLE_IDLE "http://www.apple.com/xmpp/idle"
+
#endif /* PURPLE_JABBER_NAMESPACES_H_ */
diff --git a/libpurple/protocols/jabber/presence.c b/libpurple/protocols/jabber/presence.c
--- a/libpurple/protocols/jabber/presence.c
+++ b/libpurple/protocols/jabber/presence.c
@@ -1017,7 +1017,7 @@ void jabber_presence_parse(JabberStream
pih(js, &presence, child);
}
- if (presence.delayed && presence.idle) {
+ if (presence.delayed && presence.idle && !presence.absolute_idle) {
/* Delayed and idle, so update idle time */
presence.idle = presence.idle + (time(NULL) - presence.sent);
}
@@ -1172,11 +1172,33 @@ parse_delay(JabberStream *js, JabberPres
}
static void
+parse_apple_idle(JabberStream *js, JabberPresence *presence, xmlnode *x)
+{
+ xmlnode *since = xmlnode_get_child(x, "idle-since");
+ if (since) {
+ const char *stamp = xmlnode_get_data(since);
+ if (stamp) {
+ time_t tstamp = purple_str_to_time(stamp, TRUE, NULL, NULL, NULL);
+ if (tstamp != 0) {
+ presence->idle = time(NULL) - tstamp;
+ if(presence->idle < 0) {
+ purple_debug_warning("jabber", "Received bogus idle timestamp %s\n", stamp);
+ presence->idle = 0;
+ } else {
+ presence->absolute_idle = TRUE;
+ }
+ }
+ }
+ }
+}
+
+static void
parse_idle(JabberStream *js, JabberPresence *presence, xmlnode *query)
{
const gchar *seconds = xmlnode_get_attrib(query, "seconds");
if (seconds) {
presence->idle = atoi(seconds);
+ presence->absolute_idle = FALSE;
if (presence->idle < 0) {
purple_debug_warning("jabber", "Received bogus idle time %s\n", seconds);
presence->idle = 0;
@@ -1276,6 +1298,9 @@ void jabber_presence_init(void)
jabber_presence_register_handler("x", NS_DELAYED_DELIVERY_LEGACY, parse_delay);
jabber_presence_register_handler("x", "http://jabber.org/protocol/muc#user", parse_muc_user);
jabber_presence_register_handler("x", "vcard-temp:x:update", parse_vcard_avatar);
+
+ /* Apple idle */
+ jabber_presence_register_handler("x", NS_APPLE_IDLE, parse_apple_idle);
}
void jabber_presence_uninit(void)
diff --git a/libpurple/protocols/jabber/presence.h b/libpurple/protocols/jabber/presence.h
--- a/libpurple/protocols/jabber/presence.h
+++ b/libpurple/protocols/jabber/presence.h
@@ -71,6 +71,9 @@ struct _JabberPresence {
gboolean delayed;
time_t sent;
int idle;
+ /* this is TRUE if we got the idle time as an absolute timestamp
+ * and it shouldn't be adjusted if the presence was delayed */
+ gboolean absolute_idle;
};
typedef void (JabberPresenceHandler)(JabberStream *js, JabberPresence *presence,
More information about the Commits
mailing list