Commit 485b1f70 authored by Derek DeMoro's avatar Derek DeMoro Committed by derek

Have Session address be unique.


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@655 b35dd754-fafc-0310-a699-88a17e54d16e
parent 9bb81f7f
/**
* $RCSfile$
* $Revision$
* $Date$
*
* Copyright (C) 2004 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.messenger;
import org.jivesoftware.messenger.auth.AuthToken;
import org.jivesoftware.messenger.auth.UnauthorizedException;
import org.jivesoftware.messenger.user.UserManager;
import org.jivesoftware.messenger.user.UserNotFoundException;
import org.xmpp.packet.JID;
import org.xmpp.packet.Presence;
import org.xmpp.packet.Packet;
import org.dom4j.io.XMLWriter;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Date;
import java.io.IOException;
import java.io.Writer;
public class ServerSession implements Session {
private StreamID streamID;
private JID address;
private Date creationDate;
private Connection connection = new ServerConnection();
public ServerSession(JID address, StreamID streamID) {
this.address = address;
this.streamID = streamID;
creationDate = new Date();
}
public Connection getConnection() {
return connection;
}
public int getStatus() {
return Session.STATUS_AUTHENTICATED;
}
public void setStatus(int status) {
}
public boolean isInitialized() {
return true;
}
public void setInitialized(boolean isInit) throws UnauthorizedException {
}
public Presence getPresence() {
return null;
}
public Presence setPresence(Presence presence) {
return null;
}
public void setAuthToken(AuthToken auth, UserManager userManager, String resource) {
}
public void setAnonymousAuth() throws UnauthorizedException {
}
// TODO: we need a server auth token for priviledged services to use
public AuthToken getAuthToken() {
return null;
}
public StreamID getStreamID() {
return streamID;
}
public String getUsername() throws UserNotFoundException, UnauthorizedException {
return null;
}
public String getServerName() {
return address.toString();
}
public Date getCreationDate() {
return creationDate;
}
public Date getLastActiveDate() {
return new Date();
}
public void incrementClientPacketCount() {
}
public void incrementServerPacketCount() {
}
public long getNumClientPackets() {
return 0;
}
public long getNumServerPackets() {
return 0;
}
public int getConflictCount() {
return 0;
}
public void incrementConflictCount() {
}
public JID getAddress() {
return address;
}
public void setAddress(JID address){
this.address = address;
}
public void process(Packet packet) {
}
private class ServerConnection implements Connection {
public boolean validate() {
return true;
}
public void init(Session session) {
}
public InetAddress getInetAddress()
throws UnauthorizedException, UnknownHostException {
return InetAddress.getLocalHost();
}
public XMLWriter getSerializer() throws UnauthorizedException {
// todo: implement so this loops back
return null;
}
public Writer getWriter() throws UnauthorizedException {
return null;
}
public void close() throws UnauthorizedException {
}
public boolean isClosed() {
return false;
}
public boolean isSecure() {
return true;
}
public Object registerCloseListener(ConnectionCloseListener listener,
Object handbackMessage)
throws UnauthorizedException {
return null;
}
public Object removeCloseListener(ConnectionCloseListener listener)
throws UnauthorizedException {
return null;
}
public void deliver(Packet packet)
throws UnauthorizedException {
}
public void deliver(String text) throws UnauthorizedException, IOException {
}
}
}
\ No newline at end of file
...@@ -24,5 +24,5 @@ public interface StreamID { ...@@ -24,5 +24,5 @@ public interface StreamID {
* *
* @return The unique ID for this stream * @return The unique ID for this stream
*/ */
public long getID(); public String getID();
} }
\ No newline at end of file
package org.jivesoftware.messenger.net;
import org.xmpp.packet.Packet;
import org.jivesoftware.messenger.Session;
/*
* $RCSfile$
* $Revision$
* $Date$
*
* Copyright (C) 2004 Jive Software. All rights reserved.
*
* This software is the proprietary information of CoolServlets, Inc.
* Use is subject to license terms.
*/
/**
* The Composite Packet class defines the holder of both a <code>Packet</code> and it's associated
* <code>Session</code> object.
*/
public class CompositePacket {
private Session session;
private Packet packet;
public CompositePacket(){
}
public CompositePacket(Packet packet, Session session){
setPacket(packet);
setSession(session);
}
/**
* Returns the Session.
* @return the Session to return.
*/
public Session getSession() {
return session;
}
/**
* Sets the Session for this packet.
* @param session the Session to set.
*/
public void setSession(Session session) {
this.session = session;
}
/**
* Returns the Packet.
* @return the Packet to return.
*/
public Packet getPacket() {
return packet;
}
/**
* Sets the Packet.
* @param packet the Packet to set.
*/
public void setPacket(Packet packet) {
this.packet = packet;
}
}
...@@ -33,7 +33,6 @@ import org.xmpp.packet.IQ; ...@@ -33,7 +33,6 @@ import org.xmpp.packet.IQ;
import org.xmpp.packet.Message; import org.xmpp.packet.Message;
import org.xmpp.packet.Presence; import org.xmpp.packet.Presence;
import org.xmpp.packet.Roster; import org.xmpp.packet.Roster;
import org.xmpp.packet.Packet;
/** /**
* @author Derek DeMoro * @author Derek DeMoro
...@@ -127,9 +126,7 @@ public class SocketReadThread extends Thread { ...@@ -127,9 +126,7 @@ public class SocketReadThread extends Thread {
Presence packet = presence.createCopy(); Presence packet = presence.createCopy();
packet.setType(Presence.Type.unavailable); packet.setType(Presence.Type.unavailable);
packet.setFrom(session.getAddress()); packet.setFrom(session.getAddress());
router.route(packet);
CompositePacket compPacket = new CompositePacket(packet, session);
router.route(compPacket);
clearSignout = true; clearSignout = true;
} }
} }
...@@ -181,36 +178,33 @@ public class SocketReadThread extends Thread { ...@@ -181,36 +178,33 @@ public class SocketReadThread extends Thread {
if (document != null) { if (document != null) {
Element doc = document.getRootElement(); Element doc = document.getRootElement();
Packet packet = null;
String tag = doc.getName(); String tag = doc.getName();
if ("message".equals(tag)) { if ("message".equals(tag)) {
packet = new Message(doc); Message packet = new Message(doc);
packet.setFrom(session.getAddress());
auditor.audit(packet);
router.route(packet);
session.incrementClientPacketCount();
} }
else if ("presence".equals(tag)) { else if ("presence".equals(tag)) {
packet = new Presence(doc); Presence packet = new Presence(doc);
packet.setFrom(session.getAddress());
Presence.Type type = ((Presence)packet).getType(); auditor.audit(packet);
router.route(packet);
session.incrementClientPacketCount();
// Update the flag that indicates if the user made a clean sign out // Update the flag that indicates if the user made a clean sign out
clearSignout = (Presence.Type.unavailable == type ? true : false); clearSignout = (Presence.Type.unavailable == packet.getType() ? true : false);
} }
else if ("iq".equals(tag)) { else if ("iq".equals(tag)) {
packet = getIQ(doc); IQ packet = getIQ(doc);
packet.setFrom(session.getAddress());
auditor.audit(packet);
router.route(packet);
session.incrementClientPacketCount();
} }
else { else {
throw new XmlPullParserException(LocaleUtils.getLocalizedString("admin.error.packet.tag") + tag); throw new XmlPullParserException(LocaleUtils.getLocalizedString("admin.error.packet.tag") + tag);
} }
// Create the composite packet
CompositePacket compositePacket = new CompositePacket(packet, session);
// Route to the Packet Auditor
auditor.audit(compositePacket);
// Route to PacketRouter
router.route(compositePacket);
// Increment number of sessions.
session.incrementClientPacketCount();
} }
} }
} }
......
...@@ -43,8 +43,8 @@ public class BasicStreamIDFactory implements StreamIDFactory { ...@@ -43,8 +43,8 @@ public class BasicStreamIDFactory implements StreamIDFactory {
this.id = id; this.id = id;
} }
public long getID() { public String getID() {
return -1; return id;
} }
public String toString() { public String toString() {
......
...@@ -81,7 +81,8 @@ public class SessionImpl implements Session { ...@@ -81,7 +81,8 @@ public class SessionImpl implements Session {
conn = connection; conn = connection;
this.streamID = streamID; this.streamID = streamID;
this.serverName = serverName; this.serverName = serverName;
this.address = new JID(null, serverName, null); String id = streamID.getID();
this.address = new JID(null, serverName, id);
presence = new Presence(); presence = new Presence();
this.sessionManager = SessionManager.getInstance(); this.sessionManager = SessionManager.getInstance();
......
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