Commit 5dab4a3a authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

Optimized usage of StringBuilder. JM-480

git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@3156 b35dd754-fafc-0310-a699-88a17e54d16e
parent fc325453
......@@ -151,9 +151,7 @@ public class ClientSession extends Session {
connection.getInetAddress().getHostAddress());
// Include the not-authorized error in the response
StreamError error = new StreamError(StreamError.Condition.not_authorized);
StringBuilder sb = new StringBuilder();
sb.append(error.toXML());
connection.deliverRawText(sb.toString());
connection.deliverRawText(error.toXML());
// Close the underlying connection
connection.close();
return null;
......@@ -211,7 +209,7 @@ public class ClientSession extends Session {
Writer writer = connection.getWriter();
// Build the start packet response
StringBuilder sb = new StringBuilder();
StringBuilder sb = new StringBuilder(200);
sb.append("<?xml version='1.0' encoding='");
sb.append(CHARSET);
sb.append("'?>");
......@@ -248,7 +246,7 @@ public class ClientSession extends Session {
}
// Otherwise, this is at least XMPP 1.0 so we need to announce stream features.
sb = new StringBuilder();
sb = new StringBuilder(300);
sb.append("<stream:features>");
if (tlsPolicy != SocketConnection.TLSPolicy.disabled) {
sb.append("<starttls xmlns=\"urn:ietf:params:xml:ns:xmpp-tls\">");
......
......@@ -93,7 +93,7 @@ public class ClientSocketReader extends SocketReader {
}
protected String getAvailableStreamFeatures() {
StringBuilder sb = new StringBuilder();
StringBuilder sb = new StringBuilder(110);
// TODO Create and use #hasSASLAuthentication
if (((ClientSession)session).getAuthToken() == null) {
// Advertise that the server supports Non-SASL Authentication
......
......@@ -104,7 +104,7 @@ public class SASLAuthentication {
* @return a string with the valid SASL mechanisms available for the specified session.
*/
public static String getSASLMechanisms(Session session) {
StringBuilder sb = new StringBuilder();
StringBuilder sb = new StringBuilder(195);
sb.append("<mechanisms xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">");
// Check if the user provider in use supports passwords retrieval. Accessing to the users
// passwords will be required by the CallbackHandler
......@@ -287,7 +287,7 @@ public class SASLAuthentication {
}
private void sendChallenge(byte[] challenge) {
StringBuilder reply = new StringBuilder();
StringBuilder reply = new StringBuilder(250);
reply.append(
"<challenge xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">");
reply.append(StringUtils.encodeBase64(challenge).trim());
......@@ -296,9 +296,7 @@ public class SASLAuthentication {
}
private void authenticationSuccessful(String username) {
StringBuilder reply = new StringBuilder();
reply.append("<success xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\"/>");
connection.deliverRawText(reply.toString());
connection.deliverRawText("<success xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\"/>");
// We only support SASL for c2s
if (session instanceof ClientSession) {
((ClientSession) session).setAuthToken(new AuthToken(username));
......@@ -314,7 +312,7 @@ public class SASLAuthentication {
}
private void authenticationFailed() {
StringBuilder reply = new StringBuilder();
StringBuilder reply = new StringBuilder(80);
reply.append("<failure xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">");
reply.append("<not-authorized/></failure>");
connection.deliverRawText(reply.toString());
......
......@@ -452,12 +452,10 @@ public abstract class SocketReader implements Runnable {
* closing the connection a stream error will be sent to the entity.
*/
private void closeNeverSecuredConnection() {
StringBuilder sb = new StringBuilder();
// Set the not_authorized error
StreamError error = new StreamError(StreamError.Condition.not_authorized);
sb.append(error.toXML());
// Deliver stanza
connection.deliverRawText(sb.toString());
connection.deliverRawText(error.toXML());
// Close the underlying connection
connection.close();
// Log a warning so that admins can track this case from the server side
......@@ -495,7 +493,7 @@ public abstract class SocketReader implements Runnable {
// error and close the underlying connection.
String host = reader.getXPPParser().getAttributeValue("", "to");
if (validateHost() && isHostUnknown(host)) {
StringBuilder sb = new StringBuilder();
StringBuilder sb = new StringBuilder(250);
sb.append("<?xml version='1.0' encoding='");
sb.append(CHARSET);
sb.append("'?>");
......@@ -524,7 +522,7 @@ public abstract class SocketReader implements Runnable {
else if (!createSession(xpp.getNamespace(null))) {
// No session was created because of an invalid namespace prefix so answer a stream
// error and close the underlying connection
StringBuilder sb = new StringBuilder();
StringBuilder sb = new StringBuilder(250);
sb.append("<?xml version='1.0' encoding='");
sb.append(CHARSET);
sb.append("'?>");
......@@ -578,12 +576,10 @@ public abstract class SocketReader implements Runnable {
*/
private boolean negotiateTLS() throws IOException, XmlPullParserException {
if (connection.getTlsPolicy() == SocketConnection.TLSPolicy.disabled) {
StringBuilder sb = new StringBuilder();
// Set the not_authorized error
StreamError error = new StreamError(StreamError.Condition.not_authorized);
sb.append(error.toXML());
// Deliver stanza
connection.deliverRawText(sb.toString());
connection.deliverRawText(error.toXML());
// Close the underlying connection
connection.close();
// Log a warning so that admins can track this case from the server side
......@@ -620,7 +616,7 @@ public abstract class SocketReader implements Runnable {
*/
private void tlsNegotiated() {
// Offer stream features including SASL Mechanisms
StringBuilder sb = new StringBuilder();
StringBuilder sb = new StringBuilder(340);
sb.append(geStreamHeader());
sb.append("<stream:features>");
// Include available SASL Mechanisms
......@@ -641,7 +637,7 @@ public abstract class SocketReader implements Runnable {
* to servers or external components)
*/
private void saslSuccessful() throws XmlPullParserException, IOException {
StringBuilder sb = new StringBuilder();
StringBuilder sb = new StringBuilder(145);
sb.append(geStreamHeader());
sb.append("<stream:features>");
......@@ -697,7 +693,7 @@ public abstract class SocketReader implements Runnable {
abstract boolean validateHost();
private String geStreamHeader() {
StringBuilder sb = new StringBuilder();
StringBuilder sb = new StringBuilder(200);
sb.append("<?xml version='1.0' encoding='");
sb.append(CHARSET);
sb.append("'?>");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment