cgi.h   cgi.h 
// Copyright 2003 John Wiggins (http://johnwiggins.net) // Note that the only valid version of the GPL as far as ceegeye
// is concerned is v2 of the license (ie v2, not v2.2 or v3.x or whatever),
// unless explicitly otherwise stated.
// //
// This file is part of the jwCGI library. // This file is part of the ceegeye library.
// //
// jwCGI library is free software; you can redistribute it and/or modify // ceegeye library is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or // the Free Software Foundation; version 2 of the License.
// (at your option) any later version.
// //
// jwCGI library is distributed in the hope that it will be useful, // ceegeye library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details. // GNU General Public License for more details.
// //
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with jwCGI library; if not, write to the Free Software // along with ceegeye library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 U SA // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 U SA
// //
// http://johnwiggins.net // http://johnwiggins.net
// cgilib@johnwiggins.net // cgilib@johnwiggins.net
// //
// cgi.h: interface for the CGI class. // cgi.h: interface for the CGI class.
// //
#ifndef __CGI_H__ #ifndef __CGI_H__
#define __CGI_H__ #define __CGI_H__
#include <iostream> #include <iostream>
#include <string> #include <string>
#include <vector> #include <vector>
#include <utility> // for std::pair #include <utility> // for std::pair
#include <algorithm> #include <algorithm>
namespace ceegeye {
using std::vector; using std::vector;
using std::string; using std::string;
namespace jwcgi {
// less typing // less typing
typedef std::vector<string::value_type>::size_type V_S_sizeT; // vector str ing size type typedef std::vector<string::value_type>::size_type V_S_sizeT; // vector str ing size type
typedef std::vector<string::value_type>::const_iterator V_S_iter; // vector string iterator typedef std::vector<string::value_type>::const_iterator V_S_iter; // vector string iterator
// Handle DLL specific issues for the windows platform // Handle DLL specific issues for the windows platform
// //
// disable this warning (C4231) re: msdn knowledge base article: (Q168958) // disable this warning (C4231) re: msdn knowledge base article: (Q168958)
// HOWTO: Exporting STL Components Inside & Outside of a Class (Q168958) // HOWTO: Exporting STL Components Inside & Outside of a Class (Q168958)
// actually cannot see the difference if I exclude the declaration of the v ector class!! // actually cannot see the difference if I exclude the declaration of the v ector class!!
// but will leave the code as they say to. // but will leave the code as they say to.
#ifdef CGI_DLL #ifdef CGI_DLL
#pragma warning (disable: 4231) #pragma warning (disable: 4231)
#ifdef JWCGIDLL_EXPORTS #ifdef CEEGEYEDLL_EXPORTS
#define CGI_API __declspec(dllexport) #define CGI_API __declspec(dllexport)
template class CGI_API std::vector<char>; template class CGI_API std::vector<char>;
#else #else
#define CGI_API __declspec(dllimport) #define CGI_API __declspec(dllimport)
extern template class CGI_API std::vector<char>; extern template class CGI_API std::vector<char>;
#endif #endif
#pragma warning (default: 4231) #pragma warning (default: 4231)
#else #else
#define CGI_API #define CGI_API
#endif #endif
class CGI_API CGI class CGI_API CGI {
{
public: public:
// wincgi variable is used on the windows platform only. // wincgi variable is used on the windows platform only.
// i.e. if your on windows and the web server you use // i.e. if your on windows and the web server you use
// implements CGI using the wincgi interface instantiate CGI // implements CGI using the wincgi interface instantiate CGI
// like this: // like this:
// CGI cgi(true); // CGI cgi(true);
// otherwise: // otherwise:
// CGI cgi; // no wincgi. // CGI cgi; // no wincgi.
// Apache on windows + IIS is okay to do the second instance here. // Apache on windows + IIS is okay to do the second instance here.
CGI(bool wincgi = false); CGI();
~CGI(); ~CGI();
// return the data in a POST query represented by "valuename" // return the data in a POST query represented by "valuename"
// returns true on success. // returns true on success.
// if the POST query has encoding "multipart/form-data" // if the POST query has encoding "multipart/form-data"
// "filedata" will hold the data represented by "valuename" and "data" w ill be the name // "filedata" will hold the data represented by "valuename" and "data" w ill be the name
// sent to the web server of that file without path information. // sent to the web server of that file without path information.
// if this is not a "multipart/form-data" encoding data will hold the // if this is not a "multipart/form-data" encoding data will hold the
// data represented by "valuename". // data represented by "valuename".
skipping to change at line 109 skipping to change at line 110
// // now save the data to a file // // now save the data to a file
// } // }
bool GetValue(const string& valuename, vector<char>& filedata, string& d ata) const; bool GetValue(const string& valuename, vector<char>& filedata, string& d ata) const;
// return the data in a POST query (application/x-www-form-urlencoded da ta) // return the data in a POST query (application/x-www-form-urlencoded da ta)
// represented by "valuename". NOT file uploading. // represented by "valuename". NOT file uploading.
// returns true on success. // returns true on success.
// To use: // To use:
// //
// on html page: // on html page:
// <FORM METHOD="POST" ACTION="cgi program e.g:upload.cgi" ENCTYPE="appl ication/x-www-form-urlencoded"> // <FORM METHOD="POST" ACTION="my.cgi" ENCTYPE="application/x-www-form-u rlencoded">
// <INPUT TYPE="submit" NAME="submit" VALUE="Submit"></TD> // <INPUT TYPE="submit" NAME="submit" VALUE="Submit"></TD>
// <INPUT TYPE="text" NAME="Text1"> // <INPUT TYPE="text" NAME="Text1">
// </FORM> // </FORM>
// //
// now to get this data from the program // now to get this data from the program
// //
// CGI cgi // CGI cgi
// std::string value; // std::string value;
// if(cgi.GetValue("Text1", value) { // if(cgi.GetValue("Text1", value) {
// // now use the data returned in value // // now use the data returned in value
skipping to change at line 258 skipping to change at line 259
private: private:
// disallow copying // disallow copying
CGI(const CGI&); CGI(const CGI&);
CGI& operator= (const CGI& cgi); CGI& operator= (const CGI& cgi);
// return the next boundary in STDIN if multipart encoded data // return the next boundary in STDIN if multipart encoded data
std::vector <char>::size_type nextboundary(const string& boundary, strin g::size_type pos) const; std::vector <char>::size_type nextboundary(const string& boundary, strin g::size_type pos) const;
// get a character from its "POST" format // get a character from its "POST" format
char getcharacter(short c) const; char getcharacter(short c) const;
vector <char> STDIN; vector<char> STDIN;
}; };
} // end namespace jwcgi } // end namespace ceegeye
#endif // !#ifndef __CGI_H__ #endif // !#ifndef __CGI_H__
 End of changes. 14 change blocks. 
16 lines changed or deleted 17 lines changed or added


