summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2023-09-23 02:38:54 +0000
committerLaurent Bercot <ska@appnovation.com>2023-09-23 02:38:54 +0000
commit68a35fb8e58f86995929839330b7aee0a3a92a87 (patch)
treebebf8cf5b90c3104a211e2f326cbf0f3799a47d4
parent139b577cbeccd495038da51a8a3ddc8eb3397a4d (diff)
downloadtipidee-68a35fb8e58f86995929839330b7aee0a3a92a87.tar.xz
Better logging
Signed-off-by: Laurent Bercot <ska@appnovation.com>
-rw-r--r--src/libtipidee/tipidee_headers_parse.c13
-rw-r--r--src/tipideed/cgi.c4
-rw-r--r--src/tipideed/log.c4
-rw-r--r--src/tipideed/regular.c2
-rw-r--r--src/tipideed/responses.c7
-rw-r--r--src/tipideed/tipideed-internal.h2
6 files changed, 19 insertions, 13 deletions
diff --git a/src/libtipidee/tipidee_headers_parse.c b/src/libtipidee/tipidee_headers_parse.c
index ca14ca5..d906885 100644
--- a/src/libtipidee/tipidee_headers_parse.c
+++ b/src/libtipidee/tipidee_headers_parse.c
@@ -10,7 +10,6 @@
#include <skalibs/error.h>
#include <skalibs/avltreen.h>
#include <skalibs/unix-timed.h>
-#include <skalibs/lolstdio.h>
#include <tipidee/headers.h>
@@ -126,7 +125,7 @@ static int tipidee_headers_parse_with (buffer *b, tipidee_headers *hdr, get1_fun
if (!(*next)(b, &cur, data))
return errno == ETIMEDOUT ? 408 : error_isagain(errno) ? -2 : -1 ;
c = table[*state][cclass(cur)] ;
-
+/*
{
char s[2] = { cur, 0 } ;
@@ -143,7 +142,7 @@ static int tipidee_headers_parse_with (buffer *b, tipidee_headers *hdr, get1_fun
c & 0x0100 ? "p" : ""
) ;
}
-
+*/
*state = c & 0x0f ;
if (c & 0x4000) { if (hdr->len >= hdr->max) return 413 ; hdr->buf[hdr->len++] = ' ' ; }
if (c & 0x2000) hdr->len-- ;
@@ -155,14 +154,14 @@ static int tipidee_headers_parse_with (buffer *b, tipidee_headers *hdr, get1_fun
hdr->list[hdr->n] = *header ;
if (needs_processing(hdr->buf + header->left))
{
- LOLDEBUG("tipidee_headers_parse_with: n: adding header %u - key %zu (%s), value %zu (%s)", hdr->n, header->left, hdr->buf + header->left, header->right, hdr->buf + header->right) ;
+// LOLDEBUG("tipidee_headers_parse_with: n: adding header %u - key %zu (%s), value %zu (%s)", hdr->n, header->left, hdr->buf + header->left, header->right, hdr->buf + header->right) ;
if (avltreen_search(&hdr->map, hdr->buf + header->left, &prev))
{
size_t start = hdr->list[prev+1].left ;
- LOLDEBUG(" found at %u (next start is %zu), needs to collate", prev, start) ;
+// LOLDEBUG(" found at %u (next start is %zu), needs to collate", prev, start) ;
if (prev+1 == hdr->n)
{
- LOLDEBUG(" consecutive headers -> concatenating") ;
+// LOLDEBUG(" consecutive headers -> concatenating") ;
hdr->buf[start - 1] = ',' ;
hdr->buf[start] = ' ' ;
memmove(hdr->buf + start + 1, hdr->buf + header->right, hdr->len - header->right) ;
@@ -172,7 +171,7 @@ static int tipidee_headers_parse_with (buffer *b, tipidee_headers *hdr, get1_fun
size_t len = header->left - start ;
size_t offset = hdr->len - header->right + 1 ;
char tmp[len] ;
- LOLDEBUG(" not consecutive: len is %zu, offset is %zu", len, offset) ;
+// LOLDEBUG(" not consecutive: len is %zu, offset is %zu", len, offset) ;
memcpy(tmp, hdr->buf + start, len) ;
hdr->buf[start - 1] = ',' ;
hdr->buf[start] = ' ' ;
diff --git a/src/tipideed/cgi.c b/src/tipideed/cgi.c
index 1ce0b1d..c2c62a1 100644
--- a/src/tipideed/cgi.c
+++ b/src/tipideed/cgi.c
@@ -102,7 +102,6 @@ static inline int do_nph (tipidee_rql const *rql, char const *const *argv, char
static inline int do_nph (tipidee_rql const *rql, char const *const *argv, char const *const *envp, char const *body, size_t bodylen)
{
int p[2] ;
- log_nph(argv, envp) ;
if (pipe(p) == -1) die500sys(rql, 111, "pipe") ;
if (bodylen)
{
@@ -134,6 +133,7 @@ static inline int do_nph (tipidee_rql const *rql, char const *const *argv, char
}
close(p[1]) ;
if (fd_move(0, p[0]) == -1) die500sys(rql, 111, "fd_move") ;
+ log_nph(argv, envp) ;
exec_e(argv, envp) ;
die500sys(rql, errno == ENOENT ? 127 : 126, "exec nph ", argv[0]) ;
}
@@ -365,7 +365,7 @@ static inline int process_cgi_output (tipidee_rql *rql, tipidee_headers const *h
}
if (!buffer_timed_flush_g(buffer_1, &deadline))
strerr_diefu1sys(111, "write to stdout") ;
- if (g.verbosity >= 4)
+ if (g.verbosity >= 2)
{
char fmt[UINT_FMT] ;
fmt[uint_fmt(fmt, status)] = 0 ;
diff --git a/src/tipideed/log.c b/src/tipideed/log.c
index f5f2e81..b08e16f 100644
--- a/src/tipideed/log.c
+++ b/src/tipideed/log.c
@@ -44,10 +44,10 @@ void log_regular (char const *fn, char const *sizefmt, int ishead, char const *c
strerr_warni8x("sending ", ishead ? "headers for " : "", "regular file ", fn, " (", sizefmt, " bytes) with type ", ct) ;
}
-void log_304 (char const *fn)
+void log_response (char const *ans, char const *fn)
{
if (g.verbosity >= 2)
- strerr_warni2x("answering 304 for regular file ", fn) ;
+ strerr_warni4x("answering ", ans, fn ? " for " : 0, fn) ;
}
void log_nph (char const *const *argv, char const *const *envp)
diff --git a/src/tipideed/regular.c b/src/tipideed/regular.c
index 5af364d..24dc392 100644
--- a/src/tipideed/regular.c
+++ b/src/tipideed/regular.c
@@ -70,7 +70,7 @@ int respond_304 (tipidee_rql const *rql, char const *fn, struct stat const *st)
if (l) n += buffer_putnoflush(buffer_1, fmt, l) ;
}
n += buffer_putnoflush(buffer_1, "\r\n", 2) ;
- log_304(fn) ;
+ log_response("304", fn) ;
tain_add_g(&deadline, &g.writetto) ;
if (!buffer_timed_flush_g(buffer_1, &deadline))
strerr_diefu1sys(111, "write to stdout") ;
diff --git a/src/tipideed/responses.c b/src/tipideed/responses.c
index 0c93582..8c6f1f5 100644
--- a/src/tipideed/responses.c
+++ b/src/tipideed/responses.c
@@ -2,6 +2,7 @@
#include <unistd.h>
+#include <skalibs/types.h>
#include <skalibs/buffer.h>
#include <skalibs/strerr.h>
#include <skalibs/tai.h>
@@ -15,8 +16,11 @@
void response_error (tipidee_rql const *rql, char const *rsl, char const *text, int doclose)
{
tain deadline ;
+ char ans[4] = "???" ;
+ memcpy(ans, rsl, 3) ;
tipidee_response_error(buffer_1, rql, rsl, text, doclose || !g.cont) ;
tain_add_g(&deadline, &g.writetto) ;
+ log_response(ans, 0) ;
if (!buffer_timed_flush_g(buffer_1, &deadline))
strerr_diefu1sys(111, "write to stdout") ;
}
@@ -52,6 +56,8 @@ void respond_30x (tipidee_rql const *rql, tipidee_redirection const *rd)
{
static char const *rsl[4] = { "307 Temporary Redirect", "308 Permanent Redirect", "302 Found", "301 Moved Permanently" } ;
tain deadline ;
+ char ans[4] = "30x" ;
+ memcpy(ans, rsl[rd->type], 3) ;
tipidee_response_status_line(buffer_1, rql, rsl[rd->type]) ;
tipidee_response_header_common_put_g(buffer_1, 0) ;
buffer_putsnoflush(buffer_1, "Content-Length: 0\r\nLocation: ") ;
@@ -59,6 +65,7 @@ void respond_30x (tipidee_rql const *rql, tipidee_redirection const *rd)
if (rd->sub) buffer_putsnoflush(buffer_1, rd->sub) ;
buffer_putnoflush(buffer_1, "\r\n\r\n", 4) ;
tain_add_g(&deadline, &g.writetto) ;
+ log_response(ans, 0) ;
if (!buffer_timed_flush_g(buffer_1, &deadline))
strerr_diefu1sys(111, "write to stdout") ;
}
diff --git a/src/tipideed/tipideed-internal.h b/src/tipideed/tipideed-internal.h
index a53fc0c..75f5be2 100644
--- a/src/tipideed/tipideed-internal.h
+++ b/src/tipideed/tipideed-internal.h
@@ -145,7 +145,7 @@ extern void log_start (void) ;
extern void log_and_exit (int) gccattr_noreturn ;
extern void log_request (tipidee_rql const *) ;
extern void log_regular (char const *, char const *, int, char const *) ;
-extern void log_304 (char const *) ;
+extern void log_response (char const *, char const *) ;
extern void log_nph (char const *const *, char const *const *) ;
extern void log_cgi (char const *const *, char const *const *) ;