about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2015-10-14 21:45:19 +0100
committerJames Booth <boothj5@gmail.com>2015-10-14 21:45:19 +0100
commit1fd2a8a4e91e2bdb21a6ad5643eee875894001fb (patch)
tree37d7a7fb615b5ec1f1c0a9eb1cf5205838924359 /src
parent5fb8acb17fcf52cbab6abbeb7d34a5bc5de2dfac (diff)
downloadprofani-tty-1fd2a8a4e91e2bdb21a6ad5643eee875894001fb.tar.gz
Send service-unavailable when lastactivity disabled
Diffstat (limited to 'src')
-rw-r--r--src/xmpp/iq.c32
1 files changed, 30 insertions, 2 deletions
diff --git a/src/xmpp/iq.c b/src/xmpp/iq.c
index ba2d8e63..99327b41 100644
--- a/src/xmpp/iq.c
+++ b/src/xmpp/iq.c
@@ -1094,7 +1094,11 @@ _last_activity_get_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanz
     xmpp_ctx_t *ctx = connection_get_ctx();
     const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
 
-    if (from) {
+    if (!from) {
+        return 1;
+    }
+
+    if (prefs_get_boolean(PREF_LASTACTIVITY)) {
         int idls_secs = ui_get_idle_time() / 1000;
         char str[50];
         sprintf(str, "%d", idls_secs);
@@ -1111,10 +1115,34 @@ _last_activity_get_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanz
         xmpp_stanza_set_attribute(query, "seconds", str);
 
         xmpp_stanza_add_child(response, query);
+        xmpp_stanza_release(query);
+
+        xmpp_send(conn, response);
+
+        xmpp_stanza_release(response);
+    } else {
+        xmpp_stanza_t *response = xmpp_stanza_new(ctx);
+        xmpp_stanza_set_name(response, STANZA_NAME_IQ);
+        xmpp_stanza_set_id(response, xmpp_stanza_get_id(stanza));
+        xmpp_stanza_set_attribute(response, STANZA_ATTR_TO, from);
+        xmpp_stanza_set_type(response, STANZA_TYPE_ERROR);
+
+        xmpp_stanza_t *error = xmpp_stanza_new(ctx);
+        xmpp_stanza_set_name(error, STANZA_NAME_ERROR);
+        xmpp_stanza_set_type(error, "cancel");
+
+        xmpp_stanza_t *service_unavailable = xmpp_stanza_new(ctx);
+        xmpp_stanza_set_name(service_unavailable, "service-unavailable");
+        xmpp_stanza_set_ns(service_unavailable, "urn:ietf:params:xml:ns:xmpp-stanzas");
+
+        xmpp_stanza_add_child(error, service_unavailable);
+        xmpp_stanza_release(service_unavailable);
+
+        xmpp_stanza_add_child(response, error);
+        xmpp_stanza_release(error);
 
         xmpp_send(conn, response);
 
-        xmpp_stanza_release(query);
         xmpp_stanza_release(response);
     }