X-Git-Url: http://dxcluster.org/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FDXXml.pm;h=a9072d467d4fcc3ea8e3ea150be2174c3cd749af;hb=bc67e4afa9b3c9fcf0e537e04a743ad5852356e6;hp=c877436b7ba0b96941708accfcdb3ccc25299ee1;hpb=fd20f44c57b732d5362a5ee9b9edb25c958cf71c;p=spider.git diff --git a/perl/DXXml.pm b/perl/DXXml.pm index c877436b..a9072d46 100644 --- a/perl/DXXml.pm +++ b/perl/DXXml.pm @@ -18,8 +18,10 @@ use DXUtil; use DXXml::Ping; use DXXml::Dx; use DXXml::IM; +use DXXml::Text; +use DXXml::Cmd; -use vars qw($VERSION $BRANCH $xs $id $max_old_age $max_future_age); +use vars qw($VERSION $BRANCH $xs $id $max_old_age $max_future_age $dupeage); $VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ ); $BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/ || (0,0)); $main::build += $VERSION; @@ -29,13 +31,21 @@ $xs = undef; # the XML::Simple parser instance $id = 0; # the next ID to be used $max_old_age = 3600; # how old a sentence we will accept $max_future_age = 900; # how far into the future we will accept +$dupeage = 12*60*60; # duplicates stored half a day + # generate a new XML sentence structure sub new { my $pkg = shift; my $class = ref $pkg || $pkg; - return bless{@_}, $class; + my $self = bless{@_}, $class; + while (@_) { + my $key = shift; + my $val = shift; + $self->{$key} = $val if defined $val; + } + return $self; } # @@ -97,11 +107,11 @@ sub normal dbg("Invalid, non-existant or zero time") if isdbg('chanerr'); return; } - unless ($t < $main::systime - $max_old_age || $t > $main::systime + $max_future_age) { + unless ($t > $main::systime - $max_old_age && $t < $main::systime + $max_future_age) { dbg("Too old or too far in the future") if isdbg('chanerr'); return; } - unless (exists $xref->{id} && ($id = $xref->{id}) >= 0 && $id <= 9999) { + unless (exists $xref->{id} && ($id = $xref->{id}) >= 0 && $id <= 999) { dbg("Invalid or non-existant id") if isdbg('chanerr'); return; } @@ -113,7 +123,7 @@ sub normal # now check that we have not seen this before # this is based on the tuple (o (origin), t (time, normalised to time_t), id) $xref->{'-timet'} = $t; - return if DXDupe::check("xml,$o,$t,$id"); + return if DXDupe::check("xml,$o,$t,$id", $dupeage); $xref = bless $xref, $pkg; $xref->{'-xml'} = $line; @@ -188,7 +198,7 @@ sub toxml unless (exists $self->{'-xml'}) { $self->{o} ||= $main::mycall; - $self->{t} ||= IsoTime::dayminsec(); + $self->{t} ||= IsoTime::hourminsec(); $self->{id} ||= nextid(); my ($name) = (ref $self) =~ /::(\w+)$/; @@ -202,7 +212,13 @@ sub route my $self = shift; my $fromdxchan = shift; my $to = shift; - my $via = $to || $self->{'-via'} || $self->{to}; + my $via = $to; + my $dxchan; + + if (my $u = $self->{u}) { + $via ||= $u if ($dxchan = DXChannel::get($u)); + } + $via ||= $self->{'-via'} || $self->{to}; unless ($via) { dbg("XML: no route specified (" . $self->toxml . ")") if isdbg('chanerr'); @@ -214,7 +230,7 @@ sub route } # always send it down the local interface if available - my $dxchan = DXChannel::get($via); + $dxchan ||= DXChannel::get($via); if ($dxchan) { dbg("route: $via -> $dxchan->{call} direct" ) if isdbg('route'); } else { @@ -247,13 +263,30 @@ sub route return; } + $self->{o} ||= $main::mycall; + $self->{id} ||= nextid(); + $self->{'-timet'} ||= $main::systime; + if ($dxchan->handle_xml) { $dxchan->send($self->toxml); + } elsif ($dxchan->isnode) { + my $ref = $self->topcxx($dxchan); + if (ref $ref) { + for (@$ref) { + $dxchan->send($_); + } + } else { + $dxchan->send($ref); + } } else { - $self->{o} ||= $main::mycall; - $self->{id} ||= nextid(); - $self->{'-timet'} ||= $main::systime; - $dxchan->send($self->topcxx); + my $ref = $self->tocmd($dxchan); + if (ref $ref) { + for (@$ref) { + $dxchan->send($_); + } + } else { + $dxchan->send($ref); + } } }