summaryrefslogtreecommitdiffstats
path: root/store/src
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2018-08-29 14:47:57 +0200
committerJustus Winter <justus@sequoia-pgp.org>2018-08-29 17:11:58 +0200
commit80b0d59448feb30daa527688e73a56c5cefca92c (patch)
tree36db7ee7f4f60ec1abc054d159356b43899c96f7 /store/src
parent7918ea29a1f7c5dcbee6e8826a9f8644de3a7fe1 (diff)
store: Add method to query a binding's label.
Diffstat (limited to 'store/src')
-rw-r--r--store/src/backend/mod.rs15
-rw-r--r--store/src/lib.rs33
-rw-r--r--store/src/store_protocol.capnp1
3 files changed, 40 insertions, 9 deletions
diff --git a/store/src/backend/mod.rs b/store/src/backend/mod.rs
index 59a126bf..3c6051dd 100644
--- a/store/src/backend/mod.rs
+++ b/store/src/backend/mod.rs
@@ -580,6 +580,21 @@ impl node::binding::Server for BindingServer {
node::log_iter::ToClient::new(iter).from_server::<capnp_rpc::Server>()));
Promise::ok(())
}
+
+ fn label(&mut self,
+ _: node::binding::LabelParams,
+ mut results: node::binding::LabelResults)
+ -> Promise<(), capnp::Error> {
+ bind_results!(results);
+ let label = sry!(self.c.query_row(
+ "SELECT label FROM bindings WHERE id = ?1",
+ &[&self.id], |row| -> String {
+ row.get(0)
+ }));
+
+ pry!(pry!(results.get().get_result()).set_ok(label.as_str()));
+ Promise::ok(())
+ }
}
struct KeyServer {
diff --git a/store/src/lib.rs b/store/src/lib.rs
index fcc2c403..947ed5d8 100644
--- a/store/src/lib.rs
+++ b/store/src/lib.rs
@@ -216,7 +216,7 @@ impl Store {
request.get().set_label(label);
request.get().set_fingerprint(fingerprint.to_hex().as_ref());
let binding = make_request!(self.core.borrow_mut(), request)?;
- Ok(Binding::new(self.core.clone(), label, binding))
+ Ok(Binding::new(self.core.clone(), Some(label), binding))
}
/// Imports a key into the store.
@@ -249,7 +249,7 @@ impl Store {
request.get().set_label(label);
request.get().set_fingerprint(fingerprint.to_hex().as_ref());
let binding = make_request!(self.core.borrow_mut(), request)?;
- let binding = Binding::new(self.core.clone(), label, binding);
+ let binding = Binding::new(self.core.clone(), Some(label), binding);
binding.import(tpk)
}
@@ -284,7 +284,7 @@ impl Store {
let mut request = self.store.lookup_request();
request.get().set_label(label);
let binding = make_request!(self.core.borrow_mut(), request)?;
- Ok(Binding::new(self.core.clone(), label, binding))
+ Ok(Binding::new(self.core.clone(), Some(label), binding))
}
/// Deletes this store.
@@ -361,20 +361,22 @@ macro_rules! make_stats_request {
/// relation. We make this explicit because we associate metadata
/// with these pairs.
pub struct Binding {
- label: String,
+ label: Option<String>,
core: Rc<RefCell<Core>>,
binding: node::binding::Client,
}
impl fmt::Debug for Binding {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- write!(f, "Binding {{ label: {} }}", self.label)
+ write!(f, "Binding {{ label: {:?} }}", self.label)
}
}
impl Binding {
- fn new(core: Rc<RefCell<Core>>, label: &str, binding: node::binding::Client) -> Self {
- Binding{label: label.into(), core: core, binding: binding}
+ fn new(core: Rc<RefCell<Core>>,
+ label: Option<&str>,
+ binding: node::binding::Client) -> Self {
+ Binding{label: label.map(|l| l.into()), core: core, binding: binding}
}
/// Returns stats for this binding.
@@ -589,6 +591,18 @@ impl Binding {
let iter = make_request!(self.core.borrow_mut(), request)?;
Ok(LogIter{core: self.core.clone(), iter: iter})
}
+
+ /// Gets this binding's label.
+ pub fn label(&self) -> Result<String> {
+ if let Some(ref label) = self.label {
+ return Ok(label.clone());
+ }
+
+ let request = self.binding.label_request();
+ make_request_map!(self.core.borrow_mut(),
+ request,
+ |l: &str| Ok(l.into()))
+ }
}
/// Represents a key in a store.
@@ -860,7 +874,8 @@ impl Iterator for BindingIter {
|r: node::binding_iter::item::Reader|
Ok((String::from(r.get_label()?),
openpgp::Fingerprint::from_hex(r.get_fingerprint()?).unwrap(),
- Binding::new(self.core.clone(), r.get_label()?, r.get_binding()?))))
+ Binding::new(self.core.clone(), Some(r.get_label()?),
+ r.get_binding()?))))
};
doit().ok()
}
@@ -907,7 +922,7 @@ impl Iterator for LogIter {
r.get_store().ok().map(
|cap| Store::new(self.core.clone(), &"", cap)),
r.get_binding().ok().map(
- |cap| Binding::new(self.core.clone(), &"", cap)),
+ |cap| Binding::new(self.core.clone(), None, cap)),
r.get_key().ok().map(
|cap| Key::new(self.core.clone(), cap)),
r.get_slug()?,
diff --git a/store/src/store_protocol.capnp b/store/src/store_protocol.capnp
index a043ca26..11ef362a 100644
--- a/store/src/store_protocol.capnp
+++ b/store/src/store_protocol.capnp
@@ -23,6 +23,7 @@ interface Node {
registerEncryption @4 () -> (result: Result(Stats));
registerVerification @5 () -> (result: Result(Stats));
log @6 () -> (result: Result(LogIter));
+ label @7 () -> (result: Result(Text));
}
interface Key {