ref: de06aef194165f01b3c8ba55b4e6c2fa48a84d18
parent: e5a84b2eaed7326db5ac7f673569fc8c70b6d16a
author: uriel <uriel@engel.se.cat-v.org>
date: Thu Jan 22 09:21:40 EST 2009
Rewrite http post parsing code, this should be faster and cleaner, added a get_post_args function to keep backwards compat but it is not really needed. Fix a silly bug in urldecode.
--- a/bin/cgilib.rc
+++ b/bin/cgilib.rc
@@ -25,34 +25,33 @@
# Status is () if at least one arg is found.
-fn get_post_args {- _status='Args not found'
- if(! ~ $REQUEST_METHOD POST)
- _status='No http post!'
- if not if(~ $#POST_ARGS 0) {+# Note: should check if content type is application/x-www-form-urlencoded?
+fn load_post_args {+ if(~ $REQUEST_METHOD POST && ~ $#post_args 0) {ifs='&
' for(pair in `{cat}) {- pair=`{echo -n $pair | sed 's/=/\&/'}- # Maybe we should urldecode on the first pass?
- POST_ARGS=( $POST_ARGS $pair )
- _get_post_args_set_var $pair $*
+ ifs='=' { pair=`{echo -n $pair} }+ n='post_arg_'^`{echo $pair(1)|tr -cd 'a-zA-Z0-9_'}+ post_args=( $post_args $n )
+ $n=`{echo -n $pair(2) | urldecode}}
+ pair=()
}
- if not {- pair=$POST_ARGS
- while(! ~ $#pair 0) {- _get_post_args_set_var $pair $*
- pair=$pair(3-)
+ if not
+ status='No POST or post args already loaded'
+}
+fn get_post_args {+ load_post_args
+ _status='No post arg matches'
+ for(n in $*) {+ v=post_arg_$n
+ if(! ~ $#$v 0) {+ $n=$$v
+ _status=()
}
}
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 {@@ -104,7 +103,7 @@
decoded = decoded c
++i
}
- printf decoded
+ printf "%s", decoded
}
'
}
--- a/sites/werc.cat-v.org/_werc/config
+++ b/sites/werc.cat-v.org/_werc/config
@@ -1,3 +1,5 @@
siteTitle='werc'
siteSubTitle=' Bringing minimalism and sanity to the web'
+enable_comments=yes
+enabled_apps=($enabled_apps hello dirdir bridge)
--
⑨