r24637 - in /scripts/KGB: debian/changelog server/KGB
tincho at users.alioth.debian.org
tincho at users.alioth.debian.org
Wed Aug 27 00:51:26 UTC 2008
Author: tincho
Date: Wed Aug 27 00:51:23 2008
New Revision: 24637
URL: http://svn.debian.org/wsvn/?sc=1&rev=24637
Log:
server/KGB: move configuration reading and verification to a subroutine,
for future support of config reloading.
Modified:
scripts/KGB/debian/changelog
scripts/KGB/server/KGB
Modified: scripts/KGB/debian/changelog
URL: http://svn.debian.org/wsvn/scripts/KGB/debian/changelog?rev=24637&op=diff
==============================================================================
--- scripts/KGB/debian/changelog (original)
+++ scripts/KGB/debian/changelog Wed Aug 27 00:51:23 2008
@@ -1,5 +1,10 @@
kgb-bot (0.02) UNRELEASED; urgency=low
+ [ Damyan Ivanov ]
* Initial release. (Closes: #XXXXXX)
+ [ MartÃn Ferrari ]
+ * server/KGB: move configuration reading and verification to a subroutine,
+ for future support of config reloading.
+
-- Damyan Ivanov <dmn at debian.org> Mon, 28 Jul 2008 14:44:04 +0300
Modified: scripts/KGB/server/KGB
URL: http://svn.debian.org/wsvn/scripts/KGB/server/KGB?rev=24637&op=diff
==============================================================================
--- scripts/KGB/server/KGB (original)
+++ scripts/KGB/server/KGB Wed Aug 27 00:51:23 2008
@@ -54,6 +54,8 @@
use Digest::SHA1 qw(sha1_hex);
use Proc::PID::File;
+sub read_conf ($);
+
my $conf_file = '/etc/kgb/kgb.conf';
GetOptions(
'config=s' => \$conf_file,
@@ -61,51 +63,7 @@
@ARGV and die "No command line arguments supported\n";
-my $conf = YAML::LoadFile($conf_file) or die "Error loading config from $conf_file\n";
-
-die "Invalid config key: soap" unless(ref $conf->{soap}
- and ref $conf->{soap} eq "HASH");
-die "Invalid config key: repositories" unless(ref $conf->{repositories}
- and ref $conf->{repositories} eq "HASH");
-die "Invalid config key: networks" unless(ref $conf->{networks}
- and ref $conf->{networks} eq "HASH");
-die "Invalid config key: channels" unless(ref $conf->{channels}
- and ref $conf->{channels} eq "ARRAY");
-
-$conf->{soap}{service_name} ||= "KGB";
-$conf->{soap}{server_port} ||= 9999;
-$conf->{soap}{server_addr} ||= "127.0.0.1";
-$conf->{min_protocol_ver} ||= 1;
-
-$conf->{min_protocol_ver} =~ /^[01]$/
- or die "Unrecognised min_protocol_ver (".$conf->{min_protocol_ver}."). I only know about protocol 0 and 1.\n";
-
-foreach(keys %{$conf->{networks}}) {
- $conf->{networks}{$_}{nick} ||= "KGB";
- $conf->{networks}{$_}{ircname} ||= "KGB bot";
- $conf->{networks}{$_}{username} ||= "kgb";
- $conf->{networks}{$_}{port} ||= 6667;
- die "Missing server name in network $_\n" unless(
- $conf->{networks}{$_}{server});
-}
-foreach(@{$conf->{channels}}) {
- die "Missing channel name at channel\n" unless($_->{name});
- die "Invalid network at channel ".$_->{name}."\n" unless($_->{network}
- and $conf->{networks}{$_->{network}});
- push @{$conf->{networks}{$_->{network}}{channels}}, $_->{name};
- die "Invalid repos key at channel ".$_->{name}."\n" unless(ref $_->{repos}
- and ref $_->{repos} eq "ARRAY");
- warn "Channel ".$_->{name}." doesn't listen on any repository\n" unless(
- @{$_->{repos}});
- foreach my $repo (@{$_->{repos}}) {
- die "Invalid repository $repo at channel ".$_->{name}."\n" unless(
- $conf->{repositories}{$repo});
- push @{$conf->{repositories}{$repo}{channels}}, $_->{name};
- }
-}
-my %chanidx = map ({ $conf->{channels}[$_]{name} => $conf->{channels}[$_] }
- 0..$#{$conf->{channels}});
-$conf->{chanidx} = \%chanidx;
+my $conf = read_conf($conf_file);
die "Already running\n"
if Proc::PID::File->running(
@@ -149,6 +107,58 @@
$poe_kernel->run;
exit 0;
+
+sub read_conf ($) {
+ my $file = shift;
+
+ my $conf = YAML::LoadFile($file) or die "Error loading config from $conf_file\n";
+
+ die "Invalid or missing config key: soap" unless(ref $conf->{soap}
+ and ref $conf->{soap} eq "HASH");
+ die "Invalid or missing config key: repositories" unless(ref
+ $conf->{repositories} and ref $conf->{repositories} eq "HASH");
+ die "Invalid or missing config key: networks" unless(ref $conf->{networks}
+ and ref $conf->{networks} eq "HASH");
+ die "Invalid or missing config key: channels" unless(ref $conf->{channels}
+ and ref $conf->{channels} eq "ARRAY");
+
+ $conf->{soap}{service_name} ||= "KGB";
+ $conf->{soap}{server_port} ||= 9999;
+ $conf->{soap}{server_addr} ||= "127.0.0.1";
+ $conf->{min_protocol_ver} ||= 1;
+
+ $conf->{min_protocol_ver} =~ /^[01]$/
+ or die "Unrecognised min_protocol_ver (".$conf->{min_protocol_ver}."). I only know about protocol 0 and 1.\n";
+
+ foreach(keys %{$conf->{networks}}) {
+ $conf->{networks}{$_}{nick} ||= "KGB";
+ $conf->{networks}{$_}{ircname} ||= "KGB bot";
+ $conf->{networks}{$_}{username} ||= "kgb";
+ $conf->{networks}{$_}{port} ||= 6667;
+ die "Missing server name in network $_\n" unless(
+ $conf->{networks}{$_}{server});
+ }
+
+ foreach(@{$conf->{channels}}) {
+ die "Missing channel name at channel\n" unless($_->{name});
+ die "Invalid network at channel ".$_->{name}."\n" unless($_->{network}
+ and $conf->{networks}{$_->{network}});
+ push @{$conf->{networks}{$_->{network}}{channels}}, $_->{name};
+ die "Invalid repos key at channel ".$_->{name}."\n" unless(ref $_->{repos}
+ and ref $_->{repos} eq "ARRAY");
+ warn "Channel ".$_->{name}." doesn't listen on any repository\n" unless(
+ @{$_->{repos}});
+ foreach my $repo (@{$_->{repos}}) {
+ die "Invalid repository $repo at channel ".$_->{name}."\n" unless(
+ $conf->{repositories}{$repo});
+ push @{$conf->{repositories}{$repo}{channels}}, $_->{name};
+ }
+ }
+ my %chanidx = map ({ $conf->{channels}[$_]{name} => $conf->{channels}[$_] }
+ 0..$#{$conf->{channels}});
+ $conf->{chanidx} = \%chanidx;
+ return $conf;
+}
sub setup_service {
my $kernel = $_[KERNEL];
More information about the Pkg-perl-cvs-commits
mailing list