1ncgi(n)                           CGI Support                          ncgi(n)
2
3
4
5______________________________________________________________________________
6

NAME

8       ncgi - Procedures to manipulate CGI values.
9

SYNOPSIS

11       package require Tcl  8.2
12
13       package require ncgi  ?1.3?
14
15       ::ncgi::cookie cookie
16
17       ::ncgi::decode str
18
19       ::ncgi::empty name
20
21       ::ncgi::exists name
22
23       ::ncgi::encode string
24
25       ::ncgi::header ?type? args
26
27       ::ncgi::import cginame ?tclname?
28
29       ::ncgi::importAll args
30
31       ::ncgi::importFile cmd cginame ?filename?
32
33       ::ncgi::input ?fakeinput? ?fakecookie?
34
35       ::ncgi::multipart type query
36
37       ::ncgi::nvlist
38
39       ::ncgi::names
40
41       ::ncgi::parse
42
43       ::ncgi::parseMimeValue value
44
45       ::ncgi::query
46
47       ::ncgi::redirect url
48
49       ::ncgi::reset query type
50
51       ::ncgi::setCookie args
52
53       ::ncgi::setDefaultValue key defvalue
54
55       ::ncgi::setDefaultValueList key defvaluelist
56
57       ::ncgi::setValue key value
58
59       ::ncgi::setValueList key valuelist
60
61       ::ncgi::type
62
63       ::ncgi::urlStub ?url?
64
65       ::ncgi::value key ?default?
66
67       ::ncgi::valueList key ?default?
68
69_________________________________________________________________
70

DESCRIPTION

72       The  ncgi  package provides commands that manipulate CGI values.  These
73       are values that come from Web forms and are  processed  either  by  CGI
74       scripts  or  web pages with embedded Tcl code.  Use the ncgi package to
75       query these values, set and get cookies, and encode and decode www-url-
76       encoded values.
77
78       In  the  simplest case, a CGI script first calls ::ncgi::parse and then
79       calls ::ncgi::value to get different form values.  If a  CGI  value  is
80       repeated,  you  should  use  ::ncgi::valueList to get back the complete
81       list of values.
82
83       An alternative to ::ncgi::parse is ::ncgi::input, which  has  semantics
84       similar  to  Don  Libes'  cgi_input procedure.  ::ncgi::input restricts
85       repeated CGI values to have names that end with "List".  In this  case,
86       ::ncgi::value   will   return   the   complete   list  of  values,  and
87       ::ncgi::input will raise errors if it find repeated form elements with‐
88       out the right name.
89
90       The  ::ncgi::reset procedure can be used in test suites and Web servers
91       to initialize the source of the CGI values.  Otherwise the  values  are
92       read in from the CGI environment.
93
94       The complete set of procedures is described below.
95
96       ::ncgi::cookie cookie
97              Return a list of values for cookie, if any.  It is possible that
98              more than one cookie with the same name can be present, so  this
99              procedure returns a list.
100
101       ::ncgi::decode str
102              Decode  strings  in  www-url-encoding,  which represents special
103              characters with a %xx sequence, where xx is the  character  code
104              in hex.
105
106       ::ncgi::empty name
107              Returns  1  if  the  CGI variable name is not present or has the
108              empty string as its value.
109
110       ::ncgi::exists name
111              Returns 1 if the CGI variable name is not present.
112
113       ::ncgi::encode string
114              Encode string into www-url-encoded format.
115
116       ::ncgi::header ?type? args
117              Output the CGI header to standard output.  This emits a Content-
118              Type:  header  and  additional headers based on args, which is a
119              list of header names and header values.  The  type  defaults  to
120              "text/html".
121
122       ::ncgi::import cginame ?tclname?
123              This  creates  a variable in the current scope with the value of
124              the CGI variable cginame.  The name of the variable is  tclname,
125              or cginame if tclname is empty (default).
126
127       ::ncgi::importAll args
128              This imports several CGI variables as Tcl variables.  If args is
129              empty, then every CGI value is  imported.   Otherwise  each  CGI
130              variable listed in args is imported.
131
132       ::ncgi::importFile cmd cginame ?filename?
133              This  provides  information  about  an uploaded file from a form
134              input field of type file with name cginame.  cmd can be  one  of
135              -server -client, -type or -data.
136
137              -client cginame
138                     returns the filename as sent by the client.
139
140              -type cginame
141                     returns the mime type of the uploaded file.
142
143              -data cginame
144                     returns the contents of the file.
145
146              -server cginame filename
147                     writes  the  file  contents to a local temporary file (or
148                     filename if supplied) and returns the name of  the  file.
149                     The  caller  is  responsible for deleting this file after
150                     use.
151
152       ::ncgi::input ?fakeinput? ?fakecookie?
153              This reads and decodes the CGI values from the environment.   It
154              restricts  repeated  form  values  to  have a trailing "List" in
155              their  name.   The  CGI  values  are  obtained  later  with  the
156              ::ncgi::value procedure.
157
158       ::ncgi::multipart type query
159              This procedure parses a multipart/form-data query.  This is used
160              by ::ncgi::nvlist and not normally called directly.  It  returns
161              an alternating list of names and structured values.  Each struc‐
162              ture value is in turn a list of two elements.  The first element
163              is meta-data from the multipart/form-data structure.  The second
164              element is the form value.  If you use  ::ncgi::value  you  just
165              get  the  form  value.  If you use ::ncgi::valueList you get the
166              structured value with meta data and the value.
167
168              The type is the whole  Content-Type,  including  the  parameters
169              like  boundary.   This  returns  a list of names and values that
170              describe the multipart data.   The  values  are  a  nested  list
171              structure  that  has some descriptive information first, and the
172              actual form value second.  The descriptive information  is  list
173              of header names and values that describe the content.
174
175       ::ncgi::nvlist
176              This  returns  all the query data as a name, value list.  In the
177              case  of  multipart/form-data,  the  values  are  structured  as
178              described in ::ncgi::multipart.
179
180       ::ncgi::names
181              This  returns  all  names  found  in  the query data, as a list.
182              ::ncgi::multipart.
183
184       ::ncgi::parse
185              This reads and decodes the CGI values from the environment.  The
186              CGI  values are obtained later with the ::ncgi::value procedure.
187              IF a CGI value is repeated, then  you  should  use  ::ncgi::val‐
188              ueList to get the complete list of values.
189
190       ::ncgi::parseMimeValue value
191              This  decodes  the Content-Type and other MIME headers that have
192              the form of "primary value; param=val; p2=v2" It returns a list,
193              where  the  first  element  is the primary value, and the second
194              element is a list of parameter names and values.
195
196       ::ncgi::query
197              This returns the raw query data.
198
199       ::ncgi::redirect url
200              Generate a response that  causes  a  302  redirect  by  the  Web
201              server.   The url is the new URL that is the target of the redi‐
202              rect.  The URL will be qualified with  the  current  server  and
203              current directory, if necessary, to convert it into a full URL.
204
205       ::ncgi::reset query type
206              Set the query data and Content-Type for the current CGI session.
207              This is used by the test suite and by Web servers to  initialize
208              the ncgi module so it does not try to read standard input or use
209              environment variables to get its data.  If neither query or type
210              are  specified,  then  the ncgi module will look in the standard
211              CGI environment for its data.
212
213       ::ncgi::setCookie args
214              Set a cookie value that will be returned as part of  the  reply.
215              This  must  be done before ::ncgi::header or ::ncgi::redirect is
216              called in order for the cookie to  be  returned  properly.   The
217              args are a set of flags and values:
218
219              -name name
220
221              -value value
222
223              -expires date
224
225              -path path restriction
226
227              -domain domain restriction
228
229       ::ncgi::setDefaultValue key defvalue
230              Set  a  CGI  value  if it does not already exists.  This affects
231              future  calls  to  ::ncgi::value  (but  not  future   calls   to
232              ::ncgi::nvlist).  If the CGI value already is present, then this
233              procedure has no side effects.
234
235       ::ncgi::setDefaultValueList key defvaluelist
236              Like ::ncgi::setDefaultValue except that the value  already  has
237              list  structure  to  represent  multiple  checkboxes or a multi-
238              selection.
239
240       ::ncgi::setValue key value
241              Set a CGI value, overriding whatever  was  present  in  the  CGI
242              environment already.  This affects future calls to ::ncgi::value
243              (but not future calls to ::ncgi::nvlist).
244
245       ::ncgi::setValueList key valuelist
246              Like ::ncgi::setValue except that the  value  already  has  list
247              structure to represent multiple checkboxes or a multi-selection.
248
249       ::ncgi::type
250              Returns the Content-Type of the current CGI values.
251
252       ::ncgi::urlStub ?url?
253              Returns  the  current URL, but without the protocol, server, and
254              port.  If url is specified, then it defines the URL for the cur‐
255              rent  session.   That  value will be returned by future calls to
256              ::ncgi::urlStub
257
258       ::ncgi::value key ?default?
259              Return the CGI value identified by key.  If the CGI value is not
260              present,  then the default value is returned instead. This value
261              defaults to the empty string.
262
263              If the form value key is repeated, then there are two cases:  if
264              ::ncgi::parse  was  called,  then ::ncgi::value only returns the
265              first value associated with key.  If ::ncgi::input  was  called,
266              then  ::ncgi::value returns a Tcl list value and key must end in
267              "List" (e.g., "skuList").  In the case  of  multipart/form-data,
268              this  procedure  just returns the value of the form element.  If
269              you want the meta-data associated with each form value, then use
270              ::ncgi::valueList.
271
272       ::ncgi::valueList key ?default?
273              Like  ::ncgi::value,  but  this  always returns a list of values
274              (even if there is only  one  value).   In  the  case  of  multi‐
275              part/form-data,  this  procedure returns a list of two elements.
276              The first element is meta-data in the form of a parameter, value
277              list.  The second element is the form value.
278

SEE ALSO

280       html
281

KEYWORDS

283       CGI, cookie, form, html
284
285
286
287ncgi                                  1.3                              ncgi(n)
Impressum