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;
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>) {
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; }
@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;
}