#include "apr_atomic.h"
#include <unistd.h>
#include "http_protocol.h"
+#include "../../server/test_char.h"
module AP_MODULE_DECLARE_DATA log_forensic_module;
{
for ( ; *p ; ++p) {
ap_assert(q < e);
- if (*p < ' ' || *p >= 0x7f || *p == '|' || *p == ':' || *p == '%') {
+ if (test_char_table[*(unsigned char *)p]&T_ESCAPE_FORENSIC) {
ap_assert(q+2 < e);
*q++ = '%';
sprintf(q, "%02x", *(unsigned char *)p);
int n;
for (n = 0 ; *p ; ++p, ++n)
- if (*p < ' ' || *p >= 0x7f || *p == '|' || *p == ':' || *p == '%')
+ if (test_char_table[*(unsigned char *)p]&T_ESCAPE_FORENSIC)
n += 2;
return n;
}
#define T_OS_ESCAPE_PATH (0x04)
#define T_HTTP_TOKEN_STOP (0x08)
#define T_ESCAPE_LOGITEM (0x10)
+#define T_ESCAPE_FORENSIC (0x20)
int main(int argc, char *argv[])
{
"#define T_OS_ESCAPE_PATH (%u)\n"
"#define T_HTTP_TOKEN_STOP (%u)\n"
"#define T_ESCAPE_LOGITEM (%u)\n"
+ "#define T_ESCAPE_FORENSIC (%u)\n"
"\n"
"static const unsigned char test_char_table[256] = {\n"
" 0,",
T_ESCAPE_PATH_SEGMENT,
T_OS_ESCAPE_PATH,
T_HTTP_TOKEN_STOP,
- T_ESCAPE_LOGITEM);
+ T_ESCAPE_LOGITEM,
+ T_ESCAPE_FORENSIC);
/* we explicitly dealt with NUL above
* in case some strchr() do bogosity with it */
flags |= T_ESCAPE_LOGITEM;
}
+ /* For forensic logging, scape all control characters, top bit set,
+ * :, | (used as delimiters) and % (used for escaping).
+ */
+ if (!apr_isprint(c) || c == ':' || c == '|' || c == '%'
+ || apr_iscntrl(c)) {
+ flags |= T_ESCAPE_FORENSIC;
+ }
+
printf("%u%c", flags, (c < 255) ? ',' : ' ');
}