line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FusionInventory::Agent::HTTP::Client::Fusion; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
21158280
|
use strict; |
|
3
|
|
|
|
|
20
|
|
|
3
|
|
|
|
|
144
|
|
4
|
3
|
|
|
3
|
|
19
|
use warnings; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
115
|
|
5
|
3
|
|
|
3
|
|
12
|
use base 'FusionInventory::Agent::HTTP::Client'; |
|
3
|
|
|
|
|
29
|
|
|
3
|
|
|
|
|
1283
|
|
6
|
|
|
|
|
|
|
|
7
|
3
|
|
|
3
|
|
17
|
use JSON; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
40
|
|
8
|
3
|
|
|
3
|
|
511
|
use HTTP::Request; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
22
|
|
9
|
3
|
|
|
3
|
|
66
|
use URI::Escape; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
1483
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new { |
12
|
0
|
|
|
0
|
1
|
|
my ($class, %params) = @_; |
13
|
|
|
|
|
|
|
|
14
|
0
|
|
|
|
|
|
my $self = $class->SUPER::new(%params); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# Stack the messages sent in order to be able to check the |
17
|
|
|
|
|
|
|
# correctness of the behavior with the test-suite |
18
|
0
|
0
|
|
|
|
|
if ($params{debug}) { |
19
|
0
|
|
|
|
|
|
$self->{debug} = 1; |
20
|
0
|
|
|
|
|
|
$self->{msgStack} = [] |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
0
|
|
|
|
|
|
return $self; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub _prepareVal { |
27
|
0
|
|
|
0
|
|
|
my ($self, $val) = @_; |
28
|
|
|
|
|
|
|
|
29
|
0
|
0
|
|
|
|
|
return '' unless length($val); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# forbid to long argument. |
32
|
0
|
|
|
|
|
|
while (length(URI::Escape::uri_escape_utf8($val)) > 1500) { |
33
|
0
|
|
|
|
|
|
$val =~ s/^.{5}/…/; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
return URI::Escape::uri_escape_utf8($val); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub send { ## no critic (ProhibitBuiltinHomonyms) |
40
|
0
|
|
|
0
|
1
|
|
my ($self, %params) = @_; |
41
|
|
|
|
|
|
|
|
42
|
0
|
0
|
|
|
|
|
push @{$self->{msgStack}}, $params{args} if $self->{debug}; |
|
0
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
|
44
|
0
|
0
|
|
|
|
|
my $url = ref $params{url} eq 'URI' ? |
45
|
|
|
|
|
|
|
$params{url} : URI->new($params{url}); |
46
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
my $finalUrl = $url.'?action='.uri_escape($params{args}->{action}); |
48
|
0
|
|
|
|
|
|
foreach my $k (keys %{$params{args}}) { |
|
0
|
|
|
|
|
|
|
49
|
0
|
0
|
0
|
|
|
|
if (ref($params{args}->{$k}) eq 'ARRAY') { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
foreach (@{$params{args}->{$k}}) { |
|
0
|
|
|
|
|
|
|
51
|
0
|
|
0
|
|
|
|
$finalUrl .= '&'.$k.'[]='.$self->_prepareVal($_ || ''); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
} elsif (ref($params{args}->{$k}) eq 'HASH') { |
54
|
0
|
|
|
|
|
|
foreach (keys %{$params{args}->{$k}}) { |
|
0
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
$finalUrl .= '&'.$k.'['.$_.']='.$self->_prepareVal($params{args}->{$k}{$_}); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
} elsif ($k ne 'action' && length($params{args}->{$k})) { |
58
|
0
|
|
|
|
|
|
$finalUrl .= '&'.$k.'='.$self->_prepareVal($params{args}->{$k}); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
0
|
0
|
|
|
|
|
$self->{logger}->debug2($finalUrl) if $self->{logger}; |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
my $request = HTTP::Request->new(GET => $finalUrl); |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
my $response = $self->request($request); |
67
|
|
|
|
|
|
|
|
68
|
0
|
0
|
|
|
|
|
return unless $response; |
69
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
return eval { from_json( $response->content(), { utf8 => 1 } ) }; |
|
0
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
1; |
74
|
|
|
|
|
|
|
__END__ |