updated to the new Pikotools api (new Space struct)
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2010-2019, Tomasz Sowa
|
||||
* Copyright (c) 2010-2021, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -504,6 +504,14 @@ void App::ProcessRequestThrow()
|
||||
{
|
||||
functions.Parse(); // parsing directories, files, functions and parameters
|
||||
|
||||
/*
|
||||
* set global connector for now
|
||||
* in the future each thread will have its own model_connector
|
||||
*
|
||||
* don't set connector for item_tab - it will be moved out from request
|
||||
*/
|
||||
cur.request->item.set_connector(model_connector);
|
||||
|
||||
if( !cur.request->dir_tab.empty() )
|
||||
{
|
||||
cur.mount = system.mounts.CalcCurMount();
|
||||
@@ -625,6 +633,8 @@ void App::ClearAfterRequest()
|
||||
system.mounts.pmount = cur.mount; // IMPROVE ME system.mounts.pmount will be removed
|
||||
// send_data_buf doesn't have to be cleared and it is better to not clear it (optimizing)
|
||||
|
||||
cur.request->item.set_connector(nullptr);
|
||||
|
||||
log << logendrequest;
|
||||
}
|
||||
catch(...)
|
||||
@@ -700,16 +710,7 @@ void App::CreateJSONAnswer()
|
||||
json_out_stream << L"}\n,\n\"info\": ";
|
||||
}
|
||||
|
||||
if( req.info_serializer )
|
||||
{
|
||||
req.info_serializer->Serialize(req.info, json_out_stream, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
json_out_stream << L"{}";
|
||||
log << log1 << "App: Request::info_serializer not defined" << logend;
|
||||
}
|
||||
|
||||
req.info.serialize_to_json_stream(json_out_stream, false);
|
||||
log << log3 << "App: sending JSON answer";
|
||||
|
||||
if( !req.return_info_only )
|
||||
@@ -831,16 +832,19 @@ void App::LogEnvironmentVariables()
|
||||
|
||||
void App::LogEnvironmentHTTPVariables()
|
||||
{
|
||||
PT::Space::Table::iterator i = cur.request->headers_in.table.begin();
|
||||
|
||||
for( ; i != cur.request->headers_in.table.end() ; ++i)
|
||||
if( cur.request->headers_in.is_object() )
|
||||
{
|
||||
log << log1 << "HTTP Env: " << i->first << "=";
|
||||
PT::Space::ObjectType::iterator i = cur.request->headers_in.value.value_object.begin();
|
||||
|
||||
if( i->second.size() == 1 )
|
||||
log << i->second[0] << logend;
|
||||
else
|
||||
log << "(incorrect value table size, should be one but is " << i->second.size() << ")" << logend;
|
||||
for( ; i != cur.request->headers_in.value.value_object.end() ; ++i)
|
||||
{
|
||||
log << log1 << "HTTP Env: " << i->first << "=";
|
||||
|
||||
if( i->second->is_wstr() )
|
||||
log << *i->second->get_wstr() << logend;
|
||||
else
|
||||
log << "(incorrect value type, expected wstr)" << logend;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -983,11 +987,12 @@ bool App::SaveEnvHTTPVariable(const char * env)
|
||||
return false;
|
||||
}
|
||||
|
||||
PT::UTF8ToWide(header_name, http_header);
|
||||
PT::UTF8ToWide(header_name, http_header_name);
|
||||
PT::UTF8ToWide(header_value, http_header_value);
|
||||
|
||||
std::wstring & inserted_header = cur.request->headers_in.Add(http_header, L"", true);
|
||||
PT::UTF8ToWide(header_value, inserted_header);
|
||||
http_header.clear();
|
||||
cur.request->headers_in.add(http_header_name, http_header_value);
|
||||
http_header_name.clear();
|
||||
http_header_value.clear();
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -999,11 +1004,11 @@ void App::ReadEnvRemoteIP()
|
||||
|
||||
if( config.check_proxy_ip_header )
|
||||
{
|
||||
http_header = L"HTTP_";
|
||||
http_header += config.proxy_ip_header;
|
||||
PT::ToUpper(http_header);
|
||||
http_header_name = L"HTTP_";
|
||||
http_header_name += config.proxy_ip_header;
|
||||
PT::ToUpper(http_header_name);
|
||||
|
||||
PT::WideToUTF8(http_header, http_header_8bit);
|
||||
PT::WideToUTF8(http_header_name, http_header_8bit);
|
||||
v = FCGX_GetParam(http_header_8bit.c_str(), fcgi_request.envp);
|
||||
}
|
||||
else
|
||||
@@ -1087,7 +1092,7 @@ void App::ReadPostJson()
|
||||
const int buffer_len = sizeof(buffer) / sizeof(char) - 1;
|
||||
int read_len;
|
||||
|
||||
post_json_parser.SetSpace(cur.request->post_in);
|
||||
space_parser.SetSpace(cur.request->post_in);
|
||||
post_buffer.clear();
|
||||
post_buffer.reserve(1024 * 1024 * 5); // IMPROVEME add to config?
|
||||
|
||||
@@ -1106,13 +1111,17 @@ void App::ReadPostJson()
|
||||
|
||||
if( !post_buffer.empty() )
|
||||
{
|
||||
PT::JSONToSpaceParser::Status status = post_json_parser.ParseString(post_buffer.c_str());
|
||||
PT::SpaceParser::Status status = space_parser.ParseJSON(post_buffer.c_str());
|
||||
post_buffer.clear();
|
||||
|
||||
if( status != PT::JSONToSpaceParser::ok )
|
||||
if( status != PT::SpaceParser::ok )
|
||||
{
|
||||
log << log1 << "App: cannot parse the input stream as a JSON object, status: " << (int)status << logend;
|
||||
cur.request->post_in.Clear();
|
||||
log << log1 << "App: cannot parse the input stream as an JSON object";
|
||||
|
||||
if( status == PT::SpaceParser::syntax_error )
|
||||
log << ", syntax error in line: " << space_parser.get_last_parsed_line() << logend;
|
||||
|
||||
cur.request->post_in.clear();
|
||||
// return an error (http error of some kind?)
|
||||
}
|
||||
}
|
||||
@@ -1202,9 +1211,9 @@ void App::PrepareSessionCookie()
|
||||
|
||||
bool App::AddHeader(const wchar_t * name, const wchar_t * value)
|
||||
{
|
||||
if( !cur.request->out_headers.GetValue(name) )
|
||||
if( !cur.request->out_headers.has_key(name) )
|
||||
{
|
||||
cur.request->out_headers.Add(name, value);
|
||||
cur.request->out_headers.add(name, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1214,9 +1223,9 @@ return false;
|
||||
|
||||
bool App::AddHeader(const std::wstring & name, const std::wstring & value)
|
||||
{
|
||||
if( !cur.request->out_headers.GetValue(name) )
|
||||
if( !cur.request->out_headers.has_key(name) )
|
||||
{
|
||||
cur.request->out_headers.Add(name, value);
|
||||
cur.request->out_headers.add(name, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1226,9 +1235,9 @@ return false;
|
||||
|
||||
bool App::AddHeader(const wchar_t * name, const PT::WTextStream & value)
|
||||
{
|
||||
if( !cur.request->out_headers.GetValue(name) )
|
||||
if( !cur.request->out_headers.has_key(name) )
|
||||
{
|
||||
cur.request->out_headers.Add(name, value);
|
||||
cur.request->out_headers.add_stream(name, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1238,9 +1247,9 @@ return false;
|
||||
|
||||
bool App::AddHeader(const std::wstring & name, const PT::WTextStream & value)
|
||||
{
|
||||
if( !cur.request->out_headers.GetValue(name) )
|
||||
if( !cur.request->out_headers.has_key(name) )
|
||||
{
|
||||
cur.request->out_headers.Add(name, value);
|
||||
cur.request->out_headers.add_stream(name, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1313,34 +1322,29 @@ void App::PrepareHeadersStatic()
|
||||
|
||||
void App::PrepareHeaderContentType()
|
||||
{
|
||||
std::wstring * value = 0;
|
||||
|
||||
if( !cur.request->out_headers.GetValue(L"Content-Type") )
|
||||
if( !cur.request->out_headers.has_key(L"Content-Type") )
|
||||
{
|
||||
if( cur.request->return_json )
|
||||
{
|
||||
value = &cur.request->out_headers.Add(L"Content-Type", L"application/json");
|
||||
cur.request->out_headers.add(L"Content-Type", L"application/json; charset=UTF-8");
|
||||
}
|
||||
else
|
||||
{
|
||||
switch( config.content_type_header )
|
||||
{
|
||||
case 1:
|
||||
value = &cur.request->out_headers.Add(L"Content-Type", L"application/xhtml+xml");
|
||||
cur.request->out_headers.add(L"Content-Type", L"application/xhtml+xml; charset=UTF-8");
|
||||
break;
|
||||
|
||||
case 2:
|
||||
value = &cur.request->out_headers.Add(L"Content-Type", L"application/xml");
|
||||
cur.request->out_headers.add(L"Content-Type", L"application/xml; charset=UTF-8");
|
||||
break;
|
||||
|
||||
case 0:
|
||||
default:
|
||||
value = &cur.request->out_headers.Add(L"Content-Type", L"text/html");
|
||||
cur.request->out_headers.add(L"Content-Type", L"text/html; charset=UTF-8");
|
||||
}
|
||||
}
|
||||
|
||||
if( value )
|
||||
*value += L"; charset=UTF-8";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1435,25 +1439,32 @@ void App::PrepareHeadersNormal(Header header, size_t output_size)
|
||||
// and if compression is enabled the client's browser will not be able to decompress the stream
|
||||
void App::SendHeaders()
|
||||
{
|
||||
PT::Space::Table::iterator i;
|
||||
PT::Space::ObjectType::iterator i;
|
||||
PT::Space & headers = cur.request->out_headers;
|
||||
|
||||
plugin.Call(WINIX_PREPARE_TO_SEND_HTTP_HEADERS, &headers);
|
||||
|
||||
for(i=headers.table.begin() ; i != headers.table.end() ; ++i)
|
||||
if( headers.is_object() )
|
||||
{
|
||||
if( i->second.size() == 1 )
|
||||
plugin.Call(WINIX_PREPARE_TO_SEND_HTTP_HEADERS, &headers);
|
||||
|
||||
for(i=headers.value.value_object.begin() ; i != headers.value.value_object.end() ; ++i)
|
||||
{
|
||||
PT::WideToUTF8(i->first, aheader_name);
|
||||
PT::WideToUTF8(i->second[0], aheader_value);
|
||||
if( i->second->is_wstr() )
|
||||
{
|
||||
PT::WideToUTF8(i->first, aheader_name);
|
||||
PT::WideToUTF8(*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);
|
||||
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 )
|
||||
log << log1 << "HTTP Header: " << aheader_name << ": " << aheader_value << logend;
|
||||
if( config.log_http_answer_headers )
|
||||
log << log1 << "HTTP Header: " << aheader_name << ": " << aheader_value << logend;
|
||||
}
|
||||
else
|
||||
{
|
||||
log << log2 << "Skipping HTTP Header: " << i->first << " - it's not a wstr" << logend;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1462,26 +1473,33 @@ void App::SendHeaders()
|
||||
|
||||
void App::SendCookies()
|
||||
{
|
||||
PT::Space::Table::iterator i;
|
||||
PT::Space::ObjectType::iterator i;
|
||||
PT::Space & cookies = cur.request->out_cookies;
|
||||
|
||||
plugin.Call(WINIX_PREPARE_TO_SEND_HTTP_COOKIES, &cookies);
|
||||
|
||||
for(i=cookies.table.begin() ; i != cookies.table.end() ; ++i)
|
||||
if( cookies.is_object() )
|
||||
{
|
||||
if( i->second.size() == 1 )
|
||||
plugin.Call(WINIX_PREPARE_TO_SEND_HTTP_COOKIES, &cookies);
|
||||
|
||||
for(i=cookies.value.value_object.begin() ; i != cookies.value.value_object.end() ; ++i)
|
||||
{
|
||||
PT::WideToUTF8(i->first, aheader_name);
|
||||
PT::WideToUTF8(i->second[0], aheader_value);
|
||||
if( i->second->is_wstr() )
|
||||
{
|
||||
PT::WideToUTF8(i->first, aheader_name);
|
||||
PT::WideToUTF8(*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);
|
||||
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 )
|
||||
log << log1 << "HTTP Header: Set-Cookie: " << aheader_name << "=" << aheader_value << logend;
|
||||
if( config.log_http_answer_headers )
|
||||
log << log1 << "HTTP Header: Set-Cookie: " << aheader_name << "=" << aheader_value << logend;
|
||||
}
|
||||
else
|
||||
{
|
||||
log << log2 << "Skipping Cookie: " << i->first << " - it's not a wstr" << logend;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1522,14 +1540,14 @@ void App::PrepareStandardJSONFields()
|
||||
{
|
||||
PT::Space & info = cur.request->info;
|
||||
|
||||
if( !info.GetFirstValue(L"status") )
|
||||
if( !info.has_key(L"status") )
|
||||
{
|
||||
info.Add(L"status", cur.request->status);
|
||||
info.add(L"status", cur.request->status);
|
||||
}
|
||||
|
||||
if( !cur.request->redirect_to.empty() && !info.GetFirstValue(L"redirect_to") )
|
||||
if( !cur.request->redirect_to.empty() && !info.has_key(L"redirect_to") )
|
||||
{
|
||||
info.Add(L"redirect_to", cur.request->redirect_to);
|
||||
info.add(L"redirect_to", cur.request->redirect_to);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1824,12 +1842,6 @@ int compress_encoding;
|
||||
|
||||
void App::SendAnswer()
|
||||
{
|
||||
if( !cur.request->info_serializer )
|
||||
{
|
||||
json_generic_serializer.Clear(); // !! IMPROVE ME add to the end of a request
|
||||
cur.request->info_serializer = &json_generic_serializer;
|
||||
}
|
||||
|
||||
if( cur.request->return_json )
|
||||
PrepareStandardJSONFields();
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2010-2018, Tomasz Sowa
|
||||
* Copyright (c) 2010-2021, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -54,7 +54,6 @@
|
||||
#include "cookieparser.h"
|
||||
#include "postmultiparser.h"
|
||||
#include "acceptencodingparser.h"
|
||||
#include "space/jsontospaceparser.h"
|
||||
|
||||
#include "winixrequest.h"
|
||||
#include "log/log.h"
|
||||
@@ -144,7 +143,7 @@ private:
|
||||
|
||||
PostParser post_parser;
|
||||
PostMultiParser post_multi_parser;
|
||||
PT::JSONToSpaceParser post_json_parser;
|
||||
PT::SpaceParser space_parser;
|
||||
std::string post_buffer;
|
||||
|
||||
CookieParser cookie_parser;
|
||||
@@ -156,14 +155,14 @@ private:
|
||||
pthread_t signal_thread;
|
||||
std::string socket_to_send_on_exit;
|
||||
std::string send_data_buf;
|
||||
PT::SpaceToJSON json_generic_serializer;
|
||||
TextStream<std::wstring> json_out_stream;
|
||||
std::string aheader_name, aheader_value;
|
||||
std::wstring html_filtered;
|
||||
std::string output_8bit;
|
||||
BinaryPage compressed_output;
|
||||
std::wstring cookie_id_string;
|
||||
std::wstring http_header;
|
||||
std::wstring http_header_name;
|
||||
std::wstring http_header_value;
|
||||
std::string http_header_8bit;
|
||||
|
||||
morm::ModelConnector model_connector; // main thread model connector, each thread has its own connector
|
||||
|
||||
@@ -83,9 +83,9 @@ void Config::ShowError()
|
||||
|
||||
case PT::SpaceParser::syntax_error:
|
||||
if( errors_to_stdout )
|
||||
std::wcout << "Config: syntax error, line: " << parser.line << std::endl;
|
||||
std::wcout << "Config: syntax error, line: " << parser.get_last_parsed_line() << std::endl;
|
||||
|
||||
log << log1 << "Config: syntax error, line: " << parser.line << logend;
|
||||
log << log1 << "Config: syntax error, line: " << parser.get_last_parsed_line() << logend;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -108,7 +108,7 @@ bool Config::ReadConfig(bool errors_to_stdout_, bool stdout_is_closed)
|
||||
log << log2 << "Config: reading a config file" << logend;
|
||||
|
||||
parser.SetSpace(space);
|
||||
PT::SpaceParser::Status status = parser.Parse(config_file);
|
||||
PT::SpaceParser::Status status = parser.ParseSpaceFile(config_file);
|
||||
|
||||
if( status == PT::SpaceParser::ok )
|
||||
{
|
||||
@@ -382,150 +382,112 @@ void Config::CheckPasswd()
|
||||
|
||||
std::wstring Config::Text(const wchar_t * name)
|
||||
{
|
||||
return space.Text(name);
|
||||
return space.to_wstr(name);
|
||||
}
|
||||
|
||||
|
||||
std::wstring Config::Text(const wchar_t * name, const wchar_t * def)
|
||||
{
|
||||
return space.Text(name, def);
|
||||
return space.to_wstr(name, def);
|
||||
}
|
||||
|
||||
|
||||
std::wstring Config::Text(const std::wstring & name, const wchar_t * def)
|
||||
{
|
||||
return space.Text(name, def);
|
||||
}
|
||||
|
||||
|
||||
std::wstring & Config::TextRef(const wchar_t * name)
|
||||
{
|
||||
return space.TextRef(name);
|
||||
}
|
||||
|
||||
|
||||
std::wstring & Config::TextRef(const wchar_t * name, const wchar_t * def)
|
||||
{
|
||||
return space.TextRef(name, def);
|
||||
}
|
||||
|
||||
|
||||
std::wstring & Config::TextRef(const std::wstring & name, const wchar_t * def)
|
||||
{
|
||||
return space.TextRef(name, def);
|
||||
return space.to_wstr(name, def);
|
||||
}
|
||||
|
||||
|
||||
int Config::Int(const wchar_t * name)
|
||||
{
|
||||
return space.Int(name);
|
||||
return space.to_int(name);
|
||||
}
|
||||
|
||||
|
||||
int Config::Int(const wchar_t * name, int def)
|
||||
{
|
||||
return space.Int(name, def);
|
||||
return space.to_int(name, def);
|
||||
}
|
||||
|
||||
|
||||
int Config::Int(const std::wstring & name, int def)
|
||||
{
|
||||
return space.Int(name, def);
|
||||
return space.to_int(name, def);
|
||||
}
|
||||
|
||||
|
||||
long Config::Long(const wchar_t * name)
|
||||
{
|
||||
return space.Long(name);
|
||||
return space.to_long(name);
|
||||
}
|
||||
|
||||
long Config::Long(const wchar_t * name, long def)
|
||||
{
|
||||
return space.Long(name, def);
|
||||
return space.to_long(name, def);
|
||||
}
|
||||
|
||||
long Config::Long(const std::wstring & name, long def)
|
||||
{
|
||||
return space.Long(name, def);
|
||||
return space.to_long(name, def);
|
||||
}
|
||||
|
||||
|
||||
|
||||
size_t Config::Size(const wchar_t * name)
|
||||
{
|
||||
return space.Size(name);
|
||||
return space.to_ulong(name);
|
||||
}
|
||||
|
||||
|
||||
size_t Config::Size(const wchar_t * name, size_t def)
|
||||
{
|
||||
return space.Size(name, def);
|
||||
return space.to_ulong(name, def);
|
||||
}
|
||||
|
||||
|
||||
size_t Config::Size(const std::wstring & name, size_t def)
|
||||
{
|
||||
return space.Size(name, def);
|
||||
return space.to_ulong(name, def);
|
||||
}
|
||||
|
||||
|
||||
bool Config::Bool(const wchar_t * name)
|
||||
{
|
||||
return space.Bool(name);
|
||||
return space.to_bool(name);
|
||||
}
|
||||
|
||||
|
||||
bool Config::Bool(const wchar_t * name, bool def)
|
||||
{
|
||||
return space.Bool(name, def);
|
||||
return space.to_bool(name, def);
|
||||
}
|
||||
|
||||
|
||||
bool Config::Bool(const std::wstring & name, bool def)
|
||||
{
|
||||
return space.Bool(name, def);
|
||||
return space.to_bool(name, def);
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool Config::ListText(const wchar_t * name, std::vector<std::wstring> & list)
|
||||
{
|
||||
return space.ListText(name, list);
|
||||
return space.to_list(name, list);
|
||||
}
|
||||
|
||||
|
||||
bool Config::ListText(const std::wstring & name, std::vector<std::wstring> & list)
|
||||
{
|
||||
return space.ListText(name, list);
|
||||
return space.to_list(name, list);
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool Config::HasValue(const wchar_t * name, const wchar_t * value)
|
||||
{
|
||||
return space.HasValue(name, value);
|
||||
}
|
||||
|
||||
bool Config::HasValue(const wchar_t * name, const std::wstring & value)
|
||||
{
|
||||
return space.HasValue(name, value);
|
||||
}
|
||||
|
||||
bool Config::HasValue(const std::wstring & name, const wchar_t * value)
|
||||
{
|
||||
return space.HasValue(name, value);
|
||||
}
|
||||
|
||||
bool Config::HasValue(const std::wstring & name, const std::wstring & value)
|
||||
{
|
||||
return space.HasValue(name, value);
|
||||
}
|
||||
|
||||
|
||||
void Config::Print(std::wostream & out)
|
||||
{
|
||||
space.Serialize(out);
|
||||
}
|
||||
//void Config::Print(std::wostream & out)
|
||||
//{
|
||||
// space.serialize_to_space_stream(out);
|
||||
//}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -619,6 +619,7 @@ public:
|
||||
// 2 - application/xml - for XHTML 1.0 or for XHTML 1.1
|
||||
// default: 0
|
||||
// if utf8 is true then "; charset=UTF-8" will also be appended
|
||||
// may it would be better to set just the string here instead of integers?
|
||||
int content_type_header;
|
||||
|
||||
// global umask
|
||||
@@ -793,10 +794,6 @@ public:
|
||||
std::wstring Text(const wchar_t * name, const wchar_t * def);
|
||||
std::wstring Text(const std::wstring & name, const wchar_t * def);
|
||||
|
||||
std::wstring & TextRef(const wchar_t * name);
|
||||
std::wstring & TextRef(const wchar_t * name, const wchar_t * def);
|
||||
std::wstring & TextRef(const std::wstring & name, const wchar_t * def);
|
||||
|
||||
int Int(const wchar_t *);
|
||||
int Int(const wchar_t * name, int def);
|
||||
int Int(const std::wstring & name, int def);
|
||||
@@ -812,13 +809,8 @@ public:
|
||||
bool ListText(const wchar_t * name, std::vector<std::wstring> & list);
|
||||
bool ListText(const std::wstring & name, std::vector<std::wstring> & list);
|
||||
|
||||
bool HasValue(const wchar_t * name, const wchar_t * value);
|
||||
bool HasValue(const wchar_t * name, const std::wstring & value);
|
||||
bool HasValue(const std::wstring & name, const wchar_t * value);
|
||||
bool HasValue(const std::wstring & name, const std::wstring & value);
|
||||
|
||||
// for debug
|
||||
void Print(std::wostream & out);
|
||||
//void Print(std::wostream & out);
|
||||
|
||||
// raw access to the config
|
||||
PT::Space space;
|
||||
|
||||
@@ -214,6 +214,14 @@ bool Plugin::SetDependency(PluginInfo & info)
|
||||
info.session_manager = session_manager;
|
||||
info.plugin = this;
|
||||
|
||||
/*
|
||||
* FIXME
|
||||
* if we call a message from a different thread then a different model connector is needed
|
||||
* (each thread should have its own model connector)
|
||||
*
|
||||
*/
|
||||
info.model_connector = system->get_model_connector();
|
||||
|
||||
info.log.SetDependency(&log);
|
||||
|
||||
return res;
|
||||
|
||||
@@ -93,15 +93,15 @@ void Request::Clear()
|
||||
post_tab.clear();
|
||||
post_file_tab.clear();
|
||||
cookie_tab.clear();
|
||||
post_in.Clear();
|
||||
post_in.clear();
|
||||
is_postin_used = false;
|
||||
|
||||
method = unknown_method;
|
||||
|
||||
headers_in.Clear();
|
||||
headers_in.clear();
|
||||
|
||||
out_headers.Clear();
|
||||
out_cookies.Clear();
|
||||
out_headers.clear();
|
||||
out_cookies.clear();
|
||||
|
||||
page_generated = false;
|
||||
|
||||
@@ -117,6 +117,7 @@ void Request::Clear()
|
||||
|
||||
item_tab.clear();
|
||||
item.Clear();
|
||||
item.set_connector(nullptr);
|
||||
dir_tab.clear();
|
||||
last_item = &item;
|
||||
is_item = false;
|
||||
@@ -139,8 +140,7 @@ void Request::Clear()
|
||||
|
||||
subdomain.clear();
|
||||
return_info_only = false;
|
||||
info.Clear();
|
||||
info_serializer = 0;
|
||||
info.clear();
|
||||
return_json = false;
|
||||
|
||||
out_bin_stream.clear();
|
||||
|
||||
@@ -46,7 +46,6 @@
|
||||
#include "templates/htmltextstream.h"
|
||||
#include "date/date.h"
|
||||
#include "space/space.h"
|
||||
#include "space/spacetojson.h"
|
||||
#include "textstream/textstream.h"
|
||||
#include "outstreams.h"
|
||||
|
||||
@@ -308,11 +307,6 @@ struct Request
|
||||
// additional info added when sending the JSON answer
|
||||
PT::Space info;
|
||||
|
||||
// info serializer
|
||||
// if not set then the json_generic_serializer from App will be used
|
||||
// default: null (json_generic_serializer used)
|
||||
PT::SpaceToJSON * info_serializer;
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -392,10 +386,10 @@ struct Request
|
||||
// value - cookie value (can be everything which can be put to PT::WTextStream stream)
|
||||
// the return std::wstring reference is a reference to the cookie inserted value (in out_cookies structure)
|
||||
template<typename NameType, typename ValueType>
|
||||
std::wstring & AddCookie(const NameType & name, const ValueType & value, PT::Date * expires = 0);
|
||||
void AddCookie(const NameType & name, const ValueType & value, PT::Date * expires = 0);
|
||||
|
||||
template<typename NameType, typename ValueType>
|
||||
std::wstring & AddCookie(const NameType & name, const ValueType & value, PT::Date & expires);
|
||||
void AddCookie(const NameType & name, const ValueType & value, PT::Date & expires);
|
||||
|
||||
|
||||
|
||||
@@ -415,9 +409,9 @@ private:
|
||||
|
||||
|
||||
template<typename NameType, typename ValueType>
|
||||
std::wstring & Request::AddCookie(const NameType & name, const ValueType & value, PT::Date * expires)
|
||||
void Request::AddCookie(const NameType & name, const ValueType & value, PT::Date * expires)
|
||||
{
|
||||
PT::WTextStream cookie;
|
||||
PT::WTextStream cookie;
|
||||
|
||||
cookie << value;
|
||||
|
||||
@@ -439,14 +433,14 @@ PT::WTextStream cookie;
|
||||
will be lost (the session cookie will be overwritten in the client's browser)
|
||||
*/
|
||||
|
||||
return out_cookies.Add(name, cookie);
|
||||
out_cookies.add_stream(name, cookie);
|
||||
}
|
||||
|
||||
|
||||
template<typename NameType, typename ValueType>
|
||||
std::wstring & Request::AddCookie(const NameType & name, const ValueType & value, PT::Date & expires)
|
||||
void Request::AddCookie(const NameType & name, const ValueType & value, PT::Date & expires)
|
||||
{
|
||||
return AddCookie(name, value, &expires);
|
||||
AddCookie(name, value, &expires);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2014-2018, Tomasz Sowa
|
||||
* Copyright (c) 2014-2021, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -91,7 +91,7 @@ void SessionIdManager::ReadKey(const wchar_t * name, PT::Space & space, std::vec
|
||||
std::vector<std::wstring> keys;
|
||||
std::string key_ascii, key_base64_decoded;
|
||||
|
||||
space.ListText(name, keys);
|
||||
space.to_list(name, keys);
|
||||
|
||||
for(size_t i=0 ; i<key_tab_size ; ++i)
|
||||
dest_key[i].clear();
|
||||
@@ -145,16 +145,16 @@ PT::SpaceParser parser;
|
||||
PT::Date date;
|
||||
|
||||
parser.SetSpace(space);
|
||||
PT::SpaceParser::Status status = parser.Parse(file);
|
||||
PT::SpaceParser::Status status = parser.ParseSpaceFile(file);
|
||||
|
||||
if( status == PT::SpaceParser::ok )
|
||||
{
|
||||
key_index = space.Size(L"key_index");
|
||||
key_index = space.to_ulong(L"key_index");
|
||||
|
||||
if( key_index >= 256 )
|
||||
key_index = 0;
|
||||
|
||||
if( date.Parse(space.Text(L"last_key_generated", L"0")) )
|
||||
if( date.Parse(space.to_wstr(L"last_key_generated", L"0")) )
|
||||
last_key_generated = date.ToTime();
|
||||
|
||||
ReadKey(L"key_tab1", space, key_tab1);
|
||||
|
||||
@@ -755,7 +755,7 @@ int System::NewPrivileges(int creation_mask)
|
||||
{
|
||||
if( cur && cur->session && cur->session->puser )
|
||||
{
|
||||
int umask = cur->session->puser->env.Int(L"umask", config->umask);
|
||||
int umask = cur->session->puser->env.to_int(L"umask", config->umask);
|
||||
return (~umask) & creation_mask;
|
||||
}
|
||||
else
|
||||
|
||||
@@ -109,6 +109,8 @@ public:
|
||||
TimeZones time_zones;
|
||||
|
||||
|
||||
using WinixModel::get_model_connector;
|
||||
|
||||
void SetCur(Cur * pcur);
|
||||
//void SetConfig(Config * pconfig);
|
||||
void SetDb(Db * pdb);
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2010-2014, Tomasz Sowa
|
||||
* Copyright (c) 2010-2021, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -398,7 +398,7 @@ TextStream<StringType> & TextStream<StringType>::write(const wchar_t * buf, size
|
||||
template<class StringType>
|
||||
TextStream<StringType> & TextStream<StringType>::operator<<(const PT::Space & space)
|
||||
{
|
||||
space.Serialize(*this, true, false);
|
||||
space.serialize_to_space_stream(*this, true);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -181,16 +181,17 @@ void ThreadManager::StopAll()
|
||||
for(ThreadItem & item : thread_tab)
|
||||
{
|
||||
log << log4 << "TM: waiting for thread " << id << " (" << item.object->ThreadId()
|
||||
<< ", name: " << item.name << ")" << logend;
|
||||
<< ", name: " << item.name << ")" << logend << logsave;
|
||||
|
||||
item.object->WaitForThread();
|
||||
log << log4 << "TM: thread " << id << " terminated" << logend;
|
||||
log << log4 << "TM: thread " << id << " terminated" << logend << logsave;
|
||||
|
||||
// the thread is stopped and we can set the thread log buffer pointing to
|
||||
// the main log buffer (from the main thread)
|
||||
item.object->set_log_buffer(log.GetLogBuffer());
|
||||
|
||||
delete item.thread_item_data;
|
||||
item.thread_item_data = nullptr;
|
||||
id += 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2012-2018, Tomasz Sowa
|
||||
* Copyright (c) 2012-2021, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -242,12 +242,12 @@ return offset;
|
||||
|
||||
time_t TimeZone::GetOffset(PT::Space & space)
|
||||
{
|
||||
std::wstring * offset_str = space.GetFirstValue(L"offset_str");
|
||||
std::wstring * offset_str = space.get_wstr(L"offset_str");
|
||||
|
||||
if( offset_str )
|
||||
return ParseStrOffset(offset_str->c_str());
|
||||
|
||||
return space.Long(L"offset");
|
||||
return space.to_long(L"offset");
|
||||
}
|
||||
|
||||
|
||||
@@ -257,22 +257,25 @@ bool TimeZone::SetTzDst(PT::Space & year)
|
||||
bool result = true;
|
||||
Dst dst;
|
||||
|
||||
int year_int = Toi(year.name);
|
||||
int year_int = 0;
|
||||
|
||||
if( year.name )
|
||||
year_int = Toi(*year.name);
|
||||
|
||||
if( year_int < 1970 || year_int > 10000 )
|
||||
return false;
|
||||
|
||||
dst.has_dst = year.Bool(L"has_dst", false);
|
||||
dst.has_dst = year.to_bool(L"has_dst", false);
|
||||
|
||||
if( dst.has_dst )
|
||||
{
|
||||
dst.start.year = year_int;
|
||||
dst.end.year = year_int;
|
||||
|
||||
if( !dst.start.ParseMonthDayTime(year.Text(L"start")) )
|
||||
if( !dst.start.ParseMonthDayTime(year.to_wstr(L"start")) )
|
||||
result = false;
|
||||
|
||||
if( !dst.end.ParseMonthDayTime(year.Text(L"end")) )
|
||||
if( !dst.end.ParseMonthDayTime(year.to_wstr(L"end")) )
|
||||
result = false;
|
||||
|
||||
dst.offset = GetOffset(year);
|
||||
@@ -291,24 +294,31 @@ return result;
|
||||
bool TimeZone::SetTz(PT::Space & space)
|
||||
{
|
||||
bool result = true;
|
||||
name = space.name;
|
||||
id = space.Int(L"id", -1);
|
||||
name.clear();
|
||||
|
||||
if( space.name )
|
||||
name = *space.name;
|
||||
|
||||
id = space.to_int(L"id", -1);
|
||||
offset = GetOffset(space);
|
||||
time_t h24 = 60 * 60 * 24; // 24 hours
|
||||
|
||||
if( offset < -h24 || offset > h24 )
|
||||
result = false;
|
||||
|
||||
PT::Space & dst = space.FindAddSpace(L"dst");
|
||||
PT::Space * dst = space.find_child_space(L"dst");
|
||||
|
||||
for(size_t i=0 ; i<dst.spaces.size() ; ++i)
|
||||
if( dst && dst->child_spaces )
|
||||
{
|
||||
PT::Space & year = *dst.spaces[i];
|
||||
|
||||
if( !SetTzDst(year) )
|
||||
for(size_t i=0 ; i<dst->child_spaces->size() ; ++i)
|
||||
{
|
||||
result = false;
|
||||
break;
|
||||
PT::Space & year = *(*dst->child_spaces)[i];
|
||||
|
||||
if( !SetTzDst(year) )
|
||||
{
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2012-2014, Tomasz Sowa
|
||||
* Copyright (c) 2012-2021, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -123,37 +123,40 @@ bool TimeZones::Empty() const
|
||||
|
||||
void TimeZones::ParseZones()
|
||||
{
|
||||
for(size_t i=0 ; i<temp_space.spaces.size() ; ++i)
|
||||
if( temp_space.child_spaces )
|
||||
{
|
||||
PT::Space & zone = *temp_space.spaces[i];
|
||||
temp_zone.Clear();
|
||||
|
||||
if( temp_zone.SetTz(zone) )
|
||||
for(size_t i=0 ; i<temp_space.child_spaces->size() ; ++i)
|
||||
{
|
||||
if( !HasZone(temp_zone.id) )
|
||||
PT::Space & zone = *((*temp_space.child_spaces)[i]);
|
||||
temp_zone.Clear();
|
||||
|
||||
if( temp_zone.SetTz(zone) )
|
||||
{
|
||||
if( temp_zone.id < zone_indices.size() )
|
||||
if( !HasZone(temp_zone.id) )
|
||||
{
|
||||
zone_tab.push_back(temp_zone);
|
||||
zone_indices[temp_zone.id] = zone_tab.size() - 1;
|
||||
if( temp_zone.id < zone_indices.size() )
|
||||
{
|
||||
zone_tab.push_back(temp_zone);
|
||||
zone_indices[temp_zone.id] = zone_tab.size() - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
log << log1 << "Tz: zone: " << temp_zone.name << " has too big id: "
|
||||
<< temp_zone.id << " (skipping)" << logend;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
log << log1 << "Tz: zone: " << temp_zone.name << " has too big id: "
|
||||
<< temp_zone.id << " (skipping)" << logend;
|
||||
log << log1 << "Tz: zone with id: " << temp_zone.id
|
||||
<< " already exists (skipping)" << logend;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
log << log1 << "Tz: zone with id: " << temp_zone.id
|
||||
<< " already exists (skipping)" << logend;
|
||||
log << log1 << "System: problem with reading time zone info from time zone: "
|
||||
<< zone.name << " (skipping) " << logend;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
log << log1 << "System: problem with reading time zone info from time zone: "
|
||||
<< zone.name << " (skipping) " << logend;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -166,9 +169,9 @@ bool TimeZones::ReadTimeZones(const wchar_t * path)
|
||||
{
|
||||
parser.SetSpace(temp_space);
|
||||
zone_tab.clear();
|
||||
temp_space.Clear();
|
||||
temp_space.clear();
|
||||
|
||||
PT::SpaceParser::Status status = parser.Parse(path);
|
||||
PT::SpaceParser::Status status = parser.ParseSpaceFile(path);
|
||||
|
||||
if( status == PT::SpaceParser::ok )
|
||||
{
|
||||
@@ -178,7 +181,7 @@ bool TimeZones::ReadTimeZones(const wchar_t * path)
|
||||
else
|
||||
if( status == PT::SpaceParser::syntax_error )
|
||||
{
|
||||
log << log1 << "TZ: error in time zone file, line: " << parser.line << logend;
|
||||
log << log1 << "TZ: error in time zone file, line: " << parser.get_last_parsed_line() << logend;
|
||||
}
|
||||
else
|
||||
if( status == PT::SpaceParser::cant_open_file )
|
||||
@@ -186,7 +189,7 @@ bool TimeZones::ReadTimeZones(const wchar_t * path)
|
||||
log << log1 << "TZ: I cannot open the time zone file: " << path << logend;
|
||||
}
|
||||
|
||||
temp_space.Clear();
|
||||
temp_space.clear();
|
||||
|
||||
return status == PT::SpaceParser::ok;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2012-2014, Tomasz Sowa
|
||||
* Copyright (c) 2012-2021, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -54,8 +54,8 @@ void User::Clear()
|
||||
groups.clear();
|
||||
email.clear();
|
||||
notify = 0;
|
||||
env.Clear();
|
||||
aenv.Clear();
|
||||
env.clear();
|
||||
aenv.clear();
|
||||
status = WINIX_ACCOUNT_BLOCKED;
|
||||
locale_id = 0;
|
||||
time_zone_id = 0;
|
||||
|
||||
Reference in New Issue
Block a user