]> git.plutz.net Git - cgilite/blobdiff - cgilite.sh
key listing functions: GET_KEYS() POST_KEYS() REF_KEYS()
[cgilite] / cgilite.sh
index 996fe9daa4befceac6e7461b7e4755e03feebe9c..8af3eb12790b998f59d8421778aff333c619ca53 100755 (executable)
@@ -22,8 +22,9 @@
 # set -o posix # ksh, not portable
 setopt -o OCTAL_ZEROES 2>&-
 
-BR="$(printf '\n')"
-CR="$(printf '\r')"
+CR="\r"
+BR='
+'
 cgilite_timeout=2
 
 HEADER(){
@@ -70,7 +71,7 @@ if [ -z "$REQUEST_METHOD" ]; then
     kill $cgilite_watchdog
     PATH_INFO="$(HEX_DECODE "${REQUEST_URI%\?*}")"
     QUERY_STRING="${REQUEST_URI#*\?}"
-    cgilite_headers="$(sed -u '/^\r\?$/q')"
+    cgilite_headers="$(while read -r hl; do [ "${hl%${CR}}" ] && printf '%s\n' "$hl" || break; done )"
 
     HTTP_CONTENT_LENGTH="$(HEADER Content-Length |grep -xE '[0-9]+')"
 
@@ -91,7 +92,7 @@ if [ -z "$REQUEST_METHOD" ]; then
              "$cgilite_response" "${cgilite_cl}"
            cat
            [ "${cgilite_cl#Connection}" = "${cgilite_cl}" ]; exit;;
-      *) cgilite_response="$cgilite_response${BR}$l";;
+      *) cgilite_response="${cgilite_response:+${cgilite_response}${BR}}${l}";;
     esac; done || exit 0;
     (sleep $cgilite_timeout && kill $$) & cgilite_watchdog=$!
   done
@@ -118,14 +119,26 @@ cgilite_value(){
   printf "$(printf %s "${str%%&*}" |sed -r 's;\+; ;g;'"$HEX_DECODE")"
 }
 
+cgilite_keys(){
+  local str="&$1"
+  while [ "${str#*&}" != "${str}" ]; do
+    str="${str#*&}"
+    printf '%s\n' "${str%%=*}"
+  done \
+  | sort -u
+}
+
 GET(){ cgilite_value "${QUERY_STRING}" $@; }
 GET_COUNT(){ cgilite_count "${QUERY_STRING}" $1; }
+GET_KEYS(){ cgilite_keys "${QUERY_STRING}"; }
 
 POST(){ cgilite_value "${cgilite_post}" $@; }
 POST_COUNT(){ cgilite_count "${cgilite_post}" $1; }
+POST_KEYS(){ cgilite_keys "${cgilite_post}"; }
 
 REF(){ cgilite_value "${HTTP_REFERER#*\?}" $@; }
 REF_COUNT(){ cgilite_count "${HTTP_REFERER#*\?}" $1; }
+REF_KEYS(){ cgilite_keys "${HTTP_REFERER#*\?}"; }
 
 COOKIE(){
   HEX_DECODE "$(