#include <sessionserver.h>
Collaboration diagram for Dv::Cgi::SessionServer:
Public Member Functions | |
SessionServer (const std::string &program_name, time_t delay, const std::string &timeouturl, const std::string &errorurl, const std::string &logdir="/tmp", const std::string &sockdir="/tmp") | |
Constructor. | |
virtual | ~SessionServer () |
Destructor. | |
const std::string & | name () const |
Name of server application. | |
const Util::Props & | props () const |
Get props object containing formdata from client. | |
Dv::Util::Props & | props () |
Get props object containing formdata from client. | |
const std::string * | operator() (const std::string &key) const |
Easy check for presence of a formdata item. | |
const std::string & | props (const std::string &name) const throw (std::runtime_error) |
std::string & | props (const std::string &name) throw (std::runtime_error) |
const Util::Props & | env () const |
Get Props object containing shell environment from client. | |
const std::string & | env (const std::string &name) const throw (std::runtime_error) |
const Util::Props & | cookies () const |
Get Props object containing cookies from client. | |
const std::string & | cookies (const std::string &name) const throw (std::exception) |
std::string | here () const throw (std::runtime_error) |
Return url of current request. | |
std::string | here_base () const throw (std::runtime_error) |
Return base url of current request. | |
const HttpHeader & | header () const |
Get HttpHeader object containing output headers. | |
HttpHeader & | header () |
Get HttpHeader object containing output headers. | |
HttpHeader * | operator-> () |
Get HttpHeader object containing output headers. | |
operator bool () const | |
Get status of server. | |
void | disconnect (const std::string &url) |
Remove cookie, relocate to url, stop network server and connection. | |
void | disconnect () |
Stop server and network connection. | |
void | refresh () |
Refresh: send header (if not already sent) and get input from client. | |
std::ostream & | log () const |
Log stream. | |
Private Member Functions | |
SessionServer (const SessionServer &s) | |
SessionServer & | operator= (const SessionServer &s) |
void | send_header () |
void | get_input () |
Private Attributes | |
std::string | name_ |
time_t | delay_ |
std::string | timeouturl_ |
std::string | errorurl_ |
std::string | server_filename_ |
Dv::Net::userversocket * | server_socket_ |
Dv::Net::usocket * | client_socket_ |
bool | status_ |
Dv::Util::Props | props_ |
Dv::Util::Props | env_ |
Dv::Util::Props | cookies_ |
Dv::Cgi::HttpHeader | header_ |
std::ostream * | log_ |
Filter | filter_ |
Friends | |
class | Filter |
Classes | |
class | Filter |
Filter class that ensures that header_ is output before anything else. More... |
Definition at line 19 of file sessionserver.h.
|
Constructor. A Dv::Cgi::SessionServer object must be used in a cgi program. Dv::Cgi::SessionServer client("myprog",5*1000, "index.html", "http://tinf2.vub.ac.be/index.html");
The server communicates with its (cgi) clients using a unix socket attached to a filename Application code is rather simple: the program communicates with the client (a Dv::Cgi::SessionServer object) using interactions of the form client << .. html .. << Dv::Cgi::eof; // now client input is available, e.g. in client.props() if ( client("number") ) { int number; client.props() >> "number" >> number; .. } Note that all C++ variables are persistent (since they reside in the server process). E.g. it is easy to write a login function like so: std::string login(Dv::Cgi::SessionServer& client) { while (client) { client << login_form << Dv::Cgi::eof; if ( client("name") ) { std::string uname = client.props("name"); std::string uname = client.props("password"); if (check_password_valid) return uname; } } throw std::runtime_error("login timed out"); } To exit the application use Dv::Cgi::SessionServer::disconnect . Silly example applications are available in the distribution: see test-sessionserver.C and example-session.C .
|
|
Destructor.
|
|
|
|
Name of server application.
Definition at line 103 of file sessionserver.h. References name_. |
|
Get props object containing formdata from client.
Definition at line 106 of file sessionserver.h. References props_. Referenced by operator()(), and props(). |
|
Get props object containing formdata from client.
Definition at line 108 of file sessionserver.h. References props_. |
|
Easy check for presence of a formdata item.
Definition at line 111 of file sessionserver.h. References Dv::Util::Props::find(), and props(). |
|
Definition at line 115 of file sessionserver.h. |
|
Definition at line 120 of file sessionserver.h. |
|
Get Props object containing shell environment from client.
Definition at line 123 of file sessionserver.h. References env_. Referenced by env(). |
|
Definition at line 127 of file sessionserver.h. |
|
Get Props object containing cookies from client.
Definition at line 131 of file sessionserver.h. References cookies_. Referenced by cookies(). |
|
Definition at line 135 of file sessionserver.h. |
|
Return url of current request.
|
|
Return base url of current request.
|
|
Get HttpHeader object containing output headers.
Definition at line 153 of file sessionserver.h. References header_. |
|
Get HttpHeader object containing output headers.
Definition at line 155 of file sessionserver.h. References header_. |
|
Get HttpHeader object containing output headers.
Definition at line 160 of file sessionserver.h. References header_. |
|
Get status of server.
Definition at line 166 of file sessionserver.h. References status_. |
|
Remove cookie, relocate to url, stop network server and connection.
|
|
Stop server and network connection.
|
|
Refresh: send header (if not already sent) and get input from client.
|
|
Log stream. This is a Dv::Util::logstream: each line is automatically prefixed by the date and the identification of the process.
Definition at line 182 of file sessionserver.h. References log_. |
|
|
|
|
|
|
|
Definition at line 203 of file sessionserver.h. |
|
Definition at line 208 of file sessionserver.h. Referenced by name(). |
|
Definition at line 209 of file sessionserver.h. |
|
Definition at line 210 of file sessionserver.h. |
|
Definition at line 211 of file sessionserver.h. |
|
Definition at line 212 of file sessionserver.h. |
|
Definition at line 214 of file sessionserver.h. |
|
Definition at line 215 of file sessionserver.h. |
|
Definition at line 216 of file sessionserver.h. Referenced by operator bool(). |
|
Definition at line 218 of file sessionserver.h. Referenced by props(). |
|
Definition at line 219 of file sessionserver.h. Referenced by env(). |
|
Definition at line 220 of file sessionserver.h. Referenced by cookies(). |
|
Definition at line 222 of file sessionserver.h. Referenced by header(), and operator->(). |
|
Definition at line 224 of file sessionserver.h. Referenced by log(). |
|
Definition at line 225 of file sessionserver.h. |
dvcgi-0.5.14 | [22 January, 2006] |