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.
This commit is contained in:
@@ -37,6 +37,7 @@
|
||||
#include "plugin.h"
|
||||
#include "misc.h"
|
||||
#include "functions/functionbase.h"
|
||||
#include "templates/templates.h"
|
||||
|
||||
|
||||
namespace Winix
|
||||
@@ -57,8 +58,12 @@ void Request::fields()
|
||||
{
|
||||
field(L"", L"dirs", dir_tab);
|
||||
field(L"", L"is_item", is_item);
|
||||
field(L"", L"http_status", http_status);
|
||||
|
||||
field(L"", L"current_dir", &Request::current_dir);
|
||||
field(L"", L"last_item", &Request::last_item_wrapper);
|
||||
field(L"", L"http_status_error_title", &Request::http_status_error_title);
|
||||
field(L"", L"http_status_error_description", &Request::http_status_error_description);
|
||||
}
|
||||
|
||||
|
||||
@@ -101,11 +106,9 @@ void Request::Clear()
|
||||
if( function )
|
||||
function->Clear();
|
||||
|
||||
post_tab.clear();
|
||||
post_file_tab.clear();
|
||||
cookie_tab.clear();
|
||||
post_in.clear();
|
||||
is_postin_used = false;
|
||||
|
||||
method = unknown_method;
|
||||
|
||||
@@ -148,6 +151,7 @@ void Request::Clear()
|
||||
container_type = ContainerType::container_raw;
|
||||
|
||||
status = WINIX_ERR_OK;
|
||||
http_status = Header::status_200_ok;
|
||||
|
||||
browser_msie = false;
|
||||
redirect_to.clear();
|
||||
@@ -360,122 +364,130 @@ void Request::PrepareFrameNames()
|
||||
}
|
||||
}
|
||||
|
||||
// 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();
|
||||
|
||||
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 )
|
||||
{
|
||||
(*log) << log1 << "App: more than " << WINIX_POSTTABLE_VALUT_TABLE_MAXSIZE << " post variables in a table " << name << " (skipping)" << logend;
|
||||
}
|
||||
}
|
||||
}
|
||||
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 )
|
||||
{
|
||||
(*log) << log1 << "App: more than " << WINIX_POSTTABLE_MAXSIZE << " post variables (skipping)" << logend;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
bool Request::AddPostVar(const std::wstring & name, const std::wstring & value)
|
||||
{
|
||||
return AddPostVar(name.c_str(), value.c_str());
|
||||
}
|
||||
|
||||
|
||||
bool Request::IsPostVar(const wchar_t * var)
|
||||
{
|
||||
PostTab::iterator p;
|
||||
|
||||
p = post_tab.find(var);
|
||||
|
||||
if( p == post_tab.end() )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
return post_in.has_key(var);
|
||||
}
|
||||
|
||||
|
||||
bool Request::IsPostVar(const std::wstring & var)
|
||||
{
|
||||
PostTab::iterator p;
|
||||
|
||||
p = post_tab.find(var);
|
||||
|
||||
if( p == post_tab.end() )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
return post_in.has_key(var);
|
||||
}
|
||||
|
||||
|
||||
const std::wstring & Request::PostVar(const wchar_t * var)
|
||||
{
|
||||
PostTab::iterator p = post_tab.find(var);
|
||||
|
||||
if( p == post_tab.end() )
|
||||
return str_empty;
|
||||
|
||||
return p->second;
|
||||
std::wstring * value = post_in.get_wstr(var);
|
||||
|
||||
if( value )
|
||||
return *value;
|
||||
|
||||
return str_empty;
|
||||
}
|
||||
|
||||
|
||||
const std::wstring & Request::PostVar(const std::wstring & var)
|
||||
{
|
||||
PostTab::iterator p = post_tab.find(var);
|
||||
|
||||
if( p == post_tab.end() )
|
||||
return str_empty;
|
||||
|
||||
return p->second;
|
||||
return PostVar(var.c_str());
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool Request::PostVar(const wchar_t * var, std::wstring & result)
|
||||
{
|
||||
PostTab::iterator p = post_tab.find(var);
|
||||
|
||||
if( p == post_tab.end() )
|
||||
std::wstring * value = post_in.get_wstr(var);
|
||||
bool found = false;
|
||||
|
||||
if( value )
|
||||
{
|
||||
result = *value;
|
||||
found = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
result.clear();
|
||||
return false;
|
||||
}
|
||||
|
||||
result = p->second;
|
||||
|
||||
return true;
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
|
||||
bool Request::PostVar(const std::wstring & var, std::wstring & result)
|
||||
{
|
||||
PostTab::iterator p = post_tab.find(var);
|
||||
|
||||
if( p == post_tab.end() )
|
||||
{
|
||||
result.clear();
|
||||
return false;
|
||||
}
|
||||
|
||||
result = p->second;
|
||||
|
||||
return true;
|
||||
return PostVar(var.c_str(), result);
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::wstring * Request::PostVarp(const wchar_t * var)
|
||||
{
|
||||
PostTab::iterator p = post_tab.find(var);
|
||||
|
||||
if( p == post_tab.end() )
|
||||
return 0;
|
||||
|
||||
return &p->second;
|
||||
return post_in.get_wstr(var);
|
||||
}
|
||||
|
||||
|
||||
std::wstring * Request::PostVarp(const std::wstring & var)
|
||||
{
|
||||
PostTab::iterator p = post_tab.find(var);
|
||||
|
||||
if( p == post_tab.end() )
|
||||
return 0;
|
||||
|
||||
return &p->second;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
bool Request::AllPostVarEmpty()
|
||||
{
|
||||
PostTab::iterator i;
|
||||
|
||||
for(i=post_tab.begin() ; i!=post_tab.end() ; ++i)
|
||||
if( !i->second.empty() )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
return post_in.get_wstr(var.c_str());
|
||||
}
|
||||
|
||||
|
||||
@@ -541,6 +553,7 @@ const std::wstring & Request::ParamValue(const std::wstring & param_name)
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Request::AddParam(const std::wstring & param_name, const std::wstring & param_value)
|
||||
{
|
||||
bool found = false;
|
||||
@@ -663,6 +676,24 @@ bool Request::has_frame(const std::wstring & frame)
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Winix
|
||||
|
Reference in New Issue
Block a user