From fbb7251493ff5a9bc42f849b9b781e69aef9d184 Mon Sep 17 00:00:00 2001 From: Till Hoeppner Date: Mon, 4 May 2015 21:14:52 +0200 Subject: More control about SSL methods, and proper selection between ssl vs plain at compile time in example --- examples/01.rs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'examples/01.rs') diff --git a/examples/01.rs b/examples/01.rs index 595bc70..96848f6 100644 --- a/examples/01.rs +++ b/examples/01.rs @@ -1,5 +1,7 @@ extern crate irsc; extern crate env_logger; +#[cfg(feature = "ssl")] +extern crate openssl; use std::borrow::ToOwned; use std::borrow::Cow::*; @@ -10,6 +12,9 @@ use irsc::*; use irsc::Command::*; use irsc::Reply::*; +#[cfg(feature = "ssl")] +use openssl::ssl::{ Ssl, SslContext, SslMethod }; + static NAME: &'static str = "rusticbot"; static DESC: &'static str = "A bot, written in Rust."; @@ -39,14 +44,21 @@ fn callback(server: &mut Client, msg: &Message) { } } +#[cfg(feature = "ssl")] +fn connect(s: &mut Client) { + let ssl = Ssl::new(&SslContext::new(SslMethod::Tlsv1).unwrap()).unwrap(); + s.connect_ssl("irc.mozilla.org".to_owned(), 6697, ssl).unwrap(); +} + +#[cfg(not(feature = "ssl"))] +fn connect(s: &mut Client) { + s.connect("irc.mozilla.org".to_owned(), 6667).unwrap(); +} + fn main() { env_logger::init().unwrap(); let mut s = Client::new(); - if cfg!(feature = "ssl") { - s.connect_ssl("irc.mozilla.org".to_owned(), 6697).unwrap(); - } else { - s.connect("irc.mozilla.org".to_owned(), 6667).unwrap(); - } + connect(&mut s); s.send(NICK(Borrowed(NAME))).unwrap(); s.send(USER(Borrowed(NAME), Borrowed("*"), Borrowed("*"), Borrowed(DESC))).unwrap(); -- cgit v1.2.3