a08cbda0ded9623ec17ac12095956f786a61e868
[spider.git] / perl / DXXml / Text.pm
1 #
2 # XML Text handler
3 #
4 # $Id$
5 #
6 # Copyright (c) Dirk Koopman, G1TLH
7 #
8
9 use strict;
10
11 package DXXml::Text;
12
13 use DXDebug;
14 use DXProt;
15 use IsoTime;
16 use Investigate;
17 use Time::HiRes qw(gettimeofday tv_interval);
18
19 use vars qw($VERSION $BRANCH @ISA %pings);
20 $VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ );
21 $BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/  || (0,0));
22 $main::build += $VERSION;
23 $main::branch += $BRANCH;
24
25 @ISA = qw(DXXml);
26
27 sub handle_input
28 {
29         my $self = shift;
30         my $dxchan = shift;
31
32         if ($self->{to} eq $main::mycall) {
33                 my $tochan = DXChannel::get($self->{u} || $main::myalias);
34                 if ($tochan) {
35                         my $ref = $self->tocmd;
36                         $tochan->send($_) for (ref $ref ? @$ref : $ref);
37                 } else {
38                         dbg("no user or $main::myalias not online") if isdbg('chanerr');
39                 }
40         } else {        
41                 $self->route($dxchan);
42         }
43 }
44
45 sub topcxx
46 {
47         my $self = shift;
48         my $dxchan = shift;
49         my @out;
50
51         my $ref = DXUser->get_current($self->{to});
52         while (@_) {
53                 my $line = shift;
54                 $line =~ s/\s*$//;
55                 Log('rcmd', 'out', $self->{to}, $line);
56                 if ($self->{u} && $dxchan->is_clx && $ref->is_clx) {
57                         push @out, pc85($main::mycall, $self->{to}, $self->{u}, "$main::mycall:$line");
58                 } else {
59                         push @out, pc35($main::mycall, $self->{to}, "$main::mycall:$line");
60                 }
61         }
62
63         return $self->{'-pcxx'} = \@out;
64 }
65
66 sub tocmd
67 {
68         my $self = shift;
69
70         my @out = split /(?:%0D)?\%0A/, $self->{content};
71         return $self->{-cmd} = \@out;
72 }
73
74 1;