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