From 2b7a0a458508ed2d490e43fe45eb906c7492e1da Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Mon, 10 Feb 2020 23:36:56 +0100 Subject: [PATCH] prototype dc_set_config_from_qr() --- deltachat-ffi/deltachat.h | 17 +++++++++++++++++ deltachat-ffi/src/lib.rs | 16 ++++++++++++++++ src/qr.rs | 8 ++++++++ 3 files changed, 41 insertions(+) diff --git a/deltachat-ffi/deltachat.h b/deltachat-ffi/deltachat.h index d7b1c426d..a3f8f785a 100644 --- a/deltachat-ffi/deltachat.h +++ b/deltachat-ffi/deltachat.h @@ -403,6 +403,7 @@ int dc_set_config (dc_context_t* context, const char* */ char* dc_get_config (dc_context_t* context, const char* key); + /** * Set stock string translation. * @@ -417,6 +418,22 @@ char* dc_get_config (dc_context_t* context, const char* int dc_set_stock_translation(dc_context_t* context, uint32_t stock_id, const char* stock_msg); +/** + * Set configuration values from a QR code containing an account. + * Before this function is called, dc_check_qr() should confirm the type of the + * QR code is DC_QR_ACCOUNT. + * + * Internally, the function will call dc_set_config() + * at least with the keys `addr` and `mail_pw`. + * + * @memberof dc_context_t + * @param context The context object + * @param qr scanned QR code + * @return int (==0 on error, 1 on success) + */ +int dc_set_config_from_qr (dc_context_t* context, const char* qr); + + /** * Get information about the context. * diff --git a/deltachat-ffi/src/lib.rs b/deltachat-ffi/src/lib.rs index 6d57a1906..3f13361e1 100644 --- a/deltachat-ffi/src/lib.rs +++ b/deltachat-ffi/src/lib.rs @@ -423,6 +423,22 @@ pub unsafe extern "C" fn dc_set_stock_translation( .unwrap_or(0) } +#[no_mangle] +pub unsafe extern "C" fn dc_set_config_from_qr( + context: *mut dc_context_t, + qr: *mut libc::c_char, +) -> libc::c_int { + if context.is_null() || qr.is_null() { + eprintln!("ignoring careless call to dc_set_config_from_qr"); + return 0; + } + let qr = to_string_lossy(qr); + let ffi_context = &*context; + ffi_context + .with_inner(|ctx| qr::set_config_from_qr(ctx, &qr) as libc::c_int) + .unwrap_or(0) +} + #[no_mangle] pub unsafe extern "C" fn dc_get_info(context: *mut dc_context_t) -> *mut libc::c_char { if context.is_null() { diff --git a/src/qr.rs b/src/qr.rs index 1f93dcded..a8955c78e 100644 --- a/src/qr.rs +++ b/src/qr.rs @@ -205,6 +205,14 @@ fn decode_account(_context: &Context, qr: &str) -> Lot { lot } +pub fn set_config_from_qr(context: &Context, qr: &str) -> bool { + error!( + context, + "Setting config from QR is not yet implemented :/ QR code: {}", qr + ); + false +} + /// Extract address for the mailto scheme. /// /// Scheme: `mailto:addr...?subject=...&body=..`