Changed main to only look at the config once instead of per connection
This commit is contained in:
@@ -22,22 +22,42 @@ pub struct Server {
|
||||
pub usrdir: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct ServerCfg {
|
||||
pub hostname: String,
|
||||
pub dir: String,
|
||||
pub key: String,
|
||||
pub cert: String,
|
||||
pub cgi: String,
|
||||
pub usrdir: bool,
|
||||
pub port: i32,
|
||||
}
|
||||
|
||||
impl Config {
|
||||
pub fn new(file: &Path) -> Result<Config, Error> {
|
||||
let fd = std::fs::read_to_string(file).unwrap();
|
||||
let config: Config = toml::from_str(&fd).unwrap();
|
||||
return Ok(config);
|
||||
}
|
||||
pub fn to_map(&self) -> HashMap<String, Server> {
|
||||
pub fn to_map(&self) -> HashMap<String, ServerCfg> {
|
||||
let mut map = HashMap::new();
|
||||
for srv in &self.server {
|
||||
map.insert(srv.hostname.clone(), Server {
|
||||
let cgi = match srv.cgi.to_owned() {
|
||||
Some(c) => c,
|
||||
None => "".to_string(),
|
||||
};
|
||||
let usrdir = match srv.usrdir {
|
||||
Some(u) => u,
|
||||
None => false,
|
||||
};
|
||||
map.insert(srv.hostname.clone(), ServerCfg {
|
||||
hostname: srv.hostname.clone(),
|
||||
dir: srv.dir.clone(),
|
||||
key: srv.key.clone(),
|
||||
cert: srv.cert.clone(),
|
||||
cgi: srv.cgi.clone(),
|
||||
usrdir: srv.usrdir.clone(),
|
||||
cgi: cgi,
|
||||
usrdir: usrdir,
|
||||
port: self.port.clone(),
|
||||
});
|
||||
}
|
||||
map
|
||||
|
||||
Reference in New Issue
Block a user