implementation of registration (not finished)

This commit is contained in:
2025-11-07 17:41:33 +02:00
parent 08d46cffcb
commit 4569bf1f47
3 changed files with 25 additions and 12 deletions
+17 -8
View File
@@ -41,12 +41,18 @@ void clear_list(fl_t *start) {
uint32_t navigate_list(session *sess, char *line, server_data_t *s_d) {
uint64_t num;
char op_symbol;
if (sscanf(line, "p %lu", &num)) {
if (!sscanf(line, "%c %lu", &op_symbol, &num))
return 0;
switch (op_symbol) {
case 'p':
file_list(sess, s_d, num);
return 1;
return 1;
default:
return 0;
}
return 0;
}
void file_list(session *sess, server_data_t *s_d, uint64_t page) {
@@ -76,10 +82,11 @@ void file_list(session *sess, server_data_t *s_d, uint64_t page) {
pages_count = full_count / 15;
if (!pages_count)
pages_count = 1;
if (pages_count % 15) pages_count ++;
if (pages_count % 15)
pages_count++;
sprintf(page_info, "=== PAGE %lu/%lu COUNT: %lu/%lu ===\n", page,
pages_count, count, full_count - (page-1)*15);
sprintf(page_info, "=== PAGE %lu/%lu COUNT: %lu/%lu ===\n", page, pages_count,
count, full_count - (page - 1) * 15);
if (!fl_start)
return;
@@ -110,7 +117,7 @@ void file_list(session *sess, server_data_t *s_d, uint64_t page) {
} while ((fl_current = fl_current->next) != NULL);
sess->fl_start = fl_start;
write(sess->sd, list_end, sizeof(list_end)-1);
write(sess->sd, list_end, sizeof(list_end) - 1);
write(sess->sd, page_info, strlen(page_info));
}
@@ -168,7 +175,9 @@ int32_t file_send_prepare(session *sess, char *line, server_data_t *s_d) {
lseek(file_d, 0, SEEK_SET);
if (sess->file->size != fsize) {
mlen = sprintf(err_mes, "File with id = %u exists, but seems to be damaged\n", sess->file->id);
mlen =
sprintf(err_mes, "File with id = %u exists, but seems to be damaged\n",
sess->file->id);
write(sd, err_mes, mlen);
return -3;
}
+3
View File
@@ -162,6 +162,9 @@ void perform_session_action(session *sess, char *line, server_data_t *s_d) {
process_client_command(line, sess, s_d);
}
break;
case OP_REGISTER:
// TODO:
break;
}
/* } */
}
+5 -4
View File
@@ -13,14 +13,15 @@ int process_user_name(char *uname, session *sess) {
return 1;
}
if (!strncmp(uname, "register", sizeof "register")) {
if (!strncmp(uname, "register", sizeof "register"-1)) {
sess->state = OP_REGISTER;
session_send_string(sess, "Your username > ");
return 2;
}
if (!strncmp(uname, "anon", sizeof "anon")) {
sess->state = OP_LOGIN_ANON;
if (!strncmp(uname, "anonymous", sizeof "anonymous")) {
sess->uname = malloc(sizeof "anonymous");
strcpy(sess->uname, "anonymous");
sess->state = OP_WAIT;
session_send_string(sess, "Welcome, Anonymous!");
return 3;
}