53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
-
-
-
+
+
+
+
+
+
-
-
-
+
+
+
+
|
# Change the reply code.
#
proc wapp-reply-code {x} {
global wapp
dict set wapp .reply-code $x
}
# This is a safety-check that is run prior to startup
#
# Examine the bodys of all procedures in this program looking for
# unsafe calls to "wapp". Issue warnings.
# unsafe calls to "wapp". Return a text string containing warnings.
# Return an empty string if all is ok.
#
# This routine is advisory only. It misses some constructs that are
# dangerous and flags others that are safe.
#
proc wapp-safety-check {} {
set res {}
foreach p [info procs] {
set ln 0
foreach x [split [info body $p] \n] {
incr ln
if {[regexp {[;\n] *wapp +\[} $x] ||
[regexp {[;\n] *wapp +"[^\n]*[[$]} $x]} {
puts "$p:$ln: unsafe \"wapp\" call: \"[string trim $x]\"\n"
if {[regexp {^[ \t]*wapp[ \t]+\[} $x] ||
[regexp {^[ \t]*wapp[ \t]+[^\173][^\n]*[[$]} $x]} {
append res "$p:$ln: unsafe \"wapp\" call: \"[string trim $x]\"\n"
}
}
}
return $res
}
# Start up the wapp framework. Parameters are a list passed as the
# single argument.
#
# -port $PORT Listen on this TCP port
#
|
254
255
256
257
258
259
260
261
262
263
264
265
266
267
|
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
|
+
+
+
+
+
+
+
+
+
|
dict set W BASE_URL {}
} elseif {[dict exists $W HTTPS]} {
dict set W BASE_URL https://[dict get $W .hdr:HOST]
} else {
dict set W BASE_URL http://[dict get $W .hdr:HOST]
}
dict set W SELF_URL [dict get $W BASE_URL]/[dict get $W PATH_HEAD]
if {[dict exists $W .hdr:COOKIE]} {
foreach qterm [split [dict get $W .hdr:COOKIE] {;}] {
set qsplit [split [string trim $qterm] =]
set nm [lindex $qsplit 0]
if {[regexp {^[a-z][-a-z0-9_]*$} $nm]} {
dict set W $nm [wappInt-url-decode [lindex $qsplit 1]]
}
}
}
}
# Invoke application-supplied methods to generate a reply to
# a single HTTP request.
#
# This routine always runs within [catch], so handle exceptions by
# invoking [error].
|