 cgi_session.h   cgi_session.h 
// Copyright 2003 John Wiggins (http://johnwiggins.net) // Note that the only valid version of the GPL as far as ceegeye
// is concerned is v2 of the license (ie v2, not v2.2 or v3.x or whatever),
// unless explicitly otherwise stated.
// //
// This file is part of the jwCGI library. // This file is part of the ceegeye library.
// //
// jwCGI library is free software; you can redistribute it and/or modify // ceegeye library is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or // the Free Software Foundation; version 2 of the License.
// (at your option) any later version.
// //
// jwCGI library is distributed in the hope that it will be useful, // ceegeye library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details. // GNU General Public License for more details.
// //
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with jwCGI library; if not, write to the Free Software // along with ceegeye library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 U SA // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 U SA
// //
// http://johnwiggins.net // http://johnwiggins.net
// cgilib@johnwiggins.net // cgilib@johnwiggins.net
// //
// cgi_session.h: interface for the session class // cgi_session.h: interface for the session class
// //
#ifdef WIN32 #ifdef WIN32
// stop VC++ from complaining about the length of a symbol name greater tha n 256 characters // stop VC++ from complaining about the length of a symbol name greater tha n 256 characters
#pragma warning (disable: 4786) #pragma warning (disable: 4786)
#else #else
#include <unistd.h> #include <unistd.h>
#endif #endif
#ifndef __CGI_SESSION_H__ #ifndef __CGI_SESSION_H__
#define __CGI_SESSION_H__ #define __CGI_SESSION_H__
#include <iostream>
#include <fstream> #include <fstream>
#include <sstream> #include <sstream>
#include <string> #include <string>
#include <vector> #include <vector>
#include <list> #include <list>
#include <utility> #include <utility>
#include <ctime> #include <ctime>
#include <cstring> // for std::memcpy
#include <iterator> #include <iterator>
#include <algorithm> #include <algorithm>
#include <fcntl.h> #include <fcntl.h>
#include "jwcgi.h" #include "cgi.h"
namespace jwcgi { namespace ceegeye {
using std::vector; using std::vector;
using std::list; using std::list;
using std::string; using std::string;
using std::ifstream; using std::ifstream;
using std::ofstream; using std::ofstream;
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
// Session Object class. // Session Object class.
// //
class session { class cgisession {
// helpful definitions, less typing later // helpful definitions, less typing later
typedef vector<std::pair<string, string> > vec_pair_str; typedef vector<std::pair<string, string> > vec_pair_str;
typedef vector<std::pair<string, string> >::iterator vec_pair_str_iter; typedef vector<std::pair<string, string> >::iterator vec_pair_str_iter;
typedef vector<std::pair<string, string> >::const_iterator const_vec_pai r_str_iter; typedef vector<std::pair<string, string> >::const_iterator const_vec_pai r_str_iter;
typedef list<string>::iterator list_str_it; typedef list<string>::iterator list_str_it;
typedef list<string>::const_iterator const_list_str_it; typedef list<string>::const_iterator const_list_str_it;
typedef std::istreambuf_iterator<string> istr_str_it; typedef std::istreambuf_iterator<string> istr_str_it;
public: public:
// per program sessions can be created in seperate files/folders by givi ng // per program sessions can be created in seperate files/folders by givi ng
// separate paths/filenames in this constructor. // separate paths/filenames in this constructor.
// ## the cgi program must have create/write writes to the folder hol ding ## // ## the cgi program must have create/write writes to the folder hol ding ##
// ## the file or explicit writes to an already created file of this name ## // ## the file or explicit writes to an already created file of this name ##
session(const CGI& cgi, long Expires, const string& Sessionfile = ".htce egisession"); cgisession(const CGI& cgi, long Expires = 3600 /* 1 hour default */, con st string& Sessionfile = ".htceegisession");
~session() { ~cgisession();
if(lockfileFD > 0) {
close(lockfileFD);
}
}
// set the amount of time before the session expires. // set the amount of time before the session expires.
// e.g. to have the session expire in 1 day: // e.g. to have the session expire in 1 day:
// settimeout(60 * 60 * 24); // settimeout(60 * 60 * 24);
void settimeout(long Expires); void settimeout(long Expires);
// add/change a session variable. // add/change a session variable.
void set(const string& name, const string& value); void set(const string& name, const string& value);
// return the contents of a session variable. // return the contents of a session variable.
// returns the empty string if the variable does not exist. // returns the empty string if the variable does not exist.
string get(const string& name); string get(const string& name);
// remove a session variable. // remove a session variable.
void remove(const string& name); void remove(const string& name);
private: private:
struct Client { struct Client {
const string ipaddress; const string ipaddress;
time_t last_access; time_t last_access;
string agent_id; // are we on the sme machine different user.
// vector of name/value pairs // vector of name/value pairs
vector<std::pair<string, string> >values; vector<std::pair<string, string> >values;
Client(const string& IP, time_t LA):ipaddress(IP), last_access(LA) {} Client(const string& IP, time_t LA):ipaddress(IP), last_access(LA) {}
}; };
// populate the session. // populate the session.
// This is the call does timeout checking // This is the call does timeout checking
bool getsession(); bool getsession();
// commit the sessions contents // commit the sessions contents
// no timeout check done, so we must call // no timeout check done, so we must call
skipping to change at line 134 skipping to change at line 134
bool writesessionfile(const list<string>& data) const; bool writesessionfile(const list<string>& data) const;
const string sessionfile; const string sessionfile;
Client client; Client client;
long timeout; long timeout;
const int lockfileFD; const int lockfileFD;
static const string ip; static const string ip;
static const string la; static const string la;
static const string id; static const string id;
static const string cookiename;
// remove old session data
void compact();
// use a cookie to signify a unique user agent. This allows us to use se
perate browsers on
// a machine or when NAT is involved uniquely identify a user.
string uniqueuser();
string usernumber;
void offsets();
int mins, hours, days, years;
}; };
} // end namespace jwcgi } // end namespace ceegeye
#endif // !ifndef __CGI_SESSION_H__ #endif // !ifndef __CGI_SESSION_H__
 End of changes. 16 change blocks. 
17 lines changed or deleted 30 lines changed or added


