1
0
Fork 0
mirror of https://github.com/deltachat/deltachat-core.git synced 2025-10-05 10:39:27 +02:00

hack things to work a bit more, with modifying DC_EVENT_HTTP_GET c-code

we can now perform a http request but how to return it to dc is unclear yet
This commit is contained in:
holger krekel 2018-09-05 15:45:25 +02:00
parent 31ebc32963
commit 7a54a2577a
2 changed files with 27 additions and 7 deletions

View file

@ -1,5 +1,6 @@
from __future__ import print_function from __future__ import print_function
import deltachat import deltachat
import requests
from deltachat import capi, get_dc_event_name from deltachat import capi, get_dc_event_name
from deltachat.capi import ffi from deltachat.capi import ffi
import queue import queue
@ -27,6 +28,16 @@ def test_cb(register_dc_callback):
def test_basic_events(dc_context, dc_threads, register_dc_callback, tmpdir, userpassword): def test_basic_events(dc_context, dc_threads, register_dc_callback, tmpdir, userpassword):
q = queue.Queue() q = queue.Queue()
def cb(dc_context, evt, data1, data2): def cb(dc_context, 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)) q.put((evt, data1, data2))
return 0 return 0
register_dc_callback(dc_context, cb) 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) capi.lib.dc_configure(dc_context)
while 1: while 1:
evt1, data1, data2 = q.get(timeout=1.0) evt_name, data1, data2 = q.get(timeout=1.0)
data1 = try_cast_to_string(data1) pass
data2 = try_cast_to_string(data2)
evt_name = get_dc_event_name(evt1)
print (evt_name, data1, data2) def read_url(url):
try:
r = requests.get(url)
except requests.ConnectionError:
pass
else:
return r.content
def try_cast_to_string(obj): def try_cast_to_string(obj):

View file

@ -38,8 +38,11 @@
static char* read_autoconf_file(dc_context_t* context, const char* url) static char* read_autoconf_file(dc_context_t* context, const char* url)
{ {
char* filecontent = NULL; char* filecontent = NULL;
char* urlcopy = NULL;
dc_log_info(context, 0, "Testing %s ...", url); 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) { if (filecontent==NULL) {
dc_log_info(context, 0, "Can't read file."); /* this is not a warning or an error, we're just testing */ dc_log_info(context, 0, "Can't read file."); /* this is not a warning or an error, we're just testing */
return NULL; return NULL;