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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
|
#!/usr/bin/perl
# hls_methods.pl
#
# HTTP methods script for HLS streaming
#
# (C) 2015 Fred Gleason <fredg@paravelsystems.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public
# License along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
sub Put
{
my $response=201;
my $file_name=&DestinationPath();
my $file_len = $ENV{'CONTENT_LENGTH'};
if(stat($file_name)) {
$response=204;
}
#
# Copy Data
#
my $toread = $file_len;
$content = "";
while ($toread > 0)
{
$nread = read(STDIN, $data, $file_len);
$toread -= $nread;
$content = $data;
}
if(!open(OUT, "> $file_name")) {
&Reply(500,"PUT failed!\n");
}
print OUT $content;
close(OUT);
&Reply($response,"OK");
}
sub Delete
{
my $file_name=&DestinationPath();
if(stat($file_name)) {
if(!unlink($file_name)) {
&Reply(500,"Unable to delete\n");
}
}
&Reply(204,"OK");
}
sub DestinationPath()
{
my $file_name=$ENV{'PATH_TRANSLATED'};
if(!$file_name) {
&Reply(500,"No destination path provided.");
}
return $file_name;
}
sub Reply
{
print "Status: ".$_[0]."\n";
print "Content-type: text/html\n";
print "\n";
print $_[1];
exit 0;
}
#
# Verify Method
#
if($ENV{'REQUEST_METHOD'} eq "PUT") {
&Put();
}
if($ENV{'REQUEST_METHOD'} eq "DELETE") {
&Delete();
}
&Reply(500,"Unsupported method.\n");
|