changelog shortlog tags branches files raw gz bz2 help

Mercurial > hg > werc / changeset: Rewrite http post parsing code, this should be faster and cleaner, added a

changeset 350: 902c2bbda282
parent 349: 56c0493bdf6e
child 351: e6e6f75df936
author: uriel@engel.se.cat-v.org
date: Thu, 22 Jan 2009 14:21:40 +0100
files: bin/cgilib.rc sites/werc.cat-v.org/_werc/config
description: 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.
     1.1--- a/bin/cgilib.rc	Thu Jan 22 09:24:10 2009 +0100
     1.2+++ b/bin/cgilib.rc	Thu Jan 22 14:21:40 2009 +0100
     1.3@@ -25,34 +25,33 @@
     1.4 
     1.5 
     1.6 # Status is () if at least one arg is found.
     1.7-fn get_post_args {
     1.8-    _status='Args not found'
     1.9-    if(! ~ $REQUEST_METHOD POST)
    1.10-        _status='No http post!'
    1.11-    if not if(~ $#POST_ARGS 0) {
    1.12+# Note: should check if content type is application/x-www-form-urlencoded?
    1.13+fn load_post_args {
    1.14+    if(~ $REQUEST_METHOD POST && ~ $#post_args 0) {
    1.15         ifs='&
    1.16 '       for(pair in `{cat}) {
    1.17-            pair=`{echo -n $pair | sed 's/=/\&/'}
    1.18-            # Maybe we should urldecode on the first pass?
    1.19-            POST_ARGS=( $POST_ARGS $pair )
    1.20-            _get_post_args_set_var $pair $*
    1.21+            ifs='=' { pair=`{echo -n $pair} }
    1.22+            n='post_arg_'^`{echo $pair(1)|tr -cd 'a-zA-Z0-9_'}
    1.23+            post_args=( $post_args $n )
    1.24+            $n=`{echo -n $pair(2) | urldecode}
    1.25         }
    1.26+        pair=()
    1.27     }
    1.28-    if not {
    1.29-        pair=$POST_ARGS
    1.30-        while(! ~ $#pair 0) {
    1.31-            _get_post_args_set_var $pair $*
    1.32-            pair=$pair(3-)
    1.33+    if not
    1.34+        status='No POST or post args already loaded'
    1.35+}
    1.36+fn get_post_args {
    1.37+    load_post_args
    1.38+    _status='No post arg matches'
    1.39+    for(n in $*) {
    1.40+        v=post_arg_$n
    1.41+        if(! ~ $#$v 0) {
    1.42+            $n=$$v
    1.43+            _status=()
    1.44         }
    1.45     }
    1.46     status=$_status
    1.47 }
    1.48-fn _get_post_args_set_var {
    1.49-    if(~ $1 $*(3-)) {
    1.50-        ifs=() { $1=`{echo -n $2 | urldecode | tr -d '
'} }
    1.51-        _status=()
    1.52-    }
    1.53-}
    1.54 
    1.55 # This seems slightly improve performance, but might depend on httpd buffering behavior.
    1.56 fn awk_buffer {
    1.57@@ -104,7 +103,7 @@
    1.58         decoded = decoded c
    1.59         ++i
    1.60     }
    1.61-    printf decoded
    1.62+    printf "%s", decoded
    1.63 }
    1.64 '
    1.65 }
     2.1--- a/sites/werc.cat-v.org/_werc/config	Thu Jan 22 09:24:10 2009 +0100
     2.2+++ b/sites/werc.cat-v.org/_werc/config	Thu Jan 22 14:21:40 2009 +0100
     2.3@@ -1,3 +1,5 @@
     2.4 siteTitle='werc'
     2.5 siteSubTitle=' Bringing minimalism and sanity to the web'
     2.6+enable_comments=yes
     2.7+enabled_apps=($enabled_apps hello dirdir bridge)
     2.8