| 1 | # ====================================================================== | ||||||||||||||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||||||||||||||
| 3 | # Copyright (C) 2000-2004 Paul Kulchenko (paulclinger@yahoo.com) | ||||||||||||||||||||||||||||||||||
| 4 | # SOAP::Lite is free software; you can redistribute it | ||||||||||||||||||||||||||||||||||
| 5 | # and/or modify it under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||
| 6 | # | ||||||||||||||||||||||||||||||||||
| 7 | # ====================================================================== | ||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||
| 9 | package SOAP::Packager; | ||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||
| 11 | 45 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 12 | 45 | ▶ | use vars; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||
| 14 | 45 | our $VERSION = '1.27'; # VERSION | |||||||||||||||||||||||||||||||||
| 15 | 45 | our $SUPPORTED_TYPES = { }; | |||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||
| 17 | 45 | ▶ | sub BEGIN { | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||||||||
| 18 | 45 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 19 | 45 | for my $method ( qw(parser headers_http persist_parts) ) { | |||||||||||||||||||||||||||||||||
| 20 | 135 | my $field = '_' . $method; | |||||||||||||||||||||||||||||||||
| 21 | 60 | ▶ | *$method = sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=8.4
| |||||||||||||||||||||||||||||||||||
| 22 | 60 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 23 | 0 | ▶ | if (@_) { $self->{$field} = shift; return $self } | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 24 | 60 | return $self->{$field}; | |||||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||||
| 26 | 135 | } | |||||||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||
| 29 | 55 | ▶ | sub new { | ||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 30 | 55 | my($class) = shift; | |||||||||||||||||||||||||||||||||
| 31 | 55 | my(%params) = @_; | |||||||||||||||||||||||||||||||||
| 32 | 55 | bless { | |||||||||||||||||||||||||||||||||
| 33 | "_parts" => [ ], | ||||||||||||||||||||||||||||||||||
| 34 | "_parser" => undef, | ||||||||||||||||||||||||||||||||||
| 35 | "_persist_parts" => 0, | ||||||||||||||||||||||||||||||||||
| 36 | }, $class; | ||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||
| 39 | 3 | ▶ | sub is_supported_part { | ||||||||||||||||||||||||||||||||
|
Subroutine
is_supported_part: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 40 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 41 | 3 | return $SUPPORTED_TYPES->{ref $_[0]}; | |||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||
| 44 | 83 | ▶ | sub parts { | ||||||||||||||||||||||||||||||||
|
Subroutine
parts: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 45 | 83 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 46 | 83 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 47 | 0 | $self->{'_parts'} = shift; | |||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||
| 49 | 83 | return $self->{'_parts'}; | |||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||
| 52 | # This is a static method that helps find the right Packager | ||||||||||||||||||||||||||||||||||
| 53 | 0 | ▶ | sub find_packager { | ||||||||||||||||||||||||||||||||
|
Subroutine
find_packager: not called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 54 | # TODO - Input: | ||||||||||||||||||||||||||||||||||
| 55 | # * the mimetype of the data to be decoded raw data that needs | ||||||||||||||||||||||||||||||||||
| 56 | # * the data to be decoded | ||||||||||||||||||||||||||||||||||
| 57 | # Returns: | ||||||||||||||||||||||||||||||||||
| 58 | # * the proper SOAP::Packager instance | ||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||
| 61 | 29 | ▶ | sub push_part { | ||||||||||||||||||||||||||||||||
|
Subroutine
push_part: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 62 | 29 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 63 | 29 | my ($part) = @_; | |||||||||||||||||||||||||||||||||
| 64 | 29 | push @{$self->{'_parts'}}, $part; | |||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | sub package { | ||||||||||||||||||||||||||||||||
|
Subroutine
package: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 68 | # do nothing | ||||||||||||||||||||||||||||||||||
| 69 | 0 | die "SOAP::Packager::package() must be implemented"; | |||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||
| 72 | 20 | ▶ | sub unpackage { | ||||||||||||||||||||||||||||||||
|
Subroutine
unpackage: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 73 | 20 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 74 | 20 | ▶ | $self->{'_parts'} = [] if !$self->persist_parts; # experimental | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||
| 77 | # ====================================================================== | ||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||
| 79 | package SOAP::Packager::MIME; | ||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||
| 81 | 45 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 82 | 45 | ▶ | use vars qw(@ISA); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 83 | 45 | @ISA = qw(SOAP::Packager); | |||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||
| 85 | 45 | ▶ | sub BEGIN { | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=9.6
| |||||||||||||||||||||||||||||||||||
| 86 | 45 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 87 | 45 | for my $method ( qw(transfer_encoding env_id env_location) ) { | |||||||||||||||||||||||||||||||||
| 88 | 135 | my $field = '_' . $method; | |||||||||||||||||||||||||||||||||
| 89 | 0 | ▶ | *$method = sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||
| 90 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | if (@_) { $self->{$field} = shift; return $self } | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 92 | 0 | return $self->{$field}; | |||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||
| 94 | 135 | } | |||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||
| 97 | 55 | ▶ | sub new { | ||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 98 | 55 | my ($classname) = @_; | |||||||||||||||||||||||||||||||||
| 99 | 55 | my $self = SOAP::Packager::new(@_); | |||||||||||||||||||||||||||||||||
| 100 | 55 | $self->{'_content_encoding'} = '8bit'; | |||||||||||||||||||||||||||||||||
| 101 | 55 | $self->{'_env_id'} = '<main_envelope>'; | |||||||||||||||||||||||||||||||||
| 102 | 55 | $self->{'_env_location'} = '/main_envelope'; | |||||||||||||||||||||||||||||||||
| 103 | 55 | bless $self, $classname; | |||||||||||||||||||||||||||||||||
| 104 | 55 | $SOAP::Packager::SUPPORTED_TYPES->{"MIME::Entity"} = 1; | |||||||||||||||||||||||||||||||||
| 105 | 55 | return $self; | |||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||
| 108 | 8 | ▶ | sub initialize_parser { | ||||||||||||||||||||||||||||||||
|
Subroutine
initialize_parser: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||
| 109 | 8 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 110 | 8 | eval "require MIME::Parser;"; | |||||||||||||||||||||||||||||||||
| 111 | 8 | ▶ | die "Could not find MIME::Parser - is MIME::Tools installed? Aborting." if $@; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 112 | 8 | $self->{'_parser'} = MIME::Parser->new; | |||||||||||||||||||||||||||||||||
| 113 | 8 | $self->{'_parser'}->output_to_core('ALL'); | |||||||||||||||||||||||||||||||||
| 114 | 8 | $self->{'_parser'}->tmp_to_core(1); | |||||||||||||||||||||||||||||||||
| 115 | 8 | $self->{'_parser'}->ignore_errors(1); | |||||||||||||||||||||||||||||||||
| 116 | 8 | $self->{'_parser'}->extract_nested_messages(0); | |||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||
| 119 | 1 | ▶ | sub generate_random_string { | ||||||||||||||||||||||||||||||||
|
Subroutine
generate_random_string: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 120 | 1 | my ($self,$len) = @_; | |||||||||||||||||||||||||||||||||
| 121 | 1 | my @chars=('a'..'z','A'..'Z','0'..'9','_'); | |||||||||||||||||||||||||||||||||
| 122 | 1 | my $random_string; | |||||||||||||||||||||||||||||||||
| 123 | 1 | foreach (1..$len) { | |||||||||||||||||||||||||||||||||
| 124 | 10 | $random_string .= $chars[rand @chars]; | |||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||
| 126 | 1 | return $random_string; | |||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||
| 129 | 66 | ▶ | sub get_multipart_id { | ||||||||||||||||||||||||||||||||
|
Subroutine
get_multipart_id: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||
| 130 | 66 | my ($id) = shift; | |||||||||||||||||||||||||||||||||
| 131 | 66 | ▶ | ($id || '') =~ /^<?([^>]+)>?$/; $1 || ''; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$id || ''
MC/DC100%1/1
$id || ''
$id
Truth table100%2/2
A
A= $id
| |||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||
| 134 | 0 | ▶ | sub package { | ||||||||||||||||||||||||||||||||
|
Subroutine
package: not called CC=5 SCAR=30.9
| |||||||||||||||||||||||||||||||||||
| 135 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 136 | 0 | my ($envelope,$context) = @_; | |||||||||||||||||||||||||||||||||
| 137 | 0 | ▶ | return $envelope if (!$self->parts); # if there are no parts, | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 138 | # then there is nothing to do | ||||||||||||||||||||||||||||||||||
| 139 | 0 | require MIME::Entity; | |||||||||||||||||||||||||||||||||
| 140 | 0 | local $MIME::Entity::BOUNDARY_DELIMITER = "\r\n"; | |||||||||||||||||||||||||||||||||
| 141 | 0 | my $top = MIME::Entity->build('Type' => "Multipart/Related"); | |||||||||||||||||||||||||||||||||
| 142 | 0 | ▶ | my $soapversion = defined($context) ? $context->soapversion : '1.1'; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 143 | 0 | ▶ | $top->attach('Type' => $soapversion == 1.1 ? "text/xml" : "application/soap+xml", | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 144 | 'Content-Transfer-Encoding' => $self->transfer_encoding(), | ||||||||||||||||||||||||||||||||||
| 145 | 'Content-Location' => $self->env_location(), | ||||||||||||||||||||||||||||||||||
| 146 | 'Content-ID' => $self->env_id(), | ||||||||||||||||||||||||||||||||||
| 147 | 'Data' => $envelope ); | ||||||||||||||||||||||||||||||||||
| 148 | # consume the attachments that come in as input by 'shift'ing | ||||||||||||||||||||||||||||||||||
| 149 | 45 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 150 | 0 | ▶ | while (my $part = shift(@{$self->parts})) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 151 | 0 | $top->add_part($part); | |||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||
| 153 | # determine MIME boundary | ||||||||||||||||||||||||||||||||||
| 154 | 0 | my $boundary = $top->head->multipart_boundary; | |||||||||||||||||||||||||||||||||
| 155 | 0 | $self->headers_http({ 'Content-Type' => 'Multipart/Related; type="text/xml"; start="<main_envelope>"; boundary="'.$boundary.'"'}); | |||||||||||||||||||||||||||||||||
| 156 | 0 | return $top->stringify_body; | |||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||
| 159 | 20 | ▶ | sub unpackage { | ||||||||||||||||||||||||||||||||
|
Subroutine
unpackage: called CC=9 SCAR=27.3
| |||||||||||||||||||||||||||||||||||
| 160 | 20 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 161 | 20 | my ($raw_input,$context) = @_; | |||||||||||||||||||||||||||||||||
| 162 | 20 | $self->SUPER::unpackage(); | |||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||
| 164 | # Parse the raw input into a MIME::Entity structure. | ||||||||||||||||||||||||||||||||||
| 165 | # - fail if the raw_input is not MIME formatted | ||||||||||||||||||||||||||||||||||
| 166 | 20 | ▶ | $self->initialize_parser() if !defined($self->parser); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 167 | 20 | ▶ | my $entity = eval { $self->parser->parse_data($raw_input) } | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 168 | 0 | ▶ | or die "Something wrong with MIME message: @{[$@ || $self->parser->last_error]}\n"; | ||||||||||||||||||||||||||||||||
|
Condition0%0/3
$@ || $self->parser->last_error
MC/DC0%0/2
$@ || $self->parser->last_error
$@
$self->parser->last_error
Truth table0%0/3
A || B
A= $@B= $self->parser->last_error
| |||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||
| 170 | 20 | my $env = undef; | |||||||||||||||||||||||||||||||||
| 171 | # major memory bloat below! TODO - fix! | ||||||||||||||||||||||||||||||||||
| 172 | 20 | ▶ | if (lc($entity->head->mime_type) eq 'multipart/form-data') { | ||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||
| 173 | 0 | $env = $self->process_form_data($entity); | |||||||||||||||||||||||||||||||||
| 174 | } elsif (lc($entity->head->mime_type) eq 'multipart/related') { | ||||||||||||||||||||||||||||||||||
| 175 | 18 | $env = $self->process_related($entity); | |||||||||||||||||||||||||||||||||
| 176 | } elsif (lc($entity->head->mime_type) eq 'text/xml') { | ||||||||||||||||||||||||||||||||||
| 177 | # I don't think this ever gets called. | ||||||||||||||||||||||||||||||||||
| 178 | # warn "I am somewhere in the SOAP::Packager::MIME code I didn't know I would be in!"; | ||||||||||||||||||||||||||||||||||
| 179 | 2 | $env = $entity->bodyhandle->as_string; | |||||||||||||||||||||||||||||||||
| 180 | } else { | ||||||||||||||||||||||||||||||||||
| 181 | 0 | die "Can't handle MIME messsage with specified type (@{[$entity->head->mime_type]})\n"; | |||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||
| 184 | # return the envelope | ||||||||||||||||||||||||||||||||||
| 185 | 20 | ▶ | if ($env) { | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 186 | 20 | return $env; | |||||||||||||||||||||||||||||||||
| 187 | } elsif ($entity->bodyhandle->as_string) { | ||||||||||||||||||||||||||||||||||
| 188 | 0 | return $entity->bodyhandle->as_string; | |||||||||||||||||||||||||||||||||
| 189 | } else { | ||||||||||||||||||||||||||||||||||
| 190 | 0 | die "No content in MIME message\n"; | |||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||
| 194 | 0 | ▶ | sub process_form_data { | ||||||||||||||||||||||||||||||||
|
Subroutine
process_form_data: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||
| 195 | 0 | my ($self, $entity) = @_; | |||||||||||||||||||||||||||||||||
| 196 | 0 | my $env = undef; | |||||||||||||||||||||||||||||||||
| 197 | 0 | foreach my $part ($entity->parts) { | |||||||||||||||||||||||||||||||||
| 198 | 0 | my $name = $part->head->mime_attr('content-disposition.name'); | |||||||||||||||||||||||||||||||||
| 199 | 0 | ▶ | $name eq 'payload' ? | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 200 | $env = $part->bodyhandle->as_string | ||||||||||||||||||||||||||||||||||
| 201 | : $self->push_part($part); | ||||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||
| 203 | 0 | return $env; | |||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||
| 206 | 18 | ▶ | sub process_related { | ||||||||||||||||||||||||||||||||
|
Subroutine
process_related: called CC=13 SCAR=26.3
| |||||||||||||||||||||||||||||||||||
| 207 | 18 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 208 | 18 | my ($entity) = @_; | |||||||||||||||||||||||||||||||||
| 209 | 18 | ▶ | die "Multipart MIME messages MUST declare Multipart/Related content-type" | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 210 | if ($entity->head->mime_attr('content-type') !~ /^multipart\/related/i); | ||||||||||||||||||||||||||||||||||
| 211 | # As it turns out, the Content-ID and start parameters are optional | ||||||||||||||||||||||||||||||||||
| 212 | # according to the MIME and SOAP specs. In the event that the head cannot | ||||||||||||||||||||||||||||||||||
| 213 | # be found, the head/root entity is used as a starting point. | ||||||||||||||||||||||||||||||||||
| 214 | # [19 Mar 2008] Modified by Feng Li <feng.li@sybase.com> | ||||||||||||||||||||||||||||||||||
| 215 | # Check optional start parameter, then optional Content-ID, then create/add | ||||||||||||||||||||||||||||||||||
| 216 | # Content-ID (the same approach as in SOAP::Lite 0.66) | ||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||
| 218 | #my $start = get_multipart_id($entity->head->mime_attr('content-type.start')); | ||||||||||||||||||||||||||||||||||
| 219 | 18 | ▶ | my $start = get_multipart_id($entity->head->mime_attr('content-type.start')) | ||||||||||||||||||||||||||||||||
|
Condition66%2/3
get_multipart_id($entity->head->mime_attr('content-type.start')) || get_multipart_id($entity->parts(0)->head->mime_attr('content-id'))
MC/DC50%1/2
get_multipart_id($entity->head->mime_attr('content-type.start')) || get_multipart_id($entity->parts(0)->head->mime_attr('content-id'))
get_multipart_id($entity->head->mime_attr('content-type.start'))
get_multipart_id($entity->parts(0)->head->mime_attr('content-id'))
Truth table66%2/3
A || B
A= get_multipart_id($entity->head->mime_attr('content-type.start'))B= get_multipart_id($entity->parts(0)->head->mime_attr('content-id'))
| |||||||||||||||||||||||||||||||||||
| 220 | || get_multipart_id($entity->parts(0)->head->mime_attr('content-id')); | ||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||
| 222 | 18 | ▶ | if (!defined($start) || $start eq "") { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $start or $start eq ""
MC/DC50%1/2
not defined $start or $start eq ""
not defined $start
$start eq ""
Truth table66%2/3
not(A) or B
A= not defined $startB= $start eq ""
| |||||||||||||||||||||||||||||||||||
| 223 | 1 | $start = $self->generate_random_string(10); | |||||||||||||||||||||||||||||||||
| 224 | 1 | $entity->parts(0)->head->add('content-id',$start); | |||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||
| 226 | 18 | ▶ | my $location = $entity->head->mime_attr('content-location') || | ||||||||||||||||||||||||||||||||
|
Condition100%2/2
$entity->head->mime_attr('content-location') || 'thismessage:/'
MC/DC100%1/1
$entity->head->mime_attr('content-location') || 'thismessage:/'
$entity->head->mime_attr('content-location')
Truth table100%2/2
A
A= $entity->head->mime_attr('content-location')
| |||||||||||||||||||||||||||||||||||
| 227 | 'thismessage:/'; | ||||||||||||||||||||||||||||||||||
| 228 | 18 | my $env; | |||||||||||||||||||||||||||||||||
| 229 | 18 | foreach my $part ($entity->parts) { | |||||||||||||||||||||||||||||||||
| 230 | 47 | ▶ | next if !UNIVERSAL::isa($part => "MIME::Entity"); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||
| 232 | # Weird, the following use of head->get(SCALAR[,INDEX]) doesn't work as | ||||||||||||||||||||||||||||||||||
| 233 | # expected. Work around is to eliminate the INDEX. | ||||||||||||||||||||||||||||||||||
| 234 | 47 | my $pid = get_multipart_id($part->head->mime_attr('content-id')); | |||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||
| 236 | # If Content-ID is not supplied, then generate a random one (HACK - because | ||||||||||||||||||||||||||||||||||
| 237 | # MIME::Entity does not do this as it should... content-id is required | ||||||||||||||||||||||||||||||||||
| 238 | # according to MIME specification) | ||||||||||||||||||||||||||||||||||
| 239 | 47 | ▶ | $pid = $self->generate_random_string(10) if $pid eq ''; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 240 | 47 | my $type = $part->head->mime_type; | |||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||
| 242 | # If a Content-Location header cannot be found, this will look for an | ||||||||||||||||||||||||||||||||||
| 243 | # alternative in the following MIME Header attributes | ||||||||||||||||||||||||||||||||||
| 244 | 47 | ▶ | my $plocation = $part->head->get('content-location') || | ||||||||||||||||||||||||||||||||
|
Condition66%4/6
$part->head->get('content-location') || $part->head->mime_attr('Content-Disposition.filename') || $part->head->mime_attr('Content-Type.name')
$part->head->get("content-location") or $part->head->mime_attr("Content-Disposition.filename")
MC/DC33%1/3
$part->head->get('content-location') || $part->head->mime_attr('Content-Disposition.filename') || $part->head->mime_attr('Content-Type.name')
$part->head->get("content-location")
$part->head->mime_attr("Content-Disposition.filename")
$part->head->mime_attr('Content-Type.name')
Truth table50%2/4
A or B || C
A= $part->head->get("content-location")B= $part->head->mime_attr("Content-Disposition.filename")C= $part->head->mime_attr('Content-Type.name')
| |||||||||||||||||||||||||||||||||||
| 245 | $part->head->mime_attr('Content-Disposition.filename') || | ||||||||||||||||||||||||||||||||||
| 246 | $part->head->mime_attr('Content-Type.name'); | ||||||||||||||||||||||||||||||||||
| 247 | 47 | ▶ | if ($start && $pid eq $start) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$start and $pid eq $start
MC/DC50%1/2
$start and $pid eq $start
$start
$pid eq $start
Truth table66%2/3
A and B
A= $startB= $pid eq $start
| |||||||||||||||||||||||||||||||||||
| 248 | 18 | $env = $part->bodyhandle->as_string; | |||||||||||||||||||||||||||||||||
| 249 | } else { | ||||||||||||||||||||||||||||||||||
| 250 | 29 | $self->push_part($part); | |||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||||
| 253 | # die "Can't find 'start' parameter in multipart MIME message\n" | ||||||||||||||||||||||||||||||||||
| 254 | # if @{$self->parts} > 1 && !$start; | ||||||||||||||||||||||||||||||||||
| 255 | 18 | return $env; | |||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||
| 258 | # ====================================================================== | ||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||
| 260 | package SOAP::Packager::DIME; | ||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||
| 262 | 45 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 263 | 45 | ▶ | use vars qw(@ISA); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 264 | 45 | @ISA = qw(SOAP::Packager); | |||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||
| 266 | 45 | ▶ | sub BEGIN { | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=9.6
| |||||||||||||||||||||||||||||||||||
| 267 | 45 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 268 | 45 | for my $method ( qw(foo) ) { | |||||||||||||||||||||||||||||||||
| 269 | 45 | my $field = '_' . $method; | |||||||||||||||||||||||||||||||||
| 270 | 0 | ▶ | *$method = sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||
| 271 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 272 | 0 | ▶ | if (@_) { $self->{$field} = shift; return $self } | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 273 | 0 | return $self->{$field}; | |||||||||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||||||||
| 275 | 45 | } | |||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||
| 278 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 279 | 0 | my ($classname) = @_; | |||||||||||||||||||||||||||||||||
| 280 | 0 | my $self = SOAP::Packager::new(@_); | |||||||||||||||||||||||||||||||||
| 281 | 0 | bless $self, $classname; | |||||||||||||||||||||||||||||||||
| 282 | 0 | $SOAP::Packager::SUPPORTED_TYPES->{"DIME::Payload"} = 1; | |||||||||||||||||||||||||||||||||
| 283 | 0 | return $self; | |||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||
| 286 | 0 | ▶ | sub initialize_parser { | ||||||||||||||||||||||||||||||||
|
Subroutine
initialize_parser: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||
| 287 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 288 | 0 | print STDERR "Initializing parser\n"; | |||||||||||||||||||||||||||||||||
| 289 | 0 | eval "require DIME::Parser;"; | |||||||||||||||||||||||||||||||||
| 290 | 0 | ▶ | die "Could not find DIME::Parser - is DIME::Tools installed? Aborting." if $@; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 291 | 0 | $self->{'_parser'} = DIME::Parser->new; | |||||||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||
| 294 | 0 | ▶ | sub package { | ||||||||||||||||||||||||||||||||
|
Subroutine
package: not called CC=6 SCAR=34.6
| |||||||||||||||||||||||||||||||||||
| 295 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 296 | 0 | my ($envelope,$context) = @_; | |||||||||||||||||||||||||||||||||
| 297 | 0 | ▶ | return $envelope if (!$self->parts); # if there are no parts, | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 298 | # then there is nothing to do | ||||||||||||||||||||||||||||||||||
| 299 | 0 | require DIME::Message; | |||||||||||||||||||||||||||||||||
| 300 | 0 | require DIME::Payload; | |||||||||||||||||||||||||||||||||
| 301 | 0 | my $message = DIME::Message->new; | |||||||||||||||||||||||||||||||||
| 302 | 0 | my $top = DIME::Payload->new; | |||||||||||||||||||||||||||||||||
| 303 | 0 | ▶ | my $soapversion = defined($context) ? $context->soapversion : '1.1'; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 304 | 0 | ▶ | $top->attach('MIMEType' => $soapversion == 1.1 ? | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 305 | "http://schemas.xmlsoap.org/soap/envelope/" : "application/soap+xml", | ||||||||||||||||||||||||||||||||||
| 306 | 'Data' => \$envelope ); | ||||||||||||||||||||||||||||||||||
| 307 | 0 | $message->add_payload($top); | |||||||||||||||||||||||||||||||||
| 308 | # consume the attachments that come in as input by 'shift'ing | ||||||||||||||||||||||||||||||||||
| 309 | 45 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 310 | 0 | ▶ | while (my $part = shift(@{$self->parts})) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 311 | 0 | ▶ | die "You are only allowed to add parts of type DIME::Payload to a DIME::Message" | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 312 | if (!$part->isa('DIME::Payload')); | ||||||||||||||||||||||||||||||||||
| 313 | # print STDERR "Adding payload to DIME message: ".ref($part)."\n"; | ||||||||||||||||||||||||||||||||||
| 314 | 0 | $message->add_payload($part); | |||||||||||||||||||||||||||||||||
| 315 | # print STDERR "Payload's payload is: ".${$part->print_content_data}."\n"; | ||||||||||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||||||||
| 317 | 0 | $self->headers_http({ 'Content-Type' => 'application/dime' }); | |||||||||||||||||||||||||||||||||
| 318 | 0 | return $message->print_data; | |||||||||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||
| 321 | 0 | ▶ | sub unpackage { | ||||||||||||||||||||||||||||||||
|
Subroutine
unpackage: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||
| 322 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 323 | 0 | my ($raw_input,$context) = @_; | |||||||||||||||||||||||||||||||||
| 324 | 0 | $self->SUPER::unpackage(); | |||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||
| 326 | # Parse the raw input into a DIME::Message structure. | ||||||||||||||||||||||||||||||||||
| 327 | # - fail if the raw_input is not DIME formatted | ||||||||||||||||||||||||||||||||||
| 328 | 0 | print STDERR "raw_data: $raw_input\n"; | |||||||||||||||||||||||||||||||||
| 329 | 0 | ▶ | $self->initialize_parser() if !defined($self->parser); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 330 | 0 | ▶ | my $message = eval { $self->parser->parse_data(\$raw_input) } | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 331 | 0 | or die "Something wrong with DIME message: @{[$@]}\n"; | |||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||
| 333 | # The first payload is always the SOAP Message | ||||||||||||||||||||||||||||||||||
| 334 | # TODO - Error check | ||||||||||||||||||||||||||||||||||
| 335 | 0 | my @payloads = @{$message->{'_PAYLOADS'}}; | |||||||||||||||||||||||||||||||||
| 336 | 0 | my $env = shift(@payloads); | |||||||||||||||||||||||||||||||||
| 337 | 0 | my $env_str = $env->print_content_data; | |||||||||||||||||||||||||||||||||
| 338 | 0 | print STDERR "Received this envelope: ".$env_str."\n"; | |||||||||||||||||||||||||||||||||
| 339 | 0 | ▶ | while (my $p = shift(@payloads)) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 340 | 0 | print STDERR "Adding part to Packager\n"; | |||||||||||||||||||||||||||||||||
| 341 | 0 | $self->push_part($p); | |||||||||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||||||||
| 343 | 0 | return $env_str; | |||||||||||||||||||||||||||||||||
| 344 | } | ||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||
| 346 | 45 | 1; | |||||||||||||||||||||||||||||||||
| 347 | __END__ | ||||||||||||||||||||||||||||||||||