my $f;
foreach $f (values %DXDb::avail) {
- push @out, "DB Name Location" unless @out;
- push @out, sprintf "%-15s %-s", $f->name, $f->remote ? $f->remote : "Local";
+ push @out, "DB Name Location Chain" unless @out;
+ push @out, sprintf "%-15s %-10s %s", $f->name, $f->remote ? $f->remote : "Local", $f->chain ? parray($f->chain) : "";
}
return (1, @out);
# Copyright (c) 1999 Dirk Koopman G1TLH
#
my ($self, $line) = @_;
-my ($name, $remote) = split /\s+/, $line;
+my @f = split /\s+/, $line;
+my $name = shift @f if @f;
my @out;
return (1, $self->msg('e5')) if $self->priv < 9;
-
return (1, $self->msg('db6', $name)) if DXDb::getdesc($name);
-DXDb::new($name, $remote);
+
+my $remote;
+my $chain;
+while (@f) {
+ my $f = lc shift @f;
+ if ($f eq 'remote') {
+ $remote = uc shift @f if @f;
+ next;
+ }
+ if ($f eq 'chain') {
+ if (@f) {
+ $chain = [ @f ];
+ last;
+ }
+ }
+}
+DXDb::new($name, $remote, $chain);
push @out, $self->msg($remote ? 'db7' : 'db8', $name, $remote);
return (1, @out);
my $db = DXDb::getdesc($name);
return (1, $self->msg('db3', $name)) unless $db;
-if ($db->remote) {
- push @out, $self->msg('db11', $db->remote);
- for (@f) {
- my $n = DXDb::newstream($self->call);
- DXProt::route(undef, $db->remote, DXProt::pc44($main::mycall, $db->remote, $n, uc $db->name,uc $_, $self->call));
- }
-} else {
- for (@f) {
- my $value = $db->getkey($_);
- if ($value) {
- push @out, split /\n/, $value;
- } else {
- push @out, $self->msg('db2', $_, $db->{name});
+my @db;
+push @db, $name;
+push @db, @{$db->chain} if $db->chain;
+
+my $n;
+foreach $n (@db) {
+ $db = DXDb::getdesc($n);
+ return (1, $self->msg('db3', $n)) unless $db;
+
+ if ($db->remote) {
+
+ # remote databases
+ unless (DXCluster->get_exact($db->remote) || DXChannel->get($db->remote)) {
+ push @out, $self->msg('db4', uc $name, $db->remote);
+ last;
+ }
+
+ push @out, $self->msg('db11', $db->remote);
+ for (@f) {
+ my $n = DXDb::newstream($self->call);
+ DXProt::route(undef, $db->remote, DXProt::pc44($main::mycall, $db->remote, $n, uc $db->name,uc $_, $self->call));
+ }
+ last;
+ } else {
+
+ # local databases can chain to remote ones
+ my $count;
+ push @out, $db->print('pre');
+ push @out, "@f";
+ for (@f) {
+ push @out, $db->name . " $_";
+ my $value = $db->getkey($_);
+ push @out, $db->name . ": $_ : $value";
+ if ($value) {
+ push @out, split /\n/, $value;
+ $count++;
+ } else {
+ push @out, $self->msg('db2', uc $_, uc $db->{name});
+ }
+ }
+ if ($count) {
+ push @out, $db->print('post');
+ last;
}
}
}
$self->send($self->msg('page', scalar @ans));
} else {
for (@ans) {
- s/\s+$//o; # why ?????????
- $self->send($_);
+ $self->send($_) if $_;
}
}
}
name => '0,Name',
db => '9,DB Tied hash',
remote => '0,Remote Database',
+ pre => '0,Heading text',
+ post => '0,Tail text',
+ chain => '0,Search these,parray',
+ disable => '0,Disabled?,yesno',
+ nf => '0,Not Found text',
+ cal => '0,No Key text',
+ allowread => '9,Allowed to read,parray',
+ denyread => '9,Deny to read,parray',
+ allowupd => '9,Allow to update,parray',
+ denyupd => '9,Deny to update,parray',
+ fwdupd => '9,Forward updates to,parray',
+ template => '9,Upd Templates,parray',
+ help => '0,Help txt,parray',
);
$lastprocesstime = time;
# save all the database descriptors
sub save
{
- my $date = cldatetime($main::systime);
-
- writefilestr($dbbase, "dbs", "pl", \%avail, "#\n# database descriptor file\n# Don't alter this by hand unless you know what you are doing\n# last modified $date\n#\n");
+ closeall();
+ writefilestr($dbbase, "dbs", "pl", \%avail);
}
# get the descriptor of the database you want.
{
my $self = shift;
if ($self->{db}) {
- untie $self->{db};
+ undef $self->{db};
+ delete $self->{db};
}
}
my $self = bless {};
my $name = shift;
my $remote = shift;
+ my $chain = shift;
$self->{name} = lc $name;
$self->{remote} = uc $remote if $remote;
+ $self->{chain} = $chain if $chain && ref $chain;
$self->{accesst} = $self->{createt} = $self->{lastt} = $main::systime;
$avail{$self->{name}} = $self;
mkdir $dbbase, 02775 unless -e $dbbase;
$dxchan->send(DXProt::pc46($main::mycall, $tonode, $stream));
}
+# print a value from the db reference
+sub print
+{
+ my $self = shift;
+ my $s = shift;
+ return $self->{$s} ? $self->{$s} : undef;
+}
+
# various access routines
#
}
my $fh = new IO::File ">$fn";
- my $dd = new Data::Dumper([ $obj ]);
- $dd->Indent(1);
- $dd->Terse(1);
- $dd->Quotekeys(0);
-# $fh->print(@_) if @_ > 0; # any header comments, lines etc
- $fh->print($dd->Dumpxs);
- $fh->close;
+ if ($fh) {
+ my $dd = new Data::Dumper([ $obj ]);
+ $dd->Indent(1);
+ $dd->Terse(1);
+ $dd->Quotekeys(0);
+ # $fh->print(@_) if @_ > 0; # any header comments, lines etc
+ $fh->print($dd->Dumpxs);
+ $fh->close;
+ }
}
disc1 => 'Disconnected by $_[0]',
disc2 => '$_[0] disconnected',
db1 => 'This database is hosted at $_[0]',
- db2 => 'Key: $_[0] not found in $_[1]',
+ db2 => 'Sorry, but key: $_[0] was not found in $_[1]',
db3 => 'Sorry, database $_[0] doesn\'t exist here',
db4 => 'Sorry, database $_[0] located at $_[1] isn\'t currently online',
db5 => 'Accessing remote database on $_[0]...standby...',
};
dbg('local', "Local::finish error $@") if $@;
- # close all databases
- DXDb::closeall;
-
# disconnect users
foreach $dxchan (DXChannel->get_all()) {
next if $dxchan->is_ak1a;
Msg->event_loop(1, 0.05);
Msg->event_loop(1, 0.05);
DXUser::finish();
+
+ # close all databases
+ DXDb::closeall;
+
dbg('chan', "DXSpider version $version ended");
Log('cluster', "DXSpider V$version stopped");
dbgclose();