Eliminated feature use for beta.

This commit is contained in:
Aaron Weiss 2015-04-04 23:06:13 -04:00
parent b68f7fc726
commit c26d297e62
8 changed files with 57 additions and 33 deletions

View file

@ -13,7 +13,8 @@ fn main() {
.. Default::default()
};
let server = Arc::new(IrcServer::from_config(config).unwrap());
server.conn().set_keepalive(Some(5)).unwrap();
// FIXME: if set_keepalive is stabilized, this can be readded.
// server.conn().set_keepalive(Some(5)).unwrap();
let server = server.clone();
let _ = spawn(move || {
server.identify().unwrap();

View file

@ -86,6 +86,9 @@ impl Connection<BufReader<NetStream>, BufWriter<NetStream>> {
Ok(())
}
/*
FIXME: removed until set_keepalive is stabilized.
/// Sets the keepalive for the network stream.
#[unstable = "Rust IO has not stabilized."]
pub fn set_keepalive(&self, delay_in_seconds: Option<u32>) -> Result<()> {
@ -100,6 +103,7 @@ impl Connection<BufReader<NetStream>, BufWriter<NetStream>> {
&mut NetStream::SslTcpStream(ref mut ssl) => f(ssl.get_mut()),
}
}
*/
}
#[stable]
@ -337,15 +341,14 @@ mod test {
#[test]
#[cfg(feature = "encode")]
fn recv_iso885915() {
let conn = Connection::new(
Cursor::new({
let data = [0xA4, 0xA6, 0xA8, 0xB4, 0xB8, 0xBC, 0xBD, 0xBE];
let conn = Connection::new(Cursor::new({
let mut vec = Vec::new();
vec.push_all(b"PRIVMSG test :");
vec.push_all(&[0xA4, 0xA6, 0xA8, 0xB4, 0xB8, 0xBC, 0xBD, 0xBE]);
vec.push_all(b"\r\n");
vec
}), sink()
);
vec.extend("PRIVMSG test :".as_bytes());
vec.extend(data.iter());
vec.extend("\r\n".as_bytes());
vec.into_iter().map(|b| *b).collect::<Vec<_>>()
}), sink());
assert_eq!(&conn.recv("l9").unwrap()[..], "PRIVMSG test :€ŠšŽžŒœŸ\r\n");
}
}

View file

@ -1089,7 +1089,7 @@ impl Command {
/// A list of all of the subcommands for the capabilities extension.
#[stable]
#[derive(Copy, Debug, PartialEq)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum CapSubCommand {
/// Requests a list of the server's capabilities.
#[stable]

View file

@ -83,7 +83,7 @@ impl Config {
/// 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(&String::from_str(nickname))).unwrap()
self.owners.as_ref().map(|o| o.contains(&nickname.to_string())).unwrap()
}
/// Gets the nickname specified in the configuration.

View file

@ -1,13 +1,13 @@
//! Enumeration of all the possible server responses.
#![stable]
#![allow(non_camel_case_types)]
use std::num::FromPrimitive;
use std::mem::transmute;
use std::str::FromStr;
use client::data::message::Message;
/// List of all server responses as defined in [RFC 2812](http://tools.ietf.org/html/rfc2812).
/// All commands are documented with their expected form from the RFC.
#[derive(Copy, Debug, PartialEq, FromPrimitive)]
#[derive(Clone, Copy, Debug, PartialEq, FromPrimitive)]
#[repr(u16)]
#[stable]
pub enum Response {
@ -448,8 +448,23 @@ impl Response {
impl FromStr for Response {
type Err = &'static str;
fn from_str(s: &str) -> Result<Response, &'static str> {
if let Ok(respcode) = s.parse() {
FromPrimitive::from_u16(respcode).ok_or("Failed to convert response code to u16.")
if let Ok(rc) = s.parse::<u16>() {
// This wall of text was brought to you by the slated removal of FromPrimitive.
if (rc > 0 && rc < 5) || (rc > 200 && rc < 213) || rc == 219 || rc == 221 || rc == 234
|| rc == 235 || rc == 242 || rc == 243 || (rc > 250 && rc < 260) ||
(rc > 260 && rc < 264) || (rc > 300 && rc < 307) ||
(rc > 310 && rc < 326 && rc != 320) || rc == 331 || rc == 332 || rc == 341 ||
rc == 342 || (rc > 345 && rc < 354 && rc != 350) ||
(rc > 363 && rc < 377 && rc != 370) || (rc > 380 && rc < 384) ||
(rc > 390 && rc < 396) || (rc > 400 && rc < 415 && rc != 410) ||
(rc > 420 && rc < 425) || (rc > 430 && rc < 434) || rc == 436 || rc == 437 ||
(rc > 440 && rc < 447) || rc == 451 || (rc > 460 && rc < 468) ||
(rc > 470 && rc < 479) || (rc > 480 && rc < 486) || rc == 491 || rc == 501 ||
rc == 502 {
Ok(unsafe { transmute(rc) })
} else {
Err("Failed to parse due to unknown response code.")
}
} else {
Err("Failed to parse response code.")
}

View file

@ -88,7 +88,7 @@ impl User {
/// Removes an access level from the list, and updates the highest level if necessary.
fn sub_access_level(&mut self, level: AccessLevel) {
if let Some(n) = self.access_levels[..].position_elem(&level) {
if let Some(n) = self.access_levels.iter().position(|x| *x == level) {
self.access_levels.swap_remove(n);
}
if level == self.highest_access_level() {
@ -176,15 +176,14 @@ impl PartialOrd for AccessLevel {
impl FromStr for AccessLevel {
type Err = &'static str;
fn from_str(s: &str) -> Result<AccessLevel, &'static str> {
if s.len() == 0 { Err("No access level in an empty string.") } else {
Ok(match s.char_at(0) {
'~' => AccessLevel::Owner,
'&' => AccessLevel::Admin,
'@' => AccessLevel::Oper,
'%' => AccessLevel::HalfOp,
'+' => AccessLevel::Voice,
_ => return Err("Failed to parse access level."),
})
match s.chars().next() {
Some('~') => Ok(AccessLevel::Owner),
Some('&') => Ok(AccessLevel::Admin),
Some('@') => Ok(AccessLevel::Oper),
Some('%') => Ok(AccessLevel::HalfOp),
Some('+') => Ok(AccessLevel::Voice),
None => Err("No access level in an empty string."),
_ =>Err("Failed to parse access level."),
}
}
}

View file

@ -139,7 +139,9 @@ impl<T: IrcRead, U: IrcWrite> IrcServer<T, U> {
if resp == Response::RPL_NAMREPLY {
if cfg!(not(feature = "nochanlists")) {
if let Some(users) = msg.suffix.clone() {
if let [_, _, ref chan] = &msg.args[..] {
if msg.args.len() == 3 {
// TODO: replace with slice pattern matching when/if stable
let ref chan = msg.args[2];
for user in users.split(" ") {
if match self.chanlists.lock().unwrap().get_mut(chan) {
Some(vec) => { vec.push(User::new(user)); false },
@ -186,23 +188,26 @@ impl<T: IrcRead, U: IrcWrite> IrcServer<T, U> {
Some(ref suffix) => &suffix[..],
None => &msg.args[0][..],
};
if let Some(vec) = self.chanlists.lock().unwrap().get_mut(&String::from_str(chan)) {
if let Some(vec) = self.chanlists.lock().unwrap().get_mut(&chan.to_string()) {
if let Some(ref src) = msg.prefix {
if let Some(i) = src.find('!') {
if &msg.command[..] == "JOIN" {
vec.push(User::new(&src[..i]));
} else {
if let Some(n) = vec.position_elem(&User::new(&src[..i])) {
if let Some(n) = vec.iter().position(|x| x.get_name() == &src[..i]) {
vec.swap_remove(n);
}
}
}
}
}
} else if let ("MODE", [ref chan, ref mode, ref user]) = (&msg.command[..], &msg.args[..]) {
} else if let ("MODE", 3) = (&msg.command[..], msg.args.len()) {
let ref chan = msg.args[0]; // TODO: replace with slice pattern matching when/if stable
let ref mode = msg.args[1];
let ref user = msg.args[2];
if cfg!(not(feature = "nochanlists")) {
if let Some(vec) = self.chanlists.lock().unwrap().get_mut(chan) {
if let Some(n) = vec.position_elem(&User::new(&user)) {
if let Some(n) = vec.iter().position(|x| &x.get_name() == user) {
vec[n].update_access_level(&mode);
}
}
@ -219,7 +224,9 @@ impl<T: IrcRead, U: IrcWrite> IrcServer<T, U> {
Some(ref source) => source.find('!').map_or(&source[..], |i| &source[..i]),
None => "",
};
if let ("PRIVMSG", [ref target]) = (&msg.command[..], &msg.args[..]) {
if let ("PRIVMSG", 1) = (&msg.command[..], msg.args.len()) {
// TODO: replace with slice pattern matching when/if stable
let ref target = msg.args[0];
let resp = if target.starts_with("#") { &target[..] } else { source };
match msg.suffix {
Some(ref msg) if msg.starts_with("\u{001}") => {

View file

@ -4,7 +4,6 @@
#![unstable]
#![warn(missing_docs)]
#![feature(collections, core, slice_patterns, str_char, tcp)]
#[cfg(feature = "ctcp")] extern crate time;
#[cfg(feature = "encode")] extern crate encoding;
extern crate rustc_serialize;