diff --git a/python/tests/test_lowlevel.py b/python/tests/test_lowlevel.py index e7024389..ca4a25b2 100644 --- a/python/tests/test_lowlevel.py +++ b/python/tests/test_lowlevel.py @@ -1,5 +1,6 @@ from __future__ import print_function import deltachat +import requests from deltachat import capi, get_dc_event_name from deltachat.capi import ffi import queue @@ -27,7 +28,17 @@ def test_cb(register_dc_callback): def test_basic_events(dc_context, dc_threads, register_dc_callback, tmpdir, userpassword): q = queue.Queue() def cb(dc_context, evt, data1, data2): - q.put((evt, data1, data2)) + # print (evt1, data1, data2) + data1 = try_cast_to_string(data1) + data2 = try_cast_to_string(data2) + evt_name = get_dc_event_name(evt) + print (evt_name, data1, data2) + if evt_name == "DC_EVENT_HTTP_GET": + content = read_url(data1) + # XXX how to give this string back to delta-core properly? + # for now we just return nothing + else: + q.put((evt, data1, data2)) return 0 register_dc_callback(dc_context, cb) @@ -38,11 +49,17 @@ def test_basic_events(dc_context, dc_threads, register_dc_callback, tmpdir, user capi.lib.dc_configure(dc_context) while 1: - evt1, data1, data2 = q.get(timeout=1.0) - data1 = try_cast_to_string(data1) - data2 = try_cast_to_string(data2) - evt_name = get_dc_event_name(evt1) - print (evt_name, data1, data2) + evt_name, data1, data2 = q.get(timeout=1.0) + pass + + +def read_url(url): + try: + r = requests.get(url) + except requests.ConnectionError: + pass + else: + return r.content def try_cast_to_string(obj): diff --git a/src/dc_configure.c b/src/dc_configure.c index 06fbf55c..1855cc82 100644 --- a/src/dc_configure.c +++ b/src/dc_configure.c @@ -38,8 +38,11 @@ static char* read_autoconf_file(dc_context_t* context, const char* url) { char* filecontent = NULL; + char* urlcopy = NULL; + dc_log_info(context, 0, "Testing %s ...", url); - filecontent = (char*)context->cb(context, DC_EVENT_HTTP_GET, (uintptr_t)url, 0); + urlcopy = dc_strdup(url); + filecontent = (char*)context->cb(context, DC_EVENT_HTTP_GET, (uintptr_t)urlcopy, 0); if (filecontent==NULL) { dc_log_info(context, 0, "Can't read file."); /* this is not a warning or an error, we're just testing */ return NULL;