From 588c035b3b7c0cc43dbe86fa50dadd864d22fa01 Mon Sep 17 00:00:00 2001 From: Uriel Date: Sat, 14 Mar 2009 00:28:34 +0100 Subject: [PATCH] Rewrite redirect handling code with nested lists. New ll_addh to add items to the head of a nested list (use with care!). --- bin/cgilib.rc | 7 +++++++ bin/werc.rc | 22 +++++++++------------- bin/wercconf.rc | 2 +- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/bin/cgilib.rc b/bin/cgilib.rc index eb14d12..1dfb8ca 100644 --- a/bin/cgilib.rc +++ b/bin/cgilib.rc @@ -157,6 +157,13 @@ fn ll_add { $_l=$*(2-) $1=( $$1 $_l ) } +# Add to the head: dangerous if you shrink list by hand! +fn ll_addh { + _l=$1^_^$#$1 + $_l=$*(2-) + $1=( $_l $$1 ) +} + NEW_LINE=' ' diff --git a/bin/werc.rc b/bin/werc.rc index 115622c..75aa157 100755 --- a/bin/werc.rc +++ b/bin/werc.rc @@ -89,20 +89,16 @@ fn werc_exec_request { if(~ $#perm_redir_to 1) perm_redirect $perm_redir_to - p=(); - for(i in $perm_redir_patterns) { - if(~ $#p 0) - p=$i - if not { - # If target is absolute, require patern matches whole string - if(~ $i http://* https://) - p='^'$p - t=`{ echo $req_path | sed 's!'$p'!'$i'!' } + for(l in $perm_redir_patterns) { + p=$$l + r=$p(1) + # If target is absolute, then patern must match whole string + if(~ $p(2) http://* https://) + r='^'$r + t=`{ echo $req_path | sed 's!'^$r^'!'^$p(2)^'!' } # Malicious danger! - if(! ~ $"t '' && ! ~ $t $req_path) - perm_redirect $t - p=() - } + if(! ~ $"t '' $req_path) + perm_redirect $t } # Set Page title diff --git a/bin/wercconf.rc b/bin/wercconf.rc index ee49104..bb3422d 100644 --- a/bin/wercconf.rc +++ b/bin/wercconf.rc @@ -3,7 +3,7 @@ fn conf_perm_redirect { if(~ $#* 1) perm_redir_to=$1 if not - perm_redir_patterns=($1 $2 $perm_redir_patterns) + ll_addh perm_redir_patterns $1 $2 } fn conf_hide_paths {