mirror of
https://github.com/deltachat/deltachat-core.git
synced 2025-10-04 18:29:19 +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:
parent
1c77187d5a
commit
3265178d31
9 changed files with 51 additions and 13 deletions
|
@ -34,6 +34,7 @@ def acfactory(pytestconfig, tmpdir, request):
|
||||||
configdict = self.configlist.pop(0)
|
configdict = self.configlist.pop(0)
|
||||||
tmpdb = tmpdir.join("testdb%d" % self.count)
|
tmpdb = tmpdir.join("testdb%d" % self.count)
|
||||||
ac = Account(tmpdb.strpath)
|
ac = Account(tmpdb.strpath)
|
||||||
|
ac._evlogger.set_timeout(10)
|
||||||
ac.set_config(**configdict)
|
ac.set_config(**configdict)
|
||||||
if started:
|
if started:
|
||||||
ac.start()
|
ac.start()
|
||||||
|
|
2
python/setup.cfg
Normal file
2
python/setup.cfg
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
[devpi:upload]
|
||||||
|
formats = sdist.tgz,bdist_wheel
|
|
@ -42,21 +42,26 @@ class EventLogger:
|
||||||
self._event_queue = Queue()
|
self._event_queue = Queue()
|
||||||
self._debug = debug
|
self._debug = debug
|
||||||
self._ctxinfo = str(self.dc_context).strip(">").split()[-1]
|
self._ctxinfo = str(self.dc_context).strip(">").split()[-1]
|
||||||
|
self._timeout = None
|
||||||
|
|
||||||
def __call__(self, evt_name, data1, data2):
|
def __call__(self, evt_name, data1, data2):
|
||||||
self._log_event(evt_name, data1, data2)
|
self._log_event(evt_name, data1, data2)
|
||||||
self._event_queue.put((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):
|
def get(self, timeout=None, check_error=True):
|
||||||
|
timeout = timeout or self._timeout
|
||||||
ev = self._event_queue.get(timeout=timeout)
|
ev = self._event_queue.get(timeout=timeout)
|
||||||
if check_error:
|
if check_error:
|
||||||
assert ev[0] != "DC_EVENT_ERROR"
|
assert ev[0] != "DC_EVENT_ERROR"
|
||||||
return ev
|
return ev
|
||||||
|
|
||||||
def get_matching(self, event_name_regex, timeout=None):
|
def get_matching(self, event_name_regex):
|
||||||
rex = re.compile(event_name_regex + ".*")
|
rex = re.compile("(?:{}).*".format(event_name_regex))
|
||||||
while 1:
|
while 1:
|
||||||
ev = self.get(timeout=timeout)
|
ev = self.get()
|
||||||
if rex.match(ev[0]):
|
if rex.match(ev[0]):
|
||||||
return ev
|
return ev
|
||||||
|
|
||||||
|
|
|
@ -30,10 +30,10 @@ class TestLive:
|
||||||
imap_ok = smtp_ok = False
|
imap_ok = smtp_ok = False
|
||||||
while not imap_ok or not smtp_ok:
|
while not imap_ok or not smtp_ok:
|
||||||
evt_name, data1, data2 = \
|
evt_name, data1, data2 = \
|
||||||
ac1._evlogger.get_matching("DC_EVENT_INFO", timeout=5)
|
ac1._evlogger.get_matching("DC_EVENT_(IMAP|SMTP)_CONNECTED")
|
||||||
if re.match("imap-login.*ok.", data2.lower()):
|
if evt_name == "DC_EVENT_IMAP_CONNECTED":
|
||||||
imap_ok = True
|
imap_ok = True
|
||||||
if re.match("smtp-login.*ok.", data2.lower()):
|
if evt_name == "DC_EVENT_SMTP_CONNECTED":
|
||||||
smtp_ok = True
|
smtp_ok = True
|
||||||
assert ac1.get_config("mail_pw")
|
assert ac1.get_config("mail_pw")
|
||||||
|
|
||||||
|
|
|
@ -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_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_warning (dc_context_t*, int code, const char* msg, ...);
|
||||||
void dc_log_info (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);
|
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"
|
#define DC_BAK_PREFIX "delta-chat"
|
||||||
|
|
|
@ -1153,7 +1153,8 @@ static int setup_handle_if_needed(dc_imap_t* imap)
|
||||||
goto cleanup;
|
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;
|
success = 1;
|
||||||
|
|
||||||
|
|
13
src/dc_log.c
13
src/dc_log.c
|
@ -87,13 +87,18 @@ void dc_log_info(dc_context_t* context, int code, const char* msg, ...)
|
||||||
va_end(va);
|
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, ...)
|
void dc_log_warning(dc_context_t* context, int code, const char* msg, ...)
|
||||||
{
|
{
|
||||||
va_list va;
|
dc_log_event(context, DC_EVENT_WARNING, code, msg);
|
||||||
va_start(va, msg);
|
|
||||||
log_vprintf(context, DC_EVENT_WARNING, code, msg, va);
|
|
||||||
va_end(va);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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;
|
success = 1;
|
||||||
|
|
|
@ -764,6 +764,28 @@ time_t dc_lot_get_timestamp (const dc_lot_t*);
|
||||||
#define DC_EVENT_INFO 100
|
#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.
|
* The library-user should write a warning string to the log.
|
||||||
* Passed to the callback given to dc_context_new().
|
* 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_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_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)
|
#define DC_EVENT_RETURNS_STRING(e) ((e)==DC_EVENT_GET_QUANTITY_STRING || (e)==DC_EVENT_GET_STRING || (e)==DC_EVENT_HTTP_GET)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue