implement logout command

This commit is contained in:
2019-07-08 13:04:53 +02:00
parent 6dc21a365c
commit 7a15fe6752
9 changed files with 113 additions and 45 deletions

View File

@@ -19,6 +19,7 @@ SET(SOURCES
"src/input.c"
"src/keycodes.c"
"src/login.c"
"src/logout.c"
"src/mainwindow.c"
"src/msg.c"
"src/ncdc.c"

View File

@@ -26,7 +26,8 @@ ncdc_commands_t *ncdc_find_cmd(ncdc_commands_t *cmds, wchar_t const *name);
bool ncdc_cmd_friends(ncdc_mainwindow_t n, size_t ac, wchar_t **av);
bool ncdc_cmd_login(ncdc_mainwindow_t n, size_t ac, wchar_t **av);
bool ncdc_cmd_quit(ncdc_mainwindow_t n, size_t ac, wchar_t **av);
bool ncdc_cmd_logout(ncdc_mainwindow_t n, size_t ac, wchar_t **av);
bool ncdc_cmd_msg(ncdc_mainwindow_t n, size_t ac, wchar_t **av);
bool ncdc_cmd_quit(ncdc_mainwindow_t n, size_t ac, wchar_t **av);
#endif

View File

@@ -4,6 +4,7 @@ ncdc_commands_t cmds[] = {
{ L"/friend", ncdc_cmd_friends },
{ L"/friends", ncdc_cmd_friends },
{ L"/login", ncdc_cmd_login },
{ L"/logout", ncdc_cmd_logout },
{ L"/msg", ncdc_cmd_msg },
{ L"/quit", ncdc_cmd_quit },
{ NULL, NULL }

View File

@@ -39,7 +39,7 @@ bool ncdc_cmd_login(ncdc_mainwindow_t n, size_t ac, wchar_t **av)
goto cleanup;
}
current_account = acc;
current_account = dc_ref(acc);
LOG(n, L"login: %ls: authentication successful", av[1]);
ret = true;

28
ncdc/src/logout.c Normal file
View File

@@ -0,0 +1,28 @@
#include <ncdc/cmds.h>
#include <ncdc/ncdc.h>
#include <ncdc/config.h>
bool ncdc_cmd_logout(ncdc_mainwindow_t n, size_t ac, wchar_t **av)
{
bool ret = false;
goto_if_true(current_account == NULL ||
!dc_account_has_token(current_account), error);
ret = dc_api_logout(api, current_account);
if (!ret) {
LOG(n, L"logout: failed to log out the current account");
goto error;
}
g_hash_table_remove(accounts, dc_account_fullname(current_account));
dc_unref(current_account);
current_account = NULL;
LOG(n, L"logout: successfully logged out");
error:
return ret;
}