refactoring; finishing integration of CMocka; several test cases covered
This commit is contained in:
@@ -10,6 +10,7 @@ target_sources(zbbs-server
|
||||
)
|
||||
|
||||
add_library(main INTERFACE)
|
||||
add_library(types INTERFACE)
|
||||
|
||||
target_sources(main
|
||||
PUBLIC
|
||||
@@ -18,6 +19,13 @@ target_sources(main
|
||||
main.h
|
||||
)
|
||||
|
||||
target_sources(types
|
||||
PUBLIC
|
||||
FILE_SET HEADERS
|
||||
FILES
|
||||
types.h
|
||||
)
|
||||
|
||||
|
||||
add_subdirectory(libs)
|
||||
add_subdirectory(db)
|
||||
@@ -29,6 +37,9 @@ target_link_libraries(zbbs-server
|
||||
client
|
||||
db
|
||||
murmur3
|
||||
types
|
||||
server
|
||||
utils
|
||||
OpenSSL::Crypto
|
||||
)
|
||||
|
||||
|
||||
@@ -1,2 +1,6 @@
|
||||
add_subdirectory(client)
|
||||
add_subdirectory(session)
|
||||
add_subdirectory(file_p)
|
||||
add_subdirectory(session)
|
||||
add_subdirectory(server)
|
||||
add_subdirectory(utils)
|
||||
add_subdirectory(user)
|
||||
@@ -4,6 +4,9 @@ target_link_libraries(client
|
||||
PRIVATE
|
||||
db
|
||||
main
|
||||
file_p
|
||||
session
|
||||
utils
|
||||
murmur3
|
||||
OpenSSL::Crypto
|
||||
)
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/* SPDX-License-Identifier: MIT */
|
||||
/* Copyright (c) 2026 Oleksandr Zhylin */
|
||||
|
||||
#include "client.h"
|
||||
#include "file_p.h"
|
||||
#include <client.h>
|
||||
#include <file_p.h>
|
||||
#include <main.h>
|
||||
#include "session.h"
|
||||
#include "utils.h"
|
||||
#include <session.h>
|
||||
#include <utils.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
add_library(file_p STATIC)
|
||||
|
||||
target_link_libraries(file_p
|
||||
PRIVATE
|
||||
db
|
||||
main
|
||||
murmur3
|
||||
utils
|
||||
session
|
||||
OpenSSL::Crypto
|
||||
)
|
||||
|
||||
target_sources(file_p
|
||||
PRIVATE
|
||||
file_p.c
|
||||
PUBLIC
|
||||
FILE_SET HEADERS
|
||||
FILES
|
||||
file_p.h
|
||||
)
|
||||
@@ -1,16 +1,15 @@
|
||||
/* SPDX-License-Identifier: MIT */
|
||||
/* Copyright (c) 2026 Oleksandr Zhylin */
|
||||
|
||||
#include "file_p.h"
|
||||
#include "main.h"
|
||||
#include "session.h"
|
||||
#include "utils.h"
|
||||
#include <arpa/inet.h>
|
||||
#include <db.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <file_p.h>
|
||||
#include <main.h>
|
||||
#include <murmur3.h>
|
||||
#include <netinet/in.h>
|
||||
#include <session.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
@@ -26,6 +25,7 @@
|
||||
#include <sys/uio.h>
|
||||
#include <sys/un.h>
|
||||
#include <unistd.h>
|
||||
#include <utils.h>
|
||||
|
||||
char *extract_second_arg(char *);
|
||||
size_t get_file_size(char *, char *);
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#ifndef FILEP_H
|
||||
#define FILEP_H
|
||||
#include "main.h"
|
||||
#include <main.h>
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct {
|
||||
@@ -0,0 +1,21 @@
|
||||
add_library(server STATIC)
|
||||
|
||||
target_link_libraries(server
|
||||
PRIVATE
|
||||
db
|
||||
main
|
||||
utils
|
||||
file_p
|
||||
session
|
||||
murmur3
|
||||
OpenSSL::Crypto
|
||||
)
|
||||
|
||||
target_sources(server
|
||||
PRIVATE
|
||||
server.c
|
||||
PUBLIC
|
||||
FILE_SET HEADERS
|
||||
FILES
|
||||
server.h
|
||||
)
|
||||
@@ -1,11 +1,11 @@
|
||||
/* SPDX-License-Identifier: MIT */
|
||||
/* Copyright (c) 2026 Oleksandr Zhylin */
|
||||
|
||||
#include "db.h"
|
||||
#include "file_p.h"
|
||||
#include "main.h"
|
||||
#include "session.h"
|
||||
#include "utils.h"
|
||||
#include <db.h>
|
||||
#include <file_p.h>
|
||||
#include <main.h>
|
||||
#include <session.h>
|
||||
#include <utils.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#ifndef SERVER_H
|
||||
#define SERVER_H
|
||||
#include "main.h"
|
||||
#include <main.h>
|
||||
int start_server(void);
|
||||
char *get_welcome_mes(void);
|
||||
void server_main_loop(server_data_t *);
|
||||
@@ -2,8 +2,12 @@ add_library(session STATIC)
|
||||
|
||||
target_link_libraries(session
|
||||
PRIVATE
|
||||
client
|
||||
db
|
||||
user
|
||||
main
|
||||
utils
|
||||
client
|
||||
file_p
|
||||
murmur3
|
||||
OpenSSL::Crypto
|
||||
)
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
/* Copyright (c) 2026 Oleksandr Zhylin */
|
||||
|
||||
#include "session.h"
|
||||
#include "../../client.h"
|
||||
#include "../../file_p.h"
|
||||
#include "../../main.h"
|
||||
#include "../../user.h"
|
||||
#include "../../utils.h"
|
||||
#include <client.h>
|
||||
#include <file_p.h>
|
||||
#include <main.h>
|
||||
#include <user.h>
|
||||
#include <utils.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <db.h>
|
||||
#include <fcntl.h>
|
||||
@@ -94,45 +94,51 @@ int session_do_read(session *sess, char **read_str) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int query_extract_from_buf_2(char *buf, ssize_t *buf_used, char **output_line);
|
||||
|
||||
int query_extract_from_buf(session *sess, char **output_line) {
|
||||
char *line;
|
||||
int pos = -1;
|
||||
// char *line;
|
||||
// int pos = -1;
|
||||
|
||||
if (sess->buf_used > 0) {
|
||||
char *cptr = strchr(sess->buf, '\n');
|
||||
if (cptr != NULL)
|
||||
pos = cptr - sess->buf;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
// if (sess->buf_used > 0) {
|
||||
// char *cptr = strchr(sess->buf, '\n');
|
||||
// if (cptr != NULL)
|
||||
// pos = cptr - sess->buf;
|
||||
// } else {
|
||||
// return 0;
|
||||
// }
|
||||
|
||||
if (pos == -1) {
|
||||
int b_used = sess->buf_used;
|
||||
sess->buf_used = 0;
|
||||
line = malloc(b_used + 1);
|
||||
strncpy(line, sess->buf, b_used);
|
||||
// if (pos == -1) {
|
||||
// int b_used = sess->buf_used;
|
||||
// sess->buf_used = 0;
|
||||
// line = malloc(b_used + 1);
|
||||
// strncpy(line, sess->buf, b_used);
|
||||
|
||||
line[b_used] = 0;
|
||||
// line[b_used] = 0;
|
||||
|
||||
*output_line = line;
|
||||
return b_used;
|
||||
} else {
|
||||
line = malloc(pos + 2);
|
||||
strncpy(line, sess->buf, pos + 1);
|
||||
line[++pos] = 0;
|
||||
sess->buf_used -= (pos);
|
||||
if (!pos)
|
||||
pos++;
|
||||
memmove(sess->buf, sess->buf + pos, sess->buf_used);
|
||||
sess->buf[sess->buf_used] = 0;
|
||||
if (line[pos - 2] == '\r') {
|
||||
line[pos - 2] = line[pos - 1];
|
||||
pos--;
|
||||
line[pos - 1] = 0;
|
||||
}
|
||||
*output_line = line;
|
||||
}
|
||||
return pos + 1;
|
||||
// *output_line = line;
|
||||
// return b_used;
|
||||
// } else {
|
||||
// line = malloc(pos + 2);
|
||||
// strncpy(line, sess->buf, pos + 1);
|
||||
// line[++pos] = 0;
|
||||
// sess->buf_used -= (pos);
|
||||
// if (!pos)
|
||||
// pos++;
|
||||
// memmove(sess->buf, sess->buf + pos, sess->buf_used);
|
||||
// sess->buf[sess->buf_used] = 0;
|
||||
// if (line[pos - 2] == '\r') {
|
||||
// line[pos - 2] = line[pos - 1];
|
||||
// pos--;
|
||||
// line[pos] = 0;
|
||||
// }
|
||||
// *output_line = line;
|
||||
// }
|
||||
// return pos + 1;
|
||||
ssize_t buf_used = sess->buf_used;
|
||||
int ret = query_extract_from_buf_2(sess->buf, &buf_used, output_line);
|
||||
sess->buf_used = buf_used;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int query_extract_from_buf_2(char *buf, ssize_t *buf_used, char **output_line) {
|
||||
@@ -170,7 +176,7 @@ int query_extract_from_buf_2(char *buf, ssize_t *buf_used, char **output_line) {
|
||||
if (line[pos - 2] == '\r') {
|
||||
line[pos - 2] = line[pos - 1];
|
||||
pos--;
|
||||
line[pos - 1] = 0;
|
||||
line[pos] = 0;
|
||||
}
|
||||
*output_line = line;
|
||||
*buf_used = _buf_used;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#ifndef SESSION_H
|
||||
#define SESSION_H
|
||||
#include "../../main.h"
|
||||
#include <main.h>
|
||||
#include <stdio.h>
|
||||
int accept_client(int ls, session *connections[], char *wm);
|
||||
void session_send_string(struct session *sess, const char *str, ...);
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
add_library(user STATIC)
|
||||
|
||||
target_link_libraries(user
|
||||
PRIVATE
|
||||
client
|
||||
db
|
||||
murmur3
|
||||
main
|
||||
session
|
||||
OpenSSL::Crypto
|
||||
)
|
||||
|
||||
target_sources(user
|
||||
PRIVATE
|
||||
user.c
|
||||
PUBLIC
|
||||
FILE_SET HEADERS
|
||||
FILES
|
||||
user.h
|
||||
)
|
||||
@@ -2,8 +2,8 @@
|
||||
/* Copyright (c) 2026 Oleksandr Zhylin */
|
||||
|
||||
#include <db.h>
|
||||
#include "main.h"
|
||||
#include "session.h"
|
||||
#include <main.h>
|
||||
#include <session.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -7,4 +7,7 @@
|
||||
#include "main.h"
|
||||
int login(session *sess, char *pass);
|
||||
int process_user_name(char *uname, session *sess);
|
||||
|
||||
/* Testing */
|
||||
int32_t create_user(session *sess, char *line);
|
||||
#endif
|
||||
@@ -0,0 +1,18 @@
|
||||
add_library(utils STATIC)
|
||||
|
||||
target_link_libraries(utils
|
||||
PRIVATE
|
||||
client
|
||||
db
|
||||
murmur3
|
||||
OpenSSL::Crypto
|
||||
)
|
||||
|
||||
target_sources(utils
|
||||
PRIVATE
|
||||
utils.c
|
||||
PUBLIC
|
||||
FILE_SET HEADERS
|
||||
FILES
|
||||
utils.h
|
||||
)
|
||||
@@ -5,11 +5,15 @@ if (USE_POSTGRESQL)
|
||||
target_link_libraries(db
|
||||
PRIVATE
|
||||
PostgreSQL::PostgreSQL
|
||||
main
|
||||
utils
|
||||
)
|
||||
else()
|
||||
target_link_libraries(db
|
||||
PRIVATE
|
||||
SQLite3::SQLite3
|
||||
main
|
||||
utils
|
||||
)
|
||||
endif()
|
||||
|
||||
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
/* SPDX-License-Identifier: MIT */
|
||||
/* Copyright (c) 2026 Oleksandr Zhylin */
|
||||
|
||||
#include "../main.h"
|
||||
#include "../utils.h"
|
||||
#include <main.h>
|
||||
#include <utils.h>
|
||||
#include "db_common.h"
|
||||
#include <db.h>
|
||||
#include <endian.h>
|
||||
|
||||
+2
-2
@@ -2,8 +2,8 @@
|
||||
/* Copyright (c) 2026 Oleksandr Zhylin */
|
||||
|
||||
#include "main.h"
|
||||
#include "server.h"
|
||||
#include "utils.h"
|
||||
#include <server.h>
|
||||
#include <utils.h>
|
||||
#include <db.h>
|
||||
|
||||
/* *** MAIN *** */
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
#define MAIN_H
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include "types.h"
|
||||
#include <types.h>
|
||||
#define PORT 2000
|
||||
#define MAX_CONNECTIONS 1024
|
||||
#define INBUFSIZE 1024
|
||||
|
||||
Reference in New Issue
Block a user