summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJustus Winter <justus@pep-project.org>2017-12-06 11:51:42 +0100
committerJustus Winter <justus@pep-project.org>2017-12-06 11:53:01 +0100
commitb0fd3726cf4bc9cfd1651d36a624103e65f3f3e3 (patch)
treefd537a0bbf97ee00cc473d33ea8a0bcf27e52899 /src
parent1c98b651ed00e4638be31206f790f06a4fb5c8af (diff)
Add 'domain' to the context.
- The domain uniquely identifies the application. It should be a property of the context.
Diffstat (limited to 'src')
-rw-r--r--src/ffi.rs12
-rw-r--r--src/lib.rs26
-rw-r--r--src/sequoia.h3
3 files changed, 34 insertions, 7 deletions
diff --git a/src/ffi.rs b/src/ffi.rs
index 55911b45..303a0380 100644
--- a/src/ffi.rs
+++ b/src/ffi.rs
@@ -19,8 +19,12 @@ use super::Context;
///
/// Returns `NULL` on errors.
#[no_mangle]
-pub extern "system" fn sq_context_new(home: *const c_char,
+pub extern "system" fn sq_context_new(domain: *const c_char,
+ home: *const c_char,
lib: *const c_char) -> *mut Context {
+ let domain = unsafe {
+ if domain.is_null() { None } else { Some(CStr::from_ptr(domain)) }
+ };
let home = unsafe {
if home.is_null() { None } else { Some(CStr::from_ptr(home)) }
};
@@ -28,7 +32,11 @@ pub extern "system" fn sq_context_new(home: *const c_char,
if lib.is_null() { None } else { Some(CStr::from_ptr(lib)) }
};
- let mut pre = Context::new();
+ if domain.is_none() {
+ return ptr::null_mut();
+ }
+
+ let mut pre = Context::new(&domain.unwrap().to_string_lossy());
if let Some(home) = home {
pre = pre.home(home.to_string_lossy().as_ref());
diff --git a/src/lib.rs b/src/lib.rs
index 7f737aad..ac8afc4e 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -23,7 +23,14 @@ use std::io;
use std::path::{Path, PathBuf};
/// A `&Context` is required for many operations.
+///
+/// # Example
+///
+/// ```
+/// let c = Context::new("org.example.webmail").finalize().unwrap();
+/// ```
pub struct Context {
+ domain: String,
home: PathBuf,
lib: PathBuf,
}
@@ -34,17 +41,28 @@ fn prefix() -> PathBuf {
}
impl Context {
- /// Create a `Pre(Context)` with reasonable defaults. `Pre(Context)`s
- /// can be modified, and have to be finalized in order to turn
- /// them into a Context.
- pub fn new() -> Pre {
+ /// Creates a `Pre(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.
+ ///
+ /// `Pre(Context)`s can be modified, and have to be finalized in
+ /// order to turn them into a Context.
+ pub fn new(domain: &str) -> Pre {
Pre(Context {
+ domain: String::from(domain),
home: env::home_dir().unwrap_or(env::temp_dir())
.join(".sequoia"),
lib: prefix().join("lib").join("sequoia"),
})
}
+ /// Return the directory containing backend servers.
+ pub fn domain(&self) -> &str {
+ &self.domain
+ }
+
/// Return the directory containing shared state and rendezvous
/// nodes.
pub fn home(&self) -> &Path {
diff --git a/src/sequoia.h b/src/sequoia.h
index 7b3f9cf2..4d43d99c 100644
--- a/src/sequoia.h
+++ b/src/sequoia.h
@@ -3,7 +3,8 @@
struct sq_context;
-struct sq_context *sq_context_new(const char *home, const char *lib);
+struct sq_context *sq_context_new(const char *domain, const char *home,
+ const char *lib);
void sq_context_free(struct sq_context *context);
struct sq_tpk;