Commit 59162ac0 authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gaston

Added notification of new packet received to Sessions. JM-249


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@1218 b35dd754-fafc-0310-a699-88a17e54d16e
parent 74bfd449
......@@ -379,4 +379,8 @@ public class ClientSession extends Session {
}
}
}
public void packetReceived(Packet packet) {
packet.setFrom(getAddress());
}
}
......@@ -19,6 +19,7 @@ import org.jivesoftware.messenger.auth.UnauthorizedException;
import org.jivesoftware.messenger.auth.AuthFactory;
import org.jivesoftware.util.Log;
import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.util.JiveGlobals;
import org.dom4j.io.XPPPacketReader;
import org.dom4j.Element;
import org.xmlpull.v1.XmlPullParser;
......@@ -56,6 +57,13 @@ public class ComponentSession extends Session {
Session session;
String domain = xpp.getAttributeValue("", "to");
// Get the requested subdomain
String subdomain = domain;
int index = domain.indexOf(serverName);
if (index > -1) {
subdomain = domain.substring(0, index -1);
}
Writer writer = connection.getWriter();
// Default answer header in case of an error
StringBuilder sb = new StringBuilder();
......@@ -96,8 +104,8 @@ public class ComponentSession extends Session {
connection.close();
return null;
}
// Check that the requested domain is not already in use
if (InternalComponentManager.getInstance().getComponent(domain) != null) {
// Check that the requested subdomain is not already in use
if (InternalComponentManager.getInstance().getComponent(subdomain) != null) {
// Domain already occupied so return a conflict error and close the connection
// Include the conflict error in the response
StreamError error = new StreamError(StreamError.Condition.conflict);
......@@ -113,8 +121,7 @@ public class ComponentSession extends Session {
// Create a ComponentSession for the external component
session = SessionManager.getInstance().createComponentSession(connection);
// Set the bind address as the address of the session
session.setAddress(new JID(null,
domain + "." + XMPPServer.getInstance().getServerInfo().getName(), null));
session.setAddress(new JID(null, domain , null));
try {
// Build the start packet response
......@@ -160,9 +167,7 @@ public class ComponentSession extends Session {
writer.flush();
// Bind the domain to this component
ExternalComponent component = ((ComponentSession) session).getExternalComponent();
InternalComponentManager.getInstance().addComponent(domain, component);
// Set the service name to the component
component.setServiceName(domain);
InternalComponentManager.getInstance().addComponent(subdomain, component);
return session;
}
}
......@@ -200,8 +205,6 @@ public class ComponentSession extends Session {
*/
public class ExternalComponent implements Component {
private String serviceName;
public void processPacket(Packet packet) {
if (conn != null && !conn.isClosed()) {
try {
......@@ -227,17 +230,9 @@ public class ComponentSession extends Session {
public void shutdown() {
}
}
public JID getAddress() {
return ComponentSession.this.getAddress();
}
public String getServiceName() {
return serviceName;
}
void setServiceName(String serviceName) {
this.serviceName = serviceName;
}
public void packetReceived(Packet packet) {
//Do nothing
}
}
\ No newline at end of file
......@@ -12,7 +12,6 @@
package org.jivesoftware.messenger;
import org.dom4j.Element;
import org.jivesoftware.messenger.auth.UnauthorizedException;
import org.xmpp.component.Component;
import org.xmpp.component.ComponentManager;
import org.xmpp.component.ComponentManagerFactory;
......@@ -21,6 +20,7 @@ import org.xmpp.packet.JID;
import org.xmpp.packet.Packet;
import org.xmpp.packet.Presence;
import org.jivesoftware.util.Log;
import org.jivesoftware.util.JiveGlobals;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
......@@ -80,6 +80,8 @@ public class InternalComponentManager implements ComponentManager, RoutableChann
XMPPServer.getInstance().getRoutingTable().addRoute(componentJID,
new RoutableComponent(componentJID, component));
component.initialize(componentJID, this);
// Check for potential interested users.
checkPresences();
// Send a disco#info request to the new component. If the component provides information
......@@ -119,6 +121,14 @@ public class InternalComponentManager implements ComponentManager, RoutableChann
//To change body of implemented methods use File | Settings | File Templates.
}
public String getServerName() {
return serverDomain;
}
public String getHomeDirectory() {
return JiveGlobals.getHomeDirectory();
}
public boolean isExternalMode() {
return false; //To change body of implemented methods use File | Settings | File Templates.
}
......@@ -179,11 +189,11 @@ public class InternalComponentManager implements ComponentManager, RoutableChann
* Retrieves the <code>Component</code> which is mapped
* to the specified JID.
*
* @param jid the jid mapped to the component.
* @param componentJID the jid mapped to the component.
* @return the component with the specified id.
*/
public Component getComponent(String jid) {
jid = new JID(jid).toBareJID();
public Component getComponent(JID componentJID) {
String jid = componentJID.toBareJID();
if (components.containsKey(jid)) {
return components.get(jid);
}
......@@ -198,6 +208,17 @@ public class InternalComponentManager implements ComponentManager, RoutableChann
return components.get(jid);
}
/**
* Retrieves the <code>Component</code> which is mapped
* to the specified JID.
*
* @param jid the jid mapped to the component.
* @return the component with the specified id.
*/
public Component getComponent(String jid) {
return getComponent(new JID(jid));
}
/**
* Registers Probeers who have not yet been serviced.
*
......
......@@ -13,6 +13,7 @@ package org.jivesoftware.messenger;
import org.jivesoftware.messenger.auth.AuthToken;
import org.xmpp.packet.JID;
import org.xmpp.packet.Packet;
import java.util.Date;
......@@ -208,4 +209,12 @@ public abstract class Session implements RoutableChannelHandler {
public long getNumServerPackets() {
return serverPacketCount;
}
/**
* Notification message that a packet has been received from this session. Client sessions
* will probably want to set the FROM attribute to avoid spoofing.
*
* @param packet the received packet by this session.
*/
public abstract void packetReceived(Packet packet);
}
\ No newline at end of file
......@@ -192,7 +192,9 @@ public class SocketReadThread extends Thread {
session.process(reply);
continue;
}
packet.setFrom(session.getAddress());
// Notify the session that a new packet has been received. This could be useful
// for client sessions for setting the real sender of the packet and avoid spoofing
session.packetReceived(packet);
try {
// Invoke the interceptors before we process the read packet
InterceptorManager.getInstance().invokeInterceptors(packet, session, true,
......@@ -228,7 +230,9 @@ public class SocketReadThread extends Thread {
session.process(reply);
continue;
}
packet.setFrom(session.getAddress());
// Notify the session that a new packet has been received. This could be useful
// for client sessions for setting the real sender of the packet and avoid spoofing
session.packetReceived(packet);
try {
// Invoke the interceptors before we process the read packet
InterceptorManager.getInstance().invokeInterceptors(packet, session, true,
......@@ -271,7 +275,9 @@ public class SocketReadThread extends Thread {
session.process(reply);
continue;
}
packet.setFrom(session.getAddress());
// Notify the session that a new packet has been received. This could be useful
// for client sessions for setting the real sender of the packet and avoid spoofing
session.packetReceived(packet);
try {
// Invoke the interceptors before we process the read packet
InterceptorManager.getInstance().invokeInterceptors(packet, session, true,
......
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