swpchat.server
Class ProtocolHandler

java.lang.Object
  |
  +--swpchat.server.ProtocolHandler
All Implemented Interfaces:
ChatTokens, ControlTokens, SenderReceiverTokens
Direct Known Subclasses:
ControlProtocolHandler, ReceiverProtocolHandler, SenderProtocolHandler

public abstract class ProtocolHandler
extends java.lang.Object
implements SenderReceiverTokens, ControlTokens

Used for communication with the client, the server part of the chat protocol

Author:
Brunner, Sturm, Stuellenberg This class still contains isSetNick etc. to be used by its subclasses. I(omeyer) consider this bad style as the common syntax in the protocols could be seen a coincidence

Field Summary
(package private) static java.lang.String CLS
           
 
Fields inherited from interface swpchat.protocol.SenderReceiverTokens
STR_JOIN, STR_JOINPASSWD, STR_LEAVE, STR_OFF, STR_ON, STR_PLAY, STR_PLAY_BEGIN, STR_PLAY_RE_BEGIN, STR_RECEIVE, STR_RECEIVE_BEGIN, STR_RECEIVE_USERINFO, STR_REQUEST_USERINFO, STR_SEND, STR_SEND_BEGIN, STR_SEND_RE_BEGIN, STR_SETTOPIC, STR_SETTOPIC_BEGIN, STR_SHIP, STR_SHIP_BEGIN, STR_TOPICCHANGED, STR_WHISPER, STR_WHISPRECEIVE
 
Fields inherited from interface swpchat.protocol.ChatTokens
CHAR_ARG_SEP, CHAR_MSG_END, CHAR_MSG_EOL, CHAR_QUOTE, CHAR_STRING_DELIMITER, STR_ARG_SEP, STR_AUTHORIZE, STR_MSG_END, STR_MSG_EOL, STR_NEG_ARG, STR_NEGATIVE, STR_POS_ARG, STR_POSITIVE, STR_QUOTE, STR_REPLY, STR_STRING_DELIMITER, STR_WAIT
 
Fields inherited from interface swpchat.protocol.ControlTokens
STR_EMOTION, STR_LOGIN, STR_LOGIN_BEGIN, STR_LOGIN_RE_BEGIN, STR_LOGOUT, STR_LOGOUT_BEGIN, STR_LOGOUT_RE_BEGIN, STR_MEMBER, STR_MEMBER_BEGIN, STR_MEMBER_INFO, STR_MEMBER_JOIN, STR_MEMBER_LEAVE, STR_MEMBER_SHIP, STR_NEW_CHANNEL, STR_NOTIFICATION, STR_NOTIFICATION_BEGIN, STR_NOTIFY_REQUEST, STR_REMOVE_CHANNEL, STR_RENAME_CHANNEL, STR_REQUEST_IP, STR_REQUST_IP_RE_BEGIN, STR_SEND_USERINFO, STR_SET_NICK, STR_SET_NICK_BEGIN, STR_SET_NICK_RE_BEGIN, STR_SET_SESSIONKEY, STR_STOP_NOTIFICATION, STR_TELEPHONE_REQUEST
 
Constructor Summary
ProtocolHandler()
          constuctor of this class
 
Method Summary
abstract  void disconnect()
           
protected static boolean isEmotion(java.util.Vector tokenlist)
          true, if tokenlist contains valid Emotion command
protected  boolean isJoin(java.util.Vector tokenlist)
          Returns true, iff the tokenlist contains a valid join command.
protected  boolean isJoinPasswd(java.util.Vector tokenlist)
          Returns true, iffffffff the tokenlist contains a valid joinPasswd command.
protected  boolean isLeave(java.util.Vector tokenlist)
          Returns true, iff the tokenlist contains a valid leave command.
protected  boolean isLogin(java.util.Vector tokenlist)
          Returns true, iff the tokenlist contains a valid Login command.
protected  boolean isLogout(java.util.Vector tokenlist)
          Returns true, iff the tokenlist contains a valid logout command.
protected static boolean isMemberRequest(java.util.Vector tokenlist)
          true, if tokenlist contains valid MemberRequest
protected static boolean isNewChannel(java.util.Vector tokenlist)
          Returns true, iff the tokenlist contains a valid newChannel command.
protected static boolean isNewChannelReply(java.util.Vector tokenlist)
          Returns true, iff the tokenlist contains a valid newChannel reply.
protected static boolean isNotificationRequest(java.util.Vector tokenlist)
          true, iff tokenlist contains valid notificationRequest message.
protected  boolean isPlay(java.util.Vector tokenlist)
          Returns true, iff the tokenlist contains a valid play command.
protected static boolean isPutShip(java.util.Vector tokenlist)
          true, iff tokenlist contains valid putShip command
