File Source: IRCProcessor.java
/*
P/P * Method: com.dmdirc.parser.irc.IRCProcessor__static_init
*/
1 /*
2 * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
22
23 package com.dmdirc.parser.irc;
24
25 import com.dmdirc.parser.irc.callbacks.CallbackManager;
26
27 /**
28 * IRCProcessor.
29 * Superclass for all IRCProcessor types.
30 *
31 * @author Shane Mc Cormack
32 */
33 public abstract class IRCProcessor {
34 /** Reference to the IRCParser that owns this IRCProcessor. */
35 protected IRCParser myParser;
36
37 /** Reference to the Processing in charge of this IRCProcessor. */
38 protected ProcessingManager myManager;
39
40 // Some functions from the main parser are useful, and having to use myParser.functionName
41 // is annoying, so we also implement them here (calling them again using myParser)
42 /**
43 * Create a new instance of the IRCProcessor Object.
44 *
45 * @param parser IRCParser That owns this IRCProcessor
46 * @param manager ProcessingManager that is in charge of this IRCProcessor
47 */
/*
P/P * Method: void com.dmdirc.parser.irc.IRCProcessor(IRCParser, ProcessingManager)
*
* Postconditions:
* this.myManager == manager
* init'ed(this.myManager)
* this.myParser == parser
* init'ed(this.myParser)
*/
48 protected IRCProcessor(final IRCParser parser, final ProcessingManager manager) {
49 this.myParser = parser;
50 this.myManager = manager;
51 }
52
53 /**
54 * Callback to all objects implementing the IErrorInfo Interface.
55 *
56 * @see com.dmdirc.parser.irc.callbacks.interfaces.IErrorInfo
57 * @param errorInfo ParserError object representing the error.
58 * @return true if a method was called, false otherwise
59 */
60 protected final boolean callErrorInfo(final ParserError errorInfo) {
/*
P/P * Method: bool callErrorInfo(ParserError)
*
* Preconditions:
* this.myParser != null
* this.myParser.myCallbackManager != null
* this.myParser.myCallbackManager.callbackHash != null
*
* Postconditions:
* init'ed(return_value)
*/
61 return myParser.callErrorInfo(errorInfo);
62 }
63
64 /**
65 * Callback to all objects implementing the DebugInfo Callback.
66 *
67 * @see com.dmdirc.parser.irc.callbacks.interfaces.IDebugInfo
68 * @param level Debugging Level (DEBUG_INFO, ndSocket etc)
69 * @param data Debugging Information
70 * @param args Formatting String Options
71 * @return true if a method was called, false otherwise
72 */
73 protected final boolean callDebugInfo(final int level, final String data, final Object... args) {
/*
P/P * Method: bool callDebugInfo(int, String, Object[])
*
* Preconditions:
* this.myParser != null
* this.myParser.myCallbackManager != null
* this.myParser.myCallbackManager.callbackHash != null
*
* Postconditions:
* init'ed(return_value)
*/
74 return myParser.callDebugInfo(level, String.format(data, args));
75 }
76
77 /**
78 * Callback to all objects implementing the DebugInfo Callback.
79 *
80 * @see com.dmdirc.parser.irc.callbacks.interfaces.IDebugInfo
81 * @param level Debugging Level (DEBUG_INFO, ndSocket etc)
82 * @param data Debugging Information
83 * @return true if a method was called, false otherwise
84 */
85 protected final boolean callDebugInfo(final int level, final String data) {
/*
P/P * Method: bool callDebugInfo(int, String)
*
* Preconditions:
* this.myParser != null
* this.myParser.myCallbackManager != null
* this.myParser.myCallbackManager.callbackHash != null
*
* Postconditions:
* init'ed(return_value)
*/
86 return myParser.callDebugInfo(level, data);
87 }
88
89 /**
90 * Check if a channel name is valid .
91 *
92 * @param sChannelName Channel name to test
93 * @return true if name is valid on the current connection, false otherwise. (Always false before noMOTD/MOTDEnd)
94 */
95 protected final boolean isValidChannelName(final String sChannelName) {
/*
P/P * Method: bool isValidChannelName(String)
*
* Preconditions:
* this.myParser != null
* (soft) init'ed(this.myParser.stringConverter)
* (soft) this.myParser.cMyself != null
* (soft) init'ed(this.myParser.cMyself.bIsFake)
* (soft) init'ed(this.myParser.cMyself.sNickname)
* (soft) this.myParser.hChanPrefix != null
* (soft) this.myParser.hChannelList != null
* (soft) init'ed(this.myParser.sThinkNickname)
*
* Postconditions:
* init'ed(return_value)
* init'ed(this.myParser.stringConverter)
* new IRCStringConverter(getIRCStringConverter#1) num objects == 0
* new char[](IRCStringConverter#1) num objects == 0
* new char[](IRCStringConverter#2) num objects == 0
* init'ed(new IRCStringConverter(getIRCStringConverter#1).limit)
* init'ed(new IRCStringConverter(getIRCStringConverter#1).lowercase)
* init'ed(new IRCStringConverter(getIRCStringConverter#1).uppercase)
* init'ed(new char[](IRCStringConverter#1).length)
* possibly_updated(new char[](IRCStringConverter#1)[...])
* ...
*/
96 return myParser.isValidChannelName(sChannelName);
97 }
98
99 /**
100 * Get the ClientInfo object for a person.
101 *
102 * @param sWho Who can be any valid identifier for a client as long as it contains a nickname (?:)nick(?!ident)(?@host)
103 * @return ClientInfo Object for the client, or null
104 */
105 protected final ClientInfo getClientInfo(final String sWho) {
/*
P/P * Method: ClientInfo getClientInfo(String)
*
* Preconditions:
* init'ed(this.myParser.stringConverter)
* sWho != null
* this.myParser != null
* this.myParser.hClientList != null
* (soft) this.myParser.stringConverter.lowercase != null
* (soft) init'ed(this.myParser.stringConverter.lowercase[...])
*
* Postconditions:
* init'ed(return_value)
* this.myParser.stringConverter == One-of{old this.myParser.stringConverter, &new IRCStringConverter(getIRCStringConverter#1)}
* this.myParser.stringConverter != null
* new IRCStringConverter(getIRCStringConverter#1) num objects <= 1
* new char[](IRCStringConverter#1) num objects == new IRCStringConverter(getIRCStringConverter#1) num objects
* new char[](IRCStringConverter#2) num objects == new IRCStringConverter(getIRCStringConverter#1) num objects
* new IRCStringConverter(getIRCStringConverter#1).limit == 4
* new IRCStringConverter(getIRCStringConverter#1).lowercase == &new char[](IRCStringConverter#1)
* new IRCStringConverter(getIRCStringConverter#1).uppercase == &new char[](IRCStringConverter#2)
* new char[](IRCStringConverter#1).length == 127
* ...
*/
106 return myParser.getClientInfo(sWho);
107 }
108
109 /**
110 * Get the ChannelInfo object for a channel.
111 *
112 * @param sWhat This is the name of the channel.
113 * @return ChannelInfo Object for the channel, or null
114 */
115 protected final ChannelInfo getChannelInfo(final String sWhat) {
/*
P/P * Method: ChannelInfo getChannelInfo(String)
*
* Preconditions:
* init'ed(this.myParser.stringConverter)
* sWhat != null
* this.myParser != null
* this.myParser.hChannelList != null
* (soft) this.myParser.stringConverter.lowercase != null
* (soft) init'ed(this.myParser.stringConverter.lowercase[...])
*
* Postconditions:
* init'ed(return_value)
* this.myParser.stringConverter == One-of{old this.myParser.stringConverter, &new IRCStringConverter(getIRCStringConverter#1)}
* this.myParser.stringConverter != null
* new IRCStringConverter(getIRCStringConverter#1) num objects <= 1
* new char[](IRCStringConverter#1) num objects == new IRCStringConverter(getIRCStringConverter#1) num objects
* new char[](IRCStringConverter#2) num objects == new IRCStringConverter(getIRCStringConverter#1) num objects
* new IRCStringConverter(getIRCStringConverter#1).limit == 4
* new IRCStringConverter(getIRCStringConverter#1).lowercase == &new char[](IRCStringConverter#1)
* new IRCStringConverter(getIRCStringConverter#1).uppercase == &new char[](IRCStringConverter#2)
* new char[](IRCStringConverter#1).length == 127
* ...
*/
116 return myParser.getChannelInfo(sWhat);
117 }
118
119 /**
120 * Get a reference to the CallbackManager.
121 *
122 * @return Reference to the CallbackManager
123 */
124 protected final CallbackManager getCallbackManager() {
/*
P/P * Method: CallbackManager getCallbackManager()
*
* Preconditions:
* this.myParser != null
* init'ed(this.myParser.myCallbackManager)
*
* Postconditions:
* return_value == this.myParser.myCallbackManager
* init'ed(return_value)
*/
125 return myParser.getCallbackManager();
126 }
127
128 /**
129 * Send a line to the server and add proper line ending.
130 *
131 * @param line Line to send (\r\n termination is added automatically)
132 */
133 protected final void sendString(final String line) {
/*
P/P * Method: void sendString(String)
*
* Preconditions:
* this.myParser != null
* init'ed(this.myParser.out)
* (soft) init'ed(this.myParser.stringConverter)
* (soft) this.myParser.cMyself != null
* (soft) init'ed(this.myParser.currentSocketState)
* (soft) this.myParser.hChanModesOther != null
* (soft) this.myParser.hChannelList != null
* (soft) this.myParser.myCallbackManager != null
* (soft) this.myParser.myCallbackManager.callbackHash != null
*
* Postconditions:
* init'ed(java.lang.String:substring(...)._tainted)
* possibly_updated(this.myParser.cMyself.myAwayReason)
* this.myParser.stringConverter == One-of{old this.myParser.stringConverter, &new IRCStringConverter(getIRCStringConverter#1)}
* init'ed(this.myParser.stringConverter)
* new IRCStringConverter(getIRCStringConverter#1) num objects <= 1
* new char[](IRCStringConverter#1) num objects == new IRCStringConverter(getIRCStringConverter#1) num objects
* new char[](IRCStringConverter#2) num objects == new IRCStringConverter(getIRCStringConverter#1) num objects
* init'ed(new IRCStringConverter(getIRCStringConverter#1).limit)
* init'ed(new IRCStringConverter(getIRCStringConverter#1).lowercase)
* init'ed(new IRCStringConverter(getIRCStringConverter#1).uppercase)
* ...
*/
134 myParser.sendString(line);
135 }
136
137 /**
138 * Process a Line.
139 *
140 * @param sParam Type of line to process ("005", "PRIVMSG" etc)
141 * @param token IRCTokenised line to process
142 */
143 public abstract void process(final String sParam, final String[] token);
144
145 /**
146 * What does this IRCProcessor handle.
147 *
148 * @return String[] with the names of the tokens we handle.
149 */
150 public abstract String[] handles();
151
152 /**
153 * Get the name for this Processor.
154 * @return the name of this processor
155 */
156 public final String getName() {
/*
P/P * Method: String getName()
*
* Presumptions:
* java.lang.Class:getName(...)@162 != null
* java.lang.Object:getClass(...)@157 != null
* java.lang.Object:getClass(...)@162 != null
* java.lang.Package:getName(...)@160 != null
* java.lang.String:length(...)@160 <= 232-2
*
* Postconditions:
* java.lang.String:substring(...)._tainted == 0
* return_value == &java.lang.String:substring(...)
*
* Test Vectors:
* java.lang.Class:getPackage(...)@157: Addr_Set{null}, Inverse{null}
*/
157 final Package thisPackage = this.getClass().getPackage();
158 int packageLength = 0;
159 if (thisPackage != null) {
160 packageLength = thisPackage.getName().length() + 1;
161 }
162 return this.getClass().getName().substring(packageLength);
163 }
164
165 /**
166 * Get the name for this Processor in lowercase.
167 * @return lower case name of this processor
168 */
169 public final String getLowerName() {
/*
P/P * Method: String getLowerName()
*
* Postconditions:
* return_value != null
*/
170 return this.getName().toLowerCase();
171 }
172
173 /**
174 * Get the name for this Processor.
175 * @return the name of this processor
176 */
/*
P/P * Method: String toString()
*
* Postconditions:
* java.lang.String:substring(...)._tainted == 0
* return_value == &java.lang.String:substring(...)
*/
177 public final String toString() { return this.getName(); }
178
179 }
SofCheck Inspector Build Version : 2.17854
| IRCProcessor.java |
2009-Jun-25 01:54:24 |
| IRCProcessor.class |
2009-Sep-02 17:04:12 |