56b96faa126d91d1b3256d7bba8944dfc453402b
[spider.git] / perl / DXChannel.pm
1 #
2 # module to manage channel lists & data
3 #
4 # This is the base class for all channel operations, which is everything to do 
5 # with input and output really.
6 #
7 # The instance variable in the outside world will be generally be called $dxchan
8 #
9 # This class is 'inherited' (if that is the goobledegook for what I am doing)
10 # by various other modules. The point to understand is that the 'instance variable'
11 # is in fact what normal people would call the state vector and all useful info
12 # about a connection goes in there.
13 #
14 # Another point to note is that a vector may contain a list of other vectors. 
15 # I have simply added another variable to the vector for 'simplicity' (or laziness
16 # as it is more commonly called)
17 #
18 # PLEASE NOTE - I am a C programmer using this as a method of learning perl
19 # firstly and OO about ninthly (if you don't like the design and you can't 
20 # improve it with better OO and thus make it smaller and more efficient, then tough). 
21 #
22 # Copyright (c) 1998-2016 - Dirk Koopman G1TLH
23 #
24 #
25 #
26 package DXChannel;
27
28 use Msg;
29 use DXM;
30 use DXUtil;
31 use DXVars;
32 use DXDebug;
33 use Filter;
34 use Prefix;
35 use Route;
36
37 use strict;
38 use vars qw(%channels %valid @ISA $count $maxerrors);
39
40 %channels = ();
41 $count = 0;
42
43 %valid = (
44                   'sort' => '5,Type of Channel',
45                   ann => '0,Want Announce,yesno',
46                   ann_talk => '0,Suppress Talk Anns,yesno',
47                   annfilter => '5,Ann Filt-out',
48                   badcount => '1,Bad Word Count',
49                   badip => '9,BAD IP address',
50                   beep => '0,Want Beeps,yesno',
51                   build => '1,Node Build',
52                   call => '0,Callsign',
53                   cluster => '5,Cluster data',
54                   conf => '0,In Conference?,yesno',
55                   conn => '9,Msg Conn ref',
56                   consort => '5,Connection Type',
57                   cq => '0,CQ Zone',
58                   delayed => '5,Delayed messages,parray',
59                   disconnecting => '9,Disconnecting,yesno',
60                   do_pc9x => '9,Handles PC9x,yesno',
61                   dx => '0,DX Spots,yesno',
62                   dxcc => '0,Country Code',
63                   edit => '7,Edit Function',
64                   enhanced => '5,Enhanced Client,yesno',
65                   errors => '9,Errors',
66                   func => '5,Function',
67                   group => '0,Access Group,parray',     # used to create a group of users/nodes for some purpose or other.
68                   gtk => '5,Using GTK,yesno',
69                   handle_xml => '9,Handles XML,yesno',
70                   here => '0,Here?,yesno',
71                   hostname => '0,Hostname',
72                   inannfilter => '5,Ann Filt-inp',
73                   inpc92filter => '5,PC92 Route Filt-inp',
74                   inqueue => '9,Input Queue,parray',
75                   inrbnfilter => '5,RBN Filt-inp',
76                   inroutefilter => '5,Route Filt-inp',
77                   inscript => '9,In a script,yesno',
78                   inspotsfilter => '5,Spot Filt-inp',
79                   inwcyfilter => '5,WCY Filt-inp',
80                   inwwvfilter => '5,WWV Filt-inp',
81                   isbasic => '9,Internal Connection', 
82                   isolate => '5,Isolate network,yesno',
83                   isslugged => '9,Still Slugged,yesno',
84                   itu => '0,ITU Zone',
85                   K => '9,Seen on PC92 K,yesno',
86                   lang => '0,Language',
87                   lastmsgpoll => '0,Last Msg Poll,atime',
88                   lastping => '5,Ping last sent,atime',
89                   lastread => '5,Last Msg Read',
90                   list => '9,Dep Chan List',
91                   loc => '9,Local Vars', # used by func to store local variables in
92                   logininfo => '9,Login info req,yesno',
93                   metric => '1,Route metric',
94                   name => '0,User Name',
95                   newroute => '1,New Style Routing,yesno',
96                   next_pc92_keepalive => '9,Next PC92 KeepAlive,atime',
97                   next_pc92_update => '9,Next PC92 Update,atime',
98                   nopings => '5,Ping Obs Count',
99                   oldstate => '5,Last State',
100                   outbound => '5,outbound?,yesno',
101                   pagedata => '9,Page Data Store',
102                   pagelth => '0,Page Length',
103                   passwd => '9,Passwd List,yesno',
104                   pc50_t => '5,Last PC50 Time,atime',
105                   pc92filter => '5,PC92 Route Filt-out',
106                   pingave => '0,Ping ave time',
107                   pingint => '5,Ping Interval ',
108                   pingtime => '5,Ping totaltime,parray',
109                   priv => '9,Privilege',
110                   prompt => '0,Required Prompt',
111                   rbnfilter => '5,RBN Filt-out',
112                   rbnseeme => '0,RBN See Me,yesno',
113                   redirect => '0,Redirect messages to',
114                   registered => '9,Registered?,yesno',
115                   remotecmd => '9,doing rcmd,yesno',
116                   route => '9,Route Data',
117                   routefilter => '5,Route Filt-out',
118                   senddbg => '8,Sending Debug,yesno',
119                   sluggedpcs => '9,Slugged PCxx Queue,parray',
120                   spotsfilter => '5,Spot Filt-out',
121                   startt => '0,Start Time,atime',
122                   state => '0,Current State',
123                   t => '9,Time,atime',
124                   talk => '0,Want Talk,yesno',
125                   talklist => '0,Talk List,parray',
126                   user => '9,DXUser ref',
127                   ve7cc => '0,VE7CC program special,yesno',
128                   verified => '9,Verified?,yesno',
129                   version => '1,Node Version',
130                   wcy => '0,Want WCY,yesno',
131                   wcyfilter => '5,WCY Filt-out',
132                   width => '0,Column Width',
133                   wwv => '0,Want WWV,yesno',
134                   wwvfilter => '5,WWV Filt-out',
135                   wx => '0,Want WX,yesno',                
136                  );
137
138 $maxerrors = 20;                                # the maximum number of concurrent errors allowed before disconnection
139
140 # object destruction
141 sub DESTROY
142 {
143         my $self = shift;
144         for (keys %$self) {
145                 if (ref($self->{$_})) {
146                         delete $self->{$_};
147                 }
148         }
149         dbg("DXChannel $self->{call} destroyed ($count)") if isdbg('chan');
150         $count--;
151 }
152
153 # create a new channel object [$obj = DXChannel->new($call, $msg_conn_obj, $user_obj)]
154 sub alloc
155 {
156         my ($pkg, $call, $conn, $user) = @_;
157         my $self = {};
158   
159         die "trying to create a duplicate channel for $call" if $channels{$call};
160         $self->{call} = $call;
161         $self->{priv} = 0;
162         $self->{conn} = $conn if defined $conn; # if this isn't defined then it must be a list
163         if (defined $user) {
164                 $self->{user} = $user;
165                 $self->{lang} = $user->lang;
166                 $user->new_group unless $user->group;
167                 $user->new_buddies unless $user->buddies;
168                 $self->{group} = $user->group;
169                 $self->{sort} = $user->sort;
170                 $self->{width} = $user->width;
171         }
172         $self->{startt} = $self->{t} = $main::systime;
173         $self->{state} = 0;
174         $self->{oldstate} = 0;
175         $self->{lang} = $main::lang if !$self->{lang};
176         $self->{func} = "";
177         $self->{width} ||=  80;
178
179         # add in all the dxcc, itu, zone info
180         my @dxcc = Prefix::extract($call);
181         if (@dxcc > 0) {
182                 $self->{dxcc} = $dxcc[1]->dxcc;
183                 $self->{itu} = $dxcc[1]->itu;
184                 $self->{cq} = $dxcc[1]->cq;
185         }
186         $self->{inqueue} = [];
187
188         $self->{hostname} = $self->{conn}->peerhost if $conn;
189
190         $count++;
191         dbg("DXChannel $self->{call} created ($count)") if isdbg('chan');
192         bless $self, $pkg; 
193         return $channels{$call} = $self;
194 }
195
196 # count errors and disconnect if too many
197 # this has to be here because it can come from rcmd (DXProt) as
198 # well as DXCommandmode.
199 sub _error_out
200 {
201         my $self = shift;
202         my $e = shift;
203         if (++$self->{errors} > $maxerrors) {
204                 $self->send($self->msg('e26'));
205                 $self->disconnect;
206                 return ();
207         } else {
208                 return ($self->msg($e));
209         }
210 }
211
212 # rebless this channel as something else
213 sub rebless
214 {
215         my $self = shift;
216         my $class = shift;
217         return $channels{$self->{call}} = bless $self, $class;
218 }
219
220 sub rec 
221 {
222         my ($self, $msg) = @_;
223         
224         # queue the message and the channel object for later processing
225         if (defined $msg) {
226                 push @{$self->{inqueue}}, $msg;
227         }
228         $self->process_one;
229 }
230
231 # obtain a channel object by callsign [$obj = DXChannel::get($call)]
232 sub get
233 {
234         my $call = shift;
235         return $channels{$call};
236 }
237
238 # obtain all the channel objects
239 sub get_all
240 {
241         return values(%channels);
242 }
243
244 #
245 # gimme all the ak1a nodes
246 #
247 sub get_all_nodes
248 {
249         my $ref;
250         my @out;
251         foreach $ref (values %channels) {
252                 push @out, $ref if $ref->is_node;
253         }
254         return @out;
255 }
256
257 # return a list of node calls
258 sub get_all_node_calls
259 {
260         my $ref;
261         my @out;
262         foreach $ref (values %channels) {
263                 push @out, $ref->{call} if $ref->is_node;
264         }
265         return @out;
266 }
267
268 # return a list of all users
269 sub get_all_users
270 {
271         my $ref;
272         my @out;
273         foreach $ref (values %channels) {
274                 push @out, $ref if $ref->is_user;
275         }
276         return @out;
277 }
278
279 # return a list of all user callsigns
280 sub get_all_user_calls
281 {
282         my $ref;
283         my @out;
284         foreach $ref (values %channels) {
285                 push @out, $ref->{call} if $ref->is_user;
286         }
287         return @out;
288 }
289
290 # obtain a channel object by searching for its connection reference
291 sub get_by_cnum
292 {
293         my ($pkg, $conn) = @_;
294         my $self;
295   
296         foreach $self (values(%channels)) {
297                 return $self if ($self->{conn} == $conn);
298         }
299         return undef;
300 }
301
302 # get rid of a channel object [$obj->del()]
303 sub del
304 {
305         my $self = shift;
306
307         $self->{group} = undef;         # belt and braces
308         delete $channels{$self->{call}};
309 }
310
311 # is it a bbs
312 sub is_bbs
313 {
314         return $_[0]->{sort} eq 'B';
315 }
316
317 sub is_node
318 {
319         return $_[0]->{sort} =~ /^[ACRSX]$/;
320 }
321 # is it an ak1a node ?
322 sub is_ak1a
323 {
324         return $_[0]->{sort} eq 'A';
325 }
326
327 # is it a user?
328 sub is_user
329 {
330         return $_[0]->{sort} =~ /^[UW]$/;
331 }
332
333 # is it a clx node
334 sub is_clx
335 {
336         return $_[0]->{sort} eq 'C';
337 }
338
339 # it is a Web connected user
340 sub is_web
341 {
342         return $_[0]->{sort} eq 'W';
343 }
344
345 # is it a spider node
346 sub is_spider
347 {
348         return $_[0]->{sort} eq 'S';
349 }
350
351 # is it a DXNet node
352 sub is_dxnet
353 {
354         return $_[0]->{sort} eq 'X';
355 }
356
357 # is it a ar-cluster node
358 sub is_arcluster
359 {
360         return $_[0]->{sort} eq 'R';
361 }
362
363 sub is_rbn
364 {
365         return $_[0]->{sort} eq 'N';
366 }
367
368 sub is_dslink
369 {
370         return $_[0]->{sort} eq 'L';
371 }
372
373 # for perl 5.004's benefit
374 sub sort
375 {
376         my $self = shift;
377         return @_ ? $self->{sort} = shift : $self->{sort} ;
378 }
379
380 # find out whether we are prepared to believe this callsign on this interface
381 sub is_believed
382 {
383         my $self = shift;
384         my $call = shift;
385         
386         return grep $call eq $_, $self->user->believe;
387 }
388
389 # handle out going messages, immediately without waiting for the select to drop
390 # this could, in theory, block
391 sub send_now
392 {
393         my $self = shift;
394         my $conn = $self->{conn};
395         return unless $conn;
396         my $sort = shift;
397         my $call = $self->{call};
398         
399         for (@_) {
400 #               chomp;
401         my @lines = split /\n/;
402                 for (@lines) {
403                         $conn->send_now("$sort$call|$_");
404                         # debug log it, but not if it is a log message
405                         dbg("-> $sort $call $_") if $sort ne 'L' && isdbg('chan');
406                 }
407         }
408         $self->{t} = time;
409 }
410
411 #
412 # send later with letter (more control)
413 #
414
415 sub send_later
416 {
417         my $self = shift;
418         my $conn = $self->{conn};
419         return unless $conn;
420         my $sort = shift;
421         my $call = $self->{call};
422         
423         for (@_) {
424 #               chomp;
425         my @lines = split /\n/;
426                 for (@lines) {
427                         $conn->send_later("$sort$call|$_");
428                         # debug log it, but not if it is a log message
429                         dbg("-> $sort $call $_") if $sort ne 'L' && isdbg('chan');
430                 }
431         }
432         $self->{t} = time;
433 }
434
435 #
436 # the normal output routine
437 #
438 sub send                                                # this is always later and always data
439 {
440         my $self = shift;
441         my $conn = $self->{conn};
442         return unless $conn;
443         my $call = $self->{call};
444
445         foreach my $l (@_) {
446                 for (ref $l ? @$l : $l) {
447                         my @lines = split /\n/;
448                         for (@lines) {
449                                 $conn->send_later("D$call|$_");
450                                 dbg("-> D $call $_") if isdbg('chan');
451                         }
452                 }
453         }
454         $self->{t} = $main::systime;
455 }
456
457 # send a file (always later)
458 sub send_file
459 {
460         my ($self, $fn) = @_;
461         my $call = $self->{call};
462         my $conn = $self->{conn};
463         my @buf;
464   
465         open(F, $fn) or die "can't open $fn for sending file ($!)";
466         @buf = <F>;
467         close(F);
468         $self->send(@buf);
469 }
470
471 # this will implement language independence (in time)
472 sub msg
473 {
474         my $self = shift;
475         return DXM::msg($self->{lang}, @_);
476 }
477
478 # stick a broadcast on the delayed queue (but only up to 20 items)
479 sub delay
480 {
481         my $self = shift;
482         my $s = shift;
483         
484         $self->{delayed} = [] unless $self->{delayed};
485         push @{$self->{delayed}}, $s;
486         if (@{$self->{delayed}} >= 20) {
487                 shift @{$self->{delayed}};   # lose oldest one
488         }
489 }
490
491 # change the state of the channel - lots of scope for debugging here :-)
492 sub state
493 {
494         my $self = shift;
495         if (@_) {
496                 $self->{oldstate} = $self->{state};
497                 $self->{state} = shift;
498                 $self->{func} = '' unless defined $self->{func};
499                 dbg("$self->{call} channel func $self->{func} state $self->{oldstate} -> $self->{state}\n") if isdbg('state');
500
501                 # if there is any queued up broadcasts then splurge them out here
502                 if ($self->{delayed} && ($self->{state} eq 'prompt' || $self->{state} eq 'talk')) {
503                         $self->send (@{$self->{delayed}});
504                         delete $self->{delayed};
505                 }
506         }
507         return $self->{state};
508 }
509
510 # disconnect this channel
511 sub disconnect
512 {
513         my $self = shift;
514         my $user = $self->{user};
515         
516         $user->close($self->{startt}, $self->{hostname}) if defined $user;
517         $self->{conn}->disconnect if $self->{conn};
518         $self->del();
519 }
520
521 #
522 # just close all the socket connections down without any fiddling about, cleaning, being
523 # nice to other processes and otherwise telling them what is going on.
524 #
525 # This is for the benefit of forked processes to prepare for starting new programs, they
526 # don't want or need all this baggage.
527 #
528
529 sub closeall
530 {
531         my $ref;
532         foreach $ref (values %channels) {
533                 $ref->{conn}->disconnect() if $ref->{conn};
534         }
535 }
536
537 #
538 # Tell all the users that we have come in or out (if they want to know)
539 #
540 sub tell_login
541 {
542         my ($self, $m, $call) = @_;
543         
544         $call ||= $self->{call};
545         
546         # send info to all logged in thingies
547         my @dxchan = get_all_users();
548         my $dxchan;
549         foreach $dxchan (@dxchan) {
550                 next if $dxchan == $self;
551                 next if $dxchan->{call} eq $main::mycall;
552                 $dxchan->send($dxchan->msg($m, $call)) if $dxchan->{logininfo};
553         }
554 }
555
556 #
557 # Tell all the users if a buddy is logged or out
558 #
559 sub tell_buddies
560 {
561         my ($self, $m, $call, $node) = @_;
562         
563         $call ||= $self->{call};
564         $call =~ s/-\d+$//;
565         $m .= 'n' if $node;
566         
567         # send info to all logged in thingies
568         my @dxchan = get_all_users();
569         my $dxchan;
570         foreach $dxchan (@dxchan) {
571                 next if $dxchan == $self;
572                 next if $dxchan->{call} eq $main::mycall;
573                 $dxchan->send($dxchan->msg($m, $call, $node)) if grep $_ eq $call, @{$dxchan->{user}->{buddies}} ;
574         }
575 }
576
577 # various access routines
578
579 #
580 # return a list of valid elements 
581
582
583 sub fields
584 {
585         return keys(%valid);
586 }
587
588 #
589 # return a prompt for a field
590 #
591
592 sub field_prompt
593
594         my ($self, $ele) = @_;
595         return $valid{$ele};
596 }
597
598 # take a standard input message and decode it into its standard parts
599 sub decode_input
600 {
601         my $dxchan = shift;
602         my $data = shift;
603         my ($sort, $call, $line) = $data =~ /^([A-Z])(#?[A-Z0-9\/\-]{3,25})\|(.*)$/;
604
605         my $chcall = (ref $dxchan) ? $dxchan->call : "UN.KNOWN";
606         
607         # the above regexp must work
608         unless (defined $sort && defined $call && defined $line) {
609 #               $data =~ s/([\x00-\x1f\x7f-\xff])/uc sprintf("%%%02x",ord($1))/eg;
610                 dbg("DUFF Line on $chcall: $data");
611                 return ();
612         }
613
614         if(ref($dxchan) && $call ne $chcall) {
615                 dbg("DUFF Line come in for $call on wrong channel $chcall");
616                 return();
617         }
618         
619         return ($sort, $call, $line);
620 }
621
622 # broadcast a message to all clusters taking into account isolation
623 # [except those mentioned after buffer]
624 sub broadcast_nodes
625 {
626         my $s = shift;                          # the line to be rebroadcast
627         my @except = @_;                        # to all channels EXCEPT these (dxchannel refs)
628         my @dxchan = get_all_nodes();
629         my $dxchan;
630         
631         # send it if it isn't the except list and isn't isolated and still has a hop count
632         foreach $dxchan (@dxchan) {
633                 next if grep $dxchan == $_, @except;
634                 next if $dxchan == $main::me;
635                 
636                 my $routeit = $dxchan->can('adjust_hops') ? $dxchan->adjust_hops($s) : $s;      # adjust its hop count by node name
637
638                 $dxchan->send($routeit) unless $dxchan->{isolate} || !$routeit;
639         }
640 }
641
642 # broadcast a message to all clusters ignoring isolation
643 # [except those mentioned after buffer]
644 sub broadcast_all_nodes
645 {
646         my $s = shift;                          # the line to be rebroadcast
647         my @except = @_;                        # to all channels EXCEPT these (dxchannel refs)
648         my @dxchan = get_all_nodes();
649         my $dxchan;
650         
651         # send it if it isn't the except list and isn't isolated and still has a hop count
652         foreach $dxchan (@dxchan) {
653                 next if grep $dxchan == $_, @except;
654                 next if $dxchan == $main::me;
655
656                 my $routeit = $dxchan->can('adjust_hops') ? $dxchan->adjust_hops($s) : $s;      # adjust its hop count by node name
657                 $dxchan->send($routeit);
658         }
659 }
660
661 # broadcast to all users
662 # storing the spot or whatever until it is in a state to receive it
663 sub broadcast_users
664 {
665         my $s = shift;                          # the line to be rebroadcast
666         my $sort = shift;           # the type of transmission
667         my $fref = shift;           # a reference to an object to filter on
668         my @except = @_;                        # to all channels EXCEPT these (dxchannel refs)
669         my @dxchan = get_all_users();
670         my $dxchan;
671         my @out;
672         
673         foreach $dxchan (@dxchan) {
674                 next if grep $dxchan == $_, @except;
675                 push @out, $dxchan;
676         }
677         broadcast_list($s, $sort, $fref, @out);
678 }
679
680
681 # broadcast to a list of users
682 sub broadcast_list
683 {
684         my $s = shift;
685         my $sort = shift;
686         my $fref = shift;
687         my $dxchan;
688         
689         foreach $dxchan (@_) {
690                 my $filter = 1;
691                 next if $dxchan == $main::me;
692                 
693                 if ($sort eq 'dx') {
694                     next unless $dxchan->{dx};
695                         ($filter) = $dxchan->{spotsfilter}->it($fref) if $dxchan->{spotsfilter} && ref $fref;
696                         next unless $filter;
697                 }
698                 next if $sort eq 'ann' && !$dxchan->{ann} && $s !~ /^To\s+LOCAL\s+de\s+(?:$main::myalias|$main::mycall)/i;
699                 next if $sort eq 'wwv' && !$dxchan->{wwv};
700                 next if $sort eq 'wcy' && !$dxchan->{wcy};
701                 next if $sort eq 'wx' && !$dxchan->{wx};
702
703                 $s =~ s/\a//og unless $dxchan->{beep};
704
705                 if ($dxchan->{state} eq 'prompt' || $dxchan->{state} eq 'talk') {
706                         $dxchan->send($s);      
707                 } else {
708                         $dxchan->delay($s);
709                 }
710         }
711 }
712
713 sub process_one
714 {
715         my $self = shift;
716
717         while (my $data = shift @{$self->{inqueue}}) {
718                 my ($sort, $call, $line) = $self->decode_input($data);
719                 next unless defined $sort;
720
721                 if ($sort ne 'D') {
722                         if (isdbg('chan')) {
723                                 if (($self->is_rbn && isdbg('rbnchan')) || !$self->is_rbn) {
724                                         dbg("<- $sort $call $line") if isdbg('chan'); # you may think this is tautology, but it's needed get the correct label on the debug line
725                                 }
726                         }
727                 }
728                 
729                 # handle A records
730                 my $user = $self->user;
731                 if ($sort eq 'I') {
732                         die "\$user not defined for $call" unless defined $user;
733                         
734                         # normal input
735                         $self->normal($line);
736                 } elsif ($sort eq 'G') {
737                         $self->enhanced($line);
738                 } elsif ($sort eq 'A' || $sort eq 'O' || $sort eq 'W') {
739                         $self->start($line, $sort);
740                 } elsif ($sort eq 'C') {
741                         $self->width($line); # change number of columns
742                 } elsif ($sort eq 'Z') {
743                         $self->disconnect;
744                 } elsif ($sort eq 'D') {
745                         ;                               # ignored (an echo)
746                 } else {
747                         dbg atime . " DXChannel::process_one: Unknown command letter ($sort) received from $call\n";
748                 }
749         }
750 }
751
752 sub process
753 {
754         foreach my $dxchan (values %channels) {
755                 next if $dxchan->{disconnecting};
756                 $dxchan->process_one;
757         }
758 }
759
760 sub handle_xml
761 {
762         my $self = shift;
763         my $r = 0;
764         
765         if (DXXml::available()) {
766                 $r = $self->{handle_xml} || 0;
767         } else {
768                 delete $self->{handle_xml} if exists $self->{handle_xml};
769         }
770         return $r;
771 }
772
773 sub error_handler
774 {
775         my $self = shift;
776         my $error = shift || '';
777         dbg("$self->{call} ERROR '$error', closing") if isdbg('chan');
778         $self->{conn}->set_error(undef) if exists $self->{conn};
779         $self->disconnect(1);
780 }
781
782 sub refresh_user
783 {
784         my $call = shift;
785         my $user = shift;
786         return unless $call && $user && ref $user;
787         my $self = DXChannel::get($call);
788         $self->{user} = $user;
789         return $user;
790 }
791
792 sub isregistered
793 {
794         my $self = shift;
795
796         # the sysop is registered!
797         return 1 if $self->{call} eq $main::myalias || $self->{call} eq $main::mycall;
798         
799         if ($main::reqreg) {
800                 return $self->{registered};
801         } else {
802                 return 1;
803         }
804 }
805
806 #no strict;
807 sub AUTOLOAD
808 {
809         no strict;
810         my $name = $AUTOLOAD;
811         return if $name =~ /::DESTROY$/;
812         $name =~ s/^.*:://o;
813   
814         confess "Non-existant field '$AUTOLOAD'" if !$valid{$name};
815
816         # this clever line of code creates a subroutine which takes over from autoload
817         # from OO Perl - Conway
818         *$AUTOLOAD = sub {@_ > 1 ? $_[0]->{$name} = $_[1] : $_[0]->{$name}};
819         goto &$AUTOLOAD;
820 }
821
822
823 1;
824 __END__;