Format all code, add editorconfig

This commit is contained in:
floppydiskette 2024-05-10 00:32:34 +01:00
parent a1dff2cb8d
commit 3faced7068
Signed by: fwoppydwisk
SSH key fingerprint: SHA256:Hqn452XQ1ETzUt/FthJu6+OFkS4NBxCv5VQSEvuk7CE
52 changed files with 2011 additions and 1918 deletions

11
.editorconfig Normal file
View file

@ -0,0 +1,11 @@
root = true
[*]
indent_style = space
indent_size = 4
charset = utf-8
end_of_line = lf
insert_final_newline = true
[*.iml]
indent_size = 2

2
.github/README.md vendored
View file

@ -3,9 +3,11 @@
This is a fork of [Jaim](https://jaimlib.sourceforge.net/), a Java library that implements the AOL TOC protocol. This is a fork of [Jaim](https://jaimlib.sourceforge.net/), a Java library that implements the AOL TOC protocol.
This fork features various improvements on the original Jaim: This fork features various improvements on the original Jaim:
- Support for chat invites - Support for chat invites
## Original README ## Original README
``` ```
Readme.txt for Jaimlib Readme.txt for Jaimlib
---------------------- ----------------------

View file

@ -4,6 +4,9 @@
<exclude-output /> <exclude-output />
<content url="file://$MODULE_DIR$"> <content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/.idea" />
<excludeFolder url="file://$MODULE_DIR$/build" />
<excludeFolder url="file://$MODULE_DIR$/lib" />
</content> </content>
<orderEntry type="inheritedJdk" /> <orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />

View file

@ -25,64 +25,79 @@
package com.wilko.jaim; package com.wilko.jaim;
/** This is a buddy object that holds the buddy's name and other /**
* This is a buddy object that holds the buddy's name and other
* information about a buddy. * information about a buddy.
*
* @author Brett Humphreys * @author Brett Humphreys
*/ */
public class Buddy { public class Buddy {
/** Name of the buddy */ /**
private String buddyName; * Name of the buddy
*/
private final String buddyName;
/** Permit value */ /**
* Permit value
*/
private boolean permit; private boolean permit;
/** deny value */ /**
* deny value
*/
private boolean deny; private boolean deny;
/** Constructor that sets the buddy name /**
* Constructor that sets the buddy name
*
* @param name the name of this buddy. * @param name the name of this buddy.
*/ */
public Buddy ( String name ) public Buddy(String name) {
{
buddyName = name; buddyName = name;
} }
/** Gets the buddy name /**
* Gets the buddy name
*
* @return buddy name * @return buddy name
*/ */
public String getName() public String getName() {
{
return buddyName; return buddyName;
} }
/** Sets the permit value
* @param permitVal what to set permit to
*/
public void setPermit( boolean permitVal )
{
permit = permitVal;
}
/** Gets the permit value /**
* Gets the permit value
*
* @return permit value * @return permit value
*/ */
public boolean getPermit( ) public boolean getPermit() {
{
return permit; return permit;
} }
/** Sets the deny value /**
* @param denyVal what to set deny to * Sets the permit value
*
* @param permitVal what to set permit to
*/ */
public void setDeny( boolean denyVal ) public void setPermit(boolean permitVal) {
{ permit = permitVal;
deny = denyVal;
} }
/** Gets the deny value /**
* Gets the deny value
*
* @return deny value * @return deny value
*/ */
public boolean getDeny( ) public boolean getDeny() {
{
return deny; return deny;
} }
/**
* Sets the deny value
*
* @param denyVal what to set deny to
*/
public void setDeny(boolean denyVal) {
deny = denyVal;
}
} }

View file

@ -28,12 +28,15 @@ package com.wilko.jaim;
import java.util.Date; import java.util.Date;
import java.util.StringTokenizer; import java.util.StringTokenizer;
/** A BuddyUpdateTocResponse is delivered to a {@link JaimEventListener } when a buddy update is received from the TOC server /**
* A BuddyUpdateTocResponse is delivered to a {@link JaimEventListener } when a buddy update is received from the TOC server
*
* @author paulw * @author paulw
* @version $Revision: 1.7 $ * @version $Revision: 1.7 $
*/ */
public class BuddyUpdateTocResponse extends TocResponse implements TocResponseHandler { public class BuddyUpdateTocResponse extends TocResponse implements TocResponseHandler {
public static String RESPONSE_TYPE = "UPDATE_BUDDY";
private String buddyName; private String buddyName;
private boolean online; private boolean online;
private int evil; private int evil;
@ -45,9 +48,9 @@ public class BuddyUpdateTocResponse extends TocResponse implements TocResponseHa
private Date signonTime; private Date signonTime;
private boolean away; private boolean away;
public static String RESPONSE_TYPE="UPDATE_BUDDY"; /**
* Creates new BuddyUpdateTocResponse
/** Creates new BuddyUpdateTocResponse */ */
public BuddyUpdateTocResponse() { public BuddyUpdateTocResponse() {
buddyName = ""; buddyName = "";
online = false; online = false;
@ -60,7 +63,9 @@ public class BuddyUpdateTocResponse extends TocResponse implements TocResponseHa
away = false; away = false;
} }
/** The parseString method is used to populate the fields of this class from a Buddy Update string from the TOC server /**
* The parseString method is used to populate the fields of this class from a Buddy Update string from the TOC server
*
* @param str The String containing the buddy update * @param str The String containing the buddy update
*/ */
public TocResponse parseString(java.lang.String str) { public TocResponse parseString(java.lang.String str) {
@ -69,22 +74,14 @@ public class BuddyUpdateTocResponse extends TocResponse implements TocResponseHa
return (tr); return (tr);
} }
private void doParse(String str) private void doParse(String str) {
{
cmd = str; cmd = str;
StringTokenizer st = new StringTokenizer(str, ":"); StringTokenizer st = new StringTokenizer(str, ":");
st.nextToken(); st.nextToken();
buddyName = st.nextToken(); buddyName = st.nextToken();
String onlineStr = st.nextToken(); String onlineStr = st.nextToken();
if (onlineStr.equals("T")) online = onlineStr.equals("T");
{
online=true;
}
else
{
online=false;
}
evil = Integer.parseInt(st.nextToken()); evil = Integer.parseInt(st.nextToken());
long signon = Long.parseLong(st.nextToken()); long signon = Long.parseLong(st.nextToken());
@ -93,113 +90,117 @@ public class BuddyUpdateTocResponse extends TocResponse implements TocResponseHa
String userclass = st.nextToken(); String userclass = st.nextToken();
if (userclass.charAt(0) == 'A') if (userclass.charAt(0) == 'A')
onAOL = true; onAOL = true;
if (userclass.charAt(1) == 'A') if (userclass.charAt(1) == 'A') {
{
admin = true; admin = true;
} } else {
else if (userclass.charAt(1) == 'U') {
{
if (userclass.charAt(1)=='U')
{
unconfirmed = true; unconfirmed = true;
} } else {
else if (userclass.charAt(1) == 'O') {
{
if(userclass.charAt(1)=='O')
{
confirmed = true; confirmed = true;
} }
} }
} }
if (userclass.length()>2) if (userclass.length() > 2) {
{ if (userclass.charAt(2) == 'U') {
if (userclass.charAt(2)=='U')
{
away = true; away = true;
} }
} }
} }
/** Get the away status of the buddy specified by this update /**
* Get the away status of the buddy specified by this update
*
* @return true if the buddy is "away" * @return true if the buddy is "away"
*/ */
public boolean isAway() public boolean isAway() {
{
return (away); return (away);
} }
/** Get the response type of this response. This method is used by the response dispatcher within JaimConnection /**
* Get the response type of this response. This method is used by the response dispatcher within JaimConnection
*
* @return The response type * @return The response type
*/ */
public String getResponseType() { public String getResponseType() {
return RESPONSE_TYPE; return RESPONSE_TYPE;
} }
/** Obtain the buddy name from this update /**
* Obtain the buddy name from this update
*
* @return The buddy name * @return The buddy name
*/ */
public String getBuddy() public String getBuddy() {
{
return (buddyName); return (buddyName);
} }
/** Obtain the online status of this buddy update /**
* Obtain the online status of this buddy update
*
* @return true if the buddy is on line * @return true if the buddy is on line
*/ */
public boolean isOnline() public boolean isOnline() {
{
return (online); return (online);
} }
/** Obtain the idle time of this buddy /**
* Obtain the idle time of this buddy
*
* @return The idle time in seconds * @return The idle time in seconds
*/ */
public int getIdleTime() public int getIdleTime() {
{
return (idleTime); return (idleTime);
} }
/** Obtain the "Evil" (Warning) level of this buddy /**
* Obtain the "Evil" (Warning) level of this buddy
*
* @return The warning level as a percentage * @return The warning level as a percentage
*/ */
public int getEvil() public int getEvil() {
{
return (evil); return (evil);
} }
/** Is this buddy an "Administrator" /**
* Is this buddy an "Administrator"
*
* @return true if an administrator * @return true if an administrator
*/ */
public boolean isAdmin() public boolean isAdmin() {
{
return (admin); return (admin);
} }
/** IS this buddy a "confirmed" user /**
* IS this buddy a "confirmed" user
*
* @return True if this buddy is confirmed * @return True if this buddy is confirmed
*/ */
public boolean isConfirmed() public boolean isConfirmed() {
{
return (confirmed); return (confirmed);
} }
/** Is this user an "Unconfirmed user" /**
* Is this user an "Unconfirmed user"
*
* @return True if this user is unconfirmed * @return True if this user is unconfirmed
*/ */
public boolean isUnconfirmed() public boolean isUnconfirmed() {
{
return (unconfirmed); return (unconfirmed);
} }
/** Get the signon time of this buddy /**
* Get the signon time of this buddy
*
* @return The date/time of signon * @return The date/time of signon
*/ */
public Date getSignonTime() public Date getSignonTime() {
{
return (signonTime); return (signonTime);
} }
/** Returns true if this response handler can handle the specified response. /**
* Returns true if this response handler can handle the specified response.
*
* @param Response - the response string from TOC. This is the part of the response before the first ':' * @param Response - the response string from TOC. This is the part of the response before the first ':'
* @return true if the response can be handled * @return true if the response can be handled
*/ */

View file

@ -25,23 +25,25 @@
package com.wilko.jaim; package com.wilko.jaim;
import java.util.Date;
import java.util.StringTokenizer; import java.util.StringTokenizer;
/** A BuddyUpdateTocResponse is delivered to a {@link JaimEventListener } when a buddy update is received from the TOC server /**
* A BuddyUpdateTocResponse is delivered to a {@link JaimEventListener } when a buddy update is received from the TOC server
*
* @author paulw * @author paulw
* @version $Revision: 1.7 $ * @version $Revision: 1.7 $
*/ */
public class ChatInviteTocResponse extends TocResponse implements TocResponseHandler { public class ChatInviteTocResponse extends TocResponse implements TocResponseHandler {
public static String RESPONSE_TYPE = "CHAT_INVITE";
private String roomName; private String roomName;
private String roomID; private String roomID;
private String senderScreenname; private String senderScreenname;
private String message; private String message;
public static String RESPONSE_TYPE="CHAT_INVITE"; /**
* Creates new BuddyUpdateTocResponse
/** Creates new BuddyUpdateTocResponse */ */
public ChatInviteTocResponse() { public ChatInviteTocResponse() {
roomName = ""; roomName = "";
roomID = ""; roomID = "";
@ -49,7 +51,9 @@ public class ChatInviteTocResponse extends TocResponse implements TocResponseHan
message = ""; message = "";
} }
/** The parseString method is used to populate the fields of this class from a Buddy Update string from the TOC server /**
* The parseString method is used to populate the fields of this class from a Buddy Update string from the TOC server
*
* @param str The String containing the buddy update * @param str The String containing the buddy update
*/ */
public TocResponse parseString(String str) { public TocResponse parseString(String str) {
@ -58,8 +62,7 @@ public class ChatInviteTocResponse extends TocResponse implements TocResponseHan
return (tr); return (tr);
} }
private void doParse(String str) private void doParse(String str) {
{
cmd = str; cmd = str;
StringTokenizer st = new StringTokenizer(str, ":"); StringTokenizer st = new StringTokenizer(str, ":");
@ -70,7 +73,9 @@ public class ChatInviteTocResponse extends TocResponse implements TocResponseHan
message = st.nextToken(); message = st.nextToken();
} }
/** Get the response type of this response. This method is used by the response dispatcher within JaimConnection /**
* Get the response type of this response. This method is used by the response dispatcher within JaimConnection
*
* @return The response type * @return The response type
*/ */
public String getResponseType() { public String getResponseType() {
@ -80,6 +85,7 @@ public class ChatInviteTocResponse extends TocResponse implements TocResponseHan
public String getRoomName() { public String getRoomName() {
return roomName; return roomName;
} }
public String getRoomID() { public String getRoomID() {
return roomID; return roomID;
} }
@ -92,7 +98,9 @@ public class ChatInviteTocResponse extends TocResponse implements TocResponseHan
return message; return message;
} }
/** Returns true if this response handler can handle the specified response. /**
* Returns true if this response handler can handle the specified response.
*
* @param Response - the response string from TOC. This is the part of the response before the first ':' * @param Response - the response string from TOC. This is the part of the response before the first ':'
* @return true if the response can be handled * @return true if the response can be handled
*/ */

View file

@ -25,47 +25,59 @@
import java.util.*; import java.util.*;
/** A ConfigTocResponse contains the config message received from /**
* A ConfigTocResponse contains the config message received from
* the toc server. * the toc server.
* This response is handled by the JaimConnection class, but may also be used by client programs. * This response is handled by the JaimConnection class, but may also be used by client programs.
* Once this event has been received, information returned from {@link JaimConnection#getGroups} is valid * Once this event has been received, information returned from {@link JaimConnection#getGroups} is valid
*
* @author Brett Humphreys, Paul Wilkinson * @author Brett Humphreys, Paul Wilkinson
*/ */
public class ConfigTocResponse extends TocResponse implements TocResponseHandler { public class ConfigTocResponse extends TocResponse implements TocResponseHandler {
/**
* Value for mode that indicates PERMIT ALL mode
*/
public static final int PERMIT_ALL = 1;
/**
* Value for mode that indicates DENY ALL mode
*/
public static final int DENY_ALL = 2;
/**
* Value for mode that indicates PERMIT SOME mode
*/
public static final int PERMIT_SOME = 3;
/**
* Value for mode that indicates DENY SOME mode
*/
public static final int DENY_SOME = 4;
public static String RESPONSE_TYPE = "CONFIG"; public static String RESPONSE_TYPE = "CONFIG";
/**
/** The Vector of Group objects */ * The Vector of Group objects
private Vector buddyList = new Vector(); */
private final Vector buddyList = new Vector();
/** The HashMap of known buddies */ /**
* The HashMap of known buddies
*/
private HashMap buddies; private HashMap buddies;
/**
/** The mode for this configuration */ * The mode for this configuration
*/
private int mode; private int mode;
/** Value for mode that indicates PERMIT ALL mode */ /**
public static final int PERMIT_ALL=1; * Returns an Enumeration of groups. Each Entry is a {@link Group}
/** Value for mode that indicates DENY ALL mode */
public static final int DENY_ALL=2;
/** Value for mode that indicates PERMIT SOME mode */
public static final int PERMIT_SOME=3;
/** Value for mode that indicates DENY SOME mode */
public static final int DENY_SOME=4;
/** Returns an Enumeration of groups. Each Entry is a {@link Group}
* Each group then has an Enumeration of buddies within that group See {@link Group#enumerateBuddies}. * Each group then has an Enumeration of buddies within that group See {@link Group#enumerateBuddies}.
*
* @return list of Group elements or an empty list if none are found. * @return list of Group elements or an empty list if none are found.
*/ */
public Enumeration enumerateGroups() public Enumeration enumerateGroups() {
{
return buddyList.elements(); return buddyList.elements();
} }
/** Returns a Collection of groups. Each element is a {@link Group) /**
* Returns a Collection of groups. Each element is a {@link Group)
*
* @return the groups * @return the groups
*/ */
public Collection getGroups() { public Collection getGroups() {
@ -74,45 +86,45 @@
} }
/** Get the response type of this response. This method is used by the response dispatcher within JaimConnection /**
* Get the response type of this response. This method is used by the response dispatcher within JaimConnection
*
* @return The response type * @return The response type
*/ */
public String getResponseType() { public String getResponseType() {
return RESPONSE_TYPE; return RESPONSE_TYPE;
} }
/** Parses the config string.
/**
* Parses the config string.
*/ */
public TocResponse parseString(String message) public TocResponse parseString(String message) {
{
ConfigTocResponse tr = new ConfigTocResponse(); ConfigTocResponse tr = new ConfigTocResponse();
tr.doParse(message); tr.doParse(message);
return (tr); return (tr);
} }
private void doParse(String message) private void doParse(String message) {
{
cmd = message; cmd = message;
int colonIndex = message.indexOf(':'); int colonIndex = message.indexOf(':');
//throw away the first word. //throw away the first word.
message = message.substring(colonIndex+1, message.length()); message = message.substring(colonIndex + 1);
buddies = new HashMap(); buddies = new HashMap();
StringTokenizer tok = new StringTokenizer(message, "\n"); StringTokenizer tok = new StringTokenizer(message, "\n");
String itemType; String itemType;
String itemValue; String itemValue;
Group currentGroup = null; Group currentGroup = null;
Buddy tmpBuddy; Buddy tmpBuddy;
while( tok.hasMoreTokens() ) while (tok.hasMoreTokens()) {
{
// Can't tokenize on both \n and space since there could be spaces // Can't tokenize on both \n and space since there could be spaces
// in the name, so parsing by hand. // in the name, so parsing by hand.
itemType = tok.nextToken(); itemType = tok.nextToken();
int firstSpace = itemType.indexOf(' '); int firstSpace = itemType.indexOf(' ');
itemValue = itemType.substring(firstSpace+1, itemType.length()); itemValue = itemType.substring(firstSpace + 1);
itemType = itemType.substring(0, firstSpace); itemType = itemType.substring(0, firstSpace);
char type = itemType.charAt(0); char type = itemType.charAt(0);
switch (type) switch (type) {
{
case 'g': case 'g':
currentGroup = new Group(itemValue); currentGroup = new Group(itemValue);
buddyList.add(currentGroup); buddyList.add(currentGroup);
@ -122,8 +134,7 @@
tmpBuddy = getBuddy(itemValue); tmpBuddy = getBuddy(itemValue);
//this shouldn't happen, but: //this shouldn't happen, but:
if(currentGroup==null) if (currentGroup == null) {
{
currentGroup = new Group("<unknown>"); currentGroup = new Group("<unknown>");
buddyList.add(currentGroup); buddyList.add(currentGroup);
} }
@ -150,40 +161,44 @@
} }
} }
/** Return an existing Buddy with the specified name or return a new buddy if the name is not known /**
* Return an existing Buddy with the specified name or return a new buddy if the name is not known
* The buddy is added to the buddies hash if it is a new buddy * The buddy is added to the buddies hash if it is a new buddy
*
* @param The name of the buddy we are looking for * @param The name of the buddy we are looking for
* @return The buddy object * @return The buddy object
*/ */
private Buddy getBuddy(String buddyName) private Buddy getBuddy(String buddyName) {
{
Buddy retBuddy = (Buddy) buddies.get(buddyName); Buddy retBuddy = (Buddy) buddies.get(buddyName);
if (retBuddy== null) if (retBuddy == null) {
{
retBuddy = new Buddy(buddyName); retBuddy = new Buddy(buddyName);
buddies.put(buddyName, retBuddy); buddies.put(buddyName, retBuddy);
} }
return (retBuddy); return (retBuddy);
} }
/** Sets the mode for this configuration /**
* @param modeVal the string value of the mode (1-4) * Gets the mode for this configuration
*/ *
public void setMode( int modeVal )
{
mode = modeVal;
}
/** Gets the mode for this configuration
* @return mode for the configuration * @return mode for the configuration
*/ */
public int getMode( ) public int getMode() {
{
return mode; return mode;
} }
/** Returns true if this response handler can handle the specified response. /**
* Sets the mode for this configuration
*
* @param modeVal the string value of the mode (1-4)
*/
public void setMode(int modeVal) {
mode = modeVal;
}
/**
* Returns true if this response handler can handle the specified response.
*
* @param Response - the response string from TOC. This is the part of the response before the first ':' * @param Response - the response string from TOC. This is the part of the response before the first ':'
* @return true if the response can be handled * @return true if the response can be handled
*/ */

View file

@ -27,6 +27,7 @@ package com.wilko.jaim;
/** /**
* This is a "pseudo" TOC response - it is delivered to JaimLib clients to indicate that the connection to the server has been lost. * This is a "pseudo" TOC response - it is delivered to JaimLib clients to indicate that the connection to the server has been lost.
*
* @author wilko * @author wilko
* @version: $revision: $ * @version: $revision: $
*/ */
@ -34,7 +35,9 @@ public class ConnectionLostTocResponse extends TocResponse {
public static final String RESPONSE_TYPE = "CONNECTIONLOST"; public static final String RESPONSE_TYPE = "CONNECTIONLOST";
/** Creates a new instance of LoginCompleteTocResponse */ /**
* Creates a new instance of LoginCompleteTocResponse
*/
public ConnectionLostTocResponse() { public ConnectionLostTocResponse() {
} }
@ -42,8 +45,7 @@ public class ConnectionLostTocResponse extends TocResponse {
return (RESPONSE_TYPE); return (RESPONSE_TYPE);
} }
public String toString() public String toString() {
{
return (RESPONSE_TYPE); return (RESPONSE_TYPE);
} }

View file

@ -27,75 +27,89 @@ package com.wilko.jaim;
import java.util.MissingResourceException; import java.util.MissingResourceException;
/** This TOC response is sent to a {@link JaimEventListener } when an error message is received from the TOC server /**
* This TOC response is sent to a {@link JaimEventListener } when an error message is received from the TOC server
* *
* @author paulw * @author paulw
* @version $Revision: 1.7 $ * @version $Revision: 1.7 $
*/ */
public class ErrorTocResponse extends TocResponse implements TocResponseHandler { public class ErrorTocResponse extends TocResponse implements TocResponseHandler {
public static final String RESPONSE_TYPE = "ERROR";
int errorCode; int errorCode;
String errorText; String errorText;
public static final String RESPONSE_TYPE="ERROR"; /**
* Creates new ErrorTocResponse
/** Creates new ErrorTocResponse */ */
public ErrorTocResponse() { public ErrorTocResponse() {
errorCode = 0; errorCode = 0;
errorText = ""; errorText = "";
} }
/**
* Obtain the error message that corresponds to the specified error code
*
* @param code The error code
* @return The error text
*/
static public String getErrorDescription(int code) {
try {
return (java.util.ResourceBundle.getBundle("com/wilko/jaim/TocErrorDescriptions").getString(Integer.toString(code)));
} catch (MissingResourceException e) {
return ("Unable to locate error description:" + e);
}
}
/** Parse the error response string sent by the TOC server /**
* Parse the error response string sent by the TOC server
*
* @param str The error response string * @param str The error response string
*/ */
public TocResponse parseString(String str) public TocResponse parseString(String str) {
{
ErrorTocResponse tr = new ErrorTocResponse(); ErrorTocResponse tr = new ErrorTocResponse();
tr.doParse(str); tr.doParse(str);
return (tr); return (tr);
} }
private void doParse(String str) private void doParse(String str) {
{
cmd = str; cmd = str;
int colonPos = str.indexOf(':'); int colonPos = str.indexOf(':');
if (colonPos!=-1) if (colonPos != -1) {
{
str = str.substring(colonPos + 1); str = str.substring(colonPos + 1);
colonPos = str.indexOf(':'); colonPos = str.indexOf(':');
if (colonPos!=-1) if (colonPos != -1) {
{
errorCode = Integer.parseInt(str.substring(0, colonPos)); errorCode = Integer.parseInt(str.substring(0, colonPos));
errorText = str.substring(colonPos + 1); errorText = str.substring(colonPos + 1);
} } else {
else
{
errorCode = Integer.parseInt(str); errorCode = Integer.parseInt(str);
} }
} }
} }
/** Obtain the error code for this response /**
* Obtain the error code for this response
*
* @return The error code * @return The error code
*/ */
public int getErrorCode() public int getErrorCode() {
{
return (errorCode); return (errorCode);
} }
/** Get the error text (if any) associated with this error response /**
* Get the error text (if any) associated with this error response
*
* @return The error text * @return The error text
*/ */
public String getErrorText() public String getErrorText() {
{
return (errorText); return (errorText);
} }
/**
/** Obtain the error message that corresponds to this error. * Obtain the error message that corresponds to this error.
*
* @return The error text with any applicable error argument text inserted * @return The error text with any applicable error argument text inserted
*/ */
public String getErrorDescription() { public String getErrorDescription() {
@ -108,25 +122,8 @@ public class ErrorTocResponse extends TocResponse implements TocResponseHandler
} }
return (desc.toString()); return (desc.toString());
} } catch (MissingResourceException e) {
catch (MissingResourceException e) { return ("Unable to locate error description:" + e);
return("Unable to locate error description:"+e.toString());
}
}
/** Obtain the error message that corresponds to the specified error code
* @param code The error code
* @return The error text
*/
static public String getErrorDescription(int code)
{
try
{
return(java.util.ResourceBundle.getBundle("com/wilko/jaim/TocErrorDescriptions").getString(Integer.toString(code)));
}
catch (MissingResourceException e)
{
return("Unable to locate error description:"+e.toString());
} }
} }
@ -134,7 +131,9 @@ public class ErrorTocResponse extends TocResponse implements TocResponseHandler
return RESPONSE_TYPE; return RESPONSE_TYPE;
} }
/** Returns true if this response handler can handle the specified response. /**
* Returns true if this response handler can handle the specified response.
*
* @param Response - the response string from TOC. This is the part of the response before the first ':' * @param Response - the response string from TOC. This is the part of the response before the first ':'
* @return true if the response can be handled * @return true if the response can be handled
*/ */

View file

@ -27,26 +27,31 @@ package com.wilko.jaim;
import java.util.StringTokenizer; import java.util.StringTokenizer;
/** An EvilTocResponse is delivered to a {@link JaimEventListener } when the signed on buddy is "eviled" or warned /**
* An EvilTocResponse is delivered to a {@link JaimEventListener } when the signed on buddy is "eviled" or warned
*
* @author paulw * @author paulw
* @version $Revision: 1.6 $ * @version $Revision: 1.6 $
*/ */
public class EvilTocResponse extends TocResponse implements TocResponseHandler { public class EvilTocResponse extends TocResponse implements TocResponseHandler {
public static final String RESPONSE_TYPE = "EVILED";
private boolean anonymousEvil; private boolean anonymousEvil;
private int evilAmount; private int evilAmount;
private String evilBy; private String evilBy;
public static final String RESPONSE_TYPE="EVILED"; /**
* Creates new EvilTocResponse
/** Creates new EvilTocResponse */ */
public EvilTocResponse() { public EvilTocResponse() {
anonymousEvil = true; anonymousEvil = true;
evilBy = ""; evilBy = "";
evilAmount = 0; evilAmount = 0;
} }
/** Parse the evil message from the TOC server /**
* Parse the evil message from the TOC server
*
* @param str The evil message * @param str The evil message
*/ */
public TocResponse parseString(java.lang.String str) { public TocResponse parseString(java.lang.String str) {
@ -55,50 +60,51 @@ public class EvilTocResponse extends TocResponse implements TocResponseHandler {
return (tr); return (tr);
} }
private void doParse(String str) private void doParse(String str) {
{
StringTokenizer st = new StringTokenizer(str, ":"); StringTokenizer st = new StringTokenizer(str, ":");
st.nextToken(); // skip over "EVILED" st.nextToken(); // skip over "EVILED"
evilAmount = Integer.parseInt(st.nextToken()); evilAmount = Integer.parseInt(st.nextToken());
if (st.hasMoreTokens()) if (st.hasMoreTokens()) {
{
evilBy = st.nextToken(); evilBy = st.nextToken();
anonymousEvil = false; anonymousEvil = false;
} } else {
else
{
anonymousEvil = true; anonymousEvil = true;
} }
} }
/** Get the evil amount from this response. This is the current evil or warning level for the authenticated buddy, not the increment specified by the last warning /**
* Get the evil amount from this response. This is the current evil or warning level for the authenticated buddy, not the increment specified by the last warning
*
* @return The cumulative evil or warning level * @return The cumulative evil or warning level
*/ */
public int getEvilAmount() public int getEvilAmount() {
{
return (evilAmount); return (evilAmount);
} }
/** Obtain the name of the buddy that issued the warning. /**
* Obtain the name of the buddy that issued the warning.
*
* @return The buddy name that issued the warning * @return The buddy name that issued the warning
* @see #isAnonymous * @see #isAnonymous
*/ */
public String getEvilBy() public String getEvilBy() {
{
return (evilBy); return (evilBy);
} }
/** Obtain the anonymous status of this warning /**
* Obtain the anonymous status of this warning
*
* @return true if this warning was issued anonymously * @return true if this warning was issued anonymously
*/ */
public boolean isAnonymous() public boolean isAnonymous() {
{
return (anonymousEvil); return (anonymousEvil);
} }
/** Used by the response dispatcher /**
* Used by the response dispatcher
*
* @return The response type * @return The response type
*/ */
public String getResponseType() { public String getResponseType() {
@ -106,7 +112,9 @@ public class EvilTocResponse extends TocResponse implements TocResponseHandler {
} }
/** Returns true if this response handler can handle the specified response. /**
* Returns true if this response handler can handle the specified response.
*
* @param Response - the response string from TOC. This is the part of the response before the first ':' * @param Response - the response string from TOC. This is the part of the response before the first ':'
* @return true if the response can be handled * @return true if the response can be handled
*/ */

View file

@ -26,7 +26,6 @@
package com.wilko.jaim; package com.wilko.jaim;
/** /**
*
* @author paulw * @author paulw
* @version $Revision: 1.3 $ * @version $Revision: 1.3 $
*/ */
@ -34,15 +33,16 @@ public class FLAPDataFrame extends FLAPFrame {
private int frameLen; private int frameLen;
/** Creates new FlapDataFrame */ /**
* Creates new FlapDataFrame
*/
public FLAPDataFrame() { public FLAPDataFrame() {
frame[1] = FLAP_FRAME_DATA; frame[1] = FLAP_FRAME_DATA;
frameLen = 1; frameLen = 1;
frame[FLAP_DATA_OFFSET] = 0; frame[FLAP_DATA_OFFSET] = 0;
} }
public FLAPDataFrame(byte frameData[]) public FLAPDataFrame(byte[] frameData) {
{
frame[1] = FLAP_FRAME_DATA; frame[1] = FLAP_FRAME_DATA;
frameLen = 1; frameLen = 1;
frame[FLAP_DATA_OFFSET] = 0; frame[FLAP_DATA_OFFSET] = 0;
@ -54,19 +54,16 @@ public class FLAPDataFrame extends FLAPFrame {
return (FLAPFrame.FLAP_FRAME_DATA); return (FLAPFrame.FLAP_FRAME_DATA);
} }
public void addString(String s) public void addString(String s) {
{
frameLen--; // Backspace over '0' frameLen--; // Backspace over '0'
for (int i=0;i<s.length();i++) for (int i = 0; i < s.length(); i++) {
{
frame[FLAP_DATA_OFFSET + frameLen++] = (byte) s.charAt(i); frame[FLAP_DATA_OFFSET + frameLen++] = (byte) s.charAt(i);
} }
frame[FLAP_DATA_OFFSET + frameLen++] = 0; frame[FLAP_DATA_OFFSET + frameLen++] = 0;
setLength(frameLen); setLength(frameLen);
} }
public byte[] getContent() public byte[] getContent() {
{
byte[] retarray = new byte[getLength()]; byte[] retarray = new byte[getLength()];
System.arraycopy(frame, FLAPFrame.FLAP_DATA_OFFSET, retarray, 0, getLength()); System.arraycopy(frame, FLAPFrame.FLAP_DATA_OFFSET, retarray, 0, getLength());

View file

@ -25,20 +25,20 @@
package com.wilko.jaim; package com.wilko.jaim;
/** /**
*
* @author paulw * @author paulw
* @version $Revision: 1.3 $ * @version $Revision: 1.3 $
*/ */
public class FLAPErrorFrame extends FLAPFrame { public class FLAPErrorFrame extends FLAPFrame {
/** Creates new FLAPErrorFrame */ /**
* Creates new FLAPErrorFrame
*/
public FLAPErrorFrame() { public FLAPErrorFrame() {
frame[1] = FLAP_FRAME_ERROR; frame[1] = FLAP_FRAME_ERROR;
} }
public FLAPErrorFrame(byte frameData[]) public FLAPErrorFrame(byte[] frameData) {
{
frame[1] = FLAP_FRAME_ERROR; frame[1] = FLAP_FRAME_ERROR;
setFrameData(frameData); setFrameData(frameData);
} }

View file

@ -26,7 +26,6 @@
package com.wilko.jaim; package com.wilko.jaim;
/** /**
*
* @author paulw * @author paulw
* @version $Revision: 1.4 $ * @version $Revision: 1.4 $
*/ */
@ -42,20 +41,14 @@ public abstract class FLAPFrame {
protected byte[] frame; protected byte[] frame;
protected int fLen; protected int fLen;
/** Creates new FLAPFrame */ /**
* Creates new FLAPFrame
*/
public FLAPFrame() { public FLAPFrame() {
initialise(); initialise();
} }
protected void setFrameData(byte b[]) protected void initialise() {
{
frame=new byte[b.length];
fLen=b.length;
System.arraycopy(b,0,frame,0,b.length);
}
protected void initialise()
{
frame = new byte[8192]; frame = new byte[8192];
frame[0] = (byte) '*'; frame[0] = (byte) '*';
frame[1] = 0; frame[1] = 0;
@ -67,53 +60,50 @@ public abstract class FLAPFrame {
} }
public void setSequence(int sequence) public int getSequence() {
{ return ((frame[2] & 0xff) * 256 + (frame[3] & 0xff));
}
public void setSequence(int sequence) {
frame[2] = (byte) ((sequence / 256) & 0xff); frame[2] = (byte) ((sequence / 256) & 0xff);
frame[3] = (byte) (sequence & 0xff); frame[3] = (byte) (sequence & 0xff);
} }
public int getSequence() public int getLength() {
{
return((frame[2]&0xff)*256+(frame[3]&0xff));
}
public int getLength()
{
return ((frame[4] & 0xff) * 256 + (frame[5] & 0xff)); return ((frame[4] & 0xff) * 256 + (frame[5] & 0xff));
} }
public void setLength(int length) public void setLength(int length) {
{
frame[4] = (byte) (length / 256); frame[4] = (byte) (length / 256);
frame[5] = (byte) (length & 0xff); frame[5] = (byte) (length & 0xff);
fLen = length + FLAP_DATA_OFFSET; fLen = length + FLAP_DATA_OFFSET;
} }
public byte[] getFrameData() public byte[] getFrameData() {
{
byte[] b = new byte[fLen]; byte[] b = new byte[fLen];
System.arraycopy(frame, 0, b, 0, fLen); System.arraycopy(frame, 0, b, 0, fLen);
return (b); return (b);
} }
public String toString() protected void setFrameData(byte[] b) {
{ frame = new byte[b.length];
StringBuffer temp=new StringBuffer(); fLen = b.length;
for (int i=0;i<fLen;i++) System.arraycopy(b, 0, frame, 0, b.length);
{
int k=frame[i]&0xff;
if (k<16)
{
temp.append("0"+Integer.toHexString(k)+" ");
} }
else
{ public String toString() {
StringBuffer temp = new StringBuffer();
for (int i = 0; i < fLen; i++) {
int k = frame[i] & 0xff;
if (k < 16) {
temp.append("0" + Integer.toHexString(k) + " ");
} else {
temp.append(Integer.toHexString(k) + " "); temp.append(Integer.toHexString(k) + " ");
} }
} }
return (temp.toString()); return (temp.toString());
} }
public abstract int getFLAPFrameType(); public abstract int getFLAPFrameType();
} }

View file

@ -26,7 +26,6 @@
package com.wilko.jaim; package com.wilko.jaim;
/** /**
*
* @author paulw * @author paulw
* @version $Revision: 1.3 $ * @version $Revision: 1.3 $
*/ */
@ -41,6 +40,7 @@ public class FLAPFrameException extends java.lang.Exception {
/** /**
* Constructs an <code>FLAPFrameException</code> with the specified detail message. * Constructs an <code>FLAPFrameException</code> with the specified detail message.
*
* @param msg the detail message. * @param msg the detail message.
*/ */
public FLAPFrameException(String msg) { public FLAPFrameException(String msg) {

View file

@ -26,25 +26,24 @@
package com.wilko.jaim; package com.wilko.jaim;
/** /**
*
* @author paulw * @author paulw
* @version $Revision: 1.3 $ * @version $Revision: 1.3 $
*/ */
public abstract class FLAPFrameFactory { public abstract class FLAPFrameFactory {
/** Creates new FLAPFrameFactory */ /**
* Creates new FLAPFrameFactory
*/
public FLAPFrameFactory() { public FLAPFrameFactory() {
} }
public static FLAPFrame createFLAPFrame(byte[] frameData) throws FLAPFrameException { public static FLAPFrame createFLAPFrame(byte[] frameData) throws FLAPFrameException {
FLAPFrame f = null; FLAPFrame f = null;
if (frameData[0]!='*') if (frameData[0] != '*') {
{
throw new FLAPFrameException("Frame does not start with '*'"); throw new FLAPFrameException("Frame does not start with '*'");
} }
switch (frameData[1]) switch (frameData[1]) {
{
case FLAPFrame.FLAP_FRAME_SIGNON: case FLAPFrame.FLAP_FRAME_SIGNON:
f = new FLAPSignonFrame(frameData); f = new FLAPSignonFrame(frameData);
break; break;

View file

@ -26,13 +26,14 @@
package com.wilko.jaim; package com.wilko.jaim;
/** /**
*
* @author paulw * @author paulw
* @version $Revision: 1.3 $ * @version $Revision: 1.3 $
*/ */
public class FLAPInputFrame extends FLAPFrame { public class FLAPInputFrame extends FLAPFrame {
/** Creates new FLAPInputFrame */ /**
* Creates new FLAPInputFrame
*/
private int frameLen; private int frameLen;
public FLAPInputFrame() { public FLAPInputFrame() {
@ -40,31 +41,23 @@ public class FLAPInputFrame extends FLAPFrame {
super.initialise(); super.initialise();
} }
public void addFrameData(byte b) public void addFrameData(byte b) {
{
frame[frameLen++] = b; frame[frameLen++] = b;
} }
public byte[] getFrameData() public byte[] getFrameData() {
{
byte[] b = new byte[frameLen]; byte[] b = new byte[frameLen];
System.arraycopy(frame, 0, b, 0, frameLen); System.arraycopy(frame, 0, b, 0, frameLen);
return (b); return (b);
} }
public void resetInputFrame() public void resetInputFrame() {
{
frameLen = 0; frameLen = 0;
} }
public boolean completeFrameRead() public boolean completeFrameRead() {
{ if (frameLen > 5) {
if (frameLen > 5) return frameLen - 6 == getLength();
{
if (frameLen-6 == getLength())
{
return(true);
}
} }
return (false); return (false);
} }

View file

@ -26,25 +26,24 @@
package com.wilko.jaim; package com.wilko.jaim;
/** /**
*
* @author paulw * @author paulw
* @version $Revision: 1.4 $ * @version $Revision: 1.4 $
*/ */
public class FLAPKeepAliveFrame extends FLAPFrame { public class FLAPKeepAliveFrame extends FLAPFrame {
/** Creates new FLAPKeepAliveFrame */ /**
* Creates new FLAPKeepAliveFrame
*/
public FLAPKeepAliveFrame() { public FLAPKeepAliveFrame() {
this.initialise(); this.initialise();
} }
public FLAPKeepAliveFrame(byte frameData[]) public FLAPKeepAliveFrame(byte[] frameData) {
{
initialise(); initialise();
setFrameData(frameData); setFrameData(frameData);
} }
protected void initialise() protected void initialise() {
{
super.initialise(); super.initialise();
frame[1] = FLAP_FRAME_KEEP_ALIVE; frame[1] = FLAP_FRAME_KEEP_ALIVE;
} }

View file

@ -26,20 +26,20 @@
package com.wilko.jaim; package com.wilko.jaim;
/** /**
*
* @author paulw * @author paulw
* @version $Revision: 1.3 $ * @version $Revision: 1.3 $
*/ */
public class FLAPSignoffFrame extends FLAPFrame { public class FLAPSignoffFrame extends FLAPFrame {
/** Creates new FlapSignonFrame */ /**
* Creates new FlapSignonFrame
*/
public FLAPSignoffFrame() { public FLAPSignoffFrame() {
frame[1] = FLAP_FRAME_SIGNOFF; frame[1] = FLAP_FRAME_SIGNOFF;
} }
public FLAPSignoffFrame(byte frameData[]) public FLAPSignoffFrame(byte[] frameData) {
{
frame[1] = FLAP_FRAME_SIGNOFF; frame[1] = FLAP_FRAME_SIGNOFF;
setFrameData(frameData); setFrameData(frameData);
} }

View file

@ -26,55 +26,47 @@
package com.wilko.jaim; package com.wilko.jaim;
/** /**
*
* @author paulw * @author paulw
* @version $Revision: 1.3 $ * @version $Revision: 1.3 $
*/ */
public class FLAPSignonFrame extends FLAPFrame { public class FLAPSignonFrame extends FLAPFrame {
/** Creates new FlapSignonFrame */ /**
* Creates new FlapSignonFrame
*/
public FLAPSignonFrame() { public FLAPSignonFrame() {
frame[1] = FLAP_FRAME_SIGNON; frame[1] = FLAP_FRAME_SIGNON;
} }
public FLAPSignonFrame(byte frameData[]) public FLAPSignonFrame(byte[] frameData) {
{
frame[1] = FLAP_FRAME_SIGNON; frame[1] = FLAP_FRAME_SIGNON;
setFrameData(frameData); setFrameData(frameData);
} }
public int getFLAPVersion() public int getFLAPVersion() {
{
return (((frame[6] & 0xff) * 16777216) + ((frame[7] & 0xff) * 65536) + ((frame[8] & 0xff) * 256) + (frame[9] & 0xff)); return (((frame[6] & 0xff) * 16777216) + ((frame[7] & 0xff) * 65536) + ((frame[8] & 0xff) * 256) + (frame[9] & 0xff));
} }
public void setFLAPVersion(int version) public void setFLAPVersion(int version) {
{ for (int i = 3; i >= 0; i--) {
for (int i=3;i>=0;i--)
{
frame[6 + i] = (byte) (version & 0xff); frame[6 + i] = (byte) (version & 0xff);
version = version >> 8; version = version >> 8;
} }
} }
public void setTLVTag(int tag) public void setTLVTag(int tag) {
{ for (int i = 1; i >= 0; i--) {
for (int i=1;i>=0;i--)
{
frame[10 + i] = (byte) (tag & 0xff); frame[10 + i] = (byte) (tag & 0xff);
tag = tag >> 8; tag = tag >> 8;
} }
} }
public void setUserName(String name) public void setUserName(String name) {
{
int len = 0; int len = 0;
for (int i=0;i<name.length();i++) for (int i = 0; i < name.length(); i++) {
{
char c = name.charAt(i); char c = name.charAt(i);
if (c != ' ') if (c != ' ') {
{
frame[FLAP_DATA_OFFSET + 8 + len++] = (byte) c; frame[FLAP_DATA_OFFSET + 8 + len++] = (byte) c;
} }
} }

View file

@ -25,56 +25,66 @@
package com.wilko.jaim; package com.wilko.jaim;
/** A GenericTocResponse is used internally in the Response parsing and processing logic of {@link JaimConnection} /**
* A GenericTocResponse is used internally in the Response parsing and processing logic of {@link JaimConnection}
*
* @author paulw * @author paulw
* @version $Revision: 1.5 $ * @version $Revision: 1.5 $
*/ */
public class GenericTocResponse extends TocResponse implements TocResponseHandler { public class GenericTocResponse extends TocResponse implements TocResponseHandler {
/** Creates new GenericTocCommand */ /**
* Creates new GenericTocCommand
*/
public GenericTocResponse() { public GenericTocResponse() {
this.cmd = ""; this.cmd = "";
} }
/** Parse an incoming string /**
* Parse an incoming string
*
* @param str The response string to be parsed * @param str The response string to be parsed
*/ */
public TocResponse parseString(String str) public TocResponse parseString(String str) {
{
GenericTocResponse tr = new GenericTocResponse(); GenericTocResponse tr = new GenericTocResponse();
tr.doParse(str); tr.doParse(str);
return tr; return tr;
} }
private void doParse(String str) private void doParse(String str) {
{
cmd = str; cmd = str;
} }
/** Get a byte array that contains the response /**
* Get a byte array that contains the response
*
* @return The response as an array of bytes * @return The response as an array of bytes
*/ */
public byte[] getBytes() { public byte[] getBytes() {
return (cmd.getBytes()); return (cmd.getBytes());
} }
/** Convert this response to a string /**
* Convert this response to a string
*
* @return The response as a string * @return The response as a string
*/ */
public String toString() public String toString() {
{
return (cmd); return (cmd);
} }
/** Used in the response dispatching process /**
* Used in the response dispatching process
*
* @return The respnse type * @return The respnse type
*/ */
public String getResponseType() public String getResponseType() {
{
return ("UNKNOWN"); return ("UNKNOWN");
} }
/** Returns true if this response handler can handle the specified response. /**
* Returns true if this response handler can handle the specified response.
*
* @param Response - the response string from TOC. This is the part of the response before the first ':' * @param Response - the response string from TOC. This is the part of the response before the first ':'
* @return true if the response can be handled * @return true if the response can be handled
*/ */

View file

@ -25,43 +25,49 @@
package com.wilko.jaim; package com.wilko.jaim;
/** This response is delivered to a {@link JaimEventListener } when a GOTO response is received from TOC /**
* This response is delivered to a {@link JaimEventListener } when a GOTO response is received from TOC
*
* @author paulw * @author paulw
* @version $Revision: 1.3 $ * @version $Revision: 1.3 $
*/ */
public class GotoTocResponse extends TocResponse implements TocResponseHandler { public class GotoTocResponse extends TocResponse implements TocResponseHandler {
public static final String RESPONSE_TYPE = "GOTO_URL";
String windowName; String windowName;
boolean autoResponse; boolean autoResponse;
String URL; String URL;
public static final String RESPONSE_TYPE="GOTO_URL"; /**
* Creates new GotoTocResponse
/** Creates new GotoTocResponse */ */
public GotoTocResponse() { public GotoTocResponse() {
windowName = ""; windowName = "";
URL = ""; URL = "";
} }
/** Obtain the suggested window name for this URL /**
* Obtain the suggested window name for this URL
*
* @return The window name * @return The window name
*/ */
public String getWindowName() public String getWindowName() {
{
return (windowName); return (windowName);
} }
/** Obtain the URL /**
* Obtain the URL
*
* @return The URL * @return The URL
*/ */
public String getURL() public String getURL() {
{
return (URL); return (URL);
} }
/**
/** Parse an incoming response string * Parse an incoming response string
*
* @param str The string to be parsed * @param str The string to be parsed
*/ */
public TocResponse parseString(java.lang.String str) { public TocResponse parseString(java.lang.String str) {
@ -70,16 +76,13 @@ public class GotoTocResponse extends TocResponse implements TocResponseHandler {
return (tr); return (tr);
} }
private void doParse(String str) private void doParse(String str) {
{
cmd = str; cmd = str;
int colonPos = str.indexOf(':'); int colonPos = str.indexOf(':');
if (colonPos!=-1) if (colonPos != -1) {
{
str = str.substring(colonPos + 1); str = str.substring(colonPos + 1);
colonPos = str.indexOf(':'); colonPos = str.indexOf(':');
if (colonPos != -1) if (colonPos != -1) {
{
windowName = str.substring(0, colonPos); windowName = str.substring(0, colonPos);
URL = str.substring(colonPos + 1); URL = str.substring(colonPos + 1);
@ -88,14 +91,18 @@ public class GotoTocResponse extends TocResponse implements TocResponseHandler {
} }
/** Obtain the response type for response dispatching purposes /**
* Obtain the response type for response dispatching purposes
*
* @return The response type * @return The response type
*/ */
public String getResponseType() { public String getResponseType() {
return (RESPONSE_TYPE); return (RESPONSE_TYPE);
} }
/** Returns true if this response handler can handle the specified response. /**
* Returns true if this response handler can handle the specified response.
*
* @param Response - the response string from TOC. This is the part of the response before the first ':' * @param Response - the response string from TOC. This is the part of the response before the first ':'
* @return true if the response can be handled * @return true if the response can be handled
*/ */

View file

@ -25,71 +25,89 @@
package com.wilko.jaim; package com.wilko.jaim;
import java.util.Vector;
import java.util.List;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.Vector;
/** This is a logical user group. It holds a set of users. /**
* This is a logical user group. It holds a set of users.
*
* @author Brett Humphreys * @author Brett Humphreys
*/ */
public class Group { public class Group {
/** Vector of buddies for this group */ /**
private Vector buddies = new Vector(); * Vector of buddies for this group
*/
private final Vector buddies = new Vector();
/** Name of this group */ /**
private String groupName; * Name of this group
*/
private final String groupName;
/** This constructor sets the name of the group /**
* This constructor sets the name of the group
*
* @param name the group name * @param name the group name
*/ */
public Group(String name) { public Group(String name) {
groupName = name; groupName = name;
} }
/** This method adds a buddy to the end of the group /**
* This method adds a buddy to the end of the group
*
* @param buddy The buddy object to associate with this group * @param buddy The buddy object to associate with this group
*/ */
public void addBuddy(Buddy buddy) { public void addBuddy(Buddy buddy) {
buddies.add(buddy); buddies.add(buddy);
} }
/** This method adds a buddy to the specified location in the group /**
* This method adds a buddy to the specified location in the group
* If the specified location is beyond the end of the group, then the buddy is added to the end of the group * If the specified location is beyond the end of the group, then the buddy is added to the end of the group
*
* @param buddy The buddy object to associate with this group * @param buddy The buddy object to associate with this group
* @param pos the position to add the buddy * @param pos the position to add the buddy
*/ */
public void addBuddy(Buddy buddy, int pos) { public void addBuddy(Buddy buddy, int pos) {
if (pos > buddies.size()) { if (pos > buddies.size()) {
buddies.add(buddy); buddies.add(buddy);
} } else {
else {
buddies.add(pos, buddy); buddies.add(pos, buddy);
} }
} }
/** This method gets the group name /**
* This method gets the group name
*
* @return the group name * @return the group name
*/ */
public String getName() { public String getName() {
return groupName; return groupName;
} }
/** This method returns the buddies in this group /**
* This method returns the buddies in this group
*
* @return an Enumeration of {@link Buddy} objects * @return an Enumeration of {@link Buddy} objects
*/ */
public Enumeration enumerateBuddies() { public Enumeration enumerateBuddies() {
return buddies.elements(); return buddies.elements();
} }
/** This method returns the number of buddies in this group /**
* This method returns the number of buddies in this group
*
* @return buddy count * @return buddy count
*/ */
public int getBuddyCount() { public int getBuddyCount() {
return (buddies.size()); return (buddies.size());
} }
/** This method returns the buddies in this group /**
* This method returns the buddies in this group
*
* @return a Collection of {@link Buddy} objects * @return a Collection of {@link Buddy} objects
*/ */
public java.util.Collection getBuddies() { public java.util.Collection getBuddies() {

View file

@ -25,51 +25,59 @@
package com.wilko.jaim; package com.wilko.jaim;
/** This response is delivered to a {@link JaimEventListener } when an instant message is received /**
* This response is delivered to a {@link JaimEventListener } when an instant message is received
*
* @author paulw * @author paulw
* @version $Revision: 1.6 $ * @version $Revision: 1.6 $
*/ */
public class IMTocResponse extends TocResponse implements TocResponseHandler { public class IMTocResponse extends TocResponse implements TocResponseHandler {
public static final String RESPONSE_TYPE = "IM_IN";
String from; String from;
boolean autoResponse; boolean autoResponse;
String msg; String msg;
public static final String RESPONSE_TYPE="IM_IN"; /**
* Creates new TocIMResponse
/** Creates new TocIMResponse */ */
public IMTocResponse() { public IMTocResponse() {
from = ""; from = "";
msg = ""; msg = "";
autoResponse = false; autoResponse = false;
} }
/** Obtain the name of the buddy who sent this instant message /**
* Obtain the name of the buddy who sent this instant message
*
* @return The senders name * @return The senders name
*/ */
public String getFrom() public String getFrom() {
{
return (from); return (from);
} }
/** Obtain the message /**
* Obtain the message
*
* @return The message * @return The message
* @see Utils#stripHTML * @see Utils#stripHTML
*/ */
public String getMsg() public String getMsg() {
{
return (msg); return (msg);
} }
/** Is this response an automatically generated response? /**
* Is this response an automatically generated response?
*
* @return true if this is an automatically generated response * @return true if this is an automatically generated response
*/ */
public boolean getAutoResponse() public boolean getAutoResponse() {
{
return (autoResponse); return (autoResponse);
} }
/** Parse an incoming IM response string /**
* Parse an incoming IM response string
*
* @param str The string to be parsed * @param str The string to be parsed
*/ */
public TocResponse parseString(java.lang.String str) { public TocResponse parseString(java.lang.String str) {
@ -78,25 +86,20 @@ public class IMTocResponse extends TocResponse implements TocResponseHandler {
return (tr); return (tr);
} }
private void doParse(String str) private void doParse(String str) {
{
cmd = str; cmd = str;
int colonPos = str.indexOf(':'); int colonPos = str.indexOf(':');
if (colonPos!=-1) if (colonPos != -1) {
{
str = str.substring(colonPos + 1); str = str.substring(colonPos + 1);
colonPos = str.indexOf(':'); colonPos = str.indexOf(':');
if (colonPos != -1) if (colonPos != -1) {
{
from = str.substring(0, colonPos); from = str.substring(0, colonPos);
str = str.substring(colonPos + 1); str = str.substring(colonPos + 1);
colonPos = str.indexOf(':'); colonPos = str.indexOf(':');
if (str.charAt(0) == 'T') if (str.charAt(0) == 'T') {
{
autoResponse = true; autoResponse = true;
} }
if (colonPos != -1) if (colonPos != -1) {
{
msg = str.substring(colonPos + 1); msg = str.substring(colonPos + 1);
} }
} }
@ -104,14 +107,18 @@ public class IMTocResponse extends TocResponse implements TocResponseHandler {
} }
/** Obtain the response type for response dispatching purposes /**
* Obtain the response type for response dispatching purposes
*
* @return The response type * @return The response type
*/ */
public String getResponseType() { public String getResponseType() {
return (RESPONSE_TYPE); return (RESPONSE_TYPE);
} }
/** Returns true if this response handler can handle the specified response. /**
* Returns true if this response handler can handle the specified response.
*
* @param Response - the response string from TOC. This is the part of the response before the first ':' * @param Response - the response string from TOC. This is the part of the response before the first ':'
* @return true if the response can be handled * @return true if the response can be handled
*/ */

View file

@ -25,21 +25,31 @@
package com.wilko.jaim; package com.wilko.jaim;
import java.net.*; import java.io.IOException;
import java.io.InputStream;
import java.io.InterruptedIOException;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.Socket;
import java.net.URL;
import java.text.DateFormat; import java.text.DateFormat;
import java.io.*;
import java.util.*; import java.util.*;
/** The JaimConnection object is the primary interface into the Jaim library. /**
* The JaimConnection object is the primary interface into the Jaim library.
* Programs should instantiate a JaimConnection (in most cases the simple constructor should be used). * Programs should instantiate a JaimConnection (in most cases the simple constructor should be used).
* Once JaimConnection has been instantiated, call {@link #connect} followed by {@link #logIn}. * Once JaimConnection has been instantiated, call {@link #connect} followed by {@link #logIn}.
* *
*
* @author paulw * @author paulw
* @version $Revision: 1.20 $ * @version $Revision: 1.20 $
*/ */
public class JaimConnection implements java.lang.Runnable { public class JaimConnection implements java.lang.Runnable {
private static final int MAX_POINTS = 10;
private static final int BLOCK_POINTS = 5;
private static final int POINT_RECOVERY_TIME = 2200; // Recover one point every 2.2 seconds
private static final int THRESHOLD_DELAY = 5000; // Delay when we are threshold of being blocked
private static final int WAIT_TIME = 61000; // Wait 61 secs for a keep alive
private Socket s; private Socket s;
private InputStream sin; private InputStream sin;
private OutputStream sout; private OutputStream sout;
@ -47,8 +57,8 @@ public class JaimConnection implements java.lang.Runnable {
private boolean loggedIn; private boolean loggedIn;
private boolean loginComplete; private boolean loginComplete;
private boolean configValid; private boolean configValid;
private String host; private final String host;
private int port; private final int port;
private int clientSequence; private int clientSequence;
private int serverSequence; private int serverSequence;
private ReceiverThread rt; private ReceiverThread rt;
@ -64,19 +74,11 @@ public class JaimConnection implements java.lang.Runnable {
private Vector messageQueue; private Vector messageQueue;
private boolean exit; private boolean exit;
private long lastKeepAlive; private long lastKeepAlive;
// Number of send "points" - used to control send rate // Number of send "points" - used to control send rate
private int sendPoints = 10; private int sendPoints = 10;
/**
private static final int MAX_POINTS=10; * Creates new JaimConnection that connects to the default host and port.
private static final int BLOCK_POINTS=5;
private static final int POINT_RECOVERY_TIME=2200; // Recover one point every 2.2 seconds
private static final int THRESHOLD_DELAY=5000; // Delay when we are threshold of being blocked
private static final int WAIT_TIME=61000; // Wait 61 secs for a keep alive
/** Creates new JaimConnection that connects to the default host and port.
* In most cases this constructor should be used. * In most cases this constructor should be used.
*/ */
public JaimConnection() { public JaimConnection() {
@ -86,8 +88,10 @@ public class JaimConnection implements java.lang.Runnable {
} }
/** Creates a new Jaim Connection to the specified host/port. /**
* Creates a new Jaim Connection to the specified host/port.
* There are currently no reasons to call this constructor, however AOL may change the TOC host and port in the future * There are currently no reasons to call this constructor, however AOL may change the TOC host and port in the future
*
* @param host The hostname or IP address of the TOC server * @param host The hostname or IP address of the TOC server
* @param port The port number to connect to on the host * @param port The port number to connect to on the host
*/ */
@ -97,7 +101,8 @@ public class JaimConnection implements java.lang.Runnable {
startMe(); startMe();
} }
/** start the message dispatcher thread /**
* start the message dispatcher thread
*/ */
private void startMe() { private void startMe() {
@ -133,8 +138,9 @@ public class JaimConnection implements java.lang.Runnable {
} }
/**
/** Enable/Disable debugging messages to stdout * Enable/Disable debugging messages to stdout
*
* @param debug true if debugging messages should be output * @param debug true if debugging messages should be output
*/ */
@ -142,17 +148,9 @@ public class JaimConnection implements java.lang.Runnable {
this.debug = debug; this.debug = debug;
} }
/**
/** Specify the intermessage delay time. <br> * Get the intermessage delay time
* The {@link #sendIM } method will ensure that at least this amount of time has elapsed between messages *
* @param msec The delay period in milliseconds
* @deprecated This function is no longer used - send throttling is automatic
*/
public void setInterMessageDelay(long msec) {
}
/** Get the intermessage delay time
* @return The intermessage delay time in milliseconds * @return The intermessage delay time in milliseconds
* @deprecated This function is no longer used * @deprecated This function is no longer used
*/ */
@ -160,7 +158,20 @@ public class JaimConnection implements java.lang.Runnable {
return (0); return (0);
} }
/** Set the EventListener object. This object will be notified of incoming TOC events /**
* Specify the intermessage delay time. <br>
* The {@link #sendIM } method will ensure that at least this amount of time has elapsed between messages
*
* @param msec The delay period in milliseconds
* @deprecated This function is no longer used - send throttling is automatic
*/
public void setInterMessageDelay(long msec) {
}
/**
* Set the EventListener object. This object will be notified of incoming TOC events
*
* @param l The listener class to be notified * @param l The listener class to be notified
* @deprecated replaced by {@link #addEventListener} * @deprecated replaced by {@link #addEventListener}
*/ */
@ -168,7 +179,9 @@ public class JaimConnection implements java.lang.Runnable {
eventListeners.add(l); eventListeners.add(l);
} }
/** Add an EventListener object. This object will be notified of incoming TOC events /**
* Add an EventListener object. This object will be notified of incoming TOC events
*
* @param l The listener class to be notified * @param l The listener class to be notified
*/ */
@ -176,7 +189,9 @@ public class JaimConnection implements java.lang.Runnable {
eventListeners.add(l); eventListeners.add(l);
} }
/** Remove an EventListener object. This object will no longer be notified of incoming TOC events /**
* Remove an EventListener object. This object will no longer be notified of incoming TOC events
*
* @param l The listener class to be removed * @param l The listener class to be removed
*/ */
@ -185,7 +200,9 @@ public class JaimConnection implements java.lang.Runnable {
} }
/** Initiate a connection to the TOC server /**
* Initiate a connection to the TOC server
*
* @throws IOException If an underlying network communication fails * @throws IOException If an underlying network communication fails
*/ */
public void connect() throws IOException { public void connect() throws IOException {
@ -215,9 +232,8 @@ public class JaimConnection implements java.lang.Runnable {
} }
clientSequence = sf.getSequence(); clientSequence = sf.getSequence();
serverSequence = sf.getSequence(); serverSequence = sf.getSequence();
} } catch (FLAPFrameException e) {
catch (FLAPFrameException e) { throw new IOException("FLAPFrameException:" + e);
throw new IOException("FLAPFrameException:"+e.toString());
} }
if (rt != null) { if (rt != null) {
rt.pleaseExit(); rt.pleaseExit();
@ -229,7 +245,9 @@ public class JaimConnection implements java.lang.Runnable {
connected = true; connected = true;
} }
/** Disconnect from the TOC server /**
* Disconnect from the TOC server
*
* @throws IOException if a network transport error occurs * @throws IOException if a network transport error occurs
*/ */
public void disconnect() throws IOException { public void disconnect() throws IOException {
@ -238,8 +256,7 @@ public class JaimConnection implements java.lang.Runnable {
try { try {
rt.join(700); rt.join(700);
myThread.join(700); myThread.join(700);
} } catch (InterruptedException e) {
catch (InterruptedException e) {
} }
if (connected) { if (connected) {
@ -252,14 +269,17 @@ public class JaimConnection implements java.lang.Runnable {
} }
/** Check if the TOC login process has completed /**
* Check if the TOC login process has completed
*
* @return true if the login process is complete * @return true if the login process is complete
*/ */
public boolean isLoginComplete() { public boolean isLoginComplete() {
return (loginComplete); return (loginComplete);
} }
/** Log out from the TOC server /**
* Log out from the TOC server
*/ */
public void logOut() { public void logOut() {
loggedIn = false; loggedIn = false;
@ -268,14 +288,18 @@ public class JaimConnection implements java.lang.Runnable {
} }
/** Get the formatted Nick Name for this connection. If no formatted nick name has been registered with the TOC server, then the username provided to the logIn call is returned /**
* Get the formatted Nick Name for this connection. If no formatted nick name has been registered with the TOC server, then the username provided to the logIn call is returned
*
* @return The Nick Name associated with this connection * @return The Nick Name associated with this connection
*/ */
public String getNickName() { public String getNickName() {
return (nickName); return (nickName);
} }
/** login to the TOC server. {@link #connect() } method should be called first /**
* login to the TOC server. {@link #connect() } method should be called first
*
* @param username The username to log in with * @param username The username to log in with
* @param password the password for the specified username * @param password the password for the specified username
* @param waitTime time in milliseconds for successful login before declaring an error * @param waitTime time in milliseconds for successful login before declaring an error
@ -300,25 +324,20 @@ public class JaimConnection implements java.lang.Runnable {
if (loginComplete || !connected) // Have we logged in successfully if (loginComplete || !connected) // Have we logged in successfully
{ {
break; // If so then return break; // If so then return
} } else {
else {
try { try {
Thread.sleep(100); //Sleep for a tenth of a second Thread.sleep(100); //Sleep for a tenth of a second
} } catch (InterruptedException e) {
catch (InterruptedException e) {
} }
} }
} }
if (loginComplete) { if (loginComplete) {
loggedIn = true; loggedIn = true;
} } else {
else {
throw new JaimTimeoutException("login failed-timeout waiting for valid response"); throw new JaimTimeoutException("login failed-timeout waiting for valid response");
} }
} } else
else
throw new JaimStateException("Not connected."); throw new JaimStateException("Not connected.");
} }
@ -332,8 +351,7 @@ public class JaimConnection implements java.lang.Runnable {
sout.write(fr.getFrameData()); sout.write(fr.getFrameData());
} }
private int nextSequence() private int nextSequence() {
{
int seq = clientSequence++; int seq = clientSequence++;
if (clientSequence > 65535) if (clientSequence > 65535)
clientSequence = 0; clientSequence = 0;
@ -348,7 +366,9 @@ public class JaimConnection implements java.lang.Runnable {
} }
sout.write(fr.getFrameData()); sout.write(fr.getFrameData());
} }
/** The run method for the dispatcher thread
/**
* The run method for the dispatcher thread
*/ */
public void run() { public void run() {
@ -356,21 +376,15 @@ public class JaimConnection implements java.lang.Runnable {
if (messageQueue.size() > 0) { if (messageQueue.size() > 0) {
realDispatch((FLAPFrame) messageQueue.remove(0)); realDispatch((FLAPFrame) messageQueue.remove(0));
} } else {
else { if (System.currentTimeMillis() - lastKeepAlive > WAIT_TIME) {
if (System.currentTimeMillis()-lastKeepAlive>WAIT_TIME) if (debug) {
{
if (debug)
{
System.out.println("No keepalive received - sending"); System.out.println("No keepalive received - sending");
} }
try try {
{
sendKeepAlive(); sendKeepAlive();
lastKeepAlive = System.currentTimeMillis(); lastKeepAlive = System.currentTimeMillis();
} } catch (IOException ioe) {
catch (IOException ioe)
{
connectionLost(); connectionLost();
} }
} }
@ -379,8 +393,7 @@ public class JaimConnection implements java.lang.Runnable {
synchronized (this) { synchronized (this) {
this.wait(WAIT_TIME); this.wait(WAIT_TIME);
} }
} } catch (InterruptedException e) {
catch (InterruptedException e) {
} }
} }
} }
@ -400,8 +413,7 @@ public class JaimConnection implements java.lang.Runnable {
try { try {
disconnect(); disconnect();
} } catch (IOException e) {
catch (IOException e) {
} }
break; break;
case FLAPFrame.FLAP_FRAME_DATA: case FLAPFrame.FLAP_FRAME_DATA:
@ -415,12 +427,9 @@ public class JaimConnection implements java.lang.Runnable {
System.out.println("Received keep alive frame " + DateFormat.getTimeInstance().format(new Date())); System.out.println("Received keep alive frame " + DateFormat.getTimeInstance().format(new Date()));
} }
lastKeepAlive = System.currentTimeMillis(); lastKeepAlive = System.currentTimeMillis();
try try {
{
sendKeepAlive(); sendKeepAlive();
} } catch (IOException e) {
catch (IOException e)
{
connectionLost(); connectionLost();
} }
break; break;
@ -429,8 +438,7 @@ public class JaimConnection implements java.lang.Runnable {
loggedIn = false; loggedIn = false;
try { try {
s.close(); s.close();
} } catch (IOException e) {
catch (IOException e) {
} }
break; break;
default: default:
@ -458,16 +466,13 @@ public class JaimConnection implements java.lang.Runnable {
sendTocCommand(tid); sendTocCommand(tid);
deliverEvent(new LoginCompleteTocResponse()); // nform clients that login processing is now complete deliverEvent(new LoginCompleteTocResponse()); // nform clients that login processing is now complete
loginComplete = true; loginComplete = true;
} catch (IOException e) {
} }
catch (IOException e) { } else if (tr instanceof ConfigTocResponse ctr) {
}
}
else if (tr instanceof ConfigTocResponse) {
if (debug) { if (debug) {
System.out.println("Received ConfigTocResponse"); System.out.println("Received ConfigTocResponse");
} }
ConfigTocResponse ctr=(ConfigTocResponse)tr;
Enumeration e = ctr.enumerateGroups(); Enumeration e = ctr.enumerateGroups();
while (e.hasMoreElements()) { while (e.hasMoreElements()) {
Group g = (Group) e.nextElement(); Group g = (Group) e.nextElement();
@ -486,10 +491,11 @@ public class JaimConnection implements java.lang.Runnable {
deliverEvent(tr); deliverEvent(tr);
} }
/** Deliver a TocResponse event to registered listeners /**
* Deliver a TocResponse event to registered listeners
*
* @param tr The TocResponse to be delivered * @param tr The TocResponse to be delivered
*/ */
@ -502,14 +508,17 @@ public class JaimConnection implements java.lang.Runnable {
try { try {
TocChatJoinCommand joinCommand = new TocChatJoinCommand(exchange, roomName); TocChatJoinCommand joinCommand = new TocChatJoinCommand(exchange, roomName);
sendTocCommand(joinCommand); sendTocCommand(joinCommand);
} catch (IOException ignore) {} } catch (IOException ignore) {
}
} }
public void joinChat(String roomName) { public void joinChat(String roomName) {
joinChat(4, roomName); joinChat(4, roomName);
} }
/** Send an instant message /**
* Send an instant message
*
* @param recipient The nickname of the message recipient * @param recipient The nickname of the message recipient
* @param msg The message to send * @param msg The message to send
* @throws IOException if a network error occurs * @throws IOException if a network error occurs
@ -518,7 +527,9 @@ public class JaimConnection implements java.lang.Runnable {
sendIM(recipient, msg, false); sendIM(recipient, msg, false);
} }
/** Send an instant message /**
* Send an instant message
*
* @param recipient The nickname of the message recipient * @param recipient The nickname of the message recipient
* @param msg The message to send * @param msg The message to send
* @param auto true if this is an automatic response (eg. away message) * @param auto true if this is an automatic response (eg. away message)
@ -541,8 +552,7 @@ public class JaimConnection implements java.lang.Runnable {
try { try {
Thread.sleep(THRESHOLD_DELAY); // Wait until we get one point back Thread.sleep(THRESHOLD_DELAY); // Wait until we get one point back
sendPoints++; sendPoints++;
} } catch (InterruptedException ie) {
catch (InterruptedException ie) {
} }
} }
} }
@ -559,7 +569,9 @@ public class JaimConnection implements java.lang.Runnable {
} }
/** Add a buddy to a group. This information can be saved on the server by calling {@link #saveConfig} /**
* Add a buddy to a group. This information can be saved on the server by calling {@link #saveConfig}
*
* @param buddyName The normalised buddy name to add * @param buddyName The normalised buddy name to add
* @param groupName The name of the group to add this buddy to * @param groupName The name of the group to add this buddy to
* @param pos the position in the group at which to add the buddy. * @param pos the position in the group at which to add the buddy.
@ -584,15 +596,16 @@ public class JaimConnection implements java.lang.Runnable {
} }
if (pos > group.getBuddyCount() || pos == -1) { if (pos > group.getBuddyCount() || pos == -1) {
group.addBuddy(buddy); group.addBuddy(buddy);
} } else {
else {
group.addBuddy(buddy, pos); group.addBuddy(buddy, pos);
} }
return (buddy); return (buddy);
} }
/** Add a buddy to a group. This information can be saved on the server by calling {@link #saveConfig} /**
* Add a buddy to a group. This information can be saved on the server by calling {@link #saveConfig}
* The buddy is added to the end of the group * The buddy is added to the end of the group
*
* @param buddyName The normalised buddy name to add * @param buddyName The normalised buddy name to add
* @param groupName The name of the group to add this buddy to * @param groupName The name of the group to add this buddy to
* @return The {@link Buddy} object that represents the specified buddy name. * @return The {@link Buddy} object that represents the specified buddy name.
@ -602,9 +615,11 @@ public class JaimConnection implements java.lang.Runnable {
return (addBuddy(buddyName, groupName, -1)); return (addBuddy(buddyName, groupName, -1));
} }
/** Add a buddy to the watch list for this connection. /**
* Add a buddy to the watch list for this connection.
* This method must be called after {@link #connect()} * This method must be called after {@link #connect()}
* It also appears that the login process will not complete unless at least one buddy is added to the watch list * It also appears that the login process will not complete unless at least one buddy is added to the watch list
*
* @param buddy The nickname to add to the watch list * @param buddy The nickname to add to the watch list
* @throws JaimException if the method is called at the wrong time * @throws JaimException if the method is called at the wrong time
* @see JaimEventListener * @see JaimEventListener
@ -615,9 +630,11 @@ public class JaimConnection implements java.lang.Runnable {
} }
/** Add a buddy to the watch list for this connection. /**
* Add a buddy to the watch list for this connection.
* This method must be called after {@link #connect()} * This method must be called after {@link #connect()}
* It also appears that the login process will not complete unless at least one buddy is added to the watch list * It also appears that the login process will not complete unless at least one buddy is added to the watch list
*
* @param buddy The nickname to add to the watch list * @param buddy The nickname to add to the watch list
* @throws JaimException if the method is called at the wrong time * @throws JaimException if the method is called at the wrong time
* @see JaimEventListener * @see JaimEventListener
@ -628,8 +645,7 @@ public class JaimConnection implements java.lang.Runnable {
TocAddBuddyCommand tab = new TocAddBuddyCommand(); TocAddBuddyCommand tab = new TocAddBuddyCommand();
tab.addBuddy(buddy); tab.addBuddy(buddy);
sendTocCommand(tab); sendTocCommand(tab);
} } catch (IOException e) {
catch (IOException e) {
throw new JaimException(e.toString()); throw new JaimException(e.toString());
} }
} }
@ -638,7 +654,9 @@ public class JaimConnection implements java.lang.Runnable {
} }
/** Save group/buddy list configuration to the TOC server /**
* Save group/buddy list configuration to the TOC server
*
* @throws IOException if a network error occurs * @throws IOException if a network error occurs
*/ */
@ -653,8 +671,10 @@ public class JaimConnection implements java.lang.Runnable {
} }
/** Return the set of groups that have been stored in the TOC server /**
* Return the set of groups that have been stored in the TOC server
* The information returned from this method is only valid if {@link #isConfigValid} returns true * The information returned from this method is only valid if {@link #isConfigValid} returns true
*
* @return A Collection of {@link Group} Objects * @return A Collection of {@link Group} Objects
*/ */
@ -664,6 +684,7 @@ public class JaimConnection implements java.lang.Runnable {
/** /**
* Return a group, given its name * Return a group, given its name
*
* @return A {@link Group} Object corresponding to the string name * @return A {@link Group} Object corresponding to the string name
*/ */
@ -673,8 +694,10 @@ public class JaimConnection implements java.lang.Runnable {
} }
/** Indicate whether configuration information has been received from the TOC server. /**
* Indicate whether configuration information has been received from the TOC server.
* If this method returns true then the information returned by {@link #getGroups} is valid * If this method returns true then the information returned by {@link #getGroups} is valid
*
* @return true if configuration information has been received from the TOC server. * @return true if configuration information has been received from the TOC server.
*/ */
@ -682,7 +705,9 @@ public class JaimConnection implements java.lang.Runnable {
return (configValid); return (configValid);
} }
/** Send a warning or "Evil" to another user. You must be involved in a communication with a user before you can warn them /**
* Send a warning or "Evil" to another user. You must be involved in a communication with a user before you can warn them
*
* @param buddy The nickname of the buddy to warn * @param buddy The nickname of the buddy to warn
* @param anonymous true if the warning should be sent anonymously * @param anonymous true if the warning should be sent anonymously
* @throws IOException if a network error occurs * @throws IOException if a network error occurs
@ -693,7 +718,9 @@ public class JaimConnection implements java.lang.Runnable {
} }
/** Set the information for the logged in user /**
* Set the information for the logged in user
*
* @param information The information for this user (May contain HTML) * @param information The information for this user (May contain HTML)
* @throws IOException if a network error occurs * @throws IOException if a network error occurs
*/ */
@ -702,7 +729,9 @@ public class JaimConnection implements java.lang.Runnable {
sendTocCommand(sic); sendTocCommand(sic);
} }
/** Get the information for the specified user /**
* Get the information for the specified user
*
* @param username The screenname for whom info is requested (May contain HTML) * @param username The screenname for whom info is requested (May contain HTML)
* @throws IOException if a network error occurs * @throws IOException if a network error occurs
*/ */
@ -711,7 +740,9 @@ public class JaimConnection implements java.lang.Runnable {
sendTocCommand(gic); sendTocCommand(gic);
} }
/** Get an Input stream associated with a URL returned by the "GOTO_URL" toc response /**
* Get an Input stream associated with a URL returned by the "GOTO_URL" toc response
*
* @param file The "file" returned by calling GotoTocResponse#getURL * @param file The "file" returned by calling GotoTocResponse#getURL
* @return An InputStream connected to the specified URL * @return An InputStream connected to the specified URL
* @throws IOException if an IO error occurs * @throws IOException if an IO error occurs
@ -728,8 +759,9 @@ public class JaimConnection implements java.lang.Runnable {
} }
/**
/** Set the information for the logged in user * Set the information for the logged in user
*
* @param awayMsg The away message for this user. May contain HTML. To cancel "away" status set the awayMsg to "" * @param awayMsg The away message for this user. May contain HTML. To cancel "away" status set the awayMsg to ""
* @throws IOException if a network error occurs * @throws IOException if a network error occurs
*/ */
@ -739,7 +771,9 @@ public class JaimConnection implements java.lang.Runnable {
} }
/** Adds the specified buddy to your permit list. /**
* Adds the specified buddy to your permit list.
*
* @param buddy The buddy to add to your block list. If this is an empty string, mode is changed to "permit none" * @param buddy The buddy to add to your block list. If this is an empty string, mode is changed to "permit none"
* @throws JaimException if a network error occurs * @throws JaimException if a network error occurs
*/ */
@ -749,14 +783,15 @@ public class JaimConnection implements java.lang.Runnable {
TocAddPermitCommand tap = new TocAddPermitCommand(); TocAddPermitCommand tap = new TocAddPermitCommand();
tap.addPermit(buddy); tap.addPermit(buddy);
sendTocCommand(tap); sendTocCommand(tap);
} } catch (IOException e) {
catch (IOException e) {
throw new JaimException(e.toString()); throw new JaimException(e.toString());
} }
} }
} }
/** Adds the specified buddy to your block list. /**
* Adds the specified buddy to your block list.
*
* @param buddy The buddy to add to your block list. If this is an empty string, mode is changed to "deny none" * @param buddy The buddy to add to your block list. If this is an empty string, mode is changed to "deny none"
* @throws JaimException if a network error occurs * @throws JaimException if a network error occurs
*/ */
@ -766,14 +801,14 @@ public class JaimConnection implements java.lang.Runnable {
TocAddDenyCommand tad = new TocAddDenyCommand(); TocAddDenyCommand tad = new TocAddDenyCommand();
tad.addDeny(buddy); tad.addDeny(buddy);
sendTocCommand(tad); sendTocCommand(tad);
} } catch (IOException e) {
catch (IOException e) {
throw new JaimException(e.toString()); throw new JaimException(e.toString());
} }
} }
} }
/** Called by receiver thread to indicate that the connection has been terminated by an IOException /**
* Called by receiver thread to indicate that the connection has been terminated by an IOException
*/ */
private void connectionLost() { private void connectionLost() {
@ -783,8 +818,9 @@ public class JaimConnection implements java.lang.Runnable {
} }
/**
/** Set the idle time for this user * Set the idle time for this user
*
* @param idleSecs The number of seconds the user has been idle for. Set to 0 to indicate current activity. The server will increment the idle time if non-zero * @param idleSecs The number of seconds the user has been idle for. Set to 0 to indicate current activity. The server will increment the idle time if non-zero
* @throws IOException if a network error occurs * @throws IOException if a network error occurs
*/ */
@ -794,8 +830,10 @@ public class JaimConnection implements java.lang.Runnable {
} }
/** Delete a buddy from the buddy watch list. The buddy should have been added with {@link #addBuddy } first. /**
* Delete a buddy from the buddy watch list. The buddy should have been added with {@link #addBuddy } first.
* The buddy list can only be modified after {@link #connect } is called. * The buddy list can only be modified after {@link #connect } is called.
*
* @param buddy The buddy name to be deleted\ * @param buddy The buddy name to be deleted\
* @deprecated use {@link #unwatchBuddy } instead * @deprecated use {@link #unwatchBuddy } instead
*/ */
@ -803,8 +841,10 @@ public class JaimConnection implements java.lang.Runnable {
unwatchBuddy(buddy); unwatchBuddy(buddy);
} }
/** Delete a buddy from the buddy watch list. The buddy should have been added with {@link #addBuddy } first. /**
* Delete a buddy from the buddy watch list. The buddy should have been added with {@link #addBuddy } first.
* The buddy list can only be modified after {@link #connect } is called. * The buddy list can only be modified after {@link #connect } is called.
*
* @param buddy The buddy name to be deleted * @param buddy The buddy name to be deleted
*/ */
public void unwatchBuddy(String buddy) { public void unwatchBuddy(String buddy) {
@ -814,7 +854,7 @@ public class JaimConnection implements java.lang.Runnable {
private class ReceiverThread extends Thread { private class ReceiverThread extends Thread {
private InputStream sin; private InputStream sin;
private boolean exit; private boolean exit;
private JaimConnection parent; private final JaimConnection parent;
private ReceiverThread(JaimConnection parent) { private ReceiverThread(JaimConnection parent) {
this.parent = parent; this.parent = parent;
@ -841,8 +881,7 @@ public class JaimConnection implements java.lang.Runnable {
try { try {
FLAPFrame fr = FLAPFrameFactory.createFLAPFrame(inframe.getFrameData()); FLAPFrame fr = FLAPFrameFactory.createFLAPFrame(inframe.getFrameData());
parent.Dispatch(fr); parent.Dispatch(fr);
} } catch (FLAPFrameException ffe) {
catch (FLAPFrameException ffe) {
if (debug) { if (debug) {
ffe.printStackTrace(); ffe.printStackTrace();
} }
@ -850,13 +889,11 @@ public class JaimConnection implements java.lang.Runnable {
if (inframe.completeFrameRead()) { if (inframe.completeFrameRead()) {
inframe.resetInputFrame(); inframe.resetInputFrame();
} }
} } catch (InterruptedIOException iie) {
catch (InterruptedIOException iie) {
// We expect these because we are performing reads with a timeout // We expect these because we are performing reads with a timeout
} }
} }
} } catch (IOException e) {
catch (IOException e) {
connectionLost(); // Indicate that we have lost our connection connectionLost(); // Indicate that we have lost our connection
if (debug) { if (debug) {
e.printStackTrace(); e.printStackTrace();
@ -869,9 +906,11 @@ public class JaimConnection implements java.lang.Runnable {
} }
} }
private class DeliveryThread extends Thread { private class DeliveryThread extends Thread {
private Vector messages; private final Vector messages;
private boolean exit; private boolean exit;
private DeliveryThread() { private DeliveryThread() {
messages = new Vector(); messages = new Vector();
exit = false; exit = false;
@ -892,15 +931,11 @@ public class JaimConnection implements java.lang.Runnable {
if (messages.size() > 0) { if (messages.size() > 0) {
TocResponse tr = (TocResponse) messages.remove(0); TocResponse tr = (TocResponse) messages.remove(0);
doDelivery(tr); doDelivery(tr);
} } else {
else {
synchronized (this) { synchronized (this) {
try try {
{
this.wait(); this.wait();
} } catch (InterruptedException e) {
catch (InterruptedException e)
{
} }
} }
} }

View file

@ -19,23 +19,26 @@
package com.wilko.jaim; package com.wilko.jaim;
/** The JaimEvent object is delivered to all registered {@link JaimEventListener} /**
* @see JaimConnection#addEventListener * The JaimEvent object is delivered to all registered {@link JaimEventListener}
*
* @author paulw * @author paulw
* @version $revision: $ * @version $revision: $
* @see JaimConnection#addEventListener
*/ */
public class JaimEvent extends java.util.EventObject { public class JaimEvent extends java.util.EventObject {
private TocResponse tocResponse; private final TocResponse tocResponse;
/** Creates new JaimEvent */ /**
* Creates new JaimEvent
*/
public JaimEvent(Object source, TocResponse tocResponse) { public JaimEvent(Object source, TocResponse tocResponse) {
super(source); super(source);
this.tocResponse = tocResponse; this.tocResponse = tocResponse;
} }
public TocResponse getTocResponse() public TocResponse getTocResponse() {
{
return (tocResponse); return (tocResponse);
} }

View file

@ -25,16 +25,20 @@
package com.wilko.jaim; package com.wilko.jaim;
/** A JaimEventListener receives JaimEvents from the JaimConnection class. /**
* A JaimEventListener receives JaimEvents from the JaimConnection class.
* A {@link JaimEvent} contains a {@link TocResponse} object. * A {@link JaimEvent} contains a {@link TocResponse} object.
*
* @author paulw * @author paulw
* @version $Revision: 1.3 $ * @version $Revision: 1.3 $
*/ */
public interface JaimEventListener { public interface JaimEventListener {
/** Receive an incoming {@link JaimEvent} /**
* Receive an incoming {@link JaimEvent}
*
* @param ev - The incoming event * @param ev - The incoming event
*/ */
public void receiveEvent(JaimEvent ev); void receiveEvent(JaimEvent ev);
} }

View file

@ -26,7 +26,6 @@
package com.wilko.jaim; package com.wilko.jaim;
/** /**
*
* @author paulw * @author paulw
* @version $Revision: 1.3 $ * @version $Revision: 1.3 $
*/ */
@ -41,6 +40,7 @@ public class JaimException extends java.lang.Exception {
/** /**
* Constructs an <code>JaimException</code> with the specified detail message. * Constructs an <code>JaimException</code> with the specified detail message.
*
* @param msg the detail message. * @param msg the detail message.
*/ */
public JaimException(String msg) { public JaimException(String msg) {

View file

@ -19,7 +19,6 @@
package com.wilko.jaim; package com.wilko.jaim;
/** /**
*
* @author paulw * @author paulw
* @version $version: $ * @version $version: $
*/ */
@ -34,6 +33,7 @@ public class JaimStateException extends JaimException {
/** /**
* Constructs an <code>JaimStateException</code> with the specified detail message. * Constructs an <code>JaimStateException</code> with the specified detail message.
*
* @param msg the detail message. * @param msg the detail message.
*/ */
public JaimStateException(String msg) { public JaimStateException(String msg) {

View file

@ -20,7 +20,6 @@
package com.wilko.jaim; package com.wilko.jaim;
/** /**
*
* @author paulw * @author paulw
* @version $version: $ * @version $version: $
*/ */
@ -35,6 +34,7 @@ public class JaimTimeoutException extends JaimException {
/** /**
* Constructs an <code>JaimTimeoutException</code> with the specified detail message. * Constructs an <code>JaimTimeoutException</code> with the specified detail message.
*
* @param msg the detail message. * @param msg the detail message.
*/ */
public JaimTimeoutException(String msg) { public JaimTimeoutException(String msg) {

View file

@ -27,6 +27,7 @@ package com.wilko.jaim;
/** /**
* This is a "pseudo" TOC response - it is delivered to JaimLib clients to indicate that login processing has been completed successfully. * This is a "pseudo" TOC response - it is delivered to JaimLib clients to indicate that login processing has been completed successfully.
*
* @author wilko * @author wilko
* @version: $revision: $ * @version: $revision: $
*/ */
@ -34,7 +35,9 @@ public class LoginCompleteTocResponse extends TocResponse {
public static final String RESPONSE_TYPE = "LOGINCOMPLETE"; public static final String RESPONSE_TYPE = "LOGINCOMPLETE";
/** Creates a new instance of LoginCompleteTocResponse */ /**
* Creates a new instance of LoginCompleteTocResponse
*/
public LoginCompleteTocResponse() { public LoginCompleteTocResponse() {
} }
@ -42,8 +45,7 @@ public class LoginCompleteTocResponse extends TocResponse {
return (RESPONSE_TYPE); return (RESPONSE_TYPE);
} }
public String toString() public String toString() {
{
return (RESPONSE_TYPE); return (RESPONSE_TYPE);
} }

View file

@ -27,17 +27,19 @@ package com.wilko.jaim;
/** /**
* The NicTocResponse is used internally to manage the TOC signon process. It is not delivered to clients of {@link JaimConnection} * The NicTocResponse is used internally to manage the TOC signon process. It is not delivered to clients of {@link JaimConnection}
*
* @author paulw * @author paulw
* @version $Revision: 1.6 $ * @version $Revision: 1.6 $
*/ */
public class NickTocResponse extends TocResponse implements TocResponseHandler { public class NickTocResponse extends TocResponse implements TocResponseHandler {
public static final String RESPONSE_TYPE = "NICK";
private String nickName; private String nickName;
public static final String RESPONSE_TYPE="NICK";
/**
/** Creates new NickTocResponse */ * Creates new NickTocResponse
*/
public NickTocResponse() { public NickTocResponse() {
nickName = ""; nickName = "";
} }
@ -49,20 +51,17 @@ public class NickTocResponse extends TocResponse implements TocResponseHandler {
return (tr); return (tr);
} }
private void doParse(String str) private void doParse(String str) {
{
int colonPos = str.indexOf(':'); int colonPos = str.indexOf(':');
if (colonPos != -1) if (colonPos != -1) {
{
nickName = str.substring(colonPos + 1); nickName = str.substring(colonPos + 1);
} }
} }
public String getNickName() public String getNickName() {
{
return (nickName); return (nickName);
} }
@ -71,7 +70,9 @@ public class NickTocResponse extends TocResponse implements TocResponseHandler {
return RESPONSE_TYPE; return RESPONSE_TYPE;
} }
/** Returns true if this response handler can handle the specified response. /**
* Returns true if this response handler can handle the specified response.
*
* @param Response - the response string from TOC. This is the part of the response before the first ':' * @param Response - the response string from TOC. This is the part of the response before the first ':'
* @return true if the response can be handled * @return true if the response can be handled
*/ */

View file

@ -27,17 +27,19 @@ package com.wilko.jaim;
/** /**
* The SignOnTocResponse is used internally to manage the TOC signon process. It is not delivered to clients of {@link JaimConnection} * The SignOnTocResponse is used internally to manage the TOC signon process. It is not delivered to clients of {@link JaimConnection}
*
* @author paulw * @author paulw
* @version $Revision: 1.5 $ * @version $Revision: 1.5 $
*/ */
public class SignOnTocResponse extends TocResponse implements TocResponseHandler { public class SignOnTocResponse extends TocResponse implements TocResponseHandler {
public static final String RESPONSE_TYPE = "SIGN_ON";
String version; String version;
public static final String RESPONSE_TYPE="SIGN_ON";
/**
/** Creates new SignOnTocResponse */ * Creates new SignOnTocResponse
*/
public SignOnTocResponse() { public SignOnTocResponse() {
version = ""; version = "";
} }
@ -46,30 +48,28 @@ public class SignOnTocResponse extends TocResponse implements TocResponseHandler
return (RESPONSE_TYPE); return (RESPONSE_TYPE);
} }
protected String getVersion() protected String getVersion() {
{
return (version); return (version);
} }
public TocResponse parseString(String str) public TocResponse parseString(String str) {
{
SignOnTocResponse tr = new SignOnTocResponse(); SignOnTocResponse tr = new SignOnTocResponse();
tr.doParse(str); tr.doParse(str);
return (tr); return (tr);
} }
private void doParse(String str) private void doParse(String str) {
{
cmd = str; cmd = str;
int colonpos = str.indexOf(':'); int colonpos = str.indexOf(':');
if (colonpos != -1) if (colonpos != -1) {
{
version = str.substring(colonpos + 1); version = str.substring(colonpos + 1);
} }
} }
/** Returns true if this response handler can handle the specified response. /**
* Returns true if this response handler can handle the specified response.
*
* @param Response - the response string from TOC. This is the part of the response before the first ':' * @param Response - the response string from TOC. This is the part of the response before the first ':'
* @return true if the response can be handled * @return true if the response can be handled
*/ */

View file

@ -28,31 +28,29 @@ package com.wilko.jaim;
import java.util.Vector; import java.util.Vector;
/** /**
*
* @author paulw * @author paulw
* @version $Revision: 1.3 $ * @version $Revision: 1.3 $
*/ */
public class TocAddBuddyCommand extends TocCommand { public class TocAddBuddyCommand extends TocCommand {
private static String CMD="toc_add_buddy"; private static final String CMD = "toc_add_buddy";
Vector buddyList; Vector buddyList;
/** Creates new TocAddBuddyCommand */ /**
* Creates new TocAddBuddyCommand
*/
public TocAddBuddyCommand() { public TocAddBuddyCommand() {
buddyList = new Vector(); buddyList = new Vector();
} }
public void addBuddy(String buddy) public void addBuddy(String buddy) {
{
buddyList.add(Utils.normalise(buddy)); buddyList.add(Utils.normalise(buddy));
} }
public String toString() public String toString() {
{
StringBuffer output = new StringBuffer(CMD); StringBuffer output = new StringBuffer(CMD);
for (int i=0;i<buddyList.size();i++) for (int i = 0; i < buddyList.size(); i++) {
{
output.append(' '); output.append(' ');
output.append((String) buddyList.elementAt(i)); output.append((String) buddyList.elementAt(i));
} }

View file

@ -28,31 +28,29 @@ package com.wilko.jaim;
import java.util.Vector; import java.util.Vector;
/** /**
*
* @author paulw * @author paulw
* @version $Revision: 1.3 $ * @version $Revision: 1.3 $
*/ */
public class TocAddDenyCommand extends TocCommand { public class TocAddDenyCommand extends TocCommand {
private static String CMD="toc_add_deny"; private static final String CMD = "toc_add_deny";
Vector buddyList; Vector buddyList;
/** Creates new TocAddBuddyCommand */ /**
* Creates new TocAddBuddyCommand
*/
public TocAddDenyCommand() { public TocAddDenyCommand() {
buddyList = new Vector(); buddyList = new Vector();
} }
public void addDeny(String buddy) public void addDeny(String buddy) {
{
buddyList.add(Utils.normalise(buddy)); buddyList.add(Utils.normalise(buddy));
} }
public String toString() public String toString() {
{
StringBuffer output = new StringBuffer(CMD); StringBuffer output = new StringBuffer(CMD);
for (int i=0;i<buddyList.size();i++) for (int i = 0; i < buddyList.size(); i++) {
{
output.append(' '); output.append(' ');
output.append((String) buddyList.elementAt(i)); output.append((String) buddyList.elementAt(i));
} }

View file

@ -28,31 +28,29 @@ package com.wilko.jaim;
import java.util.Vector; import java.util.Vector;
/** /**
*
* @author paulw * @author paulw
* @version $Revision: 1.1 $ * @version $Revision: 1.1 $
*/ */
public class TocAddPermitCommand extends TocCommand { public class TocAddPermitCommand extends TocCommand {
private static String CMD="toc_add_permit"; private static final String CMD = "toc_add_permit";
Vector buddyList; Vector buddyList;
/** Creates new TocAddBuddyCommand */ /**
* Creates new TocAddBuddyCommand
*/
public TocAddPermitCommand() { public TocAddPermitCommand() {
buddyList = new Vector(); buddyList = new Vector();
} }
public void addPermit(String buddy) public void addPermit(String buddy) {
{
buddyList.add(Utils.normalise(buddy)); buddyList.add(Utils.normalise(buddy));
} }
public String toString() public String toString() {
{
StringBuffer output = new StringBuffer(CMD); StringBuffer output = new StringBuffer(CMD);
for (int i=0;i<buddyList.size();i++) for (int i = 0; i < buddyList.size(); i++) {
{
output.append(' '); output.append(' ');
output.append((String) buddyList.elementAt(i)); output.append((String) buddyList.elementAt(i));
} }

View file

@ -26,23 +26,23 @@
package com.wilko.jaim; package com.wilko.jaim;
/** /**
*
* @author paulw * @author paulw
* @version $Revision: 1.4 $ * @version $Revision: 1.4 $
*/ */
public class TocChatJoinCommand extends TocCommand { public class TocChatJoinCommand extends TocCommand {
private int exchange; private final int exchange;
private String roomName; private final String roomName;
/** Creates new TocIMCommand */ /**
* Creates new TocIMCommand
*/
public TocChatJoinCommand(int exchange, String roomName) { public TocChatJoinCommand(int exchange, String roomName) {
this.exchange = exchange; this.exchange = exchange;
this.roomName = roomName; this.roomName = roomName;
} }
public String toString() public String toString() {
{
return ("toc_chat_join " + exchange + " " + roomName); return ("toc_chat_join " + exchange + " " + roomName);
} }

View file

@ -26,13 +26,14 @@
package com.wilko.jaim; package com.wilko.jaim;
/** /**
*
* @author paulw * @author paulw
* @version $Revision: 1.3 $ * @version $Revision: 1.3 $
*/ */
public abstract class TocCommand { public abstract class TocCommand {
/** Creates new TocCommand */ /**
* Creates new TocCommand
*/
public TocCommand() { public TocCommand() {
} }

View file

@ -26,29 +26,27 @@
package com.wilko.jaim; package com.wilko.jaim;
/** /**
*
* @author paulw * @author paulw
* @version $Revision: 1.3 $ * @version $Revision: 1.3 $
*/ */
public class TocEvilCommand extends TocCommand { public class TocEvilCommand extends TocCommand {
private String buddy; private final String buddy;
private boolean anonymous; private final boolean anonymous;
/** Creates new TocEvilCommand */ /**
* Creates new TocEvilCommand
*/
public TocEvilCommand(String buddy, boolean anonymous) { public TocEvilCommand(String buddy, boolean anonymous) {
this.buddy = Utils.normalise(buddy); this.buddy = Utils.normalise(buddy);
this.anonymous = anonymous; this.anonymous = anonymous;
} }
public String toString() public String toString() {
{
String ret = "toc_evil " + buddy; String ret = "toc_evil " + buddy;
if (anonymous) if (anonymous) {
{
ret = ret + " anon"; ret = ret + " anon";
} } else
else
ret = ret + " norm"; ret = ret + " norm";
return (ret); return (ret);

View file

@ -39,18 +39,18 @@
package com.wilko.jaim; package com.wilko.jaim;
/** /**
*
* @author paulw * @author paulw
* @version $version: $ * @version $version: $
*/ */
public class TocGetInfoCommand extends TocCommand { public class TocGetInfoCommand extends TocCommand {
private String username; private static final String CMD = "toc_get_info ";
private final String username;
private static String CMD="toc_get_info "; /**
/** Creates new TocGetInfoCommand * Creates new TocGetInfoCommand
*@param username The screen name for whom information is requested
* *
* @param username The screen name for whom information is requested
*/ */
public TocGetInfoCommand(String username) { public TocGetInfoCommand(String username) {
@ -58,8 +58,7 @@ public class TocGetInfoCommand extends TocCommand {
} }
public String toString() public String toString() {
{
return (CMD + username); return (CMD + username);
} }

View file

@ -26,17 +26,18 @@
package com.wilko.jaim; package com.wilko.jaim;
/** /**
*
* @author paulw * @author paulw
* @version $Revision: 1.4 $ * @version $Revision: 1.4 $
*/ */
public class TocIMCommand extends TocCommand { public class TocIMCommand extends TocCommand {
private String recipient; private final String recipient;
private String msg; private final String msg;
private String auto; private final String auto;
/** Creates new TocIMCommand */ /**
* Creates new TocIMCommand
*/
public TocIMCommand(String recipient, String msg, boolean autoMessage) { public TocIMCommand(String recipient, String msg, boolean autoMessage) {
this.recipient = Utils.normalise(recipient); this.recipient = Utils.normalise(recipient);
this.msg = Utils.encodeText(msg); this.msg = Utils.encodeText(msg);
@ -46,8 +47,7 @@ public class TocIMCommand extends TocCommand {
auto = ""; auto = "";
} }
public String toString() public String toString() {
{
return ("toc_send_im " + recipient + " " + msg + auto); return ("toc_send_im " + recipient + " " + msg + auto);
} }

View file

@ -26,7 +26,6 @@
package com.wilko.jaim; package com.wilko.jaim;
/** /**
*
* @author paulw * @author paulw
* @version $Revision: 1.4 $ * @version $Revision: 1.4 $
*/ */
@ -34,7 +33,9 @@ public class TocInitDoneCommand extends TocCommand {
private static final String CMD = "toc_init_done"; private static final String CMD = "toc_init_done";
/** Creates new TocInitDoneCommand */ /**
* Creates new TocInitDoneCommand
*/
public TocInitDoneCommand() { public TocInitDoneCommand() {
} }
@ -42,8 +43,7 @@ public class TocInitDoneCommand extends TocCommand {
return (CMD.getBytes()); return (CMD.getBytes());
} }
public String toString() public String toString() {
{
return (CMD); return (CMD);
} }

View file

@ -26,7 +26,6 @@
package com.wilko.jaim; package com.wilko.jaim;
/** /**
*
* @author paulw * @author paulw
* @version $Revision: 1.5 $ * @version $Revision: 1.5 $
*/ */
@ -34,13 +33,11 @@ public abstract class TocResponse {
protected String cmd; protected String cmd;
public TocResponse() public TocResponse() {
{
cmd = ""; cmd = "";
} }
public String toString() public String toString() {
{
return (cmd); return (cmd);
} }

View file

@ -26,7 +26,6 @@
package com.wilko.jaim; package com.wilko.jaim;
/** /**
*
* @author paulw * @author paulw
* @version $Revision: 1.5 $ * @version $Revision: 1.5 $
*/ */
@ -37,42 +36,36 @@ public abstract class TocResponseFactory {
static Vector responseHandlers = new Vector(); static Vector responseHandlers = new Vector();
/** Creates new TocResponseFactory */ /**
* Creates new TocResponseFactory
*/
public TocResponseFactory() { public TocResponseFactory() {
} }
public static void addResponseHandler(TocResponseHandler h) public static void addResponseHandler(TocResponseHandler h) {
{ synchronized (responseHandlers) {
synchronized (responseHandlers)
{
responseHandlers.add(h); responseHandlers.add(h);
} }
} }
static TocResponse createResponse(byte[] b) static TocResponse createResponse(byte[] b) {
{
TocResponse tr = null; TocResponse tr = null;
String strversion = new String(b); String strversion = new String(b);
int colonpos = strversion.indexOf(':'); int colonpos = strversion.indexOf(':');
if (colonpos != -1) if (colonpos != -1) {
{
String firstWord = strversion.substring(0, colonpos); String firstWord = strversion.substring(0, colonpos);
int i = 0; int i = 0;
synchronized (responseHandlers) synchronized (responseHandlers) {
{ while ((i < responseHandlers.size()) && (tr == null)) {
while ((i<responseHandlers.size())&&(tr==null))
{
TocResponseHandler h = (TocResponseHandler) responseHandlers.elementAt(i); TocResponseHandler h = (TocResponseHandler) responseHandlers.elementAt(i);
if (h.canHandle(firstWord)) if (h.canHandle(firstWord)) {
{
tr = h.parseString(strversion); tr = h.parseString(strversion);
} }
i++; i++;
} }
} }
} }
if (tr==null) if (tr == null) {
{
GenericTocResponse gtr = new GenericTocResponse(); GenericTocResponse gtr = new GenericTocResponse();
tr = gtr.parseString(strversion); tr = gtr.parseString(strversion);
} }

View file

@ -20,25 +20,28 @@
package com.wilko.jaim; package com.wilko.jaim;
/** /**
*
* @author paulw * @author paulw
* @version $revision: $ * @version $revision: $
*/ */
public interface TocResponseHandler { public interface TocResponseHandler {
/** Returns true if this response handler can handle the specified response. /**
* Returns true if this response handler can handle the specified response.
*
* @param Response - the response string from TOC. This is the part of the response before the first ':' * @param Response - the response string from TOC. This is the part of the response before the first ':'
* @return true if the response can be handled * @return true if the response can be handled
*/ */
public boolean canHandle(String Response); boolean canHandle(String Response);
/** Parse the provided response /**
* Parse the provided response
*
* @param Response - the response from the TOC server. This is the full TOC response string * @param Response - the response from the TOC server. This is the full TOC response string
* @return - A TocResponse object that represents this response * @return - A TocResponse object that represents this response
*/ */
public TocResponse parseString(String Response); TocResponse parseString(String Response);
} }

View file

@ -26,16 +26,17 @@
package com.wilko.jaim; package com.wilko.jaim;
/** /**
*
* @author paulw * @author paulw
* @version $version: $ * @version $version: $
*/ */
public class TocSetAwayCommand extends TocCommand { public class TocSetAwayCommand extends TocCommand {
private String awayMsg; private static final String CMD = "toc_set_away ";
private final String awayMsg;
private static String CMD="toc_set_away "; /**
/** Creates new TocSetInfoCommand * Creates new TocSetInfoCommand
*
* @param awayMsg The away message for this user. May contain HTML. To cancel "away" status set the awayMsg to "" * @param awayMsg The away message for this user. May contain HTML. To cancel "away" status set the awayMsg to ""
*/ */
@ -44,8 +45,7 @@ public class TocSetAwayCommand extends TocCommand {
} }
public String toString() public String toString() {
{
return (CMD + awayMsg); return (CMD + awayMsg);
} }

View file

@ -28,42 +28,37 @@ package com.wilko.jaim;
import java.util.Enumeration; import java.util.Enumeration;
/** /**
*
* @author paulw * @author paulw
*/ */
public class TocSetConfigCommand extends TocCommand { public class TocSetConfigCommand extends TocCommand {
private StringBuffer config; private static final String CMD = "toc_set_config ";
private final StringBuffer config;
private static String CMD="toc_set_config "; /**
* Creates a new instance of TocSetConfigCommand
/** Creates a new instance of TocSetConfigCommand */ */
public TocSetConfigCommand() { public TocSetConfigCommand() {
config = new StringBuffer(); config = new StringBuffer();
} }
public void addGroup(Group g) public void addGroup(Group g) {
{
config.append("g " + g.getName() + "\n"); config.append("g " + g.getName() + "\n");
Enumeration buddies = g.enumerateBuddies(); Enumeration buddies = g.enumerateBuddies();
while (buddies.hasMoreElements()) while (buddies.hasMoreElements()) {
{
Buddy b = (Buddy) buddies.nextElement(); Buddy b = (Buddy) buddies.nextElement();
config.append("b " + b.getName() + "\n"); config.append("b " + b.getName() + "\n");
if (b.getPermit()) if (b.getPermit()) {
{
config.append("p " + b.getName() + "\n"); config.append("p " + b.getName() + "\n");
} }
if (b.getDeny()) if (b.getDeny()) {
{
config.append("d " + b.getName() + "\n"); config.append("d " + b.getName() + "\n");
} }
} }
} }
public String toString() public String toString() {
{
return (CMD + '"' + config.toString() + '"'); return (CMD + '"' + config.toString() + '"');
} }

View file

@ -25,24 +25,24 @@
package com.wilko.jaim; package com.wilko.jaim;
/** /**
*
* @author paulw * @author paulw
* @version $version: $ * @version $version: $
*/ */
public class TocSetIdleCommand extends TocCommand { public class TocSetIdleCommand extends TocCommand {
private int idle;
private static final String CMD = "toc_set_idle "; private static final String CMD = "toc_set_idle ";
private final int idle;
/** Creates new TocSetIdleCommand /**
* Creates new TocSetIdleCommand
*
* @param idleSecs - the period for which the user has been idle * @param idleSecs - the period for which the user has been idle
*/ */
public TocSetIdleCommand(int idleSecs) { public TocSetIdleCommand(int idleSecs) {
idle = idleSecs; idle = idleSecs;
} }
public String toString() public String toString() {
{
return (CMD + idle); return (CMD + idle);
} }

View file

@ -26,16 +26,17 @@
package com.wilko.jaim; package com.wilko.jaim;
/** /**
*
* @author paulw * @author paulw
* @version $version: $ * @version $version: $
*/ */
public class TocSetInfoCommand extends TocCommand { public class TocSetInfoCommand extends TocCommand {
private String information; private static final String CMD = "toc_set_info ";
private final String information;
private static String CMD="toc_set_info "; /**
/** Creates new TocSetInfoCommand * Creates new TocSetInfoCommand
*
* @param information The information about this user can be located. May contain HTML * @param information The information about this user can be located. May contain HTML
*/ */
@ -44,8 +45,7 @@ public class TocSetInfoCommand extends TocCommand {
} }
public String toString() public String toString() {
{
return (CMD + information); return (CMD + information);
} }

View file

@ -26,20 +26,20 @@
package com.wilko.jaim; package com.wilko.jaim;
/** /**
*
* @author paulw * @author paulw
* @version $Revision: 1.3 $ * @version $Revision: 1.3 $
*/ */
public class TocSignonCommand extends TocCommand { public class TocSignonCommand extends TocCommand {
private String server;
private String username;
private String password;
private int port;
private static final String AGENTNAME = "jaim01"; private static final String AGENTNAME = "jaim01";
private final String server;
private final String username;
private final String password;
private final int port;
/** Creates new TocSignonCommand */ /**
* Creates new TocSignonCommand
*/
public TocSignonCommand(String server, int port, String username, String password) { public TocSignonCommand(String server, int port, String username, String password) {
this.server = server; this.server = server;
this.port = port; this.port = port;
@ -51,8 +51,7 @@ public class TocSignonCommand extends TocCommand {
return toString().getBytes(); return toString().getBytes();
} }
public String toString() public String toString() {
{
String temp = "toc_signon login.oscar.aol.com 5159 " + username + " " + password + " english " + AGENTNAME; String temp = "toc_signon login.oscar.aol.com 5159 " + username + " " + password + " english " + AGENTNAME;
return (temp); return (temp);
} }

View file

@ -26,7 +26,6 @@
package com.wilko.jaim; package com.wilko.jaim;
/** /**
*
* @author paulw * @author paulw
* @version $Revision: 1.4 $ * @version $Revision: 1.4 $
*/ */
@ -35,18 +34,18 @@ public class Utils {
private static final String roastKey = "Tic/Toc"; private static final String roastKey = "Tic/Toc";
private static final int roastLen = 7; private static final int roastLen = 7;
/** convert a buddy name to normalised format - remove spaces and convert to lower case /**
* convert a buddy name to normalised format - remove spaces and convert to lower case
*
* @param input The un-normalised buddy name * @param input The un-normalised buddy name
* @return the normalised buddy name * @return the normalised buddy name
*/ */
public static String normalise(java.lang.String input) { public static String normalise(java.lang.String input) {
StringBuffer output = new StringBuffer(); StringBuffer output = new StringBuffer();
String temp = input.toLowerCase(); String temp = input.toLowerCase();
for (int i=0;i<input.length();i++) for (int i = 0; i < input.length(); i++) {
{
char c = temp.charAt(i); char c = temp.charAt(i);
if ((c>= '0' && c<='9')||(c>='a' && c<='z')) if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'z')) {
{
output.append(c); output.append(c);
} }
} }
@ -54,7 +53,9 @@ public class Utils {
return (output.toString()); return (output.toString());
} }
/** Roast a password using the AOL roasting protocol /**
* Roast a password using the AOL roasting protocol
*
* @param password The password to be roasted * @param password The password to be roasted
* @return The roasted password * @return The roasted password
*/ */
@ -63,8 +64,7 @@ public class Utils {
StringBuffer temppw = new StringBuffer(); StringBuffer temppw = new StringBuffer();
temppw.append("0x"); temppw.append("0x");
for (int i=0;i<password.length();i++) for (int i = 0; i < password.length(); i++) {
{
int roastedByte = password.charAt(i) ^ roastKey.charAt(i % roastLen); int roastedByte = password.charAt(i) ^ roastKey.charAt(i % roastLen);
temppw.append(hexChars[(roastedByte >> 4) & 0x0f]); temppw.append(hexChars[(roastedByte >> 4) & 0x0f]);
@ -73,31 +73,25 @@ public class Utils {
return (temppw.toString()); return (temppw.toString());
} }
/** This method performs a simple HTML strip on text. It looks for < characters and then skips input until a matching > is found. /**
* This method performs a simple HTML strip on text. It looks for < characters and then skips input until a matching > is found.
* This may fail if the HTML tag contains an embedded '>' * This may fail if the HTML tag contains an embedded '>'
*
* @param input The text to have HTML stripped * @param input The text to have HTML stripped
* @return The text stripped of html * @return The text stripped of html
*/ */
public static String stripHTML(java.lang.String input) public static String stripHTML(java.lang.String input) {
{
StringBuffer output = new StringBuffer(); StringBuffer output = new StringBuffer();
boolean inHTML = false; boolean inHTML = false;
for (int i=0;i<input.length();i++) for (int i = 0; i < input.length(); i++) {
{
char c = input.charAt(i); char c = input.charAt(i);
if (c=='<') if (c == '<') {
{
inHTML = true; inHTML = true;
} } else {
else
{
if (c == '>') { if (c == '>') {
inHTML = false; inHTML = false;
} } else {
else if (!inHTML) {
{
if (!inHTML)
{
output.append(c); output.append(c);
} }
} }
@ -107,19 +101,17 @@ public class Utils {
} }
/** Encode a text message so that it is suitable for transmission using toc_send_im /**
* Encode a text message so that it is suitable for transmission using toc_send_im
* *
* @param input The text to be encoded * @param input The text to be encoded
* @return The encoded text * @return The encoded text
*/ */
public static String encodeText(String input) public static String encodeText(String input) {
{
StringBuffer output = new StringBuffer("\""); StringBuffer output = new StringBuffer("\"");
for (int i=0;i<input.length();i++) for (int i = 0; i < input.length(); i++) {
{
char c = input.charAt(i); char c = input.charAt(i);
switch (c) switch (c) {
{
case '\"': case '\"':
case '(': case '(':
case ')': case ')':

View file

@ -25,12 +25,13 @@
package com.wilko.jaimtest; package com.wilko.jaimtest;
import java.net.*;
import java.io.*;
import com.wilko.jaim.*; import com.wilko.jaim.*;
import java.util.*; import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Enumeration;
import java.util.Iterator;
/** /**
* @author paulw * @author paulw