X-Git-Url: http://dxcluster.net/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FDXXml.pm;h=2d83e16bb61e0d6f4a16c1f86b785b48c9be59cb;hb=aff34665f8f175d135270f9e49c110bcce90e7b8;hp=c40e3be041ff91c9f468dae81eae238e63b38aba;hpb=082d020e6964f4b822d287980740bc3d787f3685;p=spider.git diff --git a/perl/DXXml.pm b/perl/DXXml.pm index c40e3be0..2d83e16b 100644 --- a/perl/DXXml.pm +++ b/perl/DXXml.pm @@ -18,6 +18,8 @@ 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 $dupeage); $VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ ); @@ -37,7 +39,13 @@ 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; } # @@ -56,7 +64,7 @@ sub init $XML::Simple::PREFERRED_PARSER = 'XML::Parser'; import XML::Simple; $DXProt::handle_xml = 1; - $xs = new XML::Simple(Cache=>[]); + $xs = new XML::Simple(ContentKey=>'content', ForceArray=>1); } undef $@; } @@ -117,9 +125,9 @@ sub normal $xref->{'-timet'} = $t; return if DXDupe::check("xml,$o,$t,$id", $dupeage); - $xref = bless $xref, $pkg; - $xref->{'-xml'} = $line; - $xref->handle_input($dxchan); + my $r = bless $xref, $pkg; + $r->{'-xml'} = $line; + $r->handle_input($dxchan); } # @@ -190,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+)$/; @@ -204,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'); @@ -216,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 { @@ -249,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->is_node) { + 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); + } } }