[Tkabber-dev] [tclxmpp] r145 committed - * xmpp/jid.tcl, doc/xmpp_jid.man: Added a new command replaceResource...

tclxmpp at googlecode.com tclxmpp at googlecode.com
Mon Feb 1 21:42:13 MSK 2010


Revision: 145
Author: sgolovan
Date: Mon Feb  1 10:41:48 2010
Log: 	* xmpp/jid.tcl, doc/xmpp_jid.man: Added a new command replaceResource
	  which replaces the resource part of a JID by a given string. Renamed
	  bareJid to removeResource for consistency.

	* xmpp/muc.tcl: Added medium lebel commands to unban user and to
	  destroy a room. Fixed malformed JIDs creation in case when their
	  resource parts are empty. Don't reset own nickname on exit from a
	  room.

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

Modified:
  /trunk/ChangeLog
  /trunk/doc/xmpp_jid.man
  /trunk/xmpp/jid.tcl
  /trunk/xmpp/muc.tcl

=======================================
--- /trunk/ChangeLog	Sat Jan 30 12:45:47 2010
+++ /trunk/ChangeLog	Mon Feb  1 10:41:48 2010
@@ -1,3 +1,14 @@
+2010-02-01  Sergei Golovan  <sgolovan at nes.ru>
+
+	* xmpp/jid.tcl, doc/xmpp_jid.man: Added a new command replaceResource
+	  which replaces the resource part of a JID by a given string. Renamed
+	  bareJid to removeResource for consistency.
+
+	* xmpp/muc.tcl: Added medium lebel commands to unban user and to
+	  destroy a room. Fixed malformed JIDs creation in case when their
+	  resource parts are empty. Don't reset own nickname on exit from a
+	  room.
+
  2010-01-30  Sergei Golovan  <sgolovan at nes.ru>

  	* xmpp/muc.tcl: Added a new reported MUC event (disconnect). Fixed
=======================================
--- /trunk/doc/xmpp_jid.man	Mon Jan 25 09:14:37 2010
+++ /trunk/doc/xmpp_jid.man	Mon Feb  1 10:41:48 2010
@@ -43,7 +43,11 @@

  Return the resource part of a specified JID.

-[call [cmd "::xmpp::jid::bareJid"] [arg "jid"]]
+[call [cmd "::xmpp::jid::replaceResource"] [arg "jid"] [arg "resource"]]
+
+Replace the resource part of a JID by a given string.
+
+[call [cmd "::xmpp::jid::removeResource"] [arg "jid"]]

  Return the bare JID (a JID without resource part) corresponding
  to a specified JID.
=======================================
--- /trunk/xmpp/jid.tcl	Fri Jan 29 07:14:25 2010
+++ /trunk/xmpp/jid.tcl	Mon Feb  1 10:41:48 2010
@@ -13,8 +13,8 @@
  package provide xmpp::jid 0.1

  namespace eval ::xmpp::jid {
-    namespace export jid split node server resource stripResource \
-                     normalize equal
+    namespace export jid split node server resource replaceResource \
+                     removeResource normalize equal

      if {![catch {package require stringprep 1.0.1}]} {
          variable Stringprep 1
@@ -180,7 +180,27 @@
      }
  }

-# ::xmpp::jid::bareJid --
+# ::xmpp::jid::replaceResource --
+#
+#       Replace resource part for a given JID.
+#
+# Arguments:
+#       jid         JID.
+#       resource    A new JID resource.
+#
+# Result:
+#       A JID constructed from node and server parts from the given JID and
+#       the given resource part.
+#
+# Side effects:
+#       None.
+
+proc ::xmpp::jid::replaceResource {jid resource} {
+    split $jid node server res
+    jid $node $server $resource
+}
+
+# ::xmpp::jid::removeResource --
  #
  #       Remove resource part from JID.
  #
@@ -194,13 +214,13 @@
  # Side effects:
  #       None.