protected static boolean isRemoveChannel(java.util.Vector tokenlist)
          Returns true, iff the tokenlist contains a valid removeChannel command.
protected static boolean isRemoveChannelReply(java.util.Vector tokenlist)
          Returns true, iff the tokenlist contains a valid removeChannel reply.
protected static boolean isRenameChannel(java.util.Vector tokenlist)
          Returns true, iff the tokenlist contains a valid renameChannel command.
protected static boolean isRenameChannelReply(java.util.Vector tokenlist)
          Returns true, iff the tokenlist contains a valid renameChannel reply.
protected static boolean isRequestIPAddress(java.util.Vector tokenlist)
          true, iff tokenlist contains valid requestIPAddress command.
protected static boolean isRequestIPAddressReply(java.util.Vector tokenlist)
          true, iff tokenlist contains valid requestIPAddress reply.
protected static boolean isRequestUserInfo(java.util.Vector tokenlist)
          true, iff tokenlist contains valid requestUserInfo command
protected  boolean isSend(java.util.Vector tokenlist)
          Returns true, iff the tokenlist contains a valid send command.
protected static boolean isSendTelephoneRequest(java.util.Vector tokenlist)
          true, iff tokenlist contains valid sendTelephoneRequest command.
protected static boolean isSendTelephoneRequestReply(java.util.Vector tokenlist)
          true, iff tokenlist contains valid sendTelephoneRequest reply.
protected static boolean isSendUserInfo(java.util.Vector tokenlist)
          true, iff tokenlist contains valid sendUserInfo command
protected static boolean isSetNick(java.util.Vector tokenlist)
          Returns true, iff the tokenlist contains a valid setNickCommand command.
protected  boolean isSetSessionKey(java.util.Vector tokenlist)
          Returns true, iff the tokenlist contains a valid setSessionKey command.
protected  boolean isSetTopic(java.util.Vector tokenlist)
          Returns true, if the tokenlist contains a valid settopic command.
protected static boolean isStopNotification(java.util.Vector tokenlist)
          true, iff tokenlist contains valid stopNotification message.
protected  boolean isWhisper(java.util.Vector tokenlist)
          Returns true, iff the tokenlist contains a valid whisper command.
protected  java.util.Vector readCommand(ChatStreamTokenizer tokenizer, java.net.Socket sourceSocket)
           
protected static void reply(java.io.BufferedWriter ostream, java.lang.String command, java.lang.String information)
          Generate an reply answer for a given command.
protected static void send(java.io.BufferedWriter ostream, java.lang.String command, java.lang.String information)
          Generate an answer for a given command.
protected static void send(java.io.BufferedWriter ostream, java.lang.String command, java.lang.String information1, java.lang.String information2)
          Generate an answer for a given command.
protected static void send(java.io.BufferedWriter ostream, java.lang.String command, java.lang.String information1, java.lang.String information2, java.lang.String information3)
          Generate an answer for a given command.
protected static void send(java.io.BufferedWriter ostream, java.lang.String command, java.lang.String information1, java.lang.String information2, java.lang.String information3, java.lang.String information4)
          Generate an answer for a given command.
protected static void send(java.io.BufferedWriter ostream, java.lang.String command, java.lang.String information1, java.lang.String information2, java.lang.String information3, java.lang.String information4, java.lang.String information5)
          Send a given command.
abstract  void serve(java.net.Socket clientSocket, ClientConnection clientConnection, java.io.InputStream inputStream)
          serves the client: parses commands from the client and sends appropiate replies (protocol violations are ignored for now)
private static void writeLine(java.io.BufferedWriter ostream, java.lang.String message)
          Method to send the a String to the outgoing Stream
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

CLS

static final java.lang.String CLS
Constructor Detail

ProtocolHandler

public ProtocolHandler()
constuctor of this class
Method Detail

serve

public abstract void serve(java.net.Socket clientSocket,
                           ClientConnection clientConnection,
                           java.io.InputStream inputStream)
                    throws TimeoutException,
                           java.io.IOException,
                           java.security.InvalidParameterException
serves the client: parses commands from the client and sends appropiate replies (protocol violations are ignored for now)
Parameters:
clientSocket - Socket used for communication between client and server .
inputStream - The input stream of clientSocket. There were reports of problems with opening multiple streams on a socket.
Throws:
TimeoutException - thrown if connection to the client is lost or too slow.
java.io.IOException - thrown for any I/O error.
java.security.InvalidParameterException - possibly useful

disconnect

public abstract void disconnect()

isSetNick

protected static boolean isSetNick(java.util.Vector tokenlist)
Returns true, iff the tokenlist contains a valid setNickCommand command.
Parameters:
tokenlist - The Vector which is to be analysed
Returns:
result Is it the wanted command or not

isSetSessionKey

