[Tkabber-dev] r1369 - branches/xml-import-export-serialized/plugins/roster

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Sun Feb 3 04:30:37 MSK 2008


Author: kostix
Date: 2008-02-03 04:30:36 +0300 (Sun, 03 Feb 2008)
New Revision: 1369

Modified:
   branches/xml-import-export-serialized/plugins/roster/backup.tcl
   branches/xml-import-export-serialized/plugins/roster/bkup_annotations.tcl
   branches/xml-import-export-serialized/plugins/roster/bkup_conferences.tcl
Log:
Changed the logic of deserialize_roster_hook:
 * Mow handlers are passed the list of xmldatas of all collection parsed
   from a roster backup file. This allows not to force backup plugins to
   maintain their global state in order to accumulate items from the
   collections of interest -- all data is extracted in one run of each
   handler.
 * Handlers are passed two new arguments: a stack level and a name of a
   variable at that level which holds a list of tuples "priority, script"
   which are run after all handlers of deserialize_roster_hook are run.
   So now if a plugin finds a data it intends to apply to the roster,
   it constructs such a tuple and adds it to the mentioned variable.

So now we can have a roster backup which holds any number of chunks
of data pertaining to different plugins, in any order.


Modified: branches/xml-import-export-serialized/plugins/roster/backup.tcl
===================================================================
--- branches/xml-import-export-serialized/plugins/roster/backup.tcl	2008-02-02 14:43:18 UTC (rev 1368)
+++ branches/xml-import-export-serialized/plugins/roster/backup.tcl	2008-02-03 01:30:36 UTC (rev 1369)
@@ -167,26 +167,21 @@
 	    must be \"$NS(rosterbackup)\""
     }
 
-    foreach child $children {
-	hook::run deserialize_roster_hook $connid $child
+    set handlers [list]
+    hook::run deserialize_roster_hook $connid $children #[info level] handlers
+
+    foreach handler [lsort -integer -index 0 $handlers] {
+	namespace eval :: [lindex $handler 1]
     }
 }
 
 ###############################################################################
 
