3 #include <linenoise/linenoise.h>
5 #include "client_auth.h"
9 struct ClientAuth client_auth;
12 static void auth_loop()
14 while (!interrupt.set) switch (client_auth.state) {
17 linenoiseFree(client_auth.name);
19 if (!(client_auth.name = linenoise("Enter name: ")))
22 printf("[access] authenticating as %s...\n", client_auth.name);
23 client_auth.state = AUTH_WAIT;
25 dragonnet_peer_send_ToServerAuth(client, &(ToServerAuth) {
26 .name = client_auth.name,
29 __attribute__((fallthrough));
32 pthread_cond_wait(&client_auth.cv, &client_auth.mtx);
40 bool client_auth_init()
42 client_auth.name = NULL;
43 pthread_cond_init(&client_auth.cv, NULL);
44 pthread_mutex_init(&client_auth.mtx, NULL);
46 pthread_mutex_lock(&client_auth.mtx);
47 client_auth.state = AUTH_INIT;
48 flag_sub(&interrupt, &client_auth.cv); // make sure Ctrl+C will work during AUTH_WAIT
52 flag_uns(&interrupt, &client_auth.cv);
53 bool success = client_auth.state == AUTH_SUCCESS;
54 pthread_mutex_unlock(&client_auth.mtx);
59 void client_auth_deinit()
61 pthread_cond_destroy(&client_auth.cv);
62 pthread_mutex_destroy(&client_auth.mtx);
63 linenoiseFree(client_auth.name);