mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-23 04:22:05 +01:00
Rolling back some JID escaping work related to SMACK-170.
git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@5384 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
parent
6be93f4a4e
commit
e65ecdc913
8 changed files with 186 additions and 233 deletions
|
@ -40,10 +40,10 @@ import java.lang.reflect.Method;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.CopyOnWriteArrayList;
|
import java.util.concurrent.CopyOnWriteArraySet;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a connection to a XMPP server. A simple use of this API might
|
* Creates a connection to a XMPP server. A simple use of this API might
|
||||||
|
@ -89,8 +89,8 @@ public class XMPPConnection {
|
||||||
*/
|
*/
|
||||||
public static boolean DEBUG_ENABLED = false;
|
public static boolean DEBUG_ENABLED = false;
|
||||||
|
|
||||||
private final static List<ConnectionEstablishedListener> connectionEstablishedListeners =
|
private final static Set<ConnectionEstablishedListener> connectionEstablishedListeners =
|
||||||
new CopyOnWriteArrayList<ConnectionEstablishedListener>();
|
new CopyOnWriteArraySet<ConnectionEstablishedListener>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
// Use try block since we may not have permission to get a system
|
// Use try block since we may not have permission to get a system
|
||||||
|
@ -396,7 +396,6 @@ public class XMPPConnection {
|
||||||
}
|
}
|
||||||
// Do partial version of nameprep on the username.
|
// Do partial version of nameprep on the username.
|
||||||
username = username.toLowerCase().trim();
|
username = username.toLowerCase().trim();
|
||||||
username = StringUtils.escapeNode(username);
|
|
||||||
|
|
||||||
String response;
|
String response;
|
||||||
if (configuration.isSASLAuthenticationEnabled() &&
|
if (configuration.isSASLAuthenticationEnabled() &&
|
||||||
|
@ -819,9 +818,7 @@ public class XMPPConnection {
|
||||||
* @param connectionEstablishedListener a listener interested on connection established events.
|
* @param connectionEstablishedListener a listener interested on connection established events.
|
||||||
*/
|
*/
|
||||||
public static void addConnectionEstablishedListener(ConnectionEstablishedListener connectionEstablishedListener) {
|
public static void addConnectionEstablishedListener(ConnectionEstablishedListener connectionEstablishedListener) {
|
||||||
if (!connectionEstablishedListeners.contains(connectionEstablishedListener)) {
|
connectionEstablishedListeners.add(connectionEstablishedListener);
|
||||||
connectionEstablishedListeners.add(connectionEstablishedListener);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -122,8 +122,7 @@ public abstract class Packet {
|
||||||
* @param to who the packet is being sent to.
|
* @param to who the packet is being sent to.
|
||||||
*/
|
*/
|
||||||
public void setTo(String to) {
|
public void setTo(String to) {
|
||||||
// Use escaped version of the JID in case the user included invalid characters.
|
this.to = to;
|
||||||
this.to = StringUtils.escapeJID(to);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -146,8 +145,7 @@ public abstract class Packet {
|
||||||
* @param from who the packet is being sent to.
|
* @param from who the packet is being sent to.
|
||||||
*/
|
*/
|
||||||
public void setFrom(String from) {
|
public void setFrom(String from) {
|
||||||
// Use escaped version of the JID in case the user included invalid characters.
|
this.from = from;
|
||||||
this.from = StringUtils.escapeJID(from);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -198,7 +198,7 @@ public class RosterPacket extends IQ {
|
||||||
|
|
||||||
public String toXML() {
|
public String toXML() {
|
||||||
StringBuilder buf = new StringBuilder();
|
StringBuilder buf = new StringBuilder();
|
||||||
buf.append("<item jid=\"").append(StringUtils.escapeJID(user)).append("\"");
|
buf.append("<item jid=\"").append(user).append("\"");
|
||||||
if (name != null) {
|
if (name != null) {
|
||||||
buf.append(" name=\"").append(StringUtils.escapeForXML(name)).append("\"");
|
buf.append(" name=\"").append(StringUtils.escapeForXML(name)).append("\"");
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,7 @@ public class StringUtils {
|
||||||
if (XMPPAddress == null) {
|
if (XMPPAddress == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
int atIndex = XMPPAddress.lastIndexOf("@");
|
int atIndex = XMPPAddress.indexOf("@");
|
||||||
if (atIndex <= 0) {
|
if (atIndex <= 0) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ public class StringUtils {
|
||||||
if (XMPPAddress == null) {
|
if (XMPPAddress == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
int atIndex = XMPPAddress.lastIndexOf("@");
|
int atIndex = XMPPAddress.indexOf("@");
|
||||||
// If the String ends with '@', return the empty string.
|
// If the String ends with '@', return the empty string.
|
||||||
if (atIndex + 1 > XMPPAddress.length()) {
|
if (atIndex + 1 > XMPPAddress.length()) {
|
||||||
return "";
|
return "";
|
||||||
|
@ -127,8 +127,6 @@ public class StringUtils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Escapes the node portion of a JID according to "JID Escaping" (JEP-0106).
|
* Escapes the node portion of a JID according to "JID Escaping" (JEP-0106).
|
||||||
* Escaping replaces characters prohibited by node-prep with escape sequences,
|
* Escaping replaces characters prohibited by node-prep with escape sequences,
|
||||||
|
@ -168,9 +166,15 @@ public class StringUtils {
|
||||||
for (int i=0, n=node.length(); i<n; i++) {
|
for (int i=0, n=node.length(); i<n; i++) {
|
||||||
char c = node.charAt(i);
|
char c = node.charAt(i);
|
||||||
switch (c) {
|
switch (c) {
|
||||||
|
case '"': buf.append("\\22"); break;
|
||||||
|
case '&': buf.append("\\26"); break;
|
||||||
|
case '\'': buf.append("\\27"); break;
|
||||||
|
case '/': buf.append("\\2f"); break;
|
||||||
|
case ':': buf.append("\\3a"); break;
|
||||||
|
case '<': buf.append("\\3c"); break;
|
||||||
|
case '>': buf.append("\\3e"); break;
|
||||||
case '@': buf.append("\\40"); break;
|
case '@': buf.append("\\40"); break;
|
||||||
|
case '\\': buf.append("\\5c"); break;
|
||||||
default: {
|
default: {
|
||||||
if (Character.isWhitespace(c)) {
|
if (Character.isWhitespace(c)) {
|
||||||
buf.append("\\20");
|
buf.append("\\20");
|
||||||
|
@ -184,43 +188,6 @@ public class StringUtils {
|
||||||
return buf.toString();
|
return buf.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Escapes a complete JID by examing the Node itself and escaping
|
|
||||||
* when neccessary.
|
|
||||||
* @param jid the users JID
|
|
||||||
* @return the escaped JID.
|
|
||||||
*/
|
|
||||||
public static String escapeJID(String jid){
|
|
||||||
if(jid == null){
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
final StringBuilder builder = new StringBuilder();
|
|
||||||
String node = parseName(jid);
|
|
||||||
String restOfJID = jid.substring(node.length());
|
|
||||||
builder.append(escapeNode(node));
|
|
||||||
builder.append(restOfJID);
|
|
||||||
return builder.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Unescapes a complete JID by examing the node itself and unescaping when necessary.
|
|
||||||
* @param jid the users jid.
|
|
||||||
* @return the unescaped JID.
|
|
||||||
*/
|
|
||||||
public static String unescapeJID(String jid){
|
|
||||||
if(jid == null){
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
final StringBuilder builder = new StringBuilder();
|
|
||||||
String node = parseName(jid);
|
|
||||||
String restOfJID = jid.substring(node.length());
|
|
||||||
builder.append(unescapeNode(node));
|
|
||||||
builder.append(restOfJID);
|
|
||||||
return builder.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Un-escapes the node portion of a JID according to "JID Escaping" (JEP-0106).<p>
|
* Un-escapes the node portion of a JID according to "JID Escaping" (JEP-0106).<p>
|
||||||
* Escaping replaces characters prohibited by node-prep with escape sequences,
|
* Escaping replaces characters prohibited by node-prep with escape sequences,
|
||||||
|
|
|
@ -20,8 +20,6 @@
|
||||||
|
|
||||||
package org.jivesoftware.smackx;
|
package org.jivesoftware.smackx;
|
||||||
|
|
||||||
import org.jivesoftware.smack.util.StringUtils;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
@ -290,7 +288,7 @@ public class FormField {
|
||||||
}
|
}
|
||||||
// Loop through all the values and append them to the string buffer
|
// Loop through all the values and append them to the string buffer
|
||||||
for (Iterator<String> i = getValues(); i.hasNext();) {
|
for (Iterator<String> i = getValues(); i.hasNext();) {
|
||||||
buf.append("<value>").append(StringUtils.escapeForXML(i.next())).append("</value>");
|
buf.append("<value>").append(i.next()).append("</value>");
|
||||||
}
|
}
|
||||||
// Loop through all the values and append them to the string buffer
|
// Loop through all the values and append them to the string buffer
|
||||||
for (Iterator i = getOptions(); i.hasNext();) {
|
for (Iterator i = getOptions(); i.hasNext();) {
|
||||||
|
|
|
@ -20,8 +20,6 @@
|
||||||
|
|
||||||
package org.jivesoftware.smackx;
|
package org.jivesoftware.smackx;
|
||||||
|
|
||||||
import org.jivesoftware.smack.util.StringUtils;
|
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -37,7 +35,7 @@ public class RemoteRosterEntry {
|
||||||
|
|
||||||
private String user;
|
private String user;
|
||||||
private String name;
|
private String name;
|
||||||
private List groupNames = new ArrayList();
|
private final List<String> groupNames = new ArrayList<String>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new remote roster entry.
|
* Creates a new remote roster entry.
|
||||||
|
@ -51,7 +49,7 @@ public class RemoteRosterEntry {
|
||||||
this.user = user;
|
this.user = user;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
if (groups != null) {
|
if (groups != null) {
|
||||||
groupNames = new ArrayList(Arrays.asList(groups));
|
groupNames.addAll(Arrays.asList(groups));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,23 +91,19 @@ public class RemoteRosterEntry {
|
||||||
*/
|
*/
|
||||||
public String[] getGroupArrayNames() {
|
public String[] getGroupArrayNames() {
|
||||||
synchronized (groupNames) {
|
synchronized (groupNames) {
|
||||||
return (String[])
|
return Collections.unmodifiableList(groupNames).toArray(new String[groupNames.size()]);
|
||||||
(Collections
|
|
||||||
.unmodifiableList(groupNames)
|
|
||||||
.toArray(new String[groupNames.size()]));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toXML() {
|
public String toXML() {
|
||||||
StringBuilder buf = new StringBuilder();
|
StringBuilder buf = new StringBuilder();
|
||||||
buf.append("<item jid=\"").append(StringUtils.escapeJID(user)).append("\"");
|
buf.append("<item jid=\"").append(user).append("\"");
|
||||||
if (name != null) {
|
if (name != null) {
|
||||||
buf.append(" name=\"").append(name).append("\"");
|
buf.append(" name=\"").append(name).append("\"");
|
||||||
}
|
}
|
||||||
buf.append(">");
|
buf.append(">");
|
||||||
synchronized (groupNames) {
|
synchronized (groupNames) {
|
||||||
for (int i = 0; i < groupNames.size(); i++) {
|
for (String groupName : groupNames) {
|
||||||
String groupName = (String) groupNames.get(i);
|
|
||||||
buf.append("<group>").append(groupName).append("</group>");
|
buf.append("<group>").append(groupName).append("</group>");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,6 @@
|
||||||
package org.jivesoftware.smackx.packet;
|
package org.jivesoftware.smackx.packet;
|
||||||
|
|
||||||
import org.jivesoftware.smack.packet.PacketExtension;
|
import org.jivesoftware.smack.packet.PacketExtension;
|
||||||
import org.jivesoftware.smack.util.StringUtils;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents extended presence information about roles, affiliations, full JIDs,
|
* Represents extended presence information about roles, affiliations, full JIDs,
|
||||||
|
@ -277,7 +276,7 @@ public class MUCUser implements PacketExtension {
|
||||||
buf.append("</invite>");
|
buf.append("</invite>");
|
||||||
return buf.toString();
|
return buf.toString();
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a rejection to an invitation from another user to a room. The rejection will be
|
* Represents a rejection to an invitation from another user to a room. The rejection will be
|
||||||
|
@ -362,7 +361,7 @@ public class MUCUser implements PacketExtension {
|
||||||
buf.append("</decline>");
|
buf.append("</decline>");
|
||||||
return buf.toString();
|
return buf.toString();
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Item child that holds information about roles, affiliation, jids and nicks.
|
* Item child that holds information about roles, affiliation, jids and nicks.
|
||||||
|
@ -497,7 +496,7 @@ public class MUCUser implements PacketExtension {
|
||||||
buf.append(" affiliation=\"").append(getAffiliation()).append("\"");
|
buf.append(" affiliation=\"").append(getAffiliation()).append("\"");
|
||||||
}
|
}
|
||||||
if (getJid() != null) {
|
if (getJid() != null) {
|
||||||
buf.append(" jid=\"").append(StringUtils.escapeJID(getJid())).append("\"");
|
buf.append(" jid=\"").append(getJid()).append("\"");
|
||||||
}
|
}
|
||||||
if (getNick() != null) {
|
if (getNick() != null) {
|
||||||
buf.append(" nick=\"").append(getNick()).append("\"");
|
buf.append(" nick=\"").append(getNick()).append("\"");
|
||||||
|
@ -514,13 +513,13 @@ public class MUCUser implements PacketExtension {
|
||||||
buf.append("<reason>").append(getReason()).append("</reason>");
|
buf.append("<reason>").append(getReason()).append("</reason>");
|
||||||
}
|
}
|
||||||
if (getActor() != null) {
|
if (getActor() != null) {
|
||||||
buf.append("<actor jid=\"").append(StringUtils.escapeJID(getActor())).append("\"/>");
|
buf.append("<actor jid=\"").append(getActor()).append("\"/>");
|
||||||
}
|
}
|
||||||
buf.append("</item>");
|
buf.append("</item>");
|
||||||
}
|
}
|
||||||
return buf.toString();
|
return buf.toString();
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Status code assists in presenting notification messages. The following link provides the
|
* Status code assists in presenting notification messages. The following link provides the
|
||||||
|
@ -555,7 +554,7 @@ public class MUCUser implements PacketExtension {
|
||||||
buf.append("<status code=\"").append(getCode()).append("\"/>");
|
buf.append("<status code=\"").append(getCode()).append("\"/>");
|
||||||
return buf.toString();
|
return buf.toString();
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a notification that the room has been destroyed. After a room has been destroyed,
|
* Represents a notification that the room has been destroyed. After a room has been destroyed,
|
||||||
|
@ -609,7 +608,7 @@ public class MUCUser implements PacketExtension {
|
||||||
StringBuilder buf = new StringBuilder();
|
StringBuilder buf = new StringBuilder();
|
||||||
buf.append("<destroy");
|
buf.append("<destroy");
|
||||||
if (getJid() != null) {
|
if (getJid() != null) {
|
||||||
buf.append(" jid=\"").append(StringUtils.escapeJID(getJid())).append("\"");
|
buf.append(" jid=\"").append(getJid()).append("\"");
|
||||||
}
|
}
|
||||||
if (getReason() == null) {
|
if (getReason() == null) {
|
||||||
buf.append("/>");
|
buf.append("/>");
|
||||||
|
|
|
@ -91,11 +91,11 @@ public class UserSearchManager {
|
||||||
final List<String> searchServices = new ArrayList<String>();
|
final List<String> searchServices = new ArrayList<String>();
|
||||||
ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(con);
|
ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(con);
|
||||||
DiscoverItems items = discoManager.discoverItems(con.getServiceName());
|
DiscoverItems items = discoManager.discoverItems(con.getServiceName());
|
||||||
Iterator iter = items.getItems();
|
Iterator<DiscoverItems.Item> iter = items.getItems();
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
DiscoverItems.Item item = (DiscoverItems.Item) iter.next();
|
DiscoverItems.Item item = iter.next();
|
||||||
try {
|
try {
|
||||||
DiscoverInfo info = null;
|
DiscoverInfo info;
|
||||||
try {
|
try {
|
||||||
info = discoManager.discoverInfo(item.getEntityID());
|
info = discoManager.discoverInfo(item.getEntityID());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue