From 1fd5668def8a8c6ba155cf926bccb519d041c0f7 Mon Sep 17 00:00:00 2001 From: Aaron Weiss Date: Sun, 15 Jan 2017 13:31:50 -0500 Subject: [PATCH] Removed optional encoding feature, forcing encoding always. Temporarily purged SSL support. --- Cargo.toml | 24 +++----- src/client/conn.rs | 118 ++------------------------------------- src/client/server/mod.rs | 13 ----- src/lib.rs | 3 +- 4 files changed, 13 insertions(+), 145 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2ef59fa..987ee96 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,22 +12,14 @@ readme = "README.md" [features] -default = ["ctcp", "encode", "ssl"] +default = ["ctcp"] ctcp = [] -encode = ["encoding"] -ssl = ["openssl"] nochanlists = [] -[dependencies.rustc-serialize] -version = "0.3" - -[dependencies.time] -version = "0.1" - -[dependencies.encoding] -version = "0.2" -optional = true - -[dependencies.openssl] -version = "0.7" -optional = true +[dependencies] +rustc-serialize = "0.3.0" +time = "0.1.0" +encoding = "0.2.0" +tokio-core = "0.1.3" +tokio-proto = "0.1.0" +tokio-service = "0.1.0" diff --git a/src/client/conn.rs b/src/client/conn.rs index b5f11a0..f98fdb0 100644 --- a/src/client/conn.rs +++ b/src/client/conn.rs @@ -1,45 +1,23 @@ //! Thread-safe connections on IrcStreams. -#[cfg(feature = "ssl")] use std::error::Error as StdError; use std::io::prelude::*; use std::io::{BufReader, BufWriter, Cursor, Result}; -#[cfg(feature = "ssl")] use std::io::Error; -#[cfg(feature = "ssl")] use std::io::ErrorKind; use std::net::TcpStream; -#[cfg(feature = "ssl")] use std::result::Result as StdResult; use std::sync::Mutex; -#[cfg(feature = "encode")] use encoding::DecoderTrap; -#[cfg(feature = "encode")] use encoding::label::encoding_from_whatwg_label; -#[cfg(feature = "ssl")] use openssl::ssl::{SslContext, SslMethod, SslStream}; -#[cfg(feature = "ssl")] use openssl::ssl::error::SslError; +use encoding::DecoderTrap; +use encoding::label::encoding_from_whatwg_label; /// A connection. pub trait Connection { /// Sends a message over this connection. - #[cfg(feature = "encode")] fn send(&self, msg: &str, encoding: &str) -> Result<()>; - /// Sends a message over this connection. - #[cfg(not(feature = "encode"))] - fn send(&self, msg: &str) -> Result<()>; - /// Receives a single line from this connection. - #[cfg(feature = "encoding")] fn recv(&self, encoding: &str) -> Result; - /// Receives a single line from this connection. - #[cfg(not(feature = "encoding"))] - fn recv(&self) -> Result; - /// Gets the full record of all sent messages if the Connection records this. /// This is intended for use in writing tests. - #[cfg(feature = "encoding")] fn written(&self, encoding: &str) -> Option; - /// Gets the full record of all sent messages if the Connection records this. - /// This is intended for use in writing tests. - #[cfg(not(feature = "encoding"))] - fn written(&self) -> Option; - /// Re-establishes this connection, disconnecting from the existing case if necessary. fn reconnect(&self) -> Result<()>; } @@ -88,70 +66,28 @@ impl NetConnection { Ok(NetConnection::new(host, port, reader, writer)) } - /// Connects over SSL to the specified server and returns a reader-writer pair. - #[cfg(feature = "ssl")] - fn connect_ssl_internal(host: &str, port: u16) -> Result { - let socket = try!(TcpStream::connect(&format!("{}:{}", host, port)[..])); - let ssl = try!(ssl_to_io(SslContext::new(SslMethod::Tlsv1))); - let ssl_socket = try!(ssl_to_io(SslStream::connect_generic(&ssl, socket))); - Ok((BufReader::new(NetStream::Ssl(try!(ssl_socket.try_clone()))), - BufWriter::new(NetStream::Ssl(ssl_socket)))) - } - /// Panics because SSL support is not compiled in. - #[cfg(not(feature = "ssl"))] fn connect_ssl_internal(host: &str, port: u16) -> Result { panic!("Cannot connect to {}:{} over SSL without compiling with SSL support.", host, port) } } -/// Converts a Result into an Result. -#[cfg(feature = "ssl")] -fn ssl_to_io(res: StdResult) -> Result { - match res { - Ok(x) => Ok(x), - Err(e) => Err(Error::new(ErrorKind::Other, - &format!("An SSL error occurred. ({})", e.description())[..] - )), - } -} - impl Connection for NetConnection { - #[cfg(feature = "encode")] fn send(&self, msg: &str, encoding: &str) -> Result<()> { imp::send(&self.writer, msg, encoding) } - #[cfg(not(feature = "encode"))] - fn send(&self, msg: &str) -> Result<()> { - imp::send(&self.writer, msg) - } - - #[cfg(feature = "encoding")] fn recv(&self, encoding: &str) -> Result { imp::recv(&self.reader, encoding) } - #[cfg(not(feature = "encoding"))] - fn recv(&self) -> Result { - imp::recv(&self.reader) - } - - #[cfg(feature = "encoding")] fn written(&self, _: &str) -> Option { None } - #[cfg(not(feature = "encoding"))] - fn written(&self) -> Option { - None - } - fn reconnect(&self) -> Result<()> { let use_ssl = match *self.reader.lock().unwrap().get_ref() { NetStream::Unsecured(_) => false, - #[cfg(feature = "ssl")] - NetStream::Ssl(_) => true, }; let host = self.host.lock().unwrap(); let port = self.port.lock().unwrap(); @@ -193,54 +129,34 @@ impl MockConnection { } impl Connection for MockConnection { - #[cfg(feature = "encode")] fn send(&self, msg: &str, encoding: &str) -> Result<()> { imp::send(&self.writer, msg, encoding) } - #[cfg(not(feature = "encode"))] - fn send(&self, msg: &str) -> Result<()> { - imp::send(&self.writer, msg) - } - - #[cfg(feature = "encoding")] fn recv(&self, encoding: &str) -> Result { imp::recv(&self.reader, encoding) } - #[cfg(not(feature = "encoding"))] - fn recv(&self) -> Result { - imp::recv(&self.reader) - } - - #[cfg(feature = "encoding")] fn written(&self, encoding: &str) -> Option { encoding_from_whatwg_label(encoding).and_then(|enc| enc.decode(&self.writer.lock().unwrap(), DecoderTrap::Replace).ok() ) } - #[cfg(not(feature = "encoding"))] - fn written(&self) -> Option { - String::from_utf8(self.writer.lock().unwrap().clone()).ok() - } - fn reconnect(&self) -> Result<()> { Ok(()) } } mod imp { - use std::io::prelude::*; use std::io::Result; use std::io::Error; use std::io::ErrorKind; use std::sync::Mutex; - #[cfg(feature = "encode")] use encoding::{DecoderTrap, EncoderTrap, Encoding}; - #[cfg(feature = "encode")] use encoding::label::encoding_from_whatwg_label; + use encoding::{DecoderTrap, EncoderTrap}; + use encoding::label::encoding_from_whatwg_label; use client::data::kinds::{IrcRead, IrcWrite}; - #[cfg(feature = "encode")] pub fn send(writer: &Mutex, msg: &str, encoding: &str) -> Result<()> { let encoding = match encoding_from_whatwg_label(encoding) { Some(enc) => enc, @@ -259,14 +175,6 @@ mod imp { writer.flush() } - #[cfg(not(feature = "encode"))] - pub fn send(writer: &Mutex, msg: &str) -> Result<()> { - let mut writer = writer.lock().unwrap(); - try!(writer.write_all(msg.as_bytes())); - writer.flush() - } - - #[cfg(feature = "encoding")] pub fn recv(reader: &Mutex, encoding: &str) -> Result { let encoding = match encoding_from_whatwg_label(encoding) { Some(enc) => enc, @@ -286,26 +194,12 @@ mod imp { ) } - #[cfg(not(feature = "encoding"))] - pub fn recv(reader: &Mutex) -> Result { - let mut ret = String::new(); - try!(reader.lock().unwrap().read_line(&mut ret)); - if ret.is_empty() { - Err(Error::new(ErrorKind::Other, "EOF")) - } else { - Ok(ret) - } - } } /// An abstraction over different networked streams. pub enum NetStream { /// An unsecured TcpStream. Unsecured(TcpStream), - /// An SSL-secured TcpStream. - /// This is only available when compiled with SSL support. - #[cfg(feature = "ssl")] - Ssl(SslStream), } impl Read for NetStream { @@ -322,16 +216,12 @@ impl Write for NetStream { fn write(&mut self, buf: &[u8]) -> Result { match *self { NetStream::Unsecured(ref mut stream) => stream.write(buf), - #[cfg(feature = "ssl")] - NetStream::Ssl(ref mut stream) => stream.write(buf), } } fn flush(&mut self) -> Result<()> { match *self { NetStream::Unsecured(ref mut stream) => stream.flush(), - #[cfg(feature = "ssl")] - NetStream::Ssl(ref mut stream) => stream.flush(), } } } diff --git a/src/client/server/mod.rs b/src/client/server/mod.rs index b48d7b8..c1fa8e1 100644 --- a/src/client/server/mod.rs +++ b/src/client/server/mod.rs @@ -130,15 +130,9 @@ impl ServerState { self.action_taken(); } - #[cfg(feature = "encode")] fn write>(&self, msg: M) -> Result<()> { self.conn.send(&msg.into().to_string(), self.config.encoding()) } - - #[cfg(not(feature = "encode"))] - fn write>(&self, msg: M) -> Result<()> { - self.conn.send(&msg.into().to_string()) - } } impl IrcServer { @@ -505,16 +499,9 @@ impl<'a> ServerIterator<'a> { } /// Gets the next line from the connection. - #[cfg(feature = "encode")] fn get_next_line(&self) -> Result { self.server.conn().recv(self.server.config().encoding()) } - - /// Gets the next line from the connection. - #[cfg(not(feature = "encode"))] - fn get_next_line(&self) -> Result { - self.server.conn().recv() - } } impl<'a> Iterator for ServerIterator<'a> { diff --git a/src/lib.rs b/src/lib.rs index a74270b..3070838 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,9 +3,8 @@ #![warn(missing_docs)] extern crate time; -#[cfg(feature = "encode")] extern crate encoding; +extern crate encoding; extern crate rustc_serialize; -#[cfg(feature = "ssl")] extern crate openssl; pub mod client; pub mod server;