1 #*************************************************************************
3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 # Copyright 2008 by Sun Microsystems, Inc.
7 # OpenOffice.org - a multi-platform office productivity suite
9 # $RCSfile: CwsConfig.pm,v $
11 # $Revision: 1.11.44.2 $
13 # This file is part of OpenOffice.org.
15 # OpenOffice.org is free software: you can redistribute it and/or modify
16 # it under the terms of the GNU Lesser General Public License version 3
17 # only, as published by the Free Software Foundation.
19 # OpenOffice.org is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU Lesser General Public License version 3 for more details
23 # (a copy is included in the LICENSE file that accompanied this code).
25 # You should have received a copy of the GNU Lesser General Public License
26 # version 3 along with OpenOffice.org. If not, see
27 # <http://www.openoffice.org/license.html>
28 # for a copy of the LGPLv3 License.
30 #*************************************************************************
34 # CwsConfig.pm - package for read CWS config data
48 my $class = ref($invocant) || $invocant;
50 $self->{_CONFIG_FILE
} = undef; # config file
51 $self->{_GLOBAL
} = undef; # is it a global config file?
52 $self->{VCSID
} = undef; # VCSID
53 $self->{CWS_DB_URL_LIST_REF
} = undef; # list of CWS DB servers
54 $self->{NET_PROXY
} = undef; # network proxy
55 $self->{CWS_SERVER_ROOT
} = undef; # cvs server
56 $self->{CWS_MIRROR_ROOT
} = undef; # mirror of cvs server
57 $self->{CWS_LOCAL_ROOT
} = undef; # local cvs server
58 $self->{PUBLIC_SVN_SERVER
} = undef; # public svn server
59 $self->{PRIVATE_SVN_SERVER
} = undef; # private svn server
60 bless ($self, $class);
68 if ( !defined($self->{VCSID
}) ) {
69 # environment overrides config file
70 my $vcsid = $ENV{VCSID
};
71 if ( !defined($vcsid) ) {
73 my $config_file = $self->get_config_file();
74 $vcsid = $config_file->{CWS_CONFIG
}->{'CVS_ID'};
75 if ( !defined($vcsid) ) {
77 croak
("ERROR: no CVS_ID entry found in '\$HOME/.cwsrc'.\n" );
80 $self->{VCSID
} = $vcsid;
82 return $self->{VCSID
};
85 sub cws_db_url_list_ref
89 if ( !defined($self->{CWS_DB_URL_LIST_REF
}) ) {
90 my $config_file = $self->get_config_file();
96 my $val = $config_file->{CWS_CONFIG
}->{"CWS_DB_SERVER_$i"};
97 last if !defined($val);
98 push(@cws_db_servers, $val);
102 if ( !@cws_db_servers) {
103 croak
("ERROR: no CWS_DB_SERVER_* entry found in '\$HOME/.cwsrc'.\n" );
106 if ( $cws_db_servers[0] =~ /^https:\/\
// ) {
107 my $id = $self->vcsid();
108 my $password = $config_file->{CWS_CONFIG
}->{'CVS_PASSWORD'};
110 if ( !defined($password) ) {
111 croak
("ERROR: no CVS_PASSWORD entry found in '\$HOME/.cwsrc'.\n" );
114 # *i49473* - do not accept scrambled passwords ending with a space
115 if ( $password =~ / $/) {
116 croak
("ERROR: The (scrambled) CVS_PASSWORD ends with a space. This is known to cause problems when connecting to the OpenOffice.org EIS database. Please change your OOo account's password" );
119 # We are going to stuff $id and $password in an URL, do proper escaping.
120 $id = uri_escape
($id);
121 $password = uri_escape
($password);
123 foreach ( @cws_db_servers ) {
124 s/^https:\/\//https:\/\
/$id:$password@/;
128 $self->{CWS_DB_URL_LIST_REF
} = \
@cws_db_servers;
130 return $self->{CWS_DB_URL_LIST_REF
};
137 if ( !defined($self->{NET_PROXY
}) ) {
138 my $config_file = $self->get_config_file();
139 my $net_proxy = $config_file->{CWS_CONFIG
}->{'PROXY'};
140 if ( !defined($net_proxy) ) {
143 $self->{NET_PROXY
} = $net_proxy;
145 return $self->{NET_PROXY
} ?
$self->{NET_PROXY
} : undef;
152 if ( !defined($self->{CVS_BINARY
}) ) {
153 my $config_file = $self->get_config_file();
154 my $cvs_binary = $config_file->{CWS_CONFIG
}->{'CVS_BINARY'};
155 if ( !defined($cvs_binary) ) {
157 $cvs_binary = ($^O
eq 'MSWin32') ?
'cvs.exe' : 'cvs';
159 # special case, don't ask
160 if ( $self->{_GLOBAL
} && $cvs_binary =~ /cvs.clt2/ && $^O
eq 'MSWin32' ) {
161 $cvs_binary = 'cvsclt2.exe';
163 $self->{CVS_BINARY
} = $cvs_binary;
165 return $self->{CVS_BINARY
};
172 if ( !defined($self->{CVS_SERVER_ROOT
}) ) {
173 my $config_file = $self->get_config_file();
174 my $cvs_server_root = $config_file->{CWS_CONFIG
}->{'CVS_SERVER_ROOT'};
175 if ( !defined($cvs_server_root) ) {
176 # give up, this is a mandatory entry
177 croak
("ERROR: can't parse CVS_SERVER_ROOT entry in '\$HOME/.cwsrc'.\n");
179 if ( $self->{_GLOBAL
} ) {
180 # a global config file will almost always have the wrong vcsid in
181 # the cvsroot -> substitute vcsid
182 my $id = $self->vcsid();
183 $cvs_server_root =~ s/:pserver:\w+@/:pserver:$id@/;
185 $self->{CVS_SERVER_ROOT
} = $cvs_server_root;
187 return $self->{CVS_SERVER_ROOT
};
194 if ( !defined($self->{CVS_MIRROR_ROOT
}) ) {
195 my $config_file = $self->get_config_file();
196 my $cvs_mirror_root = $config_file->{CWS_CONFIG
}->{'CVS_MIRROR_ROOT'};
197 if ( !defined($cvs_mirror_root) ) {
198 $cvs_mirror_root = "";
200 $self->{CVS_MIRROR_ROOT
} = $cvs_mirror_root;
202 return $self->{CVS_MIRROR_ROOT
} ?
$self->{CVS_MIRROR_ROOT
} : undef;
209 if ( !defined($self->{CVS_LOCAL_ROOT
}) ) {
210 my $config_file = $self->get_config_file();
211 my $cvs_local_root = $config_file->{CWS_CONFIG
}->{'CVS_LOCAL_ROOT'};
212 if ( !defined($cvs_local_root) ) {
213 $cvs_local_root = "";
215 $self->{CVS_LOCAL_ROOT
} = $cvs_local_root;
217 return $self->{CVS_LOCAL_ROOT
} ?
$self->{CVS_LOCAL_ROOT
} : undef;
224 my ($method, $id, $server, $repository) = CwsConfig
::split_root
($self->cvs_server_root(), 'SERVER');
232 my ($method, $id, $server, $repository) = CwsConfig
::split_root
($self->cvs_mirror_root(), 'MIRROR');
240 my ($method, $id, $server, $repository) = CwsConfig
::split_root
($self->cvs_local_root(), 'LOCAL');
244 sub get_cvs_server_method
248 my ($method, $id, $server, $repository) = CwsConfig
::split_root
($self->cvs_server_root(), 'SERVER');
252 sub get_cvs_mirror_method
256 my ($method, $id, $server, $repository) = CwsConfig
::split_root
($self->cvs_mirror_root(), 'MIRROR');
260 sub get_cvs_local_method
264 my ($method, $id, $server, $repository) = CwsConfig
::split_root
($self->cvs_local_root(), 'LOCAL');
268 sub get_cvs_server_repository
272 my ($method, $id, $server, $repository) = CwsConfig
::split_root
($self->cvs_server_root(), 'SERVER');
276 sub get_cvs_mirror_repository
280 my ($method, $id, $server, $repository) = CwsConfig
::split_root
($self->cvs_mirror_root(), 'MIRROR');
284 sub get_cvs_local_repository
288 my ($method, $id, $server, $repository) = CwsConfig
::split_root
($self->cvs_local_root(), 'LOCAL');
292 sub get_cvs_server_id
296 my ($method, $id, $server, $repository) = CwsConfig
::split_root
($self->cvs_server_root(), 'SERVER');
300 sub get_cvs_mirror_id
304 my ($method, $id, $server, $repository) = CwsConfig
::split_root
($self->cvs_mirror_root(), 'MIRROR');
312 my ($method, $id, $server, $repository) = CwsConfig
::split_root
($self->cvs_local_root(), 'LOCAL');
316 #### SVN methods ####
318 sub get_ooo_svn_server
322 if ( !defined($self->{SVN_SERVER
}) ) {
323 my $config_file = $self->get_config_file();
324 my $ooo_svn_server = $config_file->{CWS_CONFIG
}->{'SVN_SERVER'};
325 if ( !defined($ooo_svn_server) ) {
326 $ooo_svn_server = "";
328 $self->{SVN_SERVER
} = $ooo_svn_server;
330 return $self->{SVN_SERVER
} ?
$self->{SVN_SERVER
} : undef;
333 sub get_so_svn_server
337 if ( !defined($self->{SO_SVN_SERVER
}) ) {
338 my $config_file = $self->get_config_file();
339 my $so_svn_server = $config_file->{CWS_CONFIG
}->{'SO_SVN_SERVER'};
340 if ( !defined($so_svn_server) ) {
343 $self->{SO_SVN_SERVER
} = $so_svn_server;
345 return $self->{SO_SVN_SERVER
} ?
$self->{SO_SVN_SERVER
} : undef;
348 #### Prebuild binaries configuration ####
350 sub get_prebuild_binaries_location
354 if ( !defined($self->{PREBUILD_BINARIES
}) ) {
355 my $config_file = $self->get_config_file();
356 my $pre_build_binaries = $config_file->{CWS_CONFIG
}->{'PREBUILD_BINARIES'};
357 if ( !defined($pre_build_binaries) ) {
358 $pre_build_binaries = "";
360 $self->{PREBUILD_BINARIES
} = $pre_build_binaries;
362 return $self->{PREBUILD_BINARIES
} ?
$self->{PREBUILD_BINARIES
} : undef;
367 #### class methods #####
370 my $config = CwsConfig
->new();
379 if ( !defined($root) ) {
380 return (undef, undef, undef, undef);
383 my ($dummy, $method, $id_at_host, $repository) = split(/:/, $root);
384 $repository =~ s/^\d*//;
387 ($id, $server) = split(/@/, $id_at_host);
389 if ( !defined($method) || !defined($id) || !defined($server) || !defined($repository) ) {
391 print "$method, $id, $server, $repository\n";
392 croak
("ERROR: can't parse CVS_".$type."_ROOT entry in '\$HOME/.cwsrc'.\n");
394 return ($method, $id, $server, $repository);
397 #### private helper methods ####
403 if ( !defined $self->{_CONFIG_FILE
} ) {
404 $self->parse_config_file();
406 return $self->{_CONFIG_FILE
};
417 open ($fhandle, $fname) || croak
("ERROR: Can't open '$fname': $!");
418 while ( <$fhandle> ) {
419 tr/\r\n//d; # win32 pain
420 # Issue #i62815#: Scrambled CVS passwords may contain one or more '#'.
421 # Ugly special case needed: still allow in-line (perl style) comments
422 # elsewhere because existing configuration files may depend on them.
423 if ( !/^\s*CVS_PASSWORD/ ) {
424 s/\#.*//; # kill comments
428 if (/\[\s*(\S+)\s*\]/) {
430 if (!defined $config{$section}) {
431 $config{$section} = {};
434 defined $config{$section} || croak
("ERROR: unknown / no section '$section'\n");
435 if ( m/(\w[\w\d]*)=(.*)/ ) {
438 # New style value strings may be surrounded by quotes
439 if ( $val =~ s/\s*(['"])(.*)\1\s*$/$2/ ) {
441 # If and only if the value string is surrounded by quotes we
442 # can expect that \" or \' are escaped characters. In an unquoted
443 # old style value string they could mean exactly what is standing there
445 # Actually the RE above works without quoting the quote character
446 # (either " or ') inside the value string but users will probably
447 # expect that they need to be escaped if quotes are used.
449 # This is still not completly correct for all thinkable situations but
450 # should be good enough for all practical use cases.
451 $val =~ s/\\($quote)/$1/g;
453 $config{$section}->{$var} = $val;
454 # print "Set '$var' to '$val'\n";
457 close ($fhandle) || croak
("ERROR: Failed to close: $!");
459 $self->{_CONFIG_FILE
} = \
%config;
462 sub parse_config_file
467 # check for config files
468 if ( -e
"$ENV{HOME}/.cwsrc" ) {
469 $self->read_config("$ENV{HOME}/.cwsrc");
470 $self->{_GLOBAL
} = 0;
472 elsif ( -e
"$ENV{COMMON_ENV_TOOLS}/cwsrc" ) {
473 $self->read_config("$ENV{COMMON_ENV_TOOLS}/cwsrc");
474 $self->{_GLOBAL
} = 1;
477 croak
("ERROR: can't find CWS config file '\$HOME/.cwsrc'.\n");
484 my $config_file = $self->get_config_file();
485 my $val = ($config_file->{CWS_CONFIG
}->{"SO_INTERNAL"}) ?
1 : 0;
488 1; # needed by "use" or "require"