Cleanup code

This commit is contained in:
2022-12-10 21:40:41 +01:00
parent 2937bdaded
commit 2efe65fc74
6 changed files with 8 additions and 18 deletions

View File

@ -574,7 +574,7 @@ int client_request_handler(sock *client, unsigned long client_num, unsigned int
if (res.status->code >= 300 && res.status->code < 400) { if (res.status->code >= 300 && res.status->code < 400) {
const char *location = http_get_header_field(&res.hdr, "Location"); const char *location = http_get_header_field(&res.hdr, "Location");
if (location != NULL) { if (location != NULL) {
snprintf(msg_content, sizeof(msg_content), "<ul>\n\t<li><a href=\"%1$s\">%1$s</a></li>\n</ul>\n", location); snprintf(msg_content, sizeof(msg_content), "<ul>\n\t<li><a href=\"%s\">%s</a></li>\n</ul>\n", location, location);
} }
} }
} else if (strncmp(msg_content, "<!DOCTYPE html>", 15) == 0 || strncmp(msg_content, "<html", 5) == 0) { } else if (strncmp(msg_content, "<!DOCTYPE html>", 15) == 0 || strncmp(msg_content, "<html", 5) == 0) {

View File

@ -494,13 +494,12 @@ int fastcgi_send(fastcgi_conn *conn, sock *client, int flags) {
unsigned long avail_in, avail_out; unsigned long avail_in, avail_out;
out: out:
avail_in = content_len; avail_in = content_len;
void *next_in = ptr; char *next_in = ptr;
do { do {
int buf_len = content_len; int buf_len = content_len;
if (flags & FASTCGI_COMPRESS) { if (flags & FASTCGI_COMPRESS) {
avail_out = sizeof(comp_out); avail_out = sizeof(comp_out);
compress_compress(&comp_ctx, next_in + content_len - avail_in, &avail_in, comp_out, &avail_out, compress_compress(&comp_ctx, next_in + content_len - avail_in, &avail_in, comp_out, &avail_out, finish_comp);
finish_comp);
ptr = comp_out; ptr = comp_out;
buf_len = (int) (sizeof(comp_out) - avail_out); buf_len = (int) (sizeof(comp_out) - avail_out);
} }

View File

@ -176,7 +176,7 @@ int http_receive_request(sock *client, http_req *req) {
} }
if (req->version[0] == 0) { if (req->version[0] == 0) {
pos1 = memchr(ptr, ' ', rcv_len - (ptr - buf)) + 1; pos1 = (char *) memchr(ptr, ' ', rcv_len - (ptr - buf)) + 1;
if (pos1 == NULL) goto err_hdr_fmt; if (pos1 == NULL) goto err_hdr_fmt;
if (pos1 - ptr - 1 >= sizeof(req->method)) { if (pos1 - ptr - 1 >= sizeof(req->method)) {
@ -192,7 +192,7 @@ int http_receive_request(sock *client, http_req *req) {
} }
snprintf(req->method, sizeof(req->method), "%.*s", (int) (pos1 - ptr - 1), ptr); snprintf(req->method, sizeof(req->method), "%.*s", (int) (pos1 - ptr - 1), ptr);
pos2 = memchr(pos1, ' ', rcv_len - (pos1 - buf)) + 1; pos2 = (char *) memchr(pos1, ' ', rcv_len - (pos1 - buf)) + 1;
if (pos2 == NULL) { if (pos2 == NULL) {
err_hdr_fmt: err_hdr_fmt:
error("Unable to parse http header: Invalid header format"); error("Unable to parse http header: Invalid header format");

View File

@ -511,7 +511,7 @@ int rev_proxy_send(sock *client, unsigned long len_to_send, int flags) {
ptr = buffer; ptr = buffer;
out: out:
avail_in = len; avail_in = len;
void *next_in = ptr; char *next_in = ptr;
do { do {
long buf_len = len; long buf_len = len;
if (flags & REV_PROXY_COMPRESS) { if (flags & REV_PROXY_COMPRESS) {

View File

@ -42,13 +42,6 @@ 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) {
SSL_library_init();
SSL_load_error_strings();
ERR_load_BIO_strings();
OpenSSL_add_all_algorithms();
}
static int ssl_servername_cb(SSL *ssl, int *ad, void *arg) { static int ssl_servername_cb(SSL *ssl, int *ad, void *arg) {
const char *servername = SSL_get_servername(ssl, TLSEXT_NAMETYPE_host_name); const char *servername = SSL_get_servername(ssl, TLSEXT_NAMETYPE_host_name);
if (servername != NULL) { if (servername != NULL) {
@ -88,6 +81,7 @@ void destroy(int _) {
} }
void terminate(int _) { void terminate(int _) {
fprintf(stderr, "\n");
notice("Terminating gracefully..."); notice("Terminating gracefully...");
active = 0; active = 0;
@ -289,8 +283,6 @@ int main(int argc, const char *argv[]) {
return 0; return 0;
} }
openssl_init();
for (int i = 0; i < CONFIG_MAX_CERT_CONFIG; i++) { for (int i = 0; i < CONFIG_MAX_CERT_CONFIG; i++) {
const cert_config *conf = &config->certs[i]; const cert_config *conf = &config->certs[i];
if (conf->name[0] == 0) break; if (conf->name[0] == 0) break;
@ -339,7 +331,7 @@ int main(int argc, const char *argv[]) {
} }
errno = 0; errno = 0;
info("Ready to accept connections"); notice("Ready to accept connections");
while (active) { while (active) {
ready_sockets_num = poll(poll_fds, NUM_SOCKETS, 1000); ready_sockets_num = poll(poll_fds, NUM_SOCKETS, 1000);

View File

@ -22,7 +22,6 @@
#define SERVER_TIMEOUT_INIT 4 #define SERVER_TIMEOUT_INIT 4
#define SERVER_TIMEOUT 3600 #define SERVER_TIMEOUT 3600
extern int sockets[NUM_SOCKETS]; 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];