Commit c3f13627 authored by Daniel Henninger's avatar Daniel Henninger Committed by dhenninger

[JM-761] [JM-769] Major reworking of gateway code. Built from the ground up. ...

[JM-761] [JM-769] Major reworking of gateway code.  Built from the ground up.  Still some functionality to go.  Wouldn't recommend attempting to use this yet.

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk/src/plugins/gateway@4505 b35dd754-fafc-0310-a699-88a17e54d16e
parent 1c5c4ec5
CREATE TABLE gatewayRegistration (
registrationID BIGINT NOT NULL,
jid VARCHAR(1024) NOT NULL,
gatewayType VARCHAR(15) NOT NULL,
transportType VARCHAR(15) NOT NULL,
username VARCHAR(255) NOT NULL,
password VARCHAR(255),
registrationDate BIGINT NOT NULL,
......@@ -9,6 +9,6 @@ CREATE TABLE gatewayRegistration (
CONSTRAINT gatewayReg_pk PRIMARY KEY (registrationID)
);
CREATE INDEX gatewayReg_jid_idx ON gatewayRegistration (jid);
CREATE INDEX gatewayReg_type_idx ON gatewayRegistration (gatewayType);
CREATE INDEX gatewayReg_type_idx ON gatewayRegistration (transportType);
INSERT INTO jiveVersion (name, version) VALUES ('gateway', 0);
CREATE TABLE gatewayRegistration (
registrationID BIGINT NOT NULL,
jid VARCHAR(1024) NOT NULL,
gatewayType VARCHAR(15) NOT NULL,
transportType VARCHAR(15) NOT NULL,
username VARCHAR(255) NOT NULL,
password VARCHAR(255),
registrationDate BIGINT NOT NULL,
lastLogin BIGINT,
PRIMARY KEY (registrationID),
INDEX gatewayReg_jid_idx(jid),
INDEX gatewayReg_type_idx(gatewayType)
INDEX gatewayReg_type_idx(transportType)
);
INSERT INTO jiveVersion (name, version) VALUES ('gateway', 0);
/**
* $Revision$
* $Date$
*
* Copyright (C) 2006 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.gateway;
/**
* AbstractGatewaySession provides an abstract implementation of
* <code>GatewaySession</code> that implements the some of the core responsibilties
* of a GatewaySession. This includes: handling registration and endpoint
* management.
*
* @author Noah Campbell
*/
public abstract class AbstractGatewaySession implements GatewaySession, Endpoint {
/**
* Construct an a gateway session.
*
* @param info the <code>SubscriptionInfo</code> for this session.
* @param gateway the <code>Gateway</code> that constructed this session.
*/
protected AbstractGatewaySession(SubscriptionInfo info, Gateway gateway) {
this.gateway = gateway;
this.subscription = info;
}
/**
* The gateway.
*/
protected transient Gateway gateway;
/**
* Has the client registered with the gateway?
*/
public boolean clientRegistered;
/**
* Has the server attempted to register with the client?
*/
public boolean serverRegistered;
/**
* The subscriptionInfo.
* @see org.jivesoftware.wildfire.gateway.SubscriptionInfo
*/
private final SubscriptionInfo subscription;
/**
* The jabber endpoint.
* @see org.jivesoftware.wildfire.gateway.Endpoint
*/
private Endpoint jabberEndpoint;
/**
* Set the Jabber <code>Endpoint</code>.
*
* @see org.jivesoftware.wildfire.gateway.GatewaySession#setJabberEndpoint(org.jivesoftware.wildfire.gateway.Endpoint)
*/
public void setJabberEndpoint(Endpoint jabberEndpoint) {
this.jabberEndpoint = jabberEndpoint;
}
/**
* Return the Jabber <code>Endpoint</code>.
*
* @return endpoint The Jabber endpoint.
* @see org.jivesoftware.wildfire.gateway.Endpoint
*/
public Endpoint getJabberEndpoint() {
return jabberEndpoint;
}
/**
* Return the legacy <code>Endpoint</code>.
*
* @return endpoint The legacy endpoint.
* @see org.jivesoftware.wildfire.gateway.Endpoint
*/
public Endpoint getLegacyEndpoint() {
return this;
}
/**
* Return the <code>SubscriptionInfo</code>
*
* @return subscriptionInfo the <code>SubscriptionInfo</code> associated
* this session.
* @see org.jivesoftware.wildfire.gateway.SubscriptionInfo
*/
public SubscriptionInfo getSubscriptionInfo() {
return this.subscription;
}
/**
* Return the gateway associated with this session.
*
* @return gateway The gateway.
* @see org.jivesoftware.wildfire.gateway.Gateway
*/
public Gateway getGateway() {
return this.gateway;
}
/**
* @see org.jivesoftware.wildfire.gateway.Endpoint#getValve()
*/
public EndpointValve getValve() {
return this.jabberEndpoint.getValve();
}
}
This diff is collapsed.
/**
* $Revision$
* $Date$
*
* Copyright (C) 2006 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.gateway;
import org.xmpp.component.ComponentException;
import org.xmpp.packet.Packet;
/**
* An endpoint represents a server or gateway and can forward the message to the
* underlying implementation, providing translation if necessary.
*
* @author Noah Campbell
*/
public interface Endpoint {
/**
* Send a packet to the underlying messaging services
*
* @param packet
* @throws ComponentException
*/
public void sendPacket(Packet packet) throws ComponentException;
/**
* Return the <code>EndpointValve</code>. This provides the ability of the
* caller to open or close the valve to control the follow of packets to the
* destination.
*
* @return valve The <code>EndpointValve</code> associated with this <code>Endpoint</code>
*/
public EndpointValve getValve();
}
/**
* $Revision$
* $Date$
*
* Copyright (C) 2006 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.gateway;
import java.util.concurrent.atomic.AtomicBoolean;
/**
* @author Noah Campbell
*/
public class EndpointValve {
/** The valve handle. */
private final AtomicBoolean open;
/**
* Construct a new <code>EndpointValve</code>. The valve is closed by
* default.
*/
public EndpointValve() {
this(false);
}
/**
* Construct a new <code>EndpointValve</code>.
*
* @param open The valve is open or closed.
*/
public EndpointValve(boolean open) {
this.open = new AtomicBoolean(open);
}
/**
* @return open If the valve is open or not.
*/
public boolean isOpen() {
return this.open.get();
}
/**
* Open the valve and let any pending message get processed.
*/
public void open() {
this.open.set(true);
}
/**
* Close the valve and queue any new messeages destine for the endpoint.
*/
public void close() {
this.open.set(false);
}
}
/**
* $Revision$
* $Date$
*
* Copyright (C) 2006 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.gateway;
import org.xmpp.packet.JID;
/**
* A gateway to an external or legacy messaging system. Users of the XMPP server register
* with the gateway by providing their login credentials with the external system. The
* gateway then logs into the external system on the user's behalf and translates IM
* data between the user's XMPP account and the external system.
*
* @author ncampbell
*/
public interface Gateway extends Endpoint {
/**
* Return the name, or node, of the gateway. This should comply with JID
* Node naming coventions
* @return Name The gateway name (JID Node)
*/
public String getName();
/**
* Sets the name, or node, of the gateway. This should comply with JID
* Node naming coventions
*/
public void setName(String newname);
/**
* A textual description of the gateway
* @return description
*/
public String getDescription();
/**
* The domain name
* @return domain
*/
public String getDomain();
/**
* Lookup a contact name for the JID
* @param jid The jabber id
* @return contact The legacy name
*/
public String whois(JID jid);
/**
* Lookup a JID for a legacy contact name
* @param contact The name of legacy contact
* @return JID
*/
public JID whois(String contact);
/**
* The JID of the gateway
* @return JID
*/
public JID getJID();
/**
* Return the session gateway for this gateway
* @return SessionFactory
*/
public SessionFactory getSessionFactory();
}
......@@ -13,7 +13,7 @@ package org.jivesoftware.wildfire.gateway;
import org.jivesoftware.util.Log;
import org.jivesoftware.wildfire.container.Plugin;
import org.jivesoftware.wildfire.container.PluginManager;
import org.jivesoftware.wildfire.gateway.util.GatewayInstance;
import org.jivesoftware.wildfire.gateway.TransportInstance;
import org.xmpp.component.ComponentManager;
import org.xmpp.component.ComponentManagerFactory;
import org.picocontainer.MutablePicoContainer;
......@@ -24,8 +24,11 @@ import java.io.File;
import java.util.Hashtable;
/**
* IM Gateway plugin, which provides connectivity to IM networks that don't support
* the XMPP protocol.
* IM Gateway plugin, which provides connectivity to IM networks that
* don't support the XMPP protocol.
*
* The entire plugin is referred to as the gateway, while individual
* IM network mappings are referred to as transports.
*
* @author Daniel Henninger
*/
......@@ -34,9 +37,9 @@ public class GatewayPlugin implements Plugin {
private MutablePicoContainer picoContainer;
/**
* Represents all configured gateway handlers.
* Represents all configured transport handlers.
*/
private Hashtable<String,GatewayInstance> gateways;
private Hashtable<String,TransportInstance> transports;
/**
* Represents the base component manager.
......@@ -52,29 +55,29 @@ public class GatewayPlugin implements Plugin {
public void initializePlugin(PluginManager manager, File pluginDirectory) {
picoContainer.start();
gateways = new Hashtable<String,GatewayInstance>();
transports = new Hashtable<String,TransportInstance>();
componentManager = ComponentManagerFactory.getComponentManager();
/* Set up AIM gateway. */
gateways.put("aim", new GatewayInstance("aim",
/* Set up AIM transport. */
transports.put("aim", new TransportInstance("aim",
"org.jivesoftware.wildfire.gateway.protocols.oscar.OSCARGateway", componentManager));
maybeStartService("aim");
/* Set up ICQ gateway. */
gateways.put("icq", new GatewayInstance("icq",
/* Set up ICQ transport. */
transports.put("icq", new TransportInstance("icq",
"org.jivesoftware.wildfire.gateway.protocols.oscar.OSCARGateway", componentManager));
maybeStartService("icq");
/* Set up Yahoo gateway. */
gateways.put("yahoo", new GatewayInstance("yahoo",
/* Set up Yahoo transport. */
transports.put("yahoo", new TransportInstance("yahoo",
"org.jivesoftware.wildfire.gateway.protocols.yahoo.YahooGateway", componentManager));
maybeStartService("yahoo");
}
public void destroyPlugin() {
for (GatewayInstance gwInstance : gateways.values()) {
gwInstance.stopInstance();
for (TransportInstance trInstance : transports.values()) {
trInstance.stopInstance();
}
picoContainer.stop();
picoContainer.dispose();
......@@ -92,38 +95,38 @@ public class GatewayPlugin implements Plugin {
}
/**
* Starts a gateway service, identified by subdomain. The gateway
* Starts a transport service, identified by subdomain. The transport
* service will only start if it is enabled.
*/
private void maybeStartService(String serviceName) {
GatewayInstance gwInstance = gateways.get(serviceName);
gwInstance.startInstance();
Log.debug("Starting gateway service: "+serviceName);
TransportInstance trInstance = transports.get(serviceName);
trInstance.startInstance();
Log.debug("Starting transport service: "+serviceName);
}
/**
* Enables a gateway service, identified by subdomain.
* Enables a transport service, identified by subdomain.
*/
public void enableService(String serviceName) {
GatewayInstance gwInstance = gateways.get(serviceName);
gwInstance.enable();
Log.debug("Enabling gateway service: "+serviceName);
TransportInstance trInstance = transports.get(serviceName);
trInstance.enable();
Log.debug("Enabling transport service: "+serviceName);
}
/**
* Disables a gateway service, identified by subdomain.
* Disables a transport service, identified by subdomain.
*/
public void disableService(String serviceName) {
GatewayInstance gwInstance = gateways.get(serviceName);
gwInstance.disable();
Log.debug("Disabling gateway service: "+serviceName);
TransportInstance trInstance = transports.get(serviceName);
trInstance.disable();
Log.debug("Disabling transport service: "+serviceName);
}
/**
* Returns the state of a gateway service, identified by subdomain.
* Returns the state of a transport service, identified by subdomain.
*/
public Boolean serviceEnabled(String serviceName) {
GatewayInstance gwInstance = gateways.get(serviceName);
return gwInstance.isEnabled();
TransportInstance trInstance = transports.get(serviceName);
return trInstance.isEnabled();
}
}
\ No newline at end of file
}
/**
* $Revision$
* $Date$
*
* Copyright (C) 2006 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.gateway;
import java.util.List;
import org.jivesoftware.wildfire.gateway.roster.ForeignContact;
import org.jivesoftware.wildfire.gateway.roster.UnknownForeignContactException;
import org.xmpp.packet.JID;
/**
* GatewaySession provides an interface that legacy gateways need to implement.
*
* @author Noah Campbell
*/
public interface GatewaySession {
/**
* Logout from the underlying gateway session.
* @throws Exception
*/
public void logout() throws Exception;
/**
* Login to the underlying gateway session.
* @throws Exception
*/
public void login() throws Exception;
/**
* Momento of this session, so it can be restablished later without the
* need for prompting the user for their credentials.
*
* @return SubscriptionInfo the subscription information for this session.
*/
public SubscriptionInfo getSubscriptionInfo();
/**
* Is the session connected?
*
* @return boolean
*/
public boolean isConnected();
/**
* Returns all sessions associated with this session/login.
*
* @return contacts A list of <code>String</code>s.
* @see java.util.List
*/
public List<ForeignContact> getContacts();
/**
* Return the endpoint for the legacy system.
*
* @see org.jivesoftware.wildfire.gateway.Endpoint
* @return Endpoint legacy endpoint.
*/
public Endpoint getLegacyEndpoint();
/**
* Get the Jabber endpoint.
*
* @see org.jivesoftware.wildfire.gateway.Endpoint
* @return Endpoint the jabber endpoint.
*/
public Endpoint getJabberEndpoint();
/**
* JID associated with this session.
*
* @return jid The jid for this session.
* @see org.xmpp.packet.JID
*/
public JID getJID();
/**
* Status for a particular contact.
*
* @param id The id of the contact of interest.
* @return status The status for the particular JID.
*/
public String getStatus(JID id);
/**
* Add a contact to this session. This method will typically update the
* roster on the legacy system.
*
* @param jid
* @throws Exception If add fails.
* @see org.xmpp.packet.JID
*/
public void addContact(JID jid) throws Exception;
/**
* Remove a contact from this session. This will typically update the
* roster on the legacy system.
*
* @param jid
* @throws Exception If remove fails.
* @see org.xmpp.packet.JID
*/
public void removeContact(JID jid) throws Exception;
/**
* Sets the XMPP Server endpoint.
*
* @param jabberEndpoint
* @see org.jivesoftware.wildfire.gateway.Endpoint
*/
public void setJabberEndpoint(Endpoint jabberEndpoint);
/**
* Get the gateway that is associated with this session. Every session
* has an orinating gateway from which is was created.
*
* @return gateway The underlying gateway for this sessin.
* @see org.jivesoftware.wildfire.gateway.Gateway
*/
public Gateway getGateway();
/**
* The session will return a foreign contact identified by the JID. If it
* does not exist then an exception will be thrown. The Session is responsible
* for contacting the gateway to perform any name resolution (if it cannot
* perform it from the JID).
*
* @param to The JID of the contact to locate.
* @return foreignContact The ForeignContact object that represents this JID.
* @throws UnknownForeignContactException
*/
public ForeignContact getContact(JID to) throws UnknownForeignContactException;
}
/**
* $Revision$
* $Date$
*
* Copyright (C) 2006 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.gateway;
import java.util.concurrent.ConcurrentLinkedQueue;
import org.jivesoftware.util.Log;
import org.jivesoftware.util.LocaleUtils;
import org.xmpp.component.Component;
import org.xmpp.component.ComponentException;
import org.xmpp.component.ComponentManager;
import org.xmpp.packet.Packet;
import java.util.Arrays;
/**
* The <code>JabberEndpoint</code> implements the <code>Endpoint</code> for an
* XMPP server.
*
* @author Noah Campbell
*/
public class JabberEndpoint implements Endpoint {
/**
* The componentManager
*
* @see ComponentManager
*/
private final ComponentManager componentManager;
/**
* The component
*
* @see Component
*/
private final Component component;
/**
* The value.
* @see EndpointValve
*/
private final EndpointValve valve;
/**
* Construct a new <code>JabberEndpoint</code>.
* @param componentManager The componentManager.
* @param component The component.
*/
public JabberEndpoint(ComponentManager componentManager, Component component) {
this(componentManager, component, new EndpointValve());
}
/**
* Construct a new <code>JabberEndpoint</code>.
* @param componentManager
* @param component
* @param valve
*/
public JabberEndpoint(ComponentManager componentManager, Component component, EndpointValve valve) {
this.componentManager = componentManager;
this.component = component;
this.valve= valve;
}
/**
* @see org.jivesoftware.wildfire.gateway.Endpoint#sendPacket(Packet)
*/
public void sendPacket(Packet packet) throws ComponentException {
if (valve.isOpen()) {
/**
* Push all pending packets to the XMPP Server.
*/
while (!queue.isEmpty()) {
this.componentManager.sendPacket(this.component, queue.poll());
}
this.componentManager.sendPacket(this.component, packet);
}
else {
queue.add(packet);
Log.debug(LocaleUtils.getLocalizedString("jabberendpoint.sendpacketenqueue", "gateway", Arrays.asList(packet.getFrom())));
}
}
/** The backlog queue. */
private final ConcurrentLinkedQueue<Packet> queue = new ConcurrentLinkedQueue<Packet>();
/**
* @see org.jivesoftware.wildfire.gateway.Endpoint#getValve()
*/
public EndpointValve getValve() {
return this.valve;
}
}
......@@ -22,11 +22,11 @@ import java.util.Date;
import java.sql.*;
/**
* Contains information about the registration a user has made with an external gateway.
* Each registration includes a username and password used to login to the gateway
* Contains information about the registration a user has made with an external transport.
* Each registration includes a username and password used to login to the transport
* as well as a registration date and last login date.<p>
*
* The password for the gateway registration is stored in encrypted form using
* The password for the transport registration is stored in encrypted form using
* the Wildfire password encryption key. See {@link AuthFactory#encryptPassword(String)}.
*
* @author Matt Tucker
......@@ -35,10 +35,10 @@ import java.sql.*;
public class Registration {
private static final String INSERT_REGISTRATION =
"INSERT INTO gatewayRegistration(registrationID, jid, gatewayType, " +
"INSERT INTO gatewayRegistration(registrationID, jid, transportType, " +
"username, password, registrationDate) VALUES (?,?,?,?,?,?)";
private static final String LOAD_REGISTRATION =
"SELECT jid, gatewayType, username, password, registrationDate, lastLogin " +
"SELECT jid, transportType, username, password, registrationDate, lastLogin " +
"FROM gatewayRegistration WHERE registrationID=?";
private static final String SET_LAST_LOGIN =
"UPDATE gatewayRegistration SET lastLogin=? WHERE registrationID=?";
......@@ -47,7 +47,7 @@ public class Registration {
private long registrationID;
private JID jid;
private GatewayType gatewayType;
private TransportType transportType;
private String username;
private String password;
private Date registrationDate;
......@@ -57,17 +57,17 @@ public class Registration {
* Creates a new registration.
*
* @param jid the JID of the user making the registration.
* @param gatewayType the type of the gateway.
* @param username the username on the gateway.
* @param password the password on the gateway.
* @param transportType the type of the transport.
* @param username the username on the transport.
* @param password the password on the transport.
*/
public Registration(JID jid, GatewayType gatewayType, String username, String password) {
if (jid == null || gatewayType == null || username == null) {
public Registration(JID jid, TransportType transportType, String username, String password) {
if (jid == null || transportType == null || username == null) {
throw new NullPointerException("Arguments cannot be null.");
}
// Ensure that we store the bare JID.
this.jid = new JID(jid.toBareJID());
this.gatewayType = gatewayType;
this.transportType = transportType;
this.username = username;
this.password = password;
this.registrationDate = new Date();
......@@ -111,16 +111,16 @@ public class Registration {
}
/**
* Returns the type of the gateway.
* Returns the type of the transport.
*
* @return the gateway type.
* @return the transport type.
*/
public GatewayType getGatewayType() {
return gatewayType;
public TransportType getTransportType() {
return transportType;
}
/**
* Returns the username used for logging in to the gateway.
* Returns the username used for logging in to the transport.
*
* @return the username.
*/
......@@ -129,7 +129,7 @@ public class Registration {
}
/**
* Returns the password used for logging in to the gateway.
* Returns the password used for logging in to the transport.
*
* @return the password.
*/
......@@ -138,7 +138,7 @@ public class Registration {
}
/**
* Sets the password used for logging in to the gateway.
* Sets the password used for logging in to the transport.
* @param password
*/
public void setPassword(String password) {
......@@ -168,7 +168,7 @@ public class Registration {
}
/**
* Returns the date that this gateway registration was created.
* Returns the date that this transport registration was created.
*
* @return the date the registration was created.
*/
......@@ -177,7 +177,7 @@ public class Registration {
}
/**
* Returns the date that the user last logged in to the gateway using this
* Returns the date that the user last logged in to the transport using this
* registration data, or <tt>null</tt> if the user has never logged in.
*
* @return the last login date.
......@@ -187,7 +187,7 @@ public class Registration {
}
/**
* Sets the data that the user last logged into the gateway.
* Sets the data that the user last logged into the transport.
*
* @param lastLogin the last login date.
*/
......@@ -211,7 +211,7 @@ public class Registration {
}
public String toString() {
return jid + ", " + gatewayType + ", " + username;
return jid + ", " + transportType + ", " + username;
}
/**
......@@ -227,7 +227,7 @@ public class Registration {
pstmt = con.prepareStatement(INSERT_REGISTRATION);
pstmt.setLong(1, registrationID);
pstmt.setString(2, jid.toString());
pstmt.setString(3, gatewayType.name());
pstmt.setString(3, transportType.name());
pstmt.setString(4, username);
if (password != null) {
// The password is stored in encrypted form for improved security.
......@@ -262,7 +262,7 @@ public class Registration {
throw new NotFoundException("Registration not found: " + registrationID);
}
this.jid = new JID(rs.getString(1));
this.gatewayType = GatewayType.valueOf(rs.getString(2));
this.transportType = TransportType.valueOf(rs.getString(2));
this.username = rs.getString(3);
// The password is stored in encrypted form, so decrypt it.
this.password = AuthFactory.decryptPassword(rs.getString(4));
......@@ -282,4 +282,4 @@ public class Registration {
DbConnectionManager.closeConnection(rs, pstmt, con);
}
}
}
\ No newline at end of file
}
......@@ -23,7 +23,7 @@ import java.sql.SQLException;
import java.sql.ResultSet;
/**
* Manages registration data for gateways. Individual gateways use the registration data
* Manages registration data for transports. Individual transports use the registration data
* and then create sessions used to exchange messages and presence data.
*
* @author Matt Tucker
......@@ -37,14 +37,14 @@ public class RegistrationManager implements Startable {
private static final String ALL_REGISTRATIONS =
"SELECT registrationID FROM gatewayRegistration";
private static final String LOAD_REGISTRATION =
"SELECT registrationID FROM gatewayRegistration WHERE jid=? AND gatewayType=? " +
"SELECT registrationID FROM gatewayRegistration WHERE jid=? AND transportType=? " +
"AND username=?";
private static final String ALL_USER_REGISTRATIONS =
"SELECT registrationID FROM gatewayRegistration WHERE jid=?";
private static final String ALL_GATEWAY_REGISTRATIONS =
"SELECT registrationID FROM gatewayRegistration WHERE gatewayType=?";
"SELECT registrationID FROM gatewayRegistration WHERE transportType=?";
private static final String USER_GATEWAY_REGISTRATIONS =
"SELECT registrationID FROM gatewayRegistration WHERE jid=? AND gatewayType=?";
"SELECT registrationID FROM gatewayRegistration WHERE jid=? AND transportType=?";
public void start() {
......@@ -58,15 +58,15 @@ public class RegistrationManager implements Startable {
* Creates a new registration.
*
* @param jid the JID of the user making the registration.
* @param gatewayType the type of the gateway.
* @param username the username on the gateway service.
* @param password the password on the gateway service.
* @param transportType the type of the transport.
* @param username the username on the transport service.
* @param password the password on the transport service.
* @return a new registration.
*/
public Registration createRegistration(JID jid, GatewayType gatewayType, String username,
public Registration createRegistration(JID jid, TransportType transportType, String username,
String password)
{
return new Registration(jid, gatewayType, username, password);
return new Registration(jid, transportType, username, password);
}
/**
......@@ -93,12 +93,12 @@ public class RegistrationManager implements Startable {
}
/**
* Returns all registrations for a particular type of gateway.
* Returns all registrations for a particular type of transport.
*
* @param gatewayType the gateway type.
* @return all registrations for the gateway type.
* @param transportType the transport type.
* @return all registrations for the transport type.
*/
public Collection<Registration> getRegistrations(GatewayType gatewayType) {
public Collection<Registration> getRegistrations(TransportType transportType) {
List<Long> registrationIDs = new ArrayList<Long>();
Connection con = null;
PreparedStatement pstmt = null;
......@@ -106,7 +106,7 @@ public class RegistrationManager implements Startable {
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(ALL_GATEWAY_REGISTRATIONS);
pstmt.setString(1, gatewayType.name());
pstmt.setString(1, transportType.name());
rs = pstmt.executeQuery();
while (rs.next()) {
registrationIDs.add(rs.getLong(1));
......@@ -162,17 +162,17 @@ public class RegistrationManager implements Startable {
}
/**
* Returns all registrations that a JID has on a particular gateway type.
* In the typical case, a JID has a single registration with a particular gateway
* Returns all registrations that a JID has on a particular transport type.
* In the typical case, a JID has a single registration with a particular transport
* type. However, it's also possible to maintain multiple registrations. For example,
* the user "joe_smith@example.com" might have have two user accounts on the AIM
* gateway service: "jsmith" and "joesmith".
* transport service: "jsmith" and "joesmith".
*
* @param jid the JID of the user.
* @param gatewayType the type of the gateway.
* @return all registrations for the JID of a particular gateway type.
* @param transportType the type of the transport.
* @return all registrations for the JID of a particular transport type.
*/
public Collection<Registration> getRegistrations(JID jid, GatewayType gatewayType) {
public Collection<Registration> getRegistrations(JID jid, TransportType transportType) {
List<Long> registrationIDs = new ArrayList<Long>();
Connection con = null;
PreparedStatement pstmt = null;
......@@ -182,7 +182,7 @@ public class RegistrationManager implements Startable {
pstmt = con.prepareStatement(USER_GATEWAY_REGISTRATIONS);
// Use the bare JID of the user.
pstmt.setString(1, jid.toBareJID());
pstmt.setString(2, gatewayType.name());
pstmt.setString(2, transportType.name());
rs = pstmt.executeQuery();
while (rs.next()) {
registrationIDs.add(rs.getLong(1));
......@@ -203,15 +203,15 @@ public class RegistrationManager implements Startable {
}
/**
* Returns a registration given a JID, gateway type, and username.
* Returns a registration given a JID, transport type, and username.
*
* @param jid the JID of the user.
* @param gatewayType the gateway type.
* @param username the username on the gateway service.
* @param transportType the transport type.
* @param username the username on the transport service.
* @return the registration.
* @throws NotFoundException if the registration could not be found.
*/
public Registration getRegistration(JID jid, GatewayType gatewayType, String username)
public Registration getRegistration(JID jid, TransportType transportType, String username)
throws NotFoundException
{
long registrationID = -1;
......@@ -222,7 +222,7 @@ public class RegistrationManager implements Startable {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(LOAD_REGISTRATION);
pstmt.setString(1, jid.toBareJID());
pstmt.setString(2, gatewayType.name());
pstmt.setString(2, transportType.name());
pstmt.setString(3, username);
rs = pstmt.executeQuery();
if (!rs.next()) {
......@@ -369,4 +369,4 @@ public class RegistrationManager implements Startable {
return registrationIDs.size();
}
}
}
\ No newline at end of file
}
/**
* $Revision$
* $Date$
*
* Copyright (C) 2006 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.gateway;
/**
* {@code SessionFactory} is used to generate a new {@code GatewaySession}.
*
* @author Noah Campbell
*/
public interface SessionFactory {
/**
* Return a new instance of a {@code GatewaySession}.
*
* @param info The subscription information for the session.
* @return gatewaySession The gateway session.
*/
public GatewaySession newInstance(SubscriptionInfo info);
}
/**
* $Revision$
* $Date$
*
* Copyright (C) 2006 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.gateway;
import java.io.Serializable;
import org.xmpp.packet.JID;
/**
* <code>SubscriptionInfo</code> contains all the information that pertains to
* a legacy gateway that must be persisted across sessions. For example,
* username and password are stored so the user does not have to enter the
* information repeatedly.
*
* @author Noah Campbell
*/
public class SubscriptionInfo implements Serializable {
private static final long serialVersionUID = 1L;
/**
* Construct a new <code>SubscriptionInfo</code>
* @param username The username
* @param password The password
*/
public SubscriptionInfo(String username, String password, JID jid) {
this.username = username;
this.password = password;
this.jid = jid;
}
/**
* Has the session been registered on the client?
*/
public boolean clientRegistered;
/**
* Has the server registered with the client?
*/
public boolean serverRegistered;
/**
* The username.
*/
public String username;
/**
* The password.
*/
public String password;
/**
* The jid.
*
* @see org.xmpp.packet.JID
*/
//public transient JID jid;
public JID jid;
}
/**
* $Revision$
* $Date$
*
* Copyright (C) 2006 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.gateway;
import org.jivesoftware.util.Log;
import org.xmpp.component.ComponentManager;
import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.wildfire.gateway.BaseTransport;
import org.jivesoftware.util.PropertyEventDispatcher;
/**
* Transport Instance
*
* Represents all information that needs to be tracked about a gateway instance.
*
* @author Daniel Henninger
*/
public class TransportInstance {
private ComponentManager componentManager;
private String serviceName = null;
private String nameOfClass = null;
private BaseTransport transport = null;
private Boolean enabled = false;
private Boolean running = false;
/**
* Creates a new transport instance.
*
* @param subdomain Part of transport domain prepended to server domain.
* @param classname Full name/path of class associated with instance.
* @param componentManager Component manager managing this instance.
*/
public TransportInstance(String subdomain, String classname, ComponentManager componentManager) {
this.serviceName = subdomain;
this.nameOfClass = classname;
this.componentManager = componentManager;
enabled = JiveGlobals.getBooleanProperty("plugin.gateway."+serviceName+"Enabled", false);
}
/**
* Retrieves the name of the service (aka, subdomain)
*
* @return name of the service
*/
public String getName() {
return serviceName;
}
/**
* Returns whether this transport instance is enabled.
*
* @return true or false if instance is enabled
*/
public Boolean isEnabled() {
return enabled;
}
/**
* Returns whether this transport instance is currently running.
*
* @return true or false if instance is currently running
*/
public Boolean isRunning() {
return running;
}
/**
* Enables the transport instance and starts it if it's not already running.
*/
public void enable() {
enabled = true;
JiveGlobals.setProperty("plugin.gateway."+serviceName+"Enabled", "true");
if (!running) {
startInstance();
}
}
/**
* Disables the transport instance and stops it if it's running.
*/
public void disable() {
enabled = false;
JiveGlobals.setProperty("plugin.gateway."+serviceName+"Enabled", "false");
if (running) {
stopInstance();
}
}
/**
* Starts the transport instance if it's enabled and not already running.
*/
public void startInstance() {
if (!enabled || running) {
return;
}
BaseTransport transport = null;
Log.debug("Loading class "+nameOfClass);
try {
transport = (BaseTransport)Class.forName(nameOfClass).newInstance();
}
catch (ClassNotFoundException e) {
Log.error("Unable to find class: "+nameOfClass);
}
catch (InstantiationException e) {
Log.error("Unable to instantiate class: "+nameOfClass);
}
catch (IllegalAccessException e) {
Log.error("Unable to access class: "+nameOfClass);
}
//transport.setName(serviceName);
//componentManager = ComponentManagerFactory.getComponentManager();
try {
componentManager.addComponent(serviceName, transport);
//PropertyEventDispatcher.addListener(transport);
running = true;
}
catch (Exception e) {
componentManager.getLog().error(e);
}
}
/**
* Stops the transport instance if it's running.
*/
public void stopInstance() {
if (!running) {
return;
}
//PropertyEventDispatcher.removeListener(transport);
try {
componentManager.removeComponent(serviceName);
//componentManager = null;
}
catch (Exception e) {
componentManager.getLog().error(e);
}
transport = null;
running = false;
}
}
/**
* $Revision$
* $Date$
*
* Copyright (C) 2006 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.gateway;
import org.xmpp.packet.JID;
/**
* Interface for a transport session.
*
* This outlines all of the functionality that is required for a transport
* to implement. These are functions that the XMPP side of things are going
* interact with. The legacy transport itself is expected to handle messages
* going to the Jabber user.
*
* @author Daniel Henninger
*/
public abstract class TransportSession {
/**
* Creates a TransportSession instance.
*
* @param registration Registration this session is associated with.
*/
public TransportSession(Registration registration, BaseTransport transport) {
this.registration = registration;
this.transport = transport;
}
/**
* Registration that this session is associated with.
*/
public Registration registration;
/**
* Transport this session is associated with.
*/
public BaseTransport transport;
/**
* Retrieves the registration information associated with the session.
*/
public Registration getRegistration() {
return registration;
}
/**
* Retrieves the transport associated wtih the session.
*/
public BaseTransport getTransport() {
return transport;
}
/**
* Logs in to the legacy service.
*/
public abstract void logIn();
/**
* Log out of the legacy service.
*/
public abstract void logOut();
/**
* Is the legacy service account logged in?
*
* @return True or false if the legacy account is logged in.
*/
public abstract Boolean isLoggedIn();
/**
* Adds a legacy contact to the legacy service.
*
* @param jid JID associated with the legacy contact.
*/
public abstract void addContact(JID jid);
/**
* Removes a legacy contact from the legacy service.
*
* @param jid JID associated with the legacy contact.
*/
public abstract void removeContact(JID jid);
/**
* Sends an outgoing message through the legacy serivce.
*
* @param jid JID associated with the target contact.
* @param message Message to be sent.
*/
public abstract void sendMessage(JID jid, String message);
}
/**
* $Revision$
* $Date$
*
* Copyright (C) 2006 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.gateway;
import java.util.HashMap;
import java.util.Map;
import org.jivesoftware.util.NotFoundException;
import org.xmpp.packet.JID;
/**
* Manages sessions with legacy transports implementations.
*
* Keeps track of all of the active sessions with the various transports.
* Only one expected to be associated with a single transport instance.
*
* @author Daniel Henninger
*/
public class TransportSessionManager {
/**
* Container for all active sessions.
*/
private Map<JID,TransportSession> activeSessions = new HashMap<JID,TransportSession>();
/**
* Retrieve the session instance for a given JID.
*
* Ignores the resource part of the jid.
*
* @param jid JID of the instance to be retrieved.
* @throws NotFoundException if the given jid is not found.
* @return TransportSession instance requested.
*/
public TransportSession getSession(JID jid) throws NotFoundException {
TransportSession session = activeSessions.get(jid.toBareJID());
if (session == null) {
throw new NotFoundException("Could not find session requested.");
}
return session;
}
/**
* Stores a new session instance with the legacy service.
*
* Expects to be given a JID and a pre-created session. Ignores the
* resource part of the JID.
*
* @param jid JID information used to track the session.
* @param session TransportSession associated with the jid.
*/
public void storeSession(JID jid, TransportSession session) {
activeSessions.put(new JID(jid.toBareJID()), session);
}
/**
* Removes a session instance with the legacy service.
*
* Expects to be given a JID which indicates which session we are
* removing.
*
* @param jid JID to be removed.
*/
public void removeSession(JID jid) {
activeSessions.remove(new JID(jid.toBareJID()));
}
}
......@@ -11,12 +11,12 @@
package org.jivesoftware.wildfire.gateway;
/**
* An enumeration for the valid gateway types, which encompasses proprietary IM networks
* An enumeration for the valid transport types, which encompasses proprietary IM networks
* as well as other IM protocols.
*
* @author Matt Tucker
*/
public enum GatewayType {
public enum TransportType {
/**
* The AOL instant messaging service.
......
......@@ -31,15 +31,15 @@ import java.net.InetAddress;
public class BOSConnection extends BasicFlapConnection {
protected SsiItemObjectFactory itemFactory = new DefaultSsiItemObjFactory();
public BOSConnection(OSCARGatewaySession mainSession, ByteBlock cookie) {
public BOSConnection(OSCARSession mainSession, ByteBlock cookie) {
super(mainSession, cookie); // HAnd off to BasicFlapConnection
}
public BOSConnection(String host, int port, OSCARGatewaySession mainSession, ByteBlock cookie) {
public BOSConnection(String host, int port, OSCARSession mainSession, ByteBlock cookie) {
super(host, port, mainSession, cookie); // HAnd off to BasicFlapConnection
}
public BOSConnection(InetAddress ip, int port, OSCARGatewaySession mainSession, ByteBlock cookie) {
public BOSConnection(InetAddress ip, int port, OSCARSession mainSession, ByteBlock cookie) {
super(ip, port, mainSession, cookie); // HAnd off to BasicFlapConnection
}
......@@ -107,7 +107,7 @@ public class BOSConnection extends BasicFlapConnection {
Log.debug("connecting to " + sr.getRedirectHost()
+ " for 0x" + Integer.toHexString(sr.getSnacFamily()));
session.connectToService(sr.getSnacFamily(), sr.getRedirectHost(),
oscarSession.connectToService(sr.getSnacFamily(), sr.getRedirectHost(),
sr.getCookie());
} else if (cmd instanceof SsiDataCmd) {
......@@ -117,10 +117,10 @@ public class BOSConnection extends BasicFlapConnection {
for (int i = 0; i < items.length; i++) {
SsiItemObj obj = itemFactory.getItemObj(items[i]);
if (obj instanceof BuddyItem) {
session.gotBuddy((BuddyItem)obj);
oscarSession.gotBuddy((BuddyItem)obj);
}
else if (obj instanceof GroupItem) {
session.gotGroup((GroupItem)obj);
oscarSession.gotGroup((GroupItem)obj);
}
Log.debug("- " + (obj == null ? (Object) items[i]
: (Object) obj));
......
......@@ -24,23 +24,23 @@ import java.net.InetAddress;
public abstract class BaseFlapConnection extends ClientFlapConn {
protected ClientSnacProcessor sp;
OSCARGatewaySession session;
OSCARSession oscarSession;
public BaseFlapConnection(OSCARGatewaySession mainSession) {
public BaseFlapConnection(OSCARSession mainSession) {
initBaseFlapConnection();
session = mainSession;
oscarSession = mainSession;
}
public BaseFlapConnection(String host, int port, OSCARGatewaySession mainSession) {
public BaseFlapConnection(String host, int port, OSCARSession mainSession) {
super(host, port); // Hand off to ClientFlapConn
initBaseFlapConnection();
session = mainSession;
oscarSession = mainSession;
}
public BaseFlapConnection(InetAddress ip, int port, OSCARGatewaySession mainSession) {
public BaseFlapConnection(InetAddress ip, int port, OSCARSession mainSession) {
super(ip, port); // Hand off to ClientFlapConn
initBaseFlapConnection();
session = mainSession;
oscarSession = mainSession;
}
private void initBaseFlapConnection() {
......@@ -90,7 +90,7 @@ public abstract class BaseFlapConnection extends ClientFlapConn {
return sp;
}
public OSCARGatewaySession getMainSession() { return session; }
public OSCARSession getMainSession() { return oscarSession; }
void sendRequest(SnacRequest req) {
if (!req.hasListeners()) req.addListener(genericReqListener);
......
......@@ -12,8 +12,19 @@
package org.jivesoftware.wildfire.gateway.protocols.oscar;
import org.jivesoftware.util.Log;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.net.InetAddress;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import net.kano.joscar.*;
import net.kano.joscar.flap.*;
import net.kano.joscar.flapcmd.*;
......@@ -33,22 +44,9 @@ import net.kano.joscar.snaccmd.buddy.*;
import net.kano.joscar.snaccmd.conn.*;
import net.kano.joscar.snaccmd.icbm.*;
import net.kano.joscar.snaccmd.rooms.*;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.net.InetAddress;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.jivesoftware.util.Log;
import org.xmpp.packet.Message;
import org.xmpp.packet.Packet;
public abstract class BasicFlapConnection extends BaseFlapConnection {
protected final ByteBlock cookie;
......@@ -90,17 +88,17 @@ public abstract class BasicFlapConnection extends BaseFlapConnection {
rvProcessor.addListener(rvListener);
}
public BasicFlapConnection(OSCARGatewaySession mainSession, ByteBlock cookie) {
public BasicFlapConnection(OSCARSession mainSession, ByteBlock cookie) {
super(mainSession);
this.cookie = cookie;
}
public BasicFlapConnection(String host, int port, OSCARGatewaySession mainSession, ByteBlock cookie) {
public BasicFlapConnection(String host, int port, OSCARSession mainSession, ByteBlock cookie) {
super(host, port, mainSession);
this.cookie = cookie;
}
public BasicFlapConnection(InetAddress ip, int port, OSCARGatewaySession mainSession,
public BasicFlapConnection(InetAddress ip, int port, OSCARSession mainSession,
ByteBlock cookie) {
super(ip, port, mainSession);
this.cookie = cookie;
......@@ -140,7 +138,7 @@ public abstract class BasicFlapConnection extends BaseFlapConnection {
setSnacFamilyInfos(familyInfos);
session.registerSnacFamilies(this);
oscarSession.registerSnacFamilies(this);
request(new ClientVersionsCmd(familyInfos));
request(new RateInfoRequest());
......@@ -154,16 +152,11 @@ public abstract class BasicFlapConnection extends BaseFlapConnection {
msg = OscarTools.stripHtml(message.getMessage());
Message jmessage = new Message();
jmessage.setTo(session.getSessionJID());
jmessage.setTo(oscarSession.getRegistration().getJID());
jmessage.setBody(msg);
jmessage.setType(Message.Type.chat);
jmessage.setFrom(this.session.getGateway().whois(sn));
try {
session.getJabberEndpoint().sendPacket(jmessage);
}
catch (Exception ex) {
Log.error("Unable to send packet.");
}
jmessage.setFrom(this.oscarSession.getTransport().convertIDToJID(sn));
oscarSession.getTransport().sendPacket((Packet)jmessage);
//sendRequest(new SnacRequest(new SendImIcbm(sn, msg), null));
......@@ -311,7 +304,7 @@ public abstract class BasicFlapConnection extends BaseFlapConnection {
}
protected void dispatchRequest(SnacRequest req) {
session.handleRequest(req);
oscarSession.handleRequest(req);
}
protected SnacRequest request(SnacCommand cmd,
......@@ -329,7 +322,7 @@ public abstract class BasicFlapConnection extends BaseFlapConnection {
// this connection supports this snac, so we'll send it here
sendRequest(request);
} else {
session.handleRequest(request);
oscarSession.handleRequest(request);
}
}
......
......@@ -26,15 +26,15 @@ import java.net.InetAddress;
public class LoginConnection extends BaseFlapConnection {
protected boolean loggedin = false;
public LoginConnection(OSCARGatewaySession mainSession) {
public LoginConnection(OSCARSession mainSession) {
super(mainSession); // Hand off to BaseFlapConnection
}
public LoginConnection(String host, int port, OSCARGatewaySession mainSession) {
public LoginConnection(String host, int port, OSCARSession mainSession) {
super(host, port, mainSession); // Hand off to BaseFlapConnection
}
public LoginConnection(InetAddress ip, int port, OSCARGatewaySession mainSession) {
public LoginConnection(InetAddress ip, int port, OSCARSession mainSession) {
super(ip, port, mainSession); // Hand off to BaseFlapConnection
}
......@@ -44,7 +44,7 @@ public class LoginConnection extends BaseFlapConnection {
if (e.getNewState() == ClientFlapConn.STATE_CONNECTED) {
Log.debug("connected, sending flap version and key request");
getFlapProcessor().sendFlap(new LoginFlapCmd());
request(new KeyRequest(session.getLegacyName()));
request(new KeyRequest(oscarSession.getRegistration().getUsername()));
}
else if (e.getNewState() == ClientFlapConn.STATE_FAILED) {
Log.info("connection failed: " + e.getReason());
......@@ -75,9 +75,7 @@ public class LoginConnection extends BaseFlapConnection {
"AOL Instant Messenger, version 5.2.3292/WIN32",
5, 1, 0, 3292, 238);
request(new AuthRequest(
session.getLegacyName(), session.getLegacyPassword(),
version, authkey));
request(new AuthRequest(oscarSession.getRegistration().getUsername(), oscarSession.getRegistration().getPassword(), version, authkey));
} else if (cmd instanceof AuthResponse) {
AuthResponse ar = (AuthResponse) cmd;
......@@ -90,8 +88,7 @@ public class LoginConnection extends BaseFlapConnection {
}
} else {
loggedin = true;
session.startBosConn(ar.getServer(), ar.getPort(),
ar.getCookie());
oscarSession.startBosConn(ar.getServer(), ar.getPort(), ar.getCookie());
Log.info("connecting to " + ar.getServer() + ":"
+ ar.getPort());
}
......
/**
* $Revision$
* $Date$
*
* Copyright (C) 2006 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.gateway.protocols.oscar;
import org.jivesoftware.util.Log;
import org.jivesoftware.wildfire.gateway.Gateway;
import org.jivesoftware.wildfire.gateway.roster.AbstractForeignContact;
import org.jivesoftware.wildfire.gateway.roster.Status;
import net.kano.joscar.snaccmd.ssi.*;
import net.kano.joscar.ssiitem.*;
/**
* @author Daniel Henninger
*/
public class OSCARForeignContact extends AbstractForeignContact {
private BuddyItem ssiItem;
private String oscarStatus = "offline";
public OSCARForeignContact(BuddyItem ssiItem, Gateway gateway) {
super(ssiItem.getScreenname(), new Status(), gateway);
this.ssiItem = ssiItem;
}
public Status getStatus() {
getStatusMessage(ssiItem, this.status);
return super.status;
}
public void setStatus(String oscarStatus) {
this.oscarStatus = oscarStatus;
}
private Status getStatusMessage(BuddyItem issiItem, Status status) {
status.setOnline(true);
// We need to check other statuses here, keep track of them somehow.
return status;
}
public String getName() {
return ssiItem.getScreenname();
}
public SsiItem getSSIItem() {
return ssiItem.toSsiItem();
}
}
/**
* $Revision$
* $Date$
*
* Copyright (C) 2006 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.gateway.protocols.oscar;
import org.jivesoftware.util.Log;
import org.jivesoftware.wildfire.gateway.BaseGateway;
import org.jivesoftware.wildfire.gateway.GatewaySession;
import org.jivesoftware.wildfire.gateway.SubscriptionInfo;
import org.xmpp.component.ComponentException;
import org.xmpp.packet.JID;
import org.xmpp.packet.Message;
import org.xmpp.packet.Packet;
/**
* @author Daniel Henninger
*/
public class OSCARGateway extends BaseGateway {
/* Gateway Name String */
private static String NameString = "oscar";
@Override
public String getName() {
return NameString;
}
@Override
public void setName(String newname) {
NameString = newname;
}
@Override
public String getDescription() {
return "OSCAR (AIM/ICQ) Gateway";
}
/*@SuppressWarnings("unused"); */
public void sendPacket(@SuppressWarnings("unused") Packet packet) throws ComponentException {
// Do nothing
}
public void sendMessage(JID jid, String string) throws Exception {
Message m = new Message();
m.setTo(jid);
m.setBody(string);
this.sendPacket(m);
}
@Override
public String getType() {
return "oscar";
}
@Override
public String getVersion() {
return "v1.0";
}
@Override
protected GatewaySession getSessionInstance(SubscriptionInfo info) {
Log.debug("Getting session instance");
return new OSCARGatewaySession(info, this);
}
}
......@@ -11,21 +11,9 @@
package org.jivesoftware.wildfire.gateway.protocols.oscar;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.HashSet;
import org.jivesoftware.util.Log;
import org.jivesoftware.wildfire.gateway.AbstractGatewaySession;
import org.jivesoftware.wildfire.gateway.Endpoint;
import org.jivesoftware.wildfire.gateway.Gateway;
import org.jivesoftware.wildfire.gateway.SubscriptionInfo;
import org.jivesoftware.wildfire.gateway.roster.ForeignContact;
import org.jivesoftware.wildfire.gateway.roster.UnknownForeignContactException;
import org.xmpp.packet.JID;
import org.xmpp.packet.Message;
import org.xmpp.packet.Packet;
import net.kano.joscar.flapcmd.*;
import net.kano.joscar.snac.*;
import net.kano.joscar.snaccmd.conn.*;
......@@ -33,13 +21,32 @@ import net.kano.joscar.snaccmd.icbm.*;
import net.kano.joscar.snaccmd.ssi.*;
import net.kano.joscar.ssiitem.*;
import net.kano.joscar.ByteBlock;
import org.jivesoftware.util.Log;
import org.jivesoftware.wildfire.gateway.Registration;
import org.jivesoftware.wildfire.gateway.TransportSession;
import org.xmpp.packet.JID;
import org.xmpp.packet.Message;
import org.xmpp.packet.Packet;
/**
* Manages the session to the underlying legacy system.
* Represents an OSCAR session.
*
* This is the interface with which the base transport functionality will
* communicate with OSCAR (AIM/ICQ).
*
* @author Daniel Henninger
*/
public class OSCARGatewaySession extends AbstractGatewaySession implements Endpoint {
public class OSCARSession extends TransportSession {
/**
* Initialize a new session object for OSCAR
*
* @param info The subscription information to use during login.
* @param gateway The gateway that created this session.
*/
public OSCARSession(Registration registration, OSCARTransport transport) {
super(registration, transport);
}
/**
* OSCAR Session Pieces
......@@ -47,7 +54,7 @@ public class OSCARGatewaySession extends AbstractGatewaySession implements Endpo
private LoginConnection loginConn = null;
private BOSConnection bosConn = null;
private Set services = new HashSet();
private Boolean connected = false;
private Boolean loggedIn = false;
/**
* The Screenname, Password, and JID associated with this session.
......@@ -57,97 +64,38 @@ public class OSCARGatewaySession extends AbstractGatewaySession implements Endpo
private String legacypass = null;
/**
* Misc tracking variables.
* SSI tracking variables.
*/
private ArrayList<ForeignContact> contacts = new ArrayList<ForeignContact>();
private ArrayList<BuddyItem> buddies = new ArrayList<BuddyItem>();
private ArrayList<GroupItem> groups = new ArrayList<GroupItem>();
private Integer highestBuddyId = -1;
private Integer highestGroupId = -1;
/**
* Initialize a new session object for OSCAR
*
* @param info The subscription information to use during login.
* @param gateway The gateway that created this session.
*/
public OSCARGatewaySession(SubscriptionInfo info, Gateway gateway) {
super(info, gateway);
this.jid = info.jid;
this.legacyname = info.username;
this.legacypass = info.password;
}
public synchronized void login() throws Exception {
public void logIn() {
Log.debug("Login called");
if (!isConnected()) {
if (!isLoggedIn()) {
Log.debug("Connecting...");
loginConn = new LoginConnection("login.oscar.aol.com", 5190, this);
loginConn.connect();
getJabberEndpoint().getValve().open(); // allow any buffered messages to pass through
connected = true;
loggedIn = true;
} else {
Log.warn(this.jid + " is already logged in");
}
}
public boolean isConnected() {
Log.debug("isConnected called");
return connected;
public Boolean isLoggedIn() {
Log.debug("isLoggedIn called");
return loggedIn;
}
public synchronized void logout() throws Exception {
public synchronized void logOut() {
Log.debug("logout called");
Log.info("[" + this.jid + "]" + getSubscriptionInfo().username + " logged out.");
bosConn.disconnect();
connected = false;
loggedIn = false;
}
@Override
public String toString() { return "[" + this.getSubscriptionInfo().username + " CR:" + clientRegistered + " SR:" + serverRegistered + "]"; }
public String getId() {
Log.debug("getId called");
return this.jid.toBareJID();
}
public String getLegacyName() {
Log.debug("getLegacyName called");
return this.legacyname;
}
public String getLegacyPassword() {
Log.debug("getLegacyPassword called");
return this.legacypass;
}
@SuppressWarnings("unchecked")
public List<ForeignContact> getContacts() {
Log.debug("getContacts called");
return contacts;
}
public JID getSessionJID() {
Log.debug("getSessionJID called");
return this.jid;
}
public JID getJID() {
Log.debug("getJID called");
return this.jid;
}
public String getStatus(JID to) {
Log.debug("getStatus called");
for (ForeignContact c : contacts) {
if (c.getName().equals(to.getNode())) {
return c.getStatus().getValue();
}
}
return null;
}
public void addContact(JID jid) throws Exception {
public void addContact(JID jid) {
Log.debug("addContact called");
Integer newBuddyId = highestBuddyId + 1;
Integer groupId = -1;
......@@ -167,33 +115,19 @@ public class OSCARGatewaySession extends AbstractGatewaySession implements Endpo
new BuddyItem(jid.getNode(), newBuddyId, groupId).toSsiItem() }));
}
public void removeContact(JID jid) throws Exception {
public void removeContact(JID jid) {
Log.debug("removeContact called");
for (ForeignContact c : contacts) {
if (c.getName().equals(jid.getNode())) {
OSCARForeignContact oc = (OSCARForeignContact)c;
request(new DeleteItemsCmd(new SsiItem[] { oc.getSSIItem() }));
contacts.remove(contacts.indexOf(c));
for (BuddyItem i : buddies) {
if (i.getScreenname().equals(jid.getNode())) {
request(new DeleteItemsCmd(new SsiItem[] { i.toSsiItem() }));
buddies.remove(buddies.indexOf(i));
}
}
}
public void sendPacket(Packet packet) {
Log.debug("sendPacket called:"+packet.toString());
if (packet instanceof Message) {
Message m = (Message)packet;
request(new SendImIcbm(packet.getTo().getNode(), m.getBody()));
}
}
public ForeignContact getContact(JID to) throws UnknownForeignContactException {
Log.debug("getContact called");
for (ForeignContact c : contacts) {
if (c.getName().equals(to.getNode())) {
return c;
}
}
return null;
public void sendMessage(JID jid, String message) {
Log.debug("sendPacket called:"+jid.toString()+","+message);
request(new SendImIcbm(jid.getNode(), message));
}
void startBosConn(String server, int port, ByteBlock cookie) {
......@@ -272,7 +206,7 @@ public class OSCARGatewaySession extends AbstractGatewaySession implements Endpo
}
void gotBuddy(BuddyItem buddy) {
contacts.add(new OSCARForeignContact(buddy, this.gateway));
buddies.add(buddy);
if (buddy.getId() > highestBuddyId) {
highestBuddyId = buddy.getId();
}
......
/**
* $Revision$
* $Date$
*
* Copyright (C) 2006 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.gateway.protocols.oscar;
import org.jivesoftware.wildfire.gateway.BaseTransport;
import org.jivesoftware.wildfire.gateway.Registration;
import org.jivesoftware.wildfire.gateway.TransportSession;
/**
* OSCAR Transport Interface.
*
* This handles the bulk of the XMPP work via BaseTransport and provides
* some gateway specific interactions.
*
* @author Daniel Henninger
*/
public class OSCARTransport extends BaseTransport {
/**
* Handles creating an OSCAR session and triggering a login.
*
* @param registration Registration information to be used to log in.
*/
public TransportSession registrationLoggedIn(Registration registration) {
TransportSession session = new OSCARSession(registration, this);
session.logIn();
return session;
}
/**
* Handles logging out of a Yahoo session.
*
* @param session The session to be disconnected.
*/
public void registrationLoggedOut(TransportSession session) {
session.logOut();
}
}
......@@ -37,23 +37,23 @@ public class ServiceConnection extends BasicFlapConnection {
protected int serviceFamily;
public ServiceConnection(OSCARGatewaySession mainSession, ByteBlock cookie, int serviceFamily) {
public ServiceConnection(OSCARSession mainSession, ByteBlock cookie, int serviceFamily) {
super(mainSession, cookie);
this.serviceFamily = serviceFamily;
}
public ServiceConnection(String host, int port, OSCARGatewaySession mainSession, ByteBlock cookie, int serviceFamily) {
public ServiceConnection(String host, int port, OSCARSession mainSession, ByteBlock cookie, int serviceFamily) {
super(host, port, mainSession, cookie);
this.serviceFamily = serviceFamily;
}
public ServiceConnection(InetAddress ip, int port, OSCARGatewaySession mainSession, ByteBlock cookie, int serviceFamily) {
public ServiceConnection(InetAddress ip, int port, OSCARSession mainSession, ByteBlock cookie, int serviceFamily) {
super(ip, port, mainSession, cookie);
this.serviceFamily = serviceFamily;
}
protected void clientReady() {
session.serviceReady(this);
oscarSession.serviceReady(this);
super.clientReady();
}
......@@ -63,11 +63,11 @@ public class ServiceConnection extends BasicFlapConnection {
+ ": " + e.getReason());
if (e.getNewState() == ClientFlapConn.STATE_FAILED) {
session.serviceFailed(this);
oscarSession.serviceFailed(this);
} else if (e.getNewState() == ClientFlapConn.STATE_CONNECTED) {
session.serviceConnected(this);
oscarSession.serviceConnected(this);
} else if (e.getNewState() == ClientFlapConn.STATE_NOT_CONNECTED) {
session.serviceDied(this);
oscarSession.serviceDied(this);
}
}
......@@ -151,7 +151,7 @@ public class ServiceConnection extends BasicFlapConnection {
byte[] data = idc.getIconData().toByteArray();
Image icon = Toolkit.getDefaultToolkit().createImage(data);
// session.getUserInfo(sn).setIcon(icon);
// oscarSession.getUserInfo(sn).setIcon(icon);
}
}
......
/**
* $Revision$
* $Date$
*
* Copyright (C) 2006 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.gateway.protocols.yahoo;
import org.jivesoftware.util.Log;
import ymsg.network.event.SessionChatEvent;
import ymsg.network.event.SessionConferenceEvent;
import ymsg.network.event.SessionErrorEvent;
import ymsg.network.event.SessionEvent;
import ymsg.network.event.SessionExceptionEvent;
import ymsg.network.event.SessionFileTransferEvent;
import ymsg.network.event.SessionFriendEvent;
import ymsg.network.event.SessionListener;
import ymsg.network.event.SessionNewMailEvent;
import ymsg.network.event.SessionNotifyEvent;
/**
* NoopSessionListener provides a mechanism to quickly create a SessionListener
* for the ymsg9 library.
*
* @author Noah Campbell
*/
public class NoopSessionListener implements SessionListener {
/**
* @see ymsg.network.event.SessionListener#fileTransferReceived(ymsg.network.event.SessionFileTransferEvent)
*/
public void fileTransferReceived(SessionFileTransferEvent arg0) {
Log.info(arg0.toString());
}
/**
* @see ymsg.network.event.SessionListener#connectionClosed(ymsg.network.event.SessionEvent)
*/
public void connectionClosed(SessionEvent arg0) {
Log.info(arg0.toString());
}
/**
* @see ymsg.network.event.SessionListener#listReceived(ymsg.network.event.SessionEvent)
*/
public void listReceived(SessionEvent arg0) {
Log.info(arg0.toString());
}
/**
* @see ymsg.network.event.SessionListener#messageReceived(ymsg.network.event.SessionEvent)
*/
public void messageReceived(SessionEvent arg0) {
Log.debug(arg0.toString());
}
/**
* @see ymsg.network.event.SessionListener#buzzReceived(ymsg.network.event.SessionEvent)
*/
public void buzzReceived(SessionEvent arg0) {
Log.debug(arg0.toString());
}
/**
* @see ymsg.network.event.SessionListener#offlineMessageReceived(ymsg.network.event.SessionEvent)
*/
public void offlineMessageReceived(SessionEvent arg0) {
Log.debug(arg0.toString());
}
/**
* @see ymsg.network.event.SessionListener#errorPacketReceived(ymsg.network.event.SessionErrorEvent)
*/
public void errorPacketReceived(SessionErrorEvent arg0) {
Log.error(arg0.toString());
}
/**
* @see ymsg.network.event.SessionListener#inputExceptionThrown(ymsg.network.event.SessionExceptionEvent)
*/
public void inputExceptionThrown(SessionExceptionEvent arg0) {
arg0.getException().printStackTrace();
Log.error(arg0.toString());
}
/**
* @see ymsg.network.event.SessionListener#newMailReceived(ymsg.network.event.SessionNewMailEvent)
*/
public void newMailReceived(SessionNewMailEvent arg0) {
Log.debug(arg0.toString());
}
/**
* @see ymsg.network.event.SessionListener#notifyReceived(ymsg.network.event.SessionNotifyEvent)
*/
public void notifyReceived(SessionNotifyEvent arg0) {
Log.debug(arg0.toString());
}
/**
* @see ymsg.network.event.SessionListener#contactRequestReceived(ymsg.network.event.SessionEvent)
*/
public void contactRequestReceived(SessionEvent arg0) {
Log.debug(arg0.toString());
}
/**
* @see ymsg.network.event.SessionListener#contactRejectionReceived(ymsg.network.event.SessionEvent)
*/
public void contactRejectionReceived(SessionEvent arg0) {
Log.debug(arg0.toString());
}
/**
* @see ymsg.network.event.SessionListener#conferenceInviteReceived(ymsg.network.event.SessionConferenceEvent)
*/
public void conferenceInviteReceived(SessionConferenceEvent arg0) {
Log.debug(arg0.toString());
}
/**
* @see ymsg.network.event.SessionListener#conferenceInviteDeclinedReceived(ymsg.network.event.SessionConferenceEvent)
*/
public void conferenceInviteDeclinedReceived(SessionConferenceEvent arg0) {
Log.debug(arg0.toString());
}
/**
* @see ymsg.network.event.SessionListener#conferenceLogonReceived(ymsg.network.event.SessionConferenceEvent)
*/
public void conferenceLogonReceived(SessionConferenceEvent arg0) {
Log.debug(arg0.toString());
}
/**
* @see ymsg.network.event.SessionListener#conferenceLogoffReceived(ymsg.network.event.SessionConferenceEvent)
*/
public void conferenceLogoffReceived(SessionConferenceEvent arg0) {
Log.debug(arg0.toString());
}
/**
* @see ymsg.network.event.SessionListener#conferenceMessageReceived(ymsg.network.event.SessionConferenceEvent)
*/
public void conferenceMessageReceived(SessionConferenceEvent arg0) {
Log.debug(arg0.toString());
}
/**
* @see ymsg.network.event.SessionListener#friendsUpdateReceived(ymsg.network.event.SessionFriendEvent)
*/
public void friendsUpdateReceived(SessionFriendEvent arg0) {
Log.debug(arg0.toString());
}
/**
* @see ymsg.network.event.SessionListener#friendAddedReceived(ymsg.network.event.SessionFriendEvent)
*/
public void friendAddedReceived(SessionFriendEvent arg0) {
Log.debug(arg0.toString());
}
/**
* @see ymsg.network.event.SessionListener#friendRemovedReceived(ymsg.network.event.SessionFriendEvent)
*/
public void friendRemovedReceived(SessionFriendEvent arg0) {
Log.debug(arg0.toString());
}
/**
* @see ymsg.network.event.SessionListener#chatLogonReceived(ymsg.network.event.SessionChatEvent)
*/
public void chatLogonReceived(SessionChatEvent arg0) {
Log.debug(arg0.toString());
}
/**
* @see ymsg.network.event.SessionListener#chatLogoffReceived(ymsg.network.event.SessionChatEvent)
*/
public void chatLogoffReceived(SessionChatEvent arg0) {
Log.debug(arg0.toString());
}
/**
* @see ymsg.network.event.SessionListener#chatMessageReceived(ymsg.network.event.SessionChatEvent)
*/
public void chatMessageReceived(SessionChatEvent arg0) {
Log.debug(arg0.toString());
}
/**
* @see ymsg.network.event.SessionListener#chatUserUpdateReceived(ymsg.network.event.SessionChatEvent)
*/
public void chatUserUpdateReceived(SessionChatEvent arg0) {
Log.debug(arg0.toString());
}
/**
* @see ymsg.network.event.SessionListener#chatConnectionClosed(ymsg.network.event.SessionEvent)
*/
public void chatConnectionClosed(SessionEvent arg0) {
Log.debug(arg0.toString());
}
}
/**
* $Revision$
* $Date$
*
* Copyright (C) 2006 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.gateway.protocols.yahoo;
import java.util.PropertyResourceBundle;
import java.util.ResourceBundle;
import org.jivesoftware.util.Log;
import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.wildfire.gateway.Gateway;
import org.jivesoftware.wildfire.gateway.roster.AbstractForeignContact;
import org.jivesoftware.wildfire.gateway.roster.Status;
import ymsg.network.StatusConstants;
import ymsg.network.YahooUser;
/**
* @author Noah Campbell
*/
public class YahooForeignContact extends AbstractForeignContact {
/** The yahoo user. */
final private YahooUser user;
/**
* Construct a new <code>YahooForeignContact</code>.
* @param user A YahooUser
* @param gateway
* @see YahooUser
*/
public YahooForeignContact(YahooUser user, Gateway gateway) {
super(user.getId(), new Status(), gateway);
this.user = user;
}
/**
* @see org.jivesoftware.wildfire.gateway.roster.ForeignContact#getStatus()
*/
public Status getStatus() {
getStatusMessage(user, this.status);
return super.status;
}
/**
* @param user2
* @return
*/
private Status getStatusMessage(YahooUser user2, Status status) {
long id = user2.getStatus();
status.setOnline(true);
if (StatusConstants.STATUS_AVAILABLE == id) {
status.updateValue(resource.getString("STATUS_AVAILABLE"));
}
else if (StatusConstants.STATUS_BRB == id) {
status.updateValue(resource.getString("STATUS_BRB"));
}
else if (StatusConstants.STATUS_BUSY == id) {
status.updateValue(resource.getString("STATUS_BUSY"));
}
else if (StatusConstants.STATUS_NOTATHOME == id) {
status.updateValue(resource.getString("STATUS_NOTATHOME"));
}
else if (StatusConstants.STATUS_NOTATDESK == id) {
status.updateValue(resource.getString("STATUS_NOTATDESK"));
}
else if (StatusConstants.STATUS_NOTINOFFICE == id) {
status.updateValue(resource.getString("STATUS_NOTINOFFICE"));
}
else if (StatusConstants.STATUS_ONPHONE == id) {
status.updateValue(resource.getString("STATUS_ONPHONE"));
}
else if (StatusConstants.STATUS_ONVACATION == id) {
status.updateValue(resource.getString("STATUS_ONVACATION"));
}
else if (StatusConstants.STATUS_OUTTOLUNCH == id) {
status.updateValue(resource.getString("STATUS_OUTTOLUNCH"));
}
else if (StatusConstants.STATUS_STEPPEDOUT == id) {
status.updateValue(resource.getString("STATUS_STEPPEDOUT"));
}
else if (StatusConstants.STATUS_INVISIBLE == id) {
status.updateValue(resource.getString("STATUS_INVISIBLE"));
}
else if (StatusConstants.STATUS_BAD == id) {
status.updateValue(resource.getString("STATUS_BAD")); // Bad login?
}
else if (StatusConstants.STATUS_LOCKED == id) {
status.updateValue(resource.getString("STATUS_LOCKED")); // You've been naughty
}
else if (StatusConstants.STATUS_CUSTOM == id) {
status.updateValue(user.getCustomStatusMessage());
}
else if (StatusConstants.STATUS_IDLE == id) {
status.updateValue(resource.getString("STATUS_IDLE"));
}
else if (StatusConstants.STATUS_OFFLINE == id) {
status.setOnline(false);
}
else if (StatusConstants.STATUS_TYPING == id) {
status.updateValue(resource.getString("STATUS_TYPING"));
}
else {
Log.warn(LocaleUtils.getLocalizedString("yahooforeigncontact.unabletolocatestatus", "gateway"));
status.updateValue("????");
}
return status;
}
/** The resource. */
private static ResourceBundle resource = PropertyResourceBundle.getBundle("yahoostatus");
/**
* @see org.jivesoftware.wildfire.gateway.roster.ForeignContact#getName()
*/
public String getName() {
return user.getId();
}
}
/**
* $Revision$
* $Date$
*
* Copyright (C) 2006 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.gateway.protocols.yahoo;
import org.jivesoftware.wildfire.gateway.BaseGateway;
import org.jivesoftware.wildfire.gateway.GatewaySession;
import org.jivesoftware.wildfire.gateway.SubscriptionInfo;
import org.xmpp.component.ComponentException;
import org.xmpp.packet.JID;
import org.xmpp.packet.Message;
import org.xmpp.packet.Packet;
/**
* @author Noah Campbell
*/
public class YahooGateway extends BaseGateway {
/** The YAHOO. */
private static String YAHOO = "yahoo";
/**
* @see org.jivesoftware.wildfire.gateway.BaseGateway#getName()
*/
@Override
public String getName() {
return YAHOO;
}
/**
* @see org.jivesoftware.wildfire.gateway.BaseGateway#setName(String)
*/
@Override
public void setName(String newname) {
YAHOO = newname;
}
/**
* @see org.jivesoftware.wildfire.gateway.BaseGateway#getDescription()
*/
@Override
public String getDescription() {
return "Yahoo! Gateway (ymsg9)";
}
/**
* @see org.jivesoftware.wildfire.gateway.Endpoint#sendPacket(Packet)
*/
@SuppressWarnings("unused")
public void sendPacket(@SuppressWarnings("unused") Packet packet) throws ComponentException {
// do nothing.
}
/**
* @param jid
* @param string
* @throws Exception
*/
public void sendMessage(JID jid, String string) throws Exception {
Message m = new Message();
m.setTo(jid);
m.setBody(string);
this.sendPacket(m);
}
/**
* @see org.jivesoftware.wildfire.gateway.BaseGateway#getType()
*/
@Override
public String getType() {
return "yahoo";
}
/**
* @see org.jivesoftware.wildfire.gateway.BaseGateway#getVersion()
*/
@Override
public String getVersion() {
return "v1.0";
}
/**
* @see org.jivesoftware.wildfire.gateway.BaseGateway#getSessionInstance(org.jivesoftware.wildfire.gateway.SubscriptionInfo)
*/
@Override
protected GatewaySession getSessionInstance(SubscriptionInfo info) {
return new YahooGatewaySession(info, this);
}
}
/**
* $Revision$
* $Date$
*
* Copyright (C) 2006 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.gateway.protocols.yahoo;
import java.io.IOException;
import org.jivesoftware.util.Log;
import org.jivesoftware.wildfire.gateway.Registration;
import org.jivesoftware.wildfire.gateway.TransportSession;
import org.xmpp.packet.JID;
import ymsg.network.LoginRefusedException;
import ymsg.network.Session;
/**
* Represents a Yahoo session.
*
* This is the interface with which the base transport functionality will
* communicate with Yahoo.
*
* @author Daniel Henninger
* Heavily inspired by Noah Campbell's work.
*/
public class YahooSession extends TransportSession {
/**
* Create a Yahoo Session instance.
*
* @param registration Registration informationed used for logging in.
*/
public YahooSession(Registration registration, YahooTransport transport) {
super(registration, transport);
yahooSession = new Session();
yahooSession.addSessionListener(new YahooSessionListener(this));
}
/**
* Are we logged in?
*/
private Boolean loggedIn = false;
/**
* Are we trying to log in right now?
*/
private Boolean loggingIn = false;
/**
* How many attempts have been made so far?
*/
private Integer loginAttempts = 0;
/**
* Yahoo session
*/
private final Session yahooSession;
/**
* Log in to Yahoo.
*/
public void logIn() {
if (!isLoggedIn() && !loggingIn && loginAttempts <= 3) {
loggingIn = true;
new Thread() {
public void run() {
try {
loginAttempts++;
yahooSession.login(registration.getUsername(), registration.getPassword());
loggedIn = true;
}
catch (LoginRefusedException e) {
yahooSession.reset();
Log.warn("Yahoo login failed for " + registration.getJID());
}
catch (IOException e) {
Log.error("Yahoo login caused IO exception: " + e.toString());
}
loggingIn = false;
}
}.run();
}
}
/**
* Log out of Yahoo.
*/
public void logOut() {
try {
yahooSession.logout();
}
catch (IOException e) {
Log.debug("Failed to log out from Yahoo.");
}
yahooSession.reset();
loggedIn = false;
loggingIn = false;
loginAttempts = 0;
}
/**
* Have we successfully logged in to Yahoo?
*/
public Boolean isLoggedIn() {
return loggedIn;
}
/**
* Adds a contact to the user's Yahoo contact list.
*
* @param jid JID of contact to be added.
*/
public void addContact(JID jid) {
// TODO: check jabber group and use it
try {
yahooSession.addFriend(jid.getNode(), "Yahoo Transport");
}
catch (IOException e) {
Log.error("Failed to send message to yahoo user.");
}
}
/**
* Removes a contact from the user's Yahoo contact list.
*
* @param jid JID of contact to be added.
*/
public void removeContact(JID jid) {
// TODO: check jabber group and use it
try {
yahooSession.removeFriend(jid.getNode(), "Yahoo Transport");
}
catch (IOException e) {
Log.error("Failed to send message to yahoo user.");
}
}
/**
* Sends a message from the jabber user to a Yahoo contact.
*
* @param jid JID of contact to send message to.
* @param message Message to send to yahoo contact.
*/
public void sendMessage(JID jid, String message) {
try {
yahooSession.sendMessage(jid.getNode(), message);
}
catch (IOException e) {
Log.error("Failed to send message to yahoo user.");
}
}
}
/**
* $Revision$
* $Date$
*
* Copyright (C) 2006 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.gateway.protocols.yahoo;
import org.jivesoftware.wildfire.gateway.BaseTransport;
import org.jivesoftware.wildfire.gateway.Registration;
import org.jivesoftware.wildfire.gateway.TransportSession;
/**
* Yahoo Transport Interface.
*
* This handles the bulk of the XMPP work via BaseTransport and provides
* some gateway specific interactions.
*
* @author Daniel Henninger
*/
public class YahooTransport extends BaseTransport {
/**
* Handles creating a Yahoo session and triggering a login.
*
* @param registration Registration information to be used to log in.
*/
public TransportSession registrationLoggedIn(Registration registration) {
TransportSession session = new YahooSession(registration, this);
session.logIn();
return session;
}
/**
* Handles logging out of a Yahoo session.
*
* @param session The session to be disconnected.
*/
public void registrationLoggedOut(TransportSession session) {
session.logOut();
}
}
/**
* $Revision$
* $Date$
*
* Copyright (C) 2006 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.gateway.roster;
import java.io.Serializable;
import java.io.IOException;
import java.text.MessageFormat;
import java.util.HashSet;
import java.util.Set;
import org.jivesoftware.wildfire.gateway.Gateway;
import org.jivesoftware.wildfire.gateway.GatewaySession;
import org.xmpp.packet.JID;
/**
* All maintanence information pretaining to a gateway user.
*
* @author Noah Campbell
*/
public abstract class AbstractForeignContact implements ForeignContact, Serializable {
private static final long serialVersionUID = 1L;
/**
* The id for this contact. This maps directly to the legacy userid.
*/
public final String id;
/**
* The status of this contact.
*
* @see Status
*/
public final Status status;
/**
* The jid associated with this foreign contact.
*
* @see JID
*/
private transient JID jid;
/**
* The gatewayDomain.
*/
private final String gatewayDomain;
/**
* The gatewayName.
*/
private final String gatewayName;
/**
* The associatedSessions that are currently active for this <code>ForeignContact</code>.
*
* @see java.util.Set
*/
private transient Set<GatewaySession> associatedSessions = new HashSet<GatewaySession>();
/**
* The format for a JID
*
* @see java.text.MessageFormat
*/
private static final MessageFormat mf = new MessageFormat("{0}@{1}.{2}");
/**
* Create a ForeignContact relating to the gateway it originated from.
*
* @param id the foreign contact id.
* @param status the current status of the contact.
* @param gateway the gateway the foreign contact is associated with.
*/
public AbstractForeignContact(String id, Status status, Gateway gateway) {
this.id = id;
this.status = status;
this.gatewayDomain = gateway.getDomain();
this.gatewayName = gateway.getName();
}
/**
* @see org.jivesoftware.wildfire.gateway.roster.ForeignContact#getJid()
*/
public JID getJid() {
if (jid == null) {
jid = new JID(mf.format(new Object[]{id, gatewayName, gatewayDomain}));
}
return jid;
}
/**
* @param in
* @throws IOException
* @throws ClassNotFoundException
*/
@SuppressWarnings("unused")
private void readObject(@SuppressWarnings("unused") java.io.ObjectInputStream in)
throws IOException, ClassNotFoundException {
associatedSessions = new HashSet<GatewaySession>();
getJid();
}
/**
* @see org.jivesoftware.wildfire.gateway.roster.ForeignContact#addSession(org.jivesoftware.wildfire.gateway.GatewaySession)
*/
public void addSession(GatewaySession session) {
associatedSessions.add(session);
}
/**
* @see org.jivesoftware.wildfire.gateway.roster.ForeignContact#removeSession(org.jivesoftware.wildfire.gateway.GatewaySession)
*/
public void removeSession(GatewaySession session) {
associatedSessions.remove(session);
}
/**
* @see org.jivesoftware.wildfire.gateway.roster.ForeignContact#isConnected()
*/
public boolean isConnected() {
boolean connected = true;
for (GatewaySession session : associatedSessions) {
if (!session.isConnected()) {
connected = false;
break;
}
}
return connected;
}
/**
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
if (obj instanceof AbstractForeignContact) {
AbstractForeignContact fc = (AbstractForeignContact)obj;
return fc.id.equalsIgnoreCase(this.id);
}
else {
return super.equals(obj);
}
}
/**
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
return this.getJid().toBareJID().hashCode();
}
/**
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "Foreign Contact: " + this.getJid() + "[Gateway: " + this.gatewayName + ", Connected: " + isConnected() + "]";
}
}
/**
* $Revision$
* $Date$
*
* Copyright (C) 2006 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.gateway.roster;
import java.io.Serializable;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.xmpp.packet.JID;
/**
*
* Manage contacts for a paticular JID.
*
* @author Noah Campbell
*/
public class ContactManager implements Serializable {
private static final long serialVersionUID = 1L;
/**
* Construct a new <code>ContactManager</code>
*/
ContactManager() { }
/**
* The fcs
*
* @see java.util.Set
*/
private final Set<AbstractForeignContact> fcs = new HashSet<AbstractForeignContact>();
/**
* Maintain a mapping of JIDs to their contact list.
*/
private final Map<NormalizedJID, Roster> contactLists =
new HashMap<NormalizedJID, Roster>();
/**
* Return a roster for a JID.
*
* @param name The <code>JID</code> to lookup.
* @return roster The roster for the <code>JID</code>.
*/
public synchronized Roster getRoster(JID name) {
Roster r = contactLists.get(NormalizedJID.wrap(name));
if (r == null) {
r = new Roster();
contactLists.put(NormalizedJID.wrap(name), r);
}
return r;
}
/**
* @return foreignContacts A {@code java.util.Set} of {@code ForeignContact}s.
*/
public Set<AbstractForeignContact> getAllForeignContacts() {
return this.fcs;
}
/**
* Remove the <code>JID</code> from the contact list.
*
* @param jid
*/
void remove(NormalizedJID jid) {
contactLists.remove(jid);
}
}
/**
* $Revision$
* $Date$
*
* Copyright (C) 2006 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.gateway.roster;
import org.jivesoftware.wildfire.gateway.GatewaySession;
import org.xmpp.packet.JID;
/**
* @author Noah Campbell
*/
public interface ForeignContact {
/**
* Get the JID, constructing it if necessary.
*
* @return jid returns the jid.
*/
public JID getJid();
/**
* Add a session to the associated sessions for this foreign contact.
*
* @param session
*/
public void addSession(GatewaySession session);
/**
* Remove a <code>GatewaySession</code> from the foreign contact.
*
* @param session
*/
public void removeSession(GatewaySession session);
/**
* Returns true if at least one associated session is connected.
*
* @return connected
*/
public boolean isConnected();
/**
* Return the translated status for the contact.
*
* @return Status
*/
public Status getStatus();
/**
* Return the name of the contact.
*
* @return name The name of the contact.
*/
public String getName();
}
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