Ci updates & closer to windows builds

* chore: update some ci

* feat: no more libiconv

* refactor: updates for updated mmime api

* fixup: correct mmime path

* cleanup

* use newer visual studio

* Update appveyor.yml

* unify libc imports and improve windows situation

* refactor: use rust based sleep

* improve cross platform state of types

* docs: update readme badges
This commit is contained in:
Friedel Ziegelmayer
2019-05-16 17:16:07 +02:00
committed by GitHub
parent b992b8ea09
commit 342e416b4e
33 changed files with 420 additions and 423 deletions

View File

@@ -15,7 +15,7 @@ jobs:
name: Setup build environment
command: |
apt update
apt install -y curl build-essential autoconf libtool git python pkg-config zlib1g-dev libssl-dev libetpan-dev libsasl2-dev
apt install -y curl build-essential autoconf libtool git python pkg-config libssl-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

View File

@@ -9,7 +9,6 @@ cc = "1.0.35"
pkg-config = "0.3"
[dependencies]
c2rust-bitfields = "0.1.0"
libc = "0.2.51"
pgp = "0.2.0"
hex = "0.3.2"
@@ -25,6 +24,7 @@ lettre = "0.9.0"
imap = "1.0.1"
mmime = { git = "https://github.com/dignifiedquire/mmime" }
base64 = "0.10.1"
charset = "0.1.2"
[dev-dependencies]
tempfile = "3.0.7"

View File

