diff --git a/Cargo.toml b/Cargo.toml index 1ea213e65..540c878b6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,3 +19,4 @@ hex = "0.3.2" sha2 = "0.8.0" rand = "0.6.5" smallvec = "0.6.9" +libsqlite3-sys = "0.14.0" diff --git a/build.rs b/build.rs index ed90f7000..a8eb6d80b 100644 --- a/build.rs +++ b/build.rs @@ -19,7 +19,6 @@ fn main() { println!("cargo:rustc-link-lib=dylib=sasl2"); println!("cargo:rustc-link-lib=dylib=z"); - println!("cargo:rustc-link-lib=dylib=sqlite3"); println!("cargo:rustc-link-lib=dylib=pthread"); println!("cargo:rustc-link-lib=dylib=crypto"); println!("cargo:rustc-link-lib=dylib=tools"); diff --git a/misc.c b/misc.c index 7b4978126..eb09de7ce 100644 --- a/misc.c +++ b/misc.c @@ -49,24 +49,6 @@ char* dc_mprintf(const char* format, ...) vsnprintf(buf, char_cnt_without_zero+1, format, argp_copy); va_end(argp_copy); return buf; - - #if 0 /* old implementation based upon sqlite3 */ - char *sqlite_str, *c_string; - - va_list argp; - va_start(argp, format); /* expects the last non-variable argument as the second parameter */ - sqlite_str = sqlite3_vmprintf(format, argp); - va_end(argp); - - if (sqlite_str==NULL) { - return dc_strdup("ErrFmt"); /* error - the result must be free()'d */ - } - - /* as sqlite-strings must be freed using sqlite3_free() instead of a simple free(), convert it to a normal c-string */ - c_string = dc_strdup(sqlite_str); /* exists on errors */ - sqlite3_free(sqlite_str); - return c_string; /* success - the result must be free()'d */ - #endif /* /old implementation based upon sqlite3 */ } diff --git a/src/dc_keyhistory.rs b/src/dc_keyhistory.rs index 379afe917..a31bed7b2 100644 --- a/src/dc_keyhistory.rs +++ b/src/dc_keyhistory.rs @@ -17,5 +17,5 @@ pub unsafe extern "C" fn dc_add_to_keyhistory( mut addr: *const libc::c_char, mut fingerprint: *const libc::c_char, ) { - unimplemented!() + } diff --git a/src/dc_sqlite3.rs b/src/dc_sqlite3.rs index d0804ec32..ce788b642 100644 --- a/src/dc_sqlite3.rs +++ b/src/dc_sqlite3.rs @@ -23,8 +23,6 @@ pub struct dc_sqlite3_t { pub context: *mut dc_context_t, } -pub type sqlite3_destructor_type = Option ()>; - #[no_mangle] pub unsafe extern "C" fn dc_sqlite3_new(mut context: *mut dc_context_t) -> *mut dc_sqlite3_t { let mut sql: *mut dc_sqlite3_t = 0 as *mut dc_sqlite3_t; @@ -963,7 +961,8 @@ pub unsafe extern "C" fn dc_sqlite3_log_error( if sql.is_null() || msg_format.is_null() { return; } - msg = sqlite3_vmprintf(msg_format, va); + // FIXME: evil transmute + msg = sqlite3_vmprintf(msg_format, std::mem::transmute(va)); dc_log_error( (*sql).context, 0i32, diff --git a/src/types.rs b/src/types.rs index 97e2e40fb..27bda01c6 100644 --- a/src/types.rs +++ b/src/types.rs @@ -6,18 +6,17 @@ use crate::dc_imap::dc_imap_t; use crate::dc_sqlite3::dc_sqlite3_t; use crate::x::*; +pub use libsqlite3_sys::*; + extern "C" { pub type __sFILEX; pub type _telldir; pub type mailstream_cancel; - pub type sqlite3; - pub type sqlite3_stmt; } pub type sqlite_int64 = libc::c_longlong; pub type sqlite3_int64 = sqlite_int64; -pub type sqlite3_destructor_type = Option ()>; pub type useconds_t = __darwin_useconds_t; pub type int32_t = libc::c_int; diff --git a/src/x.rs b/src/x.rs index 7babf5edb..f78c8f091 100644 --- a/src/x.rs +++ b/src/x.rs @@ -641,62 +641,4 @@ extern "C" { pub fn dc_strbuilder_catf(_: *mut dc_strbuilder_t, format: *const libc::c_char, _: ...); pub fn dc_mprintf(format: *const libc::c_char, _: ...) -> *mut libc::c_char; - - // -- Sqlite3 - - pub fn sqlite3_bind_blob( - _: *mut sqlite3_stmt, - _: libc::c_int, - _: *const libc::c_void, - n: libc::c_int, - _: Option ()>, - ) -> libc::c_int; - pub fn sqlite3_bind_int64( - _: *mut sqlite3_stmt, - _: libc::c_int, - _: sqlite3_int64, - ) -> libc::c_int; - pub fn sqlite3_bind_text( - _: *mut sqlite3_stmt, - _: libc::c_int, - _: *const libc::c_char, - _: libc::c_int, - _: Option ()>, - ) -> libc::c_int; - pub fn sqlite3_step(_: *mut sqlite3_stmt) -> libc::c_int; - pub fn sqlite3_column_int(_: *mut sqlite3_stmt, iCol: libc::c_int) -> libc::c_int; - pub fn sqlite3_column_int64(_: *mut sqlite3_stmt, iCol: libc::c_int) -> sqlite3_int64; - pub fn sqlite3_column_text(_: *mut sqlite3_stmt, iCol: libc::c_int) -> *const libc::c_uchar; - pub fn sqlite3_column_type(_: *mut sqlite3_stmt, iCol: libc::c_int) -> libc::c_int; - pub fn sqlite3_finalize(pStmt: *mut sqlite3_stmt) -> libc::c_int; - pub fn sqlite3_bind_int(_: *mut sqlite3_stmt, _: libc::c_int, _: libc::c_int) -> libc::c_int; - pub fn sqlite3_column_blob(_: *mut sqlite3_stmt, iCol: libc::c_int) -> *const libc::c_void; - pub fn sqlite3_column_bytes(_: *mut sqlite3_stmt, iCol: libc::c_int) -> libc::c_int; - pub fn sqlite3_reset(pStmt: *mut sqlite3_stmt) -> libc::c_int; - pub fn sqlite3_mprintf(_: *const libc::c_char, _: ...) -> *mut libc::c_char; - pub fn sqlite3_free(_: *mut libc::c_void); - pub fn sqlite3_bind_double( - _: *mut sqlite3_stmt, - _: libc::c_int, - _: libc::c_double, - ) -> libc::c_int; - pub fn sqlite3_column_double(_: *mut sqlite3_stmt, iCol: libc::c_int) -> libc::c_double; - pub fn sqlite3_threadsafe() -> libc::c_int; - pub fn sqlite3_close(_: *mut sqlite3) -> libc::c_int; - pub fn sqlite3_busy_timeout(_: *mut sqlite3, ms: libc::c_int) -> libc::c_int; - pub fn sqlite3_vmprintf(_: *const libc::c_char, _: ::std::ffi::VaList) -> *mut libc::c_char; - pub fn sqlite3_open_v2( - filename: *const libc::c_char, - ppDb: *mut *mut sqlite3, - flags: libc::c_int, - zVfs: *const libc::c_char, - ) -> libc::c_int; - pub fn sqlite3_errmsg(_: *mut sqlite3) -> *const libc::c_char; - pub fn sqlite3_prepare_v2( - db: *mut sqlite3, - zSql: *const libc::c_char, - nByte: libc::c_int, - ppStmt: *mut *mut sqlite3_stmt, - pzTail: *mut *const libc::c_char, - ) -> libc::c_int; }