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
|
|
|
*/
|
2009-11-21 00:09:52 +01:00
|
|
|
|
2008-12-10 05:42:49 +01:00
|
|
|
#include "request.h"
|
2009-04-21 22:50:55 +02:00
|
|
|
#include "log.h"
|
2009-11-21 00:09:52 +01:00
|
|
|
#include "misc.h"
|
2021-06-20 20:47:59 +02:00
|
|
|
#include "functions/functionbase.h"
|
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
|
|
|
#include "templates/templates.h"
|
2022-07-25 14:21:21 +02:00
|
|
|
#include "convert/misc.h"
|
|
|
|
#include "templates/templates.h"
|
|
|
|
#include "jobtask.h"
|
|
|
|
|
2010-08-12 21:10:12 +02:00
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
|
2014-02-12 17:30:49 +01:00
|
|
|
namespace Winix
|
|
|
|
{
|
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
|
|
|
|
|
2009-11-13 21:40:11 +01:00
|
|
|
|
2008-12-10 05:42:49 +01:00
|
|
|
|
2014-10-09 22:44:56 +02:00
|
|
|
Request::Request()
|
2008-12-10 05:42:49 +01:00
|
|
|
{
|
2008-12-30 02:05:03 +01:00
|
|
|
id = 0;
|
2022-07-25 14:21:21 +02:00
|
|
|
config = nullptr;
|
|
|
|
templates = nullptr;
|
|
|
|
compress = nullptr;
|
|
|
|
plugin = nullptr;
|
|
|
|
mounts = nullptr;
|
|
|
|
|
|
|
|
// set function to nullptr because is used in Clear()
|
|
|
|
function = nullptr;
|
2008-12-10 05:42:49 +01:00
|
|
|
}
|
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
|
2021-06-17 21:44:29 +02:00
|
|
|
void Request::fields()
|
|
|
|
{
|
2021-07-03 01:14:53 +02:00
|
|
|
field(L"", L"dirs", dir_tab);
|
|
|
|
field(L"", L"is_item", is_item);
|
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
|
|
|
field(L"", L"http_status", http_status);
|
|
|
|
|
2021-07-03 01:14:53 +02:00
|
|
|
field(L"", L"current_dir", &Request::current_dir);
|
|
|
|
field(L"", L"last_item", &Request::last_item_wrapper);
|
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
|
|
|
field(L"", L"http_status_error_title", &Request::http_status_error_title);
|
|
|
|
field(L"", L"http_status_error_description", &Request::http_status_error_description);
|
2021-06-17 21:44:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-07-25 14:21:21 +02:00
|
|
|
void Request::SetConfig(Config * config)
|
|
|
|
{
|
|
|
|
this->config = config;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Request::SetTemplates(Templates * templates)
|
|
|
|
{
|
|
|
|
this->templates = templates;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Request::SetCompress(Compress * compress)
|
|
|
|
{
|
|
|
|
this->compress = compress;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Request::SetPlugin(Plugin * plugin)
|
2010-08-10 18:12:50 +02:00
|
|
|
{
|
2022-07-25 14:21:21 +02:00
|
|
|
this->plugin = plugin;
|
2010-08-10 18:12:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-07-25 14:21:21 +02:00
|
|
|
void Request::SetMounts(Mounts * mounts)
|
|
|
|
{
|
|
|
|
this->mounts = mounts;
|
|
|
|
}
|
|
|
|
|
2013-11-14 21:59:23 +01:00
|
|
|
|
|
|
|
|
|
|
|
void Request::ClearOutputStreams()
|
2012-08-08 18:04:48 +02:00
|
|
|
{
|
2015-11-15 23:23:36 +01:00
|
|
|
size_t len = 0;
|
|
|
|
|
2021-07-16 18:17:57 +02:00
|
|
|
out_main_stream.clear();
|
2013-12-23 04:29:33 +01:00
|
|
|
|
|
|
|
if( config )
|
|
|
|
len = config->ezc_out_streams_size;
|
2013-11-29 22:39:23 +01:00
|
|
|
|
2015-11-15 23:23:36 +01:00
|
|
|
/*
|
|
|
|
* clearing buffers and setting 'escape' flag to true
|
|
|
|
* for all streams which were used in the map
|
|
|
|
*/
|
|
|
|
out_streams.ClearMap();
|
|
|
|
out_streams.ResizeTab(len);
|
2013-11-14 21:59:23 +01:00
|
|
|
}
|
2009-09-22 01:05:05 +02:00
|
|
|
|
|
|
|
|
2022-07-25 14:21:21 +02:00
|
|
|
/*
|
|
|
|
* we do not clear config, templates, compress, plugin and mounts pointers
|
|
|
|
*/
|
2008-12-10 05:42:49 +01:00
|
|
|
void Request::Clear()
|
|
|
|
{
|
2022-07-25 14:21:21 +02:00
|
|
|
id = -1;
|
|
|
|
run_state = RunState::not_assigned;
|
2010-01-06 20:17:53 +01:00
|
|
|
|
2011-06-24 22:53:21 +02:00
|
|
|
RemovePostFileTmp(post_file_tab);
|
2013-11-14 21:59:23 +01:00
|
|
|
ClearOutputStreams();
|
2010-08-12 21:10:12 +02:00
|
|
|
|
2021-06-20 20:47:59 +02:00
|
|
|
if( function )
|
|
|
|
function->Clear();
|
|
|
|
|
2010-08-10 22:43:38 +02:00
|
|
|
post_file_tab.clear();
|
|
|
|
cookie_tab.clear();
|
2021-04-09 17:50:58 +02:00
|
|
|
post_in.clear();
|
2008-12-10 05:42:49 +01:00
|
|
|
|
2013-11-29 22:39:23 +01:00
|
|
|
method = unknown_method;
|
2013-11-14 21:59:23 +01:00
|
|
|
|
2021-04-09 17:50:58 +02:00
|
|
|
headers_in.clear();
|
2018-04-25 21:48:47 +02:00
|
|
|
|
2021-04-09 17:50:58 +02:00
|
|
|
out_headers.clear();
|
|
|
|
out_cookies.clear();
|
2011-06-24 22:53:21 +02:00
|
|
|
|
2014-10-09 22:44:56 +02:00
|
|
|
env_request_method.clear();
|
|
|
|
env_request_uri.clear();
|
|
|
|
env_http_cookie.clear();
|
|
|
|
env_http_host.clear();
|
|
|
|
env_http_user_agent.clear();
|
|
|
|
env_http_accept_encoding.clear();
|
2022-02-01 18:44:23 +01:00
|
|
|
env_http_accept.clear();
|
2022-02-02 18:20:32 +01:00
|
|
|
env_http_accept_language.clear();
|
2014-10-09 22:44:56 +02:00
|
|
|
env_fcgi_role.clear();
|
|
|
|
env_content_type.clear();
|
|
|
|
env_https.clear();
|
2010-01-06 20:17:53 +01:00
|
|
|
|
2010-08-10 22:43:38 +02:00
|
|
|
item_tab.clear();
|
2008-12-10 05:42:49 +01:00
|
|
|
item.Clear();
|
2021-04-09 17:50:58 +02:00
|
|
|
item.set_connector(nullptr);
|
2010-08-10 22:43:38 +02:00
|
|
|
dir_tab.clear();
|
2011-01-20 19:37:51 +01:00
|
|
|
last_item = &item;
|
2008-12-30 02:05:03 +01:00
|
|
|
is_item = false;
|
2021-06-20 20:47:59 +02:00
|
|
|
function = nullptr;
|
2022-07-25 14:21:21 +02:00
|
|
|
session = nullptr;
|
|
|
|
mount = nullptr;
|
2010-08-10 22:43:38 +02:00
|
|
|
param_tab.clear();
|
2011-07-29 00:18:10 +02:00
|
|
|
anchor.clear();
|
2021-10-13 01:27:14 +02:00
|
|
|
|
2022-02-01 18:44:23 +01:00
|
|
|
send_bin_stream = false;
|
|
|
|
send_main_stream = false;
|
2021-10-13 01:27:14 +02:00
|
|
|
send_all_frames = false;
|
2022-02-01 18:44:23 +01:00
|
|
|
send_frames.clear();
|
|
|
|
|
|
|
|
use_ezc_engine = false;
|
|
|
|
serialize_models = false;
|
|
|
|
|
|
|
|
accept_mime_types.clear();
|
|
|
|
container_type = ContainerType::container_raw;
|
2008-12-30 02:05:03 +01:00
|
|
|
|
2010-02-28 01:08:10 +01:00
|
|
|
status = WINIX_ERR_OK;
|
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_status = Header::status_200_ok;
|
2010-01-25 05:52:17 +01:00
|
|
|
|
2009-10-08 19:59:10 +02:00
|
|
|
browser_msie = false;
|
2009-11-17 02:04:01 +01:00
|
|
|
redirect_to.clear();
|
2011-07-07 19:02:14 +02:00
|
|
|
redirect_type = 303;
|
2010-02-19 00:30:22 +01:00
|
|
|
x_sendfile.clear();
|
|
|
|
send_as_attachment = false;
|
2011-09-07 00:46:15 +02:00
|
|
|
|
|
|
|
using_ssl = false;
|
2021-05-31 10:58:34 +02:00
|
|
|
is_htmx_request = false;
|
2012-02-17 06:19:24 +01:00
|
|
|
|
|
|
|
start_time = 0;
|
2012-05-19 17:14:35 +02:00
|
|
|
start_date.Clear();
|
2012-04-22 20:23:44 +02:00
|
|
|
|
2021-06-24 15:33:44 +02:00
|
|
|
timespec_req_start.tv_sec = 0;
|
|
|
|
timespec_req_start.tv_nsec = 0;
|
|
|
|
timespec_req_stop.tv_sec = 0;
|
|
|
|
timespec_req_stop.tv_nsec = 0;
|
|
|
|
timespec_req_diff.tv_sec = 0;
|
|
|
|
timespec_req_diff.tv_nsec = 0;
|
|
|
|
|
|
|
|
timespec_ezc_engine_start.tv_sec = 0;
|
|
|
|
timespec_ezc_engine_start.tv_nsec = 0;
|
|
|
|
timespec_ezc_engine_stop.tv_sec = 0;
|
|
|
|
timespec_ezc_engine_stop.tv_nsec = 0;
|
|
|
|
|
2012-04-22 20:23:44 +02:00
|
|
|
subdomain.clear();
|
2021-06-16 18:07:44 +02:00
|
|
|
models.Clear();
|
2012-08-26 21:53:47 +02:00
|
|
|
|
2013-11-14 21:59:23 +01:00
|
|
|
out_bin_stream.clear();
|
2012-09-11 07:19:45 +02:00
|
|
|
|
2012-08-26 21:53:47 +02:00
|
|
|
gen_trim_white = false;
|
|
|
|
gen_skip_new_line = false;
|
|
|
|
gen_use_special_chars = false;
|
2012-10-27 09:44:26 +02:00
|
|
|
|
|
|
|
ip = 0;
|
2018-05-01 13:22:55 +02:00
|
|
|
ip_str.clear();
|
2013-03-26 01:04:01 +01:00
|
|
|
use_200_status_for_not_found_and_permission_denied = false;
|
2021-01-27 18:31:48 +01:00
|
|
|
|
|
|
|
html_template.clear();
|
2021-10-13 01:27:14 +02:00
|
|
|
use_html_filter = false;
|
2022-07-25 14:21:21 +02:00
|
|
|
|
|
|
|
job_id = JobTask::JOB_ID_DEFAULT;
|
2022-08-20 00:31:10 +02:00
|
|
|
job_second_id = JobTask::JOB_ID_DEFAULT;
|
2022-07-25 14:21:21 +02:00
|
|
|
job.clear();
|
|
|
|
|
|
|
|
accept_gzip = false;
|
|
|
|
accept_deflate = false;
|
|
|
|
|
|
|
|
output_8bit.clear();
|
|
|
|
compressed_output.clear();
|
|
|
|
output_tmp_filtered_stream.clear();
|
|
|
|
serialized_model.clear();
|
|
|
|
aheader_name.clear();
|
|
|
|
aheader_value.clear();
|
|
|
|
cookie_id_string.clear();
|
|
|
|
send_data_buf.clear();
|
|
|
|
|
2008-12-10 05:42:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-02-17 06:19:24 +01:00
|
|
|
void Request::RequestStarts()
|
|
|
|
{
|
|
|
|
// clearing it is better to use at the end of a request
|
|
|
|
// so starting is much faster
|
2021-06-24 15:33:44 +02:00
|
|
|
clock_gettime(CLOCK_REALTIME, ×pec_req_start);
|
|
|
|
timespec_req_stop = timespec_req_start;
|
2012-02-17 06:19:24 +01:00
|
|
|
|
2021-06-24 15:33:44 +02:00
|
|
|
start_time = timespec_req_start.tv_sec;
|
2012-05-19 17:14:35 +02:00
|
|
|
start_date = start_time;
|
2012-02-17 06:19:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-12-10 05:42:49 +01:00
|
|
|
|
2021-06-24 15:33:44 +02:00
|
|
|
void Request::RequestEnds()
|
|
|
|
{
|
|
|
|
clock_gettime(CLOCK_REALTIME, ×pec_req_stop);
|
|
|
|
calculate_timespec_diff(timespec_req_start, timespec_req_stop, timespec_req_diff);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-12-10 05:42:49 +01:00
|
|
|
|
2022-02-01 18:44:23 +01:00
|
|
|
void Request::PrepareAnswerType()
|
2021-10-13 01:27:14 +02:00
|
|
|
{
|
2022-02-01 18:44:23 +01:00
|
|
|
CheckAcceptHeader();
|
|
|
|
CheckContainerParameter();
|
2021-10-13 01:27:14 +02:00
|
|
|
|
2022-02-01 18:44:23 +01:00
|
|
|
serialize_models = (container_type != ContainerType::container_raw);
|
2021-10-13 01:27:14 +02:00
|
|
|
send_all_frames = (ParamValuep(config->request_all_frames_parameter) != nullptr);
|
2022-02-01 18:44:23 +01:00
|
|
|
send_main_stream = (ParamValuep(config->request_main_stream_parameter) != nullptr);
|
2021-10-13 01:27:14 +02:00
|
|
|
use_html_filter = config->html_filter;
|
2022-02-01 18:44:23 +01:00
|
|
|
PrepareFrameNames();
|
|
|
|
|
|
|
|
if( container_type == ContainerType::container_raw && !send_all_frames && send_frames.empty() )
|
|
|
|
{
|
|
|
|
send_main_stream = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
use_ezc_engine = send_main_stream || send_all_frames || !send_frames.empty();
|
|
|
|
}
|
2021-10-13 01:27:14 +02:00
|
|
|
|
|
|
|
|
2022-02-01 18:44:23 +01:00
|
|
|
void Request::CheckAcceptHeader()
|
|
|
|
{
|
|
|
|
if( !accept_mime_types.empty() )
|
|
|
|
{
|
|
|
|
bool found = false;
|
2021-10-13 01:27:14 +02:00
|
|
|
|
2022-02-01 18:44:23 +01:00
|
|
|
for(HeaderValue & h: accept_mime_types)
|
|
|
|
{
|
|
|
|
if( h.value == Header::text_html || h.value == Header::application_xhtml_xml ||
|
|
|
|
h.value == Header::text_all || h.value == Header::all_all)
|
|
|
|
{
|
|
|
|
container_type = ContainerType::container_raw;
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if( h.value == Header::application_json || h.value == Header::application_all )
|
|
|
|
{
|
|
|
|
container_type = ContainerType::container_json;
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if( h.value == Header::application_xml )
|
|
|
|
{
|
|
|
|
container_type = ContainerType::container_xml;
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if( h.value == Header::text_csv )
|
|
|
|
{
|
|
|
|
container_type = ContainerType::container_csv;
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2021-10-13 01:27:14 +02:00
|
|
|
|
2022-02-01 18:44:23 +01:00
|
|
|
if( !found )
|
|
|
|
{
|
|
|
|
Log * log = get_logger();
|
2021-10-13 01:27:14 +02:00
|
|
|
|
2022-02-01 18:44:23 +01:00
|
|
|
if( log )
|
|
|
|
{
|
2022-07-25 14:21:21 +02:00
|
|
|
(*log) << log2 << "Request: an unknown " << Header::accept << " headers: ";
|
2022-02-01 18:44:23 +01:00
|
|
|
HeaderValue::log_values(accept_mime_types, *log);
|
|
|
|
(*log) << " (skipping)" << logend;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-10-13 01:27:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-02-01 18:44:23 +01:00
|
|
|
|
|
|
|
void Request::CheckContainerParameter()
|
2021-10-13 01:27:14 +02:00
|
|
|
{
|
|
|
|
std::wstring * container = ParamValuep(L"container");
|
|
|
|
|
|
|
|
if( container )
|
|
|
|
{
|
|
|
|
// IMPROVEME do a plugin call here
|
|
|
|
// if a plugin can consume this then don't check text/json/xml/csv and just return true
|
|
|
|
|
2022-02-01 18:44:23 +01:00
|
|
|
if( *container == L"raw" )
|
2021-10-13 01:27:14 +02:00
|
|
|
{
|
2022-02-01 18:44:23 +01:00
|
|
|
container_type = ContainerType::container_raw;
|
2021-10-13 01:27:14 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
if( *container == L"json" )
|
|
|
|
{
|
2022-02-01 18:44:23 +01:00
|
|
|
container_type = ContainerType::container_json;
|
2021-10-13 01:27:14 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
if( *container == L"xml" )
|
|
|
|
{
|
2022-02-01 18:44:23 +01:00
|
|
|
container_type = ContainerType::container_xml;
|
2021-10-13 01:27:14 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
if( *container == L"csv" )
|
|
|
|
{
|
2022-02-01 18:44:23 +01:00
|
|
|
container_type = ContainerType::container_csv;
|
2021-10-13 01:27:14 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Log * log = get_logger();
|
|
|
|
|
|
|
|
if( log )
|
|
|
|
{
|
2022-07-25 14:21:21 +02:00
|
|
|
(*log) << log2 << "Request: an unknown container url parameter: " << *container << " (skipping)" << logend;
|
2021-10-13 01:27:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-02-01 18:44:23 +01:00
|
|
|
void Request::PrepareFrameNames()
|
2021-10-13 01:27:14 +02:00
|
|
|
{
|
2022-02-01 18:44:23 +01:00
|
|
|
Config * config = get_config();
|
|
|
|
Log * log = get_logger();
|
2021-10-13 01:27:14 +02:00
|
|
|
|
2022-02-01 18:44:23 +01:00
|
|
|
if( config && log )
|
2021-10-13 01:27:14 +02:00
|
|
|
{
|
2022-02-01 18:44:23 +01:00
|
|
|
const std::wstring & frame = ParamValue(config->request_frame_parameter);
|
2021-10-13 01:27:14 +02:00
|
|
|
|
2022-02-01 18:44:23 +01:00
|
|
|
if( frame.size() <= config->request_frame_parameter_max_length )
|
2021-10-13 01:27:14 +02:00
|
|
|
{
|
2022-02-01 18:44:23 +01:00
|
|
|
send_frames.clear();
|
|
|
|
slice_by(frame, ',', send_frames);
|
|
|
|
std::sort(send_frames.begin(), send_frames.end());
|
|
|
|
auto frames_end = std::unique(send_frames.begin(), send_frames.end());
|
|
|
|
send_frames.erase(frames_end, send_frames.end());
|
2021-10-13 01:27:14 +02:00
|
|
|
|
2022-02-01 18:44:23 +01:00
|
|
|
if( send_frames.size() > config->request_frame_parameter_max_frames )
|
2021-10-13 01:27:14 +02:00
|
|
|
{
|
2022-02-01 18:44:23 +01:00
|
|
|
send_frames.clear();
|
|
|
|
(*log) << log2 << "Request: the number of frames exceeds " << config->request_frame_parameter_max_frames
|
|
|
|
<< " (skipping frames)" << logend;
|
2021-10-13 01:27:14 +02:00
|
|
|
}
|
|
|
|
}
|
2022-02-01 18:44:23 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
(*log) << log2 << "Request: the length of the frame url parameter exceeds " << config->request_frame_parameter_max_length
|
|
|
|
<< " characters (skiping frames)" << logend;
|
|
|
|
}
|
2021-10-13 01:27:14 +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
|
|
|
// add such a method to Space
|
|
|
|
bool Request::AddPostVar(const wchar_t * name, const wchar_t * value)
|
|
|
|
{
|
|
|
|
bool status = false;
|
|
|
|
pt::Space * space_value = post_in.get_space(name);
|
|
|
|
Log * log = get_logger();
|
2021-10-13 01:27:14 +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
|
|
|
if( space_value )
|
|
|
|
{
|
|
|
|
if( space_value->is_table() )
|
|
|
|
{
|
|
|
|
if( space_value->table_size() < WINIX_POSTTABLE_VALUT_TABLE_MAXSIZE )
|
|
|
|
{
|
|
|
|
status = true;
|
|
|
|
space_value->add(value);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( log )
|
|
|
|
{
|
2022-07-25 14:21:21 +02:00
|
|
|
(*log) << log1 << "Request: more than " << WINIX_POSTTABLE_VALUT_TABLE_MAXSIZE << " post variables in a table " << name << " (skipping)" << logend;
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
status = true;
|
|
|
|
pt::Space new_table;
|
|
|
|
new_table.add(std::move(*space_value));
|
|
|
|
new_table.add(value);
|
|
|
|
space_value->set(std::move(new_table));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( post_in.object_size() < WINIX_POSTTABLE_MAXSIZE )
|
|
|
|
{
|
|
|
|
post_in.add(name, value);
|
|
|
|
status = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( log )
|
|
|
|
{
|
2022-07-25 14:21:21 +02:00
|
|
|
(*log) << log1 << "Request: more than " << WINIX_POSTTABLE_MAXSIZE << " post variables (skipping)" << logend;
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Request::AddPostVar(const std::wstring & name, const std::wstring & value)
|
2008-12-10 05:42:49 +01: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
|
|
|
return AddPostVar(name.c_str(), value.c_str());
|
|
|
|
}
|
2008-12-10 05:42:49 +01: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
|
|
|
|
|
|
|
bool Request::IsPostVar(const wchar_t * var)
|
|
|
|
{
|
|
|
|
return post_in.has_key(var);
|
2008-12-10 05:42:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-25 05:51:55 +01:00
|
|
|
bool Request::IsPostVar(const std::wstring & var)
|
|
|
|
{
|
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
|
|
|
return post_in.has_key(var);
|
2011-11-25 05:51:55 +01:00
|
|
|
}
|
|
|
|
|
2008-12-10 05:42:49 +01:00
|
|
|
|
2010-11-21 01:19:17 +01:00
|
|
|
const std::wstring & Request::PostVar(const wchar_t * var)
|
2008-12-10 05:42:49 +01: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
|
|
|
std::wstring * value = post_in.get_wstr(var);
|
|
|
|
|
|
|
|
if( value )
|
|
|
|
return *value;
|
|
|
|
|
|
|
|
return str_empty;
|
2008-12-10 05:42:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-25 05:51:55 +01:00
|
|
|
const std::wstring & Request::PostVar(const std::wstring & var)
|
|
|
|
{
|
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
|
|
|
return PostVar(var.c_str());
|
2011-11-25 05:51:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-17 02:04:01 +01:00
|
|
|
|
2010-11-21 01:19:17 +01:00
|
|
|
bool Request::PostVar(const wchar_t * var, std::wstring & result)
|
2008-12-30 02:05:03 +01: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
|
|
|
std::wstring * value = post_in.get_wstr(var);
|
|
|
|
bool found = false;
|
|
|
|
|
|
|
|
if( value )
|
|
|
|
{
|
|
|
|
result = *value;
|
|
|
|
found = true;
|
|
|
|
}
|
|
|
|
else
|
2009-11-17 00:36:38 +01:00
|
|
|
{
|
|
|
|
result.clear();
|
|
|
|
}
|
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
|
|
|
|
|
|
|
return found;
|
2008-12-30 02:05:03 +01:00
|
|
|
}
|
2009-11-17 02:04:01 +01:00
|
|
|
|
2008-12-10 05:42:49 +01:00
|
|
|
|
2011-11-25 05:51:55 +01:00
|
|
|
bool Request::PostVar(const std::wstring & var, std::wstring & result)
|
|
|
|
{
|
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
|
|
|
return PostVar(var.c_str(), result);
|
2011-11-25 05:51:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-11-21 01:19:17 +01:00
|
|
|
std::wstring * Request::PostVarp(const wchar_t * var)
|
2010-09-30 22:58:20 +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
|
|
|
return post_in.get_wstr(var);
|
2010-09-30 22:58:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-04 19:51:43 +02:00
|
|
|
std::wstring * Request::PostVarp(const std::wstring & var)
|
|
|
|
{
|
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
|
|
|
return post_in.get_wstr(var.c_str());
|
2009-12-09 01:42:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-04-22 23:26:56 +02:00
|
|
|
std::wstring * Request::ParamValuep(const wchar_t * param_name)
|
2008-12-30 02:05:03 +01:00
|
|
|
{
|
2018-04-22 23:26:56 +02:00
|
|
|
ParamTab::iterator i;
|
2010-11-21 01:19:17 +01:00
|
|
|
|
|
|
|
for(i=param_tab.begin() ; i!=param_tab.end() ; ++i)
|
|
|
|
{
|
|
|
|
if( i->name == param_name )
|
2018-04-22 23:26:56 +02:00
|
|
|
return &i->value;
|
2010-11-21 01:19:17 +01:00
|
|
|
}
|
|
|
|
|
2018-04-22 23:26:56 +02:00
|
|
|
return nullptr;
|
|
|
|
}
|
2010-11-21 01:19:17 +01:00
|
|
|
|
2018-04-22 23:26:56 +02:00
|
|
|
std::wstring * Request::ParamValuep(const std::wstring & param_name)
|
2010-11-21 01:19:17 +01:00
|
|
|
{
|
2018-04-22 23:26:56 +02:00
|
|
|
ParamTab::iterator i;
|
2010-11-21 01:19:17 +01:00
|
|
|
|
2010-08-10 22:43:38 +02:00
|
|
|
for(i=param_tab.begin() ; i!=param_tab.end() ; ++i)
|
2008-12-30 02:05:03 +01:00
|
|
|
{
|
2010-07-04 22:27:14 +02:00
|
|
|
if( i->name == param_name )
|
2018-04-22 23:26:56 +02:00
|
|
|
return &i->value;
|
2008-12-30 02:05:03 +01:00
|
|
|
}
|
2018-04-22 23:26:56 +02:00
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool Request::IsParam(const wchar_t * param_name)
|
|
|
|
{
|
|
|
|
return ParamValuep(param_name) != nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Request::IsParam(const std::wstring & param_name)
|
|
|
|
{
|
|
|
|
return ParamValuep(param_name) != nullptr;
|
2008-12-30 02:05:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-21 01:19:17 +01:00
|
|
|
const std::wstring & Request::ParamValue(const wchar_t * param_name)
|
2010-07-04 22:27:14 +02:00
|
|
|
{
|
2018-04-22 23:26:56 +02:00
|
|
|
const std::wstring * val = ParamValuep(param_name);
|
|
|
|
|
|
|
|
if( val != nullptr )
|
|
|
|
return *val;
|
2010-07-04 22:27:14 +02:00
|
|
|
|
2018-04-22 23:26:56 +02:00
|
|
|
return str_empty;
|
2010-07-04 22:27:14 +02:00
|
|
|
}
|
|
|
|
|
2008-12-30 02:05:03 +01:00
|
|
|
|
2011-02-11 22:37:28 +01:00
|
|
|
const std::wstring & Request::ParamValue(const std::wstring & param_name)
|
|
|
|
{
|
2018-04-22 23:26:56 +02:00
|
|
|
const std::wstring * val = ParamValuep(param_name);
|
|
|
|
|
|
|
|
if( val != nullptr )
|
|
|
|
return *val;
|
|
|
|
|
|
|
|
return str_empty;
|
2011-02-11 22:37:28 +01:00
|
|
|
}
|
|
|
|
|
2008-12-21 22:17:09 +01: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
|
|
|
|
2022-04-26 23:41:56 +02:00
|
|
|
void Request::AddParam(const std::wstring & param_name, const std::wstring & param_value)
|
|
|
|
{
|
|
|
|
bool found = false;
|
|
|
|
ParamTab::iterator i;
|
|
|
|
|
|
|
|
for(i=param_tab.begin() ; i!=param_tab.end() ; ++i)
|
|
|
|
{
|
|
|
|
if( i->name == param_name )
|
|
|
|
{
|
|
|
|
i->value = param_value;
|
|
|
|
found = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !found )
|
|
|
|
{
|
|
|
|
Param param;
|
|
|
|
param.name = param_name;
|
|
|
|
param.value = param_value;
|
|
|
|
param_tab.push_back(param);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Request::AddParam(const wchar_t * param_name, const wchar_t * param_value)
|
|
|
|
{
|
|
|
|
bool found = false;
|
|
|
|
ParamTab::iterator i;
|
|
|
|
|
|
|
|
for(i=param_tab.begin() ; i!=param_tab.end() ; ++i)
|
|
|
|
{
|
|
|
|
if( i->name == param_name )
|
|
|
|
{
|
|
|
|
i->value = param_value;
|
|
|
|
found = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !found )
|
|
|
|
{
|
|
|
|
Param param;
|
|
|
|
param.name = param_name;
|
|
|
|
param.value = param_value;
|
|
|
|
param_tab.push_back(param);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Request::RemoveParam(const wchar_t * param_name)
|
|
|
|
{
|
|
|
|
ParamTab::iterator i;
|
|
|
|
|
|
|
|
for(size_t i=0 ; i < param_tab.size() ; )
|
|
|
|
{
|
|
|
|
if( param_tab[i].name == param_name )
|
|
|
|
{
|
|
|
|
param_tab.erase(param_tab.begin() + i);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Request::RemoveParam(const std::wstring & param_name)
|
|
|
|
{
|
|
|
|
ParamTab::iterator i;
|
|
|
|
|
|
|
|
for(size_t i=0 ; i < param_tab.size() ; )
|
|
|
|
{
|
|
|
|
if( param_tab[i].name == param_name )
|
|
|
|
{
|
|
|
|
param_tab.erase(param_tab.begin() + i);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-12-21 22:17:09 +01:00
|
|
|
|
|
|
|
|
2021-07-01 23:34:49 +02:00
|
|
|
void Request::current_dir(morm::Wrapper & wrapper)
|
2021-06-18 19:18:13 +02:00
|
|
|
{
|
2021-07-01 23:34:49 +02:00
|
|
|
wrapper.model = dir_tab.back();
|
2021-06-18 19:18:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-03 01:14:53 +02:00
|
|
|
void Request::last_item_wrapper(morm::Wrapper & wrapper)
|
|
|
|
{
|
|
|
|
wrapper.model = last_item;
|
|
|
|
}
|
2021-06-18 19:18:13 +02:00
|
|
|
|
2021-06-24 15:33:44 +02:00
|
|
|
|
2022-02-01 18:44:23 +01:00
|
|
|
bool Request::has_frame(const wchar_t * frame)
|
|
|
|
{
|
|
|
|
for(std::wstring & f: send_frames)
|
|
|
|
{
|
|
|
|
if( f == frame )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Request::has_frame(const std::wstring & frame)
|
|
|
|
{
|
|
|
|
for(std::wstring & f: send_frames)
|
|
|
|
{
|
|
|
|
if( f == frame )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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 Request::http_status_error_title(EzcEnv & env)
|
|
|
|
{
|
|
|
|
pt::WTextStream str;
|
|
|
|
str << L"http_error_" << http_status << L"_title";
|
|
|
|
|
|
|
|
const std::wstring & msg = TemplatesFunctions::locale.Get(str);
|
|
|
|
env.out << msg;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Request::http_status_error_description(EzcEnv & env)
|
|
|
|
{
|
|
|
|
pt::WTextStream str;
|
|
|
|
str << L"http_error_" << http_status << L"_msg";
|
|
|
|
|
|
|
|
const std::wstring & msg = TemplatesFunctions::locale.Get(str);
|
|
|
|
env.out << msg;
|
|
|
|
}
|
2022-02-01 18:44:23 +01:00
|
|
|
|
2021-06-24 15:33:44 +02:00
|
|
|
|
2022-08-20 00:31:10 +02:00
|
|
|
void Request::create_job(long job_id, long job_secondary_id)
|
2022-07-25 14:21:21 +02:00
|
|
|
{
|
|
|
|
this->job_id = job_id;
|
2022-08-20 00:31:10 +02:00
|
|
|
this->job_second_id = job_secondary_id;
|
2022-07-25 14:21:21 +02:00
|
|
|
run_state = RunState::assigned_to_job;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-20 00:31:10 +02:00
|
|
|
|
|
|
|
|
2022-07-25 14:21:21 +02:00
|
|
|
/*
|
|
|
|
* will be removed in the future
|
|
|
|
*/
|
|
|
|
void Request::modify_status_code_if_needed()
|
|
|
|
{
|
|
|
|
// moved from Templates when a pattern was selected
|
|
|
|
switch( status )
|
|
|
|
{
|
|
|
|
case WINIX_ERR_INCORRECT_URI: // !!temporarily
|
|
|
|
case WINIX_ERR_INTERNAL_ERROR: // !! temprarily
|
|
|
|
case WINIX_ERR_PERMISSION_DENIED:
|
|
|
|
case WINIX_ERR_CANT_CHANGE_USER:
|
|
|
|
case WINIX_ERR_CANT_CHANGE_GROUP:
|
|
|
|
case WINIX_ERR_CANT_CHANGE_PRIVILEGES:
|
|
|
|
http_status = Header::status_403_forbidden;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WINIX_ERR_NO_ITEM:
|
|
|
|
case WINIX_ERR_NO_FUNCTION:
|
|
|
|
case WINIX_ERR_UNKNOWN_PARAM:
|
|
|
|
http_status = Header::status_404_not_found;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( use_200_status_for_not_found_and_permission_denied && (
|
|
|
|
http_status == Header::status_404_not_found ||
|
|
|
|
http_status == Header::status_403_forbidden
|
|
|
|
))
|
|
|
|
{
|
|
|
|
http_status = Header::status_200_ok;
|
|
|
|
Log * plog = get_logger();
|
|
|
|
|
|
|
|
if( plog )
|
|
|
|
{
|
|
|
|
(*plog) << log3 << "Request: changing the http response to: 200 OK" << logend;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Request::ModifyStatusForRedirect()
|
|
|
|
{
|
|
|
|
switch(redirect_type)
|
|
|
|
{
|
|
|
|
case 300:
|
|
|
|
http_status = Header::status_300_multiple_choices;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 301:
|
|
|
|
http_status = Header::status_301_moved_permanently;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 302:
|
|
|
|
http_status = Header::status_302_found;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 307:
|
|
|
|
http_status = Header::status_307_temporary_redirect;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 303:
|
|
|
|
default:
|
|
|
|
http_status = Header::status_303_see_other;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-08-11 08:04:40 +02:00
|
|
|
// may rename to something like PrepareAndSendAnswer()?
|
|
|
|
void Request::PrepareAndSendAnswer()
|
2022-07-25 14:21:21 +02:00
|
|
|
{
|
|
|
|
output_8bit.clear();
|
|
|
|
compressed_output.clear();
|
|
|
|
|
|
|
|
if( !fcgi_request.out )
|
|
|
|
{
|
|
|
|
Log * plog = get_logger();
|
|
|
|
|
|
|
|
if( plog )
|
|
|
|
{
|
|
|
|
(*plog) << "Request: I cannot send the answer - fcgi_request.out is null (internal error)" << logend;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-11 08:04:40 +02:00
|
|
|
if( !redirect_to.empty() || !x_sendfile.empty() || method == Request::options )
|
2022-07-25 14:21:21 +02:00
|
|
|
{
|
|
|
|
Send8bitOutput(output_8bit); // send empty content
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
plugin->Call(WINIX_CONTENT_MAKE);
|
|
|
|
|
|
|
|
if( use_ezc_engine )
|
|
|
|
{
|
|
|
|
UseEzcGenerator();
|
|
|
|
}
|
|
|
|
|
|
|
|
if( container_type == Request::ContainerType::container_raw && send_bin_stream )
|
|
|
|
{
|
|
|
|
Send8bitOutput(out_bin_stream);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if( container_type == Request::ContainerType::container_raw )
|
|
|
|
{
|
|
|
|
PrepareRawAnswer();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if( container_type == Request::ContainerType::container_json )
|
|
|
|
{
|
|
|
|
PrepareJsonAnswer();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if( container_type == Request::ContainerType::container_xml )
|
|
|
|
{
|
|
|
|
PrepareXmlAnswer();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if( container_type == Request::ContainerType::container_csv )
|
|
|
|
{
|
|
|
|
PrepareCsvAnswer();
|
|
|
|
}
|
|
|
|
|
|
|
|
Send8bitOutput(output_8bit);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Request::PrepareRawAnswer()
|
|
|
|
{
|
|
|
|
if( send_main_stream )
|
|
|
|
{
|
|
|
|
FilterHtmlIfNeeded(out_main_stream.get_buffer(), output_8bit, false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if( send_all_frames )
|
|
|
|
{
|
|
|
|
SerializeAllFrames();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if( !send_frames.empty() )
|
|
|
|
{
|
|
|
|
SerializeSpecificFrames();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Request::PrepareJsonAnswer()
|
|
|
|
{
|
|
|
|
output_8bit << '{';
|
|
|
|
PrepareContenerizedAnswer();
|
|
|
|
output_8bit << '}';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Request::PrepareXmlAnswer()
|
|
|
|
{
|
|
|
|
output_8bit << '<';
|
|
|
|
pt::esc_to_xml(config->xml_root, output_8bit);
|
|
|
|
output_8bit << '>';
|
|
|
|
|
|
|
|
PrepareContenerizedAnswer();
|
|
|
|
|
|
|
|
output_8bit << "</";
|
|
|
|
pt::esc_to_xml(config->xml_root, output_8bit);
|
|
|
|
output_8bit << '>';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Request::PrepareCsvAnswer()
|
|
|
|
{
|
|
|
|
PrepareContenerizedAnswer();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Request::PrepareContenerizedAnswer()
|
|
|
|
{
|
|
|
|
bool put_separator = false;
|
|
|
|
|
|
|
|
if( serialize_models )
|
|
|
|
{
|
|
|
|
SerializeModels();
|
|
|
|
put_separator = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( send_bin_stream )
|
|
|
|
{
|
|
|
|
PutSeparatorIfNeeded(put_separator);
|
|
|
|
|
|
|
|
// IMPLEMENT ME serialize binary stream as base64 and put in 'bin_stream' field
|
|
|
|
pt::WTextStream str;
|
|
|
|
str << "NOT IMPLEMENTED YET";
|
|
|
|
SerializeStream(str, config->bin_stream_field.c_str());
|
|
|
|
put_separator = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( send_main_stream )
|
|
|
|
{
|
|
|
|
PutSeparatorIfNeeded(put_separator);
|
|
|
|
SerializeStream(out_main_stream.get_buffer(), config->main_stream_field.c_str());
|
|
|
|
put_separator = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( send_all_frames || !send_frames.empty() )
|
|
|
|
{
|
|
|
|
PutSeparatorIfNeeded(put_separator);
|
|
|
|
SerializeFieldJson(config->ezc_frames_field.c_str());
|
|
|
|
output_8bit << "{";
|
|
|
|
|
|
|
|
if( send_all_frames )
|
|
|
|
{
|
|
|
|
SerializeAllFrames();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if( !send_frames.empty() )
|
|
|
|
{
|
|
|
|
SerializeSpecificFrames();
|
|
|
|
}
|
|
|
|
|
|
|
|
output_8bit << "}";
|
|
|
|
put_separator = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Request::PutSeparatorIfNeeded(bool put_separator)
|
|
|
|
{
|
|
|
|
if( put_separator )
|
|
|
|
{
|
|
|
|
switch( container_type )
|
|
|
|
{
|
|
|
|
case Request::ContainerType::container_json:
|
|
|
|
output_8bit << ",";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Request::ContainerType::container_xml:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Request::ContainerType::container_csv:
|
|
|
|
output_8bit << ";";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Request::ContainerType::container_raw:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Request::SerializeFieldJson(const wchar_t * field_name)
|
|
|
|
{
|
|
|
|
if( field_name )
|
|
|
|
{
|
|
|
|
output_8bit << '"';
|
|
|
|
pt::esc_to_json(field_name, output_8bit);
|
|
|
|
output_8bit << "\":";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Request::SerializeStream(const pt::WTextStream & input_stream, const wchar_t * field_name)
|
|
|
|
{
|
|
|
|
switch( container_type )
|
|
|
|
{
|
|
|
|
case Request::ContainerType::container_json:
|
|
|
|
SerializeStreamJson(input_stream, field_name);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Request::ContainerType::container_xml:
|
|
|
|
SerializeStreamXml(input_stream, field_name);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Request::ContainerType::container_csv:
|
|
|
|
SerializeStreamCsv(input_stream, field_name);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Request::ContainerType::container_raw:
|
|
|
|
default:
|
|
|
|
FilterHtmlIfNeeded(input_stream, output_8bit, false);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Request::SerializeStreamJson(const pt::WTextStream & input_stream, const wchar_t * field_name)
|
|
|
|
{
|
|
|
|
SerializeFieldJson(field_name);
|
|
|
|
output_8bit << '"';
|
|
|
|
|
|
|
|
if( config->html_filter && use_html_filter )
|
|
|
|
{
|
|
|
|
TemplatesFunctions::html_filter.filter(input_stream, output_tmp_filtered_stream, true);
|
|
|
|
pt::esc_to_json(output_tmp_filtered_stream, output_8bit);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pt::esc_to_json(input_stream, output_8bit);
|
|
|
|
}
|
|
|
|
|
|
|
|
output_8bit << '"';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Request::SerializeStreamXml(const pt::WTextStream & input_stream, const wchar_t * field_name)
|
|
|
|
{
|
|
|
|
if( field_name )
|
|
|
|
{
|
|
|
|
output_8bit << '<';
|
|
|
|
pt::esc_to_xml(field_name, output_8bit);
|
|
|
|
output_8bit << '>';
|
|
|
|
}
|
|
|
|
|
|
|
|
if( config->html_filter && use_html_filter )
|
|
|
|
{
|
|
|
|
TemplatesFunctions::html_filter.filter(input_stream, output_tmp_filtered_stream, true);
|
|
|
|
pt::esc_to_xml(output_tmp_filtered_stream, output_8bit);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pt::esc_to_xml(input_stream, output_8bit);
|
|
|
|
}
|
|
|
|
|
|
|
|
if( field_name )
|
|
|
|
{
|
|
|
|
output_8bit << "</";
|
|
|
|
pt::esc_to_xml(field_name, output_8bit);
|
|
|
|
output_8bit << '>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Request::SerializeStreamCsv(const pt::WTextStream & input_stream, const wchar_t * field_name)
|
|
|
|
{
|
|
|
|
if( field_name )
|
|
|
|
{
|
|
|
|
output_8bit << '"';
|
|
|
|
pt::esc_to_csv(field_name, output_8bit);
|
|
|
|
output_8bit << "\";";
|
|
|
|
}
|
|
|
|
|
|
|
|
output_8bit << '"';
|
|
|
|
|
|
|
|
if( config->html_filter && use_html_filter )
|
|
|
|
{
|
|
|
|
TemplatesFunctions::html_filter.filter(input_stream, output_tmp_filtered_stream, true);
|
|
|
|
pt::esc_to_csv(output_tmp_filtered_stream, output_8bit);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pt::esc_to_csv(input_stream, output_8bit);
|
|
|
|
}
|
|
|
|
|
|
|
|
output_8bit << "\";\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Request::SerializeAllFrames()
|
|
|
|
{
|
|
|
|
auto i = out_streams.streams_map.begin();
|
|
|
|
bool is_first = true;
|
|
|
|
|
|
|
|
for( ; i != out_streams.streams_map.end() ; ++i)
|
|
|
|
{
|
|
|
|
if( container_type == Request::ContainerType::container_json && !is_first )
|
|
|
|
{
|
|
|
|
output_8bit << ',';
|
|
|
|
}
|
|
|
|
|
|
|
|
if( container_type == Request::ContainerType::container_xml && i->first.empty() )
|
|
|
|
{
|
|
|
|
Log * plog = get_logger();
|
|
|
|
|
|
|
|
if( plog )
|
|
|
|
{
|
|
|
|
(*plog) << log2 << "Request: I cannot serialize a frame with an empty name to xml (frame skipped)" << logend;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SerializeStream(i->second->get_buffer(), i->first.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
is_first = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Request::SerializeSpecificFrames()
|
|
|
|
{
|
|
|
|
bool is_first = true;
|
|
|
|
|
|
|
|
for(std::wstring & frame: send_frames)
|
|
|
|
{
|
|
|
|
auto i = out_streams.streams_map.find(frame);
|
|
|
|
|
|
|
|
if( i != out_streams.streams_map.end() )
|
|
|
|
{
|
|
|
|
if( container_type == Request::ContainerType::container_json && !is_first )
|
|
|
|
{
|
|
|
|
output_8bit << ',';
|
|
|
|
}
|
|
|
|
|
|
|
|
SerializeStream(i->second->get_buffer(), frame.c_str());
|
|
|
|
is_first = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Log * plog = get_logger();
|
|
|
|
|
|
|
|
if( plog )
|
|
|
|
{
|
|
|
|
(*plog) << log2 << "Request: there is no such a frame: " << frame << logend;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Request::SerializeModels()
|
|
|
|
{
|
|
|
|
Ezc::Models::ModelsMap models_map = models.GetMap();
|
|
|
|
auto i = models_map.begin();
|
|
|
|
bool is_first = true;
|
|
|
|
|
|
|
|
for( ; i != models_map.end() ; ++i)
|
|
|
|
{
|
|
|
|
if( container_type == Request::ContainerType::container_json && !is_first )
|
|
|
|
{
|
|
|
|
output_8bit << ',';
|
|
|
|
}
|
|
|
|
|
|
|
|
if( container_type == Request::ContainerType::container_xml && i->first.empty() )
|
|
|
|
{
|
|
|
|
Log * plog = get_logger();
|
|
|
|
|
|
|
|
if( plog )
|
|
|
|
{
|
|
|
|
(*plog) << log2 << "Request: I cannot serialize a model with an empty name to xml (model skipped)" << logend;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SerializeModel(i->second, i->first.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
is_first = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Request::SerializeModel(morm::Wrapper & wrapper, const wchar_t * field_name)
|
|
|
|
{
|
|
|
|
switch( container_type )
|
|
|
|
{
|
|
|
|
case Request::ContainerType::container_json:
|
|
|
|
SerializeModelJson(wrapper, field_name);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Request::ContainerType::container_xml:
|
|
|
|
SerializeModelXml(wrapper, field_name);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Request::ContainerType::container_csv:
|
|
|
|
SerializeModelCsv(wrapper, field_name);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Request::ContainerType::container_raw:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Request::SerializeModelJson(morm::Wrapper & wrapper, const wchar_t * field_name)
|
|
|
|
{
|
|
|
|
SerializeFieldJson(field_name);
|
|
|
|
|
|
|
|
if( wrapper.model )
|
|
|
|
{
|
|
|
|
serialized_model.clear();
|
|
|
|
wrapper.model->set_connector(model_connector);
|
|
|
|
wrapper.model->to_text(serialized_model);
|
|
|
|
output_8bit << serialized_model;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( wrapper.date )
|
|
|
|
{
|
|
|
|
output_8bit << '"';
|
|
|
|
wrapper.date->SerializeISO(output_8bit);
|
|
|
|
output_8bit << '"';
|
|
|
|
}
|
|
|
|
|
|
|
|
if( wrapper.space_wrapper )
|
|
|
|
{
|
|
|
|
wrapper.space_wrapper->get_space()->serialize_to_json_stream(output_8bit, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
if( wrapper.model_container_wrapper )
|
|
|
|
{
|
|
|
|
wrapper.model_container_wrapper->set_iterator_at_first_model();
|
|
|
|
bool is_first = true;
|
|
|
|
output_8bit << '[';
|
|
|
|
|
|
|
|
while( wrapper.model_container_wrapper->is_iterator_correct() )
|
|
|
|
{
|
|
|
|
if( !is_first )
|
|
|
|
output_8bit << ',';
|
|
|
|
|
|
|
|
morm::Model * model = wrapper.model_container_wrapper->get_model();
|
|
|
|
serialized_model.clear();
|
|
|
|
model->set_connector(model_connector);
|
|
|
|
model->to_text(serialized_model);
|
|
|
|
output_8bit << serialized_model;
|
|
|
|
|
|
|
|
wrapper.model_container_wrapper->increment_iterator();
|
|
|
|
is_first = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
output_8bit << ']';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Request::SerializeModelXml(morm::Wrapper & wrapper, const wchar_t * field_name)
|
|
|
|
{
|
|
|
|
// IMPROVEME
|
|
|
|
Log * plog = get_logger();
|
|
|
|
|
|
|
|
if( plog )
|
|
|
|
{
|
|
|
|
(*plog) << log2 << "Request: serializing models to xml not implemented yet" << logend;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Request::SerializeModelCsv(morm::Wrapper & wrapper, const wchar_t * field_name)
|
|
|
|
{
|
|
|
|
// IMPROVEME
|
|
|
|
Log * plog = get_logger();
|
|
|
|
|
|
|
|
if( plog )
|
|
|
|
{
|
|
|
|
(*plog) << log2 << "Request: serializing models to csv not implemented yet" << logend;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// IMPROVEME
|
|
|
|
// gime me a better name
|
|
|
|
void Request::FilterHtmlIfNeeded(const pt::WTextStream & input_stream, BinaryPage & output, bool clear_stream)
|
|
|
|
{
|
|
|
|
if( config->html_filter && use_html_filter )
|
|
|
|
{
|
|
|
|
TemplatesFunctions::html_filter.filter(input_stream, output, clear_stream);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pt::wide_stream_to_utf8(input_stream, output, clear_stream);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Request::Send8bitOutput(BinaryPage & output)
|
|
|
|
{
|
|
|
|
bool compressing = false;
|
|
|
|
int compress_encoding = 0;
|
|
|
|
size_t output_size = 0;
|
|
|
|
Log * plog = get_logger();
|
|
|
|
|
|
|
|
SelectCompression(output.size(), compressing, compress_encoding);
|
|
|
|
|
|
|
|
if( config->log_server_answer )
|
|
|
|
{
|
|
|
|
(*plog) << log1 << "Request: the server's answer is:\n" << output << "\nRequest: end of the server's answer" << logend;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( compressing )
|
|
|
|
{
|
|
|
|
compress->Compressing(output, compressed_output, compress_encoding);
|
|
|
|
output_size = compressed_output.size();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
output_size = output.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
PrepareHeaders(compressing, compress_encoding, output_size);
|
|
|
|
SendHeaders();
|
|
|
|
SendCookies();
|
|
|
|
FCGX_PutS("\r\n", fcgi_request.out);
|
|
|
|
|
|
|
|
if( CanSendContent() )
|
|
|
|
{
|
|
|
|
if( compressing )
|
|
|
|
SendData(compressed_output, fcgi_request.out);
|
|
|
|
else
|
|
|
|
SendData(output, fcgi_request.out);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// IMPROVEME
|
|
|
|
// we can send directly from BinaryPage without copying to a temporary buffer
|
|
|
|
// (but there is no an interface in BinaryPage yet)
|
|
|
|
void Request::SendData(const BinaryPage & page, FCGX_Stream * out)
|
|
|
|
{
|
|
|
|
const size_t buf_size = 4096;
|
|
|
|
|
|
|
|
if( send_data_buf.size() != buf_size )
|
|
|
|
send_data_buf.resize(buf_size);
|
|
|
|
|
|
|
|
BinaryPage::const_iterator i = page.begin();
|
|
|
|
BinaryPage::const_iterator end = page.end();
|
|
|
|
|
|
|
|
while( i != end )
|
|
|
|
{
|
|
|
|
size_t s = 0;
|
|
|
|
|
|
|
|
for( ; i != end && s < buf_size ; ++i, ++s)
|
|
|
|
send_data_buf[s] = *i;
|
|
|
|
|
|
|
|
if( s > 0 )
|
|
|
|
FCGX_PutStr(send_data_buf.c_str(), s, out);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// !! IMPROVE ME change to a better name
|
|
|
|
void Request::UseEzcGenerator()
|
|
|
|
{
|
|
|
|
// if( page_generated || !redirect_to.empty() || !x_sendfile.empty() )
|
|
|
|
// return;
|
|
|
|
|
|
|
|
|
|
|
|
clock_gettime(CLOCK_REALTIME, ×pec_ezc_engine_start);
|
|
|
|
|
|
|
|
templates->SetEzcParameters( gen_trim_white,
|
|
|
|
gen_skip_new_line,
|
|
|
|
gen_use_special_chars);
|
|
|
|
|
|
|
|
templates->Generate();
|
|
|
|
clock_gettime(CLOCK_REALTIME, ×pec_ezc_engine_stop);
|
|
|
|
|
|
|
|
timespec diff;
|
|
|
|
calculate_timespec_diff(timespec_ezc_engine_start, timespec_ezc_engine_stop, diff);
|
|
|
|
|
|
|
|
pt::TextStream str;
|
|
|
|
timespec_to_stream_with_unit(diff, str); // IMPROVEME in the future Log can be used directly
|
|
|
|
|
|
|
|
Log * plog = get_logger();
|
|
|
|
|
|
|
|
if( plog )
|
|
|
|
{
|
|
|
|
(*plog) << log3 << "Request: ezc engine took: " << str << logend;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int Request::SelectDeflateVersion()
|
|
|
|
{
|
|
|
|
if( browser_msie )
|
|
|
|
return 0; // raw deflate
|
|
|
|
else
|
|
|
|
return 1; // deflate
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Request::SelectCompression(size_t source_len, bool & compression_allowed, int & compression_encoding)
|
|
|
|
{
|
|
|
|
compression_allowed = false;
|
|
|
|
compression_encoding = 0;
|
|
|
|
|
|
|
|
if( config->compression &&
|
|
|
|
redirect_to.empty() &&
|
|
|
|
x_sendfile.empty() &&
|
|
|
|
!browser_konqueror && /* IMPROVEME check whether the Konqueror can use deflate algorithm */
|
|
|
|
source_len >= config->compression_page_min_size )
|
|
|
|
{
|
|
|
|
// IMPROVEME put the constants somewhere (1, 2, 10, 20)
|
|
|
|
if( config->compression_encoding == 1 || config->compression_encoding == 10 )
|
|
|
|
{
|
|
|
|
if( accept_deflate )
|
|
|
|
{
|
|
|
|
compression_allowed = true;
|
|
|
|
compression_encoding = SelectDeflateVersion();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if( config->compression_encoding == 10 && accept_gzip )
|
|
|
|
{
|
|
|
|
compression_allowed = true;
|
|
|
|
compression_encoding = 2; // gzip
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( config->compression_encoding == 2 || config->compression_encoding == 20 )
|
|
|
|
{
|
|
|
|
if( accept_gzip )
|
|
|
|
{
|
|
|
|
compression_allowed = true;
|
|
|
|
compression_encoding = 2; // gzip
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if( config->compression_encoding == 20 && accept_deflate )
|
|
|
|
{
|
|
|
|
compression_allowed = true;
|
|
|
|
compression_encoding = SelectDeflateVersion();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Request::PrepareSessionCookie()
|
|
|
|
{
|
|
|
|
SessionManager * session_manager = get_session_manager();
|
|
|
|
|
|
|
|
if( !session || session->id==0 )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if( config->session_cookie_encode )
|
|
|
|
{
|
|
|
|
if( !session_manager->EncodeSessionId(session->id, session->id_index, cookie_id_string) )
|
|
|
|
Toa(session->id, cookie_id_string);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Toa(session->id, cookie_id_string);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if( !session->puser || !session->remember_me )
|
|
|
|
{
|
|
|
|
AddCookie(config->http_session_id_name, cookie_id_string);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pt::Date expires = start_time + config->session_remember_max_idle;
|
|
|
|
AddCookie(config->http_session_id_name, cookie_id_string, expires);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Request::PrepareHeaders(bool compressing, int compress_encoding, size_t output_size)
|
|
|
|
{
|
|
|
|
PrepareSessionCookie();
|
|
|
|
|
|
|
|
if( send_as_attachment )
|
|
|
|
{
|
|
|
|
AddHeader(L"Content-Disposition", L"attachment");
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !redirect_to.empty() )
|
|
|
|
{
|
|
|
|
ModifyStatusForRedirect();
|
|
|
|
AddHeader(L"Location", redirect_to);
|
|
|
|
|
|
|
|
Log * plog = get_logger();
|
|
|
|
|
|
|
|
if( plog )
|
|
|
|
{
|
|
|
|
(*plog) << log2 << "Request: redirect to: " << redirect_to << logend;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if( mount && mount->type == mounts->MountTypeStatic() )
|
|
|
|
{
|
|
|
|
PrepareSendFileHeaderForStaticMountpoint();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if( !x_sendfile.empty() )
|
|
|
|
{
|
|
|
|
PrepareSendFileHeader();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PrepareContentLengthHeader(output_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
if( compressing )
|
|
|
|
{
|
|
|
|
PrepareContentEncodingHeader(compress_encoding);
|
|
|
|
}
|
|
|
|
|
|
|
|
PrepareHeaderStatus(http_status);
|
|
|
|
PrepareHeaderContentType();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool Request::AddHeader(const wchar_t * name, const wchar_t * value)
|
|
|
|
{
|
|
|
|
if( !out_headers.has_key(name) )
|
|
|
|
{
|
|
|
|
out_headers.add(name, value);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Request::AddHeader(const std::wstring & name, const std::wstring & value)
|
|
|
|
{
|
|
|
|
if( !out_headers.has_key(name) )
|
|
|
|
{
|
|
|
|
out_headers.add(name, value);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Request::AddHeader(const wchar_t * name, const pt::WTextStream & value)
|
|
|
|
{
|
|
|
|
if( !out_headers.has_key(name) )
|
|
|
|
{
|
|
|
|
out_headers.add_stream(name, value);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Request::AddHeader(const std::wstring & name, const pt::WTextStream & value)
|
|
|
|
{
|
|
|
|
if( !out_headers.has_key(name) )
|
|
|
|
{
|
|
|
|
out_headers.add_stream(name, value);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Request::PrepareSendFileHeaderForStaticMountpoint()
|
|
|
|
{
|
|
|
|
Log * plog = get_logger();
|
|
|
|
|
|
|
|
if( mount )
|
|
|
|
{
|
|
|
|
if( PathHasUpDir(env_request_uri) )
|
|
|
|
{
|
|
|
|
if( plog )
|
|
|
|
{
|
|
|
|
(*plog) << log1 << "Request: incorrect path for a static file" << logend;
|
|
|
|
}
|
|
|
|
|
|
|
|
http_status = Header::status_403_forbidden;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::wstring & index_str = mount->FirstArg(mounts->MountParStatic());
|
|
|
|
size_t index = Toi(index_str);
|
|
|
|
|
|
|
|
if( index >= config->static_dirs.size() )
|
|
|
|
{
|
|
|
|
if( plog )
|
|
|
|
{
|
|
|
|
(*plog) << log1 << "Request: static dir with index " << index << " is not defined in the config" << logend;
|
|
|
|
}
|
|
|
|
|
|
|
|
http_status = Header::status_403_forbidden;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
pt::WTextStream path;
|
|
|
|
path << config->static_dirs[index] << L"/";
|
|
|
|
|
|
|
|
if( !CreateStaticResourcePath(path) )
|
|
|
|
{
|
|
|
|
http_status = Header::status_403_forbidden;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FIX ME now we can send full path (apache, lighttpd) and relative path (nginx)
|
|
|
|
* but this feature for mounting static content probably will be removed
|
|
|
|
*/
|
|
|
|
if( AddHeader(config->send_file_header, path) )
|
|
|
|
{
|
|
|
|
if( plog )
|
|
|
|
{
|
|
|
|
(*plog) << log2 << "Request: sending a file from a static mountpoint: " << path << logend;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Request::PrepareSendFileHeader()
|
|
|
|
{
|
|
|
|
Log * plog = get_logger();
|
|
|
|
|
|
|
|
if( AddHeader(config->send_file_header, x_sendfile) )
|
|
|
|
{
|
|
|
|
if( plog )
|
|
|
|
{
|
|
|
|
(*plog) << log2 << "Request: sending file: " << x_sendfile << logend;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Request::PrepareContentEncodingHeader(int compress_encoding)
|
|
|
|
{
|
|
|
|
if( compress_encoding == 0 || compress_encoding == 1 )
|
|
|
|
{
|
|
|
|
AddHeader(L"Content-Encoding", L"deflate");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
AddHeader(L"Content-Encoding", L"gzip");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Request::PrepareContentLengthHeader(size_t output_size)
|
|
|
|
{
|
|
|
|
if( output_size != static_cast<size_t>(-1) )
|
|
|
|
{
|
|
|
|
pt::WTextStream buf;
|
|
|
|
buf << output_size;
|
|
|
|
AddHeader(L"Content-Length", buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Request::PrepareHeaderContentType()
|
|
|
|
{
|
|
|
|
if( !out_headers.has_key(Winix::Header::content_type) )
|
|
|
|
{
|
|
|
|
if( container_type == Request::ContainerType::container_json )
|
|
|
|
{
|
|
|
|
out_headers.add(Winix::Header::content_type, Winix::Header::application_json_utf8);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if( container_type == Request::ContainerType::container_xml )
|
|
|
|
{
|
|
|
|
out_headers.add(Winix::Header::content_type, Winix::Header::application_xml_utf8);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if( container_type == Request::ContainerType::container_csv )
|
|
|
|
{
|
|
|
|
out_headers.add(Winix::Header::content_type, Winix::Header::text_csv_utf8);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if( container_type == Request::ContainerType::container_raw )
|
|
|
|
{
|
|
|
|
if( send_bin_stream )
|
|
|
|
{
|
|
|
|
out_headers.add(Winix::Header::content_type, Winix::Header::application_octet_stream);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switch( config->content_type_header )
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
out_headers.add(Winix::Header::content_type, Winix::Header::application_xhtml_xml_utf8);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
out_headers.add(Winix::Header::content_type, Winix::Header::application_xml_utf8);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0:
|
|
|
|
default:
|
|
|
|
out_headers.add(Winix::Header::content_type, Winix::Header::text_html_utf8);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Request::PrepareHeaderStatus(int http_status)
|
|
|
|
{
|
|
|
|
pt::WTextStream value;
|
|
|
|
Header::prepare_status_value(http_status, value, false);
|
|
|
|
AddHeader(L"Status", value);
|
|
|
|
|
|
|
|
Log * plog = get_logger();
|
|
|
|
|
|
|
|
if( plog )
|
|
|
|
{
|
|
|
|
(*plog) << log2 << "Request: http status: " << value << logend;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// we can improve SendHeaders and SendCookies methods by checking
|
|
|
|
// whether there is a new line character in either a name or a value
|
|
|
|
// and if such character exists and is being sent to the client it breaks the http headers and content
|
|
|
|
// and if compression is enabled the client's browser will not be able to decompress the stream
|
|
|
|
void Request::SendHeaders()
|
|
|
|
{
|
|
|
|
pt::Space::ObjectType::iterator i;
|
|
|
|
pt::Space & headers = out_headers;
|
|
|
|
Log * plog = get_logger();
|
|
|
|
|
|
|
|
if( headers.is_object() )
|
|
|
|
{
|
|
|
|
plugin->Call(WINIX_PREPARE_TO_SEND_HTTP_HEADERS, &headers);
|
|
|
|
|
|
|
|
for(i=headers.value.value_object.begin() ; i != headers.value.value_object.end() ; ++i)
|
|
|
|
{
|
|
|
|
if( i->second->is_wstr() )
|
|
|
|
{
|
2022-08-11 08:04:40 +02:00
|
|
|
pt::wide_to_utf8(i->first, aheader_name);
|
2022-07-25 14:21:21 +02:00
|
|
|
pt::wide_to_utf8(*i->second->get_wstr(), aheader_value);
|
|
|
|
|
|
|
|
FCGX_PutS(aheader_name.c_str(), fcgi_request.out);
|
|
|
|
FCGX_PutS(": ", fcgi_request.out);
|
|
|
|
FCGX_PutS(aheader_value.c_str(), fcgi_request.out);
|
|
|
|
FCGX_PutS("\r\n", fcgi_request.out);
|
|
|
|
|
|
|
|
if( config->log_http_answer_headers && plog )
|
|
|
|
(*plog) << log1 << "HTTP Header: " << aheader_name << ": " << aheader_value << logend;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( plog )
|
|
|
|
{
|
|
|
|
(*plog) << log2 << "Skipping HTTP Header: " << i->first << " - it's not a wstr" << logend;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Request::SendCookies()
|
|
|
|
{
|
|
|
|
pt::Space::ObjectType::iterator i;
|
|
|
|
pt::Space & cookies = out_cookies;
|
|
|
|
Log * plog = get_logger();
|
|
|
|
|
|
|
|
if( cookies.is_object() )
|
|
|
|
{
|
|
|
|
plugin->Call(WINIX_PREPARE_TO_SEND_HTTP_COOKIES, &cookies);
|
|
|
|
|
|
|
|
for(i=cookies.value.value_object.begin() ; i != cookies.value.value_object.end() ; ++i)
|
|
|
|
{
|
|
|
|
if( i->second->is_wstr() )
|
|
|
|
{
|
|
|
|
pt::wide_to_utf8(i->first, aheader_name);
|
|
|
|
pt::wide_to_utf8(*i->second->get_wstr(), aheader_value);
|
|
|
|
|
|
|
|
FCGX_PutS("Set-Cookie: ", fcgi_request.out);
|
|
|
|
FCGX_PutS(aheader_name.c_str(), fcgi_request.out);
|
|
|
|
FCGX_PutS("=", fcgi_request.out);
|
|
|
|
FCGX_PutS(aheader_value.c_str(), fcgi_request.out);
|
|
|
|
FCGX_PutS("\r\n", fcgi_request.out);
|
|
|
|
|
|
|
|
if( config->log_http_answer_headers && plog )
|
|
|
|
(*plog) << log1 << "HTTP Header: Set-Cookie: " << aheader_name << "=" << aheader_value << logend;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( plog )
|
|
|
|
{
|
|
|
|
(*plog) << log2 << "Skipping Cookie: " << i->first << " - it's not a wstr" << logend;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool Request::CreateStaticResourcePath(pt::WTextStream & out_path)
|
|
|
|
{
|
|
|
|
bool status = false;
|
|
|
|
size_t i = 0;
|
|
|
|
Log * plog = get_logger();
|
|
|
|
Dirs * dirs = get_dirs();
|
|
|
|
|
|
|
|
if( dirs && mount )
|
|
|
|
{
|
|
|
|
Item * dir = dirs->GetDir(mount->dir_id);
|
|
|
|
|
|
|
|
if( dir )
|
|
|
|
{
|
|
|
|
size_t how_many_dirs = dirs->DirLevel(dir->id);
|
|
|
|
const wchar_t * path = SkipDirs(env_request_uri.c_str(), how_many_dirs);
|
|
|
|
|
|
|
|
// the path begins with a slash only if how_many_dirs is zero
|
|
|
|
while( *path == '/' )
|
|
|
|
path += 1;
|
|
|
|
|
|
|
|
while( path[i]!=0 && path[i]!='?' && path[i]!='#' )
|
|
|
|
++i;
|
|
|
|
|
|
|
|
if( i > 0 )
|
|
|
|
out_path.write(path, i);
|
|
|
|
|
|
|
|
status = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( plog )
|
|
|
|
{
|
|
|
|
(*plog) << log1 << "Request: cannot find the mount directory" << logend;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Request::CanSendContent()
|
|
|
|
{
|
|
|
|
if( !x_sendfile.empty() )
|
|
|
|
{
|
|
|
|
// if there is a file to send then we do not send a content
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !redirect_to.empty() )
|
|
|
|
{
|
|
|
|
// if there is a redirect and no json is requred then we do not send the content
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-08-11 08:04:40 +02:00
|
|
|
if( method == Request::head || method == Request::options )
|
2022-07-25 14:21:21 +02:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Request::LogRequestTime()
|
|
|
|
{
|
|
|
|
pt::TextStream str;
|
|
|
|
timespec_to_stream_with_unit(timespec_req_diff, str);
|
|
|
|
|
|
|
|
Log * plog = get_logger();
|
|
|
|
|
|
|
|
if( plog )
|
|
|
|
{
|
|
|
|
(*plog) << log2 << "Request: request took: " << str << logend;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Request::FinishRequest()
|
|
|
|
{
|
|
|
|
modify_status_code_if_needed(); // will be removed
|
2022-08-11 08:04:40 +02:00
|
|
|
PrepareAndSendAnswer();
|
2022-07-25 14:21:21 +02:00
|
|
|
RequestEnds();
|
|
|
|
LogRequestTime();
|
|
|
|
|
|
|
|
if( session )
|
|
|
|
{
|
|
|
|
session->allow_to_delete = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( plugin )
|
|
|
|
{
|
|
|
|
plugin->Call(WINIX_END_REQUEST, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
run_state = RunState::finished;
|
|
|
|
FCGX_Finish_r(&fcgi_request);
|
|
|
|
|
|
|
|
if( templates )
|
|
|
|
{
|
|
|
|
templates->ClearAfterRequest();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-12 17:30:49 +01:00
|
|
|
} // namespace Winix
|
|
|
|
|
|
|
|
|
2008-12-21 22:17:09 +01:00
|
|
|
|