# HG changeset patch # User HIROSE Yuuji # Date 1437383360 -32400 # Node ID 3565d93c2fb1221741dd5228af5ebb7033b4b20a # Parent 63c0e22870bb4e3cd041f5c03233bf88b8d3c7b2 add mpsplit.pl diff -r 63c0e22870bb -r 3565d93c2fb1 mpsplit.pl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mpsplit.pl Mon Jul 20 18:09:20 2015 +0900 @@ -0,0 +1,34 @@ +#!/usr/bin/env perl +$sep = "--" . $ARGV[0]; +$dir = ($ARGV[1] || "tmp"); + +#print "sep=".$sep, "dir=$dir\n"; +#binmode STDIN; +$/ = undef; +$stream = (); +$n=0; +@slices = split($sep, $stream); +shift(@slices); +pop(@slices); +foreach $item (@slices) { + $item =~ s/^\n//; + ($header = $item) =~ s/\r\n\r\n.*//s; + ($body = $item) =~ s/.*?\r\n\r\n//s; + $body =~ s/\r\n$//; + #print "h=[$header]\n"; + #print "b=[$body]\n"; + unless ($header =~ /\bname=([\"']?)(.*?)\1/) { + next; + } + $name = $2; + #print "name=$name\n"; + if ($header =~ /filename=(['\"]?)(.*?)\1/ && $2 gt "") { + $fn = $2; + open(OUT, ">$dir/$fn"); + print OUT $body; + close(OUT); + printf("%s:filename=%s\n", $name, unpack("H*", $fn)); + } else { + printf("%s=%s\n", $name, unpack("H*", $body)); + } +} diff -r 63c0e22870bb -r 3565d93c2fb1 mpsplit.rb --- a/mpsplit.rb Mon Jul 20 11:53:05 2015 +0900 +++ b/mpsplit.rb Mon Jul 20 18:09:20 2015 +0900 @@ -20,10 +20,12 @@ open(File.expand_path(fn, tmpdir).untaint, "w") do |out| out.write body end - printf("%s:filename=%s\n", name, fn) +## printf("%s:filename=%s\n", name, fn) + printf("%s:filename=%s\n", name, fn.unpack("H*")[0]) elsif /name=(['\"]?)(.*?)\1/ =~ header v=$2 - out=NKF::nkf("-w -MQ", body).gsub(/([^=])\n/, "\\1=0a").gsub(/=\n/, "") - printf("%s=%s\n", v, out) +# out=NKF::nkf("-w -MQ", body).gsub(/([^=])\n/, "\\1=0a").gsub(/=\n/, "") +# printf("%s=%s\n", v, out) + printf("%s=%s\n", v, body.unpack("H*")[0]) end end diff -r 63c0e22870bb -r 3565d93c2fb1 y4-funcs.sh --- a/y4-funcs.sh Mon Jul 20 11:53:05 2015 +0900 +++ b/y4-funcs.sh Mon Jul 20 18:09:20 2015 +0900 @@ -442,7 +442,7 @@ esac) } mktempd() { - TMPDIR=$tmpdir mktemp -d -t $session + TMPDIR=$tmpd mktemp -d -t $session } getval() { # $1=table $2=col $3(optional)=condition @@ -939,7 +939,7 @@ cgiinit() { session=`date +%F-$$` tmpf=tmp/stream - tmpd=`mktempd` + tmpd=`tmpd=$tmpdir mktempd` tmpfiles=$tmpfiles" $tmpd" addsession $session getcookie @@ -954,12 +954,13 @@ case "$CONTENT_TYPE" in *boundary*) bndry=${CONTENT_TYPE#*boundary=} - for us in `LC_CTYPE=C ./mpsplit.rb "$bndry" $tmpdir < $tmpf` + #for us in `LC_CTYPE=C ./mpsplit.rb "$bndry" $tmpdir < $tmpf` + for us in `LC_CTYPE=C ./mpsplit.pl "$bndry" $tmpdir < $tmpf` do k=${us%%\=*} #echo u=$us - # v="`echo ${us#*=}|nkf -Ww -mQ|sed -e 's/=/=3d/g' -e 's/\"/=22/g'`" - v="`echo ${us#*=}|nkf -Ww -mQ|sed -e 's/\"/\"\"/g'`" + #v="`echo ${us#*=}|nkf -Ww -mQ|sed -e 's/\"/\"\"/g'`" + v="`echo ${us#*=}|unhexize`" # err k=$k v=$v case "$k" in *:filename) diff -r 63c0e22870bb -r 3565d93c2fb1 y4.cgi --- a/y4.cgi Mon Jul 20 11:53:05 2015 +0900 +++ b/y4.cgi Mon Jul 20 18:09:20 2015 +0900 @@ -254,13 +254,11 @@ putfooter; exit fi idir=`umask 002; mktempd` || exit 1 - tmpfiles=$tmpfiles"${tmpfiles+ }$idir" + # tmpfiles=$tmpfiles"${tmpfiles+ }$idir" bin=$idir/$myname-$$.bin - ##sql="select quote(bin) from $2 where id='$3' and val='$4'" - sql="select quote(bin) from $2 where rowid='$3'" - sq $db "$sql" | xxd -r -p > $bin - # type=`sq $db "select type from $2 where id='$3' and val='$4'"` - tv=`sq $db "select type,val from $2 where rowid='$3'"` + sql="select quote(bin) from $2 where rowid='$3';" + sq $db "$sql" | unhexize > $bin + tv=`query "select type,val from $2 where rowid='$3';"` type=${tv%|*} fn=${tv#*|} err tv=$tv type=$type fn=$fn ct=${type#file:} @@ -284,7 +282,7 @@ ## contenttype "Image/jpeg" sql="select quote(b) from te where a='${2:-mikan.jpg}'" idir=`umask 002; mktempd` || exit 1 - tmpfiles=$tmpfiles"${tmpfiles+ }$idir" + # tmpfiles=$tmpfiles"${tmpfiles+ }$idir" img=$idir/$myname-$$.bin db=b.sq3 sqlite3 $db "$sql" | xxd -r -p > $img