Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorslewis2008-09-11 16:25:27 -0400
committerslewis2008-09-11 16:25:27 -0400
commitdaa6e995e0daa68c47b38a8a5f6e465500851176 (patch)
tree80ea0bed8f83d2f9b895bba7984bfdac055c6f72 /providers/bundles/org.eclipse.ecf.provider.xmpp
parent44b24f08fced7a3f9b3a0dd4d00f87ae0328c0bb (diff)
downloadorg.eclipse.ecf-daa6e995e0daa68c47b38a8a5f6e465500851176.tar.gz
org.eclipse.ecf-daa6e995e0daa68c47b38a8a5f6e465500851176.tar.xz
org.eclipse.ecf-daa6e995e0daa68c47b38a8a5f6e465500851176.zip
Fix for bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=247039
Diffstat (limited to 'providers/bundles/org.eclipse.ecf.provider.xmpp')
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/XMPPContainerPresenceHelper.java15
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/smack/ECFConnection.java2
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/identity/XMPPID.java81
3 files changed, 83 insertions, 15 deletions
diff --git a/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/XMPPContainerPresenceHelper.java b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/XMPPContainerPresenceHelper.java
index 67e7ea86d..dc87825a2 100644
--- a/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/XMPPContainerPresenceHelper.java
+++ b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/XMPPContainerPresenceHelper.java
@@ -369,11 +369,15 @@ public class XMPPContainerPresenceHelper implements ISharedObject {
}
protected IRosterEntry createRosterEntry(RosterEntry entry) {
- return createRosterEntry(createIDFromName(entry.getUser()), entry.getName(), entry.getGroups());
+ final XMPPID xmppid = createIDFromName(entry.getUser());
+ final String name = (entry.getName() == null) ? xmppid.getUsername() : entry.getName();
+ return createRosterEntry(xmppid, name, entry.getGroups());
}
protected IRosterEntry createRosterEntry(RosterPacket.Item entry) {
- return createRosterEntry(createIDFromName(entry.getUser()), entry.getName(), entry.getGroupNames());
+ final XMPPID xmppid = createIDFromName(entry.getUser());
+ final String name = (entry.getName() == null) ? xmppid.getUsername() : entry.getName();
+ return createRosterEntry(xmppid, name, entry.getGroupNames());
}
protected void handleIQEvent(IQEvent evt) {
@@ -545,7 +549,7 @@ public class XMPPContainerPresenceHelper implements ISharedObject {
protected XMPPID createIDFromName(String uname) {
try {
- if (uname.indexOf('@') == -1) {
+ if (uname.lastIndexOf('@') == -1) {
return new XMPPID(container.getConnectNamespace(), "admin" + "@" + uname);
}
return new XMPPID(container.getConnectNamespace(), uname);
@@ -785,7 +789,10 @@ public class XMPPContainerPresenceHelper implements ISharedObject {
}
protected IRosterItem[] createRosterEntries(RosterEntry entry) {
- return createRosterEntries(entry.getGroups(), roster, new User(createIDFromName(entry.getUser()), entry.getName()));
+ final XMPPID xmppid = createIDFromName(entry.getUser());
+ final String name = entry.getName();
+ final User newUser = (name == null) ? new User(xmppid, xmppid.getUsername()) : new User(xmppid, name);
+ return createRosterEntries(entry.getGroups(), roster, newUser);
}
private IRosterItem[] createRosterEntries(Iterator grps, IRosterItem parent, IUser user) {
diff --git a/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/smack/ECFConnection.java b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/smack/ECFConnection.java
index 08a951e45..ba1cc5fd9 100644
--- a/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/smack/ECFConnection.java
+++ b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/smack/ECFConnection.java
@@ -152,7 +152,7 @@ public class ECFConnection implements ISynchAsynchConnection {
Roster.setDefaultSubscriptionMode(Roster.SUBSCRIPTION_MANUAL);
final XMPPID jabberURI = getXMPPID(remote);
- final String username = jabberURI.getUsername();
+ final String username = jabberURI.getNodename();
serverName = jabberURI.getHostname();
serverPort = jabberURI.getPort();
serverResource = jabberURI.getResourceName();
diff --git a/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/identity/XMPPID.java b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/identity/XMPPID.java
index d11c0dde5..3ad26fe90 100644
--- a/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/identity/XMPPID.java
+++ b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/identity/XMPPID.java
@@ -12,6 +12,8 @@ package org.eclipse.ecf.provider.xmpp.identity;
import java.net.URI;
import java.net.URISyntaxException;
+import java.util.Hashtable;
+import java.util.Iterator;
import org.eclipse.ecf.core.identity.BaseID;
import org.eclipse.ecf.core.identity.Namespace;
@@ -26,28 +28,83 @@ public class XMPPID extends BaseID implements IChatID, IFQID {
public static final char PORT_DELIMITER = ':';
public static final String PATH_DELIMITER = "/";
+ static class XMPPEscape {
+ StringBuffer buf = new StringBuffer();
+
+ public XMPPEscape(char[] chars) {
+ if (chars != null) {
+ for (int i = 0; i < chars.length; i++) {
+ buf.append(chars[i]);
+ }
+ }
+ }
+
+ public CharSequence getAsCharSequence() {
+ return buf;
+ }
+
+ }
+
+ protected static Hashtable escapeTable;
+
+ static {
+ escapeTable = new Hashtable(10);
+ escapeTable.put("@", new XMPPEscape(new char[] {'\\', '4', '0'}));
+ escapeTable.put("\"", new XMPPEscape(new char[] {'\\', '2', '2'}));
+ escapeTable.put("&", new XMPPEscape(new char[] {'\\', '2', '6'}));
+ escapeTable.put("'", new XMPPEscape(new char[] {'\\', '2', '7'}));
+ escapeTable.put("/", new XMPPEscape(new char[] {'\\', '2', 'f'}));
+ escapeTable.put(":", new XMPPEscape(new char[] {'\\', '3', 'a'}));
+ escapeTable.put("<", new XMPPEscape(new char[] {'\\', '3', 'c'}));
+ escapeTable.put(">", new XMPPEscape(new char[] {'\\', '3', 'e'}));
+ escapeTable.put("\\", new XMPPEscape(new char[] {'\\', '5', 'c'}));
+ }
+
+ // implements JEP-0106 JID escaping: http://www.xmpp.org/extensions/xep-0106.html
+ static String fixEscapeInNode(String node) {
+ if (node == null)
+ return null;
+ for (final Iterator i = escapeTable.keySet().iterator(); i.hasNext();) {
+ final String key = (String) i.next();
+ final XMPPEscape escape = (XMPPEscape) escapeTable.get(key);
+ node = node.replace(new StringBuffer(key), escape.getAsCharSequence());
+ }
+ return node;
+ }
+
+ static String fixPercentEscape(String src) {
+ if (src == null)
+ return null;
+ return src.replaceAll("%", "%25");
+ }
+
+ static String unfixEscapeInNode(String node) {
+ if (node == null)
+ return null;
+ for (final Iterator i = escapeTable.keySet().iterator(); i.hasNext();) {
+ final String key = (String) i.next();
+ final XMPPEscape escape = (XMPPEscape) escapeTable.get(key);
+ node = node.replace(escape.getAsCharSequence(), new StringBuffer(key));
+ }
+ return node;
+ }
+
URI uri;
String username;
String hostname;
String resourcename;
int port = -1;
- protected static String fixEscape(String src) {
- if (src == null)
- return null;
- return src.replaceAll("%", "%25"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
public XMPPID(Namespace namespace, String unamehost) throws URISyntaxException {
super(namespace);
- unamehost = fixEscape(unamehost);
+ unamehost = fixPercentEscape(unamehost);
if (unamehost == null)
throw new URISyntaxException(unamehost, Messages.XMPPID_EXCEPTION_XMPPID_USERNAME_NOT_NULL);
// Handle parsing of user@host/resource string
int atIndex = unamehost.lastIndexOf(USER_HOST_DELIMITER);
if (atIndex == -1)
throw new URISyntaxException(unamehost, Messages.XMPPID_EXCEPTION_HOST_PORT_NOT_VALID);
- username = unamehost.substring(0, atIndex);
+ username = fixEscapeInNode(unamehost.substring(0, atIndex));
final String remainder = unamehost.substring(atIndex + 1);
// Handle parsing of host:port
atIndex = remainder.lastIndexOf(PORT_DELIMITER);
@@ -96,6 +153,10 @@ public class XMPPID extends BaseID implements IChatID, IFQID {
return getUsernameAtHost().hashCode();
}
+ public String getNodename() {
+ return username;
+ }
+
/* (non-Javadoc)
* @see org.eclipse.ecf.core.identity.BaseID#namespaceToExternalForm()
*/
@@ -104,7 +165,7 @@ public class XMPPID extends BaseID implements IChatID, IFQID {
}
public String getUsername() {
- return username;
+ return unfixEscapeInNode(username);
}
public String getHostname() {
@@ -133,7 +194,7 @@ public class XMPPID extends BaseID implements IChatID, IFQID {
public String toString() {
final StringBuffer sb = new StringBuffer("XMPPID["); //$NON-NLS-1$
- sb.append(uri.toString()).append("]"); //$NON-NLS-1$
+ sb.append(uri.toString()).append("]");
return sb.toString();
}

Back to the top