protected boolean isSetSessionKey(java.util.Vector tokenlist)
Returns true, iff the tokenlist contains a valid setSessionKey command.
Parameters:
tokenlist - The Vector which is to be analysed
Returns:
result Is it the wanted command or not

isLogin

protected boolean isLogin(java.util.Vector tokenlist)
Returns true, iff the tokenlist contains a valid Login command.
Parameters:
tokenlist - The Vector which is to be analysed
Returns:
result Is it the wanted command or not

isLogout

protected boolean isLogout(java.util.Vector tokenlist)
Returns true, iff the tokenlist contains a valid logout command.
Parameters:
tokenlist - The Vector which is to be analysed
Returns:
result Is it the wanted command or not

isJoin

protected boolean isJoin(java.util.Vector tokenlist)
Returns true, iff the tokenlist contains a valid join command.
Parameters:
tokenlist - The Vector which is to be analysed
Returns:
result Is it the wanted command or not

isLeave

protected boolean isLeave(java.util.Vector tokenlist)
Returns true, iff the tokenlist contains a valid leave command.
Parameters:
tokenlist - The Vector which is to be analysed
Returns:
result Is it the wanted command or not

isSetTopic

protected boolean isSetTopic(java.util.Vector tokenlist)
Returns true, if the tokenlist contains a valid settopic command.
Parameters:
tokenlist - The Vector which is to be analysed
Returns:
result Is it the wanted command or not

isSend

protected boolean isSend(java.util.Vector tokenlist)
Returns true, iff the tokenlist contains a valid send command.
Parameters:
tokenlist - The Vector which is to be analysed
Returns:
result Is it the wanted command or not

isPlay

protected boolean isPlay(java.util.Vector tokenlist)
Returns true, iff the tokenlist contains a valid play command.
Parameters:
tokenlist - The Vector which is to be analysed
Returns:
result Is it the wanted command or not

isJoinPasswd

protected boolean isJoinPasswd(java.util.Vector tokenlist)
Returns true, iffffffff the tokenlist contains a valid joinPasswd command.
Parameters:
tokenlist - The Vector which is to be analysed
Returns:
result Is it the wanted command or not

isNewChannelReply

protected static boolean isNewChannelReply(java.util.Vector tokenlist)
Returns true, iff the tokenlist contains a valid newChannel reply.
Parameters:
tokenlist - The Vector which is to be analysed
Returns:
result Is it the wanted command or not

isRemoveChannelReply

protected static boolean isRemoveChannelReply(java.util.Vector tokenlist)
Returns true, iff the tokenlist contains a valid removeChannel reply.
Parameters:
tokenlist - The Vector which is to be analysed
Returns:
result Is it the wanted command or not

isRenameChannelReply

protected static boolean isRenameChannelReply(java.util.Vector tokenlist)
Returns true, iff the tokenlist contains a valid renameChannel reply.
Parameters:
tokenlist - The Vector which is to be analysed
Returns:
result Is it the wanted command or not

isNewChannel

protected static boolean isNewChannel(java.util.Vector tokenlist)
Returns true, iff the tokenlist contains a valid newChannel command.
Parameters:
tokenlist - The Vector which is to be analysed
Returns:
result Is it the wanted command or not

isRemoveChannel

protected static boolean isRemoveChannel(java.util.Vector tokenlist)
Returns true, iff the tokenlist contains a valid removeChannel command.
Parameters:
tokenlist - The Vector which is to be analysed
Returns:
result Is it the wanted command or not

isRenameChannel

protected static boolean isRenameChannel(java.util.Vector tokenlist)
Returns true, iff the tokenlist contains a valid renameChannel command.
Parameters:
tokenlist - The Vector which is to be analysed
Returns:
result Is it the wanted command or not

isPutShip

protected static boolean isPutShip(java.util.Vector tokenlist)
true, iff tokenlist contains valid putShip command
Parameters:
tokenlist - the vector to be analysed
Returns:
result true, iff it is a putShip command

isEmotion

protected static boolean isEmotion(java.util.Vector tokenlist)
true, if tokenlist contains valid Emotion command
Parameters:
tokenlist - the vector to be analysed
Returns:
result true, iff it is a sendEmotion command

isWhisper

protected boolean isWhisper(java.util.Vector tokenlist)
Returns true, iff the tokenlist contains a valid whisper command.
Parameters:
tokenlist - The Vector which is to be analysed
Returns:
result Is it the wanted command or not

isSendUserInfo

protected static boolean isSendUserInfo(java.util.Vector tokenlist)
true, iff tokenlist contains valid sendUserInfo command
Parameters:
tokenlist - the vector to be analysed
Returns:
result true, iff it is a sendUserInfo command

isRequestUserInfo

protected static boolean isRequestUserInfo(java.util.Vector tokenlist)
true, iff tokenlist contains valid requestUserInfo command
Parameters:
tokenlist - the tokenlist to be analysed
Returns:
true, iff it is a valid requestUserInfo command

