ref: 19d6aa26e4a6bc77be5a0048ed55f4822b115181
parent: 34820f18ce85546e51fda38dd0f472dbfb762af7
author: uriel <[email protected]>
date: Sat Jan 10 23:02:07 EST 2009
- New static_file and select_mime functions. - Minor improvements to get_post_args, set status unless one of the requested args is present.
--- a/bin/cgilib.rc
+++ b/bin/cgilib.rc
@@ -16,28 +16,43 @@
exit
}
+fn static_file {
+ echo 'Content-Type: '`{select_mime $1}
+ echo
+ cat $1
+ exit
+}
+
+
+# Status is () if at least one arg is found.
fn get_post_args {
- if(~ $#POST_ARGS 0) {
+ _status='Args not found'
+ if(! ~ $REQUEST_METHOD POST)
+ _status='No http post!'
+ if not if(~ $#POST_ARGS 0) {
ifs='&
' for(pair in `{cat}) {
- pair=`{echo -n $pair | sed 's/=/\&/'} \
+ pair=`{echo -n $pair | sed 's/=/\&/'}
# Maybe we should urldecode on the first pass?
POST_ARGS=( $POST_ARGS $pair )
- ifs=() \
- if(~ $pair(1) $*)
- $pair(1)=`{echo -n $pair(2) | urldecode | tr -d ' '}
+ _get_post_args_set_var $pair $*
}
}
if not {
- pa=$POST_ARGS
- while(! ~ $#pa 0) {
- ifs=() \
- if(~ $pa(1) $*)
- $pa(1)=`{echo -n $pa(2) | urldecode | tr -d ' '}
- pa=$pa(3-)
+ pair=$POST_ARGS
+ while(! ~ $#pair 0) {
+ _get_post_args_set_var $pair $*
+ pair=$pair(3-)
}
}
+ status=$_status
}
+fn _get_post_args_set_var {
+ if(~ $1 $*(3-)) {
+ ifs=() { $1=`{echo -n $2 | urldecode | tr -d ' '} }
+ _status=()
+ }
+}
# This seems slightly improve performance, but might depend on httpd buffering behavior.
fn awk_buffer {
@@ -131,6 +146,22 @@
{ for(c in $co) echo $c } | sed -n 's/[^=]*=//p'
}
+fn select_mime {
+ m='text/plain'
+ if(~ $1 *.css)
+ m='text/css'
+ if not if(~ $1 *.ico)
+ m='image/x-icon'
+ if not if(~ $1 *.png)
+ m='image/png'
+ if not if(~ $1 *.jpg *.jpeg)
+ m='image/jpeg'
+ if not if(~ $1 *.gif)
+ m='image/gif'
+ if not if(~ $1 *.pdf)
+ m='application/pdf'
+ echo $m
+}
##############################################
# Generic rc programming helpers
@@ -247,7 +278,7 @@
###################################
# App framework
-fn select_apps {
+fn init_apps {
found=()
for(a in $enabled_apps) {
. ./apps/$a/app.rc