Changed main to only look at the config once instead of per connection

This commit is contained in:
int 80h
2020-05-06 23:19:34 -04:00
parent 83163f9a95
commit a066e54acc
3 changed files with 58 additions and 40 deletions

View File

@@ -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