ui: login process (without error processing)

This commit is contained in:
2025-12-17 15:12:41 +02:00
parent b5d638bbc9
commit 1e2e180be4
8 changed files with 53 additions and 24 deletions
-2
View File
@@ -75,7 +75,5 @@ int32_t process_user_input(app_t *app, callback_args_t *d_args) {
} }
break; break;
} }
app_draw_modal(app);
app_refresh(app);
return OK; return OK;
} }
+4 -3
View File
@@ -39,6 +39,7 @@ enum state {
S_UPLOAD_REQUESTED, S_UPLOAD_REQUESTED,
S_ASK_USER_BEFORE_LOGIN, S_ASK_USER_BEFORE_LOGIN,
S_ERR, S_ERR,
S_NEXT_ACTION,
WAIT_SERVER_INIT, WAIT_SERVER_INIT,
WAIT_SERVER, WAIT_SERVER,
WAIT_REGISTER, WAIT_REGISTER,
@@ -70,12 +71,12 @@ typedef struct file_args {
} file_args_t; } file_args_t;
typedef struct query_args { typedef struct query_args {
int sd; int32_t sd;
int buf_used; int32_t buf_used;
p_file_t *file; p_file_t *file;
enum state state; enum state state;
char *buf; char *buf;
char from_server; uint32_t from_server : 1;
params_t *params; params_t *params;
char *next_server_command; char *next_server_command;
struct { struct {
+20 -2
View File
@@ -32,6 +32,7 @@ void query_loop(app_t *app) {
query_args_t *query_args = app->query_args; query_args_t *query_args = app->query_args;
fd_set readfds; fd_set readfds;
int32_t sd = app->params->sd; int32_t sd = app->params->sd;
app->query_args->sd = app->params->sd;
size_t qlen; size_t qlen;
int sr; int sr;
static file_args_t file_args; static file_args_t file_args;
@@ -57,11 +58,26 @@ void query_loop(app_t *app) {
maxfd = query_args->file->fd; maxfd = query_args->file->fd;
} }
} }
if (query_args->state == S_NEXT_ACTION &&
query_args->next_server_command != NULL) {
query_args->buf_used = strlen(query_args->next_server_command);
memcpy(query_args->buf, query_args->next_server_command,
query_args->buf_used);
free(query_args->next_server_command);
query_args->next_server_command = NULL;
query_args->from_server = TRUE;
if (-1 == process_query(query_args, &file_args)) {
close_session(sd);
exit(1);
}
continue;
} else {
sr = select(maxfd + 1, &readfds, NULL, NULL, NULL); sr = select(maxfd + 1, &readfds, NULL, NULL, NULL);
if (sr == -1) { if (sr == -1) {
perror("select"); perror("select");
exit(3); exit(3);
} }
}
if (FD_ISSET(sd, &readfds)) { if (FD_ISSET(sd, &readfds)) {
/* process request from the server */ /* process request from the server */
@@ -72,7 +88,7 @@ void query_loop(app_t *app) {
exit(1); exit(1);
} else { } else {
query_args->buf_used = qlen; query_args->buf_used = qlen;
query_args->from_server = 1; query_args->from_server = TRUE;
if (-1 == process_query(query_args, &file_args)) { if (-1 == process_query(query_args, &file_args)) {
close_session(sd); close_session(sd);
exit(1); exit(1);
@@ -83,7 +99,8 @@ void query_loop(app_t *app) {
if (query_args->file && query_args->file->fd > -1 && if (query_args->file && query_args->file->fd > -1 &&
FD_ISSET(query_args->file->fd, &readfds)) { FD_ISSET(query_args->file->fd, &readfds)) {
/* process upload/download */ /* process upload/download */
query_args->buf_used = read(query_args->file->fd, query_args->buf, INBUFSIZE); query_args->buf_used =
read(query_args->file->fd, query_args->buf, INBUFSIZE);
process_query(query_args, &file_args); process_query(query_args, &file_args);
} }
@@ -122,6 +139,7 @@ int process_query(query_args_t *query_args, file_args_t *file_args) {
case WAIT_SERVER: case WAIT_SERVER:
case WAIT_SERVER_INIT: case WAIT_SERVER_INIT:
case WAIT_CLIENT: case WAIT_CLIENT:
case S_NEXT_ACTION:
case S_WAIT_SERVER: case S_WAIT_SERVER:
case WAIT_REGISTER_CONFIRMATION: case WAIT_REGISTER_CONFIRMATION:
wait_side(query_args); wait_side(query_args);
+10 -5
View File
@@ -16,6 +16,14 @@
void ask_uname_and_password(params_t *params); void ask_uname_and_password(params_t *params);
void ask_register(params_t *params, char *email); void ask_register(params_t *params, char *email);
#define PRINT_SRV_MESSAGE(q_args) \
if (q_args->server_message.size > 0) { \
q_args->state = S_PRINT_SERVER_MESSAGE; \
q_args->next_server_command = malloc(l_len + 1); \
strcpy(q_args->next_server_command, line); \
return 0; \
}
int process_server_command(char *line, int l_len, query_args_t *q_args) { int process_server_command(char *line, int l_len, query_args_t *q_args) {
int ws_pos = l_len; int ws_pos = l_len;
params_t *params = q_args->params; params_t *params = q_args->params;
@@ -29,11 +37,8 @@ int process_server_command(char *line, int l_len, query_args_t *q_args) {
/* LOGIN */ /* LOGIN */
if (!strncmp(line, "login>", ws_pos)) { if (!strncmp(line, "login>", ws_pos)) {
if (q_args->server_message.size > 0) { PRINT_SRV_MESSAGE(q_args);
q_args->state = S_PRINT_SERVER_MESSAGE; q_args->state = S_ASK_LOGIN_TYPE;
q_args->next_server_command = malloc(l_len + 1);
strcpy(q_args->next_server_command, line);
}
return 0; return 0;
} }
+1
View File
@@ -149,6 +149,7 @@ void app_draw_modal(app_t *app) {
case S_ERR: case S_ERR:
case S_WAIT_SERVER: case S_WAIT_SERVER:
case S_N_D: case S_N_D:
case S_NEXT_ACTION:
return; return;
} }
} }
+11 -3
View File
@@ -2,6 +2,7 @@
#include <stdint.h> #include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h>
#include "../app.h" #include "../app.h"
#include "../widget/dialogue.h" #include "../widget/dialogue.h"
@@ -21,13 +22,20 @@ void init_login_credentials_modal_cb(callback_args_t *args) {
memcpy(&d_args, args, sizeof(callback_args_t)); memcpy(&d_args, args, sizeof(callback_args_t));
d_args.app = NULL; d_args.app = NULL;
d_args.resp_data = &response; d_args.resp_data = &response;
input_t *in_ip = d->g_content->elements[0].element; input_t *in_name = d->g_content->elements[0].element;
input_t *in_port = d->g_content->elements[1].element; input_t *in_pass = d->g_content->elements[1].element;
dialogue_default_callback(&d_args); dialogue_default_callback(&d_args);
if (response > -1) { if (response > -1) {
switch (response) { switch (response) {
case 0: case 0:
app->query_args->state = S_ASK_LOGIN_USER; app->params->uname = malloc(in_name->value_len + 1);
app->params->pass = malloc(in_pass->value_len + 1);
strncpy(app->params->uname, in_name->value, in_name->value_len);
app->params->uname[in_name->value_len] = 0;
strncpy(app->params->pass, in_pass->value, in_pass->value_len);
app->params->pass[in_pass->value_len] = 0;
write(app->params->sd, app->params->uname, in_name->value_len);
app->query_args->state = S_WAIT_SERVER;
destroy_dialogue(d); destroy_dialogue(d);
break; break;
case 1: case 1:
+2 -2
View File
@@ -25,11 +25,11 @@ void server_message_modal_cb(callback_args_t *args) {
switch (response) { switch (response) {
case 0: case 0:
destroy_dialogue(d); destroy_dialogue(d);
// TODO: macros /* TODO: macros */
free(app->query_args->server_message.text); free(app->query_args->server_message.text);
app->query_args->server_message.capacity = 0; app->query_args->server_message.capacity = 0;
app->query_args->server_message.size = 0; app->query_args->server_message.size = 0;
app->query_args->state = S_ASK_LOGIN_USER; app->query_args->state = S_NEXT_ACTION;
break; break;
} }
} }
-2
View File
@@ -186,8 +186,6 @@ int32_t draw_dialogue(dialogue_t *d) {
x += 1; /* when uses box */ x += 1; /* when uses box */
y += 1; /* when uses box */ y += 1; /* when uses box */
/* space for action block */
d->w.x = x; d->w.x = x;
d->w.y = y; d->w.y = y;
d->w.m_y = (d->p_coordinates->max_y - y) / 2; d->w.m_y = (d->p_coordinates->max_y - y) / 2;