mirror of
https://github.com/chatmail/core.git
synced 2026-05-04 13:56:30 +03:00
refactor: start using rust for allocations & locks + no more libetpan
This commit is contained in:
@@ -1,6 +1,4 @@
|
||||
# copied from http://koushiro.me/2019/04/30/Building-and-Testing-Rust-projects-on-CircleCI/
|
||||
# TODO remove things that aren't needed for apt
|
||||
# TODO might want to create our own docker image for this and get rid of apt stuff
|
||||
|
||||
version: 2.1
|
||||
jobs:
|
||||
@@ -14,38 +12,15 @@ jobs:
|
||||
- checkout
|
||||
|
||||
- run:
|
||||
name: Setup build environment (TODO move this to custom docker container)
|
||||
name: Setup build environment
|
||||
command: |
|
||||
apt update
|
||||
apt install -y sudo curl build-essential git pkg-config zlib1g-dev python libssl-dev autoconf libtool
|
||||
apt install -y curl build-essential autoconf libtool git python pkg-config zlib1g-dev libssl-dev libetpan-dev libsasl2-dev
|
||||
# this will pick default toolchain from `rust-toolchain` file
|
||||
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --no-modify-path --default-toolchain none -y;
|
||||
source $HOME/.cargo/env
|
||||
no_output_timeout: 1800s
|
||||
|
||||
- run:
|
||||
name: build etpan (TODO move this to custom docker container)
|
||||
command: |
|
||||
curl -L -o libetpan-1.9.1.tar.gz https://github.com/dinhviethoa/libetpan/archive/1.9.1.tar.gz
|
||||
tar xzf libetpan-1.9.1.tar.gz
|
||||
cd libetpan-1.9.1
|
||||
./autogen.sh
|
||||
./configure --disable-silent-rules --enable-ipv6 --enable-iconv --disable-db --with-openssl --with-sasl --with-zlib --without-curl --without-expat
|
||||
make -j $(nproc)
|
||||
sudo make install
|
||||
sudo ldconfig -v
|
||||
|
||||
- run:
|
||||
name: build sasl2 (TODO move this to custom docker container)
|
||||
command: |
|
||||
curl -O https://www.cyrusimap.org/releases/cyrus-sasl-2.1.27.tar.gz
|
||||
tar zxf cyrus-sasl-2.1.27.tar.gz
|
||||
cd cyrus-sasl-2.1.27
|
||||
./configure --enable-shared --disable-cmulocal --disable-sample --disable-obsolete_cram_attr --disable-obsolete_digest_attr --disable-alwaystrue --enable-checkapop --enable-cram --enable-digest --enable-scram --enable-plain --enable-anon --enable-login
|
||||
make -j $(nproc)
|
||||
sudo make install
|
||||
sudo ldconfig -v
|
||||
|
||||
- run:
|
||||
name: Format
|
||||
command: |
|
||||
@@ -60,6 +35,13 @@ jobs:
|
||||
export RUST_BACKTRACE=1
|
||||
cargo test
|
||||
|
||||
- run:
|
||||
name: Build deltachat-ffi
|
||||
command: |
|
||||
export PATH=~/.cargo/bin:$PATH
|
||||
export RUST_BACKTRACE=1
|
||||
cargo build --release -p deltachat_ffi
|
||||
|
||||
workflows:
|
||||
version: 2.1
|
||||
build:
|
||||
|
||||
10
Cargo.toml
10
Cargo.toml
@@ -21,6 +21,12 @@ libsqlite3-sys = { version = "0.14.0", features = ["bundled"] }
|
||||
reqwest = "0.9.15"
|
||||
num-derive = "0.2.5"
|
||||
num-traits = "0.2.6"
|
||||
native-tls = "0.2.3"
|
||||
lettre = "0.9.0"
|
||||
imap = "1.0.1"
|
||||
# rental = "0.5.3"
|
||||
mmime = { git = "https://github.com/dignifiedquire/mmime" }
|
||||
base64 = "0.10.1"
|
||||
|
||||
[dev-dependencies]
|
||||
tempfile = "3.0.7"
|
||||
@@ -37,3 +43,7 @@ name = "simple"
|
||||
name = "repl"
|
||||
path = "examples/repl/main.rs"
|
||||
|
||||
|
||||
[features]
|
||||
default = []
|
||||
vendored = ["native-tls/vendored"]
|
||||
|
||||
49
build.rs
49
build.rs
@@ -1,9 +1,5 @@
|
||||
extern crate cc;
|
||||
|
||||
fn link_dylib(lib: &str) {
|
||||
println!("cargo:rustc-link-lib=dylib={}", lib);
|
||||
}
|
||||
|
||||
fn link_static(lib: &str) {
|
||||
println!("cargo:rustc-link-lib=static={}", lib);
|
||||
}
|
||||
@@ -29,57 +25,12 @@ fn main() {
|
||||
build_tools();
|
||||
|
||||
add_search_path("/usr/local/lib");
|
||||
add_search_path("./include/include");
|
||||
add_search_path("./include/libs");
|
||||
|
||||
let target = std::env::var("TARGET").unwrap();
|
||||
if target.contains("-apple") || target.contains("-darwin") {
|
||||
link_static("etpan");
|
||||
link_dylib("iconv");
|
||||
|
||||
link_framework("CoreFoundation");
|
||||
link_framework("CoreServices");
|
||||
link_framework("Security");
|
||||
|
||||
link_dylib("sasl2");
|
||||
link_dylib("z");
|
||||
link_dylib("pthread");
|
||||
} else if target.contains("-android") {
|
||||
add_search_path("./include/cyrus-sasl-android-4/include");
|
||||
add_search_path("./include/openssl-android-3/include");
|
||||
add_search_path("./include/iconv-android-1/include");
|
||||
|
||||
let arch = if target.contains("x86") {
|
||||
"x86"
|
||||
} else if target.contains("64") {
|
||||
"arm64-v8a"
|
||||
} else if target.contains("v7") {
|
||||
"armeabi-v7a"
|
||||
} else {
|
||||
"armeabi"
|
||||
};
|
||||
|
||||
add_search_path(&format!("./include/libs/{}", arch));
|
||||
add_search_path(&format!("./include/iconv-android-1/libs/{}", arch));
|
||||
add_search_path(&format!("./include/openssl-android-3/libs/{}", arch));
|
||||
add_search_path(&format!("./include/cyrus-sasl-android-4/libs/{}", arch));
|
||||
|
||||
// dependencies for libetpan
|
||||
link_static("crypto");
|
||||
link_static("sasl2");
|
||||
link_static("iconv");
|
||||
link_static("ssl");
|
||||
link_dylib("z");
|
||||
|
||||
// libetpan iteself
|
||||
link_static("etpan");
|
||||
} else if target.contains("-linux") {
|
||||
link_dylib("etpan");
|
||||
link_dylib("sasl2");
|
||||
link_dylib("z");
|
||||
link_dylib("pthread");
|
||||
} else {
|
||||
panic!("unsupported target");
|
||||
}
|
||||
|
||||
// local tools
|
||||
|
||||
@@ -28,11 +28,14 @@ pub unsafe extern "C" fn dc_context_new(
|
||||
userdata: *mut libc::c_void,
|
||||
os_name: *const libc::c_char,
|
||||
) -> *mut dc_context_t {
|
||||
dc_context::dc_context_new(cb, userdata, os_name)
|
||||
let ctx = dc_context::dc_context_new(cb, userdata, os_name);
|
||||
Box::into_raw(Box::new(ctx))
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_context_unref(context: *mut dc_context_t) {
|
||||
assert!(!context.is_null());
|
||||
let context = &mut *context;
|
||||
dc_context::dc_context_unref(context)
|
||||
}
|
||||
|
||||
@@ -40,6 +43,9 @@ pub unsafe extern "C" fn dc_context_unref(context: *mut dc_context_t) {
|
||||
pub unsafe extern "C" fn dc_get_userdata(
|
||||
context: *mut dc_context::dc_context_t,
|
||||
) -> *mut libc::c_void {
|
||||
assert!(!context.is_null());
|
||||
let context = &mut *context;
|
||||
|
||||
dc_context::dc_get_userdata(context)
|
||||
}
|
||||
|
||||
@@ -49,16 +55,23 @@ pub unsafe extern "C" fn dc_open(
|
||||
dbfile: *mut libc::c_char,
|
||||
blobdir: *mut libc::c_char,
|
||||
) -> libc::c_int {
|
||||
assert!(!context.is_null());
|
||||
let context = &mut *context;
|
||||
|
||||
dc_context::dc_open(context, dbfile, blobdir)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_close(context: *mut dc_context::dc_context_t) {
|
||||
assert!(!context.is_null());
|
||||
let context = &mut *context;
|
||||
dc_context::dc_close(context)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_is_open(context: *mut dc_context::dc_context_t) -> libc::c_int {
|
||||
assert!(!context.is_null());
|
||||
let context = &mut *context;
|
||||
dc_context::dc_is_open(context)
|
||||
}
|
||||
|
||||
@@ -66,6 +79,9 @@ pub unsafe extern "C" fn dc_is_open(context: *mut dc_context::dc_context_t) -> l
|
||||
pub unsafe extern "C" fn dc_get_blobdir(
|
||||
context: *mut dc_context::dc_context_t,
|
||||
) -> *mut libc::c_char {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_context::dc_get_blobdir(context)
|
||||
}
|
||||
|
||||
@@ -75,6 +91,9 @@ pub unsafe extern "C" fn dc_set_config(
|
||||
key: *mut libc::c_char,
|
||||
value: *mut libc::c_char,
|
||||
) -> libc::c_int {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_context::dc_set_config(context, key, value)
|
||||
}
|
||||
|
||||
@@ -83,11 +102,17 @@ pub unsafe extern "C" fn dc_get_config(
|
||||
context: *mut dc_context::dc_context_t,
|
||||
key: *mut libc::c_char,
|
||||
) -> *mut libc::c_char {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_context::dc_get_config(context, key)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_get_info(context: *mut dc_context::dc_context_t) -> *mut libc::c_char {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_context::dc_get_info(context)
|
||||
}
|
||||
|
||||
@@ -97,6 +122,9 @@ pub unsafe extern "C" fn dc_get_oauth2_url(
|
||||
addr: *mut libc::c_char,
|
||||
redirect: *mut libc::c_char,
|
||||
) -> *mut libc::c_char {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_oauth2::dc_get_oauth2_url(context, addr, redirect)
|
||||
}
|
||||
|
||||
@@ -107,91 +135,142 @@ pub unsafe extern "C" fn dc_get_version_str() -> *mut libc::c_char {
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_configure(context: *mut dc_context::dc_context_t) {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_configure::dc_configure(context)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_is_configured(context: *mut dc_context::dc_context_t) -> libc::c_int {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_configure::dc_is_configured(context)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_perform_imap_jobs(context: *mut dc_context::dc_context_t) {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_job::dc_perform_imap_jobs(context)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_perform_imap_fetch(context: *mut dc_context::dc_context_t) {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_job::dc_perform_imap_fetch(context)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_perform_imap_idle(context: *mut dc_context::dc_context_t) {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_job::dc_perform_imap_idle(context)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_interrupt_imap_idle(context: *mut dc_context::dc_context_t) {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_job::dc_interrupt_imap_idle(context)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_perform_mvbox_fetch(context: *mut dc_context::dc_context_t) {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_job::dc_perform_mvbox_fetch(context)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_perform_mvbox_idle(context: *mut dc_context::dc_context_t) {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_job::dc_perform_mvbox_idle(context)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_interrupt_mvbox_idle(context: *mut dc_context::dc_context_t) {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_job::dc_interrupt_mvbox_idle(context)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_perform_sentbox_fetch(context: *mut dc_context::dc_context_t) {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_job::dc_perform_sentbox_fetch(context)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_perform_sentbox_idle(context: *mut dc_context::dc_context_t) {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_job::dc_perform_sentbox_idle(context)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_interrupt_sentbox_idle(context: *mut dc_context::dc_context_t) {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_job::dc_interrupt_sentbox_idle(context)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_perform_smtp_jobs(context: *mut dc_context::dc_context_t) {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_job::dc_perform_smtp_jobs(context)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_perform_smtp_idle(context: *mut dc_context::dc_context_t) {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_job::dc_perform_smtp_idle(context)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_interrupt_smtp_idle(context: *mut dc_context::dc_context_t) {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_job::dc_interrupt_smtp_idle(context)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_maybe_network(context: *mut dc_context::dc_context_t) {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_job::dc_maybe_network(context)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_get_chatlist(
|
||||
pub unsafe extern "C" fn dc_get_chatlist<'a>(
|
||||
context: *mut dc_context::dc_context_t,
|
||||
flags: libc::c_int,
|
||||
query_str: *mut libc::c_char,
|
||||
query_id: libc::uint32_t,
|
||||
) -> *mut dc_chatlist::dc_chatlist_t {
|
||||
) -> *mut dc_chatlist::dc_chatlist_t<'a> {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_chatlist::dc_get_chatlist(context, flags, query_str, query_id)
|
||||
}
|
||||
|
||||
@@ -200,6 +279,9 @@ pub unsafe extern "C" fn dc_create_chat_by_msg_id(
|
||||
context: *mut dc_context::dc_context_t,
|
||||
msg_id: libc::uint32_t,
|
||||
) -> libc::uint32_t {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_chat::dc_create_chat_by_msg_id(context, msg_id)
|
||||
}
|
||||
|
||||
@@ -208,6 +290,9 @@ pub unsafe extern "C" fn dc_create_chat_by_contact_id(
|
||||
context: *mut dc_context::dc_context_t,
|
||||
contact_id: libc::uint32_t,
|
||||
) -> libc::uint32_t {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_chat::dc_create_chat_by_contact_id(context, contact_id)
|
||||
}
|
||||
|
||||
@@ -216,6 +301,9 @@ pub unsafe extern "C" fn dc_get_chat_id_by_contact_id(
|
||||
context: *mut dc_context::dc_context_t,
|
||||
contact_id: libc::uint32_t,
|
||||
) -> libc::uint32_t {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_chat::dc_get_chat_id_by_contact_id(context, contact_id)
|
||||
}
|
||||
|
||||
@@ -225,6 +313,9 @@ pub unsafe extern "C" fn dc_prepare_msg(
|
||||
chat_id: libc::uint32_t,
|
||||
msg: *mut dc_msg::dc_msg_t,
|
||||
) -> libc::uint32_t {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_chat::dc_prepare_msg(context, chat_id, msg)
|
||||
}
|
||||
|
||||
@@ -234,6 +325,9 @@ pub unsafe extern "C" fn dc_send_msg(
|
||||
chat_id: libc::uint32_t,
|
||||
msg: *mut dc_msg::dc_msg_t,
|
||||
) -> libc::uint32_t {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_chat::dc_send_msg(context, chat_id, msg)
|
||||
}
|
||||
|
||||
@@ -243,6 +337,9 @@ pub unsafe extern "C" fn dc_send_text_msg(
|
||||
chat_id: libc::uint32_t,
|
||||
text_to_send: *mut libc::c_char,
|
||||
) -> libc::uint32_t {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_chat::dc_send_text_msg(context, chat_id, text_to_send)
|
||||
}
|
||||
|
||||
@@ -252,14 +349,20 @@ pub unsafe extern "C" fn dc_set_draft(
|
||||
chat_id: libc::uint32_t,
|
||||
msg: *mut dc_msg::dc_msg_t,
|
||||
) {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_chat::dc_set_draft(context, chat_id, msg)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_get_draft(
|
||||
pub unsafe extern "C" fn dc_get_draft<'a>(
|
||||
context: *mut dc_context::dc_context_t,
|
||||
chat_id: libc::uint32_t,
|
||||
) -> *mut dc_msg::dc_msg_t {
|
||||
) -> *mut dc_msg::dc_msg_t<'a> {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_chat::dc_get_draft(context, chat_id)
|
||||
}
|
||||
|
||||
@@ -270,6 +373,9 @@ pub unsafe extern "C" fn dc_get_chat_msgs(
|
||||
flags: libc::uint32_t,
|
||||
marker1before: libc::uint32_t,
|
||||
) -> *mut dc_array::dc_array_t {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_chat::dc_get_chat_msgs(context, chat_id, flags, marker1before)
|
||||
}
|
||||
|
||||
@@ -278,6 +384,9 @@ pub unsafe extern "C" fn dc_get_msg_cnt(
|
||||
context: *mut dc_context::dc_context_t,
|
||||
chat_id: libc::uint32_t,
|
||||
) -> libc::c_int {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_chat::dc_get_msg_cnt(context, chat_id)
|
||||
}
|
||||
|
||||
@@ -286,6 +395,9 @@ pub unsafe extern "C" fn dc_get_fresh_msg_cnt(
|
||||
context: *mut dc_context::dc_context_t,
|
||||
chat_id: libc::uint32_t,
|
||||
) -> libc::c_int {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_chat::dc_get_fresh_msg_cnt(context, chat_id)
|
||||
}
|
||||
|
||||
@@ -293,6 +405,9 @@ pub unsafe extern "C" fn dc_get_fresh_msg_cnt(
|
||||
pub unsafe extern "C" fn dc_get_fresh_msgs(
|
||||
context: *mut dc_context::dc_context_t,
|
||||
) -> *mut dc_array::dc_array_t {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_context::dc_get_fresh_msgs(context)
|
||||
}
|
||||
|
||||
@@ -301,11 +416,17 @@ pub unsafe extern "C" fn dc_marknoticed_chat(
|
||||
context: *mut dc_context::dc_context_t,
|
||||
chat_id: libc::uint32_t,
|
||||
) {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_chat::dc_marknoticed_chat(context, chat_id)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_marknoticed_all_chats(context: *mut dc_context::dc_context_t) {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_chat::dc_marknoticed_all_chats(context)
|
||||
}
|
||||
|
||||
@@ -317,6 +438,9 @@ pub unsafe extern "C" fn dc_get_chat_media(
|
||||
or_msg_type2: libc::c_int,
|
||||
or_msg_type3: libc::c_int,
|
||||
) -> *mut dc_array::dc_array_t {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_chat::dc_get_chat_media(context, chat_id, msg_type, or_msg_type2, or_msg_type3)
|
||||
}
|
||||
|
||||
@@ -329,6 +453,9 @@ pub unsafe extern "C" fn dc_get_next_media(
|
||||
or_msg_type2: libc::c_int,
|
||||
or_msg_type3: libc::c_int,
|
||||
) -> libc::uint32_t {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_chat::dc_get_next_media(context, msg_id, dir, msg_type, or_msg_type2, or_msg_type3)
|
||||
}
|
||||
|
||||
@@ -338,6 +465,9 @@ pub unsafe extern "C" fn dc_archive_chat(
|
||||
chat_id: libc::uint32_t,
|
||||
archive: libc::c_int,
|
||||
) {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_chat::dc_archive_chat(context, chat_id, archive)
|
||||
}
|
||||
|
||||
@@ -346,6 +476,9 @@ pub unsafe extern "C" fn dc_delete_chat(
|
||||
context: *mut dc_context::dc_context_t,
|
||||
chat_id: libc::uint32_t,
|
||||
) {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_chat::dc_delete_chat(context, chat_id)
|
||||
}
|
||||
|
||||
@@ -354,6 +487,9 @@ pub unsafe extern "C" fn dc_get_chat_contacts(
|
||||
context: *mut dc_context::dc_context_t,
|
||||
chat_id: libc::uint32_t,
|
||||
) -> *mut dc_array::dc_array_t {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_chat::dc_get_chat_contacts(context, chat_id)
|
||||
}
|
||||
|
||||
@@ -363,14 +499,20 @@ pub unsafe extern "C" fn dc_search_msgs(
|
||||
chat_id: libc::uint32_t,
|
||||
query: *mut libc::c_char,
|
||||
) -> *mut dc_array::dc_array_t {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_context::dc_search_msgs(context, chat_id, query)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_get_chat(
|
||||
pub unsafe extern "C" fn dc_get_chat<'a>(
|
||||
context: *mut dc_context::dc_context_t,
|
||||
chat_id: libc::uint32_t,
|
||||
) -> *mut dc_chat::dc_chat_t {
|
||||
) -> *mut dc_chat::dc_chat_t<'a> {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_chat::dc_get_chat(context, chat_id)
|
||||
}
|
||||
|
||||
@@ -380,6 +522,9 @@ pub unsafe extern "C" fn dc_create_group_chat(
|
||||
verified: libc::c_int,
|
||||
name: *mut libc::c_char,
|
||||
) -> libc::uint32_t {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_chat::dc_create_group_chat(context, verified, name)
|
||||
}
|
||||
|
||||
@@ -389,6 +534,9 @@ pub unsafe extern "C" fn dc_is_contact_in_chat(
|
||||
chat_id: libc::uint32_t,
|
||||
contact_id: libc::uint32_t,
|
||||
) -> libc::c_int {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_chat::dc_is_contact_in_chat(context, chat_id, contact_id)
|
||||
}
|
||||
|
||||
@@ -398,6 +546,9 @@ pub unsafe extern "C" fn dc_add_contact_to_chat(
|
||||
chat_id: libc::uint32_t,
|
||||
contact_id: libc::uint32_t,
|
||||
) -> libc::c_int {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_chat::dc_add_contact_to_chat(context, chat_id, contact_id)
|
||||
}
|
||||
|
||||
@@ -407,6 +558,9 @@ pub unsafe extern "C" fn dc_remove_contact_from_chat(
|
||||
chat_id: libc::uint32_t,
|
||||
contact_id: libc::uint32_t,
|
||||
) -> libc::c_int {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_chat::dc_remove_contact_from_chat(context, chat_id, contact_id)
|
||||
}
|
||||
|
||||
@@ -416,6 +570,9 @@ pub unsafe extern "C" fn dc_set_chat_name(
|
||||
chat_id: libc::uint32_t,
|
||||
name: *mut libc::c_char,
|
||||
) -> libc::c_int {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_chat::dc_set_chat_name(context, chat_id, name)
|
||||
}
|
||||
|
||||
@@ -425,6 +582,9 @@ pub unsafe extern "C" fn dc_set_chat_profile_image(
|
||||
chat_id: libc::uint32_t,
|
||||
image: *mut libc::c_char,
|
||||
) -> libc::c_int {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_chat::dc_set_chat_profile_image(context, chat_id, image)
|
||||
}
|
||||
|
||||
@@ -433,6 +593,9 @@ pub unsafe extern "C" fn dc_get_msg_info(
|
||||
context: *mut dc_context::dc_context_t,
|
||||
msg_id: libc::uint32_t,
|
||||
) -> *mut libc::c_char {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_msg::dc_get_msg_info(context, msg_id)
|
||||
}
|
||||
|
||||
@@ -441,6 +604,9 @@ pub unsafe extern "C" fn dc_get_mime_headers(
|
||||
context: *mut dc_context::dc_context_t,
|
||||
msg_id: libc::uint32_t,
|
||||
) -> *mut libc::c_char {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_msg::dc_get_mime_headers(context, msg_id)
|
||||
}
|
||||
|
||||
@@ -450,6 +616,9 @@ pub unsafe extern "C" fn dc_delete_msgs(
|
||||
msg_ids: *const libc::uint32_t,
|
||||
msg_cnt: libc::c_int,
|
||||
) {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_msg::dc_delete_msgs(context, msg_ids, msg_cnt)
|
||||
}
|
||||
|
||||
@@ -460,6 +629,9 @@ pub unsafe extern "C" fn dc_forward_msgs(
|
||||
msg_cnt: libc::c_int,
|
||||
chat_id: libc::uint32_t,
|
||||
) {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_chat::dc_forward_msgs(context, msg_ids, msg_cnt, chat_id)
|
||||
}
|
||||
|
||||
@@ -468,6 +640,9 @@ pub unsafe extern "C" fn dc_marknoticed_contact(
|
||||
context: *mut dc_context::dc_context_t,
|
||||
contact_id: libc::uint32_t,
|
||||
) {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_contact::dc_marknoticed_contact(context, contact_id)
|
||||
}
|
||||
|
||||
@@ -477,6 +652,9 @@ pub unsafe extern "C" fn dc_markseen_msgs(
|
||||
msg_ids: *const libc::uint32_t,
|
||||
msg_cnt: libc::c_int,
|
||||
) {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_msg::dc_markseen_msgs(context, msg_ids, msg_cnt)
|
||||
}
|
||||
|
||||
@@ -487,14 +665,20 @@ pub unsafe extern "C" fn dc_star_msgs(
|
||||
msg_cnt: libc::c_int,
|
||||
star: libc::c_int,
|
||||
) {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_msg::dc_star_msgs(context, msg_ids, msg_cnt, star)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_get_msg(
|
||||
pub unsafe extern "C" fn dc_get_msg<'a>(
|
||||
context: *mut dc_context::dc_context_t,
|
||||
msg_id: libc::uint32_t,
|
||||
) -> *mut dc_msg::dc_msg_t {
|
||||
) -> *mut dc_msg::dc_msg_t<'a> {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_msg::dc_get_msg(context, msg_id)
|
||||
}
|
||||
|
||||
@@ -508,6 +692,9 @@ pub unsafe extern "C" fn dc_lookup_contact_id_by_addr(
|
||||
context: *mut dc_context::dc_context_t,
|
||||
addr: *mut libc::c_char,
|
||||
) -> libc::uint32_t {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_contact::dc_lookup_contact_id_by_addr(context, addr)
|
||||
}
|
||||
|
||||
@@ -517,6 +704,9 @@ pub unsafe extern "C" fn dc_create_contact(
|
||||
name: *mut libc::c_char,
|
||||
addr: *mut libc::c_char,
|
||||
) -> libc::uint32_t {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_contact::dc_create_contact(context, name, addr)
|
||||
}
|
||||
|
||||
@@ -525,6 +715,9 @@ pub unsafe extern "C" fn dc_add_address_book(
|
||||
context: *mut dc_context::dc_context_t,
|
||||
addr_book: *mut libc::c_char,
|
||||
) -> libc::c_int {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_contact::dc_add_address_book(context, addr_book)
|
||||
}
|
||||
|
||||
@@ -534,11 +727,17 @@ pub unsafe extern "C" fn dc_get_contacts(
|
||||
flags: libc::uint32_t,
|
||||
query: *mut libc::c_char,
|
||||
) -> *mut dc_array::dc_array_t {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_contact::dc_get_contacts(context, flags, query)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_get_blocked_cnt(context: *mut dc_context::dc_context_t) -> libc::c_int {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_contact::dc_get_blocked_cnt(context)
|
||||
}
|
||||
|
||||
@@ -546,6 +745,9 @@ pub unsafe extern "C" fn dc_get_blocked_cnt(context: *mut dc_context::dc_context
|
||||
pub unsafe extern "C" fn dc_get_blocked_contacts(
|
||||
context: *mut dc_context::dc_context_t,
|
||||
) -> *mut dc_array::dc_array_t {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_contact::dc_get_blocked_contacts(context)
|
||||
}
|
||||
|
||||
@@ -555,6 +757,9 @@ pub unsafe extern "C" fn dc_block_contact(
|
||||
contact_id: libc::uint32_t,
|
||||
block: libc::c_int,
|
||||
) {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_contact::dc_block_contact(context, contact_id, block)
|
||||
}
|
||||
|
||||
@@ -563,6 +768,9 @@ pub unsafe extern "C" fn dc_get_contact_encrinfo(
|
||||
context: *mut dc_context::dc_context_t,
|
||||
contact_id: libc::uint32_t,
|
||||
) -> *mut libc::c_char {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_contact::dc_get_contact_encrinfo(context, contact_id)
|
||||
}
|
||||
|
||||
@@ -571,14 +779,20 @@ pub unsafe extern "C" fn dc_delete_contact(
|
||||
context: *mut dc_context::dc_context_t,
|
||||
contact_id: libc::uint32_t,
|
||||
) -> libc::c_int {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_contact::dc_delete_contact(context, contact_id)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_get_contact(
|
||||
pub unsafe extern "C" fn dc_get_contact<'a>(
|
||||
context: *mut dc_context::dc_context_t,
|
||||
contact_id: libc::uint32_t,
|
||||
) -> *mut dc_contact::dc_contact_t {
|
||||
) -> *mut dc_contact::dc_contact_t<'a> {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_contact::dc_get_contact(context, contact_id)
|
||||
}
|
||||
|
||||
@@ -589,6 +803,9 @@ pub unsafe extern "C" fn dc_imex(
|
||||
param1: *mut libc::c_char,
|
||||
param2: *mut libc::c_char,
|
||||
) {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_imex::dc_imex(context, what, param1, param2)
|
||||
}
|
||||
|
||||
@@ -597,6 +814,9 @@ pub unsafe extern "C" fn dc_imex_has_backup(
|
||||
context: *mut dc_context::dc_context_t,
|
||||
dir: *mut libc::c_char,
|
||||
) -> *mut libc::c_char {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_imex::dc_imex_has_backup(context, dir)
|
||||
}
|
||||
|
||||
@@ -604,6 +824,9 @@ pub unsafe extern "C" fn dc_imex_has_backup(
|
||||
pub unsafe extern "C" fn dc_initiate_key_transfer(
|
||||
context: *mut dc_context::dc_context_t,
|
||||
) -> *mut libc::c_char {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_imex::dc_initiate_key_transfer(context)
|
||||
}
|
||||
|
||||
@@ -613,11 +836,17 @@ pub unsafe extern "C" fn dc_continue_key_transfer(
|
||||
msg_id: libc::uint32_t,
|
||||
setup_code: *mut libc::c_char,
|
||||
) -> libc::c_int {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_imex::dc_continue_key_transfer(context, msg_id, setup_code)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_stop_ongoing_process(context: *mut dc_context::dc_context_t) {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_configure::dc_stop_ongoing_process(context)
|
||||
}
|
||||
|
||||
@@ -626,6 +855,9 @@ pub unsafe extern "C" fn dc_check_qr(
|
||||
context: *mut dc_context::dc_context_t,
|
||||
qr: *mut libc::c_char,
|
||||
) -> *mut dc_lot::dc_lot_t {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_qr::dc_check_qr(context, qr)
|
||||
}
|
||||
|
||||
@@ -634,6 +866,9 @@ pub unsafe extern "C" fn dc_get_securejoin_qr(
|
||||
context: *mut dc_context::dc_context_t,
|
||||
chat_id: libc::uint32_t,
|
||||
) -> *mut libc::c_char {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_securejoin::dc_get_securejoin_qr(context, chat_id)
|
||||
}
|
||||
|
||||
@@ -642,6 +877,9 @@ pub unsafe extern "C" fn dc_join_securejoin(
|
||||
context: *mut dc_context::dc_context_t,
|
||||
qr: *mut libc::c_char,
|
||||
) -> libc::uint32_t {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_securejoin::dc_join_securejoin(context, qr)
|
||||
}
|
||||
|
||||
@@ -651,6 +889,9 @@ pub unsafe extern "C" fn dc_send_locations_to_chat(
|
||||
chat_id: libc::uint32_t,
|
||||
seconds: libc::c_int,
|
||||
) {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_location::dc_send_locations_to_chat(context, chat_id, seconds)
|
||||
}
|
||||
|
||||
@@ -659,6 +900,9 @@ pub unsafe extern "C" fn dc_is_sending_locations_to_chat(
|
||||
context: *mut dc_context::dc_context_t,
|
||||
chat_id: libc::uint32_t,
|
||||
) -> libc::c_int {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_location::dc_is_sending_locations_to_chat(context, chat_id)
|
||||
}
|
||||
|
||||
@@ -669,6 +913,9 @@ pub unsafe extern "C" fn dc_set_location(
|
||||
longitude: libc::c_double,
|
||||
accuracy: libc::c_double,
|
||||
) -> libc::c_int {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_location::dc_set_location(context, latitude, longitude, accuracy)
|
||||
}
|
||||
|
||||
@@ -680,11 +927,17 @@ pub unsafe extern "C" fn dc_get_locations(
|
||||
timestamp_begin: libc::time_t,
|
||||
timestamp_end: libc::time_t,
|
||||
) -> *mut dc_array::dc_array_t {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_location::dc_get_locations(context, chat_id, contact_id, timestamp_begin, timestamp_end)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_delete_all_locations(context: *mut dc_context::dc_context_t) {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_location::dc_delete_all_locations(context)
|
||||
}
|
||||
|
||||
@@ -809,7 +1062,7 @@ pub unsafe extern "C" fn dc_array_get_raw(array: *const dc_array_t) -> *const li
|
||||
// dc_chatlist_t
|
||||
|
||||
#[no_mangle]
|
||||
pub type dc_chatlist_t = dc_chatlist::dc_chatlist_t;
|
||||
pub type dc_chatlist_t<'a> = dc_chatlist::dc_chatlist_t<'a>;
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_chatlist_unref(chatlist: *mut dc_chatlist::dc_chatlist_t) {
|
||||
@@ -840,10 +1093,10 @@ pub unsafe extern "C" fn dc_chatlist_get_msg_id(
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_chatlist_get_summary(
|
||||
chatlist: *mut dc_chatlist::dc_chatlist_t,
|
||||
pub unsafe extern "C" fn dc_chatlist_get_summary<'a>(
|
||||
chatlist: *mut dc_chatlist::dc_chatlist_t<'a>,
|
||||
index: libc::size_t,
|
||||
chat: *mut dc_chat::dc_chat_t,
|
||||
chat: *mut dc_chat::dc_chat_t<'a>,
|
||||
) -> *mut dc_lot::dc_lot_t {
|
||||
dc_chatlist::dc_chatlist_get_summary(chatlist, index, chat)
|
||||
}
|
||||
@@ -851,14 +1104,15 @@ pub unsafe extern "C" fn dc_chatlist_get_summary(
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_chatlist_get_context(
|
||||
chatlist: *mut dc_chatlist::dc_chatlist_t,
|
||||
) -> *mut dc_context::dc_context_t {
|
||||
dc_chatlist::dc_chatlist_get_context(chatlist)
|
||||
) -> *const dc_context::dc_context_t {
|
||||
assert!(!chatlist.is_null());
|
||||
(*chatlist).context as *const _
|
||||
}
|
||||
|
||||
// dc_chat_t
|
||||
|
||||
#[no_mangle]
|
||||
pub type dc_chat_t = dc_chat::dc_chat_t;
|
||||
pub type dc_chat_t<'a> = dc_chat::dc_chat_t<'a>;
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_chat_unref(chat: *mut dc_chat::dc_chat_t) {
|
||||
@@ -927,13 +1181,16 @@ pub unsafe extern "C" fn dc_chat_is_sending_locations(
|
||||
// dc_msg_t
|
||||
|
||||
#[no_mangle]
|
||||
pub type dc_msg_t = dc_msg::dc_msg_t;
|
||||
pub type dc_msg_t<'a> = dc_msg::dc_msg_t<'a>;
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_msg_new(
|
||||
pub unsafe extern "C" fn dc_msg_new<'a>(
|
||||
context: *mut dc_context::dc_context_t,
|
||||
viewtype: libc::c_int,
|
||||
) -> *mut dc_msg::dc_msg_t {
|
||||
) -> *mut dc_msg::dc_msg_t<'a> {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_msg::dc_msg_new(context, viewtype)
|
||||
}
|
||||
|
||||
@@ -1145,7 +1402,7 @@ pub unsafe extern "C" fn dc_msg_latefiling_mediasize(
|
||||
// dc_contact_t
|
||||
|
||||
#[no_mangle]
|
||||
pub type dc_contact_t = dc_contact::dc_contact_t;
|
||||
pub type dc_contact_t<'a> = dc_contact::dc_contact_t<'a>;
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_contact_unref(contact: *mut dc_contact::dc_contact_t) {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -11,7 +11,6 @@
|
||||
non_camel_case_types,
|
||||
non_snake_case,
|
||||
non_upper_case_globals,
|
||||
unused_assignments,
|
||||
unused_mut,
|
||||
unused_attributes,
|
||||
non_upper_case_globals,
|
||||
@@ -21,6 +20,7 @@
|
||||
|
||||
use std::ffi::CString;
|
||||
use std::io::{self, Write};
|
||||
use std::sync::{Arc, RwLock};
|
||||
|
||||
use deltachat::constants::*;
|
||||
use deltachat::dc_aheader::*;
|
||||
@@ -67,35 +67,28 @@ use deltachat::dc_token::*;
|
||||
use deltachat::dc_tools::*;
|
||||
use deltachat::types::*;
|
||||
use deltachat::x::*;
|
||||
use libc;
|
||||
|
||||
mod cmdline;
|
||||
mod stress;
|
||||
|
||||
use self::cmdline::*;
|
||||
use self::stress::*;
|
||||
|
||||
/* ******************************************************************************
|
||||
* Event Handler
|
||||
******************************************************************************/
|
||||
static mut s_do_log_info: libc::c_int = 1i32;
|
||||
|
||||
unsafe extern "C" fn receive_event(
|
||||
mut context: *mut dc_context_t,
|
||||
mut event: Event,
|
||||
mut data1: uintptr_t,
|
||||
mut data2: uintptr_t,
|
||||
context: &dc_context_t,
|
||||
event: Event,
|
||||
data1: uintptr_t,
|
||||
data2: uintptr_t,
|
||||
) -> uintptr_t {
|
||||
match event as u32 {
|
||||
2091 => {}
|
||||
100 => {
|
||||
/* do not show the event as this would fill the screen */
|
||||
if 0 != s_do_log_info {
|
||||
printf(
|
||||
b"%s\n\x00" as *const u8 as *const libc::c_char,
|
||||
data2 as *mut libc::c_char,
|
||||
);
|
||||
}
|
||||
printf(
|
||||
b"%s\n\x00" as *const u8 as *const libc::c_char,
|
||||
data2 as *mut libc::c_char,
|
||||
);
|
||||
}
|
||||
101 => {
|
||||
printf(
|
||||
@@ -154,7 +147,7 @@ unsafe extern "C" fn receive_event(
|
||||
let mut ret: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut tempFile: *mut libc::c_char = dc_get_fine_pathNfilename(
|
||||
context,
|
||||
(*context).blobdir,
|
||||
context.get_blobdir(),
|
||||
b"curl.result\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
let mut cmd: *mut libc::c_char = if event == Event::HTTP_GET {
|
||||
@@ -270,111 +263,88 @@ unsafe extern "C" fn receive_event(
|
||||
/* ******************************************************************************
|
||||
* Threads for waiting for messages and for jobs
|
||||
******************************************************************************/
|
||||
static mut inbox_thread: pthread_t = 0 as pthread_t;
|
||||
static mut run_threads: libc::c_int = 0i32;
|
||||
|
||||
unsafe extern "C" fn inbox_thread_entry_point(
|
||||
mut entry_arg: *mut libc::c_void,
|
||||
) -> *mut libc::c_void {
|
||||
let mut context: *mut dc_context_t = entry_arg as *mut dc_context_t;
|
||||
while 0 != run_threads {
|
||||
dc_perform_imap_jobs(context);
|
||||
dc_perform_imap_fetch(context);
|
||||
if 0 != run_threads {
|
||||
dc_perform_imap_idle(context);
|
||||
unsafe fn start_threads(
|
||||
c: Arc<RwLock<dc_context_t>>,
|
||||
) -> (
|
||||
std::thread::JoinHandle<()>,
|
||||
std::thread::JoinHandle<()>,
|
||||
std::thread::JoinHandle<()>,
|
||||
std::thread::JoinHandle<()>,
|
||||
) {
|
||||
run_threads = 1;
|
||||
|
||||
let ctx = c.clone();
|
||||
let h1 = std::thread::spawn(move || {
|
||||
let context = ctx.read().unwrap();
|
||||
while 0 != run_threads {
|
||||
dc_perform_imap_jobs(&context);
|
||||
dc_perform_imap_fetch(&context);
|
||||
if 0 != run_threads {
|
||||
dc_perform_imap_idle(&context);
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0 as *mut libc::c_void;
|
||||
}
|
||||
static mut mvbox_thread: pthread_t = 0 as pthread_t;
|
||||
unsafe extern "C" fn mvbox_thread_entry_point(
|
||||
mut entry_arg: *mut libc::c_void,
|
||||
) -> *mut libc::c_void {
|
||||
let mut context: *mut dc_context_t = entry_arg as *mut dc_context_t;
|
||||
while 0 != run_threads {
|
||||
dc_perform_mvbox_fetch(context);
|
||||
if 0 != run_threads {
|
||||
dc_perform_mvbox_idle(context);
|
||||
});
|
||||
|
||||
let ctx = c.clone();
|
||||
let h2 = std::thread::spawn(move || {
|
||||
let context = ctx.read().unwrap();
|
||||
while 0 != run_threads {
|
||||
dc_perform_mvbox_fetch(&context);
|
||||
if 0 != run_threads {
|
||||
dc_perform_mvbox_idle(&context);
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0 as *mut libc::c_void;
|
||||
}
|
||||
static mut sentbox_thread: pthread_t = 0 as pthread_t;
|
||||
unsafe extern "C" fn sentbox_thread_entry_point(
|
||||
mut entry_arg: *mut libc::c_void,
|
||||
) -> *mut libc::c_void {
|
||||
let mut context: *mut dc_context_t = entry_arg as *mut dc_context_t;
|
||||
while 0 != run_threads {
|
||||
dc_perform_sentbox_fetch(context);
|
||||
if 0 != run_threads {
|
||||
dc_perform_sentbox_idle(context);
|
||||
});
|
||||
|
||||
let ctx = c.clone();
|
||||
let h3 = std::thread::spawn(move || {
|
||||
let context = ctx.read().unwrap();
|
||||
while 0 != run_threads {
|
||||
dc_perform_sentbox_fetch(&context);
|
||||
if 0 != run_threads {
|
||||
dc_perform_sentbox_idle(&context);
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0 as *mut libc::c_void;
|
||||
}
|
||||
static mut smtp_thread: pthread_t = 0 as pthread_t;
|
||||
unsafe extern "C" fn smtp_thread_entry_point(
|
||||
mut entry_arg: *mut libc::c_void,
|
||||
) -> *mut libc::c_void {
|
||||
let mut context: *mut dc_context_t = entry_arg as *mut dc_context_t;
|
||||
while 0 != run_threads {
|
||||
dc_perform_smtp_jobs(context);
|
||||
if 0 != run_threads {
|
||||
dc_perform_smtp_idle(context);
|
||||
});
|
||||
|
||||
let ctx = c.clone();
|
||||
let h4 = std::thread::spawn(move || {
|
||||
let context = ctx.read().unwrap();
|
||||
while 0 != run_threads {
|
||||
dc_perform_smtp_jobs(&context);
|
||||
if 0 != run_threads {
|
||||
dc_perform_smtp_idle(&context);
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0 as *mut libc::c_void;
|
||||
});
|
||||
|
||||
(h1, h2, h3, h4)
|
||||
}
|
||||
unsafe extern "C" fn start_threads(mut context: *mut dc_context_t) {
|
||||
run_threads = 1i32;
|
||||
if inbox_thread == 0 {
|
||||
pthread_create(
|
||||
&mut inbox_thread,
|
||||
0 as *const pthread_attr_t,
|
||||
Some(inbox_thread_entry_point),
|
||||
context as *mut libc::c_void,
|
||||
);
|
||||
}
|
||||
if mvbox_thread == 0 {
|
||||
pthread_create(
|
||||
&mut mvbox_thread,
|
||||
0 as *const pthread_attr_t,
|
||||
Some(mvbox_thread_entry_point),
|
||||
context as *mut libc::c_void,
|
||||
);
|
||||
}
|
||||
if sentbox_thread == 0 {
|
||||
pthread_create(
|
||||
&mut sentbox_thread,
|
||||
0 as *const pthread_attr_t,
|
||||
Some(sentbox_thread_entry_point),
|
||||
context as *mut libc::c_void,
|
||||
);
|
||||
}
|
||||
if smtp_thread == 0 {
|
||||
pthread_create(
|
||||
&mut smtp_thread,
|
||||
0 as *const pthread_attr_t,
|
||||
Some(smtp_thread_entry_point),
|
||||
context as *mut libc::c_void,
|
||||
);
|
||||
};
|
||||
}
|
||||
unsafe extern "C" fn stop_threads(mut context: *mut dc_context_t) {
|
||||
|
||||
unsafe fn stop_threads(
|
||||
context: &dc_context_t,
|
||||
handles: Option<(
|
||||
std::thread::JoinHandle<()>,
|
||||
std::thread::JoinHandle<()>,
|
||||
std::thread::JoinHandle<()>,
|
||||
std::thread::JoinHandle<()>,
|
||||
)>,
|
||||
) {
|
||||
run_threads = 0i32;
|
||||
dc_interrupt_imap_idle(context);
|
||||
dc_interrupt_mvbox_idle(context);
|
||||
dc_interrupt_sentbox_idle(context);
|
||||
dc_interrupt_smtp_idle(context);
|
||||
pthread_join(inbox_thread, 0 as *mut *mut libc::c_void);
|
||||
pthread_join(mvbox_thread, 0 as *mut *mut libc::c_void);
|
||||
pthread_join(sentbox_thread, 0 as *mut *mut libc::c_void);
|
||||
pthread_join(smtp_thread, 0 as *mut *mut libc::c_void);
|
||||
inbox_thread = 0 as pthread_t;
|
||||
mvbox_thread = 0 as pthread_t;
|
||||
sentbox_thread = 0 as pthread_t;
|
||||
smtp_thread = 0 as pthread_t;
|
||||
if let Some((h1, h2, h3, h4)) = handles {
|
||||
h1.join().unwrap();
|
||||
h2.join().unwrap();
|
||||
h3.join().unwrap();
|
||||
h4.join().unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
/* ******************************************************************************
|
||||
* The main loop
|
||||
******************************************************************************/
|
||||
@@ -387,24 +357,18 @@ fn read_cmd() -> String {
|
||||
input.trim_end().to_string()
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "android"))]
|
||||
unsafe fn main_0(mut argc: libc::c_int, mut argv: *mut *mut libc::c_char) -> libc::c_int {
|
||||
let mut cmd: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut context: *mut dc_context_t = dc_context_new(
|
||||
let mut context = dc_context_new(
|
||||
receive_event,
|
||||
0 as *mut libc::c_void,
|
||||
b"CLI\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
let mut stresstest_only: libc::c_int = 0i32;
|
||||
|
||||
dc_cmdline_skip_auth();
|
||||
|
||||
if argc == 2i32 {
|
||||
if strcmp(
|
||||
*argv.offset(1isize),
|
||||
b"--stress\x00" as *const u8 as *const libc::c_char,
|
||||
) == 0i32
|
||||
{
|
||||
stresstest_only = 1i32
|
||||
} else if 0 == dc_open(context, *argv.offset(1isize), 0 as *const libc::c_char) {
|
||||
if 0 == dc_open(&mut context, *argv.offset(1isize), 0 as *const libc::c_char) {
|
||||
printf(
|
||||
b"ERROR: Cannot open %s.\n\x00" as *const u8 as *const libc::c_char,
|
||||
*argv.offset(1isize),
|
||||
@@ -413,13 +377,13 @@ unsafe fn main_0(mut argc: libc::c_int, mut argv: *mut *mut libc::c_char) -> lib
|
||||
} else if argc != 1i32 {
|
||||
printf(b"ERROR: Bad arguments\n\x00" as *const u8 as *const libc::c_char);
|
||||
}
|
||||
s_do_log_info = 0i32;
|
||||
stress_functions(context);
|
||||
s_do_log_info = 1i32;
|
||||
if 0 != stresstest_only {
|
||||
return 0i32;
|
||||
}
|
||||
|
||||
printf(b"Delta Chat Core is awaiting your commands.\n\x00" as *const u8 as *const libc::c_char);
|
||||
|
||||
let mut handles = None;
|
||||
|
||||
let ctx = Arc::new(RwLock::new(context));
|
||||
|
||||
loop {
|
||||
/* read command */
|
||||
let cmdline = read_cmd();
|
||||
@@ -431,9 +395,10 @@ unsafe fn main_0(mut argc: libc::c_int, mut argv: *mut *mut libc::c_char) -> lib
|
||||
arg1 = arg1.offset(1isize)
|
||||
}
|
||||
if strcmp(cmd, b"connect\x00" as *const u8 as *const libc::c_char) == 0i32 {
|
||||
start_threads(context);
|
||||
handles = Some(start_threads(ctx.clone()));
|
||||
} else if strcmp(cmd, b"disconnect\x00" as *const u8 as *const libc::c_char) == 0i32 {
|
||||
stop_threads(context);
|
||||
stop_threads(&ctx.read().unwrap(), handles);
|
||||
handles = None;
|
||||
} else if strcmp(cmd, b"smtp-jobs\x00" as *const u8 as *const libc::c_char) == 0i32 {
|
||||
if 0 != run_threads {
|
||||
printf(
|
||||
@@ -441,7 +406,7 @@ unsafe fn main_0(mut argc: libc::c_int, mut argv: *mut *mut libc::c_char) -> lib
|
||||
as *const libc::c_char,
|
||||
);
|
||||
} else {
|
||||
dc_perform_smtp_jobs(context);
|
||||
dc_perform_smtp_jobs(&ctx.read().unwrap());
|
||||
}
|
||||
} else if strcmp(cmd, b"imap-jobs\x00" as *const u8 as *const libc::c_char) == 0i32 {
|
||||
if 0 != run_threads {
|
||||
@@ -450,19 +415,21 @@ unsafe fn main_0(mut argc: libc::c_int, mut argv: *mut *mut libc::c_char) -> lib
|
||||
as *const libc::c_char,
|
||||
);
|
||||
} else {
|
||||
dc_perform_imap_jobs(context);
|
||||
dc_perform_imap_jobs(&ctx.read().unwrap());
|
||||
}
|
||||
} else if strcmp(cmd, b"configure\x00" as *const u8 as *const libc::c_char) == 0i32 {
|
||||
start_threads(context);
|
||||
dc_configure(context);
|
||||
handles = { Some(start_threads(ctx.clone())) };
|
||||
dc_configure(&ctx.read().unwrap());
|
||||
} else if strcmp(cmd, b"oauth2\x00" as *const u8 as *const libc::c_char) == 0i32 {
|
||||
let mut addr: *mut libc::c_char =
|
||||
dc_get_config(context, b"addr\x00" as *const u8 as *const libc::c_char);
|
||||
let mut addr: *mut libc::c_char = dc_get_config(
|
||||
&ctx.read().unwrap(),
|
||||
b"addr\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
if addr.is_null() || *addr.offset(0isize) as libc::c_int == 0i32 {
|
||||
printf(b"oauth2: set addr first.\n\x00" as *const u8 as *const libc::c_char);
|
||||
} else {
|
||||
let mut oauth2_url: *mut libc::c_char = dc_get_oauth2_url(
|
||||
context,
|
||||
&ctx.read().unwrap(),
|
||||
addr,
|
||||
b"chat.delta:/com.b44t.messenger\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
@@ -485,9 +452,9 @@ unsafe fn main_0(mut argc: libc::c_int, mut argv: *mut *mut libc::c_char) -> lib
|
||||
} else if strcmp(cmd, b"getqr\x00" as *const u8 as *const libc::c_char) == 0i32
|
||||
|| strcmp(cmd, b"getbadqr\x00" as *const u8 as *const libc::c_char) == 0i32
|
||||
{
|
||||
start_threads(context);
|
||||
handles = Some(start_threads(ctx.clone()));
|
||||
let mut qrstr: *mut libc::c_char = dc_get_securejoin_qr(
|
||||
context,
|
||||
&ctx.read().unwrap(),
|
||||
(if !arg1.is_null() { atoi(arg1) } else { 0i32 }) as uint32_t,
|
||||
);
|
||||
if !qrstr.is_null() && 0 != *qrstr.offset(0isize) as libc::c_int {
|
||||
@@ -510,16 +477,17 @@ unsafe fn main_0(mut argc: libc::c_int, mut argv: *mut *mut libc::c_char) -> lib
|
||||
}
|
||||
free(qrstr as *mut libc::c_void);
|
||||
} else if strcmp(cmd, b"joinqr\x00" as *const u8 as *const libc::c_char) == 0i32 {
|
||||
start_threads(context);
|
||||
handles = Some(start_threads(ctx.clone()));
|
||||
if !arg1.is_null() {
|
||||
dc_join_securejoin(context, arg1);
|
||||
dc_join_securejoin(&ctx.read().unwrap(), arg1);
|
||||
}
|
||||
} else {
|
||||
if strcmp(cmd, b"exit\x00" as *const u8 as *const libc::c_char) == 0i32 {
|
||||
break;
|
||||
}
|
||||
if !(*cmd.offset(0isize) as libc::c_int == 0i32) {
|
||||
let mut execute_result: *mut libc::c_char = dc_cmdline(context, &cmdline);
|
||||
let mut execute_result: *mut libc::c_char =
|
||||
dc_cmdline(&ctx.read().unwrap(), &cmdline);
|
||||
if !execute_result.is_null() {
|
||||
printf(
|
||||
b"%s\n\x00" as *const u8 as *const libc::c_char,
|
||||
@@ -530,12 +498,17 @@ unsafe fn main_0(mut argc: libc::c_int, mut argv: *mut *mut libc::c_char) -> lib
|
||||
}
|
||||
}
|
||||
}
|
||||
free(cmd as *mut libc::c_void);
|
||||
stop_threads(context);
|
||||
dc_close(context);
|
||||
dc_context_unref(context);
|
||||
context = 0 as *mut dc_context_t;
|
||||
return 0i32;
|
||||
|
||||
let ctx = ctx.clone();
|
||||
|
||||
{
|
||||
let mut ctx = ctx.write().unwrap();
|
||||
free(cmd as *mut libc::c_void);
|
||||
stop_threads(&ctx, handles);
|
||||
dc_close(&mut ctx);
|
||||
dc_context_unref(&mut ctx);
|
||||
}
|
||||
0
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
extern crate deltachat;
|
||||
|
||||
use std::ffi::{CStr, CString};
|
||||
use std::ptr::NonNull;
|
||||
use std::sync::Arc;
|
||||
use std::{thread, time};
|
||||
use tempfile::tempdir;
|
||||
|
||||
use deltachat::constants::Event;
|
||||
@@ -16,10 +17,14 @@ use deltachat::dc_job::{
|
||||
};
|
||||
use deltachat::dc_lot::*;
|
||||
|
||||
extern "C" fn cb(_ctx: *mut dc_context_t, event: Event, data1: usize, data2: usize) -> usize {
|
||||
extern "C" fn cb(_ctx: &dc_context_t, event: Event, data1: usize, data2: usize) -> usize {
|
||||
println!("[{:?}]", event);
|
||||
|
||||
match event {
|
||||
Event::CONFIGURE_PROGRESS => {
|
||||
println!(" progress: {}", data1);
|
||||
0
|
||||
}
|
||||
Event::HTTP_GET => {
|
||||
let url = unsafe { CStr::from_ptr(data1 as *const _).to_str().unwrap() };
|
||||
|
||||
@@ -49,61 +54,60 @@ extern "C" fn cb(_ctx: *mut dc_context_t, event: Event, data1: usize, data2: usi
|
||||
}
|
||||
}
|
||||
|
||||
struct Wrapper(NonNull<dc_context_t>);
|
||||
|
||||
unsafe impl std::marker::Send for Wrapper {}
|
||||
unsafe impl std::marker::Sync for Wrapper {}
|
||||
|
||||
fn main() {
|
||||
unsafe {
|
||||
let ctx = dc_context_new(cb, std::ptr::null_mut(), std::ptr::null_mut());
|
||||
let info = dc_get_info(ctx);
|
||||
let info = dc_get_info(&ctx);
|
||||
let info_s = CStr::from_ptr(info);
|
||||
let duration = time::Duration::from_millis(4000);
|
||||
println!("info: {}", info_s.to_str().unwrap());
|
||||
|
||||
let sendable_ctx = Wrapper(NonNull::new(ctx).unwrap());
|
||||
let t1 = std::thread::spawn(move || loop {
|
||||
dc_perform_imap_jobs(sendable_ctx.0.as_ptr());
|
||||
dc_perform_imap_fetch(sendable_ctx.0.as_ptr());
|
||||
dc_perform_imap_idle(sendable_ctx.0.as_ptr());
|
||||
let ctx = Arc::new(ctx);
|
||||
let ctx1 = ctx.clone();
|
||||
let t1 = thread::spawn(move || loop {
|
||||
dc_perform_imap_jobs(&ctx1);
|
||||
dc_perform_imap_fetch(&ctx1);
|
||||
dc_perform_imap_idle(&ctx1);
|
||||
});
|
||||
|
||||
let sendable_ctx = Wrapper(NonNull::new(ctx).unwrap());
|
||||
let t2 = std::thread::spawn(move || loop {
|
||||
dc_perform_smtp_jobs(sendable_ctx.0.as_ptr());
|
||||
dc_perform_smtp_idle(sendable_ctx.0.as_ptr());
|
||||
let ctx1 = ctx.clone();
|
||||
let t2 = thread::spawn(move || loop {
|
||||
dc_perform_smtp_jobs(&ctx1);
|
||||
dc_perform_smtp_idle(&ctx1);
|
||||
});
|
||||
|
||||
let dir = tempdir().unwrap();
|
||||
let dbfile = CString::new(dir.path().join("db.sqlite").to_str().unwrap()).unwrap();
|
||||
|
||||
println!("opening database {:?}", dbfile);
|
||||
dc_open(ctx, dbfile.as_ptr(), std::ptr::null());
|
||||
|
||||
dc_open(&ctx, dbfile.as_ptr(), std::ptr::null());
|
||||
|
||||
println!("configuring");
|
||||
let pw = std::env::args().collect::<Vec<String>>()[1].clone();
|
||||
dc_set_config(
|
||||
ctx,
|
||||
&ctx,
|
||||
CString::new("addr").unwrap().as_ptr(),
|
||||
CString::new("d@testrun.org").unwrap().as_ptr(),
|
||||
);
|
||||
dc_set_config(
|
||||
ctx,
|
||||
&ctx,
|
||||
CString::new("mail_pw").unwrap().as_ptr(),
|
||||
CString::new("***").unwrap().as_ptr(),
|
||||
CString::new(pw).unwrap().as_ptr(),
|
||||
);
|
||||
dc_configure(ctx);
|
||||
dc_configure(&ctx);
|
||||
|
||||
std::thread::sleep_ms(4000);
|
||||
thread::sleep(duration);
|
||||
|
||||
let email = CString::new("dignifiedquire@gmail.com").unwrap();
|
||||
println!("sending a message");
|
||||
let contact_id = dc_create_contact(ctx, std::ptr::null(), email.as_ptr());
|
||||
let chat_id = dc_create_chat_by_contact_id(ctx, contact_id);
|
||||
let contact_id = dc_create_contact(&ctx, std::ptr::null(), email.as_ptr());
|
||||
let chat_id = dc_create_chat_by_contact_id(&ctx, contact_id);
|
||||
let msg_text = CString::new("Hi, here is my first message!").unwrap();
|
||||
dc_send_text_msg(ctx, chat_id, msg_text.as_ptr());
|
||||
dc_send_text_msg(&ctx, chat_id, msg_text.as_ptr());
|
||||
|
||||
println!("fetching chats..");
|
||||
let chats = dc_get_chatlist(ctx, 0, std::ptr::null(), 0);
|
||||
let chats = dc_get_chatlist(&ctx, 0, std::ptr::null(), 0);
|
||||
|
||||
for i in 0..dc_chatlist_get_cnt(chats) {
|
||||
let summary = dc_chatlist_get_summary(chats, 0, std::ptr::null_mut());
|
||||
@@ -125,7 +129,7 @@ fn main() {
|
||||
}
|
||||
dc_chatlist_unref(chats);
|
||||
|
||||
// let msglist = dc_get_chat_msgs(ctx, chat_id, 0, 0);
|
||||
// let msglist = dc_get_chat_msgs(&ctx, chat_id, 0, 0);
|
||||
// for i in 0..dc_array_get_cnt(msglist) {
|
||||
// let msg_id = dc_array_get_id(msglist, i);
|
||||
// let msg = dc_get_msg(context, msg_id);
|
||||
|
||||
@@ -2,6 +2,11 @@
|
||||
|
||||
pub const VERSION: &'static [u8; 7] = b"0.43.0\x00";
|
||||
|
||||
pub const DC_MOVE_STATE_MOVING: u32 = 3;
|
||||
pub const DC_MOVE_STATE_STAY: u32 = 2;
|
||||
pub const DC_MOVE_STATE_PENDING: u32 = 1;
|
||||
pub const DC_MOVE_STATE_UNDEFINED: u32 = 0;
|
||||
|
||||
pub const DC_GCL_ARCHIVED_ONLY: usize = 0x01;
|
||||
pub const DC_GCL_NO_SPECIALS: usize = 0x02;
|
||||
pub const DC_GCL_ADD_ALLDONE_HINT: usize = 0x04;
|
||||
@@ -88,6 +93,8 @@ pub const DC_TEXT1_DRAFT: usize = 1;
|
||||
pub const DC_TEXT1_USERNAME: usize = 2;
|
||||
pub const DC_TEXT1_SELF: usize = 3;
|
||||
|
||||
pub const DC_CREATE_MVBOX: usize = 1;
|
||||
|
||||
/// Text message.
|
||||
/// The text of the message is set using dc_msg_set_text()
|
||||
/// and retrieved with dc_msg_get_text().
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use libc;
|
||||
use mmime::mailimf_types::*;
|
||||
|
||||
use crate::dc_contact::*;
|
||||
use crate::dc_key::*;
|
||||
@@ -34,7 +34,7 @@ pub unsafe fn dc_aheader_new_from_imffields(
|
||||
mut wanted_from: *const libc::c_char,
|
||||
mut header: *const mailimf_fields,
|
||||
) -> *mut dc_aheader_t {
|
||||
let mut cur = 0 as *mut clistiter;
|
||||
let mut cur;
|
||||
let mut fine_header = 0 as *mut dc_aheader_t;
|
||||
|
||||
if wanted_from.is_null() || header.is_null() {
|
||||
@@ -78,7 +78,7 @@ pub unsafe fn dc_aheader_new_from_imffields(
|
||||
cur = if !cur.is_null() {
|
||||
(*cur).next
|
||||
} else {
|
||||
0 as *mut clistcell_s
|
||||
0 as *mut clistcell
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,10 +105,10 @@ pub unsafe fn dc_aheader_set_from_string(
|
||||
(b) for the key, non-base64-characters are ignored and
|
||||
(c) for parsing, we ignore `\r\n` as well as tabs for spaces */
|
||||
let mut header_str = 0 as *mut libc::c_char;
|
||||
let mut p = 0 as *mut libc::c_char;
|
||||
let mut beg_attr_name = 0 as *mut libc::c_char;
|
||||
let mut after_attr_name = 0 as *mut libc::c_char;
|
||||
let mut beg_attr_value = 0 as *mut libc::c_char;
|
||||
let mut p;
|
||||
let mut beg_attr_name;
|
||||
let mut after_attr_name;
|
||||
let mut beg_attr_value;
|
||||
let mut success: libc::c_int = 0;
|
||||
|
||||
dc_aheader_empty(aheader);
|
||||
@@ -263,12 +263,8 @@ pub unsafe fn dc_aheader_render(mut aheader: *const dc_aheader_t) -> *mut libc::
|
||||
// TODO replace 78 with enum /rtn
|
||||
/* adds a whitespace every 78 characters, this allows libEtPan to wrap the lines according to RFC 5322
|
||||
(which may insert a linebreak before every whitespace) */
|
||||
keybase64_wrapped = dc_key_render_base64(
|
||||
(*aheader).public_key,
|
||||
78,
|
||||
b" \x00" as *const u8 as *const libc::c_char,
|
||||
0,
|
||||
);
|
||||
keybase64_wrapped = dc_key_render_base64((*aheader).public_key, 78);
|
||||
|
||||
if !keybase64_wrapped.is_null() {
|
||||
/*no checksum*/
|
||||
dc_strbuilder_cat(&mut ret, keybase64_wrapped);
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
use libc;
|
||||
|
||||
use crate::dc_aheader::*;
|
||||
use crate::dc_chat::*;
|
||||
use crate::dc_context::dc_context_t;
|
||||
@@ -11,14 +9,14 @@ use crate::types::*;
|
||||
use crate::x::*;
|
||||
|
||||
/* prefer-encrypt states */
|
||||
/* *
|
||||
/**
|
||||
* @class dc_apeerstate_t
|
||||
* Library-internal.
|
||||
*/
|
||||
#[derive(Copy, Clone)]
|
||||
#[repr(C)]
|
||||
pub struct dc_apeerstate_t {
|
||||
pub context: *mut dc_context_t,
|
||||
pub struct dc_apeerstate_t<'a> {
|
||||
pub context: &'a dc_context_t,
|
||||
pub addr: *mut libc::c_char,
|
||||
pub last_seen: time_t,
|
||||
pub last_seen_autocrypt: time_t,
|
||||
@@ -35,20 +33,23 @@ pub struct dc_apeerstate_t {
|
||||
}
|
||||
|
||||
/* the returned pointer is ref'd and must be unref'd after usage */
|
||||
pub unsafe fn dc_apeerstate_new(mut context: *mut dc_context_t) -> *mut dc_apeerstate_t {
|
||||
let mut peerstate: *mut dc_apeerstate_t = 0 as *mut dc_apeerstate_t;
|
||||
pub unsafe fn dc_apeerstate_new<'a>(context: &'a dc_context_t) -> *mut dc_apeerstate_t<'a> {
|
||||
let mut peerstate: *mut dc_apeerstate_t;
|
||||
peerstate = calloc(1, ::std::mem::size_of::<dc_apeerstate_t>()) as *mut dc_apeerstate_t;
|
||||
if peerstate.is_null() {
|
||||
exit(43i32);
|
||||
}
|
||||
(*peerstate).context = context;
|
||||
return peerstate;
|
||||
|
||||
peerstate
|
||||
}
|
||||
|
||||
pub unsafe fn dc_apeerstate_unref(mut peerstate: *mut dc_apeerstate_t) {
|
||||
dc_apeerstate_empty(peerstate);
|
||||
free(peerstate as *mut libc::c_void);
|
||||
}
|
||||
/* ******************************************************************************
|
||||
|
||||
/*******************************************************************************
|
||||
* dc_apeerstate_t represents the state of an Autocrypt peer - Load/save
|
||||
******************************************************************************/
|
||||
unsafe fn dc_apeerstate_empty(mut peerstate: *mut dc_apeerstate_t) {
|
||||
@@ -76,6 +77,8 @@ unsafe fn dc_apeerstate_empty(mut peerstate: *mut dc_apeerstate_t) {
|
||||
(*peerstate).verified_key = 0 as *mut dc_key_t;
|
||||
(*peerstate).degrade_event = 0i32;
|
||||
}
|
||||
|
||||
// TODO should return bool /rtn
|
||||
pub unsafe fn dc_apeerstate_init_from_header(
|
||||
mut peerstate: *mut dc_apeerstate_t,
|
||||
mut header: *const dc_aheader_t,
|
||||
@@ -93,8 +96,11 @@ pub unsafe fn dc_apeerstate_init_from_header(
|
||||
(*peerstate).public_key = dc_key_new();
|
||||
dc_key_set_from_key((*peerstate).public_key, (*header).public_key);
|
||||
dc_apeerstate_recalc_fingerprint(peerstate);
|
||||
return 1i32;
|
||||
|
||||
1
|
||||
}
|
||||
|
||||
// TODO should return bool /rtn
|
||||
pub unsafe fn dc_apeerstate_recalc_fingerprint(mut peerstate: *mut dc_apeerstate_t) -> libc::c_int {
|
||||
let mut success: libc::c_int = 0i32;
|
||||
let mut old_public_fingerprint: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
@@ -102,7 +108,8 @@ pub unsafe fn dc_apeerstate_recalc_fingerprint(mut peerstate: *mut dc_apeerstate
|
||||
if !peerstate.is_null() {
|
||||
if !(*peerstate).public_key.is_null() {
|
||||
old_public_fingerprint = (*peerstate).public_key_fingerprint;
|
||||
(*peerstate).public_key_fingerprint = dc_key_get_fingerprint((*peerstate).public_key);
|
||||
(*peerstate).public_key_fingerprint =
|
||||
dc_key_get_fingerprint((*peerstate).context, (*peerstate).public_key);
|
||||
if old_public_fingerprint.is_null()
|
||||
|| *old_public_fingerprint.offset(0isize) as libc::c_int == 0i32
|
||||
|| (*peerstate).public_key_fingerprint.is_null()
|
||||
@@ -119,7 +126,8 @@ pub unsafe fn dc_apeerstate_recalc_fingerprint(mut peerstate: *mut dc_apeerstate
|
||||
}
|
||||
if !(*peerstate).gossip_key.is_null() {
|
||||
old_gossip_fingerprint = (*peerstate).gossip_key_fingerprint;
|
||||
(*peerstate).gossip_key_fingerprint = dc_key_get_fingerprint((*peerstate).gossip_key);
|
||||
(*peerstate).gossip_key_fingerprint =
|
||||
dc_key_get_fingerprint((*peerstate).context, (*peerstate).gossip_key);
|
||||
if old_gossip_fingerprint.is_null()
|
||||
|| *old_gossip_fingerprint.offset(0isize) as libc::c_int == 0i32
|
||||
|| (*peerstate).gossip_key_fingerprint.is_null()
|
||||
@@ -136,10 +144,14 @@ pub unsafe fn dc_apeerstate_recalc_fingerprint(mut peerstate: *mut dc_apeerstate
|
||||
}
|
||||
success = 1i32
|
||||
}
|
||||
|
||||
free(old_public_fingerprint as *mut libc::c_void);
|
||||
free(old_gossip_fingerprint as *mut libc::c_void);
|
||||
return success;
|
||||
|
||||
success
|
||||
}
|
||||
|
||||
// TODO should return bool /rtn
|
||||
pub unsafe extern "C" fn dc_apeerstate_init_from_gossip(
|
||||
mut peerstate: *mut dc_apeerstate_t,
|
||||
mut gossip_header: *const dc_aheader_t,
|
||||
@@ -155,8 +167,11 @@ pub unsafe extern "C" fn dc_apeerstate_init_from_gossip(
|
||||
(*peerstate).gossip_key = dc_key_new();
|
||||
dc_key_set_from_key((*peerstate).gossip_key, (*gossip_header).public_key);
|
||||
dc_apeerstate_recalc_fingerprint(peerstate);
|
||||
return 1i32;
|
||||
|
||||
1
|
||||
}
|
||||
|
||||
// TODO should return bool /rtn
|
||||
pub unsafe fn dc_apeerstate_degrade_encryption(
|
||||
mut peerstate: *mut dc_apeerstate_t,
|
||||
mut message_time: time_t,
|
||||
@@ -170,8 +185,10 @@ pub unsafe fn dc_apeerstate_degrade_encryption(
|
||||
(*peerstate).prefer_encrypt = 20i32;
|
||||
(*peerstate).last_seen = message_time;
|
||||
(*peerstate).to_save |= 0x2i32;
|
||||
return 1i32;
|
||||
|
||||
1
|
||||
}
|
||||
|
||||
pub unsafe fn dc_apeerstate_apply_header(
|
||||
mut peerstate: *mut dc_apeerstate_t,
|
||||
mut header: *const dc_aheader_t,
|
||||
@@ -209,6 +226,7 @@ pub unsafe fn dc_apeerstate_apply_header(
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
pub unsafe fn dc_apeerstate_apply_gossip(
|
||||
mut peerstate: *mut dc_apeerstate_t,
|
||||
mut gossip_header: *const dc_aheader_t,
|
||||
@@ -236,6 +254,7 @@ pub unsafe fn dc_apeerstate_apply_gossip(
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
pub unsafe fn dc_apeerstate_render_gossip_header(
|
||||
mut peerstate: *const dc_apeerstate_t,
|
||||
mut min_verified: libc::c_int,
|
||||
@@ -249,8 +268,9 @@ pub unsafe fn dc_apeerstate_render_gossip_header(
|
||||
ret = dc_aheader_render(autocryptheader)
|
||||
}
|
||||
dc_aheader_unref(autocryptheader);
|
||||
return ret;
|
||||
ret
|
||||
}
|
||||
|
||||
pub unsafe fn dc_apeerstate_peek_key(
|
||||
mut peerstate: *const dc_apeerstate_t,
|
||||
mut min_verified: libc::c_int,
|
||||
@@ -274,8 +294,10 @@ pub unsafe fn dc_apeerstate_peek_key(
|
||||
if !(*peerstate).public_key.is_null() {
|
||||
return (*peerstate).public_key;
|
||||
}
|
||||
return (*peerstate).gossip_key;
|
||||
(*peerstate).gossip_key
|
||||
}
|
||||
|
||||
// TODO should return bool /rtn
|
||||
pub unsafe fn dc_apeerstate_set_verified(
|
||||
mut peerstate: *mut dc_apeerstate_t,
|
||||
mut which_key: libc::c_int,
|
||||
@@ -307,19 +329,24 @@ pub unsafe fn dc_apeerstate_set_verified(
|
||||
success = 1i32
|
||||
}
|
||||
}
|
||||
return success;
|
||||
|
||||
success
|
||||
}
|
||||
|
||||
// TODO should return bool /rtn
|
||||
pub unsafe fn dc_apeerstate_load_by_addr(
|
||||
mut peerstate: *mut dc_apeerstate_t,
|
||||
mut sql: *mut dc_sqlite3_t,
|
||||
mut sql: &dc_sqlite3_t,
|
||||
mut addr: *const libc::c_char,
|
||||
) -> libc::c_int {
|
||||
let mut success: libc::c_int = 0i32;
|
||||
let mut stmt: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt;
|
||||
if !(peerstate.is_null() || sql.is_null() || addr.is_null()) {
|
||||
if !(peerstate.is_null() || addr.is_null()) {
|
||||
dc_apeerstate_empty(peerstate);
|
||||
stmt =
|
||||
dc_sqlite3_prepare(sql,
|
||||
dc_sqlite3_prepare(
|
||||
(*peerstate).context,
|
||||
sql,
|
||||
b"SELECT addr, last_seen, last_seen_autocrypt, prefer_encrypted, public_key, gossip_timestamp, gossip_key, public_key_fingerprint, gossip_key_fingerprint, verified_key, verified_key_fingerprint FROM acpeerstates WHERE addr=? COLLATE NOCASE;\x00"
|
||||
as *const u8 as *const libc::c_char);
|
||||
sqlite3_bind_text(stmt, 1i32, addr, -1i32, None);
|
||||
@@ -329,8 +356,9 @@ pub unsafe fn dc_apeerstate_load_by_addr(
|
||||
}
|
||||
}
|
||||
sqlite3_finalize(stmt);
|
||||
return success;
|
||||
success
|
||||
}
|
||||
|
||||
unsafe fn dc_apeerstate_set_from_stmt(
|
||||
mut peerstate: *mut dc_apeerstate_t,
|
||||
mut stmt: *mut sqlite3_stmt,
|
||||
@@ -359,18 +387,22 @@ unsafe fn dc_apeerstate_set_from_stmt(
|
||||
dc_key_set_from_stmt((*peerstate).verified_key, stmt, 9i32, 0i32);
|
||||
};
|
||||
}
|
||||
|
||||
// TODO should return bool /rtn
|
||||
pub unsafe fn dc_apeerstate_load_by_fingerprint(
|
||||
mut peerstate: *mut dc_apeerstate_t,
|
||||
mut sql: *mut dc_sqlite3_t,
|
||||
mut sql: &dc_sqlite3_t,
|
||||
mut fingerprint: *const libc::c_char,
|
||||
) -> libc::c_int {
|
||||
let mut success: libc::c_int = 0i32;
|
||||
let mut stmt: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt;
|
||||
if !(peerstate.is_null() || sql.is_null() || fingerprint.is_null()) {
|
||||
if !(peerstate.is_null() || fingerprint.is_null()) {
|
||||
dc_apeerstate_empty(peerstate);
|
||||
stmt =
|
||||
dc_sqlite3_prepare(sql,
|
||||
b"SELECT addr, last_seen, last_seen_autocrypt, prefer_encrypted, public_key, gossip_timestamp, gossip_key, public_key_fingerprint, gossip_key_fingerprint, verified_key, verified_key_fingerprint FROM acpeerstates WHERE public_key_fingerprint=? COLLATE NOCASE OR gossip_key_fingerprint=? COLLATE NOCASE ORDER BY public_key_fingerprint=? DESC;\x00"
|
||||
dc_sqlite3_prepare(
|
||||
(*peerstate).context,
|
||||
sql,
|
||||
b"SELECT addr, last_seen, last_seen_autocrypt, prefer_encrypted, public_key, gossip_timestamp, gossip_key, public_key_fingerprint, gossip_key_fingerprint, verified_key, verified_key_fingerprint FROM acpeerstates WHERE public_key_fingerprint=? COLLATE NOCASE OR gossip_key_fingerprint=? COLLATE NOCASE ORDER BY public_key_fingerprint=? DESC;\x00"
|
||||
as *const u8 as *const libc::c_char);
|
||||
sqlite3_bind_text(stmt, 1i32, fingerprint, -1i32, None);
|
||||
sqlite3_bind_text(stmt, 2i32, fingerprint, -1i32, None);
|
||||
@@ -381,21 +413,24 @@ pub unsafe fn dc_apeerstate_load_by_fingerprint(
|
||||
}
|
||||
}
|
||||
sqlite3_finalize(stmt);
|
||||
return success;
|
||||
success
|
||||
}
|
||||
|
||||
// TODO should return bool /rtn
|
||||
pub unsafe fn dc_apeerstate_save_to_db(
|
||||
mut peerstate: *const dc_apeerstate_t,
|
||||
mut sql: *mut dc_sqlite3_t,
|
||||
mut sql: &dc_sqlite3_t,
|
||||
mut create: libc::c_int,
|
||||
) -> libc::c_int {
|
||||
let mut current_block: u64;
|
||||
let mut success: libc::c_int = 0i32;
|
||||
let mut stmt: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt;
|
||||
if peerstate.is_null() || sql.is_null() || (*peerstate).addr.is_null() {
|
||||
if peerstate.is_null() || (*peerstate).addr.is_null() {
|
||||
return 0i32;
|
||||
}
|
||||
if 0 != create {
|
||||
stmt = dc_sqlite3_prepare(
|
||||
(*peerstate).context,
|
||||
sql,
|
||||
b"INSERT INTO acpeerstates (addr) VALUES(?);\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
@@ -406,7 +441,8 @@ pub unsafe fn dc_apeerstate_save_to_db(
|
||||
}
|
||||
if 0 != (*peerstate).to_save & 0x2i32 || 0 != create {
|
||||
stmt =
|
||||
dc_sqlite3_prepare(sql,
|
||||
dc_sqlite3_prepare(
|
||||
(*peerstate).context,sql,
|
||||
b"UPDATE acpeerstates SET last_seen=?, last_seen_autocrypt=?, prefer_encrypted=?, public_key=?, gossip_timestamp=?, gossip_key=?, public_key_fingerprint=?, gossip_key_fingerprint=?, verified_key=?, verified_key_fingerprint=? WHERE addr=?;\x00"
|
||||
as *const u8 as *const libc::c_char);
|
||||
sqlite3_bind_int64(stmt, 1i32, (*peerstate).last_seen as sqlite3_int64);
|
||||
@@ -481,7 +517,8 @@ pub unsafe fn dc_apeerstate_save_to_db(
|
||||
}
|
||||
} else if 0 != (*peerstate).to_save & 0x1i32 {
|
||||
stmt =
|
||||
dc_sqlite3_prepare(sql,
|
||||
dc_sqlite3_prepare(
|
||||
(*peerstate).context,sql,
|
||||
b"UPDATE acpeerstates SET last_seen=?, last_seen_autocrypt=?, gossip_timestamp=? WHERE addr=?;\x00"
|
||||
as *const u8 as *const libc::c_char);
|
||||
sqlite3_bind_int64(stmt, 1i32, (*peerstate).last_seen as sqlite3_int64);
|
||||
@@ -512,8 +549,11 @@ pub unsafe fn dc_apeerstate_save_to_db(
|
||||
_ => {}
|
||||
}
|
||||
sqlite3_finalize(stmt);
|
||||
return success;
|
||||
|
||||
success
|
||||
}
|
||||
|
||||
// TODO should return bool /rtn
|
||||
pub unsafe fn dc_apeerstate_has_verified_key(
|
||||
mut peerstate: *const dc_apeerstate_t,
|
||||
mut fingerprints: *const dc_hash_t,
|
||||
@@ -532,5 +572,6 @@ pub unsafe fn dc_apeerstate_has_verified_key(
|
||||
{
|
||||
return 1i32;
|
||||
}
|
||||
return 0i32;
|
||||
|
||||
0
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
use libc;
|
||||
|
||||
use crate::dc_context::*;
|
||||
use crate::dc_tools::*;
|
||||
use crate::types::*;
|
||||
@@ -10,14 +8,13 @@ use crate::x::*;
|
||||
#[repr(C)]
|
||||
pub struct dc_array_t {
|
||||
pub magic: uint32_t,
|
||||
pub context: *mut dc_context_t,
|
||||
pub allocated: size_t,
|
||||
pub count: size_t,
|
||||
pub type_0: libc::c_int,
|
||||
pub array: *mut uintptr_t,
|
||||
}
|
||||
|
||||
/* *
|
||||
/**
|
||||
* @class dc_array_t
|
||||
*
|
||||
* An object containing a simple array.
|
||||
@@ -36,6 +33,7 @@ pub unsafe fn dc_array_unref(mut array: *mut dc_array_t) {
|
||||
(*array).magic = 0i32 as uint32_t;
|
||||
free(array as *mut libc::c_void);
|
||||
}
|
||||
|
||||
pub unsafe fn dc_array_free_ptr(mut array: *mut dc_array_t) {
|
||||
if array.is_null() || (*array).magic != 0xa11aai32 as libc::c_uint {
|
||||
return;
|
||||
@@ -53,6 +51,7 @@ pub unsafe fn dc_array_free_ptr(mut array: *mut dc_array_t) {
|
||||
i = i.wrapping_add(1)
|
||||
}
|
||||
}
|
||||
|
||||
pub unsafe fn dc_array_add_uint(mut array: *mut dc_array_t, mut item: uintptr_t) {
|
||||
if array.is_null() || (*array).magic != 0xa11aai32 as libc::c_uint {
|
||||
return;
|
||||
@@ -71,24 +70,29 @@ pub unsafe fn dc_array_add_uint(mut array: *mut dc_array_t, mut item: uintptr_t)
|
||||
*(*array).array.offset((*array).count as isize) = item;
|
||||
(*array).count = (*array).count.wrapping_add(1);
|
||||
}
|
||||
|
||||
pub unsafe fn dc_array_add_id(mut array: *mut dc_array_t, mut item: uint32_t) {
|
||||
dc_array_add_uint(array, item as uintptr_t);
|
||||
}
|
||||
|
||||
pub unsafe fn dc_array_add_ptr(mut array: *mut dc_array_t, mut item: *mut libc::c_void) {
|
||||
dc_array_add_uint(array, item as uintptr_t);
|
||||
}
|
||||
|
||||
pub unsafe fn dc_array_get_cnt(mut array: *const dc_array_t) -> size_t {
|
||||
if array.is_null() || (*array).magic != 0xa11aai32 as libc::c_uint {
|
||||
return 0i32 as size_t;
|
||||
}
|
||||
return (*array).count;
|
||||
(*array).count
|
||||
}
|
||||
|
||||
pub unsafe fn dc_array_get_uint(mut array: *const dc_array_t, mut index: size_t) -> uintptr_t {
|
||||
if array.is_null() || (*array).magic != 0xa11aai32 as libc::c_uint || index >= (*array).count {
|
||||
return 0i32 as uintptr_t;
|
||||
}
|
||||
return *(*array).array.offset(index as isize);
|
||||
*(*array).array.offset(index as isize)
|
||||
}
|
||||
|
||||
pub unsafe fn dc_array_get_id(mut array: *const dc_array_t, mut index: size_t) -> uint32_t {
|
||||
if array.is_null() || (*array).magic != 0xa11aai32 as libc::c_uint || index >= (*array).count {
|
||||
return 0i32 as uint32_t;
|
||||
@@ -96,8 +100,9 @@ pub unsafe fn dc_array_get_id(mut array: *const dc_array_t, mut index: size_t) -
|
||||
if (*array).type_0 == 1i32 {
|
||||
return (*(*(*array).array.offset(index as isize) as *mut _dc_location)).location_id;
|
||||
}
|
||||
return *(*array).array.offset(index as isize) as uint32_t;
|
||||
*(*array).array.offset(index as isize) as uint32_t
|
||||
}
|
||||
|
||||
pub unsafe fn dc_array_get_ptr(
|
||||
mut array: *const dc_array_t,
|
||||
mut index: size_t,
|
||||
@@ -105,8 +110,9 @@ pub unsafe fn dc_array_get_ptr(
|
||||
if array.is_null() || (*array).magic != 0xa11aai32 as libc::c_uint || index >= (*array).count {
|
||||
return 0 as *mut libc::c_void;
|
||||
}
|
||||
return *(*array).array.offset(index as isize) as *mut libc::c_void;
|
||||
*(*array).array.offset(index as isize) as *mut libc::c_void
|
||||
}
|
||||
|
||||
pub unsafe fn dc_array_get_latitude(
|
||||
mut array: *const dc_array_t,
|
||||
mut index: size_t,
|
||||
@@ -119,8 +125,9 @@ pub unsafe fn dc_array_get_latitude(
|
||||
{
|
||||
return 0i32 as libc::c_double;
|
||||
}
|
||||
return (*(*(*array).array.offset(index as isize) as *mut _dc_location)).latitude;
|
||||
(*(*(*array).array.offset(index as isize) as *mut _dc_location)).latitude
|
||||
}
|
||||
|
||||
pub unsafe fn dc_array_get_longitude(
|
||||
mut array: *const dc_array_t,
|
||||
mut index: size_t,
|
||||
@@ -133,8 +140,9 @@ pub unsafe fn dc_array_get_longitude(
|
||||
{
|
||||
return 0i32 as libc::c_double;
|
||||
}
|
||||
return (*(*(*array).array.offset(index as isize) as *mut _dc_location)).longitude;
|
||||
(*(*(*array).array.offset(index as isize) as *mut _dc_location)).longitude
|
||||
}
|
||||
|
||||
pub unsafe fn dc_array_get_accuracy(
|
||||
mut array: *const dc_array_t,
|
||||
mut index: size_t,
|
||||
@@ -147,8 +155,9 @@ pub unsafe fn dc_array_get_accuracy(
|
||||
{
|
||||
return 0i32 as libc::c_double;
|
||||
}
|
||||
return (*(*(*array).array.offset(index as isize) as *mut _dc_location)).accuracy;
|
||||
(*(*(*array).array.offset(index as isize) as *mut _dc_location)).accuracy
|
||||
}
|
||||
|
||||
pub unsafe fn dc_array_get_timestamp(mut array: *const dc_array_t, mut index: size_t) -> time_t {
|
||||
if array.is_null()
|
||||
|| (*array).magic != 0xa11aai32 as libc::c_uint
|
||||
@@ -158,8 +167,9 @@ pub unsafe fn dc_array_get_timestamp(mut array: *const dc_array_t, mut index: si
|
||||
{
|
||||
return 0i32 as time_t;
|
||||
}
|
||||
return (*(*(*array).array.offset(index as isize) as *mut _dc_location)).timestamp;
|
||||
(*(*(*array).array.offset(index as isize) as *mut _dc_location)).timestamp
|
||||
}
|
||||
|
||||
pub unsafe fn dc_array_get_chat_id(mut array: *const dc_array_t, mut index: size_t) -> uint32_t {
|
||||
if array.is_null()
|
||||
|| (*array).magic != 0xa11aai32 as libc::c_uint
|
||||
@@ -169,8 +179,9 @@ pub unsafe fn dc_array_get_chat_id(mut array: *const dc_array_t, mut index: size
|
||||
{
|
||||
return 0i32 as uint32_t;
|
||||
}
|
||||
return (*(*(*array).array.offset(index as isize) as *mut _dc_location)).chat_id;
|
||||
(*(*(*array).array.offset(index as isize) as *mut _dc_location)).chat_id
|
||||
}
|
||||
|
||||
pub unsafe fn dc_array_get_contact_id(mut array: *const dc_array_t, mut index: size_t) -> uint32_t {
|
||||
if array.is_null()
|
||||
|| (*array).magic != 0xa11aai32 as libc::c_uint
|
||||
@@ -180,8 +191,9 @@ pub unsafe fn dc_array_get_contact_id(mut array: *const dc_array_t, mut index: s
|
||||
{
|
||||
return 0i32 as uint32_t;
|
||||
}
|
||||
return (*(*(*array).array.offset(index as isize) as *mut _dc_location)).contact_id;
|
||||
(*(*(*array).array.offset(index as isize) as *mut _dc_location)).contact_id
|
||||
}
|
||||
|
||||
pub unsafe fn dc_array_get_msg_id(mut array: *const dc_array_t, mut index: size_t) -> uint32_t {
|
||||
if array.is_null()
|
||||
|| (*array).magic != 0xa11aai32 as libc::c_uint
|
||||
@@ -191,8 +203,9 @@ pub unsafe fn dc_array_get_msg_id(mut array: *const dc_array_t, mut index: size_
|
||||
{
|
||||
return 0i32 as uint32_t;
|
||||
}
|
||||
return (*(*(*array).array.offset(index as isize) as *mut _dc_location)).msg_id;
|
||||
(*(*(*array).array.offset(index as isize) as *mut _dc_location)).msg_id
|
||||
}
|
||||
|
||||
pub unsafe fn dc_array_get_marker(
|
||||
mut array: *const dc_array_t,
|
||||
mut index: size_t,
|
||||
@@ -205,9 +218,7 @@ pub unsafe fn dc_array_get_marker(
|
||||
{
|
||||
return 0 as *mut libc::c_char;
|
||||
}
|
||||
return dc_strdup_keep_null(
|
||||
(*(*(*array).array.offset(index as isize) as *mut _dc_location)).marker,
|
||||
);
|
||||
dc_strdup_keep_null((*(*(*array).array.offset(index as isize) as *mut _dc_location)).marker)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -233,6 +244,7 @@ pub unsafe fn dc_array_is_independent(array: *const dc_array_t, index: size_t) -
|
||||
(*(*(*array).array.offset(index as isize) as *mut _dc_location)).independent as libc::c_int
|
||||
}
|
||||
|
||||
// TODO should return bool /rtn
|
||||
pub unsafe fn dc_array_search_id(
|
||||
mut array: *const dc_array_t,
|
||||
mut needle: uint32_t,
|
||||
@@ -244,7 +256,6 @@ pub unsafe fn dc_array_search_id(
|
||||
let mut data: *mut uintptr_t = (*array).array;
|
||||
let mut i: size_t = 0;
|
||||
let mut cnt: size_t = (*array).count;
|
||||
i = 0i32 as size_t;
|
||||
while i < cnt {
|
||||
if *data.offset(i as isize) == needle as size_t {
|
||||
if !ret_index.is_null() {
|
||||
@@ -254,32 +265,30 @@ pub unsafe fn dc_array_search_id(
|
||||
}
|
||||
i = i.wrapping_add(1)
|
||||
}
|
||||
return 0i32;
|
||||
0
|
||||
}
|
||||
|
||||
pub unsafe fn dc_array_get_raw(mut array: *const dc_array_t) -> *const uintptr_t {
|
||||
if array.is_null() || (*array).magic != 0xa11aai32 as libc::c_uint {
|
||||
return 0 as *const uintptr_t;
|
||||
}
|
||||
return (*array).array;
|
||||
(*array).array
|
||||
}
|
||||
pub unsafe fn dc_array_new(
|
||||
mut context: *mut dc_context_t,
|
||||
mut initsize: size_t,
|
||||
) -> *mut dc_array_t {
|
||||
return dc_array_new_typed(context, 0i32, initsize);
|
||||
|
||||
pub unsafe fn dc_array_new(initsize: size_t) -> *mut dc_array_t {
|
||||
dc_array_new_typed(0, initsize)
|
||||
}
|
||||
|
||||
pub unsafe extern "C" fn dc_array_new_typed(
|
||||
mut context: *mut dc_context_t,
|
||||
mut type_0: libc::c_int,
|
||||
mut initsize: size_t,
|
||||
) -> *mut dc_array_t {
|
||||
let mut array: *mut dc_array_t = 0 as *mut dc_array_t;
|
||||
let mut array: *mut dc_array_t;
|
||||
array = calloc(1, ::std::mem::size_of::<dc_array_t>()) as *mut dc_array_t;
|
||||
if array.is_null() {
|
||||
exit(47i32);
|
||||
}
|
||||
(*array).magic = 0xa11aai32 as uint32_t;
|
||||
(*array).context = context;
|
||||
(*array).count = 0i32 as size_t;
|
||||
(*array).allocated = if initsize < 1 { 1 } else { initsize };
|
||||
(*array).type_0 = type_0;
|
||||
@@ -291,20 +300,22 @@ pub unsafe extern "C" fn dc_array_new_typed(
|
||||
if (*array).array.is_null() {
|
||||
exit(48i32);
|
||||
}
|
||||
return array;
|
||||
array
|
||||
}
|
||||
|
||||
pub unsafe fn dc_array_empty(mut array: *mut dc_array_t) {
|
||||
if array.is_null() || (*array).magic != 0xa11aai32 as libc::c_uint {
|
||||
return;
|
||||
}
|
||||
(*array).count = 0i32 as size_t;
|
||||
}
|
||||
|
||||
pub unsafe fn dc_array_duplicate(mut array: *const dc_array_t) -> *mut dc_array_t {
|
||||
let mut ret: *mut dc_array_t = 0 as *mut dc_array_t;
|
||||
let mut ret: *mut dc_array_t;
|
||||
if array.is_null() || (*array).magic != 0xa11aai32 as libc::c_uint {
|
||||
return 0 as *mut dc_array_t;
|
||||
}
|
||||
ret = dc_array_new((*array).context, (*array).allocated);
|
||||
ret = dc_array_new((*array).allocated);
|
||||
(*ret).count = (*array).count;
|
||||
memcpy(
|
||||
(*ret).array as *mut libc::c_void,
|
||||
@@ -313,8 +324,9 @@ pub unsafe fn dc_array_duplicate(mut array: *const dc_array_t) -> *mut dc_array_
|
||||
.count
|
||||
.wrapping_mul(::std::mem::size_of::<uintptr_t>()),
|
||||
);
|
||||
return ret;
|
||||
ret
|
||||
}
|
||||
|
||||
pub unsafe fn dc_array_sort_ids(mut array: *mut dc_array_t) {
|
||||
if array.is_null() || (*array).magic != 0xa11aai32 as libc::c_uint || (*array).count <= 1 {
|
||||
return;
|
||||
@@ -326,6 +338,7 @@ pub unsafe fn dc_array_sort_ids(mut array: *mut dc_array_t) {
|
||||
Some(cmp_intptr_t),
|
||||
);
|
||||
}
|
||||
|
||||
unsafe extern "C" fn cmp_intptr_t(
|
||||
mut p1: *const libc::c_void,
|
||||
mut p2: *const libc::c_void,
|
||||
@@ -340,6 +353,7 @@ unsafe extern "C" fn cmp_intptr_t(
|
||||
0i32
|
||||
};
|
||||
}
|
||||
|
||||
pub unsafe fn dc_array_sort_strings(mut array: *mut dc_array_t) {
|
||||
if array.is_null() || (*array).magic != 0xa11aai32 as libc::c_uint || (*array).count <= 1 {
|
||||
return;
|
||||
@@ -351,19 +365,22 @@ pub unsafe fn dc_array_sort_strings(mut array: *mut dc_array_t) {
|
||||
Some(cmp_strings_t),
|
||||
);
|
||||
}
|
||||
|
||||
unsafe extern "C" fn cmp_strings_t(
|
||||
mut p1: *const libc::c_void,
|
||||
mut p2: *const libc::c_void,
|
||||
) -> libc::c_int {
|
||||
let mut v1: *const libc::c_char = *(p1 as *mut *const libc::c_char);
|
||||
let mut v2: *const libc::c_char = *(p2 as *mut *const libc::c_char);
|
||||
return strcmp(v1, v2);
|
||||
|
||||
strcmp(v1, v2)
|
||||
}
|
||||
|
||||
pub unsafe fn dc_array_get_string(
|
||||
mut array: *const dc_array_t,
|
||||
mut sep: *const libc::c_char,
|
||||
) -> *mut libc::c_char {
|
||||
let mut ret: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut ret: *mut libc::c_char;
|
||||
if array.is_null() || (*array).magic != 0xa11aai32 as libc::c_uint || sep.is_null() {
|
||||
return dc_strdup(b"\x00" as *const u8 as *const libc::c_char);
|
||||
}
|
||||
@@ -378,7 +395,6 @@ pub unsafe fn dc_array_get_string(
|
||||
exit(35i32);
|
||||
}
|
||||
*ret.offset(0isize) = 0i32 as libc::c_char;
|
||||
i = 0;
|
||||
while i < (*array).count {
|
||||
if 0 != i {
|
||||
strcat(ret, sep);
|
||||
@@ -390,19 +406,21 @@ pub unsafe fn dc_array_get_string(
|
||||
);
|
||||
i += 1
|
||||
}
|
||||
return ret;
|
||||
|
||||
ret
|
||||
}
|
||||
|
||||
pub unsafe fn dc_arr_to_string(
|
||||
mut arr: *const uint32_t,
|
||||
mut cnt: libc::c_int,
|
||||
) -> *mut libc::c_char {
|
||||
/* return comma-separated value-string from integer array */
|
||||
let mut ret: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut ret: *mut libc::c_char;
|
||||
let mut sep: *const libc::c_char = b",\x00" as *const u8 as *const libc::c_char;
|
||||
if arr.is_null() || cnt <= 0i32 {
|
||||
return dc_strdup(b"\x00" as *const u8 as *const libc::c_char);
|
||||
}
|
||||
let mut i: libc::c_int = 0;
|
||||
let mut i: libc::c_int;
|
||||
ret = malloc(
|
||||
(cnt as usize)
|
||||
.wrapping_mul((11usize).wrapping_add(strlen(sep)))
|
||||
@@ -424,5 +442,6 @@ pub unsafe fn dc_arr_to_string(
|
||||
);
|
||||
i += 1
|
||||
}
|
||||
return ret;
|
||||
|
||||
ret
|
||||
}
|
||||
|
||||
1024
src/dc_chat.rs
1024
src/dc_chat.rs
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,3 @@
|
||||
use libc;
|
||||
|
||||
use crate::dc_array::*;
|
||||
use crate::dc_chat::*;
|
||||
use crate::dc_contact::*;
|
||||
@@ -15,27 +13,27 @@ use crate::x::*;
|
||||
/* * the structure behind dc_chatlist_t */
|
||||
#[derive(Copy, Clone)]
|
||||
#[repr(C)]
|
||||
pub struct dc_chatlist_t {
|
||||
pub struct dc_chatlist_t<'a> {
|
||||
pub magic: uint32_t,
|
||||
pub context: *mut dc_context_t,
|
||||
pub context: &'a dc_context_t,
|
||||
pub cnt: size_t,
|
||||
pub chatNlastmsg_ids: *mut dc_array_t,
|
||||
}
|
||||
|
||||
// handle chatlists
|
||||
pub unsafe fn dc_get_chatlist(
|
||||
mut context: *mut dc_context_t,
|
||||
pub unsafe fn dc_get_chatlist<'a>(
|
||||
mut context: &'a dc_context_t,
|
||||
mut listflags: libc::c_int,
|
||||
mut query_str: *const libc::c_char,
|
||||
mut query_id: uint32_t,
|
||||
) -> *mut dc_chatlist_t {
|
||||
) -> *mut dc_chatlist_t<'a> {
|
||||
let mut success: libc::c_int = 0i32;
|
||||
let mut obj: *mut dc_chatlist_t = dc_chatlist_new(context);
|
||||
if !(context.is_null() || (*context).magic != 0x11a11807i32 as libc::c_uint) {
|
||||
if !(0 == dc_chatlist_load_from_db(obj, listflags, query_str, query_id)) {
|
||||
success = 1i32
|
||||
}
|
||||
|
||||
if !(0 == dc_chatlist_load_from_db(obj, listflags, query_str, query_id)) {
|
||||
success = 1i32
|
||||
}
|
||||
|
||||
if 0 != success {
|
||||
return obj;
|
||||
} else {
|
||||
@@ -43,7 +41,8 @@ pub unsafe fn dc_get_chatlist(
|
||||
return 0 as *mut dc_chatlist_t;
|
||||
};
|
||||
}
|
||||
/* *
|
||||
|
||||
/**
|
||||
* @class dc_chatlist_t
|
||||
*
|
||||
* An object representing a single chatlist in memory.
|
||||
@@ -81,20 +80,21 @@ pub unsafe fn dc_get_chatlist(
|
||||
* Rendering the deaddrop in the described way
|
||||
* would not add extra work in the UI then.
|
||||
*/
|
||||
pub unsafe fn dc_chatlist_new(mut context: *mut dc_context_t) -> *mut dc_chatlist_t {
|
||||
let mut chatlist: *mut dc_chatlist_t = 0 as *mut dc_chatlist_t;
|
||||
pub unsafe fn dc_chatlist_new(mut context: &dc_context_t) -> *mut dc_chatlist_t {
|
||||
let mut chatlist: *mut dc_chatlist_t;
|
||||
chatlist = calloc(1, ::std::mem::size_of::<dc_chatlist_t>()) as *mut dc_chatlist_t;
|
||||
if chatlist.is_null() {
|
||||
exit(20i32);
|
||||
}
|
||||
(*chatlist).magic = 0xc4a71157u32;
|
||||
(*chatlist).context = context;
|
||||
(*chatlist).chatNlastmsg_ids = dc_array_new(context, 128i32 as size_t);
|
||||
(*chatlist).chatNlastmsg_ids = dc_array_new(128i32 as size_t);
|
||||
if (*chatlist).chatNlastmsg_ids.is_null() {
|
||||
exit(32i32);
|
||||
}
|
||||
return chatlist;
|
||||
chatlist
|
||||
}
|
||||
|
||||
pub unsafe fn dc_chatlist_unref(mut chatlist: *mut dc_chatlist_t) {
|
||||
if chatlist.is_null() || (*chatlist).magic != 0xc4a71157u32 {
|
||||
return;
|
||||
@@ -104,6 +104,7 @@ pub unsafe fn dc_chatlist_unref(mut chatlist: *mut dc_chatlist_t) {
|
||||
(*chatlist).magic = 0i32 as uint32_t;
|
||||
free(chatlist as *mut libc::c_void);
|
||||
}
|
||||
|
||||
pub unsafe fn dc_chatlist_empty(mut chatlist: *mut dc_chatlist_t) {
|
||||
if chatlist.is_null() || (*chatlist).magic != 0xc4a71157u32 {
|
||||
return;
|
||||
@@ -111,11 +112,13 @@ pub unsafe fn dc_chatlist_empty(mut chatlist: *mut dc_chatlist_t) {
|
||||
(*chatlist).cnt = 0i32 as size_t;
|
||||
dc_array_empty((*chatlist).chatNlastmsg_ids);
|
||||
}
|
||||
/* *
|
||||
|
||||
/**
|
||||
* Load a chatlist from the database to the chatlist object.
|
||||
*
|
||||
* @private @memberof dc_chatlist_t
|
||||
*/
|
||||
// TODO should return bool /rtn
|
||||
unsafe fn dc_chatlist_load_from_db(
|
||||
mut chatlist: *mut dc_chatlist_t,
|
||||
mut listflags: libc::c_int,
|
||||
@@ -129,8 +132,7 @@ unsafe fn dc_chatlist_load_from_db(
|
||||
let mut stmt: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt;
|
||||
let mut strLikeCmd: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut query: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
if !(chatlist.is_null() || (*chatlist).magic != 0xc4a71157u32 || (*chatlist).context.is_null())
|
||||
{
|
||||
if !(chatlist.is_null() || (*chatlist).magic != 0xc4a71157u32) {
|
||||
dc_chatlist_empty(chatlist);
|
||||
// select with left join and minimum:
|
||||
// - the inner select must use `hidden` and _not_ `m.hidden`
|
||||
@@ -144,15 +146,20 @@ unsafe fn dc_chatlist_load_from_db(
|
||||
// shown at all permanent in the chatlist.
|
||||
if 0 != query_contact_id {
|
||||
stmt =
|
||||
dc_sqlite3_prepare((*(*chatlist).context).sql,
|
||||
b"SELECT c.id, m.id FROM chats c LEFT JOIN msgs m ON c.id=m.chat_id AND m.timestamp=( SELECT MAX(timestamp) FROM msgs WHERE chat_id=c.id AND (hidden=0 OR (hidden=1 AND state=19))) WHERE c.id>9 AND c.blocked=0 AND c.id IN(SELECT chat_id FROM chats_contacts WHERE contact_id=?) GROUP BY c.id ORDER BY IFNULL(m.timestamp,0) DESC, m.id DESC;\x00"
|
||||
as *const u8 as *const libc::c_char);
|
||||
dc_sqlite3_prepare(
|
||||
(*chatlist).context,
|
||||
&mut (*chatlist).context.sql.clone().read().unwrap(),
|
||||
b"SELECT c.id, m.id FROM chats c LEFT JOIN msgs m ON c.id=m.chat_id AND m.timestamp=( SELECT MAX(timestamp) FROM msgs WHERE chat_id=c.id AND (hidden=0 OR (hidden=1 AND state=19))) WHERE c.id>9 AND c.blocked=0 AND c.id IN(SELECT chat_id FROM chats_contacts WHERE contact_id=?) GROUP BY c.id ORDER BY IFNULL(m.timestamp,0) DESC, m.id DESC;\x00"
|
||||
as *const u8 as *const libc::c_char
|
||||
);
|
||||
sqlite3_bind_int(stmt, 1i32, query_contact_id as libc::c_int);
|
||||
current_block = 3437258052017859086;
|
||||
} else if 0 != listflags & 0x1i32 {
|
||||
stmt =
|
||||
dc_sqlite3_prepare((*(*chatlist).context).sql,
|
||||
b"SELECT c.id, m.id FROM chats c LEFT JOIN msgs m ON c.id=m.chat_id AND m.timestamp=( SELECT MAX(timestamp) FROM msgs WHERE chat_id=c.id AND (hidden=0 OR (hidden=1 AND state=19))) WHERE c.id>9 AND c.blocked=0 AND c.archived=1 GROUP BY c.id ORDER BY IFNULL(m.timestamp,0) DESC, m.id DESC;\x00"
|
||||
dc_sqlite3_prepare(
|
||||
(*chatlist).context,
|
||||
&mut (*chatlist).context.sql.clone().read().unwrap(),
|
||||
b"SELECT c.id, m.id FROM chats c LEFT JOIN msgs m ON c.id=m.chat_id AND m.timestamp=( SELECT MAX(timestamp) FROM msgs WHERE chat_id=c.id AND (hidden=0 OR (hidden=1 AND state=19))) WHERE c.id>9 AND c.blocked=0 AND c.archived=1 GROUP BY c.id ORDER BY IFNULL(m.timestamp,0) DESC, m.id DESC;\x00"
|
||||
as *const u8 as *const libc::c_char);
|
||||
current_block = 3437258052017859086;
|
||||
} else if query__.is_null() {
|
||||
@@ -166,7 +173,9 @@ unsafe fn dc_chatlist_load_from_db(
|
||||
add_archived_link_item = 1i32
|
||||
}
|
||||
stmt =
|
||||
dc_sqlite3_prepare((*(*chatlist).context).sql,
|
||||
dc_sqlite3_prepare(
|
||||
(*chatlist).context,
|
||||
&mut (*chatlist).context.sql.clone().read().unwrap(),
|
||||
b"SELECT c.id, m.id FROM chats c LEFT JOIN msgs m ON c.id=m.chat_id AND m.timestamp=( SELECT MAX(timestamp) FROM msgs WHERE chat_id=c.id AND (hidden=0 OR (hidden=1 AND state=19))) WHERE c.id>9 AND c.blocked=0 AND c.archived=0 GROUP BY c.id ORDER BY IFNULL(m.timestamp,0) DESC, m.id DESC;\x00"
|
||||
as *const u8 as *const libc::c_char);
|
||||
current_block = 3437258052017859086;
|
||||
@@ -179,8 +188,10 @@ unsafe fn dc_chatlist_load_from_db(
|
||||
} else {
|
||||
strLikeCmd = dc_mprintf(b"%%%s%%\x00" as *const u8 as *const libc::c_char, query);
|
||||
stmt =
|
||||
dc_sqlite3_prepare((*(*chatlist).context).sql,
|
||||
b"SELECT c.id, m.id FROM chats c LEFT JOIN msgs m ON c.id=m.chat_id AND m.timestamp=( SELECT MAX(timestamp) FROM msgs WHERE chat_id=c.id AND (hidden=0 OR (hidden=1 AND state=19))) WHERE c.id>9 AND c.blocked=0 AND c.name LIKE ? GROUP BY c.id ORDER BY IFNULL(m.timestamp,0) DESC, m.id DESC;\x00"
|
||||
dc_sqlite3_prepare(
|
||||
(*chatlist).context,
|
||||
&mut (*chatlist).context.sql.clone().read().unwrap(),
|
||||
b"SELECT c.id, m.id FROM chats c LEFT JOIN msgs m ON c.id=m.chat_id AND m.timestamp=( SELECT MAX(timestamp) FROM msgs WHERE chat_id=c.id AND (hidden=0 OR (hidden=1 AND state=19))) WHERE c.id>9 AND c.blocked=0 AND c.name LIKE ? GROUP BY c.id ORDER BY IFNULL(m.timestamp,0) DESC, m.id DESC;\x00"
|
||||
as *const u8 as
|
||||
*const libc::c_char);
|
||||
sqlite3_bind_text(stmt, 1i32, strLikeCmd, -1i32, None);
|
||||
@@ -218,13 +229,15 @@ unsafe fn dc_chatlist_load_from_db(
|
||||
sqlite3_finalize(stmt);
|
||||
free(query as *mut libc::c_void);
|
||||
free(strLikeCmd as *mut libc::c_void);
|
||||
return success;
|
||||
success
|
||||
}
|
||||
|
||||
// Context functions to work with chatlist
|
||||
pub unsafe fn dc_get_archived_cnt(mut context: *mut dc_context_t) -> libc::c_int {
|
||||
pub unsafe fn dc_get_archived_cnt(mut context: &dc_context_t) -> libc::c_int {
|
||||
let mut ret: libc::c_int = 0i32;
|
||||
let mut stmt: *mut sqlite3_stmt = dc_sqlite3_prepare(
|
||||
(*context).sql,
|
||||
context,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
b"SELECT COUNT(*) FROM chats WHERE blocked=0 AND archived=1;\x00" as *const u8
|
||||
as *const libc::c_char,
|
||||
);
|
||||
@@ -232,28 +245,33 @@ pub unsafe fn dc_get_archived_cnt(mut context: *mut dc_context_t) -> libc::c_int
|
||||
ret = sqlite3_column_int(stmt, 0i32)
|
||||
}
|
||||
sqlite3_finalize(stmt);
|
||||
return ret;
|
||||
ret
|
||||
}
|
||||
unsafe fn get_last_deaddrop_fresh_msg(mut context: *mut dc_context_t) -> uint32_t {
|
||||
|
||||
unsafe fn get_last_deaddrop_fresh_msg(mut context: &dc_context_t) -> uint32_t {
|
||||
let mut ret: uint32_t = 0i32 as uint32_t;
|
||||
let mut stmt: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt;
|
||||
let mut stmt: *mut sqlite3_stmt;
|
||||
stmt =
|
||||
dc_sqlite3_prepare((*context).sql,
|
||||
b"SELECT m.id FROM msgs m LEFT JOIN chats c ON c.id=m.chat_id WHERE m.state=10 AND m.hidden=0 AND c.blocked=2 ORDER BY m.timestamp DESC, m.id DESC;\x00"
|
||||
dc_sqlite3_prepare(
|
||||
context,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
b"SELECT m.id FROM msgs m LEFT JOIN chats c ON c.id=m.chat_id WHERE m.state=10 AND m.hidden=0 AND c.blocked=2 ORDER BY m.timestamp DESC, m.id DESC;\x00"
|
||||
as *const u8 as *const libc::c_char);
|
||||
/* we have an index over the state-column, this should be sufficient as there are typically only few fresh messages */
|
||||
if !(sqlite3_step(stmt) != 100i32) {
|
||||
ret = sqlite3_column_int(stmt, 0i32) as uint32_t
|
||||
}
|
||||
sqlite3_finalize(stmt);
|
||||
return ret;
|
||||
ret
|
||||
}
|
||||
|
||||
pub unsafe fn dc_chatlist_get_cnt(mut chatlist: *const dc_chatlist_t) -> size_t {
|
||||
if chatlist.is_null() || (*chatlist).magic != 0xc4a71157u32 {
|
||||
return 0i32 as size_t;
|
||||
}
|
||||
return (*chatlist).cnt;
|
||||
(*chatlist).cnt
|
||||
}
|
||||
|
||||
pub unsafe fn dc_chatlist_get_chat_id(
|
||||
mut chatlist: *const dc_chatlist_t,
|
||||
mut index: size_t,
|
||||
@@ -265,8 +283,9 @@ pub unsafe fn dc_chatlist_get_chat_id(
|
||||
{
|
||||
return 0i32 as uint32_t;
|
||||
}
|
||||
return dc_array_get_id((*chatlist).chatNlastmsg_ids, index.wrapping_mul(2));
|
||||
dc_array_get_id((*chatlist).chatNlastmsg_ids, index.wrapping_mul(2))
|
||||
}
|
||||
|
||||
pub unsafe fn dc_chatlist_get_msg_id(
|
||||
mut chatlist: *const dc_chatlist_t,
|
||||
mut index: size_t,
|
||||
@@ -278,15 +297,16 @@ pub unsafe fn dc_chatlist_get_msg_id(
|
||||
{
|
||||
return 0i32 as uint32_t;
|
||||
}
|
||||
return dc_array_get_id(
|
||||
dc_array_get_id(
|
||||
(*chatlist).chatNlastmsg_ids,
|
||||
index.wrapping_mul(2).wrapping_add(1),
|
||||
);
|
||||
)
|
||||
}
|
||||
pub unsafe fn dc_chatlist_get_summary(
|
||||
mut chatlist: *const dc_chatlist_t,
|
||||
|
||||
pub unsafe fn dc_chatlist_get_summary<'a>(
|
||||
mut chatlist: *const dc_chatlist_t<'a>,
|
||||
mut index: size_t,
|
||||
mut chat: *mut dc_chat_t,
|
||||
mut chat: *mut dc_chat_t<'a>,
|
||||
) -> *mut dc_lot_t {
|
||||
let mut current_block: u64;
|
||||
/* The summary is created by the chat, not by the last message.
|
||||
@@ -296,7 +316,7 @@ pub unsafe fn dc_chatlist_get_summary(
|
||||
message. */
|
||||
/* the function never returns NULL */
|
||||
let mut ret: *mut dc_lot_t = dc_lot_new();
|
||||
let mut lastmsg_id: uint32_t = 0i32 as uint32_t;
|
||||
let mut lastmsg_id: uint32_t;
|
||||
let mut lastmsg: *mut dc_msg_t = 0 as *mut dc_msg_t;
|
||||
let mut lastcontact: *mut dc_contact_t = 0 as *mut dc_contact_t;
|
||||
let mut chat_to_delete: *mut dc_chat_t = 0 as *mut dc_chat_t;
|
||||
@@ -335,7 +355,7 @@ pub unsafe fn dc_chatlist_get_summary(
|
||||
lastcontact = dc_contact_new((*chatlist).context);
|
||||
dc_contact_load_from_db(
|
||||
lastcontact,
|
||||
(*(*chatlist).context).sql,
|
||||
&mut (*chatlist).context.sql.clone().read().unwrap(),
|
||||
(*lastmsg).from_id,
|
||||
);
|
||||
}
|
||||
@@ -353,11 +373,5 @@ pub unsafe fn dc_chatlist_get_summary(
|
||||
dc_msg_unref(lastmsg);
|
||||
dc_contact_unref(lastcontact);
|
||||
dc_chat_unref(chat_to_delete);
|
||||
return ret;
|
||||
}
|
||||
pub unsafe fn dc_chatlist_get_context(mut chatlist: *mut dc_chatlist_t) -> *mut dc_context_t {
|
||||
if chatlist.is_null() || (*chatlist).magic != 0xc4a71157u32 {
|
||||
return 0 as *mut dc_context_t;
|
||||
}
|
||||
return (*chatlist).context;
|
||||
ret
|
||||
}
|
||||
|
||||
2578
src/dc_configure.rs
2578
src/dc_configure.rs
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,3 @@
|
||||
use libc;
|
||||
|
||||
use crate::dc_saxparser::*;
|
||||
use crate::dc_strbuilder::*;
|
||||
use crate::dc_tools::*;
|
||||
|
||||
232
src/dc_e2ee.rs
232
src/dc_e2ee.rs
@@ -1,4 +1,15 @@
|
||||
use libc;
|
||||
use mmime::clist::*;
|
||||
use mmime::mailimf::*;
|
||||
use mmime::mailimf_types::*;
|
||||
use mmime::mailimf_types_helper::*;
|
||||
use mmime::mailmime::*;
|
||||
use mmime::mailmime_content::*;
|
||||
use mmime::mailmime_types::*;
|
||||
use mmime::mailmime_types_helper::*;
|
||||
use mmime::mailmime_write_mem::*;
|
||||
use mmime::mailprivacy_prepare_mime;
|
||||
use mmime::mmapstring::*;
|
||||
use mmime::{mailmime_substitute, MAILIMF_NO_ERROR, MAIL_NO_ERROR};
|
||||
|
||||
use crate::dc_aheader::*;
|
||||
use crate::dc_apeerstate::*;
|
||||
@@ -33,7 +44,7 @@ pub struct dc_e2ee_helper_t {
|
||||
}
|
||||
|
||||
pub unsafe fn dc_e2ee_encrypt(
|
||||
mut context: *mut dc_context_t,
|
||||
mut context: &dc_context_t,
|
||||
mut recipients_addr: *const clist,
|
||||
mut force_unencrypted: libc::c_int,
|
||||
mut e2ee_guaranteed: libc::c_int,
|
||||
@@ -42,19 +53,19 @@ pub unsafe fn dc_e2ee_encrypt(
|
||||
mut in_out_message: *mut mailmime,
|
||||
mut helper: *mut dc_e2ee_helper_t,
|
||||
) {
|
||||
let mut p_0: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut p_0: *mut libc::c_char;
|
||||
let mut current_block: u64;
|
||||
let mut col: libc::c_int = 0i32;
|
||||
let mut do_encrypt: libc::c_int = 0i32;
|
||||
let mut autocryptheader: *mut dc_aheader_t = dc_aheader_new();
|
||||
/*just a pointer into mailmime structure, must not be freed*/
|
||||
let mut imffields_unprotected: *mut mailimf_fields = 0 as *mut mailimf_fields;
|
||||
let mut imffields_unprotected: *mut mailimf_fields;
|
||||
let mut keyring: *mut dc_keyring_t = dc_keyring_new();
|
||||
let mut sign_key: *mut dc_key_t = dc_key_new();
|
||||
let mut plain: *mut MMAPString = mmap_string_new(b"\x00" as *const u8 as *const libc::c_char);
|
||||
let mut ctext: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut ctext_bytes: size_t = 0i32 as size_t;
|
||||
let mut peerstates: *mut dc_array_t = dc_array_new(0 as *mut dc_context_t, 10i32 as size_t);
|
||||
let mut peerstates = dc_array_new(10i32 as size_t);
|
||||
if !helper.is_null() {
|
||||
memset(
|
||||
helper as *mut libc::c_void,
|
||||
@@ -62,9 +73,7 @@ pub unsafe fn dc_e2ee_encrypt(
|
||||
::std::mem::size_of::<dc_e2ee_helper_t>(),
|
||||
);
|
||||
}
|
||||
if !(context.is_null()
|
||||
|| (*context).magic != 0x11a11807i32 as libc::c_uint
|
||||
|| recipients_addr.is_null()
|
||||
if !(recipients_addr.is_null()
|
||||
|| in_out_message.is_null()
|
||||
|| !(*in_out_message).mm_parent.is_null()
|
||||
|| autocryptheader.is_null()
|
||||
@@ -76,14 +85,16 @@ pub unsafe fn dc_e2ee_encrypt(
|
||||
/* libEtPan's pgp_encrypt_mime() takes the parent as the new root. We just expect the root as being given to this function. */
|
||||
(*autocryptheader).prefer_encrypt = 0i32;
|
||||
if 0 != dc_sqlite3_get_config_int(
|
||||
(*context).sql,
|
||||
context,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
b"e2ee_enabled\x00" as *const u8 as *const libc::c_char,
|
||||
1i32,
|
||||
) {
|
||||
(*autocryptheader).prefer_encrypt = 1i32
|
||||
}
|
||||
(*autocryptheader).addr = dc_sqlite3_get_config(
|
||||
(*context).sql,
|
||||
context,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
b"configured_addr\x00" as *const u8 as *const libc::c_char,
|
||||
0 as *const libc::c_char,
|
||||
);
|
||||
@@ -99,7 +110,7 @@ pub unsafe fn dc_e2ee_encrypt(
|
||||
/*only for random-seed*/
|
||||
if (*autocryptheader).prefer_encrypt == 1i32 || 0 != e2ee_guaranteed {
|
||||
do_encrypt = 1i32;
|
||||
let mut iter1: *mut clistiter = 0 as *mut clistiter;
|
||||
let mut iter1: *mut clistiter;
|
||||
iter1 = (*recipients_addr).first;
|
||||
while !iter1.is_null() {
|
||||
let mut recipient_addr: *const libc::c_char = (if !iter1.is_null() {
|
||||
@@ -113,7 +124,7 @@ pub unsafe fn dc_e2ee_encrypt(
|
||||
if !(strcasecmp(recipient_addr, (*autocryptheader).addr) == 0i32) {
|
||||
if 0 != dc_apeerstate_load_by_addr(
|
||||
peerstate,
|
||||
(*context).sql,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
recipient_addr,
|
||||
) && {
|
||||
key_to_use = dc_apeerstate_peek_key(peerstate, min_verified);
|
||||
@@ -132,16 +143,17 @@ pub unsafe fn dc_e2ee_encrypt(
|
||||
iter1 = if !iter1.is_null() {
|
||||
(*iter1).next
|
||||
} else {
|
||||
0 as *mut clistcell_s
|
||||
0 as *mut clistcell
|
||||
}
|
||||
}
|
||||
}
|
||||
if 0 != do_encrypt {
|
||||
dc_keyring_add(keyring, (*autocryptheader).public_key);
|
||||
if 0 == dc_key_load_self_private(
|
||||
context,
|
||||
sign_key,
|
||||
(*autocryptheader).addr,
|
||||
(*context).sql,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
) {
|
||||
do_encrypt = 0i32
|
||||
}
|
||||
@@ -247,7 +259,7 @@ pub unsafe fn dc_e2ee_encrypt(
|
||||
cur = if !cur.is_null() {
|
||||
(*cur).next
|
||||
} else {
|
||||
0 as *mut clistcell_s
|
||||
0 as *mut clistcell
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -393,7 +405,8 @@ pub unsafe fn dc_e2ee_encrypt(
|
||||
}
|
||||
dc_array_unref(peerstates);
|
||||
}
|
||||
/* ******************************************************************************
|
||||
|
||||
/*******************************************************************************
|
||||
* Tools
|
||||
******************************************************************************/
|
||||
unsafe fn new_data_part(
|
||||
@@ -404,15 +417,15 @@ unsafe fn new_data_part(
|
||||
) -> *mut mailmime {
|
||||
let mut current_block: u64;
|
||||
//char basename_buf[PATH_MAX];
|
||||
let mut encoding: *mut mailmime_mechanism = 0 as *mut mailmime_mechanism;
|
||||
let mut content: *mut mailmime_content = 0 as *mut mailmime_content;
|
||||
let mut mime: *mut mailmime = 0 as *mut mailmime;
|
||||
let mut encoding: *mut mailmime_mechanism;
|
||||
let mut content: *mut mailmime_content;
|
||||
let mut mime: *mut mailmime;
|
||||
//int r;
|
||||
//char * dup_filename;
|
||||
let mut mime_fields: *mut mailmime_fields = 0 as *mut mailmime_fields;
|
||||
let mut encoding_type: libc::c_int = 0;
|
||||
let mut content_type_str: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut do_encoding: libc::c_int = 0;
|
||||
let mut mime_fields: *mut mailmime_fields;
|
||||
let mut encoding_type: libc::c_int;
|
||||
let mut content_type_str: *mut libc::c_char;
|
||||
let mut do_encoding: libc::c_int;
|
||||
encoding = 0 as *mut mailmime_mechanism;
|
||||
if default_content_type.is_null() {
|
||||
content_type_str =
|
||||
@@ -426,7 +439,7 @@ unsafe fn new_data_part(
|
||||
} else {
|
||||
do_encoding = 1i32;
|
||||
if (*(*content).ct_type).tp_type == MAILMIME_TYPE_COMPOSITE_TYPE as libc::c_int {
|
||||
let mut composite: *mut mailmime_composite_type = 0 as *mut mailmime_composite_type;
|
||||
let mut composite: *mut mailmime_composite_type;
|
||||
composite = (*(*content).ct_type).tp_data.tp_composite_type;
|
||||
match (*composite).ct_type {
|
||||
1 => {
|
||||
@@ -501,11 +514,13 @@ unsafe fn new_data_part(
|
||||
}
|
||||
return 0 as *mut mailmime;
|
||||
}
|
||||
/* ******************************************************************************
|
||||
|
||||
/*******************************************************************************
|
||||
* Generate Keypairs
|
||||
******************************************************************************/
|
||||
// TODO should return bool /rtn
|
||||
unsafe fn load_or_generate_self_public_key(
|
||||
mut context: *mut dc_context_t,
|
||||
mut context: &dc_context_t,
|
||||
mut public_key: *mut dc_key_t,
|
||||
mut self_addr: *const libc::c_char,
|
||||
mut random_data_mime: *mut mailmime,
|
||||
@@ -513,44 +528,30 @@ unsafe fn load_or_generate_self_public_key(
|
||||
let mut current_block: u64;
|
||||
/* avoid double creation (we unlock the database during creation) */
|
||||
static mut s_in_key_creation: libc::c_int = 0i32;
|
||||
let mut key_created: libc::c_int = 0i32;
|
||||
let mut key_created: libc::c_int;
|
||||
let mut success: libc::c_int = 0i32;
|
||||
let mut key_creation_here: libc::c_int = 0i32;
|
||||
if !(context.is_null()
|
||||
|| (*context).magic != 0x11a11807i32 as libc::c_uint
|
||||
|| public_key.is_null())
|
||||
{
|
||||
if 0 == dc_key_load_self_public(public_key, self_addr, (*context).sql) {
|
||||
if !public_key.is_null() {
|
||||
if 0 == dc_key_load_self_public(
|
||||
context,
|
||||
public_key,
|
||||
self_addr,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
) {
|
||||
/* create the keypair - this may take a moment, however, as this is in a thread, this is no big deal */
|
||||
if 0 != s_in_key_creation {
|
||||
current_block = 10496152961502316708;
|
||||
} else {
|
||||
key_creation_here = 1i32;
|
||||
s_in_key_creation = 1i32;
|
||||
/* seed the random generator */
|
||||
let mut seed: [uintptr_t; 4] = [0; 4];
|
||||
seed[0usize] = time(0 as *mut time_t) as uintptr_t;
|
||||
seed[1usize] = seed.as_mut_ptr() as uintptr_t;
|
||||
seed[2usize] = public_key as uintptr_t;
|
||||
seed[3usize] = pthread_self() as uintptr_t;
|
||||
dc_pgp_rand_seed(
|
||||
context,
|
||||
seed.as_mut_ptr() as *const libc::c_void,
|
||||
::std::mem::size_of::<[uintptr_t; 4]>(),
|
||||
);
|
||||
if !random_data_mime.is_null() {
|
||||
let mut random_data_mmap: *mut MMAPString = 0 as *mut MMAPString;
|
||||
let mut random_data_mmap: *mut MMAPString;
|
||||
let mut col: libc::c_int = 0i32;
|
||||
random_data_mmap = mmap_string_new(b"\x00" as *const u8 as *const libc::c_char);
|
||||
if random_data_mmap.is_null() {
|
||||
current_block = 10496152961502316708;
|
||||
} else {
|
||||
mailmime_write_mem(random_data_mmap, &mut col, random_data_mime);
|
||||
dc_pgp_rand_seed(
|
||||
context,
|
||||
(*random_data_mmap).str_0 as *const libc::c_void,
|
||||
(*random_data_mmap).len,
|
||||
);
|
||||
mmap_string_free(random_data_mmap);
|
||||
current_block = 26972500619410423;
|
||||
}
|
||||
@@ -591,11 +592,12 @@ unsafe fn load_or_generate_self_public_key(
|
||||
current_block = 10496152961502316708;
|
||||
} else if 0
|
||||
== dc_key_save_self_keypair(
|
||||
context,
|
||||
public_key,
|
||||
private_key,
|
||||
self_addr,
|
||||
1i32,
|
||||
(*context).sql,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
)
|
||||
{
|
||||
/*set default*/
|
||||
@@ -631,15 +633,17 @@ unsafe fn load_or_generate_self_public_key(
|
||||
if 0 != key_creation_here {
|
||||
s_in_key_creation = 0i32
|
||||
}
|
||||
return success;
|
||||
|
||||
success
|
||||
}
|
||||
|
||||
/* returns 1 if sth. was decrypted, 0 in other cases */
|
||||
pub unsafe fn dc_e2ee_decrypt(
|
||||
mut context: *mut dc_context_t,
|
||||
mut context: &dc_context_t,
|
||||
mut in_out_message: *mut mailmime,
|
||||
mut helper: *mut dc_e2ee_helper_t,
|
||||
) {
|
||||
let mut iterations: libc::c_int = 0;
|
||||
let mut iterations: libc::c_int;
|
||||
/* return values: 0=nothing to decrypt/cannot decrypt, 1=sth. decrypted
|
||||
(to detect parts that could not be decrypted, simply look for left "multipart/encrypted" MIME types */
|
||||
/*just a pointer into mailmime structure, must not be freed*/
|
||||
@@ -659,12 +663,7 @@ pub unsafe fn dc_e2ee_decrypt(
|
||||
::std::mem::size_of::<dc_e2ee_helper_t>(),
|
||||
);
|
||||
}
|
||||
if !(context.is_null()
|
||||
|| (*context).magic != 0x11a11807i32 as libc::c_uint
|
||||
|| in_out_message.is_null()
|
||||
|| helper.is_null()
|
||||
|| imffields.is_null())
|
||||
{
|
||||
if !(in_out_message.is_null() || helper.is_null() || imffields.is_null()) {
|
||||
if !imffields.is_null() {
|
||||
let mut field: *mut mailimf_field =
|
||||
mailimf_find_field(imffields, MAILIMF_FIELD_FROM as libc::c_int);
|
||||
@@ -692,37 +691,47 @@ pub unsafe fn dc_e2ee_decrypt(
|
||||
}
|
||||
}
|
||||
if message_time > 0i32 as libc::c_long && !from.is_null() {
|
||||
if 0 != dc_apeerstate_load_by_addr(peerstate, (*context).sql, from) {
|
||||
if 0 != dc_apeerstate_load_by_addr(
|
||||
peerstate,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
from,
|
||||
) {
|
||||
if !autocryptheader.is_null() {
|
||||
dc_apeerstate_apply_header(peerstate, autocryptheader, message_time);
|
||||
dc_apeerstate_save_to_db(peerstate, (*context).sql, 0i32);
|
||||
dc_apeerstate_save_to_db(peerstate, &context.sql.clone().read().unwrap(), 0i32);
|
||||
} else if message_time > (*peerstate).last_seen_autocrypt
|
||||
&& 0 == contains_report(in_out_message)
|
||||
{
|
||||
dc_apeerstate_degrade_encryption(peerstate, message_time);
|
||||
dc_apeerstate_save_to_db(peerstate, (*context).sql, 0i32);
|
||||
dc_apeerstate_save_to_db(peerstate, &context.sql.clone().read().unwrap(), 0i32);
|
||||
}
|
||||
} else if !autocryptheader.is_null() {
|
||||
dc_apeerstate_init_from_header(peerstate, autocryptheader, message_time);
|
||||
dc_apeerstate_save_to_db(peerstate, (*context).sql, 1i32);
|
||||
dc_apeerstate_save_to_db(peerstate, &context.sql.clone().read().unwrap(), 1i32);
|
||||
}
|
||||
}
|
||||
/* load private key for decryption */
|
||||
self_addr = dc_sqlite3_get_config(
|
||||
(*context).sql,
|
||||
context,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
b"configured_addr\x00" as *const u8 as *const libc::c_char,
|
||||
0 as *const libc::c_char,
|
||||
);
|
||||
if !self_addr.is_null() {
|
||||
if !(0
|
||||
== dc_keyring_load_self_private_for_decrypting(
|
||||
context,
|
||||
private_keyring,
|
||||
self_addr,
|
||||
(*context).sql,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
))
|
||||
{
|
||||
if (*peerstate).last_seen == 0i32 as libc::c_long {
|
||||
dc_apeerstate_load_by_addr(peerstate, (*context).sql, from);
|
||||
dc_apeerstate_load_by_addr(
|
||||
peerstate,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
from,
|
||||
);
|
||||
}
|
||||
if 0 != (*peerstate).degrade_event {
|
||||
dc_handle_degrade_event(context, peerstate);
|
||||
@@ -768,13 +777,14 @@ pub unsafe fn dc_e2ee_decrypt(
|
||||
free(from as *mut libc::c_void);
|
||||
free(self_addr as *mut libc::c_void);
|
||||
}
|
||||
|
||||
unsafe fn update_gossip_peerstates(
|
||||
mut context: *mut dc_context_t,
|
||||
mut context: &dc_context_t,
|
||||
mut message_time: time_t,
|
||||
mut imffields: *mut mailimf_fields,
|
||||
mut gossip_headers: *const mailimf_fields,
|
||||
) -> *mut dc_hash_t {
|
||||
let mut cur1: *mut clistiter = 0 as *mut clistiter;
|
||||
let mut cur1: *mut clistiter;
|
||||
let mut recipients: *mut dc_hash_t = 0 as *mut dc_hash_t;
|
||||
let mut gossipped_addr: *mut dc_hash_t = 0 as *mut dc_hash_t;
|
||||
cur1 = (*(*gossip_headers).fld_list).first;
|
||||
@@ -811,14 +821,22 @@ unsafe fn update_gossip_peerstates(
|
||||
let mut peerstate: *mut dc_apeerstate_t = dc_apeerstate_new(context);
|
||||
if 0 == dc_apeerstate_load_by_addr(
|
||||
peerstate,
|
||||
(*context).sql,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
(*gossip_header).addr,
|
||||
) {
|
||||
dc_apeerstate_init_from_gossip(peerstate, gossip_header, message_time);
|
||||
dc_apeerstate_save_to_db(peerstate, (*context).sql, 1i32);
|
||||
dc_apeerstate_save_to_db(
|
||||
peerstate,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
1i32,
|
||||
);
|
||||
} else {
|
||||
dc_apeerstate_apply_gossip(peerstate, gossip_header, message_time);
|
||||
dc_apeerstate_save_to_db(peerstate, (*context).sql, 0i32);
|
||||
dc_apeerstate_save_to_db(
|
||||
peerstate,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
0i32,
|
||||
);
|
||||
}
|
||||
if 0 != (*peerstate).degrade_event {
|
||||
dc_handle_degrade_event(context, peerstate);
|
||||
@@ -851,17 +869,20 @@ unsafe fn update_gossip_peerstates(
|
||||
cur1 = if !cur1.is_null() {
|
||||
(*cur1).next
|
||||
} else {
|
||||
0 as *mut clistcell_s
|
||||
0 as *mut clistcell
|
||||
}
|
||||
}
|
||||
if !recipients.is_null() {
|
||||
dc_hash_clear(recipients);
|
||||
free(recipients as *mut libc::c_void);
|
||||
}
|
||||
return gossipped_addr;
|
||||
|
||||
gossipped_addr
|
||||
}
|
||||
|
||||
// TODO should return bool /rtn
|
||||
unsafe fn decrypt_recursive(
|
||||
mut context: *mut dc_context_t,
|
||||
mut context: &dc_context_t,
|
||||
mut mime: *mut mailmime,
|
||||
mut private_keyring: *const dc_keyring_t,
|
||||
mut public_keyring_for_validate: *const dc_keyring_t,
|
||||
@@ -869,9 +890,9 @@ unsafe fn decrypt_recursive(
|
||||
mut ret_gossip_headers: *mut *mut mailimf_fields,
|
||||
mut ret_has_unencrypted_parts: *mut libc::c_int,
|
||||
) -> libc::c_int {
|
||||
let mut ct: *mut mailmime_content = 0 as *mut mailmime_content;
|
||||
let mut cur: *mut clistiter = 0 as *mut clistiter;
|
||||
if context.is_null() || mime.is_null() {
|
||||
let mut ct: *mut mailmime_content;
|
||||
let mut cur: *mut clistiter;
|
||||
if mime.is_null() {
|
||||
return 0i32;
|
||||
}
|
||||
if (*mime).mm_type == MAILMIME_MULTIPLE as libc::c_int {
|
||||
@@ -919,7 +940,7 @@ unsafe fn decrypt_recursive(
|
||||
cur = if !cur.is_null() {
|
||||
(*cur).next
|
||||
} else {
|
||||
0 as *mut clistcell_s
|
||||
0 as *mut clistcell
|
||||
}
|
||||
}
|
||||
*ret_has_unencrypted_parts = 1i32
|
||||
@@ -944,7 +965,7 @@ unsafe fn decrypt_recursive(
|
||||
cur = if !cur.is_null() {
|
||||
(*cur).next
|
||||
} else {
|
||||
0 as *mut clistcell_s
|
||||
0 as *mut clistcell
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -963,19 +984,21 @@ unsafe fn decrypt_recursive(
|
||||
} else {
|
||||
*ret_has_unencrypted_parts = 1i32
|
||||
}
|
||||
return 0i32;
|
||||
|
||||
0
|
||||
}
|
||||
|
||||
unsafe fn decrypt_part(
|
||||
mut context: *mut dc_context_t,
|
||||
mut context: &dc_context_t,
|
||||
mut mime: *mut mailmime,
|
||||
mut private_keyring: *const dc_keyring_t,
|
||||
mut public_keyring_for_validate: *const dc_keyring_t,
|
||||
mut ret_valid_signatures: *mut dc_hash_t,
|
||||
mut ret_decrypted_mime: *mut *mut mailmime,
|
||||
) -> libc::c_int {
|
||||
let mut add_signatures: *mut dc_hash_t = 0 as *mut dc_hash_t;
|
||||
let mut add_signatures: *mut dc_hash_t;
|
||||
let mut current_block: u64;
|
||||
let mut mime_data: *mut mailmime_data = 0 as *mut mailmime_data;
|
||||
let mut mime_data: *mut mailmime_data;
|
||||
let mut mime_transfer_encoding: libc::c_int = MAILMIME_MECHANISM_BINARY as libc::c_int;
|
||||
/* mmap_string_unref()'d if set */
|
||||
let mut transfer_decoding_buffer: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
@@ -993,7 +1016,7 @@ unsafe fn decrypt_part(
|
||||
|| (*mime_data).dt_data.dt_text.dt_length <= 0)
|
||||
{
|
||||
if !(*mime).mm_mime_fields.is_null() {
|
||||
let mut cur: *mut clistiter = 0 as *mut clistiter;
|
||||
let mut cur: *mut clistiter;
|
||||
cur = (*(*(*mime).mm_mime_fields).fld_list).first;
|
||||
while !cur.is_null() {
|
||||
let mut field: *mut mailmime_field = (if !cur.is_null() {
|
||||
@@ -1011,7 +1034,7 @@ unsafe fn decrypt_part(
|
||||
cur = if !cur.is_null() {
|
||||
(*cur).next
|
||||
} else {
|
||||
0 as *mut clistcell_s
|
||||
0 as *mut clistcell
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1029,7 +1052,7 @@ unsafe fn decrypt_part(
|
||||
current_block = 4488286894823169796;
|
||||
}
|
||||
} else {
|
||||
let mut r: libc::c_int = 0;
|
||||
let mut r: libc::c_int;
|
||||
let mut current_index: size_t = 0i32 as size_t;
|
||||
r = mailmime_part_parse(
|
||||
(*mime_data).dt_data.dt_text.dt_data,
|
||||
@@ -1104,11 +1127,14 @@ unsafe fn decrypt_part(
|
||||
if !transfer_decoding_buffer.is_null() {
|
||||
mmap_string_unref(transfer_decoding_buffer);
|
||||
}
|
||||
return sth_decrypted;
|
||||
|
||||
sth_decrypted
|
||||
}
|
||||
/* ******************************************************************************
|
||||
|
||||
/*******************************************************************************
|
||||
* Decrypt
|
||||
******************************************************************************/
|
||||
// TODO should return bool /rtn
|
||||
unsafe fn has_decrypted_pgp_armor(
|
||||
mut str__: *const libc::c_char,
|
||||
mut str_bytes: libc::c_int,
|
||||
@@ -1132,9 +1158,11 @@ unsafe fn has_decrypted_pgp_armor(
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
|
||||
0
|
||||
}
|
||||
/* *
|
||||
|
||||
/**
|
||||
* Check if a MIME structure contains a multipart/report part.
|
||||
*
|
||||
* As reports are often unencrypted, we do not reset the Autocrypt header in
|
||||
@@ -1148,6 +1176,7 @@ unsafe fn has_decrypted_pgp_armor(
|
||||
* @param mime The mime struture to check
|
||||
* @return 1=multipart/report found in MIME, 0=no multipart/report found
|
||||
*/
|
||||
// TODO should return bool /rtn
|
||||
unsafe fn contains_report(mut mime: *mut mailmime) -> libc::c_int {
|
||||
if (*mime).mm_type == MAILMIME_MULTIPLE as libc::c_int {
|
||||
if (*(*(*mime).mm_content_type).ct_type).tp_type
|
||||
@@ -1164,7 +1193,7 @@ unsafe fn contains_report(mut mime: *mut mailmime) -> libc::c_int {
|
||||
{
|
||||
return 1i32;
|
||||
}
|
||||
let mut cur: *mut clistiter = 0 as *mut clistiter;
|
||||
let mut cur: *mut clistiter;
|
||||
cur = (*(*mime).mm_data.mm_multipart.mm_mp_list).first;
|
||||
while !cur.is_null() {
|
||||
if 0 != contains_report(
|
||||
@@ -1179,7 +1208,7 @@ unsafe fn contains_report(mut mime: *mut mailmime) -> libc::c_int {
|
||||
cur = if !cur.is_null() {
|
||||
(*cur).next
|
||||
} else {
|
||||
0 as *mut clistcell_s
|
||||
0 as *mut clistcell
|
||||
}
|
||||
}
|
||||
} else if (*mime).mm_type == MAILMIME_MESSAGE as libc::c_int {
|
||||
@@ -1187,8 +1216,10 @@ unsafe fn contains_report(mut mime: *mut mailmime) -> libc::c_int {
|
||||
return 1i32;
|
||||
}
|
||||
}
|
||||
return 0i32;
|
||||
|
||||
0
|
||||
}
|
||||
|
||||
/* frees data referenced by "mailmime" but not freed by mailmime_free(). After calling this function, in_out_message cannot be used any longer! */
|
||||
pub unsafe fn dc_e2ee_thanks(mut helper: *mut dc_e2ee_helper_t) {
|
||||
if helper.is_null() {
|
||||
@@ -1207,19 +1238,19 @@ pub unsafe fn dc_e2ee_thanks(mut helper: *mut dc_e2ee_helper_t) {
|
||||
(*helper).signatures = 0 as *mut dc_hash_t
|
||||
};
|
||||
}
|
||||
|
||||
/* makes sure, the private key exists, needed only for exporting keys and the case no message was sent before */
|
||||
pub unsafe fn dc_ensure_secret_key_exists(mut context: *mut dc_context_t) -> libc::c_int {
|
||||
// TODO should return bool /rtn
|
||||
pub unsafe fn dc_ensure_secret_key_exists(mut context: &dc_context_t) -> libc::c_int {
|
||||
/* normally, the key is generated as soon as the first mail is send
|
||||
(this is to gain some extra-random-seed by the message content and the timespan between program start and message sending) */
|
||||
let mut success: libc::c_int = 0i32;
|
||||
let mut public_key: *mut dc_key_t = dc_key_new();
|
||||
let mut self_addr: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
if !(context.is_null()
|
||||
|| (*context).magic != 0x11a11807i32 as libc::c_uint
|
||||
|| public_key.is_null())
|
||||
{
|
||||
if !public_key.is_null() {
|
||||
self_addr = dc_sqlite3_get_config(
|
||||
(*context).sql,
|
||||
context,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
b"configured_addr\x00" as *const u8 as *const libc::c_char,
|
||||
0 as *const libc::c_char,
|
||||
);
|
||||
@@ -1239,5 +1270,6 @@ pub unsafe fn dc_ensure_secret_key_exists(mut context: *mut dc_context_t) -> lib
|
||||
}
|
||||
dc_key_unref(public_key);
|
||||
free(self_addr as *mut libc::c_void);
|
||||
return success;
|
||||
|
||||
success
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
use libc;
|
||||
|
||||
use crate::types::*;
|
||||
use crate::x::*;
|
||||
|
||||
@@ -21,13 +19,16 @@ pub struct dc_hash_t {
|
||||
pub htsize: libc::c_int,
|
||||
pub ht: *mut _ht,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
#[repr(C)]
|
||||
pub struct _ht {
|
||||
pub count: libc::c_int,
|
||||
pub chain: *mut dc_hashelem_t,
|
||||
}
|
||||
|
||||
pub type dc_hashelem_t = _dc_hashelem;
|
||||
|
||||
/* Each element in the hash table is an instance of the following
|
||||
* structure. All elements are stored on a single doubly-linked list.
|
||||
*
|
||||
@@ -43,6 +44,7 @@ pub struct _dc_hashelem {
|
||||
pub pKey: *mut libc::c_void,
|
||||
pub nKey: libc::c_int,
|
||||
}
|
||||
|
||||
/*
|
||||
* There are 4 different modes of operation for a hash table:
|
||||
*
|
||||
@@ -102,6 +104,7 @@ pub unsafe fn dc_hash_init(
|
||||
(*pNew).htsize = 0i32;
|
||||
(*pNew).ht = 0 as *mut _ht;
|
||||
}
|
||||
|
||||
pub unsafe fn dc_hash_insert(
|
||||
mut pH: *mut dc_hash_t,
|
||||
mut pKey: *const libc::c_void,
|
||||
@@ -109,15 +112,15 @@ pub unsafe fn dc_hash_insert(
|
||||
mut data: *mut libc::c_void,
|
||||
) -> *mut libc::c_void {
|
||||
/* Raw hash value of the key */
|
||||
let mut hraw: libc::c_int = 0;
|
||||
let mut hraw: libc::c_int;
|
||||
/* the hash of the key modulo hash table size */
|
||||
let mut h: libc::c_int = 0;
|
||||
let mut h: libc::c_int;
|
||||
/* Used to loop thru the element list */
|
||||
let mut elem: *mut dc_hashelem_t = 0 as *mut dc_hashelem_t;
|
||||
let mut elem: *mut dc_hashelem_t;
|
||||
/* New element added to the pH */
|
||||
let mut new_elem: *mut dc_hashelem_t = 0 as *mut dc_hashelem_t;
|
||||
let mut new_elem: *mut dc_hashelem_t;
|
||||
/* The hash function */
|
||||
let mut xHash: Option<unsafe fn(_: *const libc::c_void, _: libc::c_int) -> libc::c_int> = None;
|
||||
let mut xHash: Option<unsafe fn(_: *const libc::c_void, _: libc::c_int) -> libc::c_int>;
|
||||
if 0 != pH.is_null() as libc::c_int as libc::c_long {
|
||||
__assert_rtn(
|
||||
(*::std::mem::transmute::<&[u8; 15], &[libc::c_char; 15]>(b"dc_hash_insert\x00"))
|
||||
@@ -215,8 +218,10 @@ pub unsafe fn dc_hash_insert(
|
||||
h = hraw & (*pH).htsize - 1i32;
|
||||
insertElement(pH, &mut *(*pH).ht.offset(h as isize), new_elem);
|
||||
(*new_elem).data = data;
|
||||
return 0 as *mut libc::c_void;
|
||||
|
||||
0 as *mut libc::c_void
|
||||
}
|
||||
|
||||
/* Link an element into the hash table
|
||||
*/
|
||||
unsafe extern "C" fn insertElement(
|
||||
@@ -225,7 +230,7 @@ unsafe extern "C" fn insertElement(
|
||||
mut pNew: *mut dc_hashelem_t,
|
||||
) {
|
||||
/* First element already in pEntry */
|
||||
let mut pHead: *mut dc_hashelem_t = 0 as *mut dc_hashelem_t;
|
||||
let mut pHead: *mut dc_hashelem_t;
|
||||
pHead = (*pEntry).chain;
|
||||
if !pHead.is_null() {
|
||||
(*pNew).next = pHead;
|
||||
@@ -247,18 +252,19 @@ unsafe extern "C" fn insertElement(
|
||||
(*pEntry).count += 1;
|
||||
(*pEntry).chain = pNew;
|
||||
}
|
||||
|
||||
/* Resize the hash table so that it cantains "new_size" buckets.
|
||||
* "new_size" must be a power of 2. The hash table might fail
|
||||
* to resize if sjhashMalloc() fails.
|
||||
*/
|
||||
unsafe fn rehash(mut pH: *mut dc_hash_t, mut new_size: libc::c_int) {
|
||||
/* The new hash table */
|
||||
let mut new_ht: *mut _ht = 0 as *mut _ht;
|
||||
let mut new_ht: *mut _ht;
|
||||
/* For looping over existing elements */
|
||||
let mut elem: *mut dc_hashelem_t = 0 as *mut dc_hashelem_t;
|
||||
let mut next_elem: *mut dc_hashelem_t = 0 as *mut dc_hashelem_t;
|
||||
let mut elem: *mut dc_hashelem_t;
|
||||
let mut next_elem: *mut dc_hashelem_t;
|
||||
/* The hash function */
|
||||
let mut xHash: Option<unsafe fn(_: *const libc::c_void, _: libc::c_int) -> libc::c_int> = None;
|
||||
let mut xHash: Option<unsafe fn(_: *const libc::c_void, _: libc::c_int) -> libc::c_int>;
|
||||
if 0 != !(new_size & new_size - 1i32 == 0i32) as libc::c_int as libc::c_long {
|
||||
__assert_rtn(
|
||||
(*::std::mem::transmute::<&[u8; 7], &[libc::c_char; 7]>(b"rehash\x00")).as_ptr(),
|
||||
@@ -290,6 +296,7 @@ unsafe fn rehash(mut pH: *mut dc_hash_t, mut new_size: libc::c_int) {
|
||||
elem = next_elem
|
||||
}
|
||||
}
|
||||
|
||||
/* Return a pointer to the appropriate hash function given the key class.
|
||||
*
|
||||
* About the syntax:
|
||||
@@ -309,8 +316,10 @@ unsafe fn hashFunction(
|
||||
4 => return Some(binHash),
|
||||
_ => {}
|
||||
}
|
||||
return None;
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
/* Hash and comparison functions when the mode is SJHASH_BINARY
|
||||
*/
|
||||
unsafe fn binHash(mut pKey: *const libc::c_void, mut nKey: libc::c_int) -> libc::c_int {
|
||||
@@ -326,13 +335,16 @@ unsafe fn binHash(mut pKey: *const libc::c_void, mut nKey: libc::c_int) -> libc:
|
||||
z = z.offset(1);
|
||||
h = h << 3i32 ^ h ^ *fresh1 as libc::c_int
|
||||
}
|
||||
return h & 0x7fffffffi32;
|
||||
|
||||
h & 0x7fffffffi32
|
||||
}
|
||||
|
||||
/* Hash and comparison functions when the mode is SJHASH_STRING
|
||||
*/
|
||||
unsafe fn strHash(mut pKey: *const libc::c_void, mut nKey: libc::c_int) -> libc::c_int {
|
||||
return sjhashNoCase(pKey as *const libc::c_char, nKey);
|
||||
sjhashNoCase(pKey as *const libc::c_char, nKey)
|
||||
}
|
||||
|
||||
/* This function computes a hash on the name of a keyword.
|
||||
* Case is not significant.
|
||||
*/
|
||||
@@ -347,8 +359,10 @@ unsafe fn sjhashNoCase(mut z: *const libc::c_char, mut n: libc::c_int) -> libc::
|
||||
h = h << 3i32 ^ h ^ sjhashUpperToLower[*fresh2 as libc::c_uchar as usize] as libc::c_int;
|
||||
n -= 1
|
||||
}
|
||||
return h & 0x7fffffffi32;
|
||||
|
||||
h & 0x7fffffffi32
|
||||
}
|
||||
|
||||
/* An array to map all upper-case characters into their corresponding
|
||||
* lower-case character.
|
||||
*/
|
||||
@@ -610,17 +624,20 @@ static mut sjhashUpperToLower: [libc::c_uchar; 256] = [
|
||||
254i32 as libc::c_uchar,
|
||||
255i32 as libc::c_uchar,
|
||||
];
|
||||
|
||||
/* Hash and comparison functions when the mode is SJHASH_POINTER
|
||||
*/
|
||||
unsafe fn ptrHash(pKey: *const libc::c_void, _nKey: libc::c_int) -> libc::c_int {
|
||||
let mut x: uintptr_t = pKey as uintptr_t;
|
||||
return (x ^ x << 8i32 ^ x >> 8i32) as libc::c_int;
|
||||
(x ^ x << 8i32 ^ x >> 8i32) as libc::c_int
|
||||
}
|
||||
|
||||
/* Hash and comparison functions when the mode is SJHASH_INT
|
||||
*/
|
||||
unsafe fn intHash(_pKey: *const libc::c_void, mut nKey: libc::c_int) -> libc::c_int {
|
||||
return nKey ^ nKey << 8i32 ^ nKey >> 8i32;
|
||||
nKey ^ nKey << 8i32 ^ nKey >> 8i32
|
||||
}
|
||||
|
||||
/*
|
||||
** Based upon hash.c from sqlite which author disclaims copyright to this source code. In place of
|
||||
** a legal notice, here is a blessing:
|
||||
@@ -636,6 +653,7 @@ unsafe fn sjhashMalloc(mut bytes: libc::c_int) -> *mut libc::c_void {
|
||||
}
|
||||
p
|
||||
}
|
||||
|
||||
/* Remove a single entry from the hash table given a pointer to that
|
||||
* element and a hash on the element's key.
|
||||
*/
|
||||
@@ -644,7 +662,7 @@ unsafe fn removeElementGivenHash(
|
||||
mut elem: *mut dc_hashelem_t,
|
||||
mut h: libc::c_int,
|
||||
) {
|
||||
let mut pEntry: *mut _ht = 0 as *mut _ht;
|
||||
let mut pEntry: *mut _ht;
|
||||
if !(*elem).prev.is_null() {
|
||||
(*(*elem).prev).next = (*elem).next
|
||||
} else {
|
||||
@@ -667,6 +685,7 @@ unsafe fn removeElementGivenHash(
|
||||
free(elem as *mut libc::c_void);
|
||||
(*pH).count -= 1;
|
||||
}
|
||||
|
||||
/* This function (for internal use only) locates an element in an
|
||||
* hash table that matches the given key. The hash for this key has
|
||||
* already been computed and is passed as the 4th parameter.
|
||||
@@ -678,9 +697,9 @@ unsafe fn findElementGivenHash(
|
||||
mut h: libc::c_int,
|
||||
) -> *mut dc_hashelem_t {
|
||||
/* Used to loop thru the element list */
|
||||
let mut elem: *mut dc_hashelem_t = 0 as *mut dc_hashelem_t;
|
||||
let mut elem: *mut dc_hashelem_t;
|
||||
/* Number of elements left to test */
|
||||
let mut count: libc::c_int = 0;
|
||||
let mut count: libc::c_int;
|
||||
/* comparison function */
|
||||
let mut xCompare: Option<
|
||||
unsafe fn(
|
||||
@@ -689,7 +708,7 @@ unsafe fn findElementGivenHash(
|
||||
_: *const libc::c_void,
|
||||
_: libc::c_int,
|
||||
) -> libc::c_int,
|
||||
> = None;
|
||||
>;
|
||||
if !(*pH).ht.is_null() {
|
||||
let mut pEntry: *mut _ht = &mut *(*pH).ht.offset(h as isize) as *mut _ht;
|
||||
elem = (*pEntry).chain;
|
||||
@@ -709,8 +728,10 @@ unsafe fn findElementGivenHash(
|
||||
elem = (*elem).next
|
||||
}
|
||||
}
|
||||
return 0 as *mut dc_hashelem_t;
|
||||
|
||||
0 as *mut dc_hashelem_t
|
||||
}
|
||||
|
||||
/* Return a pointer to the appropriate hash function given the key class.
|
||||
*/
|
||||
unsafe fn compareFunction(
|
||||
@@ -730,8 +751,9 @@ unsafe fn compareFunction(
|
||||
4 => return Some(binCompare),
|
||||
_ => {}
|
||||
}
|
||||
return None;
|
||||
None
|
||||
}
|
||||
|
||||
unsafe fn binCompare(
|
||||
mut pKey1: *const libc::c_void,
|
||||
mut n1: libc::c_int,
|
||||
@@ -741,8 +763,9 @@ unsafe fn binCompare(
|
||||
if n1 != n2 {
|
||||
return 1i32;
|
||||
}
|
||||
return memcmp(pKey1, pKey2, n1 as libc::size_t);
|
||||
memcmp(pKey1, pKey2, n1 as libc::size_t)
|
||||
}
|
||||
|
||||
unsafe fn strCompare(
|
||||
mut pKey1: *const libc::c_void,
|
||||
mut n1: libc::c_int,
|
||||
@@ -752,12 +775,13 @@ unsafe fn strCompare(
|
||||
if n1 != n2 {
|
||||
return 1i32;
|
||||
}
|
||||
return sjhashStrNICmp(
|
||||
sjhashStrNICmp(
|
||||
pKey1 as *const libc::c_char,
|
||||
pKey2 as *const libc::c_char,
|
||||
n1,
|
||||
);
|
||||
)
|
||||
}
|
||||
|
||||
/* Some systems have stricmp(). Others have strcasecmp(). Because
|
||||
* there is no consistency, we will define our own.
|
||||
*/
|
||||
@@ -766,8 +790,8 @@ unsafe fn sjhashStrNICmp(
|
||||
mut zRight: *const libc::c_char,
|
||||
mut N: libc::c_int,
|
||||
) -> libc::c_int {
|
||||
let mut a: *mut libc::c_uchar = 0 as *mut libc::c_uchar;
|
||||
let mut b: *mut libc::c_uchar = 0 as *mut libc::c_uchar;
|
||||
let mut a: *mut libc::c_uchar;
|
||||
let mut b: *mut libc::c_uchar;
|
||||
a = zLeft as *mut libc::c_uchar;
|
||||
b = zRight as *mut libc::c_uchar;
|
||||
loop {
|
||||
@@ -790,6 +814,7 @@ unsafe fn sjhashStrNICmp(
|
||||
- sjhashUpperToLower[*b as usize] as libc::c_int
|
||||
};
|
||||
}
|
||||
|
||||
unsafe fn ptrCompare(
|
||||
pKey1: *const libc::c_void,
|
||||
_n1: libc::c_int,
|
||||
@@ -820,11 +845,11 @@ pub unsafe fn dc_hash_find(
|
||||
mut nKey: libc::c_int,
|
||||
) -> *mut libc::c_void {
|
||||
/* A hash on key */
|
||||
let mut h: libc::c_int = 0;
|
||||
let mut h: libc::c_int;
|
||||
/* The element that matches key */
|
||||
let mut elem: *mut dc_hashelem_t = 0 as *mut dc_hashelem_t;
|
||||
let mut elem: *mut dc_hashelem_t;
|
||||
/* The hash function */
|
||||
let mut xHash: Option<unsafe fn(_: *const libc::c_void, _: libc::c_int) -> libc::c_int> = None;
|
||||
let mut xHash: Option<unsafe fn(_: *const libc::c_void, _: libc::c_int) -> libc::c_int>;
|
||||
if pH.is_null() || (*pH).ht.is_null() {
|
||||
return 0 as *mut libc::c_void;
|
||||
}
|
||||
@@ -857,9 +882,10 @@ pub unsafe fn dc_hash_find(
|
||||
0 as *mut libc::c_void
|
||||
};
|
||||
}
|
||||
|
||||
pub unsafe fn dc_hash_clear(mut pH: *mut dc_hash_t) {
|
||||
/* For looping over all elements of the table */
|
||||
let mut elem: *mut dc_hashelem_t = 0 as *mut dc_hashelem_t;
|
||||
let mut elem: *mut dc_hashelem_t;
|
||||
if pH.is_null() {
|
||||
return;
|
||||
}
|
||||
|
||||
3274
src/dc_imap.rs
3274
src/dc_imap.rs
File diff suppressed because it is too large
Load Diff
836
src/dc_imex.rs
836
src/dc_imex.rs
File diff suppressed because it is too large
Load Diff
980
src/dc_job.rs
980
src/dc_job.rs
File diff suppressed because it is too large
Load Diff
@@ -1,252 +1,265 @@
|
||||
use libc;
|
||||
use std::sync::{Arc, Condvar, Mutex};
|
||||
|
||||
use crate::dc_configure::*;
|
||||
use crate::dc_context::dc_context_t;
|
||||
use crate::dc_imap::dc_imap_t;
|
||||
use crate::dc_imap::*;
|
||||
use crate::dc_imap::Imap;
|
||||
use crate::dc_log::*;
|
||||
use crate::dc_sqlite3::*;
|
||||
use crate::dc_tools::*;
|
||||
use crate::types::*;
|
||||
use crate::x::*;
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
#[repr(C)]
|
||||
pub struct dc_jobthread_t {
|
||||
pub context: *mut dc_context_t,
|
||||
pub name: *mut libc::c_char,
|
||||
pub folder_config_name: *mut libc::c_char,
|
||||
pub imap: *mut dc_imap_t,
|
||||
pub mutex: pthread_mutex_t,
|
||||
pub idle_cond: pthread_cond_t,
|
||||
pub idle_condflag: libc::c_int,
|
||||
pub jobs_needed: libc::c_int,
|
||||
pub suspended: libc::c_int,
|
||||
pub using_handle: libc::c_int,
|
||||
pub imap: Imap,
|
||||
pub state: Arc<(Mutex<JobState>, Condvar)>,
|
||||
}
|
||||
|
||||
pub unsafe fn dc_jobthread_init(
|
||||
mut jobthread: *mut dc_jobthread_t,
|
||||
mut context: *mut dc_context_t,
|
||||
mut name: *const libc::c_char,
|
||||
mut folder_config_name: *const libc::c_char,
|
||||
name: *const libc::c_char,
|
||||
folder_config_name: *const libc::c_char,
|
||||
imap: Imap,
|
||||
) -> dc_jobthread_t {
|
||||
dc_jobthread_t {
|
||||
name: dc_strdup(name),
|
||||
folder_config_name: dc_strdup(folder_config_name),
|
||||
imap,
|
||||
state: Arc::new((Mutex::new(Default::default()), Condvar::new())),
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct JobState {
|
||||
idle: bool,
|
||||
jobs_needed: i32,
|
||||
suspended: i32,
|
||||
using_handle: i32,
|
||||
}
|
||||
|
||||
pub unsafe fn dc_jobthread_exit(jobthread: &mut dc_jobthread_t) {
|
||||
free(jobthread.name as *mut libc::c_void);
|
||||
jobthread.name = 0 as *mut libc::c_char;
|
||||
free(jobthread.folder_config_name as *mut libc::c_void);
|
||||
jobthread.folder_config_name = 0 as *mut libc::c_char;
|
||||
}
|
||||
|
||||
pub unsafe fn dc_jobthread_suspend(
|
||||
context: &dc_context_t,
|
||||
jobthread: &mut dc_jobthread_t,
|
||||
suspend: libc::c_int,
|
||||
) {
|
||||
if jobthread.is_null() || context.is_null() || name.is_null() {
|
||||
return;
|
||||
}
|
||||
(*jobthread).context = context;
|
||||
(*jobthread).name = dc_strdup(name);
|
||||
(*jobthread).folder_config_name = dc_strdup(folder_config_name);
|
||||
(*jobthread).imap = 0 as *mut dc_imap_t;
|
||||
pthread_mutex_init(&mut (*jobthread).mutex, 0 as *const pthread_mutexattr_t);
|
||||
pthread_cond_init(&mut (*jobthread).idle_cond, 0 as *const pthread_condattr_t);
|
||||
(*jobthread).idle_condflag = 0i32;
|
||||
(*jobthread).jobs_needed = 0i32;
|
||||
(*jobthread).suspended = 0i32;
|
||||
(*jobthread).using_handle = 0i32;
|
||||
}
|
||||
pub unsafe fn dc_jobthread_exit(mut jobthread: *mut dc_jobthread_t) {
|
||||
if jobthread.is_null() {
|
||||
return;
|
||||
}
|
||||
pthread_cond_destroy(&mut (*jobthread).idle_cond);
|
||||
pthread_mutex_destroy(&mut (*jobthread).mutex);
|
||||
free((*jobthread).name as *mut libc::c_void);
|
||||
(*jobthread).name = 0 as *mut libc::c_char;
|
||||
free((*jobthread).folder_config_name as *mut libc::c_void);
|
||||
(*jobthread).folder_config_name = 0 as *mut libc::c_char;
|
||||
}
|
||||
pub unsafe fn dc_jobthread_suspend(mut jobthread: *mut dc_jobthread_t, mut suspend: libc::c_int) {
|
||||
if jobthread.is_null() {
|
||||
return;
|
||||
}
|
||||
if 0 != suspend {
|
||||
dc_log_info(
|
||||
(*jobthread).context,
|
||||
context,
|
||||
0i32,
|
||||
b"Suspending %s-thread.\x00" as *const u8 as *const libc::c_char,
|
||||
(*jobthread).name,
|
||||
jobthread.name,
|
||||
);
|
||||
pthread_mutex_lock(&mut (*jobthread).mutex);
|
||||
(*jobthread).suspended = 1i32;
|
||||
pthread_mutex_unlock(&mut (*jobthread).mutex);
|
||||
dc_jobthread_interrupt_idle(jobthread);
|
||||
|
||||
{
|
||||
jobthread.state.clone().0.lock().unwrap().suspended = 1;
|
||||
}
|
||||
dc_jobthread_interrupt_idle(context, jobthread);
|
||||
loop {
|
||||
pthread_mutex_lock(&mut (*jobthread).mutex);
|
||||
if (*jobthread).using_handle == 0i32 {
|
||||
pthread_mutex_unlock(&mut (*jobthread).mutex);
|
||||
let using_handle = jobthread.state.clone().0.lock().unwrap().using_handle;
|
||||
if using_handle == 0 {
|
||||
return;
|
||||
}
|
||||
pthread_mutex_unlock(&mut (*jobthread).mutex);
|
||||
usleep((300i32 * 1000i32) as useconds_t);
|
||||
}
|
||||
} else {
|
||||
dc_log_info(
|
||||
(*jobthread).context,
|
||||
context,
|
||||
0i32,
|
||||
b"Unsuspending %s-thread.\x00" as *const u8 as *const libc::c_char,
|
||||
(*jobthread).name,
|
||||
jobthread.name,
|
||||
);
|
||||
pthread_mutex_lock(&mut (*jobthread).mutex);
|
||||
(*jobthread).suspended = 0i32;
|
||||
(*jobthread).idle_condflag = 1i32;
|
||||
pthread_cond_signal(&mut (*jobthread).idle_cond);
|
||||
pthread_mutex_unlock(&mut (*jobthread).mutex);
|
||||
};
|
||||
}
|
||||
pub unsafe extern "C" fn dc_jobthread_interrupt_idle(mut jobthread: *mut dc_jobthread_t) {
|
||||
if jobthread.is_null() {
|
||||
return;
|
||||
|
||||
let &(ref lock, ref cvar) = &*jobthread.state.clone();
|
||||
let mut state = lock.lock().unwrap();
|
||||
|
||||
state.suspended = 0;
|
||||
state.idle = true;
|
||||
cvar.notify_one();
|
||||
}
|
||||
pthread_mutex_lock(&mut (*jobthread).mutex);
|
||||
(*jobthread).jobs_needed = 1i32;
|
||||
pthread_mutex_unlock(&mut (*jobthread).mutex);
|
||||
}
|
||||
|
||||
pub unsafe extern "C" fn dc_jobthread_interrupt_idle(
|
||||
context: &dc_context_t,
|
||||
jobthread: &mut dc_jobthread_t,
|
||||
) {
|
||||
{
|
||||
jobthread.state.clone().0.lock().unwrap().jobs_needed = 1;
|
||||
}
|
||||
|
||||
dc_log_info(
|
||||
(*jobthread).context,
|
||||
0i32,
|
||||
context,
|
||||
0,
|
||||
b"Interrupting %s-IDLE...\x00" as *const u8 as *const libc::c_char,
|
||||
(*jobthread).name,
|
||||
jobthread.name,
|
||||
);
|
||||
if !(*jobthread).imap.is_null() {
|
||||
dc_imap_interrupt_idle((*jobthread).imap);
|
||||
}
|
||||
pthread_mutex_lock(&mut (*jobthread).mutex);
|
||||
(*jobthread).idle_condflag = 1i32;
|
||||
pthread_cond_signal(&mut (*jobthread).idle_cond);
|
||||
pthread_mutex_unlock(&mut (*jobthread).mutex);
|
||||
|
||||
println!("jobthread interrupt, waiting for lock");
|
||||
jobthread.imap.interrupt_idle();
|
||||
|
||||
let &(ref lock, ref cvar) = &*jobthread.state.clone();
|
||||
let mut state = lock.lock().unwrap();
|
||||
|
||||
state.idle = true;
|
||||
cvar.notify_one();
|
||||
}
|
||||
pub unsafe fn dc_jobthread_fetch(mut jobthread: *mut dc_jobthread_t, mut use_network: libc::c_int) {
|
||||
let mut start: libc::clock_t = 0;
|
||||
if jobthread.is_null() {
|
||||
return;
|
||||
|
||||
pub unsafe fn dc_jobthread_fetch(
|
||||
context: &dc_context_t,
|
||||
jobthread: &mut dc_jobthread_t,
|
||||
use_network: libc::c_int,
|
||||
) {
|
||||
let mut start;
|
||||
|
||||
{
|
||||
let &(ref lock, _) = &*jobthread.state.clone();
|
||||
let mut state = lock.lock().unwrap();
|
||||
|
||||
if 0 != state.suspended {
|
||||
return;
|
||||
}
|
||||
|
||||
state.using_handle = 1;
|
||||
}
|
||||
pthread_mutex_lock(&mut (*jobthread).mutex);
|
||||
if 0 != (*jobthread).suspended {
|
||||
pthread_mutex_unlock(&mut (*jobthread).mutex);
|
||||
return;
|
||||
}
|
||||
(*jobthread).using_handle = 1i32;
|
||||
pthread_mutex_unlock(&mut (*jobthread).mutex);
|
||||
if !(0 == use_network || (*jobthread).imap.is_null()) {
|
||||
|
||||
if !0 == use_network {
|
||||
start = clock();
|
||||
if !(0 == connect_to_imap(jobthread)) {
|
||||
if !(0 == connect_to_imap(context, jobthread)) {
|
||||
dc_log_info(
|
||||
(*jobthread).context,
|
||||
0i32,
|
||||
context,
|
||||
0,
|
||||
b"%s-fetch started...\x00" as *const u8 as *const libc::c_char,
|
||||
(*jobthread).name,
|
||||
jobthread.name,
|
||||
);
|
||||
dc_imap_fetch((*jobthread).imap);
|
||||
if 0 != (*(*jobthread).imap).should_reconnect {
|
||||
jobthread.imap.fetch(context);
|
||||
|
||||
if jobthread.imap.should_reconnect() {
|
||||
dc_log_info(
|
||||
(*jobthread).context,
|
||||
context,
|
||||
0i32,
|
||||
b"%s-fetch aborted, starting over...\x00" as *const u8 as *const libc::c_char,
|
||||
(*jobthread).name,
|
||||
jobthread.name,
|
||||
);
|
||||
dc_imap_fetch((*jobthread).imap);
|
||||
jobthread.imap.fetch(context);
|
||||
}
|
||||
dc_log_info(
|
||||
(*jobthread).context,
|
||||
0i32,
|
||||
context,
|
||||
0,
|
||||
b"%s-fetch done in %.0f ms.\x00" as *const u8 as *const libc::c_char,
|
||||
(*jobthread).name,
|
||||
jobthread.name,
|
||||
clock().wrapping_sub(start) as libc::c_double * 1000.0f64
|
||||
/ 1000000i32 as libc::c_double,
|
||||
);
|
||||
}
|
||||
}
|
||||
pthread_mutex_lock(&mut (*jobthread).mutex);
|
||||
(*jobthread).using_handle = 0i32;
|
||||
pthread_mutex_unlock(&mut (*jobthread).mutex);
|
||||
|
||||
jobthread.state.clone().0.lock().unwrap().using_handle = 0;
|
||||
}
|
||||
|
||||
/* ******************************************************************************
|
||||
* the typical fetch, idle, interrupt-idle
|
||||
******************************************************************************/
|
||||
unsafe fn connect_to_imap(mut jobthread: *mut dc_jobthread_t) -> libc::c_int {
|
||||
let mut ret_connected: libc::c_int = 0i32;
|
||||
|
||||
unsafe fn connect_to_imap(context: &dc_context_t, jobthread: &mut dc_jobthread_t) -> libc::c_int {
|
||||
let mut ret_connected: libc::c_int;
|
||||
let mut mvbox_name: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
if 0 != dc_imap_is_connected((*jobthread).imap) {
|
||||
ret_connected = 1i32
|
||||
|
||||
if jobthread.imap.is_connected() {
|
||||
ret_connected = 1
|
||||
} else {
|
||||
ret_connected = dc_connect_to_configured_imap((*jobthread).context, (*jobthread).imap);
|
||||
ret_connected = dc_connect_to_configured_imap(context, &jobthread.imap);
|
||||
if !(0 == ret_connected) {
|
||||
if dc_sqlite3_get_config_int(
|
||||
(*(*jobthread).context).sql,
|
||||
context,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
b"folders_configured\x00" as *const u8 as *const libc::c_char,
|
||||
0i32,
|
||||
) < 3i32
|
||||
0,
|
||||
) < 3
|
||||
{
|
||||
dc_configure_folders((*jobthread).context, (*jobthread).imap, 0x1i32);
|
||||
jobthread.imap.configure_folders(context, 0x1);
|
||||
}
|
||||
mvbox_name = dc_sqlite3_get_config(
|
||||
(*(*jobthread).context).sql,
|
||||
(*jobthread).folder_config_name,
|
||||
context,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
jobthread.folder_config_name,
|
||||
0 as *const libc::c_char,
|
||||
);
|
||||
if mvbox_name.is_null() {
|
||||
dc_imap_disconnect((*jobthread).imap);
|
||||
ret_connected = 0i32
|
||||
jobthread.imap.disconnect(context);
|
||||
ret_connected = 0;
|
||||
} else {
|
||||
dc_imap_set_watch_folder((*jobthread).imap, mvbox_name);
|
||||
jobthread.imap.set_watch_folder(mvbox_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
free(mvbox_name as *mut libc::c_void);
|
||||
return ret_connected;
|
||||
|
||||
ret_connected
|
||||
}
|
||||
pub unsafe fn dc_jobthread_idle(mut jobthread: *mut dc_jobthread_t, mut use_network: libc::c_int) {
|
||||
if jobthread.is_null() {
|
||||
return;
|
||||
}
|
||||
pthread_mutex_lock(&mut (*jobthread).mutex);
|
||||
if 0 != (*jobthread).jobs_needed {
|
||||
dc_log_info(
|
||||
(*jobthread).context,
|
||||
0i32,
|
||||
b"%s-IDLE will not be started as it was interrupted while not ideling.\x00" as *const u8
|
||||
as *const libc::c_char,
|
||||
(*jobthread).name,
|
||||
);
|
||||
(*jobthread).jobs_needed = 0i32;
|
||||
pthread_mutex_unlock(&mut (*jobthread).mutex);
|
||||
return;
|
||||
}
|
||||
if 0 != (*jobthread).suspended {
|
||||
while (*jobthread).idle_condflag == 0i32 {
|
||||
pthread_cond_wait(&mut (*jobthread).idle_cond, &mut (*jobthread).mutex);
|
||||
|
||||
pub unsafe fn dc_jobthread_idle(
|
||||
context: &dc_context_t,
|
||||
jobthread: &mut dc_jobthread_t,
|
||||
use_network: libc::c_int,
|
||||
) {
|
||||
{
|
||||
let &(ref lock, ref cvar) = &*jobthread.state.clone();
|
||||
let mut state = lock.lock().unwrap();
|
||||
|
||||
if 0 != state.jobs_needed {
|
||||
dc_log_info(
|
||||
context,
|
||||
0,
|
||||
b"%s-IDLE will not be started as it was interrupted while not ideling.\x00"
|
||||
as *const u8 as *const libc::c_char,
|
||||
jobthread.name,
|
||||
);
|
||||
state.jobs_needed = 0;
|
||||
return;
|
||||
}
|
||||
(*jobthread).idle_condflag = 0i32;
|
||||
pthread_mutex_unlock(&mut (*jobthread).mutex);
|
||||
return;
|
||||
}
|
||||
(*jobthread).using_handle = 1i32;
|
||||
pthread_mutex_unlock(&mut (*jobthread).mutex);
|
||||
if 0 == use_network || (*jobthread).imap.is_null() {
|
||||
pthread_mutex_lock(&mut (*jobthread).mutex);
|
||||
(*jobthread).using_handle = 0i32;
|
||||
while (*jobthread).idle_condflag == 0i32 {
|
||||
pthread_cond_wait(&mut (*jobthread).idle_cond, &mut (*jobthread).mutex);
|
||||
|
||||
if 0 != state.suspended {
|
||||
while !state.idle {
|
||||
state = cvar.wait(state).unwrap();
|
||||
}
|
||||
state.idle = false;
|
||||
return;
|
||||
}
|
||||
|
||||
state.using_handle = 1;
|
||||
|
||||
if 0 == use_network {
|
||||
state.using_handle = 0;
|
||||
|
||||
while !state.idle {
|
||||
state = cvar.wait(state).unwrap();
|
||||
}
|
||||
state.idle = false;
|
||||
return;
|
||||
}
|
||||
(*jobthread).idle_condflag = 0i32;
|
||||
pthread_mutex_unlock(&mut (*jobthread).mutex);
|
||||
return;
|
||||
}
|
||||
connect_to_imap(jobthread);
|
||||
|
||||
connect_to_imap(context, jobthread);
|
||||
dc_log_info(
|
||||
(*jobthread).context,
|
||||
context,
|
||||
0i32,
|
||||
b"%s-IDLE started...\x00" as *const u8 as *const libc::c_char,
|
||||
(*jobthread).name,
|
||||
jobthread.name,
|
||||
);
|
||||
dc_imap_idle((*jobthread).imap);
|
||||
jobthread.imap.idle(context);
|
||||
dc_log_info(
|
||||
(*jobthread).context,
|
||||
context,
|
||||
0i32,
|
||||
b"%s-IDLE ended.\x00" as *const u8 as *const libc::c_char,
|
||||
(*jobthread).name,
|
||||
jobthread.name,
|
||||
);
|
||||
pthread_mutex_lock(&mut (*jobthread).mutex);
|
||||
(*jobthread).using_handle = 0i32;
|
||||
pthread_mutex_unlock(&mut (*jobthread).mutex);
|
||||
|
||||
jobthread.state.clone().0.lock().unwrap().using_handle = 0;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
use libc;
|
||||
|
||||
use crate::types::*;
|
||||
|
||||
/*
|
||||
@@ -68,6 +66,7 @@ pub struct jsmn_parser {
|
||||
pub toknext: libc::c_uint,
|
||||
pub toksuper: libc::c_int,
|
||||
}
|
||||
|
||||
/* *
|
||||
* Create JSON parser over an array of tokens
|
||||
*/
|
||||
@@ -76,6 +75,7 @@ pub unsafe fn jsmn_init(mut parser: *mut jsmn_parser) {
|
||||
(*parser).toknext = 0i32 as libc::c_uint;
|
||||
(*parser).toksuper = -1i32;
|
||||
}
|
||||
|
||||
/* *
|
||||
* Run JSON parser. It parses a JSON data string into and array of tokens, each describing
|
||||
* a single JSON object.
|
||||
@@ -87,15 +87,15 @@ pub unsafe fn jsmn_parse(
|
||||
mut tokens: *mut jsmntok_t,
|
||||
mut num_tokens: libc::c_uint,
|
||||
) -> libc::c_int {
|
||||
let mut r: libc::c_int = 0;
|
||||
let mut i: libc::c_int = 0;
|
||||
let mut token: *mut jsmntok_t = 0 as *mut jsmntok_t;
|
||||
let mut r: libc::c_int;
|
||||
let mut i: libc::c_int;
|
||||
let mut token: *mut jsmntok_t;
|
||||
let mut count: libc::c_int = (*parser).toknext as libc::c_int;
|
||||
while (*parser).pos < len as libc::c_uint
|
||||
&& *js.offset((*parser).pos as isize) as libc::c_int != '\u{0}' as i32
|
||||
{
|
||||
let mut c: libc::c_char = 0;
|
||||
let mut type_0: jsmntype_t = JSMN_UNDEFINED;
|
||||
let mut c: libc::c_char;
|
||||
let mut type_0: jsmntype_t;
|
||||
c = *js.offset((*parser).pos as isize);
|
||||
match c as libc::c_int {
|
||||
123 | 91 => {
|
||||
@@ -222,8 +222,10 @@ pub unsafe fn jsmn_parse(
|
||||
i -= 1
|
||||
}
|
||||
}
|
||||
return count;
|
||||
|
||||
count
|
||||
}
|
||||
|
||||
/* *
|
||||
* Fills next available token with JSON primitive.
|
||||
*/
|
||||
@@ -234,8 +236,8 @@ unsafe fn jsmn_parse_primitive(
|
||||
mut tokens: *mut jsmntok_t,
|
||||
mut num_tokens: size_t,
|
||||
) -> libc::c_int {
|
||||
let mut token: *mut jsmntok_t = 0 as *mut jsmntok_t;
|
||||
let mut start: libc::c_int = 0;
|
||||
let mut token: *mut jsmntok_t;
|
||||
let mut start: libc::c_int;
|
||||
start = (*parser).pos as libc::c_int;
|
||||
while (*parser).pos < len as libc::c_uint
|
||||
&& *js.offset((*parser).pos as isize) as libc::c_int != '\u{0}' as i32
|
||||
@@ -265,8 +267,10 @@ unsafe fn jsmn_parse_primitive(
|
||||
}
|
||||
jsmn_fill_token(token, JSMN_PRIMITIVE, start, (*parser).pos as libc::c_int);
|
||||
(*parser).pos = (*parser).pos.wrapping_sub(1);
|
||||
return 0i32;
|
||||
|
||||
0
|
||||
}
|
||||
|
||||
/* *
|
||||
* Fills token type and boundaries.
|
||||
*/
|
||||
@@ -281,6 +285,7 @@ unsafe fn jsmn_fill_token(
|
||||
(*token).end = end;
|
||||
(*token).size = 0i32;
|
||||
}
|
||||
|
||||
/*
|
||||
Copyright (c) 2010 Serge A. Zaitsev
|
||||
|
||||
@@ -302,6 +307,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/* *
|
||||
* Allocates a fresh unused token from the token pool.
|
||||
*/
|
||||
@@ -310,7 +316,7 @@ unsafe fn jsmn_alloc_token(
|
||||
mut tokens: *mut jsmntok_t,
|
||||
mut num_tokens: size_t,
|
||||
) -> *mut jsmntok_t {
|
||||
let mut tok: *mut jsmntok_t = 0 as *mut jsmntok_t;
|
||||
let mut tok: *mut jsmntok_t;
|
||||
if (*parser).toknext as size_t >= num_tokens {
|
||||
return 0 as *mut jsmntok_t;
|
||||
}
|
||||
@@ -320,8 +326,10 @@ unsafe fn jsmn_alloc_token(
|
||||
(*tok).end = -1i32;
|
||||
(*tok).start = (*tok).end;
|
||||
(*tok).size = 0i32;
|
||||
return tok;
|
||||
|
||||
tok
|
||||
}
|
||||
|
||||
/* *
|
||||
* Fills next token with JSON string.
|
||||
*/
|
||||
@@ -332,7 +340,7 @@ unsafe fn jsmn_parse_string(
|
||||
mut tokens: *mut jsmntok_t,
|
||||
mut num_tokens: size_t,
|
||||
) -> libc::c_int {
|
||||
let mut token: *mut jsmntok_t = 0 as *mut jsmntok_t;
|
||||
let mut token: *mut jsmntok_t;
|
||||
let mut start: libc::c_int = (*parser).pos as libc::c_int;
|
||||
(*parser).pos = (*parser).pos.wrapping_add(1);
|
||||
while ((*parser).pos as size_t) < len
|
||||
@@ -357,7 +365,7 @@ unsafe fn jsmn_parse_string(
|
||||
return 0i32;
|
||||
}
|
||||
if c as libc::c_int == '\\' as i32 && ((*parser).pos.wrapping_add(1) as size_t) < len {
|
||||
let mut i: libc::c_int = 0;
|
||||
let mut i: libc::c_int;
|
||||
(*parser).pos = (*parser).pos.wrapping_add(1);
|
||||
match *js.offset((*parser).pos as isize) as libc::c_int {
|
||||
34 | 47 | 92 | 98 | 102 | 114 | 110 | 116 => {}
|
||||
@@ -392,5 +400,6 @@ unsafe fn jsmn_parse_string(
|
||||
(*parser).pos = (*parser).pos.wrapping_add(1)
|
||||
}
|
||||
(*parser).pos = start as libc::c_uint;
|
||||
return JSMN_ERROR_PART as libc::c_int;
|
||||
|
||||
JSMN_ERROR_PART as libc::c_int
|
||||
}
|
||||
|
||||
416
src/dc_key.rs
416
src/dc_key.rs
@@ -1,4 +1,15 @@
|
||||
use mmime::mailmime_content::*;
|
||||
use mmime::mmapstring::*;
|
||||
use mmime::other::*;
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
use std::ffi::CString;
|
||||
use std::io::Cursor;
|
||||
use std::slice;
|
||||
|
||||
use libc;
|
||||
use pgp::composed::{Deserializable, SignedPublicKey, SignedSecretKey};
|
||||
use pgp::ser::Serialize;
|
||||
|
||||
use crate::dc_context::dc_context_t;
|
||||
use crate::dc_log::*;
|
||||
@@ -8,9 +19,7 @@ use crate::dc_strbuilder::*;
|
||||
use crate::dc_tools::*;
|
||||
use crate::types::*;
|
||||
use crate::x::*;
|
||||
/* *
|
||||
* Library-internal.
|
||||
*/
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
#[repr(C)]
|
||||
pub struct dc_key_t {
|
||||
@@ -26,21 +35,25 @@ pub unsafe fn toupper(mut _c: libc::c_int) -> libc::c_int {
|
||||
}
|
||||
|
||||
pub unsafe fn dc_key_new() -> *mut dc_key_t {
|
||||
let mut key: *mut dc_key_t = 0 as *mut dc_key_t;
|
||||
let mut key: *mut dc_key_t;
|
||||
key = calloc(1, ::std::mem::size_of::<dc_key_t>()) as *mut dc_key_t;
|
||||
if key.is_null() {
|
||||
exit(44i32);
|
||||
}
|
||||
(*key)._m_heap_refcnt = 1i32;
|
||||
return key;
|
||||
|
||||
key
|
||||
}
|
||||
|
||||
pub unsafe fn dc_key_ref(mut key: *mut dc_key_t) -> *mut dc_key_t {
|
||||
if key.is_null() {
|
||||
return 0 as *mut dc_key_t;
|
||||
}
|
||||
(*key)._m_heap_refcnt += 1;
|
||||
return key;
|
||||
|
||||
key
|
||||
}
|
||||
|
||||
pub unsafe fn dc_key_unref(mut key: *mut dc_key_t) {
|
||||
if key.is_null() {
|
||||
return;
|
||||
@@ -52,6 +65,7 @@ pub unsafe fn dc_key_unref(mut key: *mut dc_key_t) {
|
||||
dc_key_empty(key);
|
||||
free(key as *mut libc::c_void);
|
||||
}
|
||||
|
||||
unsafe fn dc_key_empty(mut key: *mut dc_key_t) {
|
||||
if key.is_null() {
|
||||
return;
|
||||
@@ -64,12 +78,15 @@ unsafe fn dc_key_empty(mut key: *mut dc_key_t) {
|
||||
(*key).bytes = 0i32;
|
||||
(*key).type_0 = 0i32;
|
||||
}
|
||||
|
||||
pub unsafe fn dc_wipe_secret_mem(mut buf: *mut libc::c_void, mut buf_bytes: size_t) {
|
||||
if buf.is_null() || buf_bytes <= 0 {
|
||||
return;
|
||||
}
|
||||
memset(buf, 0i32, buf_bytes);
|
||||
}
|
||||
|
||||
// TODO should return bool /rtn
|
||||
pub unsafe fn dc_key_set_from_binary(
|
||||
mut key: *mut dc_key_t,
|
||||
mut data: *const libc::c_void,
|
||||
@@ -87,15 +104,20 @@ pub unsafe fn dc_key_set_from_binary(
|
||||
memcpy((*key).binary, data, bytes as size_t);
|
||||
(*key).bytes = bytes;
|
||||
(*key).type_0 = type_0;
|
||||
return 1i32;
|
||||
|
||||
1
|
||||
}
|
||||
|
||||
pub unsafe fn dc_key_set_from_key(mut key: *mut dc_key_t, mut o: *const dc_key_t) -> libc::c_int {
|
||||
dc_key_empty(key);
|
||||
if key.is_null() || o.is_null() {
|
||||
return 0i32;
|
||||
}
|
||||
return dc_key_set_from_binary(key, (*o).binary, (*o).bytes, (*o).type_0);
|
||||
|
||||
dc_key_set_from_binary(key, (*o).binary, (*o).bytes, (*o).type_0)
|
||||
}
|
||||
|
||||
// TODO should return bool /rtn
|
||||
pub unsafe extern "C" fn dc_key_set_from_stmt(
|
||||
mut key: *mut dc_key_t,
|
||||
mut stmt: *mut sqlite3_stmt,
|
||||
@@ -106,13 +128,16 @@ pub unsafe extern "C" fn dc_key_set_from_stmt(
|
||||
if key.is_null() || stmt.is_null() {
|
||||
return 0i32;
|
||||
}
|
||||
return dc_key_set_from_binary(
|
||||
|
||||
dc_key_set_from_binary(
|
||||
key,
|
||||
sqlite3_column_blob(stmt, index) as *mut libc::c_uchar as *const libc::c_void,
|
||||
sqlite3_column_bytes(stmt, index),
|
||||
type_0,
|
||||
);
|
||||
)
|
||||
}
|
||||
|
||||
// TODO should return bool /rtn
|
||||
pub unsafe fn dc_key_set_from_base64(
|
||||
mut key: *mut dc_key_t,
|
||||
mut base64: *const libc::c_char,
|
||||
@@ -144,90 +169,11 @@ pub unsafe fn dc_key_set_from_base64(
|
||||
type_0,
|
||||
);
|
||||
mmap_string_unref(result);
|
||||
return 1i32;
|
||||
}
|
||||
pub unsafe fn dc_key_set_from_file(
|
||||
mut key: *mut dc_key_t,
|
||||
mut pathNfilename: *const libc::c_char,
|
||||
mut context: *mut dc_context_t,
|
||||
) -> libc::c_int {
|
||||
let mut current_block: u64;
|
||||
let mut buf: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
// just pointer inside buf, must not be freed
|
||||
let mut headerline: *const libc::c_char = 0 as *const libc::c_char;
|
||||
// - " -
|
||||
let mut base64: *const libc::c_char = 0 as *const libc::c_char;
|
||||
let mut buf_bytes: size_t = 0i32 as size_t;
|
||||
let mut type_0: libc::c_int = -1i32;
|
||||
let mut success: libc::c_int = 0i32;
|
||||
dc_key_empty(key);
|
||||
if !(key.is_null() || pathNfilename.is_null()) {
|
||||
if !(0
|
||||
== dc_read_file(
|
||||
context,
|
||||
pathNfilename,
|
||||
&mut buf as *mut *mut libc::c_char as *mut *mut libc::c_void,
|
||||
&mut buf_bytes,
|
||||
)
|
||||
|| buf_bytes < 50)
|
||||
{
|
||||
/* error is already loged */
|
||||
if !(0
|
||||
== dc_split_armored_data(
|
||||
buf,
|
||||
&mut headerline,
|
||||
0 as *mut *const libc::c_char,
|
||||
0 as *mut *const libc::c_char,
|
||||
&mut base64,
|
||||
)
|
||||
|| headerline.is_null()
|
||||
|| base64.is_null())
|
||||
{
|
||||
if strcmp(
|
||||
headerline,
|
||||
b"-----BEGIN PGP PUBLIC KEY BLOCK-----\x00" as *const u8 as *const libc::c_char,
|
||||
) == 0i32
|
||||
{
|
||||
type_0 = 0i32;
|
||||
current_block = 7149356873433890176;
|
||||
} else if strcmp(
|
||||
headerline,
|
||||
b"-----BEGIN PGP PRIVATE KEY BLOCK-----\x00" as *const u8
|
||||
as *const libc::c_char,
|
||||
) == 0i32
|
||||
{
|
||||
type_0 = 1i32;
|
||||
current_block = 7149356873433890176;
|
||||
} else {
|
||||
dc_log_warning(
|
||||
context,
|
||||
0i32,
|
||||
b"Header missing for key \"%s\".\x00" as *const u8 as *const libc::c_char,
|
||||
pathNfilename,
|
||||
);
|
||||
current_block = 7704194852291245876;
|
||||
}
|
||||
match current_block {
|
||||
7704194852291245876 => {}
|
||||
_ => {
|
||||
if 0 == dc_key_set_from_base64(key, base64, type_0) {
|
||||
dc_log_warning(
|
||||
context,
|
||||
0i32,
|
||||
b"Bad data in key \"%s\".\x00" as *const u8 as *const libc::c_char,
|
||||
pathNfilename,
|
||||
);
|
||||
} else {
|
||||
success = 1i32
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
free(buf as *mut libc::c_void);
|
||||
return success;
|
||||
|
||||
1
|
||||
}
|
||||
|
||||
// TODO should return bool /rtn
|
||||
pub unsafe fn dc_key_equals(mut key: *const dc_key_t, mut o: *const dc_key_t) -> libc::c_int {
|
||||
if key.is_null()
|
||||
|| o.is_null()
|
||||
@@ -251,25 +197,29 @@ pub unsafe fn dc_key_equals(mut key: *const dc_key_t, mut o: *const dc_key_t) ->
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
// TODO should return bool /rtn
|
||||
pub unsafe fn dc_key_save_self_keypair(
|
||||
mut public_key: *const dc_key_t,
|
||||
mut private_key: *const dc_key_t,
|
||||
mut addr: *const libc::c_char,
|
||||
mut is_default: libc::c_int,
|
||||
mut sql: *mut dc_sqlite3_t,
|
||||
context: &dc_context_t,
|
||||
public_key: *const dc_key_t,
|
||||
private_key: *const dc_key_t,
|
||||
addr: *const libc::c_char,
|
||||
is_default: libc::c_int,
|
||||
sql: &dc_sqlite3_t,
|
||||
) -> libc::c_int {
|
||||
let mut success: libc::c_int = 0i32;
|
||||
let mut stmt: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt;
|
||||
if !(public_key.is_null()
|
||||
|| private_key.is_null()
|
||||
|| addr.is_null()
|
||||
|| sql.is_null()
|
||||
|| (*public_key).binary.is_null()
|
||||
|| (*private_key).binary.is_null())
|
||||
{
|
||||
stmt =
|
||||
dc_sqlite3_prepare(sql,
|
||||
b"INSERT INTO keypairs (addr, is_default, public_key, private_key, created) VALUES (?,?,?,?,?);\x00"
|
||||
dc_sqlite3_prepare(
|
||||
context,
|
||||
sql,
|
||||
b"INSERT INTO keypairs (addr, is_default, public_key, private_key, created) VALUES (?,?,?,?,?);\x00"
|
||||
as *const u8 as *const libc::c_char);
|
||||
sqlite3_bind_text(stmt, 1i32, addr, -1i32, None);
|
||||
sqlite3_bind_int(stmt, 2i32, is_default);
|
||||
@@ -287,18 +237,23 @@ pub unsafe fn dc_key_save_self_keypair(
|
||||
}
|
||||
}
|
||||
sqlite3_finalize(stmt);
|
||||
return success;
|
||||
|
||||
success
|
||||
}
|
||||
|
||||
// TODO should return bool /rtn
|
||||
pub unsafe fn dc_key_load_self_public(
|
||||
mut key: *mut dc_key_t,
|
||||
mut self_addr: *const libc::c_char,
|
||||
mut sql: *mut dc_sqlite3_t,
|
||||
context: &dc_context_t,
|
||||
key: *mut dc_key_t,
|
||||
self_addr: *const libc::c_char,
|
||||
sql: &dc_sqlite3_t,
|
||||
) -> libc::c_int {
|
||||
let mut success: libc::c_int = 0i32;
|
||||
let mut stmt: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt;
|
||||
if !(key.is_null() || self_addr.is_null() || sql.is_null()) {
|
||||
if !(key.is_null() || self_addr.is_null()) {
|
||||
dc_key_empty(key);
|
||||
stmt = dc_sqlite3_prepare(
|
||||
context,
|
||||
sql,
|
||||
b"SELECT public_key FROM keypairs WHERE addr=? AND is_default=1;\x00" as *const u8
|
||||
as *const libc::c_char,
|
||||
@@ -310,18 +265,23 @@ pub unsafe fn dc_key_load_self_public(
|
||||
}
|
||||
}
|
||||
sqlite3_finalize(stmt);
|
||||
return success;
|
||||
|
||||
success
|
||||
}
|
||||
|
||||
// TODO should return bool /rtn
|
||||
pub unsafe fn dc_key_load_self_private(
|
||||
mut key: *mut dc_key_t,
|
||||
mut self_addr: *const libc::c_char,
|
||||
mut sql: *mut dc_sqlite3_t,
|
||||
context: &dc_context_t,
|
||||
key: *mut dc_key_t,
|
||||
self_addr: *const libc::c_char,
|
||||
sql: &dc_sqlite3_t,
|
||||
) -> libc::c_int {
|
||||
let mut success: libc::c_int = 0i32;
|
||||
let mut stmt: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt;
|
||||
if !(key.is_null() || self_addr.is_null() || sql.is_null()) {
|
||||
if !(key.is_null() || self_addr.is_null()) {
|
||||
dc_key_empty(key);
|
||||
stmt = dc_sqlite3_prepare(
|
||||
context,
|
||||
sql,
|
||||
b"SELECT private_key FROM keypairs WHERE addr=? AND is_default=1;\x00" as *const u8
|
||||
as *const libc::c_char,
|
||||
@@ -329,148 +289,98 @@ pub unsafe fn dc_key_load_self_private(
|
||||
sqlite3_bind_text(stmt, 1i32, self_addr, -1i32, None);
|
||||
if !(sqlite3_step(stmt) != 100i32) {
|
||||
dc_key_set_from_stmt(key, stmt, 0i32, 1i32);
|
||||
success = 1i32
|
||||
success = 1i32;
|
||||
}
|
||||
}
|
||||
sqlite3_finalize(stmt);
|
||||
return success;
|
||||
|
||||
success
|
||||
}
|
||||
|
||||
/* the result must be freed */
|
||||
pub unsafe fn dc_render_base64(
|
||||
mut buf: *const libc::c_void,
|
||||
mut buf_bytes: size_t,
|
||||
mut break_every: libc::c_int,
|
||||
mut break_chars: *const libc::c_char,
|
||||
mut add_checksum: libc::c_int,
|
||||
) -> *mut libc::c_char {
|
||||
let mut ret: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
if !(buf == 0 as *mut libc::c_void || buf_bytes <= 0) {
|
||||
ret = encode_base64(buf as *const libc::c_char, buf_bytes as libc::c_int);
|
||||
if !ret.is_null() {
|
||||
if break_every > 0i32 {
|
||||
let mut temp: *mut libc::c_char = ret;
|
||||
ret = dc_insert_breaks(temp, break_every, break_chars);
|
||||
free(temp as *mut libc::c_void);
|
||||
}
|
||||
if add_checksum == 2i32 {
|
||||
let mut checksum: libc::c_long = crc_octets(buf as *const libc::c_uchar, buf_bytes);
|
||||
let mut c: [uint8_t; 3] = [0; 3];
|
||||
c[0usize] = (checksum >> 16i32 & 0xffi32 as libc::c_long) as uint8_t;
|
||||
c[1usize] = (checksum >> 8i32 & 0xffi32 as libc::c_long) as uint8_t;
|
||||
c[2usize] = (checksum & 0xffi32 as libc::c_long) as uint8_t;
|
||||
let mut c64: *mut libc::c_char =
|
||||
encode_base64(c.as_mut_ptr() as *const libc::c_char, 3i32);
|
||||
let mut temp_0: *mut libc::c_char = ret;
|
||||
ret = dc_mprintf(
|
||||
b"%s%s=%s\x00" as *const u8 as *const libc::c_char,
|
||||
temp_0,
|
||||
break_chars,
|
||||
c64,
|
||||
);
|
||||
free(temp_0 as *mut libc::c_void);
|
||||
free(c64 as *mut libc::c_void);
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
/* ******************************************************************************
|
||||
* Render keys
|
||||
******************************************************************************/
|
||||
unsafe fn crc_octets(mut octets: *const libc::c_uchar, mut len: size_t) -> libc::c_long {
|
||||
let mut crc: libc::c_long = 0xb704ce;
|
||||
loop {
|
||||
let fresh0 = len;
|
||||
len = len.wrapping_sub(1);
|
||||
if !(0 != fresh0) {
|
||||
break;
|
||||
}
|
||||
let fresh1 = octets;
|
||||
octets = octets.offset(1);
|
||||
crc ^= ((*fresh1 as libc::c_int) << 16i32) as libc::c_long;
|
||||
let mut i: libc::c_int = 0i32;
|
||||
while i < 8i32 {
|
||||
crc <<= 1i32;
|
||||
if 0 != crc & 0x1000000 as libc::c_long {
|
||||
crc ^= 0x1864cfb
|
||||
}
|
||||
i += 1
|
||||
}
|
||||
}
|
||||
return crc & 0xffffff;
|
||||
}
|
||||
/* the result must be freed */
|
||||
pub unsafe fn dc_key_render_base64(
|
||||
mut key: *const dc_key_t,
|
||||
mut break_every: libc::c_int,
|
||||
mut break_chars: *const libc::c_char,
|
||||
mut add_checksum: libc::c_int,
|
||||
) -> *mut libc::c_char {
|
||||
pub fn dc_key_render_base64(key: *const dc_key_t, break_every: usize) -> *mut libc::c_char {
|
||||
if key.is_null() {
|
||||
return 0 as *mut libc::c_char;
|
||||
return std::ptr::null_mut();
|
||||
}
|
||||
return dc_render_base64(
|
||||
(*key).binary,
|
||||
(*key).bytes as size_t,
|
||||
break_every,
|
||||
break_chars,
|
||||
add_checksum,
|
||||
);
|
||||
|
||||
let key = unsafe { *key };
|
||||
let bytes = unsafe { slice::from_raw_parts(key.binary as *const u8, key.bytes as usize) };
|
||||
assert_eq!(bytes.len(), key.bytes as usize);
|
||||
|
||||
let buf = if key.type_0 == 0 {
|
||||
// public key
|
||||
let skey = SignedPublicKey::from_bytes(Cursor::new(bytes)).expect("invalid pub key");
|
||||
skey.to_bytes().expect("failed to serialize key")
|
||||
} else {
|
||||
// secret key
|
||||
let skey = SignedSecretKey::from_bytes(Cursor::new(bytes)).expect("invalid sec key");
|
||||
skey.to_bytes().expect("failed to serialize key")
|
||||
};
|
||||
|
||||
let encoded = base64::encode(&buf);
|
||||
let res = encoded
|
||||
.as_bytes()
|
||||
.chunks(break_every)
|
||||
.fold(String::new(), |mut res, buf| {
|
||||
// safe because we are using a base64 encoded string
|
||||
res += unsafe { std::str::from_utf8_unchecked(buf) };
|
||||
res += " ";
|
||||
res
|
||||
});
|
||||
|
||||
let res_c = CString::new(res.trim()).unwrap();
|
||||
|
||||
// need to use strdup to allocate the result with malloc
|
||||
// so it can be `free`d later.
|
||||
unsafe { libc::strdup(res_c.as_ptr()) }
|
||||
}
|
||||
/* each header line must be terminated by \r\n, the result must be freed */
|
||||
pub unsafe fn dc_key_render_asc(
|
||||
mut key: *const dc_key_t,
|
||||
mut add_header_lines: *const libc::c_char,
|
||||
) -> *mut libc::c_char {
|
||||
/* see RFC 4880, 6.2. Forming ASCII Armor, https://tools.ietf.org/html/rfc4880#section-6.2 */
|
||||
let mut base64: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut ret: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
if !key.is_null() {
|
||||
base64 = dc_key_render_base64(
|
||||
key,
|
||||
76i32,
|
||||
b"\r\n\x00" as *const u8 as *const libc::c_char,
|
||||
2i32,
|
||||
);
|
||||
if !base64.is_null() {
|
||||
/*checksum in new line*/
|
||||
/* RFC: The encoded output stream must be represented in lines of no more than 76 characters each. */
|
||||
ret =
|
||||
dc_mprintf(b"-----BEGIN PGP %s KEY BLOCK-----\r\n%s\r\n%s\r\n-----END PGP %s KEY BLOCK-----\r\n\x00"
|
||||
as *const u8 as *const libc::c_char,
|
||||
if (*key).type_0 == 0i32 {
|
||||
b"PUBLIC\x00" as *const u8 as
|
||||
*const libc::c_char
|
||||
} else {
|
||||
b"PRIVATE\x00" as *const u8 as
|
||||
*const libc::c_char
|
||||
},
|
||||
if !add_header_lines.is_null() {
|
||||
add_header_lines
|
||||
} else {
|
||||
b"\x00" as *const u8 as *const libc::c_char
|
||||
}, base64,
|
||||
if (*key).type_0 == 0i32 {
|
||||
b"PUBLIC\x00" as *const u8 as
|
||||
*const libc::c_char
|
||||
} else {
|
||||
b"PRIVATE\x00" as *const u8 as
|
||||
*const libc::c_char
|
||||
})
|
||||
}
|
||||
|
||||
/// each header line must be terminated by `\r\n`, the result must be freed.
|
||||
pub fn dc_key_render_asc(key: *const dc_key_t, header: Option<(&str, &str)>) -> *mut libc::c_char {
|
||||
if key.is_null() {
|
||||
return std::ptr::null_mut();
|
||||
}
|
||||
free(base64 as *mut libc::c_void);
|
||||
return ret;
|
||||
|
||||
let key = unsafe { *key };
|
||||
|
||||
let headers = header.map(|(key, value)| {
|
||||
let mut m = BTreeMap::new();
|
||||
m.insert(key.to_string(), value.to_string());
|
||||
m
|
||||
});
|
||||
|
||||
let bytes = unsafe { slice::from_raw_parts(key.binary as *const u8, key.bytes as usize) };
|
||||
|
||||
let buf = if key.type_0 == 0 {
|
||||
// public key
|
||||
let skey = SignedPublicKey::from_bytes(Cursor::new(bytes)).expect("invalid key");
|
||||
skey.to_armored_string(headers.as_ref())
|
||||
.expect("failed to serialize key")
|
||||
} else {
|
||||
// secret key
|
||||
let skey = SignedSecretKey::from_bytes(Cursor::new(bytes)).expect("invalid key");
|
||||
skey.to_armored_string(headers.as_ref())
|
||||
.expect("failed to serialize key")
|
||||
};
|
||||
|
||||
let buf_c = CString::new(buf).unwrap();
|
||||
|
||||
// need to use strdup to allocate the result with malloc
|
||||
// so it can be `free`d later.
|
||||
unsafe { libc::strdup(buf_c.as_ptr()) }
|
||||
}
|
||||
|
||||
pub unsafe fn dc_key_render_asc_to_file(
|
||||
mut key: *const dc_key_t,
|
||||
mut file: *const libc::c_char,
|
||||
mut context: *mut dc_context_t,
|
||||
mut context: &dc_context_t,
|
||||
) -> libc::c_int {
|
||||
let mut success: libc::c_int = 0i32;
|
||||
let mut file_content: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
if !(key.is_null() || file.is_null() || context.is_null()) {
|
||||
file_content = dc_key_render_asc(key, 0 as *const libc::c_char);
|
||||
|
||||
if !(key.is_null() || file.is_null()) {
|
||||
file_content = dc_key_render_asc(key, None);
|
||||
|
||||
if !file_content.is_null() {
|
||||
if 0 == dc_write_file(
|
||||
context,
|
||||
@@ -490,8 +400,10 @@ pub unsafe fn dc_key_render_asc_to_file(
|
||||
}
|
||||
}
|
||||
free(file_content as *mut libc::c_void);
|
||||
return success;
|
||||
|
||||
success
|
||||
}
|
||||
|
||||
pub unsafe fn dc_format_fingerprint(mut fingerprint: *const libc::c_char) -> *mut libc::c_char {
|
||||
let mut i: libc::c_int = 0i32;
|
||||
let mut fingerprint_len: libc::c_int = strlen(fingerprint) as libc::c_int;
|
||||
@@ -517,8 +429,10 @@ pub unsafe fn dc_format_fingerprint(mut fingerprint: *const libc::c_char) -> *mu
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret.buf;
|
||||
|
||||
ret.buf
|
||||
}
|
||||
|
||||
pub unsafe fn dc_normalize_fingerprint(mut in_0: *const libc::c_char) -> *mut libc::c_char {
|
||||
if in_0.is_null() {
|
||||
return 0 as *mut libc::c_char;
|
||||
@@ -544,14 +458,21 @@ pub unsafe fn dc_normalize_fingerprint(mut in_0: *const libc::c_char) -> *mut li
|
||||
}
|
||||
p1 = p1.offset(1isize)
|
||||
}
|
||||
return out.buf;
|
||||
|
||||
out.buf
|
||||
}
|
||||
pub unsafe fn dc_key_get_fingerprint(mut key: *const dc_key_t) -> *mut libc::c_char {
|
||||
|
||||
pub unsafe fn dc_key_get_fingerprint(
|
||||
context: &dc_context_t,
|
||||
key: *const dc_key_t,
|
||||
) -> *mut libc::c_char {
|
||||
let mut fingerprint_buf: *mut uint8_t = 0 as *mut uint8_t;
|
||||
let mut fingerprint_bytes: size_t = 0i32 as size_t;
|
||||
let mut fingerprint_hex: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
if !key.is_null() {
|
||||
if !(0 == dc_pgp_calc_fingerprint(key, &mut fingerprint_buf, &mut fingerprint_bytes)) {
|
||||
if !(0
|
||||
== dc_pgp_calc_fingerprint(context, key, &mut fingerprint_buf, &mut fingerprint_bytes))
|
||||
{
|
||||
fingerprint_hex = dc_binary_to_uc_hex(fingerprint_buf, fingerprint_bytes)
|
||||
}
|
||||
}
|
||||
@@ -562,9 +483,14 @@ pub unsafe fn dc_key_get_fingerprint(mut key: *const dc_key_t) -> *mut libc::c_c
|
||||
dc_strdup(0 as *const libc::c_char)
|
||||
};
|
||||
}
|
||||
pub unsafe fn dc_key_get_formatted_fingerprint(mut key: *const dc_key_t) -> *mut libc::c_char {
|
||||
let mut rawhex: *mut libc::c_char = dc_key_get_fingerprint(key);
|
||||
|
||||
pub unsafe fn dc_key_get_formatted_fingerprint(
|
||||
context: &dc_context_t,
|
||||
key: *const dc_key_t,
|
||||
) -> *mut libc::c_char {
|
||||
let mut rawhex: *mut libc::c_char = dc_key_get_fingerprint(context, key);
|
||||
let mut formatted: *mut libc::c_char = dc_format_fingerprint(rawhex);
|
||||
free(rawhex as *mut libc::c_void);
|
||||
return formatted;
|
||||
|
||||
formatted
|
||||
}
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
use libc;
|
||||
|
||||
use crate::dc_context::dc_context_t;
|
||||
use crate::types::*;
|
||||
|
||||
/* yes: uppercase */
|
||||
/* library private: key-history */
|
||||
pub unsafe fn dc_add_to_keyhistory(
|
||||
_context: *mut dc_context_t,
|
||||
pub fn dc_add_to_keyhistory(
|
||||
_context: &dc_context_t,
|
||||
_rfc724_mid: *const libc::c_char,
|
||||
_sending_time: time_t,
|
||||
_addr: *const libc::c_char,
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
use libc;
|
||||
|
||||
use crate::dc_context::dc_context_t;
|
||||
use crate::dc_key::*;
|
||||
use crate::dc_sqlite3::*;
|
||||
use crate::types::*;
|
||||
@@ -14,13 +13,15 @@ pub struct dc_keyring_t {
|
||||
}
|
||||
|
||||
pub unsafe fn dc_keyring_new() -> *mut dc_keyring_t {
|
||||
let mut keyring: *mut dc_keyring_t = 0 as *mut dc_keyring_t;
|
||||
let mut keyring: *mut dc_keyring_t;
|
||||
keyring = calloc(1, ::std::mem::size_of::<dc_keyring_t>()) as *mut dc_keyring_t;
|
||||
if keyring.is_null() {
|
||||
exit(42i32);
|
||||
}
|
||||
return keyring;
|
||||
|
||||
keyring
|
||||
}
|
||||
|
||||
pub unsafe fn dc_keyring_unref(mut keyring: *mut dc_keyring_t) {
|
||||
if keyring.is_null() {
|
||||
return;
|
||||
@@ -33,6 +34,7 @@ pub unsafe fn dc_keyring_unref(mut keyring: *mut dc_keyring_t) {
|
||||
free((*keyring).keys as *mut libc::c_void);
|
||||
free(keyring as *mut libc::c_void);
|
||||
}
|
||||
|
||||
/* the reference counter of the key is increased by one */
|
||||
pub unsafe fn dc_keyring_add(mut keyring: *mut dc_keyring_t, mut to_add: *mut dc_key_t) {
|
||||
if keyring.is_null() || to_add.is_null() {
|
||||
@@ -53,15 +55,20 @@ pub unsafe fn dc_keyring_add(mut keyring: *mut dc_keyring_t, mut to_add: *mut dc
|
||||
*fresh0 = dc_key_ref(to_add);
|
||||
(*keyring).count += 1;
|
||||
}
|
||||
|
||||
// TODO should return bool? /rtn
|
||||
pub unsafe fn dc_keyring_load_self_private_for_decrypting(
|
||||
mut keyring: *mut dc_keyring_t,
|
||||
mut self_addr: *const libc::c_char,
|
||||
mut sql: *mut dc_sqlite3_t,
|
||||
context: &dc_context_t,
|
||||
keyring: *mut dc_keyring_t,
|
||||
self_addr: *const libc::c_char,
|
||||
sql: &dc_sqlite3_t,
|
||||
) -> libc::c_int {
|
||||
if keyring.is_null() || self_addr.is_null() || sql.is_null() {
|
||||
// Can we prevent keyring and self_addr to be null?
|
||||
if keyring.is_null() || self_addr.is_null() {
|
||||
return 0i32;
|
||||
}
|
||||
let mut stmt: *mut sqlite3_stmt = dc_sqlite3_prepare(
|
||||
context,
|
||||
sql,
|
||||
b"SELECT private_key FROM keypairs ORDER BY addr=? DESC, is_default DESC;\x00" as *const u8
|
||||
as *const libc::c_char,
|
||||
@@ -75,5 +82,6 @@ pub unsafe fn dc_keyring_load_self_private_for_decrypting(
|
||||
dc_key_unref(key);
|
||||
}
|
||||
sqlite3_finalize(stmt);
|
||||
return 1i32;
|
||||
|
||||
1
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
use libc;
|
||||
|
||||
use crate::constants::Event;
|
||||
use crate::dc_array::*;
|
||||
use crate::dc_chat::*;
|
||||
@@ -42,7 +40,7 @@ pub struct dc_kml_t {
|
||||
|
||||
// location streaming
|
||||
pub unsafe fn dc_send_locations_to_chat(
|
||||
mut context: *mut dc_context_t,
|
||||
mut context: &dc_context_t,
|
||||
mut chat_id: uint32_t,
|
||||
mut seconds: libc::c_int,
|
||||
) {
|
||||
@@ -50,17 +48,15 @@ pub unsafe fn dc_send_locations_to_chat(
|
||||
let mut now: time_t = time(0 as *mut time_t);
|
||||
let mut msg: *mut dc_msg_t = 0 as *mut dc_msg_t;
|
||||
let mut stock_str: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut is_sending_locations_before: libc::c_int = 0i32;
|
||||
if !(context.is_null()
|
||||
|| (*context).magic != 0x11a11807i32 as libc::c_uint
|
||||
|| seconds < 0i32
|
||||
|| chat_id <= 9i32 as libc::c_uint)
|
||||
{
|
||||
let mut is_sending_locations_before: libc::c_int;
|
||||
if !(seconds < 0i32 || chat_id <= 9i32 as libc::c_uint) {
|
||||
is_sending_locations_before = dc_is_sending_locations_to_chat(context, chat_id);
|
||||
stmt =
|
||||
dc_sqlite3_prepare((*context).sql,
|
||||
b"UPDATE chats SET locations_send_begin=?, locations_send_until=? WHERE id=?\x00"
|
||||
as *const u8 as *const libc::c_char);
|
||||
dc_sqlite3_prepare(
|
||||
context,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
b"UPDATE chats SET locations_send_begin=?, locations_send_until=? WHERE id=?\x00"
|
||||
as *const u8 as *const libc::c_char);
|
||||
sqlite3_bind_int64(
|
||||
stmt,
|
||||
1i32,
|
||||
@@ -102,7 +98,7 @@ pub unsafe fn dc_send_locations_to_chat(
|
||||
);
|
||||
dc_add_device_msg(context, chat_id, stock_str);
|
||||
}
|
||||
((*context).cb)(
|
||||
(context.cb)(
|
||||
context,
|
||||
Event::CHAT_MODIFIED,
|
||||
chat_id as uintptr_t,
|
||||
@@ -123,46 +119,51 @@ pub unsafe fn dc_send_locations_to_chat(
|
||||
dc_msg_unref(msg);
|
||||
sqlite3_finalize(stmt);
|
||||
}
|
||||
/* ******************************************************************************
|
||||
|
||||
/*******************************************************************************
|
||||
* job to send locations out to all chats that want them
|
||||
******************************************************************************/
|
||||
unsafe fn schedule_MAYBE_SEND_LOCATIONS(mut context: *mut dc_context_t, mut flags: libc::c_int) {
|
||||
unsafe fn schedule_MAYBE_SEND_LOCATIONS(mut context: &dc_context_t, mut flags: libc::c_int) {
|
||||
if 0 != flags & 0x1i32 || 0 == dc_job_action_exists(context, 5005i32) {
|
||||
dc_job_add(context, 5005i32, 0i32, 0 as *const libc::c_char, 60i32);
|
||||
};
|
||||
}
|
||||
|
||||
pub unsafe extern "C" fn dc_is_sending_locations_to_chat(
|
||||
mut context: *mut dc_context_t,
|
||||
mut context: &dc_context_t,
|
||||
mut chat_id: uint32_t,
|
||||
) -> libc::c_int {
|
||||
let mut is_sending_locations: libc::c_int = 0i32;
|
||||
let mut stmt: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt;
|
||||
if !(context.is_null() || (*context).magic != 0x11a11807i32 as libc::c_uint) {
|
||||
stmt = dc_sqlite3_prepare(
|
||||
(*context).sql,
|
||||
b"SELECT id FROM chats WHERE (? OR id=?) AND locations_send_until>?;\x00"
|
||||
as *const u8 as *const libc::c_char,
|
||||
);
|
||||
sqlite3_bind_int(
|
||||
stmt,
|
||||
1i32,
|
||||
if chat_id == 0i32 as libc::c_uint {
|
||||
1i32
|
||||
} else {
|
||||
0i32
|
||||
},
|
||||
);
|
||||
sqlite3_bind_int(stmt, 2i32, chat_id as libc::c_int);
|
||||
sqlite3_bind_int64(stmt, 3i32, time(0 as *mut time_t) as sqlite3_int64);
|
||||
if !(sqlite3_step(stmt) != 100i32) {
|
||||
is_sending_locations = 1i32
|
||||
}
|
||||
let mut stmt: *mut sqlite3_stmt;
|
||||
|
||||
stmt = dc_sqlite3_prepare(
|
||||
context,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
b"SELECT id FROM chats WHERE (? OR id=?) AND locations_send_until>?;\x00" as *const u8
|
||||
as *const libc::c_char,
|
||||
);
|
||||
sqlite3_bind_int(
|
||||
stmt,
|
||||
1i32,
|
||||
if chat_id == 0i32 as libc::c_uint {
|
||||
1i32
|
||||
} else {
|
||||
0i32
|
||||
},
|
||||
);
|
||||
sqlite3_bind_int(stmt, 2i32, chat_id as libc::c_int);
|
||||
sqlite3_bind_int64(stmt, 3i32, time(0 as *mut time_t) as sqlite3_int64);
|
||||
if !(sqlite3_step(stmt) != 100i32) {
|
||||
is_sending_locations = 1i32
|
||||
}
|
||||
|
||||
sqlite3_finalize(stmt);
|
||||
return is_sending_locations;
|
||||
|
||||
is_sending_locations
|
||||
}
|
||||
|
||||
pub unsafe fn dc_set_location(
|
||||
mut context: *mut dc_context_t,
|
||||
mut context: &dc_context_t,
|
||||
mut latitude: libc::c_double,
|
||||
mut longitude: libc::c_double,
|
||||
mut accuracy: libc::c_double,
|
||||
@@ -170,14 +171,12 @@ pub unsafe fn dc_set_location(
|
||||
let mut stmt_chats: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt;
|
||||
let mut stmt_insert: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt;
|
||||
let mut continue_streaming: libc::c_int = 0i32;
|
||||
if context.is_null()
|
||||
|| (*context).magic != 0x11a11807i32 as libc::c_uint
|
||||
|| latitude == 0.0f64 && longitude == 0.0f64
|
||||
{
|
||||
if latitude == 0.0f64 && longitude == 0.0f64 {
|
||||
continue_streaming = 1i32
|
||||
} else {
|
||||
stmt_chats = dc_sqlite3_prepare(
|
||||
(*context).sql,
|
||||
context,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
b"SELECT id FROM chats WHERE locations_send_until>?;\x00" as *const u8
|
||||
as *const libc::c_char,
|
||||
);
|
||||
@@ -185,9 +184,11 @@ pub unsafe fn dc_set_location(
|
||||
while sqlite3_step(stmt_chats) == 100i32 {
|
||||
let mut chat_id: uint32_t = sqlite3_column_int(stmt_chats, 0i32) as uint32_t;
|
||||
stmt_insert =
|
||||
dc_sqlite3_prepare((*context).sql,
|
||||
b"INSERT INTO locations (latitude, longitude, accuracy, timestamp, chat_id, from_id) VALUES (?,?,?,?,?,?);\x00"
|
||||
as *const u8 as *const libc::c_char);
|
||||
dc_sqlite3_prepare(
|
||||
context,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
b"INSERT INTO locations (latitude, longitude, accuracy, timestamp, chat_id, from_id) VALUES (?,?,?,?,?,?);\x00"
|
||||
as *const u8 as *const libc::c_char);
|
||||
sqlite3_bind_double(stmt_insert, 1i32, latitude);
|
||||
sqlite3_bind_double(stmt_insert, 2i32, longitude);
|
||||
sqlite3_bind_double(stmt_insert, 3i32, accuracy);
|
||||
@@ -198,7 +199,7 @@ pub unsafe fn dc_set_location(
|
||||
continue_streaming = 1i32
|
||||
}
|
||||
if 0 != continue_streaming {
|
||||
((*context).cb)(
|
||||
(context.cb)(
|
||||
context,
|
||||
Event::LOCATION_CHANGED,
|
||||
1i32 as uintptr_t,
|
||||
@@ -209,82 +210,88 @@ pub unsafe fn dc_set_location(
|
||||
}
|
||||
sqlite3_finalize(stmt_chats);
|
||||
sqlite3_finalize(stmt_insert);
|
||||
return continue_streaming;
|
||||
|
||||
continue_streaming
|
||||
}
|
||||
|
||||
pub unsafe fn dc_get_locations(
|
||||
mut context: *mut dc_context_t,
|
||||
mut context: &dc_context_t,
|
||||
mut chat_id: uint32_t,
|
||||
mut contact_id: uint32_t,
|
||||
mut timestamp_from: time_t,
|
||||
mut timestamp_to: time_t,
|
||||
) -> *mut dc_array_t {
|
||||
let mut ret: *mut dc_array_t = dc_array_new_typed(context, 1i32, 500i32 as size_t);
|
||||
let mut stmt: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt;
|
||||
if !(context.is_null() || (*context).magic != 0x11a11807i32 as libc::c_uint) {
|
||||
if timestamp_to == 0i32 as libc::c_long {
|
||||
timestamp_to = time(0 as *mut time_t) + 10i32 as libc::c_long
|
||||
}
|
||||
stmt = dc_sqlite3_prepare(
|
||||
(*context).sql,
|
||||
b"SELECT l.id, l.latitude, l.longitude, l.accuracy, l.timestamp, l.independent \
|
||||
let mut ret: *mut dc_array_t = dc_array_new_typed(1i32, 500i32 as size_t);
|
||||
let mut stmt: *mut sqlite3_stmt;
|
||||
|
||||
if timestamp_to == 0i32 as libc::c_long {
|
||||
timestamp_to = time(0 as *mut time_t) + 10i32 as libc::c_long
|
||||
}
|
||||
stmt = dc_sqlite3_prepare(
|
||||
context,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
b"SELECT l.id, l.latitude, l.longitude, l.accuracy, l.timestamp, l.independent \
|
||||
m.id, l.from_id, l.chat_id, m.txt \
|
||||
FROM locations l LEFT JOIN msgs m ON l.id=m.location_id WHERE (? OR l.chat_id=?) \
|
||||
AND (? OR l.from_id=?) \
|
||||
AND (l.independent=1 OR (l.timestamp>=? AND l.timestamp<=?)) \
|
||||
ORDER BY l.timestamp DESC, l.id DESC, m.id DESC;\x00" as *const u8
|
||||
as *const libc::c_char,
|
||||
);
|
||||
sqlite3_bind_int(
|
||||
stmt,
|
||||
1i32,
|
||||
if chat_id == 0i32 as libc::c_uint {
|
||||
1i32
|
||||
} else {
|
||||
0i32
|
||||
},
|
||||
);
|
||||
sqlite3_bind_int(stmt, 2i32, chat_id as libc::c_int);
|
||||
sqlite3_bind_int(
|
||||
stmt,
|
||||
3i32,
|
||||
if contact_id == 0i32 as libc::c_uint {
|
||||
1i32
|
||||
} else {
|
||||
0i32
|
||||
},
|
||||
);
|
||||
sqlite3_bind_int(stmt, 4i32, contact_id as libc::c_int);
|
||||
sqlite3_bind_int(stmt, 5i32, timestamp_from as libc::c_int);
|
||||
sqlite3_bind_int(stmt, 6i32, timestamp_to as libc::c_int);
|
||||
while sqlite3_step(stmt) == 100i32 {
|
||||
let mut loc: *mut _dc_location =
|
||||
calloc(1, ::std::mem::size_of::<_dc_location>()) as *mut _dc_location;
|
||||
if loc.is_null() {
|
||||
break;
|
||||
}
|
||||
(*loc).location_id = sqlite3_column_double(stmt, 0i32) as uint32_t;
|
||||
(*loc).latitude = sqlite3_column_double(stmt, 1i32);
|
||||
(*loc).longitude = sqlite3_column_double(stmt, 2i32);
|
||||
(*loc).accuracy = sqlite3_column_double(stmt, 3i32);
|
||||
(*loc).timestamp = sqlite3_column_int64(stmt, 4i32) as time_t;
|
||||
(*loc).independent = sqlite3_column_int(stmt, 5i32) as uint32_t;
|
||||
(*loc).msg_id = sqlite3_column_int(stmt, 6i32) as uint32_t;
|
||||
(*loc).contact_id = sqlite3_column_int(stmt, 7i32) as uint32_t;
|
||||
(*loc).chat_id = sqlite3_column_int(stmt, 8i32) as uint32_t;
|
||||
|
||||
if 0 != (*loc).msg_id {
|
||||
let mut txt: *const libc::c_char =
|
||||
sqlite3_column_text(stmt, 9i32) as *const libc::c_char;
|
||||
if 0 != is_marker(txt) {
|
||||
(*loc).marker = strdup(txt)
|
||||
}
|
||||
}
|
||||
dc_array_add_ptr(ret, loc as *mut libc::c_void);
|
||||
as *const libc::c_char,
|
||||
);
|
||||
sqlite3_bind_int(
|
||||
stmt,
|
||||
1i32,
|
||||
if chat_id == 0i32 as libc::c_uint {
|
||||
1i32
|
||||
} else {
|
||||
0i32
|
||||
},
|
||||
);
|
||||
sqlite3_bind_int(stmt, 2i32, chat_id as libc::c_int);
|
||||
sqlite3_bind_int(
|
||||
stmt,
|
||||
3i32,
|
||||
if contact_id == 0i32 as libc::c_uint {
|
||||
1i32
|
||||
} else {
|
||||
0i32
|
||||
},
|
||||
);
|
||||
sqlite3_bind_int(stmt, 4i32, contact_id as libc::c_int);
|
||||
sqlite3_bind_int(stmt, 5i32, timestamp_from as libc::c_int);
|
||||
sqlite3_bind_int(stmt, 6i32, timestamp_to as libc::c_int);
|
||||
while sqlite3_step(stmt) == 100i32 {
|
||||
let mut loc: *mut _dc_location =
|
||||
calloc(1, ::std::mem::size_of::<_dc_location>()) as *mut _dc_location;
|
||||
if loc.is_null() {
|
||||
break;
|
||||
}
|
||||
(*loc).location_id = sqlite3_column_double(stmt, 0i32) as uint32_t;
|
||||
(*loc).latitude = sqlite3_column_double(stmt, 1i32);
|
||||
(*loc).longitude = sqlite3_column_double(stmt, 2i32);
|
||||
(*loc).accuracy = sqlite3_column_double(stmt, 3i32);
|
||||
(*loc).timestamp = sqlite3_column_int64(stmt, 4i32) as time_t;
|
||||
(*loc).independent = sqlite3_column_int(stmt, 5i32) as uint32_t;
|
||||
(*loc).msg_id = sqlite3_column_int(stmt, 6i32) as uint32_t;
|
||||
(*loc).contact_id = sqlite3_column_int(stmt, 7i32) as uint32_t;
|
||||
(*loc).chat_id = sqlite3_column_int(stmt, 8i32) as uint32_t;
|
||||
|
||||
if 0 != (*loc).msg_id {
|
||||
let mut txt: *const libc::c_char =
|
||||
sqlite3_column_text(stmt, 9i32) as *const libc::c_char;
|
||||
if 0 != is_marker(txt) {
|
||||
(*loc).marker = strdup(txt)
|
||||
}
|
||||
}
|
||||
dc_array_add_ptr(ret, loc as *mut libc::c_void);
|
||||
}
|
||||
|
||||
sqlite3_finalize(stmt);
|
||||
return ret;
|
||||
|
||||
ret
|
||||
}
|
||||
|
||||
// TODO should be bool /rtn
|
||||
unsafe fn is_marker(mut txt: *const libc::c_char) -> libc::c_int {
|
||||
if !txt.is_null() {
|
||||
let mut len: libc::c_int = dc_utf8_strlen(txt) as libc::c_int;
|
||||
@@ -292,37 +299,41 @@ unsafe fn is_marker(mut txt: *const libc::c_char) -> libc::c_int {
|
||||
return 1i32;
|
||||
}
|
||||
}
|
||||
return 0i32;
|
||||
|
||||
0
|
||||
}
|
||||
pub unsafe fn dc_delete_all_locations(mut context: *mut dc_context_t) {
|
||||
let mut stmt: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt;
|
||||
if !(context.is_null() || (*context).magic != 0x11a11807i32 as libc::c_uint) {
|
||||
stmt = dc_sqlite3_prepare(
|
||||
(*context).sql,
|
||||
b"DELETE FROM locations;\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
sqlite3_step(stmt);
|
||||
((*context).cb)(
|
||||
context,
|
||||
Event::LOCATION_CHANGED,
|
||||
0i32 as uintptr_t,
|
||||
0i32 as uintptr_t,
|
||||
);
|
||||
}
|
||||
|
||||
pub unsafe fn dc_delete_all_locations(mut context: &dc_context_t) {
|
||||
let mut stmt: *mut sqlite3_stmt;
|
||||
|
||||
stmt = dc_sqlite3_prepare(
|
||||
context,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
b"DELETE FROM locations;\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
sqlite3_step(stmt);
|
||||
(context.cb)(
|
||||
context,
|
||||
Event::LOCATION_CHANGED,
|
||||
0i32 as uintptr_t,
|
||||
0i32 as uintptr_t,
|
||||
);
|
||||
|
||||
sqlite3_finalize(stmt);
|
||||
}
|
||||
|
||||
pub unsafe fn dc_get_location_kml(
|
||||
mut context: *mut dc_context_t,
|
||||
mut context: &dc_context_t,
|
||||
mut chat_id: uint32_t,
|
||||
mut last_added_location_id: *mut uint32_t,
|
||||
) -> *mut libc::c_char {
|
||||
let mut success: libc::c_int = 0i32;
|
||||
let mut stmt: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt;
|
||||
let mut self_addr: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut stmt: *mut sqlite3_stmt;
|
||||
let mut self_addr: *mut libc::c_char;
|
||||
let mut now: time_t = time(0 as *mut time_t);
|
||||
let mut locations_send_begin: time_t = 0i32 as time_t;
|
||||
let mut locations_send_until: time_t = 0i32 as time_t;
|
||||
let mut locations_last_sent: time_t = 0i32 as time_t;
|
||||
let mut locations_send_begin: time_t;
|
||||
let mut locations_send_until: time_t;
|
||||
let mut locations_last_sent: time_t;
|
||||
let mut location_count: libc::c_int = 0i32;
|
||||
let mut ret: dc_strbuilder_t = dc_strbuilder_t {
|
||||
buf: 0 as *mut libc::c_char,
|
||||
@@ -331,30 +342,34 @@ pub unsafe fn dc_get_location_kml(
|
||||
eos: 0 as *mut libc::c_char,
|
||||
};
|
||||
dc_strbuilder_init(&mut ret, 1000i32);
|
||||
if !(context.is_null() || (*context).magic != 0x11a11807i32 as libc::c_uint) {
|
||||
self_addr = dc_sqlite3_get_config(
|
||||
(*context).sql,
|
||||
b"configured_addr\x00" as *const u8 as *const libc::c_char,
|
||||
b"\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
stmt =
|
||||
dc_sqlite3_prepare((*context).sql,
|
||||
b"SELECT locations_send_begin, locations_send_until, locations_last_sent FROM chats WHERE id=?;\x00"
|
||||
as *const u8 as *const libc::c_char);
|
||||
sqlite3_bind_int(stmt, 1i32, chat_id as libc::c_int);
|
||||
if !(sqlite3_step(stmt) != 100i32) {
|
||||
locations_send_begin = sqlite3_column_int64(stmt, 0i32) as time_t;
|
||||
locations_send_until = sqlite3_column_int64(stmt, 1i32) as time_t;
|
||||
locations_last_sent = sqlite3_column_int64(stmt, 2i32) as time_t;
|
||||
sqlite3_finalize(stmt);
|
||||
stmt = 0 as *mut sqlite3_stmt;
|
||||
if !(locations_send_begin == 0i32 as libc::c_long || now > locations_send_until) {
|
||||
dc_strbuilder_catf(&mut ret as *mut dc_strbuilder_t,
|
||||
|
||||
self_addr = dc_sqlite3_get_config(
|
||||
context,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
b"configured_addr\x00" as *const u8 as *const libc::c_char,
|
||||
b"\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
stmt =
|
||||
dc_sqlite3_prepare(
|
||||
context,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
b"SELECT locations_send_begin, locations_send_until, locations_last_sent FROM chats WHERE id=?;\x00"
|
||||
as *const u8 as *const libc::c_char);
|
||||
sqlite3_bind_int(stmt, 1i32, chat_id as libc::c_int);
|
||||
if !(sqlite3_step(stmt) != 100i32) {
|
||||
locations_send_begin = sqlite3_column_int64(stmt, 0i32) as time_t;
|
||||
locations_send_until = sqlite3_column_int64(stmt, 1i32) as time_t;
|
||||
locations_last_sent = sqlite3_column_int64(stmt, 2i32) as time_t;
|
||||
sqlite3_finalize(stmt);
|
||||
stmt = 0 as *mut sqlite3_stmt;
|
||||
if !(locations_send_begin == 0i32 as libc::c_long || now > locations_send_until) {
|
||||
dc_strbuilder_catf(&mut ret as *mut dc_strbuilder_t,
|
||||
b"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<kml xmlns=\"http://www.opengis.net/kml/2.2\">\n<Document addr=\"%s\">\n\x00"
|
||||
as *const u8 as *const libc::c_char,
|
||||
self_addr);
|
||||
stmt = dc_sqlite3_prepare(
|
||||
(*context).sql,
|
||||
stmt = dc_sqlite3_prepare(
|
||||
context,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
b"SELECT id, latitude, longitude, accuracy, timestamp\
|
||||
FROM locations WHERE from_id=? \
|
||||
AND timestamp>=? \
|
||||
@@ -365,44 +380,41 @@ pub unsafe fn dc_get_location_kml(
|
||||
as *const libc::c_char,
|
||||
);
|
||||
|
||||
sqlite3_bind_int(stmt, 1i32, 1i32);
|
||||
sqlite3_bind_int64(stmt, 2i32, locations_send_begin as sqlite3_int64);
|
||||
sqlite3_bind_int64(stmt, 3i32, locations_last_sent as sqlite3_int64);
|
||||
sqlite3_bind_int(stmt, 4i32, 1i32);
|
||||
while sqlite3_step(stmt) == 100i32 {
|
||||
let mut location_id: uint32_t = sqlite3_column_int(stmt, 0i32) as uint32_t;
|
||||
let mut latitude: *mut libc::c_char =
|
||||
dc_ftoa(sqlite3_column_double(stmt, 1i32));
|
||||
let mut longitude: *mut libc::c_char =
|
||||
dc_ftoa(sqlite3_column_double(stmt, 2i32));
|
||||
let mut accuracy: *mut libc::c_char =
|
||||
dc_ftoa(sqlite3_column_double(stmt, 3i32));
|
||||
let mut timestamp: *mut libc::c_char =
|
||||
get_kml_timestamp(sqlite3_column_int64(stmt, 4i32) as time_t);
|
||||
dc_strbuilder_catf(&mut ret as *mut dc_strbuilder_t,
|
||||
sqlite3_bind_int(stmt, 1i32, 1i32);
|
||||
sqlite3_bind_int64(stmt, 2i32, locations_send_begin as sqlite3_int64);
|
||||
sqlite3_bind_int64(stmt, 3i32, locations_last_sent as sqlite3_int64);
|
||||
sqlite3_bind_int(stmt, 4i32, 1i32);
|
||||
while sqlite3_step(stmt) == 100i32 {
|
||||
let mut location_id: uint32_t = sqlite3_column_int(stmt, 0i32) as uint32_t;
|
||||
let mut latitude: *mut libc::c_char = dc_ftoa(sqlite3_column_double(stmt, 1i32));
|
||||
let mut longitude: *mut libc::c_char = dc_ftoa(sqlite3_column_double(stmt, 2i32));
|
||||
let mut accuracy: *mut libc::c_char = dc_ftoa(sqlite3_column_double(stmt, 3i32));
|
||||
let mut timestamp: *mut libc::c_char =
|
||||
get_kml_timestamp(sqlite3_column_int64(stmt, 4i32) as time_t);
|
||||
dc_strbuilder_catf(&mut ret as *mut dc_strbuilder_t,
|
||||
b"<Placemark><Timestamp><when>%s</when></Timestamp><Point><coordinates accuracy=\"%s\">%s,%s</coordinates></Point></Placemark>\n\x00"
|
||||
as *const u8 as
|
||||
*const libc::c_char, timestamp,
|
||||
accuracy, longitude, latitude);
|
||||
location_count += 1;
|
||||
if !last_added_location_id.is_null() {
|
||||
*last_added_location_id = location_id
|
||||
}
|
||||
free(latitude as *mut libc::c_void);
|
||||
free(longitude as *mut libc::c_void);
|
||||
free(accuracy as *mut libc::c_void);
|
||||
free(timestamp as *mut libc::c_void);
|
||||
}
|
||||
if !(location_count == 0i32) {
|
||||
dc_strbuilder_cat(
|
||||
&mut ret,
|
||||
b"</Document>\n</kml>\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
success = 1i32
|
||||
location_count += 1;
|
||||
if !last_added_location_id.is_null() {
|
||||
*last_added_location_id = location_id
|
||||
}
|
||||
free(latitude as *mut libc::c_void);
|
||||
free(longitude as *mut libc::c_void);
|
||||
free(accuracy as *mut libc::c_void);
|
||||
free(timestamp as *mut libc::c_void);
|
||||
}
|
||||
if !(location_count == 0i32) {
|
||||
dc_strbuilder_cat(
|
||||
&mut ret,
|
||||
b"</Document>\n</kml>\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
success = 1i32
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sqlite3_finalize(stmt);
|
||||
free(self_addr as *mut libc::c_void);
|
||||
if 0 == success {
|
||||
@@ -414,7 +426,8 @@ pub unsafe fn dc_get_location_kml(
|
||||
0 as *mut libc::c_char
|
||||
};
|
||||
}
|
||||
/* ******************************************************************************
|
||||
|
||||
/*******************************************************************************
|
||||
* create kml-files
|
||||
******************************************************************************/
|
||||
unsafe fn get_kml_timestamp(mut utc: time_t) -> *mut libc::c_char {
|
||||
@@ -437,7 +450,8 @@ unsafe fn get_kml_timestamp(mut utc: time_t) -> *mut libc::c_char {
|
||||
gmtime(&mut utc) as *const libc::c_void,
|
||||
::std::mem::size_of::<tm>(),
|
||||
);
|
||||
return dc_mprintf(
|
||||
|
||||
dc_mprintf(
|
||||
b"%04i-%02i-%02iT%02i:%02i:%02iZ\x00" as *const u8 as *const libc::c_char,
|
||||
wanted_struct.tm_year as libc::c_int + 1900i32,
|
||||
wanted_struct.tm_mon as libc::c_int + 1i32,
|
||||
@@ -445,19 +459,14 @@ unsafe fn get_kml_timestamp(mut utc: time_t) -> *mut libc::c_char {
|
||||
wanted_struct.tm_hour as libc::c_int,
|
||||
wanted_struct.tm_min as libc::c_int,
|
||||
wanted_struct.tm_sec as libc::c_int,
|
||||
);
|
||||
)
|
||||
}
|
||||
|
||||
pub unsafe fn dc_get_message_kml(
|
||||
context: *const dc_context_t,
|
||||
timestamp: time_t,
|
||||
latitude: libc::c_double,
|
||||
longitude: libc::c_double,
|
||||
) -> *mut libc::c_char {
|
||||
if !(context.is_null() || (*context).magic != 0x11a11807i32 as libc::c_uint) {
|
||||
return std::ptr::null_mut();
|
||||
}
|
||||
|
||||
let timestamp_str = get_kml_timestamp(timestamp);
|
||||
let latitude_str = dc_ftoa(latitude);
|
||||
let longitude_str = dc_ftoa(longitude);
|
||||
@@ -485,13 +494,14 @@ pub unsafe fn dc_get_message_kml(
|
||||
}
|
||||
|
||||
pub unsafe fn dc_set_kml_sent_timestamp(
|
||||
mut context: *mut dc_context_t,
|
||||
mut chat_id: uint32_t,
|
||||
mut timestamp: time_t,
|
||||
context: &dc_context_t,
|
||||
chat_id: uint32_t,
|
||||
timestamp: time_t,
|
||||
) {
|
||||
let mut stmt: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt;
|
||||
let mut stmt: *mut sqlite3_stmt;
|
||||
stmt = dc_sqlite3_prepare(
|
||||
(*context).sql,
|
||||
context,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
b"UPDATE chats SET locations_last_sent=? WHERE id=?;\x00" as *const u8
|
||||
as *const libc::c_char,
|
||||
);
|
||||
@@ -500,14 +510,16 @@ pub unsafe fn dc_set_kml_sent_timestamp(
|
||||
sqlite3_step(stmt);
|
||||
sqlite3_finalize(stmt);
|
||||
}
|
||||
|
||||
pub unsafe fn dc_set_msg_location_id(
|
||||
mut context: *mut dc_context_t,
|
||||
mut context: &dc_context_t,
|
||||
mut msg_id: uint32_t,
|
||||
mut location_id: uint32_t,
|
||||
) {
|
||||
let mut stmt: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt;
|
||||
let mut stmt: *mut sqlite3_stmt;
|
||||
stmt = dc_sqlite3_prepare(
|
||||
(*context).sql,
|
||||
context,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
b"UPDATE msgs SET location_id=? WHERE id=?;\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
sqlite3_bind_int64(stmt, 1i32, location_id as sqlite3_int64);
|
||||
@@ -515,8 +527,9 @@ pub unsafe fn dc_set_msg_location_id(
|
||||
sqlite3_step(stmt);
|
||||
sqlite3_finalize(stmt);
|
||||
}
|
||||
|
||||
pub unsafe fn dc_save_locations(
|
||||
mut context: *mut dc_context_t,
|
||||
mut context: &dc_context_t,
|
||||
mut chat_id: uint32_t,
|
||||
mut contact_id: uint32_t,
|
||||
mut locations: *const dc_array_t,
|
||||
@@ -526,18 +539,16 @@ pub unsafe fn dc_save_locations(
|
||||
let mut stmt_insert: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt;
|
||||
let mut newest_timestamp: time_t = 0i32 as time_t;
|
||||
let mut newest_location_id: uint32_t = 0i32 as uint32_t;
|
||||
if !(context.is_null()
|
||||
|| (*context).magic != 0x11a11807i32 as libc::c_uint
|
||||
|| chat_id <= 9i32 as libc::c_uint
|
||||
|| locations.is_null())
|
||||
{
|
||||
if !(chat_id <= 9i32 as libc::c_uint || locations.is_null()) {
|
||||
stmt_test = dc_sqlite3_prepare(
|
||||
(*context).sql,
|
||||
context,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
b"SELECT id FROM locations WHERE timestamp=? AND from_id=?\x00" as *const u8
|
||||
as *const libc::c_char,
|
||||
);
|
||||
stmt_insert = dc_sqlite3_prepare(
|
||||
(*context).sql,
|
||||
context,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
b"INSERT INTO locations\
|
||||
(timestamp, from_id, chat_id, latitude, longitude, accuracy, independent) \
|
||||
VALUES (?,?,?,?,?,?,?);\x00" as *const u8 as *const libc::c_char,
|
||||
@@ -563,7 +574,8 @@ pub unsafe fn dc_save_locations(
|
||||
if (*location).timestamp > newest_timestamp {
|
||||
newest_timestamp = (*location).timestamp;
|
||||
newest_location_id = dc_sqlite3_get_rowid2(
|
||||
(*context).sql,
|
||||
context,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
b"locations\x00" as *const u8 as *const libc::c_char,
|
||||
b"timestamp\x00" as *const u8 as *const libc::c_char,
|
||||
(*location).timestamp as uint64_t,
|
||||
@@ -576,10 +588,12 @@ pub unsafe fn dc_save_locations(
|
||||
}
|
||||
sqlite3_finalize(stmt_test);
|
||||
sqlite3_finalize(stmt_insert);
|
||||
return newest_location_id;
|
||||
|
||||
newest_location_id
|
||||
}
|
||||
|
||||
pub unsafe fn dc_kml_parse(
|
||||
mut context: *mut dc_context_t,
|
||||
mut context: &dc_context_t,
|
||||
mut content: *const libc::c_char,
|
||||
mut content_bytes: size_t,
|
||||
) -> *mut dc_kml_t {
|
||||
@@ -591,33 +605,35 @@ pub unsafe fn dc_kml_parse(
|
||||
text_cb: None,
|
||||
userdata: 0 as *mut libc::c_void,
|
||||
};
|
||||
if !(context.is_null() || (*context).magic != 0x11a11807i32 as libc::c_uint) {
|
||||
if content_bytes > (1 * 1024 * 1024) {
|
||||
dc_log_warning(
|
||||
context,
|
||||
0,
|
||||
b"A kml-files with %i bytes is larger than reasonably expected.\x00" as *const u8
|
||||
as *const libc::c_char,
|
||||
content_bytes,
|
||||
|
||||
if content_bytes > (1 * 1024 * 1024) {
|
||||
dc_log_warning(
|
||||
context,
|
||||
0,
|
||||
b"A kml-files with %i bytes is larger than reasonably expected.\x00" as *const u8
|
||||
as *const libc::c_char,
|
||||
content_bytes,
|
||||
);
|
||||
} else {
|
||||
content_nullterminated = dc_null_terminate(content, content_bytes as libc::c_int);
|
||||
if !content_nullterminated.is_null() {
|
||||
(*kml).locations = dc_array_new_typed(1, 100 as size_t);
|
||||
dc_saxparser_init(&mut saxparser, kml as *mut libc::c_void);
|
||||
dc_saxparser_set_tag_handler(
|
||||
&mut saxparser,
|
||||
Some(kml_starttag_cb),
|
||||
Some(kml_endtag_cb),
|
||||
);
|
||||
} else {
|
||||
content_nullterminated = dc_null_terminate(content, content_bytes as libc::c_int);
|
||||
if !content_nullterminated.is_null() {
|
||||
(*kml).locations = dc_array_new_typed(context, 1, 100 as size_t);
|
||||
dc_saxparser_init(&mut saxparser, kml as *mut libc::c_void);
|
||||
dc_saxparser_set_tag_handler(
|
||||
&mut saxparser,
|
||||
Some(kml_starttag_cb),
|
||||
Some(kml_endtag_cb),
|
||||
);
|
||||
dc_saxparser_set_text_handler(&mut saxparser, Some(kml_text_cb));
|
||||
dc_saxparser_parse(&mut saxparser, content_nullterminated);
|
||||
}
|
||||
dc_saxparser_set_text_handler(&mut saxparser, Some(kml_text_cb));
|
||||
dc_saxparser_parse(&mut saxparser, content_nullterminated);
|
||||
}
|
||||
}
|
||||
|
||||
free(content_nullterminated as *mut libc::c_void);
|
||||
return kml;
|
||||
|
||||
kml
|
||||
}
|
||||
|
||||
unsafe fn kml_text_cb(userdata: *mut libc::c_void, text: *const libc::c_char, _len: libc::c_int) {
|
||||
let mut kml: *mut dc_kml_t = userdata as *mut dc_kml_t;
|
||||
if 0 != (*kml).tag & (0x4 | 0x10) {
|
||||
@@ -694,6 +710,7 @@ unsafe fn kml_text_cb(userdata: *mut libc::c_void, text: *const libc::c_char, _l
|
||||
free(val as *mut libc::c_void);
|
||||
};
|
||||
}
|
||||
|
||||
unsafe fn kml_endtag_cb(mut userdata: *mut libc::c_void, mut tag: *const libc::c_char) {
|
||||
let mut kml: *mut dc_kml_t = userdata as *mut dc_kml_t;
|
||||
if strcmp(tag, b"placemark\x00" as *const u8 as *const libc::c_char) == 0i32 {
|
||||
@@ -710,7 +727,8 @@ unsafe fn kml_endtag_cb(mut userdata: *mut libc::c_void, mut tag: *const libc::c
|
||||
(*kml).tag = 0i32
|
||||
};
|
||||
}
|
||||
/* ******************************************************************************
|
||||
|
||||
/*******************************************************************************
|
||||
* parse kml-files
|
||||
******************************************************************************/
|
||||
unsafe fn kml_starttag_cb(
|
||||
@@ -754,6 +772,7 @@ unsafe fn kml_starttag_cb(
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
pub unsafe fn dc_kml_unref(mut kml: *mut dc_kml_t) {
|
||||
if kml.is_null() {
|
||||
return;
|
||||
@@ -762,11 +781,9 @@ pub unsafe fn dc_kml_unref(mut kml: *mut dc_kml_t) {
|
||||
free((*kml).addr as *mut libc::c_void);
|
||||
free(kml as *mut libc::c_void);
|
||||
}
|
||||
pub unsafe fn dc_job_do_DC_JOB_MAYBE_SEND_LOCATIONS(
|
||||
context: *mut dc_context_t,
|
||||
_job: *mut dc_job_t,
|
||||
) {
|
||||
let mut stmt_chats: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt;
|
||||
|
||||
pub unsafe fn dc_job_do_DC_JOB_MAYBE_SEND_LOCATIONS(context: &dc_context_t, _job: *mut dc_job_t) {
|
||||
let mut stmt_chats: *mut sqlite3_stmt;
|
||||
let mut stmt_locations: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt;
|
||||
let mut now: time_t = time(0 as *mut time_t);
|
||||
let mut continue_streaming: libc::c_int = 1i32;
|
||||
@@ -777,9 +794,10 @@ pub unsafe fn dc_job_do_DC_JOB_MAYBE_SEND_LOCATIONS(
|
||||
as *const libc::c_char,
|
||||
);
|
||||
stmt_chats = dc_sqlite3_prepare(
|
||||
(*context).sql,
|
||||
b"SELECT id, locations_send_begin, locations_last_sent\
|
||||
FROM chats\
|
||||
context,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
b"SELECT id, locations_send_begin, locations_last_sent \
|
||||
FROM chats \
|
||||
WHERE locations_send_until>?;\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
sqlite3_bind_int64(stmt_chats, 1i32, now as sqlite3_int64);
|
||||
@@ -794,7 +812,8 @@ pub unsafe fn dc_job_do_DC_JOB_MAYBE_SEND_LOCATIONS(
|
||||
}
|
||||
if stmt_locations.is_null() {
|
||||
stmt_locations = dc_sqlite3_prepare(
|
||||
(*context).sql,
|
||||
context,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
b"SELECT id \
|
||||
FROM locations \
|
||||
WHERE from_id=? \
|
||||
@@ -835,20 +854,22 @@ pub unsafe fn dc_job_do_DC_JOB_MAYBE_SEND_LOCATIONS(
|
||||
sqlite3_finalize(stmt_chats);
|
||||
sqlite3_finalize(stmt_locations);
|
||||
}
|
||||
|
||||
pub unsafe fn dc_job_do_DC_JOB_MAYBE_SEND_LOC_ENDED(
|
||||
mut context: *mut dc_context_t,
|
||||
mut job: *mut dc_job_t,
|
||||
mut context: &dc_context_t,
|
||||
mut job: &mut dc_job_t,
|
||||
) {
|
||||
// this function is called when location-streaming _might_ have ended for a chat.
|
||||
// the function checks, if location-streaming is really ended;
|
||||
// if so, a device-message is added if not yet done.
|
||||
let mut chat_id: uint32_t = (*job).foreign_id;
|
||||
let mut locations_send_begin: time_t = 0i32 as time_t;
|
||||
let mut locations_send_until: time_t = 0i32 as time_t;
|
||||
let mut stmt: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt;
|
||||
let mut locations_send_begin: time_t;
|
||||
let mut locations_send_until: time_t;
|
||||
let mut stmt;
|
||||
let mut stock_str: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
stmt = dc_sqlite3_prepare(
|
||||
(*context).sql,
|
||||
context,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
b"SELECT locations_send_begin, locations_send_until FROM chats WHERE id=?\x00"
|
||||
as *const u8 as *const libc::c_char,
|
||||
);
|
||||
@@ -869,10 +890,12 @@ pub unsafe fn dc_job_do_DC_JOB_MAYBE_SEND_LOC_ENDED(
|
||||
{
|
||||
// not streaming, device-message already sent
|
||||
stmt =
|
||||
dc_sqlite3_prepare((*context).sql,
|
||||
b"UPDATE chats SET locations_send_begin=0, locations_send_until=0 WHERE id=?\x00"
|
||||
as *const u8 as
|
||||
*const libc::c_char);
|
||||
dc_sqlite3_prepare(
|
||||
context,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
b"UPDATE chats SET locations_send_begin=0, locations_send_until=0 WHERE id=?\x00"
|
||||
as *const u8 as
|
||||
*const libc::c_char);
|
||||
sqlite3_bind_int(stmt, 1i32, chat_id as libc::c_int);
|
||||
sqlite3_step(stmt);
|
||||
stock_str = dc_stock_system_msg(
|
||||
@@ -883,7 +906,7 @@ pub unsafe fn dc_job_do_DC_JOB_MAYBE_SEND_LOC_ENDED(
|
||||
0i32 as uint32_t,
|
||||
);
|
||||
dc_add_device_msg(context, chat_id, stock_str);
|
||||
((*context).cb)(
|
||||
(context.cb)(
|
||||
context,
|
||||
Event::CHAT_MODIFIED,
|
||||
chat_id as uintptr_t,
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
use libc;
|
||||
|
||||
use crate::constants::Event;
|
||||
use crate::dc_context::dc_context_t;
|
||||
use crate::dc_tools::*;
|
||||
@@ -7,7 +5,7 @@ use crate::types::*;
|
||||
use crate::x::*;
|
||||
|
||||
pub unsafe extern "C" fn dc_log_event(
|
||||
mut context: *mut dc_context_t,
|
||||
mut context: &dc_context_t,
|
||||
mut event_code: Event,
|
||||
mut data1: libc::c_int,
|
||||
mut msg: *const libc::c_char,
|
||||
@@ -15,6 +13,7 @@ pub unsafe extern "C" fn dc_log_event(
|
||||
) {
|
||||
log_vprintf(context, event_code, data1, msg, va);
|
||||
}
|
||||
|
||||
/* Asynchronous "Thread-errors" are reported by the dc_log_error()
|
||||
function. These errors must be shown to the user by a bubble or so.
|
||||
|
||||
@@ -23,16 +22,13 @@ usually not reported using dc_log_error() - its up to the caller to
|
||||
decide, what should be reported or done. However, these "Normal" errors
|
||||
are usually logged by dc_log_warning(). */
|
||||
unsafe fn log_vprintf(
|
||||
mut context: *mut dc_context_t,
|
||||
mut context: &dc_context_t,
|
||||
mut event: Event,
|
||||
mut data1: libc::c_int,
|
||||
mut msg_format: *const libc::c_char,
|
||||
mut va_0: ::std::ffi::VaList,
|
||||
) {
|
||||
let mut msg: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
if context.is_null() || (*context).magic != 0x11a11807i32 as libc::c_uint {
|
||||
return;
|
||||
}
|
||||
let mut msg: *mut libc::c_char;
|
||||
if !msg_format.is_null() {
|
||||
let mut tempbuf: [libc::c_char; 1025] = [0; 1025];
|
||||
vsnprintf(
|
||||
@@ -51,43 +47,95 @@ unsafe fn log_vprintf(
|
||||
((*context).cb)(context, event, data1 as uintptr_t, msg as uintptr_t);
|
||||
free(msg as *mut libc::c_void);
|
||||
}
|
||||
|
||||
pub unsafe extern "C" fn dc_log_event_seq(
|
||||
mut context: *mut dc_context_t,
|
||||
mut context: &dc_context_t,
|
||||
mut event_code: Event,
|
||||
mut sequence_start: *mut libc::c_int,
|
||||
mut msg: *const libc::c_char,
|
||||
mut va_0: ...
|
||||
) {
|
||||
if context.is_null()
|
||||
|| sequence_start.is_null()
|
||||
|| (*context).magic != 0x11a11807i32 as libc::c_uint
|
||||
{
|
||||
if sequence_start.is_null() {
|
||||
return;
|
||||
}
|
||||
log_vprintf(context, event_code, *sequence_start, msg, va_0);
|
||||
*sequence_start = 0i32;
|
||||
}
|
||||
|
||||
pub unsafe extern "C" fn dc_log_error(
|
||||
mut context: *mut dc_context_t,
|
||||
mut context: &dc_context_t,
|
||||
mut data1: libc::c_int,
|
||||
mut msg: *const libc::c_char,
|
||||
mut va_1: ...
|
||||
) {
|
||||
log_vprintf(context, Event::ERROR, data1, msg, va_1);
|
||||
}
|
||||
|
||||
pub unsafe extern "C" fn dc_log_warning(
|
||||
mut context: *mut dc_context_t,
|
||||
mut context: &dc_context_t,
|
||||
mut data1: libc::c_int,
|
||||
mut msg: *const libc::c_char,
|
||||
mut va_2: ...
|
||||
) {
|
||||
log_vprintf(context, Event::WARNING, data1, msg, va_2);
|
||||
}
|
||||
|
||||
pub unsafe extern "C" fn dc_log_info(
|
||||
mut context: *mut dc_context_t,
|
||||
mut context: &dc_context_t,
|
||||
mut data1: libc::c_int,
|
||||
mut msg: *const libc::c_char,
|
||||
mut va_3: ...
|
||||
) {
|
||||
log_vprintf(context, Event::INFO, data1, msg, va_3);
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! info {
|
||||
($ctx:expr, $data1:expr, $msg:expr) => {
|
||||
info!($ctx, $data1, $msg,)
|
||||
};
|
||||
($ctx:expr, $data1:expr, $msg:expr, $($args:expr),* $(,)?) => {
|
||||
unsafe {
|
||||
dc_log_info(
|
||||
$ctx,
|
||||
$data1,
|
||||
std::ffi::CString::new($msg).unwrap().as_ptr(),
|
||||
$($args),*
|
||||
)
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! warn {
|
||||
($ctx:expr, $data1:expr, $msg:expr) => {
|
||||
warn!($ctx, $data1, $msg,)
|
||||
};
|
||||
($ctx:expr, $data1:expr, $msg:expr, $($args:expr),* $(,)?) => {
|
||||
unsafe {
|
||||
dc_log_warning(
|
||||
$ctx,
|
||||
$data1,
|
||||
std::ffi::CString::new($msg).unwrap().as_ptr(),
|
||||
$($args),*
|
||||
)
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! error {
|
||||
($ctx:expr, $data1:expr, $msg:expr) => {
|
||||
error!($ctx, $data1, $msg,)
|
||||
};
|
||||
($ctx:expr, $data1:expr, $msg:expr, $($args:expr),* $(,)?) => {
|
||||
unsafe {
|
||||
dc_log_error(
|
||||
$ctx,
|
||||
$data1,
|
||||
std::ffi::CString::new($msg).unwrap().as_ptr(),
|
||||
$($args),*
|
||||
)
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
use libc;
|
||||
|
||||
use crate::dc_context::dc_context_t;
|
||||
use crate::dc_sqlite3::*;
|
||||
use crate::dc_strbuilder::*;
|
||||
use crate::dc_tools::*;
|
||||
@@ -22,13 +21,15 @@ pub struct dc_loginparam_t {
|
||||
}
|
||||
|
||||
pub unsafe fn dc_loginparam_new() -> *mut dc_loginparam_t {
|
||||
let mut loginparam: *mut dc_loginparam_t = 0 as *mut dc_loginparam_t;
|
||||
let mut loginparam: *mut dc_loginparam_t;
|
||||
loginparam = calloc(1, ::std::mem::size_of::<dc_loginparam_t>()) as *mut dc_loginparam_t;
|
||||
if loginparam.is_null() {
|
||||
exit(22i32);
|
||||
}
|
||||
return loginparam;
|
||||
|
||||
loginparam
|
||||
}
|
||||
|
||||
pub unsafe fn dc_loginparam_unref(mut loginparam: *mut dc_loginparam_t) {
|
||||
if loginparam.is_null() {
|
||||
return;
|
||||
@@ -36,6 +37,7 @@ pub unsafe fn dc_loginparam_unref(mut loginparam: *mut dc_loginparam_t) {
|
||||
dc_loginparam_empty(loginparam);
|
||||
free(loginparam as *mut libc::c_void);
|
||||
}
|
||||
|
||||
/* clears all data and frees its memory. All pointers are NULL after this function is called. */
|
||||
pub unsafe fn dc_loginparam_empty(mut loginparam: *mut dc_loginparam_t) {
|
||||
if loginparam.is_null() {
|
||||
@@ -59,10 +61,12 @@ pub unsafe fn dc_loginparam_empty(mut loginparam: *mut dc_loginparam_t) {
|
||||
(*loginparam).send_pw = 0 as *mut libc::c_char;
|
||||
(*loginparam).server_flags = 0i32;
|
||||
}
|
||||
|
||||
pub unsafe fn dc_loginparam_read(
|
||||
mut loginparam: *mut dc_loginparam_t,
|
||||
mut sql: *mut dc_sqlite3_t,
|
||||
mut prefix: *const libc::c_char,
|
||||
context: &dc_context_t,
|
||||
loginparam: *mut dc_loginparam_t,
|
||||
sql: &dc_sqlite3_t,
|
||||
prefix: *const libc::c_char,
|
||||
) {
|
||||
let mut key: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
dc_loginparam_empty(loginparam);
|
||||
@@ -72,76 +76,78 @@ pub unsafe fn dc_loginparam_read(
|
||||
prefix,
|
||||
b"addr\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
(*loginparam).addr = dc_sqlite3_get_config(sql, key, 0 as *const libc::c_char);
|
||||
(*loginparam).addr = dc_sqlite3_get_config(context, sql, key, 0 as *const libc::c_char);
|
||||
sqlite3_free(key as *mut libc::c_void);
|
||||
key = sqlite3_mprintf(
|
||||
b"%s%s\x00" as *const u8 as *const libc::c_char,
|
||||
prefix,
|
||||
b"mail_server\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
(*loginparam).mail_server = dc_sqlite3_get_config(sql, key, 0 as *const libc::c_char);
|
||||
(*loginparam).mail_server = dc_sqlite3_get_config(context, sql, key, 0 as *const libc::c_char);
|
||||
sqlite3_free(key as *mut libc::c_void);
|
||||
key = sqlite3_mprintf(
|
||||
b"%s%s\x00" as *const u8 as *const libc::c_char,
|
||||
prefix,
|
||||
b"mail_port\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
(*loginparam).mail_port = dc_sqlite3_get_config_int(sql, key, 0i32);
|
||||
(*loginparam).mail_port = dc_sqlite3_get_config_int(context, sql, key, 0i32);
|
||||
sqlite3_free(key as *mut libc::c_void);
|
||||
key = sqlite3_mprintf(
|
||||
b"%s%s\x00" as *const u8 as *const libc::c_char,
|
||||
prefix,
|
||||
b"mail_user\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
(*loginparam).mail_user = dc_sqlite3_get_config(sql, key, 0 as *const libc::c_char);
|
||||
(*loginparam).mail_user = dc_sqlite3_get_config(context, sql, key, 0 as *const libc::c_char);
|
||||
sqlite3_free(key as *mut libc::c_void);
|
||||
key = sqlite3_mprintf(
|
||||
b"%s%s\x00" as *const u8 as *const libc::c_char,
|
||||
prefix,
|
||||
b"mail_pw\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
(*loginparam).mail_pw = dc_sqlite3_get_config(sql, key, 0 as *const libc::c_char);
|
||||
(*loginparam).mail_pw = dc_sqlite3_get_config(context, sql, key, 0 as *const libc::c_char);
|
||||
sqlite3_free(key as *mut libc::c_void);
|
||||
key = sqlite3_mprintf(
|
||||
b"%s%s\x00" as *const u8 as *const libc::c_char,
|
||||
prefix,
|
||||
b"send_server\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
(*loginparam).send_server = dc_sqlite3_get_config(sql, key, 0 as *const libc::c_char);
|
||||
(*loginparam).send_server = dc_sqlite3_get_config(context, sql, key, 0 as *const libc::c_char);
|
||||
sqlite3_free(key as *mut libc::c_void);
|
||||
key = sqlite3_mprintf(
|
||||
b"%s%s\x00" as *const u8 as *const libc::c_char,
|
||||
prefix,
|
||||
b"send_port\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
(*loginparam).send_port = dc_sqlite3_get_config_int(sql, key, 0i32);
|
||||
(*loginparam).send_port = dc_sqlite3_get_config_int(context, sql, key, 0i32);
|
||||
sqlite3_free(key as *mut libc::c_void);
|
||||
key = sqlite3_mprintf(
|
||||
b"%s%s\x00" as *const u8 as *const libc::c_char,
|
||||
prefix,
|
||||
b"send_user\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
(*loginparam).send_user = dc_sqlite3_get_config(sql, key, 0 as *const libc::c_char);
|
||||
(*loginparam).send_user = dc_sqlite3_get_config(context, sql, key, 0 as *const libc::c_char);
|
||||
sqlite3_free(key as *mut libc::c_void);
|
||||
key = sqlite3_mprintf(
|
||||
b"%s%s\x00" as *const u8 as *const libc::c_char,
|
||||
prefix,
|
||||
b"send_pw\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
(*loginparam).send_pw = dc_sqlite3_get_config(sql, key, 0 as *const libc::c_char);
|
||||
(*loginparam).send_pw = dc_sqlite3_get_config(context, sql, key, 0 as *const libc::c_char);
|
||||
sqlite3_free(key as *mut libc::c_void);
|
||||
key = sqlite3_mprintf(
|
||||
b"%s%s\x00" as *const u8 as *const libc::c_char,
|
||||
prefix,
|
||||
b"server_flags\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
(*loginparam).server_flags = dc_sqlite3_get_config_int(sql, key, 0i32);
|
||||
(*loginparam).server_flags = dc_sqlite3_get_config_int(context, sql, key, 0i32);
|
||||
sqlite3_free(key as *mut libc::c_void);
|
||||
}
|
||||
|
||||
pub unsafe fn dc_loginparam_write(
|
||||
mut loginparam: *const dc_loginparam_t,
|
||||
mut sql: *mut dc_sqlite3_t,
|
||||
mut prefix: *const libc::c_char,
|
||||
context: &dc_context_t,
|
||||
loginparam: *const dc_loginparam_t,
|
||||
sql: &dc_sqlite3_t,
|
||||
prefix: *const libc::c_char,
|
||||
) {
|
||||
let mut key: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
sqlite3_free(key as *mut libc::c_void);
|
||||
@@ -150,72 +156,73 @@ pub unsafe fn dc_loginparam_write(
|
||||
prefix,
|
||||
b"addr\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
dc_sqlite3_set_config(sql, key, (*loginparam).addr);
|
||||
dc_sqlite3_set_config(context, sql, key, (*loginparam).addr);
|
||||
sqlite3_free(key as *mut libc::c_void);
|
||||
key = sqlite3_mprintf(
|
||||
b"%s%s\x00" as *const u8 as *const libc::c_char,
|
||||
prefix,
|
||||
b"mail_server\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
dc_sqlite3_set_config(sql, key, (*loginparam).mail_server);
|
||||
dc_sqlite3_set_config(context, sql, key, (*loginparam).mail_server);
|
||||
sqlite3_free(key as *mut libc::c_void);
|
||||
key = sqlite3_mprintf(
|
||||
b"%s%s\x00" as *const u8 as *const libc::c_char,
|
||||
prefix,
|
||||
b"mail_port\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
dc_sqlite3_set_config_int(sql, key, (*loginparam).mail_port);
|
||||
dc_sqlite3_set_config_int(context, sql, key, (*loginparam).mail_port);
|
||||
sqlite3_free(key as *mut libc::c_void);
|
||||
key = sqlite3_mprintf(
|
||||
b"%s%s\x00" as *const u8 as *const libc::c_char,
|
||||
prefix,
|
||||
b"mail_user\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
dc_sqlite3_set_config(sql, key, (*loginparam).mail_user);
|
||||
dc_sqlite3_set_config(context, sql, key, (*loginparam).mail_user);
|
||||
sqlite3_free(key as *mut libc::c_void);
|
||||
key = sqlite3_mprintf(
|
||||
b"%s%s\x00" as *const u8 as *const libc::c_char,
|
||||
prefix,
|
||||
b"mail_pw\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
dc_sqlite3_set_config(sql, key, (*loginparam).mail_pw);
|
||||
dc_sqlite3_set_config(context, sql, key, (*loginparam).mail_pw);
|
||||
sqlite3_free(key as *mut libc::c_void);
|
||||
key = sqlite3_mprintf(
|
||||
b"%s%s\x00" as *const u8 as *const libc::c_char,
|
||||
prefix,
|
||||
b"send_server\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
dc_sqlite3_set_config(sql, key, (*loginparam).send_server);
|
||||
dc_sqlite3_set_config(context, sql, key, (*loginparam).send_server);
|
||||
sqlite3_free(key as *mut libc::c_void);
|
||||
key = sqlite3_mprintf(
|
||||
b"%s%s\x00" as *const u8 as *const libc::c_char,
|
||||
prefix,
|
||||
b"send_port\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
dc_sqlite3_set_config_int(sql, key, (*loginparam).send_port);
|
||||
dc_sqlite3_set_config_int(context, sql, key, (*loginparam).send_port);
|
||||
sqlite3_free(key as *mut libc::c_void);
|
||||
key = sqlite3_mprintf(
|
||||
b"%s%s\x00" as *const u8 as *const libc::c_char,
|
||||
prefix,
|
||||
b"send_user\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
dc_sqlite3_set_config(sql, key, (*loginparam).send_user);
|
||||
dc_sqlite3_set_config(context, sql, key, (*loginparam).send_user);
|
||||
sqlite3_free(key as *mut libc::c_void);
|
||||
key = sqlite3_mprintf(
|
||||
b"%s%s\x00" as *const u8 as *const libc::c_char,
|
||||
prefix,
|
||||
b"send_pw\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
dc_sqlite3_set_config(sql, key, (*loginparam).send_pw);
|
||||
dc_sqlite3_set_config(context, sql, key, (*loginparam).send_pw);
|
||||
sqlite3_free(key as *mut libc::c_void);
|
||||
key = sqlite3_mprintf(
|
||||
b"%s%s\x00" as *const u8 as *const libc::c_char,
|
||||
prefix,
|
||||
b"server_flags\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
dc_sqlite3_set_config_int(sql, key, (*loginparam).server_flags);
|
||||
dc_sqlite3_set_config_int(context, sql, key, (*loginparam).server_flags);
|
||||
sqlite3_free(key as *mut libc::c_void);
|
||||
}
|
||||
|
||||
pub unsafe fn dc_loginparam_get_readable(
|
||||
mut loginparam: *const dc_loginparam_t,
|
||||
) -> *mut libc::c_char {
|
||||
@@ -267,8 +274,10 @@ pub unsafe fn dc_loginparam_get_readable(
|
||||
flags_readable,
|
||||
);
|
||||
free(flags_readable as *mut libc::c_void);
|
||||
return ret;
|
||||
|
||||
ret
|
||||
}
|
||||
|
||||
unsafe fn get_readable_flags(mut flags: libc::c_int) -> *mut libc::c_char {
|
||||
let mut strbuilder: dc_strbuilder_t = dc_strbuilder_t {
|
||||
buf: 0 as *mut libc::c_char,
|
||||
@@ -355,5 +364,6 @@ unsafe fn get_readable_flags(mut flags: libc::c_int) -> *mut libc::c_char {
|
||||
);
|
||||
}
|
||||
dc_trim(strbuilder.buf);
|
||||
return strbuilder.buf;
|
||||
|
||||
strbuilder.buf
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
use libc;
|
||||
|
||||
use crate::dc_chat::*;
|
||||
use crate::dc_contact::*;
|
||||
use crate::dc_context::dc_context_t;
|
||||
@@ -36,15 +34,17 @@ pub struct dc_lot_t {
|
||||
* NB: _Lot_ is used in the meaning _heap_ here.
|
||||
*/
|
||||
pub unsafe fn dc_lot_new() -> *mut dc_lot_t {
|
||||
let mut lot: *mut dc_lot_t = 0 as *mut dc_lot_t;
|
||||
let mut lot: *mut dc_lot_t;
|
||||
lot = calloc(1, ::std::mem::size_of::<dc_lot_t>()) as *mut dc_lot_t;
|
||||
if lot.is_null() {
|
||||
exit(27i32);
|
||||
}
|
||||
(*lot).magic = 0x107107i32 as uint32_t;
|
||||
(*lot).text1_meaning = 0i32;
|
||||
return lot;
|
||||
|
||||
lot
|
||||
}
|
||||
|
||||
pub unsafe fn dc_lot_empty(mut lot: *mut dc_lot_t) {
|
||||
if lot.is_null() || (*lot).magic != 0x107107i32 as libc::c_uint {
|
||||
return;
|
||||
@@ -64,6 +64,7 @@ pub unsafe fn dc_lot_empty(mut lot: *mut dc_lot_t) {
|
||||
(*lot).state = 0i32;
|
||||
(*lot).id = 0i32 as uint32_t;
|
||||
}
|
||||
|
||||
pub unsafe fn dc_lot_unref(mut set: *mut dc_lot_t) {
|
||||
if set.is_null() || (*set).magic != 0x107107i32 as libc::c_uint {
|
||||
return;
|
||||
@@ -72,42 +73,55 @@ pub unsafe fn dc_lot_unref(mut set: *mut dc_lot_t) {
|
||||
(*set).magic = 0i32 as uint32_t;
|
||||
free(set as *mut libc::c_void);
|
||||
}
|
||||
|
||||
pub unsafe fn dc_lot_get_text1(mut lot: *const dc_lot_t) -> *mut libc::c_char {
|
||||
if lot.is_null() || (*lot).magic != 0x107107i32 as libc::c_uint {
|
||||
return 0 as *mut libc::c_char;
|
||||
}
|
||||
return dc_strdup_keep_null((*lot).text1);
|
||||
|
||||
dc_strdup_keep_null((*lot).text1)
|
||||
}
|
||||
|
||||
pub unsafe fn dc_lot_get_text2(mut lot: *const dc_lot_t) -> *mut libc::c_char {
|
||||
if lot.is_null() || (*lot).magic != 0x107107i32 as libc::c_uint {
|
||||
return 0 as *mut libc::c_char;
|
||||
}
|
||||
return dc_strdup_keep_null((*lot).text2);
|
||||
|
||||
dc_strdup_keep_null((*lot).text2)
|
||||
}
|
||||
|
||||
pub unsafe fn dc_lot_get_text1_meaning(mut lot: *const dc_lot_t) -> libc::c_int {
|
||||
if lot.is_null() || (*lot).magic != 0x107107i32 as libc::c_uint {
|
||||
return 0i32;
|
||||
}
|
||||
return (*lot).text1_meaning;
|
||||
|
||||
(*lot).text1_meaning
|
||||
}
|
||||
|
||||
pub unsafe fn dc_lot_get_state(mut lot: *const dc_lot_t) -> libc::c_int {
|
||||
if lot.is_null() || (*lot).magic != 0x107107i32 as libc::c_uint {
|
||||
return 0i32;
|
||||
}
|
||||
return (*lot).state;
|
||||
|
||||
(*lot).state
|
||||
}
|
||||
|
||||
pub unsafe fn dc_lot_get_id(mut lot: *const dc_lot_t) -> uint32_t {
|
||||
if lot.is_null() || (*lot).magic != 0x107107i32 as libc::c_uint {
|
||||
return 0i32 as uint32_t;
|
||||
}
|
||||
return (*lot).id;
|
||||
|
||||
(*lot).id
|
||||
}
|
||||
|
||||
pub unsafe fn dc_lot_get_timestamp(mut lot: *const dc_lot_t) -> time_t {
|
||||
if lot.is_null() || (*lot).magic != 0x107107i32 as libc::c_uint {
|
||||
return 0i32 as time_t;
|
||||
}
|
||||
return (*lot).timestamp;
|
||||
|
||||
(*lot).timestamp
|
||||
}
|
||||
|
||||
/* library-internal */
|
||||
/* in practice, the user additionally cuts the string himself pixel-accurate */
|
||||
pub unsafe fn dc_lot_fill(
|
||||
@@ -115,7 +129,7 @@ pub unsafe fn dc_lot_fill(
|
||||
mut msg: *const dc_msg_t,
|
||||
mut chat: *const dc_chat_t,
|
||||
mut contact: *const dc_contact_t,
|
||||
mut context: *mut dc_context_t,
|
||||
mut context: &dc_context_t,
|
||||
) {
|
||||
if lot.is_null() || (*lot).magic != 0x107107i32 as libc::c_uint || msg.is_null() {
|
||||
return;
|
||||
|
||||
@@ -1,4 +1,11 @@
|
||||
use libc;
|
||||
use mmime::mailimf_types::*;
|
||||
use mmime::mailimf_types_helper::*;
|
||||
use mmime::mailmime_disposition::*;
|
||||
use mmime::mailmime_types::*;
|
||||
use mmime::mailmime_types_helper::*;
|
||||
use mmime::mailmime_write_mem::*;
|
||||
use mmime::mmapstring::*;
|
||||
use mmime::other::*;
|
||||
|
||||
use crate::constants::VERSION;
|
||||
use crate::dc_chat::*;
|
||||
@@ -19,7 +26,7 @@ use crate::x::*;
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
#[repr(C)]
|
||||
pub struct dc_mimefactory_t {
|
||||
pub struct dc_mimefactory_t<'a> {
|
||||
pub from_addr: *mut libc::c_char,
|
||||
pub from_displayname: *mut libc::c_char,
|
||||
pub selfstatus: *mut libc::c_char,
|
||||
@@ -28,8 +35,8 @@ pub struct dc_mimefactory_t {
|
||||
pub timestamp: time_t,
|
||||
pub rfc724_mid: *mut libc::c_char,
|
||||
pub loaded: dc_mimefactory_loaded_t,
|
||||
pub msg: *mut dc_msg_t,
|
||||
pub chat: *mut dc_chat_t,
|
||||
pub msg: *mut dc_msg_t<'a>,
|
||||
pub chat: *mut dc_chat_t<'a>,
|
||||
pub increation: libc::c_int,
|
||||
pub in_reply_to: *mut libc::c_char,
|
||||
pub references: *mut libc::c_char,
|
||||
@@ -39,7 +46,7 @@ pub struct dc_mimefactory_t {
|
||||
pub out_gossiped: libc::c_int,
|
||||
pub out_last_added_location_id: uint32_t,
|
||||
pub error: *mut libc::c_char,
|
||||
pub context: *mut dc_context_t,
|
||||
pub context: &'a dc_context_t,
|
||||
}
|
||||
|
||||
pub type dc_mimefactory_loaded_t = libc::c_uint;
|
||||
@@ -47,11 +54,11 @@ pub const DC_MF_MDN_LOADED: dc_mimefactory_loaded_t = 2;
|
||||
pub const DC_MF_MSG_LOADED: dc_mimefactory_loaded_t = 1;
|
||||
pub const DC_MF_NOTHING_LOADED: dc_mimefactory_loaded_t = 0;
|
||||
|
||||
pub unsafe fn dc_mimefactory_init(
|
||||
mut factory: *mut dc_mimefactory_t,
|
||||
mut context: *mut dc_context_t,
|
||||
pub unsafe fn dc_mimefactory_init<'a>(
|
||||
factory: *mut dc_mimefactory_t<'a>,
|
||||
context: &'a dc_context_t,
|
||||
) {
|
||||
if factory.is_null() || context.is_null() {
|
||||
if factory.is_null() {
|
||||
return;
|
||||
}
|
||||
memset(
|
||||
@@ -61,6 +68,7 @@ pub unsafe fn dc_mimefactory_init(
|
||||
);
|
||||
(*factory).context = context;
|
||||
}
|
||||
|
||||
pub unsafe fn dc_mimefactory_empty(mut factory: *mut dc_mimefactory_t) {
|
||||
if factory.is_null() {
|
||||
return;
|
||||
@@ -101,20 +109,16 @@ pub unsafe fn dc_mimefactory_empty(mut factory: *mut dc_mimefactory_t) {
|
||||
(*factory).error = 0 as *mut libc::c_char;
|
||||
(*factory).timestamp = 0i32 as time_t;
|
||||
}
|
||||
|
||||
pub unsafe fn dc_mimefactory_load_msg(
|
||||
mut factory: *mut dc_mimefactory_t,
|
||||
mut msg_id: uint32_t,
|
||||
) -> libc::c_int {
|
||||
let mut context: *mut dc_context_t = 0 as *mut dc_context_t;
|
||||
let mut success: libc::c_int = 0i32;
|
||||
let mut stmt: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt;
|
||||
if !(factory.is_null()
|
||||
|| msg_id <= 9i32 as libc::c_uint
|
||||
|| (*factory).context.is_null()
|
||||
|| !(*factory).msg.is_null())
|
||||
{
|
||||
if !(factory.is_null() || msg_id <= 9i32 as libc::c_uint || !(*factory).msg.is_null()) {
|
||||
/*call empty() before */
|
||||
context = (*factory).context;
|
||||
let context = (*factory).context;
|
||||
(*factory).recipients_names = clist_new();
|
||||
(*factory).recipients_addr = clist_new();
|
||||
(*factory).msg = dc_msg_new_untyped(context);
|
||||
@@ -137,10 +141,12 @@ pub unsafe fn dc_mimefactory_load_msg(
|
||||
);
|
||||
} else {
|
||||
stmt =
|
||||
dc_sqlite3_prepare((*context).sql,
|
||||
b"SELECT c.authname, c.addr FROM chats_contacts cc LEFT JOIN contacts c ON cc.contact_id=c.id WHERE cc.chat_id=? AND cc.contact_id>9;\x00"
|
||||
as *const u8 as
|
||||
*const libc::c_char);
|
||||
dc_sqlite3_prepare(
|
||||
context,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
b"SELECT c.authname, c.addr FROM chats_contacts cc LEFT JOIN contacts c ON cc.contact_id=c.id WHERE cc.chat_id=? AND cc.contact_id>9;\x00"
|
||||
as *const u8 as
|
||||
*const libc::c_char);
|
||||
sqlite3_bind_int(stmt, 1i32, (*(*factory).msg).chat_id as libc::c_int);
|
||||
while sqlite3_step(stmt) == 100i32 {
|
||||
let mut authname: *const libc::c_char =
|
||||
@@ -166,7 +172,6 @@ pub unsafe fn dc_mimefactory_load_msg(
|
||||
}
|
||||
}
|
||||
sqlite3_finalize(stmt);
|
||||
stmt = 0 as *mut sqlite3_stmt;
|
||||
let mut command: libc::c_int =
|
||||
dc_param_get_int((*(*factory).msg).param, 'S' as i32, 0i32);
|
||||
if command == 5i32 {
|
||||
@@ -176,7 +181,8 @@ pub unsafe fn dc_mimefactory_load_msg(
|
||||
0 as *const libc::c_char,
|
||||
);
|
||||
let mut self_addr: *mut libc::c_char = dc_sqlite3_get_config(
|
||||
(*context).sql,
|
||||
context,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
b"configured_addr\x00" as *const u8 as *const libc::c_char,
|
||||
b"\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
@@ -202,7 +208,8 @@ pub unsafe fn dc_mimefactory_load_msg(
|
||||
if command != 6i32
|
||||
&& command != 7i32
|
||||
&& 0 != dc_sqlite3_get_config_int(
|
||||
(*context).sql,
|
||||
context,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
b"mdns_enabled\x00" as *const u8 as *const libc::c_char,
|
||||
1i32,
|
||||
)
|
||||
@@ -211,7 +218,8 @@ pub unsafe fn dc_mimefactory_load_msg(
|
||||
}
|
||||
}
|
||||
stmt = dc_sqlite3_prepare(
|
||||
(*context).sql,
|
||||
context,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
b"SELECT mime_in_reply_to, mime_references FROM msgs WHERE id=?\x00" as *const u8
|
||||
as *const libc::c_char,
|
||||
);
|
||||
@@ -236,19 +244,23 @@ pub unsafe fn dc_mimefactory_load_msg(
|
||||
sqlite3_finalize(stmt);
|
||||
return success;
|
||||
}
|
||||
|
||||
unsafe fn load_from(mut factory: *mut dc_mimefactory_t) {
|
||||
(*factory).from_addr = dc_sqlite3_get_config(
|
||||
(*(*factory).context).sql,
|
||||
(*factory).context,
|
||||
&mut (*factory).context.sql.clone().read().unwrap(),
|
||||
b"configured_addr\x00" as *const u8 as *const libc::c_char,
|
||||
0 as *const libc::c_char,
|
||||
);
|
||||
(*factory).from_displayname = dc_sqlite3_get_config(
|
||||
(*(*factory).context).sql,
|
||||
(*factory).context,
|
||||
&mut (*factory).context.sql.clone().read().unwrap(),
|
||||
b"displayname\x00" as *const u8 as *const libc::c_char,
|
||||
0 as *const libc::c_char,
|
||||
);
|
||||
(*factory).selfstatus = dc_sqlite3_get_config(
|
||||
(*(*factory).context).sql,
|
||||
(*factory).context,
|
||||
&mut (*factory).context.sql.clone().read().unwrap(),
|
||||
b"selfstatus\x00" as *const u8 as *const libc::c_char,
|
||||
0 as *const libc::c_char,
|
||||
);
|
||||
@@ -256,6 +268,7 @@ unsafe fn load_from(mut factory: *mut dc_mimefactory_t) {
|
||||
(*factory).selfstatus = dc_stock_str((*factory).context, 13i32)
|
||||
};
|
||||
}
|
||||
|
||||
pub unsafe fn dc_mimefactory_load_mdn(
|
||||
mut factory: *mut dc_mimefactory_t,
|
||||
mut msg_id: uint32_t,
|
||||
@@ -268,7 +281,8 @@ pub unsafe fn dc_mimefactory_load_mdn(
|
||||
(*factory).msg = dc_msg_new_untyped((*factory).context);
|
||||
if !(0
|
||||
== dc_sqlite3_get_config_int(
|
||||
(*(*factory).context).sql,
|
||||
(*factory).context,
|
||||
&mut (*factory).context.sql.clone().read().unwrap(),
|
||||
b"mdns_enabled\x00" as *const u8 as *const libc::c_char,
|
||||
1i32,
|
||||
))
|
||||
@@ -278,7 +292,7 @@ pub unsafe fn dc_mimefactory_load_mdn(
|
||||
if !(0 == dc_msg_load_from_db((*factory).msg, (*factory).context, msg_id)
|
||||
|| 0 == dc_contact_load_from_db(
|
||||
contact,
|
||||
(*(*factory).context).sql,
|
||||
&mut (*factory).context.sql.clone().read().unwrap(),
|
||||
(*(*factory).msg).from_id,
|
||||
))
|
||||
{
|
||||
@@ -315,12 +329,15 @@ pub unsafe fn dc_mimefactory_load_mdn(
|
||||
}
|
||||
}
|
||||
dc_contact_unref(contact);
|
||||
return success;
|
||||
|
||||
success
|
||||
}
|
||||
|
||||
// TODO should return bool /rtn
|
||||
pub unsafe fn dc_mimefactory_render(mut factory: *mut dc_mimefactory_t) -> libc::c_int {
|
||||
let mut subject: *mut mailimf_subject = 0 as *mut mailimf_subject;
|
||||
let mut subject: *mut mailimf_subject;
|
||||
let mut current_block: u64;
|
||||
let mut imf_fields: *mut mailimf_fields = 0 as *mut mailimf_fields;
|
||||
let mut imf_fields: *mut mailimf_fields;
|
||||
let mut message: *mut mailmime = 0 as *mut mailmime;
|
||||
let mut message_text: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut message_text2: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
@@ -374,8 +391,8 @@ pub unsafe fn dc_mimefactory_render(mut factory: *mut dc_mimefactory_t) -> libc:
|
||||
&& !(*factory).recipients_addr.is_null()
|
||||
&& (*(*factory).recipients_addr).count > 0i32
|
||||
{
|
||||
let mut iter1: *mut clistiter = 0 as *mut clistiter;
|
||||
let mut iter2: *mut clistiter = 0 as *mut clistiter;
|
||||
let mut iter1: *mut clistiter;
|
||||
let mut iter2: *mut clistiter;
|
||||
to = mailimf_address_list_new_empty();
|
||||
iter1 = (*(*factory).recipients_names).first;
|
||||
iter2 = (*(*factory).recipients_addr).first;
|
||||
@@ -408,12 +425,12 @@ pub unsafe fn dc_mimefactory_render(mut factory: *mut dc_mimefactory_t) -> libc:
|
||||
iter1 = if !iter1.is_null() {
|
||||
(*iter1).next
|
||||
} else {
|
||||
0 as *mut clistcell_s
|
||||
0 as *mut clistcell
|
||||
};
|
||||
iter2 = if !iter2.is_null() {
|
||||
(*iter2).next
|
||||
} else {
|
||||
0 as *mut clistcell_s
|
||||
0 as *mut clistcell
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -844,7 +861,6 @@ pub unsafe fn dc_mimefactory_render(mut factory: *mut dc_mimefactory_t) -> libc:
|
||||
} else {
|
||||
if !meta_part.is_null() {
|
||||
mailmime_smart_add_part(message, meta_part);
|
||||
parts += 1
|
||||
}
|
||||
if 0 != dc_param_exists((*msg).param, DC_PARAM_SET_LATITUDE as libc::c_int)
|
||||
{
|
||||
@@ -858,12 +874,8 @@ pub unsafe fn dc_mimefactory_render(mut factory: *mut dc_mimefactory_t) -> libc:
|
||||
DC_PARAM_SET_LONGITUDE as libc::c_int,
|
||||
0.0,
|
||||
);
|
||||
let kml_file = dc_get_message_kml(
|
||||
(*msg).context,
|
||||
(*msg).timestamp_sort,
|
||||
latitude,
|
||||
longitude,
|
||||
);
|
||||
let kml_file =
|
||||
dc_get_message_kml((*msg).timestamp_sort, latitude, longitude);
|
||||
if !kml_file.is_null() {
|
||||
let content_type = mailmime_content_new_with_str(
|
||||
b"application/vnd.google-earth.kml+xml\x00" as *const u8
|
||||
@@ -880,7 +892,6 @@ pub unsafe fn dc_mimefactory_render(mut factory: *mut dc_mimefactory_t) -> libc:
|
||||
mailmime_set_body_text(kml_mime_part, kml_file, strlen(kml_file));
|
||||
|
||||
mailmime_smart_add_part(message, kml_mime_part);
|
||||
parts += 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -909,7 +920,6 @@ pub unsafe fn dc_mimefactory_render(mut factory: *mut dc_mimefactory_t) -> libc:
|
||||
mailmime_new_empty(content_type, mime_fields);
|
||||
mailmime_set_body_text(kml_mime_part, kml_file, strlen(kml_file));
|
||||
mailmime_smart_add_part(message, kml_mime_part);
|
||||
parts += 1;
|
||||
if 0 == dc_param_exists(
|
||||
(*msg).param,
|
||||
DC_PARAM_SET_LATITUDE as libc::c_int,
|
||||
@@ -939,8 +949,8 @@ pub unsafe fn dc_mimefactory_render(mut factory: *mut dc_mimefactory_t) -> libc:
|
||||
) as *mut libc::c_void,
|
||||
);
|
||||
mailmime_add_part(message, multipart);
|
||||
let mut p1: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut p2: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut p1: *mut libc::c_char;
|
||||
let mut p2: *mut libc::c_char;
|
||||
if 0 != dc_param_get_int((*(*factory).msg).param, 'c' as i32, 0i32) {
|
||||
p1 = dc_stock_str((*factory).context, 24i32)
|
||||
} else {
|
||||
@@ -1050,19 +1060,17 @@ pub unsafe fn dc_mimefactory_render(mut factory: *mut dc_mimefactory_t) -> libc:
|
||||
free(message_text2 as *mut libc::c_void);
|
||||
free(subject_str as *mut libc::c_void);
|
||||
free(grpimage as *mut libc::c_void);
|
||||
return success;
|
||||
|
||||
success
|
||||
}
|
||||
|
||||
unsafe fn get_subject(
|
||||
mut chat: *const dc_chat_t,
|
||||
mut msg: *const dc_msg_t,
|
||||
mut afwd_email: libc::c_int,
|
||||
) -> *mut libc::c_char {
|
||||
let mut context: *mut dc_context_t = if !chat.is_null() {
|
||||
(*chat).context
|
||||
} else {
|
||||
0 as *mut dc_context_t
|
||||
};
|
||||
let mut ret: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let context = (*chat).context;
|
||||
let mut ret: *mut libc::c_char;
|
||||
let mut raw_subject: *mut libc::c_char =
|
||||
dc_msg_get_summarytext_by_raw((*msg).type_0, (*msg).text, (*msg).param, 32i32, context);
|
||||
let mut fwd: *const libc::c_char = if 0 != afwd_email {
|
||||
@@ -1087,8 +1095,10 @@ unsafe fn get_subject(
|
||||
)
|
||||
}
|
||||
free(raw_subject as *mut libc::c_void);
|
||||
return ret;
|
||||
|
||||
ret
|
||||
}
|
||||
|
||||
unsafe fn set_error(mut factory: *mut dc_mimefactory_t, mut text: *const libc::c_char) {
|
||||
if factory.is_null() {
|
||||
return;
|
||||
@@ -1096,10 +1106,11 @@ unsafe fn set_error(mut factory: *mut dc_mimefactory_t, mut text: *const libc::c
|
||||
free((*factory).error as *mut libc::c_void);
|
||||
(*factory).error = dc_strdup_keep_null(text);
|
||||
}
|
||||
|
||||
unsafe fn build_body_text(mut text: *mut libc::c_char) -> *mut mailmime {
|
||||
let mut mime_fields: *mut mailmime_fields = 0 as *mut mailmime_fields;
|
||||
let mut message_part: *mut mailmime = 0 as *mut mailmime;
|
||||
let mut content: *mut mailmime_content = 0 as *mut mailmime_content;
|
||||
let mut mime_fields: *mut mailmime_fields;
|
||||
let mut message_part: *mut mailmime;
|
||||
let mut content: *mut mailmime_content;
|
||||
content = mailmime_content_new_with_str(b"text/plain\x00" as *const u8 as *const libc::c_char);
|
||||
clist_insert_after(
|
||||
(*content).ct_parameters,
|
||||
@@ -1112,17 +1123,19 @@ unsafe fn build_body_text(mut text: *mut libc::c_char) -> *mut mailmime {
|
||||
mime_fields = mailmime_fields_new_encoding(MAILMIME_MECHANISM_8BIT as libc::c_int);
|
||||
message_part = mailmime_new_empty(content, mime_fields);
|
||||
mailmime_set_body_text(message_part, text, strlen(text));
|
||||
return message_part;
|
||||
|
||||
message_part
|
||||
}
|
||||
|
||||
unsafe fn build_body_file(
|
||||
mut msg: *const dc_msg_t,
|
||||
mut base_name: *const libc::c_char,
|
||||
mut ret_file_name_as_sent: *mut *mut libc::c_char,
|
||||
) -> *mut mailmime {
|
||||
let mut needs_ext: libc::c_int = 0;
|
||||
let mut mime_fields: *mut mailmime_fields = 0 as *mut mailmime_fields;
|
||||
let mut needs_ext: libc::c_int;
|
||||
let mut mime_fields: *mut mailmime_fields;
|
||||
let mut mime_sub: *mut mailmime = 0 as *mut mailmime;
|
||||
let mut content: *mut mailmime_content = 0 as *mut mailmime_content;
|
||||
let mut content: *mut mailmime_content;
|
||||
let mut pathNfilename: *mut libc::c_char =
|
||||
dc_param_get((*msg).param, 'f' as i32, 0 as *const libc::c_char);
|
||||
let mut mimetype: *mut libc::c_char =
|
||||
@@ -1268,7 +1281,7 @@ unsafe fn build_body_file(
|
||||
cur1 = if !cur1.is_null() {
|
||||
(*cur1).next
|
||||
} else {
|
||||
0 as *mut clistcell_s
|
||||
0 as *mut clistcell
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1295,11 +1308,14 @@ unsafe fn build_body_file(
|
||||
free(filename_to_send as *mut libc::c_void);
|
||||
free(filename_encoded as *mut libc::c_void);
|
||||
free(suffix as *mut libc::c_void);
|
||||
return mime_sub;
|
||||
|
||||
mime_sub
|
||||
}
|
||||
/* ******************************************************************************
|
||||
|
||||
/*******************************************************************************
|
||||
* Render
|
||||
******************************************************************************/
|
||||
|
||||
unsafe fn is_file_size_okay(mut msg: *const dc_msg_t) -> libc::c_int {
|
||||
let mut file_size_okay: libc::c_int = 1i32;
|
||||
let mut pathNfilename: *mut libc::c_char =
|
||||
@@ -1309,5 +1325,6 @@ unsafe fn is_file_size_okay(mut msg: *const dc_msg_t) -> libc::c_int {
|
||||
file_size_okay = 0i32
|
||||
}
|
||||
free(pathNfilename as *mut libc::c_void);
|
||||
return file_size_okay;
|
||||
|
||||
file_size_okay
|
||||
}
|
||||
|
||||
@@ -1,4 +1,12 @@
|
||||
use libc;
|
||||
use mmime::charconv::*;
|
||||
use mmime::mailimf::*;
|
||||
use mmime::mailimf_types::*;
|
||||
use mmime::mailmime::*;
|
||||
use mmime::mailmime_content::*;
|
||||
use mmime::mailmime_disposition::*;
|
||||
use mmime::mailmime_types::*;
|
||||
use mmime::mmapstring::*;
|
||||
use mmime::other::*;
|
||||
|
||||
use crate::dc_contact::*;
|
||||
use crate::dc_context::dc_context_t;
|
||||
@@ -35,7 +43,7 @@ pub struct dc_mimepart_t {
|
||||
*/
|
||||
#[derive(Copy, Clone)]
|
||||
#[repr(C)]
|
||||
pub struct dc_mimeparser_t {
|
||||
pub struct dc_mimeparser_t<'a> {
|
||||
pub parts: *mut carray,
|
||||
pub mimeroot: *mut mailmime,
|
||||
pub header: dc_hash_t,
|
||||
@@ -47,7 +55,7 @@ pub struct dc_mimeparser_t {
|
||||
pub e2ee_helper: *mut dc_e2ee_helper_t,
|
||||
pub blobdir: *const libc::c_char,
|
||||
pub is_forwarded: libc::c_int,
|
||||
pub context: *mut dc_context_t,
|
||||
pub context: &'a dc_context_t,
|
||||
pub reports: *mut carray,
|
||||
pub is_system_message: libc::c_int,
|
||||
pub location_kml: *mut dc_kml_t,
|
||||
@@ -58,13 +66,15 @@ pub struct dc_mimeparser_t {
|
||||
pub unsafe fn dc_no_compound_msgs() {
|
||||
s_generate_compound_msgs = 0i32;
|
||||
}
|
||||
|
||||
// deprecated: flag to switch generation of compound messages on and off.
|
||||
static mut s_generate_compound_msgs: libc::c_int = 1i32;
|
||||
|
||||
pub unsafe fn dc_mimeparser_new(
|
||||
mut blobdir: *const libc::c_char,
|
||||
mut context: *mut dc_context_t,
|
||||
blobdir: *const libc::c_char,
|
||||
context: &dc_context_t,
|
||||
) -> *mut dc_mimeparser_t {
|
||||
let mut mimeparser: *mut dc_mimeparser_t = 0 as *mut dc_mimeparser_t;
|
||||
let mut mimeparser: *mut dc_mimeparser_t;
|
||||
mimeparser = calloc(1, ::std::mem::size_of::<dc_mimeparser_t>()) as *mut dc_mimeparser_t;
|
||||
if mimeparser.is_null() {
|
||||
exit(30i32);
|
||||
@@ -76,8 +86,10 @@ pub unsafe fn dc_mimeparser_new(
|
||||
(*mimeparser).e2ee_helper =
|
||||
calloc(1, ::std::mem::size_of::<dc_e2ee_helper_t>()) as *mut dc_e2ee_helper_t;
|
||||
dc_hash_init(&mut (*mimeparser).header, 3i32, 0i32);
|
||||
return mimeparser;
|
||||
|
||||
mimeparser
|
||||
}
|
||||
|
||||
pub unsafe fn dc_mimeparser_unref(mut mimeparser: *mut dc_mimeparser_t) {
|
||||
if mimeparser.is_null() {
|
||||
return;
|
||||
@@ -98,7 +110,7 @@ pub unsafe fn dc_mimeparser_empty(mut mimeparser: *mut dc_mimeparser_t) {
|
||||
return;
|
||||
}
|
||||
if !(*mimeparser).parts.is_null() {
|
||||
let mut i: libc::c_int = 0;
|
||||
let mut i: libc::c_int;
|
||||
let mut cnt: libc::c_int = carray_count((*mimeparser).parts) as libc::c_int;
|
||||
i = 0i32;
|
||||
while i < cnt {
|
||||
@@ -150,14 +162,15 @@ unsafe fn dc_mimepart_unref(mut mimepart: *mut dc_mimepart_t) {
|
||||
dc_param_unref((*mimepart).param);
|
||||
free(mimepart as *mut libc::c_void);
|
||||
}
|
||||
|
||||
pub unsafe fn dc_mimeparser_parse(
|
||||
mut mimeparser: *mut dc_mimeparser_t,
|
||||
mut body_not_terminated: *const libc::c_char,
|
||||
mut body_bytes: size_t,
|
||||
) {
|
||||
let mut r: libc::c_int = 0i32;
|
||||
let mut r: libc::c_int;
|
||||
let mut index: size_t = 0i32 as size_t;
|
||||
let mut optional_field: *mut mailimf_optional_field = 0 as *mut mailimf_optional_field;
|
||||
let mut optional_field: *mut mailimf_optional_field;
|
||||
dc_mimeparser_empty(mimeparser);
|
||||
r = mailmime_parse(
|
||||
body_not_terminated,
|
||||
@@ -194,7 +207,7 @@ pub unsafe fn dc_mimeparser_parse(
|
||||
)
|
||||
.is_null()
|
||||
{
|
||||
let mut i: libc::c_int = 0;
|
||||
let mut i: libc::c_int;
|
||||
let mut has_setup_file: libc::c_int = 0i32;
|
||||
i = 0i32;
|
||||
while (i as libc::c_uint) < carray_count((*mimeparser).parts) {
|
||||
@@ -303,7 +316,7 @@ pub unsafe fn dc_mimeparser_parse(
|
||||
}
|
||||
dc_trim(subj);
|
||||
if 0 != *subj.offset(0isize) {
|
||||
let mut i_0: libc::c_int = 0;
|
||||
let mut i_0: libc::c_int;
|
||||
let mut icnt: libc::c_int = carray_count((*mimeparser).parts) as libc::c_int;
|
||||
i_0 = 0i32;
|
||||
while i_0 < icnt {
|
||||
@@ -328,7 +341,7 @@ pub unsafe fn dc_mimeparser_parse(
|
||||
}
|
||||
}
|
||||
if 0 != (*mimeparser).is_forwarded {
|
||||
let mut i_1: libc::c_int = 0;
|
||||
let mut i_1: libc::c_int;
|
||||
let mut icnt_0: libc::c_int = carray_count((*mimeparser).parts) as libc::c_int;
|
||||
i_1 = 0i32;
|
||||
while i_1 < icnt_0 {
|
||||
@@ -430,24 +443,26 @@ pub unsafe fn dc_mimeparser_parse(
|
||||
);
|
||||
};
|
||||
}
|
||||
/* ******************************************************************************
|
||||
|
||||
/*******************************************************************************
|
||||
* a MIME part
|
||||
******************************************************************************/
|
||||
unsafe fn dc_mimepart_new() -> *mut dc_mimepart_t {
|
||||
let mut mimepart: *mut dc_mimepart_t = 0 as *mut dc_mimepart_t;
|
||||
let mut mimepart: *mut dc_mimepart_t;
|
||||
mimepart = calloc(1, ::std::mem::size_of::<dc_mimepart_t>()) as *mut dc_mimepart_t;
|
||||
if mimepart.is_null() {
|
||||
exit(33i32);
|
||||
}
|
||||
(*mimepart).type_0 = 0i32;
|
||||
(*mimepart).param = dc_param_new();
|
||||
return mimepart;
|
||||
mimepart
|
||||
}
|
||||
|
||||
pub unsafe fn dc_mimeparser_get_last_nonmeta(
|
||||
mut mimeparser: *mut dc_mimeparser_t,
|
||||
) -> *mut dc_mimepart_t {
|
||||
if !mimeparser.is_null() && !(*mimeparser).parts.is_null() {
|
||||
let mut i: libc::c_int = 0;
|
||||
let mut i: libc::c_int;
|
||||
let mut icnt: libc::c_int = carray_count((*mimeparser).parts) as libc::c_int;
|
||||
i = icnt - 1i32;
|
||||
while i >= 0i32 {
|
||||
@@ -459,8 +474,10 @@ pub unsafe fn dc_mimeparser_get_last_nonmeta(
|
||||
i -= 1
|
||||
}
|
||||
}
|
||||
return 0 as *mut dc_mimepart_t;
|
||||
|
||||
0 as *mut dc_mimepart_t
|
||||
}
|
||||
|
||||
/*the result must be freed*/
|
||||
pub unsafe fn mailimf_find_first_addr(
|
||||
mut mb_list: *const mailimf_mailbox_list,
|
||||
@@ -481,22 +498,25 @@ pub unsafe fn mailimf_find_first_addr(
|
||||
cur = if !cur.is_null() {
|
||||
(*cur).next
|
||||
} else {
|
||||
0 as *mut clistcell_s
|
||||
0 as *mut clistcell
|
||||
}
|
||||
}
|
||||
return 0 as *mut libc::c_char;
|
||||
|
||||
0 as *mut libc::c_char
|
||||
}
|
||||
|
||||
/* the following functions can be used only after a call to dc_mimeparser_parse() */
|
||||
pub unsafe fn dc_mimeparser_lookup_field(
|
||||
mut mimeparser: *mut dc_mimeparser_t,
|
||||
mut field_name: *const libc::c_char,
|
||||
) -> *mut mailimf_field {
|
||||
return dc_hash_find(
|
||||
dc_hash_find(
|
||||
&mut (*mimeparser).header,
|
||||
field_name as *const libc::c_void,
|
||||
strlen(field_name) as libc::c_int,
|
||||
) as *mut mailimf_field;
|
||||
) as *mut mailimf_field
|
||||
}
|
||||
|
||||
pub unsafe fn dc_mimeparser_lookup_optional_field(
|
||||
mut mimeparser: *mut dc_mimeparser_t,
|
||||
mut field_name: *const libc::c_char,
|
||||
@@ -509,14 +529,16 @@ pub unsafe fn dc_mimeparser_lookup_optional_field(
|
||||
if !field.is_null() && (*field).fld_type == MAILIMF_FIELD_OPTIONAL_FIELD as libc::c_int {
|
||||
return (*field).fld_data.fld_optional_field;
|
||||
}
|
||||
return 0 as *mut mailimf_optional_field;
|
||||
|
||||
0 as *mut mailimf_optional_field
|
||||
}
|
||||
|
||||
unsafe fn dc_mimeparser_parse_mime_recursive(
|
||||
mut mimeparser: *mut dc_mimeparser_t,
|
||||
mut mime: *mut mailmime,
|
||||
) -> libc::c_int {
|
||||
let mut any_part_added: libc::c_int = 0i32;
|
||||
let mut cur: *mut clistiter = 0 as *mut clistiter;
|
||||
let mut cur: *mut clistiter;
|
||||
if mimeparser.is_null() || mime.is_null() {
|
||||
return 0i32;
|
||||
}
|
||||
@@ -577,6 +599,7 @@ unsafe fn dc_mimeparser_parse_mime_recursive(
|
||||
}
|
||||
}
|
||||
match (*mime).mm_type {
|
||||
// TODO match on enums /rtn
|
||||
1 => any_part_added = dc_mimeparser_add_single_part_if_known(mimeparser, mime),
|
||||
2 => {
|
||||
match mailmime_get_mime_type(mime, 0 as *mut libc::c_int, 0 as *mut *mut libc::c_char) {
|
||||
@@ -602,7 +625,7 @@ unsafe fn dc_mimeparser_parse_mime_recursive(
|
||||
cur = if !cur.is_null() {
|
||||
(*cur).next
|
||||
} else {
|
||||
0 as *mut clistcell_s
|
||||
0 as *mut clistcell
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -628,7 +651,7 @@ unsafe fn dc_mimeparser_parse_mime_recursive(
|
||||
cur = if !cur.is_null() {
|
||||
(*cur).next
|
||||
} else {
|
||||
0 as *mut clistcell_s
|
||||
0 as *mut clistcell
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -651,7 +674,7 @@ unsafe fn dc_mimeparser_parse_mime_recursive(
|
||||
cur = if !cur.is_null() {
|
||||
(*cur).next
|
||||
} else {
|
||||
0 as *mut clistcell_s
|
||||
0 as *mut clistcell
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -762,7 +785,7 @@ unsafe fn dc_mimeparser_parse_mime_recursive(
|
||||
cur = if !cur.is_null() {
|
||||
(*cur).next
|
||||
} else {
|
||||
0 as *mut clistcell_s
|
||||
0 as *mut clistcell
|
||||
}
|
||||
}
|
||||
if plain_cnt == 1i32 && html_cnt == 1i32 {
|
||||
@@ -788,7 +811,7 @@ unsafe fn dc_mimeparser_parse_mime_recursive(
|
||||
cur = if !cur.is_null() {
|
||||
(*cur).next
|
||||
} else {
|
||||
0 as *mut clistcell_s
|
||||
0 as *mut clistcell
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -812,13 +835,11 @@ unsafe fn dc_mimeparser_parse_mime_recursive(
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
return any_part_added;
|
||||
|
||||
any_part_added
|
||||
}
|
||||
unsafe fn hash_header(
|
||||
out: *mut dc_hash_t,
|
||||
in_0: *const mailimf_fields,
|
||||
_context: *mut dc_context_t,
|
||||
) {
|
||||
|
||||
unsafe fn hash_header(out: *mut dc_hash_t, in_0: *const mailimf_fields, _context: &dc_context_t) {
|
||||
if in_0.is_null() {
|
||||
return;
|
||||
}
|
||||
@@ -830,6 +851,7 @@ unsafe fn hash_header(
|
||||
0 as *mut libc::c_void
|
||||
}) as *mut mailimf_field;
|
||||
let mut key: *const libc::c_char = 0 as *const libc::c_char;
|
||||
// TODO match on enums /rtn
|
||||
match (*field).fld_type {
|
||||
1 => key = b"Return-Path\x00" as *const u8 as *const libc::c_char,
|
||||
9 => key = b"Date\x00" as *const u8 as *const libc::c_char,
|
||||
@@ -879,10 +901,11 @@ unsafe fn hash_header(
|
||||
cur1 = if !cur1.is_null() {
|
||||
(*cur1).next
|
||||
} else {
|
||||
0 as *mut clistcell_s
|
||||
0 as *mut clistcell
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unsafe fn mailmime_get_mime_type(
|
||||
mut mime: *mut mailmime,
|
||||
mut msg_type: *mut libc::c_int,
|
||||
@@ -897,6 +920,7 @@ unsafe fn mailmime_get_mime_type(
|
||||
if c.is_null() || (*c).ct_type.is_null() {
|
||||
return 0i32;
|
||||
}
|
||||
// TODO match on enums /rtn
|
||||
match (*(*c).ct_type).tp_type {
|
||||
1 => match (*(*(*c).ct_type).tp_data.tp_discrete_type).dt_type {
|
||||
1 => {
|
||||
@@ -1051,8 +1075,10 @@ unsafe fn mailmime_get_mime_type(
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
return 0i32;
|
||||
|
||||
0
|
||||
}
|
||||
|
||||
unsafe fn reconcat_mime(
|
||||
mut raw_mime: *mut *mut libc::c_char,
|
||||
mut type_0: *const libc::c_char,
|
||||
@@ -1074,6 +1100,7 @@ unsafe fn reconcat_mime(
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
unsafe fn mailmime_is_attachment_disposition(mut mime: *mut mailmime) -> libc::c_int {
|
||||
if !(*mime).mm_mime_fields.is_null() {
|
||||
let mut cur: *mut clistiter = (*(*(*mime).mm_mime_fields).fld_list).first;
|
||||
@@ -1097,12 +1124,14 @@ unsafe fn mailmime_is_attachment_disposition(mut mime: *mut mailmime) -> libc::c
|
||||
cur = if !cur.is_null() {
|
||||
(*cur).next
|
||||
} else {
|
||||
0 as *mut clistcell_s
|
||||
0 as *mut clistcell
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0i32;
|
||||
|
||||
0
|
||||
}
|
||||
|
||||
/* low-level-tools for working with mailmime structures directly */
|
||||
pub unsafe fn mailmime_find_ct_parameter(
|
||||
mut mime: *mut mailmime,
|
||||
@@ -1115,7 +1144,7 @@ pub unsafe fn mailmime_find_ct_parameter(
|
||||
{
|
||||
return 0 as *mut mailmime_parameter;
|
||||
}
|
||||
let mut cur: *mut clistiter = 0 as *mut clistiter;
|
||||
let mut cur: *mut clistiter;
|
||||
cur = (*(*(*mime).mm_content_type).ct_parameters).first;
|
||||
while !cur.is_null() {
|
||||
let mut param: *mut mailmime_parameter = (if !cur.is_null() {
|
||||
@@ -1131,11 +1160,13 @@ pub unsafe fn mailmime_find_ct_parameter(
|
||||
cur = if !cur.is_null() {
|
||||
(*cur).next
|
||||
} else {
|
||||
0 as *mut clistcell_s
|
||||
0 as *mut clistcell
|
||||
}
|
||||
}
|
||||
return 0 as *mut mailmime_parameter;
|
||||
|
||||
0 as *mut mailmime_parameter
|
||||
}
|
||||
|
||||
unsafe fn dc_mimeparser_add_single_part_if_known(
|
||||
mut mimeparser: *mut dc_mimeparser_t,
|
||||
mut mime: *mut mailmime,
|
||||
@@ -1143,8 +1174,8 @@ unsafe fn dc_mimeparser_add_single_part_if_known(
|
||||
let mut current_block: u64;
|
||||
let mut part: *mut dc_mimepart_t = 0 as *mut dc_mimepart_t;
|
||||
let mut old_part_count: libc::c_int = carray_count((*mimeparser).parts) as libc::c_int;
|
||||
let mut mime_type: libc::c_int = 0;
|
||||
let mut mime_data: *mut mailmime_data = 0 as *mut mailmime_data;
|
||||
let mut mime_type: libc::c_int;
|
||||
let mut mime_data: *mut mailmime_data;
|
||||
let mut file_suffix: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut desired_filename: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut msg_type: libc::c_int = 0i32;
|
||||
@@ -1187,6 +1218,7 @@ unsafe fn dc_mimeparser_add_single_part_if_known(
|
||||
} else {
|
||||
current_block = 13797916685926291137;
|
||||
}
|
||||
// TODO match on enums /rtn
|
||||
match current_block {
|
||||
8795901732489102124 => {}
|
||||
_ => {
|
||||
@@ -1346,7 +1378,7 @@ unsafe fn dc_mimeparser_add_single_part_if_known(
|
||||
cur2 = if !cur2.is_null() {
|
||||
(*cur2).next
|
||||
} else {
|
||||
0 as *mut clistcell_s
|
||||
0 as *mut clistcell
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1355,7 +1387,7 @@ unsafe fn dc_mimeparser_add_single_part_if_known(
|
||||
cur1 = if !cur1.is_null() {
|
||||
(*cur1).next
|
||||
} else {
|
||||
0 as *mut clistcell_s
|
||||
0 as *mut clistcell
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1478,6 +1510,7 @@ unsafe fn dc_mimeparser_add_single_part_if_known(
|
||||
0i32
|
||||
};
|
||||
}
|
||||
|
||||
unsafe fn do_add_single_file_part(
|
||||
mut parser: *mut dc_mimeparser_t,
|
||||
mut msg_type: libc::c_int,
|
||||
@@ -1488,7 +1521,7 @@ unsafe fn do_add_single_file_part(
|
||||
mut desired_filename: *const libc::c_char,
|
||||
) {
|
||||
let mut part: *mut dc_mimepart_t = 0 as *mut dc_mimepart_t;
|
||||
let mut pathNfilename: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut pathNfilename: *mut libc::c_char;
|
||||
/* create a free file name to use */
|
||||
pathNfilename = dc_get_fine_pathNfilename(
|
||||
(*parser).context,
|
||||
@@ -1530,6 +1563,7 @@ unsafe fn do_add_single_file_part(
|
||||
free(pathNfilename as *mut libc::c_void);
|
||||
dc_mimepart_unref(part);
|
||||
}
|
||||
|
||||
unsafe fn do_add_single_part(mut parser: *mut dc_mimeparser_t, mut part: *mut dc_mimepart_t) {
|
||||
if 0 != (*(*parser).e2ee_helper).encrypted
|
||||
&& (*(*(*parser).e2ee_helper).signatures).count > 0i32
|
||||
@@ -1544,6 +1578,8 @@ unsafe fn do_add_single_part(mut parser: *mut dc_mimeparser_t, mut part: *mut dc
|
||||
0 as *mut libc::c_uint,
|
||||
);
|
||||
}
|
||||
|
||||
// TODO should return bool /rtn
|
||||
pub unsafe fn mailmime_transfer_decode(
|
||||
mut mime: *mut mailmime,
|
||||
mut ret_decoded_data: *mut *const libc::c_char,
|
||||
@@ -1551,9 +1587,9 @@ pub unsafe fn mailmime_transfer_decode(
|
||||
mut ret_to_mmap_string_unref: *mut *mut libc::c_char,
|
||||
) -> libc::c_int {
|
||||
let mut mime_transfer_encoding: libc::c_int = MAILMIME_MECHANISM_BINARY as libc::c_int;
|
||||
let mut mime_data: *mut mailmime_data = 0 as *mut mailmime_data;
|
||||
let mut mime_data: *mut mailmime_data;
|
||||
/* must not be free()'d */
|
||||
let mut decoded_data: *const libc::c_char = 0 as *const libc::c_char;
|
||||
let mut decoded_data: *const libc::c_char;
|
||||
let mut decoded_data_bytes: size_t = 0i32 as size_t;
|
||||
/* mmap_string_unref()'d if set */
|
||||
let mut transfer_decoding_buffer: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
@@ -1569,7 +1605,7 @@ pub unsafe fn mailmime_transfer_decode(
|
||||
}
|
||||
mime_data = (*mime).mm_data.mm_single;
|
||||
if !(*mime).mm_mime_fields.is_null() {
|
||||
let mut cur: *mut clistiter = 0 as *mut clistiter;
|
||||
let mut cur: *mut clistiter;
|
||||
cur = (*(*(*mime).mm_mime_fields).fld_list).first;
|
||||
while !cur.is_null() {
|
||||
let mut field: *mut mailmime_field = (if !cur.is_null() {
|
||||
@@ -1587,7 +1623,7 @@ pub unsafe fn mailmime_transfer_decode(
|
||||
cur = if !cur.is_null() {
|
||||
(*cur).next
|
||||
} else {
|
||||
0 as *mut clistcell_s
|
||||
0 as *mut clistcell
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1602,7 +1638,7 @@ pub unsafe fn mailmime_transfer_decode(
|
||||
return 0i32;
|
||||
}
|
||||
} else {
|
||||
let mut r: libc::c_int = 0;
|
||||
let mut r: libc::c_int;
|
||||
let mut current_index: size_t = 0i32 as size_t;
|
||||
r = mailmime_part_parse(
|
||||
(*mime_data).dt_data.dt_text.dt_data,
|
||||
@@ -1623,8 +1659,11 @@ pub unsafe fn mailmime_transfer_decode(
|
||||
*ret_decoded_data = decoded_data;
|
||||
*ret_decoded_data_bytes = decoded_data_bytes;
|
||||
*ret_to_mmap_string_unref = transfer_decoding_buffer;
|
||||
return 1i32;
|
||||
|
||||
1
|
||||
}
|
||||
|
||||
// TODO should return bool /rtn
|
||||
pub unsafe fn dc_mimeparser_is_mailinglist_message(
|
||||
mut mimeparser: *mut dc_mimeparser_t,
|
||||
) -> libc::c_int {
|
||||
@@ -1656,15 +1695,17 @@ pub unsafe fn dc_mimeparser_is_mailinglist_message(
|
||||
return 1i32;
|
||||
}
|
||||
}
|
||||
return 0i32;
|
||||
|
||||
0
|
||||
}
|
||||
|
||||
pub unsafe fn dc_mimeparser_sender_equals_recipient(
|
||||
mut mimeparser: *mut dc_mimeparser_t,
|
||||
) -> libc::c_int {
|
||||
let mut sender_equals_recipient: libc::c_int = 0i32;
|
||||
let mut fld: *const mailimf_field = 0 as *const mailimf_field;
|
||||
let mut fld: *const mailimf_field;
|
||||
let mut fld_from: *const mailimf_from = 0 as *const mailimf_from;
|
||||
let mut mb: *mut mailimf_mailbox = 0 as *mut mailimf_mailbox;
|
||||
let mut mb: *mut mailimf_mailbox;
|
||||
let mut from_addr_norm: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut recipients: *mut dc_hash_t = 0 as *mut dc_hash_t;
|
||||
if !(mimeparser.is_null() || (*mimeparser).header_root.is_null()) {
|
||||
@@ -1704,14 +1745,16 @@ pub unsafe fn dc_mimeparser_sender_equals_recipient(
|
||||
dc_hash_clear(recipients);
|
||||
free(recipients as *mut libc::c_void);
|
||||
free(from_addr_norm as *mut libc::c_void);
|
||||
return sender_equals_recipient;
|
||||
|
||||
sender_equals_recipient
|
||||
}
|
||||
|
||||
pub unsafe fn mailimf_get_recipients(mut imffields: *mut mailimf_fields) -> *mut dc_hash_t {
|
||||
/* the returned value must be dc_hash_clear()'d and free()'d. returned addresses are normalized. */
|
||||
let mut recipients: *mut dc_hash_t =
|
||||
malloc(::std::mem::size_of::<dc_hash_t>()) as *mut dc_hash_t;
|
||||
dc_hash_init(recipients, 3i32, 1i32);
|
||||
let mut cur1: *mut clistiter = 0 as *mut clistiter;
|
||||
let mut cur1: *mut clistiter;
|
||||
cur1 = (*(*imffields).fld_list).first;
|
||||
while !cur1.is_null() {
|
||||
let mut fld: *mut mailimf_field = (if !cur1.is_null() {
|
||||
@@ -1719,9 +1762,10 @@ pub unsafe fn mailimf_get_recipients(mut imffields: *mut mailimf_fields) -> *mut
|
||||
} else {
|
||||
0 as *mut libc::c_void
|
||||
}) as *mut mailimf_field;
|
||||
let mut fld_to: *mut mailimf_to = 0 as *mut mailimf_to;
|
||||
let mut fld_cc: *mut mailimf_cc = 0 as *mut mailimf_cc;
|
||||
let mut fld_to: *mut mailimf_to;
|
||||
let mut fld_cc: *mut mailimf_cc;
|
||||
let mut addr_list: *mut mailimf_address_list = 0 as *mut mailimf_address_list;
|
||||
// TODO match on enums /rtn
|
||||
match (*fld).fld_type {
|
||||
13 => {
|
||||
fld_to = (*fld).fld_data.fld_to;
|
||||
@@ -1738,7 +1782,7 @@ pub unsafe fn mailimf_get_recipients(mut imffields: *mut mailimf_fields) -> *mut
|
||||
_ => {}
|
||||
}
|
||||
if !addr_list.is_null() {
|
||||
let mut cur2: *mut clistiter = 0 as *mut clistiter;
|
||||
let mut cur2: *mut clistiter;
|
||||
cur2 = (*(*addr_list).ad_list).first;
|
||||
while !cur2.is_null() {
|
||||
let mut adr: *mut mailimf_address = (if !cur2.is_null() {
|
||||
@@ -1752,7 +1796,7 @@ pub unsafe fn mailimf_get_recipients(mut imffields: *mut mailimf_fields) -> *mut
|
||||
} else if (*adr).ad_type == MAILIMF_ADDRESS_GROUP as libc::c_int {
|
||||
let mut group: *mut mailimf_group = (*adr).ad_data.ad_group;
|
||||
if !group.is_null() && !(*group).grp_mb_list.is_null() {
|
||||
let mut cur3: *mut clistiter = 0 as *mut clistiter;
|
||||
let mut cur3: *mut clistiter;
|
||||
cur3 = (*(*(*group).grp_mb_list).mb_list).first;
|
||||
while !cur3.is_null() {
|
||||
mailimf_get_recipients__add_addr(
|
||||
@@ -1766,7 +1810,7 @@ pub unsafe fn mailimf_get_recipients(mut imffields: *mut mailimf_fields) -> *mut
|
||||
cur3 = if !cur3.is_null() {
|
||||
(*cur3).next
|
||||
} else {
|
||||
0 as *mut clistcell_s
|
||||
0 as *mut clistcell
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1775,18 +1819,20 @@ pub unsafe fn mailimf_get_recipients(mut imffields: *mut mailimf_fields) -> *mut
|
||||
cur2 = if !cur2.is_null() {
|
||||
(*cur2).next
|
||||
} else {
|
||||
0 as *mut clistcell_s
|
||||
0 as *mut clistcell
|
||||
}
|
||||
}
|
||||
}
|
||||
cur1 = if !cur1.is_null() {
|
||||
(*cur1).next
|
||||
} else {
|
||||
0 as *mut clistcell_s
|
||||
0 as *mut clistcell
|
||||
}
|
||||
}
|
||||
return recipients;
|
||||
|
||||
recipients
|
||||
}
|
||||
|
||||
/* ******************************************************************************
|
||||
* debug output
|
||||
******************************************************************************/
|
||||
@@ -1809,6 +1855,7 @@ unsafe fn mailimf_get_recipients__add_addr(
|
||||
free(addr_norm as *mut libc::c_void);
|
||||
};
|
||||
}
|
||||
|
||||
/*the result is a pointer to mime, must not be freed*/
|
||||
pub unsafe fn mailimf_find_field(
|
||||
mut header: *mut mailimf_fields,
|
||||
@@ -1832,17 +1879,19 @@ pub unsafe fn mailimf_find_field(
|
||||
cur1 = if !cur1.is_null() {
|
||||
(*cur1).next
|
||||
} else {
|
||||
0 as *mut clistcell_s
|
||||
0 as *mut clistcell
|
||||
}
|
||||
}
|
||||
return 0 as *mut mailimf_field;
|
||||
|
||||
0 as *mut mailimf_field
|
||||
}
|
||||
|
||||
pub unsafe fn dc_mimeparser_repl_msg_by_error(
|
||||
mut mimeparser: *mut dc_mimeparser_t,
|
||||
mut error_msg: *const libc::c_char,
|
||||
) {
|
||||
let mut part: *mut dc_mimepart_t = 0 as *mut dc_mimepart_t;
|
||||
let mut i: libc::c_int = 0i32;
|
||||
let mut part: *mut dc_mimepart_t;
|
||||
let mut i: libc::c_int;
|
||||
if mimeparser.is_null()
|
||||
|| (*mimeparser).parts.is_null()
|
||||
|| carray_count((*mimeparser).parts) <= 0i32 as libc::c_uint
|
||||
@@ -1863,11 +1912,13 @@ pub unsafe fn dc_mimeparser_repl_msg_by_error(
|
||||
}
|
||||
carray_set_size((*mimeparser).parts, 1i32 as libc::c_uint);
|
||||
}
|
||||
|
||||
/*the result is a pointer to mime, must not be freed*/
|
||||
pub unsafe fn mailmime_find_mailimf_fields(mut mime: *mut mailmime) -> *mut mailimf_fields {
|
||||
if mime.is_null() {
|
||||
return 0 as *mut mailimf_fields;
|
||||
}
|
||||
// TODO match on enums
|
||||
match (*mime).mm_type {
|
||||
2 => {
|
||||
let mut cur: *mut clistiter = (*(*mime).mm_data.mm_multipart.mm_mp_list).first;
|
||||
@@ -1885,15 +1936,17 @@ pub unsafe fn mailmime_find_mailimf_fields(mut mime: *mut mailmime) -> *mut mail
|
||||
cur = if !cur.is_null() {
|
||||
(*cur).next
|
||||
} else {
|
||||
0 as *mut clistcell_s
|
||||
0 as *mut clistcell
|
||||
}
|
||||
}
|
||||
}
|
||||
3 => return (*mime).mm_data.mm_message.mm_fields,
|
||||
_ => {}
|
||||
}
|
||||
return 0 as *mut mailimf_fields;
|
||||
|
||||
0 as *mut mailimf_fields
|
||||
}
|
||||
|
||||
pub unsafe fn mailimf_find_optional_field(
|
||||
mut header: *mut mailimf_fields,
|
||||
mut wanted_fld_name: *const libc::c_char,
|
||||
@@ -1922,8 +1975,9 @@ pub unsafe fn mailimf_find_optional_field(
|
||||
cur1 = if !cur1.is_null() {
|
||||
(*cur1).next
|
||||
} else {
|
||||
0 as *mut clistcell_s
|
||||
0 as *mut clistcell
|
||||
}
|
||||
}
|
||||
return 0 as *mut mailimf_optional_field;
|
||||
|
||||
0 as *mut mailimf_optional_field
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
use libc;
|
||||
|
||||
use crate::constants::*;
|
||||
use crate::dc_context::*;
|
||||
use crate::dc_job::*;
|
||||
use crate::dc_msg::*;
|
||||
@@ -7,7 +6,7 @@ use crate::dc_sqlite3::*;
|
||||
use crate::types::*;
|
||||
|
||||
pub unsafe fn dc_do_heuristics_moves(
|
||||
mut context: *mut dc_context_t,
|
||||
mut context: &dc_context_t,
|
||||
mut folder: *const libc::c_char,
|
||||
mut msg_id: uint32_t,
|
||||
) {
|
||||
@@ -15,7 +14,8 @@ pub unsafe fn dc_do_heuristics_moves(
|
||||
let mut msg: *mut dc_msg_t = 0 as *mut dc_msg_t;
|
||||
let mut stmt: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt;
|
||||
if !(dc_sqlite3_get_config_int(
|
||||
(*context).sql,
|
||||
context,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
b"mvbox_move\x00" as *const u8 as *const libc::c_char,
|
||||
1i32,
|
||||
) == 0i32)
|
||||
|
||||
876
src/dc_msg.rs
876
src/dc_msg.rs
File diff suppressed because it is too large
Load Diff
129
src/dc_oauth2.rs
129
src/dc_oauth2.rs
@@ -1,5 +1,3 @@
|
||||
use libc;
|
||||
|
||||
use crate::constants::Event;
|
||||
use crate::dc_contact::*;
|
||||
use crate::dc_context::dc_context_t;
|
||||
@@ -22,21 +20,18 @@ pub struct oauth2_t {
|
||||
}
|
||||
|
||||
pub unsafe fn dc_get_oauth2_url(
|
||||
mut context: *mut dc_context_t,
|
||||
mut context: &dc_context_t,
|
||||
mut addr: *const libc::c_char,
|
||||
mut redirect_uri: *const libc::c_char,
|
||||
) -> *mut libc::c_char {
|
||||
let mut oauth2: *mut oauth2_t = 0 as *mut oauth2_t;
|
||||
let mut oauth2_url: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
if !(context.is_null()
|
||||
|| (*context).magic != 0x11a11807i32 as libc::c_uint
|
||||
|| redirect_uri.is_null()
|
||||
|| *redirect_uri.offset(0isize) as libc::c_int == 0i32)
|
||||
{
|
||||
if !(redirect_uri.is_null() || *redirect_uri.offset(0isize) as libc::c_int == 0i32) {
|
||||
oauth2 = get_info(addr);
|
||||
if !oauth2.is_null() {
|
||||
dc_sqlite3_set_config(
|
||||
(*context).sql,
|
||||
context,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
b"oauth2_pending_redirect_uri\x00" as *const u8 as *const libc::c_char,
|
||||
redirect_uri,
|
||||
);
|
||||
@@ -54,8 +49,10 @@ pub unsafe fn dc_get_oauth2_url(
|
||||
}
|
||||
}
|
||||
free(oauth2 as *mut libc::c_void);
|
||||
return oauth2_url;
|
||||
|
||||
oauth2_url
|
||||
}
|
||||
|
||||
unsafe fn replace_in_uri(
|
||||
mut uri: *mut *mut libc::c_char,
|
||||
mut key: *const libc::c_char,
|
||||
@@ -67,10 +64,11 @@ unsafe fn replace_in_uri(
|
||||
free(value_urlencoded as *mut libc::c_void);
|
||||
};
|
||||
}
|
||||
|
||||
unsafe fn get_info(mut addr: *const libc::c_char) -> *mut oauth2_t {
|
||||
let mut oauth2: *mut oauth2_t = 0 as *mut oauth2_t;
|
||||
let mut addr_normalized: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut domain: *const libc::c_char = 0 as *const libc::c_char;
|
||||
let mut addr_normalized: *mut libc::c_char;
|
||||
let mut domain: *const libc::c_char;
|
||||
addr_normalized = dc_addr_normalize(addr);
|
||||
domain = strchr(addr_normalized, '@' as i32);
|
||||
if !(domain.is_null() || *domain.offset(0isize) as libc::c_int == 0i32) {
|
||||
@@ -119,12 +117,14 @@ unsafe fn get_info(mut addr: *const libc::c_char) -> *mut oauth2_t {
|
||||
}
|
||||
}
|
||||
free(addr_normalized as *mut libc::c_void);
|
||||
return oauth2;
|
||||
|
||||
oauth2
|
||||
}
|
||||
|
||||
// the following function may block due http-requests;
|
||||
// must not be called from the main thread or by the ui!
|
||||
pub unsafe fn dc_get_oauth2_access_token(
|
||||
mut context: *mut dc_context_t,
|
||||
mut context: &dc_context_t,
|
||||
mut addr: *const libc::c_char,
|
||||
mut code: *const libc::c_char,
|
||||
mut flags: libc::c_int,
|
||||
@@ -153,13 +153,8 @@ pub unsafe fn dc_get_oauth2_access_token(
|
||||
end: 0,
|
||||
size: 0,
|
||||
}; 128];
|
||||
let mut tok_cnt: libc::c_int = 0i32;
|
||||
let mut locked: libc::c_int = 0i32;
|
||||
if context.is_null()
|
||||
|| (*context).magic != 0x11a11807i32 as libc::c_uint
|
||||
|| code.is_null()
|
||||
|| *code.offset(0isize) as libc::c_int == 0i32
|
||||
{
|
||||
let mut tok_cnt: libc::c_int;
|
||||
if code.is_null() || *code.offset(0isize) as libc::c_int == 0i32 {
|
||||
dc_log_warning(
|
||||
context,
|
||||
0i32,
|
||||
@@ -174,12 +169,14 @@ pub unsafe fn dc_get_oauth2_access_token(
|
||||
b"Internal OAuth2 error: 2\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
} else {
|
||||
pthread_mutex_lock(&mut (*context).oauth2_critical);
|
||||
locked = 1i32;
|
||||
let lock = context.oauth2_critical.clone();
|
||||
|
||||
let l = lock.lock().unwrap();
|
||||
// read generated token
|
||||
if 0 == flags & 0x1i32 && 0 == is_expired(context) {
|
||||
access_token = dc_sqlite3_get_config(
|
||||
(*context).sql,
|
||||
context,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
b"oauth2_access_token\x00" as *const u8 as *const libc::c_char,
|
||||
0 as *const libc::c_char,
|
||||
);
|
||||
@@ -196,12 +193,14 @@ pub unsafe fn dc_get_oauth2_access_token(
|
||||
16914036240511706173 => {}
|
||||
_ => {
|
||||
refresh_token = dc_sqlite3_get_config(
|
||||
(*context).sql,
|
||||
context,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
b"oauth2_refresh_token\x00" as *const u8 as *const libc::c_char,
|
||||
0 as *const libc::c_char,
|
||||
);
|
||||
refresh_token_for = dc_sqlite3_get_config(
|
||||
(*context).sql,
|
||||
context,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
b"oauth2_refresh_token_for\x00" as *const u8 as *const libc::c_char,
|
||||
b"unset\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
@@ -213,7 +212,8 @@ pub unsafe fn dc_get_oauth2_access_token(
|
||||
as *const libc::c_char,
|
||||
);
|
||||
redirect_uri = dc_sqlite3_get_config(
|
||||
(*context).sql,
|
||||
context,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
b"oauth2_pending_redirect_uri\x00" as *const u8 as *const libc::c_char,
|
||||
b"unset\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
@@ -227,7 +227,8 @@ pub unsafe fn dc_get_oauth2_access_token(
|
||||
as *const libc::c_char,
|
||||
);
|
||||
redirect_uri = dc_sqlite3_get_config(
|
||||
(*context).sql,
|
||||
context,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
b"oauth2_redirect_uri\x00" as *const u8 as *const libc::c_char,
|
||||
b"unset\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
@@ -253,7 +254,7 @@ pub unsafe fn dc_get_oauth2_access_token(
|
||||
b"$REFRESH_TOKEN\x00" as *const u8 as *const libc::c_char,
|
||||
refresh_token,
|
||||
);
|
||||
json = ((*context).cb)(
|
||||
json = (context.cb)(
|
||||
context,
|
||||
Event::HTTP_POST,
|
||||
token_url as uintptr_t,
|
||||
@@ -381,12 +382,14 @@ pub unsafe fn dc_get_oauth2_access_token(
|
||||
&& 0 != *refresh_token.offset(0isize) as libc::c_int
|
||||
{
|
||||
dc_sqlite3_set_config(
|
||||
(*context).sql,
|
||||
context,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
b"oauth2_refresh_token\x00" as *const u8 as *const libc::c_char,
|
||||
refresh_token,
|
||||
);
|
||||
dc_sqlite3_set_config(
|
||||
(*context).sql,
|
||||
context,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
b"oauth2_refresh_token_for\x00" as *const u8
|
||||
as *const libc::c_char,
|
||||
code,
|
||||
@@ -405,12 +408,14 @@ pub unsafe fn dc_get_oauth2_access_token(
|
||||
);
|
||||
} else {
|
||||
dc_sqlite3_set_config(
|
||||
(*context).sql,
|
||||
context,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
b"oauth2_access_token\x00" as *const u8 as *const libc::c_char,
|
||||
access_token,
|
||||
);
|
||||
dc_sqlite3_set_config_int64(
|
||||
(*context).sql,
|
||||
context,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
b"oauth2_timestamp_expires\x00" as *const u8
|
||||
as *const libc::c_char,
|
||||
(if 0 != expires_in {
|
||||
@@ -421,7 +426,8 @@ pub unsafe fn dc_get_oauth2_access_token(
|
||||
);
|
||||
if 0 != update_redirect_uri_on_success {
|
||||
dc_sqlite3_set_config(
|
||||
(*context).sql,
|
||||
context,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
b"oauth2_redirect_uri\x00" as *const u8
|
||||
as *const libc::c_char,
|
||||
redirect_uri,
|
||||
@@ -432,11 +438,9 @@ pub unsafe fn dc_get_oauth2_access_token(
|
||||
}
|
||||
}
|
||||
}
|
||||
drop(l);
|
||||
}
|
||||
}
|
||||
if 0 != locked {
|
||||
pthread_mutex_unlock(&mut (*context).oauth2_critical);
|
||||
}
|
||||
free(refresh_token as *mut libc::c_void);
|
||||
free(refresh_token_for as *mut libc::c_void);
|
||||
free(redirect_uri as *mut libc::c_void);
|
||||
@@ -451,6 +455,7 @@ pub unsafe fn dc_get_oauth2_access_token(
|
||||
dc_strdup(0 as *const libc::c_char)
|
||||
};
|
||||
}
|
||||
|
||||
unsafe fn jsondup(mut json: *const libc::c_char, mut tok: *mut jsmntok_t) -> *mut libc::c_char {
|
||||
if (*tok).type_0 as libc::c_uint == JSMN_STRING as libc::c_int as libc::c_uint
|
||||
|| (*tok).type_0 as libc::c_uint == JSMN_PRIMITIVE as libc::c_int as libc::c_uint
|
||||
@@ -460,8 +465,10 @@ unsafe fn jsondup(mut json: *const libc::c_char, mut tok: *mut jsmntok_t) -> *mu
|
||||
((*tok).end - (*tok).start) as libc::c_ulong,
|
||||
);
|
||||
}
|
||||
return strdup(b"\x00" as *const u8 as *const libc::c_char);
|
||||
|
||||
strdup(b"\x00" as *const u8 as *const libc::c_char)
|
||||
}
|
||||
|
||||
unsafe extern "C" fn jsoneq(
|
||||
mut json: *const libc::c_char,
|
||||
mut tok: *mut jsmntok_t,
|
||||
@@ -477,11 +484,15 @@ unsafe extern "C" fn jsoneq(
|
||||
{
|
||||
return 0i32;
|
||||
}
|
||||
return -1i32;
|
||||
|
||||
-1
|
||||
}
|
||||
unsafe fn is_expired(mut context: *mut dc_context_t) -> libc::c_int {
|
||||
|
||||
// TODO should return bool /rtn
|
||||
unsafe fn is_expired(mut context: &dc_context_t) -> libc::c_int {
|
||||
let mut expire_timestamp: time_t = dc_sqlite3_get_config_int64(
|
||||
(*context).sql,
|
||||
context,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
b"oauth2_timestamp_expires\x00" as *const u8 as *const libc::c_char,
|
||||
0i32 as int64_t,
|
||||
) as time_t;
|
||||
@@ -491,23 +502,22 @@ unsafe fn is_expired(mut context: *mut dc_context_t) -> libc::c_int {
|
||||
if expire_timestamp > time(0 as *mut time_t) {
|
||||
return 0i32;
|
||||
}
|
||||
return 1i32;
|
||||
|
||||
1
|
||||
}
|
||||
|
||||
pub unsafe fn dc_get_oauth2_addr(
|
||||
mut context: *mut dc_context_t,
|
||||
mut context: &dc_context_t,
|
||||
mut addr: *const libc::c_char,
|
||||
mut code: *const libc::c_char,
|
||||
) -> *mut libc::c_char {
|
||||
let mut access_token: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut addr_out: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut oauth2: *mut oauth2_t = 0 as *mut oauth2_t;
|
||||
if !(context.is_null()
|
||||
|| (*context).magic != 0x11a11807i32 as libc::c_uint
|
||||
|| {
|
||||
oauth2 = get_info(addr);
|
||||
oauth2.is_null()
|
||||
}
|
||||
|| (*oauth2).get_userinfo.is_null())
|
||||
let mut oauth2: *mut oauth2_t;
|
||||
if !({
|
||||
oauth2 = get_info(addr);
|
||||
oauth2.is_null()
|
||||
} || (*oauth2).get_userinfo.is_null())
|
||||
{
|
||||
access_token = dc_get_oauth2_access_token(context, addr, code, 0i32);
|
||||
addr_out = get_oauth2_addr(context, oauth2, access_token);
|
||||
@@ -519,10 +529,12 @@ pub unsafe fn dc_get_oauth2_addr(
|
||||
}
|
||||
free(access_token as *mut libc::c_void);
|
||||
free(oauth2 as *mut libc::c_void);
|
||||
return addr_out;
|
||||
|
||||
addr_out
|
||||
}
|
||||
|
||||
unsafe fn get_oauth2_addr(
|
||||
mut context: *mut dc_context_t,
|
||||
mut context: &dc_context_t,
|
||||
mut oauth2: *const oauth2_t,
|
||||
mut access_token: *const libc::c_char,
|
||||
) -> *mut libc::c_char {
|
||||
@@ -541,10 +553,8 @@ unsafe fn get_oauth2_addr(
|
||||
end: 0,
|
||||
size: 0,
|
||||
}; 128];
|
||||
let mut tok_cnt: libc::c_int = 0i32;
|
||||
if !(context.is_null()
|
||||
|| (*context).magic != 0x11a11807i32 as libc::c_uint
|
||||
|| access_token.is_null()
|
||||
let mut tok_cnt: libc::c_int;
|
||||
if !(access_token.is_null()
|
||||
|| *access_token.offset(0isize) as libc::c_int == 0i32
|
||||
|| oauth2.is_null())
|
||||
{
|
||||
@@ -554,7 +564,7 @@ unsafe fn get_oauth2_addr(
|
||||
b"$ACCESS_TOKEN\x00" as *const u8 as *const libc::c_char,
|
||||
access_token,
|
||||
);
|
||||
json = ((*context).cb)(
|
||||
json = (context.cb)(
|
||||
context,
|
||||
Event::HTTP_GET,
|
||||
userinfo_url as uintptr_t,
|
||||
@@ -611,5 +621,6 @@ unsafe fn get_oauth2_addr(
|
||||
}
|
||||
free(userinfo_url as *mut libc::c_void);
|
||||
free(json as *mut libc::c_void);
|
||||
return addr_out;
|
||||
|
||||
addr_out
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
use libc;
|
||||
|
||||
use crate::dc_tools::*;
|
||||
use crate::types::*;
|
||||
use crate::x::*;
|
||||
@@ -94,8 +92,8 @@ unsafe extern "C" fn find_param(
|
||||
mut key: libc::c_int,
|
||||
mut ret_p2: *mut *mut libc::c_char,
|
||||
) -> *mut libc::c_char {
|
||||
let mut p1: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut p2: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut p1: *mut libc::c_char;
|
||||
let mut p2: *mut libc::c_char;
|
||||
p1 = haystack;
|
||||
loop {
|
||||
if p1.is_null() || *p1 as libc::c_int == 0i32 {
|
||||
@@ -115,18 +113,20 @@ unsafe extern "C" fn find_param(
|
||||
p2 = &mut *p1.offset(strlen(p1) as isize) as *mut libc::c_char
|
||||
}
|
||||
*ret_p2 = p2;
|
||||
return p1;
|
||||
|
||||
p1
|
||||
}
|
||||
|
||||
/* the value may be an empty string, "def" is returned only if the value unset. The result must be free()'d in any case. */
|
||||
pub unsafe fn dc_param_get(
|
||||
mut param: *const dc_param_t,
|
||||
mut key: libc::c_int,
|
||||
mut def: *const libc::c_char,
|
||||
param: *const dc_param_t,
|
||||
key: libc::c_int,
|
||||
def: *const libc::c_char,
|
||||
) -> *mut libc::c_char {
|
||||
let mut p1: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut p1: *mut libc::c_char;
|
||||
let mut p2: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut bak: libc::c_char = 0i32 as libc::c_char;
|
||||
let mut ret: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut bak: libc::c_char;
|
||||
let mut ret: *mut libc::c_char;
|
||||
if param.is_null() || key == 0i32 {
|
||||
return if !def.is_null() {
|
||||
dc_strdup(def)
|
||||
@@ -148,8 +148,10 @@ pub unsafe fn dc_param_get(
|
||||
ret = dc_strdup(p1);
|
||||
dc_rtrim(ret);
|
||||
*p2 = bak;
|
||||
return ret;
|
||||
|
||||
ret
|
||||
}
|
||||
|
||||
pub unsafe fn dc_param_get_int(
|
||||
mut param: *const dc_param_t,
|
||||
mut key: libc::c_int,
|
||||
@@ -164,7 +166,8 @@ pub unsafe fn dc_param_get_int(
|
||||
}
|
||||
let mut ret: int32_t = atol(str) as int32_t;
|
||||
free(str as *mut libc::c_void);
|
||||
return ret;
|
||||
|
||||
ret
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -201,16 +204,16 @@ pub unsafe fn dc_param_set(
|
||||
mut key: libc::c_int,
|
||||
mut value: *const libc::c_char,
|
||||
) {
|
||||
let mut old1: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut old2: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut new1: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut old1: *mut libc::c_char;
|
||||
let mut old2: *mut libc::c_char;
|
||||
let mut new1: *mut libc::c_char;
|
||||
if param.is_null() || key == 0i32 {
|
||||
return;
|
||||
}
|
||||
old1 = (*param).packed;
|
||||
old2 = 0 as *mut libc::c_char;
|
||||
if !old1.is_null() {
|
||||
let mut p1: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut p1: *mut libc::c_char;
|
||||
let mut p2: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
p1 = find_param(old1, key, &mut p2);
|
||||
if !p1.is_null() {
|
||||
@@ -277,6 +280,7 @@ pub unsafe fn dc_param_set(
|
||||
free((*param).packed as *mut libc::c_void);
|
||||
(*param).packed = new1;
|
||||
}
|
||||
|
||||
pub unsafe fn dc_param_set_int(
|
||||
mut param: *mut dc_param_t,
|
||||
mut key: libc::c_int,
|
||||
@@ -295,22 +299,26 @@ pub unsafe fn dc_param_set_int(
|
||||
dc_param_set(param, key, value_str);
|
||||
free(value_str as *mut libc::c_void);
|
||||
}
|
||||
|
||||
/* library-private */
|
||||
pub unsafe fn dc_param_new() -> *mut dc_param_t {
|
||||
let mut param: *mut dc_param_t = 0 as *mut dc_param_t;
|
||||
let mut param: *mut dc_param_t;
|
||||
param = calloc(1, ::std::mem::size_of::<dc_param_t>()) as *mut dc_param_t;
|
||||
if param.is_null() {
|
||||
exit(28i32);
|
||||
}
|
||||
(*param).packed = calloc(1, 1) as *mut libc::c_char;
|
||||
return param;
|
||||
|
||||
param
|
||||
}
|
||||
|
||||
pub unsafe fn dc_param_empty(mut param: *mut dc_param_t) {
|
||||
if param.is_null() {
|
||||
return;
|
||||
}
|
||||
*(*param).packed.offset(0isize) = 0i32 as libc::c_char;
|
||||
}
|
||||
|
||||
pub unsafe fn dc_param_unref(mut param: *mut dc_param_t) {
|
||||
if param.is_null() {
|
||||
return;
|
||||
@@ -319,6 +327,7 @@ pub unsafe fn dc_param_unref(mut param: *mut dc_param_t) {
|
||||
free((*param).packed as *mut libc::c_void);
|
||||
free(param as *mut libc::c_void);
|
||||
}
|
||||
|
||||
pub unsafe fn dc_param_set_packed(mut param: *mut dc_param_t, mut packed: *const libc::c_char) {
|
||||
if param.is_null() {
|
||||
return;
|
||||
@@ -329,6 +338,7 @@ pub unsafe fn dc_param_set_packed(mut param: *mut dc_param_t, mut packed: *const
|
||||
(*param).packed = dc_strdup(packed)
|
||||
};
|
||||
}
|
||||
|
||||
pub unsafe fn dc_param_set_urlencoded(
|
||||
mut param: *mut dc_param_t,
|
||||
mut urlencoded: *const libc::c_char,
|
||||
|
||||
137
src/dc_pgp.rs
137
src/dc_pgp.rs
@@ -1,5 +1,3 @@
|
||||
use libc;
|
||||
|
||||
use crate::dc_context::dc_context_t;
|
||||
use crate::dc_hash::*;
|
||||
use crate::dc_key::*;
|
||||
@@ -10,18 +8,9 @@ use crate::pgp as rpgp;
|
||||
use crate::types::*;
|
||||
use crate::x::*;
|
||||
|
||||
/* ** library-private **********************************************************/
|
||||
/* validation errors */
|
||||
/* misc. */
|
||||
pub unsafe fn dc_pgp_init() {}
|
||||
pub unsafe fn dc_pgp_exit() {}
|
||||
pub unsafe fn dc_pgp_rand_seed(
|
||||
_context: *mut dc_context_t,
|
||||
_buf: *const libc::c_void,
|
||||
_bytes: size_t,
|
||||
) {
|
||||
}
|
||||
|
||||
// TODO should return bool /rtn
|
||||
pub unsafe fn dc_split_armored_data(
|
||||
mut buf: *mut libc::c_char,
|
||||
mut ret_headerline: *mut *const libc::c_char,
|
||||
@@ -33,7 +22,7 @@ pub unsafe fn dc_split_armored_data(
|
||||
let mut line_chars: size_t = 0i32 as size_t;
|
||||
let mut line: *mut libc::c_char = buf;
|
||||
let mut p1: *mut libc::c_char = buf;
|
||||
let mut p2: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut p2: *mut libc::c_char;
|
||||
let mut headerline: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut base64: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
if !ret_headerline.is_null() {
|
||||
@@ -136,21 +125,24 @@ pub unsafe fn dc_split_armored_data(
|
||||
}
|
||||
}
|
||||
}
|
||||
return success;
|
||||
|
||||
success
|
||||
}
|
||||
|
||||
/* public key encryption */
|
||||
// TODO should return bool /rtn
|
||||
pub unsafe fn dc_pgp_create_keypair(
|
||||
mut context: *mut dc_context_t,
|
||||
mut context: &dc_context_t,
|
||||
mut addr: *const libc::c_char,
|
||||
mut ret_public_key: *mut dc_key_t,
|
||||
mut ret_private_key: *mut dc_key_t,
|
||||
) -> libc::c_int {
|
||||
let mut success: libc::c_int = 0i32;
|
||||
let mut skey: *mut rpgp::signed_secret_key = 0 as *mut rpgp::signed_secret_key;
|
||||
let mut skey: *mut rpgp::signed_secret_key;
|
||||
let mut pkey: *mut rpgp::signed_public_key = 0 as *mut rpgp::signed_public_key;
|
||||
let mut skey_bytes: *mut rpgp::cvec = 0 as *mut rpgp::cvec;
|
||||
let mut pkey_bytes: *mut rpgp::cvec = 0 as *mut rpgp::cvec;
|
||||
let mut user_id: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut user_id: *mut libc::c_char;
|
||||
user_id = dc_mprintf(b"<%s>\x00" as *const u8 as *const libc::c_char, addr);
|
||||
skey = rpgp::rpgp_create_rsa_skey(2048i32 as uint32_t, user_id);
|
||||
if !(0 != dc_pgp_handle_rpgp_error(context)) {
|
||||
@@ -197,42 +189,42 @@ pub unsafe fn dc_pgp_create_keypair(
|
||||
if !user_id.is_null() {
|
||||
free(user_id as *mut libc::c_void);
|
||||
}
|
||||
return success;
|
||||
|
||||
success
|
||||
}
|
||||
|
||||
/* returns 0 if there is no error, otherwise logs the error if a context is provided and returns 1*/
|
||||
pub unsafe fn dc_pgp_handle_rpgp_error(mut context: *mut dc_context_t) -> libc::c_int {
|
||||
// TODO should return bool /rtn
|
||||
pub unsafe fn dc_pgp_handle_rpgp_error(mut context: &dc_context_t) -> libc::c_int {
|
||||
let mut success: libc::c_int = 0i32;
|
||||
let mut len: libc::c_int = 0i32;
|
||||
let mut len: libc::c_int;
|
||||
let mut msg: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
len = rpgp::rpgp_last_error_length();
|
||||
if !(len == 0i32) {
|
||||
msg = rpgp::rpgp_last_error_message();
|
||||
if !context.is_null() {
|
||||
dc_log_info(
|
||||
context,
|
||||
0i32,
|
||||
b"[rpgp][error] %s\x00" as *const u8 as *const libc::c_char,
|
||||
msg,
|
||||
);
|
||||
}
|
||||
dc_log_info(
|
||||
context,
|
||||
0i32,
|
||||
b"[rpgp][error] %s\x00" as *const u8 as *const libc::c_char,
|
||||
msg,
|
||||
);
|
||||
success = 1i32
|
||||
}
|
||||
if !msg.is_null() {
|
||||
rpgp::rpgp_string_drop(msg);
|
||||
}
|
||||
return success;
|
||||
|
||||
success
|
||||
}
|
||||
|
||||
// TODO should return bool /rtn
|
||||
pub unsafe fn dc_pgp_is_valid_key(
|
||||
mut context: *mut dc_context_t,
|
||||
mut context: &dc_context_t,
|
||||
mut raw_key: *const dc_key_t,
|
||||
) -> libc::c_int {
|
||||
let mut key_is_valid: libc::c_int = 0i32;
|
||||
let mut key: *mut rpgp::public_or_secret_key = 0 as *mut rpgp::public_or_secret_key;
|
||||
if !(context.is_null()
|
||||
|| raw_key.is_null()
|
||||
|| (*raw_key).binary.is_null()
|
||||
|| (*raw_key).bytes <= 0i32)
|
||||
{
|
||||
if !(raw_key.is_null() || (*raw_key).binary.is_null() || (*raw_key).bytes <= 0i32) {
|
||||
key = rpgp::rpgp_key_from_bytes(
|
||||
(*raw_key).binary as *const uint8_t,
|
||||
(*raw_key).bytes as usize,
|
||||
@@ -249,12 +241,16 @@ pub unsafe fn dc_pgp_is_valid_key(
|
||||
if !key.is_null() {
|
||||
rpgp::rpgp_key_drop(key);
|
||||
}
|
||||
return key_is_valid;
|
||||
|
||||
key_is_valid
|
||||
}
|
||||
|
||||
// TODO should return bool /rtn
|
||||
pub unsafe fn dc_pgp_calc_fingerprint(
|
||||
mut raw_key: *const dc_key_t,
|
||||
mut ret_fingerprint: *mut *mut uint8_t,
|
||||
mut ret_fingerprint_bytes: *mut size_t,
|
||||
context: &dc_context_t,
|
||||
raw_key: *const dc_key_t,
|
||||
ret_fingerprint: *mut *mut uint8_t,
|
||||
ret_fingerprint_bytes: *mut size_t,
|
||||
) -> libc::c_int {
|
||||
let mut success: libc::c_int = 0i32;
|
||||
let mut key: *mut rpgp::public_or_secret_key = 0 as *mut rpgp::public_or_secret_key;
|
||||
@@ -271,9 +267,9 @@ pub unsafe fn dc_pgp_calc_fingerprint(
|
||||
(*raw_key).binary as *const uint8_t,
|
||||
(*raw_key).bytes as usize,
|
||||
);
|
||||
if !(0 != dc_pgp_handle_rpgp_error(0 as *mut dc_context_t)) {
|
||||
if !(0 != dc_pgp_handle_rpgp_error(context)) {
|
||||
fingerprint = rpgp::rpgp_key_fingerprint(key);
|
||||
if !(0 != dc_pgp_handle_rpgp_error(0 as *mut dc_context_t)) {
|
||||
if !(0 != dc_pgp_handle_rpgp_error(context)) {
|
||||
*ret_fingerprint_bytes = rpgp::rpgp_cvec_len(fingerprint) as size_t;
|
||||
*ret_fingerprint = malloc(*ret_fingerprint_bytes) as *mut uint8_t;
|
||||
memcpy(
|
||||
@@ -291,10 +287,13 @@ pub unsafe fn dc_pgp_calc_fingerprint(
|
||||
if !fingerprint.is_null() {
|
||||
rpgp::rpgp_cvec_drop(fingerprint);
|
||||
}
|
||||
return success;
|
||||
|
||||
success
|
||||
}
|
||||
|
||||
// TODO should return bool /rtn
|
||||
pub unsafe fn dc_pgp_split_key(
|
||||
mut context: *mut dc_context_t,
|
||||
mut context: &dc_context_t,
|
||||
mut private_in: *const dc_key_t,
|
||||
mut ret_public_key: *mut dc_key_t,
|
||||
) -> libc::c_int {
|
||||
@@ -302,7 +301,7 @@ pub unsafe fn dc_pgp_split_key(
|
||||
let mut key: *mut rpgp::signed_secret_key = 0 as *mut rpgp::signed_secret_key;
|
||||
let mut pub_key: *mut rpgp::signed_public_key = 0 as *mut rpgp::signed_public_key;
|
||||
let mut buf: *mut rpgp::cvec = 0 as *mut rpgp::cvec;
|
||||
if !(context.is_null() || private_in.is_null() || ret_public_key.is_null()) {
|
||||
if !(private_in.is_null() || ret_public_key.is_null()) {
|
||||
if (*private_in).type_0 != 1i32 {
|
||||
dc_log_warning(
|
||||
context,
|
||||
@@ -340,10 +339,13 @@ pub unsafe fn dc_pgp_split_key(
|
||||
if !buf.is_null() {
|
||||
rpgp::rpgp_cvec_drop(buf);
|
||||
}
|
||||
return success;
|
||||
|
||||
success
|
||||
}
|
||||
|
||||
// TODO should return bool /rtn
|
||||
pub unsafe fn dc_pgp_pk_encrypt(
|
||||
mut context: *mut dc_context_t,
|
||||
mut context: &dc_context_t,
|
||||
mut plain_text: *const libc::c_void,
|
||||
mut plain_bytes: size_t,
|
||||
mut raw_public_keys_for_encryption: *const dc_keyring_t,
|
||||
@@ -353,14 +355,13 @@ pub unsafe fn dc_pgp_pk_encrypt(
|
||||
mut ret_ctext_bytes: *mut size_t,
|
||||
) -> libc::c_int {
|
||||
let mut current_block: u64;
|
||||
let mut i: libc::c_int = 0i32;
|
||||
let mut i: libc::c_int;
|
||||
let mut success: libc::c_int = 0i32;
|
||||
let mut public_keys_len: libc::c_int = 0i32;
|
||||
let mut public_keys: *mut *mut rpgp::signed_public_key = 0 as *mut *mut rpgp::signed_public_key;
|
||||
let mut private_key: *mut rpgp::signed_secret_key = 0 as *mut rpgp::signed_secret_key;
|
||||
let mut encrypted: *mut rpgp::Message = 0 as *mut rpgp::Message;
|
||||
if !(context.is_null()
|
||||
|| plain_text == 0 as *mut libc::c_void
|
||||
if !(plain_text == 0 as *mut libc::c_void
|
||||
|| plain_bytes == 0
|
||||
|| ret_ctext.is_null()
|
||||
|| ret_ctext_bytes.is_null()
|
||||
@@ -422,7 +423,7 @@ pub unsafe fn dc_pgp_pk_encrypt(
|
||||
2132137392766895896 => {}
|
||||
_ => {
|
||||
/* sign & encrypt */
|
||||
let mut op_clocks: libc::clock_t = 0i32 as libc::clock_t;
|
||||
let mut op_clocks: libc::clock_t;
|
||||
let mut start: libc::clock_t = clock();
|
||||
if private_key.is_null() {
|
||||
encrypted = rpgp::rpgp_encrypt_bytes_to_keys(
|
||||
@@ -509,10 +510,13 @@ pub unsafe fn dc_pgp_pk_encrypt(
|
||||
if !encrypted.is_null() {
|
||||
rpgp::rpgp_msg_drop(encrypted);
|
||||
}
|
||||
return success;
|
||||
|
||||
success
|
||||
}
|
||||
|
||||
// TODO should return bool /rtn
|
||||
pub unsafe fn dc_pgp_pk_decrypt(
|
||||
mut context: *mut dc_context_t,
|
||||
mut context: &dc_context_t,
|
||||
mut ctext: *const libc::c_void,
|
||||
mut ctext_bytes: size_t,
|
||||
mut raw_private_keys_for_decryption: *const dc_keyring_t,
|
||||
@@ -523,7 +527,7 @@ pub unsafe fn dc_pgp_pk_decrypt(
|
||||
mut ret_signature_fingerprints: *mut dc_hash_t,
|
||||
) -> libc::c_int {
|
||||
let mut current_block: u64;
|
||||
let mut i: libc::c_int = 0i32;
|
||||
let mut i: libc::c_int;
|
||||
let mut success: libc::c_int = 0i32;
|
||||
let mut encrypted: *mut rpgp::Message = 0 as *mut rpgp::Message;
|
||||
let mut decrypted: *mut rpgp::message_decrypt_result = 0 as *mut rpgp::message_decrypt_result;
|
||||
@@ -532,8 +536,7 @@ pub unsafe fn dc_pgp_pk_decrypt(
|
||||
let mut private_keys: *mut *mut rpgp::signed_secret_key =
|
||||
0 as *mut *mut rpgp::signed_secret_key;
|
||||
let mut public_keys: *mut *mut rpgp::signed_public_key = 0 as *mut *mut rpgp::signed_public_key;
|
||||
if !(context.is_null()
|
||||
|| ctext == 0 as *mut libc::c_void
|
||||
if !(ctext == 0 as *mut libc::c_void
|
||||
|| ctext_bytes == 0
|
||||
|| ret_plain.is_null()
|
||||
|| ret_plain_bytes.is_null()
|
||||
@@ -671,11 +674,14 @@ pub unsafe fn dc_pgp_pk_decrypt(
|
||||
if !decrypted.is_null() {
|
||||
rpgp::rpgp_message_decrypt_result_drop(decrypted);
|
||||
}
|
||||
return success;
|
||||
|
||||
success
|
||||
}
|
||||
|
||||
/* symm. encryption */
|
||||
// TODO should return bool /rtn
|
||||
pub unsafe fn dc_pgp_symm_encrypt(
|
||||
mut context: *mut dc_context_t,
|
||||
mut context: &dc_context_t,
|
||||
mut passphrase: *const libc::c_char,
|
||||
mut plain: *const libc::c_void,
|
||||
mut plain_bytes: size_t,
|
||||
@@ -683,8 +689,7 @@ pub unsafe fn dc_pgp_symm_encrypt(
|
||||
) -> libc::c_int {
|
||||
let mut success: libc::c_int = 0i32;
|
||||
let mut decrypted: *mut rpgp::Message = 0 as *mut rpgp::Message;
|
||||
if !(context.is_null()
|
||||
|| passphrase.is_null()
|
||||
if !(passphrase.is_null()
|
||||
|| plain == 0 as *mut libc::c_void
|
||||
|| plain_bytes == 0
|
||||
|| ret_ctext_armored.is_null())
|
||||
@@ -704,19 +709,22 @@ pub unsafe fn dc_pgp_symm_encrypt(
|
||||
if !decrypted.is_null() {
|
||||
rpgp::rpgp_msg_drop(decrypted);
|
||||
}
|
||||
return success;
|
||||
|
||||
success
|
||||
}
|
||||
|
||||
// TODO should return bool /rtn
|
||||
pub unsafe fn dc_pgp_symm_decrypt(
|
||||
mut context: *mut dc_context_t,
|
||||
mut context: &dc_context_t,
|
||||
mut passphrase: *const libc::c_char,
|
||||
mut ctext: *const libc::c_void,
|
||||
mut ctext_bytes: size_t,
|
||||
mut ret_plain_text: *mut *mut libc::c_void,
|
||||
mut ret_plain_bytes: *mut size_t,
|
||||
) -> libc::c_int {
|
||||
let mut decrypted_bytes: *mut rpgp::cvec = 0 as *mut rpgp::cvec;
|
||||
let mut decrypted_bytes: *mut rpgp::cvec;
|
||||
let mut success: libc::c_int = 0i32;
|
||||
let mut encrypted: *mut rpgp::Message = 0 as *mut rpgp::Message;
|
||||
let mut encrypted: *mut rpgp::Message;
|
||||
let mut decrypted: *mut rpgp::Message = 0 as *mut rpgp::Message;
|
||||
encrypted = rpgp::rpgp_msg_from_bytes(ctext as *const uint8_t, ctext_bytes as usize);
|
||||
if !(0 != dc_pgp_handle_rpgp_error(context)) {
|
||||
@@ -737,5 +745,6 @@ pub unsafe fn dc_pgp_symm_decrypt(
|
||||
if !decrypted.is_null() {
|
||||
rpgp::rpgp_msg_drop(decrypted);
|
||||
}
|
||||
return success;
|
||||
|
||||
success
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
use libc;
|
||||
|
||||
use crate::dc_apeerstate::*;
|
||||
use crate::dc_chat::*;
|
||||
use crate::dc_contact::*;
|
||||
@@ -24,7 +22,7 @@ use crate::x::*;
|
||||
// text1=URL
|
||||
// text1=error string
|
||||
pub unsafe fn dc_check_qr(
|
||||
mut context: *mut dc_context_t,
|
||||
mut context: &dc_context_t,
|
||||
mut qr: *const libc::c_char,
|
||||
) -> *mut dc_lot_t {
|
||||
let mut current_block: u64;
|
||||
@@ -43,7 +41,7 @@ pub unsafe fn dc_check_qr(
|
||||
let mut grpid: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut grpname: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
(*qr_parsed).state = 0i32;
|
||||
if !(context.is_null() || (*context).magic != 0x11a11807i32 as libc::c_uint || qr.is_null()) {
|
||||
if !qr.is_null() {
|
||||
dc_log_info(
|
||||
context,
|
||||
0i32,
|
||||
@@ -247,7 +245,7 @@ pub unsafe fn dc_check_qr(
|
||||
if addr.is_null() || invitenumber.is_null() || auth.is_null() {
|
||||
if 0 != dc_apeerstate_load_by_fingerprint(
|
||||
peerstate,
|
||||
(*context).sql,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
fingerprint,
|
||||
) {
|
||||
(*qr_parsed).state = 210i32;
|
||||
|
||||
@@ -1,4 +1,10 @@
|
||||
use libc;
|
||||
use mmime::mailimf::*;
|
||||
use mmime::mailimf_types::*;
|
||||
use mmime::mailmime::*;
|
||||
use mmime::mailmime_content::*;
|
||||
use mmime::mailmime_types::*;
|
||||
use mmime::mmapstring::*;
|
||||
use mmime::other::*;
|
||||
|
||||
use crate::constants::*;
|
||||
use crate::dc_apeerstate::*;
|
||||
@@ -25,40 +31,39 @@ use crate::types::*;
|
||||
use crate::x::*;
|
||||
|
||||
pub unsafe fn dc_receive_imf(
|
||||
mut context: *mut dc_context_t,
|
||||
mut imf_raw_not_terminated: *const libc::c_char,
|
||||
mut imf_raw_bytes: size_t,
|
||||
mut server_folder: *const libc::c_char,
|
||||
mut server_uid: uint32_t,
|
||||
mut flags: uint32_t,
|
||||
context: &dc_context_t,
|
||||
imf_raw_not_terminated: *const libc::c_char,
|
||||
imf_raw_bytes: size_t,
|
||||
server_folder: *const libc::c_char,
|
||||
server_uid: uint32_t,
|
||||
flags: uint32_t,
|
||||
) {
|
||||
let mut current_block: u64;
|
||||
/* the function returns the number of created messages in the database */
|
||||
let mut incoming: libc::c_int = 1i32;
|
||||
let mut incoming_origin: libc::c_int = 0i32;
|
||||
let mut to_ids: *mut dc_array_t = 0 as *mut dc_array_t;
|
||||
let mut to_ids: *mut dc_array_t;
|
||||
let mut to_self: libc::c_int = 0i32;
|
||||
let mut from_id: uint32_t = 0i32 as uint32_t;
|
||||
let mut from_id_blocked: libc::c_int = 0i32;
|
||||
let mut to_id: uint32_t = 0i32 as uint32_t;
|
||||
let mut chat_id: uint32_t = 0i32 as uint32_t;
|
||||
let mut chat_id_blocked: libc::c_int = 0i32;
|
||||
let mut state: libc::c_int = 0i32;
|
||||
let mut state: libc::c_int;
|
||||
let mut hidden: libc::c_int = 0i32;
|
||||
let mut msgrmsg: libc::c_int = 0i32;
|
||||
let mut msgrmsg: libc::c_int;
|
||||
let mut add_delete_job: libc::c_int = 0i32;
|
||||
let mut insert_msg_id: uint32_t = 0i32 as uint32_t;
|
||||
let mut stmt: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt;
|
||||
let mut i: size_t = 0i32 as size_t;
|
||||
let mut icnt: size_t = 0i32 as size_t;
|
||||
let mut i: size_t;
|
||||
let mut icnt: size_t;
|
||||
/* Message-ID from the header */
|
||||
let mut rfc724_mid: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut sort_timestamp: time_t = -1i32 as time_t;
|
||||
let mut sent_timestamp: time_t = -1i32 as time_t;
|
||||
let mut rcvd_timestamp: time_t = -1i32 as time_t;
|
||||
let mut mime_parser: *mut dc_mimeparser_t = dc_mimeparser_new((*context).blobdir, context);
|
||||
let mut transaction_pending: libc::c_int = 0i32;
|
||||
let mut field: *const mailimf_field = 0 as *const mailimf_field;
|
||||
let mut mime_parser: *mut dc_mimeparser_t = dc_mimeparser_new(context.get_blobdir(), context);
|
||||
let mut field: *const mailimf_field;
|
||||
let mut mime_in_reply_to: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut mime_references: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut created_db_entries: *mut carray = carray_new(16i32 as libc::c_uint);
|
||||
@@ -76,7 +81,7 @@ pub unsafe fn dc_receive_imf(
|
||||
},
|
||||
server_uid,
|
||||
);
|
||||
to_ids = dc_array_new(context, 16i32 as size_t);
|
||||
to_ids = dc_array_new(16i32 as size_t);
|
||||
if to_ids.is_null()
|
||||
|| created_db_entries.is_null()
|
||||
|| rr_event_to_send.is_null()
|
||||
@@ -107,8 +112,6 @@ pub unsafe fn dc_receive_imf(
|
||||
sent_timestamp = dc_timestamp_from_date((*orig_date).dt_date_time)
|
||||
}
|
||||
}
|
||||
dc_sqlite3_begin_transaction((*context).sql);
|
||||
transaction_pending = 1i32;
|
||||
field = dc_mimeparser_lookup_field(
|
||||
mime_parser,
|
||||
b"From\x00" as *const u8 as *const libc::c_char,
|
||||
@@ -117,7 +120,7 @@ pub unsafe fn dc_receive_imf(
|
||||
let mut fld_from: *mut mailimf_from = (*field).fld_data.fld_from;
|
||||
if !fld_from.is_null() {
|
||||
let mut check_self: libc::c_int = 0;
|
||||
let mut from_list: *mut dc_array_t = dc_array_new(context, 16i32 as size_t);
|
||||
let mut from_list: *mut dc_array_t = dc_array_new(16i32 as size_t);
|
||||
dc_add_or_lookup_contacts_by_mailbox_list(
|
||||
context,
|
||||
(*fld_from).frm_mb_list,
|
||||
@@ -226,8 +229,6 @@ pub unsafe fn dc_receive_imf(
|
||||
if strcmp(old_server_folder, server_folder) != 0i32
|
||||
|| old_server_uid != server_uid
|
||||
{
|
||||
dc_sqlite3_rollback((*context).sql);
|
||||
transaction_pending = 0i32;
|
||||
dc_update_server_uid(
|
||||
context,
|
||||
rfc724_mid,
|
||||
@@ -255,7 +256,8 @@ pub unsafe fn dc_receive_imf(
|
||||
let mut allow_creation: libc::c_int = 1i32;
|
||||
if msgrmsg == 0i32 {
|
||||
let mut show_emails: libc::c_int = dc_sqlite3_get_config_int(
|
||||
(*context).sql,
|
||||
context,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
b"show_emails\x00" as *const u8 as *const libc::c_char,
|
||||
0i32,
|
||||
);
|
||||
@@ -282,7 +284,6 @@ pub unsafe fn dc_receive_imf(
|
||||
msgrmsg = 1i32;
|
||||
chat_id = 0i32 as uint32_t;
|
||||
allow_creation = 1i32;
|
||||
dc_sqlite3_commit((*context).sql);
|
||||
let mut handshake: libc::c_int = dc_handle_securejoin_handshake(
|
||||
context,
|
||||
mime_parser,
|
||||
@@ -293,7 +294,6 @@ pub unsafe fn dc_receive_imf(
|
||||
add_delete_job = handshake & 0x4i32;
|
||||
state = 16i32
|
||||
}
|
||||
dc_sqlite3_begin_transaction((*context).sql);
|
||||
}
|
||||
let mut test_normal_chat_id: uint32_t = 0i32 as uint32_t;
|
||||
let mut test_normal_chat_id_blocked: libc::c_int = 0i32;
|
||||
@@ -469,13 +469,14 @@ pub unsafe fn dc_receive_imf(
|
||||
// if the mime-headers should be saved, find out its size
|
||||
// (the mime-header ends with an empty line)
|
||||
let mut save_mime_headers: libc::c_int = dc_sqlite3_get_config_int(
|
||||
(*context).sql,
|
||||
context,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
b"save_mime_headers\x00" as *const u8 as *const libc::c_char,
|
||||
0i32,
|
||||
);
|
||||
let mut header_bytes: libc::c_int = imf_raw_bytes as libc::c_int;
|
||||
if 0 != save_mime_headers {
|
||||
let mut p: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut p: *mut libc::c_char;
|
||||
p = strstr(
|
||||
imf_raw_not_terminated,
|
||||
b"\r\n\r\n\x00" as *const u8 as *const libc::c_char,
|
||||
@@ -533,8 +534,10 @@ pub unsafe fn dc_receive_imf(
|
||||
}
|
||||
icnt = carray_count((*mime_parser).parts) as size_t;
|
||||
stmt =
|
||||
dc_sqlite3_prepare((*context).sql,
|
||||
b"INSERT INTO msgs (rfc724_mid, server_folder, server_uid, chat_id, from_id, to_id, timestamp, timestamp_sent, timestamp_rcvd, type, state, msgrmsg, txt, txt_raw, param, bytes, hidden, mime_headers, mime_in_reply_to, mime_references) VALUES (?,?,?,?,?,?, ?,?,?,?,?,?, ?,?,?,?,?,?, ?,?);\x00"
|
||||
dc_sqlite3_prepare(
|
||||
context,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
b"INSERT INTO msgs (rfc724_mid, server_folder, server_uid, chat_id, from_id, to_id, timestamp, timestamp_sent, timestamp_rcvd, type, state, msgrmsg, txt, txt_raw, param, bytes, hidden, mime_headers, mime_in_reply_to, mime_references) VALUES (?,?,?,?,?,?, ?,?,?,?,?,?, ?,?,?,?,?,?, ?,?);\x00"
|
||||
as *const u8 as
|
||||
*const libc::c_char);
|
||||
i = 0i32 as size_t;
|
||||
@@ -650,7 +653,8 @@ pub unsafe fn dc_receive_imf(
|
||||
free(txt_raw as *mut libc::c_void);
|
||||
txt_raw = 0 as *mut libc::c_char;
|
||||
insert_msg_id = dc_sqlite3_get_rowid(
|
||||
(*context).sql,
|
||||
context,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
b"msgs\x00" as *const u8 as *const libc::c_char,
|
||||
b"rfc724_mid\x00" as *const u8 as *const libc::c_char,
|
||||
rfc724_mid,
|
||||
@@ -710,7 +714,8 @@ pub unsafe fn dc_receive_imf(
|
||||
_ => {
|
||||
if carray_count((*mime_parser).reports) > 0i32 as libc::c_uint {
|
||||
let mut mdns_enabled: libc::c_int = dc_sqlite3_get_config_int(
|
||||
(*context).sql,
|
||||
context,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
b"mdns_enabled\x00" as *const u8 as *const libc::c_char,
|
||||
1i32,
|
||||
);
|
||||
@@ -751,7 +756,7 @@ pub unsafe fn dc_receive_imf(
|
||||
.first)
|
||||
.next
|
||||
} else {
|
||||
0 as *mut clistcell_s
|
||||
0 as *mut clistcell
|
||||
}
|
||||
.is_null()
|
||||
{
|
||||
@@ -769,7 +774,7 @@ pub unsafe fn dc_receive_imf(
|
||||
.first)
|
||||
.next
|
||||
} else {
|
||||
0 as *mut clistcell_s
|
||||
0 as *mut clistcell
|
||||
})
|
||||
.data
|
||||
} else {
|
||||
@@ -901,7 +906,8 @@ pub unsafe fn dc_receive_imf(
|
||||
dc_param_set_int(param, 'z' as i32, server_uid as int32_t);
|
||||
if 0 != (*mime_parser).is_send_by_messenger
|
||||
&& 0 != dc_sqlite3_get_config_int(
|
||||
(*context).sql,
|
||||
context,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
b"mvbox_move\x00" as *const u8
|
||||
as *const libc::c_char,
|
||||
1i32,
|
||||
@@ -988,15 +994,10 @@ pub unsafe fn dc_receive_imf(
|
||||
0i32,
|
||||
);
|
||||
}
|
||||
dc_sqlite3_commit((*context).sql);
|
||||
transaction_pending = 0i32
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if 0 != transaction_pending {
|
||||
dc_sqlite3_rollback((*context).sql);
|
||||
}
|
||||
dc_mimeparser_unref(mime_parser);
|
||||
free(rfc724_mid as *mut libc::c_void);
|
||||
free(mime_in_reply_to as *mut libc::c_void);
|
||||
@@ -1006,7 +1007,6 @@ pub unsafe fn dc_receive_imf(
|
||||
if let Some(create_event_to_send) = create_event_to_send {
|
||||
let mut i_0: size_t = 0;
|
||||
let mut icnt_0: size_t = carray_count(created_db_entries) as size_t;
|
||||
i_0 = 0i32 as size_t;
|
||||
while i_0 < icnt_0 {
|
||||
((*context).cb)(
|
||||
context,
|
||||
@@ -1021,7 +1021,7 @@ pub unsafe fn dc_receive_imf(
|
||||
carray_free(created_db_entries);
|
||||
}
|
||||
if !rr_event_to_send.is_null() {
|
||||
let mut i_1: size_t = 0;
|
||||
let mut i_1: size_t;
|
||||
let mut icnt_1: size_t = carray_count(rr_event_to_send) as size_t;
|
||||
i_1 = 0i32 as size_t;
|
||||
while i_1 < icnt_1 {
|
||||
@@ -1042,7 +1042,7 @@ pub unsafe fn dc_receive_imf(
|
||||
* Misc. Tools
|
||||
******************************************************************************/
|
||||
unsafe fn calc_timestamps(
|
||||
mut context: *mut dc_context_t,
|
||||
mut context: &dc_context_t,
|
||||
mut chat_id: uint32_t,
|
||||
mut from_id: uint32_t,
|
||||
mut message_timestamp: time_t,
|
||||
@@ -1059,7 +1059,8 @@ unsafe fn calc_timestamps(
|
||||
*sort_timestamp = message_timestamp;
|
||||
if 0 != is_fresh_msg {
|
||||
let mut stmt: *mut sqlite3_stmt = dc_sqlite3_prepare(
|
||||
(*context).sql,
|
||||
context,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
b"SELECT MAX(timestamp) FROM msgs WHERE chat_id=? and from_id!=? AND timestamp>=?\x00"
|
||||
as *const u8 as *const libc::c_char,
|
||||
);
|
||||
@@ -1093,7 +1094,7 @@ which tries to create or find out the chat_id by:
|
||||
So when the function returns, the caller has the group id matching the current
|
||||
state of the group. */
|
||||
unsafe fn create_or_lookup_group(
|
||||
mut context: *mut dc_context_t,
|
||||
mut context: &dc_context_t,
|
||||
mut mime_parser: *mut dc_mimeparser_t,
|
||||
mut allow_creation: libc::c_int,
|
||||
mut create_blocked: libc::c_int,
|
||||
@@ -1102,15 +1103,15 @@ unsafe fn create_or_lookup_group(
|
||||
mut ret_chat_id: *mut uint32_t,
|
||||
mut ret_chat_id_blocked: *mut libc::c_int,
|
||||
) {
|
||||
let mut group_explicitly_left: libc::c_int = 0;
|
||||
let mut group_explicitly_left: libc::c_int;
|
||||
let mut current_block: u64;
|
||||
let mut chat_id: uint32_t = 0i32 as uint32_t;
|
||||
let mut chat_id_blocked: libc::c_int = 0i32;
|
||||
let mut chat_id_verified: libc::c_int = 0i32;
|
||||
let mut grpid: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut grpname: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut stmt: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt;
|
||||
let mut i: libc::c_int = 0i32;
|
||||
let mut stmt: *mut sqlite3_stmt;
|
||||
let mut i: libc::c_int;
|
||||
let mut to_ids_cnt: libc::c_int = dc_array_get_cnt(to_ids) as libc::c_int;
|
||||
let mut self_addr: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut recreate_member_list: libc::c_int = 0i32;
|
||||
@@ -1134,8 +1135,8 @@ unsafe fn create_or_lookup_group(
|
||||
}
|
||||
set_better_msg(mime_parser, &mut better_msg);
|
||||
/* search the grpid in the header */
|
||||
let mut field: *mut mailimf_field = 0 as *mut mailimf_field;
|
||||
let mut optional_field: *mut mailimf_optional_field = 0 as *mut mailimf_optional_field;
|
||||
let mut field: *mut mailimf_field;
|
||||
let mut optional_field: *mut mailimf_optional_field;
|
||||
optional_field = dc_mimeparser_lookup_optional_field(
|
||||
mime_parser,
|
||||
b"Chat-Group-ID\x00" as *const u8 as *const libc::c_char,
|
||||
@@ -1321,7 +1322,8 @@ unsafe fn create_or_lookup_group(
|
||||
/* check if the group does not exist but should be created */
|
||||
group_explicitly_left = dc_is_group_explicitly_left(context, grpid);
|
||||
self_addr = dc_sqlite3_get_config(
|
||||
(*context).sql,
|
||||
context,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
b"configured_addr\x00" as *const u8 as *const libc::c_char,
|
||||
b"\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
@@ -1364,7 +1366,6 @@ unsafe fn create_or_lookup_group(
|
||||
create_verified,
|
||||
);
|
||||
chat_id_blocked = create_blocked;
|
||||
chat_id_verified = create_verified;
|
||||
recreate_member_list = 1i32;
|
||||
current_block = 200744462051969938;
|
||||
}
|
||||
@@ -1399,7 +1400,8 @@ unsafe fn create_or_lookup_group(
|
||||
&& strlen(grpname) < 200
|
||||
{
|
||||
stmt = dc_sqlite3_prepare(
|
||||
(*context).sql,
|
||||
context,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
b"UPDATE chats SET name=? WHERE id=?;\x00" as *const u8
|
||||
as *const libc::c_char,
|
||||
);
|
||||
@@ -1468,7 +1470,8 @@ unsafe fn create_or_lookup_group(
|
||||
0 as *mut libc::c_char
|
||||
};
|
||||
stmt = dc_sqlite3_prepare(
|
||||
(*context).sql,
|
||||
context,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
b"DELETE FROM chats_contacts WHERE chat_id=?;\x00" as *const u8
|
||||
as *const libc::c_char,
|
||||
);
|
||||
@@ -1559,7 +1562,7 @@ unsafe fn create_or_lookup_group(
|
||||
* Handle groups for received messages
|
||||
******************************************************************************/
|
||||
unsafe fn create_or_lookup_adhoc_group(
|
||||
mut context: *mut dc_context_t,
|
||||
mut context: &dc_context_t,
|
||||
mut mime_parser: *mut dc_mimeparser_t,
|
||||
mut allow_creation: libc::c_int,
|
||||
mut create_blocked: libc::c_int,
|
||||
@@ -1574,7 +1577,7 @@ unsafe fn create_or_lookup_adhoc_group(
|
||||
let mut member_ids: *mut dc_array_t = 0 as *mut dc_array_t;
|
||||
let mut chat_id: uint32_t = 0i32 as uint32_t;
|
||||
let mut chat_id_blocked = 0;
|
||||
let mut i = 0;
|
||||
let mut i;
|
||||
let mut chat_ids: *mut dc_array_t = 0 as *mut dc_array_t;
|
||||
let mut chat_ids_str: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut q3: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
@@ -1601,7 +1604,7 @@ unsafe fn create_or_lookup_adhoc_group(
|
||||
sqlite3_mprintf(b"SELECT c.id, c.blocked FROM chats c LEFT JOIN msgs m ON m.chat_id=c.id WHERE c.id IN(%s) ORDER BY m.timestamp DESC, m.id DESC LIMIT 1;\x00"
|
||||
as *const u8 as *const libc::c_char,
|
||||
chat_ids_str);
|
||||
stmt = dc_sqlite3_prepare((*context).sql, q3);
|
||||
stmt = dc_sqlite3_prepare(context, &context.sql.clone().read().unwrap(), q3);
|
||||
if sqlite3_step(stmt) == 100i32 {
|
||||
chat_id = sqlite3_column_int(stmt, 0i32) as uint32_t;
|
||||
chat_id_blocked = sqlite3_column_int(stmt, 1i32);
|
||||
@@ -1673,16 +1676,17 @@ unsafe fn create_or_lookup_adhoc_group(
|
||||
};
|
||||
}
|
||||
unsafe fn create_group_record(
|
||||
mut context: *mut dc_context_t,
|
||||
mut context: &dc_context_t,
|
||||
mut grpid: *const libc::c_char,
|
||||
mut grpname: *const libc::c_char,
|
||||
mut create_blocked: libc::c_int,
|
||||
mut create_verified: libc::c_int,
|
||||
) -> uint32_t {
|
||||
let mut chat_id: uint32_t = 0i32 as uint32_t;
|
||||
let mut stmt: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt;
|
||||
let mut stmt: *mut sqlite3_stmt;
|
||||
stmt = dc_sqlite3_prepare(
|
||||
(*context).sql,
|
||||
context,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
b"INSERT INTO chats (type, name, grpid, blocked) VALUES(?, ?, ?, ?);\x00" as *const u8
|
||||
as *const libc::c_char,
|
||||
);
|
||||
@@ -1696,7 +1700,8 @@ unsafe fn create_group_record(
|
||||
sqlite3_bind_int(stmt, 4i32, create_blocked);
|
||||
if !(sqlite3_step(stmt) != 101i32) {
|
||||
chat_id = dc_sqlite3_get_rowid(
|
||||
(*context).sql,
|
||||
context,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
b"chats\x00" as *const u8 as *const libc::c_char,
|
||||
b"grpid\x00" as *const u8 as *const libc::c_char,
|
||||
grpid,
|
||||
@@ -1706,7 +1711,7 @@ unsafe fn create_group_record(
|
||||
return chat_id;
|
||||
}
|
||||
unsafe fn create_adhoc_grp_id(
|
||||
mut context: *mut dc_context_t,
|
||||
mut context: &dc_context_t,
|
||||
mut member_ids: *mut dc_array_t,
|
||||
) -> *mut libc::c_char {
|
||||
/* algorithm:
|
||||
@@ -1715,14 +1720,14 @@ unsafe fn create_adhoc_grp_id(
|
||||
- sha-256 this string (without possibly terminating null-characters)
|
||||
- encode the first 64 bits of the sha-256 output as lowercase hex (results in 16 characters from the set [0-9a-f])
|
||||
*/
|
||||
let mut member_addrs: *mut dc_array_t = dc_array_new(context, 23i32 as size_t);
|
||||
let mut member_addrs: *mut dc_array_t = dc_array_new(23i32 as size_t);
|
||||
let mut member_ids_str: *mut libc::c_char =
|
||||
dc_array_get_string(member_ids, b",\x00" as *const u8 as *const libc::c_char);
|
||||
let mut stmt: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt;
|
||||
let mut q3: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut addr: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut i: libc::c_int = 0i32;
|
||||
let mut iCnt: libc::c_int = 0i32;
|
||||
let mut stmt: *mut sqlite3_stmt;
|
||||
let mut q3: *mut libc::c_char;
|
||||
let mut addr: *mut libc::c_char;
|
||||
let mut i: libc::c_int;
|
||||
let mut iCnt: libc::c_int;
|
||||
let mut ret: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut member_cs: dc_strbuilder_t = dc_strbuilder_t {
|
||||
buf: 0 as *mut libc::c_char,
|
||||
@@ -1736,9 +1741,10 @@ unsafe fn create_adhoc_grp_id(
|
||||
as *const libc::c_char,
|
||||
member_ids_str,
|
||||
);
|
||||
stmt = dc_sqlite3_prepare((*context).sql, q3);
|
||||
stmt = dc_sqlite3_prepare(context, &context.sql.clone().read().unwrap(), q3);
|
||||
addr = dc_sqlite3_get_config(
|
||||
(*context).sql,
|
||||
context,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
b"configured_addr\x00" as *const u8 as *const libc::c_char,
|
||||
b"no-self\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
@@ -1791,67 +1797,67 @@ unsafe fn create_adhoc_grp_id(
|
||||
return ret;
|
||||
}
|
||||
unsafe fn search_chat_ids_by_contact_ids(
|
||||
mut context: *mut dc_context_t,
|
||||
mut context: &dc_context_t,
|
||||
mut unsorted_contact_ids: *const dc_array_t,
|
||||
) -> *mut dc_array_t {
|
||||
/* searches chat_id's by the given contact IDs, may return zero, one or more chat_id's */
|
||||
let mut stmt: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt;
|
||||
let mut contact_ids: *mut dc_array_t = dc_array_new(context, 23i32 as size_t);
|
||||
let mut contact_ids: *mut dc_array_t = dc_array_new(23i32 as size_t);
|
||||
let mut contact_ids_str: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut q3: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut chat_ids: *mut dc_array_t = dc_array_new(context, 23i32 as size_t);
|
||||
if !(context.is_null() || (*context).magic != 0x11a11807i32 as libc::c_uint) {
|
||||
/* copy array, remove duplicates and SELF, sort by ID */
|
||||
let mut i: libc::c_int = 0;
|
||||
let mut iCnt: libc::c_int = dc_array_get_cnt(unsorted_contact_ids) as libc::c_int;
|
||||
if !(iCnt <= 0i32) {
|
||||
i = 0i32;
|
||||
while i < iCnt {
|
||||
let mut curr_id: uint32_t = dc_array_get_id(unsorted_contact_ids, i as size_t);
|
||||
if curr_id != 1i32 as libc::c_uint
|
||||
&& 0 == dc_array_search_id(contact_ids, curr_id, 0 as *mut size_t)
|
||||
{
|
||||
dc_array_add_id(contact_ids, curr_id);
|
||||
}
|
||||
i += 1
|
||||
let mut chat_ids: *mut dc_array_t = dc_array_new(23i32 as size_t);
|
||||
|
||||
/* copy array, remove duplicates and SELF, sort by ID */
|
||||
let mut i: libc::c_int;
|
||||
let mut iCnt: libc::c_int = dc_array_get_cnt(unsorted_contact_ids) as libc::c_int;
|
||||
if !(iCnt <= 0i32) {
|
||||
i = 0i32;
|
||||
while i < iCnt {
|
||||
let mut curr_id: uint32_t = dc_array_get_id(unsorted_contact_ids, i as size_t);
|
||||
if curr_id != 1i32 as libc::c_uint
|
||||
&& 0 == dc_array_search_id(contact_ids, curr_id, 0 as *mut size_t)
|
||||
{
|
||||
dc_array_add_id(contact_ids, curr_id);
|
||||
}
|
||||
if !(dc_array_get_cnt(contact_ids) == 0) {
|
||||
dc_array_sort_ids(contact_ids);
|
||||
contact_ids_str =
|
||||
dc_array_get_string(contact_ids, b",\x00" as *const u8 as *const libc::c_char);
|
||||
q3 =
|
||||
i += 1
|
||||
}
|
||||
if !(dc_array_get_cnt(contact_ids) == 0) {
|
||||
dc_array_sort_ids(contact_ids);
|
||||
contact_ids_str =
|
||||
dc_array_get_string(contact_ids, b",\x00" as *const u8 as *const libc::c_char);
|
||||
q3 =
|
||||
sqlite3_mprintf(b"SELECT DISTINCT cc.chat_id, cc.contact_id FROM chats_contacts cc LEFT JOIN chats c ON c.id=cc.chat_id WHERE cc.chat_id IN(SELECT chat_id FROM chats_contacts WHERE contact_id IN(%s)) AND c.type=120 AND cc.contact_id!=1 ORDER BY cc.chat_id, cc.contact_id;\x00"
|
||||
as *const u8 as *const libc::c_char,
|
||||
contact_ids_str);
|
||||
stmt = dc_sqlite3_prepare((*context).sql, q3);
|
||||
let mut last_chat_id = 0;
|
||||
let mut matches = 0;
|
||||
let mut mismatches = 0;
|
||||
while sqlite3_step(stmt) == 100 {
|
||||
let mut chat_id: uint32_t = sqlite3_column_int(stmt, 0i32) as uint32_t;
|
||||
let mut contact_id: uint32_t = sqlite3_column_int(stmt, 1i32) as uint32_t;
|
||||
if chat_id != last_chat_id {
|
||||
if matches == dc_array_get_cnt(contact_ids)
|
||||
&& mismatches == 0i32 as libc::c_uint
|
||||
{
|
||||
dc_array_add_id(chat_ids, last_chat_id);
|
||||
}
|
||||
last_chat_id = chat_id;
|
||||
matches = 0;
|
||||
mismatches = 0;
|
||||
}
|
||||
if contact_id == dc_array_get_id(contact_ids, matches as size_t) {
|
||||
matches = matches.wrapping_add(1)
|
||||
} else {
|
||||
mismatches = mismatches.wrapping_add(1)
|
||||
stmt = dc_sqlite3_prepare(context, &context.sql.clone().read().unwrap(), q3);
|
||||
let mut last_chat_id = 0;
|
||||
let mut matches = 0;
|
||||
let mut mismatches = 0;
|
||||
while sqlite3_step(stmt) == 100 {
|
||||
let mut chat_id: uint32_t = sqlite3_column_int(stmt, 0i32) as uint32_t;
|
||||
let mut contact_id: uint32_t = sqlite3_column_int(stmt, 1i32) as uint32_t;
|
||||
if chat_id != last_chat_id {
|
||||
if matches == dc_array_get_cnt(contact_ids)
|
||||
&& mismatches == 0i32 as libc::c_uint
|
||||
{
|
||||
dc_array_add_id(chat_ids, last_chat_id);
|
||||
}
|
||||
last_chat_id = chat_id;
|
||||
matches = 0;
|
||||
mismatches = 0;
|
||||
}
|
||||
if matches == dc_array_get_cnt(contact_ids) && mismatches == 0 {
|
||||
dc_array_add_id(chat_ids, last_chat_id);
|
||||
if contact_id == dc_array_get_id(contact_ids, matches as size_t) {
|
||||
matches = matches.wrapping_add(1)
|
||||
} else {
|
||||
mismatches = mismatches.wrapping_add(1)
|
||||
}
|
||||
}
|
||||
if matches == dc_array_get_cnt(contact_ids) && mismatches == 0 {
|
||||
dc_array_add_id(chat_ids, last_chat_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sqlite3_finalize(stmt);
|
||||
free(contact_ids_str as *mut libc::c_void);
|
||||
dc_array_unref(contact_ids);
|
||||
@@ -1859,7 +1865,7 @@ unsafe fn search_chat_ids_by_contact_ids(
|
||||
return chat_ids;
|
||||
}
|
||||
unsafe fn check_verified_properties(
|
||||
mut context: *mut dc_context_t,
|
||||
mut context: &dc_context_t,
|
||||
mut mimeparser: *mut dc_mimeparser_t,
|
||||
mut from_id: uint32_t,
|
||||
mut to_ids: *const dc_array_t,
|
||||
@@ -1872,7 +1878,7 @@ unsafe fn check_verified_properties(
|
||||
let mut to_ids_str: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut q3: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut stmt: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt;
|
||||
if 0 == dc_contact_load_from_db(contact, (*context).sql, from_id) {
|
||||
if 0 == dc_contact_load_from_db(contact, &context.sql.clone().read().unwrap(), from_id) {
|
||||
*failure_reason = dc_mprintf(
|
||||
b"%s. See \"Info\" for details.\x00" as *const u8 as *const libc::c_char,
|
||||
b"Internal Error; cannot load contact.\x00" as *const u8 as *const libc::c_char,
|
||||
@@ -1890,8 +1896,11 @@ unsafe fn check_verified_properties(
|
||||
// this check is skipped for SELF as there is no proper SELF-peerstate
|
||||
// and results in group-splits otherwise.
|
||||
if from_id != 1i32 as libc::c_uint {
|
||||
if 0 == dc_apeerstate_load_by_addr(peerstate, (*context).sql, (*contact).addr)
|
||||
|| dc_contact_is_verified_ex(contact, peerstate) != 2i32
|
||||
if 0 == dc_apeerstate_load_by_addr(
|
||||
peerstate,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
(*contact).addr,
|
||||
) || dc_contact_is_verified_ex(contact, peerstate) != 2i32
|
||||
{
|
||||
*failure_reason = dc_mprintf(
|
||||
b"%s. See \"Info\" for details.\x00" as *const u8 as *const libc::c_char,
|
||||
@@ -1928,7 +1937,7 @@ unsafe fn check_verified_properties(
|
||||
sqlite3_mprintf(b"SELECT c.addr, LENGTH(ps.verified_key_fingerprint) FROM contacts c LEFT JOIN acpeerstates ps ON c.addr=ps.addr WHERE c.id IN(%s) \x00"
|
||||
as *const u8 as *const libc::c_char,
|
||||
to_ids_str);
|
||||
stmt = dc_sqlite3_prepare((*context).sql, q3);
|
||||
stmt = dc_sqlite3_prepare(context, &context.sql.clone().read().unwrap(), q3);
|
||||
loop {
|
||||
if !(sqlite3_step(stmt) == 100i32) {
|
||||
current_block = 2604890879466389055;
|
||||
@@ -1943,7 +1952,11 @@ unsafe fn check_verified_properties(
|
||||
strlen(to_addr) as libc::c_int,
|
||||
)
|
||||
.is_null()
|
||||
&& 0 != dc_apeerstate_load_by_addr(peerstate, (*context).sql, to_addr)
|
||||
&& 0 != dc_apeerstate_load_by_addr(
|
||||
peerstate,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
to_addr,
|
||||
)
|
||||
{
|
||||
if 0 == is_verified
|
||||
|| strcmp(
|
||||
@@ -1968,7 +1981,11 @@ unsafe fn check_verified_properties(
|
||||
(*peerstate).gossip_key_fingerprint,
|
||||
2i32,
|
||||
);
|
||||
dc_apeerstate_save_to_db(peerstate, (*context).sql, 0i32);
|
||||
dc_apeerstate_save_to_db(
|
||||
peerstate,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
0i32,
|
||||
);
|
||||
is_verified = 1i32
|
||||
}
|
||||
}
|
||||
@@ -2018,12 +2035,12 @@ unsafe fn set_better_msg(
|
||||
};
|
||||
}
|
||||
unsafe fn dc_is_reply_to_known_message(
|
||||
mut context: *mut dc_context_t,
|
||||
mut context: &dc_context_t,
|
||||
mut mime_parser: *mut dc_mimeparser_t,
|
||||
) -> libc::c_int {
|
||||
/* check if the message is a reply to a known message; the replies are identified by the Message-ID from
|
||||
`In-Reply-To`/`References:` (to support non-Delta-Clients) or from `Chat-Predecessor:` (Delta clients, see comment in dc_chat.c) */
|
||||
let mut optional_field: *mut mailimf_optional_field = 0 as *mut mailimf_optional_field;
|
||||
let mut optional_field: *mut mailimf_optional_field;
|
||||
optional_field = dc_mimeparser_lookup_optional_field(
|
||||
mime_parser,
|
||||
b"Chat-Predecessor\x00" as *const u8 as *const libc::c_char,
|
||||
@@ -2033,7 +2050,7 @@ unsafe fn dc_is_reply_to_known_message(
|
||||
return 1i32;
|
||||
}
|
||||
}
|
||||
let mut field: *mut mailimf_field = 0 as *mut mailimf_field;
|
||||
let mut field: *mut mailimf_field;
|
||||
field = dc_mimeparser_lookup_field(
|
||||
mime_parser,
|
||||
b"In-Reply-To\x00" as *const u8 as *const libc::c_char,
|
||||
@@ -2067,11 +2084,11 @@ unsafe fn dc_is_reply_to_known_message(
|
||||
return 0i32;
|
||||
}
|
||||
unsafe fn is_known_rfc724_mid_in_list(
|
||||
mut context: *mut dc_context_t,
|
||||
mut context: &dc_context_t,
|
||||
mut mid_list: *const clist,
|
||||
) -> libc::c_int {
|
||||
if !mid_list.is_null() {
|
||||
let mut cur: *mut clistiter = 0 as *mut clistiter;
|
||||
let mut cur: *mut clistiter;
|
||||
cur = (*mid_list).first;
|
||||
while !cur.is_null() {
|
||||
if 0 != is_known_rfc724_mid(
|
||||
@@ -2087,7 +2104,7 @@ unsafe fn is_known_rfc724_mid_in_list(
|
||||
cur = if !cur.is_null() {
|
||||
(*cur).next
|
||||
} else {
|
||||
0 as *mut clistcell_s
|
||||
0 as *mut clistcell
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2097,13 +2114,13 @@ unsafe fn is_known_rfc724_mid_in_list(
|
||||
* Check if a message is a reply to a known message (messenger or non-messenger)
|
||||
******************************************************************************/
|
||||
unsafe fn is_known_rfc724_mid(
|
||||
mut context: *mut dc_context_t,
|
||||
mut context: &dc_context_t,
|
||||
mut rfc724_mid: *const libc::c_char,
|
||||
) -> libc::c_int {
|
||||
let mut is_known: libc::c_int = 0i32;
|
||||
if !rfc724_mid.is_null() {
|
||||
let mut stmt: *mut sqlite3_stmt =
|
||||
dc_sqlite3_prepare((*context).sql,
|
||||
dc_sqlite3_prepare(context, &context.sql.clone().read().unwrap(),
|
||||
b"SELECT m.id FROM msgs m LEFT JOIN chats c ON m.chat_id=c.id WHERE m.rfc724_mid=? AND m.chat_id>9 AND c.blocked=0;\x00"
|
||||
as *const u8 as *const libc::c_char);
|
||||
sqlite3_bind_text(stmt, 1i32, rfc724_mid, -1i32, None);
|
||||
@@ -2115,7 +2132,7 @@ unsafe fn is_known_rfc724_mid(
|
||||
return is_known;
|
||||
}
|
||||
unsafe fn dc_is_reply_to_messenger_message(
|
||||
mut context: *mut dc_context_t,
|
||||
mut context: &dc_context_t,
|
||||
mut mime_parser: *mut dc_mimeparser_t,
|
||||
) -> libc::c_int {
|
||||
/* function checks, if the message defined by mime_parser references a message send by us from Delta Chat.
|
||||
@@ -2123,7 +2140,7 @@ unsafe fn dc_is_reply_to_messenger_message(
|
||||
- checks also if any of the referenced IDs are send by a messenger
|
||||
- it is okay, if the referenced messages are moved to trash here
|
||||
- no check for the Chat-* headers (function is only called if it is no messenger message itself) */
|
||||
let mut field: *mut mailimf_field = 0 as *mut mailimf_field;
|
||||
let mut field: *mut mailimf_field;
|
||||
field = dc_mimeparser_lookup_field(
|
||||
mime_parser,
|
||||
b"In-Reply-To\x00" as *const u8 as *const libc::c_char,
|
||||
@@ -2157,7 +2174,7 @@ unsafe fn dc_is_reply_to_messenger_message(
|
||||
return 0i32;
|
||||
}
|
||||
unsafe fn is_msgrmsg_rfc724_mid_in_list(
|
||||
mut context: *mut dc_context_t,
|
||||
mut context: &dc_context_t,
|
||||
mut mid_list: *const clist,
|
||||
) -> libc::c_int {
|
||||
if !mid_list.is_null() {
|
||||
@@ -2176,7 +2193,7 @@ unsafe fn is_msgrmsg_rfc724_mid_in_list(
|
||||
cur = if !cur.is_null() {
|
||||
(*cur).next
|
||||
} else {
|
||||
0 as *mut clistcell_s
|
||||
0 as *mut clistcell
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2186,13 +2203,14 @@ unsafe fn is_msgrmsg_rfc724_mid_in_list(
|
||||
* Check if a message is a reply to any messenger message
|
||||
******************************************************************************/
|
||||
unsafe fn is_msgrmsg_rfc724_mid(
|
||||
mut context: *mut dc_context_t,
|
||||
mut context: &dc_context_t,
|
||||
mut rfc724_mid: *const libc::c_char,
|
||||
) -> libc::c_int {
|
||||
let mut is_msgrmsg: libc::c_int = 0i32;
|
||||
if !rfc724_mid.is_null() {
|
||||
let mut stmt: *mut sqlite3_stmt = dc_sqlite3_prepare(
|
||||
(*context).sql,
|
||||
context,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
b"SELECT id FROM msgs WHERE rfc724_mid=? AND msgrmsg!=0 AND chat_id>9;\x00"
|
||||
as *const u8 as *const libc::c_char,
|
||||
);
|
||||
@@ -2205,14 +2223,13 @@ unsafe fn is_msgrmsg_rfc724_mid(
|
||||
return is_msgrmsg;
|
||||
}
|
||||
unsafe fn dc_add_or_lookup_contacts_by_address_list(
|
||||
mut context: *mut dc_context_t,
|
||||
mut context: &dc_context_t,
|
||||
mut adr_list: *const mailimf_address_list,
|
||||
mut origin: libc::c_int,
|
||||
mut ids: *mut dc_array_t,
|
||||
mut check_self: *mut libc::c_int,
|
||||
) {
|
||||
if context.is_null() || (*context).magic != 0x11a11807i32 as libc::c_uint || adr_list.is_null()
|
||||
{
|
||||
if adr_list.is_null() {
|
||||
return;
|
||||
}
|
||||
let mut cur: *mut clistiter = (*(*adr_list).ad_list).first;
|
||||
@@ -2251,18 +2268,18 @@ unsafe fn dc_add_or_lookup_contacts_by_address_list(
|
||||
cur = if !cur.is_null() {
|
||||
(*cur).next
|
||||
} else {
|
||||
0 as *mut clistcell_s
|
||||
0 as *mut clistcell
|
||||
}
|
||||
}
|
||||
}
|
||||
unsafe fn dc_add_or_lookup_contacts_by_mailbox_list(
|
||||
mut context: *mut dc_context_t,
|
||||
mut context: &dc_context_t,
|
||||
mut mb_list: *const mailimf_mailbox_list,
|
||||
mut origin: libc::c_int,
|
||||
mut ids: *mut dc_array_t,
|
||||
mut check_self: *mut libc::c_int,
|
||||
) {
|
||||
if context.is_null() || (*context).magic != 0x11a11807i32 as libc::c_uint || mb_list.is_null() {
|
||||
if mb_list.is_null() {
|
||||
return;
|
||||
}
|
||||
let mut cur: *mut clistiter = (*(*mb_list).mb_list).first;
|
||||
@@ -2285,7 +2302,7 @@ unsafe fn dc_add_or_lookup_contacts_by_mailbox_list(
|
||||
cur = if !cur.is_null() {
|
||||
(*cur).next
|
||||
} else {
|
||||
0 as *mut clistcell_s
|
||||
0 as *mut clistcell
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2293,7 +2310,7 @@ unsafe fn dc_add_or_lookup_contacts_by_mailbox_list(
|
||||
* Add contacts to database on receiving messages
|
||||
******************************************************************************/
|
||||
unsafe fn add_or_lookup_contact_by_addr(
|
||||
mut context: *mut dc_context_t,
|
||||
mut context: &dc_context_t,
|
||||
mut display_name_enc: *const libc::c_char,
|
||||
mut addr_spec: *const libc::c_char,
|
||||
mut origin: libc::c_int,
|
||||
@@ -2305,13 +2322,13 @@ unsafe fn add_or_lookup_contact_by_addr(
|
||||
if check_self.is_null() {
|
||||
check_self = &mut dummy
|
||||
}
|
||||
if context.is_null() || (*context).magic != 0x11a11807i32 as libc::c_uint || addr_spec.is_null()
|
||||
{
|
||||
if addr_spec.is_null() {
|
||||
return;
|
||||
}
|
||||
*check_self = 0i32;
|
||||
let mut self_addr: *mut libc::c_char = dc_sqlite3_get_config(
|
||||
(*context).sql,
|
||||
context,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
b"configured_addr\x00" as *const u8 as *const libc::c_char,
|
||||
b"\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
use libc;
|
||||
|
||||
use crate::dc_tools::*;
|
||||
use crate::types::*;
|
||||
use crate::x::*;
|
||||
@@ -31,6 +29,7 @@ pub unsafe extern "C" fn dc_saxparser_init(
|
||||
(*saxparser).endtag_cb = Some(def_endtag_cb);
|
||||
(*saxparser).text_cb = Some(def_text_cb);
|
||||
}
|
||||
|
||||
unsafe fn def_text_cb(_userdata: *mut libc::c_void, _text: *const libc::c_char, _len: libc::c_int) {
|
||||
}
|
||||
|
||||
@@ -65,6 +64,7 @@ pub unsafe fn dc_saxparser_set_tag_handler(
|
||||
Some(def_endtag_cb)
|
||||
};
|
||||
}
|
||||
|
||||
pub unsafe fn dc_saxparser_set_text_handler(
|
||||
mut saxparser: *mut dc_saxparser_t,
|
||||
mut text_cb: dc_saxparser_text_cb_t,
|
||||
@@ -78,15 +78,16 @@ pub unsafe fn dc_saxparser_set_text_handler(
|
||||
Some(def_text_cb)
|
||||
};
|
||||
}
|
||||
|
||||
pub unsafe fn dc_saxparser_parse(
|
||||
mut saxparser: *mut dc_saxparser_t,
|
||||
mut buf_start__: *const libc::c_char,
|
||||
) {
|
||||
let mut current_block: u64;
|
||||
let mut bak: libc::c_char = 0i32 as libc::c_char;
|
||||
let mut buf_start: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut last_text_start: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut p: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut bak: libc::c_char;
|
||||
let mut buf_start: *mut libc::c_char;
|
||||
let mut last_text_start: *mut libc::c_char;
|
||||
let mut p: *mut libc::c_char;
|
||||
/* attributes per tag - a fixed border here is a security feature, not a limit */
|
||||
/* attributes as key/value pairs, +1 for terminating the list */
|
||||
let mut attr: [*mut libc::c_char; 202] = [0 as *mut libc::c_char; 202];
|
||||
@@ -205,7 +206,7 @@ pub unsafe fn dc_saxparser_parse(
|
||||
if p != beg_tag_name_0 {
|
||||
let mut after_tag_name: *mut libc::c_char = p;
|
||||
let mut attr_index: libc::c_int = 0i32;
|
||||
while 0 != isspace(*p as libc::c_int) {
|
||||
while 0 != libc::isspace(*p as libc::c_int) {
|
||||
p = p.offset(1isize)
|
||||
}
|
||||
while 0 != *p as libc::c_int
|
||||
@@ -214,7 +215,7 @@ pub unsafe fn dc_saxparser_parse(
|
||||
{
|
||||
let mut beg_attr_name: *mut libc::c_char = p;
|
||||
let mut beg_attr_value: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut beg_attr_value_new: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut beg_attr_value_new: *mut libc::c_char;
|
||||
if '=' as i32 == *beg_attr_name as libc::c_int {
|
||||
p = p.offset(1isize)
|
||||
} else {
|
||||
@@ -301,7 +302,7 @@ pub unsafe fn dc_saxparser_parse(
|
||||
attr_index += 2i32
|
||||
}
|
||||
}
|
||||
while 0 != isspace(*p as libc::c_int) {
|
||||
while 0 != libc::isspace(*p as libc::c_int) {
|
||||
p = p.offset(1isize)
|
||||
}
|
||||
}
|
||||
@@ -356,6 +357,7 @@ pub unsafe fn dc_saxparser_parse(
|
||||
do_free_attr(attr.as_mut_ptr(), free_attr.as_mut_ptr());
|
||||
free(buf_start as *mut libc::c_void);
|
||||
}
|
||||
|
||||
unsafe fn do_free_attr(mut attr: *mut *mut libc::c_char, mut free_attr: *mut libc::c_int) {
|
||||
/* "attr" are key/value pairs; the function frees the data if the corresponding bit in "free_attr" is set.
|
||||
(we need this as we try to use the strings from the "main" document instead of allocating small strings) */
|
||||
@@ -376,6 +378,7 @@ unsafe fn do_free_attr(mut attr: *mut *mut libc::c_char, mut free_attr: *mut lib
|
||||
let ref mut fresh0 = *attr.offset(0isize);
|
||||
*fresh0 = 0 as *mut libc::c_char;
|
||||
}
|
||||
|
||||
unsafe fn call_text_cb(
|
||||
mut saxparser: *mut dc_saxparser_t,
|
||||
mut text: *mut libc::c_char,
|
||||
@@ -384,7 +387,7 @@ unsafe fn call_text_cb(
|
||||
) {
|
||||
if !text.is_null() && 0 != len {
|
||||
let mut bak: libc::c_char = *text.offset(len as isize);
|
||||
let mut text_new: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut text_new: *mut libc::c_char;
|
||||
*text.offset(len as isize) = '\u{0}' as i32 as libc::c_char;
|
||||
text_new = xml_decode(text, type_0);
|
||||
(*saxparser).text_cb.expect("non-null function pointer")(
|
||||
@@ -398,6 +401,7 @@ unsafe fn call_text_cb(
|
||||
*text.offset(len as isize) = bak
|
||||
};
|
||||
}
|
||||
|
||||
/* Convert entities as ä to UTF-8 characters.
|
||||
|
||||
- The first strings MUST NOT start with `&` and MUST end with `;`.
|
||||
@@ -421,10 +425,10 @@ unsafe fn xml_decode(mut s: *mut libc::c_char, mut type_0: libc::c_char) -> *mut
|
||||
let mut e: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut r: *mut libc::c_char = s;
|
||||
let mut original_buf: *const libc::c_char = s;
|
||||
let mut b = 0;
|
||||
let mut c: isize = 0;
|
||||
let mut d: isize = 0;
|
||||
let mut l: isize = 0;
|
||||
let mut b;
|
||||
let mut c: isize;
|
||||
let mut d: isize;
|
||||
let mut l: isize;
|
||||
while 0 != *s {
|
||||
while *s as libc::c_int == '\r' as i32 {
|
||||
let fresh1 = s;
|
||||
@@ -444,7 +448,7 @@ unsafe fn xml_decode(mut s: *mut libc::c_char, mut type_0: libc::c_char) -> *mut
|
||||
loop {
|
||||
while 0 != *s as libc::c_int
|
||||
&& *s as libc::c_int != '&' as i32
|
||||
&& 0 == isspace(*s as libc::c_int)
|
||||
&& 0 == libc::isspace(*s as libc::c_int)
|
||||
{
|
||||
s = s.offset(1isize)
|
||||
}
|
||||
@@ -539,7 +543,7 @@ unsafe fn xml_decode(mut s: *mut libc::c_char, mut type_0: libc::c_char) -> *mut
|
||||
} else {
|
||||
s = s.offset(1isize)
|
||||
}
|
||||
} else if type_0 as libc::c_int == ' ' as i32 && 0 != isspace(*s as libc::c_int) {
|
||||
} else if type_0 as libc::c_int == ' ' as i32 && 0 != libc::isspace(*s as libc::c_int) {
|
||||
let fresh6 = s;
|
||||
s = s.offset(1);
|
||||
*fresh6 = ' ' as i32 as libc::c_char
|
||||
@@ -547,8 +551,10 @@ unsafe fn xml_decode(mut s: *mut libc::c_char, mut type_0: libc::c_char) -> *mut
|
||||
s = s.offset(1isize)
|
||||
}
|
||||
}
|
||||
return r;
|
||||
|
||||
r
|
||||
}
|
||||
|
||||
/* dc_saxparser_t parses XML and HTML files that may not be wellformed
|
||||
and spits out all text and tags found.
|
||||
|
||||
@@ -1077,6 +1083,7 @@ static mut s_ent: [*const libc::c_char; 508] = [
|
||||
0 as *const libc::c_char,
|
||||
0 as *const libc::c_char,
|
||||
];
|
||||
|
||||
pub unsafe fn dc_attr_find(
|
||||
mut attr: *mut *mut libc::c_char,
|
||||
mut key: *const libc::c_char,
|
||||
@@ -1090,5 +1097,6 @@ pub unsafe fn dc_attr_find(
|
||||
return *attr.offset((i + 1i32) as isize);
|
||||
}
|
||||
}
|
||||
return 0 as *const libc::c_char;
|
||||
|
||||
0 as *const libc::c_char
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use libc;
|
||||
use mmime::mailimf_types::*;
|
||||
|
||||
use crate::constants::Event;
|
||||
use crate::dc_apeerstate::*;
|
||||
@@ -25,7 +25,7 @@ use crate::types::*;
|
||||
use crate::x::*;
|
||||
|
||||
pub unsafe fn dc_get_securejoin_qr(
|
||||
mut context: *mut dc_context_t,
|
||||
mut context: &dc_context_t,
|
||||
mut group_chat_id: uint32_t,
|
||||
) -> *mut libc::c_char {
|
||||
let mut current_block: u64;
|
||||
@@ -34,101 +34,102 @@ pub unsafe fn dc_get_securejoin_qr(
|
||||
==== Step 1 in "Setup verified contact" protocol ====
|
||||
========================================================= */
|
||||
let mut qr: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut self_addr: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut self_addr: *mut libc::c_char;
|
||||
let mut self_addr_urlencoded: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut self_name: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut self_name_urlencoded: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut fingerprint: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut invitenumber: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut auth: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut invitenumber: *mut libc::c_char;
|
||||
let mut auth: *mut libc::c_char;
|
||||
let mut chat: *mut dc_chat_t = 0 as *mut dc_chat_t;
|
||||
let mut group_name: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut group_name_urlencoded: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
if !(context.is_null() || (*context).magic != 0x11a11807i32 as libc::c_uint) {
|
||||
dc_ensure_secret_key_exists(context);
|
||||
invitenumber = dc_token_lookup(context, DC_TOKEN_INVITENUMBER, group_chat_id);
|
||||
if invitenumber.is_null() {
|
||||
invitenumber = dc_create_id();
|
||||
dc_token_save(context, DC_TOKEN_INVITENUMBER, group_chat_id, invitenumber);
|
||||
}
|
||||
auth = dc_token_lookup(context, DC_TOKEN_AUTH, group_chat_id);
|
||||
if auth.is_null() {
|
||||
auth = dc_create_id();
|
||||
dc_token_save(context, DC_TOKEN_AUTH, group_chat_id, auth);
|
||||
}
|
||||
self_addr = dc_sqlite3_get_config(
|
||||
(*context).sql,
|
||||
b"configured_addr\x00" as *const u8 as *const libc::c_char,
|
||||
0 as *const libc::c_char,
|
||||
|
||||
dc_ensure_secret_key_exists(context);
|
||||
invitenumber = dc_token_lookup(context, DC_TOKEN_INVITENUMBER, group_chat_id);
|
||||
if invitenumber.is_null() {
|
||||
invitenumber = dc_create_id();
|
||||
dc_token_save(context, DC_TOKEN_INVITENUMBER, group_chat_id, invitenumber);
|
||||
}
|
||||
auth = dc_token_lookup(context, DC_TOKEN_AUTH, group_chat_id);
|
||||
if auth.is_null() {
|
||||
auth = dc_create_id();
|
||||
dc_token_save(context, DC_TOKEN_AUTH, group_chat_id, auth);
|
||||
}
|
||||
self_addr = dc_sqlite3_get_config(
|
||||
context,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
b"configured_addr\x00" as *const u8 as *const libc::c_char,
|
||||
0 as *const libc::c_char,
|
||||
);
|
||||
if self_addr.is_null() {
|
||||
dc_log_error(
|
||||
context,
|
||||
0i32,
|
||||
b"Not configured, cannot generate QR code.\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
if self_addr.is_null() {
|
||||
dc_log_error(
|
||||
context,
|
||||
0i32,
|
||||
b"Not configured, cannot generate QR code.\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
} else {
|
||||
self_name = dc_sqlite3_get_config(
|
||||
(*context).sql,
|
||||
b"displayname\x00" as *const u8 as *const libc::c_char,
|
||||
b"\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
fingerprint = get_self_fingerprint(context);
|
||||
if !fingerprint.is_null() {
|
||||
self_addr_urlencoded = dc_urlencode(self_addr);
|
||||
self_name_urlencoded = dc_urlencode(self_name);
|
||||
if 0 != group_chat_id {
|
||||
chat = dc_get_chat(context, group_chat_id);
|
||||
if chat.is_null() {
|
||||
dc_log_error(
|
||||
context,
|
||||
0i32,
|
||||
b"Cannot get QR-code for chat-id %i\x00" as *const u8
|
||||
as *const libc::c_char,
|
||||
group_chat_id,
|
||||
);
|
||||
current_block = 9531737720721467826;
|
||||
} else {
|
||||
group_name = dc_chat_get_name(chat);
|
||||
group_name_urlencoded = dc_urlencode(group_name);
|
||||
qr = dc_mprintf(
|
||||
b"OPENPGP4FPR:%s#a=%s&g=%s&x=%s&i=%s&s=%s\x00" as *const u8
|
||||
as *const libc::c_char,
|
||||
fingerprint,
|
||||
self_addr_urlencoded,
|
||||
group_name_urlencoded,
|
||||
(*chat).grpid,
|
||||
invitenumber,
|
||||
auth,
|
||||
);
|
||||
current_block = 1118134448028020070;
|
||||
}
|
||||
} else {
|
||||
self_name = dc_sqlite3_get_config(
|
||||
context,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
b"displayname\x00" as *const u8 as *const libc::c_char,
|
||||
b"\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
fingerprint = get_self_fingerprint(context);
|
||||
if !fingerprint.is_null() {
|
||||
self_addr_urlencoded = dc_urlencode(self_addr);
|
||||
self_name_urlencoded = dc_urlencode(self_name);
|
||||
if 0 != group_chat_id {
|
||||
chat = dc_get_chat(context, group_chat_id);
|
||||
if chat.is_null() {
|
||||
dc_log_error(
|
||||
context,
|
||||
0i32,
|
||||
b"Cannot get QR-code for chat-id %i\x00" as *const u8
|
||||
as *const libc::c_char,
|
||||
group_chat_id,
|
||||
);
|
||||
current_block = 9531737720721467826;
|
||||
} else {
|
||||
group_name = dc_chat_get_name(chat);
|
||||
group_name_urlencoded = dc_urlencode(group_name);
|
||||
qr = dc_mprintf(
|
||||
b"OPENPGP4FPR:%s#a=%s&n=%s&i=%s&s=%s\x00" as *const u8
|
||||
b"OPENPGP4FPR:%s#a=%s&g=%s&x=%s&i=%s&s=%s\x00" as *const u8
|
||||
as *const libc::c_char,
|
||||
fingerprint,
|
||||
self_addr_urlencoded,
|
||||
self_name_urlencoded,
|
||||
group_name_urlencoded,
|
||||
(*chat).grpid,
|
||||
invitenumber,
|
||||
auth,
|
||||
);
|
||||
current_block = 1118134448028020070;
|
||||
}
|
||||
match current_block {
|
||||
9531737720721467826 => {}
|
||||
_ => {
|
||||
dc_log_info(
|
||||
context,
|
||||
0i32,
|
||||
b"Generated QR code: %s\x00" as *const u8 as *const libc::c_char,
|
||||
qr,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
qr = dc_mprintf(
|
||||
b"OPENPGP4FPR:%s#a=%s&n=%s&i=%s&s=%s\x00" as *const u8 as *const libc::c_char,
|
||||
fingerprint,
|
||||
self_addr_urlencoded,
|
||||
self_name_urlencoded,
|
||||
invitenumber,
|
||||
auth,
|
||||
);
|
||||
current_block = 1118134448028020070;
|
||||
}
|
||||
match current_block {
|
||||
9531737720721467826 => {}
|
||||
_ => {
|
||||
dc_log_info(
|
||||
context,
|
||||
0i32,
|
||||
b"Generated QR code: %s\x00" as *const u8 as *const libc::c_char,
|
||||
qr,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
free(self_addr_urlencoded as *mut libc::c_void);
|
||||
free(self_addr as *mut libc::c_void);
|
||||
free(self_name as *mut libc::c_void);
|
||||
@@ -145,25 +146,36 @@ pub unsafe fn dc_get_securejoin_qr(
|
||||
dc_strdup(0 as *const libc::c_char)
|
||||
};
|
||||
}
|
||||
unsafe fn get_self_fingerprint(mut context: *mut dc_context_t) -> *mut libc::c_char {
|
||||
let mut self_addr: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
|
||||
unsafe fn get_self_fingerprint(mut context: &dc_context_t) -> *mut libc::c_char {
|
||||
let mut self_addr: *mut libc::c_char;
|
||||
let mut self_key: *mut dc_key_t = dc_key_new();
|
||||
let mut fingerprint: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
self_addr = dc_sqlite3_get_config(
|
||||
(*context).sql,
|
||||
context,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
b"configured_addr\x00" as *const u8 as *const libc::c_char,
|
||||
0 as *const libc::c_char,
|
||||
);
|
||||
if !(self_addr.is_null() || 0 == dc_key_load_self_public(self_key, self_addr, (*context).sql)) {
|
||||
fingerprint = dc_key_get_fingerprint(self_key);
|
||||
if !(self_addr.is_null()
|
||||
|| 0 == dc_key_load_self_public(
|
||||
context,
|
||||
self_key,
|
||||
self_addr,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
))
|
||||
{
|
||||
fingerprint = dc_key_get_fingerprint(context, self_key);
|
||||
fingerprint.is_null();
|
||||
}
|
||||
free(self_addr as *mut libc::c_void);
|
||||
dc_key_unref(self_key);
|
||||
return fingerprint;
|
||||
|
||||
fingerprint
|
||||
}
|
||||
|
||||
pub unsafe fn dc_join_securejoin(
|
||||
mut context: *mut dc_context_t,
|
||||
mut context: &dc_context_t,
|
||||
mut qr: *const libc::c_char,
|
||||
) -> uint32_t {
|
||||
/* ==========================================================
|
||||
@@ -171,11 +183,10 @@ pub unsafe fn dc_join_securejoin(
|
||||
==== Step 2 in "Setup verified contact" protocol =====
|
||||
========================================================== */
|
||||
let mut ret_chat_id: libc::c_int = 0i32;
|
||||
let mut ongoing_allocated: libc::c_int = 0i32;
|
||||
let mut ongoing_allocated: libc::c_int;
|
||||
let mut contact_chat_id: uint32_t = 0i32 as uint32_t;
|
||||
let mut join_vg: libc::c_int = 0i32;
|
||||
let mut qr_scan: *mut dc_lot_t = 0 as *mut dc_lot_t;
|
||||
let mut qr_locked: libc::c_int = 0i32;
|
||||
dc_log_info(
|
||||
context,
|
||||
0i32,
|
||||
@@ -199,16 +210,18 @@ pub unsafe fn dc_join_securejoin(
|
||||
0i32,
|
||||
b"Unknown contact.\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
} else if !(0 != (*context).shall_stop_ongoing) {
|
||||
} else if !(context
|
||||
.running_state
|
||||
.clone()
|
||||
.read()
|
||||
.unwrap()
|
||||
.shall_stop_ongoing)
|
||||
{
|
||||
join_vg = ((*qr_scan).state == 202i32) as libc::c_int;
|
||||
(*context).bobs_status = 0i32;
|
||||
pthread_mutex_lock(&mut (*context).bobs_qr_critical);
|
||||
qr_locked = 1i32;
|
||||
(*context).bobs_qr_scan = qr_scan;
|
||||
if 0 != qr_locked {
|
||||
pthread_mutex_unlock(&mut (*context).bobs_qr_critical);
|
||||
qr_locked = 0i32
|
||||
}
|
||||
let bob_a = context.bob.clone();
|
||||
let mut bob = bob_a.write().unwrap();
|
||||
bob.status = 0;
|
||||
bob.qr_scan = qr_scan;
|
||||
if 0 != fingerprint_equals_sender(context, (*qr_scan).fingerprint, contact_chat_id)
|
||||
{
|
||||
dc_log_info(
|
||||
@@ -216,8 +229,8 @@ pub unsafe fn dc_join_securejoin(
|
||||
0i32,
|
||||
b"Taking protocol shortcut.\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
(*context).bob_expects = 6i32;
|
||||
((*context).cb)(
|
||||
bob.expects = 6;
|
||||
(context.cb)(
|
||||
context,
|
||||
Event::SECUREJOIN_JOINER_PROGRESS,
|
||||
chat_id_2_contact_id(context, contact_chat_id) as uintptr_t,
|
||||
@@ -242,7 +255,7 @@ pub unsafe fn dc_join_securejoin(
|
||||
);
|
||||
free(own_fingerprint as *mut libc::c_void);
|
||||
} else {
|
||||
(*context).bob_expects = 2i32;
|
||||
bob.expects = 2;
|
||||
send_handshake_msg(
|
||||
context,
|
||||
contact_chat_id,
|
||||
@@ -257,14 +270,23 @@ pub unsafe fn dc_join_securejoin(
|
||||
);
|
||||
}
|
||||
// Bob -> Alice
|
||||
while !(0 != (*context).shall_stop_ongoing) {
|
||||
while !(context
|
||||
.running_state
|
||||
.clone()
|
||||
.read()
|
||||
.unwrap()
|
||||
.shall_stop_ongoing)
|
||||
{
|
||||
usleep((300i32 * 1000i32) as useconds_t);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
(*context).bob_expects = 0i32;
|
||||
if (*context).bobs_status == 1i32 {
|
||||
let bob_a = context.bob.clone();
|
||||
let mut bob = bob_a.write().unwrap();
|
||||
|
||||
bob.expects = 0;
|
||||
if bob.status == 1 {
|
||||
if 0 != join_vg {
|
||||
ret_chat_id = dc_get_chat_id_by_grpid(
|
||||
context,
|
||||
@@ -276,21 +298,17 @@ pub unsafe fn dc_join_securejoin(
|
||||
ret_chat_id = contact_chat_id as libc::c_int
|
||||
}
|
||||
}
|
||||
pthread_mutex_lock(&mut (*context).bobs_qr_critical);
|
||||
qr_locked = 1i32;
|
||||
(*context).bobs_qr_scan = 0 as *mut dc_lot_t;
|
||||
if 0 != qr_locked {
|
||||
pthread_mutex_unlock(&mut (*context).bobs_qr_critical);
|
||||
qr_locked = 0i32
|
||||
}
|
||||
bob.qr_scan = std::ptr::null_mut();
|
||||
|
||||
dc_lot_unref(qr_scan);
|
||||
if 0 != ongoing_allocated {
|
||||
dc_free_ongoing(context);
|
||||
}
|
||||
return ret_chat_id as uint32_t;
|
||||
ret_chat_id as uint32_t
|
||||
}
|
||||
|
||||
unsafe fn send_handshake_msg(
|
||||
mut context: *mut dc_context_t,
|
||||
mut context: &dc_context_t,
|
||||
mut contact_chat_id: uint32_t,
|
||||
mut step: *const libc::c_char,
|
||||
mut param2: *const libc::c_char,
|
||||
@@ -325,8 +343,9 @@ unsafe fn send_handshake_msg(
|
||||
dc_send_msg(context, contact_chat_id, msg);
|
||||
dc_msg_unref(msg);
|
||||
}
|
||||
|
||||
unsafe fn chat_id_2_contact_id(
|
||||
mut context: *mut dc_context_t,
|
||||
mut context: &dc_context_t,
|
||||
mut contact_chat_id: uint32_t,
|
||||
) -> uint32_t {
|
||||
let mut contact_id: uint32_t = 0i32 as uint32_t;
|
||||
@@ -335,10 +354,12 @@ unsafe fn chat_id_2_contact_id(
|
||||
contact_id = dc_array_get_id(contacts, 0i32 as size_t)
|
||||
}
|
||||
dc_array_unref(contacts);
|
||||
return contact_id;
|
||||
|
||||
contact_id
|
||||
}
|
||||
|
||||
unsafe fn fingerprint_equals_sender(
|
||||
mut context: *mut dc_context_t,
|
||||
mut context: &dc_context_t,
|
||||
mut fingerprint: *const libc::c_char,
|
||||
mut contact_chat_id: uint32_t,
|
||||
) -> libc::c_int {
|
||||
@@ -351,10 +372,14 @@ unsafe fn fingerprint_equals_sender(
|
||||
if !(0
|
||||
== dc_contact_load_from_db(
|
||||
contact,
|
||||
(*context).sql,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
dc_array_get_id(contacts, 0i32 as size_t),
|
||||
)
|
||||
|| 0 == dc_apeerstate_load_by_addr(peerstate, (*context).sql, (*contact).addr))
|
||||
|| 0 == dc_apeerstate_load_by_addr(
|
||||
peerstate,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
(*contact).addr,
|
||||
))
|
||||
{
|
||||
fingerprint_normalized = dc_normalize_fingerprint(fingerprint);
|
||||
if strcasecmp(fingerprint_normalized, (*peerstate).public_key_fingerprint) == 0i32 {
|
||||
@@ -365,18 +390,19 @@ unsafe fn fingerprint_equals_sender(
|
||||
free(fingerprint_normalized as *mut libc::c_void);
|
||||
dc_contact_unref(contact);
|
||||
dc_array_unref(contacts);
|
||||
return fingerprint_equal;
|
||||
|
||||
fingerprint_equal
|
||||
}
|
||||
|
||||
/* library private: secure-join */
|
||||
pub unsafe fn dc_handle_securejoin_handshake(
|
||||
mut context: *mut dc_context_t,
|
||||
mut mimeparser: *mut dc_mimeparser_t,
|
||||
mut contact_id: uint32_t,
|
||||
context: &dc_context_t,
|
||||
mimeparser: *mut dc_mimeparser_t,
|
||||
contact_id: uint32_t,
|
||||
) -> libc::c_int {
|
||||
let mut current_block: u64;
|
||||
let mut qr_locked: libc::c_int = 0i32;
|
||||
let mut step: *const libc::c_char = 0 as *const libc::c_char;
|
||||
let mut join_vg: libc::c_int = 0i32;
|
||||
let mut step: *const libc::c_char;
|
||||
let mut join_vg: libc::c_int;
|
||||
let mut scanned_fingerprint_of_alice: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut auth: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut own_fingerprint: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
@@ -385,7 +411,7 @@ pub unsafe fn dc_handle_securejoin_handshake(
|
||||
let mut grpid: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut ret: libc::c_int = 0i32;
|
||||
let mut contact: *mut dc_contact_t = 0 as *mut dc_contact_t;
|
||||
if !(context.is_null() || mimeparser.is_null() || contact_id <= 9i32 as libc::c_uint) {
|
||||
if !(mimeparser.is_null() || contact_id <= 9i32 as libc::c_uint) {
|
||||
step = lookup_field(
|
||||
mimeparser,
|
||||
b"Secure-Join\x00" as *const u8 as *const libc::c_char,
|
||||
@@ -422,7 +448,7 @@ pub unsafe fn dc_handle_securejoin_handshake(
|
||||
// it just ensures, we have Bobs key now. If we do _not_ have the key because eg. MitM has removed it,
|
||||
// send_message() will fail with the error "End-to-end-encryption unavailable unexpectedly.", so, there is no additional check needed here.
|
||||
// verify that the `Secure-Join-Invitenumber:`-header matches invitenumber written to the QR code
|
||||
let mut invitenumber: *const libc::c_char = 0 as *const libc::c_char;
|
||||
let mut invitenumber: *const libc::c_char;
|
||||
invitenumber = lookup_field(
|
||||
mimeparser,
|
||||
b"Secure-Join-Invitenumber\x00" as *const u8 as *const libc::c_char,
|
||||
@@ -449,7 +475,7 @@ pub unsafe fn dc_handle_securejoin_handshake(
|
||||
0i32,
|
||||
b"Secure-join requested.\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
((*context).cb)(
|
||||
(context.cb)(
|
||||
context,
|
||||
Event::SECUREJOIN_INVITER_PROGRESS,
|
||||
contact_id as uintptr_t,
|
||||
@@ -478,11 +504,10 @@ pub unsafe fn dc_handle_securejoin_handshake(
|
||||
b"vc-auth-required\x00" as *const u8 as *const libc::c_char,
|
||||
) == 0i32
|
||||
{
|
||||
pthread_mutex_lock(&mut (*context).bobs_qr_critical);
|
||||
qr_locked = 1i32;
|
||||
if (*context).bobs_qr_scan.is_null()
|
||||
|| (*context).bob_expects != 2i32
|
||||
|| 0 != join_vg && (*(*context).bobs_qr_scan).state != 202i32
|
||||
let bob_a = context.bob.clone();
|
||||
let bob = bob_a.read().unwrap();
|
||||
let scan = bob.qr_scan;
|
||||
if scan.is_null() || bob.expects != 2i32 || 0 != join_vg && (*scan).state != 202i32
|
||||
{
|
||||
dc_log_warning(
|
||||
context,
|
||||
@@ -493,15 +518,10 @@ pub unsafe fn dc_handle_securejoin_handshake(
|
||||
// no error, just aborted somehow or a mail from another handshake
|
||||
current_block = 4378276786830486580;
|
||||
} else {
|
||||
scanned_fingerprint_of_alice =
|
||||
dc_strdup((*(*context).bobs_qr_scan).fingerprint);
|
||||
auth = dc_strdup((*(*context).bobs_qr_scan).auth);
|
||||
scanned_fingerprint_of_alice = dc_strdup((*scan).fingerprint);
|
||||
auth = dc_strdup((*scan).auth);
|
||||
if 0 != join_vg {
|
||||
grpid = dc_strdup((*(*context).bobs_qr_scan).text2)
|
||||
}
|
||||
if 0 != qr_locked {
|
||||
pthread_mutex_unlock(&mut (*context).bobs_qr_critical);
|
||||
qr_locked = 0i32
|
||||
grpid = dc_strdup((*scan).text2)
|
||||
}
|
||||
if 0 == encrypted_and_signed(mimeparser, scanned_fingerprint_of_alice) {
|
||||
could_not_establish_secure_connection(
|
||||
@@ -537,13 +557,14 @@ pub unsafe fn dc_handle_securejoin_handshake(
|
||||
b"Fingerprint verified.\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
own_fingerprint = get_self_fingerprint(context);
|
||||
((*context).cb)(
|
||||
(context.cb)(
|
||||
context,
|
||||
Event::SECUREJOIN_JOINER_PROGRESS,
|
||||
contact_id as uintptr_t,
|
||||
400i32 as uintptr_t,
|
||||
);
|
||||
(*context).bob_expects = 6i32;
|
||||
context.bob.clone().write().unwrap().expects = 6;
|
||||
|
||||
send_handshake_msg(
|
||||
context,
|
||||
contact_chat_id,
|
||||
@@ -574,7 +595,7 @@ pub unsafe fn dc_handle_securejoin_handshake(
|
||||
==== Step 6 in "Out-of-band verified groups" protocol ====
|
||||
============================================================ */
|
||||
// verify that Secure-Join-Fingerprint:-header matches the fingerprint of Bob
|
||||
let mut fingerprint: *const libc::c_char = 0 as *const libc::c_char;
|
||||
let mut fingerprint: *const libc::c_char;
|
||||
fingerprint = lookup_field(
|
||||
mimeparser,
|
||||
b"Secure-Join-Fingerprint\x00" as *const u8 as *const libc::c_char,
|
||||
@@ -608,7 +629,7 @@ pub unsafe fn dc_handle_securejoin_handshake(
|
||||
b"Fingerprint verified.\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
// verify that the `Secure-Join-Auth:`-header matches the secret written to the QR code
|
||||
let mut auth_0: *const libc::c_char = 0 as *const libc::c_char;
|
||||
let mut auth_0: *const libc::c_char;
|
||||
auth_0 = lookup_field(
|
||||
mimeparser,
|
||||
b"Secure-Join-Auth\x00" as *const u8 as *const libc::c_char,
|
||||
@@ -643,13 +664,13 @@ pub unsafe fn dc_handle_securejoin_handshake(
|
||||
b"Auth verified.\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
secure_connection_established(context, contact_chat_id);
|
||||
((*context).cb)(
|
||||
(context.cb)(
|
||||
context,
|
||||
Event::CONTACTS_CHANGED,
|
||||
contact_id as uintptr_t,
|
||||
0i32 as uintptr_t,
|
||||
);
|
||||
((*context).cb)(
|
||||
(context.cb)(
|
||||
context,
|
||||
Event::SECUREJOIN_INVITER_PROGRESS,
|
||||
contact_id as uintptr_t,
|
||||
@@ -692,7 +713,7 @@ pub unsafe fn dc_handle_securejoin_handshake(
|
||||
0 as *const libc::c_char,
|
||||
0 as *const libc::c_char,
|
||||
);
|
||||
((*context).cb)(
|
||||
(context.cb)(
|
||||
context,
|
||||
Event::SECUREJOIN_INVITER_PROGRESS,
|
||||
contact_id as uintptr_t,
|
||||
@@ -714,7 +735,7 @@ pub unsafe fn dc_handle_securejoin_handshake(
|
||||
if 0 != join_vg {
|
||||
ret = 0x1i32
|
||||
}
|
||||
if (*context).bob_expects != 6i32 {
|
||||
if context.bob.clone().read().unwrap().expects != 6 {
|
||||
dc_log_info(
|
||||
context,
|
||||
0i32,
|
||||
@@ -723,11 +744,8 @@ pub unsafe fn dc_handle_securejoin_handshake(
|
||||
);
|
||||
current_block = 4378276786830486580;
|
||||
} else {
|
||||
pthread_mutex_lock(&mut (*context).bobs_qr_critical);
|
||||
qr_locked = 1i32;
|
||||
if (*context).bobs_qr_scan.is_null()
|
||||
|| 0 != join_vg && (*(*context).bobs_qr_scan).state != 202i32
|
||||
{
|
||||
let scan = context.bob.clone().read().unwrap().qr_scan;
|
||||
if scan.is_null() || 0 != join_vg && (*scan).state != 202i32 {
|
||||
dc_log_warning(
|
||||
context,
|
||||
0i32,
|
||||
@@ -736,14 +754,9 @@ pub unsafe fn dc_handle_securejoin_handshake(
|
||||
);
|
||||
current_block = 4378276786830486580;
|
||||
} else {
|
||||
scanned_fingerprint_of_alice =
|
||||
dc_strdup((*(*context).bobs_qr_scan).fingerprint);
|
||||
scanned_fingerprint_of_alice = dc_strdup((*scan).fingerprint);
|
||||
if 0 != join_vg {
|
||||
grpid = dc_strdup((*(*context).bobs_qr_scan).text2)
|
||||
}
|
||||
if 0 != qr_locked {
|
||||
pthread_mutex_unlock(&mut (*context).bobs_qr_critical);
|
||||
qr_locked = 0i32
|
||||
grpid = dc_strdup((*scan).text2)
|
||||
}
|
||||
let mut vg_expect_encrypted: libc::c_int = 1i32;
|
||||
if 0 != join_vg {
|
||||
@@ -788,7 +801,7 @@ pub unsafe fn dc_handle_securejoin_handshake(
|
||||
current_block = 4378276786830486580;
|
||||
} else {
|
||||
dc_scaleup_contact_origin(context, contact_id, 0x2000000i32);
|
||||
((*context).cb)(
|
||||
(context.cb)(
|
||||
context,
|
||||
Event::CONTACTS_CHANGED,
|
||||
0i32 as uintptr_t,
|
||||
@@ -818,7 +831,7 @@ pub unsafe fn dc_handle_securejoin_handshake(
|
||||
4378276786830486580 => {}
|
||||
_ => {
|
||||
secure_connection_established(context, contact_chat_id);
|
||||
(*context).bob_expects = 0i32;
|
||||
context.bob.clone().write().unwrap().expects = 0;
|
||||
if 0 != join_vg {
|
||||
send_handshake_msg(
|
||||
context,
|
||||
@@ -858,13 +871,13 @@ pub unsafe fn dc_handle_securejoin_handshake(
|
||||
);
|
||||
current_block = 4378276786830486580;
|
||||
} else {
|
||||
((*context).cb)(
|
||||
(context.cb)(
|
||||
context,
|
||||
Event::SECUREJOIN_INVITER_PROGRESS,
|
||||
contact_id as uintptr_t,
|
||||
800i32 as uintptr_t,
|
||||
);
|
||||
((*context).cb)(
|
||||
(context.cb)(
|
||||
context,
|
||||
Event::SECUREJOIN_INVITER_PROGRESS,
|
||||
contact_id as uintptr_t,
|
||||
@@ -885,25 +898,21 @@ pub unsafe fn dc_handle_securejoin_handshake(
|
||||
}
|
||||
}
|
||||
}
|
||||
if 0 != qr_locked {
|
||||
pthread_mutex_unlock(&mut (*context).bobs_qr_critical);
|
||||
qr_locked = 0i32
|
||||
}
|
||||
dc_contact_unref(contact);
|
||||
free(scanned_fingerprint_of_alice as *mut libc::c_void);
|
||||
free(auth as *mut libc::c_void);
|
||||
free(own_fingerprint as *mut libc::c_void);
|
||||
free(grpid as *mut libc::c_void);
|
||||
return ret;
|
||||
|
||||
ret
|
||||
}
|
||||
unsafe fn end_bobs_joining(mut context: *mut dc_context_t, mut status: libc::c_int) {
|
||||
(*context).bobs_status = status;
|
||||
|
||||
unsafe fn end_bobs_joining(context: &dc_context_t, status: libc::c_int) {
|
||||
context.bob.clone().write().unwrap().status = status;
|
||||
dc_stop_ongoing_process(context);
|
||||
}
|
||||
unsafe fn secure_connection_established(
|
||||
mut context: *mut dc_context_t,
|
||||
mut contact_chat_id: uint32_t,
|
||||
) {
|
||||
|
||||
unsafe fn secure_connection_established(mut context: &dc_context_t, mut contact_chat_id: uint32_t) {
|
||||
let mut contact_id: uint32_t = chat_id_2_contact_id(context, contact_chat_id);
|
||||
let mut contact: *mut dc_contact_t = dc_get_contact(context, contact_id);
|
||||
let mut msg: *mut libc::c_char = dc_stock_str_repl_string(
|
||||
@@ -916,7 +925,7 @@ unsafe fn secure_connection_established(
|
||||
},
|
||||
);
|
||||
dc_add_device_msg(context, contact_chat_id, msg);
|
||||
((*context).cb)(
|
||||
(context.cb)(
|
||||
context,
|
||||
Event::CHAT_MODIFIED,
|
||||
contact_chat_id as uintptr_t,
|
||||
@@ -925,6 +934,7 @@ unsafe fn secure_connection_established(
|
||||
free(msg as *mut libc::c_void);
|
||||
dc_contact_unref(contact);
|
||||
}
|
||||
|
||||
unsafe fn lookup_field(
|
||||
mut mimeparser: *mut dc_mimeparser_t,
|
||||
mut key: *const libc::c_char,
|
||||
@@ -941,15 +951,17 @@ unsafe fn lookup_field(
|
||||
{
|
||||
return 0 as *const libc::c_char;
|
||||
}
|
||||
return value;
|
||||
|
||||
value
|
||||
}
|
||||
|
||||
unsafe fn could_not_establish_secure_connection(
|
||||
mut context: *mut dc_context_t,
|
||||
mut contact_chat_id: uint32_t,
|
||||
mut details: *const libc::c_char,
|
||||
context: &dc_context_t,
|
||||
contact_chat_id: uint32_t,
|
||||
details: *const libc::c_char,
|
||||
) {
|
||||
let mut contact_id: uint32_t = chat_id_2_contact_id(context, contact_chat_id);
|
||||
let mut contact: *mut dc_contact_t = dc_get_contact(context, contact_id);
|
||||
let mut contact = dc_get_contact(context, contact_id);
|
||||
let mut msg: *mut libc::c_char = dc_stock_str_repl_string(
|
||||
context,
|
||||
36i32,
|
||||
@@ -970,26 +982,37 @@ unsafe fn could_not_establish_secure_connection(
|
||||
free(msg as *mut libc::c_void);
|
||||
dc_contact_unref(contact);
|
||||
}
|
||||
|
||||
unsafe fn mark_peer_as_verified(
|
||||
mut context: *mut dc_context_t,
|
||||
mut fingerprint: *const libc::c_char,
|
||||
context: &dc_context_t,
|
||||
fingerprint: *const libc::c_char,
|
||||
) -> libc::c_int {
|
||||
let mut success: libc::c_int = 0i32;
|
||||
let mut peerstate: *mut dc_apeerstate_t = dc_apeerstate_new(context);
|
||||
if !(0 == dc_apeerstate_load_by_fingerprint(peerstate, (*context).sql, fingerprint)) {
|
||||
let mut peerstate = dc_apeerstate_new(context);
|
||||
if !(0
|
||||
== dc_apeerstate_load_by_fingerprint(
|
||||
peerstate,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
fingerprint,
|
||||
))
|
||||
{
|
||||
if !(0 == dc_apeerstate_set_verified(peerstate, 1i32, fingerprint, 2i32)) {
|
||||
(*peerstate).prefer_encrypt = 1i32;
|
||||
(*peerstate).to_save |= 0x2i32;
|
||||
dc_apeerstate_save_to_db(peerstate, (*context).sql, 0i32);
|
||||
dc_apeerstate_save_to_db(peerstate, &context.sql.clone().read().unwrap(), 0i32);
|
||||
success = 1i32
|
||||
}
|
||||
}
|
||||
dc_apeerstate_unref(peerstate);
|
||||
return success;
|
||||
|
||||
success
|
||||
}
|
||||
|
||||
/* ******************************************************************************
|
||||
* Tools: Misc.
|
||||
******************************************************************************/
|
||||
|
||||
// TODO should return bool
|
||||
unsafe fn encrypted_and_signed(
|
||||
mut mimeparser: *mut dc_mimeparser_t,
|
||||
mut expected_fingerprint: *const libc::c_char,
|
||||
@@ -1034,16 +1057,18 @@ unsafe fn encrypted_and_signed(
|
||||
);
|
||||
return 0i32;
|
||||
}
|
||||
return 1i32;
|
||||
|
||||
1
|
||||
}
|
||||
|
||||
pub unsafe fn dc_handle_degrade_event(
|
||||
mut context: *mut dc_context_t,
|
||||
mut context: &dc_context_t,
|
||||
mut peerstate: *mut dc_apeerstate_t,
|
||||
) {
|
||||
let mut stmt: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt;
|
||||
let mut contact_id: uint32_t = 0i32 as uint32_t;
|
||||
let mut stmt;
|
||||
let mut contact_id: uint32_t;
|
||||
let mut contact_chat_id: uint32_t = 0i32 as uint32_t;
|
||||
if !(context.is_null() || peerstate.is_null()) {
|
||||
if !peerstate.is_null() {
|
||||
// - we do not issue an warning for DC_DE_ENCRYPTION_PAUSED as this is quite normal
|
||||
// - currently, we do not issue an extra warning for DC_DE_VERIFICATION_LOST - this always comes
|
||||
// together with DC_DE_FINGERPRINT_CHANGED which is logged, the idea is not to bother
|
||||
@@ -1051,7 +1076,8 @@ pub unsafe fn dc_handle_degrade_event(
|
||||
// (and he will know this and can fix this)
|
||||
if 0 != (*peerstate).degrade_event & 0x2i32 {
|
||||
stmt = dc_sqlite3_prepare(
|
||||
(*context).sql,
|
||||
context,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
b"SELECT id FROM contacts WHERE addr=?;\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
sqlite3_bind_text(stmt, 1i32, (*peerstate).addr, -1i32, None);
|
||||
@@ -1070,7 +1096,7 @@ pub unsafe fn dc_handle_degrade_event(
|
||||
dc_stock_str_repl_string(context, 37i32, (*peerstate).addr);
|
||||
dc_add_device_msg(context, contact_chat_id, msg);
|
||||
free(msg as *mut libc::c_void);
|
||||
((*context).cb)(
|
||||
(context.cb)(
|
||||
context,
|
||||
Event::CHAT_MODIFIED,
|
||||
contact_chat_id as uintptr_t,
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
use libc;
|
||||
|
||||
use crate::dc_dehtml::*;
|
||||
use crate::dc_strbuilder::*;
|
||||
use crate::dc_tools::*;
|
||||
@@ -15,19 +13,22 @@ pub struct dc_simplify_t {
|
||||
}
|
||||
|
||||
pub unsafe fn dc_simplify_new() -> *mut dc_simplify_t {
|
||||
let mut simplify: *mut dc_simplify_t = 0 as *mut dc_simplify_t;
|
||||
let mut simplify: *mut dc_simplify_t;
|
||||
simplify = calloc(1, ::std::mem::size_of::<dc_simplify_t>()) as *mut dc_simplify_t;
|
||||
if simplify.is_null() {
|
||||
exit(31i32);
|
||||
}
|
||||
return simplify;
|
||||
|
||||
simplify
|
||||
}
|
||||
|
||||
pub unsafe fn dc_simplify_unref(mut simplify: *mut dc_simplify_t) {
|
||||
if simplify.is_null() {
|
||||
return;
|
||||
}
|
||||
free(simplify as *mut libc::c_void);
|
||||
}
|
||||
|
||||
/* Simplify and normalise text: Remove quotes, signatures, unnecessary
|
||||
lineends etc.
|
||||
The data returned from Simplify() must be free()'d when no longer used, private */
|
||||
@@ -39,8 +40,8 @@ pub unsafe fn dc_simplify_simplify(
|
||||
mut is_msgrmsg: libc::c_int,
|
||||
) -> *mut libc::c_char {
|
||||
/* create a copy of the given buffer */
|
||||
let mut out: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut temp: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut out: *mut libc::c_char;
|
||||
let mut temp: *mut libc::c_char;
|
||||
if simplify.is_null() || in_unterminated.is_null() || in_bytes <= 0i32 {
|
||||
return dc_strdup(b"\x00" as *const u8 as *const libc::c_char);
|
||||
}
|
||||
@@ -68,8 +69,10 @@ pub unsafe fn dc_simplify_simplify(
|
||||
out = temp
|
||||
}
|
||||
dc_remove_cr_chars(out);
|
||||
return out;
|
||||
|
||||
out
|
||||
}
|
||||
|
||||
/* ******************************************************************************
|
||||
* Simplify Plain Text
|
||||
******************************************************************************/
|
||||
@@ -85,12 +88,12 @@ unsafe fn dc_simplify_simplify_plain_text(
|
||||
... remove a non-empty line before the removed quote (contains sth. like "On 2.9.2016, Bjoern wrote:" in different formats and lanugages) */
|
||||
/* split the given buffer into lines */
|
||||
let mut lines: *mut carray = dc_split_into_lines(buf_terminated);
|
||||
let mut l: libc::c_int = 0i32;
|
||||
let mut l: libc::c_int;
|
||||
let mut l_first: libc::c_int = 0i32;
|
||||
/* if l_last is -1, there are no lines */
|
||||
let mut l_last: libc::c_int =
|
||||
carray_count(lines).wrapping_sub(1i32 as libc::c_uint) as libc::c_int;
|
||||
let mut line: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut line: *mut libc::c_char;
|
||||
let mut footer_mark: libc::c_int = 0i32;
|
||||
l = l_first;
|
||||
while l <= l_last {
|
||||
@@ -246,11 +249,14 @@ unsafe fn dc_simplify_simplify_plain_text(
|
||||
dc_strbuilder_cat(&mut ret, b" [...]\x00" as *const u8 as *const libc::c_char);
|
||||
}
|
||||
dc_free_splitted_lines(lines);
|
||||
return ret.buf;
|
||||
|
||||
ret.buf
|
||||
}
|
||||
|
||||
/* ******************************************************************************
|
||||
* Tools
|
||||
******************************************************************************/
|
||||
// TODO should return bool /rtn
|
||||
unsafe fn is_empty_line(mut buf: *const libc::c_char) -> libc::c_int {
|
||||
/* force unsigned - otherwise the `> ' '` comparison will fail */
|
||||
let mut p1: *const libc::c_uchar = buf as *const libc::c_uchar;
|
||||
@@ -260,8 +266,11 @@ unsafe fn is_empty_line(mut buf: *const libc::c_char) -> libc::c_int {
|
||||
}
|
||||
p1 = p1.offset(1isize)
|
||||
}
|
||||
return 1i32;
|
||||
|
||||
1
|
||||
}
|
||||
|
||||
// TODO should return bool /rtn
|
||||
unsafe fn is_quoted_headline(mut buf: *const libc::c_char) -> libc::c_int {
|
||||
/* This function may be called for the line _directly_ before a quote.
|
||||
The function checks if the line contains sth. like "On 01.02.2016, xy@z wrote:" in various languages.
|
||||
@@ -274,11 +283,15 @@ unsafe fn is_quoted_headline(mut buf: *const libc::c_char) -> libc::c_int {
|
||||
if buf_len > 0i32 && *buf.offset((buf_len - 1i32) as isize) as libc::c_int == ':' as i32 {
|
||||
return 1i32;
|
||||
}
|
||||
return 0i32;
|
||||
|
||||
0
|
||||
}
|
||||
|
||||
// TODO should return bool /rtn
|
||||
unsafe fn is_plain_quote(mut buf: *const libc::c_char) -> libc::c_int {
|
||||
if *buf.offset(0isize) as libc::c_int == '>' as i32 {
|
||||
return 1i32;
|
||||
}
|
||||
return 0i32;
|
||||
|
||||
0
|
||||
}
|
||||
|
||||
664
src/dc_smtp.rs
664
src/dc_smtp.rs
@@ -1,526 +1,188 @@
|
||||
use libc;
|
||||
use std::ffi::{CStr, CString};
|
||||
|
||||
use lettre::smtp::client::net::*;
|
||||
use lettre::*;
|
||||
use native_tls::TlsConnector;
|
||||
|
||||
use crate::constants::Event;
|
||||
use crate::constants::*;
|
||||
use crate::dc_context::dc_context_t;
|
||||
use crate::dc_log::*;
|
||||
use crate::dc_loginparam::*;
|
||||
use crate::dc_oauth2::*;
|
||||
use crate::dc_tools::*;
|
||||
use crate::types::*;
|
||||
use crate::x::*;
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
#[repr(C)]
|
||||
pub struct dc_smtp_t {
|
||||
pub etpan: *mut mailsmtp,
|
||||
pub from: *mut libc::c_char,
|
||||
pub esmtp: libc::c_int,
|
||||
pub log_connect_errors: libc::c_int,
|
||||
pub context: *mut dc_context_t,
|
||||
pub struct Smtp {
|
||||
transport: Option<lettre::smtp::SmtpTransport>,
|
||||
transport_connected: bool,
|
||||
/// Email address we are sending from.
|
||||
from: Option<EmailAddress>,
|
||||
pub error: *mut libc::c_char,
|
||||
pub error_etpan: libc::c_int,
|
||||
}
|
||||
|
||||
pub unsafe fn dc_smtp_new(mut context: *mut dc_context_t) -> *mut dc_smtp_t {
|
||||
let mut smtp: *mut dc_smtp_t = 0 as *mut dc_smtp_t;
|
||||
smtp = calloc(1, ::std::mem::size_of::<dc_smtp_t>()) as *mut dc_smtp_t;
|
||||
if smtp.is_null() {
|
||||
exit(29i32);
|
||||
impl Smtp {
|
||||
/// Create a new Smtp instances.
|
||||
pub fn new() -> Self {
|
||||
Smtp {
|
||||
transport: None,
|
||||
transport_connected: false,
|
||||
from: None,
|
||||
error: std::ptr::null_mut(),
|
||||
}
|
||||
}
|
||||
(*smtp).log_connect_errors = 1i32;
|
||||
(*smtp).context = context;
|
||||
return smtp;
|
||||
}
|
||||
pub unsafe fn dc_smtp_unref(mut smtp: *mut dc_smtp_t) {
|
||||
if smtp.is_null() {
|
||||
return;
|
||||
|
||||
/// Disconnect the SMTP transport and drop it entirely.
|
||||
pub fn disconnect(&mut self) {
|
||||
if self.transport.is_none() || !self.transport_connected {
|
||||
return;
|
||||
}
|
||||
|
||||
let mut transport = self.transport.take().unwrap();
|
||||
transport.close();
|
||||
self.transport_connected = false;
|
||||
}
|
||||
dc_smtp_disconnect(smtp);
|
||||
free((*smtp).from as *mut libc::c_void);
|
||||
free((*smtp).error as *mut libc::c_void);
|
||||
free(smtp as *mut libc::c_void);
|
||||
}
|
||||
pub unsafe fn dc_smtp_disconnect(mut smtp: *mut dc_smtp_t) {
|
||||
if smtp.is_null() {
|
||||
return;
|
||||
|
||||
/// Check if a connection already exists.
|
||||
pub fn is_connected(&self) -> bool {
|
||||
self.transport.is_some()
|
||||
}
|
||||
if !(*smtp).etpan.is_null() {
|
||||
mailsmtp_free((*smtp).etpan);
|
||||
(*smtp).etpan = 0 as *mut mailsmtp
|
||||
};
|
||||
}
|
||||
pub unsafe fn dc_smtp_is_connected(mut smtp: *const dc_smtp_t) -> libc::c_int {
|
||||
return if !smtp.is_null() && !(*smtp).etpan.is_null() {
|
||||
1i32
|
||||
} else {
|
||||
0i32
|
||||
};
|
||||
}
|
||||
pub unsafe fn dc_smtp_connect(
|
||||
mut smtp: *mut dc_smtp_t,
|
||||
mut lp: *const dc_loginparam_t,
|
||||
) -> libc::c_int {
|
||||
let mut current_block: u64;
|
||||
let mut success: libc::c_int = 0i32;
|
||||
let mut r: libc::c_int = 0i32;
|
||||
let mut try_esmtp: libc::c_int = 0i32;
|
||||
if smtp.is_null() || lp.is_null() {
|
||||
return 0i32;
|
||||
}
|
||||
if !(*smtp).etpan.is_null() {
|
||||
dc_log_warning(
|
||||
(*smtp).context,
|
||||
0i32,
|
||||
b"SMTP already connected.\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
success = 1i32
|
||||
} else if (*lp).addr.is_null() || (*lp).send_server.is_null() || (*lp).send_port == 0i32 {
|
||||
dc_log_event_seq(
|
||||
(*smtp).context,
|
||||
Event::ERROR_NETWORK,
|
||||
&mut (*smtp).log_connect_errors as *mut libc::c_int,
|
||||
b"SMTP bad parameters.\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
} else {
|
||||
free((*smtp).from as *mut libc::c_void);
|
||||
(*smtp).from = dc_strdup((*lp).addr);
|
||||
(*smtp).etpan = mailsmtp_new(0i32 as size_t, None);
|
||||
if (*smtp).etpan.is_null() {
|
||||
dc_log_error(
|
||||
(*smtp).context,
|
||||
0i32,
|
||||
b"SMTP-object creation failed.\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
|
||||
/// Connect using the provided login params
|
||||
pub fn connect(&mut self, context: &dc_context_t, lp: *const dc_loginparam_t) -> usize {
|
||||
if lp.is_null() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if self.is_connected() {
|
||||
warn!(context, 0, "SMTP already connected.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Safe because we checked for null pointer above.
|
||||
let lp = unsafe { *lp };
|
||||
|
||||
if lp.addr.is_null() || lp.send_server.is_null() || lp.send_port == 0 {
|
||||
unsafe {
|
||||
dc_log_event(
|
||||
context,
|
||||
Event::ERROR_NETWORK,
|
||||
0,
|
||||
b"SMTP bad parameters.\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
let raw_addr = unsafe {
|
||||
CStr::from_ptr(lp.addr)
|
||||
.to_str()
|
||||
.expect("invalid from address")
|
||||
.to_string()
|
||||
};
|
||||
self.from = if let Ok(addr) = EmailAddress::new(raw_addr) {
|
||||
Some(addr)
|
||||
} else {
|
||||
mailsmtp_set_timeout((*smtp).etpan, 10i32 as time_t);
|
||||
mailsmtp_set_progress_callback(
|
||||
(*smtp).etpan,
|
||||
Some(body_progress),
|
||||
smtp as *mut libc::c_void,
|
||||
);
|
||||
/* connect to SMTP server */
|
||||
if 0 != (*lp).server_flags & (0x10000i32 | 0x40000i32) {
|
||||
r = mailsmtp_socket_connect(
|
||||
(*smtp).etpan,
|
||||
(*lp).send_server,
|
||||
(*lp).send_port as uint16_t,
|
||||
);
|
||||
if r != MAILSMTP_NO_ERROR as libc::c_int {
|
||||
dc_log_event_seq(
|
||||
(*smtp).context,
|
||||
Event::ERROR_NETWORK,
|
||||
&mut (*smtp).log_connect_errors as *mut libc::c_int,
|
||||
b"SMTP-Socket connection to %s:%i failed (%s)\x00" as *const u8
|
||||
as *const libc::c_char,
|
||||
(*lp).send_server,
|
||||
(*lp).send_port as libc::c_int,
|
||||
mailsmtp_strerror(r),
|
||||
);
|
||||
current_block = 12512295087047028901;
|
||||
} else {
|
||||
current_block = 10043043949733653460;
|
||||
}
|
||||
} else {
|
||||
r = mailsmtp_ssl_connect(
|
||||
(*smtp).etpan,
|
||||
(*lp).send_server,
|
||||
(*lp).send_port as uint16_t,
|
||||
);
|
||||
if r != MAILSMTP_NO_ERROR as libc::c_int {
|
||||
dc_log_event_seq(
|
||||
(*smtp).context,
|
||||
Event::ERROR_NETWORK,
|
||||
&mut (*smtp).log_connect_errors as *mut libc::c_int,
|
||||
b"SMTP-SSL connection to %s:%i failed (%s)\x00" as *const u8
|
||||
as *const libc::c_char,
|
||||
(*lp).send_server,
|
||||
(*lp).send_port as libc::c_int,
|
||||
mailsmtp_strerror(r),
|
||||
);
|
||||
current_block = 12512295087047028901;
|
||||
} else {
|
||||
current_block = 10043043949733653460;
|
||||
}
|
||||
}
|
||||
match current_block {
|
||||
12512295087047028901 => {}
|
||||
_ => {
|
||||
try_esmtp = 1i32;
|
||||
(*smtp).esmtp = 0i32;
|
||||
if 0 != try_esmtp && {
|
||||
r = mailesmtp_ehlo((*smtp).etpan);
|
||||
r == MAILSMTP_NO_ERROR as libc::c_int
|
||||
} {
|
||||
(*smtp).esmtp = 1i32
|
||||
} else if 0 == try_esmtp || r == MAILSMTP_ERROR_NOT_IMPLEMENTED as libc::c_int {
|
||||
r = mailsmtp_helo((*smtp).etpan)
|
||||
}
|
||||
if r != MAILSMTP_NO_ERROR as libc::c_int {
|
||||
dc_log_event_seq(
|
||||
(*smtp).context,
|
||||
Event::ERROR_NETWORK,
|
||||
&mut (*smtp).log_connect_errors as *mut libc::c_int,
|
||||
b"SMTP-helo failed (%s)\x00" as *const u8 as *const libc::c_char,
|
||||
mailsmtp_strerror(r),
|
||||
);
|
||||
} else {
|
||||
if 0 != (*lp).server_flags & 0x10000i32 {
|
||||
r = mailsmtp_socket_starttls((*smtp).etpan);
|
||||
if r != MAILSMTP_NO_ERROR as libc::c_int {
|
||||
dc_log_event_seq(
|
||||
(*smtp).context,
|
||||
Event::ERROR_NETWORK,
|
||||
&mut (*smtp).log_connect_errors as *mut libc::c_int,
|
||||
b"SMTP-STARTTLS failed (%s)\x00" as *const u8
|
||||
as *const libc::c_char,
|
||||
mailsmtp_strerror(r),
|
||||
);
|
||||
current_block = 12512295087047028901;
|
||||
} else {
|
||||
(*smtp).esmtp = 0i32;
|
||||
if 0 != try_esmtp && {
|
||||
r = mailesmtp_ehlo((*smtp).etpan);
|
||||
r == MAILSMTP_NO_ERROR as libc::c_int
|
||||
} {
|
||||
(*smtp).esmtp = 1i32
|
||||
} else if 0 == try_esmtp
|
||||
|| r == MAILSMTP_ERROR_NOT_IMPLEMENTED as libc::c_int
|
||||
{
|
||||
r = mailsmtp_helo((*smtp).etpan)
|
||||
}
|
||||
if r != MAILSMTP_NO_ERROR as libc::c_int {
|
||||
dc_log_event_seq(
|
||||
(*smtp).context,
|
||||
Event::ERROR_NETWORK,
|
||||
&mut (*smtp).log_connect_errors as *mut libc::c_int,
|
||||
b"SMTP-helo failed (%s)\x00" as *const u8
|
||||
as *const libc::c_char,
|
||||
mailsmtp_strerror(r),
|
||||
);
|
||||
current_block = 12512295087047028901;
|
||||
} else {
|
||||
dc_log_info(
|
||||
(*smtp).context,
|
||||
0i32,
|
||||
b"SMTP-server %s:%i STARTTLS-connected.\x00" as *const u8
|
||||
as *const libc::c_char,
|
||||
(*lp).send_server,
|
||||
(*lp).send_port as libc::c_int,
|
||||
);
|
||||
current_block = 5892776923941496671;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if 0 != (*lp).server_flags & 0x40000i32 {
|
||||
dc_log_info(
|
||||
(*smtp).context,
|
||||
0i32,
|
||||
b"SMTP-server %s:%i connected.\x00" as *const u8
|
||||
as *const libc::c_char,
|
||||
(*lp).send_server,
|
||||
(*lp).send_port as libc::c_int,
|
||||
);
|
||||
} else {
|
||||
dc_log_info(
|
||||
(*smtp).context,
|
||||
0i32,
|
||||
b"SMTP-server %s:%i SSL-connected.\x00" as *const u8
|
||||
as *const libc::c_char,
|
||||
(*lp).send_server,
|
||||
(*lp).send_port as libc::c_int,
|
||||
);
|
||||
}
|
||||
current_block = 5892776923941496671;
|
||||
}
|
||||
match current_block {
|
||||
12512295087047028901 => {}
|
||||
_ => {
|
||||
if !(*lp).send_user.is_null() {
|
||||
if 0 != (*lp).server_flags & 0x2i32 {
|
||||
dc_log_info(
|
||||
(*smtp).context,
|
||||
0i32,
|
||||
b"SMTP-OAuth2 connect...\x00" as *const u8
|
||||
as *const libc::c_char,
|
||||
);
|
||||
let mut access_token: *mut libc::c_char =
|
||||
dc_get_oauth2_access_token(
|
||||
(*smtp).context,
|
||||
(*lp).addr,
|
||||
(*lp).send_pw,
|
||||
0i32,
|
||||
);
|
||||
r = mailsmtp_oauth2_authenticate(
|
||||
(*smtp).etpan,
|
||||
(*lp).send_user,
|
||||
access_token,
|
||||
);
|
||||
if r != MAILSMTP_NO_ERROR as libc::c_int {
|
||||
free(access_token as *mut libc::c_void);
|
||||
access_token = dc_get_oauth2_access_token(
|
||||
(*smtp).context,
|
||||
(*lp).addr,
|
||||
(*lp).send_pw,
|
||||
0x1i32,
|
||||
);
|
||||
r = mailsmtp_oauth2_authenticate(
|
||||
(*smtp).etpan,
|
||||
(*lp).send_user,
|
||||
access_token,
|
||||
)
|
||||
}
|
||||
free(access_token as *mut libc::c_void);
|
||||
current_block = 15462640364611497761;
|
||||
} else {
|
||||
r = mailsmtp_auth(
|
||||
(*smtp).etpan,
|
||||
(*lp).send_user,
|
||||
(*lp).send_pw,
|
||||
);
|
||||
if r != MAILSMTP_NO_ERROR as libc::c_int {
|
||||
/*
|
||||
* There are some Mailservers which do not correclty implement PLAIN auth (hMail)
|
||||
* So here we try a workaround. See https://github.com/deltachat/deltachat-android/issues/67
|
||||
*/
|
||||
if 0 != (*(*smtp).etpan).auth
|
||||
& MAILSMTP_AUTH_PLAIN as libc::c_int
|
||||
{
|
||||
dc_log_info(
|
||||
(*smtp).context,
|
||||
0i32,
|
||||
b"Trying SMTP-Login workaround \"%s\"...\x00"
|
||||
as *const u8
|
||||
as *const libc::c_char,
|
||||
(*lp).send_user,
|
||||
);
|
||||
let mut err: libc::c_int = 0;
|
||||
let mut hostname: [libc::c_char; 513] = [0; 513];
|
||||
err = gethostname(
|
||||
hostname.as_mut_ptr(),
|
||||
::std::mem::size_of::<[libc::c_char; 513]>(),
|
||||
);
|
||||
if err < 0i32 {
|
||||
dc_log_error(
|
||||
(*smtp).context,
|
||||
0i32,
|
||||
b"SMTP-Login: Cannot get hostname.\x00"
|
||||
as *const u8
|
||||
as *const libc::c_char,
|
||||
);
|
||||
current_block = 12512295087047028901;
|
||||
} else {
|
||||
r = mailesmtp_auth_sasl(
|
||||
(*smtp).etpan,
|
||||
b"PLAIN\x00" as *const u8
|
||||
as *const libc::c_char,
|
||||
hostname.as_mut_ptr(),
|
||||
0 as *const libc::c_char,
|
||||
0 as *const libc::c_char,
|
||||
0 as *const libc::c_char,
|
||||
(*lp).send_user,
|
||||
(*lp).send_pw,
|
||||
0 as *const libc::c_char,
|
||||
);
|
||||
current_block = 15462640364611497761;
|
||||
}
|
||||
} else {
|
||||
current_block = 15462640364611497761;
|
||||
}
|
||||
} else {
|
||||
current_block = 15462640364611497761;
|
||||
}
|
||||
}
|
||||
match current_block {
|
||||
12512295087047028901 => {}
|
||||
_ => {
|
||||
if r != MAILSMTP_NO_ERROR as libc::c_int {
|
||||
dc_log_event_seq(
|
||||
(*smtp).context,
|
||||
Event::ERROR_NETWORK,
|
||||
&mut (*smtp).log_connect_errors
|
||||
as *mut libc::c_int,
|
||||
b"SMTP-login failed for user %s (%s)\x00"
|
||||
as *const u8
|
||||
as *const libc::c_char,
|
||||
(*lp).send_user,
|
||||
mailsmtp_strerror(r),
|
||||
);
|
||||
current_block = 12512295087047028901;
|
||||
} else {
|
||||
dc_log_event(
|
||||
(*smtp).context,
|
||||
Event::SMTP_CONNECTED,
|
||||
0i32,
|
||||
b"SMTP-login as %s ok.\x00" as *const u8
|
||||
as *const libc::c_char,
|
||||
(*lp).send_user,
|
||||
);
|
||||
current_block = 3736434875406665187;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
current_block = 3736434875406665187;
|
||||
}
|
||||
match current_block {
|
||||
12512295087047028901 => {}
|
||||
_ => success = 1i32,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if 0 == success {
|
||||
if !(*smtp).etpan.is_null() {
|
||||
mailsmtp_free((*smtp).etpan);
|
||||
(*smtp).etpan = 0 as *mut mailsmtp
|
||||
}
|
||||
}
|
||||
return success;
|
||||
}
|
||||
unsafe extern "C" fn body_progress(
|
||||
_current: size_t,
|
||||
_maximum: size_t,
|
||||
_user_data: *mut libc::c_void,
|
||||
) {
|
||||
}
|
||||
None
|
||||
};
|
||||
|
||||
pub unsafe fn dc_smtp_send_msg(
|
||||
mut smtp: *mut dc_smtp_t,
|
||||
mut recipients: *const clist,
|
||||
mut data_not_terminated: *const libc::c_char,
|
||||
mut data_bytes: size_t,
|
||||
) -> libc::c_int {
|
||||
let mut current_block: u64;
|
||||
let mut success: libc::c_int = 0i32;
|
||||
let mut r: libc::c_int = 0i32;
|
||||
let mut iter: *mut clistiter = 0 as *mut clistiter;
|
||||
if !smtp.is_null() {
|
||||
if recipients.is_null()
|
||||
|| (*recipients).count == 0i32
|
||||
|| data_not_terminated.is_null()
|
||||
|| data_bytes == 0
|
||||
if self.from.is_none() {
|
||||
// TODO: print error
|
||||
return 0;
|
||||
}
|
||||
|
||||
let domain = unsafe {
|
||||
CStr::from_ptr(lp.send_server)
|
||||
.to_str()
|
||||
.expect("invalid send server")
|
||||
};
|
||||
let port = lp.send_port as u16;
|
||||
|
||||
let mut tls_builder = TlsConnector::builder();
|
||||
tls_builder.min_protocol_version(Some(DEFAULT_TLS_PROTOCOLS[0]));
|
||||
|
||||
let tls_parameters =
|
||||
ClientTlsParameters::new(domain.to_string(), tls_builder.build().unwrap());
|
||||
|
||||
let creds = if 0 != lp.server_flags & (DC_LP_AUTH_OAUTH2 as i32) {
|
||||
// oauth2
|
||||
|
||||
let mut access_token =
|
||||
unsafe { dc_get_oauth2_access_token(context, lp.addr, lp.send_pw, 0i32) };
|
||||
if access_token.is_null() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
let user = unsafe { CStr::from_ptr(lp.send_user).to_str().unwrap().to_string() };
|
||||
let token = unsafe { CStr::from_ptr(access_token).to_str().unwrap().to_string() };
|
||||
unsafe { free(access_token as *mut libc::c_void) };
|
||||
|
||||
lettre::smtp::authentication::Credentials::new(user, token)
|
||||
} else {
|
||||
// plain
|
||||
let user = unsafe { CStr::from_ptr(lp.send_user).to_str().unwrap().to_string() };
|
||||
let pw = unsafe { CStr::from_ptr(lp.send_pw).to_str().unwrap().to_string() };
|
||||
lettre::smtp::authentication::Credentials::new(user, pw)
|
||||
};
|
||||
|
||||
let security = if 0
|
||||
!= lp.server_flags & (DC_LP_SMTP_SOCKET_STARTTLS | DC_LP_SMTP_SOCKET_PLAIN) as i32
|
||||
{
|
||||
success = 1i32
|
||||
} else if !(*smtp).etpan.is_null() {
|
||||
// set source
|
||||
// the `etPanSMTPTest` is the ENVID from RFC 3461 (SMTP DSNs), we should probably replace it by a random value
|
||||
r = if 0 != (*smtp).esmtp {
|
||||
mailesmtp_mail(
|
||||
(*smtp).etpan,
|
||||
(*smtp).from,
|
||||
1i32,
|
||||
b"etPanSMTPTest\x00" as *const u8 as *const libc::c_char,
|
||||
)
|
||||
} else {
|
||||
mailsmtp_mail((*smtp).etpan, (*smtp).from)
|
||||
};
|
||||
if r != MAILSMTP_NO_ERROR as libc::c_int {
|
||||
log_error(
|
||||
smtp,
|
||||
b"SMTP failed to start message\x00" as *const u8 as *const libc::c_char,
|
||||
r,
|
||||
);
|
||||
} else {
|
||||
// set recipients
|
||||
// if the recipient is on the same server, this may fail at once.
|
||||
// TODO: question is what to do if one recipient in a group fails
|
||||
iter = (*recipients).first;
|
||||
loop {
|
||||
if iter.is_null() {
|
||||
current_block = 12039483399334584727;
|
||||
break;
|
||||
}
|
||||
let mut rcpt: *const libc::c_char = (if !iter.is_null() {
|
||||
(*iter).data
|
||||
} else {
|
||||
0 as *mut libc::c_void
|
||||
})
|
||||
as *const libc::c_char;
|
||||
r = if 0 != (*smtp).esmtp {
|
||||
mailesmtp_rcpt((*smtp).etpan, rcpt, 2i32 | 4i32, 0 as *const libc::c_char)
|
||||
} else {
|
||||
mailsmtp_rcpt((*smtp).etpan, rcpt)
|
||||
};
|
||||
if r != MAILSMTP_NO_ERROR as libc::c_int {
|
||||
log_error(
|
||||
smtp,
|
||||
b"SMTP failed to add recipient\x00" as *const u8 as *const libc::c_char,
|
||||
r,
|
||||
lettre::smtp::ClientSecurity::Opportunistic(tls_parameters)
|
||||
} else {
|
||||
lettre::smtp::ClientSecurity::Wrapper(tls_parameters)
|
||||
};
|
||||
|
||||
let client = lettre::smtp::SmtpClient::new((domain, port), security)
|
||||
.expect("failed to construct stmp client")
|
||||
.smtp_utf8(true)
|
||||
.credentials(creds)
|
||||
.connection_reuse(lettre::smtp::ConnectionReuseParameters::ReuseUnlimited);
|
||||
|
||||
self.transport = Some(client.transport());
|
||||
|
||||
1
|
||||
}
|
||||
|
||||
pub fn send<'a>(
|
||||
&mut self,
|
||||
context: &dc_context_t,
|
||||
recipients: Vec<EmailAddress>,
|
||||
body: Vec<u8>,
|
||||
) -> usize {
|
||||
if let Some(ref mut transport) = self.transport {
|
||||
let envelope = Envelope::new(self.from.clone(), recipients).expect("invalid envelope");
|
||||
let mail = SendableEmail::new(
|
||||
envelope,
|
||||
"mail-id".into(), // TODO: random id
|
||||
body,
|
||||
);
|
||||
|
||||
match transport.send(mail) {
|
||||
Ok(_) => {
|
||||
unsafe {
|
||||
dc_log_event(
|
||||
context,
|
||||
Event::SMTP_MESSAGE_SENT,
|
||||
0,
|
||||
b"Message was sent to SMTP server\x00" as *const u8
|
||||
as *const libc::c_char,
|
||||
);
|
||||
current_block = 5498835644851925448;
|
||||
break;
|
||||
} else {
|
||||
iter = if !iter.is_null() {
|
||||
(*iter).next
|
||||
} else {
|
||||
0 as *mut clistcell_s
|
||||
}
|
||||
}
|
||||
self.transport_connected = true;
|
||||
1
|
||||
}
|
||||
match current_block {
|
||||
5498835644851925448 => {}
|
||||
_ => {
|
||||
// message
|
||||
r = mailsmtp_data((*smtp).etpan);
|
||||
if r != MAILSMTP_NO_ERROR as libc::c_int {
|
||||
log_error(
|
||||
smtp,
|
||||
b"SMTP failed to set data\x00" as *const u8 as *const libc::c_char,
|
||||
r,
|
||||
);
|
||||
} else {
|
||||
r = mailsmtp_data_message(
|
||||
(*smtp).etpan,
|
||||
data_not_terminated,
|
||||
data_bytes,
|
||||
);
|
||||
if r != MAILSMTP_NO_ERROR as libc::c_int {
|
||||
log_error(
|
||||
smtp,
|
||||
b"SMTP failed to send message\x00" as *const u8
|
||||
as *const libc::c_char,
|
||||
r,
|
||||
);
|
||||
} else {
|
||||
dc_log_event(
|
||||
(*smtp).context,
|
||||
Event::SMTP_MESSAGE_SENT,
|
||||
0i32,
|
||||
b"Message was sent to SMTP server\x00" as *const u8
|
||||
as *const libc::c_char,
|
||||
);
|
||||
success = 1i32
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
let error_msg = format!("SMTP failed to send message: {:?}", err);
|
||||
let msg = CString::new(error_msg).unwrap();
|
||||
self.error = unsafe { libc::strdup(msg.as_ptr()) };
|
||||
|
||||
warn!(context, 0, "%s", msg,);
|
||||
|
||||
0
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// TODO: log error
|
||||
0
|
||||
}
|
||||
}
|
||||
return success;
|
||||
}
|
||||
unsafe fn log_error(
|
||||
mut smtp: *mut dc_smtp_t,
|
||||
mut what_failed: *const libc::c_char,
|
||||
mut r: libc::c_int,
|
||||
) {
|
||||
let mut error_msg: *mut libc::c_char = dc_mprintf(
|
||||
b"%s: %s: %s\x00" as *const u8 as *const libc::c_char,
|
||||
what_failed,
|
||||
mailsmtp_strerror(r),
|
||||
(*(*smtp).etpan).response,
|
||||
);
|
||||
dc_log_warning(
|
||||
(*smtp).context,
|
||||
0i32,
|
||||
b"%s\x00" as *const u8 as *const libc::c_char,
|
||||
error_msg,
|
||||
);
|
||||
free((*smtp).error as *mut libc::c_void);
|
||||
(*smtp).error = error_msg;
|
||||
(*smtp).error_etpan = r;
|
||||
}
|
||||
|
||||
1125
src/dc_sqlite3.rs
1125
src/dc_sqlite3.rs
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,3 @@
|
||||
use libc;
|
||||
|
||||
use crate::constants::Event;
|
||||
use crate::dc_contact::*;
|
||||
use crate::dc_context::dc_context_t;
|
||||
@@ -9,35 +7,36 @@ use crate::x::*;
|
||||
|
||||
/* Return the string with the given ID by calling DC_EVENT_GET_STRING.
|
||||
The result must be free()'d! */
|
||||
pub unsafe fn dc_stock_str(
|
||||
mut context: *mut dc_context_t,
|
||||
mut id: libc::c_int,
|
||||
) -> *mut libc::c_char {
|
||||
pub unsafe fn dc_stock_str(mut context: &dc_context_t, mut id: libc::c_int) -> *mut libc::c_char {
|
||||
return get_string(context, id, 0i32);
|
||||
}
|
||||
|
||||
unsafe fn get_string(
|
||||
mut context: *mut dc_context_t,
|
||||
mut context: &dc_context_t,
|
||||
mut id: libc::c_int,
|
||||
mut qty: libc::c_int,
|
||||
) -> *mut libc::c_char {
|
||||
let mut ret: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
if !context.is_null() {
|
||||
ret = ((*context).cb)(
|
||||
context,
|
||||
Event::GET_STRING,
|
||||
id as uintptr_t,
|
||||
qty as uintptr_t,
|
||||
) as *mut libc::c_char;
|
||||
}
|
||||
let mut ret: *mut libc::c_char;
|
||||
|
||||
ret = ((*context).cb)(
|
||||
context,
|
||||
Event::GET_STRING,
|
||||
id as uintptr_t,
|
||||
qty as uintptr_t,
|
||||
) as *mut libc::c_char;
|
||||
|
||||
if ret.is_null() {
|
||||
ret = default_string(id)
|
||||
}
|
||||
return ret;
|
||||
|
||||
ret
|
||||
}
|
||||
|
||||
/* Add translated strings that are used by the messager backend.
|
||||
As the logging functions may use these strings, do not log any
|
||||
errors from here. */
|
||||
unsafe fn default_string(mut id: libc::c_int) -> *mut libc::c_char {
|
||||
// TODO match on enum values /rtn
|
||||
match id {
|
||||
1 => {
|
||||
return dc_strdup(b"No messages.\x00" as *const u8 as
|
||||
@@ -210,12 +209,14 @@ unsafe fn default_string(mut id: libc::c_int) -> *mut libc::c_char {
|
||||
}
|
||||
_ => { }
|
||||
}
|
||||
return dc_strdup(b"ErrStr\x00" as *const u8 as *const libc::c_char);
|
||||
|
||||
dc_strdup(b"ErrStr\x00" as *const u8 as *const libc::c_char)
|
||||
}
|
||||
|
||||
/* Replaces the first `%1$s` in the given String-ID by the given value.
|
||||
The result must be free()'d! */
|
||||
pub unsafe fn dc_stock_str_repl_string(
|
||||
mut context: *mut dc_context_t,
|
||||
mut context: &dc_context_t,
|
||||
mut id: libc::c_int,
|
||||
mut to_insert: *const libc::c_char,
|
||||
) -> *mut libc::c_char {
|
||||
@@ -230,10 +231,12 @@ pub unsafe fn dc_stock_str_repl_string(
|
||||
b"%1$d\x00" as *const u8 as *const libc::c_char,
|
||||
to_insert,
|
||||
);
|
||||
return ret;
|
||||
|
||||
ret
|
||||
}
|
||||
|
||||
pub unsafe fn dc_stock_str_repl_int(
|
||||
mut context: *mut dc_context_t,
|
||||
mut context: &dc_context_t,
|
||||
mut id: libc::c_int,
|
||||
mut to_insert_int: libc::c_int,
|
||||
) -> *mut libc::c_char {
|
||||
@@ -253,12 +256,14 @@ pub unsafe fn dc_stock_str_repl_int(
|
||||
to_insert_str,
|
||||
);
|
||||
free(to_insert_str as *mut libc::c_void);
|
||||
return ret;
|
||||
|
||||
ret
|
||||
}
|
||||
|
||||
/* Replaces the first `%1$s` and `%2$s` in the given String-ID by the two given strings.
|
||||
The result must be free()'d! */
|
||||
pub unsafe fn dc_stock_str_repl_string2(
|
||||
mut context: *mut dc_context_t,
|
||||
mut context: &dc_context_t,
|
||||
mut id: libc::c_int,
|
||||
mut to_insert: *const libc::c_char,
|
||||
mut to_insert2: *const libc::c_char,
|
||||
@@ -284,17 +289,19 @@ pub unsafe fn dc_stock_str_repl_string2(
|
||||
b"%2$d\x00" as *const u8 as *const libc::c_char,
|
||||
to_insert2,
|
||||
);
|
||||
return ret;
|
||||
|
||||
ret
|
||||
}
|
||||
|
||||
/* Misc. */
|
||||
pub unsafe fn dc_stock_system_msg(
|
||||
mut context: *mut dc_context_t,
|
||||
mut context: &dc_context_t,
|
||||
mut str_id: libc::c_int,
|
||||
mut param1: *const libc::c_char,
|
||||
mut param2: *const libc::c_char,
|
||||
mut from_id: uint32_t,
|
||||
) -> *mut libc::c_char {
|
||||
let mut ret: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut ret: *mut libc::c_char;
|
||||
let mut mod_contact: *mut dc_contact_t = 0 as *mut dc_contact_t;
|
||||
let mut mod_displayname: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut from_contact: *mut dc_contact_t = 0 as *mut dc_contact_t;
|
||||
@@ -334,5 +341,6 @@ pub unsafe fn dc_stock_system_msg(
|
||||
free(mod_displayname as *mut libc::c_void);
|
||||
dc_contact_unref(from_contact);
|
||||
dc_contact_unref(mod_contact);
|
||||
return ret;
|
||||
|
||||
ret
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
use libc;
|
||||
|
||||
use crate::x::*;
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
|
||||
@@ -1,17 +1,10 @@
|
||||
use libc;
|
||||
use mmime::charconv::*;
|
||||
use mmime::mailmime_decode::*;
|
||||
use mmime::mmapstring::*;
|
||||
use mmime::other::*;
|
||||
|
||||
use crate::dc_tools::*;
|
||||
use crate::types::*;
|
||||
use crate::x::*;
|
||||
|
||||
#[inline]
|
||||
unsafe fn __isctype(mut _c: __darwin_ct_rune_t, mut _f: libc::c_ulong) -> __darwin_ct_rune_t {
|
||||
return if _c < 0i32 || _c >= 1i32 << 8i32 {
|
||||
0i32
|
||||
} else {
|
||||
(0 != _DefaultRuneLocale.__runetype[_c as usize] as libc::c_ulong & _f) as libc::c_int
|
||||
};
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn isalnum(mut _c: libc::c_int) -> libc::c_int {
|
||||
@@ -22,14 +15,6 @@ pub fn isalnum(mut _c: libc::c_int) -> libc::c_int {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[test]
|
||||
fn test_isalnum() {
|
||||
assert_eq!(isalnum(0), 0);
|
||||
assert_eq!(isalnum('5' as libc::c_int), 1);
|
||||
assert_eq!(isalnum('Q' as libc::c_int), 1);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn isdigit(mut _c: libc::c_int) -> libc::c_int {
|
||||
if _c < std::u8::MAX as libc::c_int {
|
||||
@@ -78,8 +63,10 @@ pub unsafe extern "C" fn dc_urlencode(mut to_encode: *const libc::c_char) -> *mu
|
||||
pstr = pstr.offset(1isize)
|
||||
}
|
||||
*pbuf = '\u{0}' as i32 as libc::c_char;
|
||||
return buf;
|
||||
|
||||
buf
|
||||
}
|
||||
|
||||
/* ******************************************************************************
|
||||
* URL encoding and decoding, RFC 3986
|
||||
******************************************************************************/
|
||||
@@ -87,8 +74,10 @@ unsafe fn int_2_uppercase_hex(mut code: libc::c_char) -> libc::c_char {
|
||||
static mut hex: [libc::c_char; 17] = [
|
||||
48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 65, 66, 67, 68, 69, 70, 0,
|
||||
];
|
||||
return hex[(code as libc::c_int & 15i32) as usize];
|
||||
|
||||
hex[(code as libc::c_int & 15i32) as usize]
|
||||
}
|
||||
|
||||
pub unsafe fn dc_urldecode(mut to_decode: *const libc::c_char) -> *mut libc::c_char {
|
||||
let mut pstr: *const libc::c_char = to_decode;
|
||||
if to_decode.is_null() {
|
||||
@@ -122,15 +111,18 @@ pub unsafe fn dc_urldecode(mut to_decode: *const libc::c_char) -> *mut libc::c_c
|
||||
pstr = pstr.offset(1isize)
|
||||
}
|
||||
*pbuf = '\u{0}' as i32 as libc::c_char;
|
||||
return buf;
|
||||
|
||||
buf
|
||||
}
|
||||
|
||||
unsafe fn hex_2_int(mut ch: libc::c_char) -> libc::c_char {
|
||||
return (if 0 != isdigit(ch as libc::c_int) {
|
||||
ch as libc::c_int - '0' as i32
|
||||
} else {
|
||||
tolower(ch as libc::c_int) - 'a' as i32 + 10i32
|
||||
libc::tolower(ch as libc::c_int) - 'a' as i32 + 10i32
|
||||
}) as libc::c_char;
|
||||
}
|
||||
|
||||
pub unsafe fn dc_encode_header_words(mut to_encode: *const libc::c_char) -> *mut libc::c_char {
|
||||
let mut current_block: u64;
|
||||
let mut ret_str: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
@@ -151,10 +143,10 @@ pub unsafe fn dc_encode_header_words(mut to_encode: *const libc::c_char) -> *mut
|
||||
}
|
||||
_ => {
|
||||
if *cur as libc::c_int != '\u{0}' as i32 {
|
||||
let mut begin: *const libc::c_char = 0 as *const libc::c_char;
|
||||
let mut end: *const libc::c_char = 0 as *const libc::c_char;
|
||||
let mut do_quote: libc::c_int = 0;
|
||||
let mut quote_words: libc::c_int = 0;
|
||||
let mut begin: *const libc::c_char;
|
||||
let mut end: *const libc::c_char;
|
||||
let mut do_quote: libc::c_int;
|
||||
let mut quote_words: libc::c_int;
|
||||
begin = cur;
|
||||
end = begin;
|
||||
quote_words = 0i32;
|
||||
@@ -226,15 +218,18 @@ pub unsafe fn dc_encode_header_words(mut to_encode: *const libc::c_char) -> *mut
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret_str;
|
||||
|
||||
ret_str
|
||||
}
|
||||
|
||||
// TODO return bool /rtn
|
||||
unsafe fn quote_word(
|
||||
mut display_charset: *const libc::c_char,
|
||||
mut mmapstr: *mut MMAPString,
|
||||
mut word: *const libc::c_char,
|
||||
mut size: size_t,
|
||||
) -> libc::c_int {
|
||||
let mut cur: *const libc::c_char = 0 as *const libc::c_char;
|
||||
let mut cur: *const libc::c_char;
|
||||
let mut i: size_t = 0i32 as size_t;
|
||||
let mut hex: [libc::c_char; 4] = [0; 4];
|
||||
// let mut col: libc::c_int = 0i32;
|
||||
@@ -249,10 +244,8 @@ unsafe fn quote_word(
|
||||
}
|
||||
// col = (*mmapstr).len as libc::c_int;
|
||||
cur = word;
|
||||
i = 0i32 as size_t;
|
||||
while i < size {
|
||||
let mut do_quote_char: libc::c_int = 0;
|
||||
do_quote_char = 0i32;
|
||||
match *cur as libc::c_int {
|
||||
44 | 58 | 33 | 34 | 35 | 36 | 64 | 91 | 92 | 93 | 94 | 96 | 123 | 124 | 125 | 126
|
||||
| 61 | 63 | 95 => do_quote_char = 1i32,
|
||||
@@ -289,12 +282,14 @@ unsafe fn quote_word(
|
||||
if mmap_string_append(mmapstr, b"?=\x00" as *const u8 as *const libc::c_char).is_null() {
|
||||
return 0i32;
|
||||
}
|
||||
return 1i32;
|
||||
|
||||
1
|
||||
}
|
||||
|
||||
unsafe fn get_word(
|
||||
mut begin: *const libc::c_char,
|
||||
mut pend: *mut *const libc::c_char,
|
||||
mut pto_be_quoted: *mut libc::c_int,
|
||||
mut pto_be_quoted: *mut libc::c_int, // TODO should be bool /rtn
|
||||
) {
|
||||
let mut cur: *const libc::c_char = begin;
|
||||
while *cur as libc::c_int != ' ' as i32
|
||||
@@ -309,14 +304,16 @@ unsafe fn get_word(
|
||||
);
|
||||
*pend = cur;
|
||||
}
|
||||
|
||||
/* ******************************************************************************
|
||||
* Encode/decode header words, RFC 2047
|
||||
******************************************************************************/
|
||||
|
||||
/* see comment below */
|
||||
// TODO should be bool /rtn
|
||||
unsafe fn to_be_quoted(mut word: *const libc::c_char, mut size: size_t) -> libc::c_int {
|
||||
let mut cur: *const libc::c_char = word;
|
||||
let mut i: size_t = 0i32 as size_t;
|
||||
i = 0i32 as size_t;
|
||||
while i < size {
|
||||
match *cur as libc::c_int {
|
||||
44 | 58 | 33 | 34 | 35 | 36 | 64 | 91 | 92 | 93 | 94 | 96 | 123 | 124 | 125 | 126
|
||||
@@ -330,8 +327,10 @@ unsafe fn to_be_quoted(mut word: *const libc::c_char, mut size: size_t) -> libc:
|
||||
cur = cur.offset(1isize);
|
||||
i = i.wrapping_add(1)
|
||||
}
|
||||
return 0i32;
|
||||
|
||||
0
|
||||
}
|
||||
|
||||
pub unsafe fn dc_decode_header_words(mut in_0: *const libc::c_char) -> *mut libc::c_char {
|
||||
if in_0.is_null() {
|
||||
return 0 as *mut libc::c_char;
|
||||
@@ -349,22 +348,24 @@ pub unsafe fn dc_decode_header_words(mut in_0: *const libc::c_char) -> *mut libc
|
||||
if r != MAILIMF_NO_ERROR as libc::c_int || out.is_null() {
|
||||
out = dc_strdup(in_0)
|
||||
}
|
||||
return out;
|
||||
|
||||
out
|
||||
}
|
||||
|
||||
pub unsafe fn dc_encode_modified_utf7(
|
||||
mut to_encode: *const libc::c_char,
|
||||
mut change_spaces: libc::c_int,
|
||||
) -> *mut libc::c_char {
|
||||
let mut utf8pos: libc::c_uint = 0i32 as libc::c_uint;
|
||||
let mut utf8total: libc::c_uint = 0i32 as libc::c_uint;
|
||||
let mut c: libc::c_uint = 0i32 as libc::c_uint;
|
||||
let mut utf7mode: libc::c_uint = 0i32 as libc::c_uint;
|
||||
let mut bitstogo: libc::c_uint = 0i32 as libc::c_uint;
|
||||
let mut utf16flag: libc::c_uint = 0i32 as libc::c_uint;
|
||||
let mut utf8pos: libc::c_uint;
|
||||
let mut utf8total: libc::c_uint;
|
||||
let mut c: libc::c_uint;
|
||||
let mut utf7mode: libc::c_uint;
|
||||
let mut bitstogo: libc::c_uint;
|
||||
let mut utf16flag: libc::c_uint;
|
||||
let mut ucs4: libc::c_ulong = 0;
|
||||
let mut bitbuf: libc::c_ulong = 0;
|
||||
let mut dst: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut res: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut dst: *mut libc::c_char;
|
||||
let mut res: *mut libc::c_char;
|
||||
if to_encode.is_null() {
|
||||
return dc_strdup(b"\x00" as *const u8 as *const libc::c_char);
|
||||
}
|
||||
@@ -487,31 +488,35 @@ pub unsafe fn dc_encode_modified_utf7(
|
||||
*fresh16 = '-' as i32 as libc::c_char
|
||||
}
|
||||
*dst = '\u{0}' as i32 as libc::c_char;
|
||||
return res;
|
||||
|
||||
res
|
||||
}
|
||||
|
||||
/* ******************************************************************************
|
||||
* Encode/decode modified UTF-7 as needed for IMAP, see RFC 2192
|
||||
******************************************************************************/
|
||||
|
||||
// UTF7 modified base64 alphabet
|
||||
static mut base64chars: [libc::c_char; 65] = [
|
||||
65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88,
|
||||
89, 90, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114,
|
||||
115, 116, 117, 118, 119, 120, 121, 122, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 43, 44, 0,
|
||||
];
|
||||
|
||||
pub unsafe fn dc_decode_modified_utf7(
|
||||
mut to_decode: *const libc::c_char,
|
||||
mut change_spaces: libc::c_int,
|
||||
) -> *mut libc::c_char {
|
||||
let mut c: libc::c_uint = 0i32 as libc::c_uint;
|
||||
let mut i: libc::c_uint = 0i32 as libc::c_uint;
|
||||
let mut bitcount: libc::c_uint = 0i32 as libc::c_uint;
|
||||
let mut ucs4: libc::c_ulong = 0;
|
||||
let mut utf16: libc::c_ulong = 0;
|
||||
let mut bitbuf: libc::c_ulong = 0;
|
||||
let mut c: libc::c_uint;
|
||||
let mut i: libc::c_uint;
|
||||
let mut bitcount: libc::c_uint;
|
||||
let mut ucs4: libc::c_ulong;
|
||||
let mut utf16: libc::c_ulong;
|
||||
let mut bitbuf: libc::c_ulong;
|
||||
let mut base64: [libc::c_uchar; 256] = [0; 256];
|
||||
let mut src: *const libc::c_char = 0 as *const libc::c_char;
|
||||
let mut dst: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut res: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut src: *const libc::c_char;
|
||||
let mut dst: *mut libc::c_char;
|
||||
let mut res: *mut libc::c_char;
|
||||
if to_decode.is_null() {
|
||||
return dc_strdup(b"\x00" as *const u8 as *const libc::c_char);
|
||||
}
|
||||
@@ -607,8 +612,11 @@ pub unsafe fn dc_decode_modified_utf7(
|
||||
}
|
||||
}
|
||||
*dst = '\u{0}' as i32 as libc::c_char;
|
||||
return res;
|
||||
|
||||
res
|
||||
}
|
||||
|
||||
// TODO should be bool /rtn
|
||||
pub unsafe fn dc_needs_ext_header(mut to_check: *const libc::c_char) -> libc::c_int {
|
||||
if !to_check.is_null() {
|
||||
while 0 != *to_check {
|
||||
@@ -623,8 +631,10 @@ pub unsafe fn dc_needs_ext_header(mut to_check: *const libc::c_char) -> libc::c_
|
||||
to_check = to_check.offset(1isize)
|
||||
}
|
||||
}
|
||||
return 0i32;
|
||||
|
||||
0
|
||||
}
|
||||
|
||||
pub unsafe fn dc_encode_ext_header(mut to_encode: *const libc::c_char) -> *mut libc::c_char {
|
||||
let mut pstr: *const libc::c_char = to_encode;
|
||||
if to_encode.is_null() {
|
||||
@@ -665,12 +675,14 @@ pub unsafe fn dc_encode_ext_header(mut to_encode: *const libc::c_char) -> *mut l
|
||||
pstr = pstr.offset(1isize)
|
||||
}
|
||||
*pbuf = '\u{0}' as i32 as libc::c_char;
|
||||
return buf;
|
||||
|
||||
buf
|
||||
}
|
||||
|
||||
pub unsafe fn dc_decode_ext_header(mut to_decode: *const libc::c_char) -> *mut libc::c_char {
|
||||
let mut decoded: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut charset: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut p2: *const libc::c_char = 0 as *const libc::c_char;
|
||||
let mut p2: *const libc::c_char;
|
||||
if !to_decode.is_null() {
|
||||
// get char set
|
||||
p2 = strchr(to_decode, '\'' as i32);
|
||||
@@ -715,3 +727,15 @@ pub unsafe fn dc_decode_ext_header(mut to_decode: *const libc::c_char) -> *mut l
|
||||
dc_strdup(to_decode)
|
||||
};
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_isalnum() {
|
||||
assert_eq!(isalnum(0), 0);
|
||||
assert_eq!(isalnum('5' as libc::c_int), 1);
|
||||
assert_eq!(isalnum('Q' as libc::c_int), 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
use libc;
|
||||
|
||||
use crate::dc_context::dc_context_t;
|
||||
use crate::dc_sqlite3::*;
|
||||
use crate::dc_tools::*;
|
||||
@@ -12,17 +10,17 @@ pub const DC_TOKEN_AUTH: dc_tokennamespc_t = 110;
|
||||
pub const DC_TOKEN_INVITENUMBER: dc_tokennamespc_t = 100;
|
||||
// Functions to read/write token from/to the database. A token is any string associated with a key.
|
||||
pub unsafe fn dc_token_save(
|
||||
mut context: *mut dc_context_t,
|
||||
mut context: &dc_context_t,
|
||||
mut namespc: dc_tokennamespc_t,
|
||||
mut foreign_id: uint32_t,
|
||||
mut token: *const libc::c_char,
|
||||
) {
|
||||
let mut stmt: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt;
|
||||
if !(context.is_null() || (*context).magic != 0x11a11807i32 as libc::c_uint || token.is_null())
|
||||
{
|
||||
if !token.is_null() {
|
||||
// foreign_id may be 0
|
||||
stmt = dc_sqlite3_prepare(
|
||||
(*context).sql,
|
||||
context,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
b"INSERT INTO tokens (namespc, foreign_id, token, timestamp) VALUES (?, ?, ?, ?);\x00"
|
||||
as *const u8 as *const libc::c_char,
|
||||
);
|
||||
@@ -35,37 +33,38 @@ pub unsafe fn dc_token_save(
|
||||
sqlite3_finalize(stmt);
|
||||
}
|
||||
pub unsafe fn dc_token_lookup(
|
||||
mut context: *mut dc_context_t,
|
||||
mut context: &dc_context_t,
|
||||
mut namespc: dc_tokennamespc_t,
|
||||
mut foreign_id: uint32_t,
|
||||
) -> *mut libc::c_char {
|
||||
let mut token: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut stmt: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt;
|
||||
if !(context.is_null() || (*context).magic != 0x11a11807i32 as libc::c_uint) {
|
||||
stmt = dc_sqlite3_prepare(
|
||||
(*context).sql,
|
||||
b"SELECT token FROM tokens WHERE namespc=? AND foreign_id=?;\x00" as *const u8
|
||||
as *const libc::c_char,
|
||||
);
|
||||
sqlite3_bind_int(stmt, 1i32, namespc as libc::c_int);
|
||||
sqlite3_bind_int(stmt, 2i32, foreign_id as libc::c_int);
|
||||
sqlite3_step(stmt);
|
||||
token = dc_strdup_keep_null(sqlite3_column_text(stmt, 0i32) as *mut libc::c_char)
|
||||
}
|
||||
let mut token: *mut libc::c_char;
|
||||
let mut stmt: *mut sqlite3_stmt;
|
||||
stmt = dc_sqlite3_prepare(
|
||||
context,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
b"SELECT token FROM tokens WHERE namespc=? AND foreign_id=?;\x00" as *const u8
|
||||
as *const libc::c_char,
|
||||
);
|
||||
sqlite3_bind_int(stmt, 1i32, namespc as libc::c_int);
|
||||
sqlite3_bind_int(stmt, 2i32, foreign_id as libc::c_int);
|
||||
sqlite3_step(stmt);
|
||||
token = dc_strdup_keep_null(sqlite3_column_text(stmt, 0i32) as *mut libc::c_char);
|
||||
|
||||
sqlite3_finalize(stmt);
|
||||
return token;
|
||||
token
|
||||
}
|
||||
|
||||
pub unsafe fn dc_token_exists(
|
||||
mut context: *mut dc_context_t,
|
||||
mut context: &dc_context_t,
|
||||
mut namespc: dc_tokennamespc_t,
|
||||
mut token: *const libc::c_char,
|
||||
) -> libc::c_int {
|
||||
let mut exists: libc::c_int = 0i32;
|
||||
let mut stmt: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt;
|
||||
if !(context.is_null() || (*context).magic != 0x11a11807i32 as libc::c_uint || token.is_null())
|
||||
{
|
||||
if !token.is_null() {
|
||||
stmt = dc_sqlite3_prepare(
|
||||
(*context).sql,
|
||||
context,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
b"SELECT id FROM tokens WHERE namespc=? AND token=?;\x00" as *const u8
|
||||
as *const libc::c_char,
|
||||
);
|
||||
|
||||
726
src/dc_tools.rs
726
src/dc_tools.rs
File diff suppressed because it is too large
Load Diff
@@ -3,7 +3,6 @@
|
||||
non_camel_case_types,
|
||||
non_snake_case,
|
||||
non_upper_case_globals,
|
||||
unused_assignments,
|
||||
unused_mut,
|
||||
unused_attributes,
|
||||
non_upper_case_globals,
|
||||
@@ -21,6 +20,11 @@
|
||||
extern crate failure;
|
||||
#[macro_use]
|
||||
extern crate num_derive;
|
||||
// #[macro_use]
|
||||
// extern crate rental;
|
||||
|
||||
#[macro_use]
|
||||
pub mod dc_log;
|
||||
|
||||
mod pgp;
|
||||
|
||||
@@ -44,7 +48,6 @@ pub mod dc_key;
|
||||
pub mod dc_keyhistory;
|
||||
pub mod dc_keyring;
|
||||
pub mod dc_location;
|
||||
pub mod dc_log;
|
||||
pub mod dc_loginparam;
|
||||
pub mod dc_lot;
|
||||
pub mod dc_mimefactory;
|
||||
|
||||
1576
src/types.rs
1576
src/types.rs
File diff suppressed because it is too large
Load Diff
477
src/x.rs
477
src/x.rs
@@ -1,5 +1,3 @@
|
||||
use libc;
|
||||
|
||||
use crate::dc_strbuilder::dc_strbuilder_t;
|
||||
use crate::types::*;
|
||||
|
||||
@@ -13,7 +11,7 @@ pub use libc::{
|
||||
};
|
||||
|
||||
extern "C" {
|
||||
pub static mut _DefaultRuneLocale: _RuneLocale;
|
||||
// pub static mut _DefaultRuneLocale: _RuneLocale;
|
||||
|
||||
pub fn clock() -> libc::clock_t;
|
||||
pub fn qsort(
|
||||
@@ -55,483 +53,10 @@ extern "C" {
|
||||
_: *const libc::c_char,
|
||||
) -> !;
|
||||
|
||||
// --charconv
|
||||
|
||||
pub fn charconv(
|
||||
tocode: *const libc::c_char,
|
||||
fromcode: *const libc::c_char,
|
||||
str: *const libc::c_char,
|
||||
length: size_t,
|
||||
result: *mut *mut libc::c_char,
|
||||
) -> libc::c_int;
|
||||
pub fn charconv_buffer(
|
||||
tocode: *const libc::c_char,
|
||||
fromcode: *const libc::c_char,
|
||||
str: *const libc::c_char,
|
||||
length: size_t,
|
||||
result: *mut *mut libc::c_char,
|
||||
result_len: *mut size_t,
|
||||
) -> libc::c_int;
|
||||
pub fn charconv_buffer_free(str: *mut libc::c_char);
|
||||
|
||||
// -- libetpan Methods
|
||||
|
||||
pub fn libetpan_get_version_major() -> libc::c_int;
|
||||
pub fn libetpan_get_version_minor() -> libc::c_int;
|
||||
pub fn gethostname(_: *mut libc::c_char, _: size_t) -> libc::c_int;
|
||||
pub fn mailsmtp_socket_connect(
|
||||
session: *mut mailsmtp,
|
||||
server: *const libc::c_char,
|
||||
port: uint16_t,
|
||||
) -> libc::c_int;
|
||||
pub fn mailsmtp_socket_starttls(session: *mut mailsmtp) -> libc::c_int;
|
||||
pub fn mailsmtp_ssl_connect(
|
||||
session: *mut mailsmtp,
|
||||
server: *const libc::c_char,
|
||||
port: uint16_t,
|
||||
) -> libc::c_int;
|
||||
pub fn mailsmtp_oauth2_authenticate(
|
||||
session: *mut mailsmtp,
|
||||
auth_user: *const libc::c_char,
|
||||
access_token: *const libc::c_char,
|
||||
) -> libc::c_int;
|
||||
pub fn mailsmtp_new(
|
||||
progr_rate: size_t,
|
||||
progr_fun: Option<unsafe extern "C" fn(_: size_t, _: size_t) -> ()>,
|
||||
) -> *mut mailsmtp;
|
||||
pub fn mailsmtp_free(session: *mut mailsmtp);
|
||||
pub fn mailsmtp_set_timeout(session: *mut mailsmtp, timeout: time_t);
|
||||
pub fn mailsmtp_auth(
|
||||
session: *mut mailsmtp,
|
||||
user: *const libc::c_char,
|
||||
pass: *const libc::c_char,
|
||||
) -> libc::c_int;
|
||||
pub fn mailsmtp_helo(session: *mut mailsmtp) -> libc::c_int;
|
||||
pub fn mailsmtp_mail(session: *mut mailsmtp, from: *const libc::c_char) -> libc::c_int;
|
||||
pub fn mailsmtp_rcpt(session: *mut mailsmtp, to: *const libc::c_char) -> libc::c_int;
|
||||
pub fn mailsmtp_data(session: *mut mailsmtp) -> libc::c_int;
|
||||
pub fn mailsmtp_data_message(
|
||||
session: *mut mailsmtp,
|
||||
message: *const libc::c_char,
|
||||
size: size_t,
|
||||
) -> libc::c_int;
|
||||
pub fn mailesmtp_ehlo(session: *mut mailsmtp) -> libc::c_int;
|
||||
pub fn mailesmtp_mail(
|
||||
session: *mut mailsmtp,
|
||||
from: *const libc::c_char,
|
||||
return_full: libc::c_int,
|
||||
envid: *const libc::c_char,
|
||||
) -> libc::c_int;
|
||||
pub fn mailesmtp_rcpt(
|
||||
session: *mut mailsmtp,
|
||||
to: *const libc::c_char,
|
||||
notify: libc::c_int,
|
||||
orcpt: *const libc::c_char,
|
||||
) -> libc::c_int;
|
||||
pub fn mailsmtp_strerror(errnum: libc::c_int) -> *const libc::c_char;
|
||||
pub fn mailesmtp_auth_sasl(
|
||||
session: *mut mailsmtp,
|
||||
auth_type: *const libc::c_char,
|
||||
server_fqdn: *const libc::c_char,
|
||||
local_ip_port: *const libc::c_char,
|
||||
remote_ip_port: *const libc::c_char,
|
||||
login: *const libc::c_char,
|
||||
auth_name: *const libc::c_char,
|
||||
password: *const libc::c_char,
|
||||
realm: *const libc::c_char,
|
||||
) -> libc::c_int;
|
||||
pub fn mailsmtp_set_progress_callback(
|
||||
session: *mut mailsmtp,
|
||||
progr_fun: Option<unsafe extern "C" fn(_: size_t, _: size_t, _: *mut libc::c_void) -> ()>,
|
||||
context: *mut libc::c_void,
|
||||
);
|
||||
|
||||
pub fn mailmime_base64_body_parse(
|
||||
message: *const libc::c_char,
|
||||
length: size_t,
|
||||
indx: *mut size_t,
|
||||
result: *mut *mut libc::c_char,
|
||||
result_len: *mut size_t,
|
||||
) -> libc::c_int;
|
||||
pub fn mailimf_address_new(
|
||||
ad_type: libc::c_int,
|
||||
ad_mailbox: *mut mailimf_mailbox,
|
||||
ad_group: *mut mailimf_group,
|
||||
) -> *mut mailimf_address;
|
||||
pub fn mailimf_mailbox_new(
|
||||
mb_display_name: *mut libc::c_char,
|
||||
mb_addr_spec: *mut libc::c_char,
|
||||
) -> *mut mailimf_mailbox;
|
||||
pub fn mailimf_field_new(
|
||||
fld_type: libc::c_int,
|
||||
fld_return_path: *mut mailimf_return,
|
||||
fld_resent_date: *mut mailimf_orig_date,
|
||||
fld_resent_from: *mut mailimf_from,
|
||||
fld_resent_sender: *mut mailimf_sender,
|
||||
fld_resent_to: *mut mailimf_to,
|
||||
fld_resent_cc: *mut mailimf_cc,
|
||||
fld_resent_bcc: *mut mailimf_bcc,
|
||||
fld_resent_msg_id: *mut mailimf_message_id,
|
||||
fld_orig_date: *mut mailimf_orig_date,
|
||||
fld_from: *mut mailimf_from,
|
||||
fld_sender: *mut mailimf_sender,
|
||||
fld_reply_to: *mut mailimf_reply_to,
|
||||
fld_to: *mut mailimf_to,
|
||||
fld_cc: *mut mailimf_cc,
|
||||
fld_bcc: *mut mailimf_bcc,
|
||||
fld_message_id: *mut mailimf_message_id,
|
||||
fld_in_reply_to: *mut mailimf_in_reply_to,
|
||||
fld_references: *mut mailimf_references,
|
||||
fld_subject: *mut mailimf_subject,
|
||||
fld_comments: *mut mailimf_comments,
|
||||
fld_keywords: *mut mailimf_keywords,
|
||||
fld_optional_field: *mut mailimf_optional_field,
|
||||
) -> *mut mailimf_field;
|
||||
pub fn mailimf_subject_new(sbj_value: *mut libc::c_char) -> *mut mailimf_subject;
|
||||
pub fn mailimf_mailbox_list_new_empty() -> *mut mailimf_mailbox_list;
|
||||
pub fn mailimf_mailbox_list_add(
|
||||
mailbox_list: *mut mailimf_mailbox_list,
|
||||
mb: *mut mailimf_mailbox,
|
||||
) -> libc::c_int;
|
||||
pub fn mailimf_address_list_new_empty() -> *mut mailimf_address_list;
|
||||
pub fn mailimf_address_list_add(
|
||||
address_list: *mut mailimf_address_list,
|
||||
addr: *mut mailimf_address,
|
||||
) -> libc::c_int;
|
||||
pub fn mailimf_fields_add(
|
||||
fields: *mut mailimf_fields,
|
||||
field: *mut mailimf_field,
|
||||
) -> libc::c_int;
|
||||
pub fn mailimf_fields_new_with_data_all(
|
||||
date: *mut mailimf_date_time,
|
||||
from: *mut mailimf_mailbox_list,
|
||||
sender: *mut mailimf_mailbox,
|
||||
reply_to: *mut mailimf_address_list,
|
||||
to: *mut mailimf_address_list,
|
||||
cc: *mut mailimf_address_list,
|
||||
bcc: *mut mailimf_address_list,
|
||||
message_id: *mut libc::c_char,
|
||||
in_reply_to: *mut clist,
|
||||
references: *mut clist,
|
||||
subject: *mut libc::c_char,
|
||||
) -> *mut mailimf_fields;
|
||||
pub fn mailimf_get_date(time_0: time_t) -> *mut mailimf_date_time;
|
||||
pub fn mailimf_field_new_custom(
|
||||
name: *mut libc::c_char,
|
||||
value: *mut libc::c_char,
|
||||
) -> *mut mailimf_field;
|
||||
pub fn mailmime_parameter_new(
|
||||
pa_name: *mut libc::c_char,
|
||||
pa_value: *mut libc::c_char,
|
||||
) -> *mut mailmime_parameter;
|
||||
pub fn mailmime_free(mime: *mut mailmime);
|
||||
pub fn mailmime_disposition_parm_new(
|
||||
pa_type: libc::c_int,
|
||||
pa_filename: *mut libc::c_char,
|
||||
pa_creation_date: *mut libc::c_char,
|
||||
pa_modification_date: *mut libc::c_char,
|
||||
pa_read_date: *mut libc::c_char,
|
||||
pa_size: size_t,
|
||||
pa_parameter: *mut mailmime_parameter,
|
||||
) -> *mut mailmime_disposition_parm;
|
||||
pub fn mailmime_new_message_data(msg_mime: *mut mailmime) -> *mut mailmime;
|
||||
pub fn mailmime_new_empty(
|
||||
content: *mut mailmime_content,
|
||||
mime_fields: *mut mailmime_fields,
|
||||
) -> *mut mailmime;
|
||||
pub fn mailmime_set_body_file(
|
||||
build_info: *mut mailmime,
|
||||
filename: *mut libc::c_char,
|
||||
) -> libc::c_int;
|
||||
pub fn mailmime_set_body_text(
|
||||
build_info: *mut mailmime,
|
||||
data_str: *mut libc::c_char,
|
||||
length: size_t,
|
||||
) -> libc::c_int;
|
||||
pub fn mailmime_add_part(build_info: *mut mailmime, part: *mut mailmime) -> libc::c_int;
|
||||
pub fn mailmime_set_imf_fields(build_info: *mut mailmime, fields: *mut mailimf_fields);
|
||||
pub fn mailmime_smart_add_part(mime: *mut mailmime, mime_sub: *mut mailmime) -> libc::c_int;
|
||||
pub fn mailmime_content_new_with_str(str: *const libc::c_char) -> *mut mailmime_content;
|
||||
pub fn mailmime_fields_new_encoding(type_0: libc::c_int) -> *mut mailmime_fields;
|
||||
pub fn mailmime_multiple_new(type_0: *const libc::c_char) -> *mut mailmime;
|
||||
pub fn mailmime_fields_new_filename(
|
||||
dsp_type: libc::c_int,
|
||||
filename: *mut libc::c_char,
|
||||
encoding_type: libc::c_int,
|
||||
) -> *mut mailmime_fields;
|
||||
pub fn mailmime_param_new_with_data(
|
||||
name: *mut libc::c_char,
|
||||
value: *mut libc::c_char,
|
||||
) -> *mut mailmime_parameter;
|
||||
pub fn mailmime_write_mem(
|
||||
f: *mut MMAPString,
|
||||
col: *mut libc::c_int,
|
||||
build_info: *mut mailmime,
|
||||
) -> libc::c_int;
|
||||
pub fn mailimf_fields_free(fields: *mut mailimf_fields);
|
||||
pub fn mailimf_fields_new_empty() -> *mut mailimf_fields;
|
||||
pub fn mailimf_envelope_and_optional_fields_parse(
|
||||
message: *const libc::c_char,
|
||||
length: size_t,
|
||||
indx: *mut size_t,
|
||||
result: *mut *mut mailimf_fields,
|
||||
) -> libc::c_int;
|
||||
pub fn mailmime_content_free(content: *mut mailmime_content);
|
||||
pub fn mailmime_mechanism_new(
|
||||
enc_type: libc::c_int,
|
||||
enc_token: *mut libc::c_char,
|
||||
) -> *mut mailmime_mechanism;
|
||||
pub fn mailmime_mechanism_free(mechanism: *mut mailmime_mechanism);
|
||||
pub fn mailmime_fields_free(fields: *mut mailmime_fields);
|
||||
pub fn mailmime_new(
|
||||
mm_type: libc::c_int,
|
||||
mm_mime_start: *const libc::c_char,
|
||||
mm_length: size_t,
|
||||
mm_mime_fields: *mut mailmime_fields,
|
||||
mm_content_type: *mut mailmime_content,
|
||||
mm_body: *mut mailmime_data,
|
||||
mm_preamble: *mut mailmime_data,
|
||||
mm_epilogue: *mut mailmime_data,
|
||||
mm_mp_list: *mut clist,
|
||||
mm_fields: *mut mailimf_fields,
|
||||
mm_msg_mime: *mut mailmime,
|
||||
) -> *mut mailmime;
|
||||
pub fn mailmime_fields_new_empty() -> *mut mailmime_fields;
|
||||
pub fn mailmime_fields_new_with_data(
|
||||
encoding: *mut mailmime_mechanism,
|
||||
id: *mut libc::c_char,
|
||||
description: *mut libc::c_char,
|
||||
disposition: *mut mailmime_disposition,
|
||||
language: *mut mailmime_language,
|
||||
) -> *mut mailmime_fields;
|
||||
pub fn mailmime_get_content_message() -> *mut mailmime_content;
|
||||
pub fn mailmime_parse(
|
||||
message: *const libc::c_char,
|
||||
length: size_t,
|
||||
indx: *mut size_t,
|
||||
result: *mut *mut mailmime,
|
||||
) -> libc::c_int;
|
||||
pub fn mailmime_part_parse(
|
||||
message: *const libc::c_char,
|
||||
length: size_t,
|
||||
indx: *mut size_t,
|
||||
encoding: libc::c_int,
|
||||
result: *mut *mut libc::c_char,
|
||||
result_len: *mut size_t,
|
||||
) -> libc::c_int;
|
||||
pub fn mailmime_substitute(old_mime: *mut mailmime, new_mime: *mut mailmime) -> libc::c_int;
|
||||
pub fn mailprivacy_prepare_mime(mime: *mut mailmime);
|
||||
pub fn mailmime_encoded_phrase_parse(
|
||||
default_fromcode: *const libc::c_char,
|
||||
message: *const libc::c_char,
|
||||
length: size_t,
|
||||
indx: *mut size_t,
|
||||
tocode: *const libc::c_char,
|
||||
result: *mut *mut libc::c_char,
|
||||
) -> libc::c_int;
|
||||
pub fn mailimap_date_time_new(
|
||||
dt_day: libc::c_int,
|
||||
dt_month: libc::c_int,
|
||||
dt_year: libc::c_int,
|
||||
dt_hour: libc::c_int,
|
||||
dt_min: libc::c_int,
|
||||
dt_sec: libc::c_int,
|
||||
dt_zone: libc::c_int,
|
||||
) -> *mut mailimap_date_time;
|
||||
pub fn mailimap_xlist(
|
||||
session: *mut mailimap,
|
||||
mb: *const libc::c_char,
|
||||
list_mb: *const libc::c_char,
|
||||
result: *mut *mut clist,
|
||||
) -> libc::c_int;
|
||||
pub fn mailimap_create(session: *mut mailimap, mb: *const libc::c_char) -> libc::c_int;
|
||||
pub fn mailimap_list(
|
||||
session: *mut mailimap,
|
||||
mb: *const libc::c_char,
|
||||
list_mb: *const libc::c_char,
|
||||
result: *mut *mut clist,
|
||||
) -> libc::c_int;
|
||||
pub fn mailimap_list_result_free(list: *mut clist);
|
||||
pub fn mailimap_subscribe(session: *mut mailimap, mb: *const libc::c_char) -> libc::c_int;
|
||||
pub fn mailstream_close(s: *mut mailstream) -> libc::c_int;
|
||||
pub fn mailstream_wait_idle(s: *mut mailstream, max_idle_delay: libc::c_int) -> libc::c_int;
|
||||
pub fn mailstream_setup_idle(s: *mut mailstream) -> libc::c_int;
|
||||
pub fn mailstream_unsetup_idle(s: *mut mailstream);
|
||||
pub fn mailstream_interrupt_idle(s: *mut mailstream);
|
||||
pub fn mailimap_section_new(sec_spec: *mut mailimap_section_spec) -> *mut mailimap_section;
|
||||
pub fn mailimap_set_free(set: *mut mailimap_set);
|
||||
pub fn mailimap_fetch_type_free(fetch_type: *mut mailimap_fetch_type);
|
||||
pub fn mailimap_store_att_flags_free(store_att_flags: *mut mailimap_store_att_flags);
|
||||
pub fn mailimap_set_new_interval(first: uint32_t, last: uint32_t) -> *mut mailimap_set;
|
||||
pub fn mailimap_set_new_single(indx: uint32_t) -> *mut mailimap_set;
|
||||
pub fn mailimap_fetch_att_new_envelope() -> *mut mailimap_fetch_att;
|
||||
pub fn mailimap_fetch_att_new_flags() -> *mut mailimap_fetch_att;
|
||||
pub fn mailimap_fetch_att_new_uid() -> *mut mailimap_fetch_att;
|
||||
pub fn mailimap_fetch_att_new_body_peek_section(
|
||||
section: *mut mailimap_section,
|
||||
) -> *mut mailimap_fetch_att;
|
||||
pub fn mailimap_fetch_type_new_fetch_att_list_empty() -> *mut mailimap_fetch_type;
|
||||
pub fn mailimap_fetch_type_new_fetch_att_list_add(
|
||||
fetch_type: *mut mailimap_fetch_type,
|
||||
fetch_att: *mut mailimap_fetch_att,
|
||||
) -> libc::c_int;
|
||||
pub fn mailimap_store_att_flags_new_add_flags(
|
||||
flags: *mut mailimap_flag_list,
|
||||
) -> *mut mailimap_store_att_flags;
|
||||
pub fn mailimap_flag_list_new_empty() -> *mut mailimap_flag_list;
|
||||
pub fn mailimap_flag_list_add(
|
||||
flag_list: *mut mailimap_flag_list,
|
||||
f: *mut mailimap_flag,
|
||||
) -> libc::c_int;
|
||||
pub fn mailimap_flag_new_deleted() -> *mut mailimap_flag;
|
||||
pub fn mailimap_flag_new_seen() -> *mut mailimap_flag;
|
||||
pub fn mailimap_flag_new_flag_keyword(flag_keyword: *mut libc::c_char) -> *mut mailimap_flag;
|
||||
pub fn mailimap_socket_connect(
|
||||
f: *mut mailimap,
|
||||
server: *const libc::c_char,
|
||||
port: uint16_t,
|
||||
) -> libc::c_int;
|
||||
pub fn mailimap_socket_starttls(f: *mut mailimap) -> libc::c_int;
|
||||
pub fn mailimap_ssl_connect(
|
||||
f: *mut mailimap,
|
||||
server: *const libc::c_char,
|
||||
port: uint16_t,
|
||||
) -> libc::c_int;
|
||||
pub fn mailimap_uidplus_uid_copy(
|
||||
session: *mut mailimap,
|
||||
set: *mut mailimap_set,
|
||||
mb: *const libc::c_char,
|
||||
uidvalidity_result: *mut uint32_t,
|
||||
source_result: *mut *mut mailimap_set,
|
||||
dest_result: *mut *mut mailimap_set,
|
||||
) -> libc::c_int;
|
||||
pub fn mailimap_uidplus_uid_move(
|
||||
session: *mut mailimap,
|
||||
set: *mut mailimap_set,
|
||||
mb: *const libc::c_char,
|
||||
uidvalidity_result: *mut uint32_t,
|
||||
source_result: *mut *mut mailimap_set,
|
||||
dest_result: *mut *mut mailimap_set,
|
||||
) -> libc::c_int;
|
||||
pub fn mailimap_idle(session: *mut mailimap) -> libc::c_int;
|
||||
pub fn mailimap_idle_done(session: *mut mailimap) -> libc::c_int;
|
||||
pub fn mailimap_has_idle(session: *mut mailimap) -> libc::c_int;
|
||||
pub fn mailimap_has_xlist(session: *mut mailimap) -> libc::c_int;
|
||||
pub fn mailimap_oauth2_authenticate(
|
||||
session: *mut mailimap,
|
||||
auth_user: *const libc::c_char,
|
||||
access_token: *const libc::c_char,
|
||||
) -> libc::c_int;
|
||||
pub fn mailimap_close(session: *mut mailimap) -> libc::c_int;
|
||||
pub fn mailimap_fetch(
|
||||
session: *mut mailimap,
|
||||
set: *mut mailimap_set,
|
||||
fetch_type: *mut mailimap_fetch_type,
|
||||
result: *mut *mut clist,
|
||||
) -> libc::c_int;
|
||||
pub fn mailimap_uid_fetch(
|
||||
session: *mut mailimap,
|
||||
set: *mut mailimap_set,
|
||||
fetch_type: *mut mailimap_fetch_type,
|
||||
result: *mut *mut clist,
|
||||
) -> libc::c_int;
|
||||
pub fn mailimap_fetch_list_free(fetch_list: *mut clist);
|
||||
pub fn mailimap_login(
|
||||
session: *mut mailimap,
|
||||
userid: *const libc::c_char,
|
||||
password: *const libc::c_char,
|
||||
) -> libc::c_int;
|
||||
pub fn mailimap_select(session: *mut mailimap, mb: *const libc::c_char) -> libc::c_int;
|
||||
pub fn mailimap_uid_store(
|
||||
session: *mut mailimap,
|
||||
set: *mut mailimap_set,
|
||||
store_att_flags: *mut mailimap_store_att_flags,
|
||||
) -> libc::c_int;
|
||||
pub fn mailimap_new(
|
||||
imap_progr_rate: size_t,
|
||||
imap_progr_fun: Option<unsafe extern "C" fn(_: size_t, _: size_t) -> ()>,
|
||||
) -> *mut mailimap;
|
||||
pub fn mailimap_free(session: *mut mailimap);
|
||||
pub fn mailimap_set_timeout(session: *mut mailimap, timeout: time_t);
|
||||
pub fn mailimf_msg_id_parse(
|
||||
message: *const libc::c_char,
|
||||
length: size_t,
|
||||
indx: *mut size_t,
|
||||
result: *mut *mut libc::c_char,
|
||||
) -> libc::c_int;
|
||||
pub fn mailimf_mailbox_list_free(mb_list: *mut mailimf_mailbox_list);
|
||||
pub fn mailimf_mailbox_list_parse(
|
||||
message: *const libc::c_char,
|
||||
length: size_t,
|
||||
indx: *mut size_t,
|
||||
result: *mut *mut mailimf_mailbox_list,
|
||||
) -> libc::c_int;
|
||||
pub fn mailmime_content_charset_get(content: *mut mailmime_content) -> *mut libc::c_char;
|
||||
|
||||
pub fn carray_new(initsize: libc::c_uint) -> *mut carray;
|
||||
pub fn carray_add(
|
||||
array: *mut carray,
|
||||
data: *mut libc::c_void,
|
||||
indx: *mut libc::c_uint,
|
||||
) -> libc::c_int;
|
||||
pub fn carray_set_size(array: *mut carray, new_size: libc::c_uint);
|
||||
pub fn carray_free(array: *mut carray);
|
||||
pub fn carray_delete_slow(array: *mut carray, indx: libc::c_uint) -> libc::c_int;
|
||||
|
||||
pub fn mmap_string_unref(str: *mut libc::c_char) -> libc::c_int;
|
||||
pub fn mmap_string_new(init: *const libc::c_char) -> *mut MMAPString;
|
||||
pub fn mmap_string_free(string: *mut MMAPString);
|
||||
pub fn mmap_string_append(string: *mut MMAPString, val: *const libc::c_char)
|
||||
-> *mut MMAPString;
|
||||
pub fn mmap_string_append_len(
|
||||
string: *mut MMAPString,
|
||||
val: *const libc::c_char,
|
||||
len: size_t,
|
||||
) -> *mut MMAPString;
|
||||
pub fn mmap_string_append_c(string: *mut MMAPString, c: libc::c_char) -> *mut MMAPString;
|
||||
|
||||
pub fn clist_free(_: *mut clist);
|
||||
pub fn clist_insert_after(
|
||||
_: *mut clist,
|
||||
_: *mut clistiter,
|
||||
_: *mut libc::c_void,
|
||||
) -> libc::c_int;
|
||||
pub fn clist_new() -> *mut clist;
|
||||
pub fn clist_delete(_: *mut clist, _: *mut clistiter) -> *mut clistiter;
|
||||
|
||||
pub fn encode_base64(in_0: *const libc::c_char, len: libc::c_int) -> *mut libc::c_char;
|
||||
|
||||
// -- DC Methods
|
||||
|
||||
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;
|
||||
|
||||
// -- Pthread
|
||||
|
||||
pub fn pthread_create(
|
||||
_: *mut pthread_t,
|
||||
_: *const pthread_attr_t,
|
||||
_: Option<unsafe extern "C" fn(_: *mut libc::c_void) -> *mut libc::c_void>,
|
||||
_: *mut libc::c_void,
|
||||
) -> libc::c_int;
|
||||
pub fn pthread_join(_: pthread_t, _: *mut *mut libc::c_void) -> libc::c_int;
|
||||
pub fn pthread_cond_signal(_: *mut pthread_cond_t) -> libc::c_int;
|
||||
pub fn pthread_cond_timedwait(
|
||||
_: *mut pthread_cond_t,
|
||||
_: *mut pthread_mutex_t,
|
||||
_: *const timespec,
|
||||
) -> libc::c_int;
|
||||
pub fn pthread_mutex_lock(_: *mut pthread_mutex_t) -> libc::c_int;
|
||||
pub fn pthread_mutex_unlock(_: *mut pthread_mutex_t) -> libc::c_int;
|
||||
pub fn pthread_cond_destroy(_: *mut pthread_cond_t) -> libc::c_int;
|
||||
pub fn pthread_cond_init(_: *mut pthread_cond_t, _: *const pthread_condattr_t) -> libc::c_int;
|
||||
pub fn pthread_cond_wait(_: *mut pthread_cond_t, _: *mut pthread_mutex_t) -> libc::c_int;
|
||||
pub fn pthread_mutex_destroy(_: *mut pthread_mutex_t) -> libc::c_int;
|
||||
pub fn pthread_mutex_init(
|
||||
_: *mut pthread_mutex_t,
|
||||
_: *const pthread_mutexattr_t,
|
||||
) -> libc::c_int;
|
||||
pub fn pthread_self() -> pthread_t;
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user