diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2018-02-13 14:21:07 +0100 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2018-02-13 14:21:53 +0100 |
commit | c3ff12f1d72d893468d21ff06bea616039ffcb29 (patch) | |
tree | 449d09cebc9adf8e6fcde9a767cbedd06bd44a9a | |
parent | e0ad70eea4ceb6ef04f279c80bcba68252915785 (diff) |
ffi: Add glue for net::Keyserver::send.
-rw-r--r-- | ffi/src/lib.rs | 35 | ||||
-rw-r--r-- | ffi/src/sequoia.h | 9 |
2 files changed, 39 insertions, 5 deletions
diff --git a/ffi/src/lib.rs b/ffi/src/lib.rs index ab6ad8f0..9b5333a8 100644 --- a/ffi/src/lib.rs +++ b/ffi/src/lib.rs @@ -77,7 +77,7 @@ use std::slice; use openpgp::tpk::TPK; use openpgp::KeyID; -use self::libc::{uint8_t, c_char, size_t}; +use self::libc::{uint8_t, c_char, size_t, c_long}; use self::native_tls::Certificate; use sequoia_core as core; use sequoia_core::Config; @@ -99,19 +99,29 @@ impl Context { /// Like try! for ffi glue. /// /// Unwraps the given expression. On failure, stashes the error in -/// the context and returns NULL. -macro_rules! fry { - ($ctx:expr, $expr:expr) => { +/// the context and returns $or. +macro_rules! fry_or { + ($ctx:expr, $expr:expr, $or:expr) => { match $expr { Ok(v) => v, Err(e) => { $ctx.e = Some(Box::new(e)); - return ptr::null_mut(); + return $or; }, } }; } +/// Like try! for ffi glue. +/// +/// Unwraps the given expression. On failure, stashes the error in +/// the context and returns NULL. +macro_rules! fry { + ($ctx:expr, $expr:expr) => { + fry_or!($ctx, $expr, ptr::null_mut()) + }; +} + /// Like try! for ffi glue, then box into raw pointer. /// /// Unwraps the given expression. On success, it boxes the value @@ -464,3 +474,18 @@ pub extern "system" fn sq_keyserver_get(ctx: Option<&mut Context>, fry_box!(ctx, ks.get(&id)) } + +/// Sends the given key to the server. +/// +/// Returns != 0 on errors. +#[no_mangle] +pub extern "system" fn sq_keyserver_send(ctx: Option<&mut Context>, + ks: Option<&mut KeyServer>, + tpk: Option<&TPK>) -> c_long { + let ctx = ctx.expect("Context is NULL"); + let ks = ks.expect("KeyServer is NULL"); + let tpk = tpk.expect("TPK is NULL"); + + fry_or!(ctx, ks.send(tpk), 1); + 0 // Success! +} diff --git a/ffi/src/sequoia.h b/ffi/src/sequoia.h index 00cd7449..679e7da4 100644 --- a/ffi/src/sequoia.h +++ b/ffi/src/sequoia.h @@ -313,4 +313,13 @@ sq_tpk_t sq_keyserver_get (sq_context_t ctx, sq_keyserver_t ks, const sq_keyid_t id); +/*/ +/// Sends the given key to the server. +/// +/// Returns != 0 on errors. +/*/ +int sq_keyserver_send (sq_context_t ctx, + sq_keyserver_t ks, + const sq_tpk_t tpk); + #endif |