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:
Gaston Dombiak 2006-09-15 22:42:06 +00:00 committed by gato
parent 6be93f4a4e
commit e65ecdc913
8 changed files with 186 additions and 233 deletions

View File

@ -40,10 +40,10 @@ import java.lang.reflect.Method;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
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
@ -89,8 +89,8 @@ public class XMPPConnection {
*/
public static boolean DEBUG_ENABLED = false;
private final static List<ConnectionEstablishedListener> connectionEstablishedListeners =
new CopyOnWriteArrayList<ConnectionEstablishedListener>();
private final static Set<ConnectionEstablishedListener> connectionEstablishedListeners =
new CopyOnWriteArraySet<ConnectionEstablishedListener>();
static {
// 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.
username = username.toLowerCase().trim();
username = StringUtils.escapeNode(username);
String response;
if (configuration.isSASLAuthenticationEnabled() &&
@ -819,9 +818,7 @@ public class XMPPConnection {
* @param connectionEstablishedListener a listener interested on connection established events.
*/
public static void addConnectionEstablishedListener(ConnectionEstablishedListener connectionEstablishedListener) {
if (!connectionEstablishedListeners.contains(connectionEstablishedListener)) {
connectionEstablishedListeners.add(connectionEstablishedListener);
}
connectionEstablishedListeners.add(connectionEstablishedListener);
}
/**

View File

@ -122,8 +122,7 @@ public abstract class Packet {
* @param to who the packet is being sent to.
*/
public void setTo(String to) {
// Use escaped version of the JID in case the user included invalid characters.
this.to = StringUtils.escapeJID(to);
this.to = to;
}
/**
@ -146,8 +145,7 @@ public abstract class Packet {
* @param from who the packet is being sent to.
*/
public void setFrom(String from) {
// Use escaped version of the JID in case the user included invalid characters.
this.from = StringUtils.escapeJID(from);
this.from = from;
}
/**

View File

@ -198,7 +198,7 @@ public class RosterPacket extends IQ {
public String toXML() {
StringBuilder buf = new StringBuilder();
buf.append("<item jid=\"").append(StringUtils.escapeJID(user)).append("\"");
buf.append("<item jid=\"").append(user).append("\"");
if (name != null) {
buf.append(" name=\"").append(StringUtils.escapeForXML(name)).append("\"");
}

View File

@ -47,7 +47,7 @@ public class StringUtils {
if (XMPPAddress == null) {
return null;
}
int atIndex = XMPPAddress.lastIndexOf("@");
int atIndex = XMPPAddress.indexOf("@");
if (atIndex <= 0) {
return "";
}
@ -68,7 +68,7 @@ public class StringUtils {
if (XMPPAddress == null) {
return null;
}
int atIndex = XMPPAddress.lastIndexOf("@");
int atIndex = XMPPAddress.indexOf("@");
// If the String ends with '@', return the empty string.
if (atIndex + 1 > XMPPAddress.length()) {
return "";
@ -127,8 +127,6 @@ public class StringUtils {
}
}
/**
* Escapes the node portion of a JID according to "JID Escaping" (JEP-0106).
* 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++) {
char c = node.charAt(i);
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("\\5c"); break;
default: {
if (Character.isWhitespace(c)) {
buf.append("\\20");
@ -184,43 +188,6 @@ public class StringUtils {
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>
* Escaping replaces characters prohibited by node-prep with escape sequences,

View File

@ -20,8 +20,6 @@
package org.jivesoftware.smackx;
import org.jivesoftware.smack.util.StringUtils;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
@ -290,7 +288,7 @@ public class FormField {
}
// Loop through all the values and append them to the string buffer
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
for (Iterator i = getOptions(); i.hasNext();) {

View File

@ -20,8 +20,6 @@
package org.jivesoftware.smackx;
import org.jivesoftware.smack.util.StringUtils;
import java.util.*;
/**
@ -37,7 +35,7 @@ public class RemoteRosterEntry {
private String user;
private String name;
private List groupNames = new ArrayList();
private final List<String> groupNames = new ArrayList<String>();
/**
* Creates a new remote roster entry.
@ -51,7 +49,7 @@ public class RemoteRosterEntry {
this.user = user;
this.name = name;
if (groups != null) {
groupNames = new ArrayList(Arrays.asList(groups));
groupNames.addAll(Arrays.asList(groups));
}
}
@ -93,23 +91,19 @@ public class RemoteRosterEntry {
*/
public String[] getGroupArrayNames() {
synchronized (groupNames) {
return (String[])
(Collections
.unmodifiableList(groupNames)
.toArray(new String[groupNames.size()]));
return Collections.unmodifiableList(groupNames).toArray(new String[groupNames.size()]);
}
}
public String toXML() {
StringBuilder buf = new StringBuilder();
buf.append("<item jid=\"").append(StringUtils.escapeJID(user)).append("\"");
buf.append("<item jid=\"").append(user).append("\"");
if (name != null) {
buf.append(" name=\"").append(name).append("\"");
}
buf.append(">");
synchronized (groupNames) {
for (int i = 0; i < groupNames.size(); i++) {
String groupName = (String) groupNames.get(i);
for (String groupName : groupNames) {
buf.append("<group>").append(groupName).append("</group>");
}
}

View File

@ -21,7 +21,6 @@
package org.jivesoftware.smackx.packet;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.util.StringUtils;
/**
* Represents extended presence information about roles, affiliations, full JIDs,
@ -277,7 +276,7 @@ public class MUCUser implements PacketExtension {
buf.append("</invite>");
return buf.toString();
}
};
}
/**
* 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>");
return buf.toString();
}
};
}
/**
* 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("\"");
}
if (getJid() != null) {
buf.append(" jid=\"").append(StringUtils.escapeJID(getJid())).append("\"");
buf.append(" jid=\"").append(getJid()).append("\"");
}
if (getNick() != null) {
buf.append(" nick=\"").append(getNick()).append("\"");
@ -514,13 +513,13 @@ public class MUCUser implements PacketExtension {
buf.append("<reason>").append(getReason()).append("</reason>");
}
if (getActor() != null) {
buf.append("<actor jid=\"").append(StringUtils.escapeJID(getActor())).append("\"/>");
buf.append("<actor jid=\"").append(getActor()).append("\"/>");
}
buf.append("</item>");
}
return buf.toString();
}
};
}
/**
* 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("\"/>");
return buf.toString();
}
};
}
/**
* 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();
buf.append("<destroy");
if (getJid() != null) {
buf.append(" jid=\"").append(StringUtils.escapeJID(getJid())).append("\"");
buf.append(" jid=\"").append(getJid()).append("\"");
}
if (getReason() == null) {
buf.append("/>");

View File

@ -91,11 +91,11 @@ public class UserSearchManager {
final List<String> searchServices = new ArrayList<String>();
ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(con);
DiscoverItems items = discoManager.discoverItems(con.getServiceName());
Iterator iter = items.getItems();
Iterator<DiscoverItems.Item> iter = items.getItems();
while (iter.hasNext()) {
DiscoverItems.Item item = (DiscoverItems.Item) iter.next();
DiscoverItems.Item item = iter.next();
try {
DiscoverInfo info = null;
DiscoverInfo info;
try {
info = discoManager.discoverInfo(item.getEntityID());
}