Compare commits
4 Commits
f4c3345445
...
63b1ca5d6a
Author | SHA1 | Date | |
---|---|---|---|
63b1ca5d6a | |||
54313551fc | |||
92779e5dba | |||
100eb1597d |
77
Makefile
77
Makefile
@@ -5,22 +5,69 @@ LIBS=-lssl -lcrypto -lmagic -lz -lmaxminddb -lbrotlienc
|
|||||||
|
|
||||||
DEBIAN_OPTS=-D CACHE_MAGIC_FILE="\"/usr/share/file/magic.mgc\"" -D PHP_FPM_SOCKET="\"/var/run/php/php7.4-fpm.sock\""
|
DEBIAN_OPTS=-D CACHE_MAGIC_FILE="\"/usr/share/file/magic.mgc\"" -D PHP_FPM_SOCKET="\"/var/run/php/php7.4-fpm.sock\""
|
||||||
|
|
||||||
packages:
|
.PHONY: all prod debug default permit clean
|
||||||
@echo "Installing packages..."
|
all: prod
|
||||||
sudo apt install gcc php-fpm libmagic-dev libssl-dev libmaxminddb-dev
|
default: bin bin/lib bin/libsesimos.so bin/sesimos
|
||||||
@echo "Finished downloading!"
|
prod: CFLAGS += -O3
|
||||||
|
prod: default
|
||||||
|
debug: default
|
||||||
|
|
||||||
|
|
||||||
|
bin:
|
||||||
|
mkdir -p bin
|
||||||
|
|
||||||
|
bin/lib:
|
||||||
|
mkdir -p bin/lib
|
||||||
|
|
||||||
|
|
||||||
|
bin/%.o: src/%.c
|
||||||
|
$(CC) -c -o $@ $(CFLAGS) $<
|
||||||
|
|
||||||
|
bin/lib/%.o: src/lib/%.c
|
||||||
|
$(CC) -c -o $@ $(CFLAGS) -fPIC $<
|
||||||
|
|
||||||
|
bin/libsesimos.so: bin/lib/cache.o bin/lib/compress.o bin/lib/config.o bin/lib/fastcgi.o bin/lib/geoip.o \
|
||||||
|
bin/lib/http.o bin/lib/http_static.o bin/lib/rev_proxy.o bin/lib/sock.o bin/lib/uri.o \
|
||||||
|
bin/lib/utils.o bin/lib/websocket.o
|
||||||
|
$(CC) -o $@ --shared -fPIC $(CFLAGS) $(LIBS) $^
|
||||||
|
|
||||||
|
bin/sesimos: bin/server.o bin/client.o
|
||||||
|
$(CC) -o $@ $^ $(LIBS) -Lbin -lsesimos -Wl,-rpath=$(shell pwd)/bin
|
||||||
|
|
||||||
|
|
||||||
|
bin/server.o: src/server.c src/server.h src/defs.h src/client.h src/lib/cache.h src/lib/config.h src/lib/sock.h \
|
||||||
|
src/lib/rev_proxy.h src/lib/geoip.h src/lib/utils.h
|
||||||
|
|
||||||
|
bin/client.o: src/client.c src/client.h src/defs.h src/server.h src/lib/utils.h src/lib/config.h src/lib/sock.h \
|
||||||
|
src/lib/http.h src/lib/rev_proxy.h src/lib/fastcgi.h src/lib/cache.h src/lib/geoip.h src/lib/compress.h \
|
||||||
|
src/lib/websocket.h
|
||||||
|
|
||||||
|
bin/lib/cache.o: src/lib/cache.c src/lib/cache.h src/lib/utils.h src/lib/uri.h src/lib/compress.h
|
||||||
|
|
||||||
|
bin/lib/compress.o: src/lib/compress.c src/lib/compress.h
|
||||||
|
|
||||||
|
bin/lib/config.o: src/lib/config.c src/lib/config.h src/lib/utils.h src/lib/uri.h
|
||||||
|
|
||||||
|
bin/lib/fastcgi.o: src/lib/fastcgi.c src/lib/fastcgi.h src/server.h src/lib/utils.h src/lib/compress.h src/lib/http.h \
|
||||||
|
src/lib/uri.h src/lib/include/fastcgi.h
|
||||||
|
|
||||||
|
bin/lib/geoip.o: src/lib/geoip.c src/lib/geoip.h
|
||||||
|
|
||||||
|
bin/lib/http.o: src/lib/http.c src/lib/http.h src/lib/utils.h src/lib/compress.h src/lib/sock.h
|
||||||
|
|
||||||
|
bin/lib/rev_proxy.o: src/lib/rev_proxy.c src/lib/rev_proxy.h src/defs.h src/server.h src/lib/compress.h
|
||||||
|
|
||||||
|
bin/lib/sock.o: src/lib/sock.c src/lib/sock.h
|
||||||
|
|
||||||
|
bin/lib/uri.o: src/lib/uri.c src/lib/uri.h src/lib/utils.h
|
||||||
|
|
||||||
|
bin/lib/utils.o: src/lib/utils.c src/lib/utils.h
|
||||||
|
|
||||||
|
bin/lib/websocket.o: src/lib/websocket.c src/lib/websocket.h src/defs.h src/lib/utils.h src/lib/sock.h
|
||||||
|
|
||||||
|
|
||||||
permit:
|
permit:
|
||||||
sudo setcap 'cap_net_bind_service=+ep' "$(shell pwd)/bin/sesimos"
|
sudo setcap 'cap_net_bind_service=+ep' "$(shell pwd)/bin/sesimos"
|
||||||
|
|
||||||
compile:
|
clean:
|
||||||
@mkdir -p bin
|
rm -rf sesimos bin/*
|
||||||
$(CC) src/lib/*.c -o bin/libsesimos.so --shared -fPIC $(CFLAGS) $(LIBS)
|
|
||||||
$(CC) src/server.c src/client.c -o bin/sesimos $(CFLAGS) $(LIBS) \
|
|
||||||
-Lbin -lsesimos -Wl,-rpath=$(shell pwd)/bin
|
|
||||||
|
|
||||||
compile-prod:
|
|
||||||
@mkdir -p bin
|
|
||||||
$(CC) src/lib/*.c -o bin/libsesimos.so --shared -fPIC $(CFLAGS) $(LIBS) $(DEBIAN_OPTS) -O3
|
|
||||||
$(CC) src/server.c src/client.c -o bin/sesimos $(CFLAGS) $(LIBS) $(DEBIAN_OPTS) -O3 \
|
|
||||||
-Lbin -lsesimos -Wl,-rpath=$(shell pwd)/bin
|
|
||||||
|
11
src/client.c
11
src/client.c
@@ -1,8 +1,9 @@
|
|||||||
/**
|
/**
|
||||||
* sesimos - secure, simple, modern web server
|
* sesimos - secure, simple, modern web server
|
||||||
* Client connection and request handlers
|
* @brief Client connection and request handlers
|
||||||
* src/client.c
|
* @file src/client.c
|
||||||
* Lorenz Stechauner, 2020-12-03
|
* @author Lorenz Stechauner
|
||||||
|
* @date 2020-12-03
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "defs.h"
|
#include "defs.h"
|
||||||
@@ -29,7 +30,7 @@
|
|||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
|
|
||||||
|
|
||||||
int server_keep_alive = 1;
|
volatile sig_atomic_t server_keep_alive = 1;
|
||||||
struct timeval client_timeout = {.tv_sec = CLIENT_TIMEOUT, .tv_usec = 0};
|
struct timeval client_timeout = {.tv_sec = CLIENT_TIMEOUT, .tv_usec = 0};
|
||||||
|
|
||||||
char *log_client_prefix, *log_conn_prefix, *log_req_prefix, *client_geoip;
|
char *log_client_prefix, *log_conn_prefix, *log_req_prefix, *client_geoip;
|
||||||
@@ -48,7 +49,7 @@ host_config *get_host_config(const char *host) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void client_terminate() {
|
void client_terminate(int _) {
|
||||||
server_keep_alive = 0;
|
server_keep_alive = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,8 +1,9 @@
|
|||||||
/**
|
/**
|
||||||
* sesimos - secure, simple, modern web server
|
* sesimos - secure, simple, modern web server
|
||||||
* Client connection and request handlers (header file)
|
* @brief Client connection and request handlers (header file)
|
||||||
* src/client.h
|
* @file src/client.h
|
||||||
* Lorenz Stechauner, 2022-08-16
|
* @author Lorenz Stechauner
|
||||||
|
* @date 2022-08-16
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef SESIMOS_CLIENT_H
|
#ifndef SESIMOS_CLIENT_H
|
||||||
|
@@ -1,8 +1,9 @@
|
|||||||
/**
|
/**
|
||||||
* sesimos - secure, simple, modern web server
|
* sesimos - secure, simple, modern web server
|
||||||
* Definitions
|
* @brief Definitions
|
||||||
* src/defs.h
|
* @file src/defs.h
|
||||||
* Lorenz Stechauner, 2021-05-04
|
* @author Lorenz Stechauner
|
||||||
|
* @date 2021-05-04
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef SESIMOS_DEF_H
|
#ifndef SESIMOS_DEF_H
|
||||||
|
@@ -1,8 +1,9 @@
|
|||||||
/**
|
/**
|
||||||
* sesimos - secure, simple, modern web server
|
* sesimos - secure, simple, modern web server
|
||||||
* File cache implementation
|
* @brief File cache implementation
|
||||||
* src/lib/cache.c
|
* @file src/lib/cache.c
|
||||||
* Lorenz Stechauner, 2020-12-19
|
* @author Lorenz Stechauner
|
||||||
|
* @date 2020-12-19
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "cache.h"
|
#include "cache.h"
|
||||||
@@ -24,7 +25,7 @@ int cache_continue = 1;
|
|||||||
magic_t magic;
|
magic_t magic;
|
||||||
cache_entry *cache;
|
cache_entry *cache;
|
||||||
|
|
||||||
int magic_init() {
|
int magic_init(void) {
|
||||||
magic = magic_open(MAGIC_MIME);
|
magic = magic_open(MAGIC_MIME);
|
||||||
if (magic == NULL) {
|
if (magic == NULL) {
|
||||||
fprintf(stderr, ERR_STR "Unable to open magic cookie: %s" CLR_STR "\n", strerror(errno));
|
fprintf(stderr, ERR_STR "Unable to open magic cookie: %s" CLR_STR "\n", strerror(errno));
|
||||||
@@ -37,11 +38,11 @@ int magic_init() {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void cache_process_term() {
|
void cache_process_term(int _) {
|
||||||
cache_continue = 0;
|
cache_continue = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int cache_process() {
|
int cache_process(void) {
|
||||||
signal(SIGINT, cache_process_term);
|
signal(SIGINT, cache_process_term);
|
||||||
signal(SIGTERM, cache_process_term);
|
signal(SIGTERM, cache_process_term);
|
||||||
|
|
||||||
@@ -221,7 +222,7 @@ int cache_process() {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int cache_init() {
|
int cache_init(void) {
|
||||||
if (magic_init() != 0) {
|
if (magic_init() != 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -267,7 +268,7 @@ int cache_init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int cache_unload() {
|
int cache_unload(void) {
|
||||||
int shm_id = shmget(CACHE_SHM_KEY, 0, 0);
|
int shm_id = shmget(CACHE_SHM_KEY, 0, 0);
|
||||||
if (shm_id < 0) {
|
if (shm_id < 0) {
|
||||||
fprintf(stderr, ERR_STR "Unable to get cache shared memory id: %s" CLR_STR "\n", strerror(errno));
|
fprintf(stderr, ERR_STR "Unable to get cache shared memory id: %s" CLR_STR "\n", strerror(errno));
|
||||||
|
@@ -1,8 +1,9 @@
|
|||||||
/**
|
/**
|
||||||
* sesimos - secure, simple, modern web server
|
* sesimos - secure, simple, modern web server
|
||||||
* File cache implementation (header file)
|
* @brief File cache implementation (header file)
|
||||||
* src/lib/cache.h
|
* @file src/lib/cache.h
|
||||||
* Lorenz Stechauner, 2020-12-19
|
* @author Lorenz Stechauner
|
||||||
|
* @date 2020-12-19
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef SESIMOS_CACHE_H
|
#ifndef SESIMOS_CACHE_H
|
||||||
@@ -30,15 +31,15 @@ extern cache_entry *cache;
|
|||||||
|
|
||||||
extern int cache_continue;
|
extern int cache_continue;
|
||||||
|
|
||||||
int magic_init();
|
int magic_init(void);
|
||||||
|
|
||||||
void cache_process_term();
|
void cache_process_term(int _);
|
||||||
|
|
||||||
int cache_process();
|
int cache_process(void);
|
||||||
|
|
||||||
int cache_init();
|
int cache_init(void);
|
||||||
|
|
||||||
int cache_unload();
|
int cache_unload(void);
|
||||||
|
|
||||||
int cache_update_entry(int entry_num, const char *filename, const char *webroot);
|
int cache_update_entry(int entry_num, const char *filename, const char *webroot);
|
||||||
|
|
||||||
|
@@ -1,8 +1,9 @@
|
|||||||
/**
|
/**
|
||||||
* sesimos - secure, simple, modern web server
|
* sesimos - secure, simple, modern web server
|
||||||
* Compression interface
|
* @brief Compression interface
|
||||||
* src/lib/compress.c
|
* @file src/lib/compress.c
|
||||||
* Lorenz Stechauner, 2021-05-05
|
* @author Lorenz Stechauner
|
||||||
|
* @date 2021-05-05
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "compress.h"
|
#include "compress.h"
|
||||||
|
@@ -1,8 +1,9 @@
|
|||||||
/**
|
/**
|
||||||
* sesimos - secure, simple, modern web server
|
* sesimos - secure, simple, modern web server
|
||||||
* Compression interface (header file)
|
* @brief Compression interface (header file)
|
||||||
* src/lib/compress.h
|
* @file src/lib/compress.h
|
||||||
* Lorenz Stechauner, 2021-05-05
|
* @author Lorenz Stechauner
|
||||||
|
* @date 2021-05-05
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef SESIMOS_COMPRESS_H
|
#ifndef SESIMOS_COMPRESS_H
|
||||||
|
@@ -1,8 +1,9 @@
|
|||||||
/**
|
/**
|
||||||
* sesimos - secure, simple, modern web server
|
* sesimos - secure, simple, modern web server
|
||||||
* Configuration file loader
|
* @brief Configuration file loader
|
||||||
* src/lib/config.c
|
* @file src/lib/config.c
|
||||||
* Lorenz Stechauner, 2021-01-05
|
* @author Lorenz Stechauner
|
||||||
|
* @date 2021-01-05
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
@@ -19,7 +20,7 @@
|
|||||||
t_config *config;
|
t_config *config;
|
||||||
char geoip_dir[256], dns_server[256];
|
char geoip_dir[256], dns_server[256];
|
||||||
|
|
||||||
int config_init() {
|
int config_init(void) {
|
||||||
int shm_id = shmget(CONFIG_SHM_KEY, sizeof(t_config), IPC_CREAT | IPC_EXCL | 0640);
|
int shm_id = shmget(CONFIG_SHM_KEY, sizeof(t_config), IPC_CREAT | IPC_EXCL | 0640);
|
||||||
if (shm_id < 0) {
|
if (shm_id < 0) {
|
||||||
fprintf(stderr, ERR_STR "Unable to create config shared memory: %s" CLR_STR "\n", strerror(errno));
|
fprintf(stderr, ERR_STR "Unable to create config shared memory: %s" CLR_STR "\n", strerror(errno));
|
||||||
@@ -45,7 +46,7 @@ int config_init() {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int config_unload() {
|
int config_unload(void) {
|
||||||
int shm_id = shmget(CONFIG_SHM_KEY, 0, 0);
|
int shm_id = shmget(CONFIG_SHM_KEY, 0, 0);
|
||||||
if (shm_id < 0) {
|
if (shm_id < 0) {
|
||||||
fprintf(stderr, ERR_STR "Unable to get config shared memory id: %s" CLR_STR "\n", strerror(errno));
|
fprintf(stderr, ERR_STR "Unable to get config shared memory id: %s" CLR_STR "\n", strerror(errno));
|
||||||
|
@@ -1,8 +1,9 @@
|
|||||||
/**
|
/**
|
||||||
* sesimos - secure, simple, modern web server
|
* sesimos - secure, simple, modern web server
|
||||||
* Configuration file loader (header file)
|
* @brief Configuration file loader (header file)
|
||||||
* src/lib/config.h
|
* @file src/lib/config.h
|
||||||
* Lorenz Stechauner, 2021-01-05
|
* @author Lorenz Stechauner
|
||||||
|
* @date 2021-01-05
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef SESIMOS_CONFIG_H
|
#ifndef SESIMOS_CONFIG_H
|
||||||
@@ -55,10 +56,10 @@ typedef struct {
|
|||||||
extern t_config *config;
|
extern t_config *config;
|
||||||
extern char geoip_dir[256], dns_server[256];
|
extern char geoip_dir[256], dns_server[256];
|
||||||
|
|
||||||
int config_init();
|
int config_init(void);
|
||||||
|
|
||||||
int config_load(const char *filename);
|
int config_load(const char *filename);
|
||||||
|
|
||||||
int config_unload();
|
int config_unload(void);
|
||||||
|
|
||||||
#endif //SESIMOS_CONFIG_H
|
#endif //SESIMOS_CONFIG_H
|
||||||
|
@@ -1,8 +1,9 @@
|
|||||||
/**
|
/**
|
||||||
* sesimos - secure, simple, modern web server
|
* sesimos - secure, simple, modern web server
|
||||||
* FastCGI interface implementation
|
* @brief FastCGI interface implementation
|
||||||
* src/lib/fastcgi.c
|
* @file src/lib/fastcgi.c
|
||||||
* Lorenz Stechauner, 2020-12-26
|
* @author Lorenz Stechauner
|
||||||
|
* @date 2020-12-26
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "fastcgi.h"
|
#include "fastcgi.h"
|
||||||
|
@@ -1,8 +1,9 @@
|
|||||||
/**
|
/**
|
||||||
* sesimos - secure, simple, modern web server
|
* sesimos - secure, simple, modern web server
|
||||||
* FastCGI interface implementation (header file)
|
* @brief FastCGI interface implementation (header file)
|
||||||
* src/lib/fastcgi.h
|
* @file src/lib/fastcgi.h
|
||||||
* Lorenz Stechauner, 2020-12-26
|
* @author Lorenz Stechauner
|
||||||
|
* @date 2020-12-26
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef SESIMOS_FASTCGI_H
|
#ifndef SESIMOS_FASTCGI_H
|
||||||
|
@@ -1,8 +1,9 @@
|
|||||||
/**
|
/**
|
||||||
* sesimos - secure, simple, modern web server
|
* sesimos - secure, simple, modern web server
|
||||||
* MaxMind GeoIP Database interface
|
* @brief MaxMind GeoIP Database interface
|
||||||
* src/lib/geoip.c
|
* @file src/lib/geoip.c
|
||||||
* Lorenz Stechauner, 2021-05-04
|
* @author Lorenz Stechauner
|
||||||
|
* @date 2021-05-04
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "geoip.h"
|
#include "geoip.h"
|
||||||
|
@@ -1,8 +1,9 @@
|
|||||||
/**
|
/**
|
||||||
* sesimos - secure, simple, modern web server
|
* sesimos - secure, simple, modern web server
|
||||||
* MaxMind GeoIP Database interface (header file)
|
* @brief MaxMind GeoIP Database interface (header file)
|
||||||
* src/lib/geoip.h
|
* @file src/lib/geoip.h
|
||||||
* Lorenz Stechauner, 2021-05-04
|
* @author Lorenz Stechauner
|
||||||
|
* @date 2021-05-04
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
@@ -1,8 +1,9 @@
|
|||||||
/**
|
/**
|
||||||
* sesimos - secure, simple, modern web server
|
* sesimos - secure, simple, modern web server
|
||||||
* HTTP implementation
|
* @brief HTTP implementation
|
||||||
* src/lib/http.c
|
* @file src/lib/http.c
|
||||||
* Lorenz Stechauner, 2020-12-09
|
* @author Lorenz Stechauner
|
||||||
|
* @date 2020-12-09
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "http.h"
|
#include "http.h"
|
||||||
|
@@ -1,8 +1,9 @@
|
|||||||
/**
|
/**
|
||||||
* sesimos - secure, simple, modern web server
|
* sesimos - secure, simple, modern web server
|
||||||
* HTTP implementation (header file)
|
* @brief HTTP implementation (header file)
|
||||||
* src/lib/http.h
|
* @file src/lib/http.h
|
||||||
* Lorenz Stechauner, 2020-12-09
|
* @author Lorenz Stechauner
|
||||||
|
* @date 2020-12-09
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef SESIMOS_HTTP_H
|
#ifndef SESIMOS_HTTP_H
|
||||||
|
@@ -1,8 +1,9 @@
|
|||||||
/**
|
/**
|
||||||
* sesimos - secure, simple, modern web server
|
* sesimos - secure, simple, modern web server
|
||||||
* HTTP static implementation
|
* @brief HTTP static implementation
|
||||||
* src/lib/http_static.c
|
* @file src/lib/http_static.c
|
||||||
* Lorenz Stechauner, 2021-05-03
|
* @author Lorenz Stechauner
|
||||||
|
* @date 2021-05-03
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../defs.h"
|
#include "../defs.h"
|
||||||
|
@@ -1,8 +1,7 @@
|
|||||||
/**
|
/**
|
||||||
* sesimos - secure, simple, modern web server
|
* sesimos - secure, simple, modern web server
|
||||||
* FastCGI header file
|
* @brief FastCGI header file
|
||||||
* src/lib/include/fastcgi.h
|
* @file src/lib/include/fastcgi.h
|
||||||
* Lorenz Stechauner, 2021-05-03
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef SESIMOS_EXTERN_FASTCGI_H
|
#ifndef SESIMOS_EXTERN_FASTCGI_H
|
||||||
|
@@ -1,8 +1,9 @@
|
|||||||
/**
|
/**
|
||||||
* sesimos - secure, simple, modern web server
|
* sesimos - secure, simple, modern web server
|
||||||
* Reverse proxy
|
* @brief Reverse proxy
|
||||||
* src/lib/rev_proxy.c
|
* @file src/lib/rev_proxy.c
|
||||||
* Lorenz Stechauner, 2021-01-07
|
* @author Lorenz Stechauner
|
||||||
|
* @date 2021-01-07
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../defs.h"
|
#include "../defs.h"
|
||||||
@@ -23,7 +24,7 @@ sock rev_proxy;
|
|||||||
char *rev_proxy_host = NULL;
|
char *rev_proxy_host = NULL;
|
||||||
struct timeval server_timeout = {.tv_sec = SERVER_TIMEOUT, .tv_usec = 0};
|
struct timeval server_timeout = {.tv_sec = SERVER_TIMEOUT, .tv_usec = 0};
|
||||||
|
|
||||||
int rev_proxy_preload() {
|
int rev_proxy_preload(void) {
|
||||||
rev_proxy.buf = NULL;
|
rev_proxy.buf = NULL;
|
||||||
rev_proxy.buf_len = 0;
|
rev_proxy.buf_len = 0;
|
||||||
rev_proxy.buf_off = 0;
|
rev_proxy.buf_off = 0;
|
||||||
|
@@ -1,8 +1,9 @@
|
|||||||
/**
|
/**
|
||||||
* sesimos - secure, simple, modern web server
|
* sesimos - secure, simple, modern web server
|
||||||
* Reverse proxy (header file)
|
* @brief Reverse proxy (header file)
|
||||||
* src/lib/rev_proxy.h
|
* @file src/lib/rev_proxy.h
|
||||||
* Lorenz Stechauner, 2021-01-07
|
* @author Lorenz Stechauner
|
||||||
|
* @date 2021-01-07
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef SESIMOS_REV_PROXY_H
|
#ifndef SESIMOS_REV_PROXY_H
|
||||||
@@ -22,7 +23,7 @@
|
|||||||
|
|
||||||
extern sock rev_proxy;
|
extern sock rev_proxy;
|
||||||
|
|
||||||
int rev_proxy_preload();
|
int rev_proxy_preload(void);
|
||||||
|
|
||||||
int rev_proxy_request_header(http_req *req, int enc);
|
int rev_proxy_request_header(http_req *req, int enc);
|
||||||
|
|
||||||
|
@@ -1,8 +1,9 @@
|
|||||||
/**
|
/**
|
||||||
* sesimos - secure, simple, modern web server
|
* sesimos - secure, simple, modern web server
|
||||||
* Basic TCP and TLS socket
|
* @brief Basic TCP and TLS socket
|
||||||
* src/lib/sock.c
|
* @file src/lib/sock.c
|
||||||
* Lorenz Stechauner, 2021-01-07
|
* @author Lorenz Stechauner
|
||||||
|
* @date 2021-01-07
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "sock.h"
|
#include "sock.h"
|
||||||
|
@@ -1,8 +1,9 @@
|
|||||||
/**
|
/**
|
||||||
* sesimos - secure, simple, modern web server
|
* sesimos - secure, simple, modern web server
|
||||||
* Basic TCP and TLS socket (header file)
|
* @brief Basic TCP and TLS socket (header file)
|
||||||
* src/lib/sock.h
|
* @file src/lib/sock.h
|
||||||
* Lorenz Stechauner, 2021-01-07
|
* @author Lorenz Stechauner
|
||||||
|
* @date 2021-01-07
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef SESIMOS_SOCK_H
|
#ifndef SESIMOS_SOCK_H
|
||||||
|
@@ -1,8 +1,9 @@
|
|||||||
/**
|
/**
|
||||||
* sesimos - secure, simple, modern web server
|
* sesimos - secure, simple, modern web server
|
||||||
* URI and path handlers
|
* @brief URI and path handlers
|
||||||
* src/lib/uri.c
|
* @file src/lib/uri.c
|
||||||
* Lorenz Stechauner, 2020-12-13
|
* @author Lorenz Stechauner
|
||||||
|
* @date 2020-12-13
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "uri.h"
|
#include "uri.h"
|
||||||
|
@@ -1,8 +1,9 @@
|
|||||||
/**
|
/**
|
||||||
* sesimos - secure, simple, modern web server
|
* sesimos - secure, simple, modern web server
|
||||||
* URI and path handlers (header file)
|
* @brief URI and path handlers (header file)
|
||||||
* src/lib/uri.h
|
* @file src/lib/uri.h
|
||||||
* Lorenz Stechauner, 2020-12-13
|
* @author Lorenz Stechauner
|
||||||
|
* @date 2020-12-13
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef SESIMOS_URI_H
|
#ifndef SESIMOS_URI_H
|
||||||
|
@@ -1,8 +1,9 @@
|
|||||||
/**
|
/**
|
||||||
* sesimos - secure, simple, modern web server
|
* sesimos - secure, simple, modern web server
|
||||||
* Utilities
|
* @brief Utilities
|
||||||
* src/lib/utils.c
|
* @file src/lib/utils.c
|
||||||
* Lorenz Stechauner, 2020-12-03
|
* @author Lorenz Stechauner
|
||||||
|
* @date 2020-12-03
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
@@ -1,8 +1,9 @@
|
|||||||
/**
|
/**
|
||||||
* sesimos - secure, simple, modern web server
|
* sesimos - secure, simple, modern web server
|
||||||
* Utilities (header file)
|
* @brief Utilities (header file)
|
||||||
* src/lib/utils.h
|
* @file src/lib/utils.h
|
||||||
* Lorenz Stechauner, 2020-12-03
|
* @author Lorenz Stechauner
|
||||||
|
* @date 2020-12-03
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef SESIMOS_UTILS_H
|
#ifndef SESIMOS_UTILS_H
|
||||||
|
@@ -1,8 +1,9 @@
|
|||||||
/**
|
/**
|
||||||
* sesimos - secure, simple, modern web server
|
* sesimos - secure, simple, modern web server
|
||||||
* WebSocket reverse proxy
|
* @brief WebSocket reverse proxy
|
||||||
* src/lib/websocket.c
|
* @file src/lib/websocket.c
|
||||||
* Lorenz Stechauner, 2022-08-16
|
* @author Lorenz Stechauner
|
||||||
|
* @date 2022-08-16
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../defs.h"
|
#include "../defs.h"
|
||||||
@@ -15,9 +16,9 @@
|
|||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
|
|
||||||
int terminate = 0;
|
volatile sig_atomic_t terminate = 0;
|
||||||
|
|
||||||
void ws_terminate() {
|
void ws_terminate(int _) {
|
||||||
terminate = 1;
|
terminate = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,8 +1,9 @@
|
|||||||
/**
|
/**
|
||||||
* sesimos - secure, simple, modern web server
|
* sesimos - secure, simple, modern web server
|
||||||
* WebSocket reverse proxy (header file)
|
* @brief WebSocket reverse proxy (header file)
|
||||||
* src/lib/websocket.h
|
* @file src/lib/websocket.h
|
||||||
* Lorenz Stechauner, 2022-08-16
|
* @author Lorenz Stechauner
|
||||||
|
* @date 2022-08-16
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef SESIMOS_WEBSOCKET_H
|
#ifndef SESIMOS_WEBSOCKET_H
|
||||||
|
17
src/server.c
17
src/server.c
@@ -1,8 +1,9 @@
|
|||||||
/**
|
/**
|
||||||
* Sesimos - secure, simple, modern web server
|
* Sesimos - secure, simple, modern web server
|
||||||
* Main executable
|
* @brief Main executable
|
||||||
* src/server.c
|
* @file src/server.c
|
||||||
* Lorenz Stechauner, 2020-12-03
|
* @author Lorenz Stechauner
|
||||||
|
* @date 2020-12-03
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define _POSIX_C_SOURCE 199309L
|
#define _POSIX_C_SOURCE 199309L
|
||||||
@@ -35,14 +36,14 @@
|
|||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
|
|
||||||
|
|
||||||
int active = 1;
|
volatile sig_atomic_t active = 1;
|
||||||
const char *config_file;
|
const char *config_file;
|
||||||
int sockets[NUM_SOCKETS];
|
int sockets[NUM_SOCKETS];
|
||||||
pid_t children[MAX_CHILDREN];
|
pid_t children[MAX_CHILDREN];
|
||||||
MMDB_s mmdbs[MAX_MMDB];
|
MMDB_s mmdbs[MAX_MMDB];
|
||||||
SSL_CTX *contexts[CONFIG_MAX_CERT_CONFIG];
|
SSL_CTX *contexts[CONFIG_MAX_CERT_CONFIG];
|
||||||
|
|
||||||
void openssl_init() {
|
void openssl_init(void) {
|
||||||
SSL_library_init();
|
SSL_library_init();
|
||||||
SSL_load_error_strings();
|
SSL_load_error_strings();
|
||||||
ERR_load_BIO_strings();
|
ERR_load_BIO_strings();
|
||||||
@@ -58,7 +59,7 @@ static int ssl_servername_cb(SSL *ssl, int *ad, void *arg) {
|
|||||||
return SSL_TLSEXT_ERR_OK;
|
return SSL_TLSEXT_ERR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void destroy() {
|
void destroy(int _) {
|
||||||
fprintf(stderr, "\n" ERR_STR "Terminating forcefully!" CLR_STR "\n");
|
fprintf(stderr, "\n" ERR_STR "Terminating forcefully!" CLR_STR "\n");
|
||||||
int status = 0;
|
int status = 0;
|
||||||
int ret;
|
int ret;
|
||||||
@@ -87,7 +88,7 @@ void destroy() {
|
|||||||
exit(2);
|
exit(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void terminate() {
|
void terminate(int _) {
|
||||||
fprintf(stderr, "\nTerminating gracefully...\n");
|
fprintf(stderr, "\nTerminating gracefully...\n");
|
||||||
active = 0;
|
active = 0;
|
||||||
|
|
||||||
@@ -347,7 +348,7 @@ int main(int argc, const char *argv[]) {
|
|||||||
ready_sockets_num = poll(poll_fds, NUM_SOCKETS, 1000);
|
ready_sockets_num = poll(poll_fds, NUM_SOCKETS, 1000);
|
||||||
if (ready_sockets_num < 0) {
|
if (ready_sockets_num < 0) {
|
||||||
fprintf(stderr, ERR_STR "Unable to poll sockets: %s" CLR_STR "\n", strerror(errno));
|
fprintf(stderr, ERR_STR "Unable to poll sockets: %s" CLR_STR "\n", strerror(errno));
|
||||||
terminate();
|
terminate(0);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
10
src/server.h
10
src/server.h
@@ -1,8 +1,9 @@
|
|||||||
/**
|
/**
|
||||||
* sesimos - secure, simple, modern web server
|
* sesimos - secure, simple, modern web server
|
||||||
* Main executable (header file)
|
* @brief Main executable (header file)
|
||||||
* src/server.h
|
* @file src/server.h
|
||||||
* Lorenz Stechauner, 2020-12-03
|
* @author Lorenz Stechauner
|
||||||
|
* @date 2020-12-03
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef SESIMOS_SERVER_H
|
#ifndef SESIMOS_SERVER_H
|
||||||
@@ -10,6 +11,7 @@
|
|||||||
|
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <maxminddb.h>
|
#include <maxminddb.h>
|
||||||
|
#include <signal.h>
|
||||||
|
|
||||||
#define NUM_SOCKETS 2
|
#define NUM_SOCKETS 2
|
||||||
#define MAX_CHILDREN 1024
|
#define MAX_CHILDREN 1024
|
||||||
@@ -25,7 +27,7 @@ extern int sockets[NUM_SOCKETS];
|
|||||||
extern pid_t children[MAX_CHILDREN];
|
extern pid_t children[MAX_CHILDREN];
|
||||||
extern MMDB_s mmdbs[MAX_MMDB];
|
extern MMDB_s mmdbs[MAX_MMDB];
|
||||||
|
|
||||||
extern int server_keep_alive;
|
extern volatile sig_atomic_t server_keep_alive;
|
||||||
extern char *log_client_prefix, *log_conn_prefix, *log_req_prefix, *client_geoip;
|
extern char *log_client_prefix, *log_conn_prefix, *log_req_prefix, *client_geoip;
|
||||||
extern char *client_addr_str, *client_addr_str_ptr, *server_addr_str, *server_addr_str_ptr, *client_host_str;
|
extern char *client_addr_str, *client_addr_str_ptr, *server_addr_str, *server_addr_str_ptr, *client_host_str;
|
||||||
extern struct timeval client_timeout;
|
extern struct timeval client_timeout;
|
||||||
|
Reference in New Issue
Block a user