automatically logout all accounts

This commit is contained in:
Florian Stinglmayr 2019-07-08 14:08:25 +02:00
parent 7a15fe6752
commit 72d29f15ef
5 changed files with 37 additions and 20 deletions

View File

@ -114,7 +114,6 @@ dc_api_do(dc_api_t api, char const *verb,
dc_api_sync_t sync = NULL;
struct curl_slist *l = NULL;
char *tmp = NULL;
int ptr = 0;
c = curl_easy_init();
goto_if_true(c == NULL, cleanup);
@ -162,10 +161,10 @@ dc_api_do(dc_api_t api, char const *verb,
}
if (data != NULL) {
curl_easy_setopt(c, CURLOPT_COPYPOSTFIELDS, data);
if (len >= 0) {
curl_easy_setopt(c, CURLOPT_POSTFIELDSIZE_LARGE, len);
}
curl_easy_setopt(c, CURLOPT_COPYPOSTFIELDS, data);
}
if (strcmp(verb, "PUT") == 0 ||
@ -178,8 +177,6 @@ dc_api_do(dc_api_t api, char const *verb,
}
g_hash_table_insert(api->syncs, c, dc_ref(sync));
curl_multi_socket_action(api->curl, CURL_SOCKET_TIMEOUT, 0, &ptr);
ret = true;
cleanup:

View File

@ -30,8 +30,18 @@ static void dc_api_sync_free(dc_api_sync_t s)
pthread_cond_destroy(&s->cnd);
pthread_mutex_destroy(&s->mtx);
if (s->list != NULL) {
curl_slist_free_all(s->list);
s->list = NULL;
}
if (s->easy != NULL) {
if (s->curl != NULL) {
curl_multi_remove_handle(s->curl, s->easy);
}
curl_easy_cleanup(s->easy);
s->easy = NULL;
}
if (s->stream != NULL) {
fclose(s->stream);
@ -42,9 +52,6 @@ static void dc_api_sync_free(dc_api_sync_t s)
s->buffer = NULL;
s->bufferlen = 0;
curl_slist_free_all(s->list);
s->list = NULL;
free(s);
}

View File

@ -160,7 +160,7 @@ dc_loop_t dc_loop_new_full(struct event_base *base, CURLM *multi)
curl_multi_setopt(ptr->multi, CURLMOPT_TIMERDATA, ptr);
curl_multi_setopt(ptr->multi, CURLMOPT_TIMERFUNCTION, mcurl_timer);
return ptr;
return dc_ref(ptr);
fail:

View File

@ -21,7 +21,7 @@ bool ncdc_cmd_login(ncdc_mainwindow_t n, size_t ac, wchar_t **av)
goto cleanup;
}
g_hash_table_insert(accounts, arg, acc);
g_hash_table_insert(accounts, strdup(arg), acc);
} else {
if (dc_account_has_token(acc)) {
LOG(n, L"login: %ls: this account is already logged in", av[1]);

View File

@ -17,6 +17,7 @@ ncdc_mainwindow_t mainwin = NULL;
/* we loop in a different thread
*/
bool main_done = false;
bool thread_done = false;
static pthread_t event_thread;
static struct event_base *base = NULL;
@ -34,11 +35,28 @@ dc_loop_t loop = NULL;
*/
dc_api_t api = NULL;
static void cleanup_account(dc_account_t a)
{
if (dc_account_has_token(a)) {
dc_api_logout(api, a);
}
dc_unref(a);
}
static void cleanup(void)
{
endwin();
main_done = true;
if (accounts != NULL) {
g_hash_table_unref(accounts);
accounts = NULL;
}
dc_unref(current_account);
current_account = NULL;
thread_done = true;
dc_loop_abort(loop);
pthread_join(event_thread, NULL);
@ -52,11 +70,6 @@ static void cleanup(void)
event_base_free(base);
base = NULL;
if (accounts != NULL) {
g_hash_table_unref(accounts);
accounts = NULL;
}
dc_unref(api);
dc_unref(loop);
@ -66,7 +79,7 @@ static void cleanup(void)
static void sighandler(int sig)
{
cleanup();
exit_main();
exit(3);
}
@ -79,7 +92,7 @@ static void stdin_handler(int sock, short what, void *data)
static void *looper(void *arg)
{
while (!main_done) {
while (!thread_done) {
if (!dc_loop_once(loop)) {
break;
}
@ -126,7 +139,7 @@ static bool init_everything(void)
return_if_true(config == NULL, false);
accounts = g_hash_table_new_full(g_str_hash, g_str_equal,
g_free, dc_unref
g_free, (GDestroyNotify)cleanup_account
);
return_if_true(accounts == NULL, false);