mirror of
https://github.com/chatmail/core.git
synced 2026-05-03 13:26:28 +03:00
Introduce enum API for configuration
This introduces a new Context::get_config_item() and Context::set_config_item() API which operates on two enums: ConfigKey and ConfigItem. The latter has variats which hold the actual configuration as data. This allows to introduce stronger typing of the configuration items. This commit however does not yet do this, it adapts the existing APIs to use the new API leaving the stronger typing for future commits. This should make the changes more digestible and reviewable.
This commit is contained in:
@@ -337,12 +337,16 @@ pub unsafe extern "C" fn dc_get_config(
|
||||
return "".strdup();
|
||||
}
|
||||
let ffi_context = &*context;
|
||||
match config::Config::from_str(&to_string_lossy(key)) {
|
||||
match config::Config::from_key_str(&to_string_lossy(key)) {
|
||||
Ok(key) => ffi_context
|
||||
.with_inner(|ctx| ctx.get_config(key).unwrap_or_default().strdup())
|
||||
.unwrap_or_else(|_| "".strdup()),
|
||||
Err(_) => {
|
||||
ffi_context.error("dc_get_config(): invalid key");
|
||||
Err(err) => {
|
||||
ffi_context.error(&format!(
|
||||
"dc_get_config(): invalid key {} ({})",
|
||||
&to_string_lossy(key),
|
||||
err
|
||||
));
|
||||
"".strdup()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user