chiark / gitweb /
implement connfail
[innduct.git] / innfeed / innfeed-convcfg.in
1 #! /usr/bin/perl
2
3 # Author:       James Brister <brister@vix.com> -- berkeley-unix --
4 # Start Date:   Sun, 19 Jan 1997 21:19:24 +0100
5 # Project:      INN (innfeed)
6 # File:         innfeed-convcfg.in
7 # RCSId:        $Id: innfeed-convcfg.in 2680 1999-11-15 06:37:43Z rra $
8 # Description:  Read in a old version of innfeed.conf on the command line 
9 #               or on stdin, and write a new version on stdout.
10
11
12 require 'ctime.pl' ;
13
14
15 @keyorder = (
16 'pid-file',
17 'debug-level',
18 'use-mmap',
19 'log-file',
20 'stdio-fdmax',
21 'backlog-directory',
22 'backlog-rotate-period',
23 'backlog-ckpt-period',
24 'backlog-newfile-period',
25 'dns-retry',
26 'dns-expire',
27 'close-period',
28 'gen-html',
29 'status-file',
30 'connection-stats',
31 'host-queue-highwater',
32 'stats-period',
33 'stats-reset',
34 'max-reconnect-time',
35 'initial-reconnect-time',
36 'article-timeout',
37 'response-timeout',
38 'initial-connections',
39 'max-connections',
40 'max-queue-size',
41 'streaming',
42 'no-check-high',
43 'no-check-low',
44 'port-number',
45 'backlog-limit',
46 'backlog-factor',
47 'backlog-limit-highwater'
48 );
49
50 %procDefaults = (
51 'pid-file', 'innfeed.pid',
52 'debug-level', '0',
53 'use-mmap', 'false',
54 'log-file', 'innfeed.log',
55 'stdio-fdmax', '0',
56 'backlog-directory', 'innfeed',
57 'backlog-rotate-period', '60',
58 'backlog-ckpt-period', '30',
59 'backlog-newfile-period', '600',
60 'dns-retry', '900',
61 'dns-expire', '86400',
62 'close-period', '3600',
63 'gen-html', 'false',
64 'status-file', 'innfeed.status',
65 'connection-stats', 'false',
66 'host-queue-highwater', '10',
67 'stats-period', '600',
68 'stats-reset', '43200',
69 'max-reconnect-time', '3600',
70 'initial-reconnect-time', '30',
71 'article-timeout', '600',
72 'response-timeout', '300',
73 'initial-connections', '1',
74 'max-connections', '5',
75 'max-queue-size', '25',
76 'streaming', 'true',
77 'no-check-high', '195.0',
78 'no-check-low', '90.0',
79 'port-number', '119',
80 'backlog-limit', '0',
81 'backlog-factor', '1.10',
82 'backlog-limit-highwater', '0',
83                  );
84
85 %defaultKeys = ('article-timeout', 1,
86                 'response-timeout', 1,
87                 'initial-connections', 1,
88                 'max-connections', 1,
89                 'max-queue-size', 1,
90                 'streaming', 1,
91                 'no-check-high', 1,
92                 'no-check-low', 1,
93                 'port-number', 1,
94                 'backlog-limit', 1) ;
95
96 @defaultOrder = ('article-timeout', 
97                 'response-timeout', 
98                 'initial-connections', 
99                 'max-connections', 
100                 'max-queue-size', 
101                 'streaming', 
102                 'no-check-high', 
103                 'no-check-low', 
104                 'port-number', 
105                 'backlog-limit') ;
106
107 %formats = () ;
108
109 foreach $key (keys %procDefaults) {
110     $max = length ($key) if length ($key) > $max ;
111     if ($procDefaults{$key} =~ /^true$/i || $procDefaults{$key} =~ /^false$/i){
112         $formats{$key} = "%s" ;
113     } elsif ($procDefaults{$key} =~ /^\d+$/) {
114         $formats{$key} = "%d" ;
115     } elsif ($procDefaults{$key} =~ /^\d+\.\d*$/) {
116         $formats{$key} = "%.4f" ;
117     } else {
118         $formats{$key} = "%s" ;
119     }
120 }
121
122
123 while (<>) {
124     next if /^\s*$/ ;
125     next if /^#/ ;
126
127     chop ;
128     @F = split (':') ;
129
130     if ($F[0] eq "default") {
131         $procDefaults{'article-timeout'} = $F[2] ;
132         $procDefaults{'response-timeout'} = $F[3] ;
133         $procDefaults{'initial-connections'} = $F[4] ;
134         $procDefaults{'max-connections'} = $F[5] ;
135         $procDefaults{'max-queue-size'} = $F[6] ;
136         $procDefaults{'streaming'} = $F[7] ;
137         $procDefaults{'no-check-low'} = $F[8] * 10.0 ;
138         $procDefaults{'no-check-high'} = $F[9] * 10.0 ;
139         $procDefaults{'port-number'} = $F[10] ;
140
141         printf "## This file was automatically generated created by $0\n" ;
142         printf "## On %s##\n\n", &ctime(time) ;
143
144         foreach $key (@keyorder) {
145             next if $defaultKeys{$key} ;
146
147             die "No format for $key\n" unless $formats{$key} ;
148             $format = "%${max}s:\t" . $formats{$key} . "\n" ;
149             printf $format, $key, $procDefaults{$key} ;
150         }
151
152         printf "\n\n## Defaults merged from:\n##\t$_\n\n" ;
153         foreach $key (@defaultOrder) {
154             die "No format for $key\n" unless $formats{$key} ;
155             $format ="%${max}s:\t" . $formats{$key} . "\n" ;
156             printf $format, $key, $procDefaults{$key} ;
157         }
158         print "\n\n\n" ;
159         $gotDefault = 1 ;
160     } elsif (@F == 0) {
161         die "Badly formed line: $0\n" ;
162     } else {
163         if (!$gotDefault) {
164             $gotDefault = 1 ;   # warn only one time.
165             warn "No default line was present.\n" ;
166         }
167
168         print "## Peer created from:\n" ;
169         print "##\t$_\n\n" ;
170         printf "peer %s {\n", $F[0] ;
171
172         printf "\tip-name: $F[1]\n" if $F[1] && $F[0] ne $F[1] ;
173         printf "\tarticle-timeout: %d\n", $F[2] if $F[2] ;
174         printf "\tresponse-timeout: %d\n", $F[3] if $F[3] ;
175         printf "\tinitial-connections: %d\n", $F[4] if ($F[4] ne "") ;
176         printf "\tmax-connections: %d\n", $F[5] if ($F[5] ne "") ;
177         printf "\tmax-queue-size: %d\n", $F[6] if ($F[6] ne "") ;
178         printf "\tstreaming: %s\n", $F[7] if ($F[7] ne "") ;
179         printf "\tno-check-high: %0.2f\n", $F[9] * 10.0 if ($F[9] ne "") ;
180         printf "\tno-check-low: %0.2f\n", $F[8] * 10.0 if ($F[8] ne "") ;
181         printf "\tport-number: %d\n", $F[10] if ($F[10] ne "") ;
182
183         print "}\n\n\n" ;
184     }
185 }
186         
187