wok-current rev 9596

busybox/httpd_helper.sh: add POST & GET arrays support
author Pascal Bellard <pascal.bellard@slitaz.org>
date Wed Apr 13 11:06:30 2011 +0200 (2011-04-13)
parents a2ceb81a791d
children b0437daaa419
files busybox/stuff/httpd_helper.sh
line diff
     1.1 --- a/busybox/stuff/httpd_helper.sh	Tue Apr 12 16:24:21 2011 +0000
     1.2 +++ b/busybox/stuff/httpd_helper.sh	Wed Apr 13 11:06:30 2011 +0200
     1.3 @@ -22,17 +22,25 @@
     1.4  
     1.5  GET()
     1.6  {
     1.7 -[ -z "$1" ] && echo $GET__NAMES || [ -n "$GET__NAMES" ] && eval httpd -d \$GET_$1
     1.8 +local n
     1.9 +n=$2
    1.10 +[ -n "$n" ] || n=1
    1.11 +[ -z "$1" ] && echo $GET__NAMES ||
    1.12 +	[ -n "$GET__NAMES" ] && eval echo \$GET_${1}_$n
    1.13  }
    1.14  
    1.15  POST()
    1.16  {
    1.17 -[ -z "$1" ] && echo $POST__NAMES || [ -n "$POST__NAMES" ] && eval httpd -d \$POST_$1
    1.18 +local n
    1.19 +n=$2
    1.20 +[ -n "$n" ] || n=1
    1.21 +[ -z "$1" ] && echo $POST__NAMES ||
    1.22 +	[ -n "$POST__NAMES" ] && eval echo \$POST_${1}_$n
    1.23  }
    1.24  
    1.25  FILE()
    1.26  {
    1.27 -[ -z "$1" ] && echo $FILE__NAMES || [ -n "$FILE__NAMES" ] && eval httpd -d \$FILE_${1}_$2
    1.28 +[ -z "$1" ] && echo $FILE__NAMES || [ -n "$FILE__NAMES" ] && eval echo \$FILE_${1}_$2
    1.29  }
    1.30  
    1.31  httpinfo()
    1.32 @@ -50,10 +58,22 @@
    1.33  	[ -n "$x" ] && echo "$i='$x'"
    1.34  done
    1.35  for i in $GET__NAMES ; do
    1.36 -	echo "GET[$i]='$(GET $i)'"
    1.37 +	if [ $(GET $i count) -gt 1 ]; then
    1.38 +		for j in $(seq 1 $(GET $i count)); do
    1.39 +			echo "GET[$i][$j]='$(GET $i $j)'"
    1.40 +		done
    1.41 +	else
    1.42 +		echo "GET[$i]='$(GET $i)'"
    1.43 +	fi
    1.44  done
    1.45  for i in $POST__NAMES ; do
    1.46 -	echo "POST[$i]='$(POST $i)'"
    1.47 +	if [ $(POST $i count) -gt 1 ]; then
    1.48 +		for j in $(seq 1 $(POST $i count)); do
    1.49 +			echo "POST[$i][$j]='$(POST $i $j)'"
    1.50 +		done
    1.51 +	else
    1.52 +		echo "POST[$i]='$(POST $i)'"
    1.53 +	fi
    1.54  done
    1.55  for i in $FILE__NAMES ; do
    1.56  	for j in name size type tmpname ; do
    1.57 @@ -66,11 +86,20 @@
    1.58  {
    1.59  local i
    1.60  local names
    1.61 +local cnt
    1.62  names=""
    1.63  IFS="&"
    1.64  for i in $QUERY_STRING ; do
    1.65 -	names="$names ${i%%=*}"
    1.66 -	eval ${1}_${i%%=*}=\'$(httpd -d "${i#*=}" | sed "s/'/\'\\\\\'\'/g")\'
    1.67 +	var=${i%%=*}
    1.68 +	case " $names " in
    1.69 +	*\ $var\ *)
    1.70 +		eval cnt=\$${1}_${var}_count ;;
    1.71 +	*)	
    1.72 +		cnt=0
    1.73 +		names="$names $var" ;;
    1.74 +	esac
    1.75 +	eval ${1}_${var}_count=$((++cnt))
    1.76 +	eval ${1}_${var}_$cnt=\'$(httpd -d "${i#*=}" | sed "s/'/\'\\\\\'\'/g")\'
    1.77  done
    1.78  unset IFS
    1.79  eval ${1}__NAMES=\'${names# }\'