changeset 1015:579299b1c9b2

Add /request last
author Mikael Berthe <mikael@lilotux.net>
date Mon, 13 Nov 2006 21:58:18 +0100
parents 99c5278bf6b8
children 4d3c48844746
files mcabber/src/commands.c mcabber/src/jab_iq.c mcabber/src/jab_priv.h mcabber/src/jabglue.c mcabber/src/jabglue.h
diffstat 5 files changed, 83 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mcabber/src/commands.c	Sun Nov 12 22:25:14 2006 +0100
+++ b/mcabber/src/commands.c	Mon Nov 13 21:58:18 2006 +0100
@@ -212,6 +212,7 @@
   compl_add_category_word(COMPL_AUTH, "request_unsubscribe");
 
   // Request (query) category
+  compl_add_category_word(COMPL_REQUEST, "last");
   compl_add_category_word(COMPL_REQUEST, "time");
   compl_add_category_word(COMPL_REQUEST, "vcard");
   compl_add_category_word(COMPL_REQUEST, "version");
@@ -2248,6 +2249,8 @@
       numtype = iqreq_version;
     else if (!strcasecmp(type, "time"))
       numtype = iqreq_time;
+    else if (!strcasecmp(type, "last"))
+      numtype = iqreq_last;
     else if (!strcasecmp(type, "vcard"))
       numtype = iqreq_vcard;
     else if (!strcasecmp(type, "show_list")) {
@@ -2260,7 +2263,7 @@
 
   if (!type || !numtype) {
     scr_LogPrint(LPRINT_NORMAL,
-                 "Please specify a query type (version, time).");
+                 "Please specify a query type (version, time...).");
     free_arg_lst(paramlst);
     return;
   }
@@ -2293,6 +2296,7 @@
     switch (numtype) {
       case iqreq_version:
       case iqreq_time:
+      case iqreq_last:
       case iqreq_vcard:
           jb_request(jid, numtype);
           break;
--- a/mcabber/src/jab_iq.c	Sun Nov 12 22:25:14 2006 +0100
+++ b/mcabber/src/jab_iq.c	Mon Nov 13 21:58:18 2006 +0100
@@ -369,6 +369,79 @@
   jab_send(jc, iqn->xmldata);
 }
 
+static void iqscallback_last(eviqs *iqp, xmlnode xml_result, guint iqcontext)
+{
+  xmlnode ansqry;
+  char *p;
+  char *bjid;
+  char *buf;
+
+  // Leave now if we cannot process xml_result
+  if (!xml_result || iqcontext) return;
+
+  ansqry = xmlnode_get_tag(xml_result, "query");
+  if (!ansqry) {
+    scr_LogPrint(LPRINT_LOGNORM, "Invalid IQ:last result!");
+    return;
+  }
+  // Display IQ result sender...
+  p = xmlnode_get_attrib(xml_result, "from");
+  if (!p) {
+    scr_LogPrint(LPRINT_LOGNORM, "Invalid IQ:last result (no sender name).");
+    return;
+  }
+  bjid = p;
+
+  buf = g_strdup_printf("Received IQ:last result from <%s>", bjid);
+  scr_LogPrint(LPRINT_LOGNORM, "%s", buf);
+
+  // bjid should now really be the "bare JID", let's strip the resource
+  p = strchr(bjid, JID_RESOURCE_SEPARATOR);
+  if (p) *p = '\0';
+
+  scr_WriteIncomingMessage(bjid, buf, 0, HBB_PREFIX_INFO);
+  g_free(buf);
+
+  // Get result data...
+  p = xmlnode_get_attrib(ansqry, "seconds");
+  if (p) {
+    long int s;
+    GString *sbuf;
+    sbuf = g_string_new("Idle time: ");
+    s = atol(p);
+    // Days
+    if (s > 86400L) {
+      g_string_append_printf(sbuf, "%ldd ", s/86400L);
+      s %= 86400L;
+    }
+    // hh:mm:ss
+    g_string_append_printf(sbuf, "%02ld:", s/3600L);
+    s %= 3600L;
+    g_string_append_printf(sbuf, "%02ld:%02ld", s/60L, s%60L);
+    scr_WriteIncomingMessage(bjid, sbuf->str, 0, HBB_PREFIX_NONE);
+    g_string_free(sbuf, TRUE);
+  } else {
+    scr_WriteIncomingMessage(bjid, "No idle time reported.",
+                             0, HBB_PREFIX_NONE);
+  }
+  p = xmlnode_get_data(ansqry);
+  if (p) {
+    buf = g_strdup_printf("Status message: %s", p);
+    scr_WriteIncomingMessage(bjid, buf, 0, HBB_PREFIX_INFO);
+    g_free(buf);
+  }
+}
+
+void request_last(const char *fulljid)
+{
+  eviqs *iqn;
+
+  iqn = iqs_new(JPACKET__GET, NS_LAST, "last", IQS_DEFAULT_TIMEOUT);
+  xmlnode_put_attrib(iqn->xmldata, "to", fulljid);
+  iqn->callback = &iqscallback_last;
+  jab_send(jc, iqn->xmldata);
+}
+
 static void display_vcard_item(const char *bjid, const char *label,
                                enum vcard_attr vcard_attrib, const char *text)
 {
--- a/mcabber/src/jab_priv.h	Sun Nov 12 22:25:14 2006 +0100
+++ b/mcabber/src/jab_priv.h	Mon Nov 13 21:58:18 2006 +0100
@@ -44,6 +44,7 @@
 void iqscallback_auth(eviqs *iqp, xmlnode xml_result);
 void request_version(const char *fulljid);
 void request_time(const char *fulljid);
+void request_last(const char *fulljid);
 void request_vcard(const char *barejid);
 void send_storage_bookmarks(void);
 
--- a/mcabber/src/jabglue.c	Sun Nov 12 22:25:14 2006 +0100
+++ b/mcabber/src/jabglue.c	Mon Nov 13 21:58:18 2006 +0100
@@ -943,6 +943,9 @@
   } else if (reqtype == iqreq_time) {
     request_fn = &request_time;
     strreqtype = "time";
+  } else if (reqtype == iqreq_last) {
+    request_fn = &request_last;
+    strreqtype = "last";
   } else if (reqtype == iqreq_vcard) {
     // Special case
   } else
--- a/mcabber/src/jabglue.h	Sun Nov 12 22:25:14 2006 +0100
+++ b/mcabber/src/jabglue.h	Mon Nov 13 21:58:18 2006 +0100
@@ -31,6 +31,7 @@
   iqreq_none,
   iqreq_version,
   iqreq_time,
+  iqreq_last,
   iqreq_vcard
 };