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,6 +157,11 @@ public abstract class BaseTransport implements Component, RosterEventListener { ...@@ -157,6 +157,11 @@ public abstract class BaseTransport implements Component, RosterEventListener {
JID from = packet.getFrom(); JID from = packet.getFrom();
JID to = packet.getTo(); JID to = packet.getTo();
if (to.getNode() == null) {
// Message to gateway itself. Throw away for now.
// TODO: Repsond with a message at some point?
}
else {
try { try {
TransportSession session = sessionManager.getSession(from); TransportSession session = sessionManager.getSession(from);
session.sendMessage(to, packet.getBody()); session.sendMessage(to, packet.getBody());
...@@ -165,6 +170,7 @@ public abstract class BaseTransport implements Component, RosterEventListener { ...@@ -165,6 +170,7 @@ public abstract class BaseTransport implements Component, RosterEventListener {
// TODO: Should return an error packet here // TODO: Should return an error packet here
Log.debug("Unable to find session."); Log.debug("Unable to find session.");
} }
}
return reply; return reply;
} }
...@@ -520,7 +526,7 @@ public abstract class BaseTransport implements Component, RosterEventListener { ...@@ -520,7 +526,7 @@ public abstract class BaseTransport implements Component, RosterEventListener {
else if (var.equals("password")) { else if (var.equals("password")) {
password = field.getValues().get(0); password = field.getValues().get(0);
} }
else if (var.equals("nickname")) { else if (var.equals("nick")) {
nickname = field.getValues().get(0); nickname = field.getValues().get(0);
} }
...@@ -533,7 +539,7 @@ public abstract class BaseTransport implements Component, RosterEventListener { ...@@ -533,7 +539,7 @@ public abstract class BaseTransport implements Component, RosterEventListener {
if (packet.getType() == IQ.Type.set) { if (packet.getType() == IQ.Type.set) {
Element userEl = packet.getChildElement().element("username"); Element userEl = packet.getChildElement().element("username");
Element passEl = packet.getChildElement().element("password"); Element passEl = packet.getChildElement().element("password");
Element nickEl = packet.getChildElement().element("nickname"); Element nickEl = packet.getChildElement().element("nick");
if (userEl != null) { if (userEl != null) {
username = userEl.getTextTrim(); username = userEl.getTextTrim();
...@@ -547,6 +553,10 @@ public abstract class BaseTransport implements Component, RosterEventListener { ...@@ -547,6 +553,10 @@ public abstract class BaseTransport implements Component, RosterEventListener {
nickname = nickEl.getTextTrim(); 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)) { if (username == null || (isPasswordRequired() && password == null) || (isNicknameRequired() && nickname == null)) {
// Found nothing from stanza, lets yell. // Found nothing from stanza, lets yell.
IQ result = IQ.createResultIQ(packet); IQ result = IQ.createResultIQ(packet);
...@@ -613,14 +623,14 @@ public abstract class BaseTransport implements Component, RosterEventListener { ...@@ -613,14 +623,14 @@ public abstract class BaseTransport implements Component, RosterEventListener {
response.addElement("username").addText(registration.getUsername()); response.addElement("username").addText(registration.getUsername());
response.addElement("password").addText(registration.getPassword()); response.addElement("password").addText(registration.getPassword());
if (nicknameTerm != null) { if (nicknameTerm != null) {
response.addElement("nickname").addText(registration.getNickname()); response.addElement("nick").addText(registration.getNickname());
} }
} }
else { else {
response.addElement("username"); response.addElement("username");
response.addElement("password"); response.addElement("password");
if (nicknameTerm != null) { if (nicknameTerm != null) {
response.addElement("nickname"); response.addElement("nick");
} }
} }
......
...@@ -15,6 +15,7 @@ import org.schwering.irc.lib.IRCUser; ...@@ -15,6 +15,7 @@ import org.schwering.irc.lib.IRCUser;
import org.schwering.irc.lib.IRCModeParser; import org.schwering.irc.lib.IRCModeParser;
import org.xmpp.packet.Message; import org.xmpp.packet.Message;
import org.xmpp.packet.Presence; import org.xmpp.packet.Presence;
import org.jivesoftware.util.Log;
import java.util.Date; import java.util.Date;
...@@ -50,40 +51,65 @@ public class IRCListener implements IRCEventListener { ...@@ -50,40 +51,65 @@ public class IRCListener implements IRCEventListener {
} }
public void onDisconnected() { 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) { 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) { 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) { public void onInvite(String string, IRCUser ircUser, String string1) {
Log.debug("IRC invite: "+string+", "+ircUser+", "+string1);
} }
public void onJoin(String string, IRCUser ircUser) { public void onJoin(String string, IRCUser ircUser) {
Log.debug("IRC join: "+string+", "+ircUser);
} }
public void onKick(String string, IRCUser ircUser, String string1, String string2) { 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) { 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) { public void onMode(IRCUser ircUser, String string, String string1) {
Log.debug("IRC mode: "+ircUser+", "+string+", "+string1);
} }
public void onNick(IRCUser ircUser, String string) { public void onNick(IRCUser ircUser, String string) {
Log.debug("IRC nick: "+ircUser+", "+string);
} }
public void onNotice(String string, IRCUser ircUser, String string1) { 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) { public void onPart(String string, IRCUser ircUser, String string1) {
Log.debug("IRC part: "+string+", "+ircUser+", "+string1);
} }
public void onPing(String string) { public void onPing(String string) {
// Nothing to do, handled automatically.
} }
public void onPrivmsg(String chan, IRCUser ircUser, String msg) { public void onPrivmsg(String chan, IRCUser ircUser, String msg) {
...@@ -100,15 +126,19 @@ public class IRCListener implements IRCEventListener { ...@@ -100,15 +126,19 @@ public class IRCListener implements IRCEventListener {
p.setTo(getSession().getJID()); p.setTo(getSession().getJID());
p.setFrom(getSession().getTransport().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) { 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) { 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) { 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 { ...@@ -40,7 +40,15 @@ public class IRCSession extends TransportSession {
*/ */
public IRCSession(Registration registration, JID jid, IRCTransport transport, Integer priority) { public IRCSession(Registration registration, JID jid, IRCTransport transport, Integer priority) {
super(registration, jid, transport, 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.setPong(true);
conn.setDaemon(false); conn.setDaemon(false);
conn.setColors(false); conn.setColors(false);
...@@ -50,7 +58,7 @@ public class IRCSession extends TransportSession { ...@@ -50,7 +58,7 @@ public class IRCSession extends TransportSession {
/** /**
* IRC connection. * IRC connection.
*/ */
IRCConnection conn; public IRCConnection conn;
/** /**
* Logs the session into IRC. * Logs the session into IRC.
...@@ -59,7 +67,6 @@ public class IRCSession extends TransportSession { ...@@ -59,7 +67,6 @@ public class IRCSession extends TransportSession {
* @param verboseStatus Initial full status information. * @param verboseStatus Initial full status information.
*/ */
public void logIn(PresenceType presenceType, String verboseStatus) { public void logIn(PresenceType presenceType, String verboseStatus) {
if (!isLoggedIn()) {
try { try {
conn.connect(); conn.connect();
} }
...@@ -67,21 +74,32 @@ public class IRCSession extends TransportSession { ...@@ -67,21 +74,32 @@ public class IRCSession extends TransportSession {
Log.error("IO error while connecting to IRC: "+e.toString()); Log.error("IO error while connecting to IRC: "+e.toString());
} }
} }
}
/** /**
* Logs the session out of IRC. * Logs the session out of IRC.
*/ */
public void logOut() { public void logOut() {
if (isLoggedIn()) { conn.doQuit();
conn.close();
} }
/**
* 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) * @see org.jivesoftware.wildfire.gateway.TransportSession#updateStatus(org.jivesoftware.wildfire.gateway.PresenceType, String)
*/ */
public void updateStatus(PresenceType presenceType, String verboseStatus) { 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 { ...@@ -95,18 +113,21 @@ public class IRCSession extends TransportSession {
* @see org.jivesoftware.wildfire.gateway.TransportSession#addContact(org.jivesoftware.wildfire.roster.RosterItem) * @see org.jivesoftware.wildfire.gateway.TransportSession#addContact(org.jivesoftware.wildfire.roster.RosterItem)
*/ */
public void addContact(RosterItem item) { public void addContact(RosterItem item) {
// TODO: Handle this
} }
/** /**
* @see org.jivesoftware.wildfire.gateway.TransportSession#removeContact(org.jivesoftware.wildfire.roster.RosterItem) * @see org.jivesoftware.wildfire.gateway.TransportSession#removeContact(org.jivesoftware.wildfire.roster.RosterItem)
*/ */
public void removeContact(RosterItem item) { public void removeContact(RosterItem item) {
// TODO: Handle this
} }
/** /**
* @see org.jivesoftware.wildfire.gateway.TransportSession#updateContact(org.jivesoftware.wildfire.roster.RosterItem) * @see org.jivesoftware.wildfire.gateway.TransportSession#updateContact(org.jivesoftware.wildfire.roster.RosterItem)
*/ */
public void updateContact(RosterItem item) { public void updateContact(RosterItem item) {
// TODO: Handle this
} }
/** /**
...@@ -120,12 +141,14 @@ public class IRCSession extends TransportSession { ...@@ -120,12 +141,14 @@ public class IRCSession extends TransportSession {
* @see org.jivesoftware.wildfire.gateway.TransportSession#retrieveContactStatus(org.xmpp.packet.JID) * @see org.jivesoftware.wildfire.gateway.TransportSession#retrieveContactStatus(org.xmpp.packet.JID)
*/ */
public void retrieveContactStatus(JID jid) { public void retrieveContactStatus(JID jid) {
// TODO: Handle this
} }
/** /**
* @see org.jivesoftware.wildfire.gateway.TransportSession#resendContactStatuses(org.xmpp.packet.JID) * @see org.jivesoftware.wildfire.gateway.TransportSession#resendContactStatuses(org.xmpp.packet.JID)
*/ */
public void resendContactStatuses(JID jid) { public void resendContactStatuses(JID jid) {
// TODO: Handle this
} }
} }
...@@ -94,4 +94,35 @@ public class IRCTransport extends BaseTransport { ...@@ -94,4 +94,35 @@ public class IRCTransport extends BaseTransport {
// session.sessionDone(); // 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 { ...@@ -149,7 +149,7 @@ public class MSNListener extends MsnAdapter {
* Catches MSN exceptions. * Catches MSN exceptions.
*/ */
public void exceptionCaught(MsnMessenger messenger, Throwable throwable) { 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(); Message m = new Message();
m.setType(Message.Type.error); m.setType(Message.Type.error);
m.setTo(msnSession.getJIDWithHighestPriority()); m.setTo(msnSession.getJIDWithHighestPriority());
...@@ -158,7 +158,7 @@ public class MSNListener extends MsnAdapter { ...@@ -158,7 +158,7 @@ public class MSNListener extends MsnAdapter {
msnSession.getTransport().sendPacket(m); msnSession.getTransport().sendPacket(m);
msnSession.logOut(); msnSession.logOut();
} }
else if (throwable.getClass().getName().equals("MsnProtocolException")) { else if (throwable.getClass().getName().equals("net.sf.jml.exception.MsnProtocolException")) {
Message m = new Message(); Message m = new Message();
m.setType(Message.Type.error); m.setType(Message.Type.error);
m.setTo(msnSession.getJIDWithHighestPriority()); m.setTo(msnSession.getJIDWithHighestPriority());
...@@ -166,7 +166,7 @@ public class MSNListener extends MsnAdapter { ...@@ -166,7 +166,7 @@ public class MSNListener extends MsnAdapter {
m.setBody("MSN error: "+throwable.toString()); m.setBody("MSN error: "+throwable.toString());
msnSession.getTransport().sendPacket(m); 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(); Message m = new Message();
m.setType(Message.Type.error); m.setType(Message.Type.error);
m.setTo(msnSession.getJIDWithHighestPriority()); m.setTo(msnSession.getJIDWithHighestPriority());
...@@ -174,7 +174,7 @@ public class MSNListener extends MsnAdapter { ...@@ -174,7 +174,7 @@ public class MSNListener extends MsnAdapter {
m.setBody("Unable to send MSN message. Reason: "+throwable.toString()); m.setBody("Unable to send MSN message. Reason: "+throwable.toString());
msnSession.getTransport().sendPacket(m); 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(); Message m = new Message();
m.setType(Message.Type.error); m.setType(Message.Type.error);
m.setTo(msnSession.getJIDWithHighestPriority()); m.setTo(msnSession.getJIDWithHighestPriority());
...@@ -182,7 +182,7 @@ public class MSNListener extends MsnAdapter { ...@@ -182,7 +182,7 @@ public class MSNListener extends MsnAdapter {
m.setBody("Unknown message from MSN: "+throwable.toString()); m.setBody("Unknown message from MSN: "+throwable.toString());
msnSession.getTransport().sendPacket(m); 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(); Message m = new Message();
m.setType(Message.Type.error); m.setType(Message.Type.error);
m.setTo(msnSession.getJIDWithHighestPriority()); m.setTo(msnSession.getJIDWithHighestPriority());
......
...@@ -274,10 +274,10 @@ public class MSNSession extends TransportSession { ...@@ -274,10 +274,10 @@ public class MSNSession extends TransportSession {
if (isLoggedIn()) { if (isLoggedIn()) {
msnMessenger.getOwner().setStatus(((MSNTransport)getTransport()).convertJabStatusToMSN(presenceType)); msnMessenger.getOwner().setStatus(((MSNTransport)getTransport()).convertJabStatusToMSN(presenceType));
} }
else { // else {
// Hrm, not logged in? Lets fix that. // // Hrm, not logged in? Lets fix that.
msnMessenger.login(); // 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