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 fork features various improvements on the original Jaim:
- Support for chat invites
## Original README
```
Readme.txt for Jaimlib
----------------------

View file

@ -4,6 +4,9 @@
<exclude-output />
<content url="file://$MODULE_DIR$">
<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>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />

View file

@ -25,64 +25,79 @@
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.
*
* @author Brett Humphreys
*/
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;
/** deny value */
/**
* deny value
*/
private boolean deny;
/** Constructor that sets the buddy name
/**
* Constructor that sets the buddy name
*
* @param name the name of this buddy.
*/
public Buddy ( String name )
{
public Buddy(String name) {
buddyName = name;
}
/** Gets the buddy name
/**
* Gets the buddy name
*
* @return buddy name
*/
public String getName()
{
public String getName() {
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
*/
public boolean getPermit( )
{
public boolean getPermit() {
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 )
{
deny = denyVal;
public void setPermit(boolean permitVal) {
permit = permitVal;
}
/** Gets the deny value
/**
* Gets the deny value
*
* @return deny value
*/
public boolean getDeny( )
{
public boolean getDeny() {
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.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
* @version $Revision: 1.7 $
*/
public class BuddyUpdateTocResponse extends TocResponse implements TocResponseHandler {
public static String RESPONSE_TYPE = "UPDATE_BUDDY";
private String buddyName;
private boolean online;
private int evil;
@ -45,9 +48,9 @@ public class BuddyUpdateTocResponse extends TocResponse implements TocResponseHa
private Date signonTime;
private boolean away;
public static String RESPONSE_TYPE="UPDATE_BUDDY";
/** Creates new BuddyUpdateTocResponse */
/**
* Creates new BuddyUpdateTocResponse
*/
public BuddyUpdateTocResponse() {
buddyName = "";
online = false;
@ -60,7 +63,9 @@ public class BuddyUpdateTocResponse extends TocResponse implements TocResponseHa
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
*/
public TocResponse parseString(java.lang.String str) {
@ -69,22 +74,14 @@ public class BuddyUpdateTocResponse extends TocResponse implements TocResponseHa
return (tr);
}
private void doParse(String str)
{
private void doParse(String str) {
cmd = str;
StringTokenizer st = new StringTokenizer(str, ":");
st.nextToken();
buddyName = st.nextToken();
String onlineStr = st.nextToken();
if (onlineStr.equals("T"))
{
online=true;
}
else
{
online=false;
}
online = onlineStr.equals("T");
evil = Integer.parseInt(st.nextToken());
long signon = Long.parseLong(st.nextToken());
@ -93,113 +90,117 @@ public class BuddyUpdateTocResponse extends TocResponse implements TocResponseHa
String userclass = st.nextToken();
if (userclass.charAt(0) == 'A')
onAOL = true;
if (userclass.charAt(1) == 'A')
{
if (userclass.charAt(1) == 'A') {
admin = true;
}
else
{
if (userclass.charAt(1)=='U')
{
} else {
if (userclass.charAt(1) == 'U') {
unconfirmed = true;
}
else
{
if(userclass.charAt(1)=='O')
{
} else {
if (userclass.charAt(1) == 'O') {
confirmed = true;
}
}
}
if (userclass.length()>2)
{
if (userclass.charAt(2)=='U')
{
if (userclass.length() > 2) {
if (userclass.charAt(2) == 'U') {
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"
*/
public boolean isAway()
{
public boolean isAway() {
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
*/
public String getResponseType() {
return RESPONSE_TYPE;
}
/** Obtain the buddy name from this update
/**
* Obtain the buddy name from this update
*
* @return The buddy name
*/
public String getBuddy()
{
public String getBuddy() {
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
*/
public boolean isOnline()
{
public boolean isOnline() {
return (online);
}
/** Obtain the idle time of this buddy
/**
* Obtain the idle time of this buddy
*
* @return The idle time in seconds
*/
public int getIdleTime()
{
public int getIdleTime() {
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
*/
public int getEvil()
{
public int getEvil() {
return (evil);
}
/** Is this buddy an "Administrator"
/**
* Is this buddy an "Administrator"
*
* @return true if an administrator
*/
public boolean isAdmin()
{
public boolean isAdmin() {
return (admin);
}
/** IS this buddy a "confirmed" user
/**
* IS this buddy a "confirmed" user
*
* @return True if this buddy is confirmed
*/
public boolean isConfirmed()
{
public boolean isConfirmed() {
return (confirmed);
}
/** Is this user an "Unconfirmed user"
/**
* Is this user an "Unconfirmed user"
*
* @return True if this user is unconfirmed
*/
public boolean isUnconfirmed()
{
public boolean isUnconfirmed() {
return (unconfirmed);
}
/** Get the signon time of this buddy
/**
* Get the signon time of this buddy
*
* @return The date/time of signon
*/
public Date getSignonTime()
{
public Date getSignonTime() {
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 ':'
* @return true if the response can be handled
*/

View file

@ -25,23 +25,25 @@
package com.wilko.jaim;
import java.util.Date;
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
* @version $Revision: 1.7 $
*/
public class ChatInviteTocResponse extends TocResponse implements TocResponseHandler {
public static String RESPONSE_TYPE = "CHAT_INVITE";
private String roomName;
private String roomID;
private String senderScreenname;
private String message;
public static String RESPONSE_TYPE="CHAT_INVITE";
/** Creates new BuddyUpdateTocResponse */
/**
* Creates new BuddyUpdateTocResponse
*/
public ChatInviteTocResponse() {
roomName = "";
roomID = "";
@ -49,7 +51,9 @@ public class ChatInviteTocResponse extends TocResponse implements TocResponseHan
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
*/
public TocResponse parseString(String str) {
@ -58,8 +62,7 @@ public class ChatInviteTocResponse extends TocResponse implements TocResponseHan
return (tr);
}
private void doParse(String str)
{
private void doParse(String str) {
cmd = str;
StringTokenizer st = new StringTokenizer(str, ":");
@ -70,7 +73,9 @@ public class ChatInviteTocResponse extends TocResponse implements TocResponseHan
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
*/
public String getResponseType() {
@ -80,6 +85,7 @@ public class ChatInviteTocResponse extends TocResponse implements TocResponseHan
public String getRoomName() {
return roomName;
}
public String getRoomID() {
return roomID;
}
@ -92,7 +98,9 @@ public class ChatInviteTocResponse extends TocResponse implements TocResponseHan
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 ':'
* @return true if the response can be handled
*/

View file

@ -25,47 +25,59 @@
import java.util.*;
/** A ConfigTocResponse contains the config message received from
/**
* A ConfigTocResponse contains the config message received from
* the toc server.
* 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
*
* @author Brett Humphreys, Paul Wilkinson
*/
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";
/** The Vector of Group objects */
private Vector buddyList = new Vector();
/** The HashMap of known buddies */
/**
* The Vector of Group objects
*/
private final Vector buddyList = new Vector();
/**
* The HashMap of known buddies
*/
private HashMap buddies;
/** The mode for this configuration */
/**
* The mode for this configuration
*/
private int mode;
/** 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;
/** Returns an Enumeration of groups. Each Entry is a {@link Group}
/**
* 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}.
*
* @return list of Group elements or an empty list if none are found.
*/
public Enumeration enumerateGroups()
{
public Enumeration enumerateGroups() {
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
*/
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
*/
public String getResponseType() {
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();
tr.doParse(message);
return (tr);
}
private void doParse(String message)
{
private void doParse(String message) {
cmd = message;
int colonIndex = message.indexOf(':');
//throw away the first word.
message = message.substring(colonIndex+1, message.length());
message = message.substring(colonIndex + 1);
buddies = new HashMap();
StringTokenizer tok = new StringTokenizer(message, "\n");
String itemType;
String itemValue;
Group currentGroup = null;
Buddy tmpBuddy;
while( tok.hasMoreTokens() )
{
while (tok.hasMoreTokens()) {
// Can't tokenize on both \n and space since there could be spaces
// in the name, so parsing by hand.
itemType = tok.nextToken();
int firstSpace = itemType.indexOf(' ');
itemValue = itemType.substring(firstSpace+1, itemType.length());
itemValue = itemType.substring(firstSpace + 1);
itemType = itemType.substring(0, firstSpace);
char type = itemType.charAt(0);
switch (type)
{
switch (type) {
case 'g':
currentGroup = new Group(itemValue);
buddyList.add(currentGroup);
@ -122,8 +134,7 @@
tmpBuddy = getBuddy(itemValue);
//this shouldn't happen, but:
if(currentGroup==null)
{
if (currentGroup == null) {
currentGroup = new Group("<unknown>");
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
*
* @param The name of the buddy we are looking for
* @return The buddy object
*/
private Buddy getBuddy(String buddyName)
{
private Buddy getBuddy(String buddyName) {
Buddy retBuddy = (Buddy) buddies.get(buddyName);
if (retBuddy== null)
{
if (retBuddy == null) {
retBuddy = new Buddy(buddyName);
buddies.put(buddyName, retBuddy);
}
return (retBuddy);
}
/** Sets the mode for this configuration
* @param modeVal the string value of the mode (1-4)
*/
public void setMode( int modeVal )
{
mode = modeVal;
}
/** Gets the mode for this configuration
/**
* Gets the mode for this configuration
*
* @return mode for the configuration
*/
public int getMode( )
{
public int getMode() {
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 ':'
* @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.
*
* @author wilko
* @version: $revision: $
*/
@ -34,7 +35,9 @@ public class ConnectionLostTocResponse extends TocResponse {
public static final String RESPONSE_TYPE = "CONNECTIONLOST";
/** Creates a new instance of LoginCompleteTocResponse */
/**
* Creates a new instance of LoginCompleteTocResponse
*/
public ConnectionLostTocResponse() {
}
@ -42,8 +45,7 @@ public class ConnectionLostTocResponse extends TocResponse {
return (RESPONSE_TYPE);
}
public String toString()
{
public String toString() {
return (RESPONSE_TYPE);
}

View file

@ -27,75 +27,89 @@ package com.wilko.jaim;
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
* @version $Revision: 1.7 $
*/
public class ErrorTocResponse extends TocResponse implements TocResponseHandler {
public static final String RESPONSE_TYPE = "ERROR";
int errorCode;
String errorText;
public static final String RESPONSE_TYPE="ERROR";
/** Creates new ErrorTocResponse */
/**
* Creates new ErrorTocResponse
*/
public ErrorTocResponse() {
errorCode = 0;
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
*/
public TocResponse parseString(String str)
{
public TocResponse parseString(String str) {
ErrorTocResponse tr = new ErrorTocResponse();
tr.doParse(str);
return (tr);
}
private void doParse(String str)
{
private void doParse(String str) {
cmd = str;
int colonPos = str.indexOf(':');
if (colonPos!=-1)
{
if (colonPos != -1) {
str = str.substring(colonPos + 1);
colonPos = str.indexOf(':');
if (colonPos!=-1)
{
if (colonPos != -1) {
errorCode = Integer.parseInt(str.substring(0, colonPos));
errorText = str.substring(colonPos + 1);
}
else
{
} else {
errorCode = Integer.parseInt(str);
}
}
}
/** Obtain the error code for this response
/**
* Obtain the error code for this response
*
* @return The error code
*/
public int getErrorCode()
{
public int getErrorCode() {
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
*/
public String getErrorText()
{
public String getErrorText() {
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
*/
public String getErrorDescription() {
@ -108,25 +122,8 @@ public class ErrorTocResponse extends TocResponse implements TocResponseHandler
}
return (desc.toString());
}
catch (MissingResourceException 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());
} catch (MissingResourceException e) {
return ("Unable to locate error description:" + e);
}
}
@ -134,7 +131,9 @@ public class ErrorTocResponse extends TocResponse implements TocResponseHandler
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 ':'
* @return true if the response can be handled
*/

View file

@ -27,26 +27,31 @@ package com.wilko.jaim;
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
* @version $Revision: 1.6 $
*/
public class EvilTocResponse extends TocResponse implements TocResponseHandler {
public static final String RESPONSE_TYPE = "EVILED";
private boolean anonymousEvil;
private int evilAmount;
private String evilBy;
public static final String RESPONSE_TYPE="EVILED";
/** Creates new EvilTocResponse */
/**
* Creates new EvilTocResponse
*/
public EvilTocResponse() {
anonymousEvil = true;
evilBy = "";
evilAmount = 0;
}
/** Parse the evil message from the TOC server
/**
* Parse the evil message from the TOC server
*
* @param str The evil message
*/
public TocResponse parseString(java.lang.String str) {
@ -55,50 +60,51 @@ public class EvilTocResponse extends TocResponse implements TocResponseHandler {
return (tr);
}
private void doParse(String str)
{
private void doParse(String str) {
StringTokenizer st = new StringTokenizer(str, ":");
st.nextToken(); // skip over "EVILED"
evilAmount = Integer.parseInt(st.nextToken());
if (st.hasMoreTokens())
{
if (st.hasMoreTokens()) {
evilBy = st.nextToken();
anonymousEvil = false;
}
else
{
} else {
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
*/
public int getEvilAmount()
{
public int getEvilAmount() {
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
* @see #isAnonymous
*/
public String getEvilBy()
{
public String getEvilBy() {
return (evilBy);
}
/** Obtain the anonymous status of this warning
/**
* Obtain the anonymous status of this warning
*
* @return true if this warning was issued anonymously
*/
public boolean isAnonymous()
{
public boolean isAnonymous() {
return (anonymousEvil);
}
/** Used by the response dispatcher
/**
* Used by the response dispatcher
*
* @return The response type
*/
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 ':'
* @return true if the response can be handled
*/

View file

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

View file

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

View file

@ -26,7 +26,6 @@
package com.wilko.jaim;
/**
*
* @author paulw
* @version $Revision: 1.4 $
*/
@ -42,20 +41,14 @@ public abstract class FLAPFrame {
protected byte[] frame;
protected int fLen;
/** Creates new FLAPFrame */
/**
* Creates new FLAPFrame
*/
public FLAPFrame() {
initialise();
}
protected void setFrameData(byte b[])
{
frame=new byte[b.length];
fLen=b.length;
System.arraycopy(b,0,frame,0,b.length);
}
protected void initialise()
{
protected void initialise() {
frame = new byte[8192];
frame[0] = (byte) '*';
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[3] = (byte) (sequence & 0xff);
}
public int getSequence()
{
return((frame[2]&0xff)*256+(frame[3]&0xff));
}
public int getLength()
{
public int getLength() {
return ((frame[4] & 0xff) * 256 + (frame[5] & 0xff));
}
public void setLength(int length)
{
public void setLength(int length) {
frame[4] = (byte) (length / 256);
frame[5] = (byte) (length & 0xff);
fLen = length + FLAP_DATA_OFFSET;
}
public byte[] getFrameData()
{
public byte[] getFrameData() {
byte[] b = new byte[fLen];
System.arraycopy(frame, 0, b, 0, fLen);
return (b);
}
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)+" ");
protected void setFrameData(byte[] b) {
frame = new byte[b.length];
fLen = b.length;
System.arraycopy(b, 0, frame, 0, b.length);
}
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) + " ");
}
}
return (temp.toString());
}
public abstract int getFLAPFrameType();
}

View file

@ -26,7 +26,6 @@
package com.wilko.jaim;
/**
*
* @author paulw
* @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.
*
* @param msg the detail message.
*/
public FLAPFrameException(String msg) {

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -25,56 +25,66 @@
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
* @version $Revision: 1.5 $
*/
public class GenericTocResponse extends TocResponse implements TocResponseHandler {
/** Creates new GenericTocCommand */
/**
* Creates new GenericTocCommand
*/
public GenericTocResponse() {
this.cmd = "";
}
/** Parse an incoming string
/**
* Parse an incoming string
*
* @param str The response string to be parsed
*/
public TocResponse parseString(String str)
{
public TocResponse parseString(String str) {
GenericTocResponse tr = new GenericTocResponse();
tr.doParse(str);
return tr;
}
private void doParse(String str)
{
private void doParse(String 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
*/
public byte[] getBytes() {
return (cmd.getBytes());
}
/** Convert this response to a string
/**
* Convert this response to a string
*
* @return The response as a string
*/
public String toString()
{
public String toString() {
return (cmd);
}
/** Used in the response dispatching process
/**
* Used in the response dispatching process
*
* @return The respnse type
*/
public String getResponseType()
{
public String getResponseType() {
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 ':'
* @return true if the response can be handled
*/

View file

@ -25,43 +25,49 @@
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
* @version $Revision: 1.3 $
*/
public class GotoTocResponse extends TocResponse implements TocResponseHandler {
public static final String RESPONSE_TYPE = "GOTO_URL";
String windowName;
boolean autoResponse;
String URL;
public static final String RESPONSE_TYPE="GOTO_URL";
/** Creates new GotoTocResponse */
/**
* Creates new GotoTocResponse
*/
public GotoTocResponse() {
windowName = "";
URL = "";
}
/** Obtain the suggested window name for this URL
/**
* Obtain the suggested window name for this URL
*
* @return The window name
*/
public String getWindowName()
{
public String getWindowName() {
return (windowName);
}
/** Obtain the URL
/**
* Obtain the URL
*
* @return The URL
*/
public String getURL()
{
public String getURL() {
return (URL);
}
/** Parse an incoming response string
/**
* Parse an incoming response string
*
* @param str The string to be parsed
*/
public TocResponse parseString(java.lang.String str) {
@ -70,16 +76,13 @@ public class GotoTocResponse extends TocResponse implements TocResponseHandler {
return (tr);
}
private void doParse(String str)
{
private void doParse(String str) {
cmd = str;
int colonPos = str.indexOf(':');
if (colonPos!=-1)
{
if (colonPos != -1) {
str = str.substring(colonPos + 1);
colonPos = str.indexOf(':');
if (colonPos != -1)
{
if (colonPos != -1) {
windowName = str.substring(0, colonPos);
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
*/
public String getResponseType() {
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 ':'
* @return true if the response can be handled
*/

View file

@ -25,71 +25,89 @@
package com.wilko.jaim;
import java.util.Vector;
import java.util.List;
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
*/
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
*/
public Group(String 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
*/
public void addBuddy(Buddy 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
*
* @param buddy The buddy object to associate with this group
* @param pos the position to add the buddy
*/
public void addBuddy(Buddy buddy, int pos) {
if (pos > buddies.size()) {
buddies.add(buddy);
}
else {
} else {
buddies.add(pos, buddy);
}
}
/** This method gets the group name
/**
* This method gets the group name
*
* @return the group name
*/
public String getName() {
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
*/
public Enumeration enumerateBuddies() {
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
*/
public int getBuddyCount() {
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
*/
public java.util.Collection getBuddies() {

View file

@ -25,51 +25,59 @@
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
* @version $Revision: 1.6 $
*/
public class IMTocResponse extends TocResponse implements TocResponseHandler {
public static final String RESPONSE_TYPE = "IM_IN";
String from;
boolean autoResponse;
String msg;
public static final String RESPONSE_TYPE="IM_IN";
/** Creates new TocIMResponse */
/**
* Creates new TocIMResponse
*/
public IMTocResponse() {
from = "";
msg = "";
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
*/
public String getFrom()
{
public String getFrom() {
return (from);
}
/** Obtain the message
/**
* Obtain the message
*
* @return The message
* @see Utils#stripHTML
*/
public String getMsg()
{
public String getMsg() {
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
*/
public boolean getAutoResponse()
{
public boolean getAutoResponse() {
return (autoResponse);
}
/** Parse an incoming IM response string
/**
* Parse an incoming IM response string
*
* @param str The string to be parsed
*/
public TocResponse parseString(java.lang.String str) {
@ -78,25 +86,20 @@ public class IMTocResponse extends TocResponse implements TocResponseHandler {
return (tr);
}
private void doParse(String str)
{
private void doParse(String str) {
cmd = str;
int colonPos = str.indexOf(':');
if (colonPos!=-1)
{
if (colonPos != -1) {
str = str.substring(colonPos + 1);
colonPos = str.indexOf(':');
if (colonPos != -1)
{
if (colonPos != -1) {
from = str.substring(0, colonPos);
str = str.substring(colonPos + 1);
colonPos = str.indexOf(':');
if (str.charAt(0) == 'T')
{
if (str.charAt(0) == 'T') {
autoResponse = true;
}
if (colonPos != -1)
{
if (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
*/
public String getResponseType() {
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 ':'
* @return true if the response can be handled
*/

View file

@ -25,21 +25,31 @@
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.io.*;
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).
* Once JaimConnection has been instantiated, call {@link #connect} followed by {@link #logIn}.
*
*
* @author paulw
* @version $Revision: 1.20 $
*/
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 InputStream sin;
private OutputStream sout;
@ -47,8 +57,8 @@ public class JaimConnection implements java.lang.Runnable {
private boolean loggedIn;
private boolean loginComplete;
private boolean configValid;
private String host;
private int port;
private final String host;
private final int port;
private int clientSequence;
private int serverSequence;
private ReceiverThread rt;
@ -64,19 +74,11 @@ public class JaimConnection implements java.lang.Runnable {
private Vector messageQueue;
private boolean exit;
private long lastKeepAlive;
// Number of send "points" - used to control send rate
private int sendPoints = 10;
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
/** Creates new JaimConnection that connects to the default host and port.
/**
* Creates new JaimConnection that connects to the default host and port.
* In most cases this constructor should be used.
*/
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
*
* @param host The hostname or IP address of the TOC server
* @param port The port number to connect to on the host
*/
@ -97,7 +101,8 @@ public class JaimConnection implements java.lang.Runnable {
startMe();
}
/** start the message dispatcher thread
/**
* start the message dispatcher thread
*/
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
*/
@ -142,17 +148,9 @@ public class JaimConnection implements java.lang.Runnable {
this.debug = debug;
}
/** 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) {
}
/** Get the intermessage delay time
/**
* Get the intermessage delay time
*
* @return The intermessage delay time in milliseconds
* @deprecated This function is no longer used
*/
@ -160,7 +158,20 @@ public class JaimConnection implements java.lang.Runnable {
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
* @deprecated replaced by {@link #addEventListener}
*/
@ -168,7 +179,9 @@ public class JaimConnection implements java.lang.Runnable {
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
*/
@ -176,7 +189,9 @@ public class JaimConnection implements java.lang.Runnable {
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
*/
@ -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
*/
public void connect() throws IOException {
@ -215,9 +232,8 @@ public class JaimConnection implements java.lang.Runnable {
}
clientSequence = sf.getSequence();
serverSequence = sf.getSequence();
}
catch (FLAPFrameException e) {
throw new IOException("FLAPFrameException:"+e.toString());
} catch (FLAPFrameException e) {
throw new IOException("FLAPFrameException:" + e);
}
if (rt != null) {
rt.pleaseExit();
@ -229,7 +245,9 @@ public class JaimConnection implements java.lang.Runnable {
connected = true;
}
/** Disconnect from the TOC server
/**
* Disconnect from the TOC server
*
* @throws IOException if a network transport error occurs
*/
public void disconnect() throws IOException {
@ -238,8 +256,7 @@ public class JaimConnection implements java.lang.Runnable {
try {
rt.join(700);
myThread.join(700);
}
catch (InterruptedException e) {
} catch (InterruptedException e) {
}
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
*/
public boolean isLoginComplete() {
return (loginComplete);
}
/** Log out from the TOC server
/**
* Log out from the TOC server
*/
public void logOut() {
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
*/
public String getNickName() {
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 password the password for the specified username
* @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
{
break; // If so then return
}
else {
} else {
try {
Thread.sleep(100); //Sleep for a tenth of a second
}
catch (InterruptedException e) {
} catch (InterruptedException e) {
}
}
}
if (loginComplete) {
loggedIn = true;
}
else {
} else {
throw new JaimTimeoutException("login failed-timeout waiting for valid response");
}
}
else
} else
throw new JaimStateException("Not connected.");
}
@ -332,8 +351,7 @@ public class JaimConnection implements java.lang.Runnable {
sout.write(fr.getFrameData());
}
private int nextSequence()
{
private int nextSequence() {
int seq = clientSequence++;
if (clientSequence > 65535)
clientSequence = 0;
@ -348,7 +366,9 @@ public class JaimConnection implements java.lang.Runnable {
}
sout.write(fr.getFrameData());
}
/** The run method for the dispatcher thread
/**
* The run method for the dispatcher thread
*/
public void run() {
@ -356,21 +376,15 @@ public class JaimConnection implements java.lang.Runnable {
if (messageQueue.size() > 0) {
realDispatch((FLAPFrame) messageQueue.remove(0));
}
else {
if (System.currentTimeMillis()-lastKeepAlive>WAIT_TIME)
{
if (debug)
{
} else {
if (System.currentTimeMillis() - lastKeepAlive > WAIT_TIME) {
if (debug) {
System.out.println("No keepalive received - sending");
}
try
{
try {
sendKeepAlive();
lastKeepAlive = System.currentTimeMillis();
}
catch (IOException ioe)
{
} catch (IOException ioe) {
connectionLost();
}
}
@ -379,8 +393,7 @@ public class JaimConnection implements java.lang.Runnable {
synchronized (this) {
this.wait(WAIT_TIME);
}
}
catch (InterruptedException e) {
} catch (InterruptedException e) {
}
}
}
@ -400,8 +413,7 @@ public class JaimConnection implements java.lang.Runnable {
try {
disconnect();
}
catch (IOException e) {
} catch (IOException e) {
}
break;
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()));
}
lastKeepAlive = System.currentTimeMillis();
try
{
try {
sendKeepAlive();
}
catch (IOException e)
{
} catch (IOException e) {
connectionLost();
}
break;
@ -429,8 +438,7 @@ public class JaimConnection implements java.lang.Runnable {
loggedIn = false;
try {
s.close();
}
catch (IOException e) {
} catch (IOException e) {
}
break;
default:
@ -458,16 +466,13 @@ public class JaimConnection implements java.lang.Runnable {
sendTocCommand(tid);
deliverEvent(new LoginCompleteTocResponse()); // nform clients that login processing is now complete
loginComplete = true;
} catch (IOException e) {
}
catch (IOException e) {
}
}
else if (tr instanceof ConfigTocResponse) {
} else if (tr instanceof ConfigTocResponse ctr) {
if (debug) {
System.out.println("Received ConfigTocResponse");
}
ConfigTocResponse ctr=(ConfigTocResponse)tr;
Enumeration e = ctr.enumerateGroups();
while (e.hasMoreElements()) {
Group g = (Group) e.nextElement();
@ -486,10 +491,11 @@ public class JaimConnection implements java.lang.Runnable {
deliverEvent(tr);
}
/** Deliver a TocResponse event to registered listeners
/**
* Deliver a TocResponse event to registered listeners
*
* @param tr The TocResponse to be delivered
*/
@ -502,14 +508,17 @@ public class JaimConnection implements java.lang.Runnable {
try {
TocChatJoinCommand joinCommand = new TocChatJoinCommand(exchange, roomName);
sendTocCommand(joinCommand);
} catch (IOException ignore) {}
} catch (IOException ignore) {
}
}
public void joinChat(String roomName) {
joinChat(4, roomName);
}
/** Send an instant message
/**
* Send an instant message
*
* @param recipient The nickname of the message recipient
* @param msg The message to send
* @throws IOException if a network error occurs
@ -518,7 +527,9 @@ public class JaimConnection implements java.lang.Runnable {
sendIM(recipient, msg, false);
}
/** Send an instant message
/**
* Send an instant message
*
* @param recipient The nickname of the message recipient
* @param msg The message to send
* @param auto true if this is an automatic response (eg. away message)
@ -541,8 +552,7 @@ public class JaimConnection implements java.lang.Runnable {
try {
Thread.sleep(THRESHOLD_DELAY); // Wait until we get one point back
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 groupName The name of the group to add this buddy to
* @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) {
group.addBuddy(buddy);
}
else {
} else {
group.addBuddy(buddy, pos);
}
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
*
* @param buddyName The normalised buddy name to add
* @param groupName The name of the group to add this buddy to
* @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));
}
/** 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()}
* 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
* @throws JaimException if the method is called at the wrong time
* @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()}
* 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
* @throws JaimException if the method is called at the wrong time
* @see JaimEventListener
@ -628,8 +645,7 @@ public class JaimConnection implements java.lang.Runnable {
TocAddBuddyCommand tab = new TocAddBuddyCommand();
tab.addBuddy(buddy);
sendTocCommand(tab);
}
catch (IOException e) {
} catch (IOException e) {
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
*/
@ -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
*
* @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 {@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
*
* @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);
}
/** 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 anonymous true if the warning should be sent anonymously
* @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)
* @throws IOException if a network error occurs
*/
@ -702,7 +729,9 @@ public class JaimConnection implements java.lang.Runnable {
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)
* @throws IOException if a network error occurs
*/
@ -711,7 +740,9 @@ public class JaimConnection implements java.lang.Runnable {
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
* @return An InputStream connected to the specified URL
* @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 ""
* @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"
* @throws JaimException if a network error occurs
*/
@ -749,14 +783,15 @@ public class JaimConnection implements java.lang.Runnable {
TocAddPermitCommand tap = new TocAddPermitCommand();
tap.addPermit(buddy);
sendTocCommand(tap);
}
catch (IOException e) {
} catch (IOException e) {
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"
* @throws JaimException if a network error occurs
*/
@ -766,14 +801,14 @@ public class JaimConnection implements java.lang.Runnable {
TocAddDenyCommand tad = new TocAddDenyCommand();
tad.addDeny(buddy);
sendTocCommand(tad);
}
catch (IOException e) {
} catch (IOException e) {
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() {
@ -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
* @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.
*
* @param buddy The buddy name to be deleted\
* @deprecated use {@link #unwatchBuddy } instead
*/
@ -803,8 +841,10 @@ public class JaimConnection implements java.lang.Runnable {
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.
*
* @param buddy The buddy name to be deleted
*/
public void unwatchBuddy(String buddy) {
@ -814,7 +854,7 @@ public class JaimConnection implements java.lang.Runnable {
private class ReceiverThread extends Thread {
private InputStream sin;
private boolean exit;
private JaimConnection parent;
private final JaimConnection parent;
private ReceiverThread(JaimConnection parent) {
this.parent = parent;
@ -841,8 +881,7 @@ public class JaimConnection implements java.lang.Runnable {
try {
FLAPFrame fr = FLAPFrameFactory.createFLAPFrame(inframe.getFrameData());
parent.Dispatch(fr);
}
catch (FLAPFrameException ffe) {
} catch (FLAPFrameException ffe) {
if (debug) {
ffe.printStackTrace();
}
@ -850,13 +889,11 @@ public class JaimConnection implements java.lang.Runnable {
if (inframe.completeFrameRead()) {
inframe.resetInputFrame();
}
}
catch (InterruptedIOException iie) {
} catch (InterruptedIOException iie) {
// 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
if (debug) {
e.printStackTrace();
@ -869,9 +906,11 @@ public class JaimConnection implements java.lang.Runnable {
}
}
private class DeliveryThread extends Thread {
private Vector messages;
private final Vector messages;
private boolean exit;
private DeliveryThread() {
messages = new Vector();
exit = false;
@ -892,15 +931,11 @@ public class JaimConnection implements java.lang.Runnable {
if (messages.size() > 0) {
TocResponse tr = (TocResponse) messages.remove(0);
doDelivery(tr);
}
else {
} else {
synchronized (this) {
try
{
try {
this.wait();
}
catch (InterruptedException e)
{
} catch (InterruptedException e) {
}
}
}

View file

@ -19,23 +19,26 @@
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
* @version $revision: $
* @see JaimConnection#addEventListener
*/
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) {
super(source);
this.tocResponse = tocResponse;
}
public TocResponse getTocResponse()
{
public TocResponse getTocResponse() {
return (tocResponse);
}

View file

@ -25,16 +25,20 @@
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.
*
* @author paulw
* @version $Revision: 1.3 $
*/
public interface JaimEventListener {
/** Receive an incoming {@link JaimEvent}
/**
* Receive an incoming {@link JaimEvent}
*
* @param ev - The incoming event
*/
public void receiveEvent(JaimEvent ev);
void receiveEvent(JaimEvent ev);
}

View file

@ -26,7 +26,6 @@
package com.wilko.jaim;
/**
*
* @author paulw
* @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.
*
* @param msg the detail message.
*/
public JaimException(String msg) {

View file

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

View file

@ -20,7 +20,6 @@
package com.wilko.jaim;
/**
*
* @author paulw
* @version $version: $
*/
@ -35,6 +34,7 @@ public class JaimTimeoutException extends JaimException {
/**
* Constructs an <code>JaimTimeoutException</code> with the specified detail message.
*
* @param msg the detail message.
*/
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.
*
* @author wilko
* @version: $revision: $
*/
@ -34,7 +35,9 @@ public class LoginCompleteTocResponse extends TocResponse {
public static final String RESPONSE_TYPE = "LOGINCOMPLETE";
/** Creates a new instance of LoginCompleteTocResponse */
/**
* Creates a new instance of LoginCompleteTocResponse
*/
public LoginCompleteTocResponse() {
}
@ -42,8 +45,7 @@ public class LoginCompleteTocResponse extends TocResponse {
return (RESPONSE_TYPE);
}
public String toString()
{
public String toString() {
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}
*
* @author paulw
* @version $Revision: 1.6 $
*/
public class NickTocResponse extends TocResponse implements TocResponseHandler {
public static final String RESPONSE_TYPE = "NICK";
private String nickName;
public static final String RESPONSE_TYPE="NICK";
/** Creates new NickTocResponse */
/**
* Creates new NickTocResponse
*/
public NickTocResponse() {
nickName = "";
}
@ -49,20 +51,17 @@ public class NickTocResponse extends TocResponse implements TocResponseHandler {
return (tr);
}
private void doParse(String str)
{
private void doParse(String str) {
int colonPos = str.indexOf(':');
if (colonPos != -1)
{
if (colonPos != -1) {
nickName = str.substring(colonPos + 1);
}
}
public String getNickName()
{
public String getNickName() {
return (nickName);
}
@ -71,7 +70,9 @@ public class NickTocResponse extends TocResponse implements TocResponseHandler {
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 ':'
* @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}
*
* @author paulw
* @version $Revision: 1.5 $
*/
public class SignOnTocResponse extends TocResponse implements TocResponseHandler {
public static final String RESPONSE_TYPE = "SIGN_ON";
String version;
public static final String RESPONSE_TYPE="SIGN_ON";
/** Creates new SignOnTocResponse */
/**
* Creates new SignOnTocResponse
*/
public SignOnTocResponse() {
version = "";
}
@ -46,30 +48,28 @@ public class SignOnTocResponse extends TocResponse implements TocResponseHandler
return (RESPONSE_TYPE);
}
protected String getVersion()
{
protected String getVersion() {
return (version);
}
public TocResponse parseString(String str)
{
public TocResponse parseString(String str) {
SignOnTocResponse tr = new SignOnTocResponse();
tr.doParse(str);
return (tr);
}
private void doParse(String str)
{
private void doParse(String str) {
cmd = str;
int colonpos = str.indexOf(':');
if (colonpos != -1)
{
if (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 ':'
* @return true if the response can be handled
*/

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -39,18 +39,18 @@
package com.wilko.jaim;
/**
*
* @author paulw
* @version $version: $
*/
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
*@param username The screen name for whom information is requested
/**
* Creates new TocGetInfoCommand
*
* @param username The screen name for whom information is requested
*/
public TocGetInfoCommand(String username) {
@ -58,8 +58,7 @@ public class TocGetInfoCommand extends TocCommand {
}
public String toString()
{
public String toString() {
return (CMD + username);
}

View file

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

View file

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

View file

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

View file

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

View file

@ -20,25 +20,28 @@
package com.wilko.jaim;
/**
*
* @author paulw
* @version $revision: $
*/
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 ':'
* @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
* @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;
/**
*
* @author paulw
* @version $version: $
*/
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 ""
*/
@ -44,8 +45,7 @@ public class TocSetAwayCommand extends TocCommand {
}
public String toString()
{
public String toString() {
return (CMD + awayMsg);
}

View file

@ -28,42 +28,37 @@ package com.wilko.jaim;
import java.util.Enumeration;
/**
*
* @author paulw
*/
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() {
config = new StringBuffer();
}
public void addGroup(Group g)
{
public void addGroup(Group g) {
config.append("g " + g.getName() + "\n");
Enumeration buddies = g.enumerateBuddies();
while (buddies.hasMoreElements())
{
while (buddies.hasMoreElements()) {
Buddy b = (Buddy) buddies.nextElement();
config.append("b " + b.getName() + "\n");
if (b.getPermit())
{
if (b.getPermit()) {
config.append("p " + b.getName() + "\n");
}
if (b.getDeny())
{
if (b.getDeny()) {
config.append("d " + b.getName() + "\n");
}
}
}
public String toString()
{
public String toString() {
return (CMD + '"' + config.toString() + '"');
}

View file

@ -25,24 +25,24 @@
package com.wilko.jaim;
/**
*
* @author paulw
* @version $version: $
*/
public class TocSetIdleCommand extends TocCommand {
private int 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
*/
public TocSetIdleCommand(int idleSecs) {
idle = idleSecs;
}
public String toString()
{
public String toString() {
return (CMD + idle);
}

View file

@ -26,16 +26,17 @@
package com.wilko.jaim;
/**
*
* @author paulw
* @version $version: $
*/
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
*/
@ -44,8 +45,7 @@ public class TocSetInfoCommand extends TocCommand {
}
public String toString()
{
public String toString() {
return (CMD + information);
}

View file

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

View file

@ -26,7 +26,6 @@
package com.wilko.jaim;
/**
*
* @author paulw
* @version $Revision: 1.4 $
*/
@ -35,18 +34,18 @@ public class Utils {
private static final String roastKey = "Tic/Toc";
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
* @return the normalised buddy name
*/
public static String normalise(java.lang.String input) {
StringBuffer output = new StringBuffer();
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);
if ((c>= '0' && c<='9')||(c>='a' && c<='z'))
{
if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'z')) {
output.append(c);
}
}
@ -54,7 +53,9 @@ public class Utils {
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
* @return The roasted password
*/
@ -63,8 +64,7 @@ public class Utils {
StringBuffer temppw = new StringBuffer();
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);
temppw.append(hexChars[(roastedByte >> 4) & 0x0f]);
@ -73,31 +73,25 @@ public class Utils {
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 '>'
*
* @param input The text to have HTML stripped
* @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();
boolean inHTML = false;
for (int i=0;i<input.length();i++)
{
for (int i = 0; i < input.length(); i++) {
char c = input.charAt(i);
if (c=='<')
{
if (c == '<') {
inHTML = true;
}
else
{
} else {
if (c == '>') {
inHTML = false;
}
else
{
if (!inHTML)
{
} else {
if (!inHTML) {
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
* @return The encoded text
*/
public static String encodeText(String input)
{
public static String encodeText(String input) {
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);
switch (c)
{
switch (c) {
case '\"':
case '(':
case ')':

View file

@ -25,12 +25,13 @@
package com.wilko.jaimtest;
import java.net.*;
import java.io.*;
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