Jonas Reinsch 7 лет назад
Родитель
Сommit
e0512e7671

+ 18 - 1
deltachat-ios/libraries/deltachat-core/cmdline/stress.c

@@ -301,7 +301,7 @@ void stress_functions(dc_context_t* context)
 		free(mime);
 	}
 
-	/* test some string functions
+	/* test some string functions and macros
 	 **************************************************************************/
 
 	{
@@ -495,6 +495,23 @@ void stress_functions(dc_context_t* context)
 		assert( strcmp(buf2, "Björn Petersen")==0 );
 		free(buf1);
 		free(buf2);
+
+		assert(  DC_EVENT_DATA1_IS_STRING(2100) );
+		assert( !DC_EVENT_DATA1_IS_STRING(100) );
+		assert( !DC_EVENT_DATA1_IS_STRING(300) );
+		assert( !DC_EVENT_DATA1_IS_STRING(400) );
+
+		assert(  DC_EVENT_DATA2_IS_STRING(100) );
+		assert(  DC_EVENT_DATA2_IS_STRING(300) );
+		assert(  DC_EVENT_DATA2_IS_STRING(400) );
+		assert( !DC_EVENT_DATA2_IS_STRING(2010) );
+
+		assert(  DC_EVENT_RETURNS_STRING(2091) );
+		assert(  DC_EVENT_RETURNS_STRING(2092) );
+		assert(  DC_EVENT_RETURNS_STRING(2100) );
+		assert( !DC_EVENT_RETURNS_STRING(100) );
+		assert( !DC_EVENT_RETURNS_STRING(300) );
+		assert( !DC_EVENT_RETURNS_STRING(400) );
 	}
 
 	/* test dc_array_t

+ 14 - 0
deltachat-ios/libraries/deltachat-core/python/src/deltachat/__init__.py

@@ -0,0 +1,14 @@
+from deltachat import capi
+
+
+_DC_CALLBACK_MAP = {}
+
+
+@capi.ffi.def_extern()
+def py_dc_callback(ctx, evt, data1, data2):
+    """The global event handler.
+
+    CFFI only allows us to set one global event handler, so this one
+    looks up the correct event handler for the given context.
+    """
+    return _DC_CALLBACK_MAP.get(ctx, lambda *a: 0)

+ 7 - 0
deltachat-ios/libraries/deltachat-core/python/src/deltachat/_build.py

@@ -28,6 +28,13 @@ def ffibuilder():
                           output_file=dst_fp.name,
                           macros=[('PY_CFFI', '1')])
             builder.cdef(dst_fp.read())
+    builder.cdef("""
+        extern "Python" uintptr_t py_dc_callback(
+            dc_context_t* context,
+            int event,
+            uintptr_t data1,
+            uintptr_t data2);
+    """)
     return builder
 
 

+ 15 - 0
deltachat-ios/libraries/deltachat-core/python/tests/conftest.py

@@ -0,0 +1,15 @@
+import pytest
+
+import deltachat
+
+
+@pytest.fixture
+def register_dc_callback(monkeypatch):
+    """Register a callback for a given context.
+
+    This is a function-scoped fixture and the function will be
+    unregisterd automatically on fixture teardown.
+    """
+    def register_dc_callback(ctx, func):
+        monkeypatch.setitem(deltachat._DC_CALLBACK_MAP, ctx, func)
+    return register_dc_callback

+ 11 - 4
deltachat-ios/libraries/deltachat-core/python/tests/test_mrmailbox.py

@@ -1,10 +1,17 @@
-import pathlib
-
-import pytest
-
+import deltachat
 from deltachat import capi
 
 
 def test_empty_context():
     ctx = capi.lib.dc_context_new(capi.ffi.NULL, capi.ffi.NULL, capi.ffi.NULL)
     capi.lib.dc_close(ctx)
+
+
+def test_cb(register_dc_callback):
+    def cb(ctx, evt, data1, data2):
+        return 0
+    ctx = capi.lib.dc_context_new(capi.lib.py_dc_callback,
+                                  capi.ffi.NULL, capi.ffi.NULL)
+    register_dc_callback(ctx, cb)
+    capi.lib.dc_close(ctx)
+    assert deltachat._DC_CALLBACK_MAP[ctx] is cb

+ 2 - 2
deltachat-ios/libraries/deltachat-core/src/dc_array.c

@@ -349,10 +349,10 @@ int dc_array_search_id(const dc_array_t* array, uint32_t needle, size_t* ret_ind
 /**
  * Get raw pointer to the data.
  *
- * @private @memberof dc_array_t
+ * @memberof dc_array_t
  * @param array The array object.
  * @return Raw pointer to the array. You MUST NOT free the data. You MUST NOT access the data beyond the current item count.
- *     It is not possible to enlarge the array this way.  Calling any other dc_array-function may discard the returned pointer.
+ *     It is not possible to enlarge the array this way.  Calling any other dc_array*()-function may discard the returned pointer.
  */
 const uintptr_t* dc_array_get_raw(const dc_array_t* array)
 {

+ 17 - 10
deltachat-ios/libraries/deltachat-core/src/dc_context.c

@@ -80,7 +80,6 @@ static void cb_receive_imf(dc_imap_t* imap, const char* imf_raw_not_terminated,
 /**
  * Create a new context object.  After creation it is usually
  * opened, connected and mails are fetched.
- * After usage, the object should be deleted using dc_context_unref().
  *
  * @memberof dc_context_t
  * @param cb a callback function that is called for events (update,
@@ -149,6 +148,9 @@ dc_context_t* dc_context_new(dc_callback_t cb, void* userdata, const char* os_na
 /**
  * Free a context object.
  * If app runs can only be terminated by a forced kill, this may be superfluous.
+ * Before the context object is freed, connections to SMTP, IMAP and database
+ * are closed. You can also do this explicitly by calling dc_close() on your own
+ * before calling dc_context_unref().
  *
  * @memberof dc_context_t
  * @param context the context object as created by dc_context_new().
@@ -225,13 +227,13 @@ static void update_config_cache(dc_context_t* context, const char* key)
  * created and can be set up using dc_set_config() afterwards.
  *
  * @memberof dc_context_t
- * @param context: the context object as created by dc_context_new()
- * @param dbfile the file to use to store the database, sth. like "~/file" won't
+ * @param context The context object as created by dc_context_new().
+ * @param dbfile The file to use to store the database, sth. like `~/file` won't
  *     work on all systems, if in doubt, use absolute paths.
- * @param blobdir a directory to store the blobs in, the trailing slash is added
- *     by us, so if you want to avoid double slashes, do not add one. If you
- *     give NULL as blobdir, `dbfile-blobs` is used in the same directory as
- *     _dbfile_ will be created in.
+ * @param blobdir A directory to store the blobs in. The trailing slash is added
+ *     by deltachat-core, so if you want to avoid double slashes, do not add one.
+ *     If you pass NULL or the empty string, deltachat-core creates a directory
+ *     beside _dbfile_ with the same name and the suffix `-blobs`.
  * @return 1 on success, 0 on failure
  */
 int dc_open(dc_context_t* context, const char* dbfile, const char* blobdir)
@@ -279,11 +281,16 @@ cleanup:
 
 
 /**
- * Close context database.
+ * Close context database opened by dc_open().
+ * Before this, connections to SMTP and IMAP are closed; these connections
+ * are started automatically as needed eg. by sending for fetching messages.
+ * This function is also implicitly called by dc_context_unref().
+ * Multiple calls to this functions are okay, the function takes care not
+ * to free objects twice.
  *
  * @memberof dc_context_t
- * @param context the context object as created by dc_context_new()
- * @return none
+ * @param context The context object as created by dc_context_new().
+ * @return None.
  */
 void dc_close(dc_context_t* context)
 {

+ 2 - 3
deltachat-ios/libraries/deltachat-core/src/dc_imap.c

@@ -1045,14 +1045,13 @@ void dc_imap_idle(dc_imap_t* imap)
 
 void dc_imap_interrupt_idle(dc_imap_t* imap)
 {
-	if (imap==NULL) { // imap->etpan may be NULL
-		dc_log_warning(imap->context, 0, "Interrupt IMAP-IDLE: Bad parameter.");
+	if (imap==NULL) {
 		return;
 	}
 
 	if (imap->can_idle)
 	{
-		if (imap && imap->etpan && imap->etpan->imap_stream) {
+		if (imap->etpan && imap->etpan->imap_stream) {
 			mailstream_interrupt_idle(imap->etpan->imap_stream);
 		}
 	}

+ 11 - 0
deltachat-ios/libraries/deltachat-core/src/dc_imex.c

@@ -36,6 +36,12 @@
 #include "dc_job.h"
 
 
+/**
+ * @name Import/Export
+ * @{
+ */
+
+
 /*******************************************************************************
  * Autocrypt Key Transfer
  ******************************************************************************/
@@ -1421,3 +1427,8 @@ cleanup:
 	dc_loginparam_unref(loginparam);
 	return success;
 }
+
+
+/**
+ * @}
+ */

+ 27 - 23
deltachat-ios/libraries/deltachat-core/src/dc_mimefactory.c

@@ -103,6 +103,10 @@ void dc_mimefactory_empty(dc_mimefactory_t* factory)
 
 static void set_error(dc_mimefactory_t* factory, const char* text)
 {
+	if (factory==NULL) {
+		return;
+	}
+
 	free(factory->error);
 	factory->error = dc_strdup_keep_null(text);
 }
@@ -263,48 +267,48 @@ cleanup:
 int dc_mimefactory_load_mdn(dc_mimefactory_t* factory, uint32_t msg_id)
 {
 	int           success = 0;
-	dc_contact_t* contact = dc_contact_new(factory->context);
+	dc_contact_t* contact = NULL;
 
 	if (factory==NULL) {
 		goto cleanup;
 	}
 
-	dc_context_t* context = factory->context;
-
 	factory->recipients_names = clist_new();
 	factory->recipients_addr  = clist_new();
-	factory->msg              = dc_msg_new(context);
+	factory->msg              = dc_msg_new(factory->context);
 
-		if (!dc_sqlite3_get_config_int(context->sql, "mdns_enabled", DC_MDNS_DEFAULT_ENABLED)) {
-			goto cleanup; /* MDNs not enabled - check this is late, in the job. the use may have changed its choice while offline ... */
-		}
+	if (!dc_sqlite3_get_config_int(factory->context->sql, "mdns_enabled", DC_MDNS_DEFAULT_ENABLED)) {
+		goto cleanup; /* MDNs not enabled - check this is late, in the job. the use may have changed its choice while offline ... */
+	}
 
-		if (!dc_msg_load_from_db(factory->msg, context, msg_id)
-		 || !dc_contact_load_from_db(contact, context->sql, factory->msg->from_id)) {
-			goto cleanup;
-		}
+	contact = dc_contact_new(factory->context);
+	if (!dc_msg_load_from_db(factory->msg, factory->context, msg_id)
+	 || !dc_contact_load_from_db(contact, factory->context->sql, factory->msg->from_id)) {
+		goto cleanup;
+	}
 
-		if (contact->blocked
-		 || factory->msg->chat_id<=DC_CHAT_ID_LAST_SPECIAL/* Do not send MDNs trash etc.; chats.blocked is already checked by the caller in dc_markseen_msgs() */) {
-			goto cleanup;
-		}
+	if (contact->blocked
+	 || factory->msg->chat_id<=DC_CHAT_ID_LAST_SPECIAL/* Do not send MDNs trash etc.; chats.blocked is already checked by the caller in dc_markseen_msgs() */) {
+		goto cleanup;
+	}
 
-		if (factory->msg->from_id <= DC_CONTACT_ID_LAST_SPECIAL) {
-			goto cleanup;
-		}
+	if (factory->msg->from_id <= DC_CONTACT_ID_LAST_SPECIAL) {
+		goto cleanup;
+	}
 
-		clist_append(factory->recipients_names, (void*)((contact->authname&&contact->authname[0])? dc_strdup(contact->authname) : NULL));
-		clist_append(factory->recipients_addr,  (void*)dc_strdup(contact->addr));
+	clist_append(factory->recipients_names, (void*)((contact->authname&&contact->authname[0])? dc_strdup(contact->authname) : NULL));
+	clist_append(factory->recipients_addr,  (void*)dc_strdup(contact->addr));
 
-		load_from(factory);
+	load_from(factory);
 
-		factory->timestamp = dc_create_smeared_timestamp(context);
-		factory->rfc724_mid = dc_create_outgoing_rfc724_mid(NULL, factory->from_addr);
+	factory->timestamp = dc_create_smeared_timestamp(factory->context);
+	factory->rfc724_mid = dc_create_outgoing_rfc724_mid(NULL, factory->from_addr);
 
 	success = 1;
 	factory->loaded = DC_MF_MDN_LOADED;
 
 cleanup:
+	dc_contact_unref(contact);
 	return success;
 }
 

+ 3 - 5
deltachat-ios/libraries/deltachat-core/src/dc_msg.c

@@ -1483,10 +1483,8 @@ cleanup:
  * The max. text returned is typically longer (about 100000 characters) than the
  * max. text returned by dc_msg_get_text() (about 30000 characters).
  *
- * If the library is compiled for andoid, some basic html-formatting for he
- * subject and the footer is added. However we should change this function so
- * that it returns eg. an array of pairwise key-value strings and the caller
- * can show the whole stuff eg. in a table.
+ * If the library is compiled for android, some basic html-formatting for the
+ * subject and the footer is added.
  *
  * @memberof dc_context_t
  * @param context the context object as created by dc_context_new().
@@ -1521,7 +1519,7 @@ char* dc_get_msg_info(dc_context_t* context, uint32_t msg_id)
 	sqlite3_finalize(stmt);
 	stmt = NULL;
 
-	#ifdef __ANDROID__
+	#ifdef __ANDROID__ // TODO: this (and the following `#ifdef __ANDROID__`) is a little hack to make the android message appearing a little smarter
 		p = strchr(rawtxt, '\n');
 		if (p) {
 			char* subject = rawtxt;

+ 12 - 0
deltachat-ios/libraries/deltachat-core/src/dc_securejoin.c

@@ -31,6 +31,12 @@
 #include "dc_token.h"
 
 
+/**
+ * @name Secure Join
+ * @{
+ */
+
+
 /*******************************************************************************
  * Tools: Handle degraded keys and lost verificaton
  ******************************************************************************/
@@ -788,3 +794,9 @@ cleanup:
 	free(grpid);
 	return ret;
 }
+
+
+
+/**
+ * @}
+ */

+ 5 - 4
deltachat-ios/libraries/deltachat-core/src/deltachat.h

@@ -33,7 +33,7 @@ extern "C" {
 #endif
 
 
-#define DC_VERSION_STR "0.19.0"
+#define DC_VERSION_STR "0.19.2"
 
 
 /**
@@ -95,7 +95,7 @@ extern "C" {
  * sqlite-file and is created as needed:
  *
  * ```
- * dc_open(context, "example.db");
+ * dc_open(context, "example.db", NULL);
  * ```
  *
  * Now you can **configure the context:**
@@ -849,9 +849,10 @@ time_t          dc_lot_get_timestamp     (const dc_lot_t*);
  */
 
 
-#define DC_EVENT_DATA2_IS_STRING(e)  ((e)==DC_EVENT_INFO) || (e)==DC_EVENT_WARNING || (e)==DC_EVENT_ERROR))
+#define DC_EVENT_DATA1_IS_STRING(e)  ((e)==DC_EVENT_HTTP_GET)
+#define DC_EVENT_DATA2_IS_STRING(e)  ((e)==DC_EVENT_INFO || (e)==DC_EVENT_WARNING || (e)==DC_EVENT_ERROR)
 #define DC_EVENT_RETURNS_INT         ((e)==DC_EVENT_IS_OFFLINE)
-#define DC_EVENT_RETURNS_STRING(e)   ((e)==DC_EVENT_INFO) || (e)==DC_EVENT_GET_QUANTITY_STRING || (e)==DC_EVENT_GET_STRING))
+#define DC_EVENT_RETURNS_STRING(e)   ((e)==DC_EVENT_GET_QUANTITY_STRING || (e)==DC_EVENT_GET_STRING || (e)==DC_EVENT_HTTP_GET)
 
 
 /**