 javascripts.h   javascripts.h 
// Copyright 2003 John Wiggins (http://johnwiggins.net) // Note that the only valid version of the GPL as far as ceegeye
// is concerned is v2 of the license (ie v2, not v2.2 or v3.x or whatever),
// unless explicitly otherwise stated.
// //
// This file is part of the jwCGI library. // This file is part of the ceegeye library.
// //
// jwCGI library is free software; you can redistribute it and/or modify // ceegeye library is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or // the Free Software Foundation; version 2 of the License.
// (at your option) any later version.
// //
// jwCGI library is distributed in the hope that it will be useful, // ceegeye library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details. // GNU General Public License for more details.
// //
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with jwCGI library; if not, write to the Free Software // along with ceegeye library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 U SA // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 U SA
// //
// http://johnwiggins.net // http://johnwiggins.net
// cgilib@johnwiggins.net // cgilib@johnwiggins.net
// //
// javascripts.h: interface for the javascript function/s // javascripts.h: interface for the javascript function/s
// //
#ifndef __JAVASCRIPTS_H__ #ifndef __JAVASCRIPTS_H__
#define __JAVASCRIPTS_H__ #define __JAVASCRIPTS_H__
namespace jwcgi { namespace ceegeye {
// This function places a submit button on the page that you can check
// against its name to see if it was clicked.
// You can check whether the submit button is clicked by retrieving the val
ue
// of the hidden element and testing equality against the string value.
// e.g. Add a hidden element to the form (page)
// If the hidden value is named 'button1' and the button name is 'butt
on1'
// string thebutton;
// if(cgi.GetValue("button1", thebutton) && (thebutton == "button1"))
{
// // okay the button was clicked
// }
//
void submitbuttoncheck(wp<std::ostream>& p,
const std::string& SubmitName,
const std::string& SubmitText,
const std::string& HiddenName);
void submitbuttoncheck(xhtml<std::ostream>& p,
const std::string& SubmitName,
const std::string& SubmitText,
const std::string& HiddenName,
const std::string& FormID,
const std::string& Class = "");
} // namespace jwcgi } // namespace ceegeye
#endif // #ifndef __JAVASCRIPTS_H__ #endif // #ifndef __JAVASCRIPTS_H__
 End of changes. 8 change blocks. 
35 lines changed or deleted 10 lines changed or added


