From 0470264fd4f9e7e73d1b655dc680e5ca7c10513c Mon Sep 17 00:00:00 2001 From: Kevin Smith Date: Thu, 28 Jul 2011 14:09:53 +0100 Subject: Stringprep JIDs through icu4j diff --git a/Makefile b/Makefile index 85de348..6241ae2 100644 --- a/Makefile +++ b/Makefile @@ -10,19 +10,22 @@ distclean: clean rm -rf third-party .PHONY : dist/lib/stroke.jar -dist/lib/stroke.jar: third-party/xpp/xpp.jar third-party/jzlib/jzlib.jar +dist/lib/stroke.jar: third-party/xpp/xpp.jar third-party/jzlib/jzlib.jar third-party/icu4j.jar ant -Dxpp-dir=third-party/xpp -Djzlib-dir=third-party/jzlib -third-party/xpp/xpp.jar: third-party +third-party/xpp/xpp.jar: mkdir -p third-party/xpp curl http://www.extreme.indiana.edu/dist/java-repository/xpp3/jars/xpp3-1.1.4c.jar -o third-party/xpp/xpp.jar -third-party/jzlib/jzlib.jar: third-party +third-party/jzlib/jzlib.jar: + mkdir -p third-party curl http://www.jcraft.com/jzlib/jzlib-1.0.7.tar.gz -o third-party/jzlib-1.0.7.tar.gz tar -xvzf third-party/jzlib-1.0.7.tar.gz -C third-party/ mv third-party/jzlib-1.0.7 third-party/jzlib cp build-jzlib.xml third-party/jzlib/build.xml ant -f third-party/jzlib/build.xml -third-party: - mkdir -p third-party \ No newline at end of file +third-party/icu4j.jar: + mkdir -p third-party + curl http://download.icu-project.org/files/icu4j/4.8.1/icu4j-4_8_1.jar -o third-party/icu4j.jar + diff --git a/build.xml b/build.xml index 709f20e..6e5cbde 100644 --- a/build.xml +++ b/build.xml @@ -16,12 +16,14 @@ - + + + diff --git a/src/com/isode/stroke/jid/JID.java b/src/com/isode/stroke/jid/JID.java index a256944..a93bebc 100644 --- a/src/com/isode/stroke/jid/JID.java +++ b/src/com/isode/stroke/jid/JID.java @@ -8,6 +8,11 @@ */ package com.isode.stroke.jid; +import com.ibm.icu.text.StringPrep; +import com.ibm.icu.text.StringPrepParseException; +import java.util.logging.Level; +import java.util.logging.Logger; + /** * JID helper. * @@ -82,16 +87,30 @@ public class JID { bare = jid; } String[] nodeAndDomain = bare.split("@", 2); + String node; + String domain; if (nodeAndDomain.length == 1) { - node_ = ""; - domain_ = nodeAndDomain[0]; - resource_ = resource; + node = ""; + domain = nodeAndDomain[0]; } else { - node_ = nodeAndDomain[0]; - domain_ = nodeAndDomain[1]; - resource_ = resource; + node = nodeAndDomain[0]; + domain = nodeAndDomain[1]; } - + StringPrep nodePrep = StringPrep.getInstance(StringPrep.RFC3491_NAMEPREP); + StringPrep domainPrep = StringPrep.getInstance(StringPrep.RFC3920_NODEPREP); + StringPrep resourcePrep = StringPrep.getInstance(StringPrep.RFC3920_RESOURCEPREP); + try { + node = nodePrep.prepare(node, StringPrep.DEFAULT); + domain = domainPrep.prepare(domain, StringPrep.DEFAULT); + resource = resource != null ? resourcePrep.prepare(resource, StringPrep.DEFAULT) : null; + } catch (StringPrepParseException ex) { + node = ""; + domain = ""; + resource = ""; + } + node_ = node; + domain_ = domain; + resource_ = resource; } /** @@ -118,10 +137,24 @@ public class JID { * @param resource JID resource part. */ public JID(final String node, final String domain, final String resource) { - //FIXME: This doesn't nameprep! - node_ = node; - domain_ = domain; - resource_ = resource; + StringPrep nodePrep = StringPrep.getInstance(StringPrep.RFC3491_NAMEPREP); + StringPrep domainPrep = StringPrep.getInstance(StringPrep.RFC3920_NODEPREP); + StringPrep resourcePrep = StringPrep.getInstance(StringPrep.RFC3920_RESOURCEPREP); + String preppedNode; + String preppedDomain; + String preppedResource; + try { + preppedNode = nodePrep.prepare(node, StringPrep.DEFAULT); + preppedDomain = domainPrep.prepare(domain, StringPrep.DEFAULT); + preppedResource = resource != null ? resourcePrep.prepare(resource, StringPrep.DEFAULT) : null; + } catch (StringPrepParseException ex) { + preppedNode = ""; + preppedDomain = ""; + preppedResource = ""; + } + node_ = preppedNode; + domain_ = preppedDomain; + resource_ = preppedResource; } -- cgit v0.10.2-6-g49f6