Rudiments
Classes | Public Member Functions | List of all members
httprequest Class Reference

#include <httprequest.h>

Inherits input.

Inherited by urlhttprequest.

Classes

struct  parameterrequirement
 

Public Member Functions

 httprequest (httpserverapi *sapi)
 
virtual void writeVariables ()
 
const chargetEnvironmentVariable (const char *name)
 
uint64_t getEnvironmentVariableCount ()
 
const char *constgetEnvironmentVariables ()
 
const char *constgetEnvironmentValues ()
 
bool setEnvironmentVariable (const char *name, const char *value)
 
void writeEnvironment ()
 
const chargetParameter (const char *name)
 
void getParametersAsGetString (output *container, const char *const *exceptions)
 
void getParametersAsHiddenVariables (output *container, const char *const *excepcions)
 
uint64_t getParameterCount ()
 
const char *constgetParameterVariables ()
 
const char *constgetParameterValues ()
 
bool setParameter (const char *name, const char *value)
 
const chargetFileParameterFileName (const char *name)
 
const chargetFileParameterTempFileName (const char *name)
 
const chargetFileParameterMimeType (const char *name)
 
uint64_t getFileCount ()
 
const char *constgetFileNames ()
 
bool setFileParameter (const char *name, const char *filename, const char *tempfilename, const char *mimetype)
 
void removeTempFiles ()
 
const chargetCookie (const char *name)
 
uint64_t getCookieCount ()
 
const char *constgetCookieVariables ()
 
const char *constgetCookieValues ()
 
bool setCookie (const char *name, const char *value)
 
uint64_t getAllVariableCount ()
 
const char *constgetAllVariables ()
 
const char *constgetAllValues ()
 
ssize_t read (byte_t *buffer, size_t size)
 
ssize_t read (char *buffer, size_t length)
 
ssize_t read (char *character)
 
ssize_t read (wchar_t *buffer, size_t length)
 
ssize_t read (wchar_t *character)
 
ssize_t readUcs2 (ucs2_t *buffer, size_t length)
 
ssize_t readUcs2 (ucs2_t *character)
 
ssize_t read (int16_t *number)
 
ssize_t read (int32_t *number)
 
ssize_t read (int64_t *number)
 
ssize_t read (byte_t *character)
 
ssize_t read (uint16_t *number)
 
ssize_t read (uint32_t *number)
 
ssize_t read (uint64_t *number)
 
ssize_t read (float *number)
 
ssize_t read (double *number)
 
virtual bool getMethodIsAllowed (const char *deniedmethods, const char *allowedmethods)
 
virtual bool getContentTypeIsAllowed (const char *deniedcontenttypes, const char *allowedcontenttypes)
 
virtual bool getIpIsAllowed (const char *deniedips, const char *allowedips)
 
virtual bool getRefererIsAllowed (const char *deniedreferers, const char *allowedreferers)
 
bool getRequiredParametersWereProvided (parameterrequirement **pr)
 
- Public Member Functions inherited from input
 input ()
 
virtual ~input ()
 
virtual off64_t setPositionRelativeToBeginning (off64_t offset)
 
virtual off64_t setPositionRelativeToCurrent (off64_t offset)
 
virtual off64_t setPositionRelativeToEnd (off64_t offset)
 
virtual off64_t getPosition ()
 
ssize_t read (char **buffer, const char *terminator)
 
ssize_t read (char **buffer, const char *terminator, size_t maxbytes)
 
virtual ssize_t read (byte_t *buffer, size_t size, int32_t sec, int32_t usec)
 
virtual ssize_t read (char *buffer, size_t length, int32_t sec, int32_t usec)
 
virtual ssize_t read (char *buffer, int32_t sec, int32_t usec)
 
virtual ssize_t read (wchar_t *buffer, size_t length, int32_t sec, int32_t usec)
 
virtual ssize_t read (wchar_t *buffer, int32_t sec, int32_t usec)
 
virtual ssize_t readUcs2 (ucs2_t *buffer, size_t length, int32_t sec, int32_t usec)
 
virtual ssize_t readUcs2 (ucs2_t *buffer, int32_t sec, int32_t usec)
 
virtual ssize_t read (int16_t *buffer, int32_t sec, int32_t usec)
 
virtual ssize_t read (int32_t *buffer, int32_t sec, int32_t usec)
 
