[Tkabber-dev] r990 - in trunk/tkabber: . ifacetk

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Fri Mar 2 18:11:49 MSK 2007


Author: sergei
Date: 2007-03-02 18:11:47 +0300 (Fri, 02 Mar 2007)
New Revision: 990

Modified:
   trunk/tkabber/ChangeLog
   trunk/tkabber/ifacetk/iface.tcl
   trunk/tkabber/privacy.tcl
Log:
	* ifacetk/iface.tcl, privacy.tcl: Redone accepting messages from
	  roster only to proagate to all connected resources.


Modified: trunk/tkabber/ChangeLog
===================================================================
--- trunk/tkabber/ChangeLog	2007-03-01 17:16:19 UTC (rev 989)
+++ trunk/tkabber/ChangeLog	2007-03-02 15:11:47 UTC (rev 990)
@@ -1,3 +1,8 @@
+2007-03-02  Sergei Golovan  <sgolovan at nes.ru>
+
+	* ifacetk/iface.tcl, privacy.tcl: Redone accepting messages from
+	  roster only to proagate to all connected resources.
+
 2007-03-01  Sergei Golovan  <sgolovan at nes.ru>
 
 	* doc/tkabber.xml: Added note about new privacy lists case.

Modified: trunk/tkabber/ifacetk/iface.tcl
===================================================================
--- trunk/tkabber/ifacetk/iface.tcl	2007-03-01 17:16:19 UTC (rev 989)
+++ trunk/tkabber/ifacetk/iface.tcl	2007-03-02 15:11:47 UTC (rev 990)
@@ -267,7 +267,8 @@
 			    [list command [string trim [::msgcat::mc "Edit conference list "]] {} {} {} \
 				 -command {privacy::edit_special_list conference}] \
 			    [list checkbutton [::msgcat::mc "Accept messages from roster users only"] {} {} {} \
-				 -variable privacy::options(accept_from_roster_only)] \
+				 -variable privacy::accept_from_roster_only \
+				 -command privacy::on_accept_from_roster_only_change] \
 			    [list checkbutton [::msgcat::mc "Activate lists at startup"] {} {} {} \
 				 -variable privacy::options(activate_at_startup)] \
 			    {separator} \

Modified: trunk/tkabber/privacy.tcl
===================================================================
--- trunk/tkabber/privacy.tcl	2007-03-01 17:16:19 UTC (rev 989)
+++ trunk/tkabber/privacy.tcl	2007-03-02 15:11:47 UTC (rev 990)
@@ -30,15 +30,12 @@
 	      visible    [::msgcat::mc "Visible list"] \
 	      conference [::msgcat::mc "Conference list"]]
 
+    variable accept_from_roster 0
+
     custom::defgroup Privacy \
 	[::msgcat::mc "Blocking communication (XMPP privacy lists) options."] \
 	-group Tkabber
 
-    custom::defvar options(accept_from_roster_only) 0 \
-	[::msgcat::mc "Accept messages from users, which are in the roster, only."] \
-	-type boolean -group Privacy \
-	-command [list [namespace current]::activate_privacy_lists]
-
     custom::defvar options(activate_at_startup) 1 \
 	[::msgcat::mc "Activate visible/invisible/ignore/conference lists\
 		       before sending initial presence."] \
@@ -893,7 +890,42 @@
 	-connection $connid
 }
 
