Removed stability attributes.
This commit is contained in:
parent
1740a2e669
commit
2505cc5784
12 changed files with 3 additions and 349 deletions
|
@ -1,5 +1,4 @@
|
|||
//! Thread-safe connections on IrcStreams.
|
||||
#![stable]
|
||||
#[cfg(feature = "ssl")] use std::error::Error as StdError;
|
||||
use std::io::prelude::*;
|
||||
use std::io::{BufReader, BufWriter, Result};
|
||||
|
@ -16,22 +15,18 @@ use client::data::message::ToMessage;
|
|||
#[cfg(feature = "ssl")] use openssl::ssl::error::SslError;
|
||||
|
||||
/// A thread-safe connection.
|
||||
#[stable]
|
||||
pub struct Connection<T: IrcRead, U: IrcWrite> {
|
||||
reader: Mutex<T>,
|
||||
writer: Mutex<U>,
|
||||
}
|
||||
|
||||
/// A Connection over a buffered NetStream.
|
||||
#[stable]
|
||||
pub type NetConnection = Connection<BufReader<NetStream>, BufWriter<NetStream>>;
|
||||
/// An internal type
|
||||
type NetReadWritePair = (BufReader<NetStream>, BufWriter<NetStream>);
|
||||
|
||||
#[stable]
|
||||
impl Connection<BufReader<NetStream>, BufWriter<NetStream>> {
|
||||
/// Creates a thread-safe TCP connection to the specified server.
|
||||
#[stable]
|
||||
pub fn connect(host: &str, port: u16) -> Result<NetConnection> {
|
||||
let (reader, writer) = try!(Connection::connect_internal(host, port));
|
||||
Ok(Connection::new(reader, writer))
|
||||
|
@ -46,7 +41,6 @@ impl Connection<BufReader<NetStream>, BufWriter<NetStream>> {
|
|||
|
||||
/// Creates a thread-safe TCP connection to the specified server over SSL.
|
||||
/// If the library is compiled without SSL support, this method panics.
|
||||
#[stable]
|
||||
pub fn connect_ssl(host: &str, port: u16) -> Result<NetConnection> {
|
||||
let (reader, writer) = try!(Connection::connect_ssl_internal(host, port));
|
||||
Ok(Connection::new(reader, writer))
|
||||
|
@ -69,7 +63,6 @@ impl Connection<BufReader<NetStream>, BufWriter<NetStream>> {
|
|||
}
|
||||
|
||||
/// Reconnects to the specified server, dropping the current connection.
|
||||
#[stable]
|
||||
pub fn reconnect(&self, host: &str, port: u16) -> Result<()> {
|
||||
let use_ssl = match self.reader.lock().unwrap().get_ref() {
|
||||
&NetStream::UnsecuredTcpStream(_) => false,
|
||||
|
@ -106,10 +99,8 @@ impl Connection<BufReader<NetStream>, BufWriter<NetStream>> {
|
|||
*/
|
||||
}
|
||||
|
||||
#[stable]
|
||||
impl<T: IrcRead, U: IrcWrite> Connection<T, U> {
|
||||
/// Creates a new connection from an IrcReader and an IrcWriter.
|
||||
#[stable]
|
||||
pub fn new(reader: T, writer: U) -> Connection<T, U> {
|
||||
Connection {
|
||||
reader: Mutex::new(reader),
|
||||
|
@ -118,7 +109,6 @@ impl<T: IrcRead, U: IrcWrite> Connection<T, U> {
|
|||
}
|
||||
|
||||
/// Sends a Message over this connection.
|
||||
#[stable]
|
||||
#[cfg(feature = "encode")]
|
||||
pub fn send<M: ToMessage>(&self, to_msg: M, encoding: &str) -> Result<()> {
|
||||
let encoding = match encoding_from_whatwg_label(encoding) {
|
||||
|
@ -140,7 +130,6 @@ impl<T: IrcRead, U: IrcWrite> Connection<T, U> {
|
|||
}
|
||||
|
||||
/// Sends a message over this connection.
|
||||
#[stable]
|
||||
#[cfg(not(feature = "encode"))]
|
||||
pub fn send<M: ToMessage>(&self, to_msg: M) -> Result<()> {
|
||||
let mut writer = self.writer.lock().unwrap();
|
||||
|
@ -149,7 +138,6 @@ impl<T: IrcRead, U: IrcWrite> Connection<T, U> {
|
|||
}
|
||||
|
||||
/// Receives a single line from this connection.
|
||||
#[stable]
|
||||
#[cfg(feature = "encoding")]
|
||||
pub fn recv(&self, encoding: &str) -> Result<String> {
|
||||
let encoding = match encoding_from_whatwg_label(encoding) {
|
||||
|
@ -171,7 +159,6 @@ impl<T: IrcRead, U: IrcWrite> Connection<T, U> {
|
|||
}
|
||||
|
||||
/// Receives a single line from this connection.
|
||||
#[stable]
|
||||
#[cfg(not(feature = "encoding"))]
|
||||
pub fn recv(&self) -> Result<String> {
|
||||
let mut ret = String::new();
|
||||
|
@ -184,13 +171,11 @@ impl<T: IrcRead, U: IrcWrite> Connection<T, U> {
|
|||
}
|
||||
|
||||
/// Acquires the Reader lock.
|
||||
#[stable]
|
||||
pub fn reader<'a>(&'a self) -> MutexGuard<'a, T> {
|
||||
self.reader.lock().unwrap()
|
||||
}
|
||||
|
||||
/// Acquires the Writer lock.
|
||||
#[stable]
|
||||
pub fn writer<'a>(&'a self) -> MutexGuard<'a, U> {
|
||||
self.writer.lock().unwrap()
|
||||
}
|
||||
|
@ -208,15 +193,12 @@ fn ssl_to_io<T>(res: StdResult<T, SslError>) -> Result<T> {
|
|||
}
|
||||
|
||||
/// An abstraction over different networked streams.
|
||||
#[stable]
|
||||
pub enum NetStream {
|
||||
/// An unsecured TcpStream.
|
||||
#[stable]
|
||||
UnsecuredTcpStream(TcpStream),
|
||||
/// An SSL-secured TcpStream.
|
||||
/// This is only available when compiled with SSL support.
|
||||
#[cfg(feature = "ssl")]
|
||||
#[stable]
|
||||
SslTcpStream(SslStream<TcpStream>),
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
//! Enumeration of all available client commands.
|
||||
#![stable]
|
||||
use std::io::{Error, ErrorKind, Result};
|
||||
use std::result::Result as StdResult;
|
||||
use std::str::FromStr;
|
||||
|
@ -9,202 +8,144 @@ use client::data::message::{Message, ToMessage};
|
|||
/// also includes commands from the
|
||||
/// [capabilities extension](https://tools.ietf.org/html/draft-mitchell-irc-capabilities-01).
|
||||
/// Additionally, this includes some common additional commands from popular IRCds.
|
||||
#[stable]
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum Command {
|
||||
// 3.1 Connection Registration
|
||||
/// PASS :password
|
||||
#[stable]
|
||||
PASS(String),
|
||||
/// NICK :nickname
|
||||
#[stable]
|
||||
NICK(String),
|
||||
/// USER user mode * :realname
|
||||
#[stable]
|
||||
USER(String, String, String),
|
||||
/// OPER name :password
|
||||
#[stable]
|
||||
OPER(String, String),
|
||||
/// MODE nickname modes
|
||||
/// MODE channel modes [modeparams]
|
||||
#[stable]
|
||||
MODE(String, String, Option<String>),
|
||||
/// SERVICE nickname reserved distribution type reserved :info
|
||||
#[stable]
|
||||
SERVICE(String, String, String, String, String, String),
|
||||
/// QUIT :comment
|
||||
#[stable]
|
||||
QUIT(Option<String>),
|
||||
/// SQUIT server :comment
|
||||
#[stable]
|
||||
SQUIT(String, String),
|
||||
|
||||
// 3.2 Channel operations
|
||||
/// JOIN chanlist [chankeys]
|
||||
#[stable]
|
||||
JOIN(String, Option<String>),
|
||||
/// PART chanlist :[comment]
|
||||
#[stable]
|
||||
PART(String, Option<String>),
|
||||
// MODE is already defined.
|
||||
// MODE(String, String, Option<String>),
|
||||
/// TOPIC channel :[topic]
|
||||
#[stable]
|
||||
TOPIC(String, Option<String>),
|
||||
/// NAMES [chanlist :[target]]
|
||||
#[stable]
|
||||
NAMES(Option<String>, Option<String>),
|
||||
/// LIST [chanlist :[target]]
|
||||
#[stable]
|
||||
LIST(Option<String>, Option<String>),
|
||||
/// INVITE nickname channel
|
||||
#[stable]
|
||||
INVITE(String, String),
|
||||
/// KICK chanlist userlist :[comment]
|
||||
#[stable]
|
||||
KICK(String, String, Option<String>),
|
||||
|
||||
// 3.3 Sending messages
|
||||
/// PRIVMSG msgtarget :message
|
||||
#[stable]
|
||||
PRIVMSG(String, String),
|
||||
/// NOTICE msgtarget :message
|
||||
#[stable]
|
||||
NOTICE(String, String),
|
||||
|
||||
// 3.4 Server queries and commands
|
||||
/// MOTD :[target]
|
||||
#[stable]
|
||||
MOTD(Option<String>),
|
||||
/// LUSERS [mask :[target]]
|
||||
#[stable]
|
||||
LUSERS(Option<String>, Option<String>),
|
||||
/// VERSION :[target]
|
||||
#[stable]
|
||||
VERSION(Option<String>),
|
||||
/// STATS [query :[target]]
|
||||
#[stable]
|
||||
STATS(Option<String>, Option<String>),
|
||||
/// LINKS [[remote server] server :mask]
|
||||
#[stable]
|
||||
LINKS(Option<String>, Option<String>),
|
||||
/// TIME :[target]
|
||||
#[stable]
|
||||
TIME(Option<String>),
|
||||
/// CONNECT target server port :[remote server]
|
||||
#[stable]
|
||||
CONNECT(String, String, Option<String>),
|
||||
/// TRACE :[target]
|
||||
#[stable]
|
||||
TRACE(Option<String>),
|
||||
/// ADMIN :[target]
|
||||
#[stable]
|
||||
ADMIN(Option<String>),
|
||||
/// INFO :[target]
|
||||
#[stable]
|
||||
INFO(Option<String>),
|
||||
|
||||
// 3.5 Service Query and Commands
|
||||
/// SERVLIST [mask :[type]]
|
||||
#[stable]
|
||||
SERVLIST(Option<String>, Option<String>),
|
||||
/// SQUERY servicename text
|
||||
#[stable]
|
||||
SQUERY(String, String),
|
||||
|
||||
// 3.6 User based queries
|
||||
/// WHO [mask ["o"]]
|
||||
#[stable]
|
||||
WHO(Option<String>, Option<bool>),
|
||||
/// WHOIS [target] masklist
|
||||
#[stable]
|
||||
WHOIS(Option<String>, String),
|
||||
/// WHOWAS nicklist [count :[target]]
|
||||
#[stable]
|
||||
WHOWAS(String, Option<String>, Option<String>),
|
||||
|
||||
// 3.7 Miscellaneous messages
|
||||
/// KILL nickname :comment
|
||||
#[stable]
|
||||
KILL(String, String),
|
||||
/// PING server1 :[server2]
|
||||
#[stable]
|
||||
PING(String, Option<String>),
|
||||
/// PONG server :[server2]
|
||||
#[stable]
|
||||
PONG(String, Option<String>),
|
||||
/// ERROR :message
|
||||
#[stable]
|
||||
ERROR(String),
|
||||
|
||||
|
||||
// 4 Optional Features
|
||||
/// AWAY :[message]
|
||||
#[stable]
|
||||
AWAY(Option<String>),
|
||||
/// REHASH
|
||||
#[stable]
|
||||
REHASH,
|
||||
/// DIE
|
||||
#[stable]
|
||||
DIE,
|
||||
/// RESTART
|
||||
#[stable]
|
||||
RESTART,
|
||||
/// SUMMON user [target :[channel]]
|
||||
#[stable]
|
||||
SUMMON(String, Option<String>, Option<String>),
|
||||
/// USERS :[target]
|
||||
#[stable]
|
||||
USERS(Option<String>),
|
||||
/// WALLOPS :Text to be sent
|
||||
#[stable]
|
||||
WALLOPS(String),
|
||||
/// USERHOST space-separated nicklist
|
||||
#[stable]
|
||||
USERHOST(Vec<String>),
|
||||
/// ISON space-separated nicklist
|
||||
#[stable]
|
||||
ISON(Vec<String>),
|
||||
|
||||
// Non-RFC commands from InspIRCd
|
||||
/// SAJOIN nickname channel
|
||||
#[stable]
|
||||
SAJOIN(String, String),
|
||||
/// SAMODE target modes [modeparams]
|
||||
#[stable]
|
||||
SAMODE(String, String, Option<String>),
|
||||
/// SANICK old nickname new nickname
|
||||
#[stable]
|
||||
SANICK(String, String),
|
||||
/// SAPART nickname :comment
|
||||
#[stable]
|
||||
SAPART(String, String),
|
||||
/// SAQUIT nickname :comment
|
||||
#[stable]
|
||||
SAQUIT(String, String),
|
||||
/// NICKSERV message
|
||||
#[stable]
|
||||
NICKSERV(String),
|
||||
/// CHANSERV message
|
||||
#[stable]
|
||||
CHANSERV(String),
|
||||
/// OPERSERV message
|
||||
#[stable]
|
||||
OPERSERV(String),
|
||||
/// BOTSERV message
|
||||
#[stable]
|
||||
BOTSERV(String),
|
||||
/// HOSTSERV message
|
||||
#[stable]
|
||||
HOSTSERV(String),
|
||||
/// MEMOSERV message
|
||||
#[stable]
|
||||
MEMOSERV(String),
|
||||
|
||||
// Capabilities extension to IRCv3
|
||||
/// CAP [*] COMMAND [*] :[param]
|
||||
#[unstable = "Feature recently changed to hopefully be specification-compliant."]
|
||||
CAP(Option<String>, CapSubCommand, Option<String>, Option<String>),
|
||||
}
|
||||
|
||||
|
@ -360,10 +301,8 @@ impl ToMessage for Command {
|
|||
}
|
||||
}
|
||||
|
||||
#[stable]
|
||||
impl Command {
|
||||
/// Converts a Message into a Command.
|
||||
#[stable]
|
||||
pub fn from_message(m: &Message) -> Result<Command> {
|
||||
Ok(if let "PASS" = &m.command[..] {
|
||||
match m.suffix {
|
||||
|
@ -1081,43 +1020,32 @@ impl Command {
|
|||
}
|
||||
|
||||
/// Converts a potential Message result into a potential Command result.
|
||||
#[unstable = "This feature is still relatively new."]
|
||||
pub fn from_message_io(m: Result<Message>) -> Result<Command> {
|
||||
m.and_then(|msg| Command::from_message(&msg))
|
||||
}
|
||||
}
|
||||
|
||||
/// A list of all of the subcommands for the capabilities extension.
|
||||
#[stable]
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
pub enum CapSubCommand {
|
||||
/// Requests a list of the server's capabilities.
|
||||
#[stable]
|
||||
LS,
|
||||
/// Requests a list of the server's capabilities.
|
||||
#[stable]
|
||||
LIST,
|
||||
/// Requests specific capabilities blindly.
|
||||
#[stable]
|
||||
REQ,
|
||||
/// Acknowledges capabilities.
|
||||
#[stable]
|
||||
ACK,
|
||||
/// Does not acknowledge certain capabilities.
|
||||
#[stable]
|
||||
NAK,
|
||||
/// Requests that the server clears the capabilities of this client.
|
||||
#[stable]
|
||||
CLEAR,
|
||||
/// Ends the capability negotiation before registration.
|
||||
#[stable]
|
||||
END
|
||||
}
|
||||
|
||||
#[stable]
|
||||
impl CapSubCommand {
|
||||
/// Gets the string that corresponds to this subcommand.
|
||||
#[stable]
|
||||
pub fn to_str(&self) -> &str {
|
||||
match self {
|
||||
&CapSubCommand::LS => "LS",
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
//! JSON configuration files using libserialize.
|
||||
#![stable]
|
||||
use std::borrow::ToOwned;
|
||||
use std::collections::HashMap;
|
||||
use std::fs::File;
|
||||
|
@ -10,61 +9,43 @@ use rustc_serialize::json::decode;
|
|||
|
||||
/// Configuration data.
|
||||
#[derive(Clone, RustcDecodable, Default, PartialEq, Debug)]
|
||||
#[stable]
|
||||
pub struct Config {
|
||||
/// A list of the owners of the bot by nickname.
|
||||
#[stable]
|
||||
pub owners: Option<Vec<String>>,
|
||||
/// The bot's nickname.
|
||||
#[stable]
|
||||
pub nickname: Option<String>,
|
||||
/// The bot's NICKSERV password.
|
||||
#[stable]
|
||||
pub nick_password: Option<String>,
|
||||
/// Alternative nicknames for the bots, if the default is taken.
|
||||
#[stable]
|
||||
pub alt_nicks: Option<Vec<String>>,
|
||||
/// The bot's username.
|
||||
#[stable]
|
||||
pub username: Option<String>,
|
||||
/// The bot's real name.
|
||||
#[stable]
|
||||
pub realname: Option<String>,
|
||||
/// The server to connect to.
|
||||
#[stable]
|
||||
pub server: Option<String>,
|
||||
/// The port to connect on.
|
||||
#[stable]
|
||||
pub port: Option<u16>,
|
||||
/// The password to connect to the server.
|
||||
#[stable]
|
||||
pub password: Option<String>,
|
||||
/// Whether or not to use SSL.
|
||||
/// Bots will automatically panic if this is enabled without SSL support.
|
||||
#[stable]
|
||||
pub use_ssl: Option<bool>,
|
||||
/// The encoding type used for this connection.
|
||||
/// This is typically UTF-8, but could be something else.
|
||||
#[stable]
|
||||
pub encoding: Option<String>,
|
||||
/// A list of channels to join on connection.
|
||||
#[stable]
|
||||
pub channels: Option<Vec<String>>,
|
||||
/// User modes to set on connect. Example: "+RB-x"
|
||||
#[unstable]
|
||||
pub umodes: Option<String>,
|
||||
/// The text that'll be sent in response to CTCP USERINFO requests.
|
||||
#[stable]
|
||||
pub user_info: Option<String>,
|
||||
/// A map of additional options to be stored in config.
|
||||
#[stable]
|
||||
pub options: Option<HashMap<String, String>>,
|
||||
}
|
||||
|
||||
#[stable]
|
||||
impl Config {
|
||||
/// Loads a JSON configuration from the desired path.
|
||||
#[stable]
|
||||
pub fn load(path: &Path) -> Result<Config> {
|
||||
let mut file = try!(File::open(path));
|
||||
let mut data = String::new();
|
||||
|
@ -75,34 +56,29 @@ impl Config {
|
|||
}
|
||||
|
||||
/// Loads a JSON configuration using the string as a UTF-8 path.
|
||||
#[stable]
|
||||
pub fn load_utf8(path: &str) -> Result<Config> {
|
||||
Config::load(Path::new(path))
|
||||
}
|
||||
|
||||
/// Determines whether or not the nickname provided is the owner of the bot.
|
||||
#[stable]
|
||||
pub fn is_owner(&self, nickname: &str) -> bool {
|
||||
self.owners.as_ref().map(|o| o.contains(&nickname.to_string())).unwrap()
|
||||
}
|
||||
|
||||
/// Gets the nickname specified in the configuration.
|
||||
/// This will panic if not specified.
|
||||
#[stable]
|
||||
pub fn nickname(&self) -> &str {
|
||||
self.nickname.as_ref().map(|s| &s[..]).unwrap()
|
||||
}
|
||||
|
||||
/// Gets the bot's nickserv password specified in the configuration.
|
||||
/// This defaults to an empty string when not specified.
|
||||
#[stable]
|
||||
pub fn nick_password(&self) -> &str {
|
||||
self.nick_password.as_ref().map(|s| &s[..]).unwrap_or("")
|
||||
}
|
||||
|
||||
/// Gets the alternate nicknames specified in the configuration.
|
||||
/// This defaults to an empty vector when not specified.
|
||||
#[stable]
|
||||
pub fn get_alternate_nicknames(&self) -> Vec<&str> {
|
||||
self.alt_nicks.as_ref().map(|v| v.iter().map(|s| &s[..]).collect()).unwrap_or(vec![])
|
||||
}
|
||||
|
@ -110,28 +86,24 @@ impl Config {
|
|||
|
||||
/// Gets the username specified in the configuration.
|
||||
/// This defaults to the user's nickname when not specified.
|
||||
#[stable]
|
||||
pub fn username(&self) -> &str {
|
||||
self.username.as_ref().map(|s| &s[..]).unwrap_or(self.nickname())
|
||||
}
|
||||
|
||||
/// Gets the real name specified in the configuration.
|
||||
/// This defaults to the user's nickname when not specified.
|
||||
#[stable]
|
||||
pub fn real_name(&self) -> &str {
|
||||
self.realname.as_ref().map(|s| &s[..]).unwrap_or(self.nickname())
|
||||
}
|
||||
|
||||
/// Gets the address of the server specified in the configuration.
|
||||
/// This panics when not specified.
|
||||
#[stable]
|
||||
pub fn server(&self) -> &str {
|
||||
self.server.as_ref().map(|s| &s[..]).unwrap()
|
||||
}
|
||||
|
||||
/// Gets the port of the server specified in the configuration.
|
||||
/// This defaults to 6667 (or 6697 if use_ssl is specified as true) when not specified.
|
||||
#[stable]
|
||||
pub fn port(&self) -> u16 {
|
||||
self.port.as_ref().map(|p| *p).unwrap_or(if self.use_ssl() {
|
||||
6697
|
||||
|
@ -142,42 +114,36 @@ impl Config {
|
|||
|
||||
/// Gets the server password specified in the configuration.
|
||||
/// This defaults to a blank string when not specified.
|
||||
#[stable]
|
||||
pub fn password(&self) -> &str {
|
||||
self.password.as_ref().map(|s| &s[..]).unwrap_or("")
|
||||
}
|
||||
|
||||
/// Gets whether or not to use SSL with this connection.
|
||||
/// This defaults to false when not specified.
|
||||
#[stable]
|
||||
pub fn use_ssl(&self) -> bool {
|
||||
self.use_ssl.as_ref().map(|u| *u).unwrap_or(false)
|
||||
}
|
||||
|
||||
/// Gets the encoding to use for this connection. This requires the encode feature to work.
|
||||
/// This defaults to UTF-8 when not specified.
|
||||
#[stable]
|
||||
pub fn encoding(&self) -> &str {
|
||||
self.encoding.as_ref().map(|s| &s[..]).unwrap_or("UTF-8")
|
||||
}
|
||||
|
||||
/// Gets the channels to join upon connection.
|
||||
/// This defaults to an empty vector if it's not specified.
|
||||
#[stable]
|
||||
pub fn channels(&self) -> Vec<&str> {
|
||||
self.channels.as_ref().map(|v| v.iter().map(|s| &s[..]).collect()).unwrap_or(vec![])
|
||||
}
|
||||
|
||||
/// Gets the user modes to set on connect specified in the configuration.
|
||||
/// This defaults to an empty string when not specified.
|
||||
#[unstable = "Feature is still relatively new."]
|
||||
pub fn umodes(&self) -> &str {
|
||||
self.umodes.as_ref().map(|s| &s[..]).unwrap_or("")
|
||||
}
|
||||
|
||||
/// Gets the string to be sent in response to CTCP USERINFO requests.
|
||||
/// This defaults to an empty string when not specified.
|
||||
#[stable]
|
||||
pub fn user_info(&self) -> &str {
|
||||
self.user_info.as_ref().map(|s| &s[..]).unwrap_or("")
|
||||
}
|
||||
|
@ -185,7 +151,6 @@ impl Config {
|
|||
/// Looks up the specified string in the options map.
|
||||
/// This uses indexing, and thus panics when the string is not present.
|
||||
/// This will also panic if used and there are no options.
|
||||
#[stable]
|
||||
pub fn get_option(&self, option: &str) -> &str {
|
||||
self.options.as_ref().map(|o| &o[&option.to_owned()][..]).unwrap()
|
||||
}
|
||||
|
|
|
@ -1,31 +1,23 @@
|
|||
//! Messages to and from the server.
|
||||
#![stable]
|
||||
use std::borrow::ToOwned;
|
||||
use std::str::FromStr;
|
||||
|
||||
/// IRC Message data.
|
||||
#[stable]
|
||||
#[derive(Clone, PartialEq, Debug)]
|
||||
pub struct Message {
|
||||
/// The message prefix (or source) as defined by [RFC 2812](http://tools.ietf.org/html/rfc2812).
|
||||
#[stable]
|
||||
pub prefix: Option<String>,
|
||||
/// The IRC command as defined by [RFC 2812](http://tools.ietf.org/html/rfc2812).
|
||||
#[stable]
|
||||
pub command: String,
|
||||
/// The command arguments.
|
||||
#[stable]
|
||||
pub args: Vec<String>,
|
||||
/// The message suffix as defined by [RFC 2812](http://tools.ietf.org/html/rfc2812).
|
||||
/// This is the only part of the message that is allowed to contain spaces.
|
||||
#[stable]
|
||||
pub suffix: Option<String>,
|
||||
}
|
||||
|
||||
#[stable]
|
||||
impl Message {
|
||||
/// Creates a new Message.
|
||||
#[stable]
|
||||
pub fn new(prefix: Option<&str>, command: &str, args: Option<Vec<&str>>, suffix: Option<&str>)
|
||||
-> Message {
|
||||
Message {
|
||||
|
@ -37,13 +29,11 @@ impl Message {
|
|||
}
|
||||
|
||||
/// Gets the nickname of the message source, if it exists.
|
||||
#[stable]
|
||||
pub fn get_source_nickname(&self) -> Option<&str> {
|
||||
self.prefix.as_ref().and_then(|s| s.find('!').map(|i| &s[..i]))
|
||||
}
|
||||
|
||||
/// Converts a Message into a String according to the IRC protocol.
|
||||
#[stable]
|
||||
pub fn into_string(&self) -> String {
|
||||
let mut ret = String::new();
|
||||
if let Some(ref prefix) = self.prefix {
|
||||
|
@ -104,7 +94,6 @@ impl FromStr for Message {
|
|||
}
|
||||
|
||||
/// A trait representing the ability to be converted into a Message.
|
||||
#[stable]
|
||||
pub trait ToMessage {
|
||||
/// Converts this to a Message.
|
||||
fn to_message(&self) -> Message;
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
//! Data related to IRC functionality.
|
||||
#![stable]
|
||||
|
||||
pub use client::data::command::Command;
|
||||
pub use client::data::config::Config;
|
||||
|
@ -9,15 +8,12 @@ pub use client::data::user::{AccessLevel, User};
|
|||
|
||||
pub mod kinds {
|
||||
//! Trait definitions of appropriate Writers and Buffers for use with this library.
|
||||
#![stable]
|
||||
use std::io::prelude::*;
|
||||
|
||||
/// Trait describing all possible Writers for this library.
|
||||
#[stable]
|
||||
pub trait IrcWrite: Write + Sized + Send + 'static {}
|
||||
impl<T> IrcWrite for T where T: Write + Sized + Send + 'static {}
|
||||
/// Trait describing all possible Readers for this library.
|
||||
#[stable]
|
||||
pub trait IrcRead: BufRead + Sized + Send + 'static {}
|
||||
impl<T> IrcRead for T where T: BufRead + Sized + Send + 'static {}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
//! Enumeration of all the possible server responses.
|
||||
#![stable]
|
||||
#![allow(non_camel_case_types)]
|
||||
use std::mem::transmute;
|
||||
use std::str::FromStr;
|
||||
|
@ -9,437 +8,296 @@ use client::data::message::Message;
|
|||
/// All commands are documented with their expected form from the RFC.
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
#[repr(u16)]
|
||||
#[stable]
|
||||
pub enum Response {
|
||||
// Expected replies
|
||||
/// 001 Welcome to the Internet Relay Network <nick>!<user>@<host>
|
||||
#[stable]
|
||||
RPL_WELCOME = 001,
|
||||
/// 002 Your host is <servername>, running version <ver>
|
||||
#[stable]
|
||||
RPL_YOURHOST = 002,
|
||||
/// 003 This server was created <date>
|
||||
#[stable]
|
||||
RPL_CREATED = 003,
|
||||
/// 004 <servername> <version> <available user modes> available channel modes>
|
||||
#[stable]
|
||||
RPL_MYINFO = 004,
|
||||
/// 005 Try server <server name>, port <port number>
|
||||
#[stable]
|
||||
RPL_BOUNCE = 005,
|
||||
/// 302 :*1<reply> *( " " <reply> )
|
||||
#[stable]
|
||||
RPL_USERHOST = 302,
|
||||
/// 303 :*1<nick> *( " " <nick> )
|
||||
#[stable]
|
||||
RPL_ISON = 303,
|
||||
/// 301 <nick> :<away message>
|
||||
#[stable]
|
||||
RPL_AWAY = 301,
|
||||
/// 305 :You are no longer marked as being away
|
||||
#[stable]
|
||||
RPL_UNAWAY = 305,
|
||||
/// 306 :You have been marked as being away
|
||||
#[stable]
|
||||
RPL_NOWAWAY = 306,
|
||||
/// 311 <nick> <user> <host> * :<real name>
|
||||
#[stable]
|
||||
RPL_WHOISUSER = 311,
|
||||
/// 312 <nick> <server> :<server info>
|
||||
#[stable]
|
||||
RPL_WHOISSERVER = 312,
|
||||
/// 313 <nick> :is an IRC operator
|
||||
#[stable]
|
||||
RPL_WHOISOPERATOR = 313,
|
||||
/// 317 <nick> <integer> :seconds idle
|
||||
#[stable]
|
||||
RPL_WHOISIDLE = 317,
|
||||
/// 318 <nick> :End of WHOIS list
|
||||
#[stable]
|
||||
RPL_ENDOFWHOIS = 318,
|
||||
/// 319 <nick> :*( ( "@" / "+" ) <channel> " " )
|
||||
#[stable]
|
||||
RPL_WHOISCHANNELS = 319,
|
||||
/// 314 <nick> <user> <host> * :<real name>
|
||||
#[stable]
|
||||
RPL_WHOWASUSER = 314,
|
||||
/// 369 <nick> :End of WHOWAS
|
||||
#[stable]
|
||||
RPL_ENDOFWHOWAS = 369,
|
||||
/// Obsolete. Not used.
|
||||
#[stable]
|
||||
RPL_LISTSTART = 321,
|
||||
/// 322 <channel> <# visible> :<topic>
|
||||
#[stable]
|
||||
RPL_LIST = 322,
|
||||
/// 323 :End of LIST
|
||||
#[stable]
|
||||
RPL_LISTEND = 323,
|
||||
/// 325 <channel> <nickname>
|
||||
#[stable]
|
||||
RPL_UNIQOPIS = 325,
|
||||
/// 324 <channel> <mode> <mode params>
|
||||
#[stable]
|
||||
RPL_CHANNELMODEIS = 324,
|
||||
/// 331 <channel> :No topic is set
|
||||
#[stable]
|
||||
RPL_NOTOPIC = 331,
|
||||
/// 332 <channel> :<topic>
|
||||
#[stable]
|
||||
RPL_TOPIC = 332,
|
||||
/// 341 <channel> <nick>
|
||||
#[stable]
|
||||
RPL_INVITING = 341,
|
||||
/// 342 <user> :Summoning user to IRC
|
||||
#[stable]
|
||||
RPL_SUMMONING = 342,
|
||||
/// 346 <channel> <invitemask>
|
||||
#[stable]
|
||||
RPL_INVITELIST = 346,
|
||||
/// 347 <channel> :End of channel invite list
|
||||
#[stable]
|
||||
RPL_ENDOFINVITELIST = 347,
|
||||
/// 348 <channel> <exceptionmask>
|
||||
#[stable]
|
||||
RPL_EXCEPTLIST = 348,
|
||||
/// 349 <channel> :End of channel exception list
|
||||
#[stable]
|
||||
RPL_ENDOFEXECPTLIST = 349,
|
||||
RPL_ENDOFEXCEPTLIST = 349,
|
||||
/// 351 <version>.<debuglevel> <server> :<comments>
|
||||
#[stable]
|
||||
RPL_VERSION = 351,
|
||||
/// 352 <channel> <user> <host> <server> <nick> ( "H" / "G" > ["*"] [ ( "@" / "+" ) ]
|
||||
#[stable]
|
||||
/// :<hopcount> <real name>
|
||||
#[stable]
|
||||
RPL_WHOREPLY = 352,
|
||||
/// 315 <name> :End of WHO list
|
||||
#[stable]
|
||||
RPL_ENDOFWHO = 315,
|
||||
/// 353 ( "=" / "*" / "@" ) <channel> :[ "@" / "+" ] <nick> *( " " [ "@" / "+" ] <nick> )
|
||||
#[stable]
|
||||
RPL_NAMREPLY = 353,
|
||||
/// 366 <channel> :End of NAMES list
|
||||
#[stable]
|
||||
RPL_ENDOFNAMES = 366,
|
||||
/// 364 <mask> <server> :<hopcount> <server info>
|
||||
#[stable]
|
||||
RPL_LINKS = 364,
|
||||
/// 365 <mask> :End of LINKS list
|
||||
#[stable]
|
||||
RPL_ENDOFLINKS = 365,
|
||||
/// 367 <channel> <banmask>
|
||||
#[stable]
|
||||
RPL_BANLIST = 367,
|
||||
/// 368 <channel> :End of channel ban list
|
||||
#[stable]
|
||||
RPL_ENDOFBANLIST = 368,
|
||||
/// 371 :<string>
|
||||
#[stable]
|
||||
RPL_INFO = 371,
|
||||
/// 374 :End of INFO list
|
||||
#[stable]
|
||||
RPL_ENDOFINFO = 374,
|
||||
/// 375 :- <server> Message of the day -
|
||||
#[stable]
|
||||
RPL_MOTDSTART = 375,
|
||||
/// 372 :- <text>
|
||||
#[stable]
|
||||
RPL_MOTD = 372,
|
||||
/// 376 :End of MOTD command
|
||||
#[stable]
|
||||
RPL_ENDOFMOTD = 376,
|
||||
/// 381 :You are now an IRC operator
|
||||
#[stable]
|
||||
RPL_YOUREOPER = 381,
|
||||
/// 382 <config file> :Rehashing
|
||||
#[stable]
|
||||
RPL_REHASHING = 382,
|
||||
/// 383 You are service <servicename>
|
||||
#[stable]
|
||||
RPL_YOURESERVICE = 383,
|
||||
/// 391 <server> :<string showing server's local time>
|
||||
#[stable]
|
||||
RPL_TIME = 391,
|
||||
/// 392 :UserID Terminal Host
|
||||
#[stable]
|
||||
RPL_USERSSTART = 392,
|
||||
/// 393 :<username> <ttyline> <hostname>
|
||||
#[stable]
|
||||
RPL_USERS = 393,
|
||||
/// 394 :End of users
|
||||
#[stable]
|
||||
RPL_ENDOFUSERS = 394,
|
||||
/// 395 :Nobody logged in
|
||||
#[stable]
|
||||
RPL_NOUSERS = 395,
|
||||
/// 200 Link <version & debug level> <destination> <next server> V<protocol version>
|
||||
/// <link uptime in seconds> <backstream sendq> <upstream sendq>
|
||||
#[stable]
|
||||
RPL_TRACELINK = 200,
|
||||
/// 201 Try. <class> <server>
|
||||
#[stable]
|
||||
RPL_TRACECONNECTING = 201,
|
||||
/// 202 H.S. <class> <server>
|
||||
#[stable]
|
||||
RPL_TRACEHANDSHAKE = 202,
|
||||
/// 203 ???? <class> [<client IP address in dot form>]
|
||||
#[stable]
|
||||
RPL_TRACEUKNOWN = 203,
|
||||
/// 204 Oper <class> <nick>
|
||||
#[stable]
|
||||
RPL_TRACEOPERATOR = 204,
|
||||
/// 205 User <class> <nick>
|
||||
#[stable]
|
||||
RPL_TRACEUSER = 205,
|
||||
/// 206 Serv <class> <int>S <int>C <server> <nick!user|*!*>@<host|server> V<protocol version>
|
||||
#[stable]
|
||||
RPL_TRACESERVER = 206,
|
||||
/// 207 Service <class> <name> <type> <active type>
|
||||
#[stable]
|
||||
RPL_TRACESERVICE = 207,
|
||||
/// 208 <newtype> 0 <client name>
|
||||
#[stable]
|
||||
RPL_TRACENEWTYPE = 208,
|
||||
/// 209 Class <class> <count>
|
||||
#[stable]
|
||||
RPL_TRACECLASS = 209,
|
||||
/// Unused.
|
||||
RPL_TRACERECONNECT = 210,
|
||||
/// 261 File <logfile> <debug level>
|
||||
#[stable]
|
||||
RPL_TRACELOG = 261,
|
||||
/// 262 <server name> <version & debug level> :End of TRACE
|
||||
#[stable]
|
||||
RPL_TRACEEND = 262,
|
||||
/// 211 <linkname> <sendq> <sent messages> <sent Kbytes> <received messages> <received Kbytes>
|
||||
/// <time open>
|
||||
#[stable]
|
||||
RPL_STATSLINKINFO = 211,
|
||||
/// 212 <command> <count> <byte count> <remote count>
|
||||
#[stable]
|
||||
RPL_STATSCOMMANDS = 212,
|
||||
/// 219 <stats letter> :End of STATS report
|
||||
#[stable]
|
||||
RPL_ENDOFSTATS = 219,
|
||||
/// 242 :Server Up %d days %d:%02d:%02d
|
||||
#[stable]
|
||||
RPL_STATSUPTIME = 242,
|
||||
/// O <hostmask> * <name>
|
||||
#[stable]
|
||||
RPL_STATSOLINE = 243,
|
||||
/// 221 <user mode string>
|
||||
#[stable]
|
||||
RPL_UMODEIS = 221,
|
||||
/// 234 <name> <server> <mask> <type> <hopcount> <info>
|
||||
#[stable]
|
||||
RPL_SERVLIST = 234,
|
||||
/// 235 <mask> <type> :End of service listing
|
||||
#[stable]
|
||||
RPL_SERVLISTEND = 235,
|
||||
/// 251 :There are <integer> users and <integer> services on <integer> servers
|
||||
#[stable]
|
||||
RPL_LUSERCLIENT = 251,
|
||||
/// 252 <integer> :operator(s) online
|
||||
#[stable]
|
||||
RPL_LUSEROP = 252,
|
||||
/// 253 <integer> :unknown connection(s)
|
||||
#[stable]
|
||||
RPL_LUSERUNKNOWN = 253,
|
||||
/// 254 <integer> :channels formed
|
||||
#[stable]
|
||||
RPL_LUSERCHANNELS = 254,
|
||||
/// 255 :I have <integer> clients and <integer> servers
|
||||
#[stable]
|
||||
RPL_LUSERME = 255,
|
||||
/// 256 <server> :Administrative info
|
||||
#[stable]
|
||||
RPL_ADMINME = 256,
|
||||
/// 257 :<admin info>
|
||||
#[stable]
|
||||
RPL_ADMINLOC1 = 257,
|
||||
/// 258 :<admin info>
|
||||
#[stable]
|
||||
RPL_ADMINLOC2 = 258,
|
||||
/// 259 :<admin info>
|
||||
#[stable]
|
||||
RPL_ADMINEMAIL = 259,
|
||||
/// 263 <command> :Please wait a while and try again.
|
||||
#[stable]
|
||||
RPL_TRYAGAIN = 263,
|
||||
|
||||
|
||||
// Error replies
|
||||
/// 401 <nickname> :No such nick/channel
|
||||
#[stable]
|
||||
ERR_NOSUCHNICK = 401,
|
||||
/// 402 <server name> :No such server
|
||||
#[stable]
|
||||
ERR_NOSUCHSERVER = 402,
|
||||
/// 403 <channel name> :No such channel
|
||||
#[stable]
|
||||
ERR_NOSUCHCHANNEL = 403,
|
||||
/// 404 <channel name> :Cannot send to channel
|
||||
#[stable]
|
||||
ERR_CANNOTSENDTOCHAN = 404,
|
||||
/// 405 <channel name> :You have joined too many channels
|
||||
#[stable]
|
||||
ERR_TOOMANYCHANNELS = 405,
|
||||
/// 406 <nickname> :There was no such nickname
|
||||
#[stable]
|
||||
ERR_WASNOSUCHNICK = 406,
|
||||
/// 407 <target> :<error code> recipients. <abort message>
|
||||
#[stable]
|
||||
ERR_TOOMANYTARGETS = 407,
|
||||
/// 408 <service name> :No such service
|
||||
#[stable]
|
||||
ERR_NOSUCHSERVICE = 408,
|
||||
/// 409 :No origin specified
|
||||
#[stable]
|
||||
ERR_NOORIGIN = 409,
|
||||
/// 411 :No recipient given (<command>)
|
||||
#[stable]
|
||||
ERR_NORECIPIENT = 411,
|
||||
/// 412 :No text to send
|
||||
#[stable]
|
||||
ERR_NOTEXTTOSEND = 412,
|
||||
/// 413 <mask> :No toplevel domain specified
|
||||
#[stable]
|
||||
ERR_NOTOPLEVEL = 413,
|
||||
/// 414 <mask> :Wildcard in toplevel domain
|
||||
#[stable]
|
||||
ERR_WILDTOPLEVEL = 414,
|
||||
/// 415 <mask> :Bad Server/host mask
|
||||
#[stable]
|
||||
ERR_BADMASK = 415,
|
||||
/// 421 <command> :Unknown command
|
||||
#[stable]
|
||||
ERR_UNKNOWNCOMMAND = 421,
|
||||
/// 422 :MOTD File is missing
|
||||
#[stable]
|
||||
ERR_NOMOTD = 422,
|
||||
/// 423 <server> :No administrative info available
|
||||
#[stable]
|
||||
ERR_NOADMININFO = 423,
|
||||
/// 424 :File error doing <file op> on <file>
|
||||
#[stable]
|
||||
ERR_FILEERROR = 424,
|
||||
/// 431 :No nickname given
|
||||
#[stable]
|
||||
ERR_NONICKNAMEGIVEN = 431,
|
||||
/// 432 <nick> :Erroneous nickname"
|
||||
#[stable]
|
||||
ERR_ERRONEOUSNICKNAME = 432,
|
||||
/// 433 <nick> :Nickname is already in use
|
||||
#[stable]
|
||||
ERR_NICKNAMEINUSE = 433,
|
||||
/// 436 <nick> :Nickname collision KILL from <user>@<host>
|
||||
#[stable]
|
||||
ERR_NICKCOLLISION = 436,
|
||||
/// 437 <nick/channel> :Nick/channel is temporarily unavailable
|
||||
#[stable]
|
||||
ERR_UNAVAILRESOURCE = 437,
|
||||
/// 441 <nick> <channel> :They aren't on that channel
|
||||
#[stable]
|
||||
ERR_USERNOTINCHANNEL = 441,
|
||||
/// 442 <channel> :You're not on that channel
|
||||
#[stable]
|
||||
ERR_NOTONCHANNEL = 442,
|
||||
/// 443 <user> <channel> :is already on channel
|
||||
#[stable]
|
||||
ERR_USERONCHANNEL = 443,
|
||||
/// 444 <user> :User not logged in
|
||||
#[stable]
|
||||
ERR_NOLOGIN = 444,
|
||||
/// 445 :SUMMON has been disabled
|
||||
#[stable]
|
||||
ERR_SUMMONDISABLED = 445,
|
||||
/// 446 :USERS has been disabled
|
||||
#[stable]
|
||||
ERR_USERSDISABLED = 446,
|
||||
/// 451 :You have not registered
|
||||
#[stable]
|
||||
ERR_NOTREGISTERED = 451,
|
||||
/// 461 <command> :Not enough parameters
|
||||
#[stable]
|
||||
ERR_NEEDMOREPARAMS = 461,
|
||||
/// 462 :Unauthorized command (already registered)
|
||||
#[stable]
|
||||
ERR_ALREADYREGISTRED = 462,
|
||||
/// 463 :Your host isn't among the privileged
|
||||
#[stable]
|
||||
ERR_NOPERMFORHOST = 463,
|
||||
/// 464 :Password incorrect
|
||||
#[stable]
|
||||
ERR_PASSWDMISMATCH = 464,
|
||||
/// 465 :You are banned from this server
|
||||
#[stable]
|
||||
ERR_YOUREBANNEDCREEP = 465,
|
||||
/// 466
|
||||
#[stable]
|
||||
ERR_YOUWILLBEBANNED = 466,
|
||||
/// 467 <channel> :Channel key already set
|
||||
#[stable]
|
||||
ERR_KEYSET = 467,
|
||||
/// 471 <channel> :Cannot join channel (+l)
|
||||
#[stable]
|
||||
ERR_CHANNELISFULL = 471,
|
||||
/// 472 <char> :is unknown mode char to me for <channel>
|
||||
#[stable]
|
||||
ERR_UNKNOWNMODE = 472,
|
||||
/// 473 <channel> :Cannot join channel (+i)
|
||||
#[stable]
|
||||
ERR_INVITEONLYCHAN = 473,
|
||||
/// 474 <channel> :Cannot join channel (+b)
|
||||
#[stable]
|
||||
ERR_BANNEDFROMCHAN = 474,
|
||||
/// 475 <channel> :Cannot join channel (+k)
|
||||
#[stable]
|
||||
ERR_BADCHANNELKEY = 475,
|
||||
/// 476 <channel> :Bad Channel Mask
|
||||
#[stable]
|
||||
ERR_BADCHANMASK = 476,
|
||||
/// 477 <channel> :Channel doesn't support modes
|
||||
#[stable]
|
||||
ERR_NOCHANMODES = 477,
|
||||
/// 478 <channel> <char> :Channel list is full
|
||||
#[stable]
|
||||
ERR_BANLISTFULL = 478,
|
||||
/// 481 :Permission Denied- You're not an IRC operator
|
||||
#[stable]
|
||||
ERR_NOPRIVILEGES = 481,
|
||||
/// 482 <channel> :You're not channel operator
|
||||
#[stable]
|
||||
ERR_CHANOPRIVSNEEDED = 482,
|
||||
/// 483 :You can't kill a server!
|
||||
#[stable]
|
||||
ERR_CANTKILLSERVER = 483,
|
||||
/// 484 :Your connection is restricted!
|
||||
#[stable]
|
||||
ERR_RESTRICTED = 484,
|
||||
/// 485 :You're not the original channel operator
|
||||
#[stable]
|
||||
ERR_UNIQOPPRIVSNEEDED = 485,
|
||||
/// 491 :No O-lines for your host
|
||||
#[stable]
|
||||
ERR_NOOPERHOST = 491,
|
||||
/// 501 :Unknown MODE flag
|
||||
#[stable]
|
||||
ERR_UMODEUNKNOWNFLAG = 501,
|
||||
/// 502 :Cannot change mode for other users
|
||||
#[stable]
|
||||
ERR_USERSDONTMATCH = 502,
|
||||
}
|
||||
|
||||
#[stable]
|
||||
impl Response {
|
||||
/// Gets a response from a message.
|
||||
#[stable]
|
||||
pub fn from_message(m: &Message) -> Option<Response> {
|
||||
m.command.parse().ok()
|
||||
}
|
||||
|
||||
/// Determines whether or not this response is an error response.
|
||||
#[stable]
|
||||
/// Determines whether or not this response is an error response.
|
||||
pub fn is_error(&self) -> bool {
|
||||
*self as u16 >= 400
|
||||
}
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
//! Data for tracking user information.
|
||||
#![unstable]
|
||||
use std::borrow::ToOwned;
|
||||
use std::cmp::Ordering;
|
||||
use std::cmp::Ordering::{Less, Equal, Greater};
|
||||
use std::str::FromStr;
|
||||
|
||||
/// IRC User data.
|
||||
#[stable]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct User {
|
||||
/// The user's nickname.
|
||||
|
@ -17,10 +15,8 @@ pub struct User {
|
|||
access_levels: Vec<AccessLevel>,
|
||||
}
|
||||
|
||||
#[stable]
|
||||
impl User {
|
||||
/// Creates a new User.
|
||||
#[stable]
|
||||
pub fn new(name: &str) -> User {
|
||||
let ranks: Vec<_> = AccessLevelIterator::new(name).collect();
|
||||
User {
|
||||
|
@ -43,25 +39,21 @@ impl User {
|
|||
}
|
||||
|
||||
/// Gets the nickname of the user.
|
||||
#[stable]
|
||||
pub fn get_name(&self) -> &str {
|
||||
&self.name
|
||||
}
|
||||
|
||||
/// Gets the user's highest access level.
|
||||
#[unstable = "API may change."]
|
||||
pub fn highest_access_level(&self) -> AccessLevel {
|
||||
self.highest_access_level
|
||||
}
|
||||
|
||||
/// Gets all the user's access levels.
|
||||
#[unstable = "API may change."]
|
||||
pub fn access_levels(&self) -> Vec<AccessLevel> {
|
||||
self.access_levels.clone()
|
||||
}
|
||||
|
||||
/// Updates the user's access level.
|
||||
#[unstable = "API may change."]
|
||||
pub fn update_access_level(&mut self, mode: &str) {
|
||||
match mode {
|
||||
"+q" => self.add_access_level(AccessLevel::Owner),
|
||||
|
@ -112,26 +104,19 @@ impl PartialEq for User {
|
|||
}
|
||||
|
||||
/// The user's access level.
|
||||
#[stable]
|
||||
#[derive(Copy, PartialEq, Clone, Debug)]
|
||||
pub enum AccessLevel {
|
||||
/// The channel owner (~).
|
||||
#[stable]
|
||||
Owner,
|
||||
/// A channel administrator (&).
|
||||
#[stable]
|
||||
Admin,
|
||||
/// A channel operator (@),
|
||||
#[stable]
|
||||
Oper,
|
||||
/// A channel half-oper (%),
|
||||
#[stable]
|
||||
HalfOp,
|
||||
/// A user with voice (+),
|
||||
#[stable]
|
||||
Voice,
|
||||
/// A normal user,
|
||||
#[stable]
|
||||
Member,
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
//! A simple, thread-safe IRC client library.
|
||||
#![stable]
|
||||
|
||||
pub mod conn;
|
||||
pub mod data;
|
||||
|
@ -7,8 +6,6 @@ pub mod server;
|
|||
|
||||
pub mod prelude {
|
||||
//! A client-side IRC prelude, re-exporting all the necessary basics.
|
||||
#![unstable = "Prelude is newly added, and contents have not yet firmed up."]
|
||||
|
||||
pub use client::server::{IrcServer, Server};
|
||||
pub use client::server::utils::ServerExt;
|
||||
pub use client::data::{Command, Config, Message, Response, ToMessage};
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
//! Interface for working with IRC Servers.
|
||||
//!
|
||||
//! There are currently two recommended ways to work
|
||||
#![stable]
|
||||
use std::borrow::ToOwned;
|
||||
use std::collections::HashMap;
|
||||
use std::error::Error as StdError;
|
||||
|
@ -17,28 +16,21 @@ use client::data::kinds::{IrcRead, IrcWrite};
|
|||
pub mod utils;
|
||||
|
||||
/// Trait describing core Server functionality.
|
||||
#[stable]
|
||||
pub trait Server<'a, T, U> {
|
||||
/// Gets the configuration being used with this Server.
|
||||
#[stable]
|
||||
fn config(&self) -> &Config;
|
||||
/// Sends a Command to this Server.
|
||||
#[stable]
|
||||
fn send(&self, command: Command) -> Result<()>;
|
||||
/// Gets an Iterator over Messages received by this Server.
|
||||
#[stable]
|
||||
fn iter(&'a self) -> ServerIterator<'a, T, U>;
|
||||
/// Gets an Iterator over Commands received by this Server.
|
||||
#[unstable = "Feature is still relatively new."]
|
||||
fn iter_cmd(&'a self) -> ServerCmdIterator<'a, T, U>;
|
||||
/// Gets a list of Users in the specified channel. This will be none if the channel is not
|
||||
/// being tracked, or if tracking is not supported altogether.
|
||||
#[stable]
|
||||
fn list_users(&self, channel: &str) -> Option<Vec<User>>;
|
||||
}
|
||||
|
||||
/// A thread-safe implementation of an IRC Server connection.
|
||||
#[stable]
|
||||
pub struct IrcServer<T: IrcRead, U: IrcWrite> {
|
||||
/// The thread-safe IRC connection.
|
||||
conn: Connection<T, U>,
|
||||
|
@ -51,21 +43,17 @@ pub struct IrcServer<T: IrcRead, U: IrcWrite> {
|
|||
}
|
||||
|
||||
/// An IrcServer over a buffered NetStream.
|
||||
#[stable]
|
||||
pub type NetIrcServer = IrcServer<BufReader<NetStream>, BufWriter<NetStream>>;
|
||||
|
||||
#[stable]
|
||||
impl IrcServer<BufReader<NetStream>, BufWriter<NetStream>> {
|
||||
/// Creates a new IRC Server connection from the configuration at the specified path,
|
||||
/// connecting immediately.
|
||||
#[stable]
|
||||
pub fn new(config: &str) -> Result<NetIrcServer> {
|
||||
IrcServer::from_config(try!(Config::load_utf8(config)))
|
||||
}
|
||||
|
||||
/// Creates a new IRC server connection from the specified configuration, connecting
|
||||
/// immediately.
|
||||
#[stable]
|
||||
pub fn from_config(config: Config) -> Result<NetIrcServer> {
|
||||
let conn = try!(if config.use_ssl() {
|
||||
Connection::connect_ssl(config.server(), config.port())
|
||||
|
@ -77,7 +65,6 @@ impl IrcServer<BufReader<NetStream>, BufWriter<NetStream>> {
|
|||
}
|
||||
|
||||
/// Reconnects to the IRC server.
|
||||
#[stable]
|
||||
pub fn reconnect(&self) -> Result<()> {
|
||||
self.conn.reconnect(self.config().server(), self.config.port())
|
||||
}
|
||||
|
@ -118,17 +105,14 @@ impl<'a, T: IrcRead, U: IrcWrite> Server<'a, T, U> for IrcServer<T, U> {
|
|||
}
|
||||
}
|
||||
|
||||
#[stable]
|
||||
impl<T: IrcRead, U: IrcWrite> IrcServer<T, U> {
|
||||
/// Creates an IRC server from the specified configuration, and any arbitrary Connection.
|
||||
#[stable]
|
||||
pub fn from_connection(config: Config, conn: Connection<T, U>) -> IrcServer<T, U> {
|
||||
IrcServer { conn: conn, config: config, chanlists: Mutex::new(HashMap::new()),
|
||||
alt_nick_index: RwLock::new(0) }
|
||||
}
|
||||
|
||||
/// Gets a reference to the IRC server's connection.
|
||||
#[stable]
|
||||
pub fn conn(&self) -> &Connection<T, U> {
|
||||
&self.conn
|
||||
}
|
||||
|
@ -271,7 +255,6 @@ impl<T: IrcRead, U: IrcWrite> IrcServer<T, U> {
|
|||
}
|
||||
|
||||
/// An Iterator over an IrcServer's incoming Messages.
|
||||
#[stable]
|
||||
pub struct ServerIterator<'a, T: IrcRead, U: IrcWrite> {
|
||||
server: &'a IrcServer<T, U>
|
||||
}
|
||||
|
@ -280,10 +263,8 @@ pub struct ServerIterator<'a, T: IrcRead, U: IrcWrite> {
|
|||
pub type ServerCmdIterator<'a, T, U> =
|
||||
Map<ServerIterator<'a, T, U>, fn(Result<Message>) -> Result<Command>>;
|
||||
|
||||
#[unstable = "Design is liable to change to accomodate new functionality."]
|
||||
impl<'a, T: IrcRead, U: IrcWrite> ServerIterator<'a, T, U> {
|
||||
/// Creates a new ServerIterator for the desired IrcServer.
|
||||
#[unstable = "Design is liable to change to accomodate new functionality."]
|
||||
pub fn new(server: &IrcServer<T, U>) -> ServerIterator<T, U> {
|
||||
ServerIterator { server: server }
|
||||
}
|
||||
|
@ -302,7 +283,6 @@ impl<'a, T: IrcRead, U: IrcWrite> ServerIterator<'a, T, U> {
|
|||
}
|
||||
|
||||
impl<'a, T: IrcRead, U: IrcWrite> Iterator for ServerIterator<'a, T, U> {
|
||||
#[stable]
|
||||
type Item = Result<Message>;
|
||||
fn next(&mut self) -> Option<Result<Message>> {
|
||||
let res = self.get_next_line().and_then(|msg|
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
//! Utilities and shortcuts for working with IRC servers.
|
||||
#![stable]
|
||||
|
||||
use std::io::Result;
|
||||
use std::borrow::ToOwned;
|
||||
|
@ -11,10 +10,8 @@ use client::data::kinds::{IrcRead, IrcWrite};
|
|||
use client::server::Server;
|
||||
|
||||
/// Extensions for Server capabilities that make it easier to work directly with the protocol.
|
||||
#[unstable = "More functionality will be added."]
|
||||
pub trait ServerExt<'a, T, U>: Server<'a, T, U> {
|
||||
/// Sends a NICK and USER to identify.
|
||||
#[unstable = "Capabilities requests may be moved outside of identify."]
|
||||
fn identify(&self) -> Result<()> {
|
||||
// We'll issue a CAP REQ for multi-prefix support to improve access level tracking.
|
||||
try!(self.send(CAP(None, REQ, None, Some("multi-prefix".to_owned()))));
|
||||
|
@ -29,25 +26,21 @@ pub trait ServerExt<'a, T, U>: Server<'a, T, U> {
|
|||
}
|
||||
|
||||
/// Sends a PONG with the specified message.
|
||||
#[stable]
|
||||
fn send_pong(&self, msg: &str) -> Result<()> {
|
||||
self.send(PONG(msg.to_owned(), None))
|
||||
}
|
||||
|
||||
/// Joins the specified channel or chanlist.
|
||||
#[stable]
|
||||
fn send_join(&self, chanlist: &str) -> Result<()> {
|
||||
self.send(JOIN(chanlist.to_owned(), None))
|
||||
}
|
||||
|
||||
/// Attempts to oper up using the specified username and password.
|
||||
#[stable]
|
||||
fn send_oper(&self, username: &str, password: &str) -> Result<()> {
|
||||
self.send(OPER(username.to_owned(), password.to_owned()))
|
||||
}
|
||||
|
||||
/// Sends a message to the specified target.
|
||||
#[stable]
|
||||
fn send_privmsg(&self, target: &str, message: &str) -> Result<()> {
|
||||
for line in message.split("\r\n") {
|
||||
try!(self.send(PRIVMSG(target.to_owned(), line.to_owned())))
|
||||
|
@ -56,7 +49,6 @@ pub trait ServerExt<'a, T, U>: Server<'a, T, U> {
|
|||
}
|
||||
|
||||
/// Sends a notice to the specified target.
|
||||
#[stable]
|
||||
fn send_notice(&self, target: &str, message: &str) -> Result<()> {
|
||||
for line in message.split("\r\n") {
|
||||
try!(self.send(NOTICE(target.to_owned(), line.to_owned())))
|
||||
|
@ -66,7 +58,6 @@ pub trait ServerExt<'a, T, U>: Server<'a, T, U> {
|
|||
|
||||
/// Sets the topic of a channel or requests the current one.
|
||||
/// If `topic` is an empty string, it won't be included in the message.
|
||||
#[unstable = "Design may change."]
|
||||
fn send_topic(&self, channel: &str, topic: &str) -> Result<()> {
|
||||
self.send(TOPIC(channel.to_owned(), if topic.len() == 0 {
|
||||
None
|
||||
|
@ -76,14 +67,12 @@ pub trait ServerExt<'a, T, U>: Server<'a, T, U> {
|
|||
}
|
||||
|
||||
/// Kills the target with the provided message.
|
||||
#[stable]
|
||||
fn send_kill(&self, target: &str, message: &str) -> Result<()> {
|
||||
self.send(KILL(target.to_owned(), message.to_owned()))
|
||||
}
|
||||
|
||||
/// Kicks the listed nicknames from the listed channels with a comment.
|
||||
/// If `message` is an empty string, it won't be included in the message.
|
||||
#[unstable = "Design may change."]
|
||||
fn send_kick(&self, chanlist: &str, nicklist: &str, message: &str) -> Result<()> {
|
||||
self.send(KICK(chanlist.to_owned(), nicklist.to_owned(), if message.len() == 0 {
|
||||
None
|
||||
|
@ -94,7 +83,6 @@ pub trait ServerExt<'a, T, U>: Server<'a, T, U> {
|
|||
|
||||
/// Changes the mode of the target.
|
||||
/// If `modeparmas` is an empty string, it won't be included in the message.
|
||||
#[unstable = "Design may change."]
|
||||
fn send_mode(&self, target: &str, mode: &str, modeparams: &str) -> Result<()> {
|
||||
self.send(MODE(target.to_owned(), mode.to_owned(), if modeparams.len() == 0 {
|
||||
None
|
||||
|
@ -105,7 +93,6 @@ pub trait ServerExt<'a, T, U>: Server<'a, T, U> {
|
|||
|
||||
/// Changes the mode of the target by force.
|
||||
/// If `modeparams` is an empty string, it won't be included in the message.
|
||||
#[unstable = "Design may change."]
|
||||
fn send_samode(&self, target: &str, mode: &str, modeparams: &str) -> Result<()> {
|
||||
self.send(SAMODE(target.to_owned(), mode.to_owned(), if modeparams.len() == 0 {
|
||||
None
|
||||
|
@ -115,20 +102,17 @@ pub trait ServerExt<'a, T, U>: Server<'a, T, U> {
|
|||
}
|
||||
|
||||
/// Forces a user to change from the old nickname to the new nickname.
|
||||
#[stable]
|
||||
fn send_sanick(&self, old_nick: &str, new_nick: &str) -> Result<()> {
|
||||
self.send(SANICK(old_nick.to_owned(), new_nick.to_owned()))
|
||||
}
|
||||
|
||||
/// Invites a user to the specified channel.
|
||||
#[stable]
|
||||
fn send_invite(&self, nick: &str, chan: &str) -> Result<()> {
|
||||
self.send(INVITE(nick.to_owned(), chan.to_owned()))
|
||||
}
|
||||
|
||||
/// Quits the server entirely with a message.
|
||||
/// This defaults to `Powered by Rust.` if none is specified.
|
||||
#[unstable = "Design may change."]
|
||||
fn send_quit(&self, msg: &str) -> Result<()> {
|
||||
self.send(QUIT(Some(if msg.len() == 0 {
|
||||
"Powered by Rust.".to_owned()
|
||||
|
@ -139,7 +123,6 @@ pub trait ServerExt<'a, T, U>: Server<'a, T, U> {
|
|||
|
||||
/// Sends a CTCP-escaped message to the specified target.
|
||||
/// This requires the CTCP feature to be enabled.
|
||||
#[stable]
|
||||
#[cfg(feature = "ctcp")]
|
||||
fn send_ctcp(&self, target: &str, msg: &str) -> Result<()> {
|
||||
self.send_privmsg(target, &format!("\u{001}{}\u{001}", msg)[..])
|
||||
|
@ -147,7 +130,6 @@ pub trait ServerExt<'a, T, U>: Server<'a, T, U> {
|
|||
|
||||
/// Sends an action command to the specified target.
|
||||
/// This requires the CTCP feature to be enabled.
|
||||
#[stable]
|
||||
#[cfg(feature = "ctcp")]
|
||||
fn send_action(&self, target: &str, msg: &str) -> Result<()> {
|
||||
self.send_ctcp(target, &format!("ACTION {}", msg)[..])
|
||||
|
@ -155,7 +137,6 @@ pub trait ServerExt<'a, T, U>: Server<'a, T, U> {
|
|||
|
||||
/// Sends a finger request to the specified target.
|
||||
/// This requires the CTCP feature to be enabled.
|
||||
#[stable]
|
||||
#[cfg(feature = "ctcp")]
|
||||
fn send_finger(&self, target: &str) -> Result<()> {
|
||||
self.send_ctcp(target, "FINGER")
|
||||
|
@ -163,7 +144,6 @@ pub trait ServerExt<'a, T, U>: Server<'a, T, U> {
|
|||
|
||||
/// Sends a version request to the specified target.
|
||||
/// This requires the CTCP feature to be enabled.
|
||||
#[stable]
|
||||
#[cfg(feature = "ctcp")]
|
||||
fn send_version(&self, target: &str) -> Result<()> {
|
||||
self.send_ctcp(target, "VERSION")
|
||||
|
@ -171,7 +151,6 @@ pub trait ServerExt<'a, T, U>: Server<'a, T, U> {
|
|||
|
||||
/// Sends a source request to the specified target.
|
||||
/// This requires the CTCP feature to be enabled.
|
||||
#[stable]
|
||||
#[cfg(feature = "ctcp")]
|
||||
fn send_source(&self, target: &str) -> Result<()> {
|
||||
self.send_ctcp(target, "SOURCE")
|
||||
|
@ -179,7 +158,6 @@ pub trait ServerExt<'a, T, U>: Server<'a, T, U> {
|
|||
|
||||
/// Sends a user info request to the specified target.
|
||||
/// This requires the CTCP feature to be enabled.
|
||||
#[stable]
|
||||
#[cfg(feature = "ctcp")]
|
||||
fn send_user_info(&self, target: &str) -> Result<()> {
|
||||
self.send_ctcp(target, "USERINFO")
|
||||
|
@ -187,7 +165,6 @@ pub trait ServerExt<'a, T, U>: Server<'a, T, U> {
|
|||
|
||||
/// Sends a finger request to the specified target.
|
||||
/// This requires the CTCP feature to be enabled.
|
||||
#[stable]
|
||||
#[cfg(feature = "ctcp")]
|
||||
fn send_ctcp_ping(&self, target: &str) -> Result<()> {
|
||||
let time = get_time();
|
||||
|
@ -196,7 +173,6 @@ pub trait ServerExt<'a, T, U>: Server<'a, T, U> {
|
|||
|
||||
/// Sends a time request to the specified target.
|
||||
/// This requires the CTCP feature to be enabled.
|
||||
#[stable]
|
||||
#[cfg(feature = "ctcp")]
|
||||
fn send_time(&self, target: &str) -> Result<()> {
|
||||
self.send_ctcp(target, "TIME")
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
//! A simple, thread-safe IRC library.
|
||||
#![crate_name = "irc"]
|
||||
#![crate_type = "lib"]
|
||||
#![unstable]
|
||||
#![warn(missing_docs)]
|
||||
|
||||
#[cfg(feature = "ctcp")] extern crate time;
|
||||
|
|
|
@ -1,2 +1 @@
|
|||
//! A simple, thread-safe IRC server library.
|
||||
#![unstable = "This has yet to be written."]
|
||||
|
|
Loading…
Add table
Reference in a new issue