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