diff options
Diffstat (limited to 'rust/src/main.rs')
-rw-r--r-- | rust/src/main.rs | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/rust/src/main.rs b/rust/src/main.rs index 6338557..7a05c8b 100644 --- a/rust/src/main.rs +++ b/rust/src/main.rs @@ -1,9 +1,9 @@ use std::env; -use std::collections::HashSet; use std::iter::repeat; use std::sync::Arc; use std::thread; +extern crate ascii; extern crate crypto; extern crate env_logger; extern crate getopts; @@ -20,6 +20,7 @@ use rand::{thread_rng, Rng}; mod apachelog; mod handler; +mod message; mod sendxmpp; mod token; @@ -36,10 +37,10 @@ fn main() { let mut opts = Options::new(); opts.optopt("j", "jid", "bot jid", "JID"); opts.optopt("p", "password", "bot password", "PASSWORD"); - opts.optmulti("u", "user", "add valid user", "USER"); opts.optopt("s", "secret", "server secret for token generation", "SECRET"); opts.optopt("t", "time", "Validity of the token in hours (default 48)", "HOURS"); opts.optopt("o", "port", "TCP Port to listen on", "PORT"); + opts.optflag("n", "nosend", "Don't send XMPP message, just print debug infos"); opts.optflag("h", "help", "print this help menu"); let matches = opts.parse(&args[1..]).unwrap_or_else(|f| panic!(f.to_string())); @@ -48,12 +49,11 @@ fn main() { return; } - if !(matches.opt_present("j") && matches.opt_present("p")) { + if !(matches.opt_present("j") && matches.opt_present("p")) && !matches.opt_present("n") { print_usage(&program, opts); panic!("Missing jid or password"); } - let usernames = matches.opt_strs("u").into_iter().collect::<HashSet<String>>(); let mut hasher = Sha1::new(); let mut secret: Vec<u8> = repeat(0).take((hasher.output_bits() + 7) / 8).collect(); matches.opt_str("s").and_then(|s| { @@ -70,20 +70,20 @@ fn main() { let port = matches.opt_str("o").unwrap_or(String::from("8080")).parse() .unwrap_or_else(|_| { panic!("Failed to parse port number") }); - let handler = handler::AuthHandler::make(matches.opt_str("j").unwrap(), - matches.opt_str("p").unwrap(), - usernames, + let handler = handler::AuthHandler::make(matches.opt_str("j").unwrap_or(String::from("<jid>")), + matches.opt_str("p").unwrap_or(String::from("<password>")), time::Duration::hours(validity), - secret); + secret, + matches.opt_present("n")); let handler = Arc::new(handler); let server = Arc::new(tiny_http::Server::http(("0.0.0.0", port)).unwrap()); - let mut handles = Vec::new(); + let mut threads = Vec::new(); for _ in 0..2 { let server = server.clone(); let handler = handler.clone(); - handles.push(thread::spawn(move || { + threads.push(thread::spawn(move || { for request in server.incoming_requests() { let mut log = apachelog::LogEntry::start(&request); let response = handler.call(&request); @@ -92,7 +92,7 @@ fn main() { } })); } - for h in handles { + for h in threads { h.join().unwrap(); } }
\ No newline at end of file |