1 #***************************************************************************
3 # Project ___| | | | _ \| |
5 # | (__| |_| | _ <| |___
6 # \___|\___/|_| \_\_____|
8 # Copyright (C) 1998 - 2010, Daniel Stenberg, <daniel@haxx.se>, et al.
10 # This software is licensed as described in the file COPYING, which
11 # you should have received as part of this distribution. The terms
12 # are also available at http://curl.haxx.se/docs/copyright.html.
14 # You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 # copies of the Software, and permit persons to whom the Software is
16 # furnished to do so, under the terms of the COPYING file.
18 # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 # KIND, either express or implied.
21 #***************************************************************************
30 #***************************************************************************
31 # Global symbols allowed without explicit package name
39 #***************************************************************************
40 # Inherit Exporter's capabilities
45 #***************************************************************************
46 # Global symbols this module will export upon request
65 #***************************************************************************
66 # Return server characterization factors given a server id string.
74 if($server =~ /^((ftp|http|imap|pop3|smtp)s?)(\d*)(-ipv6|)$/) {
76 $idnum = ($3 && ($3 > 1)) ? $3 : 1;
77 $ipvnum = ($4 && ($4 =~ /6$/)) ? 6 : 4;
79 elsif($server =~ /^(tftp|sftp|socks|ssh|rtsp)(\d*)(-ipv6|)$/) {
81 $idnum = ($2 && ($2 > 1)) ? $2 : 1;
82 $ipvnum = ($3 && ($3 =~ /6$/)) ? 6 : 4;
85 die "invalid server id: $server"
87 return($proto, $ipvnum, $idnum);
91 #***************************************************************************
92 # Return server name string formatted for presentation purposes
95 my ($proto, $ipver, $idnum) = @_;
97 $proto = uc($proto) if($proto);
98 die "unsupported protocol: $proto" unless($proto &&
99 ($proto =~ /^(((FTP|HTTP|IMAP|POP3|SMTP)S?)|(TFTP|SFTP|SOCKS|SSH|RTSP|GOPHER))$/));
101 $ipver = (not $ipver) ? 'ipv4' : lc($ipver);
102 die "unsupported IP version: $ipver" unless($ipver &&
103 ($ipver =~ /^(4|6|ipv4|ipv6|-ipv4|-ipv6)$/));
104 $ipver = ($ipver =~ /6$/) ? '-IPv6' : '';
106 $idnum = 1 if(not $idnum);
107 die "unsupported ID number: $idnum" unless($idnum &&
108 ($idnum =~ /^(\d+)$/));
109 $idnum = '' unless($idnum > 1);
111 return "${proto}${idnum}${ipver}";
115 #***************************************************************************
116 # Return server name string formatted for identification purposes
119 my ($proto, $ipver, $idnum) = @_;
120 return lc(servername_str($proto, $ipver, $idnum));
124 #***************************************************************************
125 # Return server name string formatted for file name purposes
127 sub servername_canon {
128 my ($proto, $ipver, $idnum) = @_;
129 my $string = lc(servername_str($proto, $ipver, $idnum));
135 #***************************************************************************
136 # Return file name for server pid file.
138 sub server_pidfilename {
139 my ($proto, $ipver, $idnum) = @_;
140 my $trailer = '_server.pid';
141 return '.'. servername_canon($proto, $ipver, $idnum) ."$trailer";
145 #***************************************************************************
146 # Return file name for server log file.
148 sub server_logfilename {
149 my ($logdir, $proto, $ipver, $idnum) = @_;
150 my $trailer = '_server.log';
151 $trailer = '_stunnel.log' if(lc($proto) =~ /^(ftp|http|imap|pop3|smtp)s$/||
152 lc($proto) eq 'gopher');
153 return "${logdir}/". servername_canon($proto, $ipver, $idnum) ."$trailer";
157 #***************************************************************************
158 # Return file name for server commands file.
160 sub server_cmdfilename {
161 my ($logdir, $proto, $ipver, $idnum) = @_;
162 my $trailer = '_server.cmd';
163 return "${logdir}/". servername_canon($proto, $ipver, $idnum) ."$trailer";
167 #***************************************************************************
168 # Return file name for server input file.
170 sub server_inputfilename {
171 my ($logdir, $proto, $ipver, $idnum) = @_;
172 my $trailer = '_server.input';
173 return "${logdir}/". servername_canon($proto, $ipver, $idnum) ."$trailer";
177 #***************************************************************************
178 # Return file name for server output file.
180 sub server_outputfilename {
181 my ($logdir, $proto, $ipver, $idnum) = @_;
182 my $trailer = '_server.output';
183 return "${logdir}/". servername_canon($proto, $ipver, $idnum) ."$trailer";
187 #***************************************************************************
188 # Return file name for main or primary sockfilter pid file.
190 sub mainsockf_pidfilename {
191 my ($proto, $ipver, $idnum) = @_;
192 die "unsupported protocol: $proto" unless($proto &&
193 ((lc($proto) =~ /^(ftp|imap|pop3|smtp)s?$/) || lc($proto) eq 'gopher'));
194 my $trailer = (lc($proto) =~ /^ftps?$/) ? '_sockctrl.pid':'_sockfilt.pid';
195 return '.'. servername_canon($proto, $ipver, $idnum) ."$trailer";
199 #***************************************************************************
200 # Return file name for main or primary sockfilter log file.
202 sub mainsockf_logfilename {
203 my ($logdir, $proto, $ipver, $idnum) = @_;
204 die "unsupported protocol: $proto" unless($proto &&
205 ((lc($proto) =~ /^(ftp|imap|pop3|smtp)s?$/) || lc($proto) eq 'gopher'));
206 my $trailer = (lc($proto) =~ /^ftps?$/) ? '_sockctrl.log':'_sockfilt.log';
207 return "${logdir}/". servername_canon($proto, $ipver, $idnum) ."$trailer";
211 #***************************************************************************
212 # Return file name for data or secondary sockfilter pid file.
214 sub datasockf_pidfilename {
215 my ($proto, $ipver, $idnum) = @_;
216 die "unsupported protocol: $proto" unless($proto &&
217 (lc($proto) =~ /^ftps?$/));
218 my $trailer = '_sockdata.pid';
219 return '.'. servername_canon($proto, $ipver, $idnum) ."$trailer";
223 #***************************************************************************
224 # Return file name for data or secondary sockfilter log file.
226 sub datasockf_logfilename {
227 my ($logdir, $proto, $ipver, $idnum) = @_;
228 die "unsupported protocol: $proto" unless($proto &&
229 (lc($proto) =~ /^ftps?$/));
230 my $trailer = '_sockdata.log';
231 return "${logdir}/". servername_canon($proto, $ipver, $idnum) ."$trailer";
235 #***************************************************************************