virtual ssize_t read (int64_t *buffer, int32_t sec, int32_t usec)
 
virtual ssize_t read (byte_t *buffer, int32_t sec, int32_t usec)
 
virtual ssize_t read (uint16_t *buffer, int32_t sec, int32_t usec)
 
virtual ssize_t read (uint32_t *buffer, int32_t sec, int32_t usec)
 
virtual ssize_t read (uint64_t *buffer, int32_t sec, int32_t usec)
 
virtual ssize_t read (float *buffer, int32_t sec, int32_t usec)
 
virtual ssize_t read (double *buffer, int32_t sec, int32_t usec)
 
ssize_t read (char **buffer, const char *terminator, int32_t sec, int32_t usec)
 
ssize_t read (char **buffer, const char *terminator, size_t maxbytes, int32_t sec, int32_t usec)
 
ssize_t read (char **buffer, const char *terminator, size_t maxbytes, char escapechar, int32_t sec, int32_t usec)
 
- Public Member Functions inherited from object
virtual ~object ()
 

Detailed Description

The httprequest class provides methods for accessing components of the http request.

Member Function Documentation

◆ getAllValues()

const char *const * httprequest::getAllValues ( )

Returns a null terminated list of the values corresponding to the variables returned from getAllVariables().

◆ getAllVariableCount()

uint64_t httprequest::getAllVariableCount ( )

Returns the total number of variables - environment, parameters, files, and cookies.

◆ getAllVariables()

const char *const * httprequest::getAllVariables ( )

Returns a null terminated list of all variables. The order of the list is the order the variables were received in.

◆ getContentTypeIsAllowed()

virtual bool httprequest::getContentTypeIsAllowed ( const char * deniedcontenttypes,
const char * allowedcontenttypes )
virtual

Matches the CONTENT_TYPE environment variable against "deniedcontenttypes" and "allowedcontenttypes" (in that order) using regular expression syntax. Returns true if the content type of the data posted by the client is allowed and false otherwise.

This method may be overriden to provide customized content-type-based security.

◆ getCookie()

const char * httprequest::getCookie ( const char * name)

Returns the value of cookie "name".

◆ getCookieCount()

uint64_t httprequest::getCookieCount ( )

Returns the number of cookies collected.

◆ getCookieValues()

const char *const * httprequest::getCookieValues ( )

Returns a null terminated list of values corresponding to the variables returned from getCookieVariables().

◆ getCookieVariables()

const char *const * httprequest::getCookieVariables ( )

Returns a null terminated list of cookie variables. The order of the list is the order the variables were received in.

◆ getEnvironmentValues()

const char *const * httprequest::getEnvironmentValues ( )

Returns a null terminated list of environment variable values.

◆ getEnvironmentVariable()

const char * httprequest::getEnvironmentVariable ( const char * name)

Returns the value of the environment variable "name".

◆ getEnvironmentVariableCount()

uint64_t httprequest::getEnvironmentVariableCount ( )

Returns the number of environment variables.

◆ getEnvironmentVariables()

const char *const * httprequest::getEnvironmentVariables ( )

Returns a null terminated list of environment variables.

◆ getFileCount()

uint64_t httprequest::getFileCount ( )

Returns the number of posted files.

◆ getFileNames()

const char *const * httprequest::getFileNames ( )

Returns a null terminated list of file names. The order of the list is the order in which the file parameters were received.

◆ getFileParameterFileName()

const char * httprequest::getFileParameterFileName ( const char * name)

Returns the filename passed in from file parameter "name".

◆ getFileParameterMimeType()

const char * httprequest::getFileParameterMimeType ( const char * name)

Returns the mime type of the file parameter "name".

◆ getFileParameterTempFileName()

const char * httprequest::getFileParameterTempFileName ( const char * name)

Returns the filename of the local file created when file parameter "name" was passed in.

◆ getIpIsAllowed()

virtual bool httprequest::getIpIsAllowed ( const char * deniedips,
const char * allowedips )
virtual

Matches the REMOTE_ADDR environment variable against "deniedips" and "allowedips" (in that order) using regular expression syntax. Returns true if the client's IP address is allowed and false otherwise.

This method may be overriden to provide customized ip-based security.

◆ getMethodIsAllowed()

virtual bool httprequest::getMethodIsAllowed ( const char * deniedmethods,
const char * allowedmethods )
virtual

