line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::OICQ::Event; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# $Id: Event.pm,v 1.2 2007/02/01 22:07:16 tans Exp $ |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
# Copyright (c) 2003 - 2006 Shufeng Tan. All rights reserved. |
6
|
|
|
|
|
|
|
# |
7
|
|
|
|
|
|
|
# This package is free software and is provided "as is" without express |
8
|
|
|
|
|
|
|
# or implied warranty. It may be used, redistributed and/or modified |
9
|
|
|
|
|
|
|
# under the terms of the Perl Artistic License (see |
10
|
|
|
|
|
|
|
# http://www.perl.com/perl/misc/Artistic.html) |
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
36
|
|
13
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
21
|
|
14
|
1
|
|
|
1
|
|
4
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1108
|
|
15
|
|
|
|
|
|
|
|
16
|
1
|
|
|
1
|
|
81927
|
eval "no encoding; use bytes;" if $] >= 5.008; |
|
1
|
|
|
1
|
|
6017
|
|
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
72
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
7
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $AUTOLOAD; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub client_ver { |
21
|
0
|
|
|
0
|
0
|
|
substr(shift->{Header}, 1, 2) |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub cmdcode { |
25
|
0
|
|
|
0
|
0
|
|
substr(shift->{Header}, 3, 2) |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub seq { |
29
|
0
|
|
|
0
|
0
|
|
substr(shift->{Header}, 5, 2) |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub cmd { |
33
|
0
|
|
|
0
|
0
|
|
my $cmdcode = cmdcode(@_); |
34
|
0
|
0
|
|
|
|
|
$Net::OICQ::Cmd{$cmdcode} or '0x'.unpack('H*', $cmdcode) |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# $event->process() checks if an event is an ACK to a previous event, |
38
|
|
|
|
|
|
|
# or a duplicate to be ignored, or a new event to be added to the queue |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub process { |
41
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
42
|
0
|
|
|
|
|
|
my $oicq = $self->{OICQ}; |
43
|
0
|
|
|
|
|
|
my $queue = $oicq->{EventQueue}; |
44
|
0
|
|
|
|
|
|
my $seq = $self->seq; |
45
|
0
|
|
|
|
|
|
my $cmdcode = $self->cmdcode; |
46
|
0
|
|
|
|
|
|
my $event; |
47
|
0
|
|
|
|
|
|
foreach my $e (@$queue) { |
48
|
0
|
0
|
0
|
|
|
|
if ($e->seq eq $seq and $e->cmdcode eq $cmdcode) { |
49
|
0
|
0
|
|
|
|
|
return if ref($e) eq ref($event); |
50
|
0
|
|
|
|
|
|
$event = $e; |
51
|
0
|
|
|
|
|
|
last; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
0
|
0
|
|
|
|
|
if (defined($event)) { |
56
|
0
|
|
|
|
|
|
my $cmd = $self->cmd; |
57
|
0
|
|
|
|
|
|
my $seq_hex = unpack('H*', $seq); |
58
|
0
|
0
|
|
|
|
|
if ($event->{Ack}) { |
|
|
0
|
|
|
|
|
|
59
|
0
|
0
|
|
|
|
|
return unless $oicq->{Debug}; |
60
|
0
|
|
|
|
|
|
$oicq->log_t("$cmd seq 0x$seq_hex was ACK'ed at ", |
61
|
|
|
|
|
|
|
substr(localtime($event->{Ack}), 4, 16)); |
62
|
0
|
|
|
|
|
|
return; |
63
|
|
|
|
|
|
|
} elsif (ref($self) eq ref($event)) { |
64
|
|
|
|
|
|
|
# Duplicate packet such as recv_msg, recv_service_msg |
65
|
0
|
0
|
|
|
|
|
return unless $oicq->{Debug}; |
66
|
0
|
|
|
|
|
|
$oicq->log_t("$cmd seq 0x$seq_hex is a dupe"); |
67
|
0
|
|
|
|
|
|
return; |
68
|
|
|
|
|
|
|
} else { |
69
|
0
|
|
|
|
|
|
$event->{Ack} = time; |
70
|
0
|
0
|
|
|
|
|
if ($oicq->{Debug}) { |
71
|
0
|
|
|
|
|
|
$oicq->log_t("ACK $cmd seq 0x$seq_hex"); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
push @$queue, $self; |
77
|
0
|
0
|
|
|
|
|
shift @$queue if @$queue > $oicq->{EventQueueSize}; |
78
|
0
|
|
|
|
|
|
return 1; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub AUTOLOAD { |
82
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
83
|
0
|
0
|
|
|
|
|
my $type = ref($self) or croak "$self is not an object"; |
84
|
0
|
|
|
|
|
|
my $oicq = $self->{OICQ}; |
85
|
0
|
0
|
|
|
|
|
croak "$self is not a Net::OICQ::Event object\n" unless defined $oicq; |
86
|
0
|
|
|
|
|
|
my $name = $AUTOLOAD; |
87
|
0
|
|
|
|
|
|
$name =~ s/.*://; |
88
|
0
|
0
|
|
|
|
|
return if $name eq 'DESTROY'; |
89
|
0
|
|
|
|
|
|
my $cmdcode = $self->cmdcode; |
90
|
0
|
|
|
|
|
|
my $seq = $self->seq; |
91
|
0
|
|
|
|
|
|
my $cmd = $self->cmd; |
92
|
0
|
0
|
|
|
|
|
my $text = sprintf("%s %s(0x%s) %s AUTOLOAD $name\n%s", |
93
|
|
|
|
|
|
|
substr(localtime($self->{Time}), 4, 15), |
94
|
|
|
|
|
|
|
$cmd, unpack('H*', $cmdcode), |
95
|
|
|
|
|
|
|
$type =~ /Client/ ? unpack('N', $self->uid) : "", |
96
|
|
|
|
|
|
|
$oicq->hexdump($self->{Data})); |
97
|
0
|
0
|
|
|
|
|
$oicq->log_t($text) if $oicq->{Debug}; |
98
|
0
|
|
|
|
|
|
return; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
# This method should never croak now that we have AUTOLOAD |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub parse { |
104
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
105
|
0
|
|
|
|
|
|
my $cmd = $self->cmd; |
106
|
0
|
0
|
|
|
|
|
return unless defined $cmd; |
107
|
0
|
|
|
|
|
|
$self->$cmd; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub dump { |
111
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
112
|
0
|
|
|
|
|
|
my $ref = ref($self); |
113
|
0
|
|
|
|
|
|
my $res = sprintf "%s $ref %s 0x%s\n", substr(localtime($self->{Time}), 4, 15), |
114
|
|
|
|
|
|
|
$self->cmd, unpack("H*", $self->seq); |
115
|
0
|
|
|
|
|
|
foreach my $attr (keys %$self) { |
116
|
0
|
0
|
|
|
|
|
next if $attr =~ /^(?:Data|Time|Header|OICQ)$/; |
117
|
0
|
|
|
|
|
|
$res .= " $attr: "; |
118
|
0
|
|
|
|
|
|
my $value = $self->{$attr}; |
119
|
0
|
0
|
|
|
|
|
if (ref($value) eq 'ARRAY') { |
|
|
0
|
|
|
|
|
|
120
|
0
|
|
|
|
|
|
$res .= '[' . join(', ', @$value) . "]\n"; |
121
|
|
|
|
|
|
|
} elsif (ref($value) eq 'HASH') { |
122
|
0
|
|
|
|
|
|
foreach my $k (keys %$value) { |
123
|
0
|
|
|
|
|
|
$res .= " $k: $value->{$k}\n"; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
} else { |
126
|
0
|
|
|
|
|
|
$res .= "$value\n"; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
} |
129
|
0
|
|
|
|
|
|
return $res; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
1 |