Deal with serve()'s recently changed log messages.
[privoxy.git] / tools / privoxy-log-parser.pl
1 #!/usr/bin/perl
2
3 ################################################################################
4 # privoxy-log-parser
5 #
6 # A parser for Privoxy log messages. For incomplete documentation run
7 # perldoc privoxy-log-parser(.pl), for fancy screenshots see:
8 #
9 # http://www.fabiankeil.de/sourcecode/privoxy-log-parser/
10 #
11 # $Id: privoxy-log-parser.pl,v 1.61 2009/12/12 11:31:17 fabiankeil Exp $
12 #
13 # TODO:
14 #       - LOG_LEVEL_CGI, LOG_LEVEL_ERROR, LOG_LEVEL_WRITE content highlighting
15 #       - create fancy statistics
16 #       - grep through Privoxy sources to find unsupported log messages
17 #       - hunt down substitutions that match content from variables which
18 #         can contain stuff like ()?'[]
19 #       - replace $h{'foo'} with h('foo') where possible
20 #       - hunt down XXX comments instead of just creating them
21 #       - add example log lines for every regex and mark them up for
22 #         regression testing
23 #       - Handle incomplete input without Perl warning about undefined variables.
24 #       - Use generic highlighting function that takes a regex and the
25 #         hash key as input.
26 #
27 # Copyright (c) 2007-2009 Fabian Keil <fk@fabiankeil.de>
28 #
29 # Permission to use, copy, modify, and distribute this software for any
30 # purpose with or without fee is hereby granted, provided that the above
31 # copyright notice and this permission notice appear in all copies.
32 #
33 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
34 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
35 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
36 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
37 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
38 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
39 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
40 ################################################################################
41
42 use strict;
43 use warnings;
44 use Getopt::Long;
45
46 use constant {
47     PRIVOXY_LOG_PARSER_VERSION => '0.5',
48     # Feel free to mess with these ...
49     DEFAULT_BACKGROUND => 'black',  # Choose registered colour (like 'black')
50     DEFAULT_TEXT_COLOUR => 'white', # Choose registered colour (like 'black')
51     HEADER_DEFAULT_COLOUR => 'yellow',
52     REGISTER_HEADERS_WITH_THE_SAME_COLOUR => 1,
53
54     CLI_OPTION_DEFAULT_TO_HTML_OUTPUT => 0,
55     CLI_OPTION_TITLE => 'Privoxy-Log-Parser in da house',
56     CLI_OPTION_NO_EMBEDDED_CSS => 0,
57     CLI_OPTION_NO_MSECS => 0,
58     CLI_OPTION_NO_SYNTAX_HIGHLIGHTING => 0,
59     CLI_OPTION_ERROR_LOG_FILE => '/var/log/privoxy-log.log',
60     CLI_OPTION_SHOW_INEFFECTIVE_FILTERS => 0,
61     CLI_OPTION_ACCEPT_UNKNOWN_MESSAGES => 0,
62     CLI_OPTION_STATISTICS => 0,
63
64     SUPPRESS_SUCCEEDED_FILTER_ADDITIONS => 1,
65     SHOW_SCAN_INTRO => 0,
66     SHOW_FILTER_READIN_IN => 0,
67     SUPPRESS_EMPTY_LINES => 1,
68     SUPPRESS_SUCCESSFUL_CONNECTIONS => 1,
69     SUPPRESS_ACCEPTED_CONNECTIONS => 1,
70     SUPPRESS_GIF_NOT_CHANGED => 1,
71     SUPPRESS_NEED_TO_DE_CHUNK_FIRST => 1,
72
73     DEBUG_HEADER_REGISTERING => 0,
74     DEBUG_HEADER_HIGHLIGHTING => 0,
75     DEBUG_TICKS => 0,
76     DEBUG_PAINT_IT => 0,
77     DEBUG_SUPPRESS_LOG_MESSAGES => 0,
78
79     PUNISH_MISSING_LOG_KNOWLEDGE_WITH_DEATH => 0,
80     PUNISH_MISSING_HIGHLIGHT_KNOWLEDGE_WITH_DEATH => 1,
81
82     LOG_UNPARSED_LINES_TO_EXTRA_FILE => 0,
83
84     # You better leave these alone unless you know what you're doing.
85     COLOUR_RESET      => "\033[0;0m",
86     ESCAPE => "\033[",
87 };
88
89 sub prepare_our_stuff () {
90
91     # Syntax Higlight hash
92     our @all_colours = (
93         'red', 'green', 'brown', 'blue', 'purple', 'cyan',
94         'light_gray', 'light_red', 'light_green', 'yellow',
95         'light_blue', 'pink', 'light_cyan', 'white'
96     );
97
98     our %h = (
99         # LOG_LEVEL
100         Info            => 'blue',
101         Header          => 'green',
102         Filter          => 'purple', # XXX: Used?
103         'Re-Filter'     => 'purple',
104         Connect         => 'brown',
105         Request         => 'light_cyan',
106         CGI             => 'light_green',
107         Redirect        => 'cyan',
108         Error           => 'light_red',
109         Crunch          => 'cyan',
110         'Fatal error'   => 'light_red',
111         'Gif-Deanimate' => 'blue',
112         Force           => 'red',
113         Writing         => 'light_green',
114         # ----------------------
115         URL                  => 'yellow',
116         path                 => 'brown',
117         request_             => 'brown', # host+path but no protocol
118         'ip-address'         => 'yellow',
119         Number               => 'yellow',
120         Standard             => 'reset',
121         Truncation           => 'light_red',
122         Status               => 'brown',
123         Timestamp            => 'brown',
124         Crunching            => 'light_red',
125         crunched             => 'light_red',
126         'Request-Line'       => 'pink',
127         method               => 'purple',
128         destination          => 'yellow',
129         'http-version'       => 'pink',
130         'crunch-pattern'     => 'pink',
131         not                  => 'brown',
132         file                 => 'brown',
133         signal               => 'yellow',
134         version              => 'green',
135         'program-name'       => 'cyan',
136         port                 => 'red',
137         host                 => 'red',
138         warning              => 'light_red',
139         debug                => 'light_red',
140         filter               => 'green',
141         tag                  => 'green',
142         tagger               => 'green',
143         'status-message'     => 'light_cyan',
144         'status-code'        => 'yellow',
145         'invalid-request'    => 'light_red',
146         'hits'               => 'yellow',
147         error                => 'light_red',
148         'rewritten-URL'      => 'light_red',
149         'pcrs-delimiter'     => 'light_red',
150         'ignored'            => 'light_red',
151         'action-bits-update' => 'light_red',
152         'configuration-line' => 'red',
153         'content-type'       => 'yellow',
154     );
155
156     our %h_colours = %h;
157
158     # Header colours need their own hash so the keys can be accessed properly
159     our %header_colours = (
160         # Prefilled with headers that should not appear with default header colours
161         Cookie => 'light_red',
162         'Set-Cookie' => 'light_red',
163         Warning => 'light_red',
164         Default => HEADER_DEFAULT_COLOUR,
165     );
166
167     # Crunch reasons need their own hash as well
168     our %reason_colours = (
169         'Unsupported HTTP feature'               => 'light_red',
170         Blocked                                  => 'light_red',
171         Untrusted                                => 'light_red',
172         Redirected                               => 'green', 
173         'CGI Call'                               => 'white',
174         'DNS failure'                            => 'red',
175         'Forwarding failed'                      => 'light_red',
176         'Connection failure'                     => 'light_red',
177         'Out of memory (may mask other reasons)' => 'light_red',
178         'No reason recorded'                     => 'light_red',
179     );
180
181     our @time_colours = ('white', 'light_gray');
182
183     # Translate highlight strings into highlight code
184     prepare_highlight_hash(\%header_colours);
185     prepare_highlight_hash(\%reason_colours);
186     prepare_highlight_hash(\%h);
187     prepare_colour_array(\@all_colours);
188     prepare_colour_array(\@time_colours);
189     init_css_colours();
190
191     init_stats();
192 }
193
194 sub paint_it ($) {
195 ###############################################################
196 # Takes a colour string and returns an ANSI escape sequence
197 # (unless --no-syntax-highlighting is used).
198 # XXX: The Rolling Stones reference has to go.
199 ###############################################################
200
201     my $colour = shift @_;
202
203     return "" if cli_option_is_set('no-syntax-highlighting');
204
205     my %light = (
206         black       => 0,    
207         red         => 0,   
208         green       => 0,  
209         brown       => 0, 
210         blue        => 0,   
211         purple      => 0, 
212         cyan        => 0,  
213         light_gray  => 0,
214         gray        => 0,
215         dark_gray   => 1,
216         light_red   => 1,
217         light_green => 1,
218         yellow      => 1,
219         light_blue  => 1,
220         pink        => 1,
221         light_cyan  => 1,
222         white       => 1,
223     );
224
225     my %text = (
226         black       => 30,    
227         red         => 31,   
228         green       => 32,  
229         brown       => 33, 
230         blue        => 34,   
231         purple      => 35, 
232         cyan        => 36,  
233         gray        => 37,
234         light_gray  => 37,
235         dark_gray   => 30,
236         light_red   => 31,
237         light_green => 32,
238         yellow      => 33,
239         light_blue  => 34,
240         pink        => 35,
241         light_cyan  => 36,
242         white       => 37,
243     );
244
245     my $bg_code = get_background();
246     my $colour_code;
247     our $default = default_colours();
248
249     if (defined($text{$colour})) {
250         $colour_code  = ESCAPE;
251         $colour_code .= $text{$colour};
252         $colour_code .= ";";
253         $colour_code .= $light{$colour} ? "1" : "2";
254         $colour_code .= ";";
255         $colour_code .= $bg_code; 
256         $colour_code .= "m";
257         debug_message $colour . " is \'" . $colour_code . $colour . $default . "\'" if DEBUG_PAINT_IT; 
258
259     } elsif ($colour =~ /reset/) {
260
261         $colour_code = default_colours();
262
263     } else {
264
265         die "What's $colour supposed to mean?\n"; 
266     }
267
268     return $colour_code;
269 }
270
271 sub get_semantic_html_markup ($) {
272 ###############################################################
273 # Takes a string and returns a span element
274 ###############################################################
275
276     my $type = shift @_;
277     my $code;
278
279     if ($type =~ /Standard/) {
280         $code = '</span>';
281     } else {
282         $type = lc($type);
283         $code = '<span title="' . $type . '" class="' . $type . '">';
284     }
285
286     return $code;
287 }
288
289 sub cli_option_is_set ($) {
290
291     our %cli_options;
292     my $cli_option = shift;
293
294     die "Unknown CLI option: $cli_option" unless defined $cli_options{$cli_option};
295
296     return $cli_options{$cli_option};
297 }
298
299 sub get_html_title () {
300
301     our %cli_options;
302     return $cli_options{'title'};
303
304 }
305
306 sub init_css_colours() {
307
308     our %css_colours = (
309         black       => "000",    
310         red         => "F00",   
311         green       => "0F0",  
312         brown       => "C90", 
313         blue        => "0F0",   
314         purple      => "F06", # XXX: wrong  
315         cyan        => "F09", # XXX: wrong  
316         light_gray  => "999",
317         gray        => "333",
318         dark_gray   => "222",
319         light_red   => "F33",
320         light_green => "33F",
321         yellow      => "FF0",
322         light_blue  => "30F",
323         pink        => "F0F",
324         light_cyan  => "66F",
325         white       => "FFF",
326     );
327 }
328
329 sub get_css_colour ($) {
330
331    our %css_colours;
332    my $colour = shift;
333
334    die "What's $colour supposed to mean?\n" unless defined($css_colours{$colour}); 
335
336    return '#' . $css_colours{$colour};
337 }
338
339 sub get_css_line ($) {
340
341     our %h_colours;
342
343     my $class = shift;
344     my $css_line;
345
346     $css_line .= '.' . lc($class) . ' {'; # XXX: lc() shouldn't be necessary
347     die "What's $class supposed to mean?\n" unless defined($h_colours{$class}); 
348     $css_line .= 'color:' . get_css_colour($h_colours{$class}) . ';';
349     $css_line .= 'background-color:' . get_css_colour(DEFAULT_BACKGROUND) . ';';
350     $css_line .= '}' . "\n"; 
351
352     return $css_line;
353 }
354
355 sub get_css_line_for_colour ($) {
356
357     our %h_colours;
358
359     my $colour = shift;
360     my $css_line;
361
362     $css_line .= '.' . lc($colour) . ' {'; # XXX: lc() shouldn't be necessary
363     $css_line .= 'color:' . get_css_colour($colour) . ';';
364     $css_line .= 'background-color:' . get_css_colour(DEFAULT_BACKGROUND) . ';';
365     $css_line .= '}' . "\n"; 
366
367     return $css_line;
368 }
369
370 # XXX: Wrong solution
371 sub get_missing_css_lines () {
372
373     my $css_line;
374
375     $css_line .= '.' . 'default' . ' {';
376     $css_line .= 'color:' . HEADER_DEFAULT_COLOUR . ';';
377     $css_line .= 'background-color:' . get_css_colour(DEFAULT_BACKGROUND) . ';';
378     $css_line .= '}' . "\n"; 
379
380     return $css_line;
381 }
382
383 sub get_css () {
384
385     our %h_colours;
386     our %css_colours; #XXX: Wrong solution
387
388     my $css = '';
389
390     $css .= '.privoxy-log {';
391     $css .= 'color:' . get_css_colour(DEFAULT_TEXT_COLOUR) . ';';
392     $css .= 'background-color:' . get_css_colour(DEFAULT_BACKGROUND) . ';';
393     $css .= '}' . "\n"; 
394  
395     foreach my $key (keys %h_colours) {
396
397         next if ($h_colours{$key} =~ m/reset/); #XXX: Wrong solution.
398         $css .= get_css_line($key);
399
400     }
401
402     foreach my $colour (keys %css_colours) {
403
404         $css .= get_css_line_for_colour($colour);
405
406     }
407
408     $css .= get_missing_css_lines(); #XXX: Wrong solution
409
410     return $css;
411 }
412
413 sub print_intro () {
414
415     my $intro = '';
416
417     if (cli_option_is_set('html-output')) {
418
419         my $title = get_html_title();
420
421         $intro .= '<html><head>';
422         $intro .= '<title>' . $title . '</title>';
423         $intro .= '<style>' . get_css() . '</style>' unless cli_option_is_set('no-embedded-css');
424         $intro .= '</head><body>';
425         $intro .= '<h1>' . $title . '</h1><p class="privoxy-log">';
426
427         print $intro;
428     }
429 }
430
431 sub print_outro () {
432
433     my $outro = '';
434
435     if (cli_option_is_set('html-output')) {
436
437         $outro = '</p></body></html>';
438         print $outro;
439
440     }
441 }
442
443 sub get_line_end () {
444
445     my $line_end = "\n";
446
447     $line_end = '<br>' . $line_end if cli_option_is_set('html-output');
448
449     return $line_end;
450 }
451
452 sub get_colour_html_markup ($) {
453 ###############################################################
454 # Takes a colour string a span element. XXX: WHAT?
455 # XXX: This function shouldn't be necessary, the
456 # markup should always be semantically correct.
457 ###############################################################
458
459     my $type = shift @_;
460     my $code;
461
462     if ($type =~ /Standard/) {
463         $code = '</span>';
464     } else {
465         $code = '<span class="' . lc($type) . '">';
466     }
467
468     return $code;
469 }
470
471 sub default_colours () {
472     # XXX: Properly
473     our $bg_code;
474     return reset_colours();
475 }
476
477 sub show_colours () {
478     # XXX: Implement
479 }
480
481 sub reset_colours () {
482     return ESCAPE . "0m";
483 }
484
485 sub set_background ($){
486
487     my $colour = shift;
488     our $bg_code;
489     my %backgrounds = (
490               black       => "40",    
491               red         => "41",   
492               green       => "42",  
493               brown       => "43", 
494               blue        => "44",   
495               magenta     => "45",  
496               cyan        => "46",
497               white       => "47",  
498               default     => "49",  
499     );
500     
501     if (defined($backgrounds{$colour})) {
502         $bg_code = $backgrounds{$colour};
503     } else {
504         die "Invalid background colour: " . $colour;
505     }
506 }
507
508 sub get_background (){
509     return our $bg_code;
510 }
511
512 sub prepare_highlight_hash ($) {
513     my $ref = shift;
514
515     if (!cli_option_is_set('html-output')) {
516
517         foreach my $key (keys %$ref) {
518             $$ref{$key} = paint_it($$ref{$key}); 
519         }
520
521     } else {
522
523         foreach my $key (keys %$ref) {
524             $$ref{$key} = get_semantic_html_markup($key); 
525         }
526
527     } 
528 }
529
530 sub prepare_colour_array ($) {
531     my $ref = shift;
532
533     if (!cli_option_is_set('html-output')) {
534
535         foreach my $i (0 ... @$ref - 1) {
536             $$ref[$i] = paint_it($$ref[$i]); 
537         } 
538
539     } else {
540
541         foreach my $i (0 ... @$ref - 1) {
542             $$ref[$i] = get_colour_html_markup($$ref[$i]);
543         } 
544
545     }
546 }
547
548 sub found_unknown_content ($) {
549
550     my $unknown = shift;
551     my $message;
552
553     our %req;
554     our $t;
555
556     return if cli_option_is_set('accept-unknown-messages');
557
558     return if ($unknown =~ /\[too long, truncated\]$/);
559
560     $message = "found_unknown_content: Don't know how to highlight: ";
561     # Break line so the log file can later be parsed as Privoxy log file again
562     $message .= '"' . $unknown . '"' . " in:\n";
563     $message .= $req{$t}{'log-message'};
564     debug_message($message);
565     log_parse_error($req{$t}{'log-message'});
566
567     die "Unworthy content parser" if PUNISH_MISSING_LOG_KNOWLEDGE_WITH_DEATH;
568 }
569
570 sub log_parse_error ($) {
571
572     my $message = shift;
573
574     if (LOG_UNPARSED_LINES_TO_EXTRA_FILE) {
575         open(ERRORLOG, ">>" . ERROR_LOG_FILE) || die "Writing " . ERROR_LOG_FILE . " failed";
576         print ERRORLOG $message;
577         close(ERRORLOG);
578     }
579 }
580
581 sub debug_message (@) {
582     my @message = @_;
583     our %h;
584
585     print $h{'debug'} . "@message" . $h{'Standard'} . "\n";
586 }
587
588 ################################################################################
589 # highlighter functions that aren't loglevel-specific 
590 ################################################################################
591
592 sub h ($) {
593
594     # Get highlight marker
595     our %h;
596     my $highlight = shift; # XXX: Stupid name;
597     my $result = '';
598     my $message;
599
600     if (defined($highlight)) {
601
602         $result = $h{$highlight};
603
604     } else {
605
606         $message = "h: Don't recognize highlighter $highlight.";
607         debug_message($message);
608         log_parser_error($message);
609         die "Unworthy highlighter function" if PUNISH_MISSING_HIGHLIGHT_KNOWLEDGE_WITH_DEATH;
610     }
611    
612     return $result;
613 }
614
615 sub highlight_known_headers ($) {
616
617     my $content = shift;
618     our %header_colours;
619     our %h;
620     my $headers = join ('|', keys %header_colours);
621
622     debug_message("Searching $content for things to highlight.") if DEBUG_HEADER_HIGHLIGHTING;
623
624     if ($content =~ m/(?<=\s)($headers):/) {
625         my $header = $1;
626         $content =~ s@(?<=[\s|'])($header)(?=:)@$header_colours{$header}$1$h{'Standard'}@ig;
627         debug_message("Highlighted $content") if DEBUG_HEADER_HIGHLIGHTING;
628     }
629
630     return $content;
631 }
632
633 sub highlight_matched_request_line ($$) {
634
635     my $result = shift; # XXX: Stupid name;
636     my $regex = shift;
637     if ($result =~ m@(.*)($regex)(.*)@) {
638         $result = $1 . highlight_request_line($2) . $3
639     }
640     return $result;
641 }
642
643 sub highlight_request_line ($) {
644
645     my $rl = shift;
646     my ($method, $url, $http_version);
647     our %h;
648
649     #GET http://images.sourceforge.net/sfx/icon_warning.gif HTTP/1.1
650     if ($rl =~ m/Invalid request/) {
651
652         $rl = h('invalid-request') . $rl . h('Standard');
653
654     } elsif ($rl =~ m/^([-\w]+) (.*) (HTTP\/\d\.\d)/) {
655
656         # XXX: might not match in case of HTTP method fuzzing.
657         # XXX: save these: ($method, $path, $http_version) = ($1, $2, $3);
658         $rl =~ s@^(\w+)@$h{'method'}$1$h{'Standard'}@;
659         if ($rl =~ /http:\/\//) {
660             $rl = highlight_matched_url($rl, '[^\s]*(?=\sHTTP)');
661         } else {
662             $rl = highlight_matched_pattern($rl, 'request_', '[^\s]*(?=\sHTTP)');
663         }
664
665         $rl =~ s@(HTTP\/\d\.\d)$@$h{'http-version'}$1$h{'Standard'}@;
666
667     } elsif ($rl =~ m/\.\.\. \[too long, truncated\]$/) {
668
669         $rl =~ s@^(\w+)@$h{'method'}$1$h{'Standard'}@;
670         $rl = highlight_matched_url($rl, '[^\s]*(?=\.\.\.)');
671
672     } elsif ($rl =~ m/^ $/) {
673
674         $rl = h('error') . "No request line specified!" . h('Standard');
675
676     } else {
677
678         debug_message ("Can't parse request line: $rl");
679
680     }
681
682     return $rl;
683 }
684
685 sub highlight_response_line ($) {
686
687     my $rl = shift;
688     my ($http_version, $status_code, $status_message);
689
690     #HTTP/1.1 200 OK
691     #ICY 200 OK
692
693     # TODO: Mark different status codes differently
694
695     if ($rl =~ m/((?:HTTP\/\d\.\d|ICY)) (\d+) (.*)/) {
696         ($http_version, $status_code, $status_message) = ($1, $2, $3);
697     } else {
698         debug_message ("Can't parse response line: $rl") and die 'Fix this';
699     }
700
701     # Rebuild highlighted
702     $rl= "";
703     $rl .= h('http-version') . $http_version . h('Standard');
704     $rl .= " ";
705     $rl .= h('status-code') . $status_code . h('Standard');
706     $rl .= " ";
707     $rl .= h('status-message') . $status_message . h('Standard');
708
709     return $rl;
710 }
711
712 sub highlight_matched_url ($$) {
713
714     my $result = shift; # XXX: Stupid name;
715     my $regex = shift;
716
717     #print "Got $result, regex ($regex)\n";
718
719     if ($result =~ m@(.*?)($regex)(.*)@) {
720         $result = $1 . highlight_url($2) . $3;
721         #print "Now the result is $result\n";
722     }
723
724     return $result;
725 }
726
727 sub highlight_matched_host ($$) {
728
729     my $result = shift; # XXX: Stupid name;
730     my $regex = shift;
731
732     if ($result =~ m@(.*?)($regex)(.*)@) {
733         $result = $1 . h('host') . $2 . h('Standard') . $3;
734     }
735
736     return $result;
737 }
738
739 sub highlight_matched_pattern ($$$) {
740
741     our %h;
742     my $result = shift; # XXX: Stupid name;
743     my $key = shift;
744     my $regex = shift;
745
746     die "Unknown key $key" unless defined $h{$key};
747
748     if ($result =~ m@(.*?)($regex)(.*)@) {
749         $result = $1 . h($key) . $2 . h('Standard') . $3;
750     }
751
752     return $result;
753 }
754
755 sub highlight_matched_path ($$) {
756
757     my $result = shift; # XXX: Stupid name;
758     my $regex = shift;
759
760     if ($result =~ m@(.*?)($regex)(.*)@) {
761         $result = $1 . h('path') . $2 . h('Standard') . $3;
762     }
763
764     return $result;
765 }
766
767 sub highlight_url ($) {
768
769     my $url = shift;
770
771     if (cli_option_is_set('html-output')) {
772
773         $url = '<a href="' . $url . '">' . $url . '</a>';
774
775     } else {
776
777         $url = h('URL') . $url . h('Standard');
778
779     }
780
781     return $url;
782 }
783
784 ################################################################################
785 # loglevel-specific highlighter functions
786 ################################################################################
787
788 sub handle_loglevel_header ($) {
789
790     my $content = shift;
791     my $c = $content;
792     our $t;
793     our %req;
794     our %h;
795     our %header_colours;
796     our @all_colours;
797     our $header_colour_index;
798     our $no_special_header_highlighting;
799
800     # Register new headers
801     # scan: Accept: image/png,image/*;q=0.8,*/*;q=0.5
802     if ($c =~ m/^scan: ((?>[^:]+)):/) {
803         my $header = $1;
804         if (!defined($header_colours{$header}) and $header =~ /^[\d\w-]*$/) {
805             debug_message "Registering previously unknown header $1" if DEBUG_HEADER_REGISTERING;
806
807             if (REGISTER_HEADERS_WITH_THE_SAME_COLOUR) {
808                 $header_colours{$header} =  $header_colours{'Default'};
809             } else {
810                 $header_colours{$header} = $all_colours[$header_colour_index % @all_colours];
811                 $header_colour_index++;
812             }
813         }
814     }
815
816     if ($c =~ m/^scan: ((\w*) (.*) (HTTP\/\d\.\d))/) {
817
818             # Client request line
819             # Save for statistics (XXX: Not implemented yet)
820             $req{$t}{'method'} = $2;
821             $req{$t}{'destination'} = $3;
822             $req{$t}{'http-version'} = $4;
823
824             $content = highlight_request_line($1);
825
826     } elsif ($c =~ m/^(scan: )((?:HTTP\/\d\.\d|ICY) (\d+) (.*))/) {
827
828             # Server response line
829             $req{$t}{'response_line'} = $2;
830             $req{$t}{'status_code'} = $3;
831             $req{$t}{'status_message'} = $4;
832             $content = $1 . highlight_response_line($req{$t}{'response_line'});
833
834     } elsif ($c =~ m/^Crunching (?:server|client) header: .* \(contains: ([^\)]*)\)/) {
835
836         # Crunching server header: Set-Cookie: trac_form_token=d5308c34e16d15e9e301a456; (contains: Cookie:)
837         $content =~ s@(?<=contains: )($1)@$h{'crunch-pattern'}$1$h{'Standard'}@;
838         $content =~ s@(Crunching)@$h{$1}$1$h{'Standard'}@;    
839
840     } elsif ($c =~ m/^New host is: ([^\s]*)\./) {
841
842         # New host is: trac.vidalia-project.net. Crunching Referer: http://www.vidalia-project.net/
843         $c = highlight_matched_host($c, '(?<=New host is: )[^\s]+');
844         $content = highlight_matched_url($c, '(?<=Crunching Referer: )[^\s]+');
845
846     } elsif ($c =~ m/^Text mode enabled by force. (Take cover)!/) {
847
848         # Text mode enabled by force. Take cover!
849         $content =~ s@($1)@$h{'warning'}$1$h{'Standard'}@;
850
851     } elsif ($c =~ m/^(New HTTP Request-Line: )(.*)/) {
852
853         # New HTTP Request-Line: GET http://www.privoxy.org/ HTTP/1.1
854         $content = $1 . highlight_request_line($2);
855
856     } elsif ($c =~ m/^Adjust(ed)? Content-Length to \d+/) {
857
858         # Adjusted Content-Length to 2132
859         # Adjust Content-Length to 33533
860         $content =~ s@(?<=Content-Length to )(\d+)@$h{'Number'}$1$h{'Standard'}@;
861         $content = highlight_known_headers($content);
862
863     } elsif ($c =~ m/^Destination extracted from "Host:" header. New request URL:/) {
864
865         # Destination extracted from "Host:" header. New request URL: http://www.cccmz.de/~ridcully/blog/
866         $content = highlight_matched_url($content, '(?<=New request URL: ).*');
867
868     } elsif ($c =~ m/^Couldn\'t parse:/) {
869
870         # XXX: These should probable be logged with LOG_LEVEL_ERROR
871         # Couldn't parse: If-Modified-Since: Wed, 21 Mar 2007 16:34:50 GMT (crunching!)
872         # Couldn't parse: at, 24 Mar 2007 13:46:21 GMT in If-Modified-Since: Sat, 24 Mar 2007 13:46:21 GMT (crunching!)
873         $content =~ s@^(Couldn\'t parse)@$h{'error'}$1$h{'Standard'}@;
874
875     } elsif ($c =~ /^Tagger \'([^\']*)\' added tag \'([^\']*)\'/ or
876              $c =~ m/^Adding tag \'([^\']*)\' created by header tagger \'([^\']*)\'/) {
877
878         # Adding tag 'GET request' created by header tagger 'method-man' (XXX: no longer used)
879         # Tagger 'revalidation' added tag 'REVALIDATION-REQUEST'. No action bit update necessary.
880         # Tagger 'revalidation' added tag 'REVALIDATION-REQUEST'. Action bits updated accordingly.
881
882         # XXX: Save tag and tagger
883
884         $content =~ s@(?<=^Tagger \')([^\']*)@$h{'tagger'}$1$h{'Standard'}@;
885         $content =~ s@(?<=added tag \')([^\']*)@$h{'tag'}$1$h{'Standard'}@;
886         $content =~ s@(?<=Action bits )(updated)@$h{'action-bits-update'}$1$h{'Standard'}@;
887         $no_special_header_highlighting = 1;
888
889     } elsif ($c =~ /^Tagger \'([^\']*)\' didn['']t add tag \'([^\']*)\'/) {
890
891         # Tagger 'revalidation' didn't add tag 'REVALIDATION-REQUEST'. Tag already present
892         # XXX: Save tag and tagger
893
894         $content =~ s@(?<=^Tagger \')([^\']*)@$h{'tag'}$1$h{'Standard'}@;
895         $content =~ s@(?<=didn['']t add tag \')([^\']*)@$h{'tagger'}$1$h{'Standard'}@;
896
897     } elsif ($c =~ m/^(?:scan:|Randomiz|addh:|Adding:|Removing:|Referer:|Modified:|Accept-Language header|[Cc]ookie)/
898           or $c =~ m/^(Text mode is already enabled|Denied request with NULL byte|Replaced:|add-unique:)/
899           or $c =~ m/^(Crunched (incoming|outgoing) cookie|Suppressed offer|Accepted the client)/
900           or $c =~ m/^(addh-unique|Referer forged to)/
901           or $c =~ m/^Downgraded answer to HTTP\/1.0/
902           or $c =~ m/^Parameter: \+hide-referrer\{[^\}]*\} is a bad idea, but I don\'t care./
903           or $c =~ m/^Referer (?:overwritten|replaced) with: Referer: / #XXX: should this be highlighted?
904           or $c =~ m/^Referer crunched!/
905           or $c =~ m/^crunched x-forwarded-for!/
906           or $c =~ m/^crunched From!/
907           or $c =~ m/^ modified$/
908           or $c =~ m/^Content filtering is enabled. Crunching:/
909           or $c =~ m/^force-text-mode overruled the client/
910           or $c =~ m/^Server time in the future\./
911           or $c =~ m/^content-disposition header crunched and replaced with:/i
912           or $c =~ m/^Reducing white space in /
913           or $c =~ m/^Ignoring single quote in /
914           or $c =~ m/^Converting tab to space in /
915           or $c =~ m/A HTTP\/1\.1 response without/
916           or $c =~ m/Disabled filter mode on behalf of the client/
917           or $c =~ m/Keeping the (?:server|client) header /
918           or $c =~ m/Content modified with no Content-Length header set/
919           or $c =~ m/^Appended client IP address to/
920           or $c =~ m/^Removing 'Connection: close' to imply keep-alive./
921           or $c =~ m/^keep-alive support is disabled/
922             )
923     {
924         # XXX: Some of these may need highlighting
925
926         # Modified: User-Agent: Mozilla/5.0 (X11; U; SunOS i86pc; pl-PL; rv:1.8.1.1) Gecko/20070214 Firefox/2.0.0.1
927         # Accept-Language header crunched and replaced with: Accept-Language: pl-pl
928         # cookie 'Set-Cookie: eZSessionCookie=07bfec287c197440d299f81580593c3d; \
929         #  expires=Thursday, 12-Apr-07 15:16:18 GMT; path=/' send by \
930         #  http://wirres.net/article/articleview/4265/1/6/ appears to be using time format 1 (XXX: gone with the wind)
931         # Cookie rewritten to a temporary one: Set-Cookie: NSC_gffe-iuuq-mc-wtfswfs=8efb33a53660;path=/
932         # Text mode is already enabled
933         # Denied request with NULL byte(s) turned into line break(s)
934         # Replaced: 'Connection: Yo, home to Bel Air' with 'Connection: close'
935         # addh-unique: Host: people.freebsd.org
936         # Suppressed offer to compress content
937         # Crunched incoming cookie -- yum!
938         # Accepted the client's request to fetch without filtering.
939         # Crunched outgoing cookie: Cookie: PREF=ID=6cf0abd347b30262:TM=1173357617:LM=1173357617:S=jZypyyJ7LPiwFi1_
940         # addh-unique: Host: subkeys.pgp.net:11371
941         # Referer forged to: Referer: http://10.0.0.1/
942         # Downgraded answer to HTTP/1.0
943         # Parameter: +hide-referrer{pille-palle} is a bad idea, but I don't care.
944         # Referer overwritten with: Referer: pille-palle
945         # Referer replaced with: Referer: pille-palle
946         # crunched x-forwarded-for!
947         # crunched From!
948         #  modified # XXX: pretty stupid log message
949         # Content filtering is enabled. Crunching: 'Range: 1234-5678' to prevent range-mismatch problems
950         # force-text-mode overruled the client's request to fetch without filtering!
951         # Server time in the future.
952         # content-disposition header crunched and replaced with: content-disposition: filename=baz
953         # Content-Disposition header crunched and replaced with: content-disposition: filename=baz
954         # Reducing white space in 'X-LWS-Test: "This  is  quoted" this is not "this  is  " but " this again   is  not'
955         # Ignoring single quote in 'X-LWS-Test: "This  is  quoted" this is not "this  is  " but "  this again   is  not'
956         # Converting tab to space in 'X-LWS-Test:   "This  is  quoted" this   is  not "this  is  "  but  "\
957         #  this again   is  not'
958         # A HTTP/1.1 response without Connection header implies keep-alive.
959         # Disabled filter mode on behalf of the client.
960         # Keeping the server header 'Connection: keep-alive' around.
961         # Keeping the client header 'Connection: close' around. The connection will not be kept alive.
962         # Keeping the client header 'Connection: keep-alive' around. The connection will be kept alive if possible.
963         # Content modified with no Content-Length header set. Creating a fake one for adjustment later on.
964         # Appended client IP address to X-Forwarded-For: 10.0.0.2, 10.0.0.1
965         # Removing 'Connection: close' to imply keep-alive.
966         # keep-alive support is disabled. Crunching: Keep-Alive: 300.
967
968     } elsif ($c =~ m/^scanning headers for:/) {
969
970         return '' unless SHOW_SCAN_INTRO;
971
972     } elsif ($c =~ m/^[Cc]runch(ing|ed)|crumble crunched:/) {
973         # crunched User-Agent!
974         # Crunching: Content-Encoding: gzip
975
976         $content =~ s@(Crunching|crunched)@$h{$1}$1$h{'Standard'}@;
977
978     } elsif ($c =~ m/^Offending request data with NULL bytes turned into \'°\' characters:/) {
979         
980         # Offending request data with NULL bytes turned into '°' characters: Â°Â°n°°(°°°
981
982         $content = h('warning') . $content . h('Standard');
983  
984     } elsif ($c =~ m/^(Transforming \")(.*?)(\" to \")(.*?)(\")/) {
985
986         # Transforming "Proxy-Authenticate: Basic realm="Correos Proxy Server"" to\
987         #  "Proxy-Authenticate: Basic realm="Correos Proxy Server""
988
989        $content =~ s@(?<=^Transforming \")(.*)(?=\" to)@$h{'Header'}$1$h{'Standard'}@;
990        $content =~ s@(?<=to \")(.*)(?=\")@$h{'Header'}$1$h{'Standard'}@;
991
992     } elsif ($c =~ m/^Removing empty header/) {
993
994         # Removing empty header
995         # Ignore for now
996
997     } elsif ($c =~ m/^Content-Type: .* not replaced/) {
998
999         # Content-Type: application/octet-stream not replaced. It doesn't look like text.\
1000         #  Enable force-text-mode if you know what you're doing.
1001         # XXX: Could highlight more here.
1002         $content =~ s@(?<=^Content-Type: )(.*)(?= not replaced)@$h{'content-type'}$1$h{'Standard'}@;
1003
1004     } elsif ($c =~ m/^(Server|Client) keep-alive timeout is/) {
1005
1006        # Server keep-alive timeout is 5. Sticking with 10.
1007        # Client keep-alive timeout is 20. Sticking with 10.
1008
1009        $content =~ s@(?<=timeout is )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1010        $content =~ s@(?<=Sticking with )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1011
1012     } elsif ($c =~ m/^Reducing keep-alive timeout/) {
1013
1014        # Reducing keep-alive timeout from 60 to 10.
1015
1016        $content =~ s@(?<= from )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1017        $content =~ s@(?<= to )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1018
1019     } else {
1020
1021         found_unknown_content($content);
1022     }
1023
1024     # Highlight headers   
1025     unless ($c =~ m/^Transforming/) {
1026         $content = highlight_known_headers($content) unless $no_special_header_highlighting;
1027     }
1028
1029     return $content;
1030 }
1031
1032 sub handle_loglevel_re_filter ($) {
1033
1034     my $content = shift;
1035     my $c = $content;
1036     my $key;
1037     our $t;
1038     our %req;
1039     our %h;
1040     our %header_colours;
1041     our @all_colours;
1042     our $header_colour_index;
1043
1044     if ($c =~ /\.{3}$/
1045         and $c =~ m/^(?:re_)?filtering \'?(.*?)\'? \(size (\d*)\) with (?:filter )?\'?([^\s]*?)\'? ?\.{3}$/) {
1046
1047         # Used by Privoxy 3.0.5 and 3.0.6:
1048         # XXX: Fill in ...
1049         # Used by Privoxy 3.0.7:
1050         # filtering 'Connection: close' (size 17) with 'generic-content-ads' ...
1051
1052         $req{$t}{'filtered_header'} = $1;
1053         $req{$t}{'old_header_size'} = $2;
1054         $req{$t}{'header_filter_name'} = $3;
1055
1056         unless (cli_option_is_set('show-ineffective-filters') or
1057                 $req{$t}{'header_filter_name'} =~ m/^privoxy-filter-test$/) {
1058             return '';
1059         }
1060         $content =~ s@(?<=\(size )(\d+)@$h{'Number'}$1$h{'Standard'}@;   
1061         $content =~ s@($req{$t}{'header_filter_name'})@$h{'filter'}$1$h{'Standard'}@;
1062
1063     } elsif ($c =~ m/^ ?\.\.\. ?produced (\d*) hits \(new size (\d*)\)\./) {
1064
1065         # ...produced 0 hits (new size 23).
1066         #... produced 1 hits (new size 54).
1067
1068         $req{$t}{'header_filter_hits'} = $1;
1069         $req{$t}{'new_header_size'} = $2;
1070
1071         unless (cli_option_is_set('show-ineffective-filters') or
1072                 (defined($req{$t}{'header_filter_name'}) and
1073                  $req{$t}{'header_filter_name'} =~ m/^privoxy-filter-test$/)) {
1074
1075             if ($req{$t}{'header_filter_hits'} == 0 and
1076                 not (defined($req{$t}{'header_filter_name'}) and
1077                  $req{$t}{'header_filter_name'} =~ m/^privoxy-filter-test$/)) {
1078                 return ''; 
1079             }
1080             # Reformat including information from the intro
1081             $c = "'" . h('filter') . $req{$t}{'header_filter_name'} . h('Standard') . "'";
1082             $c .= " hit ";
1083             # XXX: Hide behind constant, it may be interesting if LOG_LEVEL_HEADER isn't enabled as well.
1084             # $c .= $req{$t}{'filtered_header'} . " ";
1085             $c .= h('Number') . $req{$t}{'header_filter_hits'}. h('Standard');
1086             $c .= ($req{$t}{'header_filter_hits'} == 1) ? " time, " : " times, ";
1087
1088             if ($req{$t}{'old_header_size'} !=  $req{$t}{'new_header_size'}) {
1089
1090                 $c .= "changing size from ";
1091                 $c .=  h('Number') . $req{$t}{'old_header_size'} . h('Standard');
1092                 $c .= " to ";
1093                 $c .= h('Number') . $req{$t}{'new_header_size'} . h('Standard');
1094                 $c .= ".";
1095
1096             } else {
1097
1098                 $c .= "keeping the size at " . $req{$t}{'old_header_size'};
1099
1100             }
1101
1102             # Highlight from last line (XXX: What?)
1103             # $c =~ s@(?<=produced )(\d+)@$h{'Number'}$1$h{'Standard'}@;   
1104             # $c =~ s@($req{$t}{'header_filter_name'})@$h{'filter'}$1$h{'Standard'}@;
1105
1106         } else {
1107
1108            # XXX: Untested
1109            $c =~ s@(?<=produced )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1110            $c =~ s@(?<=new size )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1111
1112         }
1113         $content = $c;
1114
1115     } elsif ($c =~ m/^(Tagger|Filter) ([^\s]*) has empty joblist. Nothing to do./) {
1116
1117         # Filter privoxy-filter-test has empty joblist. Nothing to do.
1118         # Tagger variable-test has empty joblist. Nothing to do.
1119
1120         $content =~ s@(?<=$1 )([^\s]*)@$h{'filter'}$1$h{'Standard'}@;
1121
1122     } elsif ($c =~ m/^(?:re_)?filtering ([^\s]+) \(size (\d+)\) with (?:filter )?\'?([^\s]+?)\'? produced (\d+) hits \(new size (\d+)\)/) {
1123
1124         # XXX: only the second version gets highlighted properly.
1125         # re_filtering www.lfk.de/favicon.ico (size 209) with filter untrackable-hulk produced 0 hits (new size 209).
1126         # filtering aci.blogg.de/ (size 37988) with 'blogg.de' produced 3 hits (new size 38057)
1127         $req{$t}{'content_source'} = $1;
1128         $req{$t}{'content_size'}   = $2;
1129         $req{$t}{'content_filter'} = $3;
1130         $req{$t}{'content_hits'}   = $4;
1131         $req{$t}{'new_content_size'} = $5;
1132         $req{$t}{'content_size_change'} = $req{$t}{'new_content_size'} - $req{$t}{'content_size'};
1133         #return '' if ($req{$t}{'content_hits'} == 0 && !cli_option_is_set('show-ineffective-filters'));
1134         if ($req{$t}{'content_hits'} == 0 and
1135             not (cli_option_is_set('show-ineffective-filters')
1136                  or ($req{$t}{'content_filter'} =~ m/^privoxy-filter-test$/))) {
1137                 return ''; 
1138         }
1139
1140         $c =~ s@(?<=\(size )(\d+)\)(?= with)@$h{'Number'}$1$h{'Standard'}@;
1141         $c =~ s@(?<=\(new size )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1142         $c =~ s@(?<=produced )(\d+)(?= hits)@$h{'Number'}$1$h{'Standard'}@;
1143
1144         $c =~ s@([^\s]+?)(\'? produced)@$h{'filter'}$1$h{'Standard'}$2@;
1145         $c = highlight_matched_host($c, '(?<=filtering )[^\s]+');
1146
1147         $c =~ s@\.$@ @;
1148         $c .= "(" . $h{'Number'};
1149         $c .= "+" if ($req{$t}{'content_size_change'} >= 0);
1150         $c .= $req{$t}{'content_size_change'} . $h{'Standard'} . ")";
1151         $content = $c;
1152
1153     } elsif ($c =~ m/^De-chunking successful. Shrunk from (\d+) to (\d+)/) {
1154
1155         $req{$t}{'chunked-size'} = $1;
1156         $req{$t}{'dechunked-size'} = $2;
1157         $req{$t}{'dechunk-change'} = $req{$t}{'dechunked-size'} - $req{$t}{'chunked-size'};
1158
1159         $content .= " (" . h('Number') . $req{$t}{'dechunk-change'} . h('Standard') . ")";
1160
1161         $content =~ s@(?<=from )($req{$t}{'chunked-size'})@$h{'Number'}$1$h{'Standard'}@;
1162         $content =~ s@(?<=to )($req{$t}{'dechunked-size'})@$h{'Number'}$1$h{'Standard'}@;
1163
1164     } elsif ($c =~ m/^Decompression successful. Old size: (\d+), new size: (\d+)./) {
1165
1166         # Decompression successful. Old size: 670, new size: 1166.
1167
1168         $req{$t}{'size-compressed'} = $1;
1169         $req{$t}{'size-decompressed'} = $2;
1170         $req{$t}{'decompression-gain'} = $req{$t}{'size-decompressed'} - $req{$t}{'size-compressed'};
1171
1172         $content =~ s@(?<=Old size: )($req{$t}{'size-compressed'})@$h{'Number'}$1$h{'Standard'}@;
1173         $content =~ s@(?<=new size: )($req{$t}{'size-decompressed'})@$h{'Number'}$1$h{'Standard'}@;
1174
1175         # XXX: Create sub get_percentage()
1176         if ($req{$t}{'size-decompressed'}) {
1177             $req{$t}{'decompression-gain-percent'} =
1178                 $req{$t}{'decompression-gain'} / $req{$t}{'size-decompressed'} * 100;
1179
1180             $content .= " (saved: ";
1181             #$content .= h('Number') . $req{$t}{'decompression-gain'} . h('Standard');
1182             #$content .= "/";
1183             $content .= h('Number') . sprintf("%.2f%%", $req{$t}{'decompression-gain-percent'}) . h('Standard');
1184             $content .= ")";
1185         }
1186
1187     } elsif ($c =~ m/^(Need to de-chunk first)/) {
1188
1189         # Need to de-chunk first
1190         return '' if SUPPRESS_NEED_TO_DE_CHUNK_FIRST;
1191
1192     } elsif ($c =~ m/^(Adding (?:dynamic )?re_filter job)/) {
1193
1194         return ''  if (SUPPRESS_SUCCEEDED_FILTER_ADDITIONS && m/succeeded/);
1195
1196         # Adding re_filter job ...
1197         # Adding dynamic re_filter job s@^(?:\w*)\s+.*\s+HTTP/\d\.\d\s*@IP-ADDRESS: $origin@D\
1198         #  to filter client-ip-address succeeded.
1199
1200     } elsif ($c =~ m/^Reading in filter/) {
1201
1202         return '' unless SHOW_FILTER_READIN_IN;
1203
1204     } else {
1205
1206         found_unknown_content($content);
1207
1208     }
1209
1210     return $content;
1211 }
1212
1213 sub handle_loglevel_redirect ($) {
1214
1215     my $c = shift;
1216     our $t;
1217     our %req;
1218     our %h;
1219
1220     if ($c =~ m/^Decoding "([^""]*)"/) {
1221
1222          $req{$t}{'original-destination'} = $1;
1223          $c = highlight_matched_path($c, '(?<=Decoding ")[^"]*');
1224          $c =~ s@\"@@g;
1225
1226     } elsif ($c =~ m/^Checking/) {
1227
1228          # Checking /_ylt=A0geu.Z76BRGR9k/**http://search.yahoo.com/search?p=view+odb+presentation+on+freebsd\
1229          #  &ei=UTF-8&xargs=0&pstart=1&fr=moz2&b=11 for redirects.
1230
1231          # TODO: Change colour if really url-decoded
1232          $req{$t}{'decoded-original-destination'} = $1;
1233          $c = highlight_matched_path($c, '(?<=Checking ")[^"]*');
1234          $c =~ s@\"@@g;
1235
1236     } elsif ($c =~ m/^pcrs command "([^""]*)" changed /) {
1237
1238         # pcrs command "s@&from=rss@@" changed \
1239         #  "http://it.slashdot.org/article.pl?sid=07/03/02/1657247&from=rss"\
1240         #  to "http://it.slashdot.org/article.pl?sid=07/03/02/1657247" (1 hit).
1241         $c =~ s@(?<=pcrs command )"([^""]*)"@$h{'filter'}$1$h{'Standard'}@;
1242         $c = highlight_matched_url($c, '(?<=changed ")[^""]*');
1243         $c =~ s@(?<=changed )"([^""]*)"@$1@; # Remove quotes
1244         $c = highlight_matched_url($c, '(?<=to ")[^""]*');
1245         $c =~ s@(?<=to )"([^""]*)"@$1@; # Remove quotes
1246         $c =~ s@(\d+)(?= hits?)@$h{'hits'}$1$h{'Standard'}@;
1247
1248     } elsif ($c =~ m/^pcrs command "([^""]*)" didn\'t change/) {
1249
1250         # pcrs command "s@^http://([^.]+?)/?$@http://www.bing.com/search?q=$1@" didn't \
1251         #  change "http://www.example.org/".
1252         $c =~ s@(?<=pcrs command )"([^""]*)"@$h{'filter'}$1$h{'Standard'}@;
1253         $c = highlight_matched_url($c, '(?<=change ")[^""]*');
1254
1255     } elsif ($c =~ m/(^New URL is: )(.*)/) {
1256
1257         # New URL is: http://it.slashdot.org/article.pl?sid=07/03/04/1511210
1258         # XXX: Use URL highlighter
1259         # XXX: Save?
1260         $c = $1 . h('rewritten-URL') . $2 . h('Standard');
1261
1262     } elsif ($c =~ m/No pcrs command recognized, assuming that/) {
1263         # No pcrs command recognized, assuming that "http://config.privoxy.org/user-manual/favicon.png"\
1264         #  is already properly formatted.
1265         # XXX: assume the same?
1266         $c = highlight_matched_url($c, '(?<=assuming that \")[^"]*');
1267
1268     } else {
1269
1270         found_unknown_content($c);
1271
1272     }
1273
1274     return $c;
1275 }
1276
1277 sub handle_loglevel_gif_deanimate ($) {
1278
1279     my $content = shift;
1280     our $t;
1281     our %req;
1282     our %h;
1283
1284     if ($content =~ m/Success! GIF shrunk from (\d+) bytes to (\d+)\./) {
1285
1286         my $bytes_from = $1;
1287         my $bytes_to = $2;
1288         # Gif-Deanimate: Success! GIF shrunk from 205 bytes to 133.
1289         $content =~ s@$bytes_from@$h{'Number'}$bytes_from$h{'Standard'}@;
1290         # XXX: Do we need g in case of ($1 == $2)?
1291         $content =~ s@$bytes_to@$h{'Number'}$bytes_to$h{'Standard'}@;
1292
1293     } elsif ($content =~ m/GIF (not) changed/) {
1294
1295         # Gif-Deanimate: GIF not changed.
1296         return '' if SUPPRESS_GIF_NOT_CHANGED;
1297         $content =~ s@($1)@$h{'not'}$1$h{'Standard'}@;
1298
1299     } elsif ($content =~ m/^failed! \(gif parsing\)/) {
1300
1301         # failed! (gif parsing)
1302         # XXX: Replace this error message with something less stupid 
1303         $content =~ s@(failed!)@$h{'error'}$1$h{'Standard'}@;
1304
1305     } elsif ($content =~ m/^Need to de-chunk first/) {
1306
1307         # Need to de-chunk first
1308         return '' if SUPPRESS_NEED_TO_DE_CHUNK_FIRST;
1309
1310     } elsif ($content =~ m/^(?:No GIF header found|failed while parsing)/) {
1311
1312         # No GIF header found (XXX: Did I ever commit this?)
1313         # failed while parsing 195 134747048 (XXX: never commited)
1314
1315         # Ignore these for now
1316
1317     } else {
1318
1319         found_unknown_content($content);
1320
1321     }
1322
1323     return $content;
1324 }
1325
1326 sub handle_loglevel_request ($) {
1327
1328     my $content = shift;
1329     our $t;
1330     our %req;
1331     our %h;
1332     our %reason_colours;
1333
1334     if ($content =~ m/crunch! /) {
1335
1336         # config.privoxy.org/send-stylesheet crunch! (CGI Call)
1337
1338         # Highlight crunch reasons
1339         foreach my $reason (keys %reason_colours) {
1340             $content =~ s@\(($reason)\)@$reason_colours{$reason}($1)$h{'Standard'}@g;
1341         }
1342         # Highlight request URL domain and ditch 'crunch!'
1343         $content = highlight_matched_pattern($content, 'request_', '[^ ]*(?= crunch!)');
1344         $content =~ s@ crunch!@@;
1345
1346     } elsif ($content =~ m/\[too long, truncated\]$/) {
1347
1348         # config.privoxy.org/edit-actions-submit?f=3&v=1176116716&s=7&Submit=Submit[...]&filter... [too long, truncated]
1349         $content = highlight_matched_pattern($content, 'request_', '^.*(?=\.\.\. \[too long, truncated\]$)');
1350
1351     } elsif ($content =~ m/(.*)/) { # XXX: Pretty stupid
1352
1353         # trac.vidalia-project.net/wiki/Volunteer?format=txt
1354         $content = h('request_') . $content . h('Standard');
1355
1356     } else {  # XXX: Nop
1357
1358         found_unknown_content($content);
1359
1360     }
1361             
1362     return $content;
1363 }
1364
1365 sub handle_loglevel_crunch ($) {
1366
1367     my $content = shift;
1368     our %h;
1369     our %reason_colours;
1370
1371     # Highlight crunch reason
1372     foreach my $reason (keys %reason_colours) {
1373         $content =~ s@($reason)@$reason_colours{$reason}$1$h{'Standard'}@g;
1374     }
1375
1376     if ($content =~ m/\[too long, truncated\]$/) {
1377
1378         # Blocked: config.privoxy.org/edit-actions-submit?f=3&v=1176116716&s=7&Submit=Submit\
1379         #  [...]&filter... [too long, truncated]
1380         $content = highlight_matched_pattern($content, 'request_', '^.*(?=\.\.\. \[too long, truncated\]$)');
1381
1382     } else {
1383
1384         # Blocked: http://ads.example.org/
1385         $content = highlight_matched_pattern($content, 'request_', '(?<=: ).*');
1386     }
1387
1388     return $content;
1389 }
1390
1391 sub handle_loglevel_connect ($) {
1392
1393     my $c = shift;
1394     our $t;
1395     our %req;
1396     our %h;
1397
1398     if ($c =~ m/^via [^\s]+ to: [^\s]+/) {
1399
1400         # Connect: via 10.0.0.1:8123 to: www.example.org.noconnect
1401
1402         $c = highlight_matched_host($c, '(?<=via )[^\s]+');
1403         $c = highlight_matched_host($c, '(?<=to: )[^\s]+');
1404
1405     } elsif ($c =~ m/^connect to: .* failed: .*/) {
1406
1407         # connect to: www.example.org.noconnect failed: Operation not permitted
1408
1409         $c = highlight_matched_host($c, '(?<=connect to: )[^\s]+');
1410
1411         $c =~ s@(?<=failed: )(.*)@$h{'error'}$1$h{'Standard'}@;
1412
1413     } elsif ($c =~ m/^to ([^\s]*)( successful)?$/) {
1414
1415         # Connect: to www.nzherald.co.nz successful
1416         # Connect: to archiv.radiotux.de
1417
1418         return '' if SUPPRESS_SUCCESSFUL_CONNECTIONS;
1419         $c = highlight_matched_host($c, '(?<=to )[^\s]+');
1420
1421     } elsif ($c =~ m/^to ([^\s]*)$/) {
1422
1423         # Connect: to lists.sourceforge.net:443
1424
1425         $c = highlight_matched_host($c, '(?<=to )[^\s]+');
1426
1427     } elsif ($c =~ m/^accepted connection from .*/ or
1428              $c =~ m/^OK/) {
1429
1430         # accepted connection from 10.0.0.1
1431         # Privoxy 3.0.6 and earlier just say:
1432         # OK
1433         return '' if SUPPRESS_ACCEPTED_CONNECTIONS;
1434         $c = highlight_matched_host($c, '(?<=connection from ).*');
1435
1436     } elsif ($c =~ m/^write header to: .* failed:/) {
1437
1438         # write header to: 10.0.0.1 failed: Broken pipe
1439
1440         $c = highlight_matched_host($c, '(?<=write header to: )[^\s]*');
1441         $c =~ s@(?<=failed: )(.*)@$h{'Error'}$1$h{'Standard'}@;
1442
1443     } elsif ($c =~ m/^write header to client failed:/) {
1444
1445         # write header to client failed: Broken pipe
1446         # XXX: Stil in use?
1447         $c =~ s@(?<=failed: )(.*)@$h{'Error'}$1$h{'Standard'}@;
1448
1449     } elsif ($c =~ m/^socks4_connect:/) {
1450
1451         # socks4_connect: SOCKS request rejected or failed.
1452         $c =~ s@(?<=socks4_connect: )(.*)@$h{'Error'}$1$h{'Standard'}@;
1453
1454     } elsif ($c =~ m/^Listening for new connections/ or
1455              $c =~ m/^accept connection/) {
1456         # XXX: Highlight?
1457         # Privoxy versions above 3.0.6 say:
1458         # Listening for new connections ...
1459         # earlier versions say:
1460         # accept connection ...
1461         return '';
1462
1463     } elsif ($c =~ m/^accept failed:/) {
1464
1465         $c =~ s@(?<=accept failed: )(.*)@$h{'Error'}$1$h{'Standard'}@;
1466
1467     } elsif ($c =~ m/^Overriding forwarding settings/) {
1468
1469         # Overriding forwarding settings based on 'forward 10.0.0.1:8123'
1470         $c =~ s@(?<=based on \')(.*)(?=\')@$h{'configuration-line'}$1$h{'Standard'}@;
1471
1472     } elsif ($c =~ m/^Denying suspicious CONNECT request from/) {
1473
1474         # Denying suspicious CONNECT request from 10.0.0.1
1475         $c = highlight_matched_host($c, '(?<=from )[^\s]+'); # XXX: not an URL
1476
1477     } elsif ($c =~ m/^socks5_connect:/) {
1478     
1479         $c =~ s@(?<=socks5_connect: )(.*)@$h{'error'}$1$h{'Standard'}@;
1480
1481     } elsif ($c =~ m/^Created new connection to/) {
1482
1483         # Created new connection to www.privoxy.org:80 on socket 11.
1484         $c = highlight_matched_host($c, '(?<=connection to )[^\s]+');
1485         $c =~ s@(?<=on socket )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1486
1487     } elsif ($c =~ m/^Found reusable socket/) {
1488
1489         # Found reusable socket 9 for www.privoxy.org:80 in slot 0.
1490         # 3.0.15 and later:
1491         # Found reusable socket 8 for www.privoxy.org:80 in slot 2.\
1492         #  Timestamp made 0 seconds ago. Timeout: 1. Latency: 0.
1493         $c =~ s@(?<=Found reusable socket )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1494         $c = highlight_matched_host($c, '(?<=for )[^\s]+');
1495         $c =~ s@(?<=in slot )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1496         $c =~ s@(?<=made )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1497         $c =~ s@(?<=Timeout: )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1498         $c =~ s@(?<=Latency: )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1499
1500     } elsif ($c =~ m/^Marking open socket/) {
1501
1502         # Marking open socket 9 for www.privoxy.org:80 in slot 0 as unused.
1503         $c =~ s@(?<=Marking open socket )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1504         $c = highlight_matched_host($c, '(?<=for )[^\s]+');
1505         $c =~ s@(?<=in slot )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1506
1507     } elsif ($c =~ m/^No reusable/) {
1508
1509         # No reusable socket for addons.mozilla.org:443 found. Opening a new one.
1510         $c = highlight_matched_host($c, '(?<=for )[^\s]+');
1511
1512     } elsif ($c =~ m/^(Remembering|Forgetting) socket/) {
1513
1514         # Remembering socket 13 for www.privoxy.org:80 in slot 0.
1515         # Forgetting socket 38 for www.privoxy.org:80 in slot 5.
1516
1517         $c =~ s@(?<=socket )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1518         $c = highlight_matched_host($c, '(?<=for )[^\s]+');
1519         $c =~ s@(?<=in slot )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1520
1521     } elsif ($c =~ m/^Socket/) {
1522
1523         # Socket 16 already forgotten or never remembered.
1524         $c =~ s@(?<=Socket )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1525
1526     } elsif ($c =~ m/^The connection to/) {
1527
1528         # The connection to www.privoxy.org:80 in slot 6 timed out. Closing socket 19. Timeout is: 61.
1529         # 3.0.15 and later:
1530         # The connection to 1.bp.blogspot.com:80 in slot 0 timed out. Closing socket 5.\
1531         #  Timeout is: 1. Assumed latency: 4.
1532         # The connection to 10.0.0.1:80 in slot 0 is no longer usable. Closing socket 4.
1533         $c = highlight_matched_host($c, '(?<=connection to )[^\s]+');
1534         $c =~ s@(?<=in slot )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1535         $c =~ s@(?<=Closing socket )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1536         $c =~ s@(?<=Timeout is: )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1537         $c =~ s@(?<=Assumed latency: )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1538
1539     } elsif ($c =~ m/^Stopped waiting for the request line./) {
1540
1541         # Stopped waiting for the request line. Timeout: 121.
1542         $c =~ s@(?<=Timeout: )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1543
1544     } elsif ($c =~ m/^Waiting for \d/) {
1545
1546         # Waiting for 1 connections to timeout.
1547         $c =~ s@(?<=^Waiting for )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1548
1549     } elsif ($c =~ m/^Initialized/) {
1550
1551         # Initialized 20 socket slots.
1552         $c =~ s@(?<=Initialized )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1553
1554     } elsif ($c =~ m/^Done reading from server/) {
1555
1556         # Done reading from server. Expected content length: 24892. \
1557         #  Actual content length: 24892. Most recently received: 4412.
1558         # 3.0.15 and later:
1559         # Done reading from server. Expected content length: 24892. \
1560         #  Actual content length: 24892. Bytes most recently read: 4412.
1561         # Done reading from server. Content length: 6018 as expected. \
1562         #  Bytes most recently read: 294.
1563         $c =~ s@(?<=ontent length: )(\d+)@$h{'Number'}$1$h{'Standard'}@g;
1564         $c =~ s@(?<=received: )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1565         $c =~ s@(?<=read: )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1566
1567     } elsif ($c =~ m/^Continuing buffering headers/) {
1568
1569         # Continuing buffering headers. byte_count: 19. header_offset: 517. len: 536.
1570         $c =~ s@(?<=byte_count: )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1571         $c =~ s@(?<=header_offset: )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1572         $c =~ s@(?<=len: )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1573         # 3.0.15 and later:
1574         # Continuing buffering headers. Bytes most recently read: %d.
1575         $c =~ s@(?<=read: )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1576
1577     } elsif ($c =~ m/^Received \d+ bytes while/) {
1578
1579         # Received 206 bytes while expecting 12103.
1580         $c =~ s@(?<=Received )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1581         $c =~ s@(?<=expecting )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1582
1583     } elsif ($c =~ m/^Connection from/) {
1584
1585         # Connection from 81.163.28.218 dropped due to ACL
1586         $c =~ s@(?<=^Connection from )((?:\d+\.?){4})@$h{'Number'}$1$h{'Standard'}@;
1587
1588     } elsif ($c =~ m/^(?:Reusing|Closing) server socket \d./ or
1589              $c =~ m/^No additional client request/) {
1590
1591         # Reusing server socket 4. Opened for 10.0.0.1.
1592         # Closing server socket 2. Opened for 10.0.0.1.
1593         # No additional client request received in time. \
1594         #  Closing server socket 4, initially opened for 10.0.0.1.
1595         # No additional client request received in time on socket 29.
1596
1597         $c =~ s@(?<= socket )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1598         $c = highlight_matched_host($c, '(?<=for )[^\s]+(?=\.$)');
1599
1600     } elsif ($c =~ m/^Connected to /) {
1601
1602         # Connected to tor-jail[10.0.0.2]:9050.
1603
1604         $c = highlight_matched_host($c, '(?<=\[)[^\]]+');
1605         $c = highlight_matched_host($c, '(?<=Connected to )[^\[\s]+');
1606         $c =~ s@(?<=\]:)(\d+)@$h{'Number'}$1$h{'Standard'}@;
1607
1608     } elsif ($c =~ m/^Could not connect to /) {
1609
1610         # Could not connect to [10.0.0.1]:80.
1611
1612         $c = highlight_matched_host($c, '(?<=\[)[^\]]+');
1613         $c =~ s@(?<=\]:)(\d+)@$h{'Number'}$1$h{'Standard'}@;
1614
1615     } elsif ($c =~ m/^Waiting for the next client request/ or
1616              $c =~ m/^The connection on server socket/ or
1617              $c =~ m/^Client request arrived in time or the client closed the connection/) {
1618
1619         # Waiting for the next client request on socket 3. Keeping the server \
1620         #  socket 12 to a.fsdn.com open.
1621         # The connection on server socket 6 to upload.wikimedia.org isn't reusable. Closing.
1622         # Client request arrived in time or the client closed the connection on socket 12.
1623
1624         $c =~ s@(?<=on socket )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1625         $c =~ s@(?<=server socket )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1626         $c = highlight_matched_host($c, '(?<=to )[^\s]+');
1627
1628     } elsif ($c =~ m/^Marking the server socket/) {
1629
1630         # Marking the server socket 7 tainted.
1631
1632         $c =~ s@(?<=server socket )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1633
1634     } elsif ($c =~ m/^Reduced expected bytes to /) {
1635
1636         # Reduced expected bytes to 0 to account for the 1542 ones we already got.
1637         $c =~ s@(?<=bytes to )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1638         $c =~ s@(?<=for the )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1639
1640     } elsif ($c =~ m/^The client closed socket /) {
1641
1642         # The client closed socket 2 while the server socket 4 is still open.
1643         $c =~ s@(?<=closed socket )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1644         $c =~ s@(?<=server socket )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1645
1646     } elsif ($c =~ m/^Expected client content length set /) {
1647
1648         # Expected client content length set to 667325411 after reading 4999 bytes.
1649         $c =~ s@(?<=set to )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1650         $c =~ s@(?<=reading )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1651
1652     } elsif ($c =~ m/^Waiting for up to /) {
1653
1654         # Waiting for up to 4999 bytes from the client.
1655         $c =~ s@(?<=up to )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1656
1657     } elsif ($c =~ m/^Looks like we rea/ or
1658              $c =~ m/^Unsetting keep-alive flag/ or
1659              $c =~ m/^No connections to wait/ or
1660              $c =~ m/^Complete client request received/ or
1661              $c =~ m/^Possible pipeline attempt detected./ or
1662              $c =~ m/^POST request detected. The connection will not be kept alive./ or
1663              $c =~ m/^The server still wants to talk, but the client hung up on us./ or
1664              $c =~ m/^The server didn't specify how long the connection will stay open/ or
1665              $c =~ m/^There might be a request body. The connection will not be kept alive/ or
1666              $c =~ m/^Stopping to watch the client socket. There's already another request waiting./ or
1667              $c =~ m/^Done reading from the client\.$/) {
1668
1669         # Looks like we reached the end of the last chunk. We better stop reading.
1670         # Looks like we read the end of the last chunk together with the server \
1671         #  headers. We better stop reading.
1672         # Unsetting keep-alive flag.
1673         # No connections to wait for left.
1674         # Client request arrived in time or the client closed the connection.
1675         # Complete client request received
1676         # Possible pipeline attempt detected. The connection will not be \
1677         #  kept alive and we will only serve the first request.
1678         # POST request detected. The connection will not be kept alive.
1679         # The server still wants to talk, but the client hung up on us.
1680         # The server didn't specify how long the connection will stay open. Assume it's only a second.
1681         # There might be a request body. The connection will not be kept alive.
1682         # Stopping to watch the client socket. There's already another request waiting.
1683         # Done reading from the client\.
1684
1685     } else {
1686
1687         found_unknown_content($c);
1688
1689     }
1690             
1691     return $c;
1692 }
1693
1694
1695 sub handle_loglevel_info ($) {
1696
1697     my $c = shift;
1698     our $t;
1699     our %req;
1700     our %h;
1701  
1702     if ($c =~ m/^Rewrite detected:/) {
1703
1704         # Rewrite detected: GET http://10.0.0.2:88/blah.txt HTTP/1.1
1705         $c = highlight_matched_request_line($c, '(?<=^Rewrite detected: ).*');
1706
1707     } elsif ($c =~ m/^Decompress(ing deflated|ion didn)/ or
1708              $c =~ m/^Compressed content detected/ or
1709              $c =~ m/^Tagger/
1710             ) {
1711         # Decompressing deflated iob: 117
1712         # Decompression didn't result in any content.
1713         # Compressed content detected, content filtering disabled. Consider recompiling Privoxy\
1714         #  with zlib support or enable the prevent-compression action.
1715         # Tagger 'complete-url' created empty tag. Ignored.
1716
1717         # Ignored for now
1718
1719     } elsif ($c =~ m/^(Re)?loading configuration file /) {
1720
1721         # loading configuration file '/usr/local/etc/privoxy/config':
1722         # Reloading configuration file '/usr/local/etc/privoxy/config'
1723         $c =~ s@(?<=loading configuration file \')([^\']*)@$h{'file'}$1$h{'Standard'}@;
1724
1725     } elsif ($c =~ m/^exiting by signal/) {
1726         
1727         # exiting by signal 15 .. bye
1728         $c =~ s@(?<=exiting by signal )(\d+)@$h{'signal'}$1$h{'Standard'}@;
1729
1730     } elsif ($c =~ m/^Privoxy version/) {
1731         
1732         # Privoxy version 3.0.7
1733         $c =~ s@(?<=^Privoxy version )(\d+\.\d+\.\d+)$@$h{'version'}$1$h{'Standard'}@;
1734
1735     } elsif ($c =~ m/^Program name: /) {
1736
1737         # Program name: /usr/local/sbin/privoxy
1738         $c =~ s@(?<=Program name: )(.*)@$h{'program-name'}$1$h{'Standard'}@;
1739
1740     } elsif ($c =~ m/^Listening on port /) {
1741
1742         # Listening on port 8118 on IP address 10.0.0.1
1743         $c =~ s@(?<=Listening on port )(\d+)@$h{'port'}$1$h{'Standard'}@;
1744         $c =~ s@(?<=on IP address )(.*)@$h{'ip-address'}$1$h{'Standard'}@;
1745
1746     } elsif ($c =~ m/^\(Re-\)Open(?:ing)? logfile/) {
1747
1748         # (Re-)Open logfile /var/log/privoxy/privoxy.log
1749         $c =~ s@(?<=Open logfile )(.*)@$h{'file'}$1$h{'Standard'}@;
1750
1751     } elsif ($c =~ m/^(Request from|Malformed server response detected)/) {
1752
1753         # Request from 10.0.0.1 denied. limit-connect{,} doesn't allow CONNECT requests to port 443.
1754         # Request from 10.0.0.1 marked for blocking. limit-connect{,} doesn't allow CONNECT requests to port 443.
1755         # Malformed server response detected. Downgrading to HTTP/1.0 impossible.
1756
1757         $c =~ s@(?<=Request from )([^\s]*)@$h{'ip-address'}$1$h{'Standard'}@;
1758         $c =~ s@(denied|blocking)@$h{'warning'}$1$h{'Standard'}@;
1759         $c =~ s@(CONNECT)@$h{'method'}$1$h{'Standard'}@;
1760         $c =~ s@(?<=to port )(\d+)@$h{'port'}$1$h{'Standard'}@;
1761
1762     } elsif ($c =~ m/^Status code/) {
1763
1764         # Status code 304 implies no body.
1765         $c =~ s@(?<=Status code )(\d+)@$h{'status-code'}$1$h{'Standard'}@;
1766
1767     } elsif ($c =~ m/^Method/) {
1768
1769         # Method HEAD implies no body.
1770         $c =~ s@(?<=Method )([^\s]+)@$h{'method'}$1$h{'Standard'}@;
1771
1772     } elsif ($c =~ m/^Buffer limit reached while extending /) {
1773
1774         # Buffer limit reached while extending the buffer (iob). Needed: 4197470. Limit: 4194304
1775         $c =~ s@(?<=Needed: )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1776         $c =~ s@(?<=Limit: )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1777
1778     } elsif ($c =~ m/^No logfile configured/ or
1779              $c =~ m/^Malformerd HTTP headers detected and MS IIS5 hack enabled/ or
1780              $c =~ m/^Invalid \"chunked\" transfer/ or
1781              $c =~ m/^Support for/ or
1782              $c =~ m/^Flushing header and buffers/
1783              ) {
1784
1785         # No logfile configured. Please enable it before reporting any problems.
1786         # Malformerd HTTP headers detected and MS IIS5 hack enabled. Expect an invalid \
1787         #  response or even no response at all.
1788         # No logfile configured. Logging disabled.
1789         # Invalid "chunked" transfer encoding detected and ignored.
1790         # Support for 'Connection: keep-alive' is experimental, incomplete and\
1791         #  known not to work properly in some situations.
1792         # Flushing header and buffers. Stepping back from filtering.
1793
1794     } else {
1795
1796         found_unknown_content($c);
1797
1798     }
1799
1800     return $c;
1801 }
1802
1803 sub handle_loglevel_cgi ($) {
1804
1805     my $c = shift;
1806     our $t;
1807     our %req;
1808     our %h;
1809
1810     if ($c =~ m/^Granting access to/) {
1811       
1812         #Granting access to http://config.privoxy.org/send-stylesheet, referrer http://p.p/ is trustworthy.
1813
1814     } elsif ($c =~ m/^Substituting: s(.)/) {
1815       
1816         # Substituting: s/@else-not-FEATURE_ZLIB@.*@endif-FEATURE_ZLIB@//sigTU
1817         # XXX: prone to span several lines
1818
1819         my $delimiter = $1;
1820         #$c =~ s@(?<=failed: )(.*)@$h{'error'}$1$h{'Standard'}@;
1821         $c =~ s@(?!<=\\)($delimiter)@$h{'pcrs-delimiter'}$1$h{'Standard'}@g; # XXX: Too aggressive
1822         #$c =~ s@(?!<=\\)($1)@$h{'pcrs-delimiter'}$1$h{'Standard'}@g;
1823     }
1824
1825     return $c;
1826 }
1827
1828 sub handle_loglevel_force ($) {
1829
1830     my $c = shift;
1831     our $t;
1832     our %req;
1833     our %h;
1834
1835     if ($c =~ m/^Ignored force prefix in request:/) {
1836       
1837         # Ignored force prefix in request: "GET http://10.0.0.1/PRIVOXY-FORCE/block HTTP/1.1"
1838         $c =~ s@^(Ignored)@$h{'ignored'}$1$h{'Standard'}@;
1839         $c = highlight_matched_request_line($c, '(?<=request: ")[^"]*');
1840
1841     } elsif ($c =~ m/^Enforcing request:/) {
1842       
1843         # Enforcing request: "GET http://10.0.0.1/block HTTP/1.1".
1844         $c = highlight_matched_request_line($c, '(?<=request: ")[^"]*');
1845
1846     } else {
1847
1848         found_unknown_content($c);
1849
1850     }
1851
1852     return $c;
1853 }
1854
1855 sub handle_loglevel_error ($) {
1856
1857     my $c = shift;
1858     our %h;
1859
1860     if ($c =~ m/^Empty server or forwarder response received on socket \d+./) {
1861
1862         # Empty server or forwarder response received on socket 4.
1863         # Empty server or forwarder response received on socket 3. \
1864         #  Closing client socket 15 without sending data.
1865         $c =~ s@(?<=on socket )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1866         $c =~ s@(?<=client socket )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1867     }
1868     # XXX: There are probably more messages that deserve highlighting.
1869
1870     return $c;
1871 }
1872
1873
1874 sub handle_loglevel_ignore ($) {
1875     return shift;
1876 }
1877
1878 sub gather_loglevel_request_stats ($$) {
1879     my $c = shift;
1880     my $thread = shift;
1881     our %stats;
1882
1883     $stats{requests}++;
1884 }
1885
1886 sub gather_loglevel_crunch_stats ($$) {
1887     my $c = shift;
1888     my $thread = shift;
1889     our %stats;
1890
1891     $stats{requests}++;
1892     $stats{crunches}++;
1893 }
1894
1895
1896 sub gather_loglevel_error_stats ($$) {
1897
1898     my $c = shift;
1899     my $thread = shift;
1900     our %stats;
1901     our %thread_data;
1902
1903     if ($c =~ m/^Empty server or forwarder response received on socket \d+./) {
1904
1905         # Empty server or forwarder response received on socket 4.
1906         $stats{'empty-responses'}++;
1907         if ($thread_data{$thread}{'new_connection'}) {
1908             $stats{'empty-responses-on-new-connections'}++;
1909         } else {
1910             $stats{'empty-responses-on-reused-connections'}++;
1911         }
1912     }
1913 }
1914
1915 sub gather_loglevel_connect_stats ($$) {
1916
1917     my $c = shift;
1918     my $thread = shift;
1919     our %thread_data;
1920     our %stats;
1921
1922     if ($c =~ m/^via ([^\s]+) to: [^\s]+/) {
1923
1924         # Connect: via 10.0.0.1:8123 to: www.example.org.noconnect
1925         $thread_data{$thread}{'forwarder'} = $1; # XXX: is this missue?
1926
1927     } elsif ($c =~ m/^to ([^\s]*)$/) {
1928
1929         # Connect: to lists.sourceforge.net:443
1930
1931         $thread_data{$thread}{'forwarder'} = 'direct connection';
1932
1933     } elsif ($c =~ m/^Created new connection to/) {
1934
1935         # Created new connection to www.privoxy.org:80 on socket 11.
1936
1937         $thread_data{$thread}{'new_connection'} = 1;
1938
1939     } elsif ($c =~ m/^Reusing server socket \d./ or
1940              $c =~ m/^Found reusable socket/) {
1941
1942         # Reusing server socket 4. Opened for 10.0.0.1.
1943         # Found reusable socket 9 for www.privoxy.org:80 in slot 0.
1944
1945         $thread_data{$thread}{'new_connection'} = 0;
1946         $stats{'reused-connections'}++;
1947     }
1948 }
1949
1950 sub gather_loglevel_header_stats ($) {
1951
1952     my $c = shift;
1953     my $thread = shift;
1954     our %stats;
1955
1956     if ($c =~ m/^A HTTP\/1\.1 response without/ or
1957         $c =~ m/^Keeping the server header 'Connection: keep-alive' around./)
1958     {
1959         # A HTTP/1.1 response without Connection header implies keep-alive.
1960         # Keeping the server header 'Connection: keep-alive' around.
1961         $stats{'server-keep-alive'}++;
1962     }
1963 }
1964
1965 sub init_stats () {
1966     our %stats = (
1967         requests => 0,
1968         crunches => 0,
1969         'server-keep-alive' => 0,
1970         'reused-connections' => 0,
1971         'empty-responses' => 0,
1972         'empty-responses-on-new-connections' => 0,
1973         'empty-responses-on-reused-connections' => 0,
1974         );
1975 }
1976
1977 sub get_percentage ($$) {
1978     my $big = shift;
1979     my $small = shift;
1980     return "NaN" if ($big eq 0);
1981     return sprintf("%.2f%%", $small / $big * 100);
1982 }
1983
1984 sub print_stats () {
1985
1986     our %stats;
1987     my $new_connections = $stats{requests} - $stats{crunches} - $stats{'reused-connections'};
1988     my $outgoing_requests = $stats{requests} - $stats{crunches};
1989
1990     if ($stats{requests} eq 0) {
1991         print "No requests yet.\n";
1992         return;
1993     }
1994
1995     print "Client requests total: " . $stats{requests} . "\n";
1996     print "Crunches: " . $stats{crunches} . " (" .
1997         get_percentage($stats{requests}, $stats{crunches}) . ")\n";
1998     print "Outgoing requests: " . $outgoing_requests . " (" .
1999         get_percentage($stats{requests}, $outgoing_requests) . ")\n";
2000     print "Server keep-alive offers: " . $stats{'server-keep-alive'} . " (" .
2001         get_percentage($stats{requests}, $stats{'server-keep-alive'}) . ")\n";
2002     print "New outgoing connections: " . $new_connections . " (" .
2003         get_percentage($stats{requests}, $new_connections) . ")\n";
2004     print "Reused connections: " . $stats{'reused-connections'} . " (" .
2005         get_percentage($stats{requests}, $stats{'reused-connections'}) . ")\n";
2006     print "Empty responses: " . $stats{'empty-responses'} . " (" .
2007         get_percentage($stats{requests}, $stats{'empty-responses'}) . ")\n";
2008     print "Empty responses on new connections: "
2009          . $stats{'empty-responses-on-new-connections'} . " (" .
2010         get_percentage($stats{requests}, $stats{'empty-responses-on-new-connections'})
2011         . ")\n";
2012     print "Empty responses on reused connections: " .
2013         $stats{'empty-responses-on-reused-connections'} . " (" .
2014         get_percentage($stats{requests}, $stats{'empty-responses-on-reused-connections'}) .
2015         ")\n";
2016 }
2017
2018
2019 ################################################################################
2020 # Functions that actually print stuff
2021 ################################################################################
2022
2023 sub print_clf_message () {
2024
2025     our ($ip, $timestamp, $request_line, $status_code, $size);
2026     our %h;
2027     my $output = '';
2028
2029     return if DEBUG_SUPPRESS_LOG_MESSAGES;
2030
2031     # Rebuild highlighted
2032     $output .= $h{'Number'} . $ip . $h{'Standard'};
2033     $output .= " - - ";
2034     $output .= "[" . $h{'Timestamp'} . $timestamp . $h{'Standard'} . "]";
2035     $output .= " ";
2036     $output .= "\"" . highlight_request_line("$request_line") . "\"";
2037     $output .= " ";
2038     $output .= $h{'Status'} . $status_code . $h{'Standard'};
2039     $output .= " ";
2040     $output .= $h{'Number'} . $size . $h{'Standard'};
2041     $output .= get_line_end();
2042
2043     print $output;
2044 }
2045
2046 sub print_non_clf_message ($) {
2047
2048     our %req;
2049     our %thread_colours;
2050     our %h;
2051     our $t;
2052     our $time_colour_index;
2053     our @time_colours;
2054     my $output;
2055     my $content = shift;
2056     my ($day, $time_stamp, $msecs, $thread, $log_level)
2057      = ($req{$t}{'day'}, $req{$t}{'time-stamp'}, $req{$t}{'msecs'}, $t, $req{$t}{'log-level'} );
2058
2059     return if DEBUG_SUPPRESS_LOG_MESSAGES;
2060
2061     $output .= $h{"Standard"} unless cli_option_is_set('html-output');
2062     #    $output .= "$day ";
2063     $output .= $time_colours[$time_colour_index % 2]; 
2064
2065     $output .= $time_stamp;
2066     $output .= ".$msecs" unless cli_option_is_set('no-msecs');
2067     $output .= $h{"Standard"};
2068     $output .= " ";
2069     $output .= $thread_colours{$thread} if (defined($thread_colours{$thread}));
2070     $output .= $thread;
2071     $output .= $h{"Standard"} . " ";
2072     $output .= $h{$log_level} if (defined($h{$log_level}));
2073     $output .= $log_level;
2074     $output .= $h{"Standard"} . ": ";
2075     $output .= "$content";
2076     $output .= get_line_end();
2077
2078     print $output;
2079 }
2080
2081 sub parse_loop () {
2082
2083     our $t;
2084     our %req; # request data from previous lines
2085     our %h;
2086     our %thread_colours;
2087     our @all_colours;
2088     our @time_colours;
2089     our $thread_colour_index = 0;
2090     our $header_colour_index = 0;
2091     our $time_colour_index = 0;
2092
2093     my ($day, $time_stamp, $thread, $log_level, $content, $c, $msecs);
2094     my $last_msecs  = 0;
2095     my $last_thread = 0;
2096     my $last_timestamp = 0;
2097     my $output;
2098     my $filters_that_did_nothing;
2099     my $key;
2100     my $time_colour;
2101     our $no_special_header_highlighting;
2102     $time_colour = paint_it('white');
2103
2104     my %log_level_handlers = (
2105         'Re-Filter'         => \&handle_loglevel_re_filter,
2106         'Header'            => \&handle_loglevel_header,
2107         'Connect'           => \&handle_loglevel_connect,
2108         'Redirect'          => \&handle_loglevel_redirect,
2109         'Request'           => \&handle_loglevel_request,
2110         'Crunch'            => \&handle_loglevel_crunch,
2111         'Gif-Deanimate'     => \&handle_loglevel_gif_deanimate,
2112         'Info'              => \&handle_loglevel_info,
2113         'CGI'               => \&handle_loglevel_cgi,
2114         'Force'             => \&handle_loglevel_force,
2115         'Error'             => \&handle_loglevel_error,
2116         'Fatal error'       => \&handle_loglevel_ignore,
2117         'Writing'           => \&handle_loglevel_ignore,
2118         'Unknown log level' => \&handle_loglevel_ignore,
2119     );
2120
2121     while (<>) {
2122  
2123         $output = '';
2124
2125         if (m/^(\w{3} \d{2}) (\d\d:\d\d:\d\d)\.?(\d+)? (?:Privoxy\()?([^\)\s]*)[\)]? ([\w -]*): (.*?)\r?$/) {
2126             # XXX: Put in req hash?
2127             $day = $1;
2128             $time_stamp = $2;
2129             $msecs = $3 ? $3 : 0; # Only the cool kids have micro second resolution
2130             $log_level = $5;
2131             $content = $c = $6;
2132             $thread = $t = $4;
2133
2134             $req{$t}{'day'} = $day;
2135             $req{$t}{'time-stamp'} = $time_stamp;
2136             $req{$t}{'msecs'} = $msecs; # Only the cool kids have micro second resolution;
2137             $req{$t}{'log-level'} = $log_level;
2138             $req{$t}{'content'} = $content;
2139             $req{$t}{'log-message'} = $_;
2140             $no_special_header_highlighting = 0;
2141
2142             if (defined($log_level_handlers{$log_level})) {
2143
2144                 $content = $log_level_handlers{$log_level}($content);
2145
2146             } else {
2147
2148                 die "No handler found for log level \"$log_level\"\n";
2149
2150             }
2151
2152             # Highlight Truncations    
2153             if (m/\.\.\. \[(too long, truncated)/) {
2154                 $content =~ s@($1)@$h{'Truncation'}$1$h{'Standard'}@g;
2155             }
2156
2157             next unless $content;
2158
2159             # Register threads to keep the colour constant
2160             if (!defined($thread_colours{$thread})) {
2161                 $thread_colours{$thread} = $all_colours[$thread_colour_index % @all_colours];
2162                 $thread_colour_index++;
2163             }
2164
2165             # Switch timestamp colour if timestamps differ
2166             if ($msecs != $last_msecs || !($time_stamp =~ m/$last_timestamp/)) {
2167                debug_message("Tick tack!") if DEBUG_TICKS;
2168                $time_colour = $time_colours[$time_colour_index % 2]; 
2169                $time_colour_index++
2170             }
2171
2172             $last_msecs = $msecs;
2173             $last_thread = $thread;
2174             $last_timestamp = $time_stamp;
2175
2176             print_non_clf_message($content);
2177
2178         } elsif (m/^((?:\d+\.\d+\.\d+\.\d+|[:\d]+)) - - \[(.*)\] "(.*)" (\d+) (\d+)/) {
2179
2180             # LOG_LEVEL_CLF lines look like this
2181             # 61.152.239.32 - - [04/Mar/2007:18:28:23 +0100] "GET \
2182             #  http://ad.yieldmanager.com/imp?z=1&Z=120x600&s=109339&u=http%3A%2F%2Fwww.365loan.co.uk%2F&r=1\
2183             #  HTTP/1.1" 403 1730
2184             our ($ip, $timestamp, $request_line, $status_code, $size) = ($1, $2, $3, $4, $5);
2185
2186             print_clf_message();
2187     
2188         } else {
2189
2190             # Some Privoxy log messages span more than one line,
2191             # usually to dump lots of content that doesn't need any syntax highlighting.
2192             # XXX: add mechanism to forward these lines to the right handler anyway.
2193             chomp();
2194             unless (DEBUG_SUPPRESS_LOG_MESSAGES or (SUPPRESS_EMPTY_LINES and m/^\s+$/)) {
2195                 print and print get_line_end(); # unless (SUPPRESS_EMPTY_LINES and m/^\s+$/);
2196             }
2197         }
2198     }
2199 }
2200
2201 sub stats_loop () {
2202
2203     my ($day, $time_stamp, $thread, $log_level, $content, $c, $msecs);
2204     my %log_level_handlers = (
2205          'Re-Filter'         => \&handle_loglevel_ignore,
2206          'Header'            => \&gather_loglevel_header_stats,
2207          'Connect'           => \&gather_loglevel_connect_stats,
2208          'Redirect'          => \&handle_loglevel_ignore,
2209          'Request'           => \&gather_loglevel_request_stats,
2210          'Crunch'            => \&gather_loglevel_crunch_stats,
2211          'Gif-Deanimate'     => \&handle_loglevel_ignore,
2212          'Info'              => \&handle_loglevel_ignore,
2213          'CGI'               => \&handle_loglevel_ignore,
2214          'Force'             => \&handle_loglevel_ignore,
2215          'Error'             => \&gather_loglevel_error_stats,
2216          'Fatal error'       => \&handle_loglevel_ignore,
2217          'Writing'           => \&handle_loglevel_ignore,
2218          'Unknown log level' => \&handle_loglevel_ignore
2219     );
2220
2221     while (<>) {
2222         if (m/^(\w{3} \d{2}) (\d\d:\d\d:\d\d)\.?(\d+)? (?:Privoxy\()?([^\)\s]*)[\)]? ([\w -]*): (.*?)\r?$/) {
2223             $day = $1;
2224             $time_stamp = $2;
2225             $msecs = $3 ? $3 : 0;
2226             $log_level = $5;
2227             $content = $c = $6;
2228             $thread = $4;
2229
2230             if (defined($log_level_handlers{$log_level})) {
2231
2232                 $content = $log_level_handlers{$log_level}($content, $thread);
2233
2234             } else {
2235
2236                 die "No handler found for log level \"$log_level\"\n";
2237
2238             }
2239         }
2240     }
2241
2242     print_stats();
2243
2244 }
2245
2246 sub VersionMessage {
2247     my $version_message;
2248
2249     $version_message .= 'Privoxy-Log-Parser ' . PRIVOXY_LOG_PARSER_VERSION  . "\n";
2250     $version_message .= 'Copyright (C) 2007-2009 Fabian Keil <fk@fabiankeil.de>' . "\n";
2251     $version_message .= 'http://www.fabiankeil.de/sourcecode/privoxy-log-parser/' . "\n";
2252
2253     print $version_message;
2254 }
2255
2256 sub get_cli_options () {
2257
2258     our %cli_options = (
2259         'html-output'              => CLI_OPTION_DEFAULT_TO_HTML_OUTPUT,
2260         'title'                    => CLI_OPTION_TITLE,
2261         'no-syntax-highlighting'   => CLI_OPTION_NO_SYNTAX_HIGHLIGHTING,
2262         'no-embedded-css'          => CLI_OPTION_NO_EMBEDDED_CSS,
2263         'no-msecs'                 => CLI_OPTION_NO_MSECS,
2264         'show-ineffective-filters' => CLI_OPTION_SHOW_INEFFECTIVE_FILTERS,
2265         'accept-unknown-messages'  => CLI_OPTION_ACCEPT_UNKNOWN_MESSAGES,
2266         'statistics'               => CLI_OPTION_STATISTICS,
2267     ); 
2268
2269     GetOptions (
2270         'html-output'              => \$cli_options{'html-output'},
2271         'title'                    => \$cli_options{'title'},
2272         'no-syntax-highlighting'   => \$cli_options{'no-syntax-highlighting'},
2273         'no-embedded-css'          => \$cli_options{'no-embedded-css'},
2274         'no-msecs'                 => \$cli_options{'no-msecs'},
2275         'show-ineffective-filters' => \$cli_options{'show-ineffective-filters'},
2276         'accept-unknown-messages'  => \$cli_options{'accept-unknown-messages'},
2277         'statistics'               => \$cli_options{'statistics'},
2278         'version'                  => sub { VersionMessage && exit(0) },
2279         'help'                     => \&help,
2280    ) or exit(1);
2281 }
2282
2283 sub help () {
2284
2285     our %cli_options;
2286
2287     VersionMessage();
2288
2289     print << "    EOF"
2290
2291 Options and their default values if they have any:
2292     [--accept-unknown-messages]
2293     [--html-output]
2294     [--no-embedded-css]
2295     [--no-msecs]
2296     [--no-syntax-highlighting]
2297     [--show-ineffective-filters]
2298     [--statistics]
2299     [--title $cli_options{'title'}]
2300     [--version]
2301 see "perldoc $0" for more information
2302     EOF
2303     ;
2304     exit(0);
2305 }
2306
2307 ################################################################################
2308 # main
2309 ################################################################################
2310 sub main () {
2311
2312     get_cli_options();
2313     set_background(DEFAULT_BACKGROUND);
2314     prepare_our_stuff();
2315
2316     print_intro();
2317
2318     if (cli_option_is_set('statistics')) {
2319         stats_loop();
2320     } else {
2321         parse_loop();
2322     }
2323
2324     print_outro();
2325 }
2326
2327 main();
2328
2329 =head1 NAME
2330
2331 B<privoxy-log-parser> - A parser and syntax-highlighter for Privoxy log messages
2332
2333 =head1 SYNOPSIS
2334
2335 B<privoxy-log-parser> [B<--accept-unknown-messages>] [B<--html-output>]
2336 [B<--no-msecs>] [B<--no-syntax-higlighting>] [B<--show-ineffective-filters>]
2337 [B<--version>]
2338
2339 =head1 DESCRIPTION
2340
2341 B<privoxy-log-parser> reads Privoxy log messages and
2342
2343 - syntax-highlights recognized lines,
2344
2345 - reformats some of them for easier comprehension,
2346
2347 - filters out less useful messages, and
2348
2349 - (in some cases) calculates additional information,
2350   like the compression ratio or how a filter affected
2351   the content size.
2352  
2353 With B<privoxy-log-parser> you should be able to increase Privoxy's log level
2354 without getting confused by the resulting amount of output. For example for
2355 "debug 64" B<privoxy-log-parser> will (by default) only show messages that
2356 affect the content. If a filter doesn't cause any hits, B<privoxy-log-parser>
2357 will hide the "filter foo caused 0 hits" message.
2358
2359 =head1 OPTIONS
2360
2361 [B<--accept-unknown-messages>] Don't print warnings in case of unknown messages,
2362 just don't highlight them.
2363
2364 [B<--html-output>] Use HTML and CSS for the syntax highlighting. If this option is
2365 omitted, ANSI escape sequences are used unless B<--no-syntax-highlighting> is active.
2366 This option is only intended to make embedding log excerpts in web pages easier.
2367 It does not escape any input!
2368
2369 [B<--no-msecs>] Don't expect milisecond resolution
2370
2371 [B<--no-syntax-highlighting>] Disable syntax-highlighting. Useful when
2372 the filtered output is piped into less in which case the ANSI control
2373 codes don't work, or if the terminal itself doesn't support the control
2374 codes.
2375
2376 [B<--show-ineffective-filters>] Don't suppress log lines for filters
2377 that didn't modify the content.
2378
2379 [B<--statistics>] Gather various statistics instead of syntax highlighting
2380 log messages. This is an experimental feature, if the results look wrong
2381 they very well might be. Also note that the results a pretty much guaranteed
2382 to be incorrect if Privoxy and Privoxy-Log-Parser aren't in sync.
2383
2384 [B<--version>] Print version and exit.
2385
2386 =head1 EXAMPLES
2387
2388 To monitor a log file:
2389
2390 tail -F /usr/jails/privoxy-jail/var/log/privoxy/privoxy.log | B<privoxy-log-parser>
2391
2392 Replace '-F' with '-f' if your tail implementation lacks '-F' support
2393 or if the log won't get rotated anyway. The log file location depends
2394 on your system (Doh!).
2395
2396 To monitor Privoxy without having it write to a log file:
2397
2398 privoxy --no-daemon /usr/jails/privoxy-jail/usr/local/etc/privoxy/config 2>&1 | B<privoxy-log-parser>
2399
2400 Again, the config file location depends on your system. Output redirection
2401 depends on your shell, the above works with bourne shells.
2402
2403 To read a processed Privoxy log file from top to bottom, letting the content
2404 scroll by slightly faster than you can read:
2405
2406 B<privoxy-log-parser> < /usr/jails/privoxy-jail/var/log/privoxy/privoxy.log
2407
2408 This is probably only useful to fill screens in the background of haxor movies.
2409
2410 =head1 CAVEATS
2411
2412 Syntax highlighting with ANSI escape sequences will look strange
2413 if your background color isn't black.
2414
2415 Some messages aren't recognized yet and will not be fully highlighted.
2416
2417 B<privoxy-log-parser> is developed with Privoxy 3.0.7 or later in mind,
2418 using earlier Privoxy versions will probably result in an increased amount
2419 of unrecognized log lines.
2420
2421 Privoxy's log files tend to be rather large. If you use HTML
2422 highlighting some browsers can't handle them, get confused and
2423 will eventually crash because of segmentation faults or unexpected
2424 exceptions. This is a problem in the browser and not B<privoxy-log-parser>'s
2425 fault.
2426
2427 =head1 BUGS
2428
2429 Many settings can't be controlled through command line options yet.
2430
2431 =head1 SEE ALSO
2432
2433 privoxy(1)
2434
2435 =head1 AUTHOR
2436
2437 Fabian Keil <fk@fabiankeil.de>
2438
2439 =cut