00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00028 #include <new>
00029 #include <string>
00030 #include <vector>
00031 #include <stdexcept>
00032 #include <iostream>
00033 #include <cstdlib>
00034
00035 #include "cgicc/CgiDefs.h"
00036 #include "cgicc/Cgicc.h"
00037 #include "cgicc/HTTPHeaders.h"
00038 #include "cgicc/HTMLClasses.h"
00039
00040 #if HAVE_UNAME
00041 # include <sys/utsname.h>
00042 #endif
00043
00044 #if HAVE_SYS_TIME_H
00045 # include <sys/time.h>
00046 #endif
00047
00048
00049
00050 #if DEBUG
00051 STDNS ofstream gLogFile( "/change_this_path/cgicc.log", STDNS ios::app );
00052 #endif
00053
00054 #if CGICC_USE_NAMESPACES
00055 using namespace std;
00056 using namespace cgicc;
00057 #else
00058 # define div div_
00059 # define link link_
00060 # define select select_
00061 #endif
00062
00063
00064 int
00065 main(int ,
00066 char ** )
00067 {
00068 try {
00069 #if HAVE_GETTIMEOFDAY
00070 timeval start;
00071 gettimeofday(&start, NULL);
00072 #endif
00073
00074
00075 Cgicc cgi;
00076
00077
00078 cout << HTTPHTMLHeader() << HTMLDoctype(HTMLDoctype::eStrict) << endl;
00079 cout << html().set("lang", "en").set("dir", "ltr") << endl;
00080
00081
00082
00083 cout << head() << endl;
00084
00085
00086 cout << style() << comment() << endl;
00087 cout << "body { color: black; background-color: white; }" << endl;
00088 cout << "hr.half { width: 60%; align: center; }" << endl;
00089 cout << "span.red, strong.red { color: red; }" << endl;
00090 cout << "div.smaller { font-size: small; }" << endl;
00091 cout << "div.notice { border: solid thin; padding: 1em; margin: 1em 0; "
00092 << "background: #ddd; }" << endl;
00093 cout << "span.blue { color: blue; }" << endl;
00094 cout << "col.title { color: white; background-color: black; ";
00095 cout << "font-weight: bold; text-align: center; }" << endl;
00096 cout << "col.data { background-color: #ddd; text-align: left; }" << endl;
00097 cout << "td.data, TR.data { background-color: #ddd; text-align: left; }"
00098 << endl;
00099 cout << "td.grayspecial { background-color: #ddd; text-align: left; }"
00100 << endl;
00101 cout << "td.ltgray, tr.ltgray { background-color: #ddd; }" << endl;
00102 cout << "td.dkgray, tr.dkgray { background-color: #bbb; }" << endl;
00103 cout << "col.black, td.black, td.title, tr.title { color: white; "
00104 << "background-color: black; font-weight: bold; text-align: center; }"
00105 << endl;
00106 cout << "col.gray, td.gray { background-color: #ddd; text-align: center; }"
00107 << endl;
00108 cout << "table.cgi { left-margin: auto; right-margin: auto; width: 90%; }"
00109 << endl;
00110
00111 cout << comment() << style() << endl;
00112
00113 cout << title() << "GNU cgicc v" << cgi.getVersion()
00114 << " File Upload Test Results" << title() << endl;
00115 cout << meta().set("name", "author").set("content", "Stephen F. Booth")
00116 << endl;
00117
00118 cout << head() << endl;
00119
00120
00121 cout << body() << endl;
00122
00123 cout << h1() << "GNU cgi" << span("cc").set("class","red")
00124 << " v"<< cgi.getVersion() << " File Upload Test Results"
00125 << h1() << endl;
00126
00127
00128 const CgiEnvironment& env = cgi.getEnvironment();
00129
00130
00131 cout << comment() << "This page generated by cgicc for "
00132 << env.getRemoteHost() << comment() << endl;
00133 cout << h4() << "Thanks for using cgi" << span("cc").set("class", "red")
00134 << ", " << env.getRemoteHost()
00135 << '(' << env.getRemoteAddr() << ")!" << h4() << endl;
00136
00137
00138
00139 cout << h2("File Uploaded via FormFile") << endl;
00140
00141 const_file_iterator file;
00142 file = cgi.getFile("userfile");
00143
00144 if(file != cgi.getFiles().end()) {
00145 cout << CGICCNS div().set("align","center") << endl;
00146
00147 cout << table().set("border","0").set("rules","none").set("frame","void")
00148 .set("cellspacing","2").set("cellpadding","2")
00149 .set("class","cgi") << endl;
00150 cout << colgroup().set("span","2") << endl;
00151 cout << col().set("align","center").set("class","title").set("span","1")
00152 << endl;
00153 cout << col().set("align","left").set("class","data").set("span","1")
00154 << endl;
00155 cout << colgroup() << endl;
00156
00157 cout << tr() << td("Name").set("class","title")
00158 << td((*file).getName()).set("class","data") << tr() << endl;
00159
00160 cout << tr() << td("Data Type").set("class","title")
00161 << td((*file).getDataType()).set("class","data") << tr() << endl;
00162
00163 cout << tr() << td("Filename").set("class","title")
00164 << td((*file).getFilename()).set("class","data") << tr() << endl;
00165 cout << tr() << td("Data Length").set("class","title")
00166 << td().set("class","data") << (*file).getDataLength()
00167 << td() << tr() << endl;
00168
00169 cout << tr() << td("File Data").set("class","title")
00170 << td().set("class","data") << pre();
00171 (*file).writeToStream(cout);
00172
00173
00174
00175
00176
00177
00178
00179
00180 cout << pre() << td() << tr() << endl;
00181
00182 cout << table() << CGICCNS div() << endl;
00183 }
00184 else {
00185 cout << p() << CGICCNS div().set("class", "notice") << endl;
00186 cout << "No file was uploaded." << endl << CGICCNS div() << p() << endl;
00187 }
00188
00189
00190 cout << p() << CGICCNS div().set("align","center");
00191 cout << a("Back to form").set("href", cgi.getEnvironment().getReferrer())
00192 << endl;
00193 cout << CGICCNS div() << br() << hr(set("class","half")) << endl;
00194
00195
00196 cout << CGICCNS div().set("align","center").set("class","smaller") << endl;
00197 cout << "GNU cgi" << span("cc").set("class","red") << " v";
00198 cout << cgi.getVersion();
00199 cout << " by " << a("Stephen F. Booth")
00200 .set("href", "mailto:sbooth@gnu.org")
00201 << br() << endl;
00202 cout << "Compiled at " << cgi.getCompileTime();
00203 cout << " on " << cgi.getCompileDate() << br() << endl;
00204
00205 cout << "Configured for " << cgi.getHost();
00206 #if HAVE_UNAME
00207 struct utsname info;
00208 if(uname(&info) != -1) {
00209 cout << ". Running on " << info.sysname;
00210 cout << ' ' << info.release << " (";
00211 cout << info.nodename << ")." << endl;
00212 }
00213 #else
00214 cout << "." << endl;
00215 #endif
00216
00217 #if HAVE_GETTIMEOFDAY
00218
00219 timeval end;
00220 gettimeofday(&end, NULL);
00221 long us = ((end.tv_sec - start.tv_sec) * 1000000)
00222 + (end.tv_usec - start.tv_usec);
00223
00224 cout << br() << "Total time for request = " << us << " us";
00225 cout << " (" << (double) (us/1000000.0) << " s)";
00226 #endif
00227
00228
00229 cout << CGICCNS div() << endl;
00230 cout << body() << html() << endl;
00231
00232
00233 return EXIT_SUCCESS;
00234 }
00235
00236
00237 catch(const STDNS exception& e) {
00238
00239
00240
00241
00242
00243
00244 html::reset(); head::reset(); body::reset();
00245 title::reset(); h1::reset(); h4::reset();
00246 comment::reset(); td::reset(); tr::reset();
00247 table::reset(); CGICCNS div::reset(); p::reset();
00248 a::reset(); h2::reset(); colgroup::reset();
00249
00250
00251 cout << HTTPHTMLHeader() << HTMLDoctype(HTMLDoctype::eStrict) << endl;
00252 cout << html().set("lang","en").set("dir","ltr") << endl;
00253
00254
00255
00256 cout << head() << endl;
00257
00258
00259 cout << style() << comment() << endl;
00260 cout << "body { color: black; background-color: white; }" << endl;
00261 cout << "hr.half { width: 60%; align: center; }" << endl;
00262 cout << "span.red, strong.red { color: red; }" << endl;
00263 cout << "div.notice { border: solid thin; padding: 1em; margin: 1em 0; "
00264 << "background: #ddd; }" << endl;
00265
00266 cout << comment() << style() << endl;
00267
00268 cout << title("GNU cgicc exception") << endl;
00269 cout << meta().set("name", "author")
00270 .set("content", "Stephen F. Booth") << endl;
00271 cout << head() << endl;
00272
00273 cout << body() << endl;
00274
00275 cout << h1() << "GNU cgi" << span("cc", set("class","red"))
00276 << " caught an exception" << h1() << endl;
00277
00278 cout << CGICCNS div().set("align","center").set("class","notice") << endl;
00279
00280 cout << h2(e.what()) << endl;
00281
00282
00283 cout << CGICCNS div() << endl;
00284 cout << hr().set("class","half") << endl;
00285 cout << body() << html() << endl;
00286
00287 return EXIT_SUCCESS;
00288 }
00289 }