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