changed: we do not make a 'base redirect' when the request method is POST

changed: ConfParser -- now we have spaces (only one level)



git-svn-id: svn://ttmath.org/publicrep/winix/trunk@767 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
Tomasz Sowa 2011-09-16 22:46:42 +00:00
parent f113e2ef31
commit 60f0e62c23
11 changed files with 546 additions and 307 deletions

View File

@ -189,6 +189,9 @@ bool App::BaseUrlRedirect()
{ {
if( config.base_url.empty() ) if( config.base_url.empty() )
return false; return false;
if( cur.request->method == Request::post )
return false;
if( Equal(config.base_url.c_str(), cur.request->env_http_host) ) if( Equal(config.base_url.c_str(), cur.request->env_http_host) )
return false; return false;
@ -202,6 +205,9 @@ return true;
bool App::ShouldChangeToSSL() bool App::ShouldChangeToSSL()
{ {
if( cur.request->method == Request::post )
return false;
if( !config.use_ssl || cur.request->using_ssl ) if( !config.use_ssl || cur.request->using_ssl )
return false; return false;

View File

@ -295,37 +295,37 @@ void Config::CheckPasswd()
std::wstring Config::Text(const wchar_t * name) std::wstring & Config::Text(const wchar_t * name)
{ {
return parser.Text(name); return parser.Text(name);
} }
std::wstring Config::Text(const wchar_t * name, const wchar_t * def) std::wstring & Config::Text(const wchar_t * name, const wchar_t * def)
{ {
return parser.Text(name, def); return parser.Text(name, def);
} }
std::wstring Config::Text(const std::wstring & name, const std::wstring & def) std::wstring & Config::Text(const std::wstring & name, const wchar_t * def)
{ {
return parser.Text(name, def); return parser.Text(name, def);
} }
std::string Config::AText(const wchar_t * name) std::string & Config::AText(const wchar_t * name)
{ {
return parser.AText(name); return parser.AText(name);
} }
std::string Config::AText(const wchar_t * name, const wchar_t * def) std::string & Config::AText(const wchar_t * name, const wchar_t * def)
{ {
return parser.AText(name, def); return parser.AText(name, def);
} }
std::string Config::AText(const std::wstring & name, const std::wstring & def) std::string & Config::AText(const std::wstring & name, const wchar_t * def)
{ {
return parser.AText(name, def); return parser.AText(name, def);
} }

View File

@ -455,12 +455,12 @@ public:
Config(); Config();
bool ReadConfig(bool errors_to_stdout_, bool stdout_is_closed = true); bool ReadConfig(bool errors_to_stdout_, bool stdout_is_closed = true);
std::wstring Text(const wchar_t * name); std::wstring & Text(const wchar_t * name);
std::wstring Text(const wchar_t * name, const wchar_t * def); std::wstring & Text(const wchar_t * name, const wchar_t * def);
std::wstring Text(const std::wstring & name, const std::wstring & def); std::wstring & Text(const std::wstring & name, const wchar_t * def);
std::string AText(const wchar_t * name); std::string & AText(const wchar_t * name);
std::string AText(const wchar_t * name, const wchar_t * def); std::string & AText(const wchar_t * name, const wchar_t * def);
std::string AText(const std::wstring & name, const std::wstring & def); std::string & AText(const std::wstring & name, const wchar_t * def);
int Int(const wchar_t *); int Int(const wchar_t *);
int Int(const wchar_t * name, int def); int Int(const wchar_t * name, int def);

View File

@ -2,7 +2,7 @@
* This file is a part of Winix * This file is a part of Winix
* and is not publicly distributed * and is not publicly distributed
* *
* Copyright (c) 2008-2010, Tomasz Sowa * Copyright (c) 2008-2011, Tomasz Sowa
* All rights reserved. * All rights reserved.
* *
*/ */
@ -10,30 +10,35 @@
#include <cstdlib> #include <cstdlib>
#include <wchar.h> #include <wchar.h>
#include "confparser.h" #include "confparser.h"
#include "misc.h"
#include "utf8.h" #include "utf8.h"
ConfParser::ConfParser() ConfParser::ConfParser()
{
SetDefault();
}
void ConfParser::SetDefault()
{ {
// you can change this separators to what you want // you can change this separators to what you want
// you shoud not use only white characters here (as expected by IsWhite() method) // you shoud not use only white characters here (as expected by IsWhite() method)
// and new line characters ('\n') // and new line characters ('\n')
separator = '='; separator = '=';
commentary = '#'; commentary = '#';
list_start = '('; list_start = '(';
list_end = ')'; list_end = ')';
list_delimiter = ','; list_delimiter = ',';
split_single = false; split_single = false;
skip_empty = false; skip_empty = false;
use_escape_char = true; use_escape_char = true;
input_as_utf8 = false; input_as_utf8 = false;
default_str = L""; default_str = L"";
default_int = 0; default_int = 0;
default_size = 0; default_size = 0;
default_bool = false; default_bool = false;
} }
@ -55,22 +60,38 @@ void ConfParser::UseEscapeChar(bool escape)
} }
void ConfParser::UTF8(bool utf)
{
input_as_utf8 = utf;
}
void ConfParser::Clear()
{
space.table.clear();
space.table_single.clear();
spaces.clear();
line = 1;
using_global_space = true;
pchar_ascii = 0;
pchar_unicode = 0;
status = ok;
}
ConfParser::Status ConfParser::Parse(const char * file_name) ConfParser::Status ConfParser::Parse(const char * file_name)
{ {
Clear();
reading_from_file = true; reading_from_file = true;
line = 1;
table.clear();
table_single.clear();
file.clear(); file.clear();
file.open( file_name ); file.open( file_name );
if( file ) if( file )
{ {
status = ParseFile(); Parse();
file.close(); file.close();
} }
else else
@ -108,15 +129,12 @@ ConfParser::Status ConfParser::Parse(const std::wstring & file_name)
ConfParser::Status ConfParser::ParseString(const char * str) ConfParser::Status ConfParser::ParseString(const char * str)
{ {
Clear();
reading_from_file = false; reading_from_file = false;
reading_from_wchar_string = false; reading_from_wchar_string = false;
line = 1; pchar_ascii = str;
table.clear();
table_single.clear();
pchar_ascii = str;
pchar_unicode = 0;
status = ParseFile(); Parse();
return status; return status;
} }
@ -130,15 +148,12 @@ ConfParser::Status ConfParser::ParseString(const std::string & str)
ConfParser::Status ConfParser::ParseString(const wchar_t * str) ConfParser::Status ConfParser::ParseString(const wchar_t * str)
{ {
Clear();
reading_from_file = false; reading_from_file = false;
reading_from_wchar_string = true; reading_from_wchar_string = true;
line = 1; pchar_unicode = str;
table.clear();
table_single.clear();
pchar_ascii = 0;
pchar_unicode = str;
status = ParseFile(); Parse();
return status; return status;
} }
@ -150,35 +165,89 @@ ConfParser::Status ConfParser::ParseString(const std::wstring & str)
} }
ConfParser::Status ConfParser::ParseFile() void ConfParser::Parse()
{ {
status = ok;
ReadChar(); ReadChar();
SkipWhiteLines(); SkipWhiteLines();
while( lastc != -1 ) while( status == ok && lastc != -1 )
{ {
if( !ReadVariable() ) if( lastc == list_end )
return syntax_error; {
TestListEnd();
}
else
{
ReadVariable();
if( lastc != separator ) if( lastc == list_start )
return syntax_error; {
TestListStart();
if( !ReadValue() ) }
return syntax_error; else
if( lastc == separator && !variable.empty() )
{
ReadAddValue();
}
else
{
status = syntax_error;
}
}
AddOption(); if( status == ok )
SkipWhite(); SkipWhiteLines();
if( lastc != -1 && lastc != '\n' )
return syntax_error; // some characters have left at the end of an option
SkipWhiteLines();
} }
return ok;
} }
void ConfParser::TestListEnd()
{
if( using_global_space )
{
// there cannot be a loose list end character in the global space
status = syntax_error;
}
else
{
using_global_space = true;
ReadChar();
}
}
void ConfParser::TestListStart()
{
if( using_global_space )
{
spaces.insert(spaces.end(), Space());
spaces.back().name = variable;
using_global_space = false;
ReadChar();
}
else
{
// only one additional level of spaces is allowed
status = syntax_error;
}
}
void ConfParser::ReadAddValue()
{
ReadChar(); // skipping separator '='
if( ReadValue() )
{
AddOption();
}
else
{
status = syntax_error;
}
}
bool ConfParser::IsVariableChar(int c) bool ConfParser::IsVariableChar(int c)
{ {
@ -192,6 +261,105 @@ return false;
} }
bool ConfParser::IsWhite(int c)
{
// dont use '\n' here
// 13 (\r) is at the end of a line in a dos file \r\n
// 160 is an unbreakable space
if( c==' ' || c=='\t' || c==13 || c==160 )
return true;
return false;
}
void ConfParser::SkipWhite()
{
while( IsWhite(lastc) || lastc == commentary )
{
if( lastc == commentary )
SkipLine();
else
ReadChar();
}
}
void ConfParser::SkipWhiteLines()
{
while( IsWhite(lastc) || lastc == commentary || lastc=='\n' )
{
if( lastc == commentary )
SkipLine();
else
ReadChar();
}
}
void ConfParser::SkipLine()
{
while( lastc != -1 && lastc != '\n' )
ReadChar();
}
void ConfParser::Trim(std::wstring & s)
{
std::wstring::size_type i;
if( s.empty() )
return;
// looking for white characters at the end
for(i=s.size()-1 ; i>0 && IsWhite(s[i]) ; --i);
if( i==0 && IsWhite(s[i]) )
{
// the whole string has white characters
s.clear();
return;
}
// deleting white characters at the end
if( i != s.size() - 1 )
s.erase(i+1, std::wstring::npos);
// looking for white characters at the beginning
for(i=0 ; i<s.size() && IsWhite(s[i]) ; ++i);
// deleting white characters at the beginning
if( i != 0 )
s.erase(0, i);
}
wchar_t ConfParser::ToSmall(wchar_t c)
{
if( c>='A' && c<='Z' )
c = c - 'A' + 'a';
return c;
}
bool ConfParser::EqualNoCase(const wchar_t * str1, const wchar_t * str2)
{
while( *str1 && *str2 && ToSmall(*str1) == ToSmall(*str2) )
{
++str1;
++str2;
}
if( *str1 == 0 && *str2 == 0 )
return true;
return false;
}
void ConfParser::AddOption() void ConfParser::AddOption()
{ {
@ -202,14 +370,19 @@ void ConfParser::AddOption()
return; return;
} }
Space * ps = &space;
if( !using_global_space && !spaces.empty() )
ps = &spaces.back();
if( split_single && value.size() == 1 ) if( split_single && value.size() == 1 )
{ {
table_single[variable] = value[0]; ps->table_single[variable] = value[0];
DeleteFromTable(variable); DeleteFromTable(variable);
} }
else else
{ {
table[variable] = value; ps->table[variable] = value;
DeleteFromTableSingle(variable); DeleteFromTableSingle(variable);
} }
} }
@ -218,25 +391,35 @@ void ConfParser::AddOption()
void ConfParser::DeleteFromTable(const std::wstring & var) void ConfParser::DeleteFromTable(const std::wstring & var)
{ {
Table::iterator i = table.find(var); Space * ps = &space;
if( i != table.end() ) if( !using_global_space && !spaces.empty() )
table.erase(i); ps = &spaces.back();
Table::iterator i = ps->table.find(var);
if( i != ps->table.end() )
ps->table.erase(i);
} }
void ConfParser::DeleteFromTableSingle(const std::wstring & var) void ConfParser::DeleteFromTableSingle(const std::wstring & var)
{ {
TableSingle::iterator i = table_single.find(var); Space * ps = &space;
if( i != table_single.end() ) if( !using_global_space && !spaces.empty() )
table_single.erase(i); ps = &spaces.back();
TableSingle::iterator i = ps->table_single.find(var);
if( i != ps->table_single.end() )
ps->table_single.erase(i);
} }
bool ConfParser::ReadVariable() void ConfParser::ReadVariable()
{ {
variable.clear(); variable.clear();
SkipWhite(); SkipWhite();
@ -248,8 +431,6 @@ bool ConfParser::ReadVariable()
} }
SkipWhite(); SkipWhite();
return !variable.empty();
} }
@ -257,7 +438,6 @@ return !variable.empty();
bool ConfParser::ReadValue() bool ConfParser::ReadValue()
{ {
value.clear(); value.clear();
ReadChar(); // skipping separator '='
SkipWhite(); SkipWhite();
if( lastc == list_start ) if( lastc == list_start )
@ -351,10 +531,10 @@ bool ConfParser::ReadValueSimple(bool use_list_delimiter)
int list_delimiter2 = -1; int list_delimiter2 = -1;
if( use_list_delimiter ) if( use_list_delimiter )
{
list_delimiter1 = list_delimiter; list_delimiter1 = list_delimiter;
if( use_list_delimiter || !using_global_space )
list_delimiter2 = list_end; list_delimiter2 = list_end;
}
while( lastc!=-1 && lastc!='\n' && lastc!=commentary && while( lastc!=-1 && lastc!='\n' && lastc!=commentary &&
lastc!=list_delimiter1 && lastc!=list_delimiter2 ) lastc!=list_delimiter1 && lastc!=list_delimiter2 )
@ -490,148 +670,128 @@ int ConfParser::ReadChar()
} }
bool ConfParser::IsWhite(int c)
bool ConfParser::Space::GetValue(const wchar_t * name, std::wstring & out)
{ {
// dont use '\n' here tmp_name = name;
// 13 (\r) is at the end of a line in a dos file \r\n return GetValue(tmp_name, out, L"");
// 160 is an unbreakable space
if( c==' ' || c=='\t' || c==13 || c==160 )
return true;
return false;
} }
bool ConfParser::Space::GetValue(const wchar_t * name, std::wstring & out, const wchar_t * def)
void ConfParser::SkipWhite()
{ {
while( IsWhite(lastc) || lastc == commentary ) tmp_name = name;
{ return GetValue(tmp_name, out, def);
if( lastc == commentary )
SkipLine();
else
ReadChar();
}
} }
void ConfParser::SkipWhiteLines() bool ConfParser::Space::GetValue(const std::wstring & name, std::wstring & out)
{ {
while( IsWhite(lastc) || lastc == commentary || lastc=='\n' ) return GetValue(name, out, L"");
{
if( lastc == commentary )
SkipLine();
else
ReadChar();
}
} }
void ConfParser::SkipLine() bool ConfParser::Space::GetValue(const std::wstring & name, std::wstring & out, const wchar_t * def)
{
while( lastc != -1 && lastc != '\n' )
ReadChar();
}
void ConfParser::Trim(std::wstring & s)
{
std::wstring::size_type i;
if( s.empty() )
return;
// looking for white characters at the end
for(i=s.size()-1 ; i>0 && IsWhite(s[i]) ; --i);
if( i==0 && IsWhite(s[i]) )
{
// the whole string has white characters
s.clear();
return;
}
// deleting white characters at the end
if( i != s.size() - 1 )
s.erase(i+1, std::wstring::npos);
// looking for white characters at the beginning
for(i=0 ; i<s.size() && IsWhite(s[i]) ; ++i);
// deleting white characters at the beginning
if( i != 0 )
s.erase(0, i);
}
std::wstring ConfParser::Text(const wchar_t * name)
{
return Text(std::wstring(name), default_str);
}
std::wstring ConfParser::Text(const wchar_t * name, const wchar_t * def)
{
return Text(std::wstring(name), std::wstring(def));
}
std::wstring ConfParser::Text(const std::wstring & name, const std::wstring & def)
{ {
TableSingle::iterator i = table_single.find(name); TableSingle::iterator i = table_single.find(name);
if( i == table_single.end() ) if( i != table_single.end() )
{
out = i->second;
return true;
}
else
{ {
Table::iterator t = table.find(name); Table::iterator t = table.find(name);
if( t == table.end() || t->second.empty() ) if( t == table.end() || t->second.empty() )
return def; {
out = def;
return t->second[0]; return false;
}
else
{
out = t->second[0];
return true;
}
} }
return i->second;
} }
std::string ConfParser::AText(const wchar_t * name)
void ConfParser::ToText(const wchar_t * name, std::wstring & out)
{ {
std::wstring res = Text(name); tmp_name = name;
std::string ares; return ToText(tmp_name, out, default_str.c_str());
}
Ezc::WideToUTF8(res, ares);
return ares; void ConfParser::ToText(const wchar_t * name, std::wstring & out, const wchar_t * def)
{
tmp_name = name;
return ToText(tmp_name, out, def);
}
void ConfParser::ToText(const std::wstring & name, std::wstring & out, const wchar_t * def)
{
space.GetValue(name, out, def);
} }
std::string ConfParser::AText(const wchar_t * name, const wchar_t * def)
std::wstring & ConfParser::Text(const wchar_t * name)
{ {
std::wstring res = Text(name, def); ToText(name, tmp_value_text);
std::string ares; return tmp_value_text;
Ezc::WideToUTF8(res, ares);
return ares;
} }
std::string ConfParser::AText(const std::wstring & name, const std::wstring & def)
std::wstring & ConfParser::Text(const wchar_t * name, const wchar_t * def)
{ {
std::wstring res = Text(name, def); ToText(name, tmp_value_text, def);
std::string ares; return tmp_value_text;
}
Ezc::WideToUTF8(res, ares);
return ares; std::wstring & ConfParser::Text(const std::wstring & name, const wchar_t * def)
{
ToText(name, tmp_value_text, def);
return tmp_value_text;
}
std::string & ConfParser::AText(const wchar_t * name)
{
ToText(name, tmp_value_text);
Ezc::WideToUTF8(tmp_value_text, tmp_value_text_ascii);
return tmp_value_text_ascii;
}
std::string & ConfParser::AText(const wchar_t * name, const wchar_t * def)
{
ToText(name, tmp_value_text, def);
Ezc::WideToUTF8(tmp_value_text, tmp_value_text_ascii);
return tmp_value_text_ascii;
}
std::string & ConfParser::AText(const std::wstring & name, const wchar_t * def)
{
ToText(name, tmp_value_text, def);
Ezc::WideToUTF8(tmp_value_text, tmp_value_text_ascii);
return tmp_value_text_ascii;
} }
@ -639,13 +799,15 @@ return ares;
int ConfParser::Int(const wchar_t * name) int ConfParser::Int(const wchar_t * name)
{ {
return Int(std::wstring(name), default_int); tmp_name = name;
return Int(tmp_name, default_int);
} }
int ConfParser::Int(const wchar_t * name, int def) int ConfParser::Int(const wchar_t * name, int def)
{ {
return Int(std::wstring(name), def); tmp_name = name;
return Int(tmp_name, def);
} }
@ -659,32 +821,25 @@ return static_cast<int>(res);
int ConfParser::Int(const std::wstring & name, int def) int ConfParser::Int(const std::wstring & name, int def)
{ {
TableSingle::iterator i = table_single.find(name); if( space.GetValue(name, tmp_value_text) )
return ToInt(tmp_value_text);
if( i == table_single.end() )
{
Table::iterator t = table.find(name);
if( t == table.end() || t->second.empty() ) return def;
return def;
return ToInt(t->second[0]);
}
return ToInt(i->second);
} }
size_t ConfParser::Size(const wchar_t * name) size_t ConfParser::Size(const wchar_t * name)
{ {
return Size(std::wstring(name), default_size); tmp_name = name;
return Size(tmp_name, default_size);
} }
size_t ConfParser::Size(const wchar_t * name, size_t def) size_t ConfParser::Size(const wchar_t * name, size_t def)
{ {
return Size(std::wstring(name), def); tmp_name = name;
return Size(tmp_name, def);
} }
@ -699,19 +854,10 @@ return static_cast<size_t>(res);
size_t ConfParser::Size(const std::wstring & name, size_t def) size_t ConfParser::Size(const std::wstring & name, size_t def)
{ {
TableSingle::iterator i = table_single.find(name); if( space.GetValue(name, tmp_value_text) )
return ToSize(tmp_value_text);
if( i == table_single.end() )
{
Table::iterator t = table.find(name);
if( t == table.end() || t->second.empty() ) return def;
return def;
return ToSize(t->second[0]);
}
return ToSize(i->second);
} }
@ -719,16 +865,19 @@ return ToSize(i->second);
bool ConfParser::Bool(const wchar_t * name) bool ConfParser::Bool(const wchar_t * name)
{ {
return Bool(std::wstring(name), default_bool); tmp_name = name;
return Bool(tmp_name, default_bool);
} }
bool ConfParser::Bool(const wchar_t * name, bool def) bool ConfParser::Bool(const wchar_t * name, bool def)
{ {
return Bool(std::wstring(name), def); tmp_name = name;
return Bool(tmp_name, def);
} }
bool ConfParser::ToBool(const std::wstring & value) bool ConfParser::ToBool(const std::wstring & value)
{ {
return ( EqualNoCase(value.c_str(), L"true") || return ( EqualNoCase(value.c_str(), L"true") ||
@ -740,22 +889,18 @@ bool ConfParser::ToBool(const std::wstring & value)
bool ConfParser::Bool(const std::wstring & name, bool def) bool ConfParser::Bool(const std::wstring & name, bool def)
{ {
TableSingle::iterator i = table_single.find(name); if( space.GetValue(name, tmp_value_text) )
return ToBool(tmp_value_text);
if( i == table_single.end() )
{
Table::iterator t = table.find(name);
if( t == table.end() || t->second.empty() ) return def;
return def;
return ToBool(t->second[0]);
}
return ToBool(i->second);
} }
void ConfParser::SetDefaultText(const wchar_t * def)
{
default_str = def;
}
void ConfParser::SetDefaultText(const std::wstring & def) void ConfParser::SetDefaultText(const std::wstring & def)
{ {
default_str = def; default_str = def;
@ -782,45 +927,38 @@ void ConfParser::SetDefaultBool(bool def)
// in lists we don't use default values // in lists we don't use default values
void ConfParser::ListText(const wchar_t * name, std::vector<std::wstring> & list) void ConfParser::ListText(const wchar_t * name, std::vector<std::wstring> & list)
{ {
ListText(std::wstring(name), list); tmp_name = name;
ListText(tmp_name, list);
} }
void ConfParser::ListText(const std::wstring & name, std::vector<std::wstring> & list) void ConfParser::ListText(const std::wstring & name, std::vector<std::wstring> & list)
{ {
list.clear(); list.clear();
ConfParser::TableSingle::iterator i = space.table_single.find(name);
ConfParser::TableSingle::iterator i = table_single.find(name);
if( i != table_single.end() ) if( i != space.table_single.end() )
{ {
list.push_back(i->second); list.push_back(i->second);
return;
} }
else
ConfParser::Table::iterator z = table.find(name);
if( z != table.end() )
{ {
list = z->second; ConfParser::Table::iterator z = space.table.find(name);
return;
if( z != space.table.end() )
list = z->second;
} }
} }
void ConfParser::UTF8(bool utf)
{
input_as_utf8 = utf;
}
void ConfParser::Print(std::ostream & out) void ConfParser::Print(std::ostream & out)
{ {
TableSingle::iterator i1; TableSingle::iterator i1;
for(i1 = table_single.begin() ; i1 != table_single.end() ; ++i1) for(i1 = space.table_single.begin() ; i1 != space.table_single.end() ; ++i1)
{ {
Ezc::WideToUTF8(i1->first, out); Ezc::WideToUTF8(i1->first, out);
out << '='; out << '=';
@ -831,7 +969,7 @@ void ConfParser::Print(std::ostream & out)
Table::iterator i2; Table::iterator i2;
Value::iterator i3; Value::iterator i3;
for(i2 = table.begin() ; i2 != table.end() ; ++i2) for(i2 = space.table.begin() ; i2 != space.table.end() ; ++i2)
{ {
Ezc::WideToUTF8(i2->first, out); Ezc::WideToUTF8(i2->first, out);
out << '='; out << '=';

View File

@ -2,7 +2,7 @@
* This file is a part of Winix * This file is a part of Winix
* and is not publicly distributed * and is not publicly distributed
* *
* Copyright (c) 2008-2010, Tomasz Sowa * Copyright (c) 2008-2011, Tomasz Sowa
* All rights reserved. * All rights reserved.
* *
*/ */
@ -13,6 +13,7 @@
#include <fstream> #include <fstream>
#include <string> #include <string>
#include <vector> #include <vector>
#include <list>
#include <map> #include <map>
@ -130,9 +131,28 @@ class ConfParser
{ {
public: public:
/*
ctor -- setting default values (SetDefault() method)
*/
ConfParser(); ConfParser();
/*
setting options of the parser to the default values
utf8, split single etc.
*/
void SetDefault();
/*
clearing
this method doesn't call SetDefault() only those parsed values are cleared
and the status is set to 'ok'
*/
void Clear();
/* /*
status of parsing status of parsing
*/ */
@ -146,7 +166,13 @@ public:
/* /*
the main methods used to parse a number of a line in which there is a syntax_error
*/
int line;
/*
main methods used to parse
file_name is the path to a file file_name is the path to a file
*/ */
Status Parse(const char * file_name); Status Parse(const char * file_name);
@ -154,47 +180,23 @@ public:
Status Parse(const wchar_t * file_name); Status Parse(const wchar_t * file_name);
Status Parse(const std::wstring & file_name); Status Parse(const std::wstring & file_name);
/* /*
the main methods used to parse main methods used to parse
str - input string (either 8bit ascii or UTF-8) str - input string (either 8bit ascii or UTF-8 -- see UTF8() method)
*/ */
Status ParseString(const char * str); Status ParseString(const char * str);
Status ParseString(const std::string & str); Status ParseString(const std::string & str);
// here input string is always in unicode
/*
main methods used to parse
here input string is always in unicode (wide characters)
*/
Status ParseString(const wchar_t * str); Status ParseString(const wchar_t * str);
Status ParseString(const std::wstring & str); Status ParseString(const std::wstring & str);
/*
a number of a line in which there is a syntax_error
*/
int line;
/*
this is the table which represents your config file
in the Table map: the first (key) is your 'option' and the second is 'list'
*/
typedef std::vector<std::wstring> Value;
typedef std::map<std::wstring, Value> Table;
Table table;
/*
if your config file consists mainly of single forms such as:
option = value
option2 = value2
then you can call SplitSingle(true) for not inserting single values to
previous 'table' but instead to 'table_single'
table_single as the second parameter takes only std::wstring (instead of the whole std::vector)
so you can save a little memory from not using std::vector
*/
typedef std::map<std::wstring, std::wstring> TableSingle;
TableSingle table_single;
/* /*
if your list consists of only one item, e.g: if your list consists of only one item, e.g:
option1 = value 1 option1 = value 1
@ -208,7 +210,7 @@ public:
/* /*
if true then empty lists, e.g: if true then empty values and lists, e.g:
option = option =
option2 = () option2 = ()
will be omitted (not inserted to 'table' or 'table_single') will be omitted (not inserted to 'table' or 'table_single')
@ -227,27 +229,42 @@ public:
/* /*
those methods are used to extract information from table or table_single if true then the input file or string (char* or std::string) is treated as UTF-8
*/
void UTF8(bool utf);
/*
those methods are used to extract information from space.table or space.table_single
as a parameter they take the name of an option as a parameter they take the name of an option
and a default value (if there is no such a parameter), and a default value (if there is no such a parameter),
they return appropriate value (either text, int or boolean) they return appropriate value (either text, int or boolean)
(in lists they return the first item if exists) (in lists they return the first item if exists)
when calling Text(...) and AText(...) you should copy the object to whom a reference is returned
it will be cleared in a next call to one of these methods (as well to Int() Size() and Bool())
AText(...) always returns a reference to UTF-8 string
*/ */
std::wstring Text(const wchar_t * name); void ToText(const wchar_t * name, std::wstring & out);
std::wstring Text(const wchar_t * name, const wchar_t * def); void ToText(const wchar_t * name, std::wstring & out, const wchar_t * def);
std::wstring Text(const std::wstring & name, const std::wstring & def); void ToText(const std::wstring & name, std::wstring & out, const wchar_t * def);
std::string AText(const wchar_t * name); std::wstring & Text(const wchar_t * name);
std::string AText(const wchar_t * name, const wchar_t * def); std::wstring & Text(const wchar_t * name, const wchar_t * def);
std::string AText(const std::wstring & name, const std::wstring & def); std::wstring & Text(const std::wstring & name, const wchar_t * def);
std::string & AText(const wchar_t * name);
std::string & AText(const wchar_t * name, const wchar_t * def);
std::string & AText(const std::wstring & name, const wchar_t * def);
int Int(const wchar_t *); int Int(const wchar_t *);
int Int(const wchar_t * name, int def); int Int(const wchar_t * name, int def);
int Int(const std::wstring & name, int def); int Int(const std::wstring & name, int def);
size_t Size(const wchar_t *); size_t Size(const wchar_t *);
size_t Size(const wchar_t * name, size_t def); size_t Size(const wchar_t * name, size_t def);
size_t Size(const std::wstring & name, size_t def); size_t Size(const std::wstring & name, size_t def);
bool Bool(const wchar_t *); bool Bool(const wchar_t *);
bool Bool(const wchar_t * name, bool def); bool Bool(const wchar_t * name, bool def);
bool Bool(const std::wstring & name, bool def); bool Bool(const std::wstring & name, bool def);
/* /*
@ -259,6 +276,7 @@ public:
default int or size is: 0 default int or size is: 0
default bool is: false default bool is: false
*/ */
void SetDefaultText(const wchar_t * def);
void SetDefaultText(const std::wstring & def); void SetDefaultText(const std::wstring & def);
void SetDefaultInt(int def); void SetDefaultInt(int def);
void SetDefaultSize(size_t def); void SetDefaultSize(size_t def);
@ -273,12 +291,6 @@ public:
void ListText(const std::wstring & name, std::vector<std::wstring> & list); void ListText(const std::wstring & name, std::vector<std::wstring> & list);
/*
if true then the input file is treated as UTF-8
*/
void UTF8(bool utf);
/* /*
printing the content printing the content
(for debug purposes) (for debug purposes)
@ -286,6 +298,67 @@ public:
void Print(std::ostream & out); void Print(std::ostream & out);
/*
*
*
raw access to the parsed values
*
*
*/
/*
this is the table which represents your config file
in the Table map: the first (key) is your 'option' and the second is 'list'
*/
typedef std::vector<std::wstring> Value;
typedef std::map<std::wstring, Value> Table;
/*
if your config file consists mainly of single forms such as:
option = value
option2 = value2
then you can call SplitSingle(true) for not inserting single values to
previous 'table' but instead to 'table_single'
table_single as the second parameter takes only std::wstring (instead of the whole std::vector)
so you can save a little memory from not using std::vector
*/
typedef std::map<std::wstring, std::wstring> TableSingle;
class Space
{
public:
std::wstring name; // space name
TableSingle table_single; // std::map<std::wstring, std::wstring>
Table table; // std::map<std::wstring, std::vector<std::wstring> >
// first we are searching in 'table_single' and if there is not
// such a 'name' there then we are looking in 'table' (for the first item in the vector)
// these methods return true if 'name' was found
// in other case they return false and 'out' will be equal 'def'
bool GetValue(const wchar_t * name, std::wstring & out);
bool GetValue(const wchar_t * name, std::wstring & out, const wchar_t * def);
bool GetValue(const std::wstring & name, std::wstring & out);
bool GetValue(const std::wstring & name, std::wstring & out, const wchar_t * def);
private:
std::wstring tmp_name;
std::wstring tmp_value;
};
// one global space (without a name)
Space space;
// first namespace
typedef std::list<Space> Spaces;
Spaces spaces;
private: private:
@ -295,6 +368,7 @@ private:
*/ */
bool reading_from_file; bool reading_from_file;
/* /*
pointers to the current character pointers to the current character
if ParseString() is in used if ParseString() is in used
@ -304,10 +378,11 @@ private:
/* /*
true if ParseString(wchar_t *) or ParseString(std::wstring&) is used true if ParseString(wchar_t *) or ParseString(std::wstring&) was called
*/ */
bool reading_from_wchar_string; bool reading_from_wchar_string;
/* /*
last read variable (option) last read variable (option)
*/ */
@ -398,6 +473,12 @@ private:
*/ */
bool use_escape_char; bool use_escape_char;
/*
if true we are parsing the global space
if false we are adding to the last item from spaces tab
*/
bool using_global_space;
std::string afile_name; std::string afile_name;
std::wstring default_str; std::wstring default_str;
@ -405,17 +486,24 @@ private:
size_t default_size; size_t default_size;
bool default_bool; bool default_bool;
std::wstring tmp_name;
std::wstring tmp_value_text;
std::string tmp_value_text_ascii;
int ToInt(const std::wstring & value); int ToInt(const std::wstring & value);
size_t ToSize(const std::wstring & value); size_t ToSize(const std::wstring & value);
bool ToBool(const std::wstring & value); bool ToBool(const std::wstring & value);
Status ParseFile(); void Parse();
void TestListEnd();
void TestListStart();
void ReadAddValue();
void AddOption(); void AddOption();
void DeleteFromTable(const std::wstring & var); void DeleteFromTable(const std::wstring & var);
void DeleteFromTableSingle(const std::wstring & var); void DeleteFromTableSingle(const std::wstring & var);
bool ReadVariable(); void ReadVariable();
bool ReadValue(); bool ReadValue();
bool ReadValueList(); bool ReadValueList();
bool ReadValueNoList(bool use_list_delimiter = false); bool ReadValueNoList(bool use_list_delimiter = false);
@ -433,7 +521,9 @@ private:
void SkipWhite(); void SkipWhite();
void SkipWhiteLines(); void SkipWhiteLines();
void SkipLine(); void SkipLine();
void Trim(std::wstring & s); void Trim(std::wstring & s);
wchar_t ToSmall(wchar_t c);
bool EqualNoCase(const wchar_t * str1, const wchar_t * str2);
}; };

View File

@ -77,7 +77,8 @@
// for adding a new mount type call: system->mounts.AddMountType("new_mount_name") // for adding a new mount type call: system->mounts.AddMountType("new_mount_name")
#define WINIX_ADD_MOUNTS 3009 #define WINIX_ADD_MOUNTS 3009
// add plugin functions here // add plugin functions (winix functions) here
// call info.functions->Add() to add a function
#define WINIX_CREATE_FUNCTIONS 3010 #define WINIX_CREATE_FUNCTIONS 3010
// choose a default function // choose a default function

View File

@ -149,6 +149,8 @@ void Users::LoginUser(long user_id, bool remember_me)
cur->session->remember_me = remember_me; cur->session->remember_me = remember_me;
last.UserLogin(user_id, cur->session->puser->name, inet_addr(cur->request->env_remote_addr), cur->session->id); last.UserLogin(user_id, cur->session->puser->name, inet_addr(cur->request->env_remote_addr), cur->session->id);
// !! jesli uzytkownik ponownie sie loguje ten sam na ta sama sesje to mozna nie zwiekszac licznika
how_many_logged += 1; how_many_logged += 1;
log << log2 << "User " << cur->session->puser->name << " (id: " << user_id << ") logged" << logend; log << log2 << "User " << cur->session->puser->name << " (id: " << user_id << ") logged" << logend;

View File

@ -103,6 +103,9 @@ void Login::MakePost()
return; return;
} }
if( cur->session->puser )
system->users.LogoutCurrentUser();
const std::wstring & login = cur->request->PostVar(L"login"); const std::wstring & login = cur->request->PostVar(L"login");
const std::wstring & pass = cur->request->PostVar(L"password"); const std::wstring & pass = cur->request->PostVar(L"password");
const std::wstring & remem = cur->request->PostVar(L"rememberme"); const std::wstring & remem = cur->request->PostVar(L"rememberme");
@ -114,7 +117,7 @@ void Login::MakePost()
} }
else else
{ {
// !! moze zglosic komunikat o nie poprawnym logowaniu log << log2 << "Login: incorrect login/password" << logend;
} }
system->RedirectToLastItem(); system->RedirectToLastItem();

View File

@ -29,7 +29,6 @@ public:
private: private:
void LoginUser(long user_id, bool remember_me);
void ClearTmpStruct(); void ClearTmpStruct();
bool CheckPasswords(const std::wstring & password); bool CheckPasswords(const std::wstring & password);

View File

@ -50,7 +50,7 @@ bool GroupInfo::ParseGroups(const std::wstring & str, Groups & groups)
{ {
ConfParser::Table::iterator i; ConfParser::Table::iterator i;
for(i=conf_parser.table.begin() ; i!=conf_parser.table.end() ; ++i) for(i=conf_parser.space.table.begin() ; i!=conf_parser.space.table.end() ; ++i)
{ {
groups.AddGroup(); groups.AddGroup();
log << log1 << "stworzylem nowa grupe" << logend; log << log1 << "stworzylem nowa grupe" << logend;

View File

@ -85,16 +85,16 @@ return read;
void Locale::AddLocale(size_t lang) void Locale::AddLocale(size_t lang)
{ {
ConfParser::TableSingle::iterator i = loc_parser.table_single.begin(); ConfParser::TableSingle::iterator i = loc_parser.space.table_single.begin();
for( ; i != loc_parser.table_single.end() ; ++i) for( ; i != loc_parser.space.table_single.end() ; ++i)
loc_tab[lang][i->first] = i->second; loc_tab[lang][i->first] = i->second;
// lists // lists
ConfParser::Table::iterator i2 = loc_parser.table.begin(); ConfParser::Table::iterator i2 = loc_parser.space.table.begin();
for( ; i2 != loc_parser.table.end() ; ++i2) for( ; i2 != loc_parser.space.table.end() ; ++i2)
loc_tab_multi[lang][i2->first] = i2->second; loc_tab_multi[lang][i2->first] = i2->second;
} }
@ -132,9 +132,9 @@ bool read = false;
if( loc_parser.Parse(file_name) == ConfParser::ok ) if( loc_parser.Parse(file_name) == ConfParser::ok )
{ {
read = true; read = true;
CreateSubstVector(subst_url, loc_parser.table_single[L"url_original"], loc_parser.table_single[L"url_changeto"]); CreateSubstVector(subst_url, loc_parser.space.table_single[L"url_original"], loc_parser.space.table_single[L"url_changeto"]);
CreateSubstVector(subst_smalllet, loc_parser.table_single[L"smallleters"], loc_parser.table_single[L"capitalics"]); CreateSubstVector(subst_smalllet, loc_parser.space.table_single[L"smallleters"], loc_parser.space.table_single[L"capitalics"]);
CreateSubstVector(subst_capitallet, loc_parser.table_single[L"capitalics"], loc_parser.table_single[L"smallleters"]); CreateSubstVector(subst_capitallet, loc_parser.space.table_single[L"capitalics"], loc_parser.space.table_single[L"smallleters"]);
log << log3 << "Locale: read characters substitution tables from: " << file_name << logend; log << log3 << "Locale: read characters substitution tables from: " << file_name << logend;
} }