Commit 15a75c3d authored by Daniel Henninger's avatar Daniel Henninger Committed by dhenninger

[GATE-104] CPU 100% is actually semi different from the input error messages. ...

[GATE-104] CPU 100% is actually semi different from the input error messages.  CPU 100% was from threading being the suck.  Disabled threading for now.
[GATE-109] Fixed JML and msnSession to handle nickname changes.
[GATE-108] Only respond with forbidden if the person has an active fully logged in session.
Added ability to lock roster update carryovers to legacy service for things like roster syncs and such.
[GATE-47] Reenabled deletes.  Works great from MSN.  Haven't tested with others yet.

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk/src/plugins/gateway@5938 b35dd754-fafc-0310-a699-88a17e54d16e
parent c1d32afc
No preview for this file type
......@@ -1018,6 +1018,15 @@ public abstract class BaseTransport implements Component, RosterEventListener, P
Roster roster = rosterManager.getRoster(userjid.getNode());
boolean hasTransport = false;
// Lets lock down the roster from update notifications if there's an active session.
try {
TransportSession session = sessionManager.getSession(userjid.getNode());
session.lockRoster();
}
catch (NotFoundException e) {
// No active session? Then no problem.
}
// First thing first, we want to build ourselves an easy mapping.
Map<JID,TransportBuddy> legacymap = new HashMap<JID,TransportBuddy>();
for (TransportBuddy buddy : legacyitems) {
......@@ -1090,6 +1099,15 @@ public abstract class BaseTransport implements Component, RosterEventListener, P
Log.error("Failed adding new roster item", e);
}
}
// All done, lets unlock the roster.
try {
TransportSession session = sessionManager.getSession(userjid.getNode());
session.unlockRoster();
}
catch (NotFoundException e) {
// No active session? Then no problem.
}
}
catch (UserNotFoundException e) {
throw new UserNotFoundException("Could not find roster for " + userjid.toString());
......@@ -1187,6 +1205,16 @@ public abstract class BaseTransport implements Component, RosterEventListener, P
public void cleanUpRoster(JID jid, Boolean leaveDomain) throws UserNotFoundException {
try {
Roster roster = rosterManager.getRoster(jid.getNode());
// Lets lock down the roster from update notifications if there's an active session.
try {
TransportSession session = sessionManager.getSession(jid.getNode());
session.lockRoster();
}
catch (NotFoundException e) {
// No active session? Then no problem.
}
for (RosterItem ri : roster.getRosterItems()) {
if (ri.getJid().getDomain().equals(this.jid.getDomain())) {
if (ri.isShared()) {
......@@ -1207,6 +1235,15 @@ public abstract class BaseTransport implements Component, RosterEventListener, P
}
}
}
// All done, lets unlock the roster.
try {
TransportSession session = sessionManager.getSession(jid.getNode());
session.unlockRoster();
}
catch (NotFoundException e) {
// No active session? Then no problem.
}
}
catch (UserNotFoundException e) {
throw new UserNotFoundException("Unable to find roster.");
......@@ -1280,14 +1317,16 @@ public abstract class BaseTransport implements Component, RosterEventListener, P
// Not ours, not our problem.
return;
}
Log.debug(getType().toString()+": contactUpdated "+roster.getUsername()+":"+item.getJid());
if (item.getJid().getNode() == null) {
// Gateway itself, don't care.
return;
}
try {
TransportSession session = sessionManager.getSession(roster.getUsername());
session.updateContact(item);
if (!session.isRosterLocked()) {
Log.debug(getType().toString()+": contactUpdated "+roster.getUsername()+":"+item.getJid());
session.updateContact(item);
}
}
catch (NotFoundException e) {
// Well we just don't care then.
......@@ -1304,14 +1343,16 @@ public abstract class BaseTransport implements Component, RosterEventListener, P
// Not ours, not our problem.
return;
}
Log.debug(getType().toString()+": contactAdded "+roster.getUsername()+":"+item.getJid());
if (item.getJid().getNode() == null) {
// Gateway itself, don't care.
return;
}
try {
TransportSession session = sessionManager.getSession(roster.getUsername());
session.addContact(item);
if (!session.isRosterLocked()) {
Log.debug(getType().toString()+": contactAdded "+roster.getUsername()+":"+item.getJid());
session.addContact(item);
}
}
catch (NotFoundException e) {
// Well we just don't care then.
......@@ -1328,18 +1369,20 @@ public abstract class BaseTransport implements Component, RosterEventListener, P
// Not ours, not our problem.
return;
}
Log.debug(getType().toString()+": contactDeleted "+roster.getUsername()+":"+item.getJid());
// if (item.getJid().getNode() == null) {
// // TODO: The gateway itself was removed?
// return;
// }
// try {
// TransportSession session = sessionManager.getSession(roster.getUsername());
// session.removeContact(item);
// }
// catch (NotFoundException e) {
// // TODO: Should maybe do something about this
// }
if (item.getJid().getNode() == null) {
// Gateway itself, don't care.
return;
}
try {
TransportSession session = sessionManager.getSession(roster.getUsername());
if (!session.isRosterLocked()) {
Log.debug(getType().toString()+": contactDeleted "+roster.getUsername()+":"+item.getJid());
session.removeContact(item);
}
}
catch (NotFoundException e) {
// Well we just don't care then.
}
}
/**
......@@ -1350,7 +1393,6 @@ public abstract class BaseTransport implements Component, RosterEventListener, P
public void rosterLoaded(Roster roster) {
Log.debug(getType().toString()+": rosterLoaded "+roster.getUsername());
// Don't care
// TODO: Evaluate if we could use this, maybe an opportunity to clean up.
}
/**
......
......@@ -86,6 +86,11 @@ public abstract class TransportSession implements Runnable {
*/
public boolean validSession = true;
/**
* Is the roster locked for sync editing?
*/
public boolean rosterLocked = false;
/**
* The current login status on the legacy network.
*/
......@@ -160,6 +165,29 @@ public abstract class TransportSession implements Runnable {
return resources.size();
}
/**
* Returns if the roster is currently locked.
*
* @return true or false if the roster is locked.
*/
public boolean isRosterLocked() {
return rosterLocked;
}
/**
* Locks the roster (typically used for editing during syncing.
*/
public void lockRoster() {
rosterLocked = true;
}
/**
* Unlocks the roster after sync editing is complete.
*/
public void unlockRoster() {
rosterLocked = false;
}
/**
* Retrieves the registration information associated with the session.
*
......
......@@ -100,9 +100,11 @@ public class TransportSessionManager {
* @return A thread wrapped around the session.
*/
public Thread startThread(TransportSession session) {
Thread sessionThread = new Thread(threadGroup, session);
sessionThread.start();
return sessionThread;
// TODO: This does not work well. Disabling.
// Thread sessionThread = new Thread(threadGroup, session);
// sessionThread.start();
// return sessionThread;
return null;
}
/**
......
......@@ -248,19 +248,21 @@ public class IRCSession extends TransportSession {
* @see org.jivesoftware.wildfire.gateway.TransportSession#retrieveContactStatus(org.xmpp.packet.JID)
*/
public void retrieveContactStatus(JID jid) {
String contact = getTransport().convertJIDToID(jid);
Presence p = new Presence();
if (buddyStatuses.containsKey(contact)) {
if (buddyStatuses.get(contact).equals(PresenceType.unavailable)) {
p.setType(Presence.Type.unavailable);
if (isLoggedIn()) {
String contact = getTransport().convertJIDToID(jid);
Presence p = new Presence();
if (buddyStatuses.containsKey(contact)) {
if (buddyStatuses.get(contact).equals(PresenceType.unavailable)) {
p.setType(Presence.Type.unavailable);
}
}
else {
p.setError(PacketError.Condition.forbidden);
}
p.setTo(jid);
p.setFrom(getTransport().convertIDToJID(contact));
getTransport().sendPacket(p);
}
else {
p.setError(PacketError.Condition.forbidden);
}
p.setTo(jid);
p.setFrom(getTransport().convertIDToJID(contact));
getTransport().sendPacket(p);
}
/**
......
......@@ -115,6 +115,7 @@ public class MSNListener extends MsnAdapter {
}
}
for (MsnGroup msnGroup : messenger.getContactList().getGroups()) {
Log.debug("MSN: Got group "+msnGroup);
msnSession.storeGroup(msnGroup);
}
msnSession.syncUsers();
......
......@@ -47,10 +47,9 @@ public class MSNSession extends TransportSession {
public MSNSession(Registration registration, JID jid, MSNTransport transport, Integer priority) {
super(registration, jid, transport, priority);
Log.debug("Creating MSN session for " + registration.getUsername());
Log.debug("Creating MSN session for " + registration.getUsername());
msnMessenger = MsnMessengerFactory.createMsnMessenger(registration.getUsername(), registration.getPassword());
((BasicMessenger)msnMessenger).addSessionListener(new MsnSessionListener(this));
//msnMessenger.setSupportedProtocol(MsnProtocol.getAllSupportedProtocol());
msnMessenger.setSupportedProtocol(new MsnProtocol[] { MsnProtocol.MSNP11 });
}
......@@ -146,12 +145,13 @@ public class MSNSession extends TransportSession {
for (MsnContact friend : msnContacts.values()) {
ArrayList<String> friendGroups = new ArrayList<String>();
for (MsnGroup group : friend.getBelongGroups()) {
Log.debug("MSN: Found belong group for "+friend+" as "+group);
friendGroups.add(group.getGroupName());
}
if (friendGroups.size() < 1) {
friendGroups.add("MSN Contacts");
}
legacyusers.add(new TransportBuddy(friend.getEmail().toString(), friend.getDisplayName(), friendGroups.get(0)));
legacyusers.add(new TransportBuddy(friend.getEmail().toString(), friend.getFriendlyName(), friendGroups.get(0)));
}
try {
getTransport().syncLegacyRoster(getJID(), legacyusers);
......@@ -174,21 +174,22 @@ public class MSNSession extends TransportSession {
* @see org.jivesoftware.wildfire.gateway.TransportSession#addContact(org.jivesoftware.wildfire.roster.RosterItem)
*/
public void addContact(RosterItem item) {
// Email contact = Email.parseStr(getTransport().convertJIDToID(item.getJid()));
// String nickname = getTransport().convertJIDToID(item.getJid());
// if (item.getNickname() != null && !item.getNickname().equals("")) {
// nickname = item.getNickname();
// }
// msnMessenger.addFriend(contact, nickname);
// syncContactGroups(contact, item.getGroups());
Email contact = Email.parseStr(getTransport().convertJIDToID(item.getJid()));
String nickname = getTransport().convertJIDToID(item.getJid());
if (item.getNickname() != null && !item.getNickname().equals("")) {
nickname = item.getNickname();
}
msnMessenger.addFriend(contact, nickname);
syncContactGroups(contact, item.getGroups());
}
/**
* @see org.jivesoftware.wildfire.gateway.TransportSession#removeContact(org.jivesoftware.wildfire.roster.RosterItem)
*/
public void removeContact(RosterItem item) {
// Email contact = Email.parseStr(getTransport().convertJIDToID(item.getJid()));
Email contact = Email.parseStr(getTransport().convertJIDToID(item.getJid()));
// MsnContact msnContact = msnContacts.get(contact.toString());
msnMessenger.removeFriend(contact, false);
// for (MsnGroup msnGroup : msnContact.getBelongGroups()) {
// msnMessenger.removeFriend(contact, msnGroup.getGroupId());
// }
......@@ -198,13 +199,19 @@ public class MSNSession extends TransportSession {
* @see org.jivesoftware.wildfire.gateway.TransportSession#updateContact(org.jivesoftware.wildfire.roster.RosterItem)
*/
public void updateContact(RosterItem item) {
// Email contact = Email.parseStr(getTransport().convertJIDToID(item.getJid()));
// String nickname = getTransport().convertJIDToID(item.getJid());
// if (item.getNickname() != null && !item.getNickname().equals("")) {
// nickname = item.getNickname();
// }
// msnMessenger.renameFriend(contact, nickname);
// syncContactGroups(contact, item.getGroups());
Email contact = Email.parseStr(getTransport().convertJIDToID(item.getJid()));
String nickname = getTransport().convertJIDToID(item.getJid());
if (item.getNickname() != null && !item.getNickname().equals("")) {
nickname = item.getNickname();
}
MsnContact msnContact = msnContacts.get(contact.toString());
if (msnContact == null) {
return;
}
if (!msnContact.getFriendlyName().equals(nickname)) {
msnMessenger.renameFriend(contact, nickname);
}
syncContactGroups(contact, item.getGroups());
}
/**
......@@ -218,30 +225,30 @@ public class MSNSession extends TransportSession {
if (groups.isEmpty()) {
groups.add("Transport Buddies");
}
// MsnContact msnContact = msnContacts.get(contact.toString());
// // Create groups that do not currently exist.
// for (String group : groups) {
// if (!msnGroups.containsKey(group)) {
// msnMessenger.addGroup(group);
// }
// }
// // Lets update our list of groups.
// for (MsnGroup msnGroup : msnMessenger.getContactList().getGroups()) {
// storeGroup(msnGroup);
// }
// // Make sure contact belongs to groups that we want.
// for (String group : groups) {
// MsnGroup msnGroup = msnGroups.get(group);
// if (!msnContact.belongGroup(msnGroup)) {
// msnMessenger.copyFriend(contact, group);
// }
// }
// // Now we will clean up groups that we should no longer belong to.
// for (MsnGroup msnGroup : msnContact.getBelongGroups()) {
// if (!groups.contains(msnGroup.getGroupName())) {
// msnMessenger.removeFriend(contact, msnGroup.getGroupId());
// }
// }
MsnContact msnContact = msnContacts.get(contact.toString());
// Create groups that do not currently exist.
for (String group : groups) {
if (!msnGroups.containsKey(group)) {
msnMessenger.addGroup(group);
}
}
// Lets update our list of groups.
for (MsnGroup msnGroup : msnMessenger.getContactList().getGroups()) {
storeGroup(msnGroup);
}
// Make sure contact belongs to groups that we want.
for (String group : groups) {
MsnGroup msnGroup = msnGroups.get(group);
if (!msnContact.belongGroup(msnGroup)) {
msnMessenger.copyFriend(contact, group);
}
}
// Now we will clean up groups that we should no longer belong to.
for (MsnGroup msnGroup : msnContact.getBelongGroups()) {
if (!groups.contains(msnGroup.getGroupName())) {
msnMessenger.removeFriend(contact, msnGroup.getGroupId());
}
}
}
/**
......@@ -262,19 +269,21 @@ public class MSNSession extends TransportSession {
* @see org.jivesoftware.wildfire.gateway.TransportSession#retrieveContactStatus(org.xmpp.packet.JID)
*/
public void retrieveContactStatus(JID jid) {
MsnContact msnContact = msnContacts.get(getTransport().convertJIDToID(jid));
Presence p = new Presence();
p.setTo(getJID());
if (msnContact != null) {
p.setFrom(getTransport().convertIDToJID(msnContact.getEmail().toString()));
((MSNTransport)getTransport()).setUpPresencePacket(p, msnContact.getStatus());
}
else {
// User was not found so send an error presence
p.setFrom(jid);
p.setError(PacketError.Condition.forbidden);
if (isLoggedIn()) {
MsnContact msnContact = msnContacts.get(getTransport().convertJIDToID(jid));
Presence p = new Presence();
p.setTo(getJID());
if (msnContact != null) {
p.setFrom(getTransport().convertIDToJID(msnContact.getEmail().toString()));
((MSNTransport)getTransport()).setUpPresencePacket(p, msnContact.getStatus());
}
else {
// User was not found so send an error presence
p.setFrom(jid);
p.setError(PacketError.Condition.forbidden);
}
getTransport().sendPacket(p);
}
getTransport().sendPacket(p);
}
/**
......
......@@ -454,8 +454,10 @@ public class OSCARSession extends TransportSession {
* @see org.jivesoftware.wildfire.gateway.TransportSession#retrieveContactStatus(org.xmpp.packet.JID)
*/
public void retrieveContactStatus(JID jid) {
if (bosConn != null) {
bosConn.getAndSendStatus(getTransport().convertJIDToID(jid));
if (isLoggedIn()) {
if (bosConn != null) {
bosConn.getAndSendStatus(getTransport().convertJIDToID(jid));
}
}
}
......
......@@ -368,26 +368,28 @@ public class YahooSession extends TransportSession {
* @see org.jivesoftware.wildfire.gateway.TransportSession#retrieveContactStatus(org.xmpp.packet.JID)
*/
public void retrieveContactStatus(JID jid) {
YahooUser user = yahooSession.getUser(jid.getNode());
Presence p = new Presence();
p.setTo(getJID());
if (user != null) {
// User was found so update presence accordingly
p.setFrom(getTransport().convertIDToJID(user.getId()));
if (isLoggedIn()) {
YahooUser user = yahooSession.getUser(jid.getNode());
Presence p = new Presence();
p.setTo(getJID());
if (user != null) {
// User was found so update presence accordingly
p.setFrom(getTransport().convertIDToJID(user.getId()));
String custommsg = user.getCustomStatusMessage();
if (custommsg != null) {
p.setStatus(custommsg);
}
String custommsg = user.getCustomStatusMessage();
if (custommsg != null) {
p.setStatus(custommsg);
}
((YahooTransport)getTransport()).setUpPresencePacket(p, user.getStatus());
}
else {
// User was not found so send an error presence
p.setFrom(jid);
p.setError(PacketError.Condition.forbidden);
((YahooTransport)getTransport()).setUpPresencePacket(p, user.getStatus());
}
else {
// User was not found so send an error presence
p.setFrom(jid);
p.setError(PacketError.Condition.forbidden);
}
getTransport().sendPacket(p);
}
getTransport().sendPacket(p);
}
/**
......
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