merged all public headers into single tcp-chat.h
This commit is contained in:
119
include/tcp-chat.h
Normal file
119
include/tcp-chat.h
Normal file
@@ -0,0 +1,119 @@
|
||||
#pragma once
|
||||
#include "tlibc/errors.h"
|
||||
|
||||
/// requires tlibc and tlibtoml init
|
||||
Result(void) TcpChat_init();
|
||||
void TcpChat_deinit();
|
||||
|
||||
#define USERNAME_SIZE_MIN 2
|
||||
#define USERNAME_SIZE_MAX 31
|
||||
#define PASSWORD_SIZE_MIN 8
|
||||
#define PASSWORD_SIZE_MAX 31
|
||||
#define PASSWORD_HASH_SIZE 32
|
||||
#define HOSTADDR_SIZE_MIN 4
|
||||
#define HOSTADDR_SIZE_MAX 255
|
||||
#define PRIVATE_KEY_BASE64_SIZE_MAX 1724
|
||||
#define PUBLIC_KEY_BASE64_SIZE_MAX 699
|
||||
#define SERVER_NAME_SIZE_MIN 1
|
||||
#define SERVER_NAME_SIZE_MAX 127
|
||||
#define SERVER_DESC_SIZE_MAX 1023
|
||||
#define CHANNEL_NAME_SIZE_MIN 1
|
||||
#define CHANNEL_NAME_SIZE_MAX 127
|
||||
#define CHANNEL_DESC_SIZE_MAX 1023
|
||||
#define MESSAGE_SIZE_MIN 1
|
||||
#define MESSAGE_SIZE_MAX 4000
|
||||
#define MESSAGE_BLOCK_COUNT_MAX 50
|
||||
|
||||
#define MESSAGE_TIMESTAMP_FMT_SQL "%Y.%m.%d-%H:%M:%f"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// Logging //
|
||||
// //
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ErrorCodePage_declare(WINSOCK2);
|
||||
ErrorCodePage_declare(TcpChat);
|
||||
|
||||
typedef enum TcpChatError {
|
||||
TcpChatError_Unknown,
|
||||
TcpChatError_RejectIncoming,
|
||||
} TcpChatError;
|
||||
|
||||
typedef enum LogSeverity {
|
||||
LogSeverity_Debug,
|
||||
LogSeverity_Info,
|
||||
LogSeverity_Warn,
|
||||
LogSeverity_Error,
|
||||
} LogSeverity;
|
||||
|
||||
typedef void (*LogFunction_t)(void* logger, cstr context, LogSeverity severity, cstr msg);
|
||||
|
||||
// requires defined LOGGER, LOG_FUNC, LOG_CONTEXT
|
||||
#define log(severity, format, ...) { \
|
||||
if(LOG_FUNC) { \
|
||||
char* ___log_msg = sprintf_malloc(format ,##__VA_ARGS__); \
|
||||
LOG_FUNC(LOGGER, LOG_CONTEXT, severity, ___log_msg); \
|
||||
free(___log_msg); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define logDebug(format, ...) log(LogSeverity_Debug, format ,##__VA_ARGS__)
|
||||
#define logInfo(format, ...) log(LogSeverity_Info, format ,##__VA_ARGS__)
|
||||
#define logWarn(format, ...) log(LogSeverity_Warn, format ,##__VA_ARGS__)
|
||||
#define logError(format, ...) log(LogSeverity_Error, format ,##__VA_ARGS__)
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// Server //
|
||||
// //
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
typedef struct Server Server;
|
||||
|
||||
/// @param config_file_content config in toml format
|
||||
/// @param config_file_name to use in error messages
|
||||
/// @param logger some shared data for your log function
|
||||
/// @param log_func log function that you have to implement
|
||||
/// @return
|
||||
Result(Server*) Server_create(str config_file_content, cstr config_file_name,
|
||||
void* logger, LogFunction_t log_func);
|
||||
|
||||
void Server_free(Server* server);
|
||||
|
||||
Result(void) Server_run(Server* server);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// Client //
|
||||
// //
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
typedef struct Client Client;
|
||||
|
||||
Result(Client*) Client_create(str username, str password);
|
||||
void Client_free(Client* client);
|
||||
|
||||
/// @return username saved during client initialization
|
||||
str Client_getUserName(Client* client);
|
||||
|
||||
/// @return AES key calculated from password that can be used to encrypt user data
|
||||
Array(u8) Client_getUserDataKey(Client* client);
|
||||
|
||||
/// @param server_addr_cstr ip:port
|
||||
/// @param server_pk_base64 public key encoded by `RSA_serializePublicKey_base64()`
|
||||
Result(void) Client_connect(Client* client, cstr server_addr_cstr, cstr server_pk_base64);
|
||||
/// disconnect from current server
|
||||
void Client_disconnect(Client* client);
|
||||
|
||||
/// @param self connected client
|
||||
/// @param out_str heap-allocated string
|
||||
Result(void) Client_getServerName(Client* self, str* out_str);
|
||||
|
||||
/// @param self connected client
|
||||
/// @param out_str heap-allocated string
|
||||
Result(void) Client_getServerDescription(Client* self, str* out_str);
|
||||
|
||||
/// Create new account on connected server
|
||||
Result(void) Client_register(Client* self, i64* out_user_id);
|
||||
|
||||
/// Authorize on connected server
|
||||
Result(void) Client_login(Client* self, i64* out_user_id, i64* out_landing_channel_id);
|
||||
@@ -1,34 +0,0 @@
|
||||
#pragma once
|
||||
#include "tlibc/errors.h"
|
||||
#include "tlibc/string/str.h"
|
||||
|
||||
typedef struct Client Client;
|
||||
|
||||
Result(Client*) Client_create(str username, str password);
|
||||
void Client_free(Client* client);
|
||||
|
||||
/// @return username saved during client initialization
|
||||
str Client_getUserName(Client* client);
|
||||
|
||||
/// @return AES key calculated from password that can be used to encrypt user data
|
||||
Array(u8) Client_getUserDataKey(Client* client);
|
||||
|
||||
/// @param server_addr_cstr ip:port
|
||||
/// @param server_pk_base64 public key encoded by `RSA_serializePublicKey_base64()`
|
||||
Result(void) Client_connect(Client* client, cstr server_addr_cstr, cstr server_pk_base64);
|
||||
/// disconnect from current server
|
||||
void Client_disconnect(Client* client);
|
||||
|
||||
/// @param self connected client
|
||||
/// @param out_str heap-allocated string
|
||||
Result(void) Client_getServerName(Client* self, str* out_str);
|
||||
|
||||
/// @param self connected client
|
||||
/// @param out_str heap-allocated string
|
||||
Result(void) Client_getServerDescription(Client* self, str* out_str);
|
||||
|
||||
/// Create new account on connected server
|
||||
Result(void) Client_register(Client* self, i64* out_user_id);
|
||||
|
||||
/// Authorize on connected server
|
||||
Result(void) Client_login(Client* self, i64* out_user_id, i64* out_landing_channel_id);
|
||||
@@ -1,21 +0,0 @@
|
||||
#pragma once
|
||||
#include "tlibc/std.h"
|
||||
|
||||
#define USERNAME_SIZE_MIN 2
|
||||
#define USERNAME_SIZE_MAX 31
|
||||
#define PASSWORD_SIZE_MIN 8
|
||||
#define PASSWORD_SIZE_MAX 31
|
||||
#define PASSWORD_HASH_SIZE 32
|
||||
#define HOSTADDR_SIZE_MIN 4
|
||||
#define HOSTADDR_SIZE_MAX 255
|
||||
#define PRIVATE_KEY_BASE64_SIZE_MAX 1724
|
||||
#define PUBLIC_KEY_BASE64_SIZE_MAX 699
|
||||
#define SERVER_NAME_SIZE_MIN 1
|
||||
#define SERVER_NAME_SIZE_MAX 127
|
||||
#define SERVER_DESC_SIZE_MAX 1023
|
||||
#define CHANNEL_NAME_SIZE_MIN 1
|
||||
#define CHANNEL_NAME_SIZE_MAX 127
|
||||
#define CHANNEL_DESC_SIZE_MAX 1023
|
||||
#define MESSAGE_SIZE_MIN 1
|
||||
#define MESSAGE_SIZE_MAX 4000
|
||||
#define MESSAGE_BLOCK_COUNT_MAX 50
|
||||
@@ -1,28 +0,0 @@
|
||||
#pragma once
|
||||
#include <stdio.h>
|
||||
#include "tlibc/std.h"
|
||||
#include "tlibc/string/cstr.h"
|
||||
|
||||
typedef enum LogSeverity {
|
||||
LogSeverity_Debug,
|
||||
LogSeverity_Info,
|
||||
LogSeverity_Warn,
|
||||
LogSeverity_Error,
|
||||
} LogSeverity;
|
||||
|
||||
typedef void (*LogFunction_t)(void* logger, cstr context, LogSeverity severity, cstr msg);
|
||||
|
||||
|
||||
// requires defined LOGGER, LOG_FUNC, LOG_CONTEXT
|
||||
#define log(severity, format, ...) { \
|
||||
if(LOG_FUNC) { \
|
||||
char* ___log_msg = sprintf_malloc(format ,##__VA_ARGS__); \
|
||||
LOG_FUNC(LOGGER, LOG_CONTEXT, severity, ___log_msg); \
|
||||
free(___log_msg); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define logDebug(format, ...) log(LogSeverity_Debug, format ,##__VA_ARGS__)
|
||||
#define logInfo(format, ...) log(LogSeverity_Info, format ,##__VA_ARGS__)
|
||||
#define logWarn(format, ...) log(LogSeverity_Warn, format ,##__VA_ARGS__)
|
||||
#define logError(format, ...) log(LogSeverity_Error, format ,##__VA_ARGS__)
|
||||
@@ -1,18 +0,0 @@
|
||||
#pragma once
|
||||
#include "tlibc/errors.h"
|
||||
#include "tlibc/string/str.h"
|
||||
#include "tcp-chat/log.h"
|
||||
|
||||
typedef struct Server Server;
|
||||
|
||||
/// @param config_file_content config in toml format
|
||||
/// @param config_file_name to use in error messages
|
||||
/// @param logger some shared data for your log function
|
||||
/// @param log_func log function that you have to implement
|
||||
/// @return
|
||||
Result(Server*) Server_create(str config_file_content, cstr config_file_name,
|
||||
void* logger, LogFunction_t log_func);
|
||||
|
||||
void Server_free(Server* server);
|
||||
|
||||
Result(void) Server_run(Server* server);
|
||||
@@ -1,16 +0,0 @@
|
||||
#pragma once
|
||||
#include "tlibc/errors.h"
|
||||
|
||||
/// requires tlibc and tlibtoml init
|
||||
Result(void) TcpChat_init();
|
||||
void TcpChat_deinit();
|
||||
|
||||
ErrorCodePage_declare(WINSOCK2);
|
||||
ErrorCodePage_declare(TcpChat);
|
||||
|
||||
typedef enum TcpChatError {
|
||||
TcpChatError_Unknown,
|
||||
TcpChatError_RejectIncoming,
|
||||
} TcpChatError;
|
||||
|
||||
#define MESSAGE_TIMESTAMP_FMT_SQL "%Y.%m.%d-%H:%M:%f"
|
||||
@@ -1,7 +1,6 @@
|
||||
#include "ClientCLI.h"
|
||||
#include "tlibc/filesystem.h"
|
||||
#include "tlibc/term.h"
|
||||
#include "tcp-chat/common_constants.h"
|
||||
#include "cli/ClientCLI/ClientCLI.h"
|
||||
#include "network/tcp-chat-protocol/v1.h"
|
||||
|
||||
static const str greeting_art = STR(
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
#include <pthread.h>
|
||||
#include "tcp-chat.h"
|
||||
#include "tlibc/collections/HashMap.h"
|
||||
#include "tlibc/collections/List.h"
|
||||
#include "tcp-chat/client.h"
|
||||
#include "db/client_db.h"
|
||||
|
||||
typedef struct ClientCLI {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#pragma once
|
||||
#include "tcp-chat/tcp-chat.h"
|
||||
#include "tcp-chat.h"
|
||||
#include "tsqlite.h"
|
||||
#include "network/tcp-chat-protocol/v1.h"
|
||||
#include "tlibc/collections/List.h"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "tcp-chat.h"
|
||||
#include "tlibc/tlibc.h"
|
||||
#include "tlibtoml.h"
|
||||
#include "tcp-chat/tcp-chat.h"
|
||||
#include "cryptography/RSA.h"
|
||||
#include "cli/modes/modes.h"
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#include <pthread.h>
|
||||
#include "tcp-chat.h"
|
||||
#include "modes.h"
|
||||
#include "tcp-chat/server.h"
|
||||
#include "tlibc/time.h"
|
||||
#include "tlibc/term.h"
|
||||
#include <pthread.h>
|
||||
|
||||
typedef struct ServerLogger {
|
||||
pthread_mutex_t mutex;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#pragma once
|
||||
#include "tcp-chat/client.h"
|
||||
#include "tcp-chat.h"
|
||||
#include "cryptography/AES.h"
|
||||
#include "cryptography/RSA.h"
|
||||
#include "network/encrypted_sockets.h"
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
#pragma once
|
||||
#include "tlibc/errors.h"
|
||||
#include "tcp-chat.h"
|
||||
#include "tlibc/collections/Array.h"
|
||||
#include "tlibc/collections/Array_impl/Array_u8.h"
|
||||
#include "bearssl_rand.h"
|
||||
#include "bearssl_hash.h"
|
||||
#include "tcp-chat/common_constants.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#pragma once
|
||||
#include "tcp-chat/tcp-chat.h"
|
||||
#include "tcp-chat.h"
|
||||
#include "endpoint.h"
|
||||
|
||||
#if !defined(KN_USE_WINSOCK)
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
#include "tlibc/errors.h"
|
||||
#include "tcp-chat.h"
|
||||
#include "tlibc/magic.h"
|
||||
#include "tcp-chat/common_constants.h"
|
||||
|
||||
#define AES_SESSION_KEY_SIZE 32
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#pragma once
|
||||
#include "tlibc/errors.h"
|
||||
#include "tlibc/string/str.h"
|
||||
#include "tcp-chat.h"
|
||||
#include "tlibc/time.h"
|
||||
#include "network/tcp-chat-protocol/constant.h"
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#pragma once
|
||||
#include "tcp-chat/tcp-chat.h"
|
||||
#include "tcp-chat.h"
|
||||
#include "tsqlite.h"
|
||||
#include "network/tcp-chat-protocol/v1.h"
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#pragma once
|
||||
#include "tcp-chat/tcp-chat.h"
|
||||
#include "tcp-chat/server.h"
|
||||
#include "tcp-chat.h"
|
||||
#include "cryptography/AES.h"
|
||||
#include "cryptography/RSA.h"
|
||||
#include "network/encrypted_sockets.h"
|
||||
|
||||
Reference in New Issue
Block a user