Commit 9c70df3f authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

Code cleanup.

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@3358 b35dd754-fafc-0310-a699-88a17e54d16e
parent d7c02508
...@@ -191,10 +191,8 @@ class ServerDialback { ...@@ -191,10 +191,8 @@ class ServerDialback {
else { else {
Log.debug("OS - Invalid namespace in packet: " + xpp.getText()); Log.debug("OS - Invalid namespace in packet: " + xpp.getText());
// Send an invalid-namespace stream error condition in the response // Send an invalid-namespace stream error condition in the response
StreamError error = new StreamError(StreamError.Condition.invalid_namespace); connection.deliverRawText(
StringBuilder sb = new StringBuilder(); new StreamError(StreamError.Condition.invalid_namespace).toXML());
sb.append(error.toXML());
connection.deliverRawText(sb.toString());
// Close the connection // Close the connection
connection.close(); connection.close();
} }
...@@ -316,7 +314,6 @@ class ServerDialback { ...@@ -316,7 +314,6 @@ class ServerDialback {
XmlPullParserException { XmlPullParserException {
XmlPullParser xpp = reader.getXPPParser(); XmlPullParser xpp = reader.getXPPParser();
StringBuilder sb; StringBuilder sb;
StreamError error;
if ("jabber:server:dialback".equals(xpp.getNamespace("db"))) { if ("jabber:server:dialback".equals(xpp.getNamespace("db"))) {
StreamID streamID = sessionManager.nextStreamID(); StreamID streamID = sessionManager.nextStreamID();
...@@ -364,10 +361,8 @@ class ServerDialback { ...@@ -364,10 +361,8 @@ class ServerDialback {
} }
else { else {
// The remote server sent an invalid/unknown packet // The remote server sent an invalid/unknown packet
error = new StreamError(StreamError.Condition.invalid_xml); connection.deliverRawText(
sb = new StringBuilder(); new StreamError(StreamError.Condition.invalid_xml).toXML());
sb.append(error.toXML());
connection.deliverRawText(sb.toString());
// Close the underlying connection // Close the underlying connection
connection.close(); connection.close();
return null; return null;
...@@ -383,10 +378,8 @@ class ServerDialback { ...@@ -383,10 +378,8 @@ class ServerDialback {
} }
else { else {
// Include the invalid-namespace stream error condition in the response // Include the invalid-namespace stream error condition in the response
error = new StreamError(StreamError.Condition.invalid_namespace); connection.deliverRawText(
sb = new StringBuilder(); new StreamError(StreamError.Condition.invalid_namespace).toXML());
sb.append(error.toXML());
connection.deliverRawText(sb.toString());
// Close the underlying connection // Close the underlying connection
connection.close(); connection.close();
return null; return null;
...@@ -408,17 +401,13 @@ class ServerDialback { ...@@ -408,17 +401,13 @@ class ServerDialback {
* @return true if the requested domain is valid. * @return true if the requested domain is valid.
*/ */
public boolean validateRemoteDomain(Element doc, StreamID streamID) { public boolean validateRemoteDomain(Element doc, StreamID streamID) {
StreamError error;
StringBuilder sb; StringBuilder sb;
String recipient = doc.attributeValue("to"); String recipient = doc.attributeValue("to");
String hostname = doc.attributeValue("from"); String hostname = doc.attributeValue("from");
Log.debug("RS - Received dialback key from host: " + hostname + " to: " + recipient); Log.debug("RS - Received dialback key from host: " + hostname + " to: " + recipient);
if (!RemoteServerManager.canAccess(hostname)) { if (!RemoteServerManager.canAccess(hostname)) {
// Remote server is not allowed to establish a connection to this server // Remote server is not allowed to establish a connection to this server
error = new StreamError(StreamError.Condition.host_unknown); connection.deliverRawText(new StreamError(StreamError.Condition.host_unknown).toXML());
sb = new StringBuilder();
sb.append(error.toXML());
connection.deliverRawText(sb.toString());
// Close the underlying connection // Close the underlying connection
connection.close(); connection.close();
Log.debug("RS - Error, hostname is not allowed to establish a connection to " + Log.debug("RS - Error, hostname is not allowed to establish a connection to " +
...@@ -428,10 +417,7 @@ class ServerDialback { ...@@ -428,10 +417,7 @@ class ServerDialback {
} }
else if (isHostUnknown(recipient)) { else if (isHostUnknown(recipient)) {
// address does not match a recognized hostname // address does not match a recognized hostname
error = new StreamError(StreamError.Condition.host_unknown); connection.deliverRawText(new StreamError(StreamError.Condition.host_unknown).toXML());
sb = new StringBuilder();
sb.append(error.toXML());
connection.deliverRawText(sb.toString());
// Close the underlying connection // Close the underlying connection
connection.close(); connection.close();
Log.debug("RS - Error, hostname not recognized: " + recipient); Log.debug("RS - Error, hostname not recognized: " + recipient);
...@@ -448,10 +434,8 @@ class ServerDialback { ...@@ -448,10 +434,8 @@ class ServerDialback {
} }
if (alreadyExists) { if (alreadyExists) {
// Remote server already has a IncomingServerSession created // Remote server already has a IncomingServerSession created
error = new StreamError(StreamError.Condition.not_authorized); connection.deliverRawText(
sb = new StringBuilder(); new StreamError(StreamError.Condition.not_authorized).toXML());
sb.append(error.toXML());
connection.deliverRawText(sb.toString());
// Close the underlying connection // Close the underlying connection
connection.close(); connection.close();
Log.debug("RS - Error, incoming connection already exists from: " + hostname); Log.debug("RS - Error, incoming connection already exists from: " + hostname);
...@@ -488,11 +472,8 @@ class ServerDialback { ...@@ -488,11 +472,8 @@ class ServerDialback {
// Send a <remote-connection-failed/> stream error condition // Send a <remote-connection-failed/> stream error condition
// and terminate both the XML stream and the underlying // and terminate both the XML stream and the underlying
// TCP connection // TCP connection
error = connection.deliverRawText(new StreamError(
new StreamError(StreamError.Condition.remote_connection_failed); StreamError.Condition.remote_connection_failed).toXML());
sb = new StringBuilder();
sb.append(error.toXML());
connection.deliverRawText(sb.toString());
// Close the underlying connection // Close the underlying connection
connection.close(); connection.close();
return false; return false;
...@@ -526,7 +507,6 @@ class ServerDialback { ...@@ -526,7 +507,6 @@ class ServerDialback {
RemoteConnectionFailedException { RemoteConnectionFailedException {
XMPPPacketReader reader = null; XMPPPacketReader reader = null;
Writer writer = null; Writer writer = null;
StreamError error;
// Establish a TCP connection back to the domain name asserted by the Originating Server // Establish a TCP connection back to the domain name asserted by the Originating Server
Log.debug("RS - Trying to connect to Authoritative Server: " + hostname + ":" + port); Log.debug("RS - Trying to connect to Authoritative Server: " + hostname + ":" + port);
// Connect to the Authoritative server // Connect to the Authoritative server
...@@ -579,10 +559,7 @@ class ServerDialback { ...@@ -579,10 +559,7 @@ class ServerDialback {
if ("db".equals(doc.getNamespacePrefix()) && "verify".equals(doc.getName())) { if ("db".equals(doc.getNamespacePrefix()) && "verify".equals(doc.getName())) {
if (!streamID.equals(doc.attributeValue("id"))) { if (!streamID.equals(doc.attributeValue("id"))) {
// Include the invalid-id stream error condition in the response // Include the invalid-id stream error condition in the response
error = new StreamError(StreamError.Condition.invalid_id); writer.write(new StreamError(StreamError.Condition.invalid_id).toXML());
sb = new StringBuilder();
sb.append(error.toXML());
writer.write(sb.toString());
writer.flush(); writer.flush();
// Thrown an error so <remote-connection-failed/> stream error // Thrown an error so <remote-connection-failed/> stream error
// condition is sent to the Originating Server // condition is sent to the Originating Server
...@@ -590,10 +567,8 @@ class ServerDialback { ...@@ -590,10 +567,8 @@ class ServerDialback {
} }
else if (isHostUnknown(doc.attributeValue("to"))) { else if (isHostUnknown(doc.attributeValue("to"))) {
// Include the host-unknown stream error condition in the response // Include the host-unknown stream error condition in the response
error = new StreamError(StreamError.Condition.host_unknown); writer.write(
sb = new StringBuilder(); new StreamError(StreamError.Condition.host_unknown).toXML());
sb.append(error.toXML());
writer.write(sb.toString());
writer.flush(); writer.flush();
// Thrown an error so <remote-connection-failed/> stream error // Thrown an error so <remote-connection-failed/> stream error
// condition is sent to the Originating Server // condition is sent to the Originating Server
...@@ -601,10 +576,8 @@ class ServerDialback { ...@@ -601,10 +576,8 @@ class ServerDialback {
} }
else if (!hostname.equals(doc.attributeValue("from"))) { else if (!hostname.equals(doc.attributeValue("from"))) {
// Include the invalid-from stream error condition in the response // Include the invalid-from stream error condition in the response
error = new StreamError(StreamError.Condition.invalid_from); writer.write(
sb = new StringBuilder(); new StreamError(StreamError.Condition.invalid_from).toXML());
sb.append(error.toXML());
writer.write(sb.toString());
writer.flush(); writer.flush();
// Thrown an error so <remote-connection-failed/> stream error // Thrown an error so <remote-connection-failed/> stream error
// condition is sent to the Originating Server // condition is sent to the Originating Server
...@@ -632,10 +605,7 @@ class ServerDialback { ...@@ -632,10 +605,7 @@ class ServerDialback {
} }
else { else {
// Include the invalid-namespace stream error condition in the response // Include the invalid-namespace stream error condition in the response
error = new StreamError(StreamError.Condition.invalid_namespace); writer.write(new StreamError(StreamError.Condition.invalid_namespace).toXML());
StringBuilder sb = new StringBuilder();
sb.append(error.toXML());
writer.write(sb.toString());
writer.flush(); writer.flush();
// Thrown an error so <remote-connection-failed/> stream error condition is // Thrown an error so <remote-connection-failed/> stream error condition is
// sent to the Originating Server // sent to the Originating Server
......
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