lib/Ekahau/Server/Test.pm

filter: Statementstmt 91.5% 238 / 260 Branchbran 65.6% 88 / 134 Conditioncond 60.9% 25 / 41 MC/DCmcdc 45.4% 10 / 22 Subroutinesub 97.1% 34 / 35 Podpod 5.5% 1 / 18 totaltotal 77.6% 396 / 510 CC 89 SCAR 23.4
CC
89
Cov
81%
run
23.1
handle_talk
20.4
accept
12.0
CRAP 10.4
« lib/Ekahau.pm ↑ Summary lib/Ekahau/Response.pm »
1 package Ekahau::Server::Test;
2 15 ▶use base 'Ekahau::Server'; our $VERSION = $Ekahau::Server::VERSION;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 15 ▶use base 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 # Written by Scott Gifford <gifford@umich.edu>
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 15 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 15 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 15 ▶use bytes;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 =head1 NAME
15  
16 Ekahau::Server::Test - Creates a test Ekahau server
17  
18 =head1 SYNOPSIS
19  
20 This class is used to create a "mock" Ekahau server for testing the
21 Ekahau client.
22  
23 Because this class is used only for testing, it is not documented.
24  
25 =cut
26  
27 15 ▶use Ekahau::Response::Error qw(:codes);
Subroutine BEGIN: called CC=1 SCAR=0.0
28 15 ▶use Ekahau::License;
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30  
31 15 our @EXPORT_OK = qw(static_area static_location);
32  
33 15 ▶use constant DEFAULT_PASSWORD => 'Llama';
Subroutine BEGIN: called CC=1 SCAR=0.0
34 15 ▶use constant DEFAULT_TICK => 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36 15 our @devices = (
37 {
38 props => {
39 'ECLIENT.WLAN_TECHNOLOGY' => 0,
40 'ECLIENT.WLAN_MODEL' => 'Agere',
41 'ECLIENT.COMMON_INTERNALNAME' => 'Wlan_Agere.dll',
42 'NETWORK.MAC' => '00:10:C6:6A:12:3E',
43 'GROUP' => 'ECLIENT',
44 'NETWORK.DNS_NAME' => '141.212.55.129',
45 'ECLIENT.COMMON_OS_VER' => '4.21.1088',
46 'ECLIENT.COMMON_CLIENTID' => '000ea544c3f5ac51cc7e140b5d8',
47 'NETWORK.IP-ADDRESS' => '141.212.55.129',
48 'ECLIENT.COMMON_CLIENT_VER' => '3.2.198',
49 },
50 location_track => static_location({
51 accurateX => 100,
52 accurateY => 100,
53 accurateContextId => '12345',
54 accurateExpectedError => 1,
55 latestX => 100,
56 latestY => 100,
57 latestContextId => 'ctx1',
58 latestExpectedError => 1,
59 speed => 10,
60 heading => 180,
61 }),
62 area_track => static_area([
63 {
64 name => 'area51',
65 probability => '100.00',
66 contextId => '12345',
67 polygon => '100;75;150&100;75;150',
68 property1 => 'value1',
69 }]),
70 },
71 );
72
73
74  
75 15 our %contexts = (
76 12345 => {
77 name => 12345,
78 address => "building/floor1",
79 mapScale => '10.00',
80 property1 => 'value1',
81 },
82 );
83  
84 15 our %maps = (
85 12345 => 'Pretend this is a PNG map file',
86 23456 => 'All work and no play makes Jack a dull boy',
87 );
88
89  
90 sub new
91 28 ▶{
Subroutine new: called CC=8 SCAR=20.8
Pod documented
92 28 my $class = shift;
93 28 my(%p)=@_;
94  
95 28 my $self = $class->SUPER::new(@_);
96 28 $self->errhandler_deconstructed;
97 28 ▶ $self->{_devices}=$p{Devices} || \@devices;
Condition100%2/2
$p{'Devices'} || \@Ekahau::Server::Test::devices
l!l
820
MC/DC100%1/1
$p{'Devices'} || \@Ekahau::Server::Test::devices
$p{'Devices'}
Truth table100%2/2
A
A= $p{'Devices'}
Aresult
11
00
98 28 ▶ $self->{_contexts}=$p{Contexts} || \%contexts;
Condition100%2/2
$p{'Contexts'} || \%Ekahau::Server::Test::contexts
l!l
820
MC/DC100%1/1
$p{'Contexts'} || \%Ekahau::Server::Test::contexts
$p{'Contexts'}
Truth table100%2/2
A
A= $p{'Contexts'}
Aresult
11
00
99 28 ▶ $self->{_maps}=$p{Maps} || \%maps;
Condition100%2/2
$p{'Maps'} || \%Ekahau::Server::Test::maps
l!l
820
MC/DC100%1/1
$p{'Maps'} || \%Ekahau::Server::Test::maps
$p{'Maps'}
Truth table100%2/2
A
A= $p{'Maps'}
Aresult
11
00
100 28 ▶ $self->{_password} = $p{Password} || DEFAULT_PASSWORD;
Condition100%2/2
$p{'Password'} || 'Llama'
l!l
208
MC/DC100%1/1
$p{'Password'} || 'Llama'
$p{'Password'}
Truth table100%2/2
A
A= $p{'Password'}
Aresult
11
00
101 28 ▶ $self->{_tick} = $p{Tick} || DEFAULT_TICK;
Condition100%2/2
$p{'Tick'} || 2
l!l
820
MC/DC100%1/1
$p{'Tick'} || 2
$p{'Tick'}
Truth table100%2/2
A
A= $p{'Tick'}
Aresult
11
00
102 28 ▶ if ($p{LicenseFile})
Branch: 1 branch
BranchTrueFalseTotal
if ($p{"LicenseFile"}) 9 19 28
103 {
104 $self->{_license} = Ekahau::License->new(LicenseFile => $p{LicenseFile})
105 9 ▶ or return $self->reterr("Error processing LicenseFile '$p{LicenseFile}': ".Ekahau::License->lasterr);
Branch: 1 branch
BranchTrueFalseTotal
$self->{"_license"} = "Ekahau::License"->new("LicenseFile", $p{"LicenseFile"}) or return $self->reterr(qq[Error processing LicenseFile '$p{"LicenseFile"}': ] . "Ekahau::License"->lasterr) 9 0 9
106 }
107 28 $self->errhandler_constructed;
108 }
109  
110 sub run
111 9 ▶{
Subroutine run: called CC=20 SCAR=31.4
Pod undocumented
112 9 my $self = shift;
113  
114 9 $self->{auth_state} = 0;
115 9 $self->{_rand_str} = 'blahblahblah';
116 9 $self->command(['HELLO',1,$self->{_rand_str}]);
117  
118 9 my $lasttick = time;
119 9 while(1)
120 {
121 90 my $started_waiting = time;
122 90 $self->{_timeout} = 1;
123 warn "Waiting for response\n"
124 90 ▶ if ($ENV{VERBOSE});
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"VERBOSE"} 0 90 90
125 90 my $resp = $self->nextresponse();
126 90 my $now = time;
127 90 ▶ if (($now - $lasttick) >= $self->{_tick})
Branch: 1 branch
BranchTrueFalseTotal
if ($now - $lasttick >= $self->{"_tick"}) 17 73 90
128 {
129 17 $self->handle_tick;
130 17 $lasttick = $now;
131 }
132 90 ▶ if (!$resp)
Branch: 1 branch
BranchTrueFalseTotal
unless ($resp) 17 73 90
133 {
134 17 ▶ if ($self->{auth_state} < 1)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"auth_state"} < 1) 0 17 17
135 {
136 0 ▶ if ((time - $started_waiting) < $self->{_timeout})
Branch: 1 branch
BranchTrueFalseTotal
if (time - $started_waiting < $self->{"_timeout"}) 0 0 0
137 {
138 0 $self->auth_failure(EKAHAU_ERR_AUTH_TIMEOUT);
139 0 $self->abort;
140 0 exit(0);
141 }
142 }
143 17 next;
144 }
145  
146  
147 73 ▶ if (uc $resp->{cmd} eq 'CLOSE')
Branch: 13 branches
BranchTrueFalseTotal
if (uc $resp->{'cmd'} eq 'CLOSE') { } 9 64 73
elsif (uc $resp->{'cmd'} eq 'HELLO') { } 9 55 64
elsif (uc $resp->{'cmd'} eq 'TALK') { } 9 46 55
elsif ($self->{'auth_state'} < 1) { } 0 46 46
elsif (uc $resp->{'cmd'} eq 'GET_DEVICE_LIST') { } 11 35 46
elsif (uc $resp->{'cmd'} eq 'GET_DEVICE_PROPERTIES') { } 5 30 35
elsif (uc $resp->{'cmd'} eq 'GET_LOGICAL_AREAS') { } 2 28 30
elsif (uc $resp->{'cmd'} eq 'GET_CONTEXT') { } 5 23 28
elsif (uc $resp->{'cmd'} eq 'GET_MAP') { } 4 19 23
elsif (uc $resp->{'cmd'} eq 'START_LOCATION_TRACK') { } 5 14 19
elsif (uc $resp->{'cmd'} eq 'START_AREA_TRACK') { } 6 8 14
elsif (uc $resp->{'cmd'} eq 'STOP_LOCATION_TRACK') { } 4 4 8
elsif (uc $resp->{'cmd'} eq 'STOP_AREA_TRACK') { } 4 0 4
148 {
149 9 $self->handle_close($resp);
150 9 return;
151 }
152 elsif (uc $resp->{cmd} eq 'HELLO')
153 {
154 9 $self->handle_hello($resp);
155 }
156 elsif (uc $resp->{cmd} eq 'TALK')
157 {
158 9 $self->handle_talk($resp);
159 }
160 elsif ($self->{auth_state} < 1)
161 {
162 warn "Not authorized for this command\n"
163 0 ▶ if ($ENV{VERBOSE});
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"VERBOSE"} 0 0 0
164 # This is a fatal error.
165 0 return $self->auth_failure(EKAHAU_ERR_MALFORMED_REQUEST);
166 }
167 elsif (uc $resp->{cmd} eq 'GET_DEVICE_LIST')
168 {
169 11 $self->handle_devlist($resp);
170 }
171 elsif (uc $resp->{cmd} eq 'GET_DEVICE_PROPERTIES')
172 {
173 5 $self->handle_devprop($resp);
174 }
175 elsif (uc $resp->{cmd} eq 'GET_LOGICAL_AREAS')
176 {
177 2 $self->handle_getla($resp);
178 }
179 elsif (uc $resp->{cmd} eq 'GET_CONTEXT')
180 {
181 5 $self->handle_getctx($resp);
182 }
183 elsif (uc $resp->{cmd} eq 'GET_MAP')
184 {
185 4 $self->handle_getmap($resp);
186 }
187 elsif (uc $resp->{cmd} eq 'START_LOCATION_TRACK')
188 {
189 5 $self->handle_loctrack($resp);
190 }
191 elsif (uc $resp->{cmd} eq 'START_AREA_TRACK')
192 {
193 6 $self->handle_areatrack($resp);
194 }
195 elsif (uc $resp->{cmd} eq 'STOP_LOCATION_TRACK')
196 {
197 4 $self->handle_stoploctrack($resp);
198 }
199 elsif (uc $resp->{cmd} eq 'STOP_AREA_TRACK')
200 {
201 4 $self->handle_stopareatrack($resp);
202 }
203 else
204 {
205 0 warn "Didn't recognize command '$resp->{cmd}'\n";
206 }
207 }
208 }
209  
210 sub handle_close
211 9 ▶{
Subroutine handle_close: called CC=1 SCAR=0.0
Pod undocumented
212 9 my $self = shift;
213 9 my($resp)=@_;
214  
215 9 $self->abort();
216 }
217  
218 sub handle_hello
219 9 ▶{
Subroutine handle_hello: called CC=2 SCAR=7.4
Pod undocumented
220 9 my $self = shift;
221 9 my($resp)=@_;
222  
223 9 ▶ if ($resp->{args}[0] != 1)
Branch: 1 branch
BranchTrueFalseTotal
if ($resp->{"args"}[0] != 1) 0 9 9
224 {
225 # Should do better errors.
226 0 die "Bad protocol version\n";
227 }
228 9 $self->{hello} = $resp;
229 }
230  
231 sub handle_talk
232 9 ▶{
Subroutine handle_talk: called CC=14 SCAR=30.2
Pod undocumented
233 9 my $self = shift;
234 9 my($resp)=@_;
235 9 ▶ if (!$self->{hello})
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"hello"}) 0 9 9
236 {
237 0 return $self->auth_failure(EKAHAU_ERR_MALFORMED_REQUEST);
238 }
239  
240 9 ▶ if ($resp->{args}[0] ne 'yax' or
Branch: 1 branch
BranchTrueFalseTotal
if ($resp->{"args"}[0] ne "yax" or $resp->{"args"}[1] != 1 or $resp->{"args"}[2] ne "yax1" or $resp->{"args"}[3] ne "MD5") 0 9 9
Condition33%3/9
$resp->{"args"}[0] ne "yax" or $resp->{"args"}[1] != 1 or $resp->{"args"}[2] ne "yax1" or $resp->{"args"}[3] ne "MD5"
l!l&&r!l&&!r
009
$resp->{"args"}[0] ne "yax" or $resp->{"args"}[1] != 1 or $resp->{"args"}[2] ne "yax1"
l!l&&r!l&&!r
009
$resp->{"args"}[0] ne "yax" or $resp->{"args"}[1] != 1
l!l&&r!l&&!r
009
MC/DC0%0/4
$resp->{"args"}[0] ne "yax" or $resp->{"args"}[1] != 1 or $resp->{"args"}[2] ne "yax1" or $resp->{"args"}[3] ne "MD5"
$resp->{"args"}[0] ne "yax" $resp->{"args"}[1] != 1 $resp->{"args"}[2] ne "yax1" $resp->{"args"}[3] ne "MD5"
Truth table20%1/5
A or B or C or D
A= $resp->{"args"}[0] ne "yax"B= $resp->{"args"}[1] != 1C= $resp->{"args"}[2] ne "yax1"D= $resp->{"args"}[3] ne "MD5"
ABCDresult
1XXX1
01XX1
001X1
00011
00000
241 $resp->{args}[1] != 1 or
242 $resp->{args}[2] ne 'yax1' or
243 $resp->{args}[3] ne 'MD5')
244 {
245 0 return $self->auth_failure(EKAHAU_ERR_UNSUPPORTED_PROTOCOL);
246 }
247
248 9 ▶ if ($resp->{args}[4] eq '')
Branch: 1 branch
BranchTrueFalseTotal
if ($resp->{'args'}[4] eq '') { } 6 3 9
249 {
250 # Anonymous Login
251 6 ▶ if (!$self->{hello}{params}{password} or $self->{hello}{params}{password} ne $self->{_password})
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{"hello"}{"params"}{"password"} or $self->{"hello"}{"params"}{"password"} ne $self->{"_password"}) 1 5 6
Condition66%2/3
not $self->{"hello"}{"params"}{"password"} or $self->{"hello"}{"params"}{"password"} ne $self->{"_password"}
l!l&&r!l&&!r
015
MC/DC50%1/2
not $self->{"hello"}{"params"}{"password"} or $self->{"hello"}{"params"}{"password"} ne $self->{"_password"}
not $self->{"hello"}{"params"}{"password"} $self->{"hello"}{"params"}{"password"} ne $self->{"_password"}
Truth table66%2/3
not(A) or B
A= not $self->{"hello"}{"params"}{"password"}B= $self->{"hello"}{"params"}{"password"} ne $self->{"_password"}
ABresult
1X1
011
000
252 {
253 1 return $self->auth_failure(EKAHAU_ERR_AUTHENTICATION_FAILED);
254 }
255 5 ▶ $self->command(['TALK','yax',1,'yax1','MD5','blahblahblah'])
Branch: 1 branch
BranchTrueFalseTotal
$self->command(["TALK", "yax", 1, "yax1", "MD5", "blahblahblah"]) or die "Couldn't send TALK response\n" 5 0 5
256 or die "Couldn't send TALK response\n";
257 5 $self->{auth_state} = 1;
258 }
259 else
260 {
261 # License Login
262 3 ▶ if (!$self->{_license})
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"_license"}) 0 3 3
263 {
264 0 return $self->auth_failure(EKAHAU_ERR_AUTHENTICATION_FAILED);
265 }
266  
267 my $digest = $self->{_license}->talk_str(HelloStr => $self->{_rand_str},
268 3 Password => $self->{_password});
269 3 ▶ if (!$digest or $digest ne $resp->{args}[4])
Branch: 1 branch
BranchTrueFalseTotal
if (not $digest or $digest ne $resp->{"args"}[4]) 2 1 3
Condition66%2/3
not $digest or $digest ne $resp->{"args"}[4]
l!l&&r!l&&!r
021
MC/DC50%1/2
not $digest or $digest ne $resp->{"args"}[4]
not $digest $digest ne $resp->{"args"}[4]
Truth table66%2/3
not(A) or B
A= not $digestB= $digest ne $resp->{"args"}[4]
ABresult
1X1
011
000
270 {
271 2 return $self->auth_failure(EKAHAU_ERR_AUTHENTICATION_FAILED);
272 }
273
274 $digest = $self->{_license}->talk_str(HelloStr => $self->{hello}{args}[1],
275 1 Password => $self->{_password});
276  
277 1 ▶ $self->command(['TALK','yax',1,'yax1','MD5',$digest])
Branch: 1 branch
BranchTrueFalseTotal
$self->command(["TALK", "yax", 1, "yax1", "MD5", $digest]) or die "Couldn't send TALK response\n" 1 0 1
278 or die "Couldn't send TALK response\n";
279 1 $self->{auth_state} = 2;
280 }
281
282 }
283  
284 sub auth_failure
285 3 ▶{
Subroutine auth_failure: called CC=1 SCAR=0.0
Pod undocumented
286 3 my $self = shift;
287 3 my($reason) = @_;
288 3 $self->command(['FAILURE',$reason]);
289 3 undef;
290 }
291  
292 sub handle_devlist
293 11 ▶{
Subroutine handle_devlist: called CC=1 SCAR=0.0
Pod undocumented
294 11 my $self = shift;
295 11 my($resp)=@_;
296 11 $self->reply($resp,'DEVICE_LIST',{ map { ($_ => [{}]) } 1..@{$self->{_devices}}});
297 }
298  
299 sub handle_devprop
300 5 ▶{
Subroutine handle_devprop: called CC=4 SCAR=14.2
Pod undocumented
301 5 my $self = shift;
302 5 my($resp)=@_;
303 5 my $whichdev = $resp->{args}[0];
304
305 5 ▶ if (defined($whichdev) and $whichdev =~ /^\d+$/ and (my $dev = $self->{_devices}[$whichdev-1]))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $whichdev and $whichdev =~ /^\d+$/ and my $dev = $self->{'_devices'}[$whichdev - 1]) { } 3 2 5
Condition50%3/6
defined $whichdev and $whichdev =~ /^\d+$/ and my $dev = $self->{"_devices"}[$whichdev - 1]
!ll&&!rl&&r
023
defined $whichdev and $whichdev =~ /^\d+$/
!ll&&!rl&&r
005
MC/DC33%1/3
defined $whichdev and $whichdev =~ /^\d+$/ and my $dev = $self->{"_devices"}[$whichdev - 1]
defined $whichdev $whichdev =~ /^\d+$/ my $dev = $self->{"_devices"}[$whichdev - 1]
Truth table50%2/4
A and B and C
A= defined $whichdevB= $whichdev =~ /^\d+$/C= my $dev = $self->{"_devices"}[$whichdev - 1]
ABCresult
0XX0
10X0
1100
1111
306 {
307 3 $self->reply($resp,['DEVICE_PROPERTIES',$whichdev],$dev->{props});
308 }
309 else
310 {
311 2 $self->reply($resp,['GET_DEVICE_PROPERTIES_FAILED'],
312 {errorCode => -601,
313 errorLevel => 3});
314  
315 }
316 }
317  
318 sub handle_getla
319 2 ▶{
Subroutine handle_getla: called CC=1 SCAR=0.0
Pod undocumented
320 2 my $self = shift;
321 2 my($resp)=@_;
322  
323 2 $self->reply($resp,'AREALIST',{ AREA => [ values %{$self->{_contexts}} ] });
324 }
325  
326 sub handle_getctx
327 5 ▶{
Subroutine handle_getctx: called CC=3 SCAR=11.0
Pod undocumented
328 5 my $self = shift;
329 5 my($resp)=@_;
330 5 my $whichctx = $resp->{args}[0];
331 5 ▶ if (defined($whichctx) and (my $ctx = $self->{_contexts}{$whichctx}))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $whichctx and my $ctx = $self->{'_contexts'}{$whichctx}) { } 3 2 5
Condition66%2/3
defined $whichctx and my $ctx = $self->{"_contexts"}{$whichctx}
!ll&&!rl&&r
023
MC/DC50%1/2
defined $whichctx and my $ctx = $self->{"_contexts"}{$whichctx}
defined $whichctx my $ctx = $self->{"_contexts"}{$whichctx}
Truth table66%2/3
A and B
A= defined $whichctxB= my $ctx = $self->{"_contexts"}{$whichctx}
ABresult
0X0
100
111
332 {
333 3 $self->reply($resp,['CONTEXT',$whichctx],$ctx);
334 }
335 else
336 {
337 2 $self->reply($resp,['CONTEXT_NOT_FOUND',$whichctx],{});
338 }
339 }
340  
341 sub handle_getmap
342 4 ▶{
Subroutine handle_getmap: called CC=3 SCAR=12.3
Pod undocumented
343 4 my $self = shift;
344 4 my($resp)=@_;
345  
346 4 my $whichmap = $resp->{args}[0];
347 4 ▶ if ($whichmap and $self->{_maps}{$whichmap})
Branch: 1 branch
BranchTrueFalseTotal
if ($whichmap and $self->{'_maps'}{$whichmap}) { } 4 0 4
Condition33%1/3
$whichmap and $self->{"_maps"}{$whichmap}
!ll&&!rl&&r
004
MC/DC0%0/2
$whichmap and $self->{"_maps"}{$whichmap}
$whichmap $self->{"_maps"}{$whichmap}
Truth table33%1/3
A and B
A= $whichmapB= $self->{"_maps"}{$whichmap}
ABresult
0X0
100
111
348 {
349 4 $self->reply($resp,['MAP',$whichmap],{ type => 'png', data => \$self->{_maps}{$whichmap} });
350 }
351 else
352 {
353 0 $self->reply($resp,['MAP_NOT_FOUND',$whichmap],{});
354 }
355 }
356  
357 sub handle_loctrack
358 5 ▶{
Subroutine handle_loctrack: called CC=7 SCAR=19.8
Pod undocumented
359 5 my $self = shift;
360 5 my($req)=@_;
361 5 my $dev;
362  
363 5 eval {
364 5 ▶ $dev = $req->{args}[0]
Branch: 1 branch
BranchTrueFalseTotal
$dev = $req->{"args"}[0] or die "no dev" 5 0 5
365 or die "no dev";
366 5 ▶ $dev =~ /^\d+$/
Branch: 1 branch
BranchTrueFalseTotal
$dev =~ /^\d+$/ or die "bad dev" 5 0 5
367 or die "bad dev";
368 my $loctrack = $self->{_devices}[$dev-1]{location_track}
369 5 ▶ or die "no locator";
Branch: 1 branch
BranchTrueFalseTotal
my $loctrack = $self->{"_devices"}[$dev - 1]{"location_track"} or die "no locator" 4 1 5
370
371 4 push(@{$self->{loctrack}},{req => $req, dev => $dev, track => $loctrack});
372 warn "Starting location tracking of '$dev'\n"
373 4 ▶ if ($ENV{VERBOSE});
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"VERBOSE"} 0 4 4
374 };
375 5 ▶ if ($@)
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 1 4 5
376 {
377 1 ▶ $self->reply($req,['START_LOCATION_TRACK_FAILED',defined($dev)?$dev:'?'],
Branch: 1 branch
BranchTrueFalseTotal
defined $dev ? : 1 0 1
378 {errorCode => -600,
379 errorLevel => 2});
380 }
381
382 }
383  
384 sub handle_stoploctrack
385 4 ▶{
Subroutine handle_stoploctrack: called CC=9 SCAR=23.3
Pod undocumented
386 4 my $self = shift;
387 4 my($req)=@_;
388 4 my $dev;
389  
390 4 eval {
391 4 ▶ $dev = $req->{args}[0]
Branch: 1 branch
BranchTrueFalseTotal
$dev = $req->{"args"}[0] or die "no dev" 4 0 4
392 or die "no dev";
393 4 ▶ $dev =~ /^\d+$/
Branch: 1 branch
BranchTrueFalseTotal
$dev =~ /^\d+$/ or die "bad dev" 4 0 4
394 or die "bad dev";
395 4 my $deleted;
396
397 4 foreach my $i (0..$#{$self->{loctrack}})
398 {
399 4 ▶ if ($self->{loctrack}[$i]{dev} == $dev)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"loctrack"}[$i]{"dev"} == $dev) 4 0 4
400 {
401 # Remove that element
402 4 $deleted = splice(@{$self->{loctrack}},$i,1);
403 warn "Stopped location tracking of '$dev'\n"
404 4 ▶ if ($ENV{VERBOSE});
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"VERBOSE"} 0 4 4
405 4 last;
406 }
407 }
408 $deleted
409 4 ▶ or die "no such dev";
Branch: 1 branch
BranchTrueFalseTotal
$deleted or die "no such dev" 4 0 4
410 };
411 4 ▶ if ($@)
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 4 4
412 {
413 0 $self->reply($req,'STOP_LOCATION_TRACK_FAILED',
414 {errorCode => -600,
415 errorLevel => 2});
416 }
417 else
418 {
419 4 ▶ $self->reply($req,['STOP_LOCATION_TRACK_OK',defined($dev)?$dev:'?'],{});
Branch: 1 branch
BranchTrueFalseTotal
defined $dev ? : 4 0 4
420 }
421 }
422  
423  
424 sub handle_areatrack
425 6 ▶{
Subroutine handle_areatrack: called CC=7 SCAR=19.8
Pod undocumented
426 6 my $self = shift;
427 6 my($req)=@_;
428 6 my $dev;
429  
430 6 eval {
431 6 ▶ $dev = $req->{args}[0]
Branch: 1 branch
BranchTrueFalseTotal
$dev = $req->{"args"}[0] or die "no dev" 6 0 6
432 or die "no dev";
433 6 ▶ $dev =~ /^\d+$/
Branch: 1 branch
BranchTrueFalseTotal
$dev =~ /^\d+$/ or die "bad dev" 6 0 6
434 or die "bad dev";
435 my $track = $self->{_devices}[$dev-1]{area_track}
436 6 ▶ or die "no area tracker";
Branch: 1 branch
BranchTrueFalseTotal
my $track = $self->{"_devices"}[$dev - 1]{"area_track"} or die "no area tracker" 4 2 6
437 4 push(@{$self->{areatrack}},{req => $req, dev => $dev, track => $track});
438 warn "Starting area tracking of '$dev'\n"
439 4 ▶ if ($ENV{VERBOSE});
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"VERBOSE"} 0 4 4
440 };
441 6 ▶ if ($@)
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 2 4 6
442 {
443 2 ▶ $self->reply($req,['START_AREA_TRACK_FAILED',defined($dev)?$dev:'?'],
Branch: 1 branch
BranchTrueFalseTotal
defined $dev ? : 2 0 2
444 {errorCode => -600,
445 errorLevel => 2});
446 }
447
448 }
449  
450 sub handle_stopareatrack
451 4 ▶{
Subroutine handle_stopareatrack: called CC=9 SCAR=23.3
Pod undocumented
452 4 my $self = shift;
453 4 my($req)=@_;
454 4 my $dev;
455  
456 4 eval {
457 4 ▶ $dev = $req->{args}[0]
Branch: 1 branch
BranchTrueFalseTotal
$dev = $req->{"args"}[0] or die "no dev" 4 0 4
458 or die "no dev";
459 4 ▶ $dev =~ /^\d+$/
Branch: 1 branch
BranchTrueFalseTotal
$dev =~ /^\d+$/ or die "bad dev" 4 0 4
460 or die "bad dev";
461 4 my $deleted;
462  
463 4 foreach my $i (0..$#{$self->{areatrack}})
464 {
465 4 ▶ if ($self->{areatrack}[$i]{dev} == $dev)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"areatrack"}[$i]{"dev"} == $dev) 4 0 4
466 {
467 # Remove that element
468 4 $deleted = splice(@{$self->{areatrack}},$i,1);
469 warn "Stopped area tracking of '$dev'\n"
470 4 ▶ if ($ENV{VERBOSE});
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"VERBOSE"} 0 4 4
471 4 last;
472 }
473 }
474 $deleted
475 4 ▶ or die "no such dev";
Branch: 1 branch
BranchTrueFalseTotal
$deleted or die "no such dev" 4 0 4
476 };
477 4 ▶ if ($@)
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 4 4
478 {
479 0 $self->reply($req,'STOP_AREA_TRACK_FAILED',
480 {errorCode => -600,
481 errorLevel => 2});
482 }
483 else
484 {
485 4 ▶ $self->reply($req,['STOP_AREA_TRACK_OK',defined($dev)?$dev:'?'],{});
Branch: 1 branch
BranchTrueFalseTotal
defined $dev ? : 4 0 4
486 }
487 }
488  
489 sub handle_tick
490 17 ▶{
Subroutine handle_tick: called CC=3 SCAR=11.0
Pod undocumented
491 17 my $self = shift;
492  
493 17 foreach my $track (@{$self->{loctrack}})
494 {
495 11 $track->{track}->($self,$track->{dev},$track->{req});
496 }
497 17 foreach my $track (@{$self->{areatrack}})
498 {
499 9 $track->{track}->($self,$track->{dev},$track->{req});
500 }
501 }
502  
503 sub static_location
504 23 ▶{
Subroutine static_location: called CC=1 SCAR=0.0
Pod undocumented
505 23 my($loc)=@_;
506  
507 11 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
508 11 my($self,$dev,$req)=@_;
509 11 my $now = time;
510 11 $self->reply($req,['LOCATION_ESTIMATE',$dev],
511 {%$loc,
512 accurateTime => $now,
513 latestTime => $now,
514 });
515 23 };
516 }
517  
518 sub static_area
519 23 ▶{
Subroutine static_area: called CC=1 SCAR=0.0
Pod undocumented
520 23 my($area) = @_;
521 9 ▶ sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
522 9 my($self,$dev,$req)=@_;
523 9 ▶ my $numresp = $req->{params}{'EPE.NUMBER_OF_AREAS'} || 1;
Condition100%2/2
$req->{'params'}{'EPE.NUMBER_OF_AREAS'} || 1
l!l
54
MC/DC100%1/1
$req->{'params'}{'EPE.NUMBER_OF_AREAS'} || 1
$req->{'params'}{'EPE.NUMBER_OF_AREAS'}
Truth table100%2/2
A
A= $req->{'params'}{'EPE.NUMBER_OF_AREAS'}
Aresult
11
00
524 9 ▶ if ($numresp > @$area)
Branch: 1 branch
BranchTrueFalseTotal
if ($numresp > @$area) 2 7 9
525 {
526 2 my $ta = { %{$area->[$#{$area}]} };
527 2 $ta->{probability} = 0;
528 2 foreach my $i (scalar(@$area)..$numresp)
529 {
530 4 push(@$area,$ta);
531 }
532 }
533  
534 $self->reply($req,['AREA_ESTIMATE',$dev],
535 {
536 9 AREA => [@{$area}[0..$numresp-1] ],
537 });
538 23 };
539 }
540  
541 package Ekahau::Server::Test::Listener;
542 15 ▶use base 'Ekahau::Server::Listener';
Subroutine BEGIN: called CC=1 SCAR=0.0
543  
544 sub accept
545 0 ▶{
Subroutine accept: not called CC=3 SCAR=24.8
546 0 my $self = shift;
547 0 ▶ my $obj = $self->SUPER::accept(@_,'Ekahau::Server::Test')
Branch: 1 branch
BranchTrueFalseTotal
my $obj = $self->SUPER::accept(@_, "Ekahau::Server::Test") or return undef 0 0 0
548 or return undef;
549 0 ▶ $obj->{_password}=$self->{_password}||Ekahau::Server::Test::DEFAULT_PASSWORD;
Condition0%0/2
$self->{'_password'} || 'Llama'
l!l
00
MC/DC0%0/1
$self->{'_password'} || 'Llama'
$self->{'_password'}
Truth table0%0/2
A
A= $self->{'_password'}
Aresult
11
00
550 0 $obj;
551 }
552  
553 package Ekahau::Server::Test::Background;
554 15 ▶use base 'Ekahau::Server::Test';
Subroutine BEGIN: called CC=1 SCAR=0.0
555  
556 15 ▶use Symbol;
Subroutine BEGIN: called CC=1 SCAR=0.0
557 15 ▶use Socket;
Subroutine BEGIN: called CC=1 SCAR=0.0
558  
559 sub start
560 28 ▶{
Subroutine start: called CC=7 SCAR=21.8
561 28 my $class = shift;
562  
563 28 my $server_side = gensym;
564 28 my $client_side = gensym;
565  
566 28 ▶ socketpair($server_side, $client_side, AF_UNIX, SOCK_STREAM, PF_UNSPEC)
Branch: 1 branch
BranchTrueFalseTotal
socketpair $server_side, $client_side, 1, 1, 0 or return undef 28 0 28
567 or return undef;
568  
569 28 ▶ my $server = $class->new(Socket => $server_side,
Branch: 1 branch
BranchTrueFalseTotal
my $server = $class->new("Socket", $server_side, "Timeout", 10, @_) or return undef 28 0 28
570 Timeout => 10,
571 @_
572 )
573 or return undef;
574  
575 28 ▶ if (!defined(my $fork = fork))
Branch: 2 branches
BranchTrueFalseTotal
if (not defined(my $fork = fork)) { } 0 28 28
elsif (not $fork) { } 9 19 28
576 {
577 0 return undef;
578 0 die "fork error: $!\n";
579 }
580 elsif (!$fork)
581 {
582 9 eval {
583 # Child
584 9 close($client_side);
585 9 delete $ENV{VERBOSE};
586 $ENV{VERBOSE}=$ENV{VERBOSE_SERVER}
587 9 ▶ if($ENV{VERBOSE_SERVER});
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"VERBOSE_SERVER"} 0 9 9
588 9 $server->run;
589 9 exit(0);
590 };
591 0 ▶ warn $@
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
592 if ($@);
593 0 exit(-1);
594 }
595
596 19 close($server_side);
597 19 return $client_side;
598 }
599  
600 =head1 AUTHOR
601  
602 Scott Gifford E<lt>gifford@umich.eduE<gt>, E<lt>sgifford@suspectclass.comE<gt>
603  
604 Copyright (C) 2005 The Regents of the University of Michigan.
605  
606 See the file LICENSE included with the distribution for license
607 information.
608  
609 =cut
610  
611 15 1;
« lib/Ekahau.pm ↑ Summary lib/Ekahau/Response.pm »