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+)/ );
-$BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/ || (0,0));
-$main::build += $VERSION;
-$main::branch += $BRANCH;
-
+use vars qw($xs $id $max_old_age $max_future_age $dupeage);
$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
{
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;
}
#
eval { require XML::Parser } unless $@;
if ($@) {
LogDbg('err', "do_xml was set to 1 and the XML routines failed to load ($@)");
- $main::do_xml = 0;
+ $main::do_xml = $xs = 0;
} else {
$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 $@;
}
+# is XML avaiable and active
+sub available
+{
+ return $main::do_xml && $xs;
+}
+
#
# note that this a function not a method
#
my $dxchan = shift;
my $line = shift;
- unless ($main::do_xml) {
+ unless (available()) {
dbg("xml not enabled, IGNORED") if isdbg('chanerr');
return;
}
$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);
}
#
DXXml::Ping::add($main::me, $dxchan->call);
$dxchan->{nopings} -= 1;
$dxchan->{lastping} = $t;
- $dxchan->{lastping} += $dxchan->{pingint} / 2 unless @{$dxchan->{pingtime}};
}
}
}
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} && $self->{to} eq $main::mycall) {
+ $via ||= $u if ($dxchan = DXChannel::get($u));
+ }
+ $via ||= $self->{'-via'} || $self->{to};
unless ($via) {
- dbg("XML: no route specified (" . $self->toxml . ")") if isdbg('chanerr');
+ dbg("XML: no route specified (" . dd($self) . ")") if isdbg('chanerr');
return;
}
if (ref $fromdxchan && $via && $fromdxchan->call eq $via) {
- dbg("XML: Trying to route back to source (" . $self->toxml . ")") if isdbg('chanerr');
+ dbg("XML: Trying to route back to source (" . dd($self) . ")") if isdbg('chanerr');
return;
}
# 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 {
}
if ($fromdxchan->call eq $via) {
- dbg("XML: Trying to route back to source (" . $self->toxml . ")") if isdbg('chanerr');
+ dbg("XML: Trying to route back to source (" . dd($self) . ")") if isdbg('chanerr');
return;
}
if ($dxchan == $main::me) {
- dbg("XML: Trying to route to me (" . $self->toxml . ")") if isdbg('chanerr');
+ dbg("XML: Trying to route to me (" . dd($self) . ")") if isdbg('chanerr');
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);
+ $dxchan->send($ref);
} else {
- $self->{o} ||= $main::mycall;
- $self->{id} ||= nextid();
- $self->{'-timet'} ||= $main::systime;
- $dxchan->send($self->topcxx);
+ my $ref = $self->tocmd($dxchan);
+ $dxchan->send($ref);
}
}