-proc ::xmpp::jid::bareJid {jid} {
-    jid [node $jid] [server $jid]
+proc ::xmpp::jid::removeResource {jid} {
+    replaceResource $jid ""
  }

  # ::xmpp::jid::stripResource --
  #
-#       The same as bareJid (for backward compatibility.
+#       The same as removeResource (for backward compatibility.
  #
  # Arguments:
  #       jid         JID.
@@ -213,7 +233,7 @@
  #       None.

  proc ::xmpp::jid::stripResource {jid} {
-    bareJid $jid
+    removeResource $jid
  }

  # ::xmpp::jid::normalize --
=======================================
--- /trunk/xmpp/muc.tcl	Sat Jan 30 12:45:47 2010
+++ /trunk/xmpp/muc.tcl	Mon Feb  1 10:41:48 2010
@@ -158,7 +158,9 @@
      set xlib $state(xlib)
      set room $state(room)

-    if {[catch {set jid [::xmpp::jid::normalize $room/$nickname]}]} {
+    if {[catch {set jid [::xmpp::jid::normalize \
+                                [::xmpp::jid::replaceResource $room \
+                                                               
$nickname]]}]} {
          after idle [namespace code \
                          [list CallBack $commands error \
                                [::xmpp::xml::create error \
@@ -188,7 +190,8 @@
      array unset state role,*

      eval [list ::xmpp::sendPresence $xlib \
-                        -to $state(room)/$nickname \
+                        -to [::xmpp::jid::replaceResource $state(room) \
+                                                          $nickname] \
                          -xlist $newXlist \
                          -id $id] $state(args)
      return
@@ -215,7 +218,7 @@
          }
      }

-    set state(nick)   ""
+    #set state(nick)   ""
      set state(status) disconnected
      set state(args)   {}

@@ -228,8 +231,10 @@

      set state(commands) {}

-    eval [list ::xmpp::sendPresence $xlib -type unavailable \
-                                          -to $room/$nick] $newArgs
+    eval [list ::xmpp::sendPresence $xlib \
+                        -type unavailable \
+                        -to [::xmpp::jid::replaceResource $room \
+                                                          $nick]] $newArgs
  }

  # ::xmpp::muc::setNick --
@@ -291,7 +296,9 @@
      set room $state(room)
      set nick $state(nick)

-    if {[catch {set jid [::xmpp::jid::normalize $room/$nickname]}]} {
+    if {[catch {set jid [::xmpp::jid::normalize \
+                                [::xmpp::jid::replaceResource $room \
+                                                               
$nickname]]}]} {
          after idle [namespace code \
                          [list CallBack $commands error \
                                [::xmpp::xml::create error \
@@ -301,7 +308,8 @@
      set nickname [::xmpp::jid::resource $jid]

      # Changing nickname to the equivalent one does nothing useful
-    if {[::xmpp::jid::equal $room/$nick $room/$nickname]} {
+    if {[::xmpp::jid::equal [::xmpp::jid::replaceResource $room $nick] \
+                            [::xmpp::jid::replaceResource $room  
$nickname]]} {
          after idle [namespace code \
                          [list CallBack $commands error \
                                [::xmpp::xml::create error \
@@ -330,7 +338,8 @@
      set state(args) [array get Args]

      eval [list ::xmpp::sendPresence $xlib \
-                        -to $state(room)/$nickname \
+                        -to [::xmpp::jid::replaceResource $state(room) \
+                                                          $nickname] \
                          -id $id] $state(args)
  }

@@ -402,7 +411,7 @@
              }

              if {[string equal $nick $state(nick)]} {
-                set state(nick)   ""
+                #set state(nick)   ""
                  set state(status) disconnected
                  set state(args)   {}

@@ -746,22 +755,19 @@

  # ::xmpp::muc::setAffiliation --

-proc ::xmpp::muc::setAffiliation {token nick affiliation args} {
-    eval [list SetAttr $token $nick affiliation $affiliation] $args
+proc ::xmpp::muc::setAffiliation {xlib room nick affiliation args} {
+    eval [list SetAttr $xlib $room $nick affiliation $affiliation] $args
  }

  # ::xmpp::muc::setRole --

-proc ::xmpp::muc::setRole {token nick role args} {
-    eval [list SetAttr $token $nick role $role] $args
+proc ::xmpp::muc::setRole {xlib room nick role args} {
+    eval [list SetAttr $xlib $room $nick role $role] $args
  }

  # ::xmpp::muc::SetAttr --

-proc ::xmpp::muc::SetAttr {token nick attr value args} {
-    variable $token
-    upvar 0 $token state
-
+proc ::xmpp::muc::SetAttr {xlib room nick attr value args} {
      set commands {}
      foreach {key val} $args {
          switch -- $key {
@@ -770,16 +776,6 @@
          }
      }

-    if {![info exists state(xlib)]} {
-        CallBack $commands error \
-                 [::xmpp::xml::create error \
-                            -cdata [::msgcat::mc "MUC token doesn't  
exist"]]
-        return
-    }
-
-    set xlib $state(xlib)
-    set room $state(room)
-
      if {[info exists reason]} {
          set subels [list [::xmpp::xml::create reason -cdata $reason]]
      } else {
@@ -1038,5 +1034,91 @@
              -to $room \
              -command [namespace code [list CallBack $commands]]
  }
+
+# ::xmpp::muc::unsetOutcast --
+
+proc ::xmpp::muc::unsetOutcast {xlib room jid args} {
+    set commands {}
+    foreach {key val} $args {
+        switch -- $key {
+            -command { set commands [list $val] }
+        }
+    }
+
+    RequestList $xlib $room affiliation outcast \
+                -command [namespace code [list ParseOutcastList \
+                                               $xlib $room $jid $commands]]
+}
+
+# ::xmpp::muc::ParseOutcastList --
+
+proc ::xmpp::muc::ParseOutcastList {xlib room jid status items} {
+    if {![string equal $status ok]} {
+        CallBack $commands $status $items
+        return
+    }
+
+    set bjid [xmpp::jid::normalize [::xmpp::jid::bareJid $jid]]
+    set found 0
+    foreach item $items {
+        foreach {nick jid affiliation reason} $item break
+
+        if {[string equal $jid $bjid]} {
+            set found 1
+            break
+        }
+    }
+
+    if {!$found} {
+        CallBack $commands error \
+                 [::xmpp::xml::create error \
+                            -cdata [::msgcat::mc "User is not banned"]]
+        return
+    }
+
+    set item [::xmpp::xml::create item \
+                    -attrs [list jid $bjid affiliation none]]
+
+    ::xmpp::sendIQ $xlib set \
+            -query [::xmpp::xml::create query \
+                            -xmlns "http://jabber.org/protocol/muc#admin" \
+                            -subelement $item] \
+            -to $room \
+            -command [namespace code [list CallBack $commands]]
+}
+
+# ::xmpp::muc::destroy --
+
+proc ::xmpp::muc::destroy {xlib room args} {
+    set commands {}
+    foreach {key val} $args {
+        switch -- $key {
+            -jid     { set jid $val }
+            -reason  { set reason $val }
+            -command { set commands [list $val] }
+        }
+    }
+
+    if {[info exists jid]} {
+        set attrs [list jid $jid]
+    } else {
+        set attrs {}
+    }
+
+    if {[info exists reason]} {
+        set subels [list [::xmpp::xml::create reason -cdata $reason]]
+    } else {
+        set subels {}
+    }
+
+    ::xmpp::sendIQ $xlib set \
+            -query [::xmpp::xml::create query \
+                            -xmlns "http://jabber.org/protocol/muc#owner" \
+                            -subelement [::xmpp::xml::create destroy \
+                                                -attrs $attrs \
+                                                -subelements $subels]] \
+            -to $room \
+            -command [namespace code [list CallBack $commands]]
+}

  # vim:ft=tcl:ts=8:sw=4:sts=4:et


More information about the Tkabber-dev mailing list