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.

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