From e65284ff9d1bb7f5930408c8cd06d9048038d61d Mon Sep 17 00:00:00 2001 From: Lars-Magnus Skog Date: Fri, 3 May 2019 12:47:24 +0200 Subject: [PATCH 1/2] refactor: remove poke_public_key() and dc_key_set_from_file() :fire: --- examples/repl/cmdline.rs | 63 ------------------------------ src/dc_key.rs | 82 ---------------------------------------- 2 files changed, 145 deletions(-) diff --git a/examples/repl/cmdline.rs b/examples/repl/cmdline.rs index 9622b0e6a..8ba42e5af 100644 --- a/examples/repl/cmdline.rs +++ b/examples/repl/cmdline.rs @@ -198,47 +198,6 @@ unsafe extern "C" fn dc_poke_eml_file( free(data as *mut libc::c_void); return success; } -unsafe extern "C" fn poke_public_key( - mut context: &dc_context_t, - mut addr: *const libc::c_char, - mut public_key_file: *const libc::c_char, -) -> libc::c_int { - /* mainly for testing: if the partner does not support Autocrypt, - encryption is disabled as soon as the first messages comes from the partner */ - let mut header: *mut dc_aheader_t = dc_aheader_new(); - let mut peerstate: *mut dc_apeerstate_t = dc_apeerstate_new(context); - let mut success: libc::c_int = 0i32; - if !(addr.is_null() || public_key_file.is_null() || peerstate.is_null() || header.is_null()) { - (*header).addr = dc_strdup(addr); - (*header).prefer_encrypt = 1i32; - if 0 == dc_key_set_from_file((*header).public_key, public_key_file, context) - || 0 == dc_pgp_is_valid_key(context, (*header).public_key) - { - dc_log_warning( - context, - 0i32, - b"No valid key found in \"%s\".\x00" as *const u8 as *const libc::c_char, - public_key_file, - ); - } else { - if 0 != dc_apeerstate_load_by_addr( - peerstate, - &context.sql.clone().read().unwrap(), - addr, - ) { - dc_apeerstate_apply_header(peerstate, header, time(0 as *mut time_t)); - dc_apeerstate_save_to_db(peerstate, &context.sql.clone().read().unwrap(), 0i32); - } else { - dc_apeerstate_init_from_header(peerstate, header, time(0 as *mut time_t)); - dc_apeerstate_save_to_db(peerstate, &context.sql.clone().read().unwrap(), 1i32); - } - success = 1i32 - } - } - dc_apeerstate_unref(peerstate); - dc_aheader_unref(header); - return success; -} /* * * Import a file to the database. * For testing, import a folder with eml-files, a single eml-file, e-mail plus public key and so on. @@ -307,28 +266,6 @@ unsafe extern "C" fn poke_spec( read_cnt += 1 } current_block = 1622411330066726685; - } else if !suffix.is_null() - && (strcmp(suffix, b"pem\x00" as *const u8 as *const libc::c_char) == 0i32 - || strcmp(suffix, b"asc\x00" as *const u8 as *const libc::c_char) == 0i32) - { - /* import a publix key */ - let mut separator: *mut libc::c_char = strchr(real_spec, ' ' as i32); - if separator.is_null() { - dc_log_error( - context, - 0i32, - b"Import: Key files must be specified as \" \".\x00" - as *const u8 as *const libc::c_char, - ); - current_block = 8522321847195001863; - } else { - *separator = 0i32 as libc::c_char; - if 0 != poke_public_key(context, real_spec, separator.offset(1isize)) { - read_cnt += 1 - } - *separator = ' ' as i32 as libc::c_char; - current_block = 1622411330066726685; - } } else { /* import a directory */ dir = opendir(real_spec); diff --git a/src/dc_key.rs b/src/dc_key.rs index a3ba5f3df..37e7412a2 100644 --- a/src/dc_key.rs +++ b/src/dc_key.rs @@ -146,88 +146,6 @@ pub unsafe fn dc_key_set_from_base64( 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: &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; -} 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() From 227a61e16f1ce1afe2c19f3d141cf6e22571094b Mon Sep 17 00:00:00 2001 From: Lars-Magnus Skog Date: Fri, 3 May 2019 13:02:14 +0200 Subject: [PATCH 2/2] refactor: remove dc_cleanup_contacts() :fire: --- examples/repl/cmdline.rs | 31 ------------------------------- 1 file changed, 31 deletions(-) diff --git a/examples/repl/cmdline.rs b/examples/repl/cmdline.rs index 8ba42e5af..677dee0f7 100644 --- a/examples/repl/cmdline.rs +++ b/examples/repl/cmdline.rs @@ -149,27 +149,6 @@ pub unsafe extern "C" fn dc_reset_tables( ); return 1i32; } -/* - * Clean up the contacts table. This function is called from Core cmdline. - * - * All contacts not involved in a chat, not blocked and not being a deaddrop - * are removed. - * - * Deleted contacts from the OS address book normally stay in the contacts - * database. With this cleanup, they are also removed, as well as all - * auto-added contacts, unless they are used in a chat or for blocking purpose. - */ -unsafe extern "C" fn dc_cleanup_contacts(mut context: &dc_context_t) -> libc::c_int { - dc_log_info( - context, - 0i32, - b"Cleaning up contacts ...\x00" as *const u8 as *const libc::c_char, - ); - dc_sqlite3_execute(context, &context.sql.clone().read().unwrap(), - b"DELETE FROM contacts WHERE id>9 AND blocked=0 AND NOT EXISTS (SELECT contact_id FROM chats_contacts where contacts.id = chats_contacts.contact_id) AND NOT EXISTS (select from_id from msgs WHERE msgs.from_id = contacts.id);\x00" - as *const u8 as *const libc::c_char); - return 1i32; -} unsafe extern "C" fn dc_poke_eml_file( mut context: &dc_context_t, mut filename: *const libc::c_char, @@ -1621,16 +1600,6 @@ pub unsafe extern "C" fn dc_cmdline( b"ERROR: Argument missing.\x00" as *const u8 as *const libc::c_char, ) } - } else if strcmp( - cmd, - b"cleanupcontacts\x00" as *const u8 as *const libc::c_char, - ) == 0i32 - { - ret = if 0 != dc_cleanup_contacts(&context) { - 2i32 as *mut libc::c_char - } else { - 1i32 as *mut libc::c_char - } } else if strcmp(cmd, b"getqr\x00" as *const u8 as *const libc::c_char) == 0i32 { ret = dc_get_securejoin_qr( &context,