summaryrefslogtreecommitdiffstats
path: root/src/com
diff options
context:
space:
mode:
authorKevin Smith <git@kismith.co.uk>2011-07-28 13:09:53 (GMT)
committerKevin Smith <git@kismith.co.uk>2012-03-07 12:18:00 (GMT)
commit0470264fd4f9e7e73d1b655dc680e5ca7c10513c (patch)
tree95e58af6ac3553123d2c404acee03938b4732647 /src/com
parenteca0a80a7abb136094f252872499c59803999f85 (diff)
downloadstroke-0470264fd4f9e7e73d1b655dc680e5ca7c10513c.zip
stroke-0470264fd4f9e7e73d1b655dc680e5ca7c10513c.tar.bz2
Stringprep JIDs through icu4j
Diffstat (limited to 'src/com')
-rw-r--r--src/com/isode/stroke/jid/JID.java55
1 files changed, 44 insertions, 11 deletions
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;
}