[Tkabber-dev] [tclxmpp] r143 committed - * xmpp/muc.tcl: Added a new reported MUC event (disconnect). Fixed...

tclxmpp at googlecode.com tclxmpp at googlecode.com
Sat Jan 30 15:32:24 MSK 2010


Revision: 143
Author: sgolovan
Date: Sat Jan 30 04:31:26 2010
Log: 	* xmpp/muc.tcl: Added a new reported MUC event (disconnect). Fixed
	  race condition on leaving room and immediately entering.

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

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

=======================================
--- /trunk/ChangeLog	Fri Jan 29 07:14:25 2010
+++ /trunk/ChangeLog	Sat Jan 30 04:31:26 2010
@@ -1,3 +1,8 @@
+2010-01-30  Sergei Golovan  <sgolovan at nes.ru>
+
+	* xmpp/muc.tcl: Added a new reported MUC event (disconnect). Fixed
+	  race condition on leaving room and immediately entering.
+
  2010-01-29  Sergei Golovan  <sgolovan at nes.ru>

  	* xmpp/stanzaerror.tcl: Fixed numeric code processing for legacy
=======================================
--- /trunk/xmpp/muc.tcl	Fri Jan 29 07:14:25 2010
+++ /trunk/xmpp/muc.tcl	Sat Jan 30 04:31:26 2010
@@ -168,12 +168,24 @@

      set nickname [::xmpp::jid::resource $jid]

+    if {[string equal $nickname ""]} {
+        after idle [namespace code \
+                        [list CallBack $commands error \
+                              [::xmpp::xml::create error \
+                                    -cdata [::msgcat::mc "Empty  
nickname"]]]]
+        return
+    }
+
      set id [::xmpp::packetID $xlib]
      set state(id) $id
      set state(commands) $commands

      set state(status) connecting
-    set state(nick) $nickname
+    set state(nick) ""
+    set state(users) {}
+    array unset state jid,*
+    array unset state affiliation,*
+    array unset state role,*

      eval [list ::xmpp::sendPresence $xlib \
                          -to $state(room)/$nickname \
@@ -380,11 +392,25 @@
                          [string equal $state(ignore_unavailable) $nick]} {
                  unset state(ignore_unavailable)
              } else {
-                if {[string equal $nick $state(nick)]} {
-                    lappend args -own 1
-                }
                  uplevel #0 $state(-eventcommand) [list exit $nick] $args
              }
+
+            if {[string equal $nick $state(nick)]} {
+                set state(nick)   ""
+                set state(status) disconnected
+                set state(args)   {}
+
+                if {[info exists state(id)]} {
+                    unset state(id)
+                    CallBack $state(commands) error \
+                        [::xmpp::xml::create error \
+                            -cdata [::msgcat::mc "Disconnected from the  
room"]]
+                }
+
+                set state(commands) {}
+
+                uplevel #0 $state(-eventcommand) [list disconnect $nick]  
$args
+            }
          }
          available {
              set status $type
@@ -422,9 +448,6 @@
                      [string equal $state(ignore_available) $nick]} {
                  unset state(ignore_available)
              } else {
-                if {[string equal $nick $state(nick)]} {
-                    lappend args -own 1
-                }
                  uplevel #0 $state(-eventcommand) [list $action $nick] $args
              }
          }
@@ -449,6 +472,21 @@
      }
      return
  }
+
+# ::xmpp::muc::AttrChanged --
+
+proc ::xmpp::muc::AttrChanged {token nick attr value} {
+    variable $token
+    upvar 0 $token state
+
+    if {![string equal $value ""] && \
+            (![info exists state($attr,$nick)] || \
+             ![string equal $value $state($attr,$nick)])} {
+        return 1
+    } else {
+        return 0
+    }
+}

  # ::xmpp::muc::ProcessMUCUser --

@@ -467,24 +505,18 @@
                          set args {}
                          set callback 0
                          set jid [::xmpp::xml::getAttr $attrs jid]
-                        if {![string equal $jid ""] && \
-                                (![info exists state(jid,$nick)] || \
-                                 ![string equal $jid $state(jid,$nick)])} {
+                        if {[AttrChanged $token $nick jid $jid]} {
                              lappend args -jid $jid
                              set state(jid,$nick) $jid
                          }
                          set affiliation [::xmpp::xml::getAttr $attrs  
affiliation]
-                        if {![string equal $affiliation ""] && \
-                                (![info exists state(affiliation,$nick)] | 
| \
-                                 ![string equal $affiliation  
$state(affiliation,$nick)])} {
+                        if {[AttrChanged $token $nick affiliation  
$affiliation]} {
                              lappend args -affiliation $affiliation
                              set state(affiliation,$nick) $affiliation
                              set callback 1
                          }
                          set role [::xmpp::xml::getAttr $attrs role]
-                        if {![string equal $role ""] && \
-                                (![info exists state(role,$nick)] || \
-                                 ![string equal $role  
$state(role,$nick)])} {
+                        if {[AttrChanged $token $nick role $role]} {
                              lappend args -role $role
                              set state(role,$nick) $role
                              set callback 1
@@ -533,9 +565,9 @@
          switch -- $tag {
              status {
                  set code [::xmpp::xml::getAttr $attrs code]
-                switch -- $code {
-                    110 -
-                    210 {
+                switch -- $code/$type {
+                    110/available -
+                    210/available {
                          # 110: This present packet is our own
                          # 210: The service has changed our nickname
                          set state(nick) $nick


More information about the Tkabber-dev mailing list