@@ -2,7 +2,8 @@
> Project porting deltachat-core to rust
[![CircleCI](https://circleci.com/gh/deltachat/deltachat-core-rust.svg?style=svg)](https://circleci.com/gh/deltachat/deltachat-core-rust)
[![CircleCI build status][circle-shield]][circle] [![Appveyor build status][appveyor-shield]][appveyor]
Current commit on deltachat/deltachat-core: `12ef73c8e76185f9b78e844ea673025f56a959ab`.
@@ -17,3 +18,8 @@ $ cat deltachat-ffi/deltachat.h
# run tests
$ cargo test --all
```
[circle-shield]: https://img.shields.io/circleci/project/github/deltachat/deltachat-core-rust/master.svg?style=flat-square
[circle]: https://circleci.com/gh/deltachat/deltachat-core-rust/
[appveyor-shield]: https://ci.appveyor.com/api/projects/status/lqpegel3ld4ipxj8/branch/master?style=flat-square
[appveyor]: https://ci.appveyor.com/project/dignifiedquire/deltachat-core-rust/branch/master

37
appveyor.yml Normal file
View File

@@ -0,0 +1,37 @@
environment:
matrix:
# MinGW
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
TARGET: i686-pc-windows-gnu
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
TARGET: x86_64-pc-windows-gnu
# MSVC
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
TARGET: i686-pc-windows-msvc
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
TARGET: x86_64-pc-windows-msvc
install:
- ps: >-
If ($Env:TARGET -eq 'x86_64-pc-windows-gnu') {
$Env:PATH += ';C:\msys64\mingw64\bin'
} ElseIf ($Env:TARGET -eq 'i686-pc-windows-gnu') {
$Env:PATH += ';C:\msys64\mingw32\bin'
}
- appveyor DownloadFile https://win.rustup.rs/ -FileName rustup-init.exe
- rustup-init -yv --default-host %target% --default-toolchain none
- set PATH=%PATH%;%USERPROFILE%\.cargo\bin
- rustc -vV
- cargo -vV
- cd %APPVEYOR_BUILD_FOLDER%
- git submodule update --init --recursive
build: false
test_script:
- cargo test
cache:
- target
- C:\Users\appveyor\.cargo\registry

View File

@@ -1014,7 +1014,7 @@ pub unsafe extern "C" fn dc_array_get_accuracy(
pub unsafe extern "C" fn dc_array_get_timestamp(
array: *const dc_array_t,
index: libc::size_t,
) -> libc::c_long {
) -> libc::time_t {
dc_array::dc_array_get_timestamp(array, index)
}
#[no_mangle]

View File

@@ -16,6 +16,7 @@ use deltachat::dc_job::{
dc_perform_smtp_jobs,
};
use deltachat::dc_lot::*;
use deltachat::x::strdup;
extern "C" fn cb(_ctx: &dc_context_t, event: Event, data1: usize, data2: usize) -> usize {
println!("[{:?}]", event);
@@ -33,7 +34,7 @@ extern "C" fn cb(_ctx: &dc_context_t, event: Event, data1: usize, data2: usize)
let c_res = CString::new(res.text().unwrap()).unwrap();
// need to use strdup to allocate the result with malloc
// so it can be `free`d later.
unsafe { libc::strdup(c_res.as_ptr()) as usize }
unsafe { strdup(c_res.as_ptr()) as usize }
}
Err(err) => {
println!("failed to download: {}: {:?}", url, err);

View File

@@ -162,7 +162,6 @@ impl str::FromStr for Aheader {
{
Some(key) => key,
None => {
println!("invalid key");
return Err(());
}
};

View File

@@ -261,7 +261,7 @@ pub unsafe fn dc_apeerstate_render_gossip_header(
let header = Aheader::new(addr, key.clone(), EncryptPreference::NoPreference);
let rendered = header.to_string();
let rendered_c = CString::new(rendered).unwrap();
return libc::strdup(rendered_c.as_ptr());
return strdup(rendered_c.as_ptr());
}
std::ptr::null_mut()

View File

@@ -188,9 +188,8 @@ unsafe fn set_from_stmt(mut chat: *mut dc_chat_t, row: *mut sqlite3_stmt) -> lib
(*chat).gossiped_timestamp = sqlite3_column_int64(row, fresh7) as time_t;
let fresh8 = row_offset;
row_offset = row_offset + 1;
(*chat).is_sending_locations = (sqlite3_column_int64(row, fresh8)
> time(0 as *mut time_t) as libc::c_longlong)
as libc::c_int;
(*chat).is_sending_locations =
(sqlite3_column_int64(row, fresh8) > time(0 as *mut time_t)) as libc::c_int;
if (*chat).id == 1i32 as libc::c_uint {
free((*chat).name as *mut libc::c_void);
(*chat).name = dc_stock_str((*chat).context, 8i32)
@@ -314,7 +313,7 @@ pub unsafe fn dc_create_or_lookup_nchat_by_contact_id(
create_blocked,
(*contact).addr,
);
if 0 != !('K' as i32 == 'K' as i32) as libc::c_int as libc::c_long {
if 0 != !('K' as i32 == 'K' as i32) as usize {
__assert_rtn(
(*::std::mem::transmute::<&[u8; 40], &[libc::c_char; 40]>(
b"dc_create_or_lookup_nchat_by_contact_id\x00",
@@ -1227,8 +1226,8 @@ pub unsafe fn dc_get_chat_msgs(
let mut curr_id: uint32_t;
let mut curr_local_timestamp: time_t;
let mut curr_day: libc::c_int;
let mut last_day: libc::c_int = 0i32;
let cnv_to_local: libc::c_long = dc_gm2local_offset();
let mut last_day = 0;
let cnv_to_local = dc_gm2local_offset();
if !ret.is_null() {
if chat_id == 1i32 as libc::c_uint {
let show_emails: libc::c_int = dc_sqlite3_get_config_int(
@@ -1264,7 +1263,7 @@ pub unsafe fn dc_get_chat_msgs(
}
if 0 != flags & 0x1i32 as libc::c_uint {
curr_local_timestamp = sqlite3_column_int64(stmt, 1i32) as time_t + cnv_to_local;
curr_day = (curr_local_timestamp / 86400i32 as libc::c_long) as libc::c_int;
curr_day = (curr_local_timestamp / 86400) as libc::c_int;
if curr_day != last_day {
dc_array_add_id(ret, 9i32 as uint32_t);
last_day = curr_day

View File

@@ -51,12 +51,12 @@ pub unsafe fn dc_may_be_valid_addr(addr: *const libc::c_char) -> bool {
return false;
}
let at: *const libc::c_char = strchr(addr, '@' as i32);
if at.is_null() || (at.wrapping_offset_from(addr) as libc::c_long) < 1i32 as libc::c_long {
if at.is_null() || at.wrapping_offset_from(addr) < 1 {
return false;
}
let dot: *const libc::c_char = strchr(at, '.' as i32);
if dot.is_null()
|| (dot.wrapping_offset_from(at) as libc::c_long) < 2i32 as libc::c_long
|| dot.wrapping_offset_from(at) < 2
|| *dot.offset(1isize) as libc::c_int == 0i32
|| *dot.offset(2isize) as libc::c_int == 0i32
{

View File

@@ -309,7 +309,7 @@ pub unsafe fn dc_e2ee_encrypt(
) {
let ctext_bytes = ctext_v.len();
let ctext_c = CString::new(ctext_v).unwrap();
let ctext = libc::strdup(ctext_c.as_ptr());
let ctext = strdup(ctext_c.as_ptr());
(*helper).cdata_to_free = ctext as *mut libc::c_void;
@@ -375,7 +375,7 @@ pub unsafe fn dc_e2ee_encrypt(
imffields_unprotected,
mailimf_field_new_custom(
strdup(b"Autocrypt\x00" as *const u8 as *const libc::c_char),
libc::strdup(rendered.as_ptr()),
strdup(rendered.as_ptr()),
),
);
}
@@ -612,16 +612,14 @@ pub unsafe fn dc_e2ee_decrypt(
let orig_date: *mut mailimf_orig_date = (*field).fld_data.fld_orig_date;
if !orig_date.is_null() {
message_time = dc_timestamp_from_date((*orig_date).dt_date_time);
if message_time != -1i32 as libc::c_long
&& message_time > time(0 as *mut time_t)
{
if message_time != -1 && message_time > time(0 as *mut time_t) {
message_time = time(0 as *mut time_t)
}
}
}
}
let autocryptheader = Aheader::from_imffields(from, imffields);
if message_time > 0i32 as libc::c_long && !from.is_null() {
if message_time > 0 && !from.is_null() {
if 0 != dc_apeerstate_load_by_addr(
&mut peerstate,
&context.sql.clone().read().unwrap(),
@@ -662,7 +660,7 @@ pub unsafe fn dc_e2ee_decrypt(
self_addr,
&context.sql.clone().read().unwrap(),
) {
if peerstate.last_seen == 0i32 as libc::c_long {
if peerstate.last_seen == 0 {
dc_apeerstate_load_by_addr(
&mut peerstate,
&context.sql.clone().read().unwrap(),
@@ -1032,7 +1030,7 @@ unsafe fn decrypt_part(
) {
let plain_bytes = plain.len();
let plain_c = CString::new(plain).unwrap();
let plain_buf = libc::strdup(plain_c.as_ptr());
let plain_buf = strdup(plain_c.as_ptr());
let mut index: size_t = 0i32 as size_t;
let mut decrypted_mime: *mut mailmime = 0 as *mut mailmime;

View File

@@ -73,7 +73,7 @@ pub unsafe fn dc_hash_init(
keyClass: libc::c_int,
mut copyKey: libc::c_int,
) {
if 0 != pNew.is_null() as libc::c_int as libc::c_long {
if 0 != pNew.is_null() as usize {
__assert_rtn(
(*::std::mem::transmute::<&[u8; 13], &[libc::c_char; 13]>(b"dc_hash_init\x00"))
.as_ptr(),
@@ -83,7 +83,7 @@ pub unsafe fn dc_hash_init(
);
} else {
};
if 0 != !(keyClass >= 1i32 && keyClass <= 4i32) as libc::c_int as libc::c_long {
if 0 != !(keyClass >= 1i32 && keyClass <= 4i32) as usize {
__assert_rtn(
(*::std::mem::transmute::<&[u8; 13], &[libc::c_char; 13]>(b"dc_hash_init\x00"))
.as_ptr(),
@@ -126,7 +126,7 @@ pub unsafe fn dc_hash_insert(
assert!(xHash.is_some(), "missing hashing function");
hraw = xHash.expect("non-null function pointer")(pKey, nKey);
if 0 != !((*pH).htsize & (*pH).htsize - 1i32 == 0i32) as libc::c_int as libc::c_long {
if 0 != !((*pH).htsize & (*pH).htsize - 1i32 == 0i32) as usize {
__assert_rtn(
(*::std::mem::transmute::<&[u8; 15], &[libc::c_char; 15]>(b"dc_hash_insert\x00"))
.as_ptr(),
@@ -178,7 +178,7 @@ pub unsafe fn dc_hash_insert(
if (*pH).count > (*pH).htsize {
rehash(pH, (*pH).htsize * 2);
}
if 0 != !((*pH).htsize > 0i32) as libc::c_int as libc::c_long {
if 0 != !((*pH).htsize > 0i32) as usize {
__assert_rtn(
(*::std::mem::transmute::<&[u8; 15], &[libc::c_char; 15]>(b"dc_hash_insert\x00"))
.as_ptr(),
@@ -188,7 +188,7 @@ pub unsafe fn dc_hash_insert(
);
} else {
};
if 0 != !((*pH).htsize & (*pH).htsize - 1i32 == 0i32) as libc::c_int as libc::c_long {
if 0 != !((*pH).htsize & (*pH).htsize - 1i32 == 0i32) as usize {
__assert_rtn(
(*::std::mem::transmute::<&[u8; 15], &[libc::c_char; 15]>(b"dc_hash_insert\x00"))
.as_ptr(),
@@ -248,7 +248,7 @@ unsafe fn rehash(mut pH: *mut dc_hash_t, new_size: libc::c_int) {
let mut next_elem: *mut dc_hashelem_t;
/* The hash function */
let 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 {
if 0 != !(new_size & new_size - 1i32 == 0i32) as usize {
__assert_rtn(
(*::std::mem::transmute::<&[u8; 7], &[libc::c_char; 7]>(b"rehash\x00")).as_ptr(),
b"../src/dc_hash.c\x00" as *const u8 as *const libc::c_char,

View File

@@ -103,8 +103,7 @@ pub unsafe fn dc_imex_has_backup(
b"backup_time\x00" as *const u8 as *const libc::c_char,
0i32,
) as time_t;
if curr_backup_time > 0i32 as libc::c_long && curr_backup_time > ret_backup_time
{
if curr_backup_time > 0 && curr_backup_time > ret_backup_time {
free(ret as *mut libc::c_void);
ret = curr_pathNfilename;
ret_backup_time = curr_backup_time;
@@ -243,7 +242,7 @@ pub unsafe fn dc_initiate_key_transfer(context: &dc_context_t) -> *mut libc::c_c
current_block = 6116957410927263949;
break;
}
sleep(1i32 as libc::c_uint);
std::thread::sleep(std::time::Duration::from_secs(1));
msg = dc_get_msg(context, msg_id);
if 0 != dc_msg_is_sent(msg) {
current_block = 6450636197030046351;
@@ -326,7 +325,7 @@ pub unsafe extern "C" fn dc_render_setup_file(
strlen(payload_key_asc),
) {
let encr_string_c = CString::new(encr).unwrap();
let mut encr_string = libc::strdup(encr_string_c.as_ptr());
let mut encr_string = strdup(encr_string_c.as_ptr());
free(payload_key_asc as *mut libc::c_void);
let replacement: *mut libc::c_char =
@@ -666,7 +665,7 @@ pub unsafe fn dc_decrypt_setup_file(
if let Some(plain) =
dc_pgp_symm_decrypt(passphrase, binary as *const libc::c_void, binary_bytes)
{
payload = libc::strdup(CString::new(plain).unwrap().as_ptr());
payload = strdup(CString::new(plain).unwrap().as_ptr());
}
}
}

View File

@@ -268,15 +268,15 @@ unsafe fn dc_job_delete(context: &dc_context_t, job: &dc_job_t) {
******************************************************************************/
unsafe fn get_backoff_time_offset(c_tries: libc::c_int) -> time_t {
// results in ~3 weeks for the last backoff timespan
let mut N: time_t = pow(2i32 as libc::c_double, (c_tries - 1i32) as libc::c_double) as time_t;
N = N * 60i32 as libc::c_long;
let mut N = 2_i32.pow((c_tries - 1) as u32);
N = N * 60;
let mut rng = thread_rng();
let n: libc::c_long = rng.gen();
let mut seconds: time_t = n % (N + 1i32 as libc::c_long);
if seconds < 1i32 as libc::c_long {
seconds = 1i32 as time_t
let n: i32 = rng.gen();
let mut seconds = n % (N + 1);
if seconds < 1 {
seconds = 1;
}
return seconds;
seconds as time_t
}
unsafe fn dc_job_update(context: &dc_context_t, job: &dc_job_t) {
let stmt: *mut sqlite3_stmt = dc_sqlite3_prepare(
@@ -299,7 +299,7 @@ unsafe fn dc_suspend_smtp_thread(context: &dc_context_t, suspend: libc::c_int) {
if context.smtp_state.0.lock().unwrap().doing_jobs == 0 {
return;
}
usleep((300i32 * 1000i32) as libc::useconds_t);
std::thread::sleep(std::time::Duration::from_micros(300 * 1000));
}
}
}
@@ -891,7 +891,7 @@ pub unsafe fn dc_job_add(
sqlite3_bind_int64(
stmt,
6i32,
(timestamp + delay_seconds as libc::c_long) as sqlite3_int64,
(timestamp + delay_seconds as time_t) as sqlite3_int64,
);
sqlite3_step(stmt);
sqlite3_finalize(stmt);

View File

@@ -6,7 +6,6 @@ use crate::dc_imap::Imap;
use crate::dc_log::*;
use crate::dc_sqlite3::*;
use crate::dc_tools::*;
use crate::types::*;
use crate::x::*;
#[repr(C)]
@@ -67,7 +66,7 @@ pub unsafe fn dc_jobthread_suspend(
if using_handle == 0 {
return;
}
usleep((300i32 * 1000i32) as useconds_t);
std::thread::sleep(std::time::Duration::from_micros(300 * 1000));
}
} else {
dc_log_info(

View File

@@ -4,7 +4,6 @@ use std::io::Cursor;
use std::slice;
use libc;
use mmime::other::*;
use pgp::composed::{Deserializable, SignedPublicKey, SignedSecretKey};
use pgp::ser::Serialize;
use pgp::types::{KeyTrait, SecretKeyTrait};
@@ -15,6 +14,7 @@ use crate::dc_log::*;
use crate::dc_sqlite3::*;
use crate::dc_tools::*;
use crate::types::*;
use crate::x::*;
#[derive(Debug, PartialEq, Eq, Clone)]
pub enum Key {
@@ -106,7 +106,7 @@ impl Key {
}
}
Err(err) => {
println!("Invalid key bytes: {:?}\n{}", err, hex::encode(bytes));
eprintln!("Invalid key bytes: {:?}\n{}", err, hex::encode(bytes));
None
}
}
@@ -246,7 +246,7 @@ impl Key {
// need to use strdup to allocate the result with malloc
// so it can be `free`d later.
unsafe { libc::strdup(res_c.as_ptr()) }
unsafe { strdup(res_c.as_ptr()) }
}
pub fn to_armored_string(
@@ -274,7 +274,7 @@ impl Key {
// need to use strdup to allocate the result with malloc
// so it can be `free`d later.
unsafe { libc::strdup(buf_c.as_ptr()) }
unsafe { strdup(buf_c.as_ptr()) }
}
pub fn write_asc_to_file(&self, file: *const libc::c_char, context: &dc_context_t) -> bool {
@@ -314,7 +314,7 @@ impl Key {
pub fn fingerprint_c(&self) -> *mut libc::c_char {
let res = CString::new(self.fingerprint()).unwrap();
unsafe { libc::strdup(res.as_ptr()) }
unsafe { strdup(res.as_ptr()) }
}
pub fn formatted_fingerprint(&self) -> String {
@@ -325,7 +325,7 @@ impl Key {
pub fn formatted_fingerprint_c(&self) -> *mut libc::c_char {
let res = CString::new(self.formatted_fingerprint()).unwrap();
unsafe { libc::strdup(res.as_ptr()) }
unsafe { strdup(res.as_ptr()) }
}
pub fn split_key(&self) -> Option<Key> {
@@ -384,7 +384,7 @@ pub fn dc_key_save_self_keypair(
None,
)
};
unsafe { sqlite3_bind_int64(stmt, 5, time(0 as *mut time_t) as sqlite3_int64) };
unsafe { sqlite3_bind_int64(stmt, 5, libc::time(0 as *mut time_t) as sqlite3_int64) };
let success = if unsafe { sqlite3_step(stmt) } == 101 {
true
} else {
@@ -419,7 +419,7 @@ pub fn dc_format_fingerprint_c(fp: *const libc::c_char) -> *mut libc::c_char {
let res = dc_format_fingerprint(input);
let res_c = CString::new(res).unwrap();
unsafe { libc::strdup(res_c.as_ptr()) }
unsafe { strdup(res_c.as_ptr()) }
}
/// Bring a human-readable or otherwise formatted fingerprint back to the 40-characters-uppercase-hex format.
@@ -435,7 +435,7 @@ pub fn dc_normalize_fingerprint_c(fp: *const libc::c_char) -> *mut libc::c_char
let res = dc_normalize_fingerprint(input);
let res_c = CString::new(res).unwrap();
unsafe { libc::strdup(res_c.as_ptr()) }
unsafe { strdup(res_c.as_ptr()) }
}
#[cfg(test)]

View File

@@ -60,19 +60,15 @@ pub unsafe fn dc_send_locations_to_chat(
sqlite3_bind_int64(
stmt,
1i32,
(if 0 != seconds {
now
} else {
0i32 as libc::c_long
}) as sqlite3_int64,
(if 0 != seconds { now } else { 0 }) as sqlite3_int64,
);
sqlite3_bind_int64(
stmt,
2i32,
(if 0 != seconds {
now + seconds as libc::c_long
now + seconds as time_t
} else {
0i32 as libc::c_long
0
}) as sqlite3_int64,
);
sqlite3_bind_int(stmt, 3i32, chat_id as libc::c_int);
@@ -224,8 +220,8 @@ pub unsafe fn dc_get_locations(
let ret: *mut dc_array_t = dc_array_new_typed(1i32, 500i32 as size_t);
let 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
if timestamp_to == 0 {
timestamp_to = time(0 as *mut time_t) + 10;
}
stmt = dc_sqlite3_prepare(
context,
@@ -361,7 +357,7 @@ pub unsafe fn dc_get_location_kml(
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) {
if !(locations_send_begin == 0 || 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,
@@ -806,7 +802,7 @@ pub unsafe fn dc_job_do_DC_JOB_MAYBE_SEND_LOCATIONS(context: &dc_context_t, _job
let locations_last_sent: time_t = sqlite3_column_int64(stmt_chats, 2i32) as time_t;
continue_streaming = 1i32;
// be a bit tolerant as the timer may not align exactly with time(NULL)
if now - locations_last_sent < (60i32 - 3i32) as libc::c_long {
if now - locations_last_sent < (60 - 3) {
continue;
}
if stmt_locations.is_null() {
@@ -875,15 +871,11 @@ pub unsafe fn dc_job_do_DC_JOB_MAYBE_SEND_LOC_ENDED(context: &dc_context_t, job:
locations_send_until = sqlite3_column_int64(stmt, 1i32) as time_t;
sqlite3_finalize(stmt);
stmt = 0 as *mut sqlite3_stmt;
if !(locations_send_begin != 0i32 as libc::c_long
&& time(0 as *mut time_t) <= locations_send_until)
{
if !(locations_send_begin != 0 && time(0 as *mut time_t) <= locations_send_until) {
// still streaming -
// may happen as several calls to dc_send_locations_to_chat()
// do not un-schedule pending DC_MAYBE_SEND_LOC_ENDED jobs
if !(locations_send_begin == 0i32 as libc::c_long
&& locations_send_until == 0i32 as libc::c_long)
{
if !(locations_send_begin == 0 && locations_send_until == 0) {
// not streaming, device-message already sent
stmt =
dc_sqlite3_prepare(

View File

@@ -529,9 +529,8 @@ pub unsafe fn dc_mimefactory_render(mut factory: *mut dc_mimefactory_t) -> libc:
e2ee_guaranteed = dc_param_get_int((*(*factory).msg).param, 'c' as i32, 0i32)
}
}
if (*chat).gossiped_timestamp == 0i32 as libc::c_long
|| ((*chat).gossiped_timestamp + (2i32 * 24i32 * 60i32 * 60i32) as libc::c_long)
< time(0 as *mut time_t)
if (*chat).gossiped_timestamp == 0
|| ((*chat).gossiped_timestamp + (2 * 24 * 60 * 60)) < time(0 as *mut time_t)
{
do_gossip = 1i32
}

View File

@@ -1,4 +1,6 @@
use mmime::charconv::*;
use std::ffi::{CStr, CString};
use charset::Charset;
use mmime::mailimf::*;
use mmime::mailimf_types::*;
use mmime::mailmime::*;
@@ -289,10 +291,8 @@ pub unsafe fn dc_mimeparser_parse(
let mut prepend_subject: libc::c_int = 1i32;
if 0 == (*mimeparser).decrypting_failed {
let p: *mut libc::c_char = strchr((*mimeparser).subject, ':' as i32);
if p.wrapping_offset_from((*mimeparser).subject) as libc::c_long
== 2i32 as libc::c_long
|| p.wrapping_offset_from((*mimeparser).subject) as libc::c_long
== 3i32 as libc::c_long
if p.wrapping_offset_from((*mimeparser).subject) == 2
|| p.wrapping_offset_from((*mimeparser).subject) == 3
|| 0 != (*mimeparser).is_send_by_messenger
|| !strstr(
(*mimeparser).subject,
@@ -1172,8 +1172,6 @@ unsafe fn dc_mimeparser_add_single_part_if_known(
let mut raw_mime: *mut libc::c_char = 0 as *mut libc::c_char;
/* mmap_string_unref()'d if set */
let mut transfer_decoding_buffer: *mut libc::c_char = 0 as *mut libc::c_char;
/* charconv_buffer_free()'d if set (just calls mmap_string_unref()) */
let mut charset_buffer: *mut libc::c_char = 0 as *mut libc::c_char;
/* must not be free()'d */
let mut decoded_data: *const libc::c_char = 0 as *const libc::c_char;
let mut decoded_data_bytes = 0;
@@ -1225,32 +1223,34 @@ unsafe fn dc_mimeparser_add_single_part_if_known(
b"UTF-8\x00" as *const u8 as *const libc::c_char,
) != 0i32
{
let mut ret_bytes = 0;
let r: libc::c_int = charconv_buffer(
b"utf-8\x00" as *const u8 as *const libc::c_char,
charset,
decoded_data,
decoded_data_bytes,
&mut charset_buffer,
&mut ret_bytes,
);
if r != MAIL_CHARCONV_NO_ERROR as libc::c_int {
dc_log_warning((*mimeparser).context,
0i32,
b"Cannot convert %i bytes from \"%s\" to \"utf-8\"; errorcode is %i.\x00"
as *const u8 as
*const libc::c_char,
decoded_data_bytes as
libc::c_int,
charset,
r as libc::c_int);
current_block = 17788412896529399552;
} else if charset_buffer.is_null() || ret_bytes <= 0 {
/* no error - but nothing to add */
current_block = 8795901732489102124;
if let Some(encoding) = Charset::for_label(
CStr::from_ptr(charset).to_str().unwrap().as_bytes(),
) {
let data = std::slice::from_raw_parts(
decoded_data as *const u8,
decoded_data_bytes,
);
let (res, _, _) = encoding.decode(data);
if res.is_empty() {
/* no error - but nothing to add */
current_block = 8795901732489102124;
} else {
decoded_data_bytes = res.len();
let res_c = CString::new(res.as_bytes()).unwrap();
decoded_data = strdup(res_c.as_ptr());
current_block = 17788412896529399552;
}
} else {
decoded_data = charset_buffer;
decoded_data_bytes = ret_bytes;
dc_log_warning(
(*mimeparser).context,
0i32,
b"Cannot convert %i bytes from \"%s\" to \"utf-8\".\x00"
as *const u8
as *const libc::c_char,
decoded_data_bytes as libc::c_int,
charset,
);
current_block = 17788412896529399552;
}
} else {
@@ -1484,9 +1484,6 @@ unsafe fn dc_mimeparser_add_single_part_if_known(
}
/* add object? (we do not add all objetcs, eg. signatures etc. are ignored) */
dc_simplify_unref(simplifier);
if !charset_buffer.is_null() {
charconv_buffer_free(charset_buffer);
}
if !transfer_decoding_buffer.is_null() {
mmap_string_unref(transfer_decoding_buffer);
}

View File

@@ -1061,12 +1061,11 @@ pub unsafe fn dc_msg_get_summarytext_by_raw(
}
pub unsafe fn dc_msg_has_deviating_timestamp(msg: *const dc_msg_t) -> libc::c_int {
let cnv_to_local: libc::c_long = dc_gm2local_offset();
let cnv_to_local = dc_gm2local_offset();
let sort_timestamp: time_t = dc_msg_get_sort_timestamp(msg) + cnv_to_local;
let send_timestamp: time_t = dc_msg_get_timestamp(msg) + cnv_to_local;
(sort_timestamp / 86400i32 as libc::c_long != send_timestamp / 86400i32 as libc::c_long)
as libc::c_int
(sort_timestamp / 86400 != send_timestamp / 86400) as libc::c_int
}
// TODO should return bool /rtn

View File

@@ -326,11 +326,7 @@ pub unsafe fn dc_get_oauth2_access_token(
);
if !expires_in_str.is_null() {
let val: time_t = atol(expires_in_str);
if val > 20i32 as libc::c_long
&& val
< (60i32 * 60i32 * 24i32 * 365i32 * 5i32)
as libc::c_long
{
if val > 20 && val < (60 * 60 * 24 * 365 * 5) {
expires_in = val
}
free(expires_in_str as *mut libc::c_void);
@@ -419,9 +415,9 @@ pub unsafe fn dc_get_oauth2_access_token(
b"oauth2_timestamp_expires\x00" as *const u8
as *const libc::c_char,
(if 0 != expires_in {
time(0 as *mut time_t) + expires_in - 5i32 as libc::c_long
time(0 as *mut time_t) + expires_in - 5
} else {
0i32 as libc::c_long
0
}) as int64_t,
);
if 0 != update_redirect_uri_on_success {
@@ -495,7 +491,7 @@ unsafe fn is_expired(context: &dc_context_t) -> bool {
b"oauth2_timestamp_expires\x00" as *const u8 as *const libc::c_char,
0i32 as int64_t,
) as time_t;
if expire_timestamp <= 0i32 as libc::c_long {
if expire_timestamp <= 0 {
return false;
}
if expire_timestamp > time(0 as *mut time_t) {

View File

@@ -260,7 +260,7 @@ pub fn dc_pgp_pk_decrypt(
let fp_r = hex::encode_upper(pkey.fingerprint());
let len = fp_r.len() as libc::c_int;
let fp_c = CString::new(fp_r).unwrap();
let fp = unsafe { libc::strdup(fp_c.as_ptr()) };
let fp = unsafe { strdup(fp_c.as_ptr()) };
unsafe {
dc_hash_insert(

View File

@@ -268,12 +268,8 @@ pub unsafe fn dc_receive_imf(
}
}
if 0 != incoming {
state = if 0 != flags as libc::c_long & 0x1 {
16i32
} else {
10i32
};
to_id = 1i32 as uint32_t;
state = if 0 != flags & 0x1 { 16 } else { 10 };
to_id = 1 as uint32_t;
if !dc_mimeparser_lookup_field(
mime_parser,
b"Secure-Join\x00" as *const u8 as *const libc::c_char,
@@ -454,11 +450,7 @@ pub unsafe fn dc_receive_imf(
chat_id,
from_id,
sent_timestamp,
if 0 != flags as libc::c_long & 0x1 {
0i32
} else {
1i32
},
if 0 != flags & 0x1 { 0 } else { 1 },
&mut sort_timestamp,
&mut sent_timestamp,
&mut rcvd_timestamp,
@@ -481,8 +473,7 @@ pub unsafe fn dc_receive_imf(
);
if !p.is_null() {
header_bytes = (p.wrapping_offset_from(imf_raw_not_terminated)
as libc::c_long
+ 4i32 as libc::c_long)
+ 4)
as libc::c_int
} else {
p = strstr(
@@ -490,11 +481,9 @@ pub unsafe fn dc_receive_imf(
b"\n\n\x00" as *const u8 as *const libc::c_char,
);
if !p.is_null() {
header_bytes = (p
.wrapping_offset_from(imf_raw_not_terminated)
as libc::c_long
+ 2i32 as libc::c_long)
as libc::c_int
header_bytes =
(p.wrapping_offset_from(imf_raw_not_terminated) + 2)
as libc::c_int
}
}
}
@@ -1059,9 +1048,9 @@ unsafe fn calc_timestamps(
sqlite3_bind_int64(stmt, 3i32, *sort_timestamp as sqlite3_int64);
if sqlite3_step(stmt) == 100i32 {
let last_msg_time: time_t = sqlite3_column_int64(stmt, 0i32) as time_t;
if last_msg_time > 0i32 as libc::c_long {
if last_msg_time > 0 {
if *sort_timestamp <= last_msg_time {
*sort_timestamp = last_msg_time + 1i32 as libc::c_long
*sort_timestamp = last_msg_time + 1
}
}
}

View File

@@ -103,7 +103,7 @@ pub unsafe fn dc_saxparser_parse(saxparser: *mut dc_saxparser_t, buf_start__: *c
call_text_cb(
saxparser,
last_text_start,
p.wrapping_offset_from(last_text_start) as libc::c_long as size_t,
p.wrapping_offset_from(last_text_start) as size_t,
'&' as i32 as libc::c_char,
);
p = p.offset(1isize);
@@ -123,7 +123,7 @@ pub unsafe fn dc_saxparser_parse(saxparser: *mut dc_saxparser_t, buf_start__: *c
call_text_cb(
saxparser,
text_beg,
p.wrapping_offset_from(text_beg) as libc::c_long as size_t,
p.wrapping_offset_from(text_beg) as size_t,
'c' as i32 as libc::c_char,
);
p = p.offset(3isize)
@@ -341,7 +341,7 @@ pub unsafe fn dc_saxparser_parse(saxparser: *mut dc_saxparser_t, buf_start__: *c
call_text_cb(
saxparser,
last_text_start,
p.wrapping_offset_from(last_text_start) as libc::c_long as size_t,
p.wrapping_offset_from(last_text_start) as size_t,
'&' as i32 as libc::c_char,
);
}
@@ -465,7 +465,7 @@ unsafe fn xml_decode(mut s: *mut libc::c_char, type_0: libc::c_char) -> *mut lib
s = s.offset(1);
*fresh2 = c as libc::c_char
} else {
b = 0i32 as libc::c_long;
b = 0;
d = c;
while 0 != d {
b += 1;
@@ -491,7 +491,7 @@ unsafe fn xml_decode(mut s: *mut libc::c_char, type_0: libc::c_char) -> *mut lib
} else if *s as libc::c_int == '&' as i32
&& (type_0 as libc::c_int == '&' as i32 || type_0 as libc::c_int == ' ' as i32)
{
b = 0i32 as libc::c_long;
b = 0;
while !s_ent[b as usize].is_null()
&& 0 != strncmp(
s.offset(1isize),
@@ -499,7 +499,7 @@ unsafe fn xml_decode(mut s: *mut libc::c_char, type_0: libc::c_char) -> *mut lib
strlen(s_ent[b as usize]),
)
{
b += 2i32 as libc::c_long
b += 2;
}
let fresh5 = b;
b = b + 1;

View File

@@ -267,7 +267,7 @@ pub unsafe fn dc_join_securejoin(context: &dc_context_t, qr: *const libc::c_char
.unwrap()
.shall_stop_ongoing)
{
usleep((300i32 * 1000i32) as useconds_t);
std::thread::sleep(std::time::Duration::from_micros(300 * 1000));
}
}
}

View File

@@ -184,7 +184,7 @@ impl Smtp {
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()) };
self.error = unsafe { strdup(msg.as_ptr()) };
warn!(context, 0, "%s", msg,);

View File

@@ -725,9 +725,7 @@ pub unsafe fn dc_sqlite3_open(
as *const u8
as *const libc::c_char,
);
if 0 != !(DC_MOVE_STATE_UNDEFINED as libc::c_int == 0) as libc::c_int
as libc::c_long
{
if 0 != !(DC_MOVE_STATE_UNDEFINED as libc::c_int == 0) as usize {
__assert_rtn(
(*::std::mem::transmute::<&[u8; 16], &[libc::c_char; 16]>(
b"dc_sqlite3_open\x00",
@@ -740,9 +738,7 @@ pub unsafe fn dc_sqlite3_open(
);
} else {
};
if 0 != !(DC_MOVE_STATE_PENDING as libc::c_int == 1) as libc::c_int
as libc::c_long
{
if 0 != !(DC_MOVE_STATE_PENDING as libc::c_int == 1) as usize {
__assert_rtn(
(*::std::mem::transmute::<&[u8; 16], &[libc::c_char; 16]>(
b"dc_sqlite3_open\x00",
@@ -755,9 +751,7 @@ pub unsafe fn dc_sqlite3_open(
);
} else {
};
if 0 != !(DC_MOVE_STATE_STAY as libc::c_int == 2) as libc::c_int
as libc::c_long
{
if 0 != !(DC_MOVE_STATE_STAY as libc::c_int == 2) as usize {
__assert_rtn(
(*::std::mem::transmute::<&[u8; 16], &[libc::c_char; 16]>(
b"dc_sqlite3_open\x00",
@@ -770,9 +764,7 @@ pub unsafe fn dc_sqlite3_open(
);
} else {
};
if 0 != !(DC_MOVE_STATE_MOVING as libc::c_int == 3) as libc::c_int
as libc::c_long
{
if 0 != !(DC_MOVE_STATE_MOVING as libc::c_int == 3) as usize {
__assert_rtn(
(*::std::mem::transmute::<&[u8; 16], &[libc::c_char; 16]>(
b"dc_sqlite3_open\x00",
@@ -935,7 +927,7 @@ pub unsafe fn dc_sqlite3_open(
context.get_blobdir(),
);
dc_ensure_no_slash(repl_from);
if 0 != !('f' as i32 == 'f' as i32) as libc::c_int as libc::c_long {
if 0 != !('f' as i32 == 'f' as i32) as usize {
__assert_rtn(
(*::std::mem::transmute::<&[u8; 16], &[libc::c_char; 16]>(
b"dc_sqlite3_open\x00",
@@ -954,7 +946,7 @@ pub unsafe fn dc_sqlite3_open(
repl_from);
dc_sqlite3_execute(context, sql, q3);
sqlite3_free(q3 as *mut libc::c_void);
if 0 != !('i' as i32 == 'i' as i32) as libc::c_int as libc::c_long {
if 0 != !('i' as i32 == 'i' as i32) as usize {
__assert_rtn(
(*::std::mem::transmute::<&[u8; 16], &[libc::c_char; 16]>(
b"dc_sqlite3_open\x00",
@@ -1298,7 +1290,7 @@ pub unsafe fn dc_sqlite3_set_config_int64(
) -> libc::c_int {
let value_str = dc_mprintf(
b"%lld\x00" as *const u8 as *const libc::c_char,
value as libc::c_long,
value as time_t,
);
if value_str.is_null() {
return 0;

View File

@@ -40,8 +40,8 @@ pub unsafe fn dc_strbuilder_cat(
} else {
(*strbuilder).allocated
};
let old_offset: libc::c_int = (*strbuilder).eos.wrapping_offset_from((*strbuilder).buf)
as libc::c_long as libc::c_int;
let old_offset: libc::c_int =
(*strbuilder).eos.wrapping_offset_from((*strbuilder).buf) as libc::c_int;
(*strbuilder).allocated = (*strbuilder).allocated + add_bytes;
(*strbuilder).buf = realloc(
(*strbuilder).buf as *mut libc::c_void,

View File

@@ -1,10 +1,13 @@
use mmime::charconv::*;
use std::ffi::{CStr, CString};
use charset::Charset;
use mmime::mailmime_decode::*;
use mmime::mmapstring::*;
use mmime::other::*;
use crate::dc_tools::*;
use crate::types::*;
use crate::x::*;
#[inline]
pub fn isalnum(mut _c: libc::c_int) -> libc::c_int {
@@ -32,9 +35,8 @@ pub unsafe fn dc_urlencode(to_encode: *const libc::c_char) -> *mut libc::c_char
let buf: *mut libc::c_char =
malloc(strlen(to_encode).wrapping_mul(3).wrapping_add(1)) as *mut libc::c_char;
let mut pbuf: *mut libc::c_char = buf;
if buf.is_null() {
exit(46i32);
}
assert!(!buf.is_null());
while 0 != *pstr {
if 0 != isalnum(*pstr as libc::c_int)
|| *pstr as libc::c_int == '-' as i32
@@ -85,9 +87,8 @@ pub unsafe fn dc_urldecode(to_decode: *const libc::c_char) -> *mut libc::c_char
}
let buf: *mut libc::c_char = malloc(strlen(to_decode).wrapping_add(1)) as *mut libc::c_char;
let mut pbuf: *mut libc::c_char = buf;
if buf.is_null() {
exit(50i32);
}
assert!(!buf.is_null());
while 0 != *pstr {
if *pstr as libc::c_int == '%' as i32 {
if 0 != *pstr.offset(1isize) as libc::c_int && 0 != *pstr.offset(2isize) as libc::c_int
@@ -119,7 +120,7 @@ unsafe fn hex_2_int(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 {
libc::tolower(ch as libc::c_int) - 'a' as i32 + 10i32
tolower(ch as libc::c_int) - 'a' as i32 + 10i32
}) as libc::c_char;
}
@@ -167,7 +168,7 @@ pub unsafe fn dc_encode_header_words(to_encode: *const libc::c_char) -> *mut lib
b"utf-8\x00" as *const u8 as *const libc::c_char,
mmapstr,
begin,
end.wrapping_offset_from(begin) as libc::c_long as size_t,
end.wrapping_offset_from(begin) as size_t,
) {
current_block = 8550051112593613029;
continue;
@@ -183,7 +184,7 @@ pub unsafe fn dc_encode_header_words(to_encode: *const libc::c_char) -> *mut lib
if mmap_string_append_len(
mmapstr,
end,
cur.wrapping_offset_from(end) as libc::c_long as size_t,
cur.wrapping_offset_from(end) as size_t,
)
.is_null()
{
@@ -194,7 +195,7 @@ pub unsafe fn dc_encode_header_words(to_encode: *const libc::c_char) -> *mut lib
} else if mmap_string_append_len(
mmapstr,
begin,
cur.wrapping_offset_from(begin) as libc::c_long as size_t,
cur.wrapping_offset_from(begin) as size_t,
)
.is_null()
{
@@ -297,10 +298,7 @@ unsafe fn get_word(
{
cur = cur.offset(1isize)
}
*pto_be_quoted = to_be_quoted(
begin,
cur.wrapping_offset_from(begin) as libc::c_long as size_t,
);
*pto_be_quoted = to_be_quoted(begin, cur.wrapping_offset_from(begin) as size_t);
*pend = cur;
}
@@ -369,9 +367,8 @@ pub unsafe fn dc_encode_modified_utf7(
}
res = malloc(2usize.wrapping_mul(strlen(to_encode)).wrapping_add(1)) as *mut libc::c_char;
dst = res;
if dst.is_null() {
exit(51i32);
}
assert!(!dst.is_null());
utf7mode = 0i32 as libc::c_uint;
utf8total = 0i32 as libc::c_uint;
bitstogo = 0i32 as libc::c_uint;
@@ -521,10 +518,9 @@ pub unsafe fn dc_decode_modified_utf7(
res = malloc(4usize.wrapping_mul(strlen(to_decode)).wrapping_add(1)) as *mut libc::c_char;
dst = res;
src = to_decode;
if dst.is_null() {
exit(52i32);
}
memset(
assert!(!dst.is_null());
libc::memset(
base64.as_mut_ptr() as *mut libc::c_void,
64,
::std::mem::size_of::<[libc::c_uchar; 256]>(),
@@ -642,9 +638,8 @@ pub unsafe fn dc_encode_ext_header(to_encode: *const libc::c_char) -> *mut libc:
.wrapping_add(strlen(to_encode).wrapping_mul(3))
.wrapping_add(1),
) as *mut libc::c_char;
if buf.is_null() {
exit(46i32);
}
assert!(!buf.is_null());
let mut pbuf: *mut libc::c_char = buf;
strcpy(pbuf, b"utf-8\'\'\x00" as *const u8 as *const libc::c_char);
pbuf = pbuf.offset(strlen(pbuf) as isize);
@@ -685,10 +680,8 @@ pub unsafe fn dc_decode_ext_header(to_decode: *const libc::c_char) -> *mut libc:
p2 = strchr(to_decode, '\'' as i32);
if !(p2.is_null() || p2 == to_decode) {
/*no empty charset allowed*/
charset = dc_null_terminate(
to_decode,
p2.wrapping_offset_from(to_decode) as libc::c_long as libc::c_int,
);
charset =
dc_null_terminate(to_decode, p2.wrapping_offset_from(to_decode) as libc::c_int);
p2 = p2.offset(1isize);
// skip language
p2 = strchr(p2, '\'' as i32);
@@ -699,19 +692,17 @@ pub unsafe fn dc_decode_ext_header(to_decode: *const libc::c_char) -> *mut libc:
&& strcmp(charset, b"utf-8\x00" as *const u8 as *const libc::c_char) != 0i32
&& strcmp(charset, b"UTF-8\x00" as *const u8 as *const libc::c_char) != 0i32
{
let mut converted: *mut libc::c_char = 0 as *mut libc::c_char;
let r: libc::c_int = charconv(
b"utf-8\x00" as *const u8 as *const libc::c_char,
charset,
decoded,
strlen(decoded),
&mut converted,
);
if r == MAIL_CHARCONV_NO_ERROR as libc::c_int && !converted.is_null() {
if let Some(encoding) =
Charset::for_label(CStr::from_ptr(charset).to_str().unwrap().as_bytes())
{
let data =
std::slice::from_raw_parts(decoded as *const u8, strlen(decoded));
let (res, _, _) = encoding.decode(data);
free(decoded as *mut libc::c_void);
decoded = converted
} else {
free(converted as *mut libc::c_void);
let res_c = CString::new(res.as_bytes()).unwrap();
decoded = strdup(res_c.as_ptr());
}
}
}

View File

@@ -96,8 +96,8 @@ pub unsafe fn dc_str_replace(
if p2.is_null() {
break;
}
start_search_pos = (p2.wrapping_offset_from(*haystack) as libc::c_long
+ replacement_len as libc::c_long) as libc::c_int;
start_search_pos =
(p2.wrapping_offset_from(*haystack) + replacement_len as isize) as libc::c_int;
*p2 = 0i32 as libc::c_char;
p2 = p2.offset(needle_len as isize);
let new_string: *mut libc::c_char = dc_mprintf(
@@ -185,7 +185,7 @@ pub unsafe fn dc_strlower(in_0: *const libc::c_char) -> *mut libc::c_char {
let out: *mut libc::c_char = dc_strdup(in_0);
let mut p: *mut libc::c_char = out;
while 0 != *p {
*p = libc::tolower(*p as libc::c_int) as libc::c_char;
*p = tolower(*p as libc::c_int) as libc::c_char;
p = p.offset(1isize)
}
@@ -195,7 +195,7 @@ pub unsafe fn dc_strlower(in_0: *const libc::c_char) -> *mut libc::c_char {
pub unsafe fn dc_strlower_in_place(in_0: *mut libc::c_char) {
let mut p: *mut libc::c_char = in_0;
while 0 != *p {
*p = libc::tolower(*p as libc::c_int) as libc::c_char;
*p = tolower(*p as libc::c_int) as libc::c_char;
p = p.offset(1isize)
}
}
@@ -593,10 +593,7 @@ pub unsafe fn dc_str_to_clist(
clist_insert_after(
list,
(*list).last,
strndup(
p1,
p2.wrapping_offset_from(p1) as libc::c_long as libc::c_ulong,
) as *mut libc::c_void,
strndup(p1, p2.wrapping_offset_from(p1) as libc::c_ulong) as *mut libc::c_void,
);
p1 = p2.offset(strlen(delimiter) as isize)
}
@@ -725,7 +722,7 @@ pub unsafe fn dc_timestamp_from_date(date_time: *mut mailimf_date_time) -> time_
zone_hour = -(-(*date_time).dt_zone / 100i32);
zone_min = -(-(*date_time).dt_zone % 100i32)
}
timeval -= (zone_hour * 3600i32 + zone_min * 60i32) as libc::c_long;
timeval -= (zone_hour * 3600 + zone_min * 60) as time_t;
timeval
}
@@ -754,18 +751,14 @@ pub unsafe fn mkgmtime(tmp: *mut tm) -> time_t {
yourtm.tm_sec = 0i32;
bits = 0i32;
t = 1i32 as time_t;
while t > 0i32 as libc::c_long {
while t > 0 {
bits += 1;
t <<= 1i32
}
if bits > 40i32 {
bits = 40i32
}
t = if t < 0i32 as libc::c_long {
0i32 as libc::c_long
} else {
(1i32 as time_t) << bits
};
t = if t < 0 { 0 } else { (1i32 as time_t) << bits };
loop {
gmtime_r(&mut t, &mut mytm);
dir = tmcomp(&mut mytm, &mut yourtm);
@@ -785,7 +778,7 @@ pub unsafe fn mkgmtime(tmp: *mut tm) -> time_t {
t += (1i32 as time_t) << bits
}
}
t += saved_seconds as libc::c_long;
t += saved_seconds as time_t;
t
}
@@ -851,7 +844,7 @@ pub unsafe fn dc_timestamp_to_str(mut wanted: time_t) -> *mut libc::c_char {
);
}
pub unsafe fn dc_gm2local_offset() -> libc::c_long {
pub unsafe fn dc_gm2local_offset() -> time_t {
/* returns the offset that must be _added_ to an UTC/GMT-time to create the localtime.
the function may return nagative values. */
let mut gmtime: time_t = time(0 as *mut time_t);
@@ -902,14 +895,15 @@ pub unsafe fn dc_create_smeared_timestamp(context: &dc_context_t) -> time_t {
pub unsafe fn dc_create_smeared_timestamps(context: &dc_context_t, count: libc::c_int) -> time_t {
/* get a range to timestamps that can be used uniquely */
let now: time_t = time(0 as *mut time_t);
let mut start: time_t =
now + (if count < 5i32 { count } else { 5i32 }) as libc::c_long - count as libc::c_long;
let now = time(0 as *mut time_t);
let start = now + (if count < 5 { count } else { 5 }) as time_t - count as time_t;
let ts = *context.last_smeared_timestamp.clone().write().unwrap();
start = if ts + 1 > start { ts + 1 } else { start };
start
if ts + 1 > start {
ts + 1
} else {
start
}
}
/* Message-ID tools */
@@ -1212,11 +1206,10 @@ pub unsafe fn dc_get_filemeta(
as uint32_t;
return 1i32;
}
pos += (2i32
+ ((*buf.offset((pos + 2) as isize) as libc::c_int) << 8i32)
+ *buf.offset((pos + 3) as isize) as libc::c_int)
as libc::c_long;
if (pos + 12) > buf_bytes as libc::c_long {
pos += 2
+ ((*buf.offset((pos + 2) as isize) as libc::c_int) << 8)
+ *buf.offset((pos + 3) as isize) as libc::c_int;
if (pos + 12) > buf_bytes as libc::c_int {
break;
}
}
@@ -1552,10 +1545,10 @@ pub unsafe fn dc_get_fine_pathNfilename(
while i < 1000i32 {
/*no deadlocks, please*/
if 0 != i {
let idx: time_t = if i < 100i32 {
i as libc::c_long
let idx = if i < 100 {
i as time_t
} else {
now + i as libc::c_long
now + i as time_t
};
ret = dc_mprintf(
b"%s/%s-%lu%s\x00" as *const u8 as *const libc::c_char,

View File

@@ -21,12 +21,6 @@ pub type __darwin_ct_rune_t = libc::c_int;
pub type __darwin_wchar_t = libc::c_int;
pub type __darwin_rune_t = __darwin_wchar_t;
pub type uint64_t = libc::c_ulonglong;
pub type uid_t = libc::uid_t;
pub type gid_t = libc::gid_t;
pub type dev_t = libc::dev_t;
pub type blkcnt_t = libc::blkcnt_t;
pub type blksize_t = libc::blksize_t;
pub type nlink_t = __uint16_t;
/**
* Callback function that should be given to dc_context_new().
@@ -73,7 +67,6 @@ pub type dc_get_config_t = unsafe fn(
pub type sqlite_int64 = libc::int64_t;
pub type sqlite3_int64 = sqlite_int64;
pub type useconds_t = libc::useconds_t;
pub type int32_t = libc::int32_t;
pub type int64_t = libc::int64_t;
pub type uintptr_t = libc::uintptr_t;

View File

@@ -4,15 +4,23 @@ use crate::types::*;
pub use libc::{
atoi, calloc, close, closedir, exit, fclose, fgets, fopen, fread, free, fseek, ftell, fwrite,
gmtime, gmtime_r, localtime, localtime_r, malloc, memcmp, memcpy, memmove, memset, mkdir, open,
opendir, printf, read, readdir, realloc, remove, sleep, snprintf, sprintf, sscanf, strcasecmp,
strcat, strchr, strcmp, strcpy, strcspn, strdup, strlen, strncasecmp, strncmp, strncpy,
strrchr, strspn, strstr, strtol, system, time, tolower as __tolower, toupper as __toupper,
usleep, write,
opendir, printf, read, readdir, realloc, remove, sprintf, sscanf, strcat, strchr, strcmp,
strcpy, strcspn, strlen, strncmp, strncpy, strrchr, strspn, strstr, strtol, system, time,
tolower, write,
};
extern "C" {
// pub static mut _DefaultRuneLocale: _RuneLocale;
pub unsafe fn strdup(s: *const libc::c_char) -> *mut libc::c_char {
let slen = libc::strlen(s);
let result = libc::malloc(slen + 1);
if result.is_null() {
return std::ptr::null_mut();
}
libc::memcpy(result, s as *const _, slen + 1);
result as *mut _
}
extern "C" {
pub fn clock() -> libc::clock_t;
pub fn qsort(
__base: *mut libc::c_void,
@@ -53,12 +61,23 @@ extern "C" {
_: *const libc::c_char,
) -> !;
#[cfg(windows)]
pub(crate) fn snprintf(
s: *mut libc::c_char,
n: libc::size_t,
format: *const libc::c_char,
_: ...
) -> libc::c_int;
// -- 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;
}
#[cfg(not(windows))]
pub(crate) use libc::snprintf;
#[cfg(not(target_os = "macos"))]
pub unsafe extern "C" fn __assert_rtn(
a: *const libc::c_char,
@@ -77,6 +96,41 @@ pub unsafe fn atof(nptr: *mut libc::c_char) -> libc::c_double {
libc::strtod(nptr, std::ptr::null_mut())
}
pub(crate) unsafe fn strcasecmp(s1: *const libc::c_char, s2: *const libc::c_char) -> libc::c_int {
let s1 = std::ffi::CStr::from_ptr(s1)
.to_string_lossy()
.to_lowercase();
let s2 = std::ffi::CStr::from_ptr(s2)
.to_string_lossy()
.to_lowercase();
if s1 == s2 {
0
} else {
1
}
}
pub(crate) unsafe fn strncasecmp(
s1: *const libc::c_char,
s2: *const libc::c_char,
n: libc::size_t,
) -> libc::c_int {
let s1 = std::ffi::CStr::from_ptr(s1)
.to_string_lossy()
.to_lowercase();
let s2 = std::ffi::CStr::from_ptr(s2)
.to_string_lossy()
.to_lowercase();
let m1 = std::cmp::min(n, s1.len());
let m2 = std::cmp::min(n, s2.len());
if s1[..m1] == s2[..m2] {
0
} else {
1
}
}
#[cfg(test)]
mod tests {
use super::*;

File diff suppressed because it is too large Load Diff