+# subscription-list is responsible for blocking all messages
+# not from the roster.
+proc privacy::send_subscription_list {connid} {
+    variable accept_from_roster_only
 
+    if {$accept_from_roster_only} {
+	set items [list [jlib::wrapper:createtag item \
+			     -vars [list type subscription \
+					 value none \
+					 action deny \
+					 order 0]]]
+    } else {
+	set items {}
+    }
+
+    # If items aren't empty, we'll never send unavailable presence to
+    # all users to whom directed presence was sent. Bug?
+    send_list_iq "subscription-list" $items \
+	-command [list [namespace current]::update_tkabber_lists \
+		       $connid subscription $items {}] \
+	-connection $connid
+}
+
+proc privacy::on_accept_from_roster_only_change {args} {
+    foreach {opt val} $args {
+	switch -- $opt {
+	    -connection { set connid $val }
+	}
+    }
+    if {![info exists connid]} {
+	set connid [jlib::route ""]
+    }
+
+    send_subscription_list $connid
+}
+
 proc privacy::update_tkabber_lists {connid name items postitems res child} {
     global userstatus textstatus statusdesc
     variable send_messages
@@ -917,53 +949,26 @@
     }
 
     switch -- $name {
-	ignore {
+	ignore -
+	conference -
+	subscription {
 	    join_lists $connid "i-am-visible-list" \
-		       {ignore-list invisible-list conference-list} \
+		       {ignore-list invisible-list conference-list subscription-list} \
 		       {allow {} {}}
-	    join_lists $connid "i-am-visible-roster-list" \
-		       {ignore-list invisible-list conference-list} \
-		       {deny {type subscription value none} {}}
 	    join_lists $connid "i-am-invisible-list" \
-		       {ignore-list visible-list conference-list} \
+		       {ignore-list visible-list conference-list subscription-list} \
 		       [list deny {} [list [jlib::wrapper:createtag presence-out]]]
-	    join_lists $connid "i-am-invisible-roster-list" \
-		       {ignore-list visible-list conference-list} \
-		       [list deny {type subscription value none} {} \
-			     deny {} [list [jlib::wrapper:createtag presence-out]]]
 	}
 	invisible {
 	    join_lists $connid "i-am-visible-list" \
-		       {ignore-list invisible-list conference-list} \
+		       {ignore-list invisible-list conference-list subscription-list} \
 		       {allow {} {}}
-	    join_lists $connid "i-am-visible-roster-list" \
-		       {ignore-list invisible-list conference-list} \
-		       {deny {type subscription value none} {}}
 	}
 	visible {
 	    join_lists $connid "i-am-invisible-list" \
-		       {ignore-list visible-list conference-list} \
+		       {ignore-list visible-list conference-list subscription-list} \
 		       [list deny {} [list [jlib::wrapper:createtag presence-out]]]
-	    join_lists $connid "i-am-invisible-roster-list" \
-		       {ignore-list visible-list conference-list} \
-		       [list deny {type subscription value none} {} \
-			     deny {} [list [jlib::wrapper:createtag presence-out]]]
 	}
-	conference {
-	    join_lists $connid "i-am-visible-list" \
-		       {ignore-list invisible-list conference-list} \
-		       {allow {} {}}
-	    join_lists $connid "i-am-visible-roster-list" \
-		       {ignore-list invisible-list conference-list} \
-		       {deny {type subscription value none} {}}
-	    join_lists $connid "i-am-invisible-list" \
-		       {ignore-list visible-list conference-list} \
-		       [list deny {} [list [jlib::wrapper:createtag presence-out]]]
-	    join_lists $connid "i-am-invisible-roster-list" \
-		       {ignore-list visible-list conference-list} \
-		       [list deny {type subscription value none} {} \
-			     deny {} [list [jlib::wrapper:createtag presence-out]]]
-	}
     }
 
     # ejabberd behaves correctly and applies privacy lists before
@@ -992,6 +997,17 @@
 
     set items {}
     set i 0
+
+    # Appending myself to the list to make sure we can communicate
+    # between own resources
+
+    lappend items [jlib::wrapper:createtag item \
+		       -vars [list type jid \
+				   value [jlib::connection_bare_jid $connid] \
+				   action allow \
+				   order $i]]
+    incr i
+
     foreach ln $lists {
 	jlib::send_iq get \
 	    [jlib::wrapper:createtag query \
@@ -1013,16 +1029,6 @@
 	}
     }
 
-    # Appending myself to the list to make sure we can communicate
-    # between own resources
-
-    lappend items [jlib::wrapper:createtag item \
-		       -vars [list type jid \
-				   value [jlib::connection_bare_jid $connid] \
-				   action allow \
-				   order $i]]
-    incr i
-
     foreach {action vars subtags} $fallbacks {
 	lappend items [jlib::wrapper:createtag item \
 			   -vars [concat [list action $action order $i] $vars] \
@@ -1125,33 +1131,18 @@
 
 ###############################################################################
 #
-# During connect try to activate "i-am-visible-list" or
-# "i-am-visible-roster-list" privacy list
+# During connect try to activate "i-am-visible-list" privacy list
 # If it's not found then create and activate it
 # If activation or creation fails then terminate connect with error message
 #
 
-proc privacy::activate_privacy_lists {args} {
-    foreach connid [jlib::connections] {
-	activate_privacy_list 0 $connid
-    }
-}
-
 proc privacy::activate_privacy_list {depth connid} {
     variable options
     variable answer
 
-    if {$options(accept_from_roster_only)} {
-	set listname "i-am-visible-roster-list"
-	set listfallback {deny {type subscription value none} {}}
-    } else {
-	set listname "i-am-visible-list"
-	set listfallback {allow {} {}}
-    }
-
     set_status [::msgcat::mc "Waiting for activating privacy list"]
     debugmsg privacy "requested privacy list activation"
-    send_default_or_active_list $listname active \
+    send_default_or_active_list "i-am-visible-list" active \
 	-command [list [namespace current]::get_answer $connid] \
 	-connection $connid
 
@@ -1188,9 +1179,9 @@
 		    set_status \
 			[::msgcat::mc "Creating default privacy list"]
 
-		    join_lists $connid $listname \
-			{ignore-list invisible-list conference-list} \
-			$listfallback \
+		    join_lists $connid "i-am-visible-list" \
+			{ignore-list invisible-list conference-list subscription-list} \
+			{allow {} {}} \
 			-command [list [namespace current]::get_answer \
 				       $connid]
 
@@ -1426,6 +1417,9 @@
 		    conference-list {
 			reload_special_list $connid conference
 		    }
+		    subscription-list {
+			reload_subscription_list $connid
+		    }
 		}
 	    }
 	}
@@ -1459,6 +1453,7 @@
     foreach name {invisible visible ignore conference} {
 	reload_special_list $connid $name
     }
+    reload_subscription_list $connid
 }
 
 hook::add connected_hook [namespace current]::privacy::get_list_vars
