3 [ "$include_multipart" ] && return 0
6 if [ "${CONTENT_TYPE}" -a ! "${CONTENT_TYPE##multipart/form-data;*}" ]; then
7 multipart_boundary="${CONTENT_TYPE#*; boundary=}"
8 multipart_boundary="${multipart_boundary%%;*}"
9 multipart_boundary="${multipart_boundary%${CR}}"
11 multipart_cachefile="/tmp/multipart.$$"
14 # read n bytes, like `head -c` but do not consume input
17 for block in 65536 32768 16384 8192 4096 2048 1024 512 256 128 64 32 16 8 4 2 1; do
18 if [ $size -ge $block ]; then
19 dd status=none bs="$block" count="$((size / block))"
20 size="$((size % block))"
26 multipart_cachefile="${1:-${multipart_cachefile}}" # global
28 if [ "${multipart_boundary}" ]; then
29 # readbytes "$(( CONTENT_LENGTH ))" >"${multipart_cachefile}"
30 head -c "$(( CONTENT_LENGTH ))" >"${multipart_cachefile}"
37 local name="$1" count="${2:-1}"
38 local formdata state=begin
40 while IFS='' read -r formdata; do case "$formdata" in
41 "--${multipart_boundary}--${CR}")
42 [ $state = data ] && return 0 \
45 "--${multipart_boundary}${CR}")
46 [ $state = data ] && return 0 \
49 "Content-Disposition: form-data; name=\"${name}\""*"${CR}")
50 [ $state = header -a $count -eq 1 ] && state=dheader
51 [ $state = header -a $count -gt 1 ] && count=$((count - 1))
52 [ $state = data ] && printf "%s\n" "$formdata"
55 if [ $state = dheader ]; then
56 sed -n "/--${multipart_boundary}\(--\)\?${CR}/q; p;" \
60 [ $state = header ] && state=junk
62 esac; done <"${multipart_cachefile}"
66 local name="$1" count="${2:-1}"
67 local formdata state=begin
69 while read -r formdata; do case "$formdata" in
70 "--${multipart_boundary}--${CR}")
73 "--${multipart_boundary}${CR}")
76 "Content-Disposition: form-data; name=\"${name}\"; filename=\""*"\""*"${CR}")
77 [ $state = header -a $count -eq 1 ] && break
78 [ $state = header -a $count -gt 1 ] && count=$((count - 1))
81 [ $state = header ] && state=junk
83 esac; done <"${multipart_cachefile}"
85 filename="${formdata#*; filename=\"}"
86 filename="${filename%%\"${CR}}"
87 filename="${filename%%\";*}"
89 HEX_DECODE % "$filename"