Matches the REQUEST_METHOD environment variable against "deniedmethods" and "allowedmethods" (in that order) using regular expression syntax. Returns true if the request method used by the client is allowed and false otherwise.

This method may be overriden to provide customized request-method-based security.

◆ getParameter()

const char * httprequest::getParameter ( const char * name)

Returns the value of parameter "name".

◆ getParameterCount()

uint64_t httprequest::getParameterCount ( )

Returns the number of parameters.

◆ getParametersAsGetString()

void httprequest::getParametersAsGetString ( output * container,
const char *const * exceptions )

Returns all parameters formatted as an escaped get string into "container" with the exception of a NULL terminated list of exceptions. If "container" is NULL, the list is written to the browser.

◆ getParametersAsHiddenVariables()

void httprequest::getParametersAsHiddenVariables ( output * container,
const char *const * excepcions )

Returns all parameters formatted as a list of hidden variables into "container" with the exception of a NULL terminated list of exceptions passed in after "container". If "container" is NULL, the list is written to the browser.

◆ getParameterValues()

const char *const * httprequest::getParameterValues ( )

Returns a null terminated list of values corresponding to the variables returned from getParameterVariables().

◆ getParameterVariables()

const char *const * httprequest::getParameterVariables ( )

Returns a null terminated list of parameter variables. The order of the list is the order the variables were received in.

◆ getRefererIsAllowed()

virtual bool httprequest::getRefererIsAllowed ( const char * deniedreferers,
const char * allowedreferers )
virtual

Matches the HTTP_REFERER environment variable against "deniedreferers" and "allowedreferers" (in that order) using regular expression syntax. Returns true if the referrer is permitted and false otherwise.

This method may be overriden to provide customized referrer-based security.

◆ getRequiredParametersWereProvided()

bool httprequest::getRequiredParametersWereProvided ( parameterrequirement ** pr)

Reads through the NULL terminated list of parameter requirements. Returns true if the parameters meet the requirements and false if they did not.

Each parameterrequirement contains a parameter variable name and a boolean value indicating whether that variable can be empty or not.

For example. The following call requires that "first", "last", "address", "city", "state" and "phone" be present but allows "address", "city" and "state" to be blank.

parameterrequirement *pr[]={{"first",false}, {"last",false}, {"address",true}, {"city",true}, {"state",true}, {"phone",false}, NULL}; success=requiredParameters(pr);

◆ read() [1/14]

ssize_t httprequest::read ( byte_t * buffer,
size_t size )
virtual

Reads "size" bytes from the data posted by the client into "buffer". Returns the number of bytes that were successfully read or RESULT_ERROR if an error occurred.

Note that all read() methods return 0 (EOF) when the REQUEST_METHOD environment vairable is "get" or "head", as no data will have been posted, or when the REQUEST_METHOD environment variable is "post" and the CONTENT_TYPE environment variable is either "application/x-www-form-urlencoded" or "multipart-form-data", as in those cases, the posted data will have been processed internally.

Implements input.

◆ read() [2/14]

ssize_t httprequest::read ( byte_t * character)
virtual

Reads a byte from the data posted by the client into "character". Returns the number of bytes that were successfully read or RESULT_ERROR if an error occurred.

Note that all read() methods return 0 (EOF) when the REQUEST_METHOD environment vairable is "get" or "head", as no data will have been posted, or when the REQUEST_METHOD environment variable is "post" and the CONTENT_TYPE environment variable is either "application/x-www-form-urlencoded" or "multipart-form-data", as in those cases, the posted data will have been processed internally.

Implements input.

◆ read() [3/14]

ssize_t httprequest::read ( char * buffer,
size_t length )
virtual

Reads "length" characters from the data posted by the client into "buffer". Returns the number of bytes that were successfully read or RESULT_ERROR if an error occurred.

Note that all read() methods return 0 (EOF) when the REQUEST_METHOD environment vairable is "get" or "head", as no data will have been posted, or when the REQUEST_METHOD environment variable is "post" and the CONTENT_TYPE environment variable is either "application/x-www-form-urlencoded" or "multipart-form-data", as in those cases, the posted data will have been processed internally.

Implements input.

◆ read() [4/14]

ssize_t httprequest::read ( char * character)
virtual

Reads a character from the data posted by the client into "character". Returns the number of bytes that were successfully read or RESULT_ERROR if an error occurred.

