pub fn load_config(data: String, is_path: bool) -> Self {
		let datar = if is_path {
			fs::read_to_string(data.to_owned()).unwrap_or_else(|_| {
				println!("[Warn]: Unable to find configuration file, using default configuration.");
				fs::write(data, DEFAULT_CONFIG).unwrap_or_else(|_err| {
					println!("[Warn]: Unable to write default configuration to disk!");
				});
				DEFAULT_CONFIG.to_owned()
			})
		} else {
			data
		};

		let conft: ConfStruct = toml::from_str(&datar).unwrap_or_else(|err| {
			println!("[Fatal]: Unable to parse configuration! Debugging information will be printed below.");
			println!("{}", err);
			process::exit(exitcode::CONFIG);
		});

		// Parse the provided content into a Config object, using default values if an item can't be found.
		Self {
			caching_timeout: conft.content.caching_timeout.unwrap_or(12),
			stream_timeout: conft.server.stream_timeout.unwrap_or(20),
			hsts: conft.content.hsts.unwrap_or(false),
			hidden: {
				let mut tmp = conft.content.hide.to_owned().unwrap_or_else(Vec::new);
				tmp.push(conft.server.cert_folder.to_owned().unwrap_or_else(|| "ssl".to_owned()));
				tmp.push("redir".to_owned());
				tmp.sort_unstable();
				tmp
			},
			hiddenx: {
				parse_regex(conft.content.hide.unwrap_or_else(Vec::new)).unwrap_or_else(|err| {
					println!("[Fatal]: Unable to parse configuration! Debugging information will be printed below.");
					println!("{}", err);
					process::exit(exitcode::CONFIG);
				})
			},
			lredir: {
				let mut tmp = Vec::new();
				for item in conft.redir.to_owned().unwrap_or_else(Vec::new) {
					tmp.push(item.location);
				}
				tmp.sort_unstable();
				tmp
			},
			redirx: {
				let mut tmp = Vec::new();
				for item in conft.redir.to_owned().unwrap_or_else(Vec::new) {
					tmp.push(item.location);
				}
				parse_regex(tmp).unwrap_or_else(|err| {
					println!("[Fatal]: Unable to parse configuration! Debugging information will be printed below.");
					println!("{}", err);
					process::exit(exitcode::CONFIG);
				})
			},
			redirmap: {
				let mut tmp = HashMap::new();
				for item in conft.redir.unwrap_or_else(Vec::new) {
					tmp.insert(item.location, item.dest);
				}
				tmp
			},

			lproxy: {
				let mut tmp = Vec::new();
				for item in conft.proxy.to_owned().unwrap_or_else(Vec::new) {
					tmp.push(item.location);
				}
				tmp.sort_unstable();
				tmp
			},
			proxyx: {
				let mut tmp = Vec::new();
				for item in conft.proxy.to_owned().unwrap_or_else(Vec::new) {
					tmp.push(item.location);
				}
				parse_regex(tmp).unwrap_or_else(|err| {
					println!("[Fatal]: Unable to parse configuration! Debugging information will be printed below.");
					println!("{}", err);
					process::exit(exitcode::CONFIG);
				})
			},
			proxymap: {
				let mut tmp = HashMap::new();
				for item in conft.proxy.unwrap_or_else(Vec::new) {
					tmp.insert(item.location, item.dest);
				}
				tmp
			},

			authx: {
				let mut tmp = Vec::new();
				for item in conft.auth.to_owned().unwrap_or_else(Vec::new) {
					tmp.push(item.location);
				}
				parse_regex(tmp).unwrap_or_else(|err| {
					println!("[Fatal]: Unable to parse configuration! Debugging information will be printed below.");
					println!("{}", err);
					process::exit(exitcode::CONFIG);
				})
			},
			authmap: {
				let mut tmp = HashMap::new();
				for item in conft.auth.unwrap_or_else(Vec::new) {
					tmp.insert(item.location, base64::encode(item.login.as_bytes()));
				}
				tmp
			},
			protect: conft.content.protect.unwrap_or(true),
			compress_files: conft.content.compress_files.unwrap_or(true),
			log_format: conft.server.log_format.unwrap_or_else(|| "minimal".to_owned()),
			http_addr: conft.server.http_addr.unwrap_or_else(|| "[::]:80".to_owned()),
			tls_addr: conft.server.tls_addr.unwrap_or_else(|| "[::]:443".to_owned()),
			cert_folder: conft.server.cert_folder.unwrap_or_else(|| "ssl".to_owned()),
			root_folder: conft.server.root_folder.unwrap_or_else(|| ".".to_owned()),
			max_streaming_len: conft.server.copy_chunk_size.unwrap_or(65_536),
			chacha: conft.server.prefer_chacha_poly.unwrap_or(false),
			smaller_default: conft.content.smaller_default.unwrap_or(false),
		}
	}
