From d73fb78686e827360d90d91483e17c9ebd04e462 Mon Sep 17 00:00:00 2001 From: Frankie B Date: Fri, 10 May 2024 01:12:35 +0100 Subject: Implement remaining client commands, organize into packages --- src/com/wilko/jaim/BuddyUpdateTocResponse.java | 211 -------------------- src/com/wilko/jaim/ChatInviteTocResponse.java | 111 ----------- src/com/wilko/jaim/ConfigTocResponse.java | 209 -------------------- src/com/wilko/jaim/ConnectionLostTocResponse.java | 52 ----- src/com/wilko/jaim/ErrorTocResponse.java | 144 -------------- src/com/wilko/jaim/EvilTocResponse.java | 125 ------------ src/com/wilko/jaim/FLAPDataFrame.java | 73 ------- src/com/wilko/jaim/FLAPErrorFrame.java | 51 ----- src/com/wilko/jaim/FLAPFrame.java | 109 ----------- src/com/wilko/jaim/FLAPFrameException.java | 51 ----- src/com/wilko/jaim/FLAPFrameFactory.java | 68 ------- src/com/wilko/jaim/FLAPInputFrame.java | 69 ------- src/com/wilko/jaim/FLAPKeepAliveFrame.java | 55 ------ src/com/wilko/jaim/FLAPSignoffFrame.java | 52 ----- src/com/wilko/jaim/FLAPSignonFrame.java | 82 -------- src/com/wilko/jaim/GenericTocResponse.java | 95 --------- src/com/wilko/jaim/GotoTocResponse.java | 113 ----------- src/com/wilko/jaim/IMTocResponse.java | 129 ------------- src/com/wilko/jaim/JaimConnection.java | 102 ++++++++++ src/com/wilko/jaim/JaimEvent.java | 2 + src/com/wilko/jaim/JaimEventListener.java | 2 + src/com/wilko/jaim/LoginCompleteTocResponse.java | 52 ----- src/com/wilko/jaim/NickTocResponse.java | 83 -------- src/com/wilko/jaim/SignOnTocResponse.java | 80 -------- src/com/wilko/jaim/TocAddBuddyCommand.java | 65 ------- src/com/wilko/jaim/TocAddDenyCommand.java | 65 ------- src/com/wilko/jaim/TocAddPermitCommand.java | 65 ------- src/com/wilko/jaim/TocChatJoinCommand.java | 53 ----- src/com/wilko/jaim/TocCommand.java | 44 ----- src/com/wilko/jaim/TocEvilCommand.java | 59 ------ src/com/wilko/jaim/TocGetInfoCommand.java | 69 ------- src/com/wilko/jaim/TocIMCommand.java | 58 ------ src/com/wilko/jaim/TocInitDoneCommand.java | 50 ----- src/com/wilko/jaim/TocResponse.java | 46 ----- src/com/wilko/jaim/TocResponseFactory.java | 75 -------- src/com/wilko/jaim/TocResponseHandler.java | 47 ----- src/com/wilko/jaim/TocSetAwayCommand.java | 56 ------ src/com/wilko/jaim/TocSetConfigCommand.java | 69 ------- src/com/wilko/jaim/TocSetIdleCommand.java | 53 ----- src/com/wilko/jaim/TocSetInfoCommand.java | 56 ------ src/com/wilko/jaim/TocSignonCommand.java | 62 ------ .../wilko/jaim/commands/TocAddBuddyCommand.java | 67 +++++++ src/com/wilko/jaim/commands/TocAddDenyCommand.java | 67 +++++++ .../wilko/jaim/commands/TocAddPermitCommand.java | 67 +++++++ .../wilko/jaim/commands/TocChatAcceptCommand.java | 51 +++++ .../wilko/jaim/commands/TocChatEvilCommand.java | 55 ++++++ .../wilko/jaim/commands/TocChatInviteCommand.java | 55 ++++++ .../wilko/jaim/commands/TocChatJoinCommand.java | 53 +++++ .../wilko/jaim/commands/TocChatLeaveCommand.java | 51 +++++ .../wilko/jaim/commands/TocChatSendCommand.java | 53 +++++ .../wilko/jaim/commands/TocChatWhisperCommand.java | 55 ++++++ src/com/wilko/jaim/commands/TocCommand.java | 44 +++++ src/com/wilko/jaim/commands/TocEvilCommand.java | 61 ++++++ src/com/wilko/jaim/commands/TocGetInfoCommand.java | 71 +++++++ src/com/wilko/jaim/commands/TocIMCommand.java | 60 ++++++ .../wilko/jaim/commands/TocInitDoneCommand.java | 50 +++++ src/com/wilko/jaim/commands/TocSetAwayCommand.java | 58 ++++++ .../wilko/jaim/commands/TocSetConfigCommand.java | 72 +++++++ src/com/wilko/jaim/commands/TocSetIdleCommand.java | 53 +++++ src/com/wilko/jaim/commands/TocSetInfoCommand.java | 58 ++++++ src/com/wilko/jaim/commands/TocSignonCommand.java | 64 +++++++ src/com/wilko/jaim/flap/FLAPDataFrame.java | 73 +++++++ src/com/wilko/jaim/flap/FLAPErrorFrame.java | 51 +++++ src/com/wilko/jaim/flap/FLAPFrame.java | 109 +++++++++++ src/com/wilko/jaim/flap/FLAPFrameException.java | 51 +++++ src/com/wilko/jaim/flap/FLAPFrameFactory.java | 68 +++++++ src/com/wilko/jaim/flap/FLAPInputFrame.java | 69 +++++++ src/com/wilko/jaim/flap/FLAPKeepAliveFrame.java | 55 ++++++ src/com/wilko/jaim/flap/FLAPSignoffFrame.java | 52 +++++ src/com/wilko/jaim/flap/FLAPSignonFrame.java | 82 ++++++++ .../jaim/responses/BuddyUpdateTocResponse.java | 213 +++++++++++++++++++++ .../jaim/responses/ChatInviteTocResponse.java | 113 +++++++++++ .../wilko/jaim/responses/ConfigTocResponse.java | 211 ++++++++++++++++++++ .../jaim/responses/ConnectionLostTocResponse.java | 52 +++++ src/com/wilko/jaim/responses/ErrorTocResponse.java | 146 ++++++++++++++ src/com/wilko/jaim/responses/EvilTocResponse.java | 127 ++++++++++++ .../wilko/jaim/responses/GenericTocResponse.java | 97 ++++++++++ src/com/wilko/jaim/responses/GotoTocResponse.java | 115 +++++++++++ src/com/wilko/jaim/responses/IMTocResponse.java | 132 +++++++++++++ .../jaim/responses/LoginCompleteTocResponse.java | 52 +++++ src/com/wilko/jaim/responses/NickTocResponse.java | 85 ++++++++ .../wilko/jaim/responses/SignOnTocResponse.java | 82 ++++++++ src/com/wilko/jaim/responses/TocResponse.java | 46 +++++ .../wilko/jaim/responses/TocResponseFactory.java | 75 ++++++++ .../wilko/jaim/responses/TocResponseHandler.java | 47 +++++ src/com/wilko/jaimtest/JaimTest.java | 1 + 86 files changed, 3475 insertions(+), 3006 deletions(-) delete mode 100644 src/com/wilko/jaim/BuddyUpdateTocResponse.java delete mode 100644 src/com/wilko/jaim/ChatInviteTocResponse.java delete mode 100644 src/com/wilko/jaim/ConfigTocResponse.java delete mode 100644 src/com/wilko/jaim/ConnectionLostTocResponse.java delete mode 100644 src/com/wilko/jaim/ErrorTocResponse.java delete mode 100644 src/com/wilko/jaim/EvilTocResponse.java delete mode 100644 src/com/wilko/jaim/FLAPDataFrame.java delete mode 100644 src/com/wilko/jaim/FLAPErrorFrame.java delete mode 100644 src/com/wilko/jaim/FLAPFrame.java delete mode 100644 src/com/wilko/jaim/FLAPFrameException.java delete mode 100644 src/com/wilko/jaim/FLAPFrameFactory.java delete mode 100644 src/com/wilko/jaim/FLAPInputFrame.java delete mode 100644 src/com/wilko/jaim/FLAPKeepAliveFrame.java delete mode 100644 src/com/wilko/jaim/FLAPSignoffFrame.java delete mode 100644 src/com/wilko/jaim/FLAPSignonFrame.java delete mode 100644 src/com/wilko/jaim/GenericTocResponse.java delete mode 100644 src/com/wilko/jaim/GotoTocResponse.java delete mode 100644 src/com/wilko/jaim/IMTocResponse.java delete mode 100644 src/com/wilko/jaim/LoginCompleteTocResponse.java delete mode 100644 src/com/wilko/jaim/NickTocResponse.java delete mode 100644 src/com/wilko/jaim/SignOnTocResponse.java delete mode 100644 src/com/wilko/jaim/TocAddBuddyCommand.java delete mode 100644 src/com/wilko/jaim/TocAddDenyCommand.java delete mode 100644 src/com/wilko/jaim/TocAddPermitCommand.java delete mode 100644 src/com/wilko/jaim/TocChatJoinCommand.java delete mode 100644 src/com/wilko/jaim/TocCommand.java delete mode 100644 src/com/wilko/jaim/TocEvilCommand.java delete mode 100644 src/com/wilko/jaim/TocGetInfoCommand.java delete mode 100644 src/com/wilko/jaim/TocIMCommand.java delete mode 100644 src/com/wilko/jaim/TocInitDoneCommand.java delete mode 100644 src/com/wilko/jaim/TocResponse.java delete mode 100644 src/com/wilko/jaim/TocResponseFactory.java delete mode 100644 src/com/wilko/jaim/TocResponseHandler.java delete mode 100644 src/com/wilko/jaim/TocSetAwayCommand.java delete mode 100644 src/com/wilko/jaim/TocSetConfigCommand.java delete mode 100644 src/com/wilko/jaim/TocSetIdleCommand.java delete mode 100644 src/com/wilko/jaim/TocSetInfoCommand.java delete mode 100644 src/com/wilko/jaim/TocSignonCommand.java create mode 100644 src/com/wilko/jaim/commands/TocAddBuddyCommand.java create mode 100644 src/com/wilko/jaim/commands/TocAddDenyCommand.java create mode 100644 src/com/wilko/jaim/commands/TocAddPermitCommand.java create mode 100644 src/com/wilko/jaim/commands/TocChatAcceptCommand.java create mode 100644 src/com/wilko/jaim/commands/TocChatEvilCommand.java create mode 100644 src/com/wilko/jaim/commands/TocChatInviteCommand.java create mode 100644 src/com/wilko/jaim/commands/TocChatJoinCommand.java create mode 100644 src/com/wilko/jaim/commands/TocChatLeaveCommand.java create mode 100644 src/com/wilko/jaim/commands/TocChatSendCommand.java create mode 100644 src/com/wilko/jaim/commands/TocChatWhisperCommand.java create mode 100644 src/com/wilko/jaim/commands/TocCommand.java create mode 100644 src/com/wilko/jaim/commands/TocEvilCommand.java create mode 100644 src/com/wilko/jaim/commands/TocGetInfoCommand.java create mode 100644 src/com/wilko/jaim/commands/TocIMCommand.java create mode 100644 src/com/wilko/jaim/commands/TocInitDoneCommand.java create mode 100644 src/com/wilko/jaim/commands/TocSetAwayCommand.java create mode 100644 src/com/wilko/jaim/commands/TocSetConfigCommand.java create mode 100644 src/com/wilko/jaim/commands/TocSetIdleCommand.java create mode 100644 src/com/wilko/jaim/commands/TocSetInfoCommand.java create mode 100644 src/com/wilko/jaim/commands/TocSignonCommand.java create mode 100644 src/com/wilko/jaim/flap/FLAPDataFrame.java create mode 100644 src/com/wilko/jaim/flap/FLAPErrorFrame.java create mode 100644 src/com/wilko/jaim/flap/FLAPFrame.java create mode 100644 src/com/wilko/jaim/flap/FLAPFrameException.java create mode 100644 src/com/wilko/jaim/flap/FLAPFrameFactory.java create mode 100644 src/com/wilko/jaim/flap/FLAPInputFrame.java create mode 100644 src/com/wilko/jaim/flap/FLAPKeepAliveFrame.java create mode 100644 src/com/wilko/jaim/flap/FLAPSignoffFrame.java create mode 100644 src/com/wilko/jaim/flap/FLAPSignonFrame.java create mode 100644 src/com/wilko/jaim/responses/BuddyUpdateTocResponse.java create mode 100644 src/com/wilko/jaim/responses/ChatInviteTocResponse.java create mode 100644 src/com/wilko/jaim/responses/ConfigTocResponse.java create mode 100644 src/com/wilko/jaim/responses/ConnectionLostTocResponse.java create mode 100644 src/com/wilko/jaim/responses/ErrorTocResponse.java create mode 100644 src/com/wilko/jaim/responses/EvilTocResponse.java create mode 100644 src/com/wilko/jaim/responses/GenericTocResponse.java create mode 100644 src/com/wilko/jaim/responses/GotoTocResponse.java create mode 100644 src/com/wilko/jaim/responses/IMTocResponse.java create mode 100644 src/com/wilko/jaim/responses/LoginCompleteTocResponse.java create mode 100644 src/com/wilko/jaim/responses/NickTocResponse.java create mode 100644 src/com/wilko/jaim/responses/SignOnTocResponse.java create mode 100644 src/com/wilko/jaim/responses/TocResponse.java create mode 100644 src/com/wilko/jaim/responses/TocResponseFactory.java create mode 100644 src/com/wilko/jaim/responses/TocResponseHandler.java (limited to 'src') diff --git a/src/com/wilko/jaim/BuddyUpdateTocResponse.java b/src/com/wilko/jaim/BuddyUpdateTocResponse.java deleted file mode 100644 index d7cc314..0000000 --- a/src/com/wilko/jaim/BuddyUpdateTocResponse.java +++ /dev/null @@ -1,211 +0,0 @@ -/* - * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -/* - * BuddyUpdateTocResponse.java - * - * Created on 5 May 2002, 21:19 - */ - -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 - * - * @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; - private int idleTime; - private boolean onAOL; - private boolean unconfirmed; - private boolean admin; - private boolean confirmed; - private Date signonTime; - private boolean away; - - /** - * Creates new BuddyUpdateTocResponse - */ - public BuddyUpdateTocResponse() { - buddyName = ""; - online = false; - evil = 0; - idleTime = 0; - onAOL = false; - unconfirmed = false; - admin = false; - confirmed = false; - away = false; - } - - /** - * 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) { - BuddyUpdateTocResponse tr = new BuddyUpdateTocResponse(); - tr.doParse(str); - return (tr); - } - - private void doParse(String str) { - cmd = str; - StringTokenizer st = new StringTokenizer(str, ":"); - - st.nextToken(); - buddyName = st.nextToken(); - String onlineStr = st.nextToken(); - online = onlineStr.equals("T"); - - evil = Integer.parseInt(st.nextToken()); - long signon = Long.parseLong(st.nextToken()); - signonTime = new Date(signon * 1000); - idleTime = Integer.parseInt(st.nextToken()); - String userclass = st.nextToken(); - if (userclass.charAt(0) == 'A') - onAOL = true; - if (userclass.charAt(1) == 'A') { - admin = true; - } else { - if (userclass.charAt(1) == 'U') { - unconfirmed = true; - } else { - if (userclass.charAt(1) == 'O') { - confirmed = true; - } - } - } - if (userclass.length() > 2) { - if (userclass.charAt(2) == 'U') { - away = true; - } - } - } - - /** - * Get the away status of the buddy specified by this update - * - * @return true if the buddy is "away" - */ - public boolean isAway() { - return (away); - } - - /** - * 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 - * - * @return The buddy name - */ - public String getBuddy() { - return (buddyName); - } - - /** - * Obtain the online status of this buddy update - * - * @return true if the buddy is on line - */ - public boolean isOnline() { - return (online); - } - - /** - * Obtain the idle time of this buddy - * - * @return The idle time in seconds - */ - public int getIdleTime() { - return (idleTime); - } - - /** - * Obtain the "Evil" (Warning) level of this buddy - * - * @return The warning level as a percentage - */ - public int getEvil() { - return (evil); - } - - /** - * Is this buddy an "Administrator" - * - * @return true if an administrator - */ - public boolean isAdmin() { - return (admin); - } - - /** - * IS this buddy a "confirmed" user - * - * @return True if this buddy is confirmed - */ - public boolean isConfirmed() { - return (confirmed); - } - - /** - * Is this user an "Unconfirmed user" - * - * @return True if this user is unconfirmed - */ - public boolean isUnconfirmed() { - return (unconfirmed); - } - - /** - * Get the signon time of this buddy - * - * @return The date/time of signon - */ - public Date getSignonTime() { - return (signonTime); - } - - /** - * 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) { - return (Response.equalsIgnoreCase(RESPONSE_TYPE)); - } - -} diff --git a/src/com/wilko/jaim/ChatInviteTocResponse.java b/src/com/wilko/jaim/ChatInviteTocResponse.java deleted file mode 100644 index 7bd247e..0000000 --- a/src/com/wilko/jaim/ChatInviteTocResponse.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -/* - * BuddyUpdateTocResponse.java - * - * Created on 5 May 2002, 21:19 - */ - -package com.wilko.jaim; - -import java.util.StringTokenizer; - -/** - * 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; - - /** - * Creates new BuddyUpdateTocResponse - */ - public ChatInviteTocResponse() { - roomName = ""; - roomID = ""; - senderScreenname = ""; - message = ""; - } - - /** - * 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) { - ChatInviteTocResponse tr = new ChatInviteTocResponse(); - tr.doParse(str); - return (tr); - } - - private void doParse(String str) { - cmd = str; - StringTokenizer st = new StringTokenizer(str, ":"); - - st.nextToken(); - roomName = st.nextToken(); - roomID = st.nextToken(); - senderScreenname = st.nextToken(); - message = st.nextToken(); - } - - /** - * 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; - } - - public String getRoomName() { - return roomName; - } - - public String getRoomID() { - return roomID; - } - - public String getSenderScreenname() { - return senderScreenname; - } - - public String getMessage() { - return message; - } - - /** - * 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) { - return (Response.equalsIgnoreCase(RESPONSE_TYPE)); - } - -} diff --git a/src/com/wilko/jaim/ConfigTocResponse.java b/src/com/wilko/jaim/ConfigTocResponse.java deleted file mode 100644 index b9ae399..0000000 --- a/src/com/wilko/jaim/ConfigTocResponse.java +++ /dev/null @@ -1,209 +0,0 @@ -/* - * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -/* - * ConfigTocResponse.java - * Created on 1, October 2002 - */ -package com.wilko.jaim; - -import java.util.*; - -/** - * 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 final Vector buddyList = new Vector(); - /** - * The HashMap of known buddies - */ - private HashMap buddies; - /** - * The mode for this configuration - */ - private int mode; - - /** - * 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() { - return buddyList.elements(); - } - - /** - * Returns a Collection of groups. Each element is a {@link Group) - * - * @return the groups - */ - public Collection getGroups() { - java.util.Collection result = new Vector(buddyList); - return result; - } - - - /** - * 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. - */ - public TocResponse parseString(String message) { - ConfigTocResponse tr = new ConfigTocResponse(); - tr.doParse(message); - return (tr); - } - - private void doParse(String message) { - cmd = message; - int colonIndex = message.indexOf(':'); - //throw away the first word. - 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()) { - // 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 = itemType.substring(0, firstSpace); - - char type = itemType.charAt(0); - switch (type) { - case 'g': - currentGroup = new Group(itemValue); - buddyList.add(currentGroup); - break; - - case 'b': - - tmpBuddy = getBuddy(itemValue); - //this shouldn't happen, but: - if (currentGroup == null) { - currentGroup = new Group(""); - buddyList.add(currentGroup); - } - currentGroup.addBuddy(tmpBuddy); - - - break; - - case 'p': - tmpBuddy = getBuddy(itemValue); - tmpBuddy.setPermit(true); - break; - - case 'm': - setMode(Integer.valueOf(itemValue).intValue()); - break; - - case 'd': - - tmpBuddy = getBuddy(itemValue); - tmpBuddy.setDeny(true); - break; - } - } - } - - /** - * 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) { - Buddy retBuddy = (Buddy) buddies.get(buddyName); - if (retBuddy == null) { - retBuddy = new Buddy(buddyName); - buddies.put(buddyName, retBuddy); - } - return (retBuddy); - } - - /** - * Gets the mode for this configuration - * - * @return mode for the configuration - */ - public int getMode() { - return mode; - } - - /** - * 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 - */ - public boolean canHandle(String Response) { - return (Response.equalsIgnoreCase(RESPONSE_TYPE)); - } - -} diff --git a/src/com/wilko/jaim/ConnectionLostTocResponse.java b/src/com/wilko/jaim/ConnectionLostTocResponse.java deleted file mode 100644 index 4cc1724..0000000 --- a/src/com/wilko/jaim/ConnectionLostTocResponse.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -/* - * ConnectionLostTocResponse.java - * - * Created on November 2, 2002, 2:52 PM - */ - -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: $ - */ -public class ConnectionLostTocResponse extends TocResponse { - - public static final String RESPONSE_TYPE = "CONNECTIONLOST"; - - /** - * Creates a new instance of LoginCompleteTocResponse - */ - public ConnectionLostTocResponse() { - } - - public String getResponseType() { - return (RESPONSE_TYPE); - } - - public String toString() { - return (RESPONSE_TYPE); - } - -} diff --git a/src/com/wilko/jaim/ErrorTocResponse.java b/src/com/wilko/jaim/ErrorTocResponse.java deleted file mode 100644 index 1ff8188..0000000 --- a/src/com/wilko/jaim/ErrorTocResponse.java +++ /dev/null @@ -1,144 +0,0 @@ -/* - * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -/* - * ErrorTocResponse.java - * - * Created on 4 May 2002, 14:52 - */ - -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 - * - * @author paulw - * @version $Revision: 1.7 $ - */ -public class ErrorTocResponse extends TocResponse implements TocResponseHandler { - - public static final String RESPONSE_TYPE = "ERROR"; - int errorCode; - String errorText; - - /** - * 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 - * - * @param str The error response string - */ - public TocResponse parseString(String str) { - ErrorTocResponse tr = new ErrorTocResponse(); - tr.doParse(str); - return (tr); - } - - private void doParse(String str) { - - cmd = str; - int colonPos = str.indexOf(':'); - if (colonPos != -1) { - str = str.substring(colonPos + 1); - colonPos = str.indexOf(':'); - if (colonPos != -1) { - errorCode = Integer.parseInt(str.substring(0, colonPos)); - errorText = str.substring(colonPos + 1); - } else { - errorCode = Integer.parseInt(str); - } - } - - } - - /** - * Obtain the error code for this response - * - * @return The error code - */ - public int getErrorCode() { - return (errorCode); - } - - /** - * Get the error text (if any) associated with this error response - * - * @return The error text - */ - public String getErrorText() { - return (errorText); - } - - /** - * Obtain the error message that corresponds to this error. - * - * @return The error text with any applicable error argument text inserted - */ - public String getErrorDescription() { - try { - StringBuffer desc = new StringBuffer(java.util.ResourceBundle.getBundle("com/wilko/jaim/TocErrorDescriptions").getString(Integer.toString(errorCode))); - String sDesc = desc.toString(); - int argpos = sDesc.indexOf("%s"); - if (argpos != -1) { - desc.replace(argpos, argpos + 1, errorText); - } - return (desc.toString()); - - } catch (MissingResourceException e) { - return ("Unable to locate error description:" + e); - } - } - - public String getResponseType() { - return RESPONSE_TYPE; - } - - /** - * 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) { - return (Response.equalsIgnoreCase(RESPONSE_TYPE)); - } - -} diff --git a/src/com/wilko/jaim/EvilTocResponse.java b/src/com/wilko/jaim/EvilTocResponse.java deleted file mode 100644 index caa7e98..0000000 --- a/src/com/wilko/jaim/EvilTocResponse.java +++ /dev/null @@ -1,125 +0,0 @@ -/* - * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -/* - * EvilTocResponse.java - * - * Created on 6 May 2002, 16:49 - */ - -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 - * - * @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; - - /** - * Creates new EvilTocResponse - */ - public EvilTocResponse() { - anonymousEvil = true; - evilBy = ""; - evilAmount = 0; - } - - /** - * Parse the evil message from the TOC server - * - * @param str The evil message - */ - public TocResponse parseString(java.lang.String str) { - EvilTocResponse tr = new EvilTocResponse(); - tr.doParse(str); - return (tr); - } - - private void doParse(String str) { - - StringTokenizer st = new StringTokenizer(str, ":"); - - st.nextToken(); // skip over "EVILED" - evilAmount = Integer.parseInt(st.nextToken()); - if (st.hasMoreTokens()) { - evilBy = st.nextToken(); - anonymousEvil = false; - } 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 - * - * @return The cumulative evil or warning level - */ - public int getEvilAmount() { - return (evilAmount); - } - - /** - * Obtain the name of the buddy that issued the warning. - * - * @return The buddy name that issued the warning - * @see #isAnonymous - */ - public String getEvilBy() { - return (evilBy); - } - - /** - * Obtain the anonymous status of this warning - * - * @return true if this warning was issued anonymously - */ - public boolean isAnonymous() { - return (anonymousEvil); - } - - /** - * Used by the response dispatcher - * - * @return The response type - */ - public String getResponseType() { - return RESPONSE_TYPE; - } - - - /** - * 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) { - return (Response.equalsIgnoreCase(RESPONSE_TYPE)); - } - -} diff --git a/src/com/wilko/jaim/FLAPDataFrame.java b/src/com/wilko/jaim/FLAPDataFrame.java deleted file mode 100644 index a5bd2ae..0000000 --- a/src/com/wilko/jaim/FLAPDataFrame.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -/* - * FlapDataFrame.java - * - * Created on 3 May 2002, 14:54 - */ - -package com.wilko.jaim; - -/** - * @author paulw - * @version $Revision: 1.3 $ - */ -public class FLAPDataFrame extends FLAPFrame { - - private int frameLen; - - /** - * Creates new FlapDataFrame - */ - public FLAPDataFrame() { - frame[1] = FLAP_FRAME_DATA; - frameLen = 1; - frame[FLAP_DATA_OFFSET] = 0; - } - - public FLAPDataFrame(byte[] frameData) { - frame[1] = FLAP_FRAME_DATA; - frameLen = 1; - frame[FLAP_DATA_OFFSET] = 0; - setFrameData(frameData); - } - - - public int getFLAPFrameType() { - return (FLAPFrame.FLAP_FRAME_DATA); - } - - public void addString(String s) { - frameLen--; // Backspace over '0' - 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() { - byte[] retarray = new byte[getLength()]; - - System.arraycopy(frame, FLAPFrame.FLAP_DATA_OFFSET, retarray, 0, getLength()); - return (retarray); - } - -} diff --git a/src/com/wilko/jaim/FLAPErrorFrame.java b/src/com/wilko/jaim/FLAPErrorFrame.java deleted file mode 100644 index 1df6e03..0000000 --- a/src/com/wilko/jaim/FLAPErrorFrame.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ -/* - * FlapErrorFrame.java - * - * Created on 3 May 2002, 14:54 - */ - -package com.wilko.jaim; - -/** - * @author paulw - * @version $Revision: 1.3 $ - */ -public class FLAPErrorFrame extends FLAPFrame { - - /** - * Creates new FLAPErrorFrame - */ - public FLAPErrorFrame() { - frame[1] = FLAP_FRAME_ERROR; - - } - - public FLAPErrorFrame(byte[] frameData) { - frame[1] = FLAP_FRAME_ERROR; - setFrameData(frameData); - } - - - public int getFLAPFrameType() { - return FLAPFrame.FLAP_FRAME_ERROR; - } - -} diff --git a/src/com/wilko/jaim/FLAPFrame.java b/src/com/wilko/jaim/FLAPFrame.java deleted file mode 100644 index bef422d..0000000 --- a/src/com/wilko/jaim/FLAPFrame.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -/* - * FLAPFrame.java - * - * Created on 3 May 2002, 14:51 - */ - -package com.wilko.jaim; - -/** - * @author paulw - * @version $Revision: 1.4 $ - */ -public abstract class FLAPFrame { - - public static final int FLAP_FRAME_SIGNON = 1; - public static final int FLAP_FRAME_DATA = 2; - public static final int FLAP_FRAME_ERROR = 3; - public static final int FLAP_FRAME_SIGNOFF = 4; - public static final int FLAP_FRAME_KEEP_ALIVE = 5; - public static final int FLAP_DATA_OFFSET = 6; - - protected byte[] frame; - protected int fLen; - - /** - * Creates new FLAPFrame - */ - public FLAPFrame() { - initialise(); - } - - protected void initialise() { - frame = new byte[8192]; - frame[0] = (byte) '*'; - frame[1] = 0; - frame[2] = 0; - frame[3] = 0; - frame[4] = 0; - frame[5] = 0; - fLen = 6; - - } - - 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 getLength() { - return ((frame[4] & 0xff) * 256 + (frame[5] & 0xff)); - } - - public void setLength(int length) { - frame[4] = (byte) (length / 256); - frame[5] = (byte) (length & 0xff); - fLen = length + FLAP_DATA_OFFSET; - } - - public byte[] getFrameData() { - byte[] b = new byte[fLen]; - System.arraycopy(frame, 0, b, 0, fLen); - return (b); - } - - protected void setFrameData(byte[] b) { - frame = new byte[b.length]; - fLen = b.length; - System.arraycopy(b, 0, frame, 0, b.length); - } - - 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(); - -} diff --git a/src/com/wilko/jaim/FLAPFrameException.java b/src/com/wilko/jaim/FLAPFrameException.java deleted file mode 100644 index c30281b..0000000 --- a/src/com/wilko/jaim/FLAPFrameException.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -/* - * FLAPFrameException.java - * - * Created on 3 May 2002, 15:05 - */ - -package com.wilko.jaim; - -/** - * @author paulw - * @version $Revision: 1.3 $ - */ -public class FLAPFrameException extends java.lang.Exception { - - /** - * Creates new FLAPFrameException without detail message. - */ - public FLAPFrameException() { - } - - - /** - * Constructs an FLAPFrameException with the specified detail message. - * - * @param msg the detail message. - */ - public FLAPFrameException(String msg) { - super(msg); - } -} - - diff --git a/src/com/wilko/jaim/FLAPFrameFactory.java b/src/com/wilko/jaim/FLAPFrameFactory.java deleted file mode 100644 index 4df9fac..0000000 --- a/src/com/wilko/jaim/FLAPFrameFactory.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -/* - * FLAPFrameFactory.java - * - * Created on 3 May 2002, 15:04 - */ - -package com.wilko.jaim; - -/** - * @author paulw - * @version $Revision: 1.3 $ - */ -public abstract class FLAPFrameFactory { - - /** - * Creates new FLAPFrameFactory - */ - public FLAPFrameFactory() { - } - - public static FLAPFrame createFLAPFrame(byte[] frameData) throws FLAPFrameException { - FLAPFrame f = null; - if (frameData[0] != '*') { - throw new FLAPFrameException("Frame does not start with '*'"); - } - - switch (frameData[1]) { - case FLAPFrame.FLAP_FRAME_SIGNON: - f = new FLAPSignonFrame(frameData); - break; - case FLAPFrame.FLAP_FRAME_DATA: - f = new FLAPDataFrame(frameData); - break; - case FLAPFrame.FLAP_FRAME_ERROR: - f = new FLAPErrorFrame(frameData); - break; - case FLAPFrame.FLAP_FRAME_SIGNOFF: - f = new FLAPSignoffFrame(frameData); - break; - case FLAPFrame.FLAP_FRAME_KEEP_ALIVE: - f = new FLAPKeepAliveFrame(frameData); - break; - default: - throw new FLAPFrameException("Illegal FLAP Frame type: " + Integer.toString(frameData[1])); - } - return (f); - } - -} diff --git a/src/com/wilko/jaim/FLAPInputFrame.java b/src/com/wilko/jaim/FLAPInputFrame.java deleted file mode 100644 index c432f03..0000000 --- a/src/com/wilko/jaim/FLAPInputFrame.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -/* - * FLAPInputFrame.java - * - * Created on 3 May 2002, 15:52 - */ - -package com.wilko.jaim; - -/** - * @author paulw - * @version $Revision: 1.3 $ - */ -public class FLAPInputFrame extends FLAPFrame { - - /** - * Creates new FLAPInputFrame - */ - private int frameLen; - - public FLAPInputFrame() { - frameLen = 0; - super.initialise(); - } - - public void addFrameData(byte b) { - frame[frameLen++] = b; - } - - public byte[] getFrameData() { - byte[] b = new byte[frameLen]; - System.arraycopy(frame, 0, b, 0, frameLen); - return (b); - } - - public void resetInputFrame() { - frameLen = 0; - } - - public boolean completeFrameRead() { - if (frameLen > 5) { - return frameLen - 6 == getLength(); - } - return (false); - } - - public int getFLAPFrameType() { - return (-1); - } - -} diff --git a/src/com/wilko/jaim/FLAPKeepAliveFrame.java b/src/com/wilko/jaim/FLAPKeepAliveFrame.java deleted file mode 100644 index b47e96f..0000000 --- a/src/com/wilko/jaim/FLAPKeepAliveFrame.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -/* - * FLAPKeepAliveFrame.java - * - * Created on 3 May 2002, 14:54 - */ - -package com.wilko.jaim; - -/** - * @author paulw - * @version $Revision: 1.4 $ - */ -public class FLAPKeepAliveFrame extends FLAPFrame { - - /** - * Creates new FLAPKeepAliveFrame - */ - public FLAPKeepAliveFrame() { - this.initialise(); - } - - public FLAPKeepAliveFrame(byte[] frameData) { - initialise(); - setFrameData(frameData); - } - - protected void initialise() { - super.initialise(); - frame[1] = FLAP_FRAME_KEEP_ALIVE; - } - - public int getFLAPFrameType() { - return (FLAPFrame.FLAP_FRAME_KEEP_ALIVE); - } - -} diff --git a/src/com/wilko/jaim/FLAPSignoffFrame.java b/src/com/wilko/jaim/FLAPSignoffFrame.java deleted file mode 100644 index 1d8653d..0000000 --- a/src/com/wilko/jaim/FLAPSignoffFrame.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -/* - * FLAPSignoffFrame.java - * - * Created on 3 May 2002, 14:54 - */ - -package com.wilko.jaim; - -/** - * @author paulw - * @version $Revision: 1.3 $ - */ -public class FLAPSignoffFrame extends FLAPFrame { - - /** - * Creates new FlapSignonFrame - */ - public FLAPSignoffFrame() { - - frame[1] = FLAP_FRAME_SIGNOFF; - } - - public FLAPSignoffFrame(byte[] frameData) { - frame[1] = FLAP_FRAME_SIGNOFF; - setFrameData(frameData); - } - - - public int getFLAPFrameType() { - return (FLAPFrame.FLAP_FRAME_SIGNOFF); - } - -} diff --git a/src/com/wilko/jaim/FLAPSignonFrame.java b/src/com/wilko/jaim/FLAPSignonFrame.java deleted file mode 100644 index 48aa4fe..0000000 --- a/src/com/wilko/jaim/FLAPSignonFrame.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -/* - * FlapSignonFrame.java - * - * Created on 3 May 2002, 14:54 - */ - -package com.wilko.jaim; - -/** - * @author paulw - * @version $Revision: 1.3 $ - */ -public class FLAPSignonFrame extends FLAPFrame { - - /** - * Creates new FlapSignonFrame - */ - public FLAPSignonFrame() { - frame[1] = FLAP_FRAME_SIGNON; - } - - public FLAPSignonFrame(byte[] frameData) { - frame[1] = FLAP_FRAME_SIGNON; - setFrameData(frameData); - } - - 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--) { - frame[6 + i] = (byte) (version & 0xff); - version = version >> 8; - } - } - - 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) { - - int len = 0; - for (int i = 0; i < name.length(); i++) { - char c = name.charAt(i); - if (c != ' ') { - frame[FLAP_DATA_OFFSET + 8 + len++] = (byte) c; - } - } - setLength(8 + len); - frame[FLAP_DATA_OFFSET + 6] = (byte) (len / 256); - frame[FLAP_DATA_OFFSET + 7] = (byte) (len & 0xff); - } - - public int getFLAPFrameType() { - return (FLAPFrame.FLAP_FRAME_SIGNON); - } - -} diff --git a/src/com/wilko/jaim/GenericTocResponse.java b/src/com/wilko/jaim/GenericTocResponse.java deleted file mode 100644 index 79e1389..0000000 --- a/src/com/wilko/jaim/GenericTocResponse.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -/* - * GenericTocCommand.java - * - * Created on 4 May 2002, 12:07 - */ - -package com.wilko.jaim; - -/** - * 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 - */ - public GenericTocResponse() { - this.cmd = ""; - } - - /** - * Parse an incoming string - * - * @param str The response string to be parsed - */ - public TocResponse parseString(String str) { - GenericTocResponse tr = new GenericTocResponse(); - tr.doParse(str); - return tr; - } - - private void doParse(String str) { - cmd = str; - } - - /** - * 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 - * - * @return The response as a string - */ - public String toString() { - return (cmd); - } - - /** - * Used in the response dispatching process - * - * @return The respnse type - */ - public String getResponseType() { - return ("UNKNOWN"); - } - - /** - * 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) { - return (true); - } - -} diff --git a/src/com/wilko/jaim/GotoTocResponse.java b/src/com/wilko/jaim/GotoTocResponse.java deleted file mode 100644 index caf9441..0000000 --- a/src/com/wilko/jaim/GotoTocResponse.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -/* - * TocIMResponse.java - * - * Created on 4 May 2002, 14:38 - */ - -package com.wilko.jaim; - -/** - * 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; - - /** - * Creates new GotoTocResponse - */ - public GotoTocResponse() { - windowName = ""; - URL = ""; - } - - /** - * Obtain the suggested window name for this URL - * - * @return The window name - */ - public String getWindowName() { - return (windowName); - } - - /** - * Obtain the URL - * - * @return The URL - */ - public String getURL() { - return (URL); - } - - - /** - * Parse an incoming response string - * - * @param str The string to be parsed - */ - public TocResponse parseString(java.lang.String str) { - GotoTocResponse tr = new GotoTocResponse(); - tr.doParse(str); - return (tr); - } - - private void doParse(String str) { - cmd = str; - int colonPos = str.indexOf(':'); - if (colonPos != -1) { - str = str.substring(colonPos + 1); - colonPos = str.indexOf(':'); - if (colonPos != -1) { - windowName = str.substring(0, colonPos); - URL = str.substring(colonPos + 1); - - } - } - - } - - /** - * 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. - * - * @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) { - return (Response.equalsIgnoreCase(RESPONSE_TYPE)); - } - -} diff --git a/src/com/wilko/jaim/IMTocResponse.java b/src/com/wilko/jaim/IMTocResponse.java deleted file mode 100644 index 70a616e..0000000 --- a/src/com/wilko/jaim/IMTocResponse.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -/* - * TocIMResponse.java - * - * Created on 4 May 2002, 14:38 - */ - -package com.wilko.jaim; - -/** - * 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; - - /** - * Creates new TocIMResponse - */ - public IMTocResponse() { - from = ""; - msg = ""; - autoResponse = false; - } - - /** - * Obtain the name of the buddy who sent this instant message - * - * @return The senders name - */ - public String getFrom() { - return (from); - } - - /** - * Obtain the message - * - * @return The message - * @see Utils#stripHTML - */ - public String getMsg() { - return (msg); - } - - /** - * Is this response an automatically generated response? - * - * @return true if this is an automatically generated response - */ - public boolean getAutoResponse() { - return (autoResponse); - } - - /** - * Parse an incoming IM response string - * - * @param str The string to be parsed - */ - public TocResponse parseString(java.lang.String str) { - IMTocResponse tr = new IMTocResponse(); - tr.doParse(str); - return (tr); - } - - private void doParse(String str) { - cmd = str; - int colonPos = str.indexOf(':'); - if (colonPos != -1) { - str = str.substring(colonPos + 1); - colonPos = str.indexOf(':'); - if (colonPos != -1) { - from = str.substring(0, colonPos); - str = str.substring(colonPos + 1); - colonPos = str.indexOf(':'); - if (str.charAt(0) == 'T') { - autoResponse = true; - } - if (colonPos != -1) { - msg = str.substring(colonPos + 1); - } - } - } - - } - - /** - * 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. - * - * @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) { - return (Response.equalsIgnoreCase(RESPONSE_TYPE)); - } - -} diff --git a/src/com/wilko/jaim/JaimConnection.java b/src/com/wilko/jaim/JaimConnection.java index 09a8627..783ec70 100644 --- a/src/com/wilko/jaim/JaimConnection.java +++ b/src/com/wilko/jaim/JaimConnection.java @@ -25,6 +25,10 @@ package com.wilko.jaim; +import com.wilko.jaim.commands.*; +import com.wilko.jaim.flap.*; +import com.wilko.jaim.responses.*; + import java.io.IOException; import java.io.InputStream; import java.io.InterruptedIOException; @@ -504,6 +508,100 @@ public class JaimConnection implements java.lang.Runnable { } + /** + * Sends a whisper to a user in a chat room + * @param roomID The ID of the room + * @param screenname The screenname to whisper to + * @param message The message + */ + public void sentChatWhisper(String roomID, String screenname, String message) { + try { + TocChatWhisperCommand whisperCommand = new TocChatWhisperCommand(roomID, screenname, message); + sendTocCommand(whisperCommand); + } catch (IOException ignore) { + } + } + + /** + * Accept a chat invite + * @param roomID The ID of the room + */ + + public void acceptChat(String roomID) { + try { + TocChatAcceptCommand acceptCommand = new TocChatAcceptCommand(roomID); + sendTocCommand(acceptCommand); + } catch (IOException ignore) { + } + } + + /** + * Evil/warn someone inside a chat room + * @param roomID The ID of the room + * @param screenname The screenname to evil/warn + * @param anonymous Stay anonymous? + */ + public void sendChatEvil(String roomID, String screenname, Boolean anonymous) { + try { + TocChatEvilCommand evilCommand = new TocChatEvilCommand(roomID, screenname, anonymous); + sendTocCommand(evilCommand); + } catch (IOException ignore) { + } + } + + /** + * Evil/warn someone inside a chat room + * @param roomID The ID of the room + * @param screenname The screenname to evil/warn + */ + public void sendChatEvil(String roomID, String screenname) { + sendChatEvil(roomID, screenname, false); + } + + /** + * Send an invitation to a chat room + * @param roomID The ID of the room + * @param message The message to be sent with the invite + * @param buddies An array of screennames to invite + */ + public void sendChatInvite(String roomID, String message, String[] buddies) { + try { + TocChatInviteCommand inviteCommand = new TocChatInviteCommand(roomID, message, buddies); + sendTocCommand(inviteCommand); + } catch (IOException ignore) { + } + } + + /** + * Send a message in a chat room + * @param roomID The ID of the room + * @param message The message to send + */ + public void sendChatMessage(String roomID, String message) { + try { + TocChatSendCommand sendCommand = new TocChatSendCommand(roomID, message); + sendTocCommand(sendCommand); + } catch (IOException ignore) { + } + } + + /** + * Leave a chat room + * @param roomID The ID of the room + */ + public void leaveChat(String roomID) { + try { + TocChatLeaveCommand leaveCommand = new TocChatLeaveCommand(roomID); + sendTocCommand(leaveCommand); + } catch (IOException ignore) { + } + } + + /** + * Join a chat room + * @param exchange The exchange to use + * @param roomName The name of the room + */ public void joinChat(int exchange, String roomName) { try { TocChatJoinCommand joinCommand = new TocChatJoinCommand(exchange, roomName); @@ -512,6 +610,10 @@ public class JaimConnection implements java.lang.Runnable { } } + /** + * Join a chat room + * @param roomName The name of the room + */ public void joinChat(String roomName) { joinChat(4, roomName); } diff --git a/src/com/wilko/jaim/JaimEvent.java b/src/com/wilko/jaim/JaimEvent.java index 739c4ec..4412f7c 100644 --- a/src/com/wilko/jaim/JaimEvent.java +++ b/src/com/wilko/jaim/JaimEvent.java @@ -19,6 +19,8 @@ package com.wilko.jaim; +import com.wilko.jaim.responses.TocResponse; + /** * The JaimEvent object is delivered to all registered {@link JaimEventListener} * diff --git a/src/com/wilko/jaim/JaimEventListener.java b/src/com/wilko/jaim/JaimEventListener.java index 54c01d2..79d1b48 100644 --- a/src/com/wilko/jaim/JaimEventListener.java +++ b/src/com/wilko/jaim/JaimEventListener.java @@ -25,6 +25,8 @@ package com.wilko.jaim; +import com.wilko.jaim.responses.TocResponse; + /** * A JaimEventListener receives JaimEvents from the JaimConnection class. * A {@link JaimEvent} contains a {@link TocResponse} object. diff --git a/src/com/wilko/jaim/LoginCompleteTocResponse.java b/src/com/wilko/jaim/LoginCompleteTocResponse.java deleted file mode 100644 index 23ca39b..0000000 --- a/src/com/wilko/jaim/LoginCompleteTocResponse.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -/* - * LoginCompleteTocResponse.java - * - * Created on November 2, 2002, 2:52 PM - */ - -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: $ - */ -public class LoginCompleteTocResponse extends TocResponse { - - public static final String RESPONSE_TYPE = "LOGINCOMPLETE"; - - /** - * Creates a new instance of LoginCompleteTocResponse - */ - public LoginCompleteTocResponse() { - } - - public String getResponseType() { - return (RESPONSE_TYPE); - } - - public String toString() { - return (RESPONSE_TYPE); - } - -} diff --git a/src/com/wilko/jaim/NickTocResponse.java b/src/com/wilko/jaim/NickTocResponse.java deleted file mode 100644 index acca3d7..0000000 --- a/src/com/wilko/jaim/NickTocResponse.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -/* - * NickTocResponse.java - * - * Created on 6 May 2002, 17:21 - */ - -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; - - - /** - * Creates new NickTocResponse - */ - public NickTocResponse() { - nickName = ""; - } - - - public TocResponse parseString(java.lang.String str) { - NickTocResponse tr = new NickTocResponse(); - tr.doParse(str); - return (tr); - } - - private void doParse(String str) { - int colonPos = str.indexOf(':'); - - if (colonPos != -1) { - nickName = str.substring(colonPos + 1); - } - - - } - - public String getNickName() { - return (nickName); - } - - - public String getResponseType() { - return RESPONSE_TYPE; - } - - /** - * 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) { - return (Response.equalsIgnoreCase(RESPONSE_TYPE)); - } - -} diff --git a/src/com/wilko/jaim/SignOnTocResponse.java b/src/com/wilko/jaim/SignOnTocResponse.java deleted file mode 100644 index adc9f04..0000000 --- a/src/com/wilko/jaim/SignOnTocResponse.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -/* - * SignOnTocResponse.java - * - * Created on 4 May 2002, 13:29 - */ - -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; - - - /** - * Creates new SignOnTocResponse - */ - public SignOnTocResponse() { - version = ""; - } - - public String getResponseType() { - return (RESPONSE_TYPE); - } - - protected String getVersion() { - return (version); - } - - - public TocResponse parseString(String str) { - SignOnTocResponse tr = new SignOnTocResponse(); - tr.doParse(str); - return (tr); - } - - private void doParse(String str) { - cmd = str; - int colonpos = str.indexOf(':'); - if (colonpos != -1) { - version = str.substring(colonpos + 1); - } - } - - /** - * 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) { - return (Response.equalsIgnoreCase(RESPONSE_TYPE)); - } - -} diff --git a/src/com/wilko/jaim/TocAddBuddyCommand.java b/src/com/wilko/jaim/TocAddBuddyCommand.java deleted file mode 100644 index fb1a3d5..0000000 --- a/src/com/wilko/jaim/TocAddBuddyCommand.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -/* - * TocAddBuddyCommand.java - * - * Created on 4 May 2002, 13:57 - */ - -package com.wilko.jaim; - -import java.util.Vector; - -/** - * @author paulw - * @version $Revision: 1.3 $ - */ -public class TocAddBuddyCommand extends TocCommand { - - private static final String CMD = "toc_add_buddy"; - - Vector buddyList; - - /** - * Creates new TocAddBuddyCommand - */ - public TocAddBuddyCommand() { - buddyList = new Vector(); - } - - public void addBuddy(String buddy) { - buddyList.add(Utils.normalise(buddy)); - } - - public String toString() { - StringBuffer output = new StringBuffer(CMD); - for (int i = 0; i < buddyList.size(); i++) { - output.append(' '); - output.append((String) buddyList.elementAt(i)); - } - return (output.toString()); - } - - - public byte[] getBytes() { - return (toString().getBytes()); - } - -} diff --git a/src/com/wilko/jaim/TocAddDenyCommand.java b/src/com/wilko/jaim/TocAddDenyCommand.java deleted file mode 100644 index 1bb4957..0000000 --- a/src/com/wilko/jaim/TocAddDenyCommand.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -/* - * TocAddDenyCommand.java - * - * Created on 4 May 2002, 13:57 - */ - -package com.wilko.jaim; - -import java.util.Vector; - -/** - * @author paulw - * @version $Revision: 1.3 $ - */ -public class TocAddDenyCommand extends TocCommand { - - private static final String CMD = "toc_add_deny"; - - Vector buddyList; - - /** - * Creates new TocAddBuddyCommand - */ - public TocAddDenyCommand() { - buddyList = new Vector(); - } - - public void addDeny(String buddy) { - buddyList.add(Utils.normalise(buddy)); - } - - public String toString() { - StringBuffer output = new StringBuffer(CMD); - for (int i = 0; i < buddyList.size(); i++) { - output.append(' '); - output.append((String) buddyList.elementAt(i)); - } - return (output.toString()); - } - - - public byte[] getBytes() { - return (toString().getBytes()); - } - -} diff --git a/src/com/wilko/jaim/TocAddPermitCommand.java b/src/com/wilko/jaim/TocAddPermitCommand.java deleted file mode 100644 index 05c1830..0000000 --- a/src/com/wilko/jaim/TocAddPermitCommand.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -/* - * TocAddPermitCommand.java - * - * Created on 11 Oct 2002, 15:20 - */ - -package com.wilko.jaim; - -import java.util.Vector; - -/** - * @author paulw - * @version $Revision: 1.1 $ - */ -public class TocAddPermitCommand extends TocCommand { - - private static final String CMD = "toc_add_permit"; - - Vector buddyList; - - /** - * Creates new TocAddBuddyCommand - */ - public TocAddPermitCommand() { - buddyList = new Vector(); - } - - public void addPermit(String buddy) { - buddyList.add(Utils.normalise(buddy)); - } - - public String toString() { - StringBuffer output = new StringBuffer(CMD); - for (int i = 0; i < buddyList.size(); i++) { - output.append(' '); - output.append((String) buddyList.elementAt(i)); - } - return (output.toString()); - } - - - public byte[] getBytes() { - return (toString().getBytes()); - } - -} diff --git a/src/com/wilko/jaim/TocChatJoinCommand.java b/src/com/wilko/jaim/TocChatJoinCommand.java deleted file mode 100644 index d0fb1dc..0000000 --- a/src/com/wilko/jaim/TocChatJoinCommand.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -/* - * TocIMCommand.java - * - * Created on 4 May 2002, 15:18 - */ - -package com.wilko.jaim; - -/** - * @author paulw - * @version $Revision: 1.4 $ - */ -public class TocChatJoinCommand extends TocCommand { - - private final int exchange; - private final String roomName; - - /** - * Creates new TocIMCommand - */ - public TocChatJoinCommand(int exchange, String roomName) { - this.exchange = exchange; - this.roomName = roomName; - } - - public String toString() { - return ("toc_chat_join " + exchange + " " + roomName); - } - - public byte[] getBytes() { - return (this.toString().getBytes()); - } - -} diff --git a/src/com/wilko/jaim/TocCommand.java b/src/com/wilko/jaim/TocCommand.java deleted file mode 100644 index 7de992c..0000000 --- a/src/com/wilko/jaim/TocCommand.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -/* - * TocCommand.java - * - * Created on 4 May 2002, 11:19 - */ - -package com.wilko.jaim; - -/** - * @author paulw - * @version $Revision: 1.3 $ - */ -public abstract class TocCommand { - - /** - * Creates new TocCommand - */ - public TocCommand() { - } - - abstract public byte[] getBytes(); - - abstract public String toString(); - -} diff --git a/src/com/wilko/jaim/TocEvilCommand.java b/src/com/wilko/jaim/TocEvilCommand.java deleted file mode 100644 index 7ef1caa..0000000 --- a/src/com/wilko/jaim/TocEvilCommand.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -/* - * TocEvilCommand.java - * - * Created on 6 May 2002, 09:05 - */ - -package com.wilko.jaim; - -/** - * @author paulw - * @version $Revision: 1.3 $ - */ -public class TocEvilCommand extends TocCommand { - - private final String buddy; - private final boolean anonymous; - - /** - * Creates new TocEvilCommand - */ - public TocEvilCommand(String buddy, boolean anonymous) { - this.buddy = Utils.normalise(buddy); - this.anonymous = anonymous; - } - - public String toString() { - String ret = "toc_evil " + buddy; - if (anonymous) { - ret = ret + " anon"; - } else - ret = ret + " norm"; - - return (ret); - } - - public byte[] getBytes() { - return toString().getBytes(); - } - -} diff --git a/src/com/wilko/jaim/TocGetInfoCommand.java b/src/com/wilko/jaim/TocGetInfoCommand.java deleted file mode 100644 index 0ed49ce..0000000 --- a/src/com/wilko/jaim/TocGetInfoCommand.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -/* - * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -package com.wilko.jaim; - -/** - * @author paulw - * @version $version: $ - */ -public class TocGetInfoCommand extends TocCommand { - - private static final String CMD = "toc_get_info "; - private final String username; - - /** - * Creates new TocGetInfoCommand - * - * @param username The screen name for whom information is requested - */ - - public TocGetInfoCommand(String username) { - this.username = Utils.normalise(username); - } - - - public String toString() { - return (CMD + username); - } - - public byte[] getBytes() { - return (toString().getBytes()); - } - -} diff --git a/src/com/wilko/jaim/TocIMCommand.java b/src/com/wilko/jaim/TocIMCommand.java deleted file mode 100644 index 7a43319..0000000 --- a/src/com/wilko/jaim/TocIMCommand.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -/* - * TocIMCommand.java - * - * Created on 4 May 2002, 15:18 - */ - -package com.wilko.jaim; - -/** - * @author paulw - * @version $Revision: 1.4 $ - */ -public class TocIMCommand extends TocCommand { - - private final String recipient; - private final String msg; - private final String auto; - - /** - * Creates new TocIMCommand - */ - public TocIMCommand(String recipient, String msg, boolean autoMessage) { - this.recipient = Utils.normalise(recipient); - this.msg = Utils.encodeText(msg); - if (autoMessage) - auto = " auto"; - else - auto = ""; - } - - public String toString() { - return ("toc_send_im " + recipient + " " + msg + auto); - } - - public byte[] getBytes() { - return (this.toString().getBytes()); - } - -} diff --git a/src/com/wilko/jaim/TocInitDoneCommand.java b/src/com/wilko/jaim/TocInitDoneCommand.java deleted file mode 100644 index 5cb8c55..0000000 --- a/src/com/wilko/jaim/TocInitDoneCommand.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -/* - * TocInitDoneCommand.java - * - * Created on 4 May 2002, 13:35 - */ - -package com.wilko.jaim; - -/** - * @author paulw - * @version $Revision: 1.4 $ - */ -public class TocInitDoneCommand extends TocCommand { - - private static final String CMD = "toc_init_done"; - - /** - * Creates new TocInitDoneCommand - */ - public TocInitDoneCommand() { - } - - public byte[] getBytes() { - return (CMD.getBytes()); - } - - public String toString() { - return (CMD); - } - -} diff --git a/src/com/wilko/jaim/TocResponse.java b/src/com/wilko/jaim/TocResponse.java deleted file mode 100644 index 0635a6a..0000000 --- a/src/com/wilko/jaim/TocResponse.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -/* - * TocCommand.java - * - * Created on 4 May 2002, 11:19 - */ - -package com.wilko.jaim; - -/** - * @author paulw - * @version $Revision: 1.5 $ - */ -public abstract class TocResponse { - - protected String cmd; - - public TocResponse() { - cmd = ""; - } - - public String toString() { - return (cmd); - } - - public abstract String getResponseType(); - -} diff --git a/src/com/wilko/jaim/TocResponseFactory.java b/src/com/wilko/jaim/TocResponseFactory.java deleted file mode 100644 index 45b9444..0000000 --- a/src/com/wilko/jaim/TocResponseFactory.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -/* - * TocResponseFactory.java - * - * Created on 4 May 2002, 12:05 - */ - -package com.wilko.jaim; - -/** - * @author paulw - * @version $Revision: 1.5 $ - */ - -import java.util.Vector; - -public abstract class TocResponseFactory { - - static Vector responseHandlers = new Vector(); - - /** - * Creates new TocResponseFactory - */ - public TocResponseFactory() { - } - - public static void addResponseHandler(TocResponseHandler h) { - synchronized (responseHandlers) { - responseHandlers.add(h); - } - } - - static TocResponse createResponse(byte[] b) { - TocResponse tr = null; - String strversion = new String(b); - int colonpos = strversion.indexOf(':'); - if (colonpos != -1) { - String firstWord = strversion.substring(0, colonpos); - int i = 0; - synchronized (responseHandlers) { - while ((i < responseHandlers.size()) && (tr == null)) { - TocResponseHandler h = (TocResponseHandler) responseHandlers.elementAt(i); - if (h.canHandle(firstWord)) { - tr = h.parseString(strversion); - } - i++; - } - } - } - if (tr == null) { - GenericTocResponse gtr = new GenericTocResponse(); - tr = gtr.parseString(strversion); - } - return (tr); - } - -} diff --git a/src/com/wilko/jaim/TocResponseHandler.java b/src/com/wilko/jaim/TocResponseHandler.java deleted file mode 100644 index aa7be37..0000000 --- a/src/com/wilko/jaim/TocResponseHandler.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -package com.wilko.jaim; - -/** - * @author paulw - * @version $revision: $ - */ -public interface TocResponseHandler { - - /** - * 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 - */ - - boolean canHandle(String 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 - */ - - TocResponse parseString(String Response); - -} - diff --git a/src/com/wilko/jaim/TocSetAwayCommand.java b/src/com/wilko/jaim/TocSetAwayCommand.java deleted file mode 100644 index 382310f..0000000 --- a/src/com/wilko/jaim/TocSetAwayCommand.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -/* - * TocSetAwayCommand.java - * - * Created on July 17, 2002, 9:02 PM - */ - -package com.wilko.jaim; - -/** - * @author paulw - * @version $version: $ - */ -public class TocSetAwayCommand extends TocCommand { - - private static final String CMD = "toc_set_away "; - private final String awayMsg; - - /** - * Creates new TocSetInfoCommand - * - * @param awayMsg The away message for this user. May contain HTML. To cancel "away" status set the awayMsg to "" - */ - - public TocSetAwayCommand(String awayMsg) { - this.awayMsg = Utils.encodeText(awayMsg); - } - - - public String toString() { - return (CMD + awayMsg); - } - - public byte[] getBytes() { - return (toString().getBytes()); - } - -} diff --git a/src/com/wilko/jaim/TocSetConfigCommand.java b/src/com/wilko/jaim/TocSetConfigCommand.java deleted file mode 100644 index aea6d91..0000000 --- a/src/com/wilko/jaim/TocSetConfigCommand.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -/* - * TocSetConfigCommand.java - * - * Created on October 11, 2002, 9:08 AM - */ - -package com.wilko.jaim; - -import java.util.Enumeration; - -/** - * @author paulw - */ -public class TocSetConfigCommand extends TocCommand { - - private static final String CMD = "toc_set_config "; - private final StringBuffer config; - - /** - * Creates a new instance of TocSetConfigCommand - */ - public TocSetConfigCommand() { - config = new StringBuffer(); - } - - public void addGroup(Group g) { - config.append("g " + g.getName() + "\n"); - Enumeration buddies = g.enumerateBuddies(); - while (buddies.hasMoreElements()) { - Buddy b = (Buddy) buddies.nextElement(); - config.append("b " + b.getName() + "\n"); - if (b.getPermit()) { - config.append("p " + b.getName() + "\n"); - } - if (b.getDeny()) { - config.append("d " + b.getName() + "\n"); - } - } - } - - - public String toString() { - return (CMD + '"' + config.toString() + '"'); - } - - public byte[] getBytes() { - return (toString().getBytes()); - } - -} diff --git a/src/com/wilko/jaim/TocSetIdleCommand.java b/src/com/wilko/jaim/TocSetIdleCommand.java deleted file mode 100644 index 95e93c9..0000000 --- a/src/com/wilko/jaim/TocSetIdleCommand.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ -/* - * TocSetIdleCommand.java - * - * Created on July 17, 2002, 9:21 PM - */ - -package com.wilko.jaim; - -/** - * @author paulw - * @version $version: $ - */ -public class TocSetIdleCommand extends TocCommand { - - private static final String CMD = "toc_set_idle "; - private final int idle; - - /** - * Creates new TocSetIdleCommand - * - * @param idleSecs - the period for which the user has been idle - */ - public TocSetIdleCommand(int idleSecs) { - idle = idleSecs; - } - - public String toString() { - return (CMD + idle); - } - - public byte[] getBytes() { - return (toString().getBytes()); - } - -} diff --git a/src/com/wilko/jaim/TocSetInfoCommand.java b/src/com/wilko/jaim/TocSetInfoCommand.java deleted file mode 100644 index 24d4183..0000000 --- a/src/com/wilko/jaim/TocSetInfoCommand.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -/* - * TocSetInfoCommand.java - * - * Created on July 17, 2002, 9:02 PM - */ - -package com.wilko.jaim; - -/** - * @author paulw - * @version $version: $ - */ -public class TocSetInfoCommand extends TocCommand { - - private static final String CMD = "toc_set_info "; - private final String information; - - /** - * Creates new TocSetInfoCommand - * - * @param information The information about this user can be located. May contain HTML - */ - - public TocSetInfoCommand(String information) { - this.information = Utils.encodeText(information); - } - - - public String toString() { - return (CMD + information); - } - - public byte[] getBytes() { - return (toString().getBytes()); - } - -} diff --git a/src/com/wilko/jaim/TocSignonCommand.java b/src/com/wilko/jaim/TocSignonCommand.java deleted file mode 100644 index 0f73475..0000000 --- a/src/com/wilko/jaim/TocSignonCommand.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -/* - * TocSignonCommand.java - * - * Created on 4 May 2002, 11:20 - */ - -package com.wilko.jaim; - -/** - * @author paulw - * @version $Revision: 1.3 $ - */ -public class TocSignonCommand extends TocCommand { - - 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 - */ - public TocSignonCommand(String server, int port, String username, String password) { - this.server = server; - this.port = port; - this.username = Utils.normalise(username); - this.password = Utils.roast(password); - } - - public byte[] getBytes() { - return toString().getBytes(); - } - - public String toString() { - String temp = "toc_signon login.oscar.aol.com 5159 " + username + " " + password + " english " + AGENTNAME; - return (temp); - } - - public void parseString(java.lang.String str) { - } - -} diff --git a/src/com/wilko/jaim/commands/TocAddBuddyCommand.java b/src/com/wilko/jaim/commands/TocAddBuddyCommand.java new file mode 100644 index 0000000..30b1370 --- /dev/null +++ b/src/com/wilko/jaim/commands/TocAddBuddyCommand.java @@ -0,0 +1,67 @@ +/* + * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +/* + * TocAddBuddyCommand.java + * + * Created on 4 May 2002, 13:57 + */ + +package com.wilko.jaim.commands; + +import com.wilko.jaim.Utils; + +import java.util.Vector; + +/** + * @author paulw + * @version $Revision: 1.3 $ + */ +public class TocAddBuddyCommand extends TocCommand { + + private static final String CMD = "toc_add_buddy"; + + Vector buddyList; + + /** + * Creates new TocAddBuddyCommand + */ + public TocAddBuddyCommand() { + buddyList = new Vector(); + } + + public void addBuddy(String buddy) { + buddyList.add(Utils.normalise(buddy)); + } + + public String toString() { + StringBuffer output = new StringBuffer(CMD); + for (int i = 0; i < buddyList.size(); i++) { + output.append(' '); + output.append((String) buddyList.elementAt(i)); + } + return (output.toString()); + } + + + public byte[] getBytes() { + return (toString().getBytes()); + } + +} diff --git a/src/com/wilko/jaim/commands/TocAddDenyCommand.java b/src/com/wilko/jaim/commands/TocAddDenyCommand.java new file mode 100644 index 0000000..ec3b493 --- /dev/null +++ b/src/com/wilko/jaim/commands/TocAddDenyCommand.java @@ -0,0 +1,67 @@ +/* + * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +/* + * TocAddDenyCommand.java + * + * Created on 4 May 2002, 13:57 + */ + +package com.wilko.jaim.commands; + +import com.wilko.jaim.Utils; + +import java.util.Vector; + +/** + * @author paulw + * @version $Revision: 1.3 $ + */ +public class TocAddDenyCommand extends TocCommand { + + private static final String CMD = "toc_add_deny"; + + Vector buddyList; + + /** + * Creates new TocAddBuddyCommand + */ + public TocAddDenyCommand() { + buddyList = new Vector(); + } + + public void addDeny(String buddy) { + buddyList.add(Utils.normalise(buddy)); + } + + public String toString() { + StringBuffer output = new StringBuffer(CMD); + for (int i = 0; i < buddyList.size(); i++) { + output.append(' '); + output.append((String) buddyList.elementAt(i)); + } + return (output.toString()); + } + + + public byte[] getBytes() { + return (toString().getBytes()); + } + +} diff --git a/src/com/wilko/jaim/commands/TocAddPermitCommand.java b/src/com/wilko/jaim/commands/TocAddPermitCommand.java new file mode 100644 index 0000000..09d76d0 --- /dev/null +++ b/src/com/wilko/jaim/commands/TocAddPermitCommand.java @@ -0,0 +1,67 @@ +/* + * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +/* + * TocAddPermitCommand.java + * + * Created on 11 Oct 2002, 15:20 + */ + +package com.wilko.jaim.commands; + +import com.wilko.jaim.Utils; + +import java.util.Vector; + +/** + * @author paulw + * @version $Revision: 1.1 $ + */ +public class TocAddPermitCommand extends TocCommand { + + private static final String CMD = "toc_add_permit"; + + Vector buddyList; + + /** + * Creates new TocAddBuddyCommand + */ + public TocAddPermitCommand() { + buddyList = new Vector(); + } + + public void addPermit(String buddy) { + buddyList.add(Utils.normalise(buddy)); + } + + public String toString() { + StringBuffer output = new StringBuffer(CMD); + for (int i = 0; i < buddyList.size(); i++) { + output.append(' '); + output.append((String) buddyList.elementAt(i)); + } + return (output.toString()); + } + + + public byte[] getBytes() { + return (toString().getBytes()); + } + +} diff --git a/src/com/wilko/jaim/commands/TocChatAcceptCommand.java b/src/com/wilko/jaim/commands/TocChatAcceptCommand.java new file mode 100644 index 0000000..8f2e032 --- /dev/null +++ b/src/com/wilko/jaim/commands/TocChatAcceptCommand.java @@ -0,0 +1,51 @@ +/* + * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +/* + * TocIMCommand.java + * + * Created on 4 May 2002, 15:18 + */ + +package com.wilko.jaim.commands; + +/** + * @author paulw + * @version $Revision: 1.4 $ + */ +public class TocChatAcceptCommand extends TocCommand { + + private final String roomID; + + /** + * Creates new TocIMCommand + */ + public TocChatAcceptCommand(String roomID) { + this.roomID = roomID; + } + + public String toString() { + return ("toc_chat_accept " + roomID); + } + + public byte[] getBytes() { + return (this.toString().getBytes()); + } + +} diff --git a/src/com/wilko/jaim/commands/TocChatEvilCommand.java b/src/com/wilko/jaim/commands/TocChatEvilCommand.java new file mode 100644 index 0000000..5101eae --- /dev/null +++ b/src/com/wilko/jaim/commands/TocChatEvilCommand.java @@ -0,0 +1,55 @@ +/* + * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +/* + * TocIMCommand.java + * + * Created on 4 May 2002, 15:18 + */ + +package com.wilko.jaim.commands; + +/** + * @author paulw + * @version $Revision: 1.4 $ + */ +public class TocChatEvilCommand extends TocCommand { + + private final String roomID; + private final String screenname; + private final Boolean anonymous; + + /** + * Creates new TocIMCommand + */ + public TocChatEvilCommand(String roomID, String screenname, Boolean anonymous) { + this.roomID = roomID; + this.screenname = screenname; + this.anonymous = anonymous; + } + + public String toString() { + return ("toc_chat_evil " + roomID + " " + screenname + " " + (anonymous ? "anon" : "norm")); + } + + public byte[] getBytes() { + return (this.toString().getBytes()); + } + +} diff --git a/src/com/wilko/jaim/commands/TocChatInviteCommand.java b/src/com/wilko/jaim/commands/TocChatInviteCommand.java new file mode 100644 index 0000000..6970987 --- /dev/null +++ b/src/com/wilko/jaim/commands/TocChatInviteCommand.java @@ -0,0 +1,55 @@ +/* + * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +/* + * TocIMCommand.java + * + * Created on 4 May 2002, 15:18 + */ + +package com.wilko.jaim.commands; + +/** + * @author paulw + * @version $Revision: 1.4 $ + */ +public class TocChatInviteCommand extends TocCommand { + + private final String roomID; + private final String message; + private final String[] buddies; + + /** + * Creates new TocIMCommand + */ + public TocChatInviteCommand(String roomID, String message, String[] buddies) { + this.roomID = roomID; + this.message = message; + this.buddies = buddies; + } + + public String toString() { + return ("toc_chat_invite " + roomID + " \"" + message + "\" " + String.join(" ", buddies)); + } + + public byte[] getBytes() { + return (this.toString().getBytes()); + } + +} diff --git a/src/com/wilko/jaim/commands/TocChatJoinCommand.java b/src/com/wilko/jaim/commands/TocChatJoinCommand.java new file mode 100644 index 0000000..7f01378 --- /dev/null +++ b/src/com/wilko/jaim/commands/TocChatJoinCommand.java @@ -0,0 +1,53 @@ +/* + * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +/* + * TocIMCommand.java + * + * Created on 4 May 2002, 15:18 + */ + +package com.wilko.jaim.commands; + +/** + * @author paulw + * @version $Revision: 1.4 $ + */ +public class TocChatJoinCommand extends TocCommand { + + private final int exchange; + private final String roomName; + + /** + * Creates new TocIMCommand + */ + public TocChatJoinCommand(int exchange, String roomName) { + this.exchange = exchange; + this.roomName = roomName; + } + + public String toString() { + return ("toc_chat_join " + exchange + " " + roomName); + } + + public byte[] getBytes() { + return (this.toString().getBytes()); + } + +} diff --git a/src/com/wilko/jaim/commands/TocChatLeaveCommand.java b/src/com/wilko/jaim/commands/TocChatLeaveCommand.java new file mode 100644 index 0000000..8f05de1 --- /dev/null +++ b/src/com/wilko/jaim/commands/TocChatLeaveCommand.java @@ -0,0 +1,51 @@ +/* + * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +/* + * TocIMCommand.java + * + * Created on 4 May 2002, 15:18 + */ + +package com.wilko.jaim.commands; + +/** + * @author paulw + * @version $Revision: 1.4 $ + */ +public class TocChatLeaveCommand extends TocCommand { + + private final String roomID; + + /** + * Creates new TocIMCommand + */ + public TocChatLeaveCommand(String roomID) { + this.roomID = roomID; + } + + public String toString() { + return ("toc_chat_leave " + roomID); + } + + public byte[] getBytes() { + return (this.toString().getBytes()); + } + +} diff --git a/src/com/wilko/jaim/commands/TocChatSendCommand.java b/src/com/wilko/jaim/commands/TocChatSendCommand.java new file mode 100644 index 0000000..42b7764 --- /dev/null +++ b/src/com/wilko/jaim/commands/TocChatSendCommand.java @@ -0,0 +1,53 @@ +/* + * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +/* + * TocIMCommand.java + * + * Created on 4 May 2002, 15:18 + */ + +package com.wilko.jaim.commands; + +/** + * @author paulw + * @version $Revision: 1.4 $ + */ +public class TocChatSendCommand extends TocCommand { + + private final String roomID; + private final String message; + + /** + * Creates new TocIMCommand + */ + public TocChatSendCommand(String roomID, String message) { + this.roomID = roomID; + this.message = message; + } + + public String toString() { + return ("toc_chat_send " + roomID + " \"" + message + "\""); + } + + public byte[] getBytes() { + return (this.toString().getBytes()); + } + +} diff --git a/src/com/wilko/jaim/commands/TocChatWhisperCommand.java b/src/com/wilko/jaim/commands/TocChatWhisperCommand.java new file mode 100644 index 0000000..edf4ff7 --- /dev/null +++ b/src/com/wilko/jaim/commands/TocChatWhisperCommand.java @@ -0,0 +1,55 @@ +/* + * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +/* + * TocIMCommand.java + * + * Created on 4 May 2002, 15:18 + */ + +package com.wilko.jaim.commands; + +/** + * @author paulw + * @version $Revision: 1.4 $ + */ +public class TocChatWhisperCommand extends TocCommand { + + private final String roomID; + private final String screenname; + private final String message; + + /** + * Creates new TocIMCommand + */ + public TocChatWhisperCommand(String roomID, String screenname, String message) { + this.roomID = roomID; + this.screenname = screenname; + this.message = message; + } + + public String toString() { + return ("toc_chat_whisper " + roomID + " " + screenname + " \"" + message + "\""); + } + + public byte[] getBytes() { + return (this.toString().getBytes()); + } + +} diff --git a/src/com/wilko/jaim/commands/TocCommand.java b/src/com/wilko/jaim/commands/TocCommand.java new file mode 100644 index 0000000..ec7e77f --- /dev/null +++ b/src/com/wilko/jaim/commands/TocCommand.java @@ -0,0 +1,44 @@ +/* + * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +/* + * TocCommand.java + * + * Created on 4 May 2002, 11:19 + */ + +package com.wilko.jaim.commands; + +/** + * @author paulw + * @version $Revision: 1.3 $ + */ +public abstract class TocCommand { + + /** + * Creates new TocCommand + */ + public TocCommand() { + } + + abstract public byte[] getBytes(); + + abstract public String toString(); + +} diff --git a/src/com/wilko/jaim/commands/TocEvilCommand.java b/src/com/wilko/jaim/commands/TocEvilCommand.java new file mode 100644 index 0000000..15758e1 --- /dev/null +++ b/src/com/wilko/jaim/commands/TocEvilCommand.java @@ -0,0 +1,61 @@ +/* + * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +/* + * TocEvilCommand.java + * + * Created on 6 May 2002, 09:05 + */ + +package com.wilko.jaim.commands; + +import com.wilko.jaim.Utils; + +/** + * @author paulw + * @version $Revision: 1.3 $ + */ +public class TocEvilCommand extends TocCommand { + + private final String buddy; + private final boolean anonymous; + + /** + * Creates new TocEvilCommand + */ + public TocEvilCommand(String buddy, boolean anonymous) { + this.buddy = Utils.normalise(buddy); + this.anonymous = anonymous; + } + + public String toString() { + String ret = "toc_evil " + buddy; + if (anonymous) { + ret = ret + " anon"; + } else + ret = ret + " norm"; + + return (ret); + } + + public byte[] getBytes() { + return toString().getBytes(); + } + +} diff --git a/src/com/wilko/jaim/commands/TocGetInfoCommand.java b/src/com/wilko/jaim/commands/TocGetInfoCommand.java new file mode 100644 index 0000000..47927dd --- /dev/null +++ b/src/com/wilko/jaim/commands/TocGetInfoCommand.java @@ -0,0 +1,71 @@ +/* + * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +/* + * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +package com.wilko.jaim.commands; + +import com.wilko.jaim.Utils; + +/** + * @author paulw + * @version $version: $ + */ +public class TocGetInfoCommand extends TocCommand { + + private static final String CMD = "toc_get_info "; + private final String username; + + /** + * Creates new TocGetInfoCommand + * + * @param username The screen name for whom information is requested + */ + + public TocGetInfoCommand(String username) { + this.username = Utils.normalise(username); + } + + + public String toString() { + return (CMD + username); + } + + public byte[] getBytes() { + return (toString().getBytes()); + } + +} diff --git a/src/com/wilko/jaim/commands/TocIMCommand.java b/src/com/wilko/jaim/commands/TocIMCommand.java new file mode 100644 index 0000000..76630da --- /dev/null +++ b/src/com/wilko/jaim/commands/TocIMCommand.java @@ -0,0 +1,60 @@ +/* + * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +/* + * TocIMCommand.java + * + * Created on 4 May 2002, 15:18 + */ + +package com.wilko.jaim.commands; + +import com.wilko.jaim.Utils; + +/** + * @author paulw + * @version $Revision: 1.4 $ + */ +public class TocIMCommand extends TocCommand { + + private final String recipient; + private final String msg; + private final String auto; + + /** + * Creates new TocIMCommand + */ + public TocIMCommand(String recipient, String msg, boolean autoMessage) { + this.recipient = Utils.normalise(recipient); + this.msg = Utils.encodeText(msg); + if (autoMessage) + auto = " auto"; + else + auto = ""; + } + + public String toString() { + return ("toc_send_im " + recipient + " " + msg + auto); + } + + public byte[] getBytes() { + return (this.toString().getBytes()); + } + +} diff --git a/src/com/wilko/jaim/commands/TocInitDoneCommand.java b/src/com/wilko/jaim/commands/TocInitDoneCommand.java new file mode 100644 index 0000000..c97a324 --- /dev/null +++ b/src/com/wilko/jaim/commands/TocInitDoneCommand.java @@ -0,0 +1,50 @@ +/* + * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +/* + * TocInitDoneCommand.java + * + * Created on 4 May 2002, 13:35 + */ + +package com.wilko.jaim.commands; + +/** + * @author paulw + * @version $Revision: 1.4 $ + */ +public class TocInitDoneCommand extends TocCommand { + + private static final String CMD = "toc_init_done"; + + /** + * Creates new TocInitDoneCommand + */ + public TocInitDoneCommand() { + } + + public byte[] getBytes() { + return (CMD.getBytes()); + } + + public String toString() { + return (CMD); + } + +} diff --git a/src/com/wilko/jaim/commands/TocSetAwayCommand.java b/src/com/wilko/jaim/commands/TocSetAwayCommand.java new file mode 100644 index 0000000..0333cc4 --- /dev/null +++ b/src/com/wilko/jaim/commands/TocSetAwayCommand.java @@ -0,0 +1,58 @@ +/* + * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +/* + * TocSetAwayCommand.java + * + * Created on July 17, 2002, 9:02 PM + */ + +package com.wilko.jaim.commands; + +import com.wilko.jaim.Utils; + +/** + * @author paulw + * @version $version: $ + */ +public class TocSetAwayCommand extends TocCommand { + + private static final String CMD = "toc_set_away "; + private final String awayMsg; + + /** + * Creates new TocSetInfoCommand + * + * @param awayMsg The away message for this user. May contain HTML. To cancel "away" status set the awayMsg to "" + */ + + public TocSetAwayCommand(String awayMsg) { + this.awayMsg = Utils.encodeText(awayMsg); + } + + + public String toString() { + return (CMD + awayMsg); + } + + public byte[] getBytes() { + return (toString().getBytes()); + } + +} diff --git a/src/com/wilko/jaim/commands/TocSetConfigCommand.java b/src/com/wilko/jaim/commands/TocSetConfigCommand.java new file mode 100644 index 0000000..c690185 --- /dev/null +++ b/src/com/wilko/jaim/commands/TocSetConfigCommand.java @@ -0,0 +1,72 @@ +/* + * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +/* + * TocSetConfigCommand.java + * + * Created on October 11, 2002, 9:08 AM + */ + +package com.wilko.jaim.commands; + +import com.wilko.jaim.Buddy; +import com.wilko.jaim.Group; + +import java.util.Enumeration; + +/** + * @author paulw + */ +public class TocSetConfigCommand extends TocCommand { + + private static final String CMD = "toc_set_config "; + private final StringBuffer config; + + /** + * Creates a new instance of TocSetConfigCommand + */ + public TocSetConfigCommand() { + config = new StringBuffer(); + } + + public void addGroup(Group g) { + config.append("g " + g.getName() + "\n"); + Enumeration buddies = g.enumerateBuddies(); + while (buddies.hasMoreElements()) { + Buddy b = (Buddy) buddies.nextElement(); + config.append("b " + b.getName() + "\n"); + if (b.getPermit()) { + config.append("p " + b.getName() + "\n"); + } + if (b.getDeny()) { + config.append("d " + b.getName() + "\n"); + } + } + } + + + public String toString() { + return (CMD + '"' + config.toString() + '"'); + } + + public byte[] getBytes() { + return (toString().getBytes()); + } + +} diff --git a/src/com/wilko/jaim/commands/TocSetIdleCommand.java b/src/com/wilko/jaim/commands/TocSetIdleCommand.java new file mode 100644 index 0000000..ed1bf74 --- /dev/null +++ b/src/com/wilko/jaim/commands/TocSetIdleCommand.java @@ -0,0 +1,53 @@ +/* + * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +/* + * TocSetIdleCommand.java + * + * Created on July 17, 2002, 9:21 PM + */ + +package com.wilko.jaim.commands; + +/** + * @author paulw + * @version $version: $ + */ +public class TocSetIdleCommand extends TocCommand { + + private static final String CMD = "toc_set_idle "; + private final int idle; + + /** + * Creates new TocSetIdleCommand + * + * @param idleSecs - the period for which the user has been idle + */ + public TocSetIdleCommand(int idleSecs) { + idle = idleSecs; + } + + public String toString() { + return (CMD + idle); + } + + public byte[] getBytes() { + return (toString().getBytes()); + } + +} diff --git a/src/com/wilko/jaim/commands/TocSetInfoCommand.java b/src/com/wilko/jaim/commands/TocSetInfoCommand.java new file mode 100644 index 0000000..d5a3f5b --- /dev/null +++ b/src/com/wilko/jaim/commands/TocSetInfoCommand.java @@ -0,0 +1,58 @@ +/* + * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +/* + * TocSetInfoCommand.java + * + * Created on July 17, 2002, 9:02 PM + */ + +package com.wilko.jaim.commands; + +import com.wilko.jaim.Utils; + +/** + * @author paulw + * @version $version: $ + */ +public class TocSetInfoCommand extends TocCommand { + + private static final String CMD = "toc_set_info "; + private final String information; + + /** + * Creates new TocSetInfoCommand + * + * @param information The information about this user can be located. May contain HTML + */ + + public TocSetInfoCommand(String information) { + this.information = Utils.encodeText(information); + } + + + public String toString() { + return (CMD + information); + } + + public byte[] getBytes() { + return (toString().getBytes()); + } + +} diff --git a/src/com/wilko/jaim/commands/TocSignonCommand.java b/src/com/wilko/jaim/commands/TocSignonCommand.java new file mode 100644 index 0000000..8721ef0 --- /dev/null +++ b/src/com/wilko/jaim/commands/TocSignonCommand.java @@ -0,0 +1,64 @@ +/* + * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +/* + * TocSignonCommand.java + * + * Created on 4 May 2002, 11:20 + */ + +package com.wilko.jaim.commands; + +import com.wilko.jaim.Utils; + +/** + * @author paulw + * @version $Revision: 1.3 $ + */ +public class TocSignonCommand extends TocCommand { + + 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 + */ + public TocSignonCommand(String server, int port, String username, String password) { + this.server = server; + this.port = port; + this.username = Utils.normalise(username); + this.password = Utils.roast(password); + } + + public byte[] getBytes() { + return toString().getBytes(); + } + + public String toString() { + String temp = "toc_signon login.oscar.aol.com 5159 " + username + " " + password + " english " + AGENTNAME; + return (temp); + } + + public void parseString(java.lang.String str) { + } + +} diff --git a/src/com/wilko/jaim/flap/FLAPDataFrame.java b/src/com/wilko/jaim/flap/FLAPDataFrame.java new file mode 100644 index 0000000..78bea1f --- /dev/null +++ b/src/com/wilko/jaim/flap/FLAPDataFrame.java @@ -0,0 +1,73 @@ +/* + * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +/* + * FlapDataFrame.java + * + * Created on 3 May 2002, 14:54 + */ + +package com.wilko.jaim.flap; + +/** + * @author paulw + * @version $Revision: 1.3 $ + */ +public class FLAPDataFrame extends FLAPFrame { + + private int frameLen; + + /** + * Creates new FlapDataFrame + */ + public FLAPDataFrame() { + frame[1] = FLAP_FRAME_DATA; + frameLen = 1; + frame[FLAP_DATA_OFFSET] = 0; + } + + public FLAPDataFrame(byte[] frameData) { + frame[1] = FLAP_FRAME_DATA; + frameLen = 1; + frame[FLAP_DATA_OFFSET] = 0; + setFrameData(frameData); + } + + + public int getFLAPFrameType() { + return (FLAPFrame.FLAP_FRAME_DATA); + } + + public void addString(String s) { + frameLen--; // Backspace over '0' + 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() { + byte[] retarray = new byte[getLength()]; + + System.arraycopy(frame, FLAPFrame.FLAP_DATA_OFFSET, retarray, 0, getLength()); + return (retarray); + } + +} diff --git a/src/com/wilko/jaim/flap/FLAPErrorFrame.java b/src/com/wilko/jaim/flap/FLAPErrorFrame.java new file mode 100644 index 0000000..4ac5c2d --- /dev/null +++ b/src/com/wilko/jaim/flap/FLAPErrorFrame.java @@ -0,0 +1,51 @@ +/* + * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +/* + * FlapErrorFrame.java + * + * Created on 3 May 2002, 14:54 + */ + +package com.wilko.jaim.flap; + +/** + * @author paulw + * @version $Revision: 1.3 $ + */ +public class FLAPErrorFrame extends FLAPFrame { + + /** + * Creates new FLAPErrorFrame + */ + public FLAPErrorFrame() { + frame[1] = FLAP_FRAME_ERROR; + + } + + public FLAPErrorFrame(byte[] frameData) { + frame[1] = FLAP_FRAME_ERROR; + setFrameData(frameData); + } + + + public int getFLAPFrameType() { + return FLAPFrame.FLAP_FRAME_ERROR; + } + +} diff --git a/src/com/wilko/jaim/flap/FLAPFrame.java b/src/com/wilko/jaim/flap/FLAPFrame.java new file mode 100644 index 0000000..2f4a4e2 --- /dev/null +++ b/src/com/wilko/jaim/flap/FLAPFrame.java @@ -0,0 +1,109 @@ +/* + * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +/* + * FLAPFrame.java + * + * Created on 3 May 2002, 14:51 + */ + +package com.wilko.jaim.flap; + +/** + * @author paulw + * @version $Revision: 1.4 $ + */ +public abstract class FLAPFrame { + + public static final int FLAP_FRAME_SIGNON = 1; + public static final int FLAP_FRAME_DATA = 2; + public static final int FLAP_FRAME_ERROR = 3; + public static final int FLAP_FRAME_SIGNOFF = 4; + public static final int FLAP_FRAME_KEEP_ALIVE = 5; + public static final int FLAP_DATA_OFFSET = 6; + + protected byte[] frame; + protected int fLen; + + /** + * Creates new FLAPFrame + */ + public FLAPFrame() { + initialise(); + } + + protected void initialise() { + frame = new byte[8192]; + frame[0] = (byte) '*'; + frame[1] = 0; + frame[2] = 0; + frame[3] = 0; + frame[4] = 0; + frame[5] = 0; + fLen = 6; + + } + + 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 getLength() { + return ((frame[4] & 0xff) * 256 + (frame[5] & 0xff)); + } + + public void setLength(int length) { + frame[4] = (byte) (length / 256); + frame[5] = (byte) (length & 0xff); + fLen = length + FLAP_DATA_OFFSET; + } + + public byte[] getFrameData() { + byte[] b = new byte[fLen]; + System.arraycopy(frame, 0, b, 0, fLen); + return (b); + } + + protected void setFrameData(byte[] b) { + frame = new byte[b.length]; + fLen = b.length; + System.arraycopy(b, 0, frame, 0, b.length); + } + + 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(); + +} diff --git a/src/com/wilko/jaim/flap/FLAPFrameException.java b/src/com/wilko/jaim/flap/FLAPFrameException.java new file mode 100644 index 0000000..6269c78 --- /dev/null +++ b/src/com/wilko/jaim/flap/FLAPFrameException.java @@ -0,0 +1,51 @@ +/* + * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +/* + * FLAPFrameException.java + * + * Created on 3 May 2002, 15:05 + */ + +package com.wilko.jaim.flap; + +/** + * @author paulw + * @version $Revision: 1.3 $ + */ +public class FLAPFrameException extends java.lang.Exception { + + /** + * Creates new FLAPFrameException without detail message. + */ + public FLAPFrameException() { + } + + + /** + * Constructs an FLAPFrameException with the specified detail message. + * + * @param msg the detail message. + */ + public FLAPFrameException(String msg) { + super(msg); + } +} + + diff --git a/src/com/wilko/jaim/flap/FLAPFrameFactory.java b/src/com/wilko/jaim/flap/FLAPFrameFactory.java new file mode 100644 index 0000000..f6b864b --- /dev/null +++ b/src/com/wilko/jaim/flap/FLAPFrameFactory.java @@ -0,0 +1,68 @@ +/* + * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +/* + * FLAPFrameFactory.java + * + * Created on 3 May 2002, 15:04 + */ + +package com.wilko.jaim.flap; + +/** + * @author paulw + * @version $Revision: 1.3 $ + */ +public abstract class FLAPFrameFactory { + + /** + * Creates new FLAPFrameFactory + */ + public FLAPFrameFactory() { + } + + public static FLAPFrame createFLAPFrame(byte[] frameData) throws FLAPFrameException { + FLAPFrame f = null; + if (frameData[0] != '*') { + throw new FLAPFrameException("Frame does not start with '*'"); + } + + switch (frameData[1]) { + case FLAPFrame.FLAP_FRAME_SIGNON: + f = new FLAPSignonFrame(frameData); + break; + case FLAPFrame.FLAP_FRAME_DATA: + f = new FLAPDataFrame(frameData); + break; + case FLAPFrame.FLAP_FRAME_ERROR: + f = new FLAPErrorFrame(frameData); + break; + case FLAPFrame.FLAP_FRAME_SIGNOFF: + f = new FLAPSignoffFrame(frameData); + break; + case FLAPFrame.FLAP_FRAME_KEEP_ALIVE: + f = new FLAPKeepAliveFrame(frameData); + break; + default: + throw new FLAPFrameException("Illegal FLAP Frame type: " + Integer.toString(frameData[1])); + } + return (f); + } + +} diff --git a/src/com/wilko/jaim/flap/FLAPInputFrame.java b/src/com/wilko/jaim/flap/FLAPInputFrame.java new file mode 100644 index 0000000..cb9a0f6 --- /dev/null +++ b/src/com/wilko/jaim/flap/FLAPInputFrame.java @@ -0,0 +1,69 @@ +/* + * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +/* + * FLAPInputFrame.java + * + * Created on 3 May 2002, 15:52 + */ + +package com.wilko.jaim.flap; + +/** + * @author paulw + * @version $Revision: 1.3 $ + */ +public class FLAPInputFrame extends FLAPFrame { + + /** + * Creates new FLAPInputFrame + */ + private int frameLen; + + public FLAPInputFrame() { + frameLen = 0; + super.initialise(); + } + + public void addFrameData(byte b) { + frame[frameLen++] = b; + } + + public byte[] getFrameData() { + byte[] b = new byte[frameLen]; + System.arraycopy(frame, 0, b, 0, frameLen); + return (b); + } + + public void resetInputFrame() { + frameLen = 0; + } + + public boolean completeFrameRead() { + if (frameLen > 5) { + return frameLen - 6 == getLength(); + } + return (false); + } + + public int getFLAPFrameType() { + return (-1); + } + +} diff --git a/src/com/wilko/jaim/flap/FLAPKeepAliveFrame.java b/src/com/wilko/jaim/flap/FLAPKeepAliveFrame.java new file mode 100644 index 0000000..841e6b3 --- /dev/null +++ b/src/com/wilko/jaim/flap/FLAPKeepAliveFrame.java @@ -0,0 +1,55 @@ +/* + * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +/* + * FLAPKeepAliveFrame.java + * + * Created on 3 May 2002, 14:54 + */ + +package com.wilko.jaim.flap; + +/** + * @author paulw + * @version $Revision: 1.4 $ + */ +public class FLAPKeepAliveFrame extends FLAPFrame { + + /** + * Creates new FLAPKeepAliveFrame + */ + public FLAPKeepAliveFrame() { + this.initialise(); + } + + public FLAPKeepAliveFrame(byte[] frameData) { + initialise(); + setFrameData(frameData); + } + + protected void initialise() { + super.initialise(); + frame[1] = FLAP_FRAME_KEEP_ALIVE; + } + + public int getFLAPFrameType() { + return (FLAPFrame.FLAP_FRAME_KEEP_ALIVE); + } + +} diff --git a/src/com/wilko/jaim/flap/FLAPSignoffFrame.java b/src/com/wilko/jaim/flap/FLAPSignoffFrame.java new file mode 100644 index 0000000..9715ee9 --- /dev/null +++ b/src/com/wilko/jaim/flap/FLAPSignoffFrame.java @@ -0,0 +1,52 @@ +/* + * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +/* + * FLAPSignoffFrame.java + * + * Created on 3 May 2002, 14:54 + */ + +package com.wilko.jaim.flap; + +/** + * @author paulw + * @version $Revision: 1.3 $ + */ +public class FLAPSignoffFrame extends FLAPFrame { + + /** + * Creates new FlapSignonFrame + */ + public FLAPSignoffFrame() { + + frame[1] = FLAP_FRAME_SIGNOFF; + } + + public FLAPSignoffFrame(byte[] frameData) { + frame[1] = FLAP_FRAME_SIGNOFF; + setFrameData(frameData); + } + + + public int getFLAPFrameType() { + return (FLAPFrame.FLAP_FRAME_SIGNOFF); + } + +} diff --git a/src/com/wilko/jaim/flap/FLAPSignonFrame.java b/src/com/wilko/jaim/flap/FLAPSignonFrame.java new file mode 100644 index 0000000..b3e9a31 --- /dev/null +++ b/src/com/wilko/jaim/flap/FLAPSignonFrame.java @@ -0,0 +1,82 @@ +/* + * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +/* + * FlapSignonFrame.java + * + * Created on 3 May 2002, 14:54 + */ + +package com.wilko.jaim.flap; + +/** + * @author paulw + * @version $Revision: 1.3 $ + */ +public class FLAPSignonFrame extends FLAPFrame { + + /** + * Creates new FlapSignonFrame + */ + public FLAPSignonFrame() { + frame[1] = FLAP_FRAME_SIGNON; + } + + public FLAPSignonFrame(byte[] frameData) { + frame[1] = FLAP_FRAME_SIGNON; + setFrameData(frameData); + } + + 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--) { + frame[6 + i] = (byte) (version & 0xff); + version = version >> 8; + } + } + + 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) { + + int len = 0; + for (int i = 0; i < name.length(); i++) { + char c = name.charAt(i); + if (c != ' ') { + frame[FLAP_DATA_OFFSET + 8 + len++] = (byte) c; + } + } + setLength(8 + len); + frame[FLAP_DATA_OFFSET + 6] = (byte) (len / 256); + frame[FLAP_DATA_OFFSET + 7] = (byte) (len & 0xff); + } + + public int getFLAPFrameType() { + return (FLAPFrame.FLAP_FRAME_SIGNON); + } + +} diff --git a/src/com/wilko/jaim/responses/BuddyUpdateTocResponse.java b/src/com/wilko/jaim/responses/BuddyUpdateTocResponse.java new file mode 100644 index 0000000..1d79198 --- /dev/null +++ b/src/com/wilko/jaim/responses/BuddyUpdateTocResponse.java @@ -0,0 +1,213 @@ +/* + * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +/* + * BuddyUpdateTocResponse.java + * + * Created on 5 May 2002, 21:19 + */ + +package com.wilko.jaim.responses; + +import com.wilko.jaim.JaimEventListener; + +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 + * + * @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; + private int idleTime; + private boolean onAOL; + private boolean unconfirmed; + private boolean admin; + private boolean confirmed; + private Date signonTime; + private boolean away; + + /** + * Creates new BuddyUpdateTocResponse + */ + public BuddyUpdateTocResponse() { + buddyName = ""; + online = false; + evil = 0; + idleTime = 0; + onAOL = false; + unconfirmed = false; + admin = false; + confirmed = false; + away = false; + } + + /** + * 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) { + BuddyUpdateTocResponse tr = new BuddyUpdateTocResponse(); + tr.doParse(str); + return (tr); + } + + private void doParse(String str) { + cmd = str; + StringTokenizer st = new StringTokenizer(str, ":"); + + st.nextToken(); + buddyName = st.nextToken(); + String onlineStr = st.nextToken(); + online = onlineStr.equals("T"); + + evil = Integer.parseInt(st.nextToken()); + long signon = Long.parseLong(st.nextToken()); + signonTime = new Date(signon * 1000); + idleTime = Integer.parseInt(st.nextToken()); + String userclass = st.nextToken(); + if (userclass.charAt(0) == 'A') + onAOL = true; + if (userclass.charAt(1) == 'A') { + admin = true; + } else { + if (userclass.charAt(1) == 'U') { + unconfirmed = true; + } else { + if (userclass.charAt(1) == 'O') { + confirmed = true; + } + } + } + if (userclass.length() > 2) { + if (userclass.charAt(2) == 'U') { + away = true; + } + } + } + + /** + * Get the away status of the buddy specified by this update + * + * @return true if the buddy is "away" + */ + public boolean isAway() { + return (away); + } + + /** + * 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 + * + * @return The buddy name + */ + public String getBuddy() { + return (buddyName); + } + + /** + * Obtain the online status of this buddy update + * + * @return true if the buddy is on line + */ + public boolean isOnline() { + return (online); + } + + /** + * Obtain the idle time of this buddy + * + * @return The idle time in seconds + */ + public int getIdleTime() { + return (idleTime); + } + + /** + * Obtain the "Evil" (Warning) level of this buddy + * + * @return The warning level as a percentage + */ + public int getEvil() { + return (evil); + } + + /** + * Is this buddy an "Administrator" + * + * @return true if an administrator + */ + public boolean isAdmin() { + return (admin); + } + + /** + * IS this buddy a "confirmed" user + * + * @return True if this buddy is confirmed + */ + public boolean isConfirmed() { + return (confirmed); + } + + /** + * Is this user an "Unconfirmed user" + * + * @return True if this user is unconfirmed + */ + public boolean isUnconfirmed() { + return (unconfirmed); + } + + /** + * Get the signon time of this buddy + * + * @return The date/time of signon + */ + public Date getSignonTime() { + return (signonTime); + } + + /** + * 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) { + return (Response.equalsIgnoreCase(RESPONSE_TYPE)); + } + +} diff --git a/src/com/wilko/jaim/responses/ChatInviteTocResponse.java b/src/com/wilko/jaim/responses/ChatInviteTocResponse.java new file mode 100644 index 0000000..6bdba33 --- /dev/null +++ b/src/com/wilko/jaim/responses/ChatInviteTocResponse.java @@ -0,0 +1,113 @@ +/* + * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +/* + * BuddyUpdateTocResponse.java + * + * Created on 5 May 2002, 21:19 + */ + +package com.wilko.jaim.responses; + +import com.wilko.jaim.JaimEventListener; + +import java.util.StringTokenizer; + +/** + * 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; + + /** + * Creates new BuddyUpdateTocResponse + */ + public ChatInviteTocResponse() { + roomName = ""; + roomID = ""; + senderScreenname = ""; + message = ""; + } + + /** + * 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) { + ChatInviteTocResponse tr = new ChatInviteTocResponse(); + tr.doParse(str); + return (tr); + } + + private void doParse(String str) { + cmd = str; + StringTokenizer st = new StringTokenizer(str, ":"); + + st.nextToken(); + roomName = st.nextToken(); + roomID = st.nextToken(); + senderScreenname = st.nextToken(); + message = st.nextToken(); + } + + /** + * 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; + } + + public String getRoomName() { + return roomName; + } + + public String getRoomID() { + return roomID; + } + + public String getSenderScreenname() { + return senderScreenname; + } + + public String getMessage() { + return message; + } + + /** + * 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) { + return (Response.equalsIgnoreCase(RESPONSE_TYPE)); + } + +} diff --git a/src/com/wilko/jaim/responses/ConfigTocResponse.java b/src/com/wilko/jaim/responses/ConfigTocResponse.java new file mode 100644 index 0000000..dc72488 --- /dev/null +++ b/src/com/wilko/jaim/responses/ConfigTocResponse.java @@ -0,0 +1,211 @@ +/* + * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +/* + * ConfigTocResponse.java + * Created on 1, October 2002 + */ +package com.wilko.jaim.responses; + +import com.wilko.jaim.*; + +import java.util.*; + +/** + * 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 final Vector buddyList = new Vector(); + /** + * The HashMap of known buddies + */ + private HashMap buddies; + /** + * The mode for this configuration + */ + private int mode; + + /** + * 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() { + return buddyList.elements(); + } + + /** + * Returns a Collection of groups. Each element is a {@link Group) + * + * @return the groups + */ + public Collection getGroups() { + java.util.Collection result = new Vector(buddyList); + return result; + } + + + /** + * 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. + */ + public TocResponse parseString(String message) { + ConfigTocResponse tr = new ConfigTocResponse(); + tr.doParse(message); + return (tr); + } + + private void doParse(String message) { + cmd = message; + int colonIndex = message.indexOf(':'); + //throw away the first word. + 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()) { + // 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 = itemType.substring(0, firstSpace); + + char type = itemType.charAt(0); + switch (type) { + case 'g': + currentGroup = new Group(itemValue); + buddyList.add(currentGroup); + break; + + case 'b': + + tmpBuddy = getBuddy(itemValue); + //this shouldn't happen, but: + if (currentGroup == null) { + currentGroup = new Group(""); + buddyList.add(currentGroup); + } + currentGroup.addBuddy(tmpBuddy); + + + break; + + case 'p': + tmpBuddy = getBuddy(itemValue); + tmpBuddy.setPermit(true); + break; + + case 'm': + setMode(Integer.valueOf(itemValue).intValue()); + break; + + case 'd': + + tmpBuddy = getBuddy(itemValue); + tmpBuddy.setDeny(true); + break; + } + } + } + + /** + * 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 buddyName The name of the buddy we are looking for + * @return The buddy object + */ + + private Buddy getBuddy(String buddyName) { + Buddy retBuddy = (Buddy) buddies.get(buddyName); + if (retBuddy == null) { + retBuddy = new Buddy(buddyName); + buddies.put(buddyName, retBuddy); + } + return (retBuddy); + } + + /** + * Gets the mode for this configuration + * + * @return mode for the configuration + */ + public int getMode() { + return mode; + } + + /** + * 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 + */ + public boolean canHandle(String Response) { + return (Response.equalsIgnoreCase(RESPONSE_TYPE)); + } + +} diff --git a/src/com/wilko/jaim/responses/ConnectionLostTocResponse.java b/src/com/wilko/jaim/responses/ConnectionLostTocResponse.java new file mode 100644 index 0000000..355c4a9 --- /dev/null +++ b/src/com/wilko/jaim/responses/ConnectionLostTocResponse.java @@ -0,0 +1,52 @@ +/* + * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +/* + * ConnectionLostTocResponse.java + * + * Created on November 2, 2002, 2:52 PM + */ + +package com.wilko.jaim.responses; + +/** + * 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: $ + */ +public class ConnectionLostTocResponse extends TocResponse { + + public static final String RESPONSE_TYPE = "CONNECTIONLOST"; + + /** + * Creates a new instance of LoginCompleteTocResponse + */ + public ConnectionLostTocResponse() { + } + + public String getResponseType() { + return (RESPONSE_TYPE); + } + + public String toString() { + return (RESPONSE_TYPE); + } + +} diff --git a/src/com/wilko/jaim/responses/ErrorTocResponse.java b/src/com/wilko/jaim/responses/ErrorTocResponse.java new file mode 100644 index 0000000..eecdfeb --- /dev/null +++ b/src/com/wilko/jaim/responses/ErrorTocResponse.java @@ -0,0 +1,146 @@ +/* + * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +/* + * ErrorTocResponse.java + * + * Created on 4 May 2002, 14:52 + */ + +package com.wilko.jaim.responses; + +import com.wilko.jaim.JaimEventListener; + +import java.util.MissingResourceException; + +/** + * 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; + + /** + * 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 + * + * @param str The error response string + */ + public TocResponse parseString(String str) { + ErrorTocResponse tr = new ErrorTocResponse(); + tr.doParse(str); + return (tr); + } + + private void doParse(String str) { + + cmd = str; + int colonPos = str.indexOf(':'); + if (colonPos != -1) { + str = str.substring(colonPos + 1); + colonPos = str.indexOf(':'); + if (colonPos != -1) { + errorCode = Integer.parseInt(str.substring(0, colonPos)); + errorText = str.substring(colonPos + 1); + } else { + errorCode = Integer.parseInt(str); + } + } + + } + + /** + * Obtain the error code for this response + * + * @return The error code + */ + public int getErrorCode() { + return (errorCode); + } + + /** + * Get the error text (if any) associated with this error response + * + * @return The error text + */ + public String getErrorText() { + return (errorText); + } + + /** + * Obtain the error message that corresponds to this error. + * + * @return The error text with any applicable error argument text inserted + */ + public String getErrorDescription() { + try { + StringBuffer desc = new StringBuffer(java.util.ResourceBundle.getBundle("com/wilko/jaim/TocErrorDescriptions").getString(Integer.toString(errorCode))); + String sDesc = desc.toString(); + int argpos = sDesc.indexOf("%s"); + if (argpos != -1) { + desc.replace(argpos, argpos + 1, errorText); + } + return (desc.toString()); + + } catch (MissingResourceException e) { + return ("Unable to locate error description:" + e); + } + } + + public String getResponseType() { + return RESPONSE_TYPE; + } + + /** + * 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) { + return (Response.equalsIgnoreCase(RESPONSE_TYPE)); + } + +} diff --git a/src/com/wilko/jaim/responses/EvilTocResponse.java b/src/com/wilko/jaim/responses/EvilTocResponse.java new file mode 100644 index 0000000..60ee5a9 --- /dev/null +++ b/src/com/wilko/jaim/responses/EvilTocResponse.java @@ -0,0 +1,127 @@ +/* + * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +/* + * EvilTocResponse.java + * + * Created on 6 May 2002, 16:49 + */ + +package com.wilko.jaim.responses; + +import com.wilko.jaim.JaimEventListener; + +import java.util.StringTokenizer; + +/** + * 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; + + /** + * Creates new EvilTocResponse + */ + public EvilTocResponse() { + anonymousEvil = true; + evilBy = ""; + evilAmount = 0; + } + + /** + * Parse the evil message from the TOC server + * + * @param str The evil message + */ + public TocResponse parseString(java.lang.String str) { + EvilTocResponse tr = new EvilTocResponse(); + tr.doParse(str); + return (tr); + } + + private void doParse(String str) { + + StringTokenizer st = new StringTokenizer(str, ":"); + + st.nextToken(); // skip over "EVILED" + evilAmount = Integer.parseInt(st.nextToken()); + if (st.hasMoreTokens()) { + evilBy = st.nextToken(); + anonymousEvil = false; + } 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 + * + * @return The cumulative evil or warning level + */ + public int getEvilAmount() { + return (evilAmount); + } + + /** + * Obtain the name of the buddy that issued the warning. + * + * @return The buddy name that issued the warning + * @see #isAnonymous + */ + public String getEvilBy() { + return (evilBy); + } + + /** + * Obtain the anonymous status of this warning + * + * @return true if this warning was issued anonymously + */ + public boolean isAnonymous() { + return (anonymousEvil); + } + + /** + * Used by the response dispatcher + * + * @return The response type + */ + public String getResponseType() { + return RESPONSE_TYPE; + } + + + /** + * 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) { + return (Response.equalsIgnoreCase(RESPONSE_TYPE)); + } + +} diff --git a/src/com/wilko/jaim/responses/GenericTocResponse.java b/src/com/wilko/jaim/responses/GenericTocResponse.java new file mode 100644 index 0000000..04acd71 --- /dev/null +++ b/src/com/wilko/jaim/responses/GenericTocResponse.java @@ -0,0 +1,97 @@ +/* + * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +/* + * GenericTocCommand.java + * + * Created on 4 May 2002, 12:07 + */ + +package com.wilko.jaim.responses; + +import com.wilko.jaim.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 + */ + public GenericTocResponse() { + this.cmd = ""; + } + + /** + * Parse an incoming string + * + * @param str The response string to be parsed + */ + public TocResponse parseString(String str) { + GenericTocResponse tr = new GenericTocResponse(); + tr.doParse(str); + return tr; + } + + private void doParse(String str) { + cmd = str; + } + + /** + * 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 + * + * @return The response as a string + */ + public String toString() { + return (cmd); + } + + /** + * Used in the response dispatching process + * + * @return The respnse type + */ + public String getResponseType() { + return ("UNKNOWN"); + } + + /** + * 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) { + return (true); + } + +} diff --git a/src/com/wilko/jaim/responses/GotoTocResponse.java b/src/com/wilko/jaim/responses/GotoTocResponse.java new file mode 100644 index 0000000..f98dfb6 --- /dev/null +++ b/src/com/wilko/jaim/responses/GotoTocResponse.java @@ -0,0 +1,115 @@ +/* + * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +/* + * TocIMResponse.java + * + * Created on 4 May 2002, 14:38 + */ + +package com.wilko.jaim.responses; + +import com.wilko.jaim.JaimEventListener; + +/** + * 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; + + /** + * Creates new GotoTocResponse + */ + public GotoTocResponse() { + windowName = ""; + URL = ""; + } + + /** + * Obtain the suggested window name for this URL + * + * @return The window name + */ + public String getWindowName() { + return (windowName); + } + + /** + * Obtain the URL + * + * @return The URL + */ + public String getURL() { + return (URL); + } + + + /** + * Parse an incoming response string + * + * @param str The string to be parsed + */ + public TocResponse parseString(java.lang.String str) { + GotoTocResponse tr = new GotoTocResponse(); + tr.doParse(str); + return (tr); + } + + private void doParse(String str) { + cmd = str; + int colonPos = str.indexOf(':'); + if (colonPos != -1) { + str = str.substring(colonPos + 1); + colonPos = str.indexOf(':'); + if (colonPos != -1) { + windowName = str.substring(0, colonPos); + URL = str.substring(colonPos + 1); + + } + } + + } + + /** + * 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. + * + * @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) { + return (Response.equalsIgnoreCase(RESPONSE_TYPE)); + } + +} diff --git a/src/com/wilko/jaim/responses/IMTocResponse.java b/src/com/wilko/jaim/responses/IMTocResponse.java new file mode 100644 index 0000000..93e57af --- /dev/null +++ b/src/com/wilko/jaim/responses/IMTocResponse.java @@ -0,0 +1,132 @@ +/* + * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +/* + * TocIMResponse.java + * + * Created on 4 May 2002, 14:38 + */ + +package com.wilko.jaim.responses; + +import com.wilko.jaim.JaimEventListener; +import com.wilko.jaim.Utils; + +/** + * 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; + + /** + * Creates new TocIMResponse + */ + public IMTocResponse() { + from = ""; + msg = ""; + autoResponse = false; + } + + /** + * Obtain the name of the buddy who sent this instant message + * + * @return The senders name + */ + public String getFrom() { + return (from); + } + + /** + * Obtain the message + * + * @return The message + * @see Utils#stripHTML + */ + public String getMsg() { + return (msg); + } + + /** + * Is this response an automatically generated response? + * + * @return true if this is an automatically generated response + */ + public boolean getAutoResponse() { + return (autoResponse); + } + + /** + * Parse an incoming IM response string + * + * @param str The string to be parsed + */ + public TocResponse parseString(java.lang.String str) { + IMTocResponse tr = new IMTocResponse(); + tr.doParse(str); + return (tr); + } + + private void doParse(String str) { + cmd = str; + int colonPos = str.indexOf(':'); + if (colonPos != -1) { + str = str.substring(colonPos + 1); + colonPos = str.indexOf(':'); + if (colonPos != -1) { + from = str.substring(0, colonPos); + str = str.substring(colonPos + 1); + colonPos = str.indexOf(':'); + if (str.charAt(0) == 'T') { + autoResponse = true; + } + if (colonPos != -1) { + msg = str.substring(colonPos + 1); + } + } + } + + } + + /** + * 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. + * + * @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) { + return (Response.equalsIgnoreCase(RESPONSE_TYPE)); + } + +} diff --git a/src/com/wilko/jaim/responses/LoginCompleteTocResponse.java b/src/com/wilko/jaim/responses/LoginCompleteTocResponse.java new file mode 100644 index 0000000..e9eb463 --- /dev/null +++ b/src/com/wilko/jaim/responses/LoginCompleteTocResponse.java @@ -0,0 +1,52 @@ +/* + * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +/* + * LoginCompleteTocResponse.java + * + * Created on November 2, 2002, 2:52 PM + */ + +package com.wilko.jaim.responses; + +/** + * 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: $ + */ +public class LoginCompleteTocResponse extends TocResponse { + + public static final String RESPONSE_TYPE = "LOGINCOMPLETE"; + + /** + * Creates a new instance of LoginCompleteTocResponse + */ + public LoginCompleteTocResponse() { + } + + public String getResponseType() { + return (RESPONSE_TYPE); + } + + public String toString() { + return (RESPONSE_TYPE); + } + +} diff --git a/src/com/wilko/jaim/responses/NickTocResponse.java b/src/com/wilko/jaim/responses/NickTocResponse.java new file mode 100644 index 0000000..ec8a537 --- /dev/null +++ b/src/com/wilko/jaim/responses/NickTocResponse.java @@ -0,0 +1,85 @@ +/* + * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +/* + * NickTocResponse.java + * + * Created on 6 May 2002, 17:21 + */ + +package com.wilko.jaim.responses; + +import com.wilko.jaim.JaimConnection; + +/** + * 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; + + + /** + * Creates new NickTocResponse + */ + public NickTocResponse() { + nickName = ""; + } + + + public TocResponse parseString(java.lang.String str) { + NickTocResponse tr = new NickTocResponse(); + tr.doParse(str); + return (tr); + } + + private void doParse(String str) { + int colonPos = str.indexOf(':'); + + if (colonPos != -1) { + nickName = str.substring(colonPos + 1); + } + + + } + + public String getNickName() { + return (nickName); + } + + + public String getResponseType() { + return RESPONSE_TYPE; + } + + /** + * 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) { + return (Response.equalsIgnoreCase(RESPONSE_TYPE)); + } + +} diff --git a/src/com/wilko/jaim/responses/SignOnTocResponse.java b/src/com/wilko/jaim/responses/SignOnTocResponse.java new file mode 100644 index 0000000..f8b6a48 --- /dev/null +++ b/src/com/wilko/jaim/responses/SignOnTocResponse.java @@ -0,0 +1,82 @@ +/* + * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +/* + * SignOnTocResponse.java + * + * Created on 4 May 2002, 13:29 + */ + +package com.wilko.jaim.responses; + +import com.wilko.jaim.JaimConnection; + +/** + * 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; + + + /** + * Creates new SignOnTocResponse + */ + public SignOnTocResponse() { + version = ""; + } + + public String getResponseType() { + return (RESPONSE_TYPE); + } + + protected String getVersion() { + return (version); + } + + + public TocResponse parseString(String str) { + SignOnTocResponse tr = new SignOnTocResponse(); + tr.doParse(str); + return (tr); + } + + private void doParse(String str) { + cmd = str; + int colonpos = str.indexOf(':'); + if (colonpos != -1) { + version = str.substring(colonpos + 1); + } + } + + /** + * 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) { + return (Response.equalsIgnoreCase(RESPONSE_TYPE)); + } + +} diff --git a/src/com/wilko/jaim/responses/TocResponse.java b/src/com/wilko/jaim/responses/TocResponse.java new file mode 100644 index 0000000..3168378 --- /dev/null +++ b/src/com/wilko/jaim/responses/TocResponse.java @@ -0,0 +1,46 @@ +/* + * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +/* + * TocCommand.java + * + * Created on 4 May 2002, 11:19 + */ + +package com.wilko.jaim.responses; + +/** + * @author paulw + * @version $Revision: 1.5 $ + */ +public abstract class TocResponse { + + protected String cmd; + + public TocResponse() { + cmd = ""; + } + + public String toString() { + return (cmd); + } + + public abstract String getResponseType(); + +} diff --git a/src/com/wilko/jaim/responses/TocResponseFactory.java b/src/com/wilko/jaim/responses/TocResponseFactory.java new file mode 100644 index 0000000..6c53009 --- /dev/null +++ b/src/com/wilko/jaim/responses/TocResponseFactory.java @@ -0,0 +1,75 @@ +/* + * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +/* + * TocResponseFactory.java + * + * Created on 4 May 2002, 12:05 + */ + +package com.wilko.jaim.responses; + +/** + * @author paulw + * @version $Revision: 1.5 $ + */ + +import java.util.Vector; + +public abstract class TocResponseFactory { + + static Vector responseHandlers = new Vector(); + + /** + * Creates new TocResponseFactory + */ + public TocResponseFactory() { + } + + public static void addResponseHandler(TocResponseHandler h) { + synchronized (responseHandlers) { + responseHandlers.add(h); + } + } + + public static TocResponse createResponse(byte[] b) { + TocResponse tr = null; + String strversion = new String(b); + int colonpos = strversion.indexOf(':'); + if (colonpos != -1) { + String firstWord = strversion.substring(0, colonpos); + int i = 0; + synchronized (responseHandlers) { + while ((i < responseHandlers.size()) && (tr == null)) { + TocResponseHandler h = (TocResponseHandler) responseHandlers.elementAt(i); + if (h.canHandle(firstWord)) { + tr = h.parseString(strversion); + } + i++; + } + } + } + if (tr == null) { + GenericTocResponse gtr = new GenericTocResponse(); + tr = gtr.parseString(strversion); + } + return (tr); + } + +} diff --git a/src/com/wilko/jaim/responses/TocResponseHandler.java b/src/com/wilko/jaim/responses/TocResponseHandler.java new file mode 100644 index 0000000..7934a7e --- /dev/null +++ b/src/com/wilko/jaim/responses/TocResponseHandler.java @@ -0,0 +1,47 @@ +/* + * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +package com.wilko.jaim.responses; + +/** + * @author paulw + * @version $revision: $ + */ +public interface TocResponseHandler { + + /** + * 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 + */ + + boolean canHandle(String 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 + */ + + TocResponse parseString(String Response); + +} + diff --git a/src/com/wilko/jaimtest/JaimTest.java b/src/com/wilko/jaimtest/JaimTest.java index 032af65..2df11f9 100644 --- a/src/com/wilko/jaimtest/JaimTest.java +++ b/src/com/wilko/jaimtest/JaimTest.java @@ -26,6 +26,7 @@ package com.wilko.jaimtest; import com.wilko.jaim.*; +import com.wilko.jaim.responses.*; import java.io.IOException; import java.io.InputStream; -- cgit v1.2.3-54-g00ecf