1# Common routines for handling URIs 2 3package require st_client 4namespace eval stapi { 5 6 # 7 # uri_esc - escape a string for passing in a URI/URL 8 # 9 proc uri_esc {string {extra ""}} { 10 if {[catch {escape_string $string} result] == 0} { 11 # we were running under Apache Rivet and could use its existing command. 12 return $result 13 } else { 14 # TODO: this is not very good and is probably missing some cases. 15 foreach c [split "%\"'<> $extra" ""] { 16 scan $c "%c" i 17 regsub -all "\[$c]" $string [format "%%%02X" $i] string 18 } 19 return $string 20 } 21 } 22 23 # 24 # uri_unesc - unescape a string after passing it through a URI/URL 25 # 26 proc uri_unesc {string} { 27 if {[catch {unescape_string $string} result] == 0} { 28 # we were running under Apache Rivet and could use its existing command. 29 return $result 30 } else { 31 # TODO: this is not very good and is probably missing some cases. 32 foreach c [split {\\$[} ""] { 33 scan $c "%c" i 34 regsub -all "\\$c" $string [format "%%%02X" $i] string 35 } 36 regsub -all {%([0-9A-Fa-f][0-9A-Fa-f])} $string {[format %c 0x\1]} string 37 return [subst $string] 38 } 39 } 40 41} 42 43package provide st_client_uri 1.13.12 44 45# vim: set ts=8 sw=4 sts=4 noet : 46