File: multipart.cgi

package info (click to toggle)
qtbase-opensource-src-gles 5.15.17%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 349,996 kB
  • sloc: cpp: 2,097,620; ansic: 343,242; xml: 115,491; python: 9,447; java: 7,499; asm: 4,023; sh: 2,086; perl: 2,047; yacc: 1,687; lex: 1,333; javascript: 878; makefile: 260; objc: 70
file content (42 lines) | stat: -rwxr-xr-x 1,143 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/perl

use CGI;
use Digest::MD5 qw(md5_hex);

$q = new CGI;
print $q->header();

$contentType = $ENV{"CONTENT_TYPE"};
print "content type: $contentType\n";

if ($contentType =~ /^multipart\/form-data/) {
    foreach my $key ($q->param) {
        foreach my $value (scalar $q->param($key)) {
            if ($key =~ /text/) {
                $retValue = $value;
            } else {
                $retValue = md5_hex($value);
            }
            print "key: $key, value: $retValue\n";
        }
    }
} else {
    #$contentLength = $ENV{"CONTENT_LENGTH"};
    #print "content length: $contentLength\r\n";

    $data = $q->param('POSTDATA');
    $data =~ s/--\S*--$//; # remove ending boundary
    @parts = split(/--\S*\r\n/, $data);
    shift(@parts);
    foreach (@parts) {
        #print "raw: $_";
        ($header, $content) = split("\r\n\r\n");
        @headerFields = split("\r\n", $header);
        foreach (@headerFields) {
            ($fieldName, $value) = split(": ");
            print "header: $fieldName, value: '$value'\n";
        }
        $content =~ s/\r\n//;
        print "content: $content\n\n";
    }
}