diff --git a/src/cache.c b/src/cache.c index 1748803..3c74938 100644 --- a/src/cache.c +++ b/src/cache.c @@ -5,9 +5,8 @@ * Lorenz Stechauner, 2020-12-19 */ -#include #include "cache.h" -#include "uri.h" + int magic_init() { magic = magic_open(MAGIC_MIME); diff --git a/src/cache.h b/src/cache.h index 3e2acd3..ef848ec 100644 --- a/src/cache.h +++ b/src/cache.h @@ -8,10 +8,14 @@ #ifndef NECRONDA_SERVER_CACHE_H #define NECRONDA_SERVER_CACHE_H +#include "uri.h" + +#include +#include #include #include #include -#include "uri.h" + magic_t magic; diff --git a/src/client.c b/src/client.c index aed59f0..3223149 100644 --- a/src/client.c +++ b/src/client.c @@ -5,18 +5,9 @@ * Lorenz Stechauner, 2020-12-03 */ -#include "necronda-server.h" -#include "utils.h" -#include "uri.h" -#include "http.h" -#include "fastcgi.h" +#include "client.h" -int server_keep_alive = 1; -char *log_client_prefix, *log_conn_prefix, *log_req_prefix, *client_geoip; - -struct timeval client_timeout = {.tv_sec = CLIENT_TIMEOUT, .tv_usec = 0}; - host_config *get_host_config(const char *host) { for (int i = 0; i < MAX_HOST_CONFIG; i++) { host_config *hc = &config[i]; diff --git a/src/client.h b/src/client.h new file mode 100644 index 0000000..869d05b --- /dev/null +++ b/src/client.h @@ -0,0 +1,23 @@ +/** + * Necronda Web Server + * Client connection and request handlers (header file) + * src/client.h + * Lorenz Stechauner, 2021-01-17 + */ + +#ifndef NECRONDA_SERVER_CLIENT_H +#define NECRONDA_SERVER_CLIENT_H + +#include "necronda-server.h" +#include "utils.h" +#include "uri.h" +#include "http.h" +#include "fastcgi.h" + + +int server_keep_alive = 1; +char *log_client_prefix, *log_conn_prefix, *log_req_prefix, *client_geoip; + +struct timeval client_timeout = {.tv_sec = CLIENT_TIMEOUT, .tv_usec = 0}; + +#endif //NECRONDA_SERVER_CLIENT_H diff --git a/src/config.c b/src/config.c index fedffee..47a0cd9 100644 --- a/src/config.c +++ b/src/config.c @@ -6,9 +6,7 @@ */ #include "config.h" -#include "uri.h" -#include -#include + int config_init() { int shm_id = shmget(SHM_KEY_CONFIG, MAX_HOST_CONFIG * sizeof(host_config), IPC_CREAT | IPC_EXCL | 0640); diff --git a/src/config.h b/src/config.h index f4ffb6c..5587636 100644 --- a/src/config.h +++ b/src/config.h @@ -13,6 +13,12 @@ #define CONFIG_TYPE_LOCAL 1 #define CONFIG_TYPE_REVERSE_PROXY 2 +#include "uri.h" + +#include +#include +#include + typedef struct { int type; diff --git a/src/fastcgi.c b/src/fastcgi.c index 08e95d5..b36cf75 100644 --- a/src/fastcgi.c +++ b/src/fastcgi.c @@ -6,9 +6,6 @@ */ #include "fastcgi.h" -#include "necronda-server.h" - -#include char *fastcgi_add_param(char *buf, const char *key, const char *value) { @@ -205,7 +202,7 @@ int fastcgi_close_stdin(fastcgi_conn *conn) { return 0; } -int fastcgi_php_error(char *msg, int msg_len, char *err_msg) { +int fastcgi_php_error(const char *msg, int msg_len, char *err_msg) { char *msg_str = malloc(msg_len + 1); char *ptr0 = msg_str; strncpy(msg_str, msg, msg_len); @@ -248,7 +245,7 @@ int fastcgi_php_error(char *msg, int msg_len, char *err_msg) { if (ptr3 != NULL && (ptr3 - ptr2) < len2) { len2 = (int) (ptr3 - ptr2); } - print("%s%.*s%s", msg_type == 1 ? WRN_STR : msg_type == 2 ? ERR_STR: "", len2, ptr2, msg_type != 0 ? CLR_STR : ""); + print("%s%.*s%s", msg_type == 1 ? WRN_STR : msg_type == 2 ? ERR_STR : "", len2, ptr2, msg_type != 0 ? CLR_STR : ""); if (msg_type == 2 && ptr2 == ptr0) { sprintf(err_msg, "%.*s", len2, ptr2); err = 1; @@ -265,6 +262,7 @@ int fastcgi_php_error(char *msg, int msg_len, char *err_msg) { } ptr0 = ptr1 + 13; } + free(msg_str); return err; } diff --git a/src/fastcgi.h b/src/fastcgi.h index b39fab6..b2acc70 100644 --- a/src/fastcgi.h +++ b/src/fastcgi.h @@ -11,6 +11,15 @@ #define FASTCGI_CHUNKED 1 #define FASTCGI_COMPRESS 2 +#include "necronda-server.h" +#include "http.h" +#include "uri.h" +#include "client.h" + +#include +#include + + typedef struct { int socket; unsigned short req_id; @@ -26,6 +35,8 @@ int fastcgi_init(fastcgi_conn *conn, unsigned int client_num, unsigned int req_n int fastcgi_close_stdin(fastcgi_conn *conn); +int fastcgi_php_error(const char *msg, int msg_len, char *err_msg); + int fastcgi_header(fastcgi_conn *conn, http_res *res, char *err_msg); int fastcgi_send(fastcgi_conn *conn, sock *client, int flags); diff --git a/src/http.c b/src/http.c index b70a3fd..44f9691 100644 --- a/src/http.c +++ b/src/http.c @@ -6,7 +6,6 @@ */ #include "http.h" -#include "utils.h" void http_to_camel_case(char *str, int mode) { diff --git a/src/http.h b/src/http.h index 421f3aa..da215f1 100644 --- a/src/http.h +++ b/src/http.h @@ -16,6 +16,10 @@ #define HTTP_REMOVE_ALL 1 #define HTTP_REMOVE_LAST 2 +#include "sock.h" +#include "utils.h" + + typedef struct { unsigned short code; char type[16]; diff --git a/src/sock.h b/src/sock.h index 543c7ac..00322fd 100644 --- a/src/sock.h +++ b/src/sock.h @@ -8,6 +8,13 @@ #ifndef NECRONDA_SERVER_SOCK_H #define NECRONDA_SERVER_SOCK_H +#include +#include +#include +#include +#include +#include + typedef struct { unsigned int enc:1; int socket; diff --git a/src/uri.h b/src/uri.h index ae4d932..e66ac40 100644 --- a/src/uri.h +++ b/src/uri.h @@ -8,13 +8,14 @@ #ifndef NECRONDA_SERVER_URI_H #define NECRONDA_SERVER_URI_H -#include - #define URI_DIR_MODE_NO_VALIDATION 0 #define URI_DIR_MODE_FORBIDDEN 1 #define URI_DIR_MODE_LIST 2 #define URI_DIR_MODE_INFO 3 +#include + + typedef struct { char etag[64]; char type[24]; diff --git a/src/utils.c b/src/utils.c index 2488b5b..a8e7b36 100644 --- a/src/utils.c +++ b/src/utils.c @@ -7,6 +7,7 @@ #include "utils.h" + char *format_duration(unsigned long micros, char *buf) { if (micros < 10000) { sprintf(buf, "%.1f ms", (double) micros / 1000);