From 8e90f7a4140f3d5ebb076b23ee10b2d296340ba8 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 9 Dec 2012 03:07:33 +0000 Subject: Handle idle time from contacts --- src/stanza.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'src/stanza.c') diff --git a/src/stanza.c b/src/stanza.c index ba3e0b16..9b253891 100644 --- a/src/stanza.c +++ b/src/stanza.c @@ -20,6 +20,7 @@ * */ +#include #include #include @@ -359,3 +360,34 @@ stanza_get_new_nick(xmpp_stanza_t * const stanza) return NULL; } } + +int +stanza_get_idle_time(xmpp_stanza_t * const stanza) +{ + xmpp_stanza_t *query = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_QUERY); + + if (query == NULL) { + return 0; + } + + char *ns = xmpp_stanza_get_ns(query); + if (ns == NULL) { + return 0; + } + + if (strcmp(ns, STANZA_NS_LASTACTIVITY) != 0) { + return 0; + } + + char *seconds_str = xmpp_stanza_get_attribute(query, STANZA_ATTR_SECONDS); + if (seconds_str == NULL) { + return 0; + } + + int result = atoi(seconds_str); + if (result < 1) { + return 0; + } else { + return result; + } +} -- cgit 1.4.1-2-gfad0