about summary refs log tree commit diff stats
path: root/src/stanza.c
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2012-12-09 03:07:33 +0000
committerJames Booth <boothj5@gmail.com>2012-12-09 03:07:33 +0000
commit8e90f7a4140f3d5ebb076b23ee10b2d296340ba8 (patch)
tree903dfcdfc48991e8cefc13519b774f2cad38c8ea /src/stanza.c
parent6b9962434849587a54608ea995dcef48cc86ff39 (diff)
downloadprofani-tty-8e90f7a4140f3d5ebb076b23ee10b2d296340ba8.tar.gz
Handle idle time from contacts
Diffstat (limited to 'src/stanza.c')
-rw-r--r--src/stanza.c32
1 files changed, 32 insertions, 0 deletions
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 <stdlib.h>
 #include <string.h>
 
 #include <glib.h>
@@ -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;
+    }
+}