isRequestIPAddress

protected static boolean isRequestIPAddress(java.util.Vector tokenlist)
true, iff tokenlist contains valid requestIPAddress command.
Parameters:
tokenlist - the tokenlist to be analysed
Returns:
true, iff it is a valid requestUserInfo command

isRequestIPAddressReply

protected static boolean isRequestIPAddressReply(java.util.Vector tokenlist)
true, iff tokenlist contains valid requestIPAddress reply.
Parameters:
tokenlist - the tokenlist to be analysed
Returns:
true, iff it is a valid requestUserInfo command

isSendTelephoneRequest

protected static boolean isSendTelephoneRequest(java.util.Vector tokenlist)
true, iff tokenlist contains valid sendTelephoneRequest command.
Parameters:
tokenlist - the tokenlist to be analysed
Returns:
true, iff it is a valid sendFileRequest command

isSendTelephoneRequestReply

protected static boolean isSendTelephoneRequestReply(java.util.Vector tokenlist)
true, iff tokenlist contains valid sendTelephoneRequest reply.
Parameters:
tokenlist - the tokenlist to be analysed
Returns:
true, iff it is a valid sendFileRequestreply

isMemberRequest

protected static boolean isMemberRequest(java.util.Vector tokenlist)
true, if tokenlist contains valid MemberRequest
Parameters:
tokenlist - the tokenlist to be analysed
Returns:
true, iff it is a valid MemberRequest

isNotificationRequest

protected static boolean isNotificationRequest(java.util.Vector tokenlist)
true, iff tokenlist contains valid notificationRequest message.
Parameters:
tokenlist - the tokenlist to be analysed
Returns:
true, iff it is a valid notificationRequest.

isStopNotification

protected static boolean isStopNotification(java.util.Vector tokenlist)
true, iff tokenlist contains valid stopNotification message.
Parameters:
tokenlist - the tokenlist to be analysed
Returns:
true, iff it is a valid stopNotification message.

writeLine

private static void writeLine(java.io.BufferedWriter ostream,
                              java.lang.String message)
                       throws java.io.IOException
Method to send the a String to the outgoing Stream
Parameters:
ostream - The outgoing Stream
message - String which has to be send

reply

protected static void reply(java.io.BufferedWriter ostream,
                            java.lang.String command,
                            java.lang.String information)
                     throws java.io.IOException
Generate an reply answer for a given command.
Parameters:
ostream - The outgoing Stream
command - which has to be send
information - first parameter

send

protected static void send(java.io.BufferedWriter ostream,
                           java.lang.String command,
                           java.lang.String information)
                    throws java.io.IOException
Generate an answer for a given command.
Parameters:
ostream - The outgoing Stream
command - which has to be send
information - first parameter

send

protected static void send(java.io.BufferedWriter ostream,
                           java.lang.String command,
                           java.lang.String information1,
                           java.lang.String information2)
                    throws java.io.IOException
Generate an answer for a given command.
Parameters:
ostream - The outgoing Stream
command - which has to be send
information1 - first parameter
information2 - second parameter

send

protected static void send(java.io.BufferedWriter ostream,
                           java.lang.String command,
                           java.lang.String information1,
                           java.lang.String information2,
                           java.lang.String information3)
                    throws java.io.IOException
Generate an answer for a given command.
Parameters:
ostream - The outgoing Stream
command - which has to be send
information1 - first parameter
information2 - second parameter
information3 - third parameter

send

protected static void send(java.io.BufferedWriter ostream,
                           java.lang.String command,
                           java.lang.String information1,
                           java.lang.String information2,
                           java.lang.String information3,
                           java.lang.String information4)
                    throws java.io.IOException
Generate an answer for a given command.
Parameters:
ostream - The outgoing Stream
command - which has to be send
information1 - first parameter
information2 - second parameter
information3 - third parameter
information4 - fourth parameter

readCommand

protected java.util.Vector readCommand(ChatStreamTokenizer tokenizer,
                                       java.net.Socket sourceSocket)
                                throws TimeoutException,
                                       java.io.IOException
Parameters:
tokenizer - The tokenizer to use
sourceSocket - The socket to use
Throws:
TimeoutException,IOException - Fetch one command from the input. Used to simplify the usage of the ChatStreamTokenizer as it reads until a CHAR_MSG_EOL is receive

send

protected static void send(java.io.BufferedWriter ostream,
                           java.lang.String command,
                           java.lang.String information1,
                           java.lang.String information2,
                           java.lang.String information3,
                           java.lang.String information4,
                           java.lang.String information5)
                    throws java.io.IOException
Send a given command.
Parameters:
ostream - The outgoing Stream
command - which has to be send
information1 - first parameter
information2 - second parameter
information3 - s÷rd parameter