Note that all read() methods return 0 (EOF) when the REQUEST_METHOD environment vairable is "get" or "head", as no data will have been posted, or when the REQUEST_METHOD environment variable is "post" and the CONTENT_TYPE environment variable is either "application/x-www-form-urlencoded" or "multipart-form-data", as in those cases, the posted data will have been processed internally.

Implements input.

◆ read() [5/14]

ssize_t httprequest::read ( double * number)
virtual

Reads a double-precision floating point number from the data posted by the client into "number". Returns the number of bytes that were successfully read or RESULT_ERROR if an error occurred.

Note that all read() methods return 0 (EOF) when the REQUEST_METHOD environment vairable is "get" or "head", as no data will have been posted, or when the REQUEST_METHOD environment variable is "post" and the CONTENT_TYPE environment variable is either "application/x-www-form-urlencoded" or "multipart-form-data", as in those cases, the posted data will have been processed internally.

Implements input.

◆ read() [6/14]

ssize_t httprequest::read ( float * number)
virtual

Reads a floating point number from the data posted by the client into "number". Returns the number of bytes that were successfully read or RESULT_ERROR if an error occurred.

Note that all read() methods return 0 (EOF) when the REQUEST_METHOD environment vairable is "get" or "head", as no data will have been posted, or when the REQUEST_METHOD environment variable is "post" and the CONTENT_TYPE environment variable is either "application/x-www-form-urlencoded" or "multipart-form-data", as in those cases, the posted data will have been processed internally.

Implements input.

◆ read() [7/14]

ssize_t httprequest::read ( int16_t * number)
virtual

Reads a 16-bit integer from the data posted by the client into "number". Returns the number of bytes that were successfully read or RESULT_ERROR if an error occurred.

Note that all read() methods return 0 (EOF) when the REQUEST_METHOD environment vairable is "get" or "head", as no data will have been posted, or when the REQUEST_METHOD environment variable is "post" and the CONTENT_TYPE environment variable is either "application/x-www-form-urlencoded" or "multipart-form-data", as in those cases, the posted data will have been processed internally.

Implements input.

◆ read() [8/14]

ssize_t httprequest::read ( int32_t * number)
virtual

Reads a 32-bit integer from the data posted by the client into "number". Returns the number of bytes that were successfully read or RESULT_ERROR if an error occurred.

Note that all read() methods return 0 (EOF) when the REQUEST_METHOD environment vairable is "get" or "head", as no data will have been posted, or when the REQUEST_METHOD environment variable is "post" and the CONTENT_TYPE environment variable is either "application/x-www-form-urlencoded" or "multipart-form-data", as in those cases, the posted data will have been processed internally.

Implements input.

◆ read() [9/14]

ssize_t httprequest::read ( int64_t * number)
virtual

Reads a 64-bit integer from the data posted by the client into "number". Returns the number of bytes that were successfully read or RESULT_ERROR if an error occurred.

Note that all read() methods return 0 (EOF) when the REQUEST_METHOD environment vairable is "get" or "head", as no data will have been posted, or when the REQUEST_METHOD environment variable is "post" and the CONTENT_TYPE environment variable is either "application/x-www-form-urlencoded" or "multipart-form-data", as in those cases, the posted data will have been processed internally.

Implements input.

◆ read() [10/14]

ssize_t httprequest::read ( uint16_t * number)
virtual

Reads a 16-bit unsigned integer from the data posted by the client into "number". Returns the number of bytes that were successfully read or RESULT_ERROR if an error occurred.

Note that all read() methods return 0 (EOF) when the REQUEST_METHOD environment vairable is "get" or "head", as no data will have been posted, or when the REQUEST_METHOD environment variable is "post" and the CONTENT_TYPE environment variable is either "application/x-www-form-urlencoded" or "multipart-form-data", as in those cases, the posted data will have been processed internally.

Implements input.

◆ read() [11/14]

ssize_t httprequest::read ( uint32_t * number)
virtual

Reads a 32-bit unsigned integer from the data posted by the client into "number". Returns the number of bytes that were successfully read or RESULT_ERROR if an error occurred.

Note that all read() methods return 0 (EOF) when the REQUEST_METHOD environment vairable is "get" or "head", as no data will have been posted, or when the REQUEST_METHOD environment variable is "post" and the CONTENT_TYPE environment variable is either "application/x-www-form-urlencoded" or "multipart-form-data", as in those cases, the posted data will have been processed internally.

