43# include <sys/utsname.h>
64 cout <<
"<form method=\"post\" action=\""
65 <<
cgi.getEnvironment().getScriptName() <<
"\">" <<
endl;
69 cout <<
"<tr><td class=\"title\">Your name</td>"
70 <<
"<td class=\"form\">"
71 <<
"<input type=\"text\" name=\"name\" value=\"Uncle Bob\" />"
72 <<
"</td></tr>" <<
endl;
74 cout <<
"<tr><td class=\"title\">Your salary in millions<br />(80-120)</td>"
75 <<
"<td class=\"form\">"
76 <<
"<input type=\"text\" name=\"bucks\" value=\"93\" />"
77 <<
"</td></tr>" <<
endl;
79 cout <<
"<tr><td class=\"title\">Hours you've wasted on the web</td>"
80 <<
"<td class=\"form\">"
81 <<
"<input type=\"text\" name=\"time\" value=\"100\" />"
82 <<
"</td></tr>" <<
endl;
84 cout <<
"<tr><td class=\"title\">Your thoughts (on anything)</td>"
85 <<
"<td class=\"form\">"
86 <<
"<textarea name=\"thoughts\" rows=\"4\" cols=\"40\">"
87 <<
"I don't have any!</textarea>" <<
"</td></tr>" <<
endl;
89 cout <<
"<tr><td class=\"title\">Are you hungry?</td>"
90 <<
"<td class=\"form\">"
91 <<
"<input type=\"checkbox\" name=\"hungry\" checked=\"checked\" />"
92 <<
"Yes</td></tr>" <<
endl;
94 cout <<
"<tr><td class=\"title\">Your favorite flavors of ice cream</td>"
95 <<
"<td class=\"form\">"
96 <<
"<select name=\"flavors\" multiple=\"multiple\">"
97 <<
"<option value=\"cookie dough\">Cookie Dough</option>"
98 <<
"<option value=\"rocky road\">Rocky Road</option>"
99 <<
"<option value=\"chocolate\">Chocolate</option>"
100 <<
"<option value=\"strawberry\">Strawberry</option>"
101 <<
"<option value=\"vanilla\">Vanilla</option>"
102 <<
"</select>" <<
"</td></tr>" <<
endl;
104 cout <<
"<tr><td class=\"title\">Your hair color</td>"
105 <<
"<td class=\"form\">"
106 <<
"<select name=\"hair\">"
107 <<
"<option value=\"blond\">Blond</option>"
108 <<
"<option value=\"brown\">Brown</option>"
109 <<
"<option value=\"red\">Red</option>"
110 <<
"<option value=\"black\">Black</option>"
111 <<
"<option value=\"white\">White</option>"
112 <<
"<option value=\"green\">Green</option>"
113 <<
"<option value=\"multicolored\">Multicolored</option>"
114 <<
"</select>" <<
"</td></tr>" <<
endl;
116 cout <<
"<tr><td class=\"title\">Your web browser</td>"
117 <<
"<td class=\"form\">"
118 <<
"<input type=\"radio\" name=\"browser\" value=\"Konqueror\""
119 <<
" checked=\"checked\" />Konqeuror"
120 <<
"<input type=\"radio\" name=\"browser\" value=\"Lynx\" />Lynx"
121 <<
"<input type=\"radio\" name=\"browser\" value=\"Mozilla\" />Mozilla"
122 <<
"<input type=\"radio\" name=\"browser\" value=\"IE\" />IE"
123 <<
"<input type=\"radio\" name=\"browser\" value=\"Other\" />Other"
124 <<
"</td></tr>" <<
endl;
126 cout <<
"<tr><td class=\"title\">Your favorite authors</td>"
127 <<
"<td class=\"form\">"
128 <<
"<input type=\"checkbox\" name=\"authors\" value=\"O'Brian\" />"
130 <<
"<input type=\"checkbox\" name=\"authors\" value=\"Feynman\" />"
132 <<
"<input type=\"checkbox\" name=\"authors\" value=\"Camus\" />Camus"
133 <<
"<input type=\"checkbox\" name=\"authors\" value=\"Conrad\" />Conrad"
134 <<
"<input type=\"checkbox\" name=\"authors\" value=\"Vergil\" />Vergil"
135 <<
"<input type=\"checkbox\" name=\"authors\" value=\"Plato\" />Plato"
136 <<
"</td></tr>" <<
endl;
138 cout <<
"<tr><td class=\"title\">In the output, show</td>"
139 <<
"<td class=\"form\">"
140 <<
"<input type=\"checkbox\" name=\"showEnv\" checked=\"checked\" />"
141 <<
"Data from CgiEnvironment<br />"
142 <<
"<input type=\"checkbox\" name=\"showFE\" checked=\"checked\" />"
143 <<
"All FormEntries<br />"
144 <<
"<input type=\"checkbox\" name=\"showForm\" checked=\"checked\" />"
146 <<
"</td></tr>" <<
endl;
148 cout <<
"<tr><td class=\"title\">Exception Handling</td>"
149 <<
"<td class=\"form\">"
150 <<
"<input type=\"checkbox\" name=\"throw\" />"
151 <<
"Throw an exception to test error handling"
152 <<
"</td></tr>" <<
endl;
154 cout <<
"<tr><td class=\"title\">Save and Restore</td>"
155 <<
"<td class=\"form\">"
156 <<
"<input type=\"checkbox\" name=\"save\" />"
157 <<
" Save submission to a file<br />"
158 <<
"<input type=\"checkbox\" name=\"restore\" />"
159 <<
"Restore data from the last saved submission"
160 <<
"</td></tr>" <<
endl;
164 cout <<
"<div class=\"center\"><p>"
165 <<
"<input type=\"submit\" name=\"submit\" value=\"Submit\" />"
166 <<
"<input type=\"reset\" value=\"Nevermind\" />"
167 <<
"</p></div></form>" <<
endl;
185 if(
cgi.queryCheckbox(
"throw") && !
cgi.queryCheckbox(
"restore"))
186 throw std::runtime_error(
"User-requested Exception thrown in main()");
201 cout <<
title() <<
"GNU cgicc v" <<
cgi.getVersion() <<
" Test"
210 <<
" v"<<
cgi.getVersion() <<
" Test" <<
h1() <<
endl;
216 cout <<
comment() <<
"This page generated by cgicc for "
218 cout <<
h4() <<
"Thanks for using cgi" <<
span(
"cc").
set(
"class",
"red")
219 <<
", " <<
env.getRemoteHost()
220 <<
'(' <<
env.getRemoteAddr() <<
")!" <<
h4() <<
endl;
223 if(
cgi.queryCheckbox(
"save")) {
229 cout <<
"Your data has been saved, and may be restored (by anyone) "
234 if(
cgi.queryCheckbox(
"restore")) {
239 cout <<
"The data displayed has been restored from a file on disk."
246 if(
cgi.queryCheckbox(
"showEnv"))
247 dumpEnvironment(
env);
254 if(
cgi.queryCheckbox(
"showFE"))
261 if(
cgi.queryCheckbox(
"showForm"))
271 cout <<
"GNU cgi" <<
span(
"cc").
set(
"class",
"red") <<
" v";
273 cout <<
"Compiled at " <<
cgi.getCompileTime();
276 cout <<
"Configured for " <<
cgi.getHost();
280 cout <<
". Running on " <<
info.sysname;
281 cout <<
' ' <<
info.release <<
" (";
292 long us = ((
end.tv_sec -
start.tv_sec) * 1000000)
295 cout <<
br() <<
"Total time for request = " <<
us <<
" us";
296 cout <<
" (" <<
static_cast<double>(
us/1000000.0) <<
" s)";
308 catch(
const std::exception&
e) {
315 html::reset(); head::reset(); body::reset();
316 title::reset(); h1::reset(); h4::reset();
318 table::reset(); cgicc::div::reset(); p::reset();
319 a::reset(); h2::reset(); colgroup::reset();
331 cout <<
"body { color: black; background-color: white; }" <<
endl;
332 cout <<
"hr.half { width: 60%; align: center; }" <<
endl;
333 cout <<
"span.red, STRONG.red { color: red; }" <<
endl;
334 cout <<
"div.notice { border: solid thin; padding: 1em; margin: 1em 0; "
335 <<
"background: #ddd; }" <<
endl;
345 <<
" caught an exception" <<
h1() <<
endl;
366 cout <<
h2(
"Environment information from CgiEnvironment") <<
endl;
372 cout <<
tr() <<
td(
"Request Method").
set(
"class",
"title")
373 <<
td(
env.getRequestMethod()).
set(
"class",
"data") <<
tr() <<
endl;
374 cout <<
tr() <<
td(
"Path Info").
set(
"class",
"title")
376 cout <<
tr() <<
td(
"Path Translated").
set(
"class",
"title")
377 <<
td(
env.getPathTranslated()).
set(
"class",
"data") <<
tr() <<
endl;
378 cout <<
tr() <<
td(
"Script Name").
set(
"class",
"title")
380 cout <<
tr() <<
td(
"HTTP Referrer").
set(
"class",
"title")
382 cout <<
tr() <<
td(
"HTTP Cookie").
set(
"class",
"title")
384 cout <<
tr() <<
td(
"Query String").
set(
"class",
"title")
386 cout <<
tr() <<
td(
"Content Length").
set(
"class",
"title")
387 <<
td().
set(
"class",
"data") <<
env.getContentLength()
389 cout <<
tr() <<
td(
"Post Data").
set(
"class",
"title")
390 <<
td().
set(
"class",
"data")
391 <<
pre(
env.getPostData()).
set(
"class",
"data") <<
td()
393 cout <<
tr() <<
td(
"Remote Host").
set(
"class",
"title")
395 cout <<
tr() <<
td(
"Remote Address").
set(
"class",
"title")
397 cout <<
tr() <<
td(
"Authorization Type").
set(
"class",
"title")
399 cout <<
tr() <<
td(
"Remote User").
set(
"class",
"title")
401 cout <<
tr() <<
td(
"Remote Identification").
set(
"class",
"title")
403 cout <<
tr() <<
td(
"Content Type").
set(
"class",
"title")
405 cout <<
tr() <<
td(
"HTTP Accept").
set(
"class",
"title")
407 cout <<
tr() <<
td(
"User Agent").
set(
"class",
"title")
409 cout <<
tr() <<
td(
"Server Software").
set(
"class",
"title")
410 <<
td(
env.getServerSoftware()).
set(
"class",
"data") <<
tr() <<
endl;
411 cout <<
tr() <<
td(
"Server Name").
set(
"class",
"title")
413 cout <<
tr() <<
td(
"Gateway Interface").
set(
"class",
"title")
414 <<
td(
env.getGatewayInterface()).
set(
"class",
"data") <<
tr() <<
endl;
415 cout <<
tr() <<
td(
"Server Protocol").
set(
"class",
"title")
416 <<
td(
env.getServerProtocol()).
set(
"class",
"data") <<
tr() <<
endl;
417 cout <<
tr() <<
td(
"Server Port").
set(
"class",
"title")
418 <<
td().
set(
"class",
"data") <<
env.getServerPort()
421 <<
td().
set(
"class",
"data") << (
env.usingHTTPS() ?
"true" :
"false")
423 cout <<
tr() <<
td(
"Redirect Request").
set(
"class",
"title")
424 <<
td(
env.getRedirectRequest()).
set(
"class",
"data") <<
tr() <<
endl;
425 cout <<
tr() <<
td(
"Redirect URL").
set(
"class",
"title")
427 cout <<
tr() <<
td(
"Redirect Status").
set(
"class",
"title")
428 <<
td(
env.getRedirectStatus()).
set(
"class",
"data") <<
tr() <<
endl;
443 cout <<
tr().
set(
"class",
"title") <<
td(
"Element Name")
444 <<
td(
"Element Value") <<
tr() <<
endl;
469 if(
name != (*formData).end() && !
name->isEmpty())
472 cout <<
"You don't have a name." <<
br() <<
endl;
477 cout <<
"You make " << (*salary).getDoubleValue(80, 120)
478 <<
" million dollars." <<
br() <<
endl;
480 cout <<
"You don't have a salary." <<
br() <<
endl;
484 if(
hours != (*formData).end() && ! (*hours).isEmpty())
485 cout <<
"You've wasted " << (*hours).getIntegerValue()
486 <<
" hours on the web." <<
br() <<
endl;
488 cout <<
"You haven't wasted any time on the web." <<
br() <<
endl;
492 if(
thoughts != (*formData).end() && ! (*thoughts).isEmpty()) {
493 std::string
temp = (*thoughts).getStrippedValue();
497 cout <<
"You don't have any thoughts!?" <<
br() <<
endl;
500 if(
formData.queryCheckbox(
"hungry"))
503 cout <<
"You are not hungry." <<
br() <<
endl;
506 std::vector<FormEntry>
flavors;
510 for(std::string::size_type
i = 0;
i <
flavors.size();
i++) {
520 cout <<
"You don't like ice cream!?" <<
br() <<
endl;
524 if(
hair != (*formData).end())
527 cout <<
"You don't have any hair." <<
br() <<
endl;
529 cout <<
"You surf the web with " <<
formData(
"browser") <<
'.'
533 std::vector<FormEntry>
authors;
536 cout <<
"You like to read books by ";
537 for(std::string::size_type
i = 0;
i <
authors.size(); ++
i) {
547 cout <<
"You don't like to read!?" <<
br() <<
endl;
Platform and operating system specific macro definitions.
The main header file for the GNU cgicc library.
The header file containing HTML output classes.
Class encapsulating the CGI runtime environment.
The main class of the GNU cgicc library.
Template for concrete atomic HTMLElement subclasses.
HTMLAtomicElement()
Create a new empty atomic element.
virtual const char * getName() const
Get the name of this element.
static void reset()
Reset the state of this boolean element to closed.
Specifies the DTD of the HTML 4 document.
HTMLElement & set(const std::string &name)
Set an HTMLAttribute on this HTMLElement.
The namespace containing the cgicc library.
std::vector< FormEntry >::const_iterator const_form_iterator
A vector of const FormEntry objects.
HTMLAttributeList set(const std::string &name)
Create a new HTMLAttributeList, and set an HTMLAttribute.