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
# $Id: serverhelp.pm,v 1.7 2010-02-01 12:05:08 yangtse Exp $
22
#***************************************************************************
31
#***************************************************************************
32
# Global symbols allowed without explicit package name
40
#***************************************************************************
41
# Inherit Exporter's capabilities
46
#***************************************************************************
47
# Global symbols this module will export upon request
66
#***************************************************************************
67
# Return server characterization factors given a server id string.
75
if($server =~ /^((ftp|http|imap|pop3|smtp)s?)(\d*)(-ipv6|)$/) {
77
$idnum = ($3 && ($3 > 1)) ? $3 : 1;
78
$ipvnum = ($4 && ($4 =~ /6$/)) ? 6 : 4;
80
elsif($server =~ /^(tftp|sftp|socks|ssh|rtsp)(\d*)(-ipv6|)$/) {
82
$idnum = ($2 && ($2 > 1)) ? $2 : 1;
83
$ipvnum = ($3 && ($3 =~ /6$/)) ? 6 : 4;
86
die "invalid server id: $server"
88
return($proto, $ipvnum, $idnum);
92
#***************************************************************************
93
# Return server name string formatted for presentation purposes
96
my ($proto, $ipver, $idnum) = @_;
98
$proto = uc($proto) if($proto);
99
die "unsupported protocol: $proto" unless($proto &&
100
($proto =~ /^(((FTP|HTTP|IMAP|POP3|SMTP)S?)|(TFTP|SFTP|SOCKS|SSH|RTSP))$/));
102
$ipver = (not $ipver) ? 'ipv4' : lc($ipver);
103
die "unsupported IP version: $ipver" unless($ipver &&
104
($ipver =~ /^(4|6|ipv4|ipv6|-ipv4|-ipv6)$/));
105
$ipver = ($ipver =~ /6$/) ? '-IPv6' : '';
107
$idnum = 1 if(not $idnum);
108
die "unsupported ID number: $idnum" unless($idnum &&
109
($idnum =~ /^(\d+)$/));
110
$idnum = '' unless($idnum > 1);
112
return "${proto}${idnum}${ipver}";
116
#***************************************************************************
117
# Return server name string formatted for identification purposes
120
my ($proto, $ipver, $idnum) = @_;
121
return lc(servername_str($proto, $ipver, $idnum));
125
#***************************************************************************
126
# Return server name string formatted for file name purposes
128
sub servername_canon {
129
my ($proto, $ipver, $idnum) = @_;
130
my $string = lc(servername_str($proto, $ipver, $idnum));
136
#***************************************************************************
137
# Return file name for server pid file.
139
sub server_pidfilename {
140
my ($proto, $ipver, $idnum) = @_;
141
my $trailer = '_server.pid';
142
return '.'. servername_canon($proto, $ipver, $idnum) ."$trailer";
146
#***************************************************************************
147
# Return file name for server log file.
149
sub server_logfilename {
150
my ($logdir, $proto, $ipver, $idnum) = @_;
151
my $trailer = '_server.log';
152
$trailer = '_stunnel.log' if(lc($proto) =~ /^(ftp|http|imap|pop3|smtp)s$/);
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?$/));
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?$/));
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
#***************************************************************************