[Tkabber-dev] [tclxmpp] r115 committed - * xmpp/ping.tcl, xmpp/pkgIndex.tcl: Added support for XMPP Ping...

codesite-noreply at google.com codesite-noreply at google.com
Mon Aug 3 19:56:25 MSD 2009


Revision: 115
Author: sgolovan
Date: Mon Aug  3 08:55:40 2009
Log: 	* xmpp/ping.tcl, xmpp/pkgIndex.tcl: Added support for XMPP Ping
	  (XEP-0199). Client-side only for now.

http://code.google.com/p/tclxmpp/source/detail?r=115

Added:
  /trunk/xmpp/ping.tcl
Modified:
  /trunk/ChangeLog

=======================================
--- /dev/null
+++ /trunk/xmpp/ping.tcl	Mon Aug  3 08:55:40 2009
@@ -0,0 +1,88 @@
+# ping.tcl --
+#
+#       This file is part of the XMPP library. It implements interface to
+#       XMPP Ping (XEP-0199)
+#
+# Copyright (c) 2009 Sergei Golovan <sgolovan at nes.ru>
+#
+# See the file "license.terms" for information on usage and redistribution
+# of this file, and for a DISCLAMER OF ALL WARRANTIES.
+#
+# $Id$
+
+package provide xmpp::ping 0.1
+
+namespace eval ::xmpp::ping {}
+
+# ::xmpp::ping::ping --
+#
+#       Send XMPP ping IQ request to a specified JID.
+#
+# Arguments:
+#       xlib            XMPP token.
+#       -to jid         (optional) JID to send ping request. If empty then
+#                       the request is sent without 'to' attribute which
+#                       means sending to own bare JID.
+#       -timeout msecs  (optional) Timeout in milliseconds of waiting for
+#                       answer.
+#       -command cmd    (optional) Command to call back on receiving reply.
+#
+# Result:
+#       ID of outgoing IQ.
+#
+# Side effects:
+#       A ping packet is sent over the XMPP connection $xlib.
+
+proc ::xmpp::ping::ping {xlib args} {
+    set commands {}
+    set newArgs {}
+    foreach {key val} $args {
+        switch -- $key {
+            -to {
+                lappend newArgs -to $val
+            }
+            -timeout {
+                lappend newArgs -timeout $val
+            }
+            -command {
+                set commands [list $val]
+            }
+            default {
+                return -code error \
+                       -errorcode [::msgcat::mc "Illegal option \"%s\""  
$key]
+            }
+        }
+    }
+
+    eval [list ::xmpp::sendIQ $xlib get \
+	            -query [::xmpp::xml::create ping -xmlns urn:xmpp:ping] \
+	            -command [namespace code [list ParseAnswer $commands]]] \
+               $newArgs
+}
+
+# ::xmpp::ping::ParseAnswer --
+#
+#       A helper procedure which is called upon XMPP ping answer is  
received.
+#       It calls back the status and error message if any.
+#
+# Arguments:
+#       commands        A list of callbacks to call (only the first of them
+#                       is invoked. Status and error stanza are appended to
+#                       the called command.
+#       status          Ping request status (ok, error, abort, timeout).
+#       xml             Error message or result.
+#
+# Result:
+#       Empty string.
+#
+# Side effects:
+#       A callback is called if their list isn't empty.
+
+proc ::xmpp::ping::ParseAnswer {commands status xml} {
+    if {[llength $commands] > 0} {
+        uplevel #0 [lindex $commands 0] [list $status $xml]
+    }
+    return
+}
+
+# vim:ts=8:sw=4:sts=4:et
=======================================
--- /trunk/ChangeLog	Fri Jul 31 12:26:02 2009
+++ /trunk/ChangeLog	Mon Aug  3 08:55:40 2009
@@ -1,3 +1,8 @@
+2009-08-03  Sergei Golovan  <sgolovan at nes.ru>
+
+	* xmpp/ping.tcl, xmpp/pkgIndex.tcl: Added support for XMPP Ping
+	  (XEP-0199). Client-side only for now.
+
  2009-07-31  Sergei Golovan  <sgolovan at nes.ru>

  	* xmpp/xml.tcl: Add unique XMLNS prefixes when serializing XML element


More information about the Tkabber-dev mailing list