 log.h   log.h 
// Copyright 2003 John Wiggins (http://johnwiggins.net) // Note that the only valid version of the GPL as far as ceegeye
// is concerned is v2 of the license (ie v2, not v2.2 or v3.x or whatever),
// unless explicitly otherwise stated.
// //
// This file is part of the jwCGI library. // This file is part of the ceegeye library.
// //
// jwCGI library is free software; you can redistribute it and/or modify // ceegeye library is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or // the Free Software Foundation; version 2 of the License.
// (at your option) any later version.
// //
// jwCGI library is distributed in the hope that it will be useful, // ceegeye library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details. // GNU General Public License for more details.
// //
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with jwCGI library; if not, write to the Free Software // along with ceegeye library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 U SA // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 U SA
// //
// http://johnwiggins.net // http://johnwiggins.net
// cgilib@johnwiggins.net // cgilib@johnwiggins.net
// //
// log.h: interface for the Log class // log.h: interface for the Log class
// //
#ifndef __LOG_H__ #ifndef __LOG_H__
#define __LOG_H__ #define __LOG_H__
 End of changes. 6 change blocks. 
7 lines changed or deleted 8 lines changed or added


 statics.h   statics.h 
// Copyright 2003 John Wiggins (http://johnwiggins.net) // Note that the only valid version of the GPL as far as ceegeye
// is concerned is v2 of the license (ie v2, not v2.2 or v3.x or whatever),
// unless explicitly otherwise stated.
// //
// This file is part of the jwCGI library. // This file is part of the ceegeye library.
// //
// jwCGI library is free software; you can redistribute it and/or modify // ceegeye library is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or // the Free Software Foundation; version 2 of the License.
// (at your option) any later version.
// //
// jwCGI library is distributed in the hope that it will be useful, // ceegeye library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details. // GNU General Public License for more details.
// //
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with jwCGI library; if not, write to the Free Software // along with ceegeye library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 U SA // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 U SA
// //
// http://johnwiggins.net // http://johnwiggins.net
// cgilib@johnwiggins.net // cgilib@johnwiggins.net
// //
// statics.h: interface of the static functions // statics.h: interface of the static functions
// //
#ifndef __STATICS_H__ #ifndef __STATICS_H__
#define __STATICS_H__ #define __STATICS_H__
#include <string> #include <string>
#include <sstream> #include <sstream>
namespace jwcgi { namespace ceegeye {
using std::string;
// Helper function, used in the header part of the wp::pagebegin() function . // Helper function, used in the header part of the wp::pagebegin() function .
// if(url.length() == 0) refreshes the current page, otherwise a redirect. // if(url.length() == 0) refreshes the current page, otherwise a redirect.
// 'seconds' is the amount of time to wait before the refresh. // 'seconds' is the amount of time to wait before the refresh.
// 'url' to redirect to, if blank refresh current page // 'url' to redirect to, if blank refresh current page
// //
// e.g. // e.g.
// page.beginpage("page title", MetaRefresh(20), "head tag info"); // page.beginpage("page title", MetaRefresh(20), "head tag info");
// //
std::string MetaRefresh(signed int seconds, const std::string& url = ""); std::string MetaRefresh(signed int seconds, const std::string& url = "");
skipping to change at line 66 skipping to change at line 69
const std::string space = "&nbsp;"; const std::string space = "&nbsp;";
// ampersand // ampersand
const std::string amp = "&amp;"; const std::string amp = "&amp;";
// quotation mark // quotation mark
const std::string quot = "&quot;"; const std::string quot = "&quot;";
// less than: < // less than: <
const std::string lt = "&lt;"; const std::string lt = "&lt;";
// greater than: > // greater than: >
const std::string gt = "&gt;"; const std::string gt = "&gt;";
} // end namespace jwcgi } // end namespace ceegeye
#endif // !#ifndef __STATICS_H__ #endif // !#ifndef __STATICS_H__
 End of changes. 8 change blocks. 
9 lines changed or deleted 12 lines changed or added


