Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes

base_cgi::CGI Class Reference

cgi server class More...

#include <libppbase/base_cgi/CGI.h>

Inheritance diagram for base_cgi::CGI:
base_cgi::CGIFast base_cgi::CGIStd

List of all members.

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::ConfiggetConfig () 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.
CGIFilegetFile (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::LoggetLog () 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::StringssiBase () 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

Detailed Description

cgi server class

Author:
Christoph Schwarz
Version:
$Id: CGI.h 21 2010-09-05 04:18:17Z cschwarz1 $

Constructor & Destructor Documentation

base_cgi::CGI::CGI ( const base::String program  ) 

Constructor.

Parameters:
program program name, may be full path

Member Function Documentation

void base_cgi::CGI::add ( const base::String var,
const base::String val 
)

Adds a form variable, appends contents if the variable already exists.

Parameters:
var variable name
val variable value
bool base_cgi::CGI::exists ( const base::String var  )  const

Checks if an input variable exists.

Parameters:
var the variable name
Returns:
true if the variable exists, false if not
base::String base_cgi::CGI::get ( const base::String var  )  const

Gets an input variable.

Parameters:
var the variable name
Returns:
the variable value, or an empty string if the variable does not exist
base::String base_cgi::CGI::getCookie ( const char *  name  )  const

Gets a cookie.

Parameters:
name the cookie name
Returns:
the cookie value
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.

Parameters:
var the variable name
defval value to return if the variable does not exist
Returns:
the variable value

Implemented in base_cgi::CGIFast, and base_cgi::CGIStd.

CGIFile* base_cgi::CGI::getFile ( const base::String name  )  const

Gets an attached file.

Parameters:
name the attachment name (name of form variable)
Returns:
NULL if there is no such file
std::vector<CGIFile*> base_cgi::CGI::getFiles (  )  const

Gets all attached files.

Returns:
the attached files
base::String base_cgi::CGI::getHost (  )  const

Gets the called host name.

Returns:
the host name
base::Log* base_cgi::CGI::getLog (  )  const

Returns the cgi's log object.

Returns:
the log object
base::String base_cgi::CGI::getPath (  )  const

Returns the path part from the URI.

Returns:
the path part
base::String base_cgi::CGI::getUserAgent (  )  const

Returns the user agent of the caller.

Returns:
the user agent
static base::String base_cgi::CGI::htmlEncode ( const base::String s,
bool  crlf = false 
) [static]

Encodes a string to html.

Parameters:
s the string to encode
crlf true to encode line feeds as <br>, false to leave them alone
Returns:
the encoded string
virtual int base_cgi::CGI::inChar (  )  [protected, pure virtual]

Reads a character from the input stream.

Returns:
the character, or -1 on eof
void base_cgi::CGI::initGet ( const base::String s  ) 

Parses a get-like http request.

Parameters:
s the input uri
virtual int base_cgi::CGI::inLine ( char *  buf,
int  len 
) [protected, pure virtual]

Reads a line from the input stream.

Parameters:
buf buffer that receives the line
len maximum number of bytes to put into the buffer
Returns:
number of bytes read
void base_cgi::CGI::log ( base::Log::levels  level,
const char *  func,
const char *  fmt,
  ... 
) const

Logs a message.

Parameters:
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.

Parameters:
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.

Parameters:
s data to write
void base_cgi::CGI::outf ( const char *  fmt,
  ... 
)

Writes data (mostly html) to the output stream.

Parameters:
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.

Parameters:
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.

Parameters:
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.

Parameters:
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.

Parameters:
url the url to redirect to
void base_cgi::CGI::set ( const base::String var,
const base::String val 
)

Sets an output variable.

Parameters:
var the variable name
val the variable value
void base_cgi::CGI::set ( const base::String var,
int  val 
)

Sets an output variable.

Parameters:
var the variable name
val the variable value
const base::String& base_cgi::CGI::ssiBase (  )  const

Gets the base directory for SSI files.

Returns:
the base directory
void base_cgi::CGI::ssiError ( const base::String msg  ) 

Shows an SSI error message.

Parameters:
msg the error message
void base_cgi::CGI::ssiError ( const char *  fmt,
  ... 
)

Shows an SSI error message.

Parameters:
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.

Returns:
the count of SSI error messages
void base_cgi::CGI::ssiGeneralError ( const base::String msg = ""  ) 

Shows an SSI general error message.

Parameters:
msg an additional message to show
void base_cgi::CGI::ssiInfo ( const char *  fmt,
  ... 
)

Shows an SSI informal message.

Parameters:
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.

Parameters:
msg the error message
void base_cgi::CGI::ssiOutput ( const base::String filename  ) 

Writes an SSI to the output stream.

Parameters:
filename the ssi file name
void base_cgi::CGI::ssiOutput ( std::ifstream &  in  ) 

Writes an SSI to the output stream.

Parameters:
in stream to read output data from
static base::String base_cgi::CGI::ssiValidExpand ( const base::String pat  )  [static]

Expands a validity expression.

Parameters:
pat the expression to expand
Returns:
the expanded expression
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.

Parameters:
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
Returns:
true if valid, false if not
static base::String base_cgi::CGI::urlDecode ( const base::String s  )  [static]

Decodes a string in url-format.

Parameters:
s the string to decode
Returns:
the decoded string
static base::String base_cgi::CGI::urlEncode ( const base::String s  )  [static]

Encodes a string in url-format.

Parameters:
s the string to encode
Returns:
the encoded string

The documentation for this class was generated from the following file: