Move defines from config.h to other header files

This commit is contained in:
Night Kaly 2024-09-18 08:37:34 +01:00
parent fa729a8a45
commit 7e982c0dae
Signed by: night0721
GPG key ID: 957D67B8DB7A119B
5 changed files with 28 additions and 25 deletions

View file

@ -1,25 +1,20 @@
/* Server */ /* Server */
#define DEBUG 0 #define DEBUG 0
#define PORT 20247 #define PORT 20247
#define MAX_NAME 32 /* Max username length */ #define MAX_NAME 32 /* Max username length */
#define DATABASE_NAME "test.db" #define DATABASE_NAME "test.db"
#define MAX_MESSAGE_LENGTH 8192 #define MAX_DATA_LENGTH 8192
/* Don't touch unless you know what you are doing */ /* Don't touch unless you know what you are doing */
#define MAX_CONNECTION_QUEUE 128
#define MAX_THREADS 8 #define MAX_THREADS 8
#define MAX_EVENTS 64 /* Max events can be returned simulataneouly by epoll */
#define MAX_CLIENTS_PER_THREAD 1024 #define MAX_CLIENTS_PER_THREAD 1024
/* Client */ /* Client */
#define DOMAIN "127.0.0.1" #define DOMAIN "127.0.0.1"
/* #define USERNAME "night" */
/* UI */ /* UI */
#define PANEL_HEIGHT 1 #define PANEL_HEIGHT 1
#define DRAW_PREVIEW 1
#define CLIENT_DATA_DIR "~/.local/share/zsm/zen" #define CLIENT_DATA_DIR "~/.local/share/zsm/zen"
/* Keybindings */
#define DOWN 0x102
#define UP 0x103

View file

@ -4,6 +4,6 @@
#include <stdint.h> #include <stdint.h>
#include <libnotify/notify.h> #include <libnotify/notify.h>
void send_notification(uint8_t *content); void send_notification(uint8_t *author, uint8_t *content);
#endif #endif

View file

@ -26,8 +26,6 @@
#include "config.h" #include "config.h"
#define ERROR_LENGTH 26
#define ZSM_TYP_AUTH 0x1 #define ZSM_TYP_AUTH 0x1
#define ZSM_TYP_MESSAGE 0x2 #define ZSM_TYP_MESSAGE 0x2
#define ZSM_TYP_UPDATE_MESSAGE 0x3 #define ZSM_TYP_UPDATE_MESSAGE 0x3
@ -51,32 +49,35 @@
#define ZSM_STA_AUTHORISED 0xE #define ZSM_STA_AUTHORISED 0xE
#define ADDRESS_SIZE MAX_NAME + 1 + 255 /* 1 for @, 255 for domain, defined in RFC 5321, Section 4.5.3.1.2 */ #define ADDRESS_SIZE MAX_NAME + 1 + 255 /* 1 for @, 255 for domain, defined in RFC 5321, Section 4.5.3.1.2 */
#define CHALLENGE_SIZE 32
#define HASH_SIZE crypto_generichash_BYTES #define HASH_SIZE crypto_generichash_BYTES
#define NONCE_SIZE crypto_aead_xchacha20poly1305_ietf_NPUBBYTES #define NONCE_SIZE crypto_aead_xchacha20poly1305_ietf_NPUBBYTES
#define ADDITIONAL_SIZE crypto_aead_xchacha20poly1305_ietf_ABYTES #define ADDITIONAL_SIZE crypto_aead_xchacha20poly1305_ietf_ABYTES
#define MAX_MESSAGE_LENGTH MAX_DATA_LENGTH - MAX_NAME * 2 - NONCE_SIZE
typedef struct packet { typedef struct packet_t {
uint8_t status; uint8_t status;
uint8_t type; uint8_t type;
uint32_t length; uint32_t length;
uint8_t *data; uint8_t *data;
uint8_t *signature; uint8_t *signature;
} packet; } packet_t;
typedef struct message_t {
uint8_t author[MAX_NAME];
uint8_t recipient[MAX_NAME];
uint8_t *content;
time_t creation;
} message_t;
#include "key.h" #include "key.h"
/* Utilities functions */ /* Utilities functions */
void print_packet(packet *msg); void print_packet(packet_t *msg);
int recv_packet(packet *pkt, int fd, uint8_t required_type); int recv_packet(packet_t *pkt, int fd, uint8_t required_type);
packet *create_packet(uint8_t option, uint8_t type, uint32_t length, uint8_t *data, uint8_t *signature); packet_t *create_packet(uint8_t option, uint8_t type, uint32_t length, uint8_t *data, uint8_t *signature);
int send_packet(packet *msg, int fd); int send_packet(packet_t *msg, int fd);
void free_packet(packet *msg); void free_packet(packet_t *msg);
int encrypt_packet(int sockfd, key_pair *kp); int verify_packet(packet_t *pkt, int fd);
packet *verify_packet(packet *pkt, int fd);
uint8_t *encrypt_data(uint8_t *from, uint8_t *to, uint8_t *raw, uint32_t raw_length, uint32_t *length);
uint8_t *decrypt_data(packet *pkt);
int verify_integrity(packet *pkt, public_key *pk);
uint8_t *create_signature(uint8_t *data, uint32_t length, secret_key *sk); uint8_t *create_signature(uint8_t *data, uint32_t length, secret_key *sk);
#endif #endif

8
include/server/server.h Normal file
View file

@ -0,0 +1,8 @@
#ifndef SERVER_H_
#define SERVER_H_
#define CHALLENGE_SIZE 32
#define MAX_CONNECTION_QUEUE 128 /* for listen() */
#define MAX_EVENTS 64 /* Max events can be returned simulataneouly by epoll */
#endif

View file

@ -9,7 +9,6 @@
void error(int fatal, const char *fmt, ...); void error(int fatal, const char *fmt, ...);
void *memalloc(size_t size); void *memalloc(size_t size);
void *estrdup(void *str); void *estrdup(void *str);
int set_nonblocking(int fd);
char *replace_home(char *str); char *replace_home(char *str);
void mkdir_p(const char *destdir); void mkdir_p(const char *destdir);
void write_log(int type, const char *fmt, ...); void write_log(int type, const char *fmt, ...);