DBus/Parser.pm

filter: Statementstmt 73.3% 55 / 75 Branchbran 36.3% 16 / 44 Conditioncond 14.2% 2 / 14 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 90.0% 9 / 10 Podpod 0.0% 0 / 3 totaltotal 52.9% 82 / 155 SCAR 46.0
CC
28
Cov
55%
get_message
132.1
preserve_variant_signatures
6.0
BEGIN
1.0
CRAP 100.0
« DBus/Authn.pm ↑ Summary DBus/Marshal.pm »
1 package Protocol::DBus::Parser;
2  
3 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 5 ▶use Protocol::DBus::Marshal ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use Protocol::DBus::Message ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 5 ▶use constant SINGLE_UNIX_FD_CMSGHDR => (0, 0, pack 'I!');
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 5 ▶use constant _LE_INIT_UNPACK => 'x4 V x4 V';
Subroutine BEGIN: called CC=1 SCAR=0.0
12 5 ▶use constant _BE_INIT_UNPACK => 'x4 N x4 N';
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 sub new {
15 2 ▶ my ($class, $socket) = @_;
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
16  
17 2 return bless { _s => $socket, _buf => q<> }, $class;
18 }
19  
20 sub get_message {
21 3 ▶ my ($self) = @_;
Subroutine get_message: called CC=27 SCAR=48.8
Pod undocumented
22  
23 3 my $msg;
24  
25 3 ▶ if (!$self->{'_bodysz'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"_bodysz"}) 3 0 3
26 3 ▶ if (defined recv( $self->{'_s'}, my $peek, 16, Socket::MSG_PEEK() )) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined recv($self->{'_s'}, my $peek, 16, 2)) { } 3 0 3
elsif (not $!{'EAGAIN'} || $!{'EWOULDBLOCK'}) { } 0 0 0
27 3 ▶ if ( 16 == length $peek ) {
Branch: 1 branch
BranchTrueFalseTotal
if (16 == length $peek) 3 0 3
28 3 ▶ @{$self}{'_bodysz', '_hdrsz'} = unpack(
Branch: 1 branch
BranchTrueFalseTotal
0 == index($peek, 'B') ? : 0 3 3
29 (0 == index($peek, 'B')) ? _BE_INIT_UNPACK() : _LE_INIT_UNPACK(),
30 $peek,
31 );
32  
33 3 Protocol::DBus::Pack::align( $self->{'_hdrsz'}, 8 );
34  
35 3 $self->{'_msgsz'} = 16 + $self->{'_hdrsz'} + $self->{'_bodysz'};
36 }
37 }
38 ▶ elsif (!$!{'EAGAIN'} && !$!{'EWOULDBLOCK'}) {
Condition0%0/3
$!{'EAGAIN'} || $!{'EWOULDBLOCK'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$!{'EAGAIN'} || $!{'EWOULDBLOCK'}
$!{'EAGAIN'} $!{'EWOULDBLOCK'}
Truth table0%0/3
A || B
A= $!{'EAGAIN'}B= $!{'EWOULDBLOCK'}
ABresult
1X1
011
000
39 0 die "recv(): $!";
40 }
41 }
42  
43 3 ▶ if (defined $self->{'_bodysz'} && !defined $self->{'_unix_fds'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"_bodysz"} and not defined $self->{"_unix_fds"}) 3 0 3
Condition33%1/3
defined $self->{"_bodysz"} and not defined $self->{"_unix_fds"}
!ll&&!rl&&r
003
MC/DC0%0/2
defined $self->{"_bodysz"} and not defined $self->{"_unix_fds"}
defined $self->{"_bodysz"} not defined $self->{"_unix_fds"}
Truth table33%1/3
A and not(B)
A= defined $self->{"_bodysz"}B= not defined $self->{"_unix_fds"}
ABresult
0X0
100
111
44 3 ▶ if (defined recv( $self->{'_s'}, my $full_hdr, 16 + $self->{'_hdrsz'}, Socket::MSG_PEEK() )) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined recv($self->{'_s'}, my $full_hdr, 16 + $self->{'_hdrsz'}, 2)) { } 3 0 3
elsif (not $!{'EAGAIN'} || $!{'EWOULDBLOCK'}) { } 0 0 0
45 3 ▶ if ( length($full_hdr) == 16 + $self->{'_hdrsz'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $full_hdr == 16 + $self->{"_hdrsz"}) 3 0 3
46 3 my ($hdr) = Protocol::DBus::Message::Header::parse_simple(\$full_hdr);
47  
48 3 ▶ $self->{'_unix_fds'} = $hdr->[6]{ Protocol::DBus::Message::Header::FIELD()->{'UNIX_FDS'} } || 0;
Condition50%1/2
$hdr->[6]{{DESTINATION => 6, ERROR_NAME => 4, INTERFACE => 2, MEMBER => 3, PATH => 1, REPLY_SERIAL => 5, SENDER => 7, SIGNATURE => 8, UNIX_FDS => 9}->{'UNIX_FDS'}} || 0
l!l
03
MC/DC0%0/1
$hdr->[6]{{DESTINATION => 6, ERROR_NAME => 4, INTERFACE => 2, MEMBER => 3, PATH => 1, REPLY_SERIAL => 5, SENDER => 7, SIGNATURE => 8, UNIX_FDS => 9}->{'UNIX_FDS'}} || 0
$hdr->[6]{{DESTINATION => 6, ERROR_NAME => 4, INTERFACE => 2, MEMBER => 3, PATH => 1, REPLY_SERIAL => 5, SENDER => 7, SIGNATURE => 8, UNIX_FDS => 9}->{'UNIX_FDS'}}
Truth table50%1/2
A
A= $hdr->[6]{{DESTINATION => 6, ERROR_NAME => 4, INTERFACE => 2, MEMBER => 3, PATH => 1, REPLY_SERIAL => 5, SENDER => 7, SIGNATURE => 8, UNIX_FDS => 9}->{'UNIX_FDS'}}
Aresult
11
00
49  
50 3 $self->{'_pending_unix_fds'} = $self->{'_unix_fds'};
51  
52 3 my $body_sig = $hdr->[6]{ Protocol::DBus::Message::Header::FIELD()->{'SIGNATURE'} };
53  
54 3 ▶ if ($hdr->[4]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hdr->[4]) 2 1 3
55 2 ▶ die "No SIGNATURE header field!" if !defined $body_sig;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $body_sig 0 2 2
56 }
57 }
58 }
59 ▶ elsif (!$!{'EAGAIN'} && !$!{'EWOULDBLOCK'}) {
Condition0%0/3
$!{'EAGAIN'} || $!{'EWOULDBLOCK'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$!{'EAGAIN'} || $!{'EWOULDBLOCK'}
$!{'EAGAIN'} $!{'EWOULDBLOCK'}
Truth table0%0/3
A || B
A= $!{'EAGAIN'}B= $!{'EWOULDBLOCK'}
ABresult
1X1
011
000
60 0 die "recv(): $!";
61 }
62 }
63  
64 3 ▶ if (defined $self->{'_unix_fds'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"_unix_fds"}) 3 0 3
65  
66 3 my $needed_bytes = $self->{'_msgsz'} - length $self->{'_buf'};
67  
68 3 my $got;
69  
70 3 ▶ if ($self->{'_unix_fds'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'_unix_fds'}) { } 0 3 3
71 0 my $msg = Socket::MsgHdr->new(
72 buflen => $needed_bytes,
73 );
74  
75 # The unix FDs might arrive in a single control
76 # message, as individual control messages, or as
77 # some combination thereof. There is no way to know.
78 # So plan for the worst, and assume each unix FD is
79 # in its own control.
80 0 $msg->cmsghdr( (SINGLE_UNIX_FD_CMSGHDR()) x $self->{'_pending_unix_fds'} );
81  
82 0 $got = Socket::MsgHdr::recvmsg( $self->{'_s'}, $msg );
83 0 ▶ if (defined $got) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $got) 0 0 0
84  
85 0 ▶ if ($self->{'_pending_unix_fds'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_pending_unix_fds"}) 0 0 0
86 0 require Protocol::DBus::Parser::UnixFDs;
87 0 push @{ $self->{'_filehandles'} }, Protocol::DBus::Parser::UnixFDs::extract_from_msghdr($msg);
88 0 $self->{'_pending_unix_fds'} = $self->{'_unix_fds'} - @{ $self->{'_filehandles'} };
89 }
90  
91 0 $self->{'_buf'} .= $msg->buf();
92 }
93 }
94 else {
95 $got = sysread(
96 $self->{'_s'},
97 $self->{'_buf'},
98 $needed_bytes,
99 3 length $self->{'_buf'},
100 );
101 }
102  
103 3 ▶ if (defined $got) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $got) { } 3 0 3
elsif (not $!{'EAGAIN'} || $!{'EWOULDBLOCK'}) { } 0 0 0
104 3 ▶ if ($got >= $needed_bytes) {
Branch: 2 branches
BranchTrueFalseTotal
if ($got >= $needed_bytes) { } 3 0 3
elsif (not $got) { } 0 0 0
105 3 ▶ local $Protocol::DBus::Marshal::PRESERVE_VARIANT_SIGNATURES = 1 if $self->{'_preserve_variant_signatures'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_preserve_variant_signatures"} 0 3 3
106  
107 # This clears out the buffer .. it should??
108 3 my $msg = Protocol::DBus::Message->parse( \$self->{'_buf'}, delete $self->{'_filehandles'} );
109  
110 3 ▶ die "Not enough bytes??" if !$msg;
Branch: 1 branch
BranchTrueFalseTotal
unless $msg 0 3 3
111  
112 3 delete @{$self}{'_bodysz', '_unix_fds'};
113  
114 3 return $msg;
115 }
116 elsif (!$got) {
117 0 die "Peer stopped writing!";
118 }
119 }
120 ▶ elsif (!$!{'EAGAIN'} && !$!{'EWOULDBLOCK'}) {
Condition0%0/3
$!{'EAGAIN'} || $!{'EWOULDBLOCK'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$!{'EAGAIN'} || $!{'EWOULDBLOCK'}
$!{'EAGAIN'} $!{'EWOULDBLOCK'}
Truth table0%0/3
A || B
A= $!{'EAGAIN'}B= $!{'EWOULDBLOCK'}
ABresult
1X1
011
000
121 0 die "recv(): $!";
122 }
123 }
124  
125 0 return undef;
126 }
127  
128 sub preserve_variant_signatures {
129 0 ▶ my $self = shift;
Subroutine preserve_variant_signatures: not called CC=2 SCAR=17.9
Pod undocumented
130  
131 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
132 0 $self->{'_preserve_variant_signatures'} = !!$_[0];
133 }
134  
135 0 return !!$self->{'_preserve_variant_signatures'};
136 }
137  
138 5 1;
« DBus/Authn.pm ↑ Summary DBus/Marshal.pm »