1 #***************************************************************************
3 # Project ___| | | | _ \| |
5 # | (__| |_| | _ <| |___
6 # \___|\___/|_| \_\_____|
8 # Copyright (C) 1998 - 2016, 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 https://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|HTTP\/2|IMAP|POP3|SMTP|HTTP-PIPE)S?)|(TFTP|SFTP|SOCKS|SSH|RTSP|GOPHER|HTTPTLS|DICT|SMB|SMBS|TELNET))$/));
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));
145 #***************************************************************************
146 # Return file name for server pid file.
148 sub server_pidfilename {
149 my ($proto, $ipver, $idnum) = @_;
150 my $trailer = '_server.pid';
151 return '.'. servername_canon($proto, $ipver, $idnum) ."$trailer";
155 #***************************************************************************
156 # Return file name for server log file.
158 sub server_logfilename {
159 my ($logdir, $proto, $ipver, $idnum) = @_;
160 my $trailer = '_server.log';
161 $trailer = '_stunnel.log' if(lc($proto) =~ /^(ftp|http|imap|pop3|smtp)s$/);
162 return "${logdir}/". servername_canon($proto, $ipver, $idnum) ."$trailer";
166 #***************************************************************************
167 # Return file name for server commands file.
169 sub server_cmdfilename {
170 my ($logdir, $proto, $ipver, $idnum) = @_;
171 my $trailer = '_server.cmd';
172 return "${logdir}/". servername_canon($proto, $ipver, $idnum) ."$trailer";
176 #***************************************************************************
177 # Return file name for server input file.
179 sub server_inputfilename {
180 my ($logdir, $proto, $ipver, $idnum) = @_;
181 my $trailer = '_server.input';
182 return "${logdir}/". servername_canon($proto, $ipver, $idnum) ."$trailer";
186 #***************************************************************************
187 # Return file name for server output file.
189 sub server_outputfilename {
190 my ($logdir, $proto, $ipver, $idnum) = @_;
191 my $trailer = '_server.output';
192 return "${logdir}/". servername_canon($proto, $ipver, $idnum) ."$trailer";
196 #***************************************************************************
197 # Return file name for main or primary sockfilter pid file.
199 sub mainsockf_pidfilename {
200 my ($proto, $ipver, $idnum) = @_;
201 die "unsupported protocol: '$proto'" unless($proto &&
202 (lc($proto) =~ /^(ftp|imap|pop3|smtp)s?$/));
203 my $trailer = (lc($proto) =~ /^ftps?$/) ? '_sockctrl.pid':'_sockfilt.pid';
204 return '.'. servername_canon($proto, $ipver, $idnum) ."$trailer";
208 #***************************************************************************
209 # Return file name for main or primary sockfilter log file.
211 sub mainsockf_logfilename {
212 my ($logdir, $proto, $ipver, $idnum) = @_;
213 die "unsupported protocol: '$proto'" unless($proto &&
214 (lc($proto) =~ /^(ftp|imap|pop3|smtp)s?$/));
215 my $trailer = (lc($proto) =~ /^ftps?$/) ? '_sockctrl.log':'_sockfilt.log';
216 return "${logdir}/". servername_canon($proto, $ipver, $idnum) ."$trailer";
220 #***************************************************************************
221 # Return file name for data or secondary sockfilter pid file.
223 sub datasockf_pidfilename {
224 my ($proto, $ipver, $idnum) = @_;
225 die "unsupported protocol: '$proto'" unless($proto &&
226 (lc($proto) =~ /^ftps?$/));
227 my $trailer = '_sockdata.pid';
228 return '.'. servername_canon($proto, $ipver, $idnum) ."$trailer";
232 #***************************************************************************
233 # Return file name for data or secondary sockfilter log file.
235 sub datasockf_logfilename {
236 my ($logdir, $proto, $ipver, $idnum) = @_;
237 die "unsupported protocol: '$proto'" unless($proto &&
238 (lc($proto) =~ /^ftps?$/));
239 my $trailer = '_sockdata.log';
240 return "${logdir}/". servername_canon($proto, $ipver, $idnum) ."$trailer";
244 #***************************************************************************