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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  1. /*
  2. * Copyright (c) 2006-2014 DMDirc Developers
  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.CallbackManager;
  24. import com.dmdirc.parser.common.ChannelJoinRequest;
  25. import com.dmdirc.parser.common.CompositionState;
  26. import com.dmdirc.parser.common.IgnoreList;
  27. import com.dmdirc.parser.common.QueuePriority;
  28. import java.net.URI;
  29. import java.util.Collection;
  30. import java.util.List;
  31. /**
  32. * A parser connects to a back-end chat system and handles all communication
  33. * with it.
  34. *
  35. * @since 0.6.3m2
  36. * @author chris
  37. */
  38. public interface Parser {
  39. /**
  40. * Connect to server.
  41. */
  42. void connect();
  43. /**
  44. * Disconnect from server. This method will quit and automatically close the
  45. * socket without waiting for the server.
  46. *
  47. * @param message Reason for quitting.
  48. */
  49. void disconnect(String message);
  50. /**
  51. *
  52. * Disconnect from server. This method will wait for the server to
  53. * close the socket.
  54. *
  55. * @param message Reason for quitting.
  56. */
  57. void quit(String message);
  58. /**
  59. * Join a channel with no key.
  60. *
  61. * @param channel Name of channel to join
  62. */
  63. void joinChannel(String channel);
  64. /**
  65. * Joins a channel with the specified key.
  66. *
  67. * @param channel Name of channel to join
  68. * @param key The key required to join the channel
  69. */
  70. void joinChannel(String channel, String key);
  71. /**
  72. * Joins the specified channels.
  73. *
  74. * @since 0.6.4
  75. * @param channels The channels to be joined
  76. */
  77. void joinChannels(ChannelJoinRequest ... channels);
  78. /**
  79. * Retrieves a channel information object for the specified channel.
  80. *
  81. * @param channel Name of the channel to retrieve an information object for
  82. * @return A corresponding channel info object
  83. */
  84. ChannelInfo getChannel(String channel);
  85. /**
  86. * Retrieves a collection of all known channels.
  87. *
  88. * @return A collection of known channels
  89. */
  90. Collection<? extends ChannelInfo> getChannels();
  91. /**
  92. * Get the IP address that this parser will bind to.
  93. *
  94. * @return IP that this parser is bound to ("" for default IP)
  95. */
  96. String getBindIP();
  97. /**
  98. * Set the IP address that this parser will bind to.
  99. *
  100. * @param ip IP to bind to
  101. */
  102. void setBindIP(String ip);
  103. /**
  104. * Get the IPv6 address that this parser will bind to.
  105. *
  106. * @return IPv6 that this parser is bound to ("" for default IP)
  107. */
  108. String getBindIPv6();
  109. /**
  110. * Set the IPv6 address that this parser will bind to.
  111. *
  112. * @param ip IPv6 IP to bind to
  113. */
  114. void setBindIPv6(String ip);
  115. /**
  116. * Gets the proxy URI that this parser will use.
  117. *
  118. * @return A URI representing the proxy this parser is configured to use,
  119. * or <code>null</code> if no proxy is set.
  120. * @since 0.6.7
  121. * @see #setProxy(java.net.URI)
  122. */
  123. URI getProxy();
  124. /**
  125. * Configures the proxy that this parser will use. The URI should consist
  126. * of the following components:
  127. * <ul>
  128. * <li>scheme: the proxy type (socks, http, etc)</li>
  129. * <li>user-info: optionally, username and password separated by a ':'</li>
  130. * <li>host: the hostname or IP of the proxy server</li>
  131. * <li>port: the port to use</li>
  132. * </ul>
  133. * e.g.: <code>socks://user:pass@dmdirc.com:123/</code>.
  134. *
  135. * @param proxy A URI representing the proxy this parser should use,
  136. * or <code>null</code> to connect directly.
  137. * @since 0.6.7
  138. * @see #getProxy()
  139. */
  140. void setProxy(URI proxy);
  141. /**
  142. * Determines the maximimum length a message of the specified type may be.
  143. *
  144. * @param type Type of message (eg PRIVMSG)
  145. * @param target Target of message (eg channel name)
  146. * @return The maximum length of the message
  147. */
  148. int getMaxLength(String type, String target);
  149. /**
  150. * Determines the maximum length any message/raw command may be.
  151. *
  152. * @return The maximum length of a message
  153. */
  154. int getMaxLength();
  155. /**
  156. * Returns a {@link ClientInfo} object which represents the locally
  157. * connected client.
  158. *
  159. * @return An info object for the local client
  160. */
  161. LocalClientInfo getLocalClient();
  162. /**
  163. * Retrieves a {@link ClientInfo} object which corresponds to the specified
  164. * details. If the client wasn't previously known, it will be created.
  165. *
  166. * @param details The details of the client to look up
  167. * @return A corresponding client info object
  168. */
  169. ClientInfo getClient(String details);
  170. /**
  171. * Sends a raw message directly to the backend system. The message will
  172. * need to be of the appropriate format for whatever system is in use.
  173. *
  174. * @param message The message to be sent
  175. */
  176. void sendRawMessage(String message);
  177. /**
  178. * Sends a raw message directly to the backend system. The message will
  179. * need to be of the appropriate format for whatever system is in use.
  180. *
  181. * @param message The message to be sent
  182. * @param priority Priority of this line. (Priorities are advisory and not
  183. * guaranteed to be enforced.
  184. */
  185. void sendRawMessage(String message, QueuePriority priority);
  186. /**
  187. * Retrieves an object that can be used to convert between upper- and lower-
  188. * case strings in the relevant charset for the backend system.
  189. *
  190. * @return A string convertor for this parser
  191. */
  192. StringConverter getStringConverter();
  193. /**
  194. * Determines whether the specified channel name is valid or not for this
  195. * parser.
  196. *
  197. * @param name The name of the channel to be tested
  198. * @return True if the channel name is valid, false otherwise
  199. */
  200. boolean isValidChannelName(String name);
  201. /**
  202. * Get a URI that shows where this parser is connected to.
  203. *
  204. * @return URI that shows where this parser is connected to.
  205. * @since 0.6.3
  206. */
  207. URI getURI();
  208. /**
  209. * Compare the given URI to the URI we are currently using to see if they
  210. * would both result in the parser connecting to the same place, even if the
  211. * URIs do not match exactly.
  212. *
  213. * @param uri URI to compare with the Parsers own URI.
  214. * @return True if the Given URI is the "same" as the one we are using.
  215. * @since 0.6.3
  216. */
  217. boolean compareURI(final URI uri);
  218. /**
  219. * Extracts any channels present in the specified URI.
  220. *
  221. * @param uri The URI to extract channels from
  222. * @return A list of channel join requests extracted from the specified URI
  223. * @since 0.6.4
  224. */
  225. Collection<? extends ChannelJoinRequest> extractChannels(final URI uri);
  226. /**
  227. * Retrieves the name of the server that this parser is, or has been,
  228. * connected to.
  229. *
  230. * @return This parser's server's name
  231. */
  232. String getServerName();
  233. /**
  234. * Retrieves the name of the network that this parser is connected to.
  235. *
  236. * @return This parser's network's name
  237. */
  238. String getNetworkName();
  239. /**
  240. * Retrieves a textual description of the software running on the server.
  241. *
  242. * @return This parser's server's software name
  243. */
  244. String getServerSoftware();
  245. /**
  246. * Retrieves the detected type of the software running on the server.
  247. *
  248. * @return This parser's server's software type
  249. */
  250. String getServerSoftwareType();
  251. /**
  252. * Get the list of lines that lines that help describe the server.
  253. *
  254. * @return List of identification lines for the server.
  255. *
  256. * @since 0.6.4,
  257. */
  258. List<String> getServerInformationLines();
  259. /**
  260. * Retrieves the maximum length for a topic that can be set by this parser.
  261. *
  262. * @return The maximum length (in bytes) of a topic
  263. */
  264. int getMaxTopicLength();
  265. /**
  266. * Retrieves a list of boolean channel modes.
  267. * Boolean channel modes may only be set or unset, and do not take any
  268. * arguments.
  269. *
  270. * @return A string containing a list of channel mode characters
  271. */
  272. String getBooleanChannelModes();
  273. /**
  274. * Retrieves an alphabetically-sorted list of channel list modes.
  275. * List channel modes may be set multiple times with different arguments,
  276. * building up a "list" of values.
  277. *
  278. * @return A string containing a list of channel mode characters
  279. */
  280. String getListChannelModes();
  281. /**
  282. * Retrieves the maximum number of list modes of the specified type which
  283. * may be set on a channel. Returns 0 or -1 if the limit wasn't specified,
  284. * or couldn't be discovered, respectively.
  285. *
  286. * @param mode The list mode being requested
  287. * @return The maximimum number of that mode which can be set
  288. */
  289. int getMaxListModes(char mode);
  290. /**
  291. * Determines if the specified channel mode is settable by users.
  292. *
  293. * @param mode The mode to be tested
  294. * @return True if users may set the mode, false otherwise
  295. */
  296. boolean isUserSettable(final char mode);
  297. /**
  298. * Retrieves an alphabetically-sorted list of 'parameter' channel modes.
  299. * Parameter channel modes may only be set or unset, and require a
  300. * parameter to be specified when they are set (but not when unset).
  301. *
  302. * @return A string containing a list of channel mode characters
  303. */
  304. String getParameterChannelModes();
  305. /**
  306. * Retrieves an alphabetically-sorted list of 'double parameter' channel
  307. * modes. Double parameter channel modes may only be set or unset, and
  308. * require a parameter to be specified both when they are set and when
  309. * they are unset.
  310. *
  311. * @return A string containing a list of channel mode characters
  312. */
  313. String getDoubleParameterChannelModes();
  314. /**
  315. * Retrieves a list of user modes in no particular order.
  316. *
  317. * @return A string containing a list of user mode characters
  318. */
  319. String getUserModes();
  320. /**
  321. * Retrieves a list of channel user mode prefixes (e.g. '@', '+'), in ascending priority order.
  322. *
  323. * @return A string containing a list of channel user mode characters
  324. */
  325. String getChannelUserModes();
  326. /**
  327. * Retrieves a list of channel prefixes.
  328. *
  329. * @return A list of known channel prefixes
  330. * @since 0.6.3
  331. */
  332. String getChannelPrefixes();
  333. /**
  334. * Retrieves the object which is responsible for managing callbacks for
  335. * this parser.
  336. *
  337. * @return This parser's callback manager
  338. */
  339. CallbackManager getCallbackManager();
  340. /**
  341. * Retrieves the latency between the parser and the server in milliseconds.
  342. *
  343. * @return The current latency, in milliseconds
  344. */
  345. long getServerLatency();
  346. /**
  347. * Sends a CTCP of the specified type to the specified target.
  348. *
  349. * @param target The destination of the CTCP message
  350. * @param type The type of CTCP to send
  351. * @param message The content of the CTCP message
  352. */
  353. void sendCTCP(String target, String type, String message);
  354. /**
  355. * Sends a CTCP reply of the specified type to the specified target.
  356. *
  357. * @param target The destination of the CTCP reply
  358. * @param type The type of CTCP to reply to
  359. * @param message The content of the CTCP reply
  360. */
  361. void sendCTCPReply(String target, String type, String message);
  362. /**
  363. * Sends a message to the specified target.
  364. *
  365. * @param target The target to send the message to
  366. * @param message The message to be sent
  367. */
  368. void sendMessage(String target, String message);
  369. /**
  370. * Sends a notice to the specified target.
  371. *
  372. * @param target The target to send the notice to
  373. * @param message The message to be sent
  374. */
  375. void sendNotice(String target, String message);
  376. /**
  377. * Sends an action to the specified target.
  378. *
  379. * @param target The target to send the action to
  380. * @param message The message to be sent
  381. */
  382. void sendAction(String target, String message);
  383. /**
  384. * Sends an invite to the specified user to join the specified channel.
  385. *
  386. * @param channel The channel the user should be invited to
  387. * @param user The user to be invited to the channel
  388. * @since 0.6.4
  389. */
  390. void sendInvite(String channel, String user);
  391. /**
  392. * Retrieves the last line/communication received from the server, for use
  393. * in debugging purposes.
  394. *
  395. * @return The last line received
  396. */
  397. String getLastLine();
  398. /**
  399. * Sets the ignore list which should be used by this parser.
  400. *
  401. * @param ignoreList The new ignore list to be used by the parser
  402. */
  403. void setIgnoreList(IgnoreList ignoreList);
  404. /**
  405. * Retrieves the ignore list which is currently in use by this parser.
  406. *
  407. * @return This parser's ignore list
  408. */
  409. IgnoreList getIgnoreList();
  410. /**
  411. * Parses the specified hostmask into an array containing a nickname,
  412. * username and hostname, in that order.
  413. *
  414. * @param hostmask The hostmask to be parsed
  415. * @return An array containing the nickname, username and hostname
  416. */
  417. String[] parseHostmask(String hostmask);
  418. /**
  419. * Retrieves the local port number that this parser is using to communicate
  420. * with the service.
  421. *
  422. * @return This parser's local port number
  423. */
  424. int getLocalPort();
  425. /**
  426. * Retrieves the amount of time elapsed since the last ping request was
  427. * sent (or until the reply was received).
  428. *
  429. * @return The current ping time to the server
  430. */
  431. long getPingTime();
  432. /**
  433. * Sets the interval of the ping timer, in milliseconds. If the parser is
  434. * waiting for a ping, it should fire a PingFailed event every time this
  435. * interval is passed (or disconnect if no listeners are registered).
  436. *
  437. * @param newValue The new value for the ping timer interval
  438. */
  439. void setPingTimerInterval(long newValue);
  440. /**
  441. * Retrieves the length of the ping timer interval for this parser.
  442. *
  443. * @return This parser's ping timer interval
  444. */
  445. long getPingTimerInterval();
  446. /**
  447. * Sets how many ping timer intervals should pass before the parser sends
  448. * a ping. That is, the time between pings on an idle connection will be
  449. * <code>(ping timer interval) * (ping timer fraction)</code> millisecs.
  450. *
  451. * For example, setting the interval to 10,000 (10 seconds) and the fraction
  452. * to 6 means that pings will be sent once every minute and if a reply is
  453. * not received within 10 seconds, a ping failed event will be raised.
  454. *
  455. * @param newValue The new value of the ping timer fraction
  456. */
  457. void setPingTimerFraction(int newValue);
  458. /**
  459. * Retrieves the number of ping timer intervals that must pass before this
  460. * parser sends a ping request.
  461. *
  462. * @return This parser's ping timer fraction
  463. */
  464. int getPingTimerFraction();
  465. /**
  466. * Sets the local user's composition state for a conversation with the
  467. * specified host.
  468. *
  469. * @param host The host of the user who the conversation is with
  470. * @param state The new composition state
  471. */
  472. void setCompositionState(String host, CompositionState state);
  473. /**
  474. * Requests a list of all known groups from the server.
  475. *
  476. * @param searchTerms The search terms to pass to the server, or an empty
  477. * string for no terms.
  478. */
  479. void requestGroupList(String searchTerms);
  480. }