text
stringlengths
0
357
* 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().
* If NULL is given, nothing is done.
* @return None.
*/
void dc_context_unref(dc_context_t* context)
{
if (context==NULL || context->magic!=DC_CONTEXT_MAGIC) {
return;
}
dc_pgp_exit();
if (dc_is_open(context)) {
dc_close(context);
}
dc_imap_unref(context->inbox);
dc_imap_unref(context->sentbox_thread.imap);
dc_imap_unref(context->mvbox_thread.imap);
dc_smtp_unref(context->smtp);
dc_sqlite3_unref(context->sql);
dc_openssl_exit();
pthread_mutex_destroy(&context->smear_critical);
pthread_mutex_destroy(&context->bobs_qr_critical);
pthread_mutex_destroy(&context->inboxidle_condmutex);
dc_jobthread_exit(&context->sentbox_thread);
dc_jobthread_exit(&context->mvbox_thread);
pthread_cond_destroy(&context->smtpidle_cond);
pthread_mutex_destroy(&context->smtpidle_condmutex);
pthread_mutex_destroy(&context->oauth2_critical);
free(context->os_name);
context->magic = 0;
free(context);
}
/**
* Get user data associated with a context object.
*
* @memberof dc_context_t
* @param context The context object as created by dc_context_new().
* @return User data, this is the second parameter given to dc_context_new().
*/
void* dc_get_userdata(dc_context_t* context)
{
if (context==NULL || context->magic!=DC_CONTEXT_MAGIC) {
return NULL;
}
return context->userdata;
}
/**
* Open context database. If the given file does not exist, it is
* 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, something like `~/file` won't
* work on all systems, if in doubt, use absolute paths.
* @param blobdir A directory to store the blobs in; a trailing slash is not needed.
* 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
* eg. if the file is not writable
* or if there is already a database opened for the context.
*/
int dc_open(dc_context_t* context, const char* dbfile, const char* blobdir)
{
int success = 0;
if (dc_is_open(context)) {
return 0; // a cleanup would close the database
}
if (context==NULL || context->magic!=DC_CONTEXT_MAGIC || dbfile==NULL) {
goto cleanup;
}
context->dbfile = dc_strdup(dbfile);
/* set blob-directory
(to avoid double slashes, the given directory should not end with an slash) */
if (blobdir && blobdir[0]) {
context->blobdir = dc_strdup(blobdir);
dc_ensure_no_slash(context->blobdir);
}
else {
context->blobdir = dc_mprintf("%s-blobs", dbfile);
dc_create_folder(context, context->blobdir);