add Request::AddPostVar(pt::Space & space, const wchar_t * name)

This commit is contained in:
Tomasz Sowa 2022-08-22 16:03:07 +02:00
parent 5f77ce619e
commit d3a440fa0a
3 changed files with 28 additions and 14 deletions

View File

@ -418,45 +418,44 @@ void Request::PrepareFrameNames()
} }
} }
// add such a method to Space // add such a method to Space
bool Request::AddPostVar(const wchar_t * name, const wchar_t * value) pt::Space * Request::AddPostVar(pt::Space & space, const wchar_t * name)
{ {
bool status = false; pt::Space * space_value = space.get_space(name);
pt::Space * space_value = post_in.get_space(name); pt::Space * new_space = nullptr;
Log * log = get_logger(); Log * log = get_logger();
if( space_value ) if( space_value )
{ {
if( space_value->is_table() ) if( space_value->is_table() )
{ {
if( space_value->table_size() < WINIX_POSTTABLE_VALUT_TABLE_MAXSIZE ) if( space_value->table_size() < WINIX_POSTTABLE_VALUE_TABLE_MAXSIZE )
{ {
status = true; new_space = &space_value->add_empty_space();
space_value->add(value);
} }
else else
{ {
if( log ) if( log )
{ {
(*log) << log1 << "Request: more than " << WINIX_POSTTABLE_VALUT_TABLE_MAXSIZE << " post variables in a table " << name << " (skipping)" << logend; (*log) << log1 << "Request: more than " << WINIX_POSTTABLE_VALUE_TABLE_MAXSIZE << " post variables in a table " << name << " (skipping)" << logend;
} }
} }
} }
else else
{ {
status = true;
pt::Space new_table; pt::Space new_table;
new_table.add(std::move(*space_value)); new_table.add(std::move(*space_value));
new_table.add(value); new_space = &new_table.add_empty_space();
space_value->set(std::move(new_table)); space_value->set(std::move(new_table));
} }
} }
else else
{ {
if( post_in.object_size() < WINIX_POSTTABLE_MAXSIZE ) if( space.object_size() < WINIX_POSTTABLE_MAXSIZE )
{ {
post_in.add(name, value); new_space = &space.add_empty_space(name);
status = true;
} }
else else
{ {
@ -467,7 +466,21 @@ bool Request::AddPostVar(const wchar_t * name, const wchar_t * value)
} }
} }
return status; return new_space;
}
bool Request::AddPostVar(const wchar_t * name, const wchar_t * value)
{
pt::Space * new_space = AddPostVar(post_in, name);
if( new_space )
{
new_space->set(value);
}
return new_space != nullptr;
} }

View File

@ -481,6 +481,7 @@ public:
void RemoveParam(const wchar_t * param_name); void RemoveParam(const wchar_t * param_name);
void RemoveParam(const std::wstring & param_name); void RemoveParam(const std::wstring & param_name);
pt::Space * AddPostVar(pt::Space & space, const wchar_t * name);
bool AddPostVar(const wchar_t * name, const wchar_t * value); bool AddPostVar(const wchar_t * name, const wchar_t * value);
bool AddPostVar(const std::wstring & name, const std::wstring & value); bool AddPostVar(const std::wstring & name, const std::wstring & value);

View File

@ -47,7 +47,7 @@ namespace Winix
// may move to config? // may move to config?
#define WINIX_POSTTABLE_MAXSIZE 1024 #define WINIX_POSTTABLE_MAXSIZE 1024
#define WINIX_POSTTABLE_VALUT_TABLE_MAXSIZE 1024 #define WINIX_POSTTABLE_VALUE_TABLE_MAXSIZE 1024
struct PostFile struct PostFile