diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2019-05-15 16:28:11 +0200 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2019-05-15 16:29:55 +0200 |
commit | a25ef6974e0ba3989f6205c19a1f9ccfc81db584 (patch) | |
tree | 4ce3b386923515a662051c40f67a135ee15681f6 /ffi/src | |
parent | 36e2d97ac013e023feb27df939c3f6d6e32d8669 (diff) |
core, store, tool: Use realm instead of domain.
- Remove the domain parameter from core::Context.
- Replace it with a realm to be passed in when opening a store.
- For sq, merge store name and realm into the --store parameter.
- Fixes #105.
Diffstat (limited to 'ffi/src')
-rw-r--r-- | ffi/src/core.rs | 32 | ||||
-rw-r--r-- | ffi/src/net.rs | 2 | ||||
-rw-r--r-- | ffi/src/store.rs | 22 |
3 files changed, 19 insertions, 37 deletions
diff --git a/ffi/src/core.rs b/ffi/src/core.rs index 5b139fb4..830391d6 100644 --- a/ffi/src/core.rs +++ b/ffi/src/core.rs @@ -13,7 +13,7 @@ //! #include <sequoia.h> //! //! sq_context_t ctx; -//! ctx = sq_context_new ("org.sequoia-pgp.example", NULL); +//! ctx = sq_context_new (NULL); //! //! /* Use Sequoia. */ //! @@ -29,7 +29,7 @@ //! sq_config_t cfg; //! sq_context_t ctx; //! -//! cfg = sq_context_configure ("org.sequoia-pgp.example"); +//! cfg = sq_context_configure (); //! sq_config_network_policy (cfg, SQ_NETWORK_POLICY_OFFLINE); //! ctx = sq_config_build (cfg, NULL); //! @@ -72,20 +72,13 @@ fn sq_context_last_error(ctx: *mut Context) -> *mut ::error::Error { /// Creates a Context with reasonable defaults. /// -/// `domain` should uniquely identify your application, it is strongly -/// suggested to use a reversed fully qualified domain name that is -/// associated with your application. `domain` must not be `NULL`. -/// /// Returns `NULL` on errors. If `errp` is not `NULL`, the error is /// stored there. #[::ffi_catch_abort] #[no_mangle] pub extern "C" -fn sq_context_new(domain: *const c_char, - errp: Option<&mut *mut ::error::Error>) +fn sq_context_new(errp: Option<&mut *mut ::error::Error>) -> *mut Context { ffi_make_fry_from_errp!(errp); - let domain = ffi_param_cstr!(domain).to_string_lossy(); - - ffi_try_box!(core::Context::new(&domain).map(|ctx| Context::new(ctx))) + ffi_try_box!(core::Context::new().map(|ctx| Context::new(ctx))) } /// Frees a context. @@ -96,25 +89,12 @@ fn sq_context_free(context: Option<&mut Context>) { /// Creates a Context that can be configured. /// -/// `domain` should uniquely identify your application, it is strongly -/// suggested to use a reversed fully qualified domain name that is -/// associated with your application. `domain` must not be `NULL`. -/// /// The configuration is seeded like in `sq_context_new`, but can be /// modified. A configuration has to be finalized using /// `sq_config_build()` in order to turn it into a Context. #[::ffi_catch_abort] #[no_mangle] pub extern "C" -fn sq_context_configure(domain: *const c_char) -> *mut Config { - let domain = ffi_param_cstr!(domain).to_string_lossy(); - - Box::into_raw(Box::new(core::Context::configure(&domain))) -} - -/// Returns the domain of the context. -#[::ffi_catch_abort] #[no_mangle] pub extern "C" -fn sq_context_domain(ctx: *const Context) -> *const c_char { - let ctx = ffi_param_ref!(ctx); - ctx.c.domain().as_bytes().as_ptr() as *const c_char +fn sq_context_configure() -> *mut Config { + Box::into_raw(Box::new(core::Context::configure())) } /// Returns the directory containing shared state. diff --git a/ffi/src/net.rs b/ffi/src/net.rs index 06942739..93ea61cc 100644 --- a/ffi/src/net.rs +++ b/ffi/src/net.rs @@ -21,7 +21,7 @@ //! sq_keyserver_t ks; //! pgp_tpk_t tpk; //! -//! ctx = sq_context_new ("org.sequoia-pgp.example", NULL); +//! ctx = sq_context_new (NULL); //! ks = sq_keyserver_sks_pool (ctx); //! id = pgp_keyid_from_bytes ((uint8_t *) "\x24\x7F\x6D\xAB\xC8\x49\x14\xFE"); //! tpk = sq_keyserver_get (ctx, ks, id); diff --git a/ffi/src/store.rs b/ffi/src/store.rs index 2a2c18cf..3aef93a7 100644 --- a/ffi/src/store.rs +++ b/ffi/src/store.rs @@ -46,32 +46,32 @@ use Maybe; /// Lists all stores with the given prefix. #[::ffi_catch_abort] #[no_mangle] pub extern "C" fn sq_store_list_stores(ctx: *mut Context, - domain_prefix: *const c_char) + realm_prefix: *const c_char) -> *mut StoreIter { let ctx = ffi_param_ref_mut!(ctx); ffi_make_fry_from_ctx!(ctx); - let domain_prefix = ffi_param_cstr!(domain_prefix).to_string_lossy(); + let realm_prefix = ffi_param_cstr!(realm_prefix).to_string_lossy(); - ffi_try_box!(Store::list(&ctx.c, &domain_prefix)) + ffi_try_box!(Store::list(&ctx.c, &realm_prefix)) } /// Returns the next store. /// -/// Returns `NULL` on exhaustion. If `domainp` is not `NULL`, the -/// stores domain is stored there. If `namep` is not `NULL`, the +/// Returns `NULL` on exhaustion. If `realmp` is not `NULL`, the +/// stores realm is stored there. If `namep` is not `NULL`, the /// stores name is stored there. If `policyp` is not `NULL`, the /// stores network policy is stored there. #[::ffi_catch_abort] #[no_mangle] pub extern "C" fn sq_store_iter_next(iter: *mut StoreIter, - domainp: Option<&mut *mut c_char>, + realmp: Option<&mut *mut c_char>, namep: Option<&mut *mut c_char>, policyp: Option<&mut uint8_t>) -> *mut Store { let iter = ffi_param_ref_mut!(iter); match iter.next() { - Some((domain, name, policy, store)) => { - if domainp.is_some() { - *domainp.unwrap() = ffi_return_maybe_string!(domain); + Some((realm, name, policy, store)) => { + if realmp.is_some() { + *realmp.unwrap() = ffi_return_maybe_string!(realm); } if namep.is_some() { @@ -191,13 +191,15 @@ fn sq_log_iter_free(iter: Option<&mut LogIter>) { /// forbidden. #[::ffi_catch_abort] #[no_mangle] pub extern "C" fn sq_store_open(ctx: *mut Context, + realm: *const c_char, name: *const c_char) -> *mut Store { let ctx = ffi_param_ref_mut!(ctx); ffi_make_fry_from_ctx!(ctx); + let realm = ffi_param_cstr!(realm).to_string_lossy(); let name = ffi_param_cstr!(name).to_string_lossy(); - ffi_try_box!(Store::open(&ctx.c, &name)) + ffi_try_box!(Store::open(&ctx.c, &realm, &name)) } /// Frees a sq_store_t. |