mirror of
https://github.com/chatmail/core.git
synced 2026-05-20 07:16:31 +03:00
fix python data2/string handling and reduce extra code needed
This commit is contained in:
@@ -4202,8 +4202,8 @@ int64_t dc_lot_get_timestamp (const dc_lot_t* lot);
|
|||||||
#define DC_ERROR_SEE_STRING 0 // not used anymore
|
#define DC_ERROR_SEE_STRING 0 // not used anymore
|
||||||
#define DC_ERROR_SELF_NOT_IN_GROUP 1 // not used anymore
|
#define DC_ERROR_SELF_NOT_IN_GROUP 1 // not used anymore
|
||||||
#define DC_STR_SELFNOTINGRP 21 // not used anymore
|
#define DC_STR_SELFNOTINGRP 21 // not used anymore
|
||||||
#define DC_EVENT_DATA1_IS_STRING(e) ((e)==DC_EVENT_IMEX_FILE_WRITTEN || (e)==DC_EVENT_FILE_COPIED)
|
#define DC_EVENT_DATA1_IS_STRING(e) 0 // not used anymore
|
||||||
#define DC_EVENT_DATA2_IS_STRING(e) ((e)>=100 && (e)<=499)
|
#define DC_EVENT_DATA2_IS_STRING(e) ((e)==DC_EVENT_IMEX_FILE_WRITTEN || ((e)>=100 && (e)<=499))
|
||||||
#define DC_EVENT_RETURNS_INT(e) ((e)==DC_EVENT_IS_OFFLINE) // not used anymore
|
#define DC_EVENT_RETURNS_INT(e) ((e)==DC_EVENT_IS_OFFLINE) // not used anymore
|
||||||
#define DC_EVENT_RETURNS_STRING(e) ((e)==DC_EVENT_GET_STRING) // not used anymore
|
#define DC_EVENT_RETURNS_STRING(e) ((e)==DC_EVENT_GET_STRING) // not used anymore
|
||||||
#define dc_archive_chat(a,b,c) dc_set_chat_visibility((a), (b), (c)? 1 : 0) // not used anymore
|
#define dc_archive_chat(a,b,c) dc_set_chat_visibility((a), (b), (c)? 1 : 0) // not used anymore
|
||||||
|
|||||||
@@ -643,8 +643,8 @@ pub unsafe extern "C" fn dc_event_get_data3_str(event: *mut dc_event_t) -> *mut
|
|||||||
| Event::SecurejoinInviterProgress { .. }
|
| Event::SecurejoinInviterProgress { .. }
|
||||||
| Event::SecurejoinJoinerProgress { .. } => ptr::null_mut(),
|
| Event::SecurejoinJoinerProgress { .. } => ptr::null_mut(),
|
||||||
Event::ImexFileWritten(file) => {
|
Event::ImexFileWritten(file) => {
|
||||||
let data1 = file.to_c_string().unwrap_or_default();
|
let data2 = file.to_c_string().unwrap_or_default();
|
||||||
data1.into_raw()
|
data2.into_raw()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ if __name__ == "__main__":
|
|||||||
cmd = ["cargo", "build", "-p", "deltachat_ffi"]
|
cmd = ["cargo", "build", "-p", "deltachat_ffi"]
|
||||||
if target == 'release':
|
if target == 'release':
|
||||||
cmd.append("--release")
|
cmd.append("--release")
|
||||||
|
print("running:", " ".join(cmd))
|
||||||
subprocess.check_call(cmd)
|
subprocess.check_call(cmd)
|
||||||
subprocess.check_call("rm -rf build/ src/deltachat/*.so" , shell=True)
|
subprocess.check_call("rm -rf build/ src/deltachat/*.so" , shell=True)
|
||||||
|
|
||||||
|
|||||||
@@ -45,22 +45,9 @@ def ffibuilder():
|
|||||||
'deltachat.capi',
|
'deltachat.capi',
|
||||||
"""
|
"""
|
||||||
#include <deltachat.h>
|
#include <deltachat.h>
|
||||||
const char * dupstring_helper(const char* string)
|
int dc_event_has_string_data(int e)
|
||||||
{
|
{
|
||||||
return strdup(string);
|
return DC_EVENT_DATA2_IS_STRING(e);
|
||||||
}
|
|
||||||
int dc_get_event_signature_types(int e)
|
|
||||||
{
|
|
||||||
int result = 0;
|
|
||||||
if (DC_EVENT_DATA1_IS_STRING(e))
|
|
||||||
result |= 1;
|
|
||||||
if (DC_EVENT_DATA2_IS_STRING(e))
|
|
||||||
result |= 2;
|
|
||||||
if (DC_EVENT_RETURNS_STRING(e))
|
|
||||||
result |= 4;
|
|
||||||
if (DC_EVENT_RETURNS_INT(e))
|
|
||||||
result |= 8;
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
""",
|
""",
|
||||||
include_dirs=incs,
|
include_dirs=incs,
|
||||||
@@ -71,8 +58,7 @@ def ffibuilder():
|
|||||||
builder.cdef("""
|
builder.cdef("""
|
||||||
typedef int... time_t;
|
typedef int... time_t;
|
||||||
void free(void *ptr);
|
void free(void *ptr);
|
||||||
extern const char * dupstring_helper(const char* string);
|
extern int dc_event_has_string_data(int);
|
||||||
extern int dc_get_event_signature_types(int);
|
|
||||||
""")
|
""")
|
||||||
distutils.log.set_verbosity(distutils.log.INFO)
|
distutils.log.set_verbosity(distutils.log.INFO)
|
||||||
cc = distutils.ccompiler.new_compiler(force=True)
|
cc = distutils.ccompiler.new_compiler(force=True)
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ from .hookspec import account_hookimpl
|
|||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
from .capi import ffi, lib
|
from .capi import ffi, lib
|
||||||
from .message import map_system_message
|
from .message import map_system_message
|
||||||
|
from .cutil import from_dc_charpointer
|
||||||
|
|
||||||
|
|
||||||
class FFIEvent:
|
class FFIEvent:
|
||||||
@@ -164,23 +165,14 @@ class EventThread(threading.Thread):
|
|||||||
if event == ffi.NULL:
|
if event == ffi.NULL:
|
||||||
break
|
break
|
||||||
evt = lib.dc_event_get_id(event)
|
evt = lib.dc_event_get_id(event)
|
||||||
data1 = lib.dc_event_get_data1(event)
|
data1 = lib.dc_event_get_data1_int(event)
|
||||||
data2 = lib.dc_event_get_data2(event)
|
|
||||||
# the following code relates to the deltachat/_build.py's helper
|
# the following code relates to the deltachat/_build.py's helper
|
||||||
# function which provides us signature info of an event call
|
# function which provides us signature info of an event call
|
||||||
evt_name = deltachat.get_dc_event_name(evt)
|
evt_name = deltachat.get_dc_event_name(evt)
|
||||||
event_sig_types = lib.dc_get_event_signature_types(evt)
|
if lib.dc_event_has_string_data(evt):
|
||||||
if data1 and event_sig_types & 1:
|
data2 = from_dc_charpointer(lib.dc_event_get_data3_str(event))
|
||||||
data1 = ffi.string(ffi.gc(ffi.cast('char*', data1), lib.dc_str_unref)).decode("utf8")
|
else:
|
||||||
if data2 and event_sig_types & 2:
|
data2 = lib.dc_event_get_data2_int(event)
|
||||||
data2 = ffi.string(ffi.gc(ffi.cast('char*', data2), lib.dc_str_unref)).decode("utf8")
|
|
||||||
try:
|
|
||||||
if isinstance(data2, bytes):
|
|
||||||
data2 = data2.decode("utf8")
|
|
||||||
except UnicodeDecodeError:
|
|
||||||
# XXX ignoring the decode error is not quite correct but for now
|
|
||||||
# i don't want to hunt down encoding problems in the c lib
|
|
||||||
pass
|
|
||||||
|
|
||||||
lib.dc_event_unref(event)
|
lib.dc_event_unref(event)
|
||||||
ffi_event = FFIEvent(name=evt_name, data1=data1, data2=data2)
|
ffi_event = FFIEvent(name=evt_name, data1=data1, data2=data2)
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ class ImexTracker:
|
|||||||
if ffi_event.name == "DC_EVENT_IMEX_PROGRESS":
|
if ffi_event.name == "DC_EVENT_IMEX_PROGRESS":
|
||||||
self._imex_events.put(ffi_event.data1)
|
self._imex_events.put(ffi_event.data1)
|
||||||
elif ffi_event.name == "DC_EVENT_IMEX_FILE_WRITTEN":
|
elif ffi_event.name == "DC_EVENT_IMEX_FILE_WRITTEN":
|
||||||
self._imex_events.put(ffi_event.data1)
|
self._imex_events.put(ffi_event.data2)
|
||||||
|
|
||||||
def wait_finish(self, progress_timeout=60):
|
def wait_finish(self, progress_timeout=60):
|
||||||
""" Return list of written files, raise ValueError if ExportFailed. """
|
""" Return list of written files, raise ValueError if ExportFailed. """
|
||||||
|
|||||||
@@ -58,13 +58,15 @@ def test_event_defines():
|
|||||||
|
|
||||||
|
|
||||||
def test_sig():
|
def test_sig():
|
||||||
sig = capi.lib.dc_get_event_signature_types
|
sig = capi.lib.dc_event_has_string_data
|
||||||
assert sig(const.DC_EVENT_INFO) == 2
|
assert not sig(const.DC_EVENT_MSGS_CHANGED)
|
||||||
assert sig(const.DC_EVENT_WARNING) == 2
|
assert sig(const.DC_EVENT_INFO)
|
||||||
assert sig(const.DC_EVENT_ERROR) == 2
|
assert sig(const.DC_EVENT_WARNING)
|
||||||
assert sig(const.DC_EVENT_SMTP_CONNECTED) == 2
|
assert sig(const.DC_EVENT_ERROR)
|
||||||
assert sig(const.DC_EVENT_IMAP_CONNECTED) == 2
|
assert sig(const.DC_EVENT_SMTP_CONNECTED)
|
||||||
assert sig(const.DC_EVENT_SMTP_MESSAGE_SENT) == 2
|
assert sig(const.DC_EVENT_IMAP_CONNECTED)
|
||||||
|
assert sig(const.DC_EVENT_SMTP_MESSAGE_SENT)
|
||||||
|
assert sig(const.DC_EVENT_IMEX_FILE_WRITTEN)
|
||||||
|
|
||||||
|
|
||||||
def test_markseen_invalid_message_ids(acfactory):
|
def test_markseen_invalid_message_ids(acfactory):
|
||||||
|
|||||||
Reference in New Issue
Block a user