Commit 67f25bbc authored by Daniel Henninger's avatar Daniel Henninger Committed by dhenninger

[GATE-31] Ignore messages to gateway itself.

[GATE-14] Can log in to irc.freenode.net at the moment after registering and talk back and forth.
Some misc tweaks to MSN support.  Still getting IOException that I haven't tracked down yet.

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk/src/plugins/gateway@5315 b35dd754-fafc-0310-a699-88a17e54d16e
parent 537252ef
......@@ -157,13 +157,19 @@ public abstract class BaseTransport implements Component, RosterEventListener {
JID from = packet.getFrom();
JID to = packet.getTo();
try {
TransportSession session = sessionManager.getSession(from);
session.sendMessage(to, packet.getBody());
if (to.getNode() == null) {
// Message to gateway itself. Throw away for now.
// TODO: Repsond with a message at some point?
}
catch (NotFoundException e) {
// TODO: Should return an error packet here
Log.debug("Unable to find session.");
else {
try {
TransportSession session = sessionManager.getSession(from);
session.sendMessage(to, packet.getBody());
}
catch (NotFoundException e) {
// TODO: Should return an error packet here
Log.debug("Unable to find session.");
}
}
return reply;
......@@ -520,7 +526,7 @@ public abstract class BaseTransport implements Component, RosterEventListener {
else if (var.equals("password")) {
password = field.getValues().get(0);
}
else if (var.equals("nickname")) {
else if (var.equals("nick")) {
nickname = field.getValues().get(0);
}
......@@ -533,7 +539,7 @@ public abstract class BaseTransport implements Component, RosterEventListener {
if (packet.getType() == IQ.Type.set) {
Element userEl = packet.getChildElement().element("username");
Element passEl = packet.getChildElement().element("password");
Element nickEl = packet.getChildElement().element("nickname");
Element nickEl = packet.getChildElement().element("nick");
if (userEl != null) {
username = userEl.getTextTrim();
......@@ -546,6 +552,10 @@ public abstract class BaseTransport implements Component, RosterEventListener {
if (nickEl != null) {
nickname = nickEl.getTextTrim();
}
username = (username == null || username.equals("")) ? null : username;
password = (password == null || password.equals("")) ? null : password;
nickname = (nickname == null || nickname.equals("")) ? null : nickname;
if (username == null || (isPasswordRequired() && password == null) || (isNicknameRequired() && nickname == null)) {
// Found nothing from stanza, lets yell.
......@@ -613,14 +623,14 @@ public abstract class BaseTransport implements Component, RosterEventListener {
response.addElement("username").addText(registration.getUsername());
response.addElement("password").addText(registration.getPassword());
if (nicknameTerm != null) {
response.addElement("nickname").addText(registration.getNickname());
response.addElement("nick").addText(registration.getNickname());
}
}
else {
response.addElement("username");
response.addElement("password");
if (nicknameTerm != null) {
response.addElement("nickname");
response.addElement("nick");
}
}
......
......@@ -15,6 +15,7 @@ import org.schwering.irc.lib.IRCUser;
import org.schwering.irc.lib.IRCModeParser;
import org.xmpp.packet.Message;
import org.xmpp.packet.Presence;
import org.jivesoftware.util.Log;
import java.util.Date;
......@@ -50,40 +51,65 @@ public class IRCListener implements IRCEventListener {
}
public void onDisconnected() {
getSession().logOut();
Presence p = new Presence(Presence.Type.unavailable);
p.setTo(getSession().getJID());
p.setFrom(getSession().getTransport().getJID());
getSession().getTransport().sendPacket(p);
getSession().getConnection().close();
}
public void onError(String string) {
Message m = new Message();
m.setType(Message.Type.error);
m.setFrom(getSession().getTransport().getJID());
m.setTo(getSession().getJID());
m.setBody("IRC error received: "+string);
getSession().getTransport().sendPacket(m);
}
public void onError(int i, String string) {
Message m = new Message();
m.setType(Message.Type.error);
m.setFrom(getSession().getTransport().getJID());
m.setTo(getSession().getJID());
m.setBody("IRC error received: (code "+i+") "+string);
getSession().getTransport().sendPacket(m);
}
public void onInvite(String string, IRCUser ircUser, String string1) {
Log.debug("IRC invite: "+string+", "+ircUser+", "+string1);
}
public void onJoin(String string, IRCUser ircUser) {
Log.debug("IRC join: "+string+", "+ircUser);
}
public void onKick(String string, IRCUser ircUser, String string1, String string2) {
Log.debug("IRC kick: "+string+", "+ircUser+", "+string1+", "+string2);
}
public void onMode(String string, IRCUser ircUser, IRCModeParser ircModeParser) {
Log.debug("IRC mode: "+string+", "+ircUser+", "+ircModeParser);
}
public void onMode(IRCUser ircUser, String string, String string1) {
Log.debug("IRC mode: "+ircUser+", "+string+", "+string1);
}
public void onNick(IRCUser ircUser, String string) {
Log.debug("IRC nick: "+ircUser+", "+string);
}
public void onNotice(String string, IRCUser ircUser, String string1) {
Log.debug("IRC notice: "+string+", "+ircUser+", "+string1);
}
public void onPart(String string, IRCUser ircUser, String string1) {
Log.debug("IRC part: "+string+", "+ircUser+", "+string1);
}
public void onPing(String string) {
// Nothing to do, handled automatically.
}
public void onPrivmsg(String chan, IRCUser ircUser, String msg) {
......@@ -99,16 +125,20 @@ public class IRCListener implements IRCEventListener {
Presence p = new Presence(Presence.Type.unavailable);
p.setTo(getSession().getJID());
p.setFrom(getSession().getTransport().getJID());
getSession().getTransport().sendPacket(p);
getSession().getTransport().sendPacket(p);
getSession().getConnection().close();
}
public void onReply(int i, String string, String string1) {
Log.debug("IRC reply: "+i+", "+string+", "+string1);
}
public void onTopic(String string, IRCUser ircUser, String string1) {
Log.debug("IRC topic: "+string+", "+ircUser+", "+string1);
}
public void unknown(String string, String string1, String string2, String string3) {
Log.debug("Unknown IRC message: "+string+", "+string1+", "+string2+", "+string3);
}
}
......@@ -40,7 +40,15 @@ public class IRCSession extends TransportSession {
*/
public IRCSession(Registration registration, JID jid, IRCTransport transport, Integer priority) {
super(registration, jid, transport, priority);
conn = new IRCConnection("irc.freenode.net", new int[] { 6667, 7000 }, registration.getPassword(), registration.getNickname(), registration.getUsername(), "Wildfire User");
String server = "irc.freenode.net";
int[] ports = new int[] { 7000, 6667 };
String username = registration.getUsername();
String password = registration.getPassword();
password = (password == null || password.equals("")) ? null : password;
String nickname = registration.getNickname();
conn = new IRCConnection(server, ports, password, nickname, username, "Wildfire User");
conn.setPong(true);
conn.setDaemon(false);
conn.setColors(false);
......@@ -50,7 +58,7 @@ public class IRCSession extends TransportSession {
/**
* IRC connection.
*/
IRCConnection conn;
public IRCConnection conn;
/**
* Logs the session into IRC.
......@@ -59,13 +67,11 @@ public class IRCSession extends TransportSession {
* @param verboseStatus Initial full status information.
*/
public void logIn(PresenceType presenceType, String verboseStatus) {
if (!isLoggedIn()) {
try {
conn.connect();
}
catch (IOException e) {
Log.error("IO error while connecting to IRC: "+e.toString());
}
try {
conn.connect();
}
catch (IOException e) {
Log.error("IO error while connecting to IRC: "+e.toString());
}
}
......@@ -73,15 +79,27 @@ public class IRCSession extends TransportSession {
* Logs the session out of IRC.
*/
public void logOut() {
if (isLoggedIn()) {
conn.close();
}
conn.doQuit();
}
/**
* Returns the IRC connection associated with this session.
*/
public IRCConnection getConnection() {
return conn;
}
/**
* @see org.jivesoftware.wildfire.gateway.TransportSession#updateStatus(org.jivesoftware.wildfire.gateway.PresenceType, String)
*/
public void updateStatus(PresenceType presenceType, String verboseStatus) {
String awayMsg = ((IRCTransport)getTransport()).convertJabStatusToIRC(presenceType, verboseStatus);
if (awayMsg == null) {
conn.doAway();
}
else {
conn.doAway(awayMsg);
}
}
/**
......@@ -95,18 +113,21 @@ public class IRCSession extends TransportSession {
* @see org.jivesoftware.wildfire.gateway.TransportSession#addContact(org.jivesoftware.wildfire.roster.RosterItem)
*/
public void addContact(RosterItem item) {
// TODO: Handle this
}
/**
* @see org.jivesoftware.wildfire.gateway.TransportSession#removeContact(org.jivesoftware.wildfire.roster.RosterItem)
*/
public void removeContact(RosterItem item) {
// TODO: Handle this
}
/**
* @see org.jivesoftware.wildfire.gateway.TransportSession#updateContact(org.jivesoftware.wildfire.roster.RosterItem)
*/
public void updateContact(RosterItem item) {
// TODO: Handle this
}
/**
......@@ -120,12 +141,14 @@ public class IRCSession extends TransportSession {
* @see org.jivesoftware.wildfire.gateway.TransportSession#retrieveContactStatus(org.xmpp.packet.JID)
*/
public void retrieveContactStatus(JID jid) {
// TODO: Handle this
}
/**
* @see org.jivesoftware.wildfire.gateway.TransportSession#resendContactStatuses(org.xmpp.packet.JID)
*/
public void resendContactStatuses(JID jid) {
// TODO: Handle this
}
}
......@@ -64,7 +64,7 @@ public class IRCTransport extends BaseTransport {
/**
* @see org.jivesoftware.wildfire.gateway.BaseTransport#isNicknameRequired()
*/
public Boolean isNicknameRequired() { return true; }
public Boolean isNicknameRequired() { return true; }
/**
* Handles creating a IRC session and triggering a login.
......@@ -94,4 +94,35 @@ public class IRCTransport extends BaseTransport {
// session.sessionDone();
}
/**
* Converts a jabber status to an IRC away message (or not).
*
* @param jabStatus Jabber presence type.
* @param verboseStatus Verbose status information.
*/
public String convertJabStatusToIRC(PresenceType jabStatus, String verboseStatus) {
if (jabStatus == PresenceType.available) {
return null;
}
else if (jabStatus == PresenceType.away) {
return verboseStatus.equals("") ? "Away" : "Away: "+verboseStatus;
}
else if (jabStatus == PresenceType.xa) {
return verboseStatus.equals("") ? "Extended Away" : "Extended Away: "+verboseStatus;
}
else if (jabStatus == PresenceType.dnd) {
return verboseStatus.equals("") ? "Do Not Disturb" : "Do Not Disturb: "+verboseStatus;
}
else if (jabStatus == PresenceType.chat) {
return null;
}
else if (jabStatus == PresenceType.unavailable) {
// This should never show up.
return null;
}
else {
return null;
}
}
}
......@@ -149,7 +149,7 @@ public class MSNListener extends MsnAdapter {
* Catches MSN exceptions.
*/
public void exceptionCaught(MsnMessenger messenger, Throwable throwable) {
if (throwable.getClass().getName().equals("IncorrectPasswordException")) {
if (throwable.getClass().getName().equals("net.sf.jml.exception.IncorrectPasswordException")) {
Message m = new Message();
m.setType(Message.Type.error);
m.setTo(msnSession.getJIDWithHighestPriority());
......@@ -158,7 +158,7 @@ public class MSNListener extends MsnAdapter {
msnSession.getTransport().sendPacket(m);
msnSession.logOut();
}
else if (throwable.getClass().getName().equals("MsnProtocolException")) {
else if (throwable.getClass().getName().equals("net.sf.jml.exception.MsnProtocolException")) {
Message m = new Message();
m.setType(Message.Type.error);
m.setTo(msnSession.getJIDWithHighestPriority());
......@@ -166,7 +166,7 @@ public class MSNListener extends MsnAdapter {
m.setBody("MSN error: "+throwable.toString());
msnSession.getTransport().sendPacket(m);
}
else if (throwable.getClass().getName().equals("MsgNotSendException")) {
else if (throwable.getClass().getName().equals("net.sf.jml.exception.MsgNotSendException")) {
Message m = new Message();
m.setType(Message.Type.error);
m.setTo(msnSession.getJIDWithHighestPriority());
......@@ -174,7 +174,7 @@ public class MSNListener extends MsnAdapter {
m.setBody("Unable to send MSN message. Reason: "+throwable.toString());
msnSession.getTransport().sendPacket(m);
}
else if (throwable.getClass().getName().equals("UnknownMessageException")) {
else if (throwable.getClass().getName().equals("net.sf.jml.exception.UnknownMessageException")) {
Message m = new Message();
m.setType(Message.Type.error);
m.setTo(msnSession.getJIDWithHighestPriority());
......@@ -182,7 +182,7 @@ public class MSNListener extends MsnAdapter {
m.setBody("Unknown message from MSN: "+throwable.toString());
msnSession.getTransport().sendPacket(m);
}
else if (throwable.getClass().getName().equals("UnsupportedProtocolException")) {
else if (throwable.getClass().getName().equals("net.sf.jml.exception.UnsupportedProtocolException")) {
Message m = new Message();
m.setType(Message.Type.error);
m.setTo(msnSession.getJIDWithHighestPriority());
......
......@@ -274,10 +274,10 @@ public class MSNSession extends TransportSession {
if (isLoggedIn()) {
msnMessenger.getOwner().setStatus(((MSNTransport)getTransport()).convertJabStatusToMSN(presenceType));
}
else {
// Hrm, not logged in? Lets fix that.
msnMessenger.login();
}
// else {
// // Hrm, not logged in? Lets fix that.
// msnMessenger.login();
// }
}
/**
......
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