2008-12-10 05:42:49 +01:00
|
|
|
/*
|
2010-02-28 01:08:10 +01:00
|
|
|
* This file is a part of Winix
|
2014-10-04 20:04:03 +02:00
|
|
|
* and is distributed under the 2-Clause BSD licence.
|
|
|
|
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2022-02-02 18:34:22 +01:00
|
|
|
* Copyright (c) 2008-2022, Tomasz Sowa
|
2008-12-10 05:42:49 +01:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
2014-10-04 20:04:03 +02:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
2008-12-10 05:42:49 +01:00
|
|
|
*/
|
|
|
|
|
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"
|
2021-02-24 01:19:47 +01:00
|
|
|
#include "models/item.h"
|
2008-12-10 05:42:49 +01:00
|
|
|
#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"
|
2013-11-29 22:39:23 +01:00
|
|
|
#include "textstream/textstream.h"
|
2015-11-15 23:23:36 +01:00
|
|
|
#include "outstreams.h"
|
2021-06-16 18:07:44 +02:00
|
|
|
#include "models.h"
|
2021-06-17 21:44:29 +02:00
|
|
|
#include "models/winixmodel.h"
|
2021-09-22 00:23:25 +02:00
|
|
|
#include "header.h"
|
2022-07-25 14:21:21 +02:00
|
|
|
#include "compress.h"
|
|
|
|
#include "plugin.h"
|
|
|
|
#include "mount.h"
|
|
|
|
#include "mounts.h"
|
2022-08-20 00:31:10 +02:00
|
|
|
#include "jobtask.h"
|
2022-07-25 14:21:21 +02:00
|
|
|
|
2021-06-17 21:44:29 +02:00
|
|
|
|
2009-04-21 22:50:55 +02:00
|
|
|
|
2014-02-12 17:30:49 +01:00
|
|
|
namespace Winix
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-06-30 20:42:50 +02:00
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
class FunctionBase;
|
2022-07-25 14:21:21 +02:00
|
|
|
class Templates;
|
2010-08-10 18:12:50 +02:00
|
|
|
|
2010-08-12 21:10:12 +02:00
|
|
|
|
|
|
|
|
2021-06-18 19:18:13 +02:00
|
|
|
class Request : public WinixModel
|
2008-12-10 05:42:49 +01:00
|
|
|
{
|
2021-06-18 19:18:13 +02:00
|
|
|
public:
|
|
|
|
|
|
|
|
|
2018-04-25 21:48:47 +02:00
|
|
|
// how many input headers can be put to in_headers struct
|
|
|
|
static const size_t MAX_INPUT_HEADERS = 32;
|
|
|
|
|
|
|
|
// how many characters there can be in one header name
|
|
|
|
static const size_t INPUT_HEADER_NAME_MAX_LENGTH = 64;
|
|
|
|
|
|
|
|
// how many characters there can be in one header value
|
|
|
|
static const size_t INPUT_HEADER_VALUE_MAX_LENGTH = 8192;
|
|
|
|
|
|
|
|
|
2013-11-29 22:39:23 +01:00
|
|
|
/*
|
|
|
|
request id
|
|
|
|
is incremented for each request and is never 0
|
|
|
|
(from -1 will be incremented to one)
|
|
|
|
it's used for some optimizations e.g. in templates
|
|
|
|
*/
|
2008-12-30 02:05:03 +01:00
|
|
|
size_t id;
|
|
|
|
|
2022-07-25 14:21:21 +02:00
|
|
|
// the state of the request
|
|
|
|
// not_assigned - the object is not being used
|
|
|
|
// normal_run - run in the main thread, this state is set after a new request is made
|
|
|
|
// assigned_to_job - the request is preserved and a new job will be called
|
|
|
|
// job_run - run in the job thread (objects are locked)
|
|
|
|
// finished - the request is finished and the object can be removed
|
2022-07-25 18:37:39 +02:00
|
|
|
enum RunState { not_assigned = 0, normal_run, assigned_to_job, job_run, job_continuation_run, prepare_to_finish, finished};
|
2022-07-25 14:21:21 +02:00
|
|
|
|
|
|
|
RunState run_state;
|
2008-12-10 05:42:49 +01:00
|
|
|
|
2013-11-29 22:39:23 +01:00
|
|
|
/*
|
2021-06-24 15:33:44 +02:00
|
|
|
* request start time
|
|
|
|
*
|
|
|
|
* start_time is the same as timespec_req_start.tv_sec
|
|
|
|
* start_date is a pt::Date converted from start_time
|
|
|
|
*
|
2013-11-29 22:39:23 +01:00
|
|
|
*/
|
2021-06-24 15:33:44 +02:00
|
|
|
timespec timespec_req_start;
|
2013-11-29 22:39:23 +01:00
|
|
|
time_t start_time;
|
2021-05-20 20:59:12 +02:00
|
|
|
pt::Date start_date;
|
2013-11-29 22:39:23 +01:00
|
|
|
|
|
|
|
|
2021-06-24 15:33:44 +02:00
|
|
|
/*
|
|
|
|
* request stop time
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
timespec timespec_req_stop;
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* request stop time - start time
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
timespec timespec_req_diff;
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* start time of the ezc engine (html templates)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
timespec timespec_ezc_engine_start;
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* end time of the ezc engine (html templates)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
timespec timespec_ezc_engine_stop;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-11-29 22:39:23 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* variables representing input from client's browser
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
the HTTP method
|
|
|
|
!! IMPROVE ME add the rest methods here
|
|
|
|
*/
|
2022-08-11 08:04:40 +02:00
|
|
|
enum Method { get, post, head, delete_, options, unknown_method } method;
|
2013-11-29 22:39:23 +01:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
subdomain
|
|
|
|
subdomain = HTTP_HOST environment variable - config->base_url
|
|
|
|
*/
|
|
|
|
std::wstring subdomain;
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
raw parameters
|
2021-05-20 20:59:12 +02:00
|
|
|
!! CHECK ME may post_tab and cookie_tab should be changed to pt::Space now?
|
2013-11-29 22:39:23 +01:00
|
|
|
or may change the name to cookie_in? or in_cookie?
|
|
|
|
*/
|
|
|
|
PostFileTab post_file_tab;
|
|
|
|
CookieTab cookie_tab;
|
2021-05-20 20:59:12 +02:00
|
|
|
pt::Space post_in;
|
2013-11-29 22:39:23 +01:00
|
|
|
|
2018-04-25 21:48:47 +02:00
|
|
|
// input headers (without cookies)
|
|
|
|
// at the moment we are using FastCGI and HTTP headers are prefixed with 'HTTP_' string
|
|
|
|
// so we drop the prefix and change all characters to small ones
|
|
|
|
|
|
|
|
// although https://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2 says that there can be more
|
|
|
|
// than one http header with the same name we do not support it
|
|
|
|
// each header has a different name here, cookies we have in a different container (cookie_tab)
|
2021-05-20 20:59:12 +02:00
|
|
|
pt::Space headers_in;
|
2018-04-25 21:48:47 +02:00
|
|
|
|
2013-11-29 22:39:23 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
html anchor (those part of URI after '#' character)
|
|
|
|
*/
|
|
|
|
std::wstring anchor;
|
|
|
|
|
|
|
|
|
|
|
|
// environment variables
|
2014-10-09 22:44:56 +02:00
|
|
|
std::wstring env_request_method;
|
|
|
|
std::wstring env_request_uri;
|
|
|
|
std::wstring env_http_cookie;
|
|
|
|
std::wstring env_http_host;
|
|
|
|
std::wstring env_http_user_agent;
|
|
|
|
std::wstring env_http_accept_encoding;
|
2022-02-01 18:44:23 +01:00
|
|
|
std::wstring env_http_accept;
|
2022-02-02 18:20:32 +01:00
|
|
|
std::wstring env_http_accept_language;
|
2014-10-09 22:44:56 +02:00
|
|
|
std::wstring env_fcgi_role;
|
|
|
|
std::wstring env_content_type;
|
|
|
|
std::wstring env_https;
|
2008-12-10 05:42:49 +01:00
|
|
|
|
2018-05-01 13:22:55 +02:00
|
|
|
// current IP address of the remote host
|
|
|
|
// (read either from REMOTE_ADDR environment variable or from config.proxy_ip_header HTTP variable if config.check_proxy_ip_header is set to true)
|
2013-11-29 22:39:23 +01:00
|
|
|
// (at the moment only IPv4 are supported)
|
|
|
|
int ip;
|
2018-05-01 13:22:55 +02:00
|
|
|
std::wstring ip_str; // ip_str can be ipv6 now
|
|
|
|
|
2013-11-29 22:39:23 +01:00
|
|
|
|
|
|
|
// true if the browser is Microsoft Internet Explorer
|
|
|
|
bool browser_msie;
|
|
|
|
|
|
|
|
// true if the browser is Konqueror
|
|
|
|
bool browser_konqueror;
|
|
|
|
|
|
|
|
// true if we are using an encrypted connection (SSL)
|
|
|
|
bool using_ssl;
|
|
|
|
|
2021-05-31 10:58:34 +02:00
|
|
|
// true if the request is being made by ajax by htmx library
|
|
|
|
bool is_htmx_request;
|
2013-11-29 22:39:23 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
request input variables representing the winix filesystem
|
|
|
|
*/
|
|
|
|
|
|
|
|
// current directory
|
|
|
|
std::vector<Item*> dir_tab;
|
|
|
|
|
|
|
|
// true if a file exists
|
|
|
|
bool is_item;
|
|
|
|
|
|
|
|
// current file (valid if is_item is true)
|
|
|
|
Item item;
|
|
|
|
|
|
|
|
// current winix function
|
|
|
|
// null if there is no a function
|
|
|
|
FunctionBase * function;
|
|
|
|
|
2022-07-25 14:21:21 +02:00
|
|
|
// current session (if exists, can be null)
|
|
|
|
Session * session;
|
|
|
|
|
|
|
|
// current mount point (can be null, it is treated as cms filesystem then)
|
|
|
|
Mount * mount;
|
|
|
|
|
2013-11-29 22:39:23 +01:00
|
|
|
// parameters (name:value)
|
|
|
|
ParamTab param_tab;
|
|
|
|
|
|
|
|
// this is a pointer either to the item (if exists) or to the last directory
|
|
|
|
Item * last_item;
|
|
|
|
|
2022-07-25 14:21:21 +02:00
|
|
|
// can we use gzip compression algorithm when sending content to the client
|
|
|
|
bool accept_gzip;
|
2013-11-29 22:39:23 +01:00
|
|
|
|
2022-07-25 14:21:21 +02:00
|
|
|
// can we use deflate compression algorithm when sending content to the client
|
|
|
|
bool accept_deflate;
|
2013-11-29 22:39:23 +01:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* variables for generating output to the client's browser
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2021-10-13 01:27:14 +02:00
|
|
|
//
|
2022-02-01 18:44:23 +01:00
|
|
|
// the algorithm how a request's container is selected is shown below:
|
|
|
|
// (the whole answer's algorightm is implemented in PrepareAnswerType() method)
|
|
|
|
// ------------------------------------------------------------------------------------------
|
2021-10-13 01:27:14 +02:00
|
|
|
//
|
2022-02-01 18:44:23 +01:00
|
|
|
// at the beginning we set container_type to "raw" meaning simple text or html, then
|
|
|
|
// we check the "Accept" http header, if it is set then we set container_type accordingly:
|
2021-10-13 01:27:14 +02:00
|
|
|
//
|
2022-02-01 18:44:23 +01:00
|
|
|
// Accept | container_type
|
|
|
|
// -----------------------------------------------
|
|
|
|
// text/html | container_raw
|
|
|
|
// application/xhtml+xml | container_raw
|
|
|
|
// application/json | container_json
|
|
|
|
// application/xml | container_xml
|
|
|
|
// text/csv | container_csv
|
2021-10-13 01:27:14 +02:00
|
|
|
//
|
2022-02-01 18:44:23 +01:00
|
|
|
// next we check "container" url parameter, if it is set then we set container_type accordingly
|
|
|
|
// ("container" url parameter has higher precedence than "Accept" http header):
|
2021-10-13 01:27:14 +02:00
|
|
|
//
|
2022-02-01 18:44:23 +01:00
|
|
|
// container | container_type
|
|
|
|
// -----------------------------------------------
|
|
|
|
// raw | container_raw
|
|
|
|
// json | container_json
|
|
|
|
// xml | container_xml
|
|
|
|
// csv | container_csv
|
2021-10-13 01:27:14 +02:00
|
|
|
//
|
|
|
|
//
|
2022-02-01 18:44:23 +01:00
|
|
|
// Samples:
|
2021-10-13 01:27:14 +02:00
|
|
|
//
|
2022-02-01 18:44:23 +01:00
|
|
|
// http://domain.tld/dir/controller
|
|
|
|
// returns html answer from the main ezc stream
|
2021-10-13 01:27:14 +02:00
|
|
|
//
|
2022-02-01 18:44:23 +01:00
|
|
|
// http://domain.tld/dir/controller/container:raw
|
|
|
|
// returns html answer from the main ezc stream (the same as above)
|
2021-10-13 01:27:14 +02:00
|
|
|
//
|
2022-02-01 18:44:23 +01:00
|
|
|
// http://domain.tld/dir/controller/frame:abc
|
|
|
|
// returns "abc" frame as html
|
2021-10-13 01:27:14 +02:00
|
|
|
//
|
2022-02-01 18:44:23 +01:00
|
|
|
// http://domain.tld/dir/controller/container:json
|
|
|
|
// returns all serialized models to json and no ezc streams
|
2021-10-13 01:27:14 +02:00
|
|
|
//
|
2022-02-01 18:44:23 +01:00
|
|
|
// http://domain.tld/dir/controller/container:xml
|
|
|
|
// returns all serialized models to xml and no ezc streams
|
2021-10-13 01:27:14 +02:00
|
|
|
//
|
2022-02-01 18:44:23 +01:00
|
|
|
// http://domain.tld/dir/controller/container:json/frame:abc,xyz
|
|
|
|
// returns all serialized models to json and two frames in 'ezc_frames' object
|
2021-10-13 01:27:14 +02:00
|
|
|
//
|
2022-02-01 18:44:23 +01:00
|
|
|
// http://domain.tld/dir/controller/container:json/all_frames
|
|
|
|
// returns all serialized models to json and all frames in 'ezc_frames' object
|
2021-10-13 01:27:14 +02:00
|
|
|
//
|
2022-02-01 18:44:23 +01:00
|
|
|
// http://domain.tld/dir/controller/container:json/main_stream
|
|
|
|
// returns all serialized models and the main ezc stream in 'main_stream' field
|
2021-10-13 01:27:14 +02:00
|
|
|
//
|
2022-02-01 18:44:23 +01:00
|
|
|
// http://domain.tld/dir/controller/container:json/main_stream/all_frames
|
|
|
|
// returns all serialized models to json, all frames and the main stream
|
2021-10-13 01:27:14 +02:00
|
|
|
//
|
2022-02-01 18:44:23 +01:00
|
|
|
|
|
|
|
|
|
|
|
bool send_bin_stream;
|
|
|
|
bool send_main_stream;
|
|
|
|
bool send_all_frames;
|
|
|
|
std::vector<std::wstring> send_frames;
|
|
|
|
|
|
|
|
bool use_ezc_engine;
|
|
|
|
bool serialize_models;
|
2021-10-13 01:27:14 +02:00
|
|
|
|
|
|
|
|
|
|
|
// change maybe answer_text -> container_text?
|
2022-02-01 18:44:23 +01:00
|
|
|
enum ContainerType
|
2021-10-13 01:27:14 +02:00
|
|
|
{
|
2022-02-01 18:44:23 +01:00
|
|
|
container_raw,
|
|
|
|
container_json,
|
|
|
|
container_xml,
|
|
|
|
container_csv,
|
2021-10-13 01:27:14 +02:00
|
|
|
};
|
|
|
|
|
2022-02-01 18:44:23 +01:00
|
|
|
ContainerType container_type;
|
2021-10-13 01:27:14 +02:00
|
|
|
|
|
|
|
|
2022-02-01 18:44:23 +01:00
|
|
|
// at the beginning those with higher priority
|
|
|
|
std::vector<HeaderValue> accept_mime_types;
|
2021-10-13 01:27:14 +02:00
|
|
|
|
2022-02-02 18:20:32 +01:00
|
|
|
// at the beginning those with higher priority
|
|
|
|
std::vector<HeaderValue> accept_languages;
|
2013-11-29 22:39:23 +01:00
|
|
|
|
|
|
|
// request status
|
remove Request::post_tab and add Request::http_status
Instead of Reqest::post_tab we use now Request::post_in (pt::Space).
Request::http_status will be used instead Request::status,
but at the moment is not changed in all places.
Request::status has been marked as depracated.
While here:
- Check for root dir in App and not in FunctionParser,
let FunctionParser only log the root dir.
- Read post variables after parsing url parameters,
this allows winix functions to set limits
for post input.
- Set limits when parsing input json format, new
options added to config: post_max_object_items, post_max_table_items,
post_max_all_items, post_max_nested_objects.
There are similar options in each winix function (they are in
FunctionBase).
- Some refactoring in App.
- Add config option: log_whole_http_post if true
then the whole parsed post input is logged.
- Add config option: post_json_max - max length of input stream
for parsing json.
- Add config option: templates_request_status, default request_status.html
this is an ezc template used as [content] when the request status
is not 200_ok.
- Fix: Sort winix function didn't show items to sort (fix and do some
refactoring as well)
- Properly sort items in: ImgCrop, Ls, Sort, Upload
- Remove ezc templates: err_404.html, err_per_denied.html - now
request_status.html is used.
2022-05-30 01:29:18 +02:00
|
|
|
// DEPRECATED, use http_status instead
|
2013-11-29 22:39:23 +01:00
|
|
|
Error status;
|
|
|
|
|
remove Request::post_tab and add Request::http_status
Instead of Reqest::post_tab we use now Request::post_in (pt::Space).
Request::http_status will be used instead Request::status,
but at the moment is not changed in all places.
Request::status has been marked as depracated.
While here:
- Check for root dir in App and not in FunctionParser,
let FunctionParser only log the root dir.
- Read post variables after parsing url parameters,
this allows winix functions to set limits
for post input.
- Set limits when parsing input json format, new
options added to config: post_max_object_items, post_max_table_items,
post_max_all_items, post_max_nested_objects.
There are similar options in each winix function (they are in
FunctionBase).
- Some refactoring in App.
- Add config option: log_whole_http_post if true
then the whole parsed post input is logged.
- Add config option: post_json_max - max length of input stream
for parsing json.
- Add config option: templates_request_status, default request_status.html
this is an ezc template used as [content] when the request status
is not 200_ok.
- Fix: Sort winix function didn't show items to sort (fix and do some
refactoring as well)
- Properly sort items in: ImgCrop, Ls, Sort, Upload
- Remove ezc templates: err_404.html, err_per_denied.html - now
request_status.html is used.
2022-05-30 01:29:18 +02:00
|
|
|
/*
|
|
|
|
* HTTP result status
|
|
|
|
* at the moment default is -1 which means it is not used (use status in such a case)
|
|
|
|
*/
|
|
|
|
int http_status;
|
|
|
|
|
2013-11-29 22:39:23 +01:00
|
|
|
// if not empty means an address for redirecting to
|
|
|
|
// it should be url-encoded
|
|
|
|
std::wstring redirect_to;
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
// send header X-LIGHTTPD-send-file with path to a file
|
|
|
|
std::wstring x_sendfile;
|
|
|
|
|
|
|
|
// send as attachment (causes generating header: content-disposition: attachment)
|
|
|
|
bool send_as_attachment;
|
|
|
|
|
2018-04-25 21:48:47 +02:00
|
|
|
// headers send to the client (without cookies) (may change to headers_out?)
|
2021-05-20 20:59:12 +02:00
|
|
|
pt::Space out_headers;
|
2013-11-29 22:39:23 +01:00
|
|
|
|
|
|
|
// cookies send to the client
|
|
|
|
// a value can be either a cookie value or the whole cookie string (with domain, date etc)
|
2021-05-20 20:59:12 +02:00
|
|
|
pt::Space out_cookies;
|
2012-09-11 07:19:45 +02:00
|
|
|
|
2013-11-14 21:59:23 +01:00
|
|
|
|
2021-10-13 01:27:14 +02:00
|
|
|
// binary page sent to the client if answer_source is answer_bin_stream
|
2013-11-14 21:59:23 +01:00
|
|
|
BinaryPage out_bin_stream;
|
|
|
|
|
2015-11-15 23:23:36 +01:00
|
|
|
// main text output stream where the html otput is generated from ezc templates
|
|
|
|
// here the whole html page (with doctype, head, body) is generated
|
|
|
|
HtmlTextStream out_main_stream;
|
|
|
|
|
2021-10-13 01:27:14 +02:00
|
|
|
// text output streams used in ajax requests
|
2021-07-13 01:46:07 +02:00
|
|
|
// in ezc templates you can use [ezc frame "stream_name"] or just [frame "stream_name"] keyword
|
2015-11-15 23:23:36 +01:00
|
|
|
// to switch between streams
|
2021-07-13 01:46:07 +02:00
|
|
|
Ezc::OutStreams<HtmlTextStream, true> out_streams;
|
2013-11-14 21:59:23 +01:00
|
|
|
|
2021-06-16 18:07:44 +02:00
|
|
|
// models to return or to render through ezc library
|
|
|
|
Ezc::Models models;
|
2012-09-11 07:19:45 +02:00
|
|
|
|
2021-10-13 01:27:14 +02:00
|
|
|
// filter html content with HTMLFilter, default the same as config.html_filter
|
|
|
|
bool use_html_filter;
|
2015-11-15 23:23:36 +01:00
|
|
|
|
2013-11-29 22:39:23 +01:00
|
|
|
// if this variable is true then winix always return 200 OK header
|
|
|
|
// when the status would be 404 (not found) or 403 (permission denied)
|
|
|
|
// default: false
|
|
|
|
bool use_200_status_for_not_found_and_permission_denied;
|
2012-10-27 09:44:26 +02:00
|
|
|
|
2013-11-29 22:39:23 +01:00
|
|
|
// options used by ezc generators
|
|
|
|
bool gen_trim_white;
|
|
|
|
bool gen_skip_new_line;
|
|
|
|
bool gen_use_special_chars;
|
2009-12-19 20:46:15 +01:00
|
|
|
|
2021-01-27 18:31:48 +01:00
|
|
|
// index template name
|
|
|
|
std::wstring html_template;
|
2008-12-10 05:42:49 +01:00
|
|
|
|
2008-12-30 02:05:03 +01:00
|
|
|
|
2013-11-29 22:39:23 +01:00
|
|
|
/*
|
|
|
|
additional variables used for common uses
|
|
|
|
*/
|
2010-08-10 22:43:38 +02:00
|
|
|
|
2021-10-13 01:27:14 +02:00
|
|
|
// DEPRECATED will be removed
|
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
|
|
|
|
2008-12-10 05:42:49 +01:00
|
|
|
|
2022-07-25 14:21:21 +02:00
|
|
|
/*
|
|
|
|
* FastCGI request structure with pointers to input/output streams
|
|
|
|
*/
|
|
|
|
FCGX_Request fcgi_request;
|
2011-07-07 19:02:14 +02:00
|
|
|
|
2010-02-19 00:30:22 +01:00
|
|
|
|
2022-08-20 00:31:10 +02:00
|
|
|
long job_id; // the main id of your job
|
|
|
|
long job_second_id; // a secondary id of your job
|
2022-07-25 14:21:21 +02:00
|
|
|
pt::Space job;
|
2012-04-22 20:23:44 +02:00
|
|
|
|
2012-08-26 21:53:47 +02:00
|
|
|
|
2012-04-22 15:30:07 +02:00
|
|
|
|
2010-08-12 21:10:12 +02:00
|
|
|
Request();
|
2022-07-25 14:21:21 +02:00
|
|
|
|
|
|
|
void SetConfig(Config * config);
|
|
|
|
void SetTemplates(Templates * templates);
|
|
|
|
void SetCompress(Compress * compress);
|
|
|
|
void SetPlugin(Plugin * plugin);
|
|
|
|
void SetMounts(Mounts * mounts);
|
2013-12-23 04:29:33 +01:00
|
|
|
|
2021-06-17 21:44:29 +02:00
|
|
|
|
|
|
|
void fields();
|
|
|
|
|
|
|
|
|
2012-02-17 06:19:24 +01:00
|
|
|
void RequestStarts();
|
2021-06-24 15:33:44 +02:00
|
|
|
void RequestEnds();
|
2010-08-12 21:10:12 +02:00
|
|
|
void Clear();
|
|
|
|
|
2022-02-01 18:44:23 +01:00
|
|
|
void PrepareAnswerType();
|
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
|
|
|
|
2018-04-22 23:26:56 +02:00
|
|
|
std::wstring * ParamValuep(const wchar_t * param_name); // returns nullptr if there is no such a parameter
|
|
|
|
std::wstring * ParamValuep(const std::wstring & param_name); // returns nullptr if there is no such a parameter
|
|
|
|
|
2022-04-26 23:41:56 +02:00
|
|
|
void AddParam(const std::wstring & param_name, const std::wstring & param_value);
|
|
|
|
void AddParam(const wchar_t * param_name, const wchar_t * param_value);
|
|
|
|
|
|
|
|
void RemoveParam(const wchar_t * param_name);
|
|
|
|
void RemoveParam(const std::wstring & param_name);
|
|
|
|
|
remove Request::post_tab and add Request::http_status
Instead of Reqest::post_tab we use now Request::post_in (pt::Space).
Request::http_status will be used instead Request::status,
but at the moment is not changed in all places.
Request::status has been marked as depracated.
While here:
- Check for root dir in App and not in FunctionParser,
let FunctionParser only log the root dir.
- Read post variables after parsing url parameters,
this allows winix functions to set limits
for post input.
- Set limits when parsing input json format, new
options added to config: post_max_object_items, post_max_table_items,
post_max_all_items, post_max_nested_objects.
There are similar options in each winix function (they are in
FunctionBase).
- Some refactoring in App.
- Add config option: log_whole_http_post if true
then the whole parsed post input is logged.
- Add config option: post_json_max - max length of input stream
for parsing json.
- Add config option: templates_request_status, default request_status.html
this is an ezc template used as [content] when the request status
is not 200_ok.
- Fix: Sort winix function didn't show items to sort (fix and do some
refactoring as well)
- Properly sort items in: ImgCrop, Ls, Sort, Upload
- Remove ezc templates: err_404.html, err_per_denied.html - now
request_status.html is used.
2022-05-30 01:29:18 +02:00
|
|
|
bool AddPostVar(const wchar_t * name, const wchar_t * value);
|
|
|
|
bool AddPostVar(const std::wstring & name, const std::wstring & value);
|
|
|
|
|
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
|
|
|
|
2013-11-29 22:39:23 +01:00
|
|
|
|
|
|
|
// setting a cookie
|
2021-05-20 20:59:12 +02:00
|
|
|
// name - cookie name (either const wchar_t, or std::wstring or pt::WTextStream)
|
|
|
|
// value - cookie value (can be everything which can be put to pt::WTextStream stream)
|
2013-11-29 22:39:23 +01:00
|
|
|
// the return std::wstring reference is a reference to the cookie inserted value (in out_cookies structure)
|
|
|
|
template<typename NameType, typename ValueType>
|
2021-05-20 20:59:12 +02:00
|
|
|
void AddCookie(const NameType & name, const ValueType & value, pt::Date * expires = 0);
|
2013-11-29 22:39:23 +01:00
|
|
|
|
|
|
|
template<typename NameType, typename ValueType>
|
2021-05-20 20:59:12 +02:00
|
|
|
void AddCookie(const NameType & name, const ValueType & value, pt::Date & expires);
|
2013-11-29 22:39:23 +01:00
|
|
|
|
2022-02-01 18:44:23 +01:00
|
|
|
bool has_frame(const wchar_t * frame);
|
|
|
|
bool has_frame(const std::wstring & frame);
|
2010-08-12 21:10:12 +02:00
|
|
|
|
2022-08-20 00:31:10 +02:00
|
|
|
void create_job(long job_id = JobTask::JOB_ID_DEFAULT, long job_secondary_id = JobTask::JOB_ID_DEFAULT);
|
2022-07-25 14:21:21 +02:00
|
|
|
void modify_status_code_if_needed();
|
|
|
|
|
|
|
|
// RENAMEME to add_header_if_not_exists
|
|
|
|
bool AddHeader(const wchar_t * name, const wchar_t * value);
|
|
|
|
bool AddHeader(const std::wstring & name, const std::wstring & value);
|
|
|
|
bool AddHeader(const wchar_t * name, const pt::WTextStream & value);
|
|
|
|
bool AddHeader(const std::wstring & name, const pt::WTextStream & value);
|
|
|
|
|
|
|
|
void FinishRequest();
|
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;
|
2022-07-25 14:21:21 +02:00
|
|
|
Templates * templates;
|
|
|
|
Compress * compress;
|
|
|
|
Plugin * plugin;
|
|
|
|
Mounts * mounts;
|
|
|
|
|
|
|
|
BinaryPage output_8bit;
|
|
|
|
BinaryPage compressed_output;
|
|
|
|
pt::WTextStream output_tmp_filtered_stream;
|
|
|
|
pt::TextStream serialized_model;
|
|
|
|
std::string aheader_name, aheader_value;
|
|
|
|
std::wstring cookie_id_string;
|
|
|
|
std::string send_data_buf;
|
|
|
|
|
|
|
|
|
2010-08-10 18:12:50 +02: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
|
|
|
|
2013-11-14 21:59:23 +01:00
|
|
|
void ClearOutputStreams();
|
2012-08-08 18:04:48 +02:00
|
|
|
|
2022-02-01 18:44:23 +01:00
|
|
|
void CheckAcceptHeader();
|
|
|
|
void CheckContainerParameter();
|
|
|
|
void PrepareFrameNames();
|
2021-06-18 19:18:13 +02:00
|
|
|
|
2021-07-01 23:34:49 +02:00
|
|
|
void current_dir(morm::Wrapper & wrapper);
|
2021-07-03 01:14:53 +02:00
|
|
|
void last_item_wrapper(morm::Wrapper & wrapper);
|
2021-06-18 19:18:13 +02:00
|
|
|
|
remove Request::post_tab and add Request::http_status
Instead of Reqest::post_tab we use now Request::post_in (pt::Space).
Request::http_status will be used instead Request::status,
but at the moment is not changed in all places.
Request::status has been marked as depracated.
While here:
- Check for root dir in App and not in FunctionParser,
let FunctionParser only log the root dir.
- Read post variables after parsing url parameters,
this allows winix functions to set limits
for post input.
- Set limits when parsing input json format, new
options added to config: post_max_object_items, post_max_table_items,
post_max_all_items, post_max_nested_objects.
There are similar options in each winix function (they are in
FunctionBase).
- Some refactoring in App.
- Add config option: log_whole_http_post if true
then the whole parsed post input is logged.
- Add config option: post_json_max - max length of input stream
for parsing json.
- Add config option: templates_request_status, default request_status.html
this is an ezc template used as [content] when the request status
is not 200_ok.
- Fix: Sort winix function didn't show items to sort (fix and do some
refactoring as well)
- Properly sort items in: ImgCrop, Ls, Sort, Upload
- Remove ezc templates: err_404.html, err_per_denied.html - now
request_status.html is used.
2022-05-30 01:29:18 +02:00
|
|
|
void http_status_error_title(EzcEnv & env);
|
|
|
|
void http_status_error_description(EzcEnv & env);
|
|
|
|
|
2022-08-11 08:04:40 +02:00
|
|
|
void PrepareAndSendAnswer();
|
2022-07-25 14:21:21 +02:00
|
|
|
void PrepareRawAnswer();
|
|
|
|
void PrepareJsonAnswer();
|
|
|
|
void PrepareXmlAnswer();
|
|
|
|
void PrepareCsvAnswer();
|
|
|
|
void PrepareContenerizedAnswer();
|
|
|
|
void PutSeparatorIfNeeded(bool put_separator);
|
|
|
|
void SerializeFieldJson(const wchar_t * field_name);
|
|
|
|
void SerializeStream(const pt::WTextStream & input_stream, const wchar_t * field_name);
|
|
|
|
void SerializeStreamJson(const pt::WTextStream & input_stream, const wchar_t * field_name);
|
|
|
|
void SerializeStreamXml(const pt::WTextStream & input_stream, const wchar_t * field_name);
|
|
|
|
void SerializeStreamCsv(const pt::WTextStream & input_stream, const wchar_t * field_name);
|
|
|
|
void SerializeAllFrames();
|
|
|
|
void SerializeSpecificFrames();
|
|
|
|
void SerializeModels();
|
|
|
|
void SerializeModel(morm::Wrapper & wrapper, const wchar_t * field_name);
|
|
|
|
void SerializeModelJson(morm::Wrapper & wrapper, const wchar_t * field_name);
|
|
|
|
void SerializeModelXml(morm::Wrapper & wrapper, const wchar_t * field_name);
|
|
|
|
void SerializeModelCsv(morm::Wrapper & wrapper, const wchar_t * field_name);
|
|
|
|
void FilterHtmlIfNeeded(const pt::WTextStream & input_stream, BinaryPage & output, bool clear_stream = true);
|
|
|
|
void Send8bitOutput(BinaryPage & output);
|
|
|
|
void SendData(const BinaryPage & page, FCGX_Stream * out);
|
|
|
|
void UseEzcGenerator();
|
|
|
|
int SelectDeflateVersion();
|
|
|
|
void SelectCompression(size_t source_len, bool & compression_allowed, int & compression_encoding);
|
|
|
|
void PrepareSessionCookie();
|
|
|
|
void PrepareHeaders(bool compressing, int compress_encoding, size_t output_size);
|
|
|
|
void ModifyStatusForRedirect();
|
|
|
|
void PrepareSendFileHeaderForStaticMountpoint();
|
|
|
|
void PrepareSendFileHeader();
|
|
|
|
void PrepareContentEncodingHeader(int compress_encoding);
|
|
|
|
void PrepareContentLengthHeader(size_t output_size);
|
|
|
|
void PrepareHeaderContentType();
|
|
|
|
void PrepareHeaderStatus(int http_status);
|
|
|
|
void SendHeaders();
|
|
|
|
void SendCookies();
|
|
|
|
bool CreateStaticResourcePath(pt::WTextStream & out_path);
|
|
|
|
bool CanSendContent();
|
|
|
|
void LogRequestTime();
|
2021-06-18 19:18:13 +02:00
|
|
|
|
|
|
|
MORM_MEMBER_FIELD(Request)
|
|
|
|
|
2008-12-10 05:42:49 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-10-09 22:44:56 +02:00
|
|
|
|
2013-11-29 22:39:23 +01:00
|
|
|
template<typename NameType, typename ValueType>
|
2021-05-20 20:59:12 +02:00
|
|
|
void Request::AddCookie(const NameType & name, const ValueType & value, pt::Date * expires)
|
2013-11-29 22:39:23 +01:00
|
|
|
{
|
2021-05-20 20:59:12 +02:00
|
|
|
pt::WTextStream cookie;
|
2013-11-29 22:39:23 +01:00
|
|
|
|
|
|
|
cookie << value;
|
|
|
|
|
|
|
|
if( cookie.empty() )
|
|
|
|
cookie << L"\"\""; // cookie empty value
|
|
|
|
|
|
|
|
if( expires )
|
|
|
|
cookie << L"; expires=" << DateToStrCookie(*expires) << L" GMT";
|
|
|
|
|
|
|
|
cookie << L"; path=/; domain=" << config->base_url;
|
2010-08-10 18:12:50 +02:00
|
|
|
|
2013-11-29 22:39:23 +01:00
|
|
|
/*
|
|
|
|
!! IMPROVE ME add an option to the config
|
|
|
|
|
|
|
|
don't use '; secure' flag if you are using both sites (with SSL
|
|
|
|
and without SSL) -- with secure flag the cookie is sent only through
|
|
|
|
SSL and if you accidentally open a new window without SSL (http://)
|
|
|
|
then winix will create a new session for you and the previous session (https://)
|
|
|
|
will be lost (the session cookie will be overwritten in the client's browser)
|
|
|
|
*/
|
|
|
|
|
2021-04-09 17:50:58 +02:00
|
|
|
out_cookies.add_stream(name, cookie);
|
2013-11-29 22:39:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<typename NameType, typename ValueType>
|
2021-05-20 20:59:12 +02:00
|
|
|
void Request::AddCookie(const NameType & name, const ValueType & value, pt::Date & expires)
|
2013-11-29 22:39:23 +01:00
|
|
|
{
|
2021-04-09 17:50:58 +02:00
|
|
|
AddCookie(name, value, &expires);
|
2013-11-29 22:39:23 +01:00
|
|
|
}
|
2008-12-10 05:42:49 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
2014-02-12 17:30:49 +01:00
|
|
|
|
2021-06-18 19:18:13 +02:00
|
|
|
|
|
|
|
|
2014-02-12 17:30:49 +01:00
|
|
|
} // namespace Winix
|
|
|
|
|
2008-12-10 05:42:49 +01:00
|
|
|
#endif
|
2013-11-29 22:39:23 +01:00
|
|
|
|