diff --git a/src/dc_configure.c b/src/dc_configure.c index 2682f4bf..7bbb9c7d 100644 --- a/src/dc_configure.c +++ b/src/dc_configure.c @@ -381,7 +381,7 @@ void dc_job_do_DC_JOB_CONFIGURE_IMAP(dc_context_t* context, dc_job_t* job) ongoing_allocated_here = 1; #define PROGRESS(p) \ - if( dc_shall_stop_ongoing ) { goto cleanup; } \ + if( context->m_shall_stop_ongoing ) { goto cleanup; } \ context->m_cb(context, DC_EVENT_CONFIGURE_PROGRESS, (p)<1? 1 : ((p)>999? 999 : (p)), 0); if( !dc_sqlite3_is_open(context->m_sql) ) { @@ -739,21 +739,19 @@ int dc_is_configured(dc_context_t* context) * Request an ongoing process to start. * Returns 0=process started, 1=not started, there is running another process */ -static int s_ongoing_running = 0; -int dc_shall_stop_ongoing = 1; /* the value 1 avoids dc_stop_ongoing_process() from stopping already stopped threads */ int dc_alloc_ongoing(dc_context_t* context) { if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC ) { return 0; } - if( s_ongoing_running || dc_shall_stop_ongoing == 0 ) { + if( context->m_ongoing_running || context->m_shall_stop_ongoing == 0 ) { dc_log_warning(context, 0, "There is already another ongoing process running."); return 0; } - s_ongoing_running = 1; - dc_shall_stop_ongoing = 0; + context->m_ongoing_running = 1; + context->m_shall_stop_ongoing = 0; return 1; } @@ -768,8 +766,8 @@ void dc_free_ongoing(dc_context_t* context) return; } - s_ongoing_running = 0; - dc_shall_stop_ongoing = 1; /* avoids dc_stop_ongoing_process() to stop the thread */ + context->m_ongoing_running = 0; + context->m_shall_stop_ongoing = 1; /* avoids dc_stop_ongoing_process() to stop the thread */ } @@ -803,10 +801,10 @@ void dc_stop_ongoing_process(dc_context_t* context) return; } - if( s_ongoing_running && dc_shall_stop_ongoing==0 ) + if( context->m_ongoing_running && context->m_shall_stop_ongoing==0 ) { dc_log_info(context, 0, "Signaling the ongoing process to stop ASAP."); - dc_shall_stop_ongoing = 1; + context->m_shall_stop_ongoing = 1; } else { diff --git a/src/dc_context.c b/src/dc_context.c index 6cada69b..f58c7be7 100644 --- a/src/dc_context.c +++ b/src/dc_context.c @@ -116,6 +116,8 @@ dc_context_t* dc_context_new(dc_callback_t cb, void* userdata, const char* os_na context->m_smtp = dc_smtp_new(context); context->m_os_name = dc_strdup_keep_null(os_name); + context->m_shall_stop_ongoing = 1; /* the value 1 avoids dc_stop_ongoing_process() from stopping already stopped threads */ + dc_pgp_init(context); /* Random-seed. An additional seed with more random data is done just before key generation diff --git a/src/dc_context.h b/src/dc_context.h index f1329410..9f2147ca 100644 --- a/src/dc_context.h +++ b/src/dc_context.h @@ -112,6 +112,10 @@ struct _dc_context // time smearing - to keep messages in order, we may modify the time by some seconds time_t m_last_smeared_timestamp; pthread_mutex_t m_smear_critical; + + // handling ongoing processes initiated by the user + int m_ongoing_running; + int m_shall_stop_ongoing; }; diff --git a/src/dc_imex.c b/src/dc_imex.c index 57f5179e..cacb9051 100644 --- a/src/dc_imex.c +++ b/src/dc_imex.c @@ -468,7 +468,7 @@ char* dc_initiate_key_transfer(dc_context_t* context) if( !dc_alloc_ongoing(context) ) { return 0; /* no cleanup as this would call dc_free_ongoing() */ } - #define CHECK_EXIT if( dc_shall_stop_ongoing ) { goto cleanup; } + #define CHECK_EXIT if( context->m_shall_stop_ongoing ) { goto cleanup; } if( (setup_code=dc_create_setup_code(context)) == NULL ) { /* this may require a keypair to be created. this may take a second ... */ goto cleanup; @@ -917,7 +917,7 @@ static int export_backup(dc_context_t* context, const char* dir) stmt = dc_sqlite3_prepare(dest_sql, "INSERT INTO backup_blobs (file_name, file_content) VALUES (?, ?);"); while( (dir_entry=readdir(dir_handle))!=NULL ) { - if( dc_shall_stop_ongoing ) { + if( context->m_shall_stop_ongoing ) { delete_dest_file = 1; goto cleanup; } @@ -1051,7 +1051,7 @@ static int import_backup(dc_context_t* context, const char* backup_to_import) stmt = dc_sqlite3_prepare(context->m_sql, "SELECT file_name, file_content FROM backup_blobs ORDER BY id;"); while( sqlite3_step(stmt) == SQLITE_ROW ) { - if( dc_shall_stop_ongoing ) { + if( context->m_shall_stop_ongoing ) { goto cleanup; } diff --git a/src/dc_securejoin.c b/src/dc_securejoin.c index c3d16cb1..9673e264 100644 --- a/src/dc_securejoin.c +++ b/src/dc_securejoin.c @@ -433,7 +433,7 @@ uint32_t dc_join_securejoin(dc_context_t* context, const char* qr) int ret_chat_id = 0; int ongoing_allocated = 0; - #define CHECK_EXIT if( dc_shall_stop_ongoing ) { goto cleanup; } + #define CHECK_EXIT if( context->m_shall_stop_ongoing ) { goto cleanup; } uint32_t contact_chat_id = 0; dc_lot_t* qr_scan = NULL; int join_vg = 0;