// Generates a Config object from provided TOML input. Input can be either a file path, or TOML data provided as a string.
Generates a Config object from provided TOML input. Input can be either a file path, or TOML data provided as a string.
Generates a Config object from provided TOML input . Input can be either a file path or TOML data provided as a string .
pub fn load_config(data: String, is_path: bool) -> Self {
		let datar = if is_path {
			fs::read_to_string(data.to_owned()).unwrap_or_else(|_| {
				println!("[Warn]: Unable to find configuration file, using default configuration.");
				fs::write(data, DEFAULT_CONFIG).unwrap_or_else(|_err| {
					println!("[Warn]: Unable to write default configuration to disk!");
				});
				DEFAULT_CONFIG.to_owned()
			})
		} else {
			data
		};
		let conft: ConfStruct = toml::from_str(&datar).unwrap_or_else(|err| {
			println!("[Fatal]: Unable to parse configuration! Debugging information will be printed below.");
			println!("{}", err);
			process::exit(exitcode::CONFIG);
		});
		// Parse the provided content into a Config object, using default values if an item can't be found.
		Self {
			caching_timeout: conft.content.caching_timeout.unwrap_or(12),
			stream_timeout: conft.server.stream_timeout.unwrap_or(20),
			hsts: conft.content.hsts.unwrap_or(false),
			hidden: {
				let mut tmp = conft.content.hide.to_owned().unwrap_or_else(Vec::new);
				tmp.push(conft.server.cert_folder.to_owned().unwrap_or_else(|| "ssl".to_owned()));
				tmp.push("redir".to_owned());
				tmp.sort_unstable();
				tmp
			},
			hiddenx: {
				parse_regex(conft.content.hide.unwrap_or_else(Vec::new)).unwrap_or_else(|err| {
					println!("[Fatal]: Unable to parse configuration! Debugging information will be printed below.");
					println!("{}", err);
					process::exit(exitcode::CONFIG);
				})
			},
			lredir: {
				let mut tmp = Vec::new();
				for item in conft.redir.to_owned().unwrap_or_else(Vec::new) {
					tmp.push(item.location);
				}
				tmp.sort_unstable();
				tmp
			},
			redirx: {
				let mut tmp = Vec::new();
				for item in conft.redir.to_owned().unwrap_or_else(Vec::new) {
					tmp.push(item.location);
				}
				parse_regex(tmp).unwrap_or_else(|err| {
					println!("[Fatal]: Unable to parse configuration! Debugging information will be printed below.");
					println!("{}", err);
					process::exit(exitcode::CONFIG);
				})
			},
			redirmap: {
				let mut tmp = HashMap::new();
				for item in conft.redir.unwrap_or_else(Vec::new) {
					tmp.insert(item.location, item.dest);
				}
				tmp
			},
			lproxy: {
				let mut tmp = Vec::new();
				for item in conft.proxy.to_owned().unwrap_or_else(Vec::new) {
					tmp.push(item.location);
				}
				tmp.sort_unstable();
				tmp
			},
			proxyx: {
				let mut tmp = Vec::new();
				for item in conft.proxy.to_owned().unwrap_or_else(Vec::new) {
					tmp.push(item.location);
				}
				parse_regex(tmp).unwrap_or_else(|err| {
					println!("[Fatal]: Unable to parse configuration! Debugging information will be printed below.");
					println!("{}", err);
					process::exit(exitcode::CONFIG);
				})
			},
			proxymap: {
				let mut tmp = HashMap::new();
				for item in conft.proxy.unwrap_or_else(Vec::new) {
					tmp.insert(item.location, item.dest);
				}
				tmp
			},
			authx: {
				let mut tmp = Vec::new();
				for item in conft.auth.to_owned().unwrap_or_else(Vec::new) {
					tmp.push(item.location);
				}
				parse_regex(tmp).unwrap_or_else(|err| {
					println!("[Fatal]: Unable to parse configuration! Debugging information will be printed below.");
					println!("{}", err);
					process::exit(exitcode::CONFIG);
				})
			},
			authmap: {
				let mut tmp = HashMap::new();
				for item in conft.auth.unwrap_or_else(Vec::new) {
					tmp.insert(item.location, base64::encode(item.login.as_bytes()));
				}
				tmp
			},
			protect: conft.content.protect.unwrap_or(true),
			compress_files: conft.content.compress_files.unwrap_or(true),
			log_format: conft.server.log_format.unwrap_or_else(|| "minimal".to_owned()),
			http_addr: conft.server.http_addr.unwrap_or_else(|| "[::]:80".to_owned()),
			tls_addr: conft.server.tls_addr.unwrap_or_else(|| "[::]:443".to_owned()),
			cert_folder: conft.server.cert_folder.unwrap_or_else(|| "ssl".to_owned()),
			root_folder: conft.server.root_folder.unwrap_or_else(|| ".".to_owned()),
			max_streaming_len: conft.server.copy_chunk_size.unwrap_or(65_536),
			chacha: conft.server.prefer_chacha_poly.unwrap_or(false),
			smaller_default: conft.content.smaller_default.unwrap_or(false),
		}
	}
