mirror of
https://github.com/chatmail/core.git
synced 2026-04-20 15:06:30 +03:00
cleanup: dc_aheader
This commit is contained in:
@@ -7,10 +7,7 @@ use crate::dc_tools::*;
|
|||||||
use crate::types::*;
|
use crate::types::*;
|
||||||
use crate::x::*;
|
use crate::x::*;
|
||||||
|
|
||||||
/* *
|
/// Parse and create [Autocrypt-headers](https://autocrypt.org/en/latest/level1.html#the-autocrypt-header).
|
||||||
* @class dc_aheader_t
|
|
||||||
* Library-internal. Parse and create [Autocrypt-headers](https://autocrypt.org/en/latest/level1.html#the-autocrypt-header).
|
|
||||||
*/
|
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub struct dc_aheader_t {
|
pub struct dc_aheader_t {
|
||||||
@@ -19,38 +16,43 @@ pub struct dc_aheader_t {
|
|||||||
pub prefer_encrypt: libc::c_int,
|
pub prefer_encrypt: libc::c_int,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* the returned pointer is ref'd and must be unref'd after usage */
|
/// the returned pointer is ref'd and must be unref'd after usage
|
||||||
pub unsafe fn dc_aheader_new() -> *mut dc_aheader_t {
|
pub unsafe fn dc_aheader_new() -> *mut dc_aheader_t {
|
||||||
let mut aheader: *mut dc_aheader_t = 0 as *mut dc_aheader_t;
|
let mut aheader = calloc(
|
||||||
aheader = calloc(
|
|
||||||
1i32 as libc::c_ulong,
|
1i32 as libc::c_ulong,
|
||||||
::std::mem::size_of::<dc_aheader_t>() as libc::c_ulong,
|
::std::mem::size_of::<dc_aheader_t>() as libc::c_ulong,
|
||||||
) as *mut dc_aheader_t;
|
) as *mut dc_aheader_t;
|
||||||
|
|
||||||
if aheader.is_null() {
|
if aheader.is_null() {
|
||||||
exit(37i32);
|
exit(37i32);
|
||||||
}
|
}
|
||||||
|
|
||||||
(*aheader).public_key = dc_key_new();
|
(*aheader).public_key = dc_key_new();
|
||||||
return aheader;
|
|
||||||
|
aheader
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn dc_aheader_new_from_imffields(
|
pub unsafe fn dc_aheader_new_from_imffields(
|
||||||
mut wanted_from: *const libc::c_char,
|
mut wanted_from: *const libc::c_char,
|
||||||
mut header: *const mailimf_fields,
|
mut header: *const mailimf_fields,
|
||||||
) -> *mut dc_aheader_t {
|
) -> *mut dc_aheader_t {
|
||||||
let mut cur: *mut clistiter = 0 as *mut clistiter;
|
let mut cur = 0 as *mut clistiter;
|
||||||
let mut fine_header: *mut dc_aheader_t = 0 as *mut dc_aheader_t;
|
let mut fine_header = 0 as *mut dc_aheader_t;
|
||||||
|
|
||||||
if wanted_from.is_null() || header.is_null() {
|
if wanted_from.is_null() || header.is_null() {
|
||||||
return 0 as *mut dc_aheader_t;
|
return 0 as *mut dc_aheader_t;
|
||||||
}
|
}
|
||||||
|
|
||||||
cur = (*(*header).fld_list).first;
|
cur = (*(*header).fld_list).first;
|
||||||
while !cur.is_null() {
|
while !cur.is_null() {
|
||||||
let mut field: *mut mailimf_field = (if !cur.is_null() {
|
let mut field = (if !cur.is_null() {
|
||||||
(*cur).data
|
(*cur).data
|
||||||
} else {
|
} else {
|
||||||
0 as *mut libc::c_void
|
0 as *mut libc::c_void
|
||||||
}) as *mut mailimf_field;
|
}) as *mut mailimf_field;
|
||||||
|
|
||||||
if !field.is_null() && (*field).fld_type == MAILIMF_FIELD_OPTIONAL_FIELD as libc::c_int {
|
if !field.is_null() && (*field).fld_type == MAILIMF_FIELD_OPTIONAL_FIELD as libc::c_int {
|
||||||
let mut optional_field: *mut mailimf_optional_field =
|
let mut optional_field = (*field).fld_data.fld_optional_field;
|
||||||
(*field).fld_data.fld_optional_field;
|
|
||||||
if !optional_field.is_null()
|
if !optional_field.is_null()
|
||||||
&& !(*optional_field).fld_name.is_null()
|
&& !(*optional_field).fld_name.is_null()
|
||||||
&& strcasecmp(
|
&& strcasecmp(
|
||||||
@@ -58,7 +60,7 @@ pub unsafe fn dc_aheader_new_from_imffields(
|
|||||||
b"Autocrypt\x00" as *const u8 as *const libc::c_char,
|
b"Autocrypt\x00" as *const u8 as *const libc::c_char,
|
||||||
) == 0i32
|
) == 0i32
|
||||||
{
|
{
|
||||||
let mut test: *mut dc_aheader_t = dc_aheader_new();
|
let mut test = dc_aheader_new();
|
||||||
if 0 == dc_aheader_set_from_string(test, (*optional_field).fld_value)
|
if 0 == dc_aheader_set_from_string(test, (*optional_field).fld_value)
|
||||||
|| dc_addr_cmp((*test).addr, wanted_from) != 0i32
|
|| dc_addr_cmp((*test).addr, wanted_from) != 0i32
|
||||||
{
|
{
|
||||||
@@ -74,6 +76,7 @@ pub unsafe fn dc_aheader_new_from_imffields(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cur = if !cur.is_null() {
|
cur = if !cur.is_null() {
|
||||||
(*cur).next
|
(*cur).next
|
||||||
} else {
|
} else {
|
||||||
@@ -82,6 +85,7 @@ pub unsafe fn dc_aheader_new_from_imffields(
|
|||||||
}
|
}
|
||||||
return fine_header;
|
return fine_header;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn dc_aheader_unref(mut aheader: *mut dc_aheader_t) {
|
pub unsafe fn dc_aheader_unref(mut aheader: *mut dc_aheader_t) {
|
||||||
if aheader.is_null() {
|
if aheader.is_null() {
|
||||||
return;
|
return;
|
||||||
@@ -90,6 +94,7 @@ pub unsafe fn dc_aheader_unref(mut aheader: *mut dc_aheader_t) {
|
|||||||
dc_key_unref((*aheader).public_key);
|
dc_key_unref((*aheader).public_key);
|
||||||
free(aheader as *mut libc::c_void);
|
free(aheader as *mut libc::c_void);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn dc_aheader_set_from_string(
|
pub unsafe fn dc_aheader_set_from_string(
|
||||||
mut aheader: *mut dc_aheader_t,
|
mut aheader: *mut dc_aheader_t,
|
||||||
mut header_str__: *const libc::c_char,
|
mut header_str__: *const libc::c_char,
|
||||||
@@ -100,12 +105,13 @@ pub unsafe fn dc_aheader_set_from_string(
|
|||||||
(a) no key or value is expected to contain spaces,
|
(a) no key or value is expected to contain spaces,
|
||||||
(b) for the key, non-base64-characters are ignored and
|
(b) for the key, non-base64-characters are ignored and
|
||||||
(c) for parsing, we ignore `\r\n` as well as tabs for spaces */
|
(c) for parsing, we ignore `\r\n` as well as tabs for spaces */
|
||||||
let mut header_str: *mut libc::c_char = 0 as *mut libc::c_char;
|
let mut header_str = 0 as *mut libc::c_char;
|
||||||
let mut p: *mut libc::c_char = 0 as *mut libc::c_char;
|
let mut p = 0 as *mut libc::c_char;
|
||||||
let mut beg_attr_name: *mut libc::c_char = 0 as *mut libc::c_char;
|
let mut beg_attr_name = 0 as *mut libc::c_char;
|
||||||
let mut after_attr_name: *mut libc::c_char = 0 as *mut libc::c_char;
|
let mut after_attr_name = 0 as *mut libc::c_char;
|
||||||
let mut beg_attr_value: *mut libc::c_char = 0 as *mut libc::c_char;
|
let mut beg_attr_value = 0 as *mut libc::c_char;
|
||||||
let mut success: libc::c_int = 0i32;
|
let mut success: libc::c_int = 0i32;
|
||||||
|
|
||||||
dc_aheader_empty(aheader);
|
dc_aheader_empty(aheader);
|
||||||
if !(aheader.is_null() || header_str__.is_null()) {
|
if !(aheader.is_null() || header_str__.is_null()) {
|
||||||
(*aheader).prefer_encrypt = 0i32;
|
(*aheader).prefer_encrypt = 0i32;
|
||||||
@@ -161,8 +167,10 @@ pub unsafe fn dc_aheader_set_from_string(
|
|||||||
if 0 == success {
|
if 0 == success {
|
||||||
dc_aheader_empty(aheader);
|
dc_aheader_empty(aheader);
|
||||||
}
|
}
|
||||||
return success;
|
|
||||||
|
success
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn dc_aheader_empty(mut aheader: *mut dc_aheader_t) {
|
pub unsafe fn dc_aheader_empty(mut aheader: *mut dc_aheader_t) {
|
||||||
if aheader.is_null() {
|
if aheader.is_null() {
|
||||||
return;
|
return;
|
||||||
@@ -170,14 +178,17 @@ pub unsafe fn dc_aheader_empty(mut aheader: *mut dc_aheader_t) {
|
|||||||
(*aheader).prefer_encrypt = 0i32;
|
(*aheader).prefer_encrypt = 0i32;
|
||||||
free((*aheader).addr as *mut libc::c_void);
|
free((*aheader).addr as *mut libc::c_void);
|
||||||
(*aheader).addr = 0 as *mut libc::c_char;
|
(*aheader).addr = 0 as *mut libc::c_char;
|
||||||
|
|
||||||
if !(*(*aheader).public_key).binary.is_null() {
|
if !(*(*aheader).public_key).binary.is_null() {
|
||||||
dc_key_unref((*aheader).public_key);
|
dc_key_unref((*aheader).public_key);
|
||||||
(*aheader).public_key = dc_key_new()
|
(*aheader).public_key = dc_key_new()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ******************************************************************************
|
/* ******************************************************************************
|
||||||
* Parse Autocrypt Header
|
* Parse Autocrypt Header
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
unsafe fn add_attribute(
|
unsafe fn add_attribute(
|
||||||
mut aheader: *mut dc_aheader_t,
|
mut aheader: *mut dc_aheader_t,
|
||||||
mut name: *const libc::c_char,
|
mut name: *const libc::c_char,
|
||||||
@@ -220,6 +231,7 @@ unsafe fn add_attribute(
|
|||||||
}
|
}
|
||||||
return 0i32;
|
return 0i32;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn dc_aheader_render(mut aheader: *const dc_aheader_t) -> *mut libc::c_char {
|
pub unsafe fn dc_aheader_render(mut aheader: *const dc_aheader_t) -> *mut libc::c_char {
|
||||||
let mut success: libc::c_int = 0i32;
|
let mut success: libc::c_int = 0i32;
|
||||||
let mut keybase64_wrapped: *mut libc::c_char = 0 as *mut libc::c_char;
|
let mut keybase64_wrapped: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||||
@@ -262,10 +274,13 @@ pub unsafe fn dc_aheader_render(mut aheader: *const dc_aheader_t) -> *mut libc::
|
|||||||
success = 1i32
|
success = 1i32
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if 0 == success {
|
if 0 == success {
|
||||||
free(ret.buf as *mut libc::c_void);
|
free(ret.buf as *mut libc::c_void);
|
||||||
ret.buf = 0 as *mut libc::c_char
|
ret.buf = 0 as *mut libc::c_char
|
||||||
}
|
}
|
||||||
|
|
||||||
free(keybase64_wrapped as *mut libc::c_void);
|
free(keybase64_wrapped as *mut libc::c_void);
|
||||||
return ret.buf;
|
|
||||||
|
ret.buf
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user