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.

Connection.java 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  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.interfaces;
  23. import com.dmdirc.Channel;
  24. import com.dmdirc.Invite;
  25. import com.dmdirc.Query;
  26. import com.dmdirc.ServerState;
  27. import com.dmdirc.ServerStatus;
  28. import com.dmdirc.interfaces.config.ConfigProvider;
  29. import com.dmdirc.parser.common.ChannelJoinRequest;
  30. import com.dmdirc.parser.common.IgnoreList;
  31. import com.dmdirc.parser.interfaces.ChannelInfo;
  32. import com.dmdirc.parser.interfaces.Parser;
  33. import com.dmdirc.tls.CertificateProblemListener;
  34. import java.net.URI;
  35. import java.util.Collection;
  36. import java.util.Date;
  37. import java.util.List;
  38. /**
  39. * Represents an abstract connection to a remote chat system.
  40. */
  41. public interface Connection {
  42. /**
  43. * Attempts to accept the specified invites, and join the corresponding
  44. * channels.
  45. *
  46. * @param invites The invites to process
  47. * @since 0.6.4
  48. */
  49. void acceptInvites(final Invite... invites);
  50. /**
  51. * Attempts to accept all active invites for this server, and join the
  52. * corresponding channels.
  53. *
  54. * @since 0.6.4
  55. */
  56. void acceptInvites();
  57. /**
  58. * Adds an away state lisener to this server.
  59. *
  60. * @param listener The listener to be added
  61. */
  62. void addAwayStateListener(final AwayStateListener listener);
  63. /**
  64. * Adds a new certificate problem listener to this server. If there is
  65. * currently an on-going problem with a certificate, the listener will
  66. * be called immediately before this method returns.
  67. *
  68. * @param listener The listener to be added
  69. */
  70. void addCertificateProblemListener(final CertificateProblemListener listener);
  71. /**
  72. * Adds a specific channel and window to this server.
  73. *
  74. * @param chan channel to add
  75. * @return The channel that was added (may be null if closing)
  76. */
  77. Channel addChannel(final ChannelInfo chan);
  78. /**
  79. * Adds a specific channel and window to this server.
  80. *
  81. * @param chan channel to add
  82. * @param focus Whether or not to focus the channel
  83. * @return The channel that was added (may be null if closing)
  84. */
  85. Channel addChannel(final ChannelInfo chan, final boolean focus);
  86. /**
  87. * Adds an invite to this server, and fires the appropriate listeners.
  88. *
  89. * @param invite The invite to be added
  90. */
  91. void addInvite(final Invite invite);
  92. /**
  93. * Adds an invite listener to this server.
  94. *
  95. * @param listener The listener to be added
  96. */
  97. void addInviteListener(final InviteListener listener);
  98. /**
  99. * Passes the arguments to all frames for this server.
  100. *
  101. * @param messageType The type of message to send
  102. * @param date The date at which the event occurred
  103. * @param args The arguments of the message
  104. */
  105. void addLineToAll(final String messageType, final Date date, final Object... args);
  106. /**
  107. * Adds a raw window to this server.
  108. */
  109. void addRaw();
  110. /**
  111. * Compare the given URI to the URI we are currently using to see if they
  112. * would both result in the server connecting to the same place, even if the
  113. * URIs do not match exactly.
  114. *
  115. * @param uri URI to compare with the Servers own URI.
  116. * @return True if the Given URI is the "same" as the one we are using.
  117. * @since 0.6.3
  118. */
  119. boolean compareURI(final URI uri);
  120. /**
  121. * Connects to a new server with the previously supplied address and profile.
  122. *
  123. * @since 0.6.3m2
  124. */
  125. void connect();
  126. /**
  127. * Connects to a new server with the specified details.
  128. *
  129. * @param address The address of the server to connect to
  130. * @param profile The profile to use
  131. * @since 0.6.3
  132. */
  133. void connect(final URI address, final ConfigProvider profile);
  134. /**
  135. * Removes a specific channel and window from this server.
  136. *
  137. * @param chan channel to remove
  138. */
  139. void delChannel(final String chan);
  140. /**
  141. * Deletes a query from this server.
  142. *
  143. * @param query The query that should be removed.
  144. */
  145. void delQuery(final Query query);
  146. /**
  147. * Removes our reference to the raw object (presumably after it has been
  148. * closed).
  149. */
  150. void delRaw();
  151. /**
  152. * Disconnects from the server with the default quit message.
  153. */
  154. void disconnect();
  155. /**
  156. * Disconnects from the server.
  157. *
  158. * @param reason disconnect reason
  159. */
  160. void disconnect(final String reason);
  161. /**
  162. * Retrieves the address of this server.
  163. *
  164. * @return This sever's address
  165. */
  166. String getAddress();
  167. /**
  168. * Gets the current away message.
  169. *
  170. * @return Null if the client isn't away, or a textual away message if it is
  171. */
  172. String getAwayMessage();
  173. /**
  174. * Retrieves the specified channel belonging to this server.
  175. *
  176. * @param channel The channel to be retrieved
  177. * @return The appropriate channel object
  178. */
  179. Channel getChannel(final String channel);
  180. /**
  181. * Retrieves the possible channel prefixes in use on this server.
  182. *
  183. * @return This server's possible channel prefixes
  184. */
  185. String getChannelPrefixes();
  186. /**
  187. * Retrieves a list of channel names belonging to this server.
  188. *
  189. * @return list of channel names belonging to this server
  190. */
  191. List<String> getChannels();
  192. /**
  193. * Retrieves this server's ignore list.
  194. *
  195. * @return This server's ignore list
  196. */
  197. IgnoreList getIgnoreList();
  198. /**
  199. * Retusnt the list of invites for this server.
  200. *
  201. * @return Invite list
  202. */
  203. List<Invite> getInvites();
  204. /**
  205. * Retrieves the name of this server's IRCd.
  206. *
  207. * @return The name of this server's IRCd
  208. */
  209. String getIrcd();
  210. /**
  211. * Retrieves the name of this server's network. The network name is
  212. * determined using the following rules:
  213. *
  214. * 1. If the server includes its network name in the 005 information, we
  215. * use that
  216. * 2. If the server's name ends in biz, com, info, net or org, we use the
  217. * second level domain (e.g., foo.com)
  218. * 3. If the server's name contains more than two dots, we drop everything
  219. * up to and including the first part, and use the remainder
  220. * 4. In all other cases, we use the full server name
  221. *
  222. * @return The name of this server's network
  223. */
  224. String getNetwork();
  225. /**
  226. * Retrieves the identity for this server's network.
  227. *
  228. * @return This server's network identity
  229. */
  230. ConfigProvider getNetworkIdentity();
  231. /**
  232. * Retrieves the parser used for this connection.
  233. *
  234. * @return this connection's parser
  235. */
  236. Parser getParser();
  237. /**
  238. * Retrieves the profile that's in use for this server.
  239. *
  240. * @return The profile in use by this server
  241. */
  242. ConfigProvider getProfile();
  243. /**
  244. * Retrieves the protocol used by this server.
  245. *
  246. * @return This server's protocol
  247. * @since 0.6.3
  248. */
  249. String getProtocol();
  250. /**
  251. * Retrieves a list of queries belonging to this server.
  252. *
  253. * @return list of queries belonging to this server
  254. */
  255. Collection<Query> getQueries();
  256. /**
  257. * Retrieves the specified query belonging to this server. If the query
  258. * does not yet exist, it is created automatically.
  259. *
  260. * @param host The host of the query to look for
  261. * @return The appropriate query object
  262. */
  263. Query getQuery(final String host);
  264. /**
  265. * Retrieves the specified query belonging to this server. If the query
  266. * does not yet exist, it is created automatically.
  267. *
  268. * @param host The host of the query to look for
  269. * @param focus Should we focus the window on open?
  270. * @return The appropriate query object
  271. */
  272. Query getQuery(final String host, final boolean focus);
  273. /**
  274. * Retrieves the identity for this server.
  275. *
  276. * @return This server's identity
  277. */
  278. ConfigProvider getServerIdentity();
  279. /**
  280. * Retrieves the current state for this server.
  281. *
  282. * @return This server's state
  283. */
  284. ServerState getState();
  285. /**
  286. * Retrieves the status object for this server. Effecting state transitions
  287. * on the object returned by this method will almost certainly cause
  288. * problems.
  289. *
  290. * @since 0.6.3m1
  291. * @return This server's status object.
  292. */
  293. ServerStatus getStatus();
  294. /**
  295. * Determines whether the server knows of the specified channel.
  296. *
  297. * @param channel The channel to be checked
  298. * @return True iff the channel is known, false otherwise
  299. */
  300. boolean hasChannel(final String channel);
  301. /**
  302. * Determines whether the server knows of the specified query.
  303. *
  304. * @param host The host of the query to look for
  305. * @return True iff the query is known, false otherwise
  306. */
  307. boolean hasQuery(final String host);
  308. /**
  309. * Returns the current away status.
  310. *
  311. * @return True if the client is marked as away, false otherwise
  312. */
  313. boolean isAway();
  314. /**
  315. * Determines whether this server is currently connected to the specified
  316. * network.
  317. *
  318. * @param target The network to check for
  319. * @return True if this server is connected to the network, false otherwise
  320. * @since 0.6.3m1rc3
  321. */
  322. boolean isNetwork(final String target);
  323. /**
  324. * Determines if the specified channel name is valid. A channel name is
  325. * valid if we already have an existing Channel with the same name, or
  326. * we have a valid parser instance and the parser says it's valid.
  327. *
  328. * @param channelName The name of the channel to test
  329. * @return True if the channel name is valid, false otherwise
  330. */
  331. boolean isValidChannelName(final String channelName);
  332. /**
  333. * Attempts to join the specified channels. If channels with the same name
  334. * already exist, they are (re)joined and their windows activated.
  335. *
  336. * @param requests The channel join requests to process
  337. * @since 0.6.4
  338. */
  339. void join(final ChannelJoinRequest... requests);
  340. /**
  341. * Attempts to join the specified channels. If channels with the same name
  342. * already exist, they are (re)joined.
  343. *
  344. * @param focus Whether or not to focus any new channels
  345. * @param requests The channel join requests to process
  346. * @since 0.6.4
  347. */
  348. void join(final boolean focus, final ChannelJoinRequest... requests);
  349. /**
  350. * Parses the specified hostmask in a manner prescribed by the protocol
  351. * currently used by this server.
  352. *
  353. * @see com.dmdirc.parser.interfaces.ProtocolDescription#parseHostmask(java.lang.String)
  354. * @param hostmask The hostmask to be parsed
  355. * @return An array containing the nickname, username and hostname
  356. * @since 0.6.4
  357. */
  358. String[] parseHostmask(final String hostmask);
  359. /**
  360. * Reconnects to the server with a specified reason.
  361. *
  362. * @param reason The quit reason to send
  363. */
  364. void reconnect(final String reason);
  365. /**
  366. * Reconnects to the server.
  367. */
  368. void reconnect();
  369. /**
  370. * Removes an away state lisener from this server.
  371. *
  372. * @param listener The listener to be removed
  373. */
  374. void removeAwayStateListener(final AwayStateListener listener);
  375. /**
  376. * Removes the specified listener from this server.
  377. *
  378. * @param listener The listener to be removed
  379. */
  380. void removeCertificateProblemListener(final CertificateProblemListener listener);
  381. /**
  382. * Removes an invite from this server, and fires the appropriate listeners.
  383. *
  384. * @param invite The invite to be removed
  385. */
  386. void removeInvite(final Invite invite);
  387. /**
  388. * Removes an invite listener from this server.
  389. *
  390. * @param listener The listener to be removed
  391. */
  392. void removeInviteListener(final InviteListener listener);
  393. /**
  394. * Removes all invites for the specified channel.
  395. *
  396. * @param channel The channel to remove invites for
  397. */
  398. void removeInvites(final String channel);
  399. /**
  400. * Removes all invites for all channels.
  401. */
  402. void removeInvites();
  403. /**
  404. * Saves the contents of our ignore list to the network identity.
  405. */
  406. void saveIgnoreList();
  407. /**
  408. * Replies to an incoming CTCP message.
  409. *
  410. * @param source The source of the message
  411. * @param type The CTCP type
  412. * @param args The CTCP arguments
  413. */
  414. void sendCTCPReply(final String source, final String type, final String args);
  415. /**
  416. * Updates our away state and fires the relevant listeners.
  417. *
  418. * @param message The away message to use, or null if we're not away.
  419. */
  420. void updateAwayState(final String message);
  421. /**
  422. * Updates this server's ignore list to use the entries stored in the
  423. * config manager.
  424. */
  425. void updateIgnoreList();
  426. /**
  427. * Updates the state of this server following a nick change of someone
  428. * that the user has a query open with. Namely, this updates the
  429. * tabcompleter with the new name, and ensures that the <code>queries</code>
  430. * map uses the correct nickname.
  431. *
  432. * @param query The query object being updated
  433. * @param oldNick The old nickname of the user
  434. * @param newNick The new nickname of the user
  435. * @since 0.6.4
  436. */
  437. void updateQuery(final Query query, final String oldNick, final String newNick);
  438. /**
  439. * Updates the name and title of this window.
  440. */
  441. void updateTitle();
  442. }