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:
2011-09-16 22:46:42 +00:00
parent f113e2ef31
commit 60f0e62c23
11 changed files with 546 additions and 307 deletions

View File

@@ -2,7 +2,7 @@
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* Copyright (c) 2008-2011, Tomasz Sowa
* All rights reserved.
*
*/
@@ -13,6 +13,7 @@
#include <fstream>
#include <string>
#include <vector>
#include <list>
#include <map>
@@ -130,9 +131,28 @@ class ConfParser
{
public:
/*
ctor -- setting default values (SetDefault() method)
*/
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
*/
@@ -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
*/
Status Parse(const char * file_name);
@@ -154,47 +180,23 @@ public:
Status Parse(const wchar_t * file_name);
Status Parse(const std::wstring & file_name);
/*
the main methods used to parse
str - input string (either 8bit ascii or UTF-8)
main methods used to parse
str - input string (either 8bit ascii or UTF-8 -- see UTF8() method)
*/
Status ParseString(const char * 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 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:
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 =
option2 = ()
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
and a default value (if there is no such a parameter),
they return appropriate value (either text, int or boolean)
(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);
std::wstring Text(const wchar_t * name, const wchar_t * def);
std::wstring Text(const std::wstring & name, const std::wstring & 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 std::wstring & def);
void ToText(const wchar_t * name, std::wstring & out);
void ToText(const wchar_t * name, std::wstring & out, const wchar_t * def);
void ToText(const std::wstring & name, std::wstring & out, const wchar_t * def);
std::wstring & Text(const wchar_t * name);
std::wstring & Text(const wchar_t * name, const wchar_t * 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 * name, int def);
int Int(const std::wstring & name, int def);
int Int(const wchar_t * name, int def);
int Int(const std::wstring & name, int def);
size_t Size(const wchar_t *);
size_t Size(const wchar_t * name, size_t def);
size_t Size(const std::wstring & name, size_t def);
size_t Size(const wchar_t * name, size_t def);
size_t Size(const std::wstring & name, size_t def);
bool Bool(const wchar_t *);
bool Bool(const wchar_t * name, bool def);
bool Bool(const std::wstring & name, bool def);
bool Bool(const wchar_t * name, bool def);
bool Bool(const std::wstring & name, bool def);
/*
@@ -259,6 +276,7 @@ public:
default int or size is: 0
default bool is: false
*/
void SetDefaultText(const wchar_t * def);
void SetDefaultText(const std::wstring & def);
void SetDefaultInt(int def);
void SetDefaultSize(size_t def);
@@ -273,12 +291,6 @@ public:
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
(for debug purposes)
@@ -286,6 +298,67 @@ public:
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:
@@ -295,6 +368,7 @@ private:
*/
bool reading_from_file;
/*
pointers to the current character
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;
/*
last read variable (option)
*/
@@ -398,6 +473,12 @@ private:
*/
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::wstring default_str;
@@ -405,17 +486,24 @@ private:
size_t default_size;
bool default_bool;
std::wstring tmp_name;
std::wstring tmp_value_text;
std::string tmp_value_text_ascii;
int ToInt(const std::wstring & value);
size_t ToSize(const std::wstring & value);
bool ToBool(const std::wstring & value);
Status ParseFile();
void Parse();
void TestListEnd();
void TestListStart();
void ReadAddValue();
void AddOption();
void DeleteFromTable(const std::wstring & var);
void DeleteFromTableSingle(const std::wstring & var);
bool ReadVariable();
void ReadVariable();
bool ReadValue();
bool ReadValueList();
bool ReadValueNoList(bool use_list_delimiter = false);
@@ -433,7 +521,9 @@ private:
void SkipWhite();
void SkipWhiteLines();
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);
};