cgi server class More...
#include <libppbase/base_cgi/CGI.h>
Public Member Functions | |
CGI (const base::String &program) | |
Constructor. | |
virtual | ~CGI () |
Destructor. | |
void | add (const base::String &var, const base::String &val) |
Adds a form variable, appends contents if the variable already exists. | |
void | dump (bool showenv=false) |
Dumps all variables and the environment. | |
bool | exists (const base::String &var) const |
Checks if an input variable exists. | |
virtual void | flush ()=0 |
Flushes the output. | |
base::String | get (const base::String &var) const |
Gets an input variable. | |
const base::Config & | getConfig () const |
Gets the configuration. | |
base::String | getCookie (const char *name) const |
Gets a cookie. | |
virtual const char * | getenv (const char *var, const char *defval=NULL) const =0 |
Gets an environment variable that was set by the http server. | |
CGIFile * | getFile (const base::String &name) const |
Gets an attached file. | |
std::vector< CGIFile * > | getFiles () const |
Gets all attached files. | |
base::String | getHost () const |
Gets the called host name. | |
base::Log * | getLog () const |
Returns the cgi's log object. | |
base::String | getPath () const |
Returns the path part from the URI. | |
base::String | getUserAgent () const |
Returns the user agent of the caller. | |
void | init () |
Initializes the object and reads a http request from the input stream by calling either initGet or initPost. | |
void | initGet (const base::String &s) |
Parses a get-like http request. | |
void | initPost () |
Parses a post-like http request. | |
void | log (base::Log::levels level, const char *func, const char *fmt,...) const |
Logs a message. | |
virtual void | out (const char *s, size_t len=base::String::npos)=0 |
Writes data (mostly html) to the output stream. | |
void | out (const base::String &s) |
Writes data (mostly html) to the output stream. | |
void | outf (const char *fmt,...) |
Writes data (mostly html) to the output stream. | |
void | outputDomainCookie (const base::String &name, const base::String &value, const base::String &domain, int timeout, const base::String &path="/") |
Emits a cookie for a given domain. | |
void | outputHeader (const base::String &contenttype="text/html", const base::String &charset="iso-8859-1") |
Writes the http header to the output stream. | |
void | outputHostCookie (const base::String &name, const base::String &value, int timeout, const base::String &path="/") |
Emits a cookie for the current host. | |
void | redirect (const base::String &url) |
Redirects to a different URL via HTTP. | |
void | set (const base::String &var, const base::String &val) |
Sets an output variable. | |
void | set (const base::String &var, int val) |
Sets an output variable. | |
const base::String & | ssiBase () const |
Gets the base directory for SSI files. | |
void | ssiBegin () |
Begins SSI output. | |
void | ssiEnd () |
Ends SSI output. | |
void | ssiError (const char *fmt,...) |
Shows an SSI error message. | |
void | ssiError (const base::String &msg) |
Shows an SSI error message. | |
int | ssiErrors () const |
Returns the count of SSI error messages. | |
void | ssiGeneralError (const base::String &msg="") |
Shows an SSI general error message. | |
void | ssiInfo (const char *fmt,...) |
Shows an SSI informal message. | |
void | ssiInfo (const base::String &msg) |
Shows an SSI informal message. | |
void | ssiOutput (std::ifstream &in) |
Writes an SSI to the output stream. | |
void | ssiOutput (const base::String &filename) |
Writes an SSI to the output stream. | |
bool | ssiValidInput (const base::String &descr, const base::String &var, bool select, size_t minlen, size_t maxlen, const base::String &allowed, const base::String &denied) |
Checks for valid input and issues SSI error messages on error. | |
Static Public Member Functions | |
static base::String | htmlEncode (const base::String &s, bool crlf=false) |
Encodes a string to html. | |
static base::String | ssiValidExpand (const base::String &pat) |
Expands a validity expression. | |
static base::String | urlDecode (const base::String &s) |
Decodes a string in url-format. | |
static base::String | urlEncode (const base::String &s) |
Encodes a string in url-format. | |
Protected Member Functions | |
virtual int | inChar ()=0 |
Reads a character from the input stream. | |
virtual int | inLine (char *buf, int len)=0 |
Reads a line from the input stream. | |
Protected Attributes | |
base::Config | _config |
configuration | |
int | _errors |
number of ssi errors that have been output so far | |
std::vector< CGIFile * > | _files |
list of attached files | |
bool | _header |
true if the http header has been output, false if not | |
base::Log * | _log |
the internal log object | |
base::String | _ssibase |
the base directory of the ssi files | |
base::String | _program |
the cgi program name |
cgi server class
base_cgi::CGI::CGI | ( | const base::String & | program | ) |
Constructor.
program | program name, may be full path |
void base_cgi::CGI::add | ( | const base::String & | var, | |
const base::String & | val | |||
) |
Adds a form variable, appends contents if the variable already exists.
var | variable name | |
val | variable value |
bool base_cgi::CGI::exists | ( | const base::String & | var | ) | const |
Checks if an input variable exists.
var | the variable name |
base::String base_cgi::CGI::get | ( | const base::String & | var | ) | const |
Gets an input variable.
var | the variable name |
base::String base_cgi::CGI::getCookie | ( | const char * | name | ) | const |
Gets a cookie.
name | the cookie name |
virtual const char* base_cgi::CGI::getenv | ( | const char * | var, | |
const char * | defval = NULL | |||
) | const [pure virtual] |
Gets an environment variable that was set by the http server.
var | the variable name | |
defval | value to return if the variable does not exist |
Implemented in base_cgi::CGIFast, and base_cgi::CGIStd.
CGIFile* base_cgi::CGI::getFile | ( | const base::String & | name | ) | const |
Gets an attached file.
name | the attachment name (name of form variable) |
std::vector<CGIFile*> base_cgi::CGI::getFiles | ( | ) | const |
Gets all attached files.
base::String base_cgi::CGI::getHost | ( | ) | const |
Gets the called host name.
base::Log* base_cgi::CGI::getLog | ( | ) | const |
Returns the cgi's log object.
base::String base_cgi::CGI::getPath | ( | ) | const |
Returns the path part from the URI.
base::String base_cgi::CGI::getUserAgent | ( | ) | const |
Returns the user agent of the caller.
static base::String base_cgi::CGI::htmlEncode | ( | const base::String & | s, | |
bool | crlf = false | |||
) | [static] |
Encodes a string to html.
s | the string to encode | |
crlf | true to encode line feeds as <br>, false to leave them alone |
virtual int base_cgi::CGI::inChar | ( | ) | [protected, pure virtual] |
Reads a character from the input stream.
void base_cgi::CGI::initGet | ( | const base::String & | s | ) |
Parses a get-like http request.
s | the input uri |
virtual int base_cgi::CGI::inLine | ( | char * | buf, | |
int | len | |||
) | [protected, pure virtual] |
Reads a line from the input stream.
buf | buffer that receives the line | |
len | maximum number of bytes to put into the buffer |
void base_cgi::CGI::log | ( | base::Log::levels | level, | |
const char * | func, | |||
const char * | fmt, | |||
... | ||||
) | const |
Logs a message.
level | the log level | |
func | the calling function or method name | |
fmt | a printf-like format string | |
... | additional arguments for the format string |
virtual void base_cgi::CGI::out | ( | const char * | s, | |
size_t | len = base::String::npos | |||
) | [pure virtual] |
Writes data (mostly html) to the output stream.
s | data to write | |
len | number of bytes to write |
Implemented in base_cgi::CGIFast, and base_cgi::CGIStd.
void base_cgi::CGI::out | ( | const base::String & | s | ) |
Writes data (mostly html) to the output stream.
s | data to write |
void base_cgi::CGI::outf | ( | const char * | fmt, | |
... | ||||
) |
Writes data (mostly html) to the output stream.
fmt | a printf-like format string | |
... | additional arguments for the format string |
void base_cgi::CGI::outputDomainCookie | ( | const base::String & | name, | |
const base::String & | value, | |||
const base::String & | domain, | |||
int | timeout, | |||
const base::String & | path = "/" | |||
) |
Emits a cookie for a given domain.
name | cookie name | |
value | cookie value | |
domain | the desired domain | |
timeout | lifetime in seconds | |
path | valid for given uri path |
void base_cgi::CGI::outputHeader | ( | const base::String & | contenttype = "text/html" , |
|
const base::String & | charset = "iso-8859-1" | |||
) |
Writes the http header to the output stream.
contenttype | the http content type | |
charset | the character set |
void base_cgi::CGI::outputHostCookie | ( | const base::String & | name, | |
const base::String & | value, | |||
int | timeout, | |||
const base::String & | path = "/" | |||
) |
Emits a cookie for the current host.
name | cookie name | |
value | cookie value | |
timeout | lifetime in seconds | |
path | valid for given uri path |
void base_cgi::CGI::redirect | ( | const base::String & | url | ) |
Redirects to a different URL via HTTP.
url | the url to redirect to |
void base_cgi::CGI::set | ( | const base::String & | var, | |
const base::String & | val | |||
) |
Sets an output variable.
var | the variable name | |
val | the variable value |
void base_cgi::CGI::set | ( | const base::String & | var, | |
int | val | |||
) |
Sets an output variable.
var | the variable name | |
val | the variable value |
const base::String& base_cgi::CGI::ssiBase | ( | ) | const |
Gets the base directory for SSI files.
void base_cgi::CGI::ssiError | ( | const base::String & | msg | ) |
Shows an SSI error message.
msg | the error message |
void base_cgi::CGI::ssiError | ( | const char * | fmt, | |
... | ||||
) |
Shows an SSI error message.
fmt | a printf-like format string | |
... | additional arguments for the format string |
int base_cgi::CGI::ssiErrors | ( | ) | const |
Returns the count of SSI error messages.
void base_cgi::CGI::ssiGeneralError | ( | const base::String & | msg = "" |
) |
Shows an SSI general error message.
msg | an additional message to show |
void base_cgi::CGI::ssiInfo | ( | const char * | fmt, | |
... | ||||
) |
Shows an SSI informal message.
fmt | a printf-like format string | |
... | additional arguments for the format string |
void base_cgi::CGI::ssiInfo | ( | const base::String & | msg | ) |
Shows an SSI informal message.
msg | the error message |
void base_cgi::CGI::ssiOutput | ( | const base::String & | filename | ) |
Writes an SSI to the output stream.
filename | the ssi file name |
void base_cgi::CGI::ssiOutput | ( | std::ifstream & | in | ) |
Writes an SSI to the output stream.
in | stream to read output data from |
static base::String base_cgi::CGI::ssiValidExpand | ( | const base::String & | pat | ) | [static] |
Expands a validity expression.
pat | the expression to expand |
bool base_cgi::CGI::ssiValidInput | ( | const base::String & | descr, | |
const base::String & | var, | |||
bool | select, | |||
size_t | minlen, | |||
size_t | maxlen, | |||
const base::String & | allowed, | |||
const base::String & | denied | |||
) |
Checks for valid input and issues SSI error messages on error.
descr | field name | |
var | variable name | |
select | true if it is a select-type variable, false if it is a text-type variable | |
minlen | minimum string length | |
maxlen | maximum string length | |
allowed | allowed characters | |
denied | denied characters |
static base::String base_cgi::CGI::urlDecode | ( | const base::String & | s | ) | [static] |
Decodes a string in url-format.
s | the string to decode |
static base::String base_cgi::CGI::urlEncode | ( | const base::String & | s | ) | [static] |
Encodes a string in url-format.
s | the string to encode |