text
stringlengths
0
357
/* before we export anything, make sure the private key exists */
if (!dc_ensure_secret_key_exists(context)) {
dc_log_error(context, 0, "Import/export: Cannot create private key or private key not available.");
goto cleanup;
}
/* also make sure, the directory for exporting exists */
dc_create_folder(context, param1);
}
switch (what)
{
case DC_IMEX_EXPORT_SELF_KEYS:
if (!export_self_keys(context, param1)) {
goto cleanup;
}
break;
case DC_IMEX_IMPORT_SELF_KEYS:
if (!import_self_keys(context, param1)) {
goto cleanup;
}
break;
case DC_IMEX_EXPORT_BACKUP:
if (!export_backup(context, param1)) {
goto cleanup;
}
break;
case DC_IMEX_IMPORT_BACKUP:
if (!import_backup(context, param1)) {
goto cleanup;
}
break;
default:
goto cleanup;
}
dc_log_info(context, 0, "Import/export completed.");
success = 1;
cleanup:
free(param1);
free(param2);
if (ongoing_allocated_here) { dc_free_ongoing(context); }
context->cb(context, DC_EVENT_IMEX_PROGRESS, success? 1000 : 0, 0);
}
/**
* Check if there is a backup file.
* May only be used on fresh installations (eg. dc_is_configured() returns 0).
*
* Example:
*
* ~~~
* char dir[] = "/dir/to/search/backups/in";
*
* void ask_user_for_credentials()
* {
* // - ask the user for email and password
* // - save them using dc_set_config()
* }
*
* int ask_user_whether_to_import()
* {
* // - inform the user that we've found a backup
* // - ask if he want to import it
* // - return 1 to import, 0 to skip
* return 1;
* }
*
* if (!dc_is_configured(context))
* {
* char* file = NULL;
* if ((file=dc_imex_has_backup(context, dir))!=NULL && ask_user_whether_to_import())
* {
* dc_imex(context, DC_IMEX_IMPORT_BACKUP, file, NULL);
* // connect
* }
* else
* {
* do {
* ask_user_for_credentials();
* }
* while (!configure_succeeded())
* }
* free(file);
* }
* ~~~
*
* @memberof dc_context_t
* @param context The context as created by dc_context_new().
* @param dir_name Directory to search backups in.
* @return String with the backup file, typically given to dc_imex(), returned strings must be free()'d.
* The function returns NULL if no backup was found.