You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Parser.java 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  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. package com.dmdirc.parser.interfaces;
  23. import com.dmdirc.parser.common.IgnoreList;
  24. import com.dmdirc.parser.common.CallbackManager;
  25. import com.dmdirc.parser.common.QueuePriority;
  26. import java.util.Collection;
  27. /**
  28. * A parser connects to a back-end chat system and handles all communication
  29. * with it.
  30. *
  31. * @since 0.6.3m2
  32. * @author chris
  33. */
  34. public interface Parser extends Runnable {
  35. /**
  36. * Disconnect from server. This method will quit and automatically close the
  37. * socket without waiting for the server.
  38. *
  39. * @param message Reason for quitting.
  40. */
  41. void disconnect(String message);
  42. /**
  43. * Join a channel with no key.
  44. *
  45. * @param channel Name of channel to join
  46. */
  47. void joinChannel(String channel);
  48. /**
  49. * Joins a channel with the specified key.
  50. *
  51. * @param channel Name of channel to join
  52. * @param key The key required to join the channel
  53. */
  54. void joinChannel(String channel, String key);
  55. /**
  56. * Retrieves a channel information object for the specified channel.
  57. *
  58. * @param channel Name of the channel to retrieve an information object for
  59. * @return A corresponding channel info object
  60. */
  61. ChannelInfo getChannel(String channel);
  62. /**
  63. * Retrieves a collection of all known channels.
  64. *
  65. * @return A collection of known channels
  66. */
  67. Collection<? extends ChannelInfo> getChannels();
  68. /**
  69. * Set the IP address that this parser will bind to
  70. *
  71. * @param ip IP to bind to
  72. */
  73. void setBindIP(String ip);
  74. /**
  75. * Determines the maximimum length a message of the specified type may be.
  76. *
  77. * @param type Type of message (eg PRIVMSG)
  78. * @param target Target of message (eg channel name)
  79. * @return The maximum length of the message
  80. */
  81. int getMaxLength(String type, String target);
  82. /**
  83. * Determines the maximum length any message/raw command may be.
  84. *
  85. * @return The maximum length of a message
  86. */
  87. int getMaxLength();
  88. /**
  89. * Returns a {@link ClientInfo} object which represents the locally
  90. * connected client.
  91. *
  92. * @return An info object for the local client
  93. */
  94. LocalClientInfo getLocalClient();
  95. /**
  96. * Retrieves a {@link ClientInfo} object which corresponds to the specified
  97. * details. If the client wasn't previously known, it will be created.
  98. *
  99. * @param details The details of the client to look up
  100. * @return A corresponding client info object
  101. */
  102. ClientInfo getClient(String details);
  103. /**
  104. * Sends a raw message directly to the backend system. The message will
  105. * need to be of the appropriate format for whatever system is in use.
  106. *
  107. * @param message The message to be sent
  108. */
  109. void sendRawMessage(String message);
  110. /**
  111. * Sends a raw message directly to the backend system. The message will
  112. * need to be of the appropriate format for whatever system is in use.
  113. *
  114. * @param message The message to be sent
  115. * @param priority Priority of this line. (Priorities are advisory and not
  116. * guaranteed to be enforced.
  117. */
  118. void sendRawMessage(String message, QueuePriority priority);
  119. /**
  120. * Retrieves an object that can be used to convert between upper- and lower-
  121. * case strings in the relevant charset for the backend system.
  122. *
  123. * @return A string convertor for this parser
  124. */
  125. StringConverter getStringConverter();
  126. /**
  127. * Determines whether the specified channel name is valid or not for this
  128. * parser.
  129. *
  130. * @param name The name of the channel to be tested
  131. * @return True if the channel name is valid, false otherwise
  132. */
  133. boolean isValidChannelName(String name);
  134. /**
  135. * Retrieves the name of the server that this parser is connected to.
  136. *
  137. * @return This parser's server's name
  138. */
  139. String getServerName();
  140. /**
  141. * Retrieves the name of the network that this parser is connected to.
  142. *
  143. * @return This parser's network's name
  144. */
  145. String getNetworkName();
  146. /**
  147. * Retrieves a textual description of the software running on the server.
  148. *
  149. * @return This parser's server's software name
  150. */
  151. String getServerSoftware();
  152. /**
  153. * Retrieves the detected type of the software running on the server
  154. *
  155. * @return This parser's server's software type
  156. */
  157. String getServerSoftwareType();
  158. /**
  159. * Retrieves the maximum length for a topic that can be set by this parser.
  160. *
  161. * @return The maximum length (in bytes) of a topic
  162. */
  163. int getMaxTopicLength();
  164. /**
  165. * Retrieves an alphabetically-sorted list of boolean channel modes.
  166. * Boolean channel modes may only be set or unset, and do not take any
  167. * arguments.
  168. *
  169. * @return A string containing a list of channel mode characters
  170. */
  171. String getBooleanChannelModes();
  172. /**
  173. * Retrieves an alphabetically-sorted list of channel list modes.
  174. * List channel modes may be set multiple times with different arguments,
  175. * building up a "list" of values.
  176. *
  177. * @return A string containing a list of channel mode characters
  178. */
  179. String getListChannelModes();
  180. /**
  181. * Retrieves the maximum number of list modes of the specified type which
  182. * may be set on a channel. Returns 0 or -1 if the limit wasn't specified,
  183. * or couldn't be discovered, respectively.
  184. *
  185. * @param mode The list mode being requested
  186. * @return The maximimum number of that mode which can be set
  187. */
  188. int getMaxListModes(char mode);
  189. /**
  190. * Determines if the specified channel mode is settable by users.
  191. *
  192. * @param mode The mode to be tested
  193. * @return True if users may set the mode, false otherwise
  194. */
  195. boolean isUserSettable(final char mode);
  196. /**
  197. * Retrieves an alphabetically-sorted list of 'parameter' channel modes.
  198. * Parameter channel modes may only be set or unset, and require a
  199. * parameter to be specified when they are set (but not when unset).
  200. *
  201. * @return A string containing a list of channel mode characters
  202. */
  203. String getParameterChannelModes();
  204. /**
  205. * Retrieves an alphabetically-sorted list of 'double parameter' channel
  206. * modes. Double parameter channel modes may only be set or unset, and
  207. * require a parameter to be specified both when they are set and when
  208. * they are unset.
  209. *
  210. * @return A string containing a list of channel mode characters
  211. */
  212. String getDoubleParameterChannelModes();
  213. /**
  214. * Retrieves a list of user modes in no particular order.
  215. *
  216. * @return A string containing a list of user mode characters
  217. */
  218. String getUserModes();
  219. /**
  220. * Retrieves a list of channel user modes, in descending priority order.
  221. *
  222. * @return A string containing a list of channel user mode characters
  223. */
  224. String getChannelUserModes();
  225. /**
  226. * Retrieves the object which is responsible for managing callbacks for
  227. * this parser.
  228. *
  229. * @return This parser's callback manager
  230. */
  231. CallbackManager<? extends Parser> getCallbackManager();
  232. /**
  233. * Retrieves the latency between the parser and the server in milliseconds.
  234. *
  235. * @return The current latency, in milliseconds
  236. */
  237. long getServerLatency();
  238. /**
  239. * Sends a CTCP of the specified type to the specified target.
  240. *
  241. * @param target The destination of the CTCP message
  242. * @param type The type of CTCP to send
  243. * @param message The content of the CTCP message
  244. */
  245. void sendCTCP(String target, String type, String message);
  246. /**
  247. * Sends a CTCP reply of the specified type to the specified target.
  248. *
  249. * @param target The destination of the CTCP reply
  250. * @param type The type of CTCP to reply to
  251. * @param message The content of the CTCP reply
  252. */
  253. void sendCTCPReply(String target, String type, String message);
  254. /**
  255. * Sends a message to the specified target.
  256. *
  257. * @param target The target to send the message to
  258. * @param message The message to be sent
  259. */
  260. void sendMessage(String target, String message);
  261. /**
  262. * Sends a notice to the specified target.
  263. *
  264. * @param target The target to send the notice to
  265. * @param message The message to be sent
  266. */
  267. void sendNotice(String target, String message);
  268. /**
  269. * Sends an action to the specified target.
  270. *
  271. * @param target The target to send the action to
  272. * @param message The message to be sent
  273. */
  274. void sendAction(String target, String message);
  275. /**
  276. * Retrieves the last line/communication received from the server, for use
  277. * in debugging purposes.
  278. *
  279. * @return The last line received
  280. */
  281. String getLastLine();
  282. /**
  283. * Sets the ignore list which should be used by this parser.
  284. *
  285. * @param ignoreList The new ignore list to be used by the parser
  286. */
  287. void setIgnoreList(IgnoreList ignoreList);
  288. /**
  289. * Retrieves the ignore list which is currently in use by this parser.
  290. *
  291. * @return This parser's ignore list
  292. */
  293. IgnoreList getIgnoreList();
  294. /**
  295. * Parses the specified hostmask into an array containing a nickname,
  296. * username and hostname, in that order.
  297. *
  298. * @param hostmask The hostmask to be parsed
  299. * @return An array containing the nickname, username and hostname
  300. */
  301. String[] parseHostmask(String hostmask);
  302. /**
  303. * Retrieves the local port number that this parser is using to communicate
  304. * with the service.
  305. *
  306. * @return This parser's local port number
  307. */
  308. int getLocalPort();
  309. /**
  310. * Retrieves the amount of time elapsed since the last ping request was
  311. * sent (or until the reply was received).
  312. *
  313. * @return The current ping time to the server
  314. */
  315. long getPingTime();
  316. /**
  317. * Sets the interval of the ping timer, in milliseconds. If the parser is
  318. * waiting for a ping, it should fire a PingFailed event every time this
  319. * interval is passed (or disconnect if no listeners are registered).
  320. *
  321. * @param newValue The new value for the ping timer interval
  322. */
  323. void setPingTimerInterval(long newValue);
  324. /**
  325. * Retrieves the length of the ping timer interval for this parser.
  326. *
  327. * @return This parser's ping timer interval
  328. */
  329. long getPingTimerInterval();
  330. /**
  331. * Sets how many ping timer intervals should pass before the parser sends
  332. * a ping. That is, the time between pings on an idle connection will be
  333. * <code>(ping timer interval) * (ping timer fraction)</code> millisecs.
  334. *
  335. * For example, setting the interval to 10,000 (10 seconds) and the fraction
  336. * to 6 means that pings will be sent once every minute and if a reply is
  337. * not received within 10 seconds, a ping failed event will be raised.
  338. *
  339. * @param newValue The new value of the ping timer fraction
  340. */
  341. void setPingTimerFraction(int newValue);
  342. /**
  343. * Retrieves the number of ping timer intervals that must pass before this
  344. * parser sends a ping request.
  345. *
  346. * @return This parser's ping timer fraction
  347. */
  348. int getPingTimerFraction();
  349. }