@@ -1501,3 +1496,71 @@
 
 ###############################################################################
 
+proc privacy::reload_subscription_list {connid} {
+    jlib::send_iq get \
+	[jlib::wrapper:createtag query \
+	     -vars [list xmlns $::NS(privacy)] \
+	     -subtags [list [jlib::wrapper:createtag list \
+				 -vars [list name "subscription-list"]]]] \
+	-command [list [namespace current]::store_subscription_list $connid] \
+	-connection $connid
+}
+
+proc privacy::store_subscription_list {connid res child} {
+    variable accept_from_roster_only
+
+    set accept_from_roster_only 0
+
+    if {$res != "OK"} return
+
+    jlib::wrapper:splitxml $child tag vars isempty chdata children
+    jlib::wrapper:splitxml [lindex $children 0] tag vars isempty chdata children
+
+    if {$tag != "list"} return
+
+    foreach item $children {
+	jlib::wrapper:splitxml $item tag1 vars1 isempty1 chdata1 children1
+	if {[jlib::wrapper:getattr $vars1 type] == "subscription" && \
+		[jlib::wrapper:getattr $vars1 value] == "none" && \
+		[jlib::wrapper:getattr $vars1 action] == "deny"} {
+	    set accept_from_roster_only 1
+	}
+    }
+}
+
+###############################################################################
+
+proc privacy::enable_menu {connid} {
+    set m [.mainframe getmenu privacy]
+    if {$::ifacetk::options(show_tearoffs)} {
+	set start 1
+    } else {
+	set start 0
+    }
+    for {set i $start} {$i <= [$m index end]} {incr i} {
+	catch {$m entryconfigure $i -state normal}
+    }
+}
+
+proc privacy::disable_menu {connid} {
+    if {[llength [jlib::connections]] > 0} return
+
+    set m [.mainframe getmenu privacy]
+    if {$::ifacetk::options(show_tearoffs)} {
+	set start 1
+    } else {
+	set start 0
+    }
+    for {set i $start} {$i <= [$m index end]} {incr i} {
+	catch {$m entryconfigure $i -state disabled}
+    }
+    $m entryconfigure [$m index [::msgcat::mc "Activate lists at startup"]] \
+       -state normal
+}
+
+hook::add connected_hook [namespace current]::privacy::enable_menu
+hook::add disconnected_hook [namespace current]::privacy::disable_menu
+hook::add finload_hook [list [namespace current]::privacy::disable_menu {}]
+
+###############################################################################
+



More information about the Tkabber-dev mailing list