diff mcabber/src/jab_iq.c @ 1261:704adf4df2d0

Send service-unavailable when Last Activity is disabled According to XEP-0012, the client should return a <service-unavailable/> error when it doesn't wish to divulge the information. This patch also adds a new option: iq_last_disable_when_notavail.
author Mikael Berthe <mikael@lilotux.net>
date Sun, 01 Jul 2007 12:22:54 +0200
parents ceada40bbe20
children dbc907b2d92f
line wrap: on
line diff
--- a/mcabber/src/jab_iq.c	Wed Jun 27 23:03:22 2007 +0200
+++ b/mcabber/src/jab_iq.c	Sun Jul 01 12:22:54 2007 +0200
@@ -931,6 +931,26 @@
   xmlnode_free(x);
 }
 
+// FIXME  highly duplicated code
+static void send_iq_not_available(jconn conn, char *from, xmlnode xmldata)
+{
+  xmlnode x, y, z;
+  // Not available.
+  x = xmlnode_dup(xmldata);
+  xmlnode_put_attrib(x, "to", xmlnode_get_attrib(xmldata, "from"));
+  xmlnode_hide_attrib(x, "from");
+
+  xmlnode_put_attrib(x, "type", TMSG_ERROR);
+  y = xmlnode_insert_tag(x, TMSG_ERROR);
+  xmlnode_put_attrib(y, "code", "503");
+  xmlnode_put_attrib(y, "type", "cancel");
+  z = xmlnode_insert_tag(y, "service-unavailable");
+  xmlnode_put_attrib(z, "xmlns", NS_XMPP_STANZAS);
+
+  jab_send(conn, x);
+  xmlnode_free(x);
+}
+
 /*
 static void send_iq_commands_bad_action(jconn conn, char *from, xmlnode xmldata)
 {
@@ -1523,9 +1543,13 @@
     handle_iq_disco_items(conn, from, id, xmldata);
   } else if (ns && !strcmp(ns, NS_VERSION)) {
     handle_iq_version(conn, from, id, xmldata);
-  } else if (ns && !strcmp(ns, NS_LAST) &&
-             !settings_opt_get_int("iq_last_disable")) {
-    handle_iq_last(conn, from, id, xmldata);
+  } else if (ns && !strcmp(ns, NS_LAST)) {
+    if (!settings_opt_get_int("iq_last_disable") &&
+        (!settings_opt_get_int("iq_last_disable_when_notavail") ||
+         jb_getstatus() != notavail))
+      handle_iq_last(conn, from, id, xmldata);
+    else
+      send_iq_not_available(conn, from, xmldata);
   } else if (ns && !strcmp(ns, NS_TIME)) {
     handle_iq_time(conn, from, id, xmldata);
   } else {