line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Win32::Girder::IEvent::Client; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
#==============================================================================# |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 NAME |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
Win32::Girder::IEvent::Client - Perl API to the Win32 Girder Internet Events Client |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 SYNOPSIS |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
use Win32::Girder::IEvent::Client; |
12
|
|
|
|
|
|
|
my $gc = Win32::Girder::IEvent::Client->new( |
13
|
|
|
|
|
|
|
PeerHost => 'htpc.my.domain:1024' |
14
|
|
|
|
|
|
|
); |
15
|
|
|
|
|
|
|
$gc->send(42) || die "Can't send event"; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 DESCRIPTION |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
Girder is a Windows automation tool, originally designed to receive commands |
20
|
|
|
|
|
|
|
from IR remote controls. The client is used for sending 'Event Strings' to a |
21
|
|
|
|
|
|
|
Girder instance or a compatible server. |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head2 METHODS |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=over 4 |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=cut |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
#==============================================================================# |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
require 5.6.0; |
32
|
|
|
|
|
|
|
|
33
|
3
|
|
|
3
|
|
28203
|
use strict; |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
111
|
|
34
|
3
|
|
|
3
|
|
16
|
use warnings::register; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
518
|
|
35
|
3
|
|
|
3
|
|
2978
|
use IO::Socket; |
|
3
|
|
|
|
|
85372
|
|
|
3
|
|
|
|
|
15
|
|
36
|
|
|
|
|
|
|
|
37
|
3
|
|
|
|
|
396
|
use Win32::Girder::IEvent::Common qw( |
38
|
|
|
|
|
|
|
hash_password |
39
|
|
|
|
|
|
|
$def_pass |
40
|
|
|
|
|
|
|
$def_port |
41
|
|
|
|
|
|
|
$def_host |
42
|
3
|
|
|
3
|
|
4138
|
); |
|
3
|
|
|
|
|
9
|
|
43
|
|
|
|
|
|
|
|
44
|
3
|
|
|
3
|
|
14
|
use base qw(IO::Socket::INET); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
1535
|
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
our $VERSION = 0.01; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
#==============================================================================# |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=item my $gc = Win32::Girder::IEvent::Client->new([ARGS]); |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
Create a new client object. The client object inherits the IO::Socket::INET |
54
|
|
|
|
|
|
|
object and so the constructor can take all the IO::Socket::INET methods. |
55
|
|
|
|
|
|
|
However the only relavent ones are: |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
B<( PeerAddr =E $addr )> or B<( PeerHost =E $addr )> |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
The servername (and possibly port) of the server to connect to. Defaults to |
60
|
|
|
|
|
|
|
"localhost:1024" if not specified. |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
B<( PeerPort =E $port )> |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
The port on which the server is running. Defaults to 1024 if not specified |
65
|
|
|
|
|
|
|
or not part of the server name. |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
Girder specific parameters are: |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
B<( PassWord =E $mypass )> |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
The password needed for access to the server. Defaults to 'NewDefPWD'. Note |
72
|
|
|
|
|
|
|
that passwords are NOT sent plain text accross the wire. |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=cut |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub new { |
77
|
1
|
|
|
1
|
1
|
1001915
|
my ($pack,%opts) = @_; |
78
|
|
|
|
|
|
|
|
79
|
1
|
|
|
|
|
17
|
my $addr; |
80
|
1
|
50
|
33
|
|
|
73
|
if ( |
81
|
|
|
|
|
|
|
(defined($addr = $opts{PeerAddr})) || |
82
|
|
|
|
|
|
|
(defined($addr = $opts{PeerHost})) |
83
|
|
|
|
|
|
|
) { |
84
|
1
|
50
|
|
|
|
152
|
if ($addr !~ /:/) { |
85
|
1
|
50
|
|
|
|
18
|
if (!defined(my $addr = $opts{PeerPort})) { |
86
|
0
|
|
|
|
|
0
|
$opts{PeerPort} = $def_port; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
} else { |
90
|
0
|
|
|
|
|
0
|
$opts{PeerAddr} = "$def_host:$def_port"; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
1
|
|
33
|
|
|
230
|
my $obj = $pack->SUPER::new(%opts) || do { |
94
|
|
|
|
|
|
|
warnings::warn "Could not create socket: $!"; |
95
|
|
|
|
|
|
|
return 0; |
96
|
|
|
|
|
|
|
}; |
97
|
|
|
|
|
|
|
|
98
|
1
|
50
|
|
|
|
3055
|
if (defined(my $pass = $opts{PassWord})) { |
99
|
1
|
|
|
|
|
22
|
$$obj->{_girder_pass} = $pass; |
100
|
|
|
|
|
|
|
} else { |
101
|
0
|
|
|
|
|
0
|
$$obj->{_girder_pass} = $def_pass; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
|
105
|
1
|
|
|
|
|
32
|
$obj->print("quintessence\n"); |
106
|
1
|
|
|
|
|
344
|
my $cookie = $obj->getline; |
107
|
1
|
50
|
|
|
|
1526
|
if ($cookie) { |
108
|
1
|
|
|
|
|
3
|
chomp($cookie); |
109
|
|
|
|
|
|
|
|
110
|
1
|
|
|
|
|
19
|
$obj->print(hash_password($cookie,$$obj->{_girder_pass})."\n"); |
111
|
1
|
50
|
33
|
|
|
65
|
unless ((local $_ = $obj->getline) && (/accept/)) { |
112
|
0
|
|
|
|
|
0
|
warnings::warn "Server rejected connection - is the password correct"; |
113
|
0
|
|
|
|
|
0
|
$obj = 0; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
} else { |
116
|
0
|
|
|
|
|
0
|
warnings::warn "Server did not send back a cookie"; |
117
|
0
|
|
|
|
|
0
|
$obj = 0; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
1
|
|
|
|
|
318
|
return $obj; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
#==============================================================================# |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=item $gc->send("event1" [,"event2" ...]); |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Send an event, or several events to the server. Returns the number of events |
129
|
|
|
|
|
|
|
sent. |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=cut |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
sub send { |
134
|
1
|
|
|
1
|
1
|
562
|
my ($obj,@events) = @_; |
135
|
|
|
|
|
|
|
|
136
|
1
|
|
|
|
|
3
|
foreach my $event (@events) { |
137
|
1
|
50
|
|
|
|
6
|
$obj->print("$event\n") || return; |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
1
|
|
|
|
|
54
|
return scalar @events; |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
#==============================================================================# |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=item $gc->close(); |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
Politly shut down the connection. |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=cut |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
sub close { |
153
|
1
|
|
|
1
|
1
|
5
|
my ($obj,@opts) = @_; |
154
|
1
|
|
|
|
|
4
|
$obj->print("close\n"); |
155
|
1
|
|
|
|
|
44
|
$obj->SUPER::close(@opts); |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
#==============================================================================# |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
sub DESTROY { |
162
|
1
|
|
|
1
|
|
3
|
my ($obj) = @_; |
163
|
1
|
|
|
|
|
7
|
$$obj->{_girder_pass} = undef; |
164
|
1
|
|
|
|
|
20
|
$obj->SUPER::DESTROY(); |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
#==============================================================================# |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=back |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head1 AUTHOR |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
This module is Copyright (c) 2002 Gavin Brock gbrock@cpan.org. All rights |
175
|
|
|
|
|
|
|
reserved. This program is free software; you can redistribute it and/or |
176
|
|
|
|
|
|
|
modify it under the same terms as Perl itself. |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
The Girder application is Copyright (c) Ron Bessems. Please see the |
179
|
|
|
|
|
|
|
'copying.txt' that came with your copy of Girder or visit http://www.girder.nl |
180
|
|
|
|
|
|
|
for contact information. |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=head1 SEE ALSO |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
The Girder home page http://www.girder.nl |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
L. |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
L. |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=cut |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
# That's all folks.. |
193
|
|
|
|
|
|
|
#==============================================================================# |