[Tkabber-dev] r1717 - in trunk/tkabber: . plugins/general

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Fri Mar 13 11:08:21 MSK 2009


Author: sergei
Date: 2009-03-13 11:08:20 +0300 (Fri, 13 Mar 2009)
New Revision: 1717

Added:
   trunk/tkabber/plugins/general/captcha.tcl
Removed:
   trunk/tkabber/plugins/general/challenge.tcl
Modified:
   trunk/tkabber/ChangeLog
   trunk/tkabber/namespaces.tcl
Log:
	* plugins/general/captcha.tcl: Renamed from challenge.tcl and added
	  current XEP-0158 support (only for CAPTCHAs in messages).


Modified: trunk/tkabber/ChangeLog
===================================================================
--- trunk/tkabber/ChangeLog	2009-03-12 18:18:41 UTC (rev 1716)
+++ trunk/tkabber/ChangeLog	2009-03-13 08:08:20 UTC (rev 1717)
@@ -1,3 +1,8 @@
+2009-03-13  Sergei Golovan  <sgolovan at nes.ru>
+
+	* plugins/general/captcha.tcl: Renamed from challenge.tcl and added
+	  current XEP-0158 support (only for CAPTCHAs in messages).
+
 2009-03-12  Sergei Golovan  <sgolovan at nes.ru>
 
 	* plugins/general/bob.tcl: Added two procedures which collect Bits of

Modified: trunk/tkabber/namespaces.tcl
===================================================================
--- trunk/tkabber/namespaces.tcl	2009-03-12 18:18:41 UTC (rev 1716)
+++ trunk/tkabber/namespaces.tcl	2009-03-13 08:08:20 UTC (rev 1717)
@@ -46,8 +46,6 @@
 	pubsub      "http://jabber.org/protocol/pubsub" \
 	pubsub#owner "http://jabber.org/protocol/pubsub#owner" \
 	disco#publish "http://jabber.org/protocol/disco#publish" \
-	challenge   "urn:xmpp:tmp:challenge" \
-	media-element "urn:xmpp:tmp:media-element"
     ]
 }
 

Copied: trunk/tkabber/plugins/general/captcha.tcl (from rev 1716, trunk/tkabber/plugins/general/challenge.tcl)
===================================================================
--- trunk/tkabber/plugins/general/captcha.tcl	                        (rev 0)
+++ trunk/tkabber/plugins/general/captcha.tcl	2009-03-13 08:08:20 UTC (rev 1717)
@@ -0,0 +1,67 @@
+# $Id$
+#
+# CAPTCHA Forms support (XEP-0158)
+#
+
+namespace eval captcha {
+    set ::NS(challenge) "urn:xmpp:tmp:challenge"
+    set ::NS(captcha) "urn:xmpp:captcha"
+
+    hook::add message_process_x_hook [namespace current]::process_x 10
+}
+
+###############################################################################
+
+proc captcha::process_x {rowvar bodyvar f x xlib from id type replyP} {
+    upvar 2 $rowvar row
+    upvar 2 $bodyvar body
+
+    set captcha 0
+    foreach xa $x {
+	::xmpp::xml::split $xa tag xmlns attrs cdata subels
+
+	if {![string equal $xmlns $::NS(challenge)] && \
+			    ![string equal $xmlns $::NS(captcha)]} {
+	    continue
+	}
+
+	set captcha 1
+
+	lassign [::xmpp::data::findForm $subels] type form
+	if {[string equal $type form]} {
+	    if {[catch {process_x_data $f $xlib $from $xmlns $form}]} {
+		# Cannot process CAPTCHA form, so falling back to a
+		# legacy CAPTCHA method if any.
+		# TODO: Show error message to user.
+		set captcha 0
+	    }
+	}
+    }
+
+    if {!$captcha} {
+	return
+    } else {
+	set body ""
+	return -code break
+    }
+}
+
+proc captcha::process_x_data {f xlib from xmlns x} {
+    data::draw_window [list $x] \
+		      [namespace code [list send_x_data $xlib $from $xmlns]]
+}
+
+proc captcha::send_x_data {xlib to xmlns w restags} {
+    if {[string equal $xmlns $::NS(captcha)]} {
+	set tag captcha
+    } elseif {[string equal $xmlns $::NS(challenge)]} {
+	set tag challenge
+    }
+    ::xmpp::sendIQ $xlib set \
+		   [::xmpp::xml::create $tag \
+					-xmlns $xmlns \
+					-subelements $restags] \
+		   -to $to
+    destroy $w
+}
+


Property changes on: trunk/tkabber/plugins/general/captcha.tcl
___________________________________________________________________
Added: svn:keywords
   + Author Date Id Revision
Added: svn:mergeinfo
   + 
Added: svn:eol-style
   + native

Deleted: trunk/tkabber/plugins/general/challenge.tcl
===================================================================
--- trunk/tkabber/plugins/general/challenge.tcl	2009-03-12 18:18:41 UTC (rev 1716)
+++ trunk/tkabber/plugins/general/challenge.tcl	2009-03-13 08:08:20 UTC (rev 1717)
@@ -1,54 +0,0 @@
-# $Id$
-#
-# Robot challenge support (XEP-0158)
-#
-
-namespace eval challenge {}
-
-###############################################################################
-
-proc challenge::process_x {rowvar bodyvar f x xlib from id type replyP} {
-    upvar 2 $rowvar row
-    upvar 2 $bodyvar body
-
-    set challenge 0
-    foreach xa $x {
-	::xmpp::xml::split $xa tag xmlns attrs cdata subels
-
-	if {$xmlns != $::NS(challenge)} continue
-
-	set challenge 1
-
-	lassign [::xmpp::data::findForm $subels] type form
-	if {$type == "form"} {
-	    if {[catch {process_x_data $f $xlib $from $form}]} {
-		# Cannot process challenge form, so falling back to a
-		# legacy challenge method if any.
-		# TODO: Show error message to user.
-		set challenge 0
-	    }
-	}
-    }
-    if {!$challenge} {
-	return
-    } else {
-	set body ""
-	return stop
-    }
-}
-
-hook::add message_process_x_hook [namespace current]::challenge::process_x 10
-
-proc challenge::process_x_data {f xlib from x} {
-    data::draw_window [list $x] [list [namespace current]::send_x_data $xlib $from]
-}
-
-proc challenge::send_x_data {xlib to w restags} {
-    ::xmpp::sendIQ $xlib set \
-	[::xmpp::xml::create challenge \
-		    -xmlns $::NS(challenge) \
-		    -subelements $restags] \
-	-to $to
-    destroy $w
-}
-



More information about the Tkabber-dev mailing list