/[mws]/trunk/httpd.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/httpd.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 6 by dpavlin, Wed May 5 13:42:27 2004 UTC revision 17 by dpavlin, Fri May 7 11:25:01 2004 UTC
# Line 14  use MWS; Line 14  use MWS;
14    
15  use Data::Dumper;  use Data::Dumper;
16    
17  my $d = HTTP::Daemon->new( Reuse => 1, LocalPort => 6969 ) || die;  my $debug = 1;
 print "Please contact me at: <URL:", $d->url, ">\n";  
18    
19    my $d = HTTP::Daemon->new( Reuse => 1, LocalPort => 6969 ) || die;
20  my $cgi = new CGI::Lite;  my $cgi = new CGI::Lite;
21  my $mws = MWS->new('global.conf');  my $mws = MWS->new('global.conf');
22  my $tt = Template->new({  my $tt = Template->new({
23          INCLUDE_PATH => $mws->{config}->val('global', 'templates'),          INCLUDE_PATH => $mws->{config}->val('global', 'templates'),
24          FILTERS => {          FILTERS => {
25                  'body5' => \&body5_filter,                  'body5' => \&body5_filter,
26                    'subject_search' => \&subject_search_filter,
27          },          },
28  });  });
29    
30    print "Web server ready at: ", $d->url, "\n";
31    
32    
33  while ( my $c = $d->accept ) {  while ( my $c = $d->accept ) {
34          while ( my $r = $c->get_request ) {          while ( my $r = $c->get_request ) {
# Line 67  while ( my $c = $d->accept ) { Line 70  while ( my $c = $d->accept ) {
70                  my $url = $r->url->path;                  my $url = $r->url->path;
71    
72                  # XXX LOG                  # XXX LOG
73                  print $r->method," ",$url,Dumper($param);                  print $r->method," ",$url,"\n",Dumper($param),"\n" if ($debug);
74    
75                  # generate HTML                  # template file name (use ?format=html as default)
76                    my $tpl_file = 'master.';
77                    $tpl_file .= $param->{'format'} || 'html';
78    
79                    #
80                    # implement functionality and generate HTML
81                    #
82                  my $html;                  my $html;
83    
84                  my $s=$param->{'search'};                  if ($param->{'search_val'} && $param->{'search_fld'} && !$param->{'search'}) {
85                            $param->{'search'} = $param->{'search_fld'}.":".$param->{'search_val'};
86                    } elsif ($param->{'search'}) {
87                            ($param->{'search_fld'}, $param->{'search_val'}) = split(/:/,$param->{'search'},2);
88                    }
89    
90                  if ($s) {                  my $tpl_var = {
91                            param   => $param
92                    };
93    
94                          print STDERR "search: $s\n";                  # show search results
95                    # ?search=foo:bar
96                    if ($param->{'search'}) {
97    
98                          my $results = $mws->search($s);                          print STDERR "search: ",$param->{'search'},"\n";
99    
100                            my $results = $mws->search($param->{'search'});
101                          my @res = $mws->fetch_all_results();                          my @res = $mws->fetch_all_results();
102    
103                          my $tpl_file = 'master.';                          $tpl_var->{results} = \@res;
104                          $tpl_file .= $param->{'format'} || 'html';                          $tpl_var->{total_hits} = $mws->{total_hits};
105    
106                          $tt->process($tpl_file, {  
107                                  query   => $s,                  #
108                                  results => \@res,                  # ?show_id=XXXXxxxx___message_id___xxxxXXXX
109                                  param   => $param,                  } elsif ($param->{'show_id'}) {
110                          }, \$html) || die $tt->error();                          
111                            my $row = $mws->fetch_result_by_id($param->{'show_id'});
112                            $tpl_var->{message} = $row;
113                  }                  }
114    
115                    $tt->process($tpl_file, $tpl_var, \$html) || die $tt->error();
116    
117                    #
118                    # send HTMLto client
119                    #
120    
121                  my $res = HTTP::Response->new(RC_OK);                  my $res = HTTP::Response->new(RC_OK);
122                  $res->header( 'Content-type' => 'text/html; charset=iso-8859-2' );                  $res->header( 'Content-type' => 'text/html; charset=ISO-8859-2' );
123                  $res->content($html);                  $res->content($html);
124                  $c->send_response($res);                  $c->send_response($res);
125    
# Line 104  while ( my $c = $d->accept ) { Line 130  while ( my $c = $d->accept ) {
130    
131  # template toolkit filter  # template toolkit filter
132    
133    #use Text::Context::EitherSide;
134    
135  sub body5_filter {  sub body5_filter {
136          my $text = shift;          my $text = shift;
137          $text =~ s/^\s+//gs;          $text =~ s/^\s+//gs;
138          $text =~ s/^(.*?[\n\r]+){5}.*$/$1/s;          $text =~ s/^[\>:\|=]+\s*.*?$//msg;      # remove quoted text
139            $text =~ s/[\n\r]+/\n/gs;               # compress cr/lf
140            if ($text =~ s,^((?:.*?[\n\r]){5}).*$,$1,s) {
141                    $text =~ s/[\n\r]*$/ .../;
142            }
143            $text =~ s/[\n\r]+--\s*[\n\r]+.*$//s;
144    
145    #       my $context = Text::Context::EitherSide->new($text, context => 5);
146    #       return $context->as_string("perl");
147    
148          return $text;          return $text;
149  }  }
150    
151    sub subject_search_filter {
152            my $s = shift;
153            # remove re: fdw: [list] preffixes from e-mail
154            while ( $s =~ s/^\s*\[(?:re|fwd|fw):\s+(.+)\]\s*$/$1/ig ||
155                    $s =~ s/^\s*(?:re|fwd|fw):\s+(.+?)\s*$/$1/ig ||
156                    $s =~ s/^\[\S+\]\s*//ig ||
157                    $s =~ s/^\[[^@]+@\w+\.\w+\s*:\s+(.+)\s*\]\s*$/$1/g
158            ) { };
159            return $s;
160    }

Legend:
Removed from v.6  
changed lines
  Added in v.17

  ViewVC Help
Powered by ViewVC 1.1.26