Commit 9a23f8db authored by Derek DeMoro's avatar Derek DeMoro Committed by derek

Refactoring changes


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@614 b35dd754-fafc-0310-a699-88a17e54d16e
parent 546f70f9
......@@ -26,7 +26,6 @@ import org.jivesoftware.messenger.auth.UnauthorizedException;
import org.jivesoftware.messenger.spi.BasicConnection;
import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.util.Log;
import org.xmlpull.v1.XmlPullParserException;
import org.xmpp.packet.Packet;
/**
......@@ -79,7 +78,7 @@ public class SocketConnection extends BasicConnection {
* @throws NullPointerException If the socket is null
*/
public SocketConnection(PacketDeliverer deliverer, Auditor auditor,
Socket socket, boolean isSecure) throws IOException, XmlPullParserException {
Socket socket, boolean isSecure) throws IOException {
if (socket == null) {
throw new NullPointerException("Socket channel must be non-null");
......@@ -175,7 +174,7 @@ public class SocketConnection extends BasicConnection {
*
* @param packet The packet to deliver.
*/
public void deliver(Packet packet) throws UnauthorizedException, PacketException, XmlPullParserException {
public void deliver(Packet packet) throws UnauthorizedException, PacketException {
if (isClosed()) {
deliverer.deliver(packet);
}
......
......@@ -44,7 +44,7 @@ public class ConnectionManagerImpl extends BasicModule implements ConnectionMana
private void createSocket() {
if (!isStarted || isSocketStarted || auditManager == null ||
sessionManager == null || deliverer == null ||
router == null || serverName == null || packetFactory == null)
router == null || serverName == null)
{
return;
}
......@@ -106,7 +106,6 @@ public class ConnectionManagerImpl extends BasicModule implements ConnectionMana
public PacketRouter router;
private String serverName;
public XMPPServer server;
public PacketFactory packetFactory;
public void addSocket(Socket sock, boolean isSecure) {
try {
......@@ -137,7 +136,6 @@ public class ConnectionManagerImpl extends BasicModule implements ConnectionMana
trackInfo.getTrackerClasses().put(PacketRouter.class, "router");
trackInfo.getTrackerClasses().put(PacketDeliverer.class, "deliverer");
trackInfo.getTrackerClasses().put(AuditManager.class, "auditManager");
trackInfo.getTrackerClasses().put(PacketFactory.class, "packetFactory");
return trackInfo;
}
......
......@@ -14,7 +14,7 @@ package org.jivesoftware.messenger.spi;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import javax.xml.stream.XMLStreamException;
import java.util.Map;
import org.jivesoftware.messenger.*;
import org.jivesoftware.messenger.auth.UnauthorizedException;
import org.jivesoftware.messenger.container.BasicModule;
......@@ -38,13 +38,15 @@ public class IQRouterImpl extends BasicModule implements IQRouter {
public OfflineMessageStore messageStore;
public RoutingTable routingTable;
public LinkedList iqHandlers = new LinkedList();
private HashMap namespace2Handlers = new HashMap();
private Map namespace2Handlers = new HashMap();
private SessionManager sessionManager;
/**
* Creates a packet router.
*/
public IQRouterImpl() {
super("XMPP IQ Router");
sessionManager = SessionManager.getInstance();
}
public void route(IQ packet) {
......@@ -54,17 +56,16 @@ public class IQRouterImpl extends BasicModule implements IQRouter {
Session session = SessionManager.getInstance().getSession(packet.getFrom());
if (session == null || session.getStatus() == Session.STATUS_AUTHENTICATED
|| (isLocalServer(packet.getTo())
&& ("jabber:iq:auth".equals(packet.getChildNamespace())
|| "jabber:iq:register".equals(packet.getChildNamespace())))
&& ("jabber:iq:auth".equals(packet.getChildElement().getNamespaceURI())
|| "jabber:iq:register".equals(packet.getChildElement().getNamespaceURI())))
) {
handle(packet);
}
else {
packet.setRecipient(packet.getOriginatingSession().getAddress());
packet.setSender(null);
packet.setError(XMPPError.Code.UNAUTHORIZED);
packet.setTo(sessionManager.getSession(packet.getFrom()).getAddress());
packet.setError(PacketError.Condition.not_authorized);
try {
packet.getOriginatingSession().process(packet);
sessionManager.getSession(packet.getFrom()).process(packet);
}
catch (UnauthorizedException ue) {
Log.error(ue);
......@@ -117,7 +118,7 @@ public class IQRouterImpl extends BasicModule implements IQRouter {
// Answer an error since the server can't handle packets sent to a node
packet.setError(PacketError.Condition.service_unavailable);
}
Session session = packet.getOriginatingSession();
Session session = sessionManager.getSession(packet.getFrom());
if (session != null) {
session.getConnection().deliver(packet);
}
......@@ -139,16 +140,13 @@ public class IQRouterImpl extends BasicModule implements IQRouter {
}
catch (NoSuchRouteException e) {
Log.info("Packet sent to unreachable address " + packet);
Session session = packet.getOriginatingSession();
Session session = sessionManager.getSession(packet.getFrom());
if (session != null) {
try {
packet.setError(XMPPError.Code.SERVICE_UNAVAILABLE);
packet.setError(PacketError.Condition.service_unavailable);
session.getConnection().deliver(packet);
}
catch (UnauthorizedException ex) {
// do nothing
}
catch (XMLStreamException ex) {
Log.error(LocaleUtils.getLocalizedString("admin.error.routing"), e);
}
}
......@@ -156,7 +154,7 @@ public class IQRouterImpl extends BasicModule implements IQRouter {
catch (Exception e) {
Log.error(LocaleUtils.getLocalizedString("admin.error.routing"), e);
try {
Session session = packet.getOriginatingSession();
Session session = sessionManager.getSession(packet.getFrom());
if (session != null) {
Connection conn = session.getConnection();
if (conn != null) {
......
......@@ -14,13 +14,11 @@ package org.jivesoftware.messenger.user;
import java.util.Iterator;
import java.util.List;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.jivesoftware.messenger.auth.UnauthorizedException;
import org.jivesoftware.messenger.user.spi.IQRosterItemImpl;
import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.util.Log;
import org.jivesoftware.util.XPPReader;
import org.xmpp.packet.IQ;
import org.xmpp.packet.JID;
......
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