| 1 | package Net::QMTP; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | require 5.001; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use IO::Socket; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Text::Netstring qw(netstring_encode netstring_decode netstring_read | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | netstring_verify); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | # Copyright (c) 2003 James Raftery <james@now.ie>. All rights reserved. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | # This program is free software; you can redistribute it and/or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | # modify it under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | # Please submit bug reports, patches and comments to the author. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | # Latest information at http://romana.now.ie/#net-qmtp | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | # $Id: QMTP.pm,v 1.22 2004/11/02 14:56:18 james Exp $ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | # This module is an object interface to the Quick Mail Transfer Protocol | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | # (QMTP). QMTP is a replacement for the Simple Mail Transfer Protocol | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | # (SMTP). It offers increased speed, especially over high latency | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | # links, pipelining, 8-bit data transmission and predeclaration of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | # line-ending encoding. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | # See the Net::QMTP man page that was installed with this module for | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | # information on how to use the module. You require version 0.04 or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | # later of the Text::Netstring module. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 1 | ▶ | use vars qw($VERSION); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 1 | $VERSION = "0.06"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=17 SCAR=40.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 1 | ▶ | my $proto = shift or croak; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 1 | ▶ | my $class = ref($proto) || $proto; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 1 | ▶ | my $server = shift or croak "No server specified in constructor"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 1 | my %args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 1 | ▶ | %args = @_ if @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 1 | my $self = { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | SENDER => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | RECIPIENTS => [], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | MESSAGE => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | MSGFILE => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | ENCODING => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | SOCKET => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | SERVER => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | PORT => 209, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | DEBUG => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | TIMEOUT => undef, # use IO::Socket default | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | CONNECTTIME => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | SESSIONLIMIT => 3600, # 1 hour | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 1 | ▶ | if ($args{'Debug'}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | $self->{DEBUG} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | warn "debugging on; Version: $VERSION; RCS " . | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | qq$Revision: 1.22 $ . "\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 1 | ▶ | $self->{SERVER} = $server or croak "Constructor server failed"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 1 | ▶ | warn "server set to '$server'\n" if $self->{DEBUG}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 1 | bless($self, $class); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 1 | ▶ | unless ($self->encoding("__GUESS__")) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | carp "Constructor encoding() failed"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 1 | ▶ | if ($args{'ConnectTimeout'}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | $self->{TIMEOUT} = $args{'ConnectTimeout'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | warn "timeout ".$self->{TIMEOUT}."\n" if $self->{DEBUG}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 1 | ▶ | if ($args{'Port'}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | $self->{PORT} = $args{'Port'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | ▶ | warn "port set to ".$self->{PORT}."\n" if $self->{DEBUG}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 1 | ▶ | unless ($args{'DeferConnect'}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | warn "calling reconnect()\n" if $self->{DEBUG}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | ▶ | $self->reconnect() or return undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 1 | ▶ | warn "constructor finished\n" if $self->{DEBUG}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 1 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | sub reconnect { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
reconnect: not called CC=12 SCAR=50.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | ref($self) or croak; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | my $sock = $self->{SOCKET}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | # if have a socket, disconnect first | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | if (defined($sock)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | #carp "Socket is already defined"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | #return undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | ▶ | $self->disconnect() or return undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | # Applying timeout() to socket seems to fail. Hmm. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | ▶ | warn "opening socket to " . $self->{SERVER} . "\n" if $self->{DEBUG}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | if ($self->{TIMEOUT}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | ▶ | warn "socket timeout ".$self->{TIMEOUT}."\n" if $self->{DEBUG}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | $sock = IO::Socket::INET->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | PeerAddr => $self->{SERVER}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | PeerPort => $self->{PORT}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | Timeout => $self->{TIMEOUT}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | Proto => 'tcp') or return undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | warn "socket default timeout\n" if $self->{DEBUG}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | $sock = IO::Socket::INET->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | PeerAddr => $self->{SERVER}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | PeerPort => $self->{PORT}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | ▶ | Proto => 'tcp') or return undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | binmode($sock); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | $self->{SOCKET} = $sock; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | $sock->autoflush(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | ▶ | warn "socket opened to " . $sock->peerhost() . "\n" if $self->{DEBUG}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | $self->{CONNECTTIME} = time; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | ▶ | warn "connected at " . $self->{CONNECTTIME} . "\n" if $self->{DEBUG}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | return $self->{SOCKET}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 1 | ▶ | sub disconnect { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
disconnect: called CC=6 SCAR=27.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 1 | ▶ | ref($self) or croak; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 1 | my $sock = $self->{SOCKET}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | # can't disconnect if no socket | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 1 | ▶ | if (!defined($sock)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 1 | carp "Socket is not defined"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 1 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | ## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | ## Only on newer perls | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | ## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | ### can't disconnect if not connected | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | ##if (!$sock->connected()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | ## carp "Socket is not connected"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | ## $self->{SOCKET} = undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | ## return undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | ##} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | ▶ | warn "closing socket to " . $sock->peerhost() . "\n" if $self->{DEBUG}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | ▶ | unless (close $sock) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | carp "Cannot close socket: $!"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | $self->{SOCKET} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | warn "socket closed (was open for " . (time - $self->{CONNECTTIME}) . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | ▶ | "s)\n" if $self->{DEBUG}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 1 | ▶ | sub encoding { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
encoding: called CC=12 SCAR=38.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 1 | ▶ | ref($self) or croak; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 1 | ▶ | my $e = shift or return $self->{ENCODING}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | # guess from input record seperator | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 1 | ▶ | if ($e eq "__GUESS__") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 1 | ▶ | warn "guessing encoding\n" if $self->{DEBUG}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 1 | ▶ | if ($/ eq "\015\012") { # CRLF: Dos/Win | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | $self->{ENCODING} = "\015"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | ▶ | warn "guessed carraige-return encoding\n" if $self->{DEBUG}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | } else { # LF: Unix-like | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 1 | $self->{ENCODING} = "\012"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 1 | ▶ | warn "guessed line-feed encoding\n" if $self->{DEBUG}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | # specific encoding requested | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | } elsif ($e eq "dos") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | $self->{ENCODING} = "\015"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | ▶ | warn "set carraige-return encoding\n" if $self->{DEBUG}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | } elsif ($e eq "unix") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | $self->{ENCODING} = "\012"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | ▶ | warn "set line-feed encoding\n" if $self->{DEBUG}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | croak "Unknown encoding: '$e'"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | $self->{ENCODING} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 1 | return $self->{ENCODING}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 1 | ▶ | sub server { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
server: called CC=4 SCAR=14.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 1 | ▶ | ref($self) or croak; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 1 | ▶ | $self->{SERVER} = shift if @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 1 | ▶ | warn "server is " . $self->{SERVER} . "\n" if $self->{DEBUG}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 1 | return $self->{SERVER}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 3 | ▶ | sub sender { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sender: called CC=4 SCAR=14.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 3 | ▶ | ref($self) or croak; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 3 | ▶ | $self->{SENDER} = shift if @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 3 | ▶ | warn "sender is " . $self->{SENDER} . "\n" if $self->{DEBUG}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 3 | return $self->{SENDER}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 4 | ▶ | sub recipient { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
recipient: called CC=4 SCAR=14.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 4 | ▶ | ref($self) or croak; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 4 | ▶ | push(@{$self->{RECIPIENTS}}, shift) if @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | warn "recipients are ". join(",", @{$self->{RECIPIENTS}}) . | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 4 | ▶ | "\n" if $self->{DEBUG}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 4 | return $self->{RECIPIENTS}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 0 | ▶ | sub message { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
message: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | ▶ | ref($self) or croak; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | ▶ | warn "message() started\n" if $self->{DEBUG}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | ▶ | if ($self->{MSGFILE}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | carp "Message already created by message_from_file()"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | ▶ | $self->{MESSAGE} .= shift if @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | warn "message text appended (is now " . length($self->{MESSAGE}) . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | ▶ | " bytes)\n" if $self->{DEBUG}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | return $self->{MESSAGE}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | ▶ | sub message_from_file { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
message_from_file: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | ▶ | ref($self) or croak; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | ▶ | warn "message_from_file() started\n" if $self->{DEBUG}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | ▶ | if (defined($self->{MESSAGE})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | carp "Message already created by message()"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | ▶ | my $f = shift or return $self->{MSGFILE}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | # This is permitted in case the file needs to be created/modified | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | # by some subsequent process | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | ## -f $f or return undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | ▶ | warn "message_from_file file is '$f'\n" if $self->{DEBUG}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | $self->{MSGFILE} = $f; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | return $self->{MSGFILE}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | ▶ | sub new_message { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new_message: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | ▶ | ref($self) or croak; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | $self->{MESSAGE} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | $self->{MSGFILE} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | ▶ | warn "message reset\n" if $self->{DEBUG}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 1 | ▶ | sub new_envelope { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new_envelope: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 1 | ▶ | ref($self) or croak; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 1 | $self->{SENDER} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 1 | $self->{RECIPIENTS} = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 1 | ▶ | warn "envelope reset\n" if $self->{DEBUG}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 1 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | ▶ | sub _send_file { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_send_file: not called CC=12 SCAR=50.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | ▶ | ref($self) or die; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | my $f = $self->{MSGFILE}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | my $sock = $self->{SOCKET}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | ▶ | warn "_send_file starting\n" if $self->{DEBUG}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | ▶ | unless (open(FILE, $f)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | carp "Cannot open file '$f': $!"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | my $size = (stat(FILE))[7]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | binmode(FILE); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | #carp "File '$f' is empty" if $size == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | ▶ | if ($size < 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | carp "File '$f' has negative size"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | my $len; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | ▶ | print $sock ($size+1) . ":" . $self->{ENCODING} or return undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | ▶ | while (<FILE>) { print $sock $_ or return undef; $len += length($_) }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 0 | ▶ | if ($size != $len) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | warn "File '$f' should be $size but we read $len\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | ▶ | print $sock "," or return undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 0 | ▶ | unless (close FILE) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | carp "Cannot close file '$f': $!"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | ▶ | warn "_send_file finished\n" if $self->{DEBUG}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 0 | ▶ | sub send { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
send: not called CC=20 SCAR=60.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | ▶ | ref($self) or croak; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | ▶ | warn "send() running sanity checks\n" if $self->{DEBUG}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | ▶ | $self->_ready_to_send() or return undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | ##$self->_session_notexpired() or return undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 0 | my $sock = $self->{SOCKET}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | ▶ | if ($self->{MSGFILE}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | warn "calling _send_file for " . $self->{MSGFILE} . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 0 | ▶ | "\n" if $self->{DEBUG}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 0 | ▶ | $self->_send_file() or return undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | ▶ | warn "sending message data\n" if $self->{DEBUG}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | print $sock netstring_encode($self->{ENCODING} . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | ▶ | $self->{MESSAGE}) or return undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | my($s, %r); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | $s = netstring_encode($self->{SENDER}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | ▶ | warn "sending envelope sender $s\n" if $self->{DEBUG}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | ▶ | print $sock $s or return undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 0 | $s = netstring_encode(scalar netstring_encode($self->{RECIPIENTS})); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | ▶ | warn "sending envelope recipient(s) $s\n" if $self->{DEBUG}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 0 | ▶ | print $sock $s or return undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | $s = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | foreach (@{$self->{RECIPIENTS}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 0 | ▶ | warn "read response\n" if $self->{DEBUG}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 0 | $s = $self->_read_netstring(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 0 | ▶ | warn "parse response: $s\n" if $self->{DEBUG}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | CASE: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 0 | ▶ | $s =~ s/^K/success: / and last CASE; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 0 | ▶ | $s =~ s/^Z/deferral: / and last CASE; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | ▶ | $s =~ s/^D/failure: / and last CASE; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 0 | _badproto(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | $r{$_} = $s; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 0 | ▶ | warn "finished send()\n" if $self->{DEBUG}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | return \%r; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 0 | ▶ | sub _ready_to_send { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ready_to_send: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | ▶ | ref($self) or die; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 0 | ▶ | warn "_ready_to_send() starting\n" if $self->{DEBUG}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | # need defined sender (don't need true; empty string valid), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | # recipient(s), defined message, socket and an encoding | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 0 | ▶ | return (defined($self->{SENDER}) and scalar(@{$self->{RECIPIENTS}}) and | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
defined $self->{"MESSAGE"} or $self->{"MSGFILE"}
MC/DC0%0/2
defined $self->{"MESSAGE"} or $self->{"MSGFILE"}
defined $self->{"MESSAGE"}
$self->{"MSGFILE"}
Truth table0%0/3
A or B
A= defined $self->{"MESSAGE"}B= $self->{"MSGFILE"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | (defined($self->{MESSAGE}) or $self->{MSGFILE}) and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | ▶ | $self->{SOCKET} and $self->{ENCODING}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/11
defined $self->{'SENDER'} && scalar @{$self->{'RECIPIENTS'};} && (defined $self->{'MESSAGE'} || $self->{'MSGFILE'}) && $self->{'SOCKET'} && $self->{'ENCODING'}
defined $self->{"SENDER"} and scalar @{$self->{"RECIPIENTS"};} and defined $self->{"MESSAGE"} || $self->{"MSGFILE"} and $self->{"SOCKET"}
defined $self->{"SENDER"} and scalar @{$self->{"RECIPIENTS"};} and defined $self->{"MESSAGE"} || $self->{"MSGFILE"}
defined $self->{"SENDER"} and scalar @{$self->{"RECIPIENTS"};}
MC/DC0%0/4
defined $self->{'SENDER'} && scalar @{$self->{'RECIPIENTS'};} && (defined $self->{'MESSAGE'} || $self->{'MSGFILE'}) && $self->{'SOCKET'} && $self->{'ENCODING'}
defined $self->{"SENDER"}
defined $self->{"MESSAGE"} || $self->{"MSGFILE"}
$self->{"SOCKET"}
$self->{'ENCODING'}
Truth table0%0/5
A and B and C && D
A= defined $self->{"SENDER"}B= defined $self->{"MESSAGE"} || $self->{"MSGFILE"}C= $self->{"SOCKET"}D= $self->{'ENCODING'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 0 | ▶ | sub _session_notexpired { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_session_notexpired: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 0 | ▶ | ref($self) or die; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 0 | ▶ | if (time - $self->{CONNECTTIME} > $self->{SESSIONLIMIT}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 0 | carp "Session has expired"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 0 | $self->disconnect(); # what about failure? | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | ▶ | sub _read_netstring { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_read_netstring: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 0 | ▶ | ref($self) or die; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 0 | my $sock = $self->{SOCKET}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 0 | my $s = netstring_read($sock); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 0 | ▶ | if (defined $s and netstring_verify($s)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $s and netstring_verify($s)
MC/DC0%0/2
defined $s and netstring_verify($s)
defined $s
netstring_verify($s)
Truth table0%0/3
A and B
A= defined $sB= netstring_verify($s)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 0 | return netstring_decode($s); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | return ""; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 0 | ▶ | sub _badproto { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_badproto: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 0 | confess "Protocol violation\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 0 | ▶ | sub _badresources { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_badresources: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 0 | confess "Excessive resources requested\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 1 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=3 SCAR=11.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 1 | ▶ | ref($self) or die; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 1 | ▶ | $self->disconnect() if $self->{SOCKET}; # don't care about failure | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||