Add IM module for talk, chat and announces
authorminima <minima>
Wed, 18 Jan 2006 23:22:36 +0000 (23:22 +0000)
committerminima <minima>
Wed, 18 Jan 2006 23:22:36 +0000 (23:22 +0000)
Add deduping for DXXml.
Add -(ve) fudge for build nos

perl/DXXml.pm
perl/DXXml/IM.pm [new file with mode: 0644]
perl/cluster.pl

index c29620bbb2cf9a239b1fdb7d86e1a3ce3091f676..c877436b7ba0b96941708accfcdb3ccc25299ee1 100644 (file)
@@ -14,10 +14,12 @@ use IsoTime;
 use DXProt;
 use DXDebug;
 use DXLog;
+use DXUtil;
 use DXXml::Ping;
 use DXXml::Dx;
+use DXXml::IM;
 
-use vars qw($VERSION $BRANCH $xs $id);
+use vars qw($VERSION $BRANCH $xs $id $max_old_age $max_future_age);
 $VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ );
 $BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/  || (0,0));
 $main::build += $VERSION;
@@ -25,6 +27,8 @@ $main::branch += $BRANCH;
 
 $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
 
 # generate a new XML sentence structure 
 sub new
@@ -82,11 +86,35 @@ sub normal
                undef $@;
                return;
        }
-       
+
+       # do some basic checks
+       my ($o, $t, $id);
+       unless (exists $xref->{o} && is_callsign($o = $xref->{o})) {
+               dbg("Invalid origin, not a callsign") if isdbg('chanerr');
+               return;
+       }
+       unless (exists $xref->{t} && ($t = IsoTime::unixtime($xref->{t}))) {
+               dbg("Invalid, non-existant or zero time") if isdbg('chanerr');
+               return;
+       }
+       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) {
+               dbg("Invalid or non-existant id") if isdbg('chanerr');
+               return;
+       }
+
        # mark the handle as accepting xml (but only if they 
        # have at least one right)
        $dxchan->handle_xml(1);
 
+       # 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");
+               
        $xref = bless $xref, $pkg;
        $xref->{'-xml'} = $line; 
        $xref->handle_input($dxchan);
diff --git a/perl/DXXml/IM.pm b/perl/DXXml/IM.pm
new file mode 100644 (file)
index 0000000..d0a1847
--- /dev/null
@@ -0,0 +1,67 @@
+#
+# XML IM handler (Chat, Announces, Talk)
+#
+# $Id$
+#
+# Copyright (c) Dirk Koopman, G1TLH
+#
+
+use strict;
+
+package DXXml::IM;
+
+use DXDebug;
+use DXProt;
+use IsoTime;
+use Investigate;
+use Time::HiRes qw(gettimeofday tv_interval);
+
+use vars qw($VERSION $BRANCH @ISA %pings);
+$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;
+
+@ISA = qw(DXXml);
+
+#
+# This is the general purpose IM sentence
+#
+# It is of the form: <chat [to=<user call>|<node call>|<chat group>] ...>the text</chat>
+#
+# This covers:
+#
+#     announce/full        (no to=)
+#     announce/local       (to="$mycall")
+#     announce/<node call> (to="<node call>")
+#     chat <group>         (to="<group>")
+#     talk <user call>     (to="<user call>")
+# 
+
+sub handle_input
+{
+       my $self = shift;
+       my $dxchan = shift;
+       
+       if ($self->{to} eq $main::mycall) {
+
+       } else {
+               $self->route($dxchan);
+       }
+}
+
+sub topcxx
+{
+       my $self = shift;
+       unless (exists $self->{'-pcxx'}) {
+               if (my $to = $self->{to}) {
+                       if (Route::Node::get($to)) {
+                               
+                       }
+               }
+               $self->{'-pcxx'} = DXProt::pc51($self->{to}, $self->{o}, $self->{s});
+       }
+       return $self->{'-pcxx'};
+}
+
+1;
index 6ed4c556c3a0588176238b7cf80dea6726c7fde7..5f5b492cb8785fa46a9a2a983927d666afd443b4 100755 (executable)
@@ -135,7 +135,7 @@ $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;
-#$main::build += 2;                            # fudge (put back for now)
+$main::build -= 1;                             # fudge (put back for now)