summaryrefslogtreecommitdiff
path: root/src/libtipidee
diff options
context:
space:
mode:
Diffstat (limited to 'src/libtipidee')
-rw-r--r--src/libtipidee/tipidee_log_answer.c2
-rw-r--r--src/libtipidee/tipidee_log_request.c27
-rw-r--r--src/libtipidee/tipidee_response_error.c4
-rw-r--r--src/libtipidee/tipidee_response_status.c9
4 files changed, 23 insertions, 19 deletions
diff --git a/src/libtipidee/tipidee_log_answer.c b/src/libtipidee/tipidee_log_answer.c
index ae4e880..15dbe46 100644
--- a/src/libtipidee/tipidee_log_answer.c
+++ b/src/libtipidee/tipidee_log_answer.c
@@ -8,7 +8,7 @@
#include <tipidee/log.h>
-void tipidee_log_answer (uint32_t v, tipidee_rql const *rql, unsigned int status, off_t size)
+void tipidee_log_answer (uint32_t v, tipidee_rql const *rql, unsigned int status, uint64_t size)
{
char const *a[6] = { PROG, ": info:" } ;
size_t m = 2 ;
diff --git a/src/libtipidee/tipidee_log_request.c b/src/libtipidee/tipidee_log_request.c
index a789ca5..a50169d 100644
--- a/src/libtipidee/tipidee_log_request.c
+++ b/src/libtipidee/tipidee_log_request.c
@@ -7,25 +7,34 @@
#include <skalibs/skamisc.h>
#include <tipidee/method.h>
+#include <tipidee/headers.h>
#include <tipidee/log.h>
-void tipidee_log_request (uint32_t v, tipidee_rql const *rql, char const *referrer, char const *ua, stralloc *sa)
+void tipidee_log_request (uint32_t v, tipidee_rql const *rql, tipidee_headers const *hdr, stralloc *sa)
{
char const *a[16] = { PROG, ": info:" } ;
size_t m = 2 ;
- size_t start = sa->len ;
- size_t refpos = start, uapos = start ;
+ size_t start = sa->len ; /* assert: not zero */
+ size_t refpos = 0, uapos = 0 ;
if (!(v & TIPIDEE_LOG_REQUEST)) return ;
if (!string_quotes(sa, rql->uri.path)) goto eerr ;
if (v & TIPIDEE_LOG_REFERRER)
{
- refpos = sa->len ;
- if (!string_quotes(sa, referrer) || !stralloc_0(sa)) goto err ;
+ char const *x = tipidee_headers_search(hdr, "Referrer") ;
+ if (x)
+ {
+ refpos = sa->len ;
+ if (!string_quotes(sa, x) || !stralloc_0(sa)) goto err ;
+ }
}
if (v & TIPIDEE_LOG_UA)
{
- uapos = sa->len ;
- if (!string_quotes(sa, ua) || !stralloc_0(sa)) goto err ;
+ char const *x = tipidee_headers_search(hdr, "User-Agent") ;
+ if (x)
+ {
+ uapos = sa->len ;
+ if (!string_quotes(sa, x) || !stralloc_0(sa)) goto err ;
+ }
}
if (v & TIPIDEE_LOG_HOSTASPREFIX)
{
@@ -48,12 +57,12 @@ void tipidee_log_request (uint32_t v, tipidee_rql const *rql, char const *referr
}
a[m++] = " http 1." ;
a[m++] = rql->http_minor ? "1" : "0" ;
- if (v & TIPIDEE_LOG_REFERRER)
+ if (refpos)
{
a[m++] = " referrer " ;
a[m++] = sa->s + refpos ;
}
- if (v & TIPIDEE_LOG_UA)
+ if (uapos)
{
a[m++] = " user-agent " ;
a[m++] = sa->s + uapos ;
diff --git a/src/libtipidee/tipidee_response_error.c b/src/libtipidee/tipidee_response_error.c
index e2687a4..7c77e80 100644
--- a/src/libtipidee/tipidee_response_error.c
+++ b/src/libtipidee/tipidee_response_error.c
@@ -9,14 +9,14 @@
#include <tipidee/rql.h>
#include <tipidee/response.h>
-size_t tipidee_response_error (buffer *b, tipidee_rql const *rql, char const *rsl, char const *text, uint32_t options)
+size_t tipidee_response_error (buffer *b, tipidee_rql const *rql, unsigned int status, char const *rsl, char const *text, uint32_t options)
{
size_t n = 0 ;
static char const txt1[] = "<html>\n<head><title>" ;
static char const txt2[] = "</title></head>\n<body>\n<h1> " ;
static char const txt3[] = " </h1>\n<p>\n" ;
static char const txt4[] = "\n</p>\n</body>\n</html>\n" ;
- n += tipidee_response_status_line(b, rql, rsl) ;
+ n += tipidee_response_status(b, rql, status, rsl) ;
n += tipidee_response_header_common_put_g(buffer_1, options) ;
if (!(options & 2))
{
diff --git a/src/libtipidee/tipidee_response_status.c b/src/libtipidee/tipidee_response_status.c
index aedec39..4315f61 100644
--- a/src/libtipidee/tipidee_response_status.c
+++ b/src/libtipidee/tipidee_response_status.c
@@ -14,13 +14,8 @@ size_t tipidee_response_status (buffer *b, tipidee_rql const *rql, unsigned int
n += buffer_putnoflush(b, ".", 1) ;
n += buffer_putnoflush(b, fmt, uint_fmt(fmt, rql->http_major ? rql->http_minor : 1)) ;
n += buffer_putnoflush(b, " ", 1) ;
- if (status)
- {
- char fmt[UINT_FMT] ;
- size_t m = uint_fmt(fmt, status) ;
- n += buffer_putnoflush(b, fmt, m) ;
- n += buffer_putnoflush(b, " ", 1) ;
- }
+ n += buffer_putnoflush(b, fmt, uint_fmt(fmt, status)) ;
+ n += buffer_putnoflush(b, " ", 1) ;
n += buffer_putsnoflush(b, line) ;
n += buffer_putnoflush(b, "\r\n", 2) ;
return n ;