chiark / gitweb /
Rerun autoconf2.13 on etch and consequently refresh configure-hostname patch
[inn-innduct.git] / innfeed / testListener.pl
1 #!/usr/bin/perl
2
3 # Author:       James Brister <brister@vix.com> -- berkeley-unix --
4 # Start Date:   Wed Jan  3 00:09:01 1996
5 # Project:      INN -- innfeed
6 # File:         testListener.pl
7 # RCSId:        $Id: testListener.pl 6312 2003-05-04 21:40:11Z rra $
8 # Description:  Generate news files for testing the innfeed feeder.
9 #
10 #               Run like this:
11 #
12 #                       testListener.pl -t 30 -d tmp | innfeed
13 #
14 #               or like this:
15 #
16 #                       innfeed -s 'perl testListener.pl -t 30 -d tmp'
17
18
19 $0 =~ s!.*/!! ;
20
21 require 'getopts.pl' ;
22
23 $usage = "$0 [ -a -b name -d directory -c count -t sleep-amt -r -u ] peers\n" .
24     "  -a is for duplicate article id's periodically\n" .
25     "  -u is for random unlinking of article\n" .
26     "  -b add bogus peername periodically\n" .
27     "  -d is the directory where articles show be written.\n" .
28     "  -c is how many articles to create (0 the default meamns no limit)\n" .
29     "  -t is the number of seconds to sleep between each article.\n" .
30     "  -r is to have articles be created in NNTP ready format\n" ;
31
32 &Getopts ("a:b:c:d:t:rl:h:") || die $usage ;
33
34 die $usage if $opt_h ;
35 $total = $opt_c ;
36
37 $sleepAmt = 1 ;
38 $sleepAmt = $opt_t if ($opt_t =~ /^[\d\.]+/) ;
39
40 $lineCount = 50 ;
41 $lineCount = $opt_l if ($opt_l =~ /^\d+$/) ;
42
43 $directory = "." ;
44 $directory = $opt_d if $opt_d ;
45
46 $bogus = $opt_b ;
47 if ( $bogus && $bogus !~ /^[a-zA-Z]+$/ ) {
48     print "The bogus peername must contain only letters\n" ;
49 }
50     
51 $cr = ($opt_r ? "\r" : "") ;
52
53 $SIG{'INT'} = 'IGNORE' ;
54 $SIG{'TERM'} = 'sigHup' ;
55 $SIG{'QUIT'} = 'sigHup' ;
56 $SIG{'HUP'} = 'sigHup' ;
57
58 sub sigHup {
59         exit (1) ;
60 }
61
62
63 $monstr = "JanFebMarAprMayJunJulAugSepOctNovDec" ;
64 $letstr = "abcdefghijklmnopqrstuvwxyz" ;
65
66 sub createArticle {
67         local ($counter) = @_ ;
68         local ($filename,$msgid,$i) ;
69         local ($time) = $^T ;
70         local ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)
71                                                   = gmtime($time);
72         local ($index) = $counter ;
73
74
75         if ($opt_a && ((int (rand (4)) % 2) == 0)) {
76                 $index = int ($index / 2) ;
77         }
78
79         $msgid = "<$index.$$.$time\@home.octet.com.au>" ;
80
81         $filename = sprintf ("%s/SampleArticle.%06d",$directory,$index) ;
82
83         open (ARTICLE,">$filename") || 
84                 die "open ($filename): $!\n" ;
85         print ARTICLE  "Path: home.octet.com.au!not-for-mail$cr\n" ;
86         print ARTICLE "From: brister\@home.octet.com.au$cr\n" ;
87         print ARTICLE "Newsgroups: junk,local.test$cr\n" ;
88         print ARTICLE "Subject: Test$cr\n" ;
89         print ARTICLE "Date: " ;
90
91         printf ARTICLE "%d %s %d %02d:%02d:%02d UTC$cr\n",
92                 $mday, substr($monstr,$mon * 3, 3), $year + 1900,
93                 $hour, $min, $sec ;
94
95         print ARTICLE "Organization: None that I can think of$cr\n" ;
96         print ARTICLE "Lines: 5$cr\n" ;
97         print ARTICLE "Distribution: world$cr\n" ;
98         print ARTICLE "Message-ID: $msgid$cr\n" ;
99         print ARTICLE "NNTP-Posting-Host: localhost$cr\n" ;
100         print ARTICLE "$cr\n" ;
101         
102         for ($i = 0 ; $i < $lineCount ; $i++) {
103                 print ARTICLE "x" x ($lineCount + 1), "$cr\n";
104         }
105         print ARTICLE ".This line has a leading dot.$cr\n" ;
106         print ARTICLE "And the next line only has a dot.$cr\n" ;
107         if ($opt_r) {
108             print ARTICLE "..$cr\n" ;
109         } else {
110             print ARTICLE ".$cr\n" ;
111         }
112         print ARTICLE "And the next line has just two dots...$cr\n" ;
113         print ARTICLE "...$cr\n" ;
114         print ARTICLE "foo$cr\n" ;
115         print ARTICLE "And the next line is the last line of the article$cr\n" ;
116         print ARTICLE "and it only has a single dot on it.$cr\n" ;
117         if ($opt_r) {
118             print ARTICLE "..$cr\n" ;
119         } else {
120             print ARTICLE ".$cr\n" ;
121         }
122
123
124         close (ARTICLE) ;
125
126         return ($msgid, $filename) ;
127 }
128
129 srand ;
130
131
132 $| = 1 ;
133
134 if ( ! -t STDERR ) {
135     open (STDERR,">>/tmp/TESTLISTENER.LOG") || die ;
136 }
137
138 srand ;
139 $sleepAmt = 1 if ($sleepAmt < 0) ;
140
141 foreach $peer ( @ARGV ) {
142     $PEERS{$peer} = 1 ;
143 }
144
145 die "Must give peernames on command line:\n$usage" if ( ! @ARGV ) ;
146
147 for ( $i = 0 ; $total == 0 || $i < $total ; $i++ ) {
148         ($msgid,$filename) = &createArticle ($i) ;
149         if ($opt_a && ((rand (3) % 3) == 0)) { 
150                 print TTY "Removing file $filename\n" ;
151                 unlink ($filename) if $opt_u ;
152         }
153         print "$filename $msgid @ARGV" ;
154         print " $bogus" if ($bogus && (rand (5) % 5) == 0) ;
155         print "\n" ;
156             
157         select (undef,undef,undef,(rand ($sleepAmt-1) + 1)) if $sleepAmt ;
158 }
159
160 sleep 11500 unless -f STDOUT ;