44# include <sys/utsname.h>
58printForm(
const Cgicc& cgi)
60 cout <<
"<form method=\"post\" action=\""
62 <<
"\" enctype=\"multipart/form-data\">" << endl;
64 cout <<
"<table>" << endl;
66 cout <<
"<tr><td class=\"title\">Send a file</td>"
67 <<
"<td class=\"form\">"
68 <<
"<input type=\"file\" name=\"userfile\" accept=\"text/plain\" />"
69 <<
"</td></tr>" << endl;
71 cout <<
"<tr><td class=\"title\">Upload Redirection</td>"
72 <<
"<td class=\"form\">"
73 <<
"<input type=\"checkbox\" name=\"redirect\" />"
74 <<
"Bounce uploaded file back to browser"
75 <<
"</td></tr>" << endl;
77 cout <<
"</table>" << endl;
79 cout <<
"<div class=\"center\"><p>"
80 <<
"<input type=\"submit\" name=\"submit\" value=\"Send the file\" />"
81 <<
"<input type=\"reset\" value=\"Nevermind\" />"
82 <<
"</p></div></form>" << endl;
93 gettimeofday(&start, NULL);
106 file->writeToStream(cout);
114 cout << html().set(
"lang",
"en").set(
"dir",
"ltr") << endl;
118 cout << head() << endl;
121 cout << style() <<
comment() << endl;
123 cout <<
comment() << style() << endl;
125 cout << title() <<
"GNU cgicc v" << cgi.
getVersion()
126 <<
" File Upload Test" << title() << endl;
128 cout << head() << endl;
131 cout << body() << endl;
133 cout << h1() <<
"GNU cgi" << span(
"cc").set(
"class",
"red")
134 <<
" v"<< cgi.
getVersion() <<
" File Upload Test"
141 cout <<
comment() <<
"This page generated by cgicc for "
143 cout << h4() <<
"Thanks for using cgi" << span(
"cc").
set(
"class",
"red")
149 file = cgi.
getFile(
"userfile");
153 cout << table() << endl;
155 cout << tr() << td(
"Name").set(
"class",
"title")
156 << td(file->getName()).set(
"class",
"data") << tr() << endl;
158 cout << tr() << td(
"Data Type").set(
"class",
"title")
159 << td(file->getDataType()).set(
"class",
"data") << tr() << endl;
161 cout << tr() << td(
"Filename").set(
"class",
"title")
162 << td(file->getFilename()).set(
"class",
"data") << tr() << endl;
164 cout << tr() << td(
"Data Length").set(
"class",
"title")
165 << td().set(
"class",
"data") << file->getDataLength()
166 << td() << tr() << endl;
168 cout << tr() << td(
"File Data").set(
"class",
"title")
169 << td().set(
"class",
"data") << pre();
170 file->writeToStream(cout);
171 cout << pre() << td() << tr() << endl;
173 cout << table() << endl;
177 cout << br() << endl;
179 cout << hr().set(
"class",
"half") << endl;
182 cout << cgicc::div().set(
"align",
"center").set(
"class",
"smaller") << endl;
183 cout <<
"GNU cgi" << span(
"cc").set(
"class",
"red") <<
" v";
188 cout <<
"Configured for " << cgi.
getHost();
191 if(uname(&info) != -1) {
192 cout <<
". Running on " << info.sysname;
193 cout <<
' ' << info.release <<
" (";
194 cout << info.nodename <<
")." << endl;
203 gettimeofday(&end, NULL);
204 long us = ((end.tv_sec - start.tv_sec) * 1000000)
205 + (end.tv_usec - start.tv_usec);
207 cout << br() <<
"Total time for request = " << us <<
" us";
208 cout <<
" (" <<
static_cast<double>(us/1000000.0) <<
" s)";
212 cout << cgicc::div() << endl;
213 cout << body() << html() << endl;
220 catch(
const std::exception& e) {
227 html::reset(); head::reset(); body::reset();
228 title::reset(); h1::reset(); h4::reset();
229 comment::reset(); td::reset(); tr::reset();
230 table::reset(); cgicc::div::reset(); p::reset();
231 a::reset(); h2::reset(); colgroup::reset();
235 cout << html().set(
"lang",
"en").set(
"dir",
"ltr") << endl;
239 cout << head() << endl;
242 cout << style() <<
comment() << endl;
243 cout <<
"body { color: black; background-color: white; }" << endl;
244 cout <<
"hr.half { width: 60%; align: center; }" << endl;
245 cout <<
"span.red, strong.red { color: red; }" << endl;
246 cout <<
"div.notice { border: solid thin; padding: 1em; margin: 1em 0; "
247 <<
"background: #ddd; }" << endl;
249 cout <<
comment() << style() << endl;
251 cout << title(
"GNU cgicc exception") << endl;
252 cout << head() << endl;
254 cout << body() << endl;
256 cout << h1() <<
"GNU cgi" << span(
"cc",
set(
"class",
"red"))
257 <<
" caught an exception" << h1() << endl;
259 cout << cgicc::div().
set(
"align",
"center").
set(
"class",
"notice") << endl;
261 cout << h2(e.what()) << endl;
264 cout << cgicc::div() << endl;
265 cout << hr().
set(
"class",
"half") << endl;
266 cout << body() << html() << 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.
std::string getScriptName() const
Get the full path to this CGI application.
std::string getRemoteAddr() const
Get the IP address of the remote machine making this request.
std::string getRemoteHost() const
Get the hostname of the remote machine making this request.
The main class of the GNU cgicc library.
const char * getCompileDate() const
Get the date on which this library was compiled.
const CgiEnvironment & getEnvironment() const
bool queryCheckbox(const std::string &elementName) const
Query whether a checkbox is checked.
const char * getVersion() const
Get the version number of cgicc.
file_iterator getFile(const std::string &name)
Find an uploaded file.
const char * getCompileTime() const
Get the time at which this library was compiled.
const char * getHost() const
Get the platform for which Cgicc was configured.
const std::vector< FormFile > & getFiles() const
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< FormFile >::const_iterator const_file_iterator
A vector of const FormFile objects.
HTMLAttributeList set(const std::string &name)
Create a new HTMLAttributeList, and set an HTMLAttribute.