-proc rosterbackup::deserialize_roster_contacts {connid data} {
+proc rosterbackup::deserialize_roster_contacts {connid data level varName} {
     global NS
     variable sent
+    upvar $level $varName handlers
 
-    jlib::wrapper:splitxml $data tag vars isempty cdata children
-
-    if {![string equal $tag roster]} return
-    set xmlns [jlib::wrapper:getattr $vars xmlns]
-    if {![string equal $xmlns $NS(roster)]} {
-	return -code error "Bad roster element namespace \"$xmlns\":\
-	    must be \"$NS(roster)\""
-    }
-
     array set existing {}
     foreach jid [::roster::get_jids $connid] {
 	set existing($jid) {}
@@ -196,29 +191,53 @@
     set jids [list]
     set subtags [list]
 
-    foreach child $children {
-	set jid [get_item_jid $child]
-	if {![info exists existing($jid)]} {
-	    lappend jids $jid
-	    lappend subtags $child
+    foreach item $data {
+	jlib::wrapper:splitxml $item tag vars isempty cdata children
+
+	if {![string equal $tag roster]} continue
+	set xmlns [jlib::wrapper:getattr $vars xmlns]
+	if {![string equal $xmlns $NS(roster)]} {
+	    return -code error "Bad roster element namespace \"$xmlns\":\
+		must be \"$NS(roster)\""
 	}
+
+	foreach child $children {
+	    set jid [get_item_jid $child]
+	    if {![info exists existing($jid)]} {
+		lappend jids $jid
+		lappend subtags $child
+	    }
+	}
     }
 
     if {[llength $subtags] > 0} {
-	set status [namespace current]::sent($connid,status)
-	set $status WAITING
-	jlib::send_iq set \
-	    [jlib::wrapper:createtag query \
-		 -vars [list xmlns $NS(roster)] \
-		 -subtags $subtags] \
-	    -connection $connid
-	vwait $status
-	unset $status
+	lappend handlers [list 50 [namespace code [list \
+	    send_contacts $connid $subtags]]]
     }
 }
 
 ###############################################################################
 
+proc rosterbackup::send_contacts {connid contacts} {
+    global NS
+
+    puts "handler: roster contacts"
+
+    set status [namespace current]::sent($connid,status)
+    set $status WAITING
+
+    jlib::send_iq set \
+	[jlib::wrapper:createtag query \
+	     -vars [list xmlns $NS(roster)] \
+	     -subtags $contacts] \
+	-connection $connid
+
+    vwait $status
+    unset $status
+}
+
+###############################################################################
+
 proc rosterbackup::get_item_jid {data} {
     jlib::wrapper:splitxml $data ? vars ? ? ?
     jlib::wrapper:getattr $vars jid

Modified: branches/xml-import-export-serialized/plugins/roster/bkup_annotations.tcl
===================================================================
--- branches/xml-import-export-serialized/plugins/roster/bkup_annotations.tcl	2008-02-02 14:43:18 UTC (rev 1368)
+++ branches/xml-import-export-serialized/plugins/roster/bkup_annotations.tcl	2008-02-03 01:30:36 UTC (rev 1369)
@@ -26,30 +26,47 @@
 
 ###############################################################################
 
-proc annobackup::deserialize_annotations {connid data} {
+proc annobackup::deserialize_annotations {connid data level varName} {
     global NS
+    upvar $level $varName handlers
 
-    jlib::wrapper:splitxml $data tag vars isempty cdata children
-    if {![string equal $tag privstorage]} return
-    set xmlns [jlib::wrapper:getattr $vars xmlns]
-    if {![string equal $xmlns $NS(private)]} {
-	return -code error "Bad roster element namespace \"$xmlns\":\
-	    must be \"$NS(private)\""
+    set notes [list]
+    foreach item $data {
+	jlib::wrapper:splitxml $item tag vars isempty cdata children
+	if {![string equal $tag privstorage]} continue
+	set xmlns [jlib::wrapper:getattr $vars xmlns]
+	if {![string equal $xmlns $NS(private)]} {
+	    return -code error "Bad roster element namespace \"$xmlns\":\
+		must be \"$NS(private)\""
+	}
+
+	foreach storage $children {
+	    jlib::wrapper:splitxml $storage ctag cvars cisempty ccdata cchildren
+	    if {![string equal $ctag storage]} continue
+	    set xmlns [jlib::wrapper:getattr $cvars xmlns]
+	    if {![string equal $xmlns $NS(rosternotes)]} continue
+	    
+	    set notes [concat $notes $cchildren]
+	}
     }
 
+    if {[llength $notes] > 0} {
+	lappend handlers [list 60 [namespace code [list \
+	    send_notes $connid $notes]]]
+    }
+}
+
+###############################################################################
+
+proc annobackup::send_notes {connid notes} {
     set updated 0
 
-    foreach storage $children {
-	jlib::wrapper:splitxml $storage ctag cvars cisempty ccdata cchildren
-	if {![string equal $ctag storage]} return
-	set xmlns [jlib::wrapper:getattr $cvars xmlns]
-	if {![string equal $xmlns $NS(rosternotes)]} return
-	
-	foreach child $cchildren {
-	    set added [::plugins::annotations::create_note \
-		    $connid $child -merge yes]
-	    set updated [expr {$updated || $added}]
-	}
+    puts "handler: annotations"
+
+    foreach item $notes {
+	set added [::plugins::annotations::create_note \
+		$connid $item -merge yes]
+	set updated [expr {$updated || $added}]
     }
 
     if {$updated} {

Modified: branches/xml-import-export-serialized/plugins/roster/bkup_conferences.tcl
===================================================================
--- branches/xml-import-export-serialized/plugins/roster/bkup_conferences.tcl	2008-02-02 14:43:18 UTC (rev 1368)
+++ branches/xml-import-export-serialized/plugins/roster/bkup_conferences.tcl	2008-02-03 01:30:36 UTC (rev 1369)
@@ -3,17 +3,11 @@
 # Depends on: conferences.tcl, backup.tcl
 
 namespace eval mucbackup {
-    variable updated
-
     # Should probably go after the roster contacts, so we set prio to 70:
     hook::add serialize_roster_hook \
 	[namespace current]::serialize_muc_bookmarks 70
     hook::add deserialize_roster_hook \
 	[namespace current]::deserialize_muc_bookmarks 70
-    hook::add roster_deserializing_hook \
-	[namespace current]::prepare_deserialization
-    hook::add roster_deserialized_hook \
-	[namespace current]::push_bookmarks_to_roster
 }
 
 ###############################################################################
@@ -31,59 +25,64 @@
 
 ###############################################################################
 
-proc mucbackup::prepare_deserialization {connid} {
-    variable updated
-    set updated($connid) 0
-}
-
-###############################################################################
-
-proc mucbackup::deserialize_muc_bookmarks {connid data} {
-    variable updated
-    upvar 0 updated($connid) upd
+proc mucbackup::deserialize_muc_bookmarks {connid data level varName} {
     global NS
+    upvar $level $varName handlers
 
-    jlib::wrapper:splitxml $data tag vars isempty cdata children
-    if {![string equal $tag privstorage]} return
-    set xmlns [jlib::wrapper:getattr $vars xmlns]
-    if {![string equal $xmlns $NS(private)]} {
-	return -code error "Bad roster element namespace \"$xmlns\":\
-	    must be \"$NS(private)\""
-    }
+    set bookmarks [list]
+    set bmgroups  [list]
+    foreach item $data {
+	jlib::wrapper:splitxml $item tag vars isempty cdata children
+	if {![string equal $tag privstorage]} continue
+	set xmlns [jlib::wrapper:getattr $vars xmlns]
+	if {![string equal $xmlns $NS(private)]} {
+	    return -code error "Bad roster element namespace \"$xmlns\":\
+		must be \"$NS(private)\""
+	}
 
-    foreach storage $children {
-	jlib::wrapper:splitxml $storage ctag cvars cisempty ccdata cchildren
-	if {![string equal $ctag storage]} return
-	set xmlns [jlib::wrapper:getattr $cvars xmlns]
-	switch -- $xmlns \
-	    $NS(bookmarks) {
-		foreach child $cchildren {
-		    set added [::plugins::conferences::create_muc_bookmark \
-			    $connid $child -merge yes]
-		    set upd [expr {$upd || $added}]
+	foreach storage $children {
+	    jlib::wrapper:splitxml $storage ctag cvars cisempty ccdata cchildren
+	    if {![string equal $ctag storage]} continue
+	    set xmlns [jlib::wrapper:getattr $cvars xmlns]
+	    switch -- $xmlns \
+		$NS(bookmarks) {
+		    set bookmarks [concat $bookmarks $cchildren]
+		} \
+		$NS(tkabber:groups) {
+		    set bmgroups [concat $bmgroups $cchildren]
 		}
-	    } \
-	    $NS(tkabber:groups) {
-		foreach child $cchildren {
-		    set added [::plugins::conferences::create_muc_bmgroup \
-			    $connid $child -merge yes]
-		    set upd [expr {$upd || $added}]
-		}
-	    }
+	}
     }
+
+    if {[llength $bookmarks] > 0 && [llength $bmgroups] > 0} {
+	lappend handlers [list 70 [namespace code [list \
+	    merge_muc_bookmarks $connid $bookmarks $bmgroups]]]
+    }
 }
 
 ###############################################################################
 
-proc mucbackup::push_bookmarks_to_roster {connid} {
-    variable updated
+proc mucbackup::merge_muc_bookmarks {connid bookmarks bmgroups} {
+    variable updated 0
 
-    if {$updated($connid)} {
+    puts "handler: bookmarks"
+
+    foreach item $bookmarks {
+	set added [::plugins::conferences::create_muc_bookmark \
+		$connid $item -merge yes]
+	set updated [expr {$updated || $added}]
+    }
+
+    foreach item $bmgroups {
+	set added [::plugins::conferences::create_muc_bmgroup \
+		$connid $item -merge yes]
+	set updated [expr {$updated || $added}]
+    }
+
+    if {$updated} {
 	::plugins::conferences::push_bookmarks_to_roster $connid
 	::plugins::conferences::store_bookmarks $connid
     }
-
-    unset updated($connid)
 }
 
 # vim:ts=8:sw=4:sts=4:noet



More information about the Tkabber-dev mailing list