UI: file list improvements
This commit is contained in:
+5
-3
@@ -3,6 +3,7 @@
|
|||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "session.h"
|
#include "session.h"
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@@ -10,15 +11,16 @@
|
|||||||
void process_client_command(char *line, session *sess, server_data_t *s_d) {
|
void process_client_command(char *line, session *sess, server_data_t *s_d) {
|
||||||
char arg_1[32];
|
char arg_1[32];
|
||||||
char arg_2[32];
|
char arg_2[32];
|
||||||
int res;
|
uint32_t res;
|
||||||
|
uint32_t limit, page;
|
||||||
|
|
||||||
sscanf(line, "%s %s", arg_1, arg_2);
|
sscanf(line, "%s %s", arg_1, arg_2);
|
||||||
|
|
||||||
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, 1);
|
sscanf(line, "%*s %*s %u %u", &limit, &page);
|
||||||
sess->state = OP_FILE_LIST;
|
file_list(sess, s_d, limit, page);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -127,6 +127,9 @@ int32_t db_user_auth(i_auth_t *c, o_auth_t *r) {
|
|||||||
|
|
||||||
const char *pass = PQgetvalue(res, 0, 2);
|
const char *pass = PQgetvalue(res, 0, 2);
|
||||||
string_to_SHA256( c->pass, passHashed);
|
string_to_SHA256( c->pass, passHashed);
|
||||||
|
if (pass == NULL) {
|
||||||
|
/* TODO: return */
|
||||||
|
}
|
||||||
if (!strcmp(passHashed, pass)) {
|
if (!strcmp(passHashed, pass)) {
|
||||||
r->privileges = PQgetvalue(res, 0, 3)[0];
|
r->privileges = PQgetvalue(res, 0, 3)[0];
|
||||||
r->uid = atoi(PQgetvalue(res, 0, 0));
|
r->uid = atoi(PQgetvalue(res, 0, 0));
|
||||||
|
|||||||
+7
-23
@@ -39,23 +39,7 @@ void clear_list(fl_t *start) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t navigate_list(session *sess, char *line, server_data_t *s_d) {
|
void file_list(session *sess, server_data_t *s_d, uint32_t limit, uint32_t page) {
|
||||||
uint64_t num;
|
|
||||||
char op_symbol;
|
|
||||||
|
|
||||||
if (!sscanf(line, "%c %lu", &op_symbol, &num))
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
switch (op_symbol) {
|
|
||||||
case 'p':
|
|
||||||
file_list(sess, s_d, num);
|
|
||||||
return 1;
|
|
||||||
default:
|
|
||||||
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];
|
||||||
@@ -71,22 +55,22 @@ void file_list(session *sess, server_data_t *s_d, uint64_t page) {
|
|||||||
sess->fl_current = NULL;
|
sess->fl_current = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
args.limit = 15;
|
args.limit = limit;
|
||||||
args.offset = 15 * (page - 1);
|
args.offset = limit * (page - 1);
|
||||||
args.sort_by = ID;
|
args.sort_by = ID;
|
||||||
args.sort_direction = ASC;
|
args.sort_direction = ASC;
|
||||||
|
|
||||||
count = db_get_files_data(&args, &fl_start, &full_count);
|
count = db_get_files_data(&args, &fl_start, &full_count);
|
||||||
char page_info[256];
|
char page_info[256];
|
||||||
|
|
||||||
pages_count = full_count / 15;
|
pages_count = full_count / limit;
|
||||||
if (!pages_count)
|
if (!pages_count)
|
||||||
pages_count = 1;
|
pages_count = 1;
|
||||||
if (pages_count % 15)
|
if (pages_count % limit)
|
||||||
pages_count++;
|
pages_count++;
|
||||||
|
|
||||||
sprintf(page_info, "=== PAGE %lu/%lu COUNT: %lu/%lu ===\n", page, pages_count,
|
sprintf(page_info, "=== PAGE %u/%lu COUNT: %lu/%lu ===\n", page, pages_count,
|
||||||
count, full_count - (page - 1) * 15);
|
count, full_count - (page - 1) * limit);
|
||||||
|
|
||||||
if (!fl_start)
|
if (!fl_start)
|
||||||
return;
|
return;
|
||||||
|
|||||||
+1
-2
@@ -2,8 +2,7 @@
|
|||||||
#define FILEP_H
|
#define FILEP_H
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
void clear_list(fl_t *start);
|
void clear_list(fl_t *start);
|
||||||
uint32_t navigate_list(session *sess, char *line, server_data_t *s_d) ;
|
void file_list(session *, server_data_t *, uint32_t limit, uint32_t page);
|
||||||
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,
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ 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,
|
||||||
|
|||||||
@@ -159,11 +159,6 @@ 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