mirror of
https://github.com/chatmail/core.git
synced 2026-05-22 16:26:31 +03:00
feat: reorg code, and prepare for c bindings
This commit is contained in:
5
deltachat-ffi/.gitignore
vendored
Normal file
5
deltachat-ffi/.gitignore
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
/target/
|
||||
**/*.rs.bk
|
||||
Cargo.lock
|
||||
.profile
|
||||
*.h
|
||||
21
deltachat-ffi/Cargo.toml
Normal file
21
deltachat-ffi/Cargo.toml
Normal file
@@ -0,0 +1,21 @@
|
||||
[package]
|
||||
name = "deltachat_ffi"
|
||||
version = "0.1.0"
|
||||
description = "Deltachat FFI"
|
||||
authors = ["dignifiedquire <dignifiedquire@gmail.com>"]
|
||||
edition = "2018"
|
||||
readme = "README.md"
|
||||
license = "MIT OR Apache-2.0"
|
||||
|
||||
keywords = ["deltachat", "chat", "openpgp", "email", "encryption"]
|
||||
categories = ["cryptography", "std", "email"]
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib", "staticlib"]
|
||||
|
||||
[dependencies]
|
||||
deltachat = { path = "../" }
|
||||
libc = "0.2"
|
||||
|
||||
[build-dependencies]
|
||||
cbindgen = "0.8"
|
||||
1
deltachat-ffi/README.md
Normal file
1
deltachat-ffi/README.md
Normal file
@@ -0,0 +1 @@
|
||||
# Delta Chat C Interface
|
||||
23
deltachat-ffi/build.rs
Normal file
23
deltachat-ffi/build.rs
Normal file
@@ -0,0 +1,23 @@
|
||||
fn main() {
|
||||
let crate_dir = std::env::var("CARGO_MANIFEST_DIR").unwrap();
|
||||
|
||||
let cfg = cbindgen::Config::from_root_or_default(std::path::Path::new(&crate_dir));
|
||||
|
||||
let c = cbindgen::Builder::new()
|
||||
.with_config(cfg)
|
||||
.with_crate(crate_dir)
|
||||
.with_language(cbindgen::Language::C)
|
||||
.generate();
|
||||
|
||||
// This is needed to ensure we don't panic if there are errors in the crates code
|
||||
// but rather just tell the rest of the system we can't proceed.
|
||||
match c {
|
||||
Ok(res) => {
|
||||
res.write_to_file("deltachat.h");
|
||||
}
|
||||
Err(err) => {
|
||||
eprintln!("unable to generate bindings: {:#?}", err);
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
3
deltachat-ffi/cbindgen.toml
Normal file
3
deltachat-ffi/cbindgen.toml
Normal file
@@ -0,0 +1,3 @@
|
||||
[parse]
|
||||
parse_deps = true
|
||||
include = ["deltachat"]
|
||||
128
deltachat-ffi/src/lib.rs
Normal file
128
deltachat-ffi/src/lib.rs
Normal file
@@ -0,0 +1,128 @@
|
||||
#![allow(
|
||||
non_camel_case_types,
|
||||
non_snake_case,
|
||||
non_upper_case_globals,
|
||||
non_upper_case_globals,
|
||||
non_camel_case_types,
|
||||
non_snake_case
|
||||
)]
|
||||
use deltachat::*;
|
||||
use libc;
|
||||
|
||||
pub const DC_VERSION_STR: &'static str = "0.43.0\x00";
|
||||
|
||||
#[no_mangle]
|
||||
pub type dc_array_t = dc_array::dc_array_t;
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_array_unref(a: *mut dc_array::dc_array_t) {
|
||||
dc_array::dc_array_unref(a)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_array_add_uint(array: *mut dc_array_t, item: libc::c_ulong) {
|
||||
dc_array::dc_array_add_uint(array, item)
|
||||
}
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_array_add_id(array: *mut dc_array_t, item: libc::c_uint) {
|
||||
dc_array::dc_array_add_id(array, item)
|
||||
}
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_array_add_ptr(array: *mut dc_array_t, item: *mut libc::c_void) {
|
||||
dc_array::dc_array_add_ptr(array, item)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_array_get_cnt(array: *const dc_array_t) -> libc::c_ulong {
|
||||
dc_array::dc_array_get_cnt(array)
|
||||
}
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_array_get_uint(
|
||||
array: *const dc_array_t,
|
||||
index: libc::c_ulong,
|
||||
) -> libc::c_ulong {
|
||||
dc_array::dc_array_get_uint(array, index)
|
||||
}
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_array_get_id(
|
||||
array: *const dc_array_t,
|
||||
index: libc::c_ulong,
|
||||
) -> libc::c_uint {
|
||||
dc_array::dc_array_get_id(array, index)
|
||||
}
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_array_get_ptr(
|
||||
array: *const dc_array_t,
|
||||
index: libc::c_ulong,
|
||||
) -> *mut libc::c_void {
|
||||
dc_array::dc_array_get_ptr(array, index)
|
||||
}
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_array_get_latitude(
|
||||
array: *const dc_array_t,
|
||||
index: libc::c_ulong,
|
||||
) -> libc::c_double {
|
||||
dc_array::dc_array_get_latitude(array, index)
|
||||
}
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_array_get_longitude(
|
||||
array: *const dc_array_t,
|
||||
index: libc::c_ulong,
|
||||
) -> libc::c_double {
|
||||
dc_array::dc_array_get_longitude(array, index)
|
||||
}
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_array_get_accuracy(
|
||||
array: *const dc_array_t,
|
||||
index: libc::c_ulong,
|
||||
) -> libc::c_double {
|
||||
dc_array::dc_array_get_accuracy(array, index)
|
||||
}
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_array_get_timestamp(
|
||||
array: *const dc_array_t,
|
||||
index: libc::c_ulong,
|
||||
) -> libc::c_long {
|
||||
dc_array::dc_array_get_timestamp(array, index)
|
||||
}
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_array_get_chat_id(
|
||||
array: *const dc_array_t,
|
||||
index: libc::c_ulong,
|
||||
) -> libc::c_uint {
|
||||
dc_array::dc_array_get_chat_id(array, index)
|
||||
}
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_array_get_contact_id(
|
||||
array: *const dc_array_t,
|
||||
index: libc::c_ulong,
|
||||
) -> libc::c_uint {
|
||||
dc_array::dc_array_get_contact_id(array, index)
|
||||
}
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_array_get_msg_id(
|
||||
array: *const dc_array_t,
|
||||
index: libc::c_ulong,
|
||||
) -> libc::c_uint {
|
||||
dc_array::dc_array_get_msg_id(array, index)
|
||||
}
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_array_get_marker(
|
||||
array: *const dc_array_t,
|
||||
index: libc::c_ulong,
|
||||
) -> *mut libc::c_char {
|
||||
dc_array::dc_array_get_marker(array, index)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_array_search_id(
|
||||
array: *const dc_array_t,
|
||||
needle: libc::c_uint,
|
||||
ret_index: *mut libc::c_ulong,
|
||||
) -> libc::c_int {
|
||||
dc_array::dc_array_search_id(array, needle, ret_index)
|
||||
}
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_array_get_raw(array: *const dc_array_t) -> *const libc::c_ulong {
|
||||
dc_array::dc_array_get_raw(array)
|
||||
}
|
||||
Reference in New Issue
Block a user