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

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