From 3bdb99773bc64396bf7faf353464925e53e50953 Mon Sep 17 00:00:00 2001 From: Uriel Date: Thu, 22 Jan 2009 14:21:40 +0100 Subject: [PATCH] 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. --- bin/cgilib.rc | 41 +++++++++++++++---------------- sites/werc.cat-v.org/_werc/config | 2 ++ 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/bin/cgilib.rc b/bin/cgilib.rc index 5aa0c47..3dcea4a 100644 --- a/bin/cgilib.rc +++ b/bin/cgilib.rc @@ -25,34 +25,33 @@ fn static_file { # 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 @@ BEGIN { decoded = decoded c ++i } - printf decoded + printf "%s", decoded } ' } diff --git a/sites/werc.cat-v.org/_werc/config b/sites/werc.cat-v.org/_werc/config index f2eaae0..9c577b0 100644 --- 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)