pub fn load_config ( data : String , is_path : bool ) -> Self { let datar = if is_path { fs :: read_to_string ( data . to_owned ( ) ) . unwrap_or_else ( | _ | { println ! ( " " ) ; fs :: write ( data , DEFAULT_CONFIG ) . unwrap_or_else ( | _err | { println ! ( " " ) ; } ) ; DEFAULT_CONFIG . to_owned ( ) } ) } else { data } ; let conft : ConfStruct = toml :: from_str ( & datar ) . unwrap_or_else ( | err | { println ! ( " " ) ; println ! ( " " err ) ; process :: exit ( exitcode :: CONFIG ) ; } ) ; // Parse the provided content into a Config object, using default values if an item can't be found. Self { caching_timeout : conft . content . caching_timeout . unwrap_or ( 12 ) , stream_timeout : conft . server . stream_timeout . unwrap_or ( 20 ) , hsts : conft . content . hsts . unwrap_or ( false ) , hidden : { let mut tmp = conft . content . hide . to_owned ( ) . unwrap_or_else ( Vec :: new ) ; tmp . push ( conft . server . cert_folder . to_owned ( ) . unwrap_or_else ( | | " " . to_owned ( ) ) ) ; tmp . push ( " " . to_owned ( ) ) ; tmp . sort_unstable ( ) ; tmp } , hiddenx : { parse_regex ( conft . content . hide . unwrap_or_else ( Vec :: new ) ) . unwrap_or_else ( | err | { println ! ( " " ) ; println ! ( " " err ) ; process :: exit ( exitcode :: CONFIG ) ; } ) } , lredir : { let mut tmp = Vec :: new ( ) ; for item in conft . redir . to_owned ( ) . unwrap_or_else ( Vec :: new ) { tmp . push ( item . location ) ; } tmp . sort_unstable ( ) ; tmp } , redirx : { let mut tmp = Vec :: new ( ) ; for item in conft . redir . to_owned ( ) . unwrap_or_else ( Vec :: new ) { tmp . push ( item . location ) ; } parse_regex ( tmp ) . unwrap_or_else ( | err | { println ! ( " " ) ; println ! ( " " err ) ; process :: exit ( exitcode :: CONFIG ) ; } ) } , redirmap : { let mut tmp = HashMap :: new ( ) ; for item in conft . redir . unwrap_or_else ( Vec :: new ) { tmp . insert ( item . location , item . dest ) ; } tmp } , lproxy : { let mut tmp = Vec :: new ( ) ; for item in conft . proxy . to_owned ( ) . unwrap_or_else ( Vec :: new ) { tmp . push ( item . location ) ; } tmp . sort_unstable ( ) ; tmp } , proxyx : { let mut tmp = Vec :: new ( ) ; for item in conft . proxy . to_owned ( ) . unwrap_or_else ( Vec :: new ) { tmp . push ( item . location ) ; } parse_regex ( tmp ) . unwrap_or_else ( | err | { println ! ( " " ) ; println ! ( " " err ) ; process :: exit ( exitcode :: CONFIG ) ; } ) } , proxymap : { let mut tmp = HashMap :: new ( ) ; for item in conft . proxy . unwrap_or_else ( Vec :: new ) { tmp . insert ( item . location , item . dest ) ; } tmp } , authx : { let mut tmp = Vec :: new ( ) ; for item in conft . auth . to_owned ( ) . unwrap_or_else ( Vec :: new ) { tmp . push ( item . location ) ; } parse_regex ( tmp ) . unwrap_or_else ( | err | { println ! ( " " ) ; println ! ( " " err ) ; process :: exit ( exitcode :: CONFIG ) ; } ) } , authmap : { let mut tmp = HashMap :: new ( ) ; for item in conft . auth . unwrap_or_else ( Vec :: new ) { tmp . insert ( item . location , base64 :: encode ( item . login . as_bytes ( ) ) ) ; } tmp } , protect : conft . content . protect . unwrap_or ( true ) , compress_files : conft . content . compress_files . unwrap_or ( true ) , log_format : conft . server . log_format . unwrap_or_else ( | | " " . to_owned ( ) ) , http_addr : conft . server . http_addr . unwrap_or_else ( | | " " . to_owned ( ) ) , tls_addr : conft . server . tls_addr . unwrap_or_else ( | | " " . to_owned ( ) ) , cert_folder : conft . server . cert_folder . unwrap_or_else ( | | " " . to_owned ( ) ) , root_folder : conft . server . root_folder . unwrap_or_else ( | | " " . to_owned ( ) ) , max_streaming_len : conft . server . copy_chunk_size . unwrap_or ( 65_536 ) , chacha : conft . server . prefer_chacha_poly . unwrap_or ( false ) , smaller_default : conft . content . smaller_default . unwrap_or ( false ) , } }
Generates a Config object from provided TOML input.
Generates a Config object from provided TOML input .
data
String
is_path
bool
data
String
is_path
bool