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

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