fi
}
+HEX_DECODE='
+ s;\\;\\\\;g; :HEXDECODE_X; s;%([^0-9A-F]);\\045\1;g; tHEXDECODE_X;
+ # Hexadecimal { %00 - %FF } will be transformed to octal { \000 - \377 } for posix printf
+ s;%[0123].;&\\0;g; s;%[4567].;&\\1;g; s;%[89AB].;&\\2;g; s;%[CDEF].;&\\3;g;
+ s;%[048C][0-7]\\.;&0;g; s;%[048C][89A-F]\\.;&1;g; s;%[159D][0-7]\\.;&2;g; s;%[159D][89A-F]\\.;&3;g;
+ s;%[26AE][0-7]\\.;&4;g; s;%[26AE][89A-F]\\.;&5;g; s;%[37BF][0-7]\\.;&6;g; s;%[37BF][89A-F]\\.;&7;g;
+ s;%.[08](\\..);\10;g; s;%.[19](\\..);\11;g; s;%.[2A](\\..);\12;g; s;%.[3B](\\..);\13;g;
+ s;%.[4C](\\..);\14;g; s;%.[5D](\\..);\15;g; s;%.[6E](\\..);\16;g; s;%.[7F](\\..);\17;g;
+'
+
HEX_DECODE(){
- printf "$(printf %s "$1" \
- | sed -r '
- s;\\;\\\\;g; :x; s;%([^0-9A-F]);\\045\1;g; tx;
- # Hexadecimal { %00 - %FF } will be transformed to octal { \000 - \377 } for posix printf
- s;%[0123].;&\\0;g; s;%[4567].;&\\1;g; s;%[89AB].;&\\2;g; s;%[CDEF].;&\\3;g;
- s;%[048C][0-7]\\.;&0;g; s;%[048C][89A-F]\\.;&1;g; s;%[159D][0-7]\\.;&2;g; s;%[159D][89A-F]\\.;&3;g;
- s;%[26AE][0-7]\\.;&4;g; s;%[26AE][89A-F]\\.;&5;g; s;%[37BF][0-7]\\.;&6;g; s;%[37BF][89A-F]\\.;&7;g;
- s;%.[08](\\..);\10;g; s;%.[19](\\..);\11;g; s;%.[2A](\\..);\12;g; s;%.[3B](\\..);\13;g;
- s;%.[4C](\\..);\14;g; s;%.[5D](\\..);\15;g; s;%.[6E](\\..);\16;g; s;%.[7F](\\..);\17;g;
- ')"
+ printf "$(printf %s "$1" |sed -r "$HEX_DECODE")"
}
if [ -z "$REQUEST_METHOD" ]; then
[ -n "${DEBUG+x}" ] && env
cgilite_count(){
- case $1 in
- GET) printf %s "&${QUERY_STRING}";;
- POST) printf %s "&${cgilite_post}";;
- REF) printf %s "&${HTTP_REFERER#*\?}";;
- esac \
- | grep -Eo '&'"$2"'=[^&]*' \
+ printf %s "&$1" \
+ | grep -oE '&'"$2"'=[^&]*' \
| wc -l
}
cgilite_value(){
- HEX_DECODE "$(
- case $1 in
- GET) printf %s "&${QUERY_STRING}";;
- POST) printf %s "&${cgilite_post}";;
- REF) printf %s "&${HTTP_REFERER#*\?}";;
- esac \
- | grep -Eo '&'"$2"'=[^&]*' \
- | sed -rn "${3:-1}"'{s;^[^=]+=;;; s;\+; ;g; p;}'
- )"
+ local str="&$1" name="$2" cnt="${3:-1}"
+ while [ $cnt -gt 0 ]; do
+ str=${str#*&${name}=}
+ cnt=$((cnt - 1))
+ done
+ printf "$(printf %s "${str%%&*}" |sed -r 's;\+; ;g;'"$HEX_DECODE")"
}
-GET(){ cgilite_value GET $@; }
-GET_COUNT(){ cgilite_count GET $1; }
+GET(){ cgilite_value "${QUERY_STRING}" $@; }
+GET_COUNT(){ cgilite_count "${QUERY_STRING}" $1; }
-POST(){ cgilite_value POST $@; }
-POST_COUNT(){ cgilite_count POST $1; }
+POST(){ cgilite_value "${cgilite_post}" $@; }
+POST_COUNT(){ cgilite_count "${cgilite_post}" $1; }
-REF(){ cgilite_value REF $@; }
-REF_COUNT(){ cgilite_count REF $1; }
+REF(){ cgilite_value "${HTTP_REFERER#*\?}" $@; }
+REF_COUNT(){ cgilite_count "${HTTP_REFERER#*\?}" $1; }
COOKIE(){
HEX_DECODE "$(