use serde::{Serialize, Deserialize}; use shm_rs::Lexer; use shm_rs::scheme_composer::composer::from_struct; use shm_rs::serializator::serializator; use shm_rs::static_scheme::init; use shm_rs::dynamic_scheme::environment; pub const STATUS: u64 = 5; pub const SHA1: &'static str = "SCRAM-SHA-1"; pub const RELOAD: u64 = 2; pub const LOOKUP: u64 = 4; pub const SHA512: &'static str = "SCRAM-SHA-512"; pub const FAST: u64 = 3; pub const LOAD: u64 = 3; pub const UNBAN: u64 = 1; pub const SHA256: &'static str = "SCRAM-SHA-256"; pub const BEST: u64 = 7; pub const WITHOUT: u64 = 0; pub const BAN: u64 = 0; #[derive(Clone, Debug, Serialize, Deserialize)] pub struct LdGlobal { pub searchwin: i64, pub retrycnt: u64, pub maxscore: u64, pub bantime: i64, pub ignhosts: Vec, pub ignusers: Vec } #[derive(Clone, Debug, Serialize, Deserialize)] pub struct LdJail { pub pwuser: Option, pub chroot: Option, pub capsicum_flag: Option, pub sigguard_max: Option } #[derive(Clone, Debug, Serialize, Deserialize)] pub struct LdActionThreadExec { pub thr_worker: u64, pub thr_block: Option, pub par_acts: Option } #[derive(Clone, Debug, Serialize, Deserialize)] pub enum SocketType { Unix{ path: String, chmod: u16 }, Tcp{ addr: String, port: u16 } } #[derive(Clone, Debug, Serialize, Deserialize)] pub struct LdCtrlPassword { pub shatype: String, pub salted_password_b64: String, pub salt_b64: String, pub iterations: u32 } #[derive(Clone, Debug, Serialize, Deserialize)] pub enum LdAclEntity { Cidr(String), Lfs(String) } #[derive(Clone, Debug, Serialize, Deserialize)] pub struct LdCtrlAcl { pub aclname: String, pub caplist: Vec, pub entity: LdAclEntity, pub limit: u64 } #[derive(Clone, Debug, Serialize, Deserialize)] pub struct LdControl { pub enabled: bool, pub source: SocketType, pub limitconn: u16, pub readtimeout: u64, pub servname: String, pub password: Option, pub force_acl: bool, pub enablelog: bool, pub acls: Option> } #[derive(Clone, Debug, Serialize, Deserialize)] pub enum DestinationType { Network{ addr: String, port: u16 }, Local{ path: String, chmod: u16 } } #[derive(Clone, Debug, Serialize, Deserialize)] pub struct MysqlSslPkcs { pub path_to_cert: String, pub password: String } #[derive(Clone, Debug, Serialize, Deserialize)] pub struct MysqlSsl { pub pkcs12: Option, pub path_to_ca: Option, pub accpet_inv_certs: bool, pub skip_dom_validation: bool } #[derive(Clone, Debug, Serialize, Deserialize)] pub enum Database { None, File{ dir_path: String, rotate_size: Option, compress: Option }, Sqlite{ dir_path: String }, Mysql{ dest: DestinationType, dbname: String, username: String, password: Option, compr: Option, ssl: Option } } #[derive(Clone, Debug, Serialize, Deserialize)] pub struct LdEntityWorker { pub ramlimit: u64, pub log_facilities: Option>, pub database: Database } #[derive(Clone, Debug, Serialize, Deserialize)] pub struct LdSockThread { pub threads: u64 } #[derive(Clone, Debug, Serialize, Deserialize)] pub struct LdParser { pub log_facilities: Option>, pub database: Database } #[derive(Clone, Debug, Serialize, Deserialize)] pub struct LdLogDaemon { pub global: LdGlobal, pub jail: LdJail, pub action_exec: LdActionThreadExec, pub control: LdControl, pub ent_worker: LdEntityWorker, pub sockthread: LdSockThread, pub parser: LdParser } pub fn main() { // static let mut curdir = std::env::current_dir().unwrap(); curdir.push("examples/struct_to_scheme/advanced4"); println!("{}", curdir.display()); let schm = init::SchemeInit::new_with_path(curdir).unwrap(); let res = schm.run_from_file("init_logdaemon.shm", None).unwrap(); let resser = res.get("logdaemon").unwrap().clone(); // dynamic let mut curdir = std::env::current_dir().unwrap(); curdir.push("examples/struct_to_scheme/advanced4/logdaemon.shm"); let (_, dynres) = environment::DynEnvironment::from_file(curdir, resser.clone()).unwrap(); // serialize dyn let ret = serializator::Serialization::serialize(resser.clone(), dynres.clone()).unwrap(); let serialized = serde_json::to_string(&ret).unwrap(); /* let mut rc = RustCode::new(&["Clone", "Debug", "Serialize", "Deserialize"], &["Clone", "Debug", "Serialize", "Deserialize"]); println!("Structures: "); match resser.generate_rust_structs(&mut rc) { Ok(_) => { println!("{}", rc); }, Err(e) => { println!("{}", e); } } */ let n: LdLogDaemon = serde_json::from_str(&serialized).unwrap(); let scmp = from_struct(n, resser.clone()); if scmp.is_err() == true { panic!("{}", scmp.err().unwrap()); } else { let out_res = scmp.unwrap(); println!("{}", out_res); let lex_out = Lexer::from_str(&out_res.to_string(), "test").unwrap(); let dyn_root = environment::DynEnvironment::new_root(resser.clone()).unwrap(); let dyn_res = environment::DynEnvironment::run(&lex_out, dyn_root); if dyn_res.is_err() == true { println!("{}", dyn_res.err().unwrap()); } } }