close db in more correct way. less unsigned integers
This commit is contained in:
+9
-9
@@ -15,14 +15,14 @@ typedef struct {
|
||||
|
||||
typedef struct {
|
||||
char privileges;
|
||||
uint32_t uid;
|
||||
int32_t uid;
|
||||
} o_auth_t;
|
||||
|
||||
/* Get file */
|
||||
|
||||
typedef struct {
|
||||
uint32_t id;
|
||||
uint32_t user_id;
|
||||
int32_t id;
|
||||
int32_t user_id;
|
||||
char name[FILE_NAME_LEN];
|
||||
} i_get_file_db;
|
||||
|
||||
@@ -30,10 +30,10 @@ enum sort_direction { ASC, DESC };
|
||||
enum sort_by { ID, NAME, CREATED_AT, USER_ID };
|
||||
|
||||
typedef struct {
|
||||
uint32_t user_id; // TODO: implement
|
||||
int32_t user_id; // TODO: implement
|
||||
char search_str[FILE_NAME_LEN]; // TODO: implement
|
||||
uint32_t limit;
|
||||
uint32_t offset;
|
||||
int32_t limit;
|
||||
int32_t offset;
|
||||
enum sort_by sort_by;
|
||||
enum sort_direction sort_direction;
|
||||
} i_get_files_db;
|
||||
@@ -50,8 +50,8 @@ int32_t init_db_connection();
|
||||
int32_t db_save_file(session *s);
|
||||
int32_t db_user_auth(i_auth_t *credentials, o_auth_t *response);
|
||||
s_file_t *db_get_file(i_get_file_db *arg);
|
||||
uint64_t db_get_files_data(i_get_files_db *arg, fl_t **fl_start,
|
||||
uint64_t *full_count);
|
||||
int64_t db_get_files_data(i_get_files_db *arg, fl_t **fl_start,
|
||||
int64_t *full_count);
|
||||
int32_t db_user_create(i_db_user_create *);
|
||||
int close_connection(void);
|
||||
int db_close_connection(void);
|
||||
#endif
|
||||
+10
-10
@@ -81,7 +81,7 @@ static void processNotice(void *arg, const char *message) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
int close_connection(void) { return 0; };
|
||||
int db_close_connection(void) { return 0; };
|
||||
|
||||
int init_db_connection() {
|
||||
// TODO: get from external configs
|
||||
@@ -152,7 +152,7 @@ int32_t db_user_create(i_db_user_create *args) {
|
||||
|
||||
paramLengths[0] = strlen(args->uname);
|
||||
paramLengths[2] = strlen(args->email);
|
||||
uint32_t ret_value;
|
||||
int32_t ret_value;
|
||||
|
||||
string_to_SHA256(args->pass, passHashed);
|
||||
paramValues[1] = passHashed;
|
||||
@@ -205,7 +205,7 @@ int32_t db_save_file(session *s) {
|
||||
char empty_str[] = "";
|
||||
|
||||
int32_t uid_n = htonl(s->uid);
|
||||
uint64_t size_n = htobe64(sf->size);
|
||||
size_t size_n = htobe64(sf->size);
|
||||
int32_t hash_n = htonl(sf->hash);
|
||||
int32_t perm_n = htonl(sf->permissions);
|
||||
|
||||
@@ -222,7 +222,7 @@ int32_t db_save_file(session *s) {
|
||||
|
||||
paramLengths[0] = sizeof(int32_t);
|
||||
paramLengths[1] = strlen(sf->name);
|
||||
paramLengths[2] = sizeof(uint64_t);
|
||||
paramLengths[2] = sizeof(int64_t);
|
||||
paramLengths[3] = sizeof(int32_t);
|
||||
if (sf->description != NULL) {
|
||||
paramLengths[4] = strlen(sf->description);
|
||||
@@ -259,7 +259,7 @@ s_file_t *db_get_file(i_get_file_db *arg) {
|
||||
char value[64] = "";
|
||||
const char *paramValues[1];
|
||||
char query[512];
|
||||
uint32_t q_len = 0;
|
||||
int32_t q_len = 0;
|
||||
|
||||
if (arg->id) {
|
||||
strcpy(s_field, "id");
|
||||
@@ -306,8 +306,8 @@ s_file_t *db_get_file(i_get_file_db *arg) {
|
||||
return sf;
|
||||
}
|
||||
|
||||
uint64_t db_get_files_data(i_get_files_db *arg, fl_t **fl_start,
|
||||
uint64_t *full_count) {
|
||||
int64_t db_get_files_data(i_get_files_db *arg, fl_t **fl_start,
|
||||
int64_t *full_count) {
|
||||
fl_t *fl_current;
|
||||
char query[512];
|
||||
char sort_by[16] = "id";
|
||||
@@ -316,9 +316,9 @@ uint64_t db_get_files_data(i_get_files_db *arg, fl_t **fl_start,
|
||||
int paramLengths[3];
|
||||
int paramFormats[3];
|
||||
int i;
|
||||
uint64_t count;
|
||||
uint64_t n_limit = htobe64(arg->limit);
|
||||
uint64_t n_offset = htobe64(arg->offset);
|
||||
int64_t count;
|
||||
int64_t n_limit = htobe64(arg->limit);
|
||||
int64_t n_offset = htobe64(arg->offset);
|
||||
bool by_name = strlen(arg->search_str) > 0;
|
||||
int32_t params_num = 3;
|
||||
|
||||
|
||||
+3
-23
@@ -6,7 +6,6 @@
|
||||
#include <db.h>
|
||||
#include <endian.h>
|
||||
#include <openssl/sha.h>
|
||||
#include <signal.h>
|
||||
#include <sqlite3.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
@@ -32,8 +31,6 @@ enum db_arg_type {
|
||||
db_str,
|
||||
db_int,
|
||||
db_int64,
|
||||
db_uint,
|
||||
db_uint64,
|
||||
db_blob,
|
||||
db_size, /* size for subsequent arg */
|
||||
db_end
|
||||
@@ -41,16 +38,6 @@ enum db_arg_type {
|
||||
|
||||
typedef enum db_cb_resp (*db_callback)(sqlite3_stmt *stmt, void *resp);
|
||||
|
||||
const char message[] = "The program is closing!\n";
|
||||
|
||||
#define SIG130 130
|
||||
|
||||
void sigterm_handler(int s) {
|
||||
signal(SIGINT, sigterm_handler);
|
||||
write(STDOUT_FILENO, message, sizeof(message) - 1);
|
||||
/* sqlite3_close_v2(db); */
|
||||
}
|
||||
|
||||
void print_err(char **err) {
|
||||
if (*err != NULL) {
|
||||
printf("%s\n", *err);
|
||||
@@ -116,7 +103,6 @@ int check_and_create_tables() {
|
||||
}
|
||||
|
||||
int init_db_connection(void) {
|
||||
signal(SIGINT, sigterm_handler);
|
||||
int res = sqlite3_open("db.sqlite", &db);
|
||||
char *err = NULL;
|
||||
if (!res) {
|
||||
@@ -126,7 +112,7 @@ int init_db_connection(void) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int close_connection(void) { return sqlite3_close_v2(db); }
|
||||
int db_close_connection(void) { return sqlite3_close_v2(db); }
|
||||
|
||||
// === /* BASE FUNCTIONS */ =========================================
|
||||
|
||||
@@ -159,12 +145,6 @@ enum db_cb_resp vdb_query(const char *zSql, db_callback callback, void *a_resp,
|
||||
case db_int64:
|
||||
sqlite3_bind_int64(stmt, i + 1, va_arg(va_list, int64_t));
|
||||
break;
|
||||
case db_uint:
|
||||
sqlite3_bind_int(stmt, i + 1, va_arg(va_list, unsigned int));
|
||||
break;
|
||||
case db_uint64:
|
||||
sqlite3_bind_int64(stmt, i + 1, va_arg(va_list, uint64_t));
|
||||
break;
|
||||
case db_blob:
|
||||
if (size > 0) {
|
||||
sqlite3_bind_blob(stmt, i + 1, va_arg(va_list, void *), size, NULL);
|
||||
@@ -442,8 +422,8 @@ enum db_cb_resp db_get_files_count_db(sqlite3_stmt *stmt, void *resp) {
|
||||
return db_success;
|
||||
}
|
||||
|
||||
uint64_t db_get_files_data(i_get_files_db *arg, fl_t **fl_start,
|
||||
uint64_t *full_count) {
|
||||
int64_t db_get_files_data(i_get_files_db *arg, fl_t **fl_start,
|
||||
int64_t *full_count) {
|
||||
fl_t *fl_current = NULL;
|
||||
char zSql[512];
|
||||
struct db_get_files_data data = {.fl_current = &fl_current,
|
||||
|
||||
Reference in New Issue
Block a user