implementation of registration (not finished)
This commit is contained in:
+15
-6
@@ -41,13 +41,19 @@ void clear_list(fl_t *start) {
|
|||||||
|
|
||||||
uint32_t navigate_list(session *sess, char *line, server_data_t *s_d) {
|
uint32_t navigate_list(session *sess, char *line, server_data_t *s_d) {
|
||||||
uint64_t num;
|
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);
|
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) {
|
void file_list(session *sess, server_data_t *s_d, uint64_t page) {
|
||||||
char list_end[] = "list_end\n";
|
char list_end[] = "list_end\n";
|
||||||
@@ -76,10 +82,11 @@ void file_list(session *sess, server_data_t *s_d, uint64_t page) {
|
|||||||
pages_count = full_count / 15;
|
pages_count = full_count / 15;
|
||||||
if (!pages_count)
|
if (!pages_count)
|
||||||
pages_count = 1;
|
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,
|
sprintf(page_info, "=== PAGE %lu/%lu COUNT: %lu/%lu ===\n", page, pages_count,
|
||||||
pages_count, count, full_count - (page-1)*15);
|
count, full_count - (page - 1) * 15);
|
||||||
|
|
||||||
if (!fl_start)
|
if (!fl_start)
|
||||||
return;
|
return;
|
||||||
@@ -168,7 +175,9 @@ int32_t file_send_prepare(session *sess, char *line, server_data_t *s_d) {
|
|||||||
lseek(file_d, 0, SEEK_SET);
|
lseek(file_d, 0, SEEK_SET);
|
||||||
|
|
||||||
if (sess->file->size != fsize) {
|
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);
|
write(sd, err_mes, mlen);
|
||||||
return -3;
|
return -3;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -162,6 +162,9 @@ void perform_session_action(session *sess, char *line, server_data_t *s_d) {
|
|||||||
process_client_command(line, sess, s_d);
|
process_client_command(line, sess, s_d);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case OP_REGISTER:
|
||||||
|
// TODO:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
/* } */
|
/* } */
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-4
@@ -13,14 +13,15 @@ int process_user_name(char *uname, session *sess) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strncmp(uname, "register", sizeof "register")) {
|
if (!strncmp(uname, "register", sizeof "register"-1)) {
|
||||||
sess->state = OP_REGISTER;
|
sess->state = OP_REGISTER;
|
||||||
session_send_string(sess, "Your username > ");
|
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strncmp(uname, "anon", sizeof "anon")) {
|
if (!strncmp(uname, "anonymous", sizeof "anonymous")) {
|
||||||
sess->state = OP_LOGIN_ANON;
|
sess->uname = malloc(sizeof "anonymous");
|
||||||
|
strcpy(sess->uname, "anonymous");
|
||||||
|
sess->state = OP_WAIT;
|
||||||
session_send_string(sess, "Welcome, Anonymous!");
|
session_send_string(sess, "Welcome, Anonymous!");
|
||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user