[Tkabber-dev] [tclxmpp] r117 committed - * xmpp/ping.tcl: Added reply to XMPP ping requests support.

codesite-noreply at google.com codesite-noreply at google.com
Mon Aug 3 20:52:48 MSD 2009


Revision: 117
Author: sgolovan
Date: Mon Aug  3 09:51:53 2009
Log: 	* xmpp/ping.tcl: Added reply to XMPP ping requests support.

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

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

=======================================
--- /trunk/ChangeLog	Mon Aug  3 08:55:40 2009
+++ /trunk/ChangeLog	Mon Aug  3 09:51:53 2009
@@ -3,6 +3,8 @@
  	* xmpp/ping.tcl, xmpp/pkgIndex.tcl: Added support for XMPP Ping
  	  (XEP-0199). Client-side only for now.

+	* xmpp/ping.tcl: Added reply to XMPP ping requests support.
+
  2009-07-31  Sergei Golovan  <sgolovan at nes.ru>

  	* xmpp/xml.tcl: Add unique XMLNS prefixes when serializing XML element
=======================================
--- /trunk/xmpp/ping.tcl	Mon Aug  3 08:55:40 2009
+++ /trunk/xmpp/ping.tcl	Mon Aug  3 09:51:53 2009
@@ -12,7 +12,9 @@

  package provide xmpp::ping 0.1

-namespace eval ::xmpp::ping {}
+namespace eval ::xmpp::ping {
+    namespace export ping register unregister
+}

  # ::xmpp::ping::ping --
  #
@@ -84,5 +86,91 @@
      }
      return
  }
+
+# ::xmpp::ping::register --
+#
+#       Register handler to answer XMPP ping IQ requests.
+#
+# Arguments:
+#       -command cmd    (optional) Command to call when ping request is
+#                       arrived. The result of the command is sent back.
+#                       It must be either {result {}}, or {error type  
condition},
+#                       or empty string if the application will reply to  
the
+#                       request separately.
+#                       The command's arguments are xlib, from, xml, and
+#                       optional parameters -to, -id, -lang.
+#
+# Result:
+#       Empty string.
+#
+# Side effects:
+#       XMPP ping callback is registered.
+
+proc ::xmpp::ping::register {args} {
+    set commands {}
+    foreach {key val} $args {
+        switch -- $key {
+            -command {
+                set commands [list $val]
+            }
+            default {
+                return -code error \
+                       -errorcode [::msgcat::mc "Illegal option \"%s\""  
$key]
+            }
+        }
+    }
+
+    ::xmpp::iq::register get query urn:xmpp:ping \
+                         [namespace code [list ParseRequest $commands]]
+    return
+}
+
+# ::xmpp::ping::ParseRequest --
+#
+#       A helper procedure which is called on any incoming XMPP ping  
request.
+#       It either calls a command specified during registration or simply
+#       returns result (if there weren't any command).
+#
+# Arguments:
+#       commands            A list of commands to call (only the first one
+#                           will be invoked).
+#       xlib                XMPP token where request was received.
+#       from                JID of user who sent the request.
+#       xml                 Request XML element (in ping requests it is  
empty).
+#       args                optional arguments (-lang, -to, -id).
+#
+# Result:
+#       Either {result, {}}, or {error type condition}, or empty string, if
+#       the application desided to reply later.
+#
+# Side effects:
+#       Side effects of the called command.
+
+proc ::xmpp::ping::ParseRequest {commands xlib from xml args} {
+    if {[llength $commands] > 0} {
+        return [uplevel #0 [lindex $commands 0] [list $xlib $from $xml]  
$args]
+    } else {
+        return [list result {}]
+    }
+}
+
+# ::xmpp::ping::unregister --
+#
+#       Unregister handler which used to answer XMPP ping IQ requests.
+#
+# Arguments:
+#       None.
+#
+# Result:
+#       Empty string.
+#
+# Side effects:
+#       XMPP ping callback is registered.
+
+proc ::xmpp::ping::unregister {} {
+    ::xmpp::iq::unregister get query urn:xmpp:ping
+
+    return
+}

  # vim:ts=8:sw=4:sts=4:et


More information about the Tkabber-dev mailing list