file list: implementation of paging
This commit is contained in:
@@ -69,3 +69,5 @@ build
|
|||||||
|
|
||||||
#wdir contents
|
#wdir contents
|
||||||
wdir
|
wdir
|
||||||
|
|
||||||
|
src/deps.mk
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
## Features
|
## Features
|
||||||
|
|
||||||
- [x] Database integration
|
- [x] Database integration
|
||||||
- [ ] Paging in the file list
|
- [x] Paging in the file list
|
||||||
- [x] Get files in FS by their hash
|
- [x] Get files in FS by their hash
|
||||||
- [ ] Registration
|
- [ ] Registration
|
||||||
- [ ] Message to admin
|
- [ ] Message to admin
|
||||||
|
|||||||
+2
-1
@@ -18,7 +18,8 @@ void process_client_command(char *line, session *sess, server_data_t *s_d) {
|
|||||||
if (!strcmp(arg_1, "file")) {
|
if (!strcmp(arg_1, "file")) {
|
||||||
/* LIST */
|
/* LIST */
|
||||||
if (!strcmp(arg_2, "list")) {
|
if (!strcmp(arg_2, "list")) {
|
||||||
file_list(sess, s_d);
|
file_list(sess, s_d, 1);
|
||||||
|
sess->state = OP_FILE_LIST;
|
||||||
return;
|
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";
|
char list_end[] = "list_end\n";
|
||||||
fl_t *fl_start, *fl_current;
|
fl_t *fl_start, *fl_current;
|
||||||
char item_h[256];
|
char item_h[256];
|
||||||
i_get_files_db args;
|
i_get_files_db args;
|
||||||
uint64_t page = 1;
|
|
||||||
uint64_t full_count, count, pages_count;
|
uint64_t full_count, count, pages_count;
|
||||||
|
|
||||||
fl_start = NULL;
|
fl_start = NULL;
|
||||||
@@ -67,9 +76,10 @@ void file_list(session *sess, server_data_t *s_d) {
|
|||||||
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 ++;
|
||||||
|
|
||||||
sprintf(page_info, "PAGE %lu FROM %lu. COUNT: %lu FROM %lu\n", page,
|
sprintf(page_info, "=== PAGE %lu/%lu COUNT: %lu/%lu ===\n", page,
|
||||||
pages_count, count, full_count);
|
pages_count, count, full_count - (page-1)*15);
|
||||||
|
|
||||||
if (!fl_start)
|
if (!fl_start)
|
||||||
return;
|
return;
|
||||||
|
|||||||
+2
-2
@@ -1,9 +1,9 @@
|
|||||||
#ifndef FILEP_H
|
#ifndef FILEP_H
|
||||||
#define FILEP_H
|
#define FILEP_H
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
void get_files_data(server_data_t *, uint32_t page);
|
|
||||||
void clear_list(fl_t *start);
|
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 *);
|
int file_send_prepare(session *, char *, server_data_t *);
|
||||||
enum f_actions {
|
enum f_actions {
|
||||||
F_UPLOAD,
|
F_UPLOAD,
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ enum sess_states {
|
|||||||
OP_EDIT_FILE,
|
OP_EDIT_FILE,
|
||||||
OP_DOWNLOAD,
|
OP_DOWNLOAD,
|
||||||
OP_EDIT_USER,
|
OP_EDIT_USER,
|
||||||
|
OP_FILE_LIST,
|
||||||
OP_LOGIN_USR,
|
OP_LOGIN_USR,
|
||||||
OP_LOGIN_PSS,
|
OP_LOGIN_PSS,
|
||||||
OP_LOGIN_ANON,
|
OP_LOGIN_ANON,
|
||||||
|
|||||||
@@ -157,6 +157,11 @@ void perform_session_action(session *sess, char *line, server_data_t *s_d) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
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