Commit c4306260 authored by IKEDA Soji's avatar IKEDA Soji
Browse files

Refactoring / updating Sympa::Config::Schema:

  - Added not_before and not_after keys to hold available versions.
  - Simplified Conf.pm a bit.
  - Parameter "tracking" in sympa.conf/robot.conf will be forced renaming.
parent 3eada859
......@@ -7,7 +7,6 @@ use Cwd qw();
use English qw(-no_match_vars);
use Getopt::Long;
use Sympa::ConfDef;
use Sympa::Config::Schema;
use Sympa::Constants;
use Sympa::ListOpt;
......@@ -67,35 +66,40 @@ foreach my $okey (
and $pinfo->{$_}->{obsolete} =~ /\A[a-z]/
} _keys($pinfo)
) {
my $nkey = $pinfo->{$okey}->{obsolete};
my $pii = $pinfo->{$okey};
my $ppi = [$okey];
$parameters .= sprintf "=head3 C<%s>\n\n", _escape_pod($okey);
$parameters .= sprintf "See L<C<%s>|/%s>.\n\n", _escape_pod($nkey),
_escape_pod($nkey);
}
$parameters .= "=head2 Obsoleted F<sympa.conf> parameters\n\n";
$parameters .= "These parameters were used in F<sympa.conf> or F<robot.conf>";
$parameters .= " on Sympa 6.2.56 or earlier and are no longer";
$parameters .= " recommended.\n\n";
foreach my $okey (sort keys %Sympa::Config::Schema::obsolete_robot_params) {
my $nkey = $Sympa::Config::Schema::obsolete_robot_params{$okey};
$parameters .= sprintf "=head3 C<%s>\n\n", _escape_pod($okey);
$parameters .= sprintf "See L<C<%s>|/%s>.\n\n", _escape_pod($nkey),
_escape_pod($nkey);
$parameters .= sprintf "=head3 C<%s>\n\n", _escape_pod($okey);
_render($pii, $ppi);
}
$parameters .= "=head2 Deprecated parameters\n\n";
$parameters .= "These parameters were deprecated.";
$parameters .= " They may not be used anymore.\n\n";
foreach my $okey (
sort grep {
$pinfo->{$_}->{obsolete}
and $pinfo->{$_}->{obsolete} !~ /\A[a-z]/
} _keys($pinfo)
sort('tracking',
grep {
$pinfo->{$_}->{obsolete}
and $pinfo->{$_}->{obsolete} !~ /\A[a-z]/
} _keys($pinfo))
) {
$parameters .= sprintf "=head3 C<%s>\n\n", _escape_pod($okey);
if ($okey eq 'tracking') {
# Special: 'tracking' is a name of paragraph in list config.
$parameters .= "=head3 C<tracking> (domain and site)\n\n";
_render(
{ context => [qw(domain site)],
obsolete => 'tracking.tracking',
not_after => '6.2.56',
},
[]
);
} else {
my $pii = $pinfo->{$okey};
my $ppi = [$okey];
$parameters .= sprintf "=head3 C<%s>\n\n", _escape_pod($okey);
_render($pii, $ppi);
}
}
printf do { local $RS; <DATA> }, Sympa::Constants::CONFIG(), $parameters,
......@@ -108,12 +112,7 @@ sub _render {
my $ppi = shift;
if ($pii->{obsolete}) {
if ($pii->{obsolete} eq '1') {
$parameters .= "Deprecated.\n\n";
} else {
$parameters .= sprintf "Obsoleted. Use L<C<%s>|/%s>.\n\n",
$pii->{obsolete}, $pii->{obsolete};
}
_render_obsolete($pii, $ppi);
} elsif ($pii->{occurrence} =~ /n$/ and ref $pii->{format} eq 'ARRAY') {
_render_set($pii, $ppi);
} elsif (ref $pii->{format} eq 'HASH') {
......@@ -152,12 +151,7 @@ sub _render_paragraph {
#$parameters .= "=over\n\n" x (scalar @$pnames);
if ($pii->{obsolete}) {
if ($pii->{obsolete} eq '1') {
$parameters .= "Deprecated.\n\n";
} else {
$parameters .= sprintf "Obsoleted. Use L<C<%s>|/%s>.\n\n",
$pii->{obsolete}, join '.', @$pnames, $pii->{obsolete};
}
_render_obsolete($pii);
} elsif ($pii->{occurrence} =~ /n$/ and ref $pii->{format} eq 'ARRAY')
{
_render_set($pii, $ppi);
......@@ -181,6 +175,7 @@ sub _render_set {
_format($pinfo);
_default($pinfo, $pnames);
_context($pinfo);
_version($pinfo);
$parameters .= "=back\n\n";
$parameters .= sprintf "%s\n\n", join "\n\n", split /\n/,
......@@ -202,6 +197,7 @@ sub _render_scalar {
_format($pinfo);
_default($pinfo, $pnames);
_context($pinfo);
_version($pinfo);
$parameters .= "=back\n\n";
......@@ -212,6 +208,23 @@ sub _render_scalar {
_sample($pinfo, $pnames);
}
sub _render_obsolete {
my $pii = shift;
return unless $pii->{obsolete};
if ($pii->{obsolete} eq '1') {
$parameters .= "Deprecated.\n\n";
} else {
$parameters .= sprintf "See L<C<%s>|/%s>.\n\n",
$pii->{obsolete}, $pii->{obsolete};
}
$parameters .= "=over\n\n";
_context($pii);
_version($pii);
$parameters .= "=back\n\n";
}
sub _format {
my $pinfo = shift;
......@@ -220,7 +233,7 @@ sub _format {
if ($pinfo->{occurrence} =~ /n$/) {
if ($pinfo->{split_char}) {
$parameters .=
sprintf "Multiple values allowed, separated by C<%s>.\n\n",
sprintf "Multiple values allowed, separated by \"C<%s>\".\n\n",
$pinfo->{split_char};
} else {
$parameters .= "Multiple occurrences allowed.\n\n";
......@@ -289,6 +302,8 @@ sub _format {
$format =~ s/\A\(\?\^:(.*)\)\z/$1/
or $format =~ s/\A\(\?-xism:(.*)\)\z/$1/;
$parameters .= sprintf "/C<%s>/\n\n", _escape_pod($format);
} else {
$parameters .= "Any.\n\n";
}
}
......@@ -342,6 +357,26 @@ sub _context {
}
}
sub _version {
my $pinfo = shift;
my $param_text;
my ($nb, $na) = @{$pinfo}{qw(not_before not_after)};
undef $nb if ($nb // '') =~ /^[?]+$/;
undef $na if ($na // '') =~ /^[?]+$/;
if ($nb and $na) {
$param_text = sprintf "%s to %s.", $nb, $na;
} elsif ($nb) {
$param_text = sprintf "%s and later.", $nb;
} elsif ($na) {
$param_text = sprintf "up to %s.", $na;
}
$parameters .= "=item Available versions:\n\n$param_text\n\n"
if $param_text;
}
sub _sample {
my $pinfo = shift;
my $pnames = shift;
......
......@@ -78,40 +78,6 @@ foreach my $hash (@Sympa::ConfDef::params) {
our $params_by_categories = _get_parameters_names_by_category();
my %old_params = (
trusted_ca_options => 'capath,cafile',
'msgcat' => '',
queueexpire => '',
clean_delay_queueother => '',
web_recode_to => 'filesystem_encoding', # ??? - 5.2
'localedir' => '',
'ldap_export_connection_timeout' => '', # 3.3b3 - 4.1?
'ldap_export_dnmanager' => '', # ,,
'ldap_export_host' => '', # ,,
'ldap_export_name' => '', # ,,
'ldap_export_password' => '', # ,,
'ldap_export_suffix' => '', # ,,
'tri' => 'sort', # ??? - 1.3.4-1
'sort' => '', # 1.4.0 - ???
'pidfile' => '', # ??? - 6.1.17
'pidfile_distribute' => '', # ,,
'pidfile_creation' => '', # ,,
'pidfile_bulk' => '', # ,,
'archived_pidfile' => '', # ,,
'bounced_pidfile' => '', # ,,
'task_manager_pidfile' => '', # ,,
'email_gecos' => 'gecos', # 6.2a.?? - 6.2a.33
'lock_method' => '', # 5.3b.3 - 6.2a.33
'html_editor_file' => 'html_editor_url', # 6.2a
'openssl' => '', # ?? - 6.2a.40
'distribution_mode' => '', # 5.0a.1 - 6.2a.40
'queuedistribute' => '', # ,,
# These are not yet implemented
'crl_dir' => '',
'dkim_header_list' => '',
);
my %trusted_applications = (
'trusted_application' => {
'occurrence' => '0-n',
......@@ -301,7 +267,12 @@ sub load_robots {
sub get_robot_conf {
my ($robot, $param) = @_;
$param = $Sympa::Config::Schema::obsolete_robot_params{$param} // $param;
# Resolve alias.
my ($k, $o) = ($param, $param);
do {
($k, $o) = ($o, ($params{$o} // {})->{obsolete});
} while ($o and $params{$o});
$param = $k;
if (defined $robot && $robot ne '*') {
if ( defined $Conf{'robots'}{$robot}
......@@ -1698,16 +1669,12 @@ sub _load_config_file_to_hash {
$value;
}
$keyword =
$Sympa::Config::Schema::obsolete_robot_params{$keyword}
// $keyword;
# Resolve renamed parameters FIXME
$keyword = {
merge_feature =>
'personalization_feature', # 6.0b.2 - 6.2.59b.1
use_blacklist => 'use_blocklist', # 5.3a.4 - 6.2.60
domains_blacklist => 'domains_blocklist', # 6.2.41b.1 - 6.2.60
}->{$keyword} // $keyword;
# Resolve alias.
my ($k, $o) = ($keyword, $keyword);
do {
($k, $o) = ($o, ($params{$o} // {})->{obsolete});
} while ($o and $params{$o});
$keyword = $k;
if (exists $params{$keyword}
and (
......@@ -1757,27 +1724,30 @@ sub _detect_unknown_parameters_in_config {
my $param = shift;
my $number_of_unknown_parameters_found = 0;
foreach my $parameter (sort keys %{$param->{'config_hash'}}) {
next if (exists $params{$parameter});
if (defined $old_params{$parameter}) {
if ($old_params{$parameter}) {
$log->syslog(
'err',
'Line %d of sympa.conf, parameter %s is no more available, read documentation for new parameter(s) %s',
$param->{'config_file_line_numbering_reference'}
{$parameter}[1],
$parameter,
$old_params{$parameter}
);
} else {
$log->syslog(
'err',
'Line %d of sympa.conf, parameter %s is now obsolete',
$param->{'config_file_line_numbering_reference'}
{$parameter}[1],
$parameter
);
next;
}
next
if exists $params{$parameter}
and not exists $params{$parameter}->{obsolete};
my $obsolete = ($params{$parameter} // {})->{obsolete} // '';
if ($obsolete =~ /^\d+$/) {
$log->syslog(
'info',
'Line %d of sympa.conf, parameter %s is now obsolete',
$param->{'config_file_line_numbering_reference'}
{$parameter}[1],
$parameter
);
next;
} elsif ($obsolete) {
$log->syslog(
'info',
'Line %d of sympa.conf, parameter %s was renamed to %s',
$param->{'config_file_line_numbering_reference'}
{$parameter}[1],
$parameter,
$params{$parameter}->{obsolete}
);
next;
} else {
$log->syslog(
'err',
......@@ -1817,11 +1787,11 @@ sub _infer_server_specific_parameter_values {
}
my @dmarc = split /[,\s]+/,
($param->{'config_hash'}{'dmarc_protection_mode'} || '');
($param->{'config_hash'}{'dmarc_protection.mode'} || '');
if (@dmarc) {
$param->{'config_hash'}{'dmarc_protection_mode'} = \@dmarc;
$param->{'config_hash'}{'dmarc_protection.mode'} = \@dmarc;
} else {
delete $param->{'config_hash'}{'dmarc_protection_mode'};
delete $param->{'config_hash'}{'dmarc_protection.mode'};
}
## Set Regexp for accepted list suffixes
......@@ -2117,11 +2087,11 @@ sub _load_single_robot_config {
}
my @dmarc = split /[,\s]+/,
($robot_conf->{'dmarc_protection_mode'} || '');
($robot_conf->{'dmarc_protection.mode'} || '');
if (@dmarc) {
$robot_conf->{'dmarc_protection_mode'} = \@dmarc;
$robot_conf->{'dmarc_protection.mode'} = \@dmarc;
} else {
delete $robot_conf->{'dmarc_protection_mode'};
delete $robot_conf->{'dmarc_protection.mode'};
}
_set_listmasters_entry({'config_hash' => $robot_conf});
......
This diff is collapsed.
......@@ -2183,6 +2183,39 @@ sub upgrade {
$log->syslog('notice', '...Done.');
}
if (lower_version($previous_version, '6.2.65b.1')) {
# Site/domain parameter "tracking" has been deprecated and
# should be renamed to "tracking.tracking" to avoid conflict with
# list config paragraph named "tracking".
_process_all_files(
'',
sub {
my $that = shift;
my $dir = shift;
my $oldfile = shift;
my $file;
if (ref $that eq 'Sympa::List') {
return;
} elsif ($that and $that ne '*') {
$file = sprintf '%s/robot.conf', $dir;
} else {
$file = Sympa::Constants::CONFIG();
}
open my $fh, '<+', $file or next;
my $text = do { local $RS; <$fh> };
$text =~ s/(\A|\n)tracking(\s|\z)/${1}tracking.tracking$2/g;
seek $fh, 0, 0;
truncate $fh, 0;
print $fh $text;
close $fh;
}
);
}
return 1;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment