a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen#!/usr/bin/env perl
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainenuse strict;
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen
f2cd173a084d6aafbbcdb68fc8f8ee3da468a57dTimo Sirainenprint "/* WARNING: THIS FILE IS GENERATED - DO NOT PATCH!\n";
f2cd173a084d6aafbbcdb68fc8f8ee3da468a57dTimo Sirainenprint " It's not enough alone in any case, because the defaults may be\n";
f2cd173a084d6aafbbcdb68fc8f8ee3da468a57dTimo Sirainenprint " coming from the individual *-settings.c in some situations. If you\n";
f2cd173a084d6aafbbcdb68fc8f8ee3da468a57dTimo Sirainenprint " wish to modify defaults, change the other *-settings.c files and\n";
f2cd173a084d6aafbbcdb68fc8f8ee3da468a57dTimo Sirainenprint " just delete this file. This file will be automatically regenerated\n";
f2cd173a084d6aafbbcdb68fc8f8ee3da468a57dTimo Sirainenprint " by make. (This file is distributed in the tarball only because some\n";
f2cd173a084d6aafbbcdb68fc8f8ee3da468a57dTimo Sirainenprint " systems might not have Perl installed.) */\n";
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainenprint '#include "lib.h"'."\n";
b215a8a123623782554a83f3025ef4e771bd8f01Timo Sirainenprint '#include "array.h"'."\n";
c4fb8b3eaaa1346e3f92037aba029832a5cced9bTimo Sirainenprint '#include "ipwd.h"'."\n";
37fb6d7f94e846c2df3c388f017ffe1dcbd7b9daTimo Sirainenprint '#include "var-expand.h"'."\n";
2615df45a8027948a474abe5e817b34b0499c171Timo Sirainenprint '#include "file-lock.h"'."\n";
b780aa272b742a43579cdb523cc79cc8d4521306Timo Sirainenprint '#include "fsync-mode.h"'."\n";
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainenprint '#include "hash-format.h"'."\n";
bdd36cfdba3ff66d25570a9ff568d69e1eb543cfTimo Sirainenprint '#include "net.h"'."\n";
eb1572d7c44ebc7b0b039d085c3dbab2ef7043ddTimo Sirainenprint '#include "unichar.h"'."\n";
203bb272804e4394ae07103cdc8ce67041ba21a1Aki Tuomiprint '#include "hash-method.h"'."\n";
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainenprint '#include "settings-parser.h"'."\n";
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainenprint '#include "all-settings.h"'."\n";
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainenprint '#include <stddef.h>'."\n";
b215a8a123623782554a83f3025ef4e771bd8f01Timo Sirainenprint '#include <unistd.h>'."\n";
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainenprint '#define CONFIG_BINARY'."\n";
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainenprint 'extern buffer_t config_all_services_buf;';
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainenmy @services = ();
f9007013ea59b844e95fe32022eaf8852ba7e5a6Timo Sirainenmy @service_ifdefs = ();
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainenmy %parsers = {};
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainenforeach my $file (@ARGV) {
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen my $f;
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen open($f, $file) || die "Can't open $file: $@";
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen my $state = 0;
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen my $file_contents = "";
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen my $externs = "";
b215a8a123623782554a83f3025ef4e771bd8f01Timo Sirainen my $code = "";
b215a8a123623782554a83f3025ef4e771bd8f01Timo Sirainen my %funcs;
1cfdcb36985904eff281fc6d7ea2d13b3c375980Timo Sirainen my $cur_name = "";
f9007013ea59b844e95fe32022eaf8852ba7e5a6Timo Sirainen my $ifdef = "";
f9007013ea59b844e95fe32022eaf8852ba7e5a6Timo Sirainen my $state_ifdef = 0;
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen while (<$f>) {
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen my $write = 0;
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen if ($state == 0) {
e50a72961fca1d979afabb05e2e0e05261aac566Timo Sirainen if (/struct .*_settings \{/ ||
e50a72961fca1d979afabb05e2e0e05261aac566Timo Sirainen /struct setting_define.*\{/ ||
e50a72961fca1d979afabb05e2e0e05261aac566Timo Sirainen /struct .*_default_settings = \{/) {
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen $state++;
e50a72961fca1d979afabb05e2e0e05261aac566Timo Sirainen } elsif (/^struct service_settings (.*) = \{/) {
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen $state++;
f9007013ea59b844e95fe32022eaf8852ba7e5a6Timo Sirainen if ($ifdef eq "") {
f9007013ea59b844e95fe32022eaf8852ba7e5a6Timo Sirainen $state_ifdef = 0;
f9007013ea59b844e95fe32022eaf8852ba7e5a6Timo Sirainen } else {
f9007013ea59b844e95fe32022eaf8852ba7e5a6Timo Sirainen $_ = $ifdef."\n".$_;
f9007013ea59b844e95fe32022eaf8852ba7e5a6Timo Sirainen $state_ifdef = 1;
f9007013ea59b844e95fe32022eaf8852ba7e5a6Timo Sirainen }
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen push @services, $1;
f9007013ea59b844e95fe32022eaf8852ba7e5a6Timo Sirainen push @service_ifdefs, $ifdef;
e50a72961fca1d979afabb05e2e0e05261aac566Timo Sirainen } elsif (/^(static )?const struct setting_parser_info (.*) = \{/) {
1cfdcb36985904eff281fc6d7ea2d13b3c375980Timo Sirainen $cur_name = $2;
7744586e3e0fd60158abfbb03a233d3bd8d6c48bTimo Sirainen $state++ if ($cur_name !~ /^\*default_/);
7744586e3e0fd60158abfbb03a233d3bd8d6c48bTimo Sirainen } elsif (/^extern const struct setting_parser_info (.*);/) {
7744586e3e0fd60158abfbb03a233d3bd8d6c48bTimo Sirainen $externs .= "extern const struct setting_parser_info $1;\n";
b215a8a123623782554a83f3025ef4e771bd8f01Timo Sirainen } elsif (/\/\* <settings checks> \*\//) {
b215a8a123623782554a83f3025ef4e771bd8f01Timo Sirainen $state = 4;
b215a8a123623782554a83f3025ef4e771bd8f01Timo Sirainen $code .= $_;
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen }
f9007013ea59b844e95fe32022eaf8852ba7e5a6Timo Sirainen
f9007013ea59b844e95fe32022eaf8852ba7e5a6Timo Sirainen if (/(^#ifdef .*)$/ || /^(#if .*)$/) {
f9007013ea59b844e95fe32022eaf8852ba7e5a6Timo Sirainen $ifdef = $1;
f9007013ea59b844e95fe32022eaf8852ba7e5a6Timo Sirainen } else {
f9007013ea59b844e95fe32022eaf8852ba7e5a6Timo Sirainen $ifdef = "";
f9007013ea59b844e95fe32022eaf8852ba7e5a6Timo Sirainen }
f9007013ea59b844e95fe32022eaf8852ba7e5a6Timo Sirainen
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen if (/#define.*DEF/ || /^#undef.*DEF/ || /ARRAY_DEFINE_TYPE.*_settings/) {
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen $write = 1;
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen $state = 2 if (/\\$/);
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen }
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen } elsif ($state == 2) {
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen $write = 1;
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen $state = 0 if (!/\\$/);
b215a8a123623782554a83f3025ef4e771bd8f01Timo Sirainen } elsif ($state == 4) {
b215a8a123623782554a83f3025ef4e771bd8f01Timo Sirainen $code .= $_;
b215a8a123623782554a83f3025ef4e771bd8f01Timo Sirainen $state = 0 if (/\/\* <\/settings checks> \*\//);
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen }
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen if ($state == 1 || $state == 3) {
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen if ($state == 1) {
e4bfd63908a36efc0caf1de4219585359ea9336eTimo Sirainen if (/\.module_name = "(.*)"/) {
1cfdcb36985904eff281fc6d7ea2d13b3c375980Timo Sirainen $parsers{$cur_name} = $1;
1cfdcb36985904eff281fc6d7ea2d13b3c375980Timo Sirainen }
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen if (/DEFLIST.*".*",(.*)$/) {
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen my $value = $1;
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen if ($value =~ /.*&(.*)\)/) {
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen $parsers{$1} = 0;
7744586e3e0fd60158abfbb03a233d3bd8d6c48bTimo Sirainen $externs .= "extern const struct setting_parser_info $1;\n";
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen } else {
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen $state = 3;
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen }
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen }
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen } elsif ($state == 3) {
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen if (/.*&(.*)\)/) {
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen $parsers{$1} = 0;
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen }
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen }
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen
12ab808b472ed51923945efac4156a380bd58d57Timo Sirainen s/^static const (struct master_settings master_default_settings)/$1/;
12ab808b472ed51923945efac4156a380bd58d57Timo Sirainen
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen $write = 1;
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen if (/};/) {
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen $state = 0;
f9007013ea59b844e95fe32022eaf8852ba7e5a6Timo Sirainen if ($state_ifdef) {
f9007013ea59b844e95fe32022eaf8852ba7e5a6Timo Sirainen $_ .= "#endif\n";
f9007013ea59b844e95fe32022eaf8852ba7e5a6Timo Sirainen $state_ifdef = 0;
f9007013ea59b844e95fe32022eaf8852ba7e5a6Timo Sirainen }
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen }
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen }
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen $file_contents .= $_ if ($write);
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen }
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen print "/* $file */\n";
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen print $externs;
b215a8a123623782554a83f3025ef4e771bd8f01Timo Sirainen print $code;
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen print $file_contents;
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen close $f;
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen}
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainenprint "static struct service_settings *config_all_services[] = {\n";
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen
f9007013ea59b844e95fe32022eaf8852ba7e5a6Timo Sirainenfor (my $i = 0; $i < scalar(@services); $i++) {
f9007013ea59b844e95fe32022eaf8852ba7e5a6Timo Sirainen my $ifdef = $service_ifdefs[$i];
f9007013ea59b844e95fe32022eaf8852ba7e5a6Timo Sirainen print "$ifdef\n" if ($ifdef ne "");
9cd7d57709534174b5bc45aad3c94e7353e199d4Timo Sirainen print "\t&".$services[$i].",\n";
f9007013ea59b844e95fe32022eaf8852ba7e5a6Timo Sirainen print "#endif\n" if ($ifdef ne "");
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen}
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainenprint "};\n";
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainenprint "buffer_t config_all_services_buf = {\n";
da7f1a07f583df8905684a7b78469960afd7c78dPhil Carmodyprint "\tconfig_all_services, sizeof(config_all_services), { NULL, }\n";
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainenprint "};\n";
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen
fc4b301e2dd86c096b9c41ad1b011b752fffd570Timo Sirainenprint "const struct setting_parser_info *all_default_roots[] = {\n";
7020f569b419641e2887cf05a898947afcbb7bf1Timo Sirainenprint "\t&master_service_setting_parser_info,\n";
7020f569b419641e2887cf05a898947afcbb7bf1Timo Sirainenprint "\t&master_service_ssl_setting_parser_info,\n";
0f72f253d5a117dad2f28b2ce336190a5e6b79c8Stephan Boschprint "\t&smtp_submit_setting_parser_info,\n";
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainenforeach my $name (keys %parsers) {
1cfdcb36985904eff281fc6d7ea2d13b3c375980Timo Sirainen my $module = $parsers{$name};
1cfdcb36985904eff281fc6d7ea2d13b3c375980Timo Sirainen next if (!$module);
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen
1cfdcb36985904eff281fc6d7ea2d13b3c375980Timo Sirainen print "\t&".$name.", \n";
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen}
1cfdcb36985904eff281fc6d7ea2d13b3c375980Timo Sirainenprint "\tNULL\n";
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainenprint "};\n";
fc4b301e2dd86c096b9c41ad1b011b752fffd570Timo Sirainenprint "const struct setting_parser_info *const *all_roots = all_default_roots;\n";
12ab808b472ed51923945efac4156a380bd58d57Timo Sirainenprint "ARRAY_TYPE(service_settings) *default_services = &master_default_settings.services;\n";