 xhtml.h   xhtml.h 
// Copyright 2003 John Wiggins (http://johnwiggins.net) // Note that the only valid version of the GPL as far as ceegeye
// is concerned is v2 of the license (ie v2, not v2.2 or v3.x or whatever),
// unless explicitly otherwise stated.
// //
// This file is part of the jwCGI library. // This file is part of the ceegeye library.
// //
// jwCGI library is free software; you can redistribute it and/or modify // ceegeye library is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or // the Free Software Foundation; version 2 of the License.
// (at your option) any later version.
// //
// jwCGI library is distributed in the hope that it will be useful, // ceegeye library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details. // GNU General Public License for more details.
// //
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with jwCGI library; if not, write to the Free Software // along with ceegeye library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 U SA // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 U SA
// //
// http://johnwiggins.net // http://johnwiggins.net
// cgilib@johnwiggins.net // cgilib@johnwiggins.net
// //
// xhtml.h: interface for the xhtml class // xhtml.h: interface for the xhtml class
// //
#include <sstream> #include <sstream>
#include <stack> #include <stack>
#include <string> #include <string>
#include <utility> #include <utility>
#include <ctime> #include <ctime>
#include <ostream>
#include "outputbase.h"
#ifndef __XHTML_H__ #ifndef __XHTML_H__
#define __XHTML_H__ #define __XHTML_H__
namespace jwcgi { namespace ceegeye {
// unices have a long long map this to __int64, I can be lazy later and typ
e less
#ifndef WIN32
typedef long long __int64;
#endif
using std::string; using std::string;
using std::cout;
template <class T> class xhtml class xhtml: public outputbase<std::ostream> {
{
public: public:
// Please note that the constructor takes a reference to an object and stor es // Please note that the constructor takes a reference to an object and stor es
// this reference. Therefore you better be sure the object the reference po ints // this reference. Therefore you better be sure the object the reference po ints
// to is not destroyed before this xhtml<T> object goes out of scope! In th e case // to is not destroyed before this xhtml<T> object goes out of scope! In th e case
// of 'cout' it is okay as this is a global object. // of 'cout' it is okay as this is a global object.
// example of use: // example of use:
// using namespace jwcgi; // using namespace ceegeye;
// xhtml<std::ostream> p(std::cout); // CGI cgi;
// xhtml<std::ostream> p(cgi);
// p.pagebegin("My Page"); // p.pagebegin("My Page");
// p.body(); // p.body();
// p.p(); // p.p();
// p << " Number 123 + 300 = " << 123 + 300 // is the same as : // p << " Number 123 + 300 = " << 123 + 300 // is the same as :
// std::cout << " Number 123 + 300 = " << 123 + 300; // cout << " Number 123 + 300 = " << 123 + 300;
// p.pend(); // p.pend();
// //
xhtml(T& Output); // deafult to a one hour session
virtual ~xhtml(); xhtml(CGI& cgi, long SessionExpires = 3600, const string& Sessionfile =
".htceegisession");
~xhtml();
cgisession& session() { return Session; }
// encapsulate the http headers needed for CGI // encapsulate the http headers needed for CGI
// This function must be called before any other // This function must be called before any other
// to ensure the http headers are closed correctly. // to ensure the http headers are closed correctly.
void pagebegin(const string& title = "untitled page", void pagebegin(const string& title = "untitled page",
const string& headtag = "", const string& headtag = "",
const string& cssfile = "", const string& cssfile = "",
const string& httpheaders = "", const string& httpheaders = "",
const string& contenttype = "text/html"); const string& contenttype = "application/xhtml+xml");
// visible part of page. // visible part of page.
void body(const string& id = "", void body(const string& id = "",
const string& Class = "", const string& Class = "",
const string& onload = ""); const string& onload = "");
// Encapsulate html form tags. // Encapsulate html form tags.
void form(const string& id = "", void form(const string& id = "",
const string& action = "", const string& action = "",
const string& onsubmit = "", const string& onsubmit = "",
skipping to change at line 160 skipping to change at line 162
const string& onchange = "", const string& onclick = "", const string& onchange = "", const string& onclick = "",
const string& onfocus = "", const string& tooltip = ""); const string& onfocus = "", const string& tooltip = "");
void selectend(); void selectend();
void selectoption(const string& value, void selectoption(const string& value,
const string& text, const string& text,
bool selected = false) const; bool selected = false) const;
void inputreset(const string& name, const string& label, void inputreset(const string& name, const string& label,
const string& onclick, const string& Class = "", const string& onclick, const string& Class = "",
const string& size = "") co nst; const string& size = "") const;
// html tables // html tables
void table(const string& id = "", const string& Class = ""); void table(const string& id = "", const string& Class = "");
void tableend(); void tableend();
void tr(const string& id = "", const string& Class = ""); //row void tr(const string& id = "", const string& Class = ""); //row
void trend(); // close the tr tag void trend(); // close the tr tag
void td(const string& id = "", void td(const string& id = "",
const string& Class = "", const string& Class = "",
const string& value = ""); // data const string& value = ""); // data
void tdend(); // close the td tag void tdend(); // close the td tag
skipping to change at line 199 skipping to change at line 201
void script(const string& code = "", void script(const string& code = "",
const string& type = "text/javascript") const; const string& type = "text/javascript") const;
void p(const string& id = "", const string& Class = ""); // paragraph void p(const string& id = "", const string& Class = ""); // paragraph
void pend(); void pend();
void div(const string& id = "", const string& Class = ""); // div tag void div(const string& id = "", const string& Class = ""); // div tag
void divend(); void divend();
void comment(const string& comment) const; void comment(const string& comment) const;
void b(const string& boldedtext) const; // bold void bold(const string& boldedtext) const; // bold
void br() const; // line break void br() const; // line break
void space() const; // non breaking space void space() const; // non breaking space
// html headings 1-6 // html headings 1-6
void h1(const string& text, const string& id = "", const string& Class = "") const; void h1(const string& text, const string& id = "", const string& Class = "") const;
void h2(const string& text, const string& id = "", const string& Class = "") const; void h2(const string& text, const string& id = "", const string& Class = "") const;
void h3(const string& text, const string& id = "", const string& Class = "") const; void h3(const string& text, const string& id = "", const string& Class = "") const;
void h4(const string& text, const string& id = "", const string& Class = "") const; void h4(const string& text, const string& id = "", const string& Class = "") const;
void h5(const string& text, const string& id = "", const string& Class = "") const; void h5(const string& text, const string& id = "", const string& Class = "") const;
void h6(const string& text, const string& id = "", const string& Class = "") const; void h6(const string& text, const string& id = "", const string& Class = "") const;
// stream the built in types.
// now we can do: xhtmlObject << 10 << " hello world";
xhtml<T>& operator<<(const char* in);
xhtml<T>& operator<<(const string& in);
xhtml<T>& operator<<(char in);
xhtml<T>& operator<<(int in);
xhtml<T>& operator<<(short in);
xhtml<T>& operator<<(long in);
xhtml<T>& operator<<(__int64 in);
xhtml<T>& operator<<(float in);
xhtml<T>& operator<<(double in);
xhtml<T>& operator<<(long double in);
xhtml<T>& operator<<(unsigned int in);
xhtml<T>& operator<<(unsigned short in);
xhtml<T>& operator<<(unsigned long in);
///////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////
// cookie functions // cookie functions
// //
// SetCookie(...) must be called before beginpage() to work // SetCookie(...) must be called before beginpage() to work
// "value_name" is in the form "nameofcookie=value" // "value_name" is in the form "nameofcookie=value"
// e.g. orderno=1234567 // e.g. orderno=1234567
// example setting a cookie to expire 3 days from now: // example setting a cookie to expire 3 days from now:
// //
// long t = 60 * 60 * 24 * 3; // 3 days // long t = 60 * 60 * 24 * 3; // 3 days
// //
// to delete a cookie send a negative time // to delete a cookie send a negative time
// i.e. t -= 60; // negative one minute // i.e. t -= 60; // negative one minute
// xhtmlobject.SetCookie("clientname", "1234567", t); // xhtmlobject.SetCookie("clientname", "1234567", t);
// //
bool SetCookie(const string& cookie_name, const string& value, bool SetCookie(const string& cookie_name, const string& value,
const long& expires, const string& path = "", const long& expires, const string& path = "",
const string& domain = "", bool secure = false) const; const string& domain = "", bool secure = false);
// returns a cookie value if it exists // returns a cookie value if it exists
bool GetCookie(const CGI& cgi, const string& name, string& value) const; bool GetCookie(const string& name, string& value);
// Delete a cookie already set // Delete a cookie already set
void DeleteCookie(const string& cookiename, void DeleteCookie(const string& cookiename,
const string& path ="", const string& path = "",
const string& domain="") const; const string& domain= "");
private: private:
// stack of opened xhtml tags // stack of opened xhtml tags
std::stack<std::string> opentags; std::stack<string> opentags;
// utility method adds javascript cookie functions to a page. // utility method adds javascript cookie functions to a page.
const char* cookiefuncs() const; const char* cookiefuncs() const;
// our stream object
T& output;
// used to implicitly call the closing tags of an html page. (see destru ctor) // used to implicitly call the closing tags of an html page. (see destru ctor)
bool bodytagopen; bool bodytagopen;
bool htmltagopen; bool htmltagopen;
static bool headerssent; cgisession Session;
}; };
} // end namespace jwcgi // This function places a submit button on the page that you can check
// against its name to see if it was clicked.
// You can check whether the submit button is clicked by retrieving the val
ue
// of the hidden element and testing equality against the string value.
// e.g. Add a hidden element to the form (page)
// If the hidden value is named 'button1' and the button name is 'butt
on1'
// string thebutton;
// if(cgi.GetValue("button1", thebutton) && (thebutton == "button1"))
{
// // okay the button was clicked
// }
//
void submitbuttoncheck(xhtml& p,
const string& SubmitName,
const string& SubmitText,
const string& HiddenName,
const string& FormID,
const string& Class = "");
//////////////////////////////////////////////////////////////// } // end namespace ceegeye
//////////////// implementation
#include "xhtml.cpp"
#endif // !ifndef __XHTML_H__ #endif // !ifndef __XHTML_H__
 End of changes. 25 change blocks. 
54 lines changed or deleted 53 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/