diff --git a/example.rori b/example.rori new file mode 100644 index 0000000..af2c82e --- /dev/null +++ b/example.rori @@ -0,0 +1,7 @@ +((jobs-dir "/etc/rori.kron") + (debug t) + (allow + :all) + (deny + (:user "flon") + (:uid 8008))) diff --git a/src/config/global.rs b/src/config/global.rs index 9a6eb23..96e3b89 100644 --- a/src/config/global.rs +++ b/src/config/global.rs @@ -21,8 +21,8 @@ pub enum UserPermAlias { #[derive(Debug, PartialEq,Eq,Hash)] pub struct UserRule { - user: UserPermAlias, - mode: Access, + pub user: UserPermAlias, + pub mode: Access, } /// Global user config diff --git a/src/config/parse.rs b/src/config/parse.rs index 63a2a28..20b64ed 100644 --- a/src/config/parse.rs +++ b/src/config/parse.rs @@ -17,14 +17,36 @@ fn get_atom_string<'a>(maybe_atom: &'a Sexp) -> Result<&'a String, Error> } } -fn new_job(to: &mut Config, cdr: &[Sexp]) -> Result<(), Error> { - let what = &cdr[0]; - let what = get_atom_string(what)?; - to.job_dirs.push(PathBuf::from(what)); +#[inline] +fn add_job(to: &mut Config, cdr: &[Sexp]) -> Result<(), Error> { + to.job_dirs.push(PathBuf::from(get_atom_string(&cdr[0])?)); Ok(()) } +#[inline] +fn set_debug(to: &mut Config, cdr: &[Sexp]) -> Result<(), Error> { + if !to.debug { + let debug = get_atom_string(&cdr[0])?; + to.debug = match debug.to_lowercase().trim() { + "t" => true, + "nil" => false, + _ => return Err(Error::Unknown) + }; + } else { + // Should be debug is set. + return Err(Error::Unknown) + } + + Ok(()) +} + +#[inline] +fn mwee(to: &mut Config, cdr: &[Sexp]) -> Result<(), Error> { + println!("{:?}", cdr); + Ok(()) +} + /// Parse a single config file pub async fn global(to: &mut Config, path: impl AsRef) -> Result<(), error::Error> { @@ -48,10 +70,10 @@ pub async fn global(to: &mut Config, path: impl AsRef) -> Result<(), error Sexp::Atom(car) => { if let Atom::S(car) = car { match car.to_lowercase().trim() { - "jobs-dir" => new_job(to, cdr), - "debug" => new_job(to, cdr), - "allow" => new_job(to, cdr), - "deny" => new_job(to, cdr), + "jobs-dir" => add_job(to, cdr), + "debug" => set_debug(to ,cdr), + "allow" => mwee(to, cdr), + "deny" => mwee(to, cdr), _ => return Err(Error::Unknown), }?; } else {