file list: implementation of paging
This commit is contained in:
+2
-1
@@ -18,7 +18,8 @@ void process_client_command(char *line, session *sess, server_data_t *s_d) {
|
||||
if (!strcmp(arg_1, "file")) {
|
||||
/* LIST */
|
||||
if (!strcmp(arg_2, "list")) {
|
||||
file_list(sess, s_d);
|
||||
file_list(sess, s_d, 1);
|
||||
sess->state = OP_FILE_LIST;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
+14
-4
@@ -39,12 +39,21 @@ void clear_list(fl_t *start) {
|
||||
}
|
||||
}
|
||||
|
||||
void file_list(session *sess, server_data_t *s_d) {
|
||||
uint32_t navigate_list(session *sess, char *line, server_data_t *s_d) {
|
||||
uint64_t num;
|
||||
|
||||
if (sscanf(line, "p %lu", &num)) {
|
||||
file_list(sess, s_d, num);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void file_list(session *sess, server_data_t *s_d, uint64_t page) {
|
||||
char list_end[] = "list_end\n";
|
||||
fl_t *fl_start, *fl_current;
|
||||
char item_h[256];
|
||||
i_get_files_db args;
|
||||
uint64_t page = 1;
|
||||
uint64_t full_count, count, pages_count;
|
||||
|
||||
fl_start = NULL;
|
||||
@@ -67,9 +76,10 @@ void file_list(session *sess, server_data_t *s_d) {
|
||||
pages_count = full_count / 15;
|
||||
if (!pages_count)
|
||||
pages_count = 1;
|
||||
if (pages_count % 15) pages_count ++;
|
||||
|
||||
sprintf(page_info, "PAGE %lu FROM %lu. COUNT: %lu FROM %lu\n", page,
|
||||
pages_count, count, full_count);
|
||||
sprintf(page_info, "=== PAGE %lu/%lu COUNT: %lu/%lu ===\n", page,
|
||||
pages_count, count, full_count - (page-1)*15);
|
||||
|
||||
if (!fl_start)
|
||||
return;
|
||||
|
||||
+2
-2
@@ -1,9 +1,9 @@
|
||||
#ifndef FILEP_H
|
||||
#define FILEP_H
|
||||
#include "main.h"
|
||||
void get_files_data(server_data_t *, uint32_t page);
|
||||
void clear_list(fl_t *start);
|
||||
void file_list(session *, server_data_t *);
|
||||
uint32_t navigate_list(session *sess, char *line, server_data_t *s_d) ;
|
||||
void file_list(session *, server_data_t *, uint64_t page);
|
||||
int file_send_prepare(session *, char *, server_data_t *);
|
||||
enum f_actions {
|
||||
F_UPLOAD,
|
||||
|
||||
@@ -17,6 +17,7 @@ enum sess_states {
|
||||
OP_EDIT_FILE,
|
||||
OP_DOWNLOAD,
|
||||
OP_EDIT_USER,
|
||||
OP_FILE_LIST,
|
||||
OP_LOGIN_USR,
|
||||
OP_LOGIN_PSS,
|
||||
OP_LOGIN_ANON,
|
||||
|
||||
@@ -157,6 +157,11 @@ void perform_session_action(session *sess, char *line, server_data_t *s_d) {
|
||||
}
|
||||
}
|
||||
break;
|
||||
case OP_FILE_LIST:
|
||||
if (!navigate_list(sess, line, s_d)) {
|
||||
process_client_command(line, sess, s_d);
|
||||
}
|
||||
break;
|
||||
}
|
||||
/* } */
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user