1 #***************************************************************************
3 # Project ___| | | | _ \| |
5 # | (__| |_| | _ <| |___
6 # \___|\___/|_| \_\_____|
8 # Copyright (C) 1998 - 2011, 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 # Just for convenience, test harness uses 'https' and 'httptls' literals as
67 # values for 'proto' variable in order to differentiate different servers.
68 # 'https' literal is used for stunnel based https test servers, and 'httptls'
69 # is used for non-stunnel https test servers.
72 #***************************************************************************
73 # Return server characterization factors given a server id string.
82 /^((ftp|http|imap|pop3|smtp|http-pipe)s?)(\d*)(-ipv6|)$/) {
84 $idnum = ($3 && ($3 > 1)) ? $3 : 1;
85 $ipvnum = ($4 && ($4 =~ /6$/)) ? 6 : 4;
88 /^(tftp|sftp|socks|ssh|rtsp|gopher|httptls)(\d*)(-ipv6|)$/) {
90 $idnum = ($2 && ($2 > 1)) ? $2 : 1;
91 $ipvnum = ($3 && ($3 =~ /6$/)) ? 6 : 4;
94 die "invalid server id: '$server'"
96 return($proto, $ipvnum, $idnum);
100 #***************************************************************************
101 # Return server name string formatted for presentation purposes
104 my ($proto, $ipver, $idnum) = @_;
106 $proto = uc($proto) if($proto);
107 die "unsupported protocol: '$proto'" unless($proto &&
108 ($proto =~ /^(((FTP|HTTP|IMAP|POP3|SMTP|HTTP-PIPE)S?)|(TFTP|SFTP|SOCKS|SSH|RTSP|GOPHER|HTTPTLS))$/));
110 $ipver = (not $ipver) ? 'ipv4' : lc($ipver);
111 die "unsupported IP version: '$ipver'" unless($ipver &&
112 ($ipver =~ /^(4|6|ipv4|ipv6|-ipv4|-ipv6|unix)$/));
113 $ipver = ($ipver =~ /6$/) ? '-IPv6' : (($ipver =~ /unix$/) ? '-unix' : '');
115 $idnum = 1 if(not $idnum);
116 die "unsupported ID number: '$idnum'" unless($idnum &&
117 ($idnum =~ /^(\d+)$/));
118 $idnum = '' unless($idnum > 1);
120 return "${proto}${idnum}${ipver}";
124 #***************************************************************************
125 # Return server name string formatted for identification purposes
128 my ($proto, $ipver, $idnum) = @_;
129 return lc(servername_str($proto, $ipver, $idnum));
133 #***************************************************************************
134 # Return server name string formatted for file name purposes
136 sub servername_canon {
137 my ($proto, $ipver, $idnum) = @_;
138 my $string = lc(servername_str($proto, $ipver, $idnum));
144 #***************************************************************************
145 # Return file name for server pid file.
147 sub server_pidfilename {
148 my ($proto, $ipver, $idnum) = @_;
149 my $trailer = '_server.pid';
150 return '.'. servername_canon($proto, $ipver, $idnum) ."$trailer";
154 #***************************************************************************
155 # Return file name for server log file.
157 sub server_logfilename {
158 my ($logdir, $proto, $ipver, $idnum) = @_;
159 my $trailer = '_server.log';
160 $trailer = '_stunnel.log' if(lc($proto) =~ /^(ftp|http|imap|pop3|smtp)s$/);
161 return "${logdir}/". servername_canon($proto, $ipver, $idnum) ."$trailer";
165 #***************************************************************************
166 # Return file name for server commands file.
168 sub server_cmdfilename {
169 my ($logdir, $proto, $ipver, $idnum) = @_;
170 my $trailer = '_server.cmd';
171 return "${logdir}/". servername_canon($proto, $ipver, $idnum) ."$trailer";
175 #***************************************************************************
176 # Return file name for server input file.
178 sub server_inputfilename {
179 my ($logdir, $proto, $ipver, $idnum) = @_;
180 my $trailer = '_server.input';
181 return "${logdir}/". servername_canon($proto, $ipver, $idnum) ."$trailer";
185 #***************************************************************************
186 # Return file name for server output file.
188 sub server_outputfilename {
189 my ($logdir, $proto, $ipver, $idnum) = @_;
190 my $trailer = '_server.output';
191 return "${logdir}/". servername_canon($proto, $ipver, $idnum) ."$trailer";
195 #***************************************************************************
196 # Return file name for main or primary sockfilter pid file.
198 sub mainsockf_pidfilename {
199 my ($proto, $ipver, $idnum) = @_;
200 die "unsupported protocol: '$proto'" unless($proto &&
201 (lc($proto) =~ /^(ftp|imap|pop3|smtp)s?$/));
202 my $trailer = (lc($proto) =~ /^ftps?$/) ? '_sockctrl.pid':'_sockfilt.pid';
203 return '.'. servername_canon($proto, $ipver, $idnum) ."$trailer";
207 #***************************************************************************
208 # Return file name for main or primary sockfilter log file.
210 sub mainsockf_logfilename {
211 my ($logdir, $proto, $ipver, $idnum) = @_;
212 die "unsupported protocol: '$proto'" unless($proto &&
213 (lc($proto) =~ /^(ftp|imap|pop3|smtp)s?$/));
214 my $trailer = (lc($proto) =~ /^ftps?$/) ? '_sockctrl.log':'_sockfilt.log';
215 return "${logdir}/". servername_canon($proto, $ipver, $idnum) ."$trailer";
219 #***************************************************************************
220 # Return file name for data or secondary sockfilter pid file.
222 sub datasockf_pidfilename {
223 my ($proto, $ipver, $idnum) = @_;
224 die "unsupported protocol: '$proto'" unless($proto &&
225 (lc($proto) =~ /^ftps?$/));
226 my $trailer = '_sockdata.pid';
227 return '.'. servername_canon($proto, $ipver, $idnum) ."$trailer";
231 #***************************************************************************
232 # Return file name for data or secondary sockfilter log file.
234 sub datasockf_logfilename {
235 my ($logdir, $proto, $ipver, $idnum) = @_;
236 die "unsupported protocol: '$proto'" unless($proto &&
237 (lc($proto) =~ /^ftps?$/));
238 my $trailer = '_sockdata.log';
239 return "${logdir}/". servername_canon($proto, $ipver, $idnum) ."$trailer";
243 #***************************************************************************