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