mirror of
https://github.com/chatmail/core.git
synced 2026-04-25 01:16:29 +03:00
Return Vec instead of carray from dc_split_into_lines
This commit is contained in:
@@ -455,38 +455,29 @@ pub fn dc_add_or_lookup_contact(
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
pub unsafe fn dc_add_address_book(context: &Context, adr_book: *const libc::c_char) -> libc::c_int {
|
||||
let mut lines: *mut carray = 0 as *mut carray;
|
||||
let mut i: size_t;
|
||||
let iCnt: size_t;
|
||||
let mut sth_modified: libc::c_int = 0i32;
|
||||
let mut modify_cnt: libc::c_int = 0i32;
|
||||
if !(adr_book.is_null()) {
|
||||
lines = dc_split_into_lines(adr_book);
|
||||
if !lines.is_null() {
|
||||
iCnt = carray_count(lines) as size_t;
|
||||
i = 0i32 as size_t;
|
||||
while i.wrapping_add(1) < iCnt {
|
||||
let name: *mut libc::c_char =
|
||||
carray_get(lines, i as libc::c_uint) as *mut libc::c_char;
|
||||
let addr: *mut libc::c_char =
|
||||
carray_get(lines, i.wrapping_add(1) as libc::c_uint) as *mut libc::c_char;
|
||||
dc_normalize_name(name);
|
||||
dc_add_or_lookup_contact(context, name, addr, 0x80000i32, &mut sth_modified);
|
||||
if 0 != sth_modified {
|
||||
modify_cnt += 1
|
||||
}
|
||||
i = (i as libc::c_ulong).wrapping_add(2i32 as libc::c_ulong) as size_t as size_t
|
||||
}
|
||||
if 0 != modify_cnt {
|
||||
context.call_cb(
|
||||
Event::CONTACTS_CHANGED,
|
||||
0i32 as uintptr_t,
|
||||
0i32 as uintptr_t,
|
||||
);
|
||||
let lines = dc_split_into_lines(adr_book);
|
||||
|
||||
for chunk in lines.chunks(2) {
|
||||
let name: *mut libc::c_char = chunk[0];
|
||||
let addr: *mut libc::c_char = chunk[1];
|
||||
dc_normalize_name(name);
|
||||
dc_add_or_lookup_contact(context, name, addr, 0x80000i32, &mut sth_modified);
|
||||
if 0 != sth_modified {
|
||||
modify_cnt += 1
|
||||
}
|
||||
}
|
||||
if 0 != modify_cnt {
|
||||
context.call_cb(
|
||||
Event::CONTACTS_CHANGED,
|
||||
0i32 as uintptr_t,
|
||||
0i32 as uintptr_t,
|
||||
);
|
||||
}
|
||||
dc_free_splitted_lines(lines);
|
||||
}
|
||||
dc_free_splitted_lines(lines);
|
||||
|
||||
modify_cnt
|
||||
}
|
||||
|
||||
@@ -152,11 +152,8 @@ pub unsafe fn dc_check_qr(context: &Context, qr: *const libc::c_char) -> *mut dc
|
||||
strlen(b"BEGIN:VCARD\x00" as *const u8 as *const libc::c_char),
|
||||
) == 0i32
|
||||
{
|
||||
let lines: *mut carray = dc_split_into_lines(qr);
|
||||
let mut i: libc::c_int = 0i32;
|
||||
while (i as libc::c_uint) < carray_count(lines) {
|
||||
let key: *mut libc::c_char =
|
||||
carray_get(lines, i as libc::c_uint) as *mut libc::c_char;
|
||||
let lines = dc_split_into_lines(qr);
|
||||
for &key in &lines {
|
||||
dc_trim(key);
|
||||
let mut value: *mut libc::c_char = strchr(key, ':' as i32);
|
||||
if !value.is_null() {
|
||||
@@ -192,7 +189,6 @@ pub unsafe fn dc_check_qr(context: &Context, qr: *const libc::c_char) -> *mut dc
|
||||
dc_normalize_name(name);
|
||||
}
|
||||
}
|
||||
i += 1
|
||||
}
|
||||
dc_free_splitted_lines(lines);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
use crate::dc_dehtml::*;
|
||||
use crate::dc_tools::*;
|
||||
use crate::types::*;
|
||||
use crate::x::*;
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
@@ -76,17 +75,13 @@ impl dc_simplify_t {
|
||||
these are all lines starting with the character `>`
|
||||
... 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 lines: *mut carray = dc_split_into_lines(buf_terminated);
|
||||
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 lines = dc_split_into_lines(buf_terminated);
|
||||
let mut l_first: usize = 0;
|
||||
let mut l_last = lines.len();
|
||||
let mut line: *mut libc::c_char;
|
||||
let mut footer_mark: libc::c_int = 0i32;
|
||||
l = l_first;
|
||||
while l <= l_last {
|
||||
line = carray_get(lines, l as libc::c_uint) as *mut libc::c_char;
|
||||
for l in l_first..l_last {
|
||||
line = lines[l];
|
||||
if strcmp(line, b"-- \x00" as *const u8 as *const libc::c_char) == 0i32
|
||||
|| strcmp(line, b"-- \x00" as *const u8 as *const libc::c_char) == 0i32
|
||||
{
|
||||
@@ -100,20 +95,15 @@ impl dc_simplify_t {
|
||||
self.is_cut_at_end = 1i32
|
||||
}
|
||||
if 0 != footer_mark {
|
||||
l_last = l - 1i32;
|
||||
l_last = l;
|
||||
/* done */
|
||||
break;
|
||||
} else {
|
||||
l += 1
|
||||
}
|
||||
}
|
||||
if l_last - l_first + 1i32 >= 3i32 {
|
||||
let line0: *mut libc::c_char =
|
||||
carray_get(lines, l_first as libc::c_uint) as *mut libc::c_char;
|
||||
let line1: *mut libc::c_char =
|
||||
carray_get(lines, (l_first + 1i32) as libc::c_uint) as *mut libc::c_char;
|
||||
let line2: *mut libc::c_char =
|
||||
carray_get(lines, (l_first + 2i32) as libc::c_uint) as *mut libc::c_char;
|
||||
if l_last > l_first + 2 {
|
||||
let line0: *mut libc::c_char = lines[l_first];
|
||||
let line1: *mut libc::c_char = lines[l_first + 1];
|
||||
let line2: *mut libc::c_char = lines[l_first + 2];
|
||||
if strcmp(
|
||||
line0,
|
||||
b"---------- Forwarded message ----------\x00" as *const u8 as *const libc::c_char,
|
||||
@@ -122,49 +112,43 @@ impl dc_simplify_t {
|
||||
&& *line2.offset(0isize) as libc::c_int == 0i32
|
||||
{
|
||||
self.is_forwarded = 1i32;
|
||||
l_first += 3i32
|
||||
l_first += 3
|
||||
}
|
||||
}
|
||||
l = l_first;
|
||||
while l <= l_last {
|
||||
line = carray_get(lines, l as libc::c_uint) as *mut libc::c_char;
|
||||
for l in l_first..l_last {
|
||||
line = lines[l];
|
||||
if strncmp(line, b"-----\x00" as *const u8 as *const libc::c_char, 5) == 0i32
|
||||
|| strncmp(line, b"_____\x00" as *const u8 as *const libc::c_char, 5) == 0i32
|
||||
|| strncmp(line, b"=====\x00" as *const u8 as *const libc::c_char, 5) == 0i32
|
||||
|| strncmp(line, b"*****\x00" as *const u8 as *const libc::c_char, 5) == 0i32
|
||||
|| strncmp(line, b"~~~~~\x00" as *const u8 as *const libc::c_char, 5) == 0i32
|
||||
{
|
||||
l_last = l - 1i32;
|
||||
l_last = l;
|
||||
self.is_cut_at_end = 1i32;
|
||||
/* done */
|
||||
break;
|
||||
} else {
|
||||
l += 1
|
||||
}
|
||||
}
|
||||
if 0 == is_msgrmsg {
|
||||
let mut l_lastQuotedLine: libc::c_int = -1i32;
|
||||
l = l_last;
|
||||
while l >= l_first {
|
||||
line = carray_get(lines, l as libc::c_uint) as *mut libc::c_char;
|
||||
let mut l_lastQuotedLine = None;
|
||||
for l in (l_first..l_last).rev() {
|
||||
line = lines[l];
|
||||
if is_plain_quote(line) {
|
||||
l_lastQuotedLine = l
|
||||
l_lastQuotedLine = Some(l)
|
||||
} else if !is_empty_line(line) {
|
||||
break;
|
||||
}
|
||||
l -= 1
|
||||
}
|
||||
if l_lastQuotedLine != -1i32 {
|
||||
l_last = l_lastQuotedLine - 1i32;
|
||||
if l_lastQuotedLine.is_some() {
|
||||
l_last = l_lastQuotedLine.unwrap();
|
||||
self.is_cut_at_end = 1i32;
|
||||
if l_last > 0i32 {
|
||||
if is_empty_line(carray_get(lines, l_last as libc::c_uint) as *mut libc::c_char)
|
||||
{
|
||||
if l_last > 1 {
|
||||
if is_empty_line(lines[l_last - 1]) {
|
||||
l_last -= 1
|
||||
}
|
||||
}
|
||||
if l_last > 0i32 {
|
||||
line = carray_get(lines, l_last as libc::c_uint) as *mut libc::c_char;
|
||||
if l_last > 1 {
|
||||
line = lines[l_last - 1];
|
||||
if is_quoted_headline(line) {
|
||||
l_last -= 1
|
||||
}
|
||||
@@ -172,17 +156,16 @@ impl dc_simplify_t {
|
||||
}
|
||||
}
|
||||
if 0 == is_msgrmsg {
|
||||
let mut l_lastQuotedLine_0: libc::c_int = -1i32;
|
||||
let mut hasQuotedHeadline: libc::c_int = 0i32;
|
||||
l = l_first;
|
||||
while l <= l_last {
|
||||
line = carray_get(lines, l as libc::c_uint) as *mut libc::c_char;
|
||||
let mut l_lastQuotedLine_0 = None;
|
||||
let mut hasQuotedHeadline = 0;
|
||||
for l in l_first..l_last {
|
||||
line = lines[l];
|
||||
if is_plain_quote(line) {
|
||||
l_lastQuotedLine_0 = l
|
||||
l_lastQuotedLine_0 = Some(l)
|
||||
} else if !is_empty_line(line) {
|
||||
if is_quoted_headline(line)
|
||||
&& 0 == hasQuotedHeadline
|
||||
&& l_lastQuotedLine_0 == -1i32
|
||||
&& l_lastQuotedLine_0.is_none()
|
||||
{
|
||||
hasQuotedHeadline = 1i32
|
||||
} else {
|
||||
@@ -190,10 +173,9 @@ impl dc_simplify_t {
|
||||
break;
|
||||
}
|
||||
}
|
||||
l += 1
|
||||
}
|
||||
if l_lastQuotedLine_0 != -1i32 {
|
||||
l_first = l_lastQuotedLine_0 + 1i32;
|
||||
if l_lastQuotedLine_0.is_some() {
|
||||
l_first = l_lastQuotedLine_0.unwrap() + 1;
|
||||
self.is_cut_at_begin = 1i32
|
||||
}
|
||||
}
|
||||
@@ -205,9 +187,8 @@ impl dc_simplify_t {
|
||||
/* we write empty lines only in case and non-empty line follows */
|
||||
let mut pending_linebreaks: libc::c_int = 0i32;
|
||||
let mut content_lines_added: libc::c_int = 0i32;
|
||||
l = l_first;
|
||||
while l <= l_last {
|
||||
line = carray_get(lines, l as libc::c_uint) as *mut libc::c_char;
|
||||
for l in l_first..l_last {
|
||||
line = lines[l];
|
||||
if is_empty_line(line) {
|
||||
pending_linebreaks += 1
|
||||
} else {
|
||||
@@ -225,7 +206,6 @@ impl dc_simplify_t {
|
||||
content_lines_added += 1;
|
||||
pending_linebreaks = 1i32
|
||||
}
|
||||
l += 1
|
||||
}
|
||||
if 0 != self.is_cut_at_end && (0 == self.is_cut_at_begin || 0 != content_lines_added) {
|
||||
ret += " [...]";
|
||||
|
||||
@@ -417,47 +417,30 @@ unsafe fn dc_utf8_strnlen(s: *const libc::c_char, n: size_t) -> size_t {
|
||||
}
|
||||
|
||||
/* split string into lines*/
|
||||
pub unsafe fn dc_split_into_lines(buf_terminated: *const libc::c_char) -> *mut carray {
|
||||
let lines: *mut carray = carray_new(1024i32 as libc::c_uint);
|
||||
pub unsafe fn dc_split_into_lines(buf_terminated: *const libc::c_char) -> Vec<*mut libc::c_char> {
|
||||
let mut lines = Vec::new();
|
||||
let mut line_chars = 0;
|
||||
let mut p1: *const libc::c_char = buf_terminated;
|
||||
let mut line_start: *const libc::c_char = p1;
|
||||
let mut l_indx: libc::c_uint = 0i32 as libc::c_uint;
|
||||
while 0 != *p1 {
|
||||
if *p1 as libc::c_int == '\n' as i32 {
|
||||
carray_add(
|
||||
lines,
|
||||
strndup(line_start, line_chars) as *mut libc::c_void,
|
||||
&mut l_indx,
|
||||
);
|
||||
lines.push(strndup(line_start, line_chars));
|
||||
p1 = p1.offset(1isize);
|
||||
line_start = p1;
|
||||
line_chars = 0;
|
||||
} else {
|
||||
p1 = p1.offset(1isize);
|
||||
line_chars = line_chars.wrapping_add(1)
|
||||
line_chars += 1;
|
||||
}
|
||||
}
|
||||
carray_add(
|
||||
lines,
|
||||
strndup(line_start, line_chars) as *mut libc::c_void,
|
||||
&mut l_indx,
|
||||
);
|
||||
|
||||
lines.push(strndup(line_start, line_chars));
|
||||
lines
|
||||
}
|
||||
|
||||
pub unsafe fn dc_free_splitted_lines(lines: *mut carray) {
|
||||
if !lines.is_null() {
|
||||
let mut i: libc::c_int;
|
||||
let cnt: libc::c_int = carray_count(lines) as libc::c_int;
|
||||
i = 0i32;
|
||||
while i < cnt {
|
||||
free(carray_get(lines, i as libc::c_uint));
|
||||
i += 1
|
||||
}
|
||||
carray_free(lines);
|
||||
};
|
||||
pub unsafe fn dc_free_splitted_lines(lines: Vec<*mut libc::c_char>) {
|
||||
for s in lines {
|
||||
free(s as *mut libc::c_void);
|
||||
}
|
||||
}
|
||||
|
||||
/* insert a break every n characters, the return must be free()'d */
|
||||
|
||||
Reference in New Issue
Block a user