]> git.plutz.net Git - serve0/commitdiff
Merge commit 'b500b09d321e9657343e6d407c78d23c8da4b591'
authorPaul Hänsch <paul@plutz.net>
Sun, 12 Sep 2021 17:46:40 +0000 (19:46 +0200)
committerPaul Hänsch <paul@plutz.net>
Sun, 12 Sep 2021 17:46:40 +0000 (19:46 +0200)
1  2 
cgilite/cgilite.sh

diff --combined cgilite/cgilite.sh
index 7f828ddd6c8e2234c7cb3e2625505b5796e8eb77,6a4a64881faa4bc2836061399974e733bcdba010..6a4a64881faa4bc2836061399974e733bcdba010
  # set -o posix # ksh, not portable
  setopt -o OCTAL_ZEROES 2>&-
  
+ # Integrated webserver request timeout
+ cgilite_timeout=2
+ # General environment variables
+ # $_EXEC - directory containing application itself
+ # $_DATA - direcotry where application data may be stored
+ # $_BASE - optional prefix for http path, e.g. "/myapp"
+ #
+ # Programmers should take care to use those variables throughout the
+ # application.
+ # Variables may be set via CLI argument, in environment, or left as default.
+ for cgilite_arg in "$@"; do case $cgilite_arg in
+   --exec=*) _EXEC="${cgilite_arg#*=}";;
+   --data=*) _DATA="${cgilite_arg#*=}";;
+   --base=*) _BASE="${cgilite_arg#*=}";;
+ esac; done
+ unset cgilite_arg
+ _EXEC="${EXEC:-${0%/*}}"
+ _DATA="${DATA:-.}"
+ _EXEC="${_EXEC%/}" _DATA="${_DATA%/}" _BASE="${BASE%/}"
+ # Carriare Return and Line Break characters for convenience
  CR="\r"
  BR='
  '
- cgilite_timeout=2
  
  PATH(){ 
    local str seg out
@@@ -175,6 -198,8 +198,8 @@@ f
  debug(){ [ $# -gt 0 ] && printf '%s\n' "$@" >&2 || tee -a /dev/stderr; }
  [ "${DEBUG+x}" ] && env >&2
  
+ # general helper functions, see GET, POST, and REF below
  cgilite_count(){
    printf %s "&$1" \
    | grep -oE '&'"$2"'=[^&]*' \
@@@ -200,6 -225,17 +225,17 @@@ cgilite_keys()
    | sort -u
  }
  
+ # Read arguments from GET, POST, or the query string of the referrer (REF).
+ # Example:
+ # GET varname n
+ #
+ # where n is number for the Nth occurence of a variable and defaults to 1
+ #
+ # *_COUNT varname
+ # -> returns number of ocurences
+ # *_KEYS
+ # -> returns list of available varnames
  GET(){ cgilite_value "${QUERY_STRING}" "$@"; }
  GET_COUNT(){ cgilite_count "${QUERY_STRING}" $1; }
  GET_KEYS(){ cgilite_keys "${QUERY_STRING}"; }
@@@ -228,6 -264,7 +264,7 @@@ HEADER()
  }
  
  COOKIE(){
+   # Read value of cookie
    HEX_DECODE % "$(
      HEADER Cookie \
      | grep -oE '(^|; ?)'"$1"'=[^;]*' \
@@@ -302,6 -339,7 +339,7 @@@ SET_COOKIE()
  }
  
  REDIRECT(){
+   # Trigger redirct and terminate script
    printf '%s: %s\r\n' \
      Status "303 See Other" \
      Content-Length 0 \