Commit 8eb2f1c2 authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

Refactoring wortk. JM-924

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@6545 b35dd754-fafc-0310-a699-88a17e54d16e
parent a26c4225
......@@ -3,7 +3,7 @@
* $Revision: 3138 $
* $Date: 2005-12-01 02:13:26 -0300 (Thu, 01 Dec 2005) $
*
* Copyright (C) 2004 Jive Software. All rights reserved.
* Copyright (C) 2007 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
......@@ -16,7 +16,12 @@ import org.jivesoftware.util.Log;
import org.jivesoftware.wildfire.container.BasicModule;
import org.jivesoftware.wildfire.handler.PresenceSubscribeHandler;
import org.jivesoftware.wildfire.handler.PresenceUpdateHandler;
import org.jivesoftware.wildfire.interceptor.InterceptorManager;
import org.jivesoftware.wildfire.interceptor.PacketRejectedException;
import org.jivesoftware.wildfire.session.ClientSession;
import org.jivesoftware.wildfire.session.Session;
import org.xmpp.packet.JID;
import org.xmpp.packet.Message;
import org.xmpp.packet.PacketError;
import org.xmpp.packet.Presence;
......@@ -57,14 +62,40 @@ public class PresenceRouter extends BasicModule {
throw new NullPointerException();
}
ClientSession session = sessionManager.getSession(packet.getFrom());
if (session == null || session.getStatus() == Session.STATUS_AUTHENTICATED) {
handle(packet);
try {
// Invoke the interceptors before we process the read packet
InterceptorManager.getInstance().invokeInterceptors(packet, session, true, false);
if (session == null || session.getStatus() == Session.STATUS_AUTHENTICATED) {
handle(packet);
}
else {
packet.setTo(session.getAddress());
packet.setFrom((JID)null);
packet.setError(PacketError.Condition.not_authorized);
session.process(packet);
}
// Invoke the interceptors after we have processed the read packet
InterceptorManager.getInstance().invokeInterceptors(packet, session, true, true);
}
else {
packet.setTo(session.getAddress());
packet.setFrom((JID)null);
packet.setError(PacketError.Condition.not_authorized);
session.process(packet);
catch (PacketRejectedException e) {
if (session != null) {
// An interceptor rejected this packet so answer a not_allowed error
Presence reply = new Presence();
reply.setID(packet.getID());
reply.setTo(session.getAddress());
reply.setFrom(packet.getTo());
reply.setError(PacketError.Condition.not_allowed);
session.process(reply);
// Check if a message notifying the rejection should be sent
if (e.getRejectionMessage() != null && e.getRejectionMessage().trim().length() > 0) {
// A message for the rejection will be sent to the sender of the rejected packet
Message notification = new Message();
notification.setTo(session.getAddress());
notification.setFrom(packet.getTo());
notification.setBody(e.getRejectionMessage());
session.process(notification);
}
}
}
}
......@@ -119,7 +150,17 @@ public class PresenceRouter extends BasicModule {
}
else if (Presence.Type.probe == type) {
// Handle a presence probe sent by a remote server
presenceManager.handleProbe(packet);
if (!XMPPServer.getInstance().isLocal(recipientJID)) {
// Target is a component of the server so forward it
ChannelHandler route = routingTable.getRoute(recipientJID);
if (route != null) {
route.process(packet);
}
}
else {
// Handle probe to a local user
presenceManager.handleProbe(packet);
}
}
else {
// It's an unknown or ERROR type, just deliver it because there's nothing
......
......@@ -3,7 +3,7 @@
* $Revision: 3170 $
* $Date: 2005-12-07 14:00:58 -0300 (Wed, 07 Dec 2005) $
*
* Copyright (C) 2004 Jive Software. All rights reserved.
* Copyright (C) 2007 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
......@@ -16,18 +16,14 @@ import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.util.Log;
import org.jivesoftware.wildfire.audit.AuditStreamIDFactory;
import org.jivesoftware.wildfire.auth.UnauthorizedException;
import org.jivesoftware.wildfire.component.ComponentSession;
import org.jivesoftware.wildfire.component.InternalComponentManager;
import org.jivesoftware.wildfire.container.BasicModule;
import org.jivesoftware.wildfire.event.SessionEventDispatcher;
import org.jivesoftware.wildfire.handler.PresenceUpdateHandler;
import org.jivesoftware.wildfire.http.HttpSession;
import org.jivesoftware.wildfire.multiplex.ConnectionMultiplexerManager;
import org.jivesoftware.wildfire.multiplex.ConnectionMultiplexerSession;
import org.jivesoftware.wildfire.net.SocketConnection;
import org.jivesoftware.wildfire.server.IncomingServerSession;
import org.jivesoftware.wildfire.server.OutgoingServerSession;
import org.jivesoftware.wildfire.server.OutgoingSessionPromise;
import org.jivesoftware.wildfire.session.*;
import org.jivesoftware.wildfire.spi.BasicStreamIDFactory;
import org.jivesoftware.wildfire.user.UserManager;
import org.jivesoftware.wildfire.user.UserNotFoundException;
......@@ -37,6 +33,7 @@ import org.xmpp.packet.Packet;
import org.xmpp.packet.Presence;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
......@@ -257,7 +254,12 @@ public class SessionManager extends BasicModule {
if (sessions == null || sessions.isEmpty()) {
return null;
}
return sessions.get(0).getConnection().getInetAddress();
try {
return sessions.get(0).getConnection().getInetAddress();
} catch (UnknownHostException e) {
Log.error(e);
return null;
}
}
/**
......@@ -266,12 +268,10 @@ public class SessionManager extends BasicModule {
* @param conn the connection to create the session from.
* @param address the JID (may include a resource) of the connection manager's session.
* @return a newly created session.
* @throws UnauthorizedException
*/
public ConnectionMultiplexerSession createMultiplexerSession(SocketConnection conn, JID address)
throws UnauthorizedException {
public ConnectionMultiplexerSession createMultiplexerSession(Connection conn, JID address) {
if (serverName == null) {
throw new UnauthorizedException("Server not initialized");
throw new IllegalStateException("Server not initialized");
}
StreamID id = nextStreamID();
ConnectionMultiplexerSession session = new ConnectionMultiplexerSession(serverName, conn, id);
......@@ -1491,7 +1491,7 @@ public class SessionManager extends BasicModule {
Presence presence = new Presence();
presence.setType(Presence.Type.unavailable);
presence.setFrom(session.getAddress());
presenceHandler.process(presence);
presenceHandler.process(presence, session);
}
}
finally {
......
......@@ -3,7 +3,7 @@
* $Revision: $
* $Date: $
*
* Copyright (C) 2006 Jive Software. All rights reserved.
* Copyright (C) 2007 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
......@@ -22,6 +22,7 @@ import org.jivesoftware.wildfire.group.Group;
import org.jivesoftware.wildfire.group.GroupManager;
import org.jivesoftware.wildfire.privacy.PrivacyList;
import org.jivesoftware.wildfire.privacy.PrivacyListManager;
import org.jivesoftware.wildfire.session.ClientSession;
import org.jivesoftware.wildfire.user.UserAlreadyExistsException;
import org.jivesoftware.wildfire.user.UserNameManager;
import org.jivesoftware.wildfire.user.UserNotFoundException;
......
......@@ -3,7 +3,7 @@
* $Revision: 1751 $
* $Date: 2005-08-07 20:08:47 -0300 (Sun, 07 Aug 2005) $
*
* Copyright (C) 2004 Jive Software. All rights reserved.
* Copyright (C) 2007 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
......@@ -24,10 +24,7 @@ import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.*;
/**
* Defines the provider methods required for creating, reading, updating and deleting roster
......@@ -61,7 +58,7 @@ public class RosterItemProvider {
private static final String LOAD_ROSTER =
"SELECT jid, rosterID, sub, ask, recv, nick FROM jiveRoster WHERE username=?";
private static final String LOAD_ROSTER_ITEM_GROUPS =
"SELECT groupName FROM jiveRosterGroups WHERE rosterID=? ORDER BY rank";
"SELECT rosterID,groupName FROM jiveRosterGroups";
private static RosterItemProvider instance = new RosterItemProvider();
......@@ -265,9 +262,10 @@ public class RosterItemProvider {
*/
public Iterator<RosterItem> getItems(String username) {
LinkedList<RosterItem> itemList = new LinkedList<RosterItem>();
Map<Long, RosterItem> itemsByID = new HashMap<Long, RosterItem>();
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
ResultSet rs;
try {
// Load all the contacts in the roster
con = DbConnectionManager.getConnection();
......@@ -285,6 +283,7 @@ public class RosterItemProvider {
null);
// Add the loaded RosterItem (ie. user contact) to the result
itemList.add(item);
itemsByID.put(item.getID(), item);
}
// Close the statement and result set
rs.close();
......@@ -294,20 +293,27 @@ public class RosterItemProvider {
pstmt = null;
// Load the groups for the loaded contact
for (RosterItem item : itemList) {
pstmt = con.prepareStatement(LOAD_ROSTER_ITEM_GROUPS);
pstmt.setLong(1, item.getID());
if (!itemList.isEmpty()) {
StringBuilder sb = new StringBuilder(100);
sb.append(LOAD_ROSTER_ITEM_GROUPS).append(" WHERE rosterID IN (");
for (RosterItem item : itemList) {
sb.append(item.getID()).append(",");
}
sb.setLength(sb.length()-1);
sb.append(") ORDER BY rosterID, rank");
pstmt = con.prepareStatement(sb.toString());
rs = pstmt.executeQuery();
while (rs.next()) {
item.getGroups().add(rs.getString(1));
itemsByID.get(rs.getLong(1)).getGroups().add(rs.getString(2));
}
rs.close();
}
}
catch (SQLException e) {
Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
}
finally {
DbConnectionManager.closeConnection(rs, pstmt, con);
DbConnectionManager.closeConnection(pstmt, con);
}
return itemList.iterator();
}
......
......@@ -3,7 +3,7 @@
* $Revision: 1530 $
* $Date: 2005-06-17 18:38:27 -0300 (Fri, 17 Jun 2005) $
*
* Copyright (C) 2004 Jive Software. All rights reserved.
* Copyright (C) 2007 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
......@@ -14,6 +14,7 @@ package org.jivesoftware.wildfire.server;
import org.dom4j.Element;
import org.dom4j.io.XMPPPacketReader;
import org.jivesoftware.util.Log;
import org.jivesoftware.wildfire.session.OutgoingServerSession;
import java.io.IOException;
import java.util.concurrent.BlockingQueue;
......
......@@ -3,7 +3,7 @@
* $Revision: $
* $Date: $
*
* Copyright (C) 2004 Jive Software. All rights reserved.
* Copyright (C) 2007 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
......@@ -18,6 +18,7 @@ import org.jivesoftware.wildfire.RoutableChannelHandler;
import org.jivesoftware.wildfire.RoutingTable;
import org.jivesoftware.wildfire.XMPPServer;
import org.jivesoftware.wildfire.auth.UnauthorizedException;
import org.jivesoftware.wildfire.session.OutgoingServerSession;
import org.xmpp.packet.*;
import java.util.HashMap;
......
/**
* $Revision: $
* $Date: $
*
* Copyright (C) 2007 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.wildfire.server;
import org.jivesoftware.database.DbConnectionManager;
import org.jivesoftware.wildfire.Session;
import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.Log;
import org.jivesoftware.wildfire.SessionManager;
import org.jivesoftware.wildfire.net.SocketAcceptThread;
import org.jivesoftware.wildfire.server.RemoteServerConfiguration.Permission;
import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.Log;
import org.jivesoftware.wildfire.session.Session;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
......
......@@ -3,7 +3,7 @@
* $Revision: 3188 $
* $Date: 2005-12-12 00:28:19 -0300 (Mon, 12 Dec 2005) $
*
* Copyright (C) 2004 Jive Software. All rights reserved.
* Copyright (C) 2007 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
......@@ -23,6 +23,8 @@ import org.jivesoftware.wildfire.net.DNSUtil;
import org.jivesoftware.wildfire.net.MXParser;
import org.jivesoftware.wildfire.net.ServerTrafficCounter;
import org.jivesoftware.wildfire.net.SocketConnection;
import org.jivesoftware.wildfire.session.IncomingServerSession;
import org.jivesoftware.wildfire.session.OutgoingServerSession;
import org.jivesoftware.wildfire.spi.BasicStreamIDFactory;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
......@@ -56,7 +58,7 @@ import java.util.concurrent.TimeUnit;
*
* @author Gaston Dombiak
*/
class ServerDialback {
public class ServerDialback {
/**
* The utf-8 charset for decoding and encoding Jabber packet streams.
*/
......@@ -118,12 +120,12 @@ class ServerDialback {
* @param connection the connection created by the remote server.
* @param serverName the name of the local server.
*/
ServerDialback(Connection connection, String serverName) {
public ServerDialback(Connection connection, String serverName) {
this.connection = connection;
this.serverName = serverName;
}
ServerDialback() {
public ServerDialback() {
}
/**
......
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