X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/profile/blobdiff_plain/33edf1fb89d0b4ef7493d3753a2ed12568c46d90..be626dd5fa368d4adb39458af61a877e100e5b4e:/pl/DisOrder.pm diff --git a/pl/DisOrder.pm b/pl/DisOrder.pm index 5f72131..ab609b3 100644 --- a/pl/DisOrder.pm +++ b/pl/DisOrder.pm @@ -10,7 +10,7 @@ use Socket qw{:DEFAULT :addrinfo}; our @EXPORT_OK = qw{get_response0 decode_response get_response send_command0 send_command split_fields - connect_to_server}; + load_config connect_to_server}; use Data::Dumper; @@ -102,10 +102,9 @@ sub split_fields ($) { return @f; } -sub connect_to_server ($;$) { - my ($conf, $quietp) = @_; +sub load_config ($) { + my ($conf) = @_; my %conf = (connect => ["-unix", "/var/lib/disorder/socket"]); - my @f; open my $fh, "<", $conf; LINE: while (<$fh>) { @@ -117,9 +116,15 @@ sub connect_to_server ($;$) { close $fh; for my $i (qw{ username password }) { die "missing configuration keyword `$i'" unless exists $conf{$i}; } + return \%conf; +} + +sub connect_to_server (\%;$) { + my ($conf, $quietp) = @_; + my @f; my $af = AF_UNSPEC; - my @a = $conf{connect}->@*; + my @a = $conf->{connect}->@*; die "empty address" unless @a; if ($a[0] eq "-unix") { $af = AF_UNIX; shift @a; } elsif ($a[0] eq "-4") { $af = AF_INET; shift @a; } @@ -175,9 +180,9 @@ sub connect_to_server ($;$) { @f = split_fields get_response $sk; die "expected version 2" unless $f[0] eq "2"; my $h = Digest::SHA->new($f[1]); - $h->add($conf{password}[0], pack "H*", $f[2]); + $h->add($conf->{password}[0], pack "H*", $f[2]); my $d = $h->hexdigest; - send_command $sk, "user", $conf{username}[0], $d; + send_command $sk, "user", $conf->{username}[0], $d; return $sk; }