line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Author: Chris "BinGOs" Williams |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# This module may be used, modified, and distributed under the same |
4
|
|
|
|
|
|
|
# terms as Perl itself. Please see the license that came with your Perl |
5
|
|
|
|
|
|
|
# distribution for details. |
6
|
|
|
|
|
|
|
# |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
package POE::Component::Client::Ident; |
9
|
|
|
|
|
|
|
|
10
|
2
|
|
|
2
|
|
23526
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
75
|
|
11
|
2
|
|
|
2
|
|
12
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
60
|
|
12
|
2
|
|
|
2
|
|
1725
|
use Socket; |
|
2
|
|
|
|
|
4553
|
|
|
2
|
|
|
|
|
1607
|
|
13
|
2
|
|
|
2
|
|
929
|
use POE qw(Component::Client::Ident::Agent); |
|
2
|
|
|
|
|
55292
|
|
|
2
|
|
|
|
|
16
|
|
14
|
2
|
|
|
2
|
|
125
|
use Carp; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
118
|
|
15
|
2
|
|
|
2
|
|
9
|
use vars qw($VERSION); |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
2143
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
$VERSION = '1.16'; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub spawn { |
20
|
1
|
|
|
1
|
1
|
871
|
my ( $package, $alias ) = splice @_, 0, 2; |
21
|
|
|
|
|
|
|
|
22
|
1
|
|
|
|
|
7
|
my $self = bless { alias => $alias }, $package; |
23
|
|
|
|
|
|
|
|
24
|
1
|
|
|
|
|
15
|
$self->{session_id} = POE::Session->create ( |
25
|
|
|
|
|
|
|
object_states => [ |
26
|
|
|
|
|
|
|
$self => [qw(_start _child query)], |
27
|
|
|
|
|
|
|
$self => { ident_agent_reply => '_ident_agent_reply', |
28
|
|
|
|
|
|
|
ident_agent_error => '_ident_agent_error', |
29
|
|
|
|
|
|
|
shutdown => '_shutdown', |
30
|
|
|
|
|
|
|
}, |
31
|
|
|
|
|
|
|
], |
32
|
|
|
|
|
|
|
)->ID(); |
33
|
|
|
|
|
|
|
|
34
|
1
|
|
|
|
|
179
|
return $self; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub session_id { |
38
|
0
|
|
|
0
|
1
|
0
|
$_[0]->{session_id}; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub shutdown { |
42
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
43
|
0
|
|
|
|
|
0
|
$poe_kernel->call( $self->{session_id}, @_ ); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub _start { |
47
|
1
|
|
|
1
|
|
348
|
my ($kernel,$self,$session) = @_[KERNEL,OBJECT,SESSION]; |
48
|
1
|
|
|
|
|
26
|
$self->{session_id} = $session->ID(); |
49
|
1
|
50
|
|
|
|
18
|
$kernel->alias_set( $self->{alias} ) if $self->{alias}; |
50
|
1
|
50
|
|
|
|
44
|
$kernel->refcount_increment( $self->{session_id}, __PACKAGE__ ) unless $self->{alias}; |
51
|
1
|
|
|
|
|
4
|
undef; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub _child { |
55
|
2
|
|
|
2
|
|
207
|
my ($kernel,$self,$what,$child) = @_[KERNEL,OBJECT,ARG0,ARG1]; |
56
|
|
|
|
|
|
|
|
57
|
2
|
100
|
|
|
|
8
|
if ( $what eq 'create' ) { |
58
|
|
|
|
|
|
|
# Stuff here to match up to our query |
59
|
1
|
|
|
|
|
5
|
$self->{children}->{ $child->ID() } = 1; |
60
|
|
|
|
|
|
|
} |
61
|
2
|
100
|
|
|
|
20
|
if ( $what eq 'lose' ) { |
62
|
1
|
|
|
|
|
6
|
delete $self->{children}->{ $child->ID() }; |
63
|
|
|
|
|
|
|
} |
64
|
2
|
|
|
|
|
12
|
undef; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub _shutdown { |
68
|
1
|
|
|
1
|
|
2094
|
my ($kernel,$self) = @_[KERNEL,OBJECT]; |
69
|
1
|
|
|
|
|
3
|
$kernel->call( $_ => 'shutdown' ) for keys %{ $self->{children} }; |
|
1
|
|
|
|
|
6
|
|
70
|
1
|
|
|
|
|
7
|
$kernel->alias_remove($_) for $kernel->alias_list(); |
71
|
1
|
50
|
|
|
|
101
|
$kernel->refcount_decrement( $self->{session_id}, __PACKAGE__ ) unless $self->{alias}; |
72
|
1
|
|
|
|
|
5
|
undef; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub query { |
76
|
1
|
|
|
1
|
1
|
4235
|
my ($kernel,$self,$sender) = @_[KERNEL,OBJECT,SENDER]; |
77
|
1
|
|
|
|
|
2
|
my $package = ref $self; |
78
|
|
|
|
|
|
|
|
79
|
1
|
|
|
|
|
6
|
my ($peeraddr,$peerport,$sockaddr,$sockport,$socket) = _parse_arguments( @_[ARG0 .. $#_] ); |
80
|
|
|
|
|
|
|
|
81
|
1
|
50
|
33
|
|
|
16
|
unless ( $peeraddr and $peerport and $sockaddr and $sockport ) { |
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
82
|
0
|
|
|
|
|
0
|
croak "Not enough arguments/items for $package->query"; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
1
|
|
|
|
|
5
|
$kernel->refcount_increment( $sender->ID() => __PACKAGE__ ); |
86
|
|
|
|
|
|
|
|
87
|
1
|
|
|
|
|
35
|
POE::Component::Client::Ident::Agent->spawn( @_[ARG0 .. $#_], Reference => $sender->ID() ); |
88
|
1
|
|
|
|
|
5
|
undef; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub _ident_agent_reply { |
92
|
1
|
|
|
1
|
|
231
|
my ($kernel,$self,$ref) = @_[KERNEL,OBJECT,ARG0]; |
93
|
1
|
|
|
|
|
4
|
my $requester = delete $ref->{Reference}; |
94
|
1
|
|
|
|
|
7
|
$kernel->post( $requester, 'ident_client_reply' , $ref, @_[ARG1 .. $#_] ); |
95
|
1
|
|
|
|
|
85
|
$kernel->refcount_decrement( $requester => __PACKAGE__ ); |
96
|
1
|
|
|
|
|
61
|
undef; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub _ident_agent_error { |
100
|
0
|
|
|
0
|
|
0
|
my ($kernel,$self,$ref) = @_[KERNEL,OBJECT,ARG0]; |
101
|
0
|
|
|
|
|
0
|
my $requester = delete $ref->{Reference}; |
102
|
0
|
|
|
|
|
0
|
$kernel->post( $requester, 'ident_client_error', $ref, @_[ARG1 .. $#_] ); |
103
|
0
|
|
|
|
|
0
|
$kernel->refcount_decrement( $requester => __PACKAGE__ ); |
104
|
0
|
|
|
|
|
0
|
undef; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub _parse_arguments { |
108
|
1
|
|
|
1
|
|
13
|
my %hash = @_; |
109
|
1
|
|
|
|
|
2
|
my @returns; |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
# If we get a socket it takes precedence over any other arguments |
112
|
|
|
|
|
|
|
SWITCH: { |
113
|
1
|
50
|
|
|
|
2
|
if ( defined $hash{'Socket'} ) { |
|
1
|
|
|
|
|
8
|
|
114
|
0
|
|
|
|
|
0
|
$returns[0] = inet_ntoa( (unpack_sockaddr_in( getpeername $hash{'Socket'} ))[1] ); |
115
|
0
|
|
|
|
|
0
|
$returns[1] = (unpack_sockaddr_in( getpeername $hash{'Socket'} ))[0]; |
116
|
0
|
|
|
|
|
0
|
$returns[2] = inet_ntoa( (unpack_sockaddr_in( getsockname $hash{'Socket'} ))[1] ); |
117
|
0
|
|
|
|
|
0
|
$returns[3] = (unpack_sockaddr_in( getsockname $hash{'Socket'} ))[0]; |
118
|
0
|
|
|
|
|
0
|
$returns[4] = $hash{'Socket'}; |
119
|
0
|
|
|
|
|
0
|
last SWITCH; |
120
|
|
|
|
|
|
|
} |
121
|
1
|
50
|
33
|
|
|
18
|
if ( defined $hash{'PeerAddr'} and defined $hash{'PeerPort'} and defined $hash{'SockAddr'} and defined $hash{'SockAddr'} ) { |
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
122
|
1
|
|
|
|
|
3
|
$returns[0] = $hash{'PeerAddr'}; |
123
|
1
|
|
|
|
|
3
|
$returns[1] = $hash{'PeerPort'}; |
124
|
1
|
|
|
|
|
2
|
$returns[2] = $hash{'SockAddr'}; |
125
|
1
|
|
|
|
|
2
|
$returns[3] = $hash{'SockPort'}; |
126
|
1
|
|
|
|
|
9
|
last SWITCH; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
} |
129
|
1
|
|
|
|
|
6
|
return @returns; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
'Who are you?'; |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
__END__ |