diff --git a/winixd/core/app.cpp b/winixd/core/app.cpp index 203d6ec..a501009 100644 --- a/winixd/core/app.cpp +++ b/winixd/core/app.cpp @@ -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(); diff --git a/winixd/core/app.h b/winixd/core/app.h index f2348d8..bf02871 100644 --- a/winixd/core/app.h +++ b/winixd/core/app.h @@ -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 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 diff --git a/winixd/core/config.cpp b/winixd/core/config.cpp index 9558d74..c2b315b 100644 --- a/winixd/core/config.cpp +++ b/winixd/core/config.cpp @@ -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 & list) { - return space.ListText(name, list); + return space.to_list(name, list); } bool Config::ListText(const std::wstring & name, std::vector & 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); +//} diff --git a/winixd/core/config.h b/winixd/core/config.h index 97a17f6..0cd1134 100644 --- a/winixd/core/config.h +++ b/winixd/core/config.h @@ -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 & list); bool ListText(const std::wstring & name, std::vector & 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; diff --git a/winixd/core/plugin.cpp b/winixd/core/plugin.cpp index 2b6f720..2d2222f 100644 --- a/winixd/core/plugin.cpp +++ b/winixd/core/plugin.cpp @@ -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; diff --git a/winixd/core/request.cpp b/winixd/core/request.cpp index f6cf15f..9c72c9f 100644 --- a/winixd/core/request.cpp +++ b/winixd/core/request.cpp @@ -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(); diff --git a/winixd/core/request.h b/winixd/core/request.h index 65ac7a5..7ee0068 100644 --- a/winixd/core/request.h +++ b/winixd/core/request.h @@ -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 - 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 - 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 -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 -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); } diff --git a/winixd/core/sessionidmanager.cpp b/winixd/core/sessionidmanager.cpp index fa1c6eb..0011eb0 100644 --- a/winixd/core/sessionidmanager.cpp +++ b/winixd/core/sessionidmanager.cpp @@ -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 keys; std::string key_ascii, key_base64_decoded; - space.ListText(name, keys); + space.to_list(name, keys); for(size_t i=0 ; i= 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); diff --git a/winixd/core/system.cpp b/winixd/core/system.cpp index 4a96539..74341d5 100644 --- a/winixd/core/system.cpp +++ b/winixd/core/system.cpp @@ -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 diff --git a/winixd/core/system.h b/winixd/core/system.h index 2fa0cc4..96165ac 100644 --- a/winixd/core/system.h +++ b/winixd/core/system.h @@ -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); diff --git a/winixd/core/textstream.h b/winixd/core/textstream.h index 11db778..e7d63fa 100644 --- a/winixd/core/textstream.h +++ b/winixd/core/textstream.h @@ -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 & TextStream::write(const wchar_t * buf, size template TextStream & TextStream::operator<<(const PT::Space & space) { - space.Serialize(*this, true, false); + space.serialize_to_space_stream(*this, true); return *this; } diff --git a/winixd/core/threadmanager.cpp b/winixd/core/threadmanager.cpp index d95f884..08abf47 100644 --- a/winixd/core/threadmanager.cpp +++ b/winixd/core/threadmanager.cpp @@ -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; } diff --git a/winixd/core/timezone.cpp b/winixd/core/timezone.cpp index b50d1c6..ca97640 100644 --- a/winixd/core/timezone.cpp +++ b/winixd/core/timezone.cpp @@ -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 ; ichild_spaces ) { - PT::Space & year = *dst.spaces[i]; - - if( !SetTzDst(year) ) + for(size_t i=0 ; ichild_spaces->size() ; ++i) { - result = false; - break; + PT::Space & year = *(*dst->child_spaces)[i]; + + if( !SetTzDst(year) ) + { + result = false; + break; + } } } diff --git a/winixd/core/timezones.cpp b/winixd/core/timezones.cpp index 07a7aad..251f088 100644 --- a/winixd/core/timezones.cpp +++ b/winixd/core/timezones.cpp @@ -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 ; isize() ; ++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; } diff --git a/winixd/core/user.cpp b/winixd/core/user.cpp index fc90ada..d2f0a04 100644 --- a/winixd/core/user.cpp +++ b/winixd/core/user.cpp @@ -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; diff --git a/winixd/db/dbbase.cpp b/winixd/db/dbbase.cpp index da9d81d..71fbaef 100644 --- a/winixd/db/dbbase.cpp +++ b/winixd/db/dbbase.cpp @@ -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 @@ -260,20 +260,20 @@ bool DbBase::AssertValueSpace(PGresult * r, int row, int col, PT::Space & space) const char * res = AssertValue(r, row, col); conf_parser.SetSpace(space); - space.Clear(); + space.clear(); - PT::SpaceParser::Status status = conf_parser.ParseString(res); + PT::SpaceParser::Status status = conf_parser.ParseSpace(res); if( status != PT::SpaceParser::ok ) { log << log1 << "Db: a problem with parsing a PT::Space"; if( status == PT::SpaceParser::syntax_error ) - log << ", syntax error at line: " << conf_parser.line; + log << ", syntax error at line: " << conf_parser.get_last_parsed_line(); log << logend; - space.Clear(); + space.clear(); return false; } diff --git a/winixd/db/dbtextstream.cpp b/winixd/db/dbtextstream.cpp index d8ed62b..79a9815 100644 --- a/winixd/db/dbtextstream.cpp +++ b/winixd/db/dbtextstream.cpp @@ -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 @@ -589,7 +589,7 @@ DbTextStream & DbTextStream::operator<<(const PT::Space & space) tmp_stream.Clear(); // !! IMPROVE ME // we can calculate how much memory is needed before serializing - space.Serialize(tmp_stream, true, false); + space.serialize_to_space_stream(tmp_stream, true); operator<<(tmp_stream.Str()); tmp_stream.Clear(); diff --git a/winixd/functions/account.cpp b/winixd/functions/account.cpp index dd02c8f..4605531 100644 --- a/winixd/functions/account.cpp +++ b/winixd/functions/account.cpp @@ -5,7 +5,7 @@ */ /* - * Copyright (c) 2013-2018, Tomasz Sowa + * Copyright (c) 2013-2021, Tomasz Sowa * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -55,7 +55,7 @@ Account::Account() bool Account::ActivateAccount(User * puser, long code, bool use_ses_log) { - std::wstring * user_code_str = puser->aenv.GetFirstValue(L"activation_code"); + std::wstring * user_code_str = puser->aenv.get_wstr(L"activation_code"); if( user_code_str ) { @@ -63,7 +63,7 @@ bool Account::ActivateAccount(User * puser, long code, bool use_ses_log) { if( db->ChangeUserStatus(puser->id, WINIX_ACCOUNT_READY) == WINIX_ERR_OK ) { - puser->aenv.Remove(L"activation_code"); + puser->aenv.remove(L"activation_code"); db->ChangeUserAdminEnv(puser->id, puser->aenv); puser->status = WINIX_ACCOUNT_READY; diff --git a/winixd/functions/adduser.cpp b/winixd/functions/adduser.cpp index 92222de..8b0dcfc 100644 --- a/winixd/functions/adduser.cpp +++ b/winixd/functions/adduser.cpp @@ -5,7 +5,7 @@ */ /* - * Copyright (c) 2008-2018, Tomasz Sowa + * Copyright (c) 2008-2021, Tomasz Sowa * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -229,7 +229,7 @@ bool AddUser::AddNewUser(const std::wstring & login, if( user.status == WINIX_ACCOUNT_NOT_ACTIVATED ) { code = std::rand(); - user.aenv.Add(L"activation_code", code); + user.aenv.add(L"activation_code", code); } if( AddNewUser(user, pass) ) diff --git a/winixd/functions/env.cpp b/winixd/functions/env.cpp index 86b8749..1ecff6c 100644 --- a/winixd/functions/env.cpp +++ b/winixd/functions/env.cpp @@ -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 @@ -74,10 +74,10 @@ return true; bool Env::Parse(const std::wstring & env_str) { - space.Clear(); + space.clear(); conf_parser.SetSpace(space); -return (conf_parser.ParseString(env_str) == PT::SpaceParser::ok); +return (conf_parser.ParseSpace(env_str) == PT::SpaceParser::ok); } @@ -102,10 +102,10 @@ bool Env::EditAdminEnv(long user_id, const std::wstring & env_str, bool use_ses_ } else { - log << log2 << "Env: Syntax error in line: " << conf_parser.line << logend; + log << log2 << "Env: Syntax error in line: " << conf_parser.get_last_parsed_line() << logend; if( use_ses_log ) - slog << logerror << T("syntax_error_in_line") << ' ' << conf_parser.line << logend; + slog << logerror << T("syntax_error_in_line") << ' ' << conf_parser.get_last_parsed_line() << logend; } return false; @@ -133,10 +133,10 @@ bool Env::EditEnv(long user_id, const std::wstring & env_str, bool use_ses_log) } else { - log << log2 << "Env: Syntax error in line: " << conf_parser.line << logend; + log << log2 << "Env: Syntax error in line: " << conf_parser.get_last_parsed_line() << logend; if( use_ses_log ) - slog << logerror << T("syntax_error_in_line") << ' ' << conf_parser.line << logend; + slog << logerror << T("syntax_error_in_line") << ' ' << conf_parser.get_last_parsed_line() << logend; } return false; diff --git a/winixd/functions/meta.cpp b/winixd/functions/meta.cpp index 5b54ab2..051fa37 100644 --- a/winixd/functions/meta.cpp +++ b/winixd/functions/meta.cpp @@ -62,10 +62,10 @@ bool Meta::HasAccess() bool Meta::Parse(const std::wstring & meta_str) { - space.Clear(); + space.clear(); conf_parser.SetSpace(space); -return (conf_parser.ParseString(meta_str) == PT::SpaceParser::ok); +return (conf_parser.ParseSpace(meta_str) == PT::SpaceParser::ok); } @@ -91,10 +91,10 @@ bool Meta::EditAdminMeta(Item & item, const std::wstring & meta_str, bool use_se } else { - log << log2 << "Meta: Syntax error in line: " << conf_parser.line << logend; + log << log2 << "Meta: Syntax error in line: " << conf_parser.get_last_parsed_line() << logend; if( use_ses_log ) - slog << logerror << T("syntax_error_in_line") << ' ' << conf_parser.line << logend; + slog << logerror << T("syntax_error_in_line") << ' ' << conf_parser.get_last_parsed_line() << logend; } return false; @@ -122,10 +122,10 @@ bool Meta::EditMeta(Item & item, const std::wstring & meta_str, bool use_ses_log } else { - log << log2 << "Meta: Syntax error in line: " << conf_parser.line << logend; + log << log2 << "Meta: Syntax error in line: " << conf_parser.get_last_parsed_line() << logend; if( use_ses_log ) - slog << logerror << T("syntax_error_in_line") << ' ' << conf_parser.line << logend; + slog << logerror << T("syntax_error_in_line") << ' ' << conf_parser.get_last_parsed_line() << logend; } return false; diff --git a/winixd/functions/passwd.cpp b/winixd/functions/passwd.cpp index 223939a..64bc607 100644 --- a/winixd/functions/passwd.cpp +++ b/winixd/functions/passwd.cpp @@ -5,7 +5,7 @@ */ /* - * Copyright (c) 2011-2018, Tomasz Sowa + * Copyright (c) 2011-2021, Tomasz Sowa * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -189,7 +189,7 @@ return result; bool Passwd::ResetPassword(User * puser, long code, bool use_ses_log, bool only_check_access) { - std::wstring * user_code_str = puser->aenv.GetFirstValue(L"password_change_code"); + std::wstring * user_code_str = puser->aenv.get_wstr(L"password_change_code"); if( user_code_str ) { @@ -229,7 +229,7 @@ bool Passwd::ResetPassword(const std::wstring & login, long code, bool use_ses_l { long t = static_cast(cur->request->start_time); - if( puser->aenv.Long(L"password_change_time") + config->reset_password_code_expiration_time > t ) + if( puser->aenv.to_long(L"password_change_time") + config->reset_password_code_expiration_time > t ) { result = ResetPassword(puser, code, use_ses_log, only_check_access); } diff --git a/winixd/functions/upload.cpp b/winixd/functions/upload.cpp index 8a0a188..bd86539 100644 --- a/winixd/functions/upload.cpp +++ b/winixd/functions/upload.cpp @@ -59,8 +59,6 @@ Upload::Upload() void Upload::Init() { - json_serializer.TreatAsTable(L"files"); - json_serializer.TreatAsNumeric(L"size"); } @@ -146,9 +144,10 @@ void Upload::CreateThumb(Item & item) void Upload::UploadFile(Item & item, const std::wstring & tmp_filename) { // we should add the file beforehand to get the proper item.id - cur->request->status = system->AddFile(item, 0, false); + cur->request->status = WINIX_ERR_PERMISSION_DENIED; + bool status = system->AddFile(item, 0, false); - if( cur->request->status == WINIX_ERR_OK ) + if( status ) { if( system->CreateNewFile(item) ) { @@ -160,6 +159,7 @@ void Upload::UploadFile(Item & item, const std::wstring & tmp_filename) //cur->request->status = db->EditFileById(item, item.id); if( item.update(item_model_data) ) { + cur->request->status = WINIX_ERR_OK; plugin->Call(WINIX_FILE_ADDED, &item); if( item.item_content.file_type == WINIX_ITEM_FILETYPE_IMAGE ) @@ -174,10 +174,6 @@ void Upload::UploadFile(Item & item, const std::wstring & tmp_filename) if( is_jquery_upload ) cur->request->item_tab.push_back(item); } - else - { - cur->request->status = WINIX_ERR_PERMISSION_DENIED; - } } else { @@ -246,6 +242,8 @@ void Upload::UploadMulti() void Upload::UploadSingle() { + cur->request->item.Clear(); // clearing and setting date + const std::wstring & new_subject = cur->request->PostVar(L"subject"); const std::wstring & new_url = cur->request->PostVar(L"url"); bool has_subject = !new_subject.empty(); @@ -308,29 +306,33 @@ void Upload::MakePost() void Upload::CreateAnswer() { Request & req = *cur->request; - PT::Space & files = req.info.AddSpace(L"files"); // 'files' will be serialized to an array + PT::Space & files = req.info.add_empty_space(L"files"); for(size_t i=0 ; iCreateItemLink(req.item_tab[i], link); + file.add(L"url", link); - std::wstring & del_url = file.Add(L"deleteUrl", link); - del_url += L"/rm/jquery_upload"; + std::wstring delete_url = link; + delete_url += L"/rm/jquery_upload"; + file.add(L"deleteUrl", delete_url); - file.Add(L"deleteType", L"POST"); + file.add(L"deleteType", L"POST"); if( req.item_tab[i].item_content.file_type == WINIX_ITEM_FILETYPE_IMAGE ) { - std::wstring & thumb = file.Add(L"thumbnailUrl", link); + std::wstring thumb = link; if( req.item_tab[i].item_content.file_has_thumb ) thumb += L"/-/thumb"; + + file.add(L"thumbnailUrl", thumb); } /* @@ -341,10 +343,6 @@ void Upload::CreateAnswer() cur->request->return_json = true; cur->request->return_info_only = true; - cur->request->info_serializer = &json_serializer; - - - //cur->request->out_headers.Add(L"Content-Type", L"text/html"); } diff --git a/winixd/functions/upload.h b/winixd/functions/upload.h index 7ef65ed..9770d13 100644 --- a/winixd/functions/upload.h +++ b/winixd/functions/upload.h @@ -36,7 +36,7 @@ #define headerfile_winix_functions_upload #include "functionbase.h" -#include "space/spacetojson.h" + namespace Winix { @@ -62,11 +62,6 @@ private: //DbItemQuery query; bool is_jquery_upload; - // this object is used in App at the end of a request - // for serializing Request::info to JSON - // this will make a problem if in the future we'll use multithread requests - PT::SpaceToJSON json_serializer; - void Init(); bool HasAccess(const Item & item); diff --git a/winixd/locale/en b/winixd/locale/en index 7ee73f6..1403f6a 100644 --- a/winixd/locale/en +++ b/winixd/locale/en @@ -229,7 +229,6 @@ meta_admin_for_page = Additional administrative information for page mkdir_header = Make directory -html_lang_attr_value = "en" language_orphans = () diff --git a/winixd/locale/pl b/winixd/locale/pl index 384ff4f..9f6f100 100644 --- a/winixd/locale/pl +++ b/winixd/locale/pl @@ -232,8 +232,6 @@ man_ezc_functions = Funkcje szablonów EZC mkdir_header = Stwórz katalog -html_lang_attr_value = "pl" - # current limitation: winix is not allowed to convert polish capital letters to lower case # so we need to give both versions (small and capital letters) language_orphans = ( "(np.", "a", "al.", "ale", "aż", "aŻ", "bo", "bp", "by", "co", "cz.", "czy", "dn.", diff --git a/winixd/models/item.h b/winixd/models/item.h index 081077c..fd22d4f 100644 --- a/winixd/models/item.h +++ b/winixd/models/item.h @@ -58,6 +58,11 @@ public: field(L"item_id", item_id); } + void prepare_table() + { + table(L"core", L"item"); + } + }; diff --git a/winixd/models/itemcontent.cpp b/winixd/models/itemcontent.cpp index d42045b..30b5390 100644 --- a/winixd/models/itemcontent.cpp +++ b/winixd/models/itemcontent.cpp @@ -143,8 +143,8 @@ void ItemContent::Clear() content_parsed.clear(); content_parsed_type = ct_formatted_text; - meta.Clear(); - meta_admin.Clear(); + meta.clear(); + meta_admin.clear(); SetDateToNow(); } diff --git a/winixd/plugins/export/exportinfo.cpp b/winixd/plugins/export/exportinfo.cpp index f98cf4b..324a0dd 100644 --- a/winixd/plugins/export/exportinfo.cpp +++ b/winixd/plugins/export/exportinfo.cpp @@ -330,23 +330,27 @@ void ExportInfo::SendAllFilesFromDir(long dir_id) void ExportInfo::AdditionalExport(const Item & item) { - for(size_t i=0 ; iname == L"export" ) - AdditionalExport(item, *item.item_content.meta.spaces[i]); + for(size_t i=0 ; isize() ; ++i) + { + PT::Space & child = *(*item.item_content.meta.child_spaces)[i]; + + if( child.name && *child.name == L"export" ) + AdditionalExport(item, child); + } } } void ExportInfo::AdditionalExport(const Item & item, PT::Space & meta) { - if( meta.ListText(L"additional_export", additional_export) ) + meta.to_list(L"additional_export", additional_export); + + for(size_t i=0 ; iname; + while( seti < space.child_spaces->size() ) + { + PT::Space & sp = *(*space.child_spaces)[seti]; - if( set_index.find(name) == set_index.end() ) - { - set_index[name] = seti; - group_index_tab.push_back(GroupIndex()); - ReindexGroups(group_index_tab.back(), *space.spaces[seti]); - seti += 1; - } - else - { - slog << logerror << "set: " << name << " already defined (skipping)" << logend; - space.spaces.erase(space.spaces.begin() + seti); + if( sp.name ) + { + if( set_index.find(*sp.name) == set_index.end() ) + { + set_index[*sp.name] = seti; + group_index_tab.push_back(GroupIndex()); + ReindexGroups(group_index_tab.back(), sp); + seti += 1; + } + else + { + slog << logerror << "set: " << sp.name << " already defined (skipping)" << logend; + space.remove_child_space(seti); + } + } } } } @@ -83,74 +89,83 @@ void Groups::ReindexGroups(GroupIndex & group_index, PT::Space & set) { size_t i, v; - // loop through all groups in the set - for( i=0 ; i < set.spaces.size() ; ++i ) + if( set.child_spaces ) { - PT::Space & group = *set.spaces[i]; - // !! IMPROVE ME will be safer to copy the value out - // if we used accidently the group.Text later the key - // would be overwritten - const std::wstring & key = group.Text(L"key", L"value"); - - // loop through all values in the group - for(v=0 ; vsize() ; ++i ) { - std::wstring * vali = group.spaces[v]->GetFirstValue(key); + PT::Space & group = *(*set.child_spaces)[i]; + // !! IMPROVE ME will be safer to copy the value out + // if we used accidently the group.Text later the key + // would be overwritten + std::wstring key = group.to_wstr(L"key", L"value"); - if( vali ) + if( group.child_spaces ) { - GroupIndex::iterator g = group_index.find(*vali); - - if( g == group_index.end() ) + // loop through all values in the group + for(v=0 ; vsize() ; ) { - group_index[*vali] = i; - v += 1; - } - else - { - slog << logwarning << "set: " << set.name << " has a group with a duplicated value: " - << *vali << " (skipping)" << logend; + std::wstring * vali = (*group.child_spaces)[v]->get_wstr(key.c_str()); - group.spaces.erase(group.spaces.begin() + v); + if( vali ) + { + GroupIndex::iterator g = group_index.find(*vali); + + if( g == group_index.end() ) + { + group_index[*vali] = i; + v += 1; + } + else + { + slog << logwarning << "set: " << set.name << " has a group with a duplicated value: " + << *vali << " (skipping)" << logend; + + group.remove_child_space(v); + } + } + else + { + log << log1 << "key: " << key << " was not found" << logend; + slog << logwarning << "set: " << set.name + << " has a group without a value (skipping)" << logend; + + group.remove_child_space(v); + } } } - else - { - log << log1 << "key: " << key << " was not found" << logend; - slog << logwarning << "set: " << set.name - << " has a group without a value (skipping)" << logend; - group.spaces.erase(group.spaces.begin() + v); - } + SortValues(group); } - - SortValues(group); } } void Groups::SortValues(PT::Space & group) { - sort_by = group.Text(L"sort_by"); - sort_asc = (group.Text(L"sort_asc", L"true") == L"true"); + sort_by = group.to_wstr(L"sort_by"); + sort_asc = group.is_equal(L"sort_asc", L"true"); - if( !sort_by.empty() ) + if( !sort_by.empty() && group.child_spaces ) { - group.ListText(L"sort", sort_value); - std::sort(group.spaces.begin(), group.spaces.end(), SortFunHelper(this)); + group.to_list(L"sort", sort_value, true); + std::sort(group.child_spaces->begin(), group.child_spaces->end(), SortFunHelper(this)); } } bool Groups::SortFunHelper::operator()(PT::Space * sp1, PT::Space * sp2) { - const std::wstring & val1 = sp1->Text(groups->sort_by, L""); - const std::wstring & val2 = sp2->Text(groups->sort_by, L""); + const std::wstring * val1 = sp1->get_wstr(groups->sort_by.c_str()); + const std::wstring * val2 = sp2->get_wstr(groups->sort_by.c_str()); + + if( !val1 || !val2 ) + return false; if( groups->sort_asc ) - return SortValue(val1) < SortValue(val2); + return SortValue(*val1) < SortValue(*val2); else - return SortValue(val1) > SortValue(val2); + return SortValue(*val1) > SortValue(*val2); } @@ -191,16 +206,21 @@ return false; const std::wstring & Groups::GetOption(size_t seti, size_t groupi, size_t valuei, const wchar_t * option) { - if( seti < space.spaces.size() ) + if( space.child_spaces && seti < space.child_spaces->size() ) { - PT::Space & groups = *space.spaces[seti]; + PT::Space & groups = *(*space.child_spaces)[seti]; - if( groupi < groups.spaces.size() ) + if( groups.child_spaces && groupi < groups.child_spaces->size() ) { - PT::Space & value = *groups.spaces[groupi]; + PT::Space & value = *(*groups.child_spaces)[groupi]; - if( valuei < value.spaces.size() ) - return value.spaces[valuei]->TextRef(option); + if( value.child_spaces && valuei < value.child_spaces->size() ) + { + const std::wstring * res = (*value.child_spaces)[valuei]->get_wstr(option); + + if( res ) + return *res; + } } } @@ -217,12 +237,12 @@ const std::wstring & Groups::GetOption(size_t seti, size_t groupi, size_t valuei size_t Groups::Size(size_t seti, size_t groupi) { - if( seti < space.spaces.size() ) + if( space.child_spaces && seti < space.child_spaces->size() ) { - PT::Space & groups = *space.spaces[seti]; + PT::Space & groups = *(*space.child_spaces)[seti]; - if( groupi < groups.spaces.size() ) - return groups.spaces[groupi]->spaces.size(); + if( groups.child_spaces && groupi < groups.child_spaces->size() ) + return (*groups.child_spaces)[groupi]->child_spaces->size(); } return 0; @@ -236,7 +256,7 @@ return 0; void Groups::Clear() { - space.Clear(); + space.clear(); set_index.clear(); group_index_tab.clear(); } diff --git a/winixd/plugins/group/groups.h b/winixd/plugins/group/groups.h index b019249..6a53d65 100644 --- a/winixd/plugins/group/groups.h +++ b/winixd/plugins/group/groups.h @@ -5,7 +5,7 @@ */ /* - * Copyright (c) 2011-2014, Tomasz Sowa + * Copyright (c) 2011-2021, Tomasz Sowa * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -136,7 +136,7 @@ private: std::wstring sort_by; bool sort_asc; - PT::Space::Value sort_value; + std::vector sort_value; struct SortFunHelper { diff --git a/winixd/plugins/mailregister/init.cpp b/winixd/plugins/mailregister/init.cpp index 71366d8..993f840 100644 --- a/winixd/plugins/mailregister/init.cpp +++ b/winixd/plugins/mailregister/init.cpp @@ -77,16 +77,16 @@ void ReloadConfigFile(PluginInfo & info, Item & file) PT::SpaceParser parser; parser.SetSpace(space); - PT::SpaceParser::Status status = parser.ParseString(file.item_content.content_raw); + PT::SpaceParser::Status status = parser.ParseSpace(file.item_content.content_raw); if( status == PT::SpaceParser::syntax_error ) { - info.log << log1 << "MR: syntax error in file: " << file.url << ", line: " << parser.line << " (skipping this file)" << logend; + info.log << log1 << "MR: syntax error in file: " << file.url << ", line: " << parser.get_last_parsed_line() << " (skipping this file)" << logend; } else if( status == PT::SpaceParser::ok ) { - std::wstring * list_id_str = space.GetFirstValue(L"list_id"); + std::wstring * list_id_str = space.get_wstr(L"list_id"); if( list_id_str ) { diff --git a/winixd/plugins/menu/templates.cpp b/winixd/plugins/menu/templates.cpp index c1cb44d..178ab9f 100644 --- a/winixd/plugins/menu/templates.cpp +++ b/winixd/plugins/menu/templates.cpp @@ -390,7 +390,7 @@ void menu_dir_tab_meta_str(Info & i) StackItem * sitem = reinterpret_cast(stack->fun_data); if( stack->iter < sitem->citem->menu_items.size() ) - sitem->citem->menu_items[stack->iter].meta.Serialize(i.out, true, false); + sitem->citem->menu_items[stack->iter].meta.serialize_to_space_stream(i.out, true); } } diff --git a/winixd/plugins/seo/seo.cpp b/winixd/plugins/seo/seo.cpp index 3a4aef7..324bea2 100644 --- a/winixd/plugins/seo/seo.cpp +++ b/winixd/plugins/seo/seo.cpp @@ -77,9 +77,9 @@ void Seo::MakePost() item.subject = subject; - PT::Space & seo = item.item_content.meta.FindAddSpace(L"seo"); - seo.Add(L"description", description); - seo.Add(L"keywords", keywords); + PT::Space & seo = item.item_content.meta.find_add_child_space(L"seo"); + seo.add(L"description", description); + seo.add(L"keywords", keywords); ItemModelData item_model_data; item_model_data.prepare_unique_url = false; diff --git a/winixd/plugins/thread/reply.cpp b/winixd/plugins/thread/reply.cpp index 65ae50e..432ac6e 100644 --- a/winixd/plugins/thread/reply.cpp +++ b/winixd/plugins/thread/reply.cpp @@ -80,11 +80,11 @@ bool Reply::HasAccess() return false; - PT::Space * thread_space = cur->request->item.item_content.meta_admin.FindSpace(L"thread"); + PT::Space * thread_space = cur->request->item.item_content.meta_admin.find_child_space(L"thread"); if( thread_space ) { - if( thread_space->Bool(L"closed", false) ) + if( thread_space->to_bool(L"closed", false) ) return false; } diff --git a/winixd/plugins/thread/tdb.cpp b/winixd/plugins/thread/tdb.cpp index 088abd0..cc445c8 100644 --- a/winixd/plugins/thread/tdb.cpp +++ b/winixd/plugins/thread/tdb.cpp @@ -231,7 +231,7 @@ return DoCommand(query); long TDb::FindLastAnswer(long file_id) { PGresult * r = 0; - Error status = WINIX_ERR_OK; + //Error status = WINIX_ERR_OK; long last_item_id = -1; try @@ -249,7 +249,7 @@ long TDb::FindLastAnswer(long file_id) } catch(const Error & e) { - status = e; + //status = e; } ClearResult(r); diff --git a/winixd/plugins/ticket/editticket.cpp b/winixd/plugins/ticket/editticket.cpp index bc60714..3dab104 100644 --- a/winixd/plugins/ticket/editticket.cpp +++ b/winixd/plugins/ticket/editticket.cpp @@ -185,7 +185,7 @@ PT::Space & EditTicket::PrepareSpace() if( is_new ) { - PT::Space * ticket_space = cur->request->item.item_content.meta.FindSpace(L"ticket"); + PT::Space * ticket_space = cur->request->item.item_content.meta.find_child_space(L"ticket"); if( ticket_space ) { @@ -203,11 +203,11 @@ bool EditTicket::CloseTicket() { cur->request->item.propagate_connector(); - PT::Space & ticket_space = cur->request->item.item_content.meta_admin.FindAddSpace(L"ticket"); - ticket_space.Add(L"closed", true); + PT::Space & ticket_space = cur->request->item.item_content.meta_admin.find_add_child_space(L"ticket"); + ticket_space.add(L"closed", true); - PT::Space & thread_space = cur->request->item.item_content.meta_admin.FindAddSpace(L"thread"); - thread_space.Add(L"closed", true); + PT::Space & thread_space = cur->request->item.item_content.meta_admin.find_add_child_space(L"thread"); + thread_space.add(L"closed", true); //if( db->EditAdminMetaById(cur->request->item.ameta, cur->request->item.id) == WINIX_ERR_OK ) if( cur->request->item.item_content.update() ) diff --git a/winixd/plugins/ticket/sessiondata.cpp b/winixd/plugins/ticket/sessiondata.cpp index 0692886..d12438a 100644 --- a/winixd/plugins/ticket/sessiondata.cpp +++ b/winixd/plugins/ticket/sessiondata.cpp @@ -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 @@ -144,30 +144,36 @@ void SessionData::BuildFileList(std::vector & file_tab, PT::Space & space) { file_tab.clear(); - for(size_t i=0 ; isize() ; ++i) + { + PT::Space & sp = *(*space.child_spaces)[i]; - if( sp.name == L"param" ) - CheckFile(file_tab, sp); + if( sp.name && (*sp.name) == L"param" ) + CheckFile(file_tab, sp); + } } } void SessionData::CheckFile(std::vector & file_tab, PT::Space & space) { - for(size_t i=0 ; isize() ; ++i) { - std::wstring * file_id_str = subsp.GetFirstValue(L"itemid"); + PT::Space & subsp = *(*space.child_spaces)[i]; - if( file_id_str ) + if( subsp.name && *subsp.name == L"file" ) { - long file_id = Tol(*file_id_str); - file_tab.push_back(file_id); + std::wstring * file_id_str = subsp.get_wstr(L"itemid"); + + if( file_id_str ) + { + long file_id = Tol(*file_id_str); + file_tab.push_back(file_id); + } } } } diff --git a/winixd/plugins/ticket/templates.cpp b/winixd/plugins/ticket/templates.cpp index 31f10c1..94a15cf 100644 --- a/winixd/plugins/ticket/templates.cpp +++ b/winixd/plugins/ticket/templates.cpp @@ -173,16 +173,19 @@ PT::Space * find_ticket_param(long param_id, PT::Space & meta) { wchar_t param_id_str[50]; - // for performane - // should be a little faster in each loop comparing only just text - Toa(param_id, param_id_str, sizeof(param_id_str)/sizeof(wchar_t)); - - for(size_t i=0 ; isize() ; ++i) + { + PT::Space & sp = *(*meta.child_spaces)[i]; + + if( sp.name && *sp.name == L"param" && sp.is_equal(L"id", param_id_str) ) + return &sp; + } } return 0; @@ -226,7 +229,7 @@ size_t par_index; } else { - PT::Space * meta = item_meta.FindSpace(L"ticket"); + PT::Space * meta = item_meta.find_child_space(L"ticket"); if( meta ) { @@ -246,15 +249,19 @@ size_t par_index; void ticket_print_value_select(Info & i, TicketValue & value) { - if( value.is_param && value.is_value ) + if( value.is_param && value.is_value && value.config_par->child_spaces ) { - for(size_t a=0 ; aspaces.size() ; ++a) + for(size_t a=0 ; achild_spaces->size() ; ++a) { - PT::Space & sp = *value.config_par->spaces[a]; + PT::Space & sp = *(*value.config_par->child_spaces)[a]; - if( sp.name == L"option" && sp.Long(L"id") == value.ticket_par->intv ) + if( sp.name && *sp.name == L"option" && sp.to_long(L"id") == value.ticket_par->intv ) { - i.out << sp.Text(L"value"); + std::wstring * val = sp.get_wstr(L"value"); + + if( val ) + i.out << *val; + break; } } @@ -267,7 +274,7 @@ void ticket_print_value(Info & i, TicketValue & value) if( !value.is_param || !value.is_value ) return; - std::wstring * type = value.config_par->GetFirstValue(L"type"); + std::wstring * type = value.config_par->get_wstr(L"type"); if( value.is_in_ticket_par ) { @@ -281,7 +288,10 @@ void ticket_print_value(Info & i, TicketValue & value) } else { - i.out << value.value_meta->Text(L"value"); + std::wstring * val = value.value_meta->get_wstr(L"value"); + + if( val ) + i.out << *val; } } @@ -312,10 +322,10 @@ void ticket_meta_value(Info & i) void ticket_is_closed(Info & i) { - PT::Space * ticket_space = ticket_info.item->item_content.meta_admin.FindSpace(L"ticket"); + PT::Space * ticket_space = ticket_info.item->item_content.meta_admin.find_child_space(L"ticket"); if( ticket_space ) - i.res = ticket_space->Bool(L"closed", false); + i.res = ticket_space->to_bool(L"closed", false); } @@ -330,24 +340,27 @@ void ticket_param_value_for_param_id(Info & i) PT::Space & space = *ticket_info.cur_conf; int id = Toi(i.par); - - for( ; conf_index < space.spaces.size() ; ++conf_index) + if( space.child_spaces ) { - if( space.spaces[conf_index]->name == L"param" && - space.spaces[conf_index]->Int(L"id") == id ) + for( ; conf_index < space.child_spaces->size() ; ++conf_index) { - value_for_param_id.Clear(); - value_for_param_id.is_param = true; - value_for_param_id.config_par = space.spaces[conf_index]; - value_for_param_id.param_id = value_for_param_id.config_par->Long(L"id"); + PT::Space & sp = *(*space.child_spaces)[conf_index]; - if( ticket_info.ticket && ticket_info.item ) + if( sp.name && *sp.name == L"param" && sp.to_int(L"id") == id ) { - find_ticket_value(value_for_param_id, ticket_info.ticket->par_tab, ticket_info.item->item_content.meta); - ticket_print_value(i, value_for_param_id); - } + value_for_param_id.Clear(); + value_for_param_id.is_param = true; + value_for_param_id.config_par = &sp; + value_for_param_id.param_id = sp.to_long(L"id"); - break; + if( ticket_info.ticket && ticket_info.item ) + { + find_ticket_value(value_for_param_id, ticket_info.ticket->par_tab, ticket_info.item->item_content.meta); + ticket_print_value(i, value_for_param_id); + } + + break; + } } } } @@ -361,20 +374,21 @@ void ticket_does_param_id_have_value(Info & i) size_t conf_index = 0; PT::Space & space = *ticket_info.cur_conf; - if( i.params.size() == 2 ) + if( i.params.size() == 2 && space.child_spaces ) { long id = Tol(i.params[0].str); long id2 = Tol(i.params[1].str); - for( ; conf_index < space.spaces.size() ; ++conf_index) + for( ; conf_index < space.child_spaces->size() ; ++conf_index) { - if( space.spaces[conf_index]->name == L"param" && - space.spaces[conf_index]->Int(L"id") == id ) + PT::Space & sp = *(*space.child_spaces)[conf_index]; + + if( sp.name && *sp.name == L"param" && sp.to_long(L"id") == id ) { value_for_param_id.Clear(); value_for_param_id.is_param = true; - value_for_param_id.config_par = space.spaces[conf_index]; - value_for_param_id.param_id = value_for_param_id.config_par->Long(L"id"); + value_for_param_id.config_par = &sp; + value_for_param_id.param_id = sp.to_long(L"id"); if( ticket_info.ticket && ticket_info.item ) { @@ -545,10 +559,10 @@ void tickets_tab_is_closed(Info & i) if( tickets_value.is_item ) { - PT::Space * ticket_space = tickets_value.item->item_content.meta_admin.FindSpace(L"ticket"); + PT::Space * ticket_space = tickets_value.item->item_content.meta_admin.find_child_space(L"ticket"); if( ticket_space ) - i.res = ticket_space->Bool(L"closed", false); + i.res = ticket_space->to_bool(L"closed", false); } } @@ -625,22 +639,27 @@ void tickets_tab_param_value_for_param_id(Info & i) { size_t param_index = 0; PT::Space & space = *ticket_info.cur_conf; - int id = Toi(i.par); + long id = Tol(i.par); - for( ; param_index < space.spaces.size() ; ++param_index) + if( space.child_spaces ) { - if( space.spaces[param_index]->name == L"param" && - space.spaces[param_index]->Int(L"id") == id ) + for( ; param_index < space.child_spaces->size() ; ++param_index) { - value_for_param_id.Clear(); - value_for_param_id.is_param = true; - value_for_param_id.config_par = space.spaces[param_index]; - value_for_param_id.param_id = value_for_param_id.config_par->Long(L"id"); + PT::Space & sp = *(*space.child_spaces)[param_index]; - find_ticket_value(value_for_param_id, tickets_value.ticket->par_tab, tickets_value.item->item_content.meta); - ticket_print_value(i, value_for_param_id); + if( sp.name && *sp.name == L"param" && + sp.to_long(L"id") == id ) + { + value_for_param_id.Clear(); + value_for_param_id.is_param = true; + value_for_param_id.config_par = &sp; + value_for_param_id.param_id = sp.to_long(L"id"); - break; + find_ticket_value(value_for_param_id, tickets_value.ticket->par_tab, tickets_value.item->item_content.meta); + ticket_print_value(i, value_for_param_id); + + break; + } } } } @@ -660,32 +679,36 @@ void tickets_tab_does_param_id_have_value(Info & i) long id = Toi(i.params[0].str); long id2 = Toi(i.params[1].str); - for( ; param_index < space.spaces.size() ; ++param_index) + if( space.child_spaces ) { - if( space.spaces[param_index]->name == L"param" && - space.spaces[param_index]->Int(L"id") == id ) + for( ; param_index < space.child_spaces->size() ; ++param_index) { - value_for_param_id.Clear(); - value_for_param_id.is_param = true; - value_for_param_id.config_par = space.spaces[param_index]; - value_for_param_id.param_id = value_for_param_id.config_par->Long(L"id"); + PT::Space & sp = *(*space.child_spaces)[param_index]; - find_ticket_value(value_for_param_id, tickets_value.ticket->par_tab, tickets_value.item->item_content.meta); - - if( value_for_param_id.is_value ) + if( sp.name && *sp.name == L"param" && sp.to_long(L"id") == id ) { - if( value_for_param_id.is_in_ticket_par ) - { - i.res = value_for_param_id.ticket_par->intv == id2; - } - else - { - log << log1 << "Ticket: tickets_tab_does_param_id_have_value cannot be used with meta values" - << logend; - } - } + value_for_param_id.Clear(); + value_for_param_id.is_param = true; + value_for_param_id.config_par = &sp; + value_for_param_id.param_id = sp.to_long(L"id"); - break; + find_ticket_value(value_for_param_id, tickets_value.ticket->par_tab, tickets_value.item->item_content.meta); + + if( value_for_param_id.is_value ) + { + if( value_for_param_id.is_in_ticket_par ) + { + i.res = value_for_param_id.ticket_par->intv == id2; + } + else + { + log << log1 << "Ticket: tickets_tab_does_param_id_have_value cannot be used with meta values" + << logend; + } + } + + break; + } } } } @@ -702,17 +725,27 @@ void tickets_tab_conf_tab(Info & i) conf_index = i.iter; PT::Space & space = *ticket_info.cur_conf; - while( conf_index < space.spaces.size() && space.spaces[conf_index]->name != L"param" ) - conf_index += 1; - - i.res = conf_index < space.spaces.size(); - - if( i.res ) + if( space.child_spaces ) { - value.is_param = true; - value.config_par = space.spaces[conf_index]; - value.param_id = value.config_par->Long(L"id"); - find_ticket_value(value, tickets_value.ticket->par_tab, tickets_value.item->item_content.meta); + while( conf_index < space.child_spaces->size() ) + { + PT::Space & sp = *(*space.child_spaces)[conf_index]; + + if( sp.name && *sp.name == L"param" ) + break; + + conf_index += 1; + } + + i.res = conf_index < space.child_spaces->size(); + + if( i.res ) + { + value.is_param = true; + value.config_par = (*space.child_spaces)[conf_index]; + value.param_id = value.config_par->to_long(L"id"); + find_ticket_value(value, tickets_value.ticket->par_tab, tickets_value.item->item_content.meta); + } } } } @@ -751,7 +784,7 @@ void tickets_tab_conf_tab_param_name(Info & i) if( value.is_param ) { - std::wstring * name = value.config_par->GetFirstValue(L"name"); + std::wstring * name = value.config_par->get_wstr(L"name"); if( name ) i.out << *name; @@ -773,7 +806,7 @@ void tickets_tab_conf_tab_type_is(Info & i) tickets_tab_check_reqid(); if( value.is_param ) - i.res = (value.config_par->Text(L"type") == i.par); + i.res = value.config_par->is_equal(L"type", i.par); } @@ -809,13 +842,23 @@ void tickets_tab_conf_tab_file_tab(Info & i) PT::Space & mt = *value.value_meta; - while( tickets_file_index < mt.spaces.size() && mt.spaces[tickets_file_index]->name != L"file" ) - tickets_file_index += 1; + if( mt.child_spaces ) + { + while( tickets_file_index < mt.child_spaces->size() ) + { + PT::Space & sp = *(*mt.child_spaces)[tickets_file_index]; - i.res = (tickets_file_index < mt.spaces.size()); + if( sp.name && *sp.name == L"file" ) + break; - if( i.res && i.iter > 0 ) - tickets_file_number += 1; + tickets_file_index += 1; + } + + i.res = (tickets_file_index < mt.child_spaces->size()); + + if( i.res && i.iter > 0 ) + tickets_file_number += 1; + } } } @@ -828,7 +871,7 @@ void tickets_tab_conf_tab_file_tab_index(Info & i) { PT::Space & mt = *value.value_meta; - if( tickets_file_index < mt.spaces.size() ) + if( mt.child_spaces && tickets_file_index < mt.child_spaces->size() ) i.out << tickets_file_number; } } @@ -843,8 +886,8 @@ void tickets_tab_conf_tab_file_tab_path(Info & i) { PT::Space & mt = *value.value_meta; - if( tickets_file_index < mt.spaces.size() ) - i.out << mt.spaces[tickets_file_index]->Text(L"path"); + if( mt.child_spaces && tickets_file_index < mt.child_spaces->size() ) + i.out << (*mt.child_spaces)[tickets_file_index]->to_wstr(L"path"); } } @@ -857,8 +900,8 @@ void tickets_tab_conf_tab_file_tab_itemid(Info & i) { PT::Space & mt = *value.value_meta; - if( tickets_file_index < mt.spaces.size() ) - i.out << mt.spaces[tickets_file_index]->Text(L"itemid"); + if( mt.child_spaces && tickets_file_index < mt.child_spaces->size() ) + i.out << (*mt.child_spaces)[tickets_file_index]->to_wstr(L"itemid"); } } @@ -871,8 +914,8 @@ void tickets_tab_conf_tab_file_tab_meta(Info & i) { PT::Space & mt = *value.value_meta; - if( tickets_file_index < mt.spaces.size() ) - space_value(i, *mt.spaces[tickets_file_index]); + if( mt.child_spaces && tickets_file_index < mt.child_spaces->size() ) + space_value(i, *(*mt.child_spaces)[tickets_file_index]); } } @@ -913,19 +956,29 @@ void ticket_tab(Info & i) conf_index = i.iter; PT::Space & space = *ticket_info.cur_conf; - while( conf_index < space.spaces.size() && space.spaces[conf_index]->name != L"param" ) - conf_index += 1; - - i.res = conf_index < space.spaces.size(); - - if( i.res ) + if( space.child_spaces ) { - value.is_param = true; - value.config_par = space.spaces[conf_index]; - value.param_id = value.config_par->Long(L"id"); + while( conf_index < space.child_spaces->size() ) + { + PT::Space & sp = *(*space.child_spaces)[conf_index]; - if( ticket_info.ticket && ticket_info.item ) - find_ticket_value(value, ticket_info.ticket->par_tab, ticket_info.item->item_content.meta); + if( sp.name && *sp.name == L"param" ) + break; + + conf_index += 1; + } + + i.res = conf_index < space.child_spaces->size(); + + if( i.res ) + { + value.is_param = true; + value.config_par = (*space.child_spaces)[conf_index]; + value.param_id = value.config_par->to_long(L"id"); + + if( ticket_info.ticket && ticket_info.item ) + find_ticket_value(value, ticket_info.ticket->par_tab, ticket_info.item->item_content.meta); + } } } @@ -955,7 +1008,7 @@ void ticket_tab_param_name(Info & i) ticket_tab_check_reqid(); if( value.is_param ) - i.out << value.config_par->Text(L"name"); + i.out << value.config_par->to_wstr(L"name"); } @@ -1008,7 +1061,7 @@ void ticket_tab_type_is(Info & i) ticket_tab_check_reqid(); if( value.is_param ) - i.res = (value.config_par->Text(L"type") == i.par); + i.res = value.config_par->is_equal(L"type", i.par); } @@ -1021,10 +1074,20 @@ void ticket_tab_select_tab(Info & i) select_index = i.iter; PT::Space & sp = *value.config_par; - while( select_index < sp.spaces.size() && sp.spaces[select_index]->name != L"option" ) - select_index += 1; + if( sp.child_spaces ) + { + while( select_index < sp.child_spaces->size() ) + { + PT::Space & sp_child = *(*sp.child_spaces)[select_index]; - i.res = (select_index < sp.spaces.size()); + if( sp_child.name && *sp_child.name == L"option" ) + break; + + select_index += 1; + } + + i.res = (select_index < sp.child_spaces->size()); + } } } @@ -1037,9 +1100,11 @@ void ticket_tab_select_tab_is_selected(Info & i) { PT::Space & sp = *value.config_par; - if( select_index < sp.spaces.size() ) + if( sp.child_spaces && select_index < sp.child_spaces->size() ) { - long id = sp.spaces[select_index]->Long(L"id"); + PT::Space & sp_child = *(*sp.child_spaces)[select_index]; + + long id = sp_child.to_long(L"id"); if( value.is_value ) { @@ -1048,7 +1113,7 @@ void ticket_tab_select_tab_is_selected(Info & i) } else { - i.res = (id == sp.Long(L"default")); + i.res = (id == sp.to_long(L"default")); } } } @@ -1063,8 +1128,8 @@ void ticket_tab_select_tab_name(Info & i) { PT::Space & sp = *value.config_par; - if( select_index < sp.spaces.size() ) - i.out << sp.spaces[select_index]->Text(L"value"); + if( sp.child_spaces && select_index < sp.child_spaces->size() ) + i.out << (*sp.child_spaces)[select_index]->to_wstr(L"value"); } } @@ -1077,8 +1142,8 @@ void ticket_tab_select_tab_id(Info & i) { PT::Space & sp = *value.config_par; - if( select_index < sp.spaces.size() ) - i.out << sp.spaces[select_index]->Text(L"id"); + if( sp.child_spaces && select_index < sp.child_spaces->size() ) + i.out << (*sp.child_spaces)[select_index]->to_wstr(L"id"); } } @@ -1090,8 +1155,8 @@ void ticket_tab_select_tab_meta(Info & i) { PT::Space & sp = *value.config_par; - if( select_index < sp.spaces.size() ) - space_value(i, *sp.spaces[select_index]); + if( sp.child_spaces && select_index < sp.child_spaces->size() ) + space_value(i, *(*sp.child_spaces)[select_index]); } } @@ -1110,13 +1175,23 @@ void ticket_tab_file_tab(Info & i) PT::Space & mt = *value.value_meta; - while( ticket_file_index < mt.spaces.size() && mt.spaces[ticket_file_index]->name != L"file" ) - ticket_file_index += 1; + if( mt.child_spaces ) + { + while( ticket_file_index < mt.child_spaces->size() ) + { + PT::Space & sp = *(*mt.child_spaces)[ticket_file_index]; - i.res = (ticket_file_index < mt.spaces.size()); + if( sp.name && *sp.name == L"file" ) + break; - if( i.res && i.iter > 0 ) - ticket_file_number += 1; + ticket_file_index += 1; + } + + i.res = (ticket_file_index < mt.child_spaces->size()); + + if( i.res && i.iter > 0 ) + ticket_file_number += 1; + } } } @@ -1129,7 +1204,7 @@ void ticket_tab_file_tab_index(Info & i) { PT::Space & mt = *value.value_meta; - if( ticket_file_index < mt.spaces.size() ) + if( mt.child_spaces && ticket_file_index < mt.child_spaces->size() ) i.out << ticket_file_number; } } @@ -1143,8 +1218,8 @@ void ticket_tab_file_tab_path(Info & i) { PT::Space & mt = *value.value_meta; - if( ticket_file_index < mt.spaces.size() ) - i.out << mt.spaces[ticket_file_index]->Text(L"path"); + if( mt.child_spaces && ticket_file_index < mt.child_spaces->size() ) + i.out << (*mt.child_spaces)[ticket_file_index]->to_wstr(L"path"); } } @@ -1156,8 +1231,8 @@ void ticket_tab_file_tab_itemid(Info & i) { PT::Space & mt = *value.value_meta; - if( ticket_file_index < mt.spaces.size() ) - i.out << mt.spaces[ticket_file_index]->Text(L"itemid"); + if( mt.child_spaces && ticket_file_index < mt.child_spaces->size() ) + i.out << (*mt.child_spaces)[ticket_file_index]->to_wstr(L"itemid"); } } @@ -1169,8 +1244,8 @@ void ticket_tab_file_tab_meta(Info & i) { PT::Space & mt = *value.value_meta; - if( ticket_file_index < mt.spaces.size() ) - space_value(i, *mt.spaces[ticket_file_index]); + if( mt.child_spaces && ticket_file_index < mt.child_spaces->size() ) + space_value(i, *(*mt.child_spaces)[ticket_file_index]); } } diff --git a/winixd/plugins/ticket/ticketinfo.cpp b/winixd/plugins/ticket/ticketinfo.cpp index c83bdf0..6f44c74 100644 --- a/winixd/plugins/ticket/ticketinfo.cpp +++ b/winixd/plugins/ticket/ticketinfo.cpp @@ -106,7 +106,7 @@ void TicketInfo::Clear() cur_conf_wrap = &cur_conf_wrap_empty; cur_conf = &cur_conf_empty; - cur_conf->Clear(); + cur_conf->clear(); item_tab.clear(); ticket_tab.clear(); @@ -167,9 +167,9 @@ bool TicketInfo::ParseTicketConf(long mount_dir_id, const std::wstring & path) conf_tab[mount_dir_id].file_name = path; conf_parser.SetSpace(conf_tab[mount_dir_id].conf); - conf_tab[mount_dir_id].conf.Clear(); + conf_tab[mount_dir_id].conf.clear(); -return (conf_parser.ParseString(config_file.item_content.content_raw) == PT::SpaceParser::ok); +return (conf_parser.ParseSpace(config_file.item_content.content_raw) == PT::SpaceParser::ok); } @@ -264,15 +264,15 @@ void TicketInfo::FindCurrentConf() void TicketInfo::CheckMinMaxValue(PT::Space & space, Ticket::TicketParam & par) { - std::wstring * type = space.GetFirstValue(L"type"); + std::wstring * type = space.get_wstr(L"type"); if( !type ) return; if( *type == L"integer" ) { - std::wstring * min_str = space.GetFirstValue(L"min"); - std::wstring * max_str = space.GetFirstValue(L"min"); + std::wstring * min_str = space.get_wstr(L"min"); + std::wstring * max_str = space.get_wstr(L"min"); if( min_str ) { @@ -303,16 +303,19 @@ void TicketInfo::CheckMinMaxValue(PT::Space & space, Ticket::TicketParam & par) else if( *type == L"select" ) { - for(size_t a=0 ; asize() ; ++a) + { + PT::Space & sp = *(*space.child_spaces)[a]; - if( sp.name == L"option" && sp.Long(L"id") == par.intv ) - return; + if( sp.name && *sp.name == L"option" && sp.to_long(L"id") == par.intv ) + return; + } } par.intv = 0; - std::wstring * def = space.GetFirstValue(L"default"); + std::wstring * def = space.get_wstr(L"default"); if( def ) par.intv = Tol(*def); @@ -322,16 +325,19 @@ void TicketInfo::CheckMinMaxValue(PT::Space & space, Ticket::TicketParam & par) PT::Space & TicketInfo::FindAddMetaByParam(PT::Space & meta, long param) { - for(size_t i=0 ; isize() ; ++i) + { + PT::Space & sp = *(*meta.child_spaces)[i]; - if( sp.name == L"param" && sp.Long(L"id") == param ) - return sp; + if( sp.name && *sp.name == L"param" && sp.to_long(L"id") == param ) + return sp; + } } - PT::Space & sp = meta.AddSpace(L"param"); - sp.Add(L"id", param); + PT::Space & sp = meta.add_child_space(L"param"); + sp.add(L"id", param); return sp; } @@ -340,9 +346,9 @@ return sp; bool TicketInfo::ReadTicketValue(PT::Space & space, long param_id, Ticket::TicketParam & par, const std::wstring & value, PT::Space & meta) { - if( space.Text(L"type") == L"integer" || - space.Text(L"type") == L"progress" || - space.Text(L"type") == L"select" ) + if( space.is_equal(L"type", L"integer") || + space.is_equal(L"type", L"progress") || + space.is_equal(L"type", L"select") ) { par.intv = Tol(value); par.decv.clear(); @@ -350,16 +356,16 @@ bool TicketInfo::ReadTicketValue(PT::Space & space, long param_id, Ticket::Ticke return true; } else - if( space.Text(L"type") == L"string" || - space.Text(L"type") == L"multistring" ) + if( space.is_equal(L"type", L"string") || + space.is_equal(L"type", L"multistring") ) { // !! dodac cos co sprawdzi czy string nie zawiera znakow konca linii PT::Space & sp = FindAddMetaByParam(meta, param_id); - sp.Add(L"value", value); + sp.add(L"value", value); return false; } - if( space.Text(L"type") == L"images" || - space.Text(L"type") == L"files" ) + if( space.is_equal(L"type", L"images") || + space.is_equal(L"type", L"files") ) { if( !value.empty() ) { @@ -404,16 +410,16 @@ void TicketInfo::ReadTicketValue(PT::Space & space, if( cur->request->status == WINIX_ERR_OK ) { PT::Space & space = FindAddMetaByParam(meta, param_id); - PT::Space & file_space = space.AddSpace(L"file"); + PT::Space & file_space = space.add_child_space(L"file"); if( file.item_content.file_type == WINIX_ITEM_FILETYPE_IMAGE ) - file_space.Add(L"type", L"image"); + file_space.add(L"type", L"image"); else - file_space.Add(L"type", L"file"); + file_space.add(L"type", L"file"); - file_space.Add(L"itemid", file.id); + file_space.add(L"itemid", file.id); system->MakePath(file, file_path); - file_space.Add(L"path", file_path); + file_space.add(L"path", file_path); } else { @@ -425,11 +431,11 @@ void TicketInfo::ReadTicketValue(PT::Space & space, void TicketInfo::ReadTicketValue(PT::Space & space, long param_id, const PostFile & value, PT::Space & meta) { - std::wstring * type = space.GetFirstValue(L"type"); + std::wstring * type = space.get_wstr(L"type"); if( type && (*type == L"images" || *type == L"files") ) { - std::wstring * upload_path = space.GetFirstValue(L"upload_dir"); + std::wstring * upload_path = space.get_wstr(L"upload_dir"); if( upload_path && !upload_path->empty() ) { @@ -479,14 +485,17 @@ void TicketInfo::ReadTicketParam(Ticket & ticket, long param_id, const std::wstr { ticket_param.Clear(); - for(size_t i=0 ; ispaces.size() ; ++i) + if( cur_conf->child_spaces ) { - PT::Space & space = *cur_conf->spaces[i]; - - if( space.name == L"param" && Tol(space.Text(L"id")) == param_id ) + for(size_t i=0 ; ichild_spaces->size() ; ++i) { - ReadTicketParam(space, ticket, param_id, value, meta); - return; + PT::Space & space = *(*cur_conf->child_spaces)[i]; + + if( space.name && *space.name == L"param" && space.to_long(L"id") == param_id ) + { + ReadTicketParam(space, ticket, param_id, value, meta); + return; + } } } @@ -497,14 +506,17 @@ void TicketInfo::ReadTicketParam(Ticket & ticket, long param_id, const std::wstr // always adds a new parameter void TicketInfo::ReadTicketParam(long param_id, const PostFile & value, PT::Space & meta) { - for(size_t i=0 ; ispaces.size() ; ++i) + if( cur_conf->child_spaces ) { - PT::Space & space = *cur_conf->spaces[i]; - - if( space.name == L"param" && space.Long(L"id") == param_id ) + for(size_t i=0 ; ichild_spaces->size() ; ++i) { - ReadTicketValue(space, param_id, value, meta); - return; + PT::Space & space = *(*cur_conf->child_spaces)[i]; + + if( space.name && *space.name == L"param" && space.to_long(L"id") == param_id ) + { + ReadTicketValue(space, param_id, value, meta); + return; + } } } @@ -517,29 +529,32 @@ void TicketInfo::ReadTicketParam(long param_id, const PostFile & value, PT::Spac bool TicketInfo::DeleteTicketFile(Ticket & ticket, long file_id, PT::Space & meta) { - for(size_t i=0 ; isize() ; ++i) { - for(size_t z=0 ; zsize() ; ++z) { - if( file.Long(L"itemid") == file_id ) + PT::Space & file = *(*param.child_spaces)[z]; + + if( file.name && *file.name == L"file" ) { - param.RemoveSpace(z); + if( file.to_long(L"itemid") == file_id ) + { + param.remove_child_space(z); - // !! IMPROVE ME - // temporarily we delete the file here - // but it should be really deleted when the user will press - // the submit button - //functions->fun_rm.RemoveFileOrSymlink(file_id, true); + // !! IMPROVE ME + // temporarily we delete the file here + // but it should be really deleted when the user will press + // the submit button + //functions->fun_rm.RemoveFileOrSymlink(file_id, true); - return true; + return true; + } } } } @@ -616,9 +631,8 @@ void TicketInfo::RemoveTicket(long file_id) void TicketInfo::CopyTicketSpace(PT::Space & ticket_space, Item & item) { - PT::Space & ticket_meta = item.item_content.meta.FindAddSpace(L"ticket"); + PT::Space & ticket_meta = item.item_content.meta.find_add_child_space(L"ticket"); ticket_meta = ticket_space; - ticket_meta.name = L"ticket"; } diff --git a/winixd/templates/dir.cpp b/winixd/templates/dir.cpp index 759011b..49eda4c 100644 --- a/winixd/templates/dir.cpp +++ b/winixd/templates/dir.cpp @@ -464,7 +464,7 @@ void dir_last_has_html_template(Info & i) void dir_last_meta_str(Info & i) { - cur->request->dir_tab.back()->item_content.meta.Serialize(i.out, true, false); + cur->request->dir_tab.back()->item_content.meta.serialize_to_space_stream(i.out, true); } @@ -497,7 +497,7 @@ void dir_last_meta_tab_has_next(Info & i) void dir_last_admin_meta_str(Info & i) { - cur->request->dir_tab.back()->item_content.meta_admin.Serialize(i.out, true, false); + cur->request->dir_tab.back()->item_content.meta_admin.serialize_to_space_stream(i.out, true); } diff --git a/winixd/templates/env.cpp b/winixd/templates/env.cpp index b696e48..36d9813 100644 --- a/winixd/templates/env.cpp +++ b/winixd/templates/env.cpp @@ -5,7 +5,7 @@ */ /* - * Copyright (c) 2012-2015, Tomasz Sowa + * Copyright (c) 2012-2021, Tomasz Sowa * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -52,7 +52,7 @@ void env_str(Info & i) User * puser = cur->session->puser; if( puser ) - puser->env.Serialize(i.out, true, false); + puser->env.serialize_to_space_stream(i.out, true); } @@ -105,7 +105,7 @@ void env_admin_str(Info & i) User * puser = cur->session->puser; if( puser ) - puser->aenv.Serialize(i.out, true, false); + puser->aenv.serialize_to_space_stream(i.out, true); } diff --git a/winixd/templates/htmltextstream.cpp b/winixd/templates/htmltextstream.cpp index f7207d9..6f25bde 100644 --- a/winixd/templates/htmltextstream.cpp +++ b/winixd/templates/htmltextstream.cpp @@ -5,7 +5,7 @@ */ /* - * Copyright (c) 2010-2015, Tomasz Sowa + * Copyright (c) 2010-2021, Tomasz Sowa * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -555,7 +555,7 @@ HtmlTextStream & HtmlTextStream::operator<<(const PT::Space & space) { if( escape ) { - space.Serialize(*this, true, false); + space.serialize_to_space_stream(*this, true); /* tmp_stream.Clear(); diff --git a/winixd/templates/item.cpp b/winixd/templates/item.cpp index 0eac54a..64b210f 100644 --- a/winixd/templates/item.cpp +++ b/winixd/templates/item.cpp @@ -416,7 +416,7 @@ void item_sort(Info & i) void item_meta_str(Info & i) { - cur->request->last_item->item_content.meta.Serialize(i.out, true, false); + cur->request->last_item->item_content.meta.serialize_to_space_stream(i.out, true); } @@ -456,7 +456,7 @@ void item_meta_tab_has_next(Info & i) void item_admin_meta_str(Info & i) { - cur->request->last_item->item_content.meta_admin.Serialize(i.out, true, false); + cur->request->last_item->item_content.meta_admin.serialize_to_space_stream(i.out, true); } @@ -848,7 +848,7 @@ void item_tab_has_next(Info & i) void item_tab_meta_str(Info & i) { if( item_index < cur->request->item_tab.size() ) - cur->request->item_tab[item_index].item_content.meta.Serialize(i.out, true, false); + cur->request->item_tab[item_index].item_content.meta.serialize_to_space_stream(i.out, true); } diff --git a/winixd/templates/locale.cpp b/winixd/templates/locale.cpp index 2b47a21..599f5fc 100644 --- a/winixd/templates/locale.cpp +++ b/winixd/templates/locale.cpp @@ -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 @@ -88,7 +88,7 @@ return false; void Locale::ReadFile(const char * dir, const char * dir_def, const char * file) { bool read = false; - temp_space.Clear(); + temp_space.clear(); if( dir_def && ReadFile(dir_def, file) ) read = true; @@ -113,7 +113,7 @@ bool read = false; file_name += file; loc_parser.SetSpace(temp_space); - PT::SpaceParser::Status status = loc_parser.Parse(file_name); + PT::SpaceParser::Status status = loc_parser.ParseSpaceFile(file_name); if( status == PT::SpaceParser::ok ) { @@ -123,7 +123,7 @@ bool read = false; else if( status == PT::SpaceParser::syntax_error ) { - log << log1 << "Locale: syntax error in: " << file_name << " in line: " << loc_parser.line << logend; + log << log1 << "Locale: syntax error in: " << file_name << " in line: " << loc_parser.get_last_parsed_line() << logend; } return read; @@ -133,7 +133,7 @@ return read; void Locale::AddLocale(const char * file) { - std::wstring * id_str = temp_space.GetFirstValue(L"winix_locale_id"); + std::wstring * id_str = temp_space.get_wstr(L"winix_locale_id"); if( !id_str ) { @@ -160,6 +160,7 @@ void Locale::ReadSubstTable(const char * dir, const char * dir_def) { bool read = false; + temp_space.clear(); subst_url.clear(); subst_smalllet.clear(); subst_capitallet.clear(); @@ -186,17 +187,17 @@ bool read = false; loc_parser.SetSpace(temp_space); - if( loc_parser.Parse(file_name) == PT::SpaceParser::ok ) + if( loc_parser.ParseSpaceFile(file_name) == PT::SpaceParser::ok ) { read = true; - CreateSubstVector(subst_url, temp_space.Text(L"url_original"), temp_space.Text(L"url_changeto")); - CreateSubstVector(subst_smalllet, temp_space.Text(L"smallleters"), temp_space.Text(L"capitalics")); - CreateSubstVector(subst_capitallet, temp_space.Text(L"capitalics"), temp_space.Text(L"smallleters")); + CreateSubstVector(subst_url, temp_space.to_wstr(L"url_original"), temp_space.to_wstr(L"url_changeto")); + CreateSubstVector(subst_smalllet, temp_space.to_wstr(L"smallleters"), temp_space.to_wstr(L"capitalics")); + CreateSubstVector(subst_capitallet, temp_space.to_wstr(L"capitalics"), temp_space.to_wstr(L"smallleters")); - std::vector * sort_vec = temp_space.GetValue(L"sort"); + std::vector sort_vec; - if( sort_vec ) - CreateSubstSortVector(subst_sort, *sort_vec); + if( temp_space.to_list(L"sort", sort_vec) ) + CreateSubstSortVector(subst_sort, sort_vec); log << log3 << "Locale: read characters substitution tables from: " << file_name << logend; } @@ -361,7 +362,7 @@ const std::wstring * Locale::GetKeyInLanguage(const std::wstring & key, size_t l size_t index = locale_indices[lang_id]; if( index < locale_tab.size() ) - return locale_tab[index].GetFirstValue(key); + return locale_tab[index].get_wstr(key.c_str()); } return 0; @@ -425,64 +426,29 @@ return empty; -bool Locale::IsList(const wchar_t * key, bool try_default_too) + +bool Locale::GetList(const wchar_t * key, std::vector & list, bool try_default_too) { key_str = key; - return IsList(key_str, try_default_too); + return GetList(key_str, list, try_default_too); } -bool Locale::IsList(const std::wstring & key, bool try_default_too) const +bool Locale::GetList(const std::wstring & key, std::vector & list, bool try_default_too) const { - return IsList(key, current_lang, try_default_too); + return GetList(key, current_lang, list, try_default_too); } - -bool Locale::IsList(const wchar_t * key, size_t lang_id, bool try_default_too) +bool Locale::GetList(const wchar_t * key, size_t lang_id, std::vector & list, bool try_default_too) { key_str = key; - return IsList(key_str, lang_id, try_default_too); + return GetList(key_str, lang_id, list, try_default_too); } -bool Locale::IsList(const std::wstring & key, size_t lang_id, bool try_default_too) const -{ - if( GetListInLanguage(key, lang_id) != 0 ) - return true; - - if( !try_default_too || lang_id == default_lang ) - return false; - -return GetListInLanguage(key, default_lang) != 0; -} - - - - -const std::vector & Locale::GetList(const wchar_t * key, bool try_default_too) -{ - key_str = key; - return GetList(key_str, try_default_too); -} - - -const std::vector & Locale::GetList(const std::wstring & key, bool try_default_too) const -{ - return GetList(key, current_lang, try_default_too); -} - - -const std::vector & Locale::GetList(const wchar_t * key, size_t lang_id, bool try_default_too) -{ - key_str = key; - return GetList(key_str, lang_id, try_default_too); -} - - - -const std::vector * Locale::GetListInLanguage(const std::wstring & key, size_t lang_id) const +bool Locale::GetListInLanguage(const std::wstring & key, size_t lang_id, std::vector & list) const { if( lang_id < locale_indices.size() ) { @@ -490,34 +456,26 @@ const std::vector * Locale::GetListInLanguage(const std::wstring & if( index < locale_tab.size() ) { - PT::Space::Table::const_iterator i = locale_tab[index].table.find(key); - - if( i != locale_tab[index].table.end() ) - return &i->second; + return locale_tab[index].to_list(key, list); } } - -return 0; + + return false; } -const std::vector & Locale::GetList(const std::wstring & key, - size_t lang_id, bool try_default_too) const +bool Locale::GetList(const std::wstring & key, size_t lang_id, std::vector & list, bool try_default_too) const { - const std::vector * list = GetListInLanguage(key, lang_id); - - if( list ) - return *list; + if( GetListInLanguage(key, lang_id, list) ) + return true; if( !try_default_too || lang_id == default_lang ) - return empty_list; - - list = GetListInLanguage(key, default_lang); + return false; - if( list ) - return *list; + if( GetListInLanguage(key, default_lang, list) ) + return true; -return empty_list; + return false; } @@ -553,7 +511,7 @@ bool Locale::IsKeyByIndex(const std::wstring & key, size_t index, bool try_defau { if( index < locale_tab.size() ) { - if( locale_tab[index].GetValue(key) != 0 ) + if( locale_tab[index].get_object_field(key) != 0 ) return true; } @@ -582,7 +540,7 @@ const std::wstring & Locale::GetByIndex(const std::wstring & key, size_t index, { if( index < locale_tab.size() ) { - const std::wstring * value = locale_tab[index].GetFirstValue(key); + const std::wstring * value = locale_tab[index].get_wstr(key.c_str()); if( value ) return *value; @@ -613,47 +571,54 @@ bool Locale::IsListByIndex(const std::wstring & key, size_t index, bool try_defa { if( index < locale_tab.size() ) { - PT::Space::Table::const_iterator i = locale_tab[index].table.find(key); - - if( i != locale_tab[index].table.end() ) + if( locale_tab[index].has_key(key) ) return true; } if( try_default_too ) - return GetListInLanguage(key, default_lang) != 0; + return IsListInLanguage(key, default_lang); return false; } -const std::vector & Locale::GetListByIndex(const wchar_t * key, - size_t index, bool try_default_too) +bool Locale::IsListInLanguage(const std::wstring & key, size_t lang_id) const { - key_str = key; - return GetListByIndex(key_str, index, try_default_too); + if( lang_id < locale_indices.size() ) + { + size_t index = locale_indices[lang_id]; + + if( index < locale_tab.size() ) + { + if( locale_tab[index].has_key(key) ) + return true; + } + } + + return false; } -const std::vector & Locale::GetListByIndex(const std::wstring & key, - size_t index, bool try_default_too) const +bool Locale::GetListByIndex(const wchar_t * key, size_t index, std::vector & list, bool try_default_too) +{ + key_str = key; + return GetListByIndex(key_str, index, list, try_default_too); +} + + +bool Locale::GetListByIndex(const std::wstring & key, size_t index, std::vector & list, bool try_default_too) const { if( index < locale_tab.size() ) { - PT::Space::Table::const_iterator i = locale_tab[index].table.find(key); - - if( i != locale_tab[index].table.end() ) - return i->second; + return locale_tab[index].to_list(key, list); } if( try_default_too ) { - const std::vector * value = GetListInLanguage(key, default_lang); - - if( value ) - return *value; + return GetListInLanguage(key, default_lang, list); } -return empty_list; + return false; } diff --git a/winixd/templates/locale.h b/winixd/templates/locale.h index 63e5f10..3bbc3a1 100644 --- a/winixd/templates/locale.h +++ b/winixd/templates/locale.h @@ -145,18 +145,10 @@ public: // lists - // current limitation: - // we are looking only in 'space.table' so lists with only one item are not found - // (SplitSingle(true) was called to the space struct) - bool IsList(const wchar_t * key, bool try_default_too = true); - bool IsList(const std::wstring & key, bool try_default_too = true) const; - bool IsList(const wchar_t * key, size_t lang_id, bool try_default_too = true); - bool IsList(const std::wstring & key, size_t lang_id, bool try_default_too = true) const; - - const std::vector & GetList(const wchar_t * key, bool try_default_too = true); - const std::vector & GetList(const std::wstring & key, bool try_default_too = true) const; - const std::vector & GetList(const wchar_t * key, size_t lang_id, bool try_default_too = true); - const std::vector & GetList(const std::wstring & key, size_t lang_id, bool try_default_too = true) const; + bool GetList(const wchar_t * key, std::vector & list, bool try_default_too = true); + bool GetList(const std::wstring & key, std::vector & list, bool try_default_too = true) const; + bool GetList(const wchar_t * key, size_t lang_id, std::vector & list, bool try_default_too = true); + bool GetList(const std::wstring & key, size_t lang_id, std::vector & list, bool try_default_too = true) const; // converting lang_id to an internal index // returns an index from <0, Size()-1> or size_t(-1) if lang_id is incorrect @@ -181,10 +173,9 @@ public: // (SplitSingle(true) was called to the space struct) bool IsListByIndex(const wchar_t * key, size_t index, bool try_default_too = true); bool IsListByIndex(const std::wstring & key, size_t index, bool try_default_too = true) const; - const std::vector & GetListByIndex(const wchar_t * key, size_t index, - bool try_default_too = true); - const std::vector & GetListByIndex(const std::wstring & key, size_t index, - bool try_default_too = true) const; + + bool GetListByIndex(const wchar_t * key, size_t index, std::vector & list, bool try_default_too = true); + bool GetListByIndex(const std::wstring & key, size_t index, std::vector & list, bool try_default_too = true) const; // url substitution characters @@ -227,7 +218,8 @@ private: size_t SubstFindIndex(const std::vector & vect, wchar_t val); wchar_t SubstFind(const std::vector & vect, wchar_t val); const std::wstring * GetKeyInLanguage(const std::wstring & key, size_t lang_id) const; - const std::vector * GetListInLanguage(const std::wstring & key, size_t lang_id) const; + bool GetListInLanguage(const std::wstring & key, size_t lang_id, std::vector & list) const; + bool IsListInLanguage(const std::wstring & key, size_t lang_id) const; // locale files @@ -264,7 +256,6 @@ private: std::string file_name; std::wstring key_str; const std::wstring empty; // used when returning a non existing key from loc_tab (or in LangToFileName) - const std::vector empty_list; // the same as above std::string adir1, adir2; std::wstring pattern_value; }; diff --git a/winixd/templates/misc.cpp b/winixd/templates/misc.cpp index f57d928..29334d0 100644 --- a/winixd/templates/misc.cpp +++ b/winixd/templates/misc.cpp @@ -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 @@ -143,7 +143,7 @@ void print_date_nice(Info & i, const PT::Date & date) // cannot be a const reference at the moment (PT::Space is used) void print_user_name(Info & i, User & user) { - std::wstring * dname = user.aenv.GetFirstValue(L"display_name"); + std::wstring * dname = user.aenv.get_wstr(L"display_name"); if( dname && !IsWhite(*dname, true) ) i.out << *dname; diff --git a/winixd/templates/miscspace.cpp b/winixd/templates/miscspace.cpp index 6e4b6b8..dd3dc31 100644 --- a/winixd/templates/miscspace.cpp +++ b/winixd/templates/miscspace.cpp @@ -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 @@ -75,12 +75,14 @@ void copy_space(const std::vector & params, std::vector PT::Space * find_space(const std::vector & params, PT::Space & space, size_t level = 0) { - if( level + 1 < params.size() ) + if( level + 1 < params.size() && space.child_spaces ) { - for(size_t i=0 ; isize() ; ++i) { - if( space.spaces[i]->name == params[level].str ) - return find_space(params, *space.spaces[i], level+1); + PT::Space & child = *(*space.child_spaces)[i]; + + if( child.name && *child.name == params[level].str ) + return find_space(params, child, level+1); } // there is no such a space @@ -155,7 +157,7 @@ void space_value(Info & i, PT::Space & space, bool escape) if( space_info.last_space ) { const std::wstring & param = i.params.back().str; - const std::wstring * value = space_info.last_space->GetFirstValue(param); + const std::wstring * value = space_info.last_space->get_wstr(param.c_str()); if( value ) { @@ -193,7 +195,7 @@ void space_list_tab(Info & i, PT::Space & space) PT::Space * dst_space = find_space(i.params, space); if( dst_space ) - dst_space->ListText(i.params.back().str, stack_item->values); + dst_space->to_list(i.params.back().str, stack_item->values); i.res = i.iter < stack_item->values.size(); } diff --git a/winixd/templates/templates.cpp b/winixd/templates/templates.cpp index cc1db03..4dd67dc 100644 --- a/winixd/templates/templates.cpp +++ b/winixd/templates/templates.cpp @@ -899,11 +899,15 @@ using namespace TemplatesFunctions; for(size_t i=0 ; i orphans; + TemplatesFunctions::locale.GetListByIndex(L"language_orphans", i, orphans, false); + + html_filter.AssignOrphans(html_lang_attr, orphans); } } } diff --git a/winixd/templates/textextstream.cpp b/winixd/templates/textextstream.cpp index 2722ac9..a70680e 100644 --- a/winixd/templates/textextstream.cpp +++ b/winixd/templates/textextstream.cpp @@ -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 @@ -477,7 +477,7 @@ TexTextStream & TexTextStream::operator<<(const PT::Space & space) tmp_stream.Clear(); // !! IMPROVE ME // we can calculate how many memory is needed beforehand - space.Serialize(tmp_stream, true, false); + space.serialize_to_space_stream(tmp_stream, true); operator<<(tmp_stream.Str()); tmp_stream.Clear();