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.
12 # testListener.pl -t 30 -d tmp | innfeed
16 # innfeed -s 'perl testListener.pl -t 30 -d tmp'
21 require 'getopts.pl' ;
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" ;
32 &Getopts ("a:b:c:d:t:rl:h:") || die $usage ;
34 die $usage if $opt_h ;
38 $sleepAmt = $opt_t if ($opt_t =~ /^[\d\.]+/) ;
41 $lineCount = $opt_l if ($opt_l =~ /^\d+$/) ;
44 $directory = $opt_d if $opt_d ;
47 if ( $bogus && $bogus !~ /^[a-zA-Z]+$/ ) {
48 print "The bogus peername must contain only letters\n" ;
51 $cr = ($opt_r ? "\r" : "") ;
53 $SIG{'INT'} = 'IGNORE' ;
54 $SIG{'TERM'} = 'sigHup' ;
55 $SIG{'QUIT'} = 'sigHup' ;
56 $SIG{'HUP'} = 'sigHup' ;
63 $monstr = "JanFebMarAprMayJunJulAugSepOctNovDec" ;
64 $letstr = "abcdefghijklmnopqrstuvwxyz" ;
67 local ($counter) = @_ ;
68 local ($filename,$msgid,$i) ;
70 local ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)
72 local ($index) = $counter ;
75 if ($opt_a && ((int (rand (4)) % 2) == 0)) {
76 $index = int ($index / 2) ;
79 $msgid = "<$index.$$.$time\@home.octet.com.au>" ;
81 $filename = sprintf ("%s/SampleArticle.%06d",$directory,$index) ;
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: " ;
91 printf ARTICLE "%d %s %d %02d:%02d:%02d UTC$cr\n",
92 $mday, substr($monstr,$mon * 3, 3), $year + 1900,
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" ;
102 for ($i = 0 ; $i < $lineCount ; $i++) {
103 print ARTICLE "x" x ($lineCount + 1), "$cr\n";
105 print ARTICLE ".This line has a leading dot.$cr\n" ;
106 print ARTICLE "And the next line only has a dot.$cr\n" ;
108 print ARTICLE "..$cr\n" ;
110 print ARTICLE ".$cr\n" ;
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" ;
118 print ARTICLE "..$cr\n" ;
120 print ARTICLE ".$cr\n" ;
126 return ($msgid, $filename) ;
135 open (STDERR,">>/tmp/TESTLISTENER.LOG") || die ;
139 $sleepAmt = 1 if ($sleepAmt < 0) ;
141 foreach $peer ( @ARGV ) {
145 die "Must give peernames on command line:\n$usage" if ( ! @ARGV ) ;
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 ;
153 print "$filename $msgid @ARGV" ;
154 print " $bogus" if ($bogus && (rand (5) % 5) == 0) ;
157 select (undef,undef,undef,(rand ($sleepAmt-1) + 1)) if $sleepAmt ;
160 sleep 11500 unless -f STDOUT ;