line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Ekahau::Server; |
2
|
6
|
|
|
6
|
|
3366
|
use base 'Ekahau::Base'; our $VERSION = $Ekahau::Base::VERSION; |
|
6
|
|
|
|
|
17
|
|
|
6
|
|
|
|
|
6371
|
|
3
|
|
|
|
|
|
|
use base 'Ekahau::ErrHandler'; |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
# Written by Scott Gifford |
6
|
|
|
|
|
|
|
# Copyright (C) 2004 The Regents of the University of Michigan. |
7
|
|
|
|
|
|
|
# See the file LICENSE included with the distribution for license |
8
|
|
|
|
|
|
|
# information. |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use warnings; |
11
|
|
|
|
|
|
|
use strict; |
12
|
|
|
|
|
|
|
use bytes; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 NAME |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
Ekahau::Server - Simple class for creating an Ekahau-style server, for testing |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 SYNOPSIS |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
This class is used to create a server that behaves like the Ekahau |
21
|
|
|
|
|
|
|
Positioning Engine. It is only used for testing the Ekahau client, |
22
|
|
|
|
|
|
|
via the L class. |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
Because this class is used only for testing, it is not documented. |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=cut |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
use constant READ_BLOCKSIZE => 8192; |
29
|
|
|
|
|
|
|
use constant DEFAULT_TIMEOUT => 10; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
use IO::Select; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub new |
34
|
|
|
|
|
|
|
{ |
35
|
|
|
|
|
|
|
my $class = shift; |
36
|
|
|
|
|
|
|
my(%p) = @_; |
37
|
|
|
|
|
|
|
my $private_error; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
my $self = {}; |
40
|
|
|
|
|
|
|
bless $self, $class; |
41
|
|
|
|
|
|
|
$self->{_errhandler} = Ekahau::ErrHandler->errhandler_new($class,%p); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
$self->{tag} = 0; |
44
|
|
|
|
|
|
|
$self->{_readbuf} = ""; |
45
|
|
|
|
|
|
|
$self->{_timeout}=$p{Timeout}||$p{timeout}||DEFAULT_TIMEOUT; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
$self->{_sock} = $p{Socket} |
48
|
|
|
|
|
|
|
or return $self->reterr("No Socket supplied to Ekahau::Server constructor.\n"); |
49
|
|
|
|
|
|
|
binmode $self->{_sock}; |
50
|
|
|
|
|
|
|
$self->{_sock}->autoflush(1); |
51
|
|
|
|
|
|
|
$self->{_socksel} = IO::Select->new($self->{_sock}) |
52
|
|
|
|
|
|
|
or return $self->reterr("Couldn't create IO::Select object: $!\n"); |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
$self->errhandler_constructed(); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub ERROBJ |
58
|
|
|
|
|
|
|
{ |
59
|
|
|
|
|
|
|
my $self = shift; |
60
|
|
|
|
|
|
|
$self->{_errhandler}; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub nextresponse |
64
|
|
|
|
|
|
|
{ |
65
|
|
|
|
|
|
|
my $self = shift; |
66
|
|
|
|
|
|
|
my($sock)=@_; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
my $resp = $self->SUPER::nextresponse |
69
|
|
|
|
|
|
|
or return undef; |
70
|
|
|
|
|
|
|
$resp; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub reply |
74
|
|
|
|
|
|
|
{ |
75
|
|
|
|
|
|
|
my $self = shift; |
76
|
|
|
|
|
|
|
my $resp = shift; |
77
|
|
|
|
|
|
|
$self->command(@_,$resp->{tag}); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub DESTROY |
81
|
|
|
|
|
|
|
{ |
82
|
|
|
|
|
|
|
; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
package Ekahau::Server::Listener; |
86
|
|
|
|
|
|
|
use base 'Ekahau::ErrHandler'; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
use constant DEFAULT_PORT => 8548; |
89
|
|
|
|
|
|
|
use constant DEFAULT_HOST => 0; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub new |
92
|
|
|
|
|
|
|
{ |
93
|
|
|
|
|
|
|
my $class = shift; |
94
|
|
|
|
|
|
|
my(%p) = @_; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
my $self = {}; |
97
|
|
|
|
|
|
|
bless $self,$class; |
98
|
|
|
|
|
|
|
$self->{_errhandler} = Ekahau::ErrHandler->errhandler_new($class,%p); |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
$self->{_timeout}=$p{Timeout}||$p{timeout}||Ekahau::Server::DEFAULT_TIMEOUT; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
$self->_opensock(%p) |
103
|
|
|
|
|
|
|
or return undef; |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
$self->errhandler_constructed(); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub ERROBJ |
109
|
|
|
|
|
|
|
{ |
110
|
|
|
|
|
|
|
my $self = shift; |
111
|
|
|
|
|
|
|
$self->{_errhandler}; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
# Connect to the TCP socket |
115
|
|
|
|
|
|
|
sub _opensock |
116
|
|
|
|
|
|
|
{ |
117
|
|
|
|
|
|
|
my $self = shift; |
118
|
|
|
|
|
|
|
my(%p)=@_; |
119
|
|
|
|
|
|
|
my $sock; |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
if ($p{Socket}) |
122
|
|
|
|
|
|
|
{ |
123
|
|
|
|
|
|
|
$sock = $p{Socket}; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
else |
126
|
|
|
|
|
|
|
{ |
127
|
|
|
|
|
|
|
# For IO::Socket::INET |
128
|
|
|
|
|
|
|
if ($p{timeout} && !$p{Timeout}) |
129
|
|
|
|
|
|
|
{ |
130
|
|
|
|
|
|
|
$p{Timeout}=$p{timeout}; |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
elsif ($self->{_timeout}) |
133
|
|
|
|
|
|
|
{ |
134
|
|
|
|
|
|
|
$p{Timeout} = $self->{_timeout}; |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
if (!$p{LocalPort}) { $p{LocalPort} = DEFAULT_PORT }; |
138
|
|
|
|
|
|
|
if (!$p{LocalAddr} and !$p{LocalHost}) { $p{LocalAddr} = DEFAULT_HOST }; |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
warn "DEBUG Created listener for $p{LocalAddr}:$p{LocalPort}...\n" |
141
|
|
|
|
|
|
|
if ($ENV{VERBOSE}); |
142
|
|
|
|
|
|
|
$sock = IO::Socket::INET->new(%p, |
143
|
|
|
|
|
|
|
Listen => 5, |
144
|
|
|
|
|
|
|
ReuseAddr => 1, |
145
|
|
|
|
|
|
|
Proto => 'tcp') |
146
|
|
|
|
|
|
|
or return $self->reterr("Couldn't create IO::Socket::INET - $!"); |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
$self->{_listen} = $sock; |
150
|
|
|
|
|
|
|
binmode $self->{_listen}; |
151
|
|
|
|
|
|
|
$self->{_listen}->autoflush(1); |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
warn "DEBUG connected.\n" |
154
|
|
|
|
|
|
|
if ($ENV{VERBOSE}); |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
sub accept |
158
|
|
|
|
|
|
|
{ |
159
|
|
|
|
|
|
|
my $self = shift; |
160
|
|
|
|
|
|
|
my $class = shift || 'Ekahau::Server'; |
161
|
|
|
|
|
|
|
my $newconn = $self->{_listen}->accept |
162
|
|
|
|
|
|
|
or return undef; |
163
|
|
|
|
|
|
|
return $class->new(Socket => $newconn, |
164
|
|
|
|
|
|
|
Timeout => $self->{_timeout}); |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=head1 AUTHOR |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
Scott Gifford Egifford@umich.eduE, Esgifford@suspectclass.comE |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
Copyright (C) 2005 The Regents of the University of Michigan. |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
See the file LICENSE included with the distribution for license |
174
|
|
|
|
|
|
|
information. |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=cut |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
1; |