Update logger_prefix
This commit is contained in:
@ -15,6 +15,7 @@
|
|||||||
|
|
||||||
#define CHUNK_SIZE 8192
|
#define CHUNK_SIZE 8192
|
||||||
#define MAX_PROXY_CNX_PER_HOST 16
|
#define MAX_PROXY_CNX_PER_HOST 16
|
||||||
|
#define ADDRSTRLEN 39
|
||||||
|
|
||||||
#ifndef DEFAULT_HOST
|
#ifndef DEFAULT_HOST
|
||||||
# define DEFAULT_HOST "www.necronda.net"
|
# define DEFAULT_HOST "www.necronda.net"
|
||||||
|
@ -89,8 +89,10 @@ void proxy_unload(void) {
|
|||||||
void proxy_close_all(void) {
|
void proxy_close_all(void) {
|
||||||
proxy_ctx_t *ptr = proxies;
|
proxy_ctx_t *ptr = proxies;
|
||||||
for (int i = 0; i < MAX_PROXY_CNX_PER_HOST * num_proxy_hosts; i++, ptr++) {
|
for (int i = 0; i < MAX_PROXY_CNX_PER_HOST * num_proxy_hosts; i++, ptr++) {
|
||||||
if (ptr->initialized)
|
if (ptr->initialized) {
|
||||||
proxy_close(ptr);
|
proxy_close(ptr);
|
||||||
|
logger_set_prefix("");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -671,3 +673,16 @@ int proxy_dump(proxy_ctx_t *proxy, char *buf, long len) {
|
|||||||
sock_recv(&proxy->proxy, buf, len, 0);
|
sock_recv(&proxy->proxy, buf, len, 0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void proxy_close(proxy_ctx_t *ctx) {
|
||||||
|
client_ctx_t *cctx = ctx->client;
|
||||||
|
if (cctx) {
|
||||||
|
logger_set_prefix("[%s%*s%s]%s", BLD_STR, ADDRSTRLEN, cctx->req_host, CLR_STR, cctx->log_prefix);
|
||||||
|
}
|
||||||
|
|
||||||
|
info(BLUE_STR "Closing proxy connection");
|
||||||
|
sock_close(&ctx->proxy);
|
||||||
|
|
||||||
|
memset(ctx, 0, sizeof(*ctx));
|
||||||
|
errno = 0;
|
||||||
|
}
|
||||||
|
@ -48,4 +48,6 @@ int proxy_send(proxy_ctx_t *proxy, sock *client, unsigned long len_to_send, int
|
|||||||
|
|
||||||
int proxy_dump(proxy_ctx_t *proxy, char *buf, long len);
|
int proxy_dump(proxy_ctx_t *proxy, char *buf, long len);
|
||||||
|
|
||||||
|
void proxy_close(proxy_ctx_t *ctx);
|
||||||
|
|
||||||
#endif //SESIMOS_PROXY_H
|
#endif //SESIMOS_PROXY_H
|
||||||
|
@ -204,8 +204,8 @@ static void terminate_gracefully(int sig) {
|
|||||||
while (list_size(clients) > 0)
|
while (list_size(clients) > 0)
|
||||||
tcp_close(clients[0]);
|
tcp_close(clients[0]);
|
||||||
|
|
||||||
proxy_close_all();
|
|
||||||
logger_set_prefix("");
|
logger_set_prefix("");
|
||||||
|
proxy_close_all();
|
||||||
|
|
||||||
async_stop();
|
async_stop();
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ static int fastcgi_handler_1(client_ctx_t *ctx, fastcgi_cnx_t *fcgi_cnx);
|
|||||||
static int fastcgi_handler_2(client_ctx_t *ctx, fastcgi_cnx_t *fcgi_cnx);
|
static int fastcgi_handler_2(client_ctx_t *ctx, fastcgi_cnx_t *fcgi_cnx);
|
||||||
|
|
||||||
void fastcgi_handler_func(client_ctx_t *ctx) {
|
void fastcgi_handler_func(client_ctx_t *ctx) {
|
||||||
logger_set_prefix("[%s%*s%s]%s", BLD_STR, INET6_ADDRSTRLEN, ctx->req_host, CLR_STR, ctx->log_prefix);
|
logger_set_prefix("[%s%*s%s]%s", BLD_STR, ADDRSTRLEN, ctx->req_host, CLR_STR, ctx->log_prefix);
|
||||||
|
|
||||||
fastcgi_cnx_t fcgi_cnx;
|
fastcgi_cnx_t fcgi_cnx;
|
||||||
int ret = fastcgi_handler_1(ctx, &fcgi_cnx);
|
int ret = fastcgi_handler_1(ctx, &fcgi_cnx);
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
#ifndef SESIMOS_FUNC_H
|
#ifndef SESIMOS_FUNC_H
|
||||||
#define SESIMOS_FUNC_H
|
#define SESIMOS_FUNC_H
|
||||||
|
|
||||||
|
#include "../defs.h"
|
||||||
#include "../lib/sock.h"
|
#include "../lib/sock.h"
|
||||||
#include "../lib/http.h"
|
#include "../lib/http.h"
|
||||||
#include "../lib/uri.h"
|
#include "../lib/uri.h"
|
||||||
@ -22,7 +23,7 @@ typedef struct {
|
|||||||
char cc[3], host[256];
|
char cc[3], host[256];
|
||||||
char req_host[256], err_msg[256];
|
char req_host[256], err_msg[256];
|
||||||
char log_prefix[128];
|
char log_prefix[128];
|
||||||
char _c_addr[INET6_ADDRSTRLEN + 1], _s_addr[INET6_ADDRSTRLEN + 1];
|
char _c_addr[ADDRSTRLEN + 1], _s_addr[ADDRSTRLEN + 1];
|
||||||
long cnx_s, cnx_e, req_s, res_ts, req_e;
|
long cnx_s, cnx_e, req_s, res_ts, req_e;
|
||||||
http_req req;
|
http_req req;
|
||||||
http_res res;
|
http_res res;
|
||||||
@ -62,8 +63,6 @@ void timeout_request(client_ctx_t *ctx);
|
|||||||
|
|
||||||
void tcp_close(client_ctx_t *ctx);
|
void tcp_close(client_ctx_t *ctx);
|
||||||
|
|
||||||
void proxy_close(proxy_ctx_t *ctx);
|
|
||||||
|
|
||||||
int ws_handle_connection(client_ctx_t *ctx);
|
int ws_handle_connection(client_ctx_t *ctx);
|
||||||
|
|
||||||
void ws_close(ws_ctx_t *ctx);
|
void ws_close(ws_ctx_t *ctx);
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
static int local_handler(client_ctx_t *ctx);
|
static int local_handler(client_ctx_t *ctx);
|
||||||
|
|
||||||
void local_handler_func(client_ctx_t *ctx) {
|
void local_handler_func(client_ctx_t *ctx) {
|
||||||
logger_set_prefix("[%s%*s%s]%s", BLD_STR, INET6_ADDRSTRLEN, ctx->req_host, CLR_STR, ctx->log_prefix);
|
logger_set_prefix("[%s%*s%s]%s", BLD_STR, ADDRSTRLEN, ctx->req_host, CLR_STR, ctx->log_prefix);
|
||||||
|
|
||||||
switch (local_handler(ctx)) {
|
switch (local_handler(ctx)) {
|
||||||
case 0:
|
case 0:
|
||||||
|
@ -20,7 +20,7 @@ static int proxy_handler_1(client_ctx_t *ctx);
|
|||||||
static int proxy_handler_2(client_ctx_t *ctx);
|
static int proxy_handler_2(client_ctx_t *ctx);
|
||||||
|
|
||||||
void proxy_handler_func(client_ctx_t *ctx) {
|
void proxy_handler_func(client_ctx_t *ctx) {
|
||||||
logger_set_prefix("[%s%*s%s]%s", BLD_STR, INET6_ADDRSTRLEN, ctx->req_host, CLR_STR, ctx->log_prefix);
|
logger_set_prefix("[%s%*s%s]%s", BLD_STR, ADDRSTRLEN, ctx->req_host, CLR_STR, ctx->log_prefix);
|
||||||
|
|
||||||
// TODO handle 1xx responses
|
// TODO handle 1xx responses
|
||||||
|
|
||||||
@ -155,18 +155,3 @@ static int proxy_handler_2(client_ctx_t *ctx) {
|
|||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void proxy_close(proxy_ctx_t *ctx) {
|
|
||||||
client_ctx_t *cctx = ctx->client;
|
|
||||||
if (cctx) {
|
|
||||||
logger_set_prefix("[%s%*s%s]%s", BLD_STR, INET6_ADDRSTRLEN, cctx->req_host, CLR_STR, cctx->log_prefix);
|
|
||||||
} else {
|
|
||||||
logger_set_prefix("");
|
|
||||||
}
|
|
||||||
|
|
||||||
info(BLUE_STR "Closing proxy connection");
|
|
||||||
sock_close(&ctx->proxy);
|
|
||||||
|
|
||||||
memset(ctx, 0, sizeof(*ctx));
|
|
||||||
errno = 0;
|
|
||||||
}
|
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
static int request_handler(client_ctx_t *ctx);
|
static int request_handler(client_ctx_t *ctx);
|
||||||
|
|
||||||
void request_handler_func(client_ctx_t *ctx) {
|
void request_handler_func(client_ctx_t *ctx) {
|
||||||
logger_set_prefix("[%*s]%s", INET6_ADDRSTRLEN, ctx->socket.s_addr, ctx->log_prefix);
|
logger_set_prefix("[%*s]%s", ADDRSTRLEN, ctx->socket.s_addr, ctx->log_prefix);
|
||||||
|
|
||||||
switch (request_handler(ctx)) {
|
switch (request_handler(ctx)) {
|
||||||
case 0:
|
case 0:
|
||||||
@ -128,7 +128,7 @@ static int request_handler(client_ctx_t *ctx) {
|
|||||||
strcpy(ctx->req_host, host_ptr);
|
strcpy(ctx->req_host, host_ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
logger_set_prefix("[%s%*s%s]%s", BLD_STR, INET6_ADDRSTRLEN, ctx->req_host, CLR_STR, ctx->log_prefix);
|
logger_set_prefix("[%s%*s%s]%s", BLD_STR, ADDRSTRLEN, ctx->req_host, CLR_STR, ctx->log_prefix);
|
||||||
info(BLD_STR "%s %s", req->method, req->uri);
|
info(BLD_STR "%s %s", req->method, req->uri);
|
||||||
|
|
||||||
if (strstarts(req->uri, "/.sesimos/res/")) {
|
if (strstarts(req->uri, "/.sesimos/res/")) {
|
||||||
@ -386,7 +386,7 @@ void request_complete(client_ctx_t *ctx) {
|
|||||||
|
|
||||||
void timeout_request(client_ctx_t *ctx) {
|
void timeout_request(client_ctx_t *ctx) {
|
||||||
init_ctx(ctx);
|
init_ctx(ctx);
|
||||||
logger_set_prefix("[%*s]%s", INET6_ADDRSTRLEN, ctx->socket.s_addr, ctx->log_prefix);
|
logger_set_prefix("[%*s]%s", ADDRSTRLEN, ctx->socket.s_addr, ctx->log_prefix);
|
||||||
|
|
||||||
ctx->s_keep_alive = 0;
|
ctx->s_keep_alive = 0;
|
||||||
ctx->res.status = http_get_status(408);
|
ctx->res.status = http_get_status(408);
|
||||||
|
@ -49,10 +49,10 @@ static int tcp_acceptor(client_ctx_t *ctx) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sprintf(ctx->log_prefix, "[%s%4i%s]%s[%*s][%5i]%s", (int) ctx->socket.enc ? HTTPS_STR : HTTP_STR,
|
sprintf(ctx->log_prefix, "[%s%4i%s]%s[%*s][%5i]%s", (int) ctx->socket.enc ? HTTPS_STR : HTTP_STR,
|
||||||
ntohs(server_addr.sin6_port), CLR_STR, /*color_table[0]*/ "", INET6_ADDRSTRLEN, ctx->socket.addr,
|
ntohs(server_addr.sin6_port), CLR_STR, /*color_table[0]*/ "", ADDRSTRLEN, ctx->socket.addr,
|
||||||
ntohs(ctx->socket._addr.ipv6.sin6_port), CLR_STR);
|
ntohs(ctx->socket._addr.ipv6.sin6_port), CLR_STR);
|
||||||
|
|
||||||
logger_set_prefix("[%*s]%s", INET6_ADDRSTRLEN, ctx->socket.s_addr, ctx->log_prefix);
|
logger_set_prefix("[%*s]%s", ADDRSTRLEN, ctx->socket.s_addr, ctx->log_prefix);
|
||||||
|
|
||||||
int ret;
|
int ret;
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
@ -119,7 +119,7 @@ static int tcp_acceptor(client_ctx_t *ctx) {
|
|||||||
|
|
||||||
void tcp_close(client_ctx_t *ctx) {
|
void tcp_close(client_ctx_t *ctx) {
|
||||||
errno = 0;
|
errno = 0;
|
||||||
logger_set_prefix("[%*s]%s", INET6_ADDRSTRLEN, ctx->socket.s_addr, ctx->log_prefix);
|
logger_set_prefix("[%*s]%s", ADDRSTRLEN, ctx->socket.s_addr, ctx->log_prefix);
|
||||||
|
|
||||||
sock_close(&ctx->socket);
|
sock_close(&ctx->socket);
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
static int ws_frame_handler(ws_ctx_t *ctx);
|
static int ws_frame_handler(ws_ctx_t *ctx);
|
||||||
|
|
||||||
void ws_frame_handler_func(ws_ctx_t *ctx) {
|
void ws_frame_handler_func(ws_ctx_t *ctx) {
|
||||||
logger_set_prefix("[%*s]%s", INET6_ADDRSTRLEN, ctx->client->socket.s_addr, ctx->client->log_prefix);
|
logger_set_prefix("[%*s]%s", ADDRSTRLEN, ctx->client->socket.s_addr, ctx->client->log_prefix);
|
||||||
|
|
||||||
if (ws_frame_handler(ctx) == 0) {
|
if (ws_frame_handler(ctx) == 0) {
|
||||||
if (ctx->client->ws_close == 3) {
|
if (ctx->client->ws_close == 3) {
|
||||||
@ -84,7 +84,7 @@ void ws_close(ws_ctx_t *ctx) {
|
|||||||
ws_ctx_t *other = ctx->other;
|
ws_ctx_t *other = ctx->other;
|
||||||
if (other) {
|
if (other) {
|
||||||
other->other = NULL;
|
other->other = NULL;
|
||||||
logger_set_prefix("[%*s]%s", INET6_ADDRSTRLEN, ctx->client->socket.s_addr, ctx->client->log_prefix);
|
logger_set_prefix("[%*s]%s", ADDRSTRLEN, ctx->client->socket.s_addr, ctx->client->log_prefix);
|
||||||
info("Closing WebSocket connection");
|
info("Closing WebSocket connection");
|
||||||
proxy_close(ctx->client->proxy);
|
proxy_close(ctx->client->proxy);
|
||||||
tcp_close(ctx->client);
|
tcp_close(ctx->client);
|
||||||
|
Reference in New Issue
Block a user