Commit 5438a6bb authored by Daniel Henninger's avatar Daniel Henninger Committed by dhenninger

[GATE-3] Still working on buddy add/remove issues. More code cleanup here and...

[GATE-3] Still working on buddy add/remove issues.  More code cleanup here and there and improvements to connection status handling.  Per gato's great suggestion, switched some hashs to concurrent hashes to dodge concurrent modification exceptions.

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk/src/plugins/gateway@5267 b35dd754-fafc-0310-a699-88a17e54d16e
parent 34e704fc
...@@ -53,7 +53,6 @@ public class MSNListener extends MsnAdapter { ...@@ -53,7 +53,6 @@ public class MSNListener extends MsnAdapter {
* Handles incoming messages from MSN users. * Handles incoming messages from MSN users.
*/ */
public void instantMessageReceived(MsnSwitchboard switchboard, MsnInstantMessage message, MsnContact friend) { public void instantMessageReceived(MsnSwitchboard switchboard, MsnInstantMessage message, MsnContact friend) {
Log.debug("MSN: Received im to " + switchboard + " from " + friend + ": " + message.getContent());
Message m = new Message(); Message m = new Message();
m.setType(Message.Type.chat); m.setType(Message.Type.chat);
m.setTo(msnSession.getJIDWithHighestPriority()); m.setTo(msnSession.getJIDWithHighestPriority());
...@@ -66,7 +65,6 @@ public class MSNListener extends MsnAdapter { ...@@ -66,7 +65,6 @@ public class MSNListener extends MsnAdapter {
* Handles incoming system messages from MSN. * Handles incoming system messages from MSN.
*/ */
public void systemMessageReceived(MsnSwitchboard switchboard, MsnInstantMessage message) { public void systemMessageReceived(MsnSwitchboard switchboard, MsnInstantMessage message) {
Log.debug("MSN: Received system msg to " + switchboard + " from MSN: " + message.getContent());
Message m = new Message(); Message m = new Message();
m.setType(Message.Type.chat); m.setType(Message.Type.chat);
m.setTo(msnSession.getJIDWithHighestPriority()); m.setTo(msnSession.getJIDWithHighestPriority());
...@@ -100,7 +98,6 @@ public class MSNListener extends MsnAdapter { ...@@ -100,7 +98,6 @@ public class MSNListener extends MsnAdapter {
* The user's login has completed and was accepted. * The user's login has completed and was accepted.
*/ */
public void loginCompleted(MsnMessenger messenger) { public void loginCompleted(MsnMessenger messenger) {
Log.debug("MSN login completed");
msnSession.getRegistration().setLastLogin(new Date()); msnSession.getRegistration().setLastLogin(new Date());
msnSession.setLoginStatus(true); msnSession.setLoginStatus(true);
} }
...@@ -109,14 +106,12 @@ public class MSNListener extends MsnAdapter { ...@@ -109,14 +106,12 @@ public class MSNListener extends MsnAdapter {
* Contact list initialization has completed. * Contact list initialization has completed.
*/ */
public void contactListInitCompleted(MsnMessenger messenger) { public void contactListInitCompleted(MsnMessenger messenger) {
Log.debug("Contact list init completed.");
} }
/** /**
* Contact list has been synced. * Contact list has been synced.
*/ */
public void contactListSyncCompleted(MsnMessenger messenger) { public void contactListSyncCompleted(MsnMessenger messenger) {
Log.debug("Contact list sync completed.");
for (MsnContact msnContact : messenger.getContactList().getContacts()) { for (MsnContact msnContact : messenger.getContactList().getContacts()) {
Log.debug("Got contact "+msnContact); Log.debug("Got contact "+msnContact);
msnSession.storeFriend(msnContact); msnSession.storeFriend(msnContact);
...@@ -131,7 +126,6 @@ public class MSNListener extends MsnAdapter { ...@@ -131,7 +126,6 @@ public class MSNListener extends MsnAdapter {
* A friend for this user has changed status. * A friend for this user has changed status.
*/ */
public void contactStatusChanged(MsnMessenger messenger, MsnContact friend) { public void contactStatusChanged(MsnMessenger messenger, MsnContact friend) {
Log.debug("Got MSN status "+friend);
Presence p = new Presence(); Presence p = new Presence();
p.setTo(msnSession.getJID()); p.setTo(msnSession.getJID());
p.setFrom(msnSession.getTransport().convertIDToJID(friend.getEmail().toString())); p.setFrom(msnSession.getTransport().convertIDToJID(friend.getEmail().toString()));
...@@ -144,7 +138,6 @@ public class MSNListener extends MsnAdapter { ...@@ -144,7 +138,6 @@ public class MSNListener extends MsnAdapter {
* Owner status has changed. * Owner status has changed.
*/ */
public void ownerStatusChanged(MsnMessenger messenger) { public void ownerStatusChanged(MsnMessenger messenger) {
Log.debug("Owner status has changed: " + messenger);
Presence p = new Presence(); Presence p = new Presence();
p.setTo(msnSession.getJID()); p.setTo(msnSession.getJID());
p.setFrom(msnSession.getTransport().getJID()); p.setFrom(msnSession.getTransport().getJID());
...@@ -156,7 +149,6 @@ public class MSNListener extends MsnAdapter { ...@@ -156,7 +149,6 @@ 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) {
Log.debug("Caught MSN exception: "+messenger+":"+throwable.toString());
if (throwable.getClass().getName().equals("IncorrectPasswordException")) { if (throwable.getClass().getName().equals("IncorrectPasswordException")) {
Message m = new Message(); Message m = new Message();
m.setType(Message.Type.error); m.setType(Message.Type.error);
......
...@@ -22,9 +22,9 @@ import org.jivesoftware.util.Log; ...@@ -22,9 +22,9 @@ import org.jivesoftware.util.Log;
import org.xmpp.packet.JID; import org.xmpp.packet.JID;
import org.xmpp.packet.Presence; import org.xmpp.packet.Presence;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.concurrent.ConcurrentHashMap;
/** /**
* Represents a MSN session. * Represents a MSN session.
...@@ -59,12 +59,12 @@ public class MSNSession extends TransportSession { ...@@ -59,12 +59,12 @@ public class MSNSession extends TransportSession {
/** /**
* MSN contacts/friends. * MSN contacts/friends.
*/ */
private HashMap<String,MsnContact> msnContacts = new HashMap<String,MsnContact>(); private ConcurrentHashMap<String,MsnContact> msnContacts = new ConcurrentHashMap<String,MsnContact>();
/** /**
* MSN groups. * MSN groups.
*/ */
private HashMap<String,MsnGroup> msnGroups = new HashMap<String,MsnGroup>(); private ConcurrentHashMap<String,MsnGroup> msnGroups = new ConcurrentHashMap<String,MsnGroup>();
/** /**
* Login status * Login status
...@@ -98,7 +98,7 @@ public class MSNSession extends TransportSession { ...@@ -98,7 +98,7 @@ public class MSNSession extends TransportSession {
p.setTo(getJID()); p.setTo(getJID());
p.setFrom(getTransport().getJID()); p.setFrom(getTransport().getJID());
getTransport().sendPacket(p); getTransport().sendPacket(p);
loginStatus = false; loginStatus = false;
} }
/** /**
...@@ -142,10 +142,8 @@ public class MSNSession extends TransportSession { ...@@ -142,10 +142,8 @@ public class MSNSession extends TransportSession {
public void syncUsers() { public void syncUsers() {
List<TransportBuddy> legacyusers = new ArrayList<TransportBuddy>(); List<TransportBuddy> legacyusers = new ArrayList<TransportBuddy>();
for (MsnContact friend : msnContacts.values()) { for (MsnContact friend : msnContacts.values()) {
Log.debug("Syncing contact " + friend);
ArrayList<String> friendGroups = new ArrayList<String>(); ArrayList<String> friendGroups = new ArrayList<String>();
for (MsnGroup group : friend.getBelongGroups()) { for (MsnGroup group : friend.getBelongGroups()) {
Log.debug(" Found group " + group);
friendGroups.add(group.getGroupName()); friendGroups.add(group.getGroupName());
} }
if (friendGroups.size() < 1) { if (friendGroups.size() < 1) {
......
...@@ -130,12 +130,9 @@ public class BOSConnection extends BasicFlapConnection { ...@@ -130,12 +130,9 @@ public class BOSConnection extends BasicFlapConnection {
Log.debug("AIM got group item " + obj); Log.debug("AIM got group item " + obj);
oscarSession.gotGroup((GroupItem) obj); oscarSession.gotGroup((GroupItem) obj);
} }
//Log.debug("- " + (obj == null ? (Object) items[i]
// : (Object) obj));
} }
if (sdc.getLastModDate() != 0) { if (sdc.getLastModDate() != 0) {
//Log.debug("done with SSI");
request(new ActivateSsiCmd()); request(new ActivateSsiCmd());
clientReady(); clientReady();
oscarSession.gotCompleteSSI(); oscarSession.gotCompleteSSI();
......
...@@ -71,8 +71,6 @@ public abstract class BaseFlapConnection extends ClientFlapConn { ...@@ -71,8 +71,6 @@ public abstract class BaseFlapConnection extends ClientFlapConn {
public void handleException(FlapExceptionEvent event) { public void handleException(FlapExceptionEvent event) {
Log.error(event.getType() + " FLAP ERROR: " Log.error(event.getType() + " FLAP ERROR: "
+ event.getException().getMessage()); + event.getException().getMessage());
// How do do this right?
//Log.error(event.getException().printStackTrace());
} }
}); });
sp.addPacketListener(new SnacPacketListener() { sp.addPacketListener(new SnacPacketListener() {
......
...@@ -16,7 +16,6 @@ import java.io.UnsupportedEncodingException; ...@@ -16,7 +16,6 @@ import java.io.UnsupportedEncodingException;
import java.net.InetAddress; import java.net.InetAddress;
import java.text.DateFormat; import java.text.DateFormat;
import java.util.Arrays; import java.util.Arrays;
import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import net.kano.joscar.*; import net.kano.joscar.*;
...@@ -53,8 +52,6 @@ public abstract class BasicFlapConnection extends BaseFlapConnection { ...@@ -53,8 +52,6 @@ public abstract class BasicFlapConnection extends BaseFlapConnection {
protected RvProcessor rvProcessor = new RvProcessor(sp); protected RvProcessor rvProcessor = new RvProcessor(sp);
protected RvProcessorListener rvListener = new RvProcessorListener() { protected RvProcessorListener rvListener = new RvProcessorListener() {
public void handleNewSession(NewRvSessionEvent event) { public void handleNewSession(NewRvSessionEvent event) {
//Log.debug("new RV session: " + event.getSession());
event.getSession().addListener(rvSessionListener); event.getSession().addListener(rvSessionListener);
} }
}; };
...@@ -146,28 +143,34 @@ public abstract class BasicFlapConnection extends BaseFlapConnection { ...@@ -146,28 +143,34 @@ public abstract class BasicFlapConnection extends BaseFlapConnection {
InstantMessage message = icbm.getMessage(); InstantMessage message = icbm.getMessage();
String msg = OscarTools.stripHtml(message.getMessage()); String msg = OscarTools.stripHtml(message.getMessage());
Message jmessage = new Message(); Message m = new Message();
jmessage.setTo(oscarSession.getJIDWithHighestPriority()); m.setTo(oscarSession.getJIDWithHighestPriority());
jmessage.setBody(msg); m.setBody(msg);
jmessage.setType(Message.Type.chat); m.setType(Message.Type.chat);
jmessage.setFrom(this.oscarSession.getTransport().convertIDToJID(sn)); m.setFrom(this.oscarSession.getTransport().convertIDToJID(sn));
oscarSession.getTransport().sendPacket(jmessage); oscarSession.getTransport().sendPacket(m);
String str = dateFormat.format(new Date()) + " IM from "
+ sn + ": " + msg;
Log.debug(str);
} }
else if (cmd instanceof WarningNotification) { else if (cmd instanceof WarningNotification) {
WarningNotification wn = (WarningNotification) cmd; WarningNotification wn = (WarningNotification) cmd;
MiniUserInfo warner = wn.getWarner(); MiniUserInfo warner = wn.getWarner();
if (warner == null) { if (warner == null) {
Log.debug("*** You were warned anonymously to " Message m = new Message();
+ wn.getNewLevel() + "%"); m.setTo(oscarSession.getJIDWithHighestPriority());
m.setBody("You have received an anonymous AIM warning. Your warning level is now "+wn.getNewLevel()+"%.");
m.setType(Message.Type.headline);
m.setFrom(this.oscarSession.getTransport().getJID());
oscarSession.getTransport().sendPacket(m);
} }
else { else {
Log.debug("*** " + warner.getScreenname() Log.debug("*** " + warner.getScreenname()
+ " warned you up to " + wn.getNewLevel() + "%"); + " warned you up to " + wn.getNewLevel() + "%");
Message m = new Message();
m.setTo(oscarSession.getJIDWithHighestPriority());
m.setBody("You have received an AIM warning from "+warner.getScreenname()+". Your warning level is now "+wn.getNewLevel()+"%.");
m.setType(Message.Type.headline);
m.setFrom(this.oscarSession.getTransport().getJID());
oscarSession.getTransport().sendPacket(m);
} }
} }
else if (cmd instanceof BuddyStatusCmd) { else if (cmd instanceof BuddyStatusCmd) {
...@@ -240,7 +243,6 @@ public abstract class BasicFlapConnection extends BaseFlapConnection { ...@@ -240,7 +243,6 @@ public abstract class BasicFlapConnection extends BaseFlapConnection {
int[] classes = new int[rateClasses.length]; int[] classes = new int[rateClasses.length];
for (int i = 0; i < rateClasses.length; i++) { for (int i = 0; i < rateClasses.length; i++) {
classes[i] = rateClasses[i].getRateClass(); classes[i] = rateClasses[i].getRateClass();
// Log.debug("- " + rateClasses[i] + ": " + Arrays.asList(rateClasses[i].getCommands()));
} }
request(new RateAck(classes)); request(new RateAck(classes));
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
package org.jivesoftware.wildfire.gateway.protocols.oscar; package org.jivesoftware.wildfire.gateway.protocols.oscar;
import org.jivesoftware.util.Log; import org.jivesoftware.util.Log;
import org.xmpp.packet.Message;
import net.kano.joscar.*; import net.kano.joscar.*;
import net.kano.joscar.flap.*; import net.kano.joscar.flap.*;
...@@ -45,19 +46,28 @@ public class LoginConnection extends BaseFlapConnection { ...@@ -45,19 +46,28 @@ public class LoginConnection extends BaseFlapConnection {
} }
protected void handleStateChange(ClientConnEvent e) { protected void handleStateChange(ClientConnEvent e) {
//Log.debug("state changed to: " + e.getNewState() + " (" + e.getReason() + ")");
if (e.getNewState() == ClientFlapConn.STATE_CONNECTED) { if (e.getNewState() == ClientFlapConn.STATE_CONNECTED) {
//Log.debug("connected, sending flap version and key request");
getFlapProcessor().sendFlap(new LoginFlapCmd()); getFlapProcessor().sendFlap(new LoginFlapCmd());
request(new KeyRequest(oscarSession.getRegistration().getUsername())); request(new KeyRequest(oscarSession.getRegistration().getUsername()));
} }
else if (e.getNewState() == ClientFlapConn.STATE_FAILED) { else if (e.getNewState() == ClientFlapConn.STATE_FAILED) {
//Log.info("connection failed: " + e.getReason()); Message m = new Message();
m.setType(Message.Type.error);
m.setFrom(this.getMainSession().getTransport().getJID());
m.setTo(this.getMainSession().getJIDWithHighestPriority());
m.setBody("Connection failed: " + e.getReason());
this.getMainSession().getTransport().sendPacket(m);
this.getMainSession().logOut();
} }
else if (e.getNewState() == ClientFlapConn.STATE_NOT_CONNECTED) { else if (e.getNewState() == ClientFlapConn.STATE_NOT_CONNECTED) {
if (!loggedin) { if (!loggedin) {
//Log.info("connection lost: " + e.getReason()); Message m = new Message();
m.setType(Message.Type.error);
m.setFrom(this.getMainSession().getTransport().getJID());
m.setTo(this.getMainSession().getJIDWithHighestPriority());
m.setBody("Connection lost: " + e.getReason());
this.getMainSession().getTransport().sendPacket(m);
this.getMainSession().logOut();
} }
} }
} }
...@@ -68,9 +78,6 @@ public class LoginConnection extends BaseFlapConnection { ...@@ -68,9 +78,6 @@ public class LoginConnection extends BaseFlapConnection {
protected void handleSnacResponse(SnacResponseEvent e) { protected void handleSnacResponse(SnacResponseEvent e) {
SnacCommand cmd = e.getSnacCommand(); SnacCommand cmd = e.getSnacCommand();
//Log.debug("snac response: "
// + Integer.toHexString(cmd.getFamily()) + "/"
// + Integer.toHexString(cmd.getCommand()) + ": " + cmd);
if (cmd instanceof KeyResponse) { if (cmd instanceof KeyResponse) {
KeyResponse kr = (KeyResponse) cmd; KeyResponse kr = (KeyResponse) cmd;
......
...@@ -13,10 +13,10 @@ package org.jivesoftware.wildfire.gateway.protocols.oscar; ...@@ -13,10 +13,10 @@ package org.jivesoftware.wildfire.gateway.protocols.oscar;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.HashSet; import java.util.HashSet;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import net.kano.joscar.flapcmd.*; import net.kano.joscar.flapcmd.*;
import net.kano.joscar.snac.*; import net.kano.joscar.snac.*;
import net.kano.joscar.snaccmd.*; import net.kano.joscar.snaccmd.*;
...@@ -70,9 +70,9 @@ public class OSCARSession extends TransportSession { ...@@ -70,9 +70,9 @@ public class OSCARSession extends TransportSession {
/** /**
* SSI tracking variables. * SSI tracking variables.
*/ */
private Map<String,BuddyItem> buddies = new HashMap<String,BuddyItem>(); private ConcurrentHashMap<String,BuddyItem> buddies = new ConcurrentHashMap<String,BuddyItem>();
private Map<Integer,GroupItem> groups = new HashMap<Integer,GroupItem>(); private ConcurrentHashMap<Integer,GroupItem> groups = new ConcurrentHashMap<Integer,GroupItem>();
private Map<Integer,Integer> highestBuddyIdPerGroup = new HashMap<Integer,Integer>(); private ConcurrentHashMap<Integer,Integer> highestBuddyIdPerGroup = new ConcurrentHashMap<Integer,Integer>();
private Integer highestGroupId = -1; private Integer highestGroupId = -1;
public void logIn(PresenceType presenceType, String verboseStatus) { public void logIn(PresenceType presenceType, String verboseStatus) {
...@@ -164,7 +164,17 @@ public class OSCARSession extends TransportSession { ...@@ -164,7 +164,17 @@ public class OSCARSession extends TransportSession {
// Now, lets clean up any groups this contact should no longer be a member of. // Now, lets clean up any groups this contact should no longer be a member of.
for (BuddyItem buddy : buddies.values()) { for (BuddyItem buddy : buddies.values()) {
if (buddy.getScreenname().equals(contact)) { if (buddy.getScreenname().equals(contact)) {
if (!grouplist.contains(groups.get(buddy.getGroupId()).getGroupName())) { if (buddy.getGroupId() == 0) {
// Ok this group is the "main group", which we can cheerfully remove from.
request(new DeleteItemsCmd(new SsiItem[] { buddy.toSsiItem() }));
buddies.remove(buddy.getGroupId()+"."+buddy.getId());
}
else if (!groups.contains(buddy.getGroupId())) {
// Well this is odd, a group we don't know about? Nuke it.
request(new DeleteItemsCmd(new SsiItem[] { buddy.toSsiItem() }));
buddies.remove(buddy.getGroupId()+"."+buddy.getId());
}
else if (!grouplist.contains(groups.get(buddy.getGroupId()).getGroupName())) {
request(new DeleteItemsCmd(new SsiItem[] { buddy.toSsiItem() })); request(new DeleteItemsCmd(new SsiItem[] { buddy.toSsiItem() }));
buddies.remove(buddy.getGroupId()+"."+buddy.getId()); buddies.remove(buddy.getGroupId()+"."+buddy.getId());
} }
...@@ -328,7 +338,7 @@ public class OSCARSession extends TransportSession { ...@@ -328,7 +338,7 @@ public class OSCARSession extends TransportSession {
* @param buddy The buddy we've been told about. * @param buddy The buddy we've been told about.
*/ */
void gotBuddy(BuddyItem buddy) { void gotBuddy(BuddyItem buddy) {
//Log.debug("Found buddy item: " + buddy.toString()); Log.debug("Found buddy item: " + buddy.toString() + " at id " + buddy.getId());
buddies.put(buddy.getGroupId()+"."+buddy.getId(), buddy); buddies.put(buddy.getGroupId()+"."+buddy.getId(), buddy);
if (!highestBuddyIdPerGroup.containsKey(buddy.getGroupId())) { if (!highestBuddyIdPerGroup.containsKey(buddy.getGroupId())) {
highestBuddyIdPerGroup.put(buddy.getGroupId(), -1); highestBuddyIdPerGroup.put(buddy.getGroupId(), -1);
...@@ -344,7 +354,7 @@ public class OSCARSession extends TransportSession { ...@@ -344,7 +354,7 @@ public class OSCARSession extends TransportSession {
* @param group The group we've been told about. * @param group The group we've been told about.
*/ */
void gotGroup(GroupItem group) { void gotGroup(GroupItem group) {
//Log.debug("Found group item: " + group.toString()); Log.debug("Found group item: " + group.toString() + " at id " + group.getId());
groups.put(group.getId(), group); groups.put(group.getId(), group);
if (!highestBuddyIdPerGroup.containsKey(group.getId())) { if (!highestBuddyIdPerGroup.containsKey(group.getId())) {
highestBuddyIdPerGroup.put(group.getId(), -1); highestBuddyIdPerGroup.put(group.getId(), -1);
......
...@@ -105,7 +105,6 @@ public class YahooSession extends TransportSession { ...@@ -105,7 +105,6 @@ public class YahooSession extends TransportSession {
Presence p = new Presence(); Presence p = new Presence();
p.setTo(getJID()); p.setTo(getJID());
p.setFrom(getTransport().getJID()); p.setFrom(getTransport().getJID());
Log.debug("Logged in, sending: " + p.toString());
getTransport().sendPacket(p); getTransport().sendPacket(p);
yahooSession.setStatus(((YahooTransport)getTransport()).convertJabStatusToYahoo(pType)); yahooSession.setStatus(((YahooTransport)getTransport()).convertJabStatusToYahoo(pType));
......
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