From 5688e8c4bbc981404dbc8460bed5d228f239932d Mon Sep 17 00:00:00 2001 From: dvkt Date: Mon, 6 Jan 2020 10:26:58 -0800 Subject: [PATCH] cargo build --features disable-tls --- Cargo.toml | 4 ++-- README.md | 4 ++++ src/gopher.rs | 25 ++++++++++++++----------- src/lib.rs | 4 ++-- src/main.rs | 2 +- 5 files changed, 23 insertions(+), 16 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 72d9f0f..eac4d44 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,8 +14,8 @@ exclude = [ ] [features] -tls = [] -default =["tls"] +disable-tls = [] +default =[] [profile.release] lto = true diff --git a/README.md b/README.md index 5ea7a88..01d8e6f 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,10 @@ to build with TLS support on **linux**, you need `openssl` and sudo apt install -y pkg-config libssl-dev +to build without TLS support, build with the `no-tls` feature: + + + ## screenies ![DOS Archive](./img/dos.png) diff --git a/src/gopher.rs b/src/gopher.rs index f6603d1..34d3a85 100644 --- a/src/gopher.rs +++ b/src/gopher.rs @@ -7,7 +7,7 @@ use std::{ }; use termion::input::TermRead; -#[cfg(feature = "tls")] +#[cfg(not(feature = "disable-tls"))] use native_tls::TlsConnector; mod r#type; @@ -113,16 +113,19 @@ pub fn request(host: &str, port: &str, selector: &str, try_tls: bool) -> Result< .and_then(|mut socks| socks.next().ok_or_else(|| error!("Can't create socket")))?; // attempt tls connection - if cfg!(feature = "tls") && try_tls { - if let Ok(connector) = TlsConnector::new() { - let stream = TcpStream::connect_timeout(&sock, TCP_TIMEOUT_DURATION)?; - stream.set_read_timeout(Some(TCP_TIMEOUT_DURATION))?; - if let Ok(mut stream) = connector.connect(host, stream) { - stream.write(format!("{}\r\n", selector).as_ref())?; - return Ok(Stream { - io: Box::new(stream), - tls: true, - }); + #[cfg(not(feature = "disable-tls"))] + { + if try_tls { + if let Ok(connector) = TlsConnector::new() { + let stream = TcpStream::connect_timeout(&sock, TCP_TIMEOUT_DURATION)?; + stream.set_read_timeout(Some(TCP_TIMEOUT_DURATION))?; + if let Ok(mut stream) = connector.connect(host, stream) { + stream.write(format!("{}\r\n", selector).as_ref())?; + return Ok(Stream { + io: Box::new(stream), + tls: true, + }); + } } } } diff --git a/src/lib.rs b/src/lib.rs index f502d94..6cb0170 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -17,7 +17,7 @@ pub const GIT_REF: &str = env!("GIT_REF"); pub const BUILD_DATE: &str = env!("BUILD_DATE"); pub const BUG_URL: &str = "https://github.com/dvkt/phetch/issues/new"; -#[cfg(feature = "tls")] +#[cfg(not(feature = "disable-tls"))] pub const TLS_SUPPORT: &str = "enabled"; -#[cfg(not(feature = "tls"))] +#[cfg(feature = "disable-tls")] pub const TLS_SUPPORT: &str = "not enabled"; diff --git a/src/main.rs b/src/main.rs index 9bbfd07..4b8f217 100644 --- a/src/main.rs +++ b/src/main.rs @@ -32,7 +32,7 @@ fn run() -> i32 { "-l" | "--local" | "-local" => url = "gopher://127.0.0.1:7070", "-t" | "--tls" | "-tls" => { tls = true; - if !cfg!(feature = "tls") { + if cfg!(feature = "disable-tls") { eprintln!("phetch was compiled without TLS support"); return 1; }