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