1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2025-12-06 05:01:12 +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:
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
@ -167,7 +167,7 @@ public class XMPPConnection {
* Holds the initial configuration used while creating the connection.
*/
private ConnectionConfiguration configuration;
/**
* Creates a new connection to the specified XMPP server. A DNS SRV lookup will be
* performed to try to determine the IP address and port corresponding to the
@ -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() &&
@ -437,14 +436,14 @@ public class XMPPConnection {
if (sendPresence) {
packetWriter.sendPacket(new Presence(Presence.Type.available));
}
// Indicate that we're now authenticated.
authenticated = true;
anonymous = false;
// Stores the autentication for future reconnection
this.getConfiguration().setUsernameAndPassword(username, password);
// If debugging is enabled, change the the debug window title to include the
// name we are now logged-in as.
// If DEBUG_ENABLED was set to true AFTER the connection was created the debugger
@ -654,30 +653,30 @@ public class XMPPConnection {
catch (Exception e) {
// Ignore.
}
this.setWasAuthenticated(authenticated);
authenticated = false;
connected = false;
saslAuthentication.init();
}
/**
* Closes the connection by setting presence to unavailable then closing the stream to
* the XMPP server. The XMPPConnection can still be used for connecting to the server
* again.
*
*
* The difference between disconnect and shutdown is that disconnect makes a complete reset
* of the connection state whereas shutdown only cleans the connection and keeps alive
* packet reader listeners, previous login and roster presences.
*/
public void disconnect() {
this.shutdown();
this.roster = null;
this.wasAuthenticated = false;
packetWriter = null;
packetReader = null;
}
@ -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);
}
/**
@ -878,7 +875,7 @@ public class XMPPConnection {
// Do nothing
}
}
/**
* Initializes the connection by creating a packet reader and writer and opening a
* XMPP stream to the server.
@ -1317,14 +1314,14 @@ public class XMPPConnection {
this.notify();
}
}
/**
/**
* Establishes a connection to the XMPP server and performs an automatic login
* only if the previous connection state was logged (authenticated). It basically
* creates and maintains a socket connection to the server.<p>
*
*
* Listeners will be preserved from a previous connection if the reconnection
* occurs after an abrupt termination.
*
*
* @throws XMPPException if an error occurs while trying to establish the connection.
* Two possible errors can occur which will be wrapped by an XMPPException --
* UnknownHostException (XMPP error code 504), and IOException (XMPP error code
@ -1350,10 +1347,10 @@ public class XMPPConnection {
}
}
}
/**
/**
* Sets whether the connection has already logged in the server.
*
*
* @param wasAuthenticated true if the connection has already been authenticated.
*/
private void setWasAuthenticated(boolean wasAuthenticated) {

View file

@ -43,7 +43,7 @@ public abstract class Packet {
/**
* Constant used as packetID to indicate that a packet has no id. To indicate that a packet
* has no id set this constant as the packet's id. When the packet is asked for its id the
* has no id set this constant as the packet's id. When the packet is asked for its id the
* answer will be <tt>null</tt>.
*/
public static final String ID_NOT_AVAILABLE = "ID_NOT_AVAILABLE";
@ -86,7 +86,7 @@ public abstract class Packet {
if (ID_NOT_AVAILABLE.equals(packetID)) {
return null;
}
if (packetID == null) {
packetID = nextID();
}
@ -94,7 +94,7 @@ public abstract class Packet {
}
/**
* Sets the unique ID of the packet. To indicate that a packet has no id
* Sets the unique ID of the packet. To indicate that a packet has no id
* pass the constant ID_NOT_AVAILABLE as the packet's id value.
*
* @param packetID the unique ID for the packet.
@ -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,