diff --git a/deltachat-ffi/src/lib.rs b/deltachat-ffi/src/lib.rs index d91a2ea24..31073af17 100644 --- a/deltachat-ffi/src/lib.rs +++ b/deltachat-ffi/src/lib.rs @@ -1035,13 +1035,14 @@ pub unsafe extern "C" fn dc_get_locations( assert!(!context.is_null()); let context = &*context; - dc_location::dc_get_locations( + let res = dc_location::dc_get_locations( context, chat_id, contact_id, timestamp_begin as i64, timestamp_end as i64, - ) + ); + dc_array_t::from(res).into_raw() } #[no_mangle] diff --git a/examples/repl/cmdline.rs b/examples/repl/cmdline.rs index 0aca18d74..7939881f9 100644 --- a/examples/repl/cmdline.rs +++ b/examples/repl/cmdline.rs @@ -839,36 +839,28 @@ pub unsafe fn dc_cmdline(context: &Context, line: &str) -> Result<(), failure::E } "getlocations" => { let contact_id = arg1.parse().unwrap_or_default(); - let loc = dc_get_locations(context, dc_chat_get_id(sel_chat), contact_id, 0, 0); - let mut j = 0; - while j < dc_array_get_cnt(loc) { - let timestr_0 = dc_timestamp_to_str(dc_array_get_timestamp(loc, j as size_t)); - let marker = dc_array_get_marker(loc, j as size_t); + let locations = dc_get_locations(context, dc_chat_get_id(sel_chat), contact_id, 0, 0); + let default_marker = "-".to_string(); + for location in &locations { + let marker = location.marker.as_ref().unwrap_or(&default_marker); info!( context, 0, "Loc#{}: {}: lat={} lng={} acc={} Chat#{} Contact#{} Msg#{} {}", - dc_array_get_id(loc, j as size_t), - ×tr_0, - dc_array_get_latitude(loc, j as size_t), - dc_array_get_longitude(loc, j as size_t), - dc_array_get_accuracy(loc, j as size_t), - dc_array_get_chat_id(loc, j as size_t), - dc_array_get_contact_id(loc, j as size_t), - dc_array_get_msg_id(loc, j as size_t), - if !marker.is_null() { - as_str(marker) - } else { - "-" - }, + location.location_id, + dc_timestamp_to_str(location.timestamp), + location.latitude, + location.longitude, + location.accuracy, + location.chat_id, + location.contact_id, + location.msg_id, + marker ); - free(marker as *mut libc::c_void); - j += 1 } - if dc_array_get_cnt(loc) == 0 { + if locations.is_empty() { info!(context, 0, "No locations."); } - dc_array_unref(loc); } "sendlocations" => { ensure!(!sel_chat.is_null(), "No chat selected."); diff --git a/src/dc_location.rs b/src/dc_location.rs index fa5f6cc0a..581ba6301 100644 --- a/src/dc_location.rs +++ b/src/dc_location.rs @@ -3,7 +3,6 @@ use std::ffi::CString; use crate::constants::Event; use crate::constants::*; use crate::context::*; -use crate::dc_array::*; use crate::dc_chat::*; use crate::dc_job::*; use crate::dc_msg::*; @@ -201,7 +200,7 @@ pub fn dc_get_locations( contact_id: uint32_t, timestamp_from: i64, mut timestamp_to: i64, -) -> *mut dc_array_t { +) -> Vec { if timestamp_to == 0 { timestamp_to = time() + 10; } @@ -252,10 +251,10 @@ pub fn dc_get_locations( for location in locations { ret.push(location?); } - Ok(dc_array_t::from(ret).into_raw()) + Ok(ret) }, ) - .unwrap_or_else(|_| std::ptr::null_mut()) + .unwrap_or_default() } fn is_marker(txt: &str) -> bool {