summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/config/lexparse.c3
-rw-r--r--src/include/tipidee/log.h1
-rw-r--r--src/libtipidee/tipidee_log_request.c18
3 files changed, 19 insertions, 3 deletions
diff --git a/src/config/lexparse.c b/src/config/lexparse.c
index 799b17f..99eeaa0 100644
--- a/src/config/lexparse.c
+++ b/src/config/lexparse.c
@@ -150,7 +150,8 @@ static inline void parse_log (char const *s, size_t const *word, size_t n, mdt c
{ .name = "request", .value = TIPIDEE_LOG_REQUEST },
{ .name = "resource", .value = TIPIDEE_LOG_RESOURCE },
{ .name = "start", .value = TIPIDEE_LOG_START },
- { .name = "user-agent", .value = TIPIDEE_LOG_UA }
+ { .name = "user-agent", .value = TIPIDEE_LOG_UA },
+ { .name = "x-forwarded-for", .value = TIPIDEE_LOG_XFORWARDEDFOR }
} ;
uint32_t v = 0 ;
char pack[4] ;
diff --git a/src/include/tipidee/log.h b/src/include/tipidee/log.h
index 93ee386..b8decc0 100644
--- a/src/include/tipidee/log.h
+++ b/src/include/tipidee/log.h
@@ -23,6 +23,7 @@
#define TIPIDEE_LOG_CLIENTIP 0x0080
#define TIPIDEE_LOG_CLIENTHOST 0x0100
#define TIPIDEE_LOG_HOSTASPREFIX 0x0200
+#define TIPIDEE_LOG_XFORWARDEDFOR 0x0400
#define TIPIDEE_LOG_DEBUG 0x8000
#define TIPIDEE_LOG_DEFAULT (TIPIDEE_LOG_REQUEST | TIPIDEE_LOG_ANSWER | TIPIDEE_LOG_SIZE)
diff --git a/src/libtipidee/tipidee_log_request.c b/src/libtipidee/tipidee_log_request.c
index 6543214..54755ec 100644
--- a/src/libtipidee/tipidee_log_request.c
+++ b/src/libtipidee/tipidee_log_request.c
@@ -12,10 +12,10 @@
void tipidee_log_request (uint32_t v, tipidee_rql const *rql, tipidee_headers const *hdr, stralloc *sa)
{
- char const *a[16] = { PROG, ": info:" } ;
+ char const *a[18] = { PROG, ": info:" } ;
size_t m = 2 ;
size_t start = sa->len ; /* assert: not zero */
- size_t refpos = 0, uapos = 0 ;
+ size_t refpos = 0, uapos = 0, xffpos = 0 ;
if (!(v & TIPIDEE_LOG_REQUEST)) return ;
if (!string_quotes(sa, rql->uri.path) || !stralloc_0(sa)) goto eerr ;
if (v & TIPIDEE_LOG_REFERRER)
@@ -36,6 +36,15 @@ void tipidee_log_request (uint32_t v, tipidee_rql const *rql, tipidee_headers co
if (!string_quotes(sa, x) || !stralloc_0(sa)) goto err ;
}
}
+ if (v & TIPIDEE_LOG_XFORWARDEDFOR)
+ {
+ char const *x = tipidee_headers_search(hdr, "X-Forwarded-For") ;
+ if (x)
+ {
+ xffpos = sa->len ;
+ if (!string_quotes(sa, x) || !stralloc_0(sa)) goto err ;
+ }
+ }
if (v & TIPIDEE_LOG_HOSTASPREFIX)
{
a[m++] = " host " ;
@@ -67,6 +76,11 @@ void tipidee_log_request (uint32_t v, tipidee_rql const *rql, tipidee_headers co
a[m++] = " user-agent " ;
a[m++] = sa->s + uapos ;
}
+ if (xffpos)
+ {
+ a[m++] = " x-forwarded-for " ;
+ a[m++] = sa->s + xffpos ;
+ }
strerr_warnv(a, m) ;
sa->len = start ;
return ;