line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Drogo::MultiPart; |
2
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
61
|
|
|
1
|
|
|
|
|
47
|
|
3
|
1
|
|
|
1
|
|
964
|
use IO::File; |
|
1
|
|
|
|
|
12286
|
|
|
1
|
|
|
|
|
686
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 MODULE |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
Drogo::MultiPart |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 METHODS |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=over 4 |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=cut |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=item process |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
Processes request's multipart data. |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=cut |
20
|
|
|
|
|
|
|
|
21
|
0
|
|
|
0
|
0
|
|
sub tmpfilename { join('-', 'drogomp', $$, time) } |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub process |
24
|
|
|
|
|
|
|
{ |
25
|
0
|
|
|
0
|
1
|
|
my $server = shift; |
26
|
0
|
|
|
|
|
|
my $fh = $server->input; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# rewind |
29
|
0
|
|
|
|
|
|
$fh->seek(0, 0); |
30
|
|
|
|
|
|
|
|
31
|
0
|
|
0
|
|
|
|
my $tmpdir = $server->variable('tmpdir') || '/tmp'; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# all parts |
34
|
0
|
|
|
|
|
|
my @request_parts; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# instance |
37
|
|
|
|
|
|
|
my %request_part; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# grab first line |
40
|
0
|
|
|
|
|
|
my $key_line = $fh->getline; |
41
|
0
|
|
|
|
|
|
$key_line =~ s/\s//g; |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
my @header; |
44
|
0
|
|
|
|
|
|
my $in_header = 1; |
45
|
0
|
|
|
|
|
|
my $last_line = ''; |
46
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
while (my $line = $fh->getline) |
48
|
|
|
|
|
|
|
{ |
49
|
|
|
|
|
|
|
# write from buffer |
50
|
|
|
|
|
|
|
|
51
|
0
|
0
|
|
|
|
|
if ($line =~ /^$key_line/) |
|
|
0
|
|
|
|
|
|
52
|
|
|
|
|
|
|
{ |
53
|
|
|
|
|
|
|
# write final line |
54
|
0
|
|
|
|
|
|
$last_line =~ s/[\r\n]$//g; |
55
|
|
|
|
|
|
|
|
56
|
0
|
0
|
|
|
|
|
if ($request_part{fh}) |
57
|
|
|
|
|
|
|
{ |
58
|
0
|
|
|
|
|
|
$request_part{fh}->print($last_line); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
else |
61
|
|
|
|
|
|
|
{ |
62
|
0
|
|
|
|
|
|
$request_part{data} .= $last_line; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# process last record |
66
|
0
|
0
|
|
|
|
|
if ($request_part{fh}) |
67
|
|
|
|
|
|
|
{ |
68
|
|
|
|
|
|
|
# stop writing |
69
|
0
|
|
|
|
|
|
close($request_part{fh}); |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
$request_part{size} = -s $request_part{tmp_file}; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# open for reading only |
74
|
0
|
|
|
|
|
|
open($request_part{fh}, '<' . $request_part{tmp_file}); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
|
push @request_parts, { %request_part }; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
# reset request_part |
80
|
0
|
|
|
|
|
|
$in_header = 1; |
81
|
0
|
|
|
|
|
|
@header = (); |
82
|
0
|
|
|
|
|
|
%request_part = (); |
83
|
0
|
|
|
|
|
|
$last_line = ''; |
84
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
next; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
elsif (not $in_header) |
88
|
|
|
|
|
|
|
{ |
89
|
|
|
|
|
|
|
# if we are not in the header and we're not in a new section, write the line! |
90
|
0
|
0
|
|
|
|
|
if ($request_part{fh}) |
91
|
|
|
|
|
|
|
{ |
92
|
0
|
|
|
|
|
|
$request_part{fh}->print($last_line); |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
else |
95
|
|
|
|
|
|
|
{ |
96
|
0
|
|
|
|
|
|
$request_part{data} .= $last_line; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
0
|
0
|
|
|
|
|
if ($in_header) |
101
|
|
|
|
|
|
|
{ |
102
|
|
|
|
|
|
|
# strip newlines |
103
|
0
|
|
|
|
|
|
$line =~ s/[\r\n]//g; |
104
|
|
|
|
|
|
|
|
105
|
0
|
0
|
|
|
|
|
if ($line eq '') |
106
|
|
|
|
|
|
|
{ |
107
|
|
|
|
|
|
|
# we're not in the header anymore |
108
|
0
|
|
|
|
|
|
$in_header = 0; |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
# process header and open file |
111
|
0
|
|
|
|
|
|
my $name; |
112
|
|
|
|
|
|
|
my $filename; |
113
|
0
|
|
|
|
|
|
my $is_file = 0; |
114
|
0
|
|
|
|
|
|
for my $h_line (@header) |
115
|
|
|
|
|
|
|
{ |
116
|
0
|
0
|
|
|
|
|
$name = $1 if $h_line =~ /name=["'](.*?)["']/; |
117
|
0
|
0
|
|
|
|
|
$filename = $1 if $h_line =~ /filename=["'](.*?)["']/; |
118
|
0
|
0
|
|
|
|
|
$is_file = 1 if $h_line =~ /filename=/; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
# define info in request part |
122
|
0
|
|
|
|
|
|
$request_part{name} = $name; |
123
|
|
|
|
|
|
|
|
124
|
0
|
0
|
|
|
|
|
if ($is_file) |
125
|
|
|
|
|
|
|
{ |
126
|
0
|
|
|
|
|
|
$request_part{filename} = $filename; |
127
|
0
|
|
|
|
|
|
$request_part{tmp_file} = $tmpdir . '/' . tmpfilename(); |
128
|
0
|
|
|
|
|
|
$request_part{fh} = IO::File->new('> ' . $request_part{tmp_file}); |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
else |
131
|
|
|
|
|
|
|
{ |
132
|
0
|
|
|
|
|
|
$request_part{data} = ''; |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
0
|
|
|
|
|
|
next; |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
0
|
|
|
|
|
|
push @header, $line; |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
else |
141
|
|
|
|
|
|
|
{ |
142
|
0
|
|
|
|
|
|
$last_line = $line; |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
0
|
|
|
|
|
|
return \@request_parts; |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head1 AUTHORS |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
Bizowie |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
Copyright (C) 2013 Bizowie |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
This library is free software. You can redistribute it and/or modify it under the same terms as Perl itself. |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=cut |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
1; |