s4
changeset 11:3565d93c2fb1
add mpsplit.pl
author | HIROSE Yuuji <yuuji@gentei.org> |
---|---|
date | Mon, 20 Jul 2015 18:09:20 +0900 |
parents | 63c0e22870bb |
children | 262bbdea72e2 |
files | mpsplit.pl mpsplit.rb y4-funcs.sh y4.cgi |
diffstat | 4 files changed, 50 insertions(+), 15 deletions(-) [+] |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/mpsplit.pl Mon Jul 20 18:09:20 2015 +0900 1.3 @@ -0,0 +1,34 @@ 1.4 +#!/usr/bin/env perl 1.5 +$sep = "--" . $ARGV[0]; 1.6 +$dir = ($ARGV[1] || "tmp"); 1.7 + 1.8 +#print "sep=".$sep, "dir=$dir\n"; 1.9 +#binmode STDIN; 1.10 +$/ = undef; 1.11 +$stream = (<STDIN>); 1.12 +$n=0; 1.13 +@slices = split($sep, $stream); 1.14 +shift(@slices); 1.15 +pop(@slices); 1.16 +foreach $item (@slices) { 1.17 + $item =~ s/^\n//; 1.18 + ($header = $item) =~ s/\r\n\r\n.*//s; 1.19 + ($body = $item) =~ s/.*?\r\n\r\n//s; 1.20 + $body =~ s/\r\n$//; 1.21 + #print "h=[$header]\n"; 1.22 + #print "b=[$body]\n"; 1.23 + unless ($header =~ /\bname=([\"']?)(.*?)\1/) { 1.24 + next; 1.25 + } 1.26 + $name = $2; 1.27 + #print "name=$name\n"; 1.28 + if ($header =~ /filename=(['\"]?)(.*?)\1/ && $2 gt "") { 1.29 + $fn = $2; 1.30 + open(OUT, ">$dir/$fn"); 1.31 + print OUT $body; 1.32 + close(OUT); 1.33 + printf("%s:filename=%s\n", $name, unpack("H*", $fn)); 1.34 + } else { 1.35 + printf("%s=%s\n", $name, unpack("H*", $body)); 1.36 + } 1.37 +}
2.1 --- a/mpsplit.rb Mon Jul 20 11:53:05 2015 +0900 2.2 +++ b/mpsplit.rb Mon Jul 20 18:09:20 2015 +0900 2.3 @@ -20,10 +20,12 @@ 2.4 open(File.expand_path(fn, tmpdir).untaint, "w") do |out| 2.5 out.write body 2.6 end 2.7 - printf("%s:filename=%s\n", name, fn) 2.8 +## printf("%s:filename=%s\n", name, fn) 2.9 + printf("%s:filename=%s\n", name, fn.unpack("H*")[0]) 2.10 elsif /name=(['\"]?)(.*?)\1/ =~ header 2.11 v=$2 2.12 - out=NKF::nkf("-w -MQ", body).gsub(/([^=])\n/, "\\1=0a").gsub(/=\n/, "") 2.13 - printf("%s=%s\n", v, out) 2.14 +# out=NKF::nkf("-w -MQ", body).gsub(/([^=])\n/, "\\1=0a").gsub(/=\n/, "") 2.15 +# printf("%s=%s\n", v, out) 2.16 + printf("%s=%s\n", v, body.unpack("H*")[0]) 2.17 end 2.18 end
3.1 --- a/y4-funcs.sh Mon Jul 20 11:53:05 2015 +0900 3.2 +++ b/y4-funcs.sh Mon Jul 20 18:09:20 2015 +0900 3.3 @@ -442,7 +442,7 @@ 3.4 esac) 3.5 } 3.6 mktempd() { 3.7 - TMPDIR=$tmpdir mktemp -d -t $session 3.8 + TMPDIR=$tmpd mktemp -d -t $session 3.9 } 3.10 getval() { 3.11 # $1=table $2=col $3(optional)=condition 3.12 @@ -939,7 +939,7 @@ 3.13 cgiinit() { 3.14 session=`date +%F-$$` 3.15 tmpf=tmp/stream 3.16 - tmpd=`mktempd` 3.17 + tmpd=`tmpd=$tmpdir mktempd` 3.18 tmpfiles=$tmpfiles" $tmpd" 3.19 addsession $session 3.20 getcookie 3.21 @@ -954,12 +954,13 @@ 3.22 case "$CONTENT_TYPE" in 3.23 *boundary*) 3.24 bndry=${CONTENT_TYPE#*boundary=} 3.25 - for us in `LC_CTYPE=C ./mpsplit.rb "$bndry" $tmpdir < $tmpf` 3.26 + #for us in `LC_CTYPE=C ./mpsplit.rb "$bndry" $tmpdir < $tmpf` 3.27 + for us in `LC_CTYPE=C ./mpsplit.pl "$bndry" $tmpdir < $tmpf` 3.28 do 3.29 k=${us%%\=*} 3.30 #echo u=$us 3.31 - # v="`echo ${us#*=}|nkf -Ww -mQ|sed -e 's/=/=3d/g' -e 's/\"/=22/g'`" 3.32 - v="`echo ${us#*=}|nkf -Ww -mQ|sed -e 's/\"/\"\"/g'`" 3.33 + #v="`echo ${us#*=}|nkf -Ww -mQ|sed -e 's/\"/\"\"/g'`" 3.34 + v="`echo ${us#*=}|unhexize`" 3.35 # err k=$k v=$v 3.36 case "$k" in 3.37 *:filename)
4.1 --- a/y4.cgi Mon Jul 20 11:53:05 2015 +0900 4.2 +++ b/y4.cgi Mon Jul 20 18:09:20 2015 +0900 4.3 @@ -254,13 +254,11 @@ 4.4 putfooter; exit 4.5 fi 4.6 idir=`umask 002; mktempd` || exit 1 4.7 - tmpfiles=$tmpfiles"${tmpfiles+ }$idir" 4.8 + # tmpfiles=$tmpfiles"${tmpfiles+ }$idir" 4.9 bin=$idir/$myname-$$.bin 4.10 - ##sql="select quote(bin) from $2 where id='$3' and val='$4'" 4.11 - sql="select quote(bin) from $2 where rowid='$3'" 4.12 - sq $db "$sql" | xxd -r -p > $bin 4.13 - # type=`sq $db "select type from $2 where id='$3' and val='$4'"` 4.14 - tv=`sq $db "select type,val from $2 where rowid='$3'"` 4.15 + sql="select quote(bin) from $2 where rowid='$3';" 4.16 + sq $db "$sql" | unhexize > $bin 4.17 + tv=`query "select type,val from $2 where rowid='$3';"` 4.18 type=${tv%|*} fn=${tv#*|} 4.19 err tv=$tv type=$type fn=$fn 4.20 ct=${type#file:} 4.21 @@ -284,7 +282,7 @@ 4.22 ## contenttype "Image/jpeg" 4.23 sql="select quote(b) from te where a='${2:-mikan.jpg}'" 4.24 idir=`umask 002; mktempd` || exit 1 4.25 - tmpfiles=$tmpfiles"${tmpfiles+ }$idir" 4.26 + # tmpfiles=$tmpfiles"${tmpfiles+ }$idir" 4.27 img=$idir/$myname-$$.bin 4.28 db=b.sq3 4.29 sqlite3 $db "$sql" | xxd -r -p > $img