Websh provides a command dispatching mechanism to produce, for example, different HTML pages within one "application", which is most likely one file on the file system. The name of the command to be used for a particular page is encoded in the querystring (see web::cmdurl for details on how to produce such querystrings). Command dispatching is initiated with the command web::dispatch. Commands are defined with web::command.
web::command
?cmdName
? cmdBody
Registers cmdBody as cmdName. If cmdName is omitted, "default" is used.
Example 2. Simple command dispatching
proc page {title code} { web::put "<html><title>[web::htmlify $title]</title><body>" web::put "<h1>[web::htmlify $title]</h1>" uplevel 1 $code web::put {</body></html>} } web::command default { page "Home" { web::put "<a href=\"[web::cmdurl page1]\">Link to Page 1</a>" web::put "<br/>" web::put "<a href=\"[web::cmdurl page2]\">Link to Page 2</a>" } } web::command page1 { page "Page 1" { web::put "<a href=\"[web::cmdurl default]\">Home</a>" } } web::command page2 { page "Page 2" { web::put "<a href=\"[web::cmdurl default]\">Home</a>" } } web::dispatch
web::getcommand
?cmdName
?Retrieves the body of the command commandName or of the command "default" if cmdName is omitted.
web::cmdurl
?options
? cmdName
?key-value-list
?
web::cmdurl
?options
? cmdName
?k1 v1 ... kN vN
?
Options are: -notimestamp, and -urlformat
Generate URLs including querystring. By default, URLs are self-referencing, but the exact output is subject to configuration. The querystring is encrypted, using the encryption method specified by configuration (see web::config). If cmdName is "", no command parameter is produced in the query string.
list
Example 3. web::cmdurl
% web::cmdurl -notimestamp -urlformat [list scheme host scriptname pathinfo querystring] "test" http://websh.com/bin/returnmail/member?XDZuRD2rnsfHjFH %
web::cmdurlcfg
?option
? ?key
? ?value
?
Command options are exactly like those of web::param.
web::cmdurlcfg
option
?value
?
Options are -scheme, -host, -port, -scriptname, -pathinfo, -querystring, -urlformat
If value is omitted, the current value is returned. Otherwise, the value is stored. Configuration for web::cmdurl. This command serves two purposes:
By "static parameters", we mean those which are set for every page, instead of set on a per-page basis.
In addition to the easy way of tracking parameters using web::dispatch -track ..., specific values for parameters can be set using web::cmdurlcfg: In order to explicitly set, retrieve, append or unset static parameters, use the syntax of the web::param command, for example:
key
value
Important: web::cmdurl compares every key from the static parameters (see web::cmdurlcfg) against the keys from the command line. The static parameter is only used if there is no parameter of the same name given on the command line.
value
?value
?list
In all these cases, "web::cmdurlcfg -option value" sets the value of the given option and returns the value that was used before the change, while "web::cmdurlcfg -option" returns the current value. If no value has been set using web::cmdurlcfg, but is requested for the URL generation, the value from the request will be used. This value, however, can not be retrieved using web::cmdurlcfg.
Note that setting a value to an empty string is the same as using -unset.
Also note: web::cmdurl compares every key from the static parameters against the keys from the command line. The static parameter is only used if there is no such parameter on the command line.
Example 4. web::cmdurl and web::cmdurlcfg
% web::cmdurl "" ?XDqPtk34XvyPh41gUBo % web::cmdurlcfg -scriptname bin/test_script % web::cmdurl "" bin/test_script?XDqPtk34XvyPh41gUBo % web::cmdurlcfg -scriptname "" % web::cmdurl "" ?XDqPtk34XvyPh41gUBo % web::cmdurlcfg -urlformat {scheme host port querystring} scriptname pathinfo querystring % # for clearer view on what happens: disable querystring encryption % web::config encryptchain {} web::encryptd % web::cmdurlcfg -set foo bar bar % web::cmdurlcfg -host tcl.apache.org % web::cmdurl zoo http://tcl.apache.org:80?foo=bar&cmd=zoo&t=1141776460 % web::cmdurlcfg -reset % web::cmdurl zoo ?foo=bar&cmd=zoo&t=1141776496 % web::config cmdurltimestamp 0 1 % web::config cmdparam page cmd % web::cmdurl zoo ?foo=bar&page=zoo %
web::dispatch
?options
?Options are: -cmd, -querystring, -postdata, -track and -hook.
Parse information and call a command.
cmdName
string
channelName
?content_length?
?content_type?
application/x-www-form-urlencoded
or multipart/form-data;
boundary=xxx
.
In the case of multipat form data,
content-type must specify the
boundary as well. By default, POST data is taken from
the request data.application/x-www-form-urlencoded
.
Default for content_length is to read a
channel up to EOF or the full content of the variable.
end
for
content_length to indicate that
Websh should read all content.multipart/form-data; boundary=xxxx
application/x-www-form-urlencoded
(default)paramKeyList
code
Note: If no command is passed to web::dispatch either in the querystring or with the -cmd option, web::dispatch will call the command "default".
Example 5. web::command and web::dispatch
% set tst {puts "On the hook"} puts "On the hook" % web::command acmd {puts "this is acmd"} % web::dispatch -cmd acmd -querystring "" -postdata "" this is acmd % web::dispatch -cmd acmd -querystring "" -postdata "" -hook $tst On the hook this is acmd % set data "a=b&c=d" a=b&c=d % web::dispatch -cmd "" -querystring "" -postdata #data % web::formvar a b % web::formvar c d %
Websh session management consits of two parts:
Session context managers are described in detail below (web::filecontext, web::cookiecontext). Session id tracking is managed by web::dispatch -track. The two parts are connected with the -attachto option of the session context manager. The control is as follows:
id
.
id
(which has been specified at
creation time of the session manager using the
-attachto option). Now, it tries to
create a new session id. This will be possible if a
session id generator has been specified when the manager
was created using the -idgen option.
From now, on the session id will be a static parameter,
and will therefore be present in every URL generated
with web::cmdurl.
Example 6. Examples
See http://tcl.apache.org/websh/examples/ for several sample application demonstrating Websh's session management facilities.