Implements input.

◆ read() [12/14]

ssize_t httprequest::read ( uint64_t * number)
virtual

Reads a 64-bit unsigned integer from the data posted by the client into "number". Returns the number of bytes that were successfully read or RESULT_ERROR if an error occurred.

Note that all read() methods return 0 (EOF) when the REQUEST_METHOD environment vairable is "get" or "head", as no data will have been posted, or when the REQUEST_METHOD environment variable is "post" and the CONTENT_TYPE environment variable is either "application/x-www-form-urlencoded" or "multipart-form-data", as in those cases, the posted data will have been processed internally.

Implements input.

◆ read() [13/14]

ssize_t httprequest::read ( wchar_t * buffer,
size_t length )
virtual

Reads "length" characters from the data posted by the client into "buffer". Returns the number of bytes that were successfully read or RESULT_ERROR if an error occurred.

Note that all read() methods return 0 (EOF) when the REQUEST_METHOD environment vairable is "get" or "head", as no data will have been posted, or when the REQUEST_METHOD environment variable is "post" and the CONTENT_TYPE environment variable is either "application/x-www-form-urlencoded" or "multipart-form-data", as in those cases, the posted data will have been processed internally.

Implements input.

◆ read() [14/14]

ssize_t httprequest::read ( wchar_t * character)
virtual

Reads a character from the data posted by the client into "character". Returns the number of bytes that were successfully read or RESULT_ERROR if an error occurred.

Note that all read() methods return 0 (EOF) when the REQUEST_METHOD environment vairable is "get" or "head", as no data will have been posted, or when the REQUEST_METHOD environment variable is "post" and the CONTENT_TYPE environment variable is either "application/x-www-form-urlencoded" or "multipart-form-data", as in those cases, the posted data will have been processed internally.

Implements input.

◆ readUcs2() [1/2]

ssize_t httprequest::readUcs2 ( ucs2_t * buffer,
size_t length )
virtual

Reads "length" characters from the data posted by the client into "buffer". Returns the number of bytes that were successfully read or RESULT_ERROR if an error occurred.

Note that all read() methods return 0 (EOF) when the REQUEST_METHOD environment vairable is "get" or "head", as no data will have been posted, or when the REQUEST_METHOD environment variable is "post" and the CONTENT_TYPE environment variable is either "application/x-www-form-urlencoded" or "multipart-form-data", as in those cases, the posted data will have been processed internally.

Implements input.

◆ readUcs2() [2/2]

ssize_t httprequest::readUcs2 ( ucs2_t * character)
virtual

Reads a character from the data posted by the client into "character". Returns the number of bytes that were successfully read or RESULT_ERROR if an error occurred.

Note that all read() methods return 0 (EOF) when the REQUEST_METHOD environment vairable is "get" or "head", as no data will have been posted, or when the REQUEST_METHOD environment variable is "post" and the CONTENT_TYPE environment variable is either "application/x-www-form-urlencoded" or "multipart-form-data", as in those cases, the posted data will have been processed internally.

Implements input.

◆ removeTempFiles()

void httprequest::removeTempFiles ( )

Removes all temporary files that were created when parsing the request.

◆ setCookie()

bool httprequest::setCookie ( const char * name,
const char * value )

Creates a new cookie with name "name" and value "value" or updates an existing cookie "name" to have value "value".

◆ setEnvironmentVariable()

bool httprequest::setEnvironmentVariable ( const char * name,
const char * value )

Creates a new environment variable with name "name" and value "value" or updates an existing environment variable "name" to have value "value".

◆ setFileParameter()

bool httprequest::setFileParameter ( const char * name,
const char * filename,
const char * tempfilename,
const char * mimetype )

Updates file parameter with name "name", to filename "filename", temporary filename "tempfilename" and mime-type "mimetype". If the file parameter doesn't already exist, then no action is taken.

◆ setParameter()

bool httprequest::setParameter ( const char * name,
const char * value )

Creates a new parameter with name "name" and value "value" or updates an existing parameter "name" to have value "value".

◆ writeEnvironment()

void httprequest::writeEnvironment ( )

Writes all environment variables to the browser. Similar to running "env" on the command line.

◆ writeVariables()

virtual void httprequest::writeVariables ( )
virtual

Writes all environment variables, parameters, file parameters, and cookies to the browser.

Reimplemented in urlhttprequest.