1
0
Fork 0
mirror of https://github.com/deltachat/deltachat-core.git synced 2025-10-04 10:19:16 +02:00

emit and look for DC_EVENT_(SMTP|IMAP)_CONNECTED events which are INFO events so that we can also for other events convert the C-code easily (just use "dc_log_event" instead of "dc_log_info")

This commit is contained in:
holger krekel 2018-09-08 14:06:16 +02:00
parent 1c77187d5a
commit 3265178d31
9 changed files with 51 additions and 13 deletions

View file

@ -34,6 +34,7 @@ def acfactory(pytestconfig, tmpdir, request):
configdict = self.configlist.pop(0)
tmpdb = tmpdir.join("testdb%d" % self.count)
ac = Account(tmpdb.strpath)
ac._evlogger.set_timeout(10)
ac.set_config(**configdict)
if started:
ac.start()

2
python/setup.cfg Normal file
View file

@ -0,0 +1,2 @@
[devpi:upload]
formats = sdist.tgz,bdist_wheel

View file

@ -42,21 +42,26 @@ class EventLogger:
self._event_queue = Queue()
self._debug = debug
self._ctxinfo = str(self.dc_context).strip(">").split()[-1]
self._timeout = None
def __call__(self, evt_name, data1, data2):
self._log_event(evt_name, data1, data2)
self._event_queue.put((evt_name, data1, data2))
def set_timeout(self, timeout):
self._timeout = timeout
def get(self, timeout=None, check_error=True):
timeout = timeout or self._timeout
ev = self._event_queue.get(timeout=timeout)
if check_error:
assert ev[0] != "DC_EVENT_ERROR"
return ev
def get_matching(self, event_name_regex, timeout=None):
rex = re.compile(event_name_regex + ".*")
def get_matching(self, event_name_regex):
rex = re.compile("(?:{}).*".format(event_name_regex))
while 1:
ev = self.get(timeout=timeout)
ev = self.get()
if rex.match(ev[0]):
return ev

View file

@ -30,10 +30,10 @@ class TestLive:
imap_ok = smtp_ok = False
while not imap_ok or not smtp_ok:
evt_name, data1, data2 = \
ac1._evlogger.get_matching("DC_EVENT_INFO", timeout=5)
if re.match("imap-login.*ok.", data2.lower()):
ac1._evlogger.get_matching("DC_EVENT_(IMAP|SMTP)_CONNECTED")
if evt_name == "DC_EVENT_IMAP_CONNECTED":
imap_ok = True
if re.match("smtp-login.*ok.", data2.lower()):
if evt_name == "DC_EVENT_SMTP_CONNECTED":
smtp_ok = True
assert ac1.get_config("mail_pw")

View file

@ -122,6 +122,7 @@ void dc_log_error (dc_context_t*, int code, const char* msg,
void dc_log_error_if (int* condition, dc_context_t*, int code, const char* msg, ...);
void dc_log_warning (dc_context_t*, int code, const char* msg, ...);
void dc_log_info (dc_context_t*, int code, const char* msg, ...);
void dc_log_event (dc_context_t* context, int event_code, int code, const char* msg, ...);
void dc_receive_imf (dc_context_t*, const char* imf_raw_not_terminated, size_t imf_raw_bytes, const char* server_folder, uint32_t server_uid, uint32_t flags);
#define DC_BAK_PREFIX "delta-chat"

View file

@ -1153,7 +1153,8 @@ static int setup_handle_if_needed(dc_imap_t* imap)
goto cleanup;
}
dc_log_info(imap->context, 0, "IMAP-login as %s ok.", imap->imap_user);
dc_log_event(imap->context, DC_EVENT_IMAP_CONNECTED, 0,
"IMAP-login as %s ok.", imap->imap_user);
success = 1;

View file

@ -87,13 +87,18 @@ void dc_log_info(dc_context_t* context, int code, const char* msg, ...)
va_end(va);
}
void dc_log_event(dc_context_t* context, int event_code, int code, const char* msg, ...)
{
va_list va;
va_start(va, msg); /* va_start() expects the last non-variable argument as the second parameter */
log_vprintf(context, event_code, code, msg, va);
va_end(va);
}
void dc_log_warning(dc_context_t* context, int code, const char* msg, ...)
{
va_list va;
va_start(va, msg);
log_vprintf(context, DC_EVENT_WARNING, code, msg, va);
va_end(va);
dc_log_event(context, DC_EVENT_WARNING, code, msg);
}

View file

@ -219,7 +219,8 @@ int dc_smtp_connect(dc_smtp_t* smtp, const dc_loginparam_t* lp)
}
}
dc_log_info(smtp->context, 0, "SMTP-login as %s ok.", lp->send_user);
dc_log_event(smtp->context, DC_EVENT_SMTP_CONNECTED, 0,
"SMTP-login as %s ok.", lp->send_user);
}
success = 1;

View file

@ -764,6 +764,28 @@ time_t dc_lot_get_timestamp (const dc_lot_t*);
#define DC_EVENT_INFO 100
/**
* Emitted when SMTP connection is established and login was successful.
*
* @param data1 0
* @param data2 (const char*) Info string in english language.
* Must not be free()'d or modified and is valid only until the callback returns.
* @return 0
*/
#define DC_EVENT_SMTP_CONNECTED 101
/**
* Emitted when IMAP connection is established and login was successful.
*
* @param data1 0
* @param data2 (const char*) Info string in english language.
* Must not be free()'d or modified and is valid only until the callback returns.
* @return 0
*/
#define DC_EVENT_IMAP_CONNECTED 102
/**
* The library-user should write a warning string to the log.
* Passed to the callback given to dc_context_new().
@ -1031,7 +1053,7 @@ time_t dc_lot_get_timestamp (const dc_lot_t*);
*/
#define DC_EVENT_DATA1_IS_STRING(e) ((e)==DC_EVENT_HTTP_GET || (e)==DC_EVENT_IMEX_FILE_WRITTEN || (e)==DC_EVENT_FILE_COPIED)
#define DC_EVENT_DATA2_IS_STRING(e) ((e)==DC_EVENT_INFO || (e)==DC_EVENT_WARNING || (e)==DC_EVENT_ERROR)
#define DC_EVENT_DATA2_IS_STRING(e) ((e)==DC_EVENT_INFO || (e) == DC_EVENT_WARNING || (e) == DC_EVENT_ERROR || (e) == DC_EVENT_SMTP_CONNECTED || (e) == DC_EVENT_IMAP_CONNECTED)
#define DC_EVENT_RETURNS_INT(e) ((e)==DC_EVENT_IS_OFFLINE)
#define DC_EVENT_RETURNS_STRING(e) ((e)==DC_EVENT_GET_QUANTITY_STRING || (e)==DC_EVENT_GET_STRING || (e)==DC_EVENT_HTTP_GET)