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

[GATE-74] Playing around with an XMPP/Google Talk transport. Not remotely finished/functional yet.

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@7930 b35dd754-fafc-0310-a699-88a17e54d16e
parent 55bf232a
...@@ -12,6 +12,8 @@ joscar-common.jar | svn-20070204 ...@@ -12,6 +12,8 @@ joscar-common.jar | svn-20070204
joscar-protocol.jar | svn-20070204 (patched [#2]) joscar-protocol.jar | svn-20070204 (patched [#2])
picocontainer.jar | 1.2.0 picocontainer.jar | 1.2.0
saaj.jar | 1.3 saaj.jar | 1.3
smack.jar | 3.0.0
smackx.jar | 3.0.0
xercesImpl.jar | 2.6.2 xercesImpl.jar | 2.6.2
xml-apis.jar | 2.6.2 xml-apis.jar | 2.6.2
wsdl4j | 1.5.1 wsdl4j | 1.5.1
......
...@@ -48,6 +48,11 @@ public enum TransportType { ...@@ -48,6 +48,11 @@ public enum TransportType {
*/ */
xmpp, xmpp,
/**
* A gateway to Google Talk ('special' XMPP server)
*/
gtalk,
/** /**
* A gateway to IRC servers. * A gateway to IRC servers.
*/ */
......
/**
* $Revision$
* $Date$
*
* Copyright (C) 2006-2007 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.openfire.gateway.protocols.xmpp;
import org.jivesoftware.openfire.gateway.*;
import org.jivesoftware.openfire.roster.RosterItem;
import org.jivesoftware.util.Log;
import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.XMPPException;
import org.xmpp.packet.JID;
import org.xmpp.packet.Presence;
/**
* Represents an XMPP session.
*
* This is the interface with which the base transport functionality will
* communicate with an XMPP server.
*
* @author Daniel Henninger
*/
public class XMPPSession extends TransportSession {
/**
* Create an XMPP Session instance.
*
* @param registration Registration informationed used for logging in.
* @param jid JID associated with this session.
* @param transport Transport instance associated with this session.
* @param priority Priority of this session.
*/
public XMPPSession(Registration registration, JID jid, XMPPTransport transport, Integer priority) {
super(registration, jid, transport, priority);
Log.debug("Creating "+getTransport().getType()+" session for " + registration.getUsername());
config = new ConnectionConfiguration(
JiveGlobals.getProperty("plugin.gateway."+getTransport().getType()+".connecthost",
(getTransport().getType().equals(TransportType.gtalk) ? "talk.google.com" : "jabber.org")),
JiveGlobals.getIntProperty("plugin.gateway."+getTransport().getType()+".connectport", 5222));
}
/*
* XMPP connection
*/
private XMPPConnection conn = null;
/*
* XMPP connection configuration
*/
private ConnectionConfiguration config = null;
public void logIn(PresenceType presenceType, String verboseStatus) {
if (!this.isLoggedIn()) {
try {
setLoginStatus(TransportLoginStatus.LOGGING_IN);
conn = new XMPPConnection(config);
conn.connect();
conn.login(this.getRegistration().getUsername(), this.getRegistration().getPassword(), "IMGateway");
}
catch (XMPPException e) {
Log.error(getTransport().getType()+" user is not able to log in: "+this.getRegistration().getUsername(), e);
}
}
}
/**
* Log out of MSN.
*/
public void logOut() {
if (this.isLoggedIn()) {
setLoginStatus(TransportLoginStatus.LOGGING_OUT);
conn.disconnect();
}
Presence p = new Presence(Presence.Type.unavailable);
p.setTo(getJID());
p.setFrom(getTransport().getJID());
getTransport().sendPacket(p);
setLoginStatus(TransportLoginStatus.LOGGED_OUT);
}
public void updateStatus(PresenceType presenceType, String verboseStatus) {
}
public void addContact(RosterItem item) {
//To change body of implemented methods use File | Settings | File Templates.
}
public void removeContact(RosterItem item) {
//To change body of implemented methods use File | Settings | File Templates.
}
public void updateContact(RosterItem item) {
//To change body of implemented methods use File | Settings | File Templates.
}
public void sendMessage(JID jid, String message) {
//To change body of implemented methods use File | Settings | File Templates.
}
public void sendServerMessage(String message) {
//Don't care
}
public void sendChatState(JID jid, ChatStateType chatState) {
//To change body of implemented methods use File | Settings | File Templates.
}
public void retrieveContactStatus(JID jid) {
//To change body of implemented methods use File | Settings | File Templates.
}
public void resendContactStatuses(JID jid) {
//To change body of implemented methods use File | Settings | File Templates.
}
}
/**
* $Revision$
* $Date$
*
* Copyright (C) 2006-2007 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.openfire.gateway.protocols.xmpp;
import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.openfire.gateway.*;
import org.xmpp.packet.JID;
/**
* XMPP Transport Interface.
*
* This handles the bulk of the XMPP work via BaseTransport and provides
* some gateway specific interactions.
*
* @author Daniel Henninger
*/
public class XMPPTransport extends BaseTransport {
/**
* @see org.jivesoftware.openfire.gateway.BaseTransport#getTerminologyUsername()
*/
public String getTerminologyUsername() {
return LocaleUtils.getLocalizedString("gateway."+getType().toString()+".username", "gateway");
}
/**
* @see org.jivesoftware.openfire.gateway.BaseTransport#getTerminologyPassword()
*/
public String getTerminologyPassword() {
return LocaleUtils.getLocalizedString("gateway.xmpp.password", "gateway");
}
/**
* @see org.jivesoftware.openfire.gateway.BaseTransport#getTerminologyNickname()
*/
public String getTerminologyNickname() {
return null;
}
/**
* @see org.jivesoftware.openfire.gateway.BaseTransport#getTerminologyRegistration()
*/
public String getTerminologyRegistration() {
return LocaleUtils.getLocalizedString("gateway."+getType().toString()+".registration", "gateway");
}
/**
* @see org.jivesoftware.openfire.gateway.BaseTransport#isPasswordRequired()
*/
public Boolean isPasswordRequired() { return true; }
/**
* @see org.jivesoftware.openfire.gateway.BaseTransport#isNicknameRequired()
*/
public Boolean isNicknameRequired() { return false; }
/**
* @see org.jivesoftware.openfire.gateway.BaseTransport#isUsernameValid(String)
*/
public Boolean isUsernameValid(String username) {
if (getType() == TransportType.icq) {
return username.matches("\\d+");
}
else {
return username.matches("\\w+") || username.matches("\\w+@[\\w\\.]+");
}
}
/**
* Handles creating an OSCAR session and triggering a login.
*
* @param registration Registration information to be used to log in.
* @param jid JID that is logged into the transport.
* @param presenceType Type of presence.
* @param verboseStatus Longer status description.
*/
public TransportSession registrationLoggedIn(Registration registration, JID jid, PresenceType presenceType, String verboseStatus, Integer priority) {
TransportSession session = new XMPPSession(registration, jid, this, priority);
this.getSessionManager().startThread(session);
((XMPPSession)session).logIn(presenceType, verboseStatus);
return session;
}
/**
* Handles logging out of a Yahoo session.
*
* @param session The session to be disconnected.
*/
public void registrationLoggedOut(TransportSession session) {
((XMPPSession)session).logOut();
session.sessionDone();
// Just in case.
session.setLoginStatus(TransportLoginStatus.LOGGED_OUT);
}
}
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