Commit fbbe8aaa authored by Daniel Henninger's avatar Daniel Henninger Committed by dhenninger

Cleaned up OSCAR code a tad. Fixed bug with null pointer exception on nickname update.

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk/src/plugins/gateway@5440 b35dd754-fafc-0310-a699-88a17e54d16e
parent e3aa2ffa
......@@ -881,7 +881,14 @@ public abstract class BaseTransport implements Component, RosterEventListener {
gwitem.setAskStatus(RosterItem.ASK_NONE);
changed = true;
}
if (nickname != null && !(gwitem.getNickname() != null) && !gwitem.getNickname().equals(nickname)) {
// This could probably be simplified, for not I'm going with brute force logic.
// gnickname is null, nickname is null, leave
// gnickname is not null, nickname is null, set gnickname to null
// gnickname is null, nickname is not null, set gnickname to nickname
// gnickname is not null, nickname is not null, if different, set gnickname to nickname
if ( (gwitem.getNickname() != null && nickname == null) ||
(gwitem.getNickname() == null && nickname != null) ||
(gwitem.getNickname() != null && nickname != null && !gwitem.getNickname().equals(nickname))) {
gwitem.setNickname(nickname);
changed = true;
}
......
......@@ -24,7 +24,6 @@ import net.kano.joscar.snaccmd.loc.*;
import net.kano.joscar.snaccmd.ssi.*;
import net.kano.joscar.ssiitem.*;
import java.net.InetAddress;
import java.util.Arrays;
import java.util.List;
......@@ -39,12 +38,12 @@ import org.jivesoftware.util.Log;
public class BOSConnection extends BasicFlapConnection {
protected SsiItemObjectFactory itemFactory = new DefaultSsiItemObjFactory();
public BOSConnection(String host, int port, OSCARSession mainSession, ByteBlock cookie) {
super(host, port, mainSession, cookie); // HAnd off to BasicFlapConnection
}
private static final List<CapabilityBlock> MY_CAPS = Arrays.asList(
CapabilityBlock.BLOCK_ICQCOMPATIBLE
);
public BOSConnection(InetAddress ip, int port, OSCARSession mainSession, ByteBlock cookie) {
super(ip, port, mainSession, cookie); // HAnd off to BasicFlapConnection
public BOSConnection(ConnDescriptor cd, OSCARSession mainSession, ByteBlock cookie) {
super(cd, mainSession, cookie); // Hand off to BasicFlapConnection
}
protected void handleStateChange(ClientConnEvent e) {
......@@ -74,11 +73,10 @@ public class BOSConnection extends BasicFlapConnection {
if (cmd instanceof LocRightsCmd) {
request(new SetInfoCmd(new InfoData("oscargateway",
null, Arrays.asList(new CapabilityBlock[] {
CapabilityBlock.BLOCK_ICQCOMPATIBLE,
}), null)));
null, MY_CAPS, null)));
request(new MyInfoRequest());
} else if (cmd instanceof ParamInfoCmd) {
}
else if (cmd instanceof ParamInfoCmd) {
ParamInfoCmd pic = (ParamInfoCmd) cmd;
ParamInfo info = pic.getParamInfo();
......@@ -87,31 +85,15 @@ public class BOSConnection extends BasicFlapConnection {
info.getFlags() | ParamInfo.FLAG_TYPING_NOTIFICATION, 8000,
info.getMaxSenderWarning(), info.getMaxReceiverWarning(),
0)));
} else if (cmd instanceof YourInfoCmd) {
// YourInfoCmd yic = (YourInfoCmd) cmd;
//
// FullUserInfo info = yic.getUserInfo();
//Log.debug("got my user info: " + info);
} else if (cmd instanceof UserInfoCmd) {
// UserInfoCmd uic = (UserInfoCmd) cmd;
//
// String sn = uic.getUserInfo().getScreenname();
//Log.debug("user info for " + sn + ": "
// + uic.getInfoData());
} else if (cmd instanceof ServiceRedirect) {
}
else if (cmd instanceof ServiceRedirect) {
ServiceRedirect sr = (ServiceRedirect) cmd;
//Log.debug("connecting to " + sr.getRedirectHost()
// + " for 0x" + Integer.toHexString(sr.getSnacFamily()));
oscarSession.connectToService(sr.getSnacFamily(), sr.getRedirectHost(),
sr.getCookie());
} else if (cmd instanceof SsiDataCmd) {
}
else if (cmd instanceof SsiDataCmd) {
SsiDataCmd sdc = (SsiDataCmd) cmd;
List<SsiItem> items = sdc.getItems();
......
......@@ -14,10 +14,7 @@ package org.jivesoftware.wildfire.gateway.protocols.oscar;
import org.jivesoftware.util.Log;
import java.net.InetAddress;
import net.kano.joscar.flap.ClientFlapConn;
import net.kano.joscar.flap.FlapProcessor;
import net.kano.joscar.flap.FlapPacketListener;
import net.kano.joscar.flap.FlapPacketEvent;
import net.kano.joscar.snac.*;
......@@ -33,25 +30,17 @@ import net.kano.joscar.net.*;
* Heavily inspired by joscardemo from the joscar project.
*/
public abstract class BaseFlapConnection extends ClientFlapConn {
protected ClientSnacProcessor sp;
protected ClientSnacProcessor sp = new ClientSnacProcessor(getFlapProcessor());
OSCARSession oscarSession;
public BaseFlapConnection(String host, int port, OSCARSession mainSession) {
super(new ConnDescriptor(host, port)); // Hand off to ClientFlapConn
initBaseFlapConnection();
oscarSession = mainSession;
}
public BaseFlapConnection(InetAddress ip, int port, OSCARSession mainSession) {
super(new ConnDescriptor(ip, port)); // Hand off to ClientFlapConn
public BaseFlapConnection(ConnDescriptor cd, OSCARSession mainSession) {
super(cd); // Hand off to ClientFlapConn
initBaseFlapConnection();
oscarSession = mainSession;
}
private void initBaseFlapConnection() {
FlapProcessor fp = getFlapProcessor();
sp = new ClientSnacProcessor(fp);
fp.setFlapCmdFactory(new DefaultFlapCmdFactory());
getFlapProcessor().setFlapCmdFactory(new DefaultFlapCmdFactory());
sp.addPreprocessor(new FamilyVersionPreprocessor());
sp.getCmdFactoryMgr().setDefaultFactoryList(new DefaultClientFactoryList());
......
......@@ -13,9 +13,9 @@
package org.jivesoftware.wildfire.gateway.protocols.oscar;
import java.io.UnsupportedEncodingException;
import java.net.InetAddress;
import java.text.DateFormat;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import org.jivesoftware.util.Log;
import org.xmpp.packet.Message;
......@@ -24,6 +24,7 @@ import org.xmpp.packet.JID;
import net.kano.joscar.ByteBlock;
import net.kano.joscar.OscarTools;
import net.kano.joscar.BinaryTools;
import net.kano.joscar.net.ConnDescriptor;
import net.kano.joscar.flap.FlapCommand;
import net.kano.joscar.flap.FlapPacketEvent;
import net.kano.joscar.snac.SnacPacketEvent;
......@@ -50,25 +51,20 @@ public abstract class BasicFlapConnection extends BaseFlapConnection {
protected final ByteBlock cookie;
protected boolean sentClientReady = false;
public Map<String,FullUserInfo> buddystore = new HashMap<String, FullUserInfo>();
public ConcurrentHashMap<String,FullUserInfo> buddystore = new ConcurrentHashMap<String, FullUserInfo>();
protected int[] snacFamilies = null;
protected Collection<SnacFamilyInfo> snacFamilyInfos;
protected RateLimitingQueueMgr rateMgr = new RateLimitingQueueMgr();
{ // init
sp.setSnacQueueManager(rateMgr);
}
public BasicFlapConnection(String host, int port, OSCARSession mainSession, ByteBlock cookie) {
super(host, port, mainSession);
public BasicFlapConnection(ConnDescriptor cd, OSCARSession mainSession, ByteBlock cookie) {
super(cd, mainSession);
this.cookie = cookie;
initBasicFlapConnection();
}
public BasicFlapConnection(InetAddress ip, int port, OSCARSession mainSession,
ByteBlock cookie) {
super(ip, port, mainSession);
this.cookie = cookie;
private void initBasicFlapConnection() {
sp.setSnacQueueManager(rateMgr);
}
protected DateFormat dateFormat
......@@ -87,18 +83,15 @@ public abstract class BasicFlapConnection extends BaseFlapConnection {
SnacCommand cmd = e.getSnacCommand();
if (cmd instanceof ServerReadyCmd) {
ServerReadyCmd src = (ServerReadyCmd) cmd;
setSnacFamilies(src.getSnacFamilies());
Collection<SnacFamilyInfo> familyInfos = SnacFamilyInfoFactory.getDefaultFamilyInfos(src.getSnacFamilies());
setSnacFamilyInfos(familyInfos);
oscarSession.registerSnacFamilies(this);
request(new ClientVersionsCmd(familyInfos));
request(new RateInfoRequest());
}
else if (cmd instanceof RecvImIcbm) {
RecvImIcbm icbm = (RecvImIcbm) cmd;
......@@ -134,7 +127,6 @@ public abstract class BasicFlapConnection extends BaseFlapConnection {
m.setType(Message.Type.headline);
m.setFrom(this.oscarSession.getTransport().getJID());
oscarSession.getTransport().sendPacket(m);
}
}
else if (cmd instanceof BuddyStatusCmd) {
......@@ -155,17 +147,7 @@ public abstract class BasicFlapConnection extends BaseFlapConnection {
ExtraInfoData data = i.getExtraData();
if (i.getType() == ExtraInfoBlock.TYPE_AVAILMSG) {
ByteBlock msgBlock = data.getData();
int len = BinaryTools.getUShort(msgBlock, 0);
byte[] msgBytes = msgBlock.subBlock(2, len).toByteArray(
);
String msg;
try {
msg = new String(msgBytes, "UTF-8");
}
catch (UnsupportedEncodingException e1) {
continue;
}
String msg = ExtraInfoData.readAvailableMessage(data);
if (msg.length() > 0) {
p.setStatus(msg);
}
......@@ -189,7 +171,6 @@ public abstract class BasicFlapConnection extends BaseFlapConnection {
if (cmd instanceof RateInfoCmd) {
RateInfoCmd ric = (RateInfoCmd) cmd;
List <RateClassInfo> rateClasses = ric.getRateClassInfos();
int[] classes = new int[rateClasses.size()];
......@@ -252,7 +233,8 @@ public abstract class BasicFlapConnection extends BaseFlapConnection {
if (snacFamilies == null || supportsFamily(family)) {
// this connection supports this snac, so we'll send it here
sendRequest(request);
} else {
}
else {
oscarSession.handleRequest(request);
}
}
......
......@@ -22,8 +22,6 @@ import net.kano.joscar.net.*;
import net.kano.joscar.snac.*;
import net.kano.joscar.snaccmd.auth.*;
import java.net.InetAddress;
/**
* Handles the login process with the OSCAR login server.
*
......@@ -33,12 +31,8 @@ import java.net.InetAddress;
public class LoginConnection extends BaseFlapConnection {
protected boolean loggedin = false;
public LoginConnection(String host, int port, OSCARSession mainSession) {
super(host, port, mainSession); // Hand off to BaseFlapConnection
}
public LoginConnection(InetAddress ip, int port, OSCARSession mainSession) {
super(ip, port, mainSession); // Hand off to BaseFlapConnection
public LoginConnection(ConnDescriptor cd, OSCARSession mainSession) {
super(cd, mainSession); // Hand off to BaseFlapConnection
}
protected void handleStateChange(ClientConnEvent e) {
......@@ -79,12 +73,11 @@ public class LoginConnection extends BaseFlapConnection {
if (cmd instanceof KeyResponse) {
KeyResponse kr = (KeyResponse) cmd;
ByteBlock authkey = kr.getKey();
ClientVersionInfo version = new ClientVersionInfo(
"AOL Instant Messenger, version 5.2.3292/WIN32",
5, 1, 0, 3292, 238);
"AOL Instant Messenger, version 5.5.3415/WIN32",
-1, 5, 5, 0, 3415, 239);
request(new AuthRequest(oscarSession.getRegistration().getUsername(), oscarSession.getRegistration().getPassword(), version, authkey));
......@@ -94,11 +87,6 @@ public class LoginConnection extends BaseFlapConnection {
int error = ar.getErrorCode();
if (error != -1) {
// Log.error("connection error! code: " + error);
// if (ar.getErrorUrl() != null) {
// Log.error("Error URL: " + ar.getErrorUrl());
// }
//
String errormsg;
switch (error) {
case (AuthResponse.ERROR_ACCOUNT_DELETED): {
......
......@@ -14,6 +14,7 @@ import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import net.kano.joscar.ByteBlock;
import net.kano.joscar.net.ConnDescriptor;
import net.kano.joscar.flapcmd.SnacCommand;
import net.kano.joscar.snac.SnacRequest;
import net.kano.joscar.snac.SnacRequestListener;
......@@ -78,7 +79,7 @@ public class OSCARSession extends TransportSession {
public void logIn(PresenceType presenceType, String verboseStatus) {
if (!isLoggedIn()) {
LoginConnection loginConn = new LoginConnection("login.oscar.aol.com", 5190, this);
LoginConnection loginConn = new LoginConnection(new ConnDescriptor("login.oscar.aol.com", 5190), this);
loginConn.connect();
loggedIn = true;
......@@ -254,7 +255,7 @@ public class OSCARSession extends TransportSession {
* @param cookie Auth cookie.
*/
void startBosConn(String server, int port, ByteBlock cookie) {
bosConn = new BOSConnection(server, port, this, cookie);
bosConn = new BOSConnection(new ConnDescriptor(server, port), this, cookie);
bosConn.connect();
}
......@@ -268,10 +269,9 @@ public class OSCARSession extends TransportSession {
}
protected SnacManager snacMgr = new SnacManager(new PendingSnacListener() {
public void dequeueSnacs(SnacRequest[] pending) {
//Log.debug("dequeuing " + pending.length + " snacs");
for (SnacRequest aPending : pending) {
handleRequest(aPending);
public void dequeueSnacs(List<SnacRequest> pending) {
for (SnacRequest request : pending) {
handleRequest(request);
}
}
});
......@@ -287,7 +287,8 @@ public class OSCARSession extends TransportSession {
if (conn != null) {
conn.sendRequest(request);
} else {
}
else {
// it's time to request a service
if (!(request.getCommand() instanceof ServiceRequest)) {
snacMgr.setPending(family, true);
......@@ -311,7 +312,7 @@ public class OSCARSession extends TransportSession {
}
void connectToService(int snacFamily, String host, ByteBlock cookie) {
ServiceConnection conn = new ServiceConnection(host, 5190, this,
ServiceConnection conn = new ServiceConnection(new ConnDescriptor(host, 5190), this,
cookie, snacFamily);
conn.connect();
......
......@@ -14,6 +14,8 @@ package org.jivesoftware.wildfire.gateway.protocols.oscar;
import net.kano.joscar.snac.SnacRequest;
import java.util.List;
/**
* Handles events from pending SNAC manager.
*
......@@ -21,5 +23,5 @@ import net.kano.joscar.snac.SnacRequest;
* Heavily inspired by joscardemo from the joscar project.
*/
public interface PendingSnacListener {
void dequeueSnacs(SnacRequest[] pending);
void dequeueSnacs(List<SnacRequest> pending);
}
......@@ -13,6 +13,7 @@
package org.jivesoftware.wildfire.gateway.protocols.oscar;
import net.kano.joscar.snac.SnacRequest;
import net.kano.joscar.DefensiveTools;
import java.util.ArrayList;
import java.util.HashMap;
......@@ -41,9 +42,9 @@ public class PendingSnacMgr {
pending.add(request);
}
public SnacRequest[] getPending(int familyCode) {
public List<SnacRequest> getPending(int familyCode) {
List<SnacRequest> pending = snacs.get(familyCode);
return pending.toArray(new SnacRequest[0]);
return DefensiveTools.getUnmodifiableCopy(pending);
}
public void setPending(int familyCode, boolean pending) {
......
......@@ -21,8 +21,7 @@ import net.kano.joscar.snaccmd.conn.RateInfoCmd;
import net.kano.joscar.snac.SnacPacketEvent;
import net.kano.joscar.snac.SnacResponseEvent;
import net.kano.joscar.net.ClientConnEvent;
import java.net.InetAddress;
import net.kano.joscar.net.ConnDescriptor;
/**
* Represents a connection to a particular OSCAR service.
......@@ -34,13 +33,8 @@ public class ServiceConnection extends BasicFlapConnection {
protected int serviceFamily;
public ServiceConnection(String host, int port, OSCARSession mainSession, ByteBlock cookie, int serviceFamily) {
super(host, port, mainSession, cookie);
this.serviceFamily = serviceFamily;
}
public ServiceConnection(InetAddress ip, int port, OSCARSession mainSession, ByteBlock cookie, int serviceFamily) {
super(ip, port, mainSession, cookie);
public ServiceConnection(ConnDescriptor cd, OSCARSession mainSession, ByteBlock cookie, int serviceFamily) {
super(cd, mainSession, cookie);
this.serviceFamily = serviceFamily;
}
......@@ -77,4 +71,5 @@ public class ServiceConnection extends BasicFlapConnection {
clientReady();
}
}
}
......@@ -28,6 +28,7 @@ import java.util.Map;
* Heavily inspired by joscardemo from the joscar project.
*/
public class SnacManager {
protected Map<Integer,List<BasicFlapConnection>> conns = new HashMap<Integer,List<BasicFlapConnection>>();
protected PendingSnacMgr pendingSnacs = new PendingSnacMgr();
protected List<PendingSnacListener> listeners = new ArrayList<PendingSnacListener>();
......@@ -48,7 +49,7 @@ public class SnacManager {
if (handlers == null) {
handlers = new LinkedList<BasicFlapConnection>();
conns.put(familyCode, handlers);
conns.put((Integer)familyCode, handlers);
}
if (!handlers.contains(conn)) {
......@@ -70,31 +71,29 @@ public class SnacManager {
}
protected void dequeueSnacs(int familyCode) {
SnacRequest[] pending = pendingSnacs.getPending(familyCode);
List<SnacRequest> pending = pendingSnacs.getPending(familyCode);
pendingSnacs.setPending(familyCode, false);
for (Object listener1 : listeners) {
PendingSnacListener listener = (PendingSnacListener) listener1;
for (PendingSnacListener listener : listeners) {
listener.dequeueSnacs(pending);
}
}
public void unregister(BasicFlapConnection conn) {
for (List<BasicFlapConnection> basicFlapConnections : conns.values()) {
basicFlapConnections.remove(conn);
for (List<BasicFlapConnection> handlers : conns.values()) {
handlers.remove(conn);
}
}
public BasicFlapConnection getConn(int familyCode) {
List handlers = conns.get(familyCode);
List<BasicFlapConnection> handlers = conns.get(familyCode);
if (handlers == null || handlers.size() == 0) {
return null;
}
return (BasicFlapConnection) handlers.get(0);
return handlers.get(0);
}
......@@ -103,6 +102,11 @@ public class SnacManager {
}
public void addRequest(SnacRequest request) {
int family = request.getCommand().getFamily();
if (!isPending(family)) {
throw new IllegalArgumentException("Family 0x"
+ Integer.toHexString(family) + " is not pending");
}
pendingSnacs.add(request);
}
......
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