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 13KB

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