2008-12-10 05:42:49 +01:00
|
|
|
/*
|
2010-02-28 01:08:10 +01:00
|
|
|
* This file is a part of Winix
|
2008-12-10 05:42:49 +01:00
|
|
|
* and is not publicly distributed
|
|
|
|
*
|
2012-05-19 17:14:35 +02:00
|
|
|
* Copyright (c) 2008-2012, Tomasz Sowa
|
2008-12-10 05:42:49 +01:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2011-01-23 15:15:30 +01:00
|
|
|
#ifndef headerfile_winix_core_request
|
|
|
|
#define headerfile_winix_core_request
|
2008-12-10 05:42:49 +01:00
|
|
|
|
|
|
|
#include <fcgiapp.h>
|
|
|
|
#include <sstream>
|
|
|
|
#include <vector>
|
|
|
|
#include "requesttypes.h"
|
|
|
|
#include "item.h"
|
|
|
|
#include "error.h"
|
2010-08-10 18:12:50 +02:00
|
|
|
#include "config.h"
|
2010-11-21 01:19:17 +01:00
|
|
|
#include "textstream.h"
|
added: uptime winix function prints how many sessions there are
changed: functions for text/numbers conversions
int Toi(const std::string & str, int base = 10);
int Toi(const std::wstring & str, int base = 10);
int Toi(const char * str, int base = 10);
int Toi(const wchar_t * str, int base = 10);
long Tol(const std::string & str, int base = 10);
long Tol(const std::wstring & str, int base = 10);
long Tol(const char * str, int base = 10);
long Tol(const wchar_t * str, int base = 10);
template<class CharType>
bool Toa(unsigned long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(unsigned int value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(int value, CharType * buffer, size_t buf_len, int base = 10);
const wchar_t * Toa(unsigned int value, int base = 10);
const wchar_t * Toa(unsigned long value, int base = 10);
const wchar_t * Toa(int value, int base = 10);
const wchar_t * Toa(long value, int base = 10);
void Toa(int value, std::string & res, int base = 10, bool clear = true);
void Toa(long value, std::string & res, int base = 10, bool clear = true);
void Toa(int value, std::wstring & res, int base = 10, bool clear = true);
void Toa(long value, std::wstring & res, int base = 10, bool clear = true);
added: HtmlTextStream class (files htmltextstream.cpp htmltextstream.h in templates)
this is a special stream for automatically escaping html tags
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@682 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-11-25 02:34:46 +01:00
|
|
|
#include "templates/htmltextstream.h"
|
2012-05-19 17:14:35 +02:00
|
|
|
#include "date/date.h"
|
2012-08-08 18:04:48 +02:00
|
|
|
#include "space/space.h"
|
|
|
|
#include "space/spacetojson.h"
|
|
|
|
|
2009-04-21 22:50:55 +02:00
|
|
|
|
2010-06-30 20:42:50 +02:00
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
class FunctionBase;
|
|
|
|
|
|
|
|
|
2010-08-12 21:10:12 +02:00
|
|
|
|
|
|
|
|
2008-12-10 05:42:49 +01:00
|
|
|
struct Request
|
|
|
|
{
|
2008-12-30 02:05:03 +01:00
|
|
|
// request id
|
|
|
|
// is incremented for each request and is never 0
|
|
|
|
// (from -1 will be incremented twice)
|
2010-07-04 22:27:14 +02:00
|
|
|
// it's used for some optimalizations e.g. in templates
|
2008-12-30 02:05:03 +01:00
|
|
|
size_t id;
|
|
|
|
|
2010-08-12 21:10:12 +02:00
|
|
|
// !! moze pozbyc sie tego none?
|
|
|
|
enum Method { get, post, head, none } method;
|
2009-12-30 21:46:12 +01:00
|
|
|
enum Role { responder, authorizer } role;
|
2008-12-10 05:42:49 +01:00
|
|
|
|
|
|
|
// headers, page and debug
|
2010-11-21 01:19:17 +01:00
|
|
|
//std::ostringstream headers, page, debug;
|
|
|
|
TextStream<std::string> headers;
|
added: uptime winix function prints how many sessions there are
changed: functions for text/numbers conversions
int Toi(const std::string & str, int base = 10);
int Toi(const std::wstring & str, int base = 10);
int Toi(const char * str, int base = 10);
int Toi(const wchar_t * str, int base = 10);
long Tol(const std::string & str, int base = 10);
long Tol(const std::wstring & str, int base = 10);
long Tol(const char * str, int base = 10);
long Tol(const wchar_t * str, int base = 10);
template<class CharType>
bool Toa(unsigned long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(unsigned int value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(int value, CharType * buffer, size_t buf_len, int base = 10);
const wchar_t * Toa(unsigned int value, int base = 10);
const wchar_t * Toa(unsigned long value, int base = 10);
const wchar_t * Toa(int value, int base = 10);
const wchar_t * Toa(long value, int base = 10);
void Toa(int value, std::string & res, int base = 10, bool clear = true);
void Toa(long value, std::string & res, int base = 10, bool clear = true);
void Toa(int value, std::wstring & res, int base = 10, bool clear = true);
void Toa(long value, std::wstring & res, int base = 10, bool clear = true);
added: HtmlTextStream class (files htmltextstream.cpp htmltextstream.h in templates)
this is a special stream for automatically escaping html tags
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@682 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-11-25 02:34:46 +01:00
|
|
|
HtmlTextStream page, debug;
|
2012-08-08 18:04:48 +02:00
|
|
|
TextStream<std::wstring> ajaxpage;
|
2008-12-10 05:42:49 +01:00
|
|
|
|
2012-09-11 07:19:45 +02:00
|
|
|
// binary page
|
|
|
|
BinaryPage binary_page;
|
|
|
|
|
|
|
|
// a compressed page ready to send to the client
|
|
|
|
BinaryPage compressed_page;
|
|
|
|
|
|
|
|
// if true then either page or ajaxpage will be sent to the client
|
|
|
|
// if false then binary_page is sent
|
|
|
|
// default: true
|
|
|
|
bool use_text_page;
|
|
|
|
|
2011-06-24 22:53:21 +02:00
|
|
|
// if set to true then the standard template system will not be generated
|
|
|
|
// default: false
|
|
|
|
bool page_generated;
|
|
|
|
|
|
|
|
// whether or not the html filter should be used
|
|
|
|
// default: true
|
|
|
|
bool use_html_filter;
|
|
|
|
|
2010-08-10 22:43:38 +02:00
|
|
|
// raw parameters
|
|
|
|
PostTab post_tab;
|
|
|
|
PostFileTab post_file_tab;
|
|
|
|
CookieTab cookie_tab;
|
2008-12-10 05:42:49 +01:00
|
|
|
|
2011-07-29 00:18:10 +02:00
|
|
|
// html anchor (those part of URI after '#' character)
|
|
|
|
std::wstring anchor;
|
|
|
|
|
2008-12-12 04:11:29 +01:00
|
|
|
// environment variables
|
2009-11-17 02:04:01 +01:00
|
|
|
// they are not null -- when the server doesn't have such a variable
|
|
|
|
// it will be pointing into 'char_empty' which is default '\0'
|
2008-12-10 05:42:49 +01:00
|
|
|
const char * env_request_method;
|
|
|
|
const char * env_request_uri;
|
|
|
|
const char * env_http_cookie;
|
2008-12-11 03:46:16 +01:00
|
|
|
const char * env_remote_addr;
|
2008-12-12 04:11:29 +01:00
|
|
|
const char * env_http_host;
|
2008-12-30 02:05:03 +01:00
|
|
|
const char * env_http_user_agent;
|
2009-10-08 19:59:10 +02:00
|
|
|
const char * env_http_accept_encoding;
|
2009-12-30 21:46:12 +01:00
|
|
|
const char * env_fcgi_role;
|
2010-01-06 20:17:53 +01:00
|
|
|
const char * env_content_type;
|
2011-09-07 00:46:15 +02:00
|
|
|
const char * env_https;
|
2009-10-08 19:59:10 +02:00
|
|
|
|
2012-10-27 09:44:26 +02:00
|
|
|
// current IP address of the remote host (read from REMOTE_ADDR environment variable)
|
|
|
|
// (at the moment only IPv4 are supported)
|
|
|
|
int ip;
|
|
|
|
|
2009-10-08 19:59:10 +02:00
|
|
|
// true if the browser is Microsoft Internet Explorer
|
|
|
|
bool browser_msie;
|
|
|
|
|
2009-12-19 20:46:15 +01:00
|
|
|
// true if the browser is Konqueror
|
|
|
|
bool browser_konqueror;
|
|
|
|
|
2011-09-07 00:46:15 +02:00
|
|
|
// true if we are using encrypted connection (SSL)
|
|
|
|
bool using_ssl;
|
|
|
|
|
2008-12-30 02:05:03 +01:00
|
|
|
// current directory
|
2010-08-10 22:43:38 +02:00
|
|
|
std::vector<Item*> dir_tab;
|
2008-12-10 05:42:49 +01:00
|
|
|
|
2010-08-10 22:43:38 +02:00
|
|
|
// true if a file exists
|
2008-12-30 02:05:03 +01:00
|
|
|
bool is_item;
|
|
|
|
|
2010-08-10 22:43:38 +02:00
|
|
|
// current file (if exists)
|
2008-12-30 02:05:03 +01:00
|
|
|
Item item;
|
|
|
|
|
2010-08-12 21:10:12 +02:00
|
|
|
// current winix function
|
2008-12-30 02:05:03 +01:00
|
|
|
// null if there is no a function
|
2010-08-10 22:43:38 +02:00
|
|
|
FunctionBase * function;
|
2008-12-30 02:05:03 +01:00
|
|
|
|
2010-07-04 22:27:14 +02:00
|
|
|
// parameters (name:value)
|
2010-08-10 22:43:38 +02:00
|
|
|
ParamTab param_tab;
|
|
|
|
|
|
|
|
// request status
|
2008-12-30 02:05:03 +01:00
|
|
|
Error status;
|
|
|
|
|
2010-08-10 22:43:38 +02:00
|
|
|
// usually items in the current directory (depends on the function)
|
|
|
|
std::vector<Item> item_tab;
|
2010-01-25 05:52:17 +01:00
|
|
|
|
2009-11-17 02:04:01 +01:00
|
|
|
// if not empty means an address for redirecting to
|
2012-02-19 01:59:08 +01:00
|
|
|
// it should be url-encoded
|
2010-11-21 01:19:17 +01:00
|
|
|
std::wstring redirect_to;
|
|
|
|
std::string aredirect_to;
|
2008-12-10 05:42:49 +01:00
|
|
|
|
2011-07-07 19:02:14 +02:00
|
|
|
// a redirect type
|
|
|
|
// following redirect types are supported:
|
|
|
|
// 300 Multiple Choices
|
|
|
|
// 301 Moved Permanently
|
|
|
|
// 302 Found
|
|
|
|
// 303 See Other (default)
|
|
|
|
// 307 Temporary Redirect
|
|
|
|
int redirect_type;
|
|
|
|
|
2010-02-19 00:30:22 +01:00
|
|
|
// send header X-LIGHTTPD-send-file with path to a file
|
2010-11-21 01:19:17 +01:00
|
|
|
std::wstring x_sendfile;
|
2010-02-19 00:30:22 +01:00
|
|
|
|
2012-08-08 18:04:48 +02:00
|
|
|
// send as attachment (causes header: content-disposition: attachment)
|
2010-02-19 00:30:22 +01:00
|
|
|
bool send_as_attachment;
|
|
|
|
|
2010-08-14 16:45:25 +02:00
|
|
|
// this is a pointer either to the item (if exists) or to the last directory
|
|
|
|
Item * last_item;
|
2010-08-12 21:10:12 +02:00
|
|
|
|
2012-02-17 06:19:24 +01:00
|
|
|
// request start time
|
|
|
|
// Time() methods are very slow so it is better to directly use those two values
|
|
|
|
// they are set when a request starts
|
2012-05-24 23:09:37 +02:00
|
|
|
time_t start_time;
|
2012-05-19 17:14:35 +02:00
|
|
|
PT::Date start_date;
|
|
|
|
|
2012-04-22 20:23:44 +02:00
|
|
|
// a subdomain
|
|
|
|
// subdomain = HTTP_HOST environment variable - config->base_url
|
|
|
|
std::wstring subdomain;
|
|
|
|
|
2012-08-08 18:04:48 +02:00
|
|
|
// used as a JSON output (when ajax_serializer is defined)
|
|
|
|
// it will be serialized and have at least:
|
|
|
|
// 'content' string - the whole html content
|
|
|
|
// 'http_status' integer - http status code (e.g. 200)
|
|
|
|
PT::Space ajax;
|
|
|
|
|
|
|
|
// if not null then the request will have a JSON as an output
|
|
|
|
PT::SpaceToJSON * ajax_serializer;
|
2010-08-12 21:10:12 +02:00
|
|
|
|
2012-08-26 21:53:47 +02:00
|
|
|
// options used by ezc generators
|
|
|
|
bool gen_trim_white;
|
|
|
|
bool gen_skip_new_line;
|
|
|
|
bool gen_use_special_chars;
|
|
|
|
|
2012-04-22 15:30:07 +02:00
|
|
|
|
2010-08-12 21:10:12 +02:00
|
|
|
Request();
|
|
|
|
void SetConfig(Config * pconfig);
|
2012-02-17 06:19:24 +01:00
|
|
|
void RequestStarts();
|
2010-08-12 21:10:12 +02:00
|
|
|
void Clear();
|
|
|
|
|
2008-12-10 05:42:49 +01:00
|
|
|
|
|
|
|
|
2010-11-21 01:19:17 +01:00
|
|
|
bool IsParam(const wchar_t * param_name);
|
|
|
|
bool IsParam(const std::wstring & param_name);
|
2011-11-25 05:51:55 +01:00
|
|
|
|
|
|
|
const std::wstring & ParamValue(const wchar_t * param_name); // returns an empty string if there is no such a parameter
|
|
|
|
const std::wstring & ParamValue(const std::wstring & param_name); // returns an empty string if there is no such a parameter
|
2008-12-30 02:05:03 +01:00
|
|
|
|
2012-05-27 01:04:49 +02:00
|
|
|
void SetCookie(const char * name, const char * value, PT::Date * expires = 0);
|
|
|
|
void SetCookie(const char * name, long value, PT::Date * expires = 0);
|
2008-12-10 05:42:49 +01:00
|
|
|
|
2010-11-21 01:19:17 +01:00
|
|
|
bool IsPostVar(const wchar_t * var);
|
2011-11-25 05:51:55 +01:00
|
|
|
bool IsPostVar(const std::wstring & var);
|
|
|
|
|
|
|
|
const std::wstring & PostVar(const wchar_t * var); // returns an empty string if there is no such a parameter
|
|
|
|
const std::wstring & PostVar(const std::wstring & var); // returns an empty string if there is no such a parameter
|
|
|
|
|
|
|
|
|
2010-11-21 01:19:17 +01:00
|
|
|
bool PostVar(const wchar_t * var, std::wstring & result);
|
2011-11-25 05:51:55 +01:00
|
|
|
bool PostVar(const std::wstring & var, std::wstring & result);
|
|
|
|
|
2010-11-21 01:19:17 +01:00
|
|
|
std::wstring * PostVarp(const wchar_t * var);
|
2012-06-04 19:51:43 +02:00
|
|
|
std::wstring * PostVarp(const std::wstring & var);
|
2010-09-30 22:58:20 +02:00
|
|
|
|
2009-12-09 01:42:40 +01:00
|
|
|
bool AllPostVarEmpty(); // returning true if all post vars are empty
|
2008-12-10 05:42:49 +01:00
|
|
|
|
|
|
|
void SendAll();
|
2010-08-12 21:10:12 +02:00
|
|
|
|
2010-01-06 20:17:53 +01:00
|
|
|
|
2008-12-12 04:11:29 +01:00
|
|
|
private:
|
2009-10-08 19:59:10 +02:00
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
Config * config;
|
|
|
|
|
2010-08-12 21:10:12 +02:00
|
|
|
// contains '\0'
|
|
|
|
// used to set env_* pointers to the empty value
|
2008-12-12 04:11:29 +01:00
|
|
|
const char char_empty;
|
2009-11-17 00:36:38 +01:00
|
|
|
|
2010-08-12 21:10:12 +02:00
|
|
|
// used in ParamValue() and PostVar() when there is no such a param
|
2010-11-21 01:19:17 +01:00
|
|
|
const std::wstring str_empty;
|
2012-08-08 18:04:48 +02:00
|
|
|
|
|
|
|
void ClearAjax();
|
|
|
|
|
2008-12-10 05:42:49 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
|
2008-12-10 05:42:49 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|