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

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Thu Sep 20 14:46:27 MSD 2007


Author: sergei
Date: 2007-09-20 14:45:36 +0400 (Thu, 20 Sep 2007)
New Revision: 1231

Modified:
   trunk/tkabber/ChangeLog
   trunk/tkabber/plugins/general/xaddress.tcl
Log:
	* plugins/general/xaddress.tcl: Moved address rewriting to
	  rewrite_message_hook, check for forged address changes.


Modified: trunk/tkabber/ChangeLog
===================================================================
--- trunk/tkabber/ChangeLog	2007-09-18 12:16:06 UTC (rev 1230)
+++ trunk/tkabber/ChangeLog	2007-09-20 10:45:36 UTC (rev 1231)
@@ -1,3 +1,8 @@
+2007-09-20  Sergei Golovan  <sgolovan at nes.ru>
+
+	* plugins/general/xaddress.tcl: Moved address rewriting to
+	  rewrite_message_hook, check for forged address changes.
+
 2007-09-18  Sergei Golovan  <sgolovan at nes.ru>
 
 	* ifacetk/iroster.tcl: Fixed showing own resources if username is not

Modified: trunk/tkabber/plugins/general/xaddress.tcl
===================================================================
--- trunk/tkabber/plugins/general/xaddress.tcl	2007-09-18 12:16:06 UTC (rev 1230)
+++ trunk/tkabber/plugins/general/xaddress.tcl	2007-09-20 10:45:36 UTC (rev 1231)
@@ -2,6 +2,10 @@
 #
 # Implementation of XEP-0033: Extended Stanza Addressing
 #
+# The sender address is rewritten, but the original address is stored
+# in an additional <x/> element:
+#
+# <x xmlns='tkabber:xaddress:store' from='JID' reason='type'/>
 
 set ::NS(xaddress) "http://jabber.org/protocol/address"
 set ::NS(xaddress_store) "tkabber:xaddress:store"
@@ -107,40 +111,48 @@
 ######################################################
 # Replace original jid. Read README.xaddress
 proc ::xaddress::modify_from \
-     {connid from id type is_subject subject body err thread priority x} {
+     {vconnid vfrom vid vtype vis_subject vsubject \
+      vbody verr vthread vpriority vx} {
+    upvar 2 $vfrom from
+    upvar 2 $vtype type
+    upvar 2 $vx x
 
     # those types are supported at now.
     if {![lcontain {chat normal groupchat ""} $type]} return
 
+    set newx {}
     foreach xe $x {
 	jlib::wrapper:splitxml $xe tag vars isempty chdata children
 	
 	if {[cequal [jlib::wrapper:getattr $vars xmlns] $::NS(xaddress_store)]} {
-	    # this message already was changed by this proc => exit
-	    return
+	    # The other side tries to forge a sender sddress
+	} else {
+	    lappend newx $xe
 	}
+    }
 
+    set x $newx
+
+    foreach xe $x {
+	jlib::wrapper:splitxml $xe tag vars isempty chdata children
+	
 	if {[cequal [set res [parse_xaddress_fields $xe {ofrom}]] {}]} continue
 
-	# FIX: now we get only first but is there can be several ofrom fields?
+	# FIX: now we get only first but what if there are several ofrom fields?
 	lassign $res reason vars1
 	set ofrom [jlib::wrapper:getattr $vars1 jid]
 	if {[cequal $ofrom ""]} return
 
 	set x [linsert $x 0 [jlib::wrapper:createtag x \
 				 -vars [list xmlns $::NS(xaddress_store) \
-					     real_from $from \
+					     from $from \
 					     reason $reason]]]
 	set from $ofrom
-	hook::run process_message_hook \
-		  $connid $from $id $type $is_subject $subject $body \
-		  $err $thread $priority $x
-
-	return stop
+	return
     }
 }
 
-hook::add process_message_hook ::xaddress::modify_from 1
+hook::add rewrite_message_hook ::xaddress::modify_from
 
 #####################################################################
 # Draw special icon and tooltip for xaddress messages in the chat.
@@ -158,7 +170,7 @@
 	set xmlns [jlib::wrapper:getattr $vars xmlns]
 	
 	if {[cequal  $xmlns $::NS(xaddress_store)] && [cequal $tag x]} {
-	    set real_from [jlib::wrapper:getattr $vars real_from]
+	    set real_from [jlib::wrapper:getattr $vars from]
 	    set reason [jlib::wrapper:getattr $vars reason]
 	    continue
 	}
@@ -201,7 +213,7 @@
 
 	# if "from" was modified draw reason and real_from
 	if {[cequal  $xmlns $::NS(xaddress_store)] && [cequal $tag x]} {
-	    set real_from [jlib::wrapper:getattr $vars real_from]
+	    set real_from [jlib::wrapper:getattr $vars from]
 	    set reason [jlib::wrapper:getattr $vars reason]
 
 	    switch -- $reason {



More information about the Tkabber-dev mailing list