[Tkabber-dev] [tclxmpp] r140 committed - * xmpp/jid.tcl: Added stringprep support in JID normalization.

tclxmpp at googlecode.com tclxmpp at googlecode.com
Sun Jan 24 17:21:12 MSK 2010


Revision: 140
Author: sgolovan
Date: Sun Jan 24 06:20:01 2010
Log: 	* xmpp/jid.tcl: Added stringprep support in JID normalization.

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

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

=======================================
--- /trunk/ChangeLog	Sat Jan 23 06:47:26 2010
+++ /trunk/ChangeLog	Sun Jan 24 06:20:01 2010
@@ -1,3 +1,7 @@
+2010-01-24  Sergei Golovan  <sgolovan at nes.ru>
+
+	* xmpp/jid.tcl: Added stringprep support in JID normalization.
+
  2010-01-23  Sergei Golovan  <sgolovan at nes.ru>

  	* xmpp/negotiate.tcl, xmpp/register.tcl, xmpp/search.tcl: Reimplemented
=======================================
--- /trunk/xmpp/jid.tcl	Sat Jan 23 00:12:12 2010
+++ /trunk/xmpp/jid.tcl	Sun Jan 24 06:20:01 2010
@@ -16,10 +16,31 @@
      namespace export jid split node server resource stripResource \
                       normalize equal

-    if {[catch {package require stringprep}]} {
-        variable Stringprep 0
-    } else {
+    if {![catch {package require stringprep 1.0.1}]} {
          variable Stringprep 1
+
+        ::stringprep::register nameprep \
+                -mapping {B.1 B.2} \
+                -normalization KC \
+                -prohibited {A.1 C.1.2 C.2.2 C.3 C.4 C.5 C.6 C.7 C.8 C.9} \
+                -prohibitedBidi 1
+
+        ::stringprep::register nodeprep \
+                -mapping {B.1 B.2} \
+                -normalization KC \
+                -prohibited {A.1 C.1.1 C.1.2 C.2.1 C.2.2 C.3 C.4 C.5 C.6
+                             C.7 C.8 C.9} \
+                -prohibitedList {0x22 0x26 0x27 0x2f 0x3a 0x3c 0x3e 0x40} \
+                -prohibitedBidi 1
+
+        ::stringprep::register resourceprep \
+                -mapping {B.1} \
+                -normalization KC \
+                -prohibited {A.1 C.1.2 C.2.1 C.2.2 C.3 C.4 C.5 C.6 C.7
+                             C.8 C.9} \
+                -prohibitedBidi 1
+    } else {
+        variable Stringprep 0
      }
  }

@@ -197,21 +218,34 @@

  # ::xmpp::jid::normalize --
  #
-#       Normalize JID (convert node and server parts to lowercase).
+#       Normalize JID for comparison. In case if stringprep package is  
loaded
+#       it means applying the correspondent stringprep profiles to JID  
node,
+#       server and resource. If stringprep isn'r available then JID node  
and
+#       server parts are simply converted to lowercase.
  #
  # Arguments:
  #       jid         JID.
  #
  # Result:
-#       A JID with node and server parts converted to lowercase.
+#       A normalised JID with either all its parts stringprepped or with  
node
+#       and server parts converted to lowercase. If JID is malformed then  
the
+#       error is returned.
  #
  # Side effects:
  #       None.

  proc ::xmpp::jid::normalize {jid} {
-    set node     [string tolower [node $jid]]
-    set server   [string tolower [server $jid]]
-    set resource [resource $jid]
+    variable Stringprep
+
+    if {$Stringprep} {
+        set node     [::stringprep::stringprep nodeprep [node $jid]]
+        set server   [::stringprep::stringprep nameprep [server $jid]]
+        set resource [::stringprep::stringprep resourceprep [resource  
$jid]]
+    } else {
+        set node     [string tolower [node $jid]]
+        set server   [string tolower [server $jid]]
+        set resource [resource $jid]
+    }

      jid $node $server $resource
  }
@@ -225,7 +259,8 @@
  #       jid1        JID to compare.
  #
  # Result:
-#       1 if normalized JIDs are equal, 0 otherwise.
+#       1 if normalized JIDs are equal, 0 otherwise. Error if some of the  
JIDs
+#       is malformed.
  #
  # Side effects:
  #       None.


More information about the Tkabber-dev mailing list