(src[i]);
+}
+
+
+
+void AssignString(const std::string & src, std::string & dst, bool clear)
+{
+ if( clear )
+ dst.clear();
+
+ dst += src;
+}
+
+
+void AssignString(const std::wstring & src, std::wstring & dst, bool clear)
+{
+ if( clear )
+ dst.clear();
+
+ dst += src;
+}
+
+// !! skasowac, jest juz Itoa
void ToString(std::string & s, int value)
{
static char buffer[50];
@@ -33,27 +200,38 @@ static char buffer[50];
}
-
-
-bool CorrectUrlChar(char c)
+void ToString(std::wstring & s, int value)
{
- if( (c >= 'a' && c <='z') ||
- (c >= 'A' && c <='Z') ||
- (c >= '0' && c <='9') ||
- (c == '(' || c == ')' || c == '.' || c == ',' || c == '_' )
- )
- {
- return true;
- }
+static wchar_t buffer[50];
+
+ swprintf(buffer, sizeof(buffer)/sizeof(wchar_t), L"%d", value);
+ s = buffer;
+}
-return false;
+
+void ToString(std::wstring & s, long value)
+{
+static wchar_t buffer[50];
+
+ swprintf(buffer, sizeof(buffer)/sizeof(wchar_t), L"%ld", value);
+ s = buffer;
+}
+
+
+
+bool CorrectUrlChar(wchar_t c)
+{
+ return (c >= 'a' && c <='z') ||
+ (c >= 'A' && c <='Z') ||
+ (c >= '0' && c <='9') ||
+ c == '(' || c == ')' || c == '.' || c == ',' || c == '_' || c == '-';
}
// this function checks how many dots there are in the url
// if there are more than one (last) dot then the first dots will be changed into '_'
-void CorrectUrlDots(std::string & url)
+void CorrectUrlDots(std::wstring & url)
{
size_t i = url.size();
bool was_dot = false;
@@ -64,45 +242,49 @@ bool was_dot = false;
{
if( was_dot )
// only one dot is allowed
- url[i] = '_';
+ url[i] = '_'; // !! do konfiga
was_dot = true;
}
}
}
-
-void CorrectUrlChars(std::string & url)
+// !! pomyslec o lepszej nazwie
+void CorrectUrlChars(std::wstring & url)
{
-std::string::iterator i;
+std::wstring::iterator i;
for(i=url.begin(); i != url.end() ; ++i)
{
if( !CorrectUrlChar(*i) )
{
- int c = ChangeLocalChar(*i);
+ //wchar_t c = ChangeLocalChar(*i);
+ wchar_t c = TemplatesFunctions::locale.Subst(*i);
if( CorrectUrlChar(c) )
*i = c;
else
- *i = '_';
+ *i = '_'; // !! dodac do konfiga
}
}
}
-void CorrectUrlOnlyAllowedChar(std::string & url)
+// !! pomyslec o lepszej nazwie
+// przerzucic do funkcji - tam gdzie jest PrepareUrl()
+// bo tutaj nie mamy wskaznika na config
+void CorrectUrlOnlyAllowedChar(std::wstring & url)
{
CorrectUrlDots(url);
CorrectUrlChars(url);
ToSmall(url);
Trim(url, '_');
- if( url.empty() || url == "." )
+ if( url.empty() || url == L"." )
{
// !! brakuje config->
//if( config->item_url_empty.empty() )
- url = "unnamed";
+ url = L"unnamed";
//else
//{
// url = config->item_url_empty;
@@ -121,7 +303,7 @@ void CorrectUrlOnlyAllowedChar(std::string & url)
-
+/*
int polish_letters_simple[] =
{ 'a', 'A',
'c', 'C',
@@ -165,110 +347,14 @@ int ChangeLocalChar(unsigned char c)
return c;
}
+*/
-bool HtmlTryChar(std::ostringstream & out, int c)
+
+const wchar_t * DateToStr(int year, int month, int day)
{
- if( c == '<' )
- {
- out << "<";
- return true;
- }
- else
- if( c == '>' )
- {
- out << ">";
- return true;
- }
- else
- if( c == '&' )
- {
- out << "&";
- return true;
- }
-
-return false;
-}
-
-
-
-void HtmlEscape(std::ostringstream & out, const std::string & in)
-{
-std::string::const_iterator i;
-
- for(i = in.begin() ; i != in.end() ; ++i)
- {
- if( !HtmlTryChar(out, *i) )
- out << *i;
- }
-}
-
-
-std::string HtmlEscape(const std::string & in)
-{
- std::ostringstream out;
-
- HtmlEscape(out, in);
-
-return out.str();
-}
-
-
-void HtmlEscapeFormTxt(std::ostringstream & out, const std::string & in)
-{
-std::string::const_iterator i;
-int was_enter = 0; // how many enteres there were before
-
- if( in.empty() )
- return;
-
- out << "";
-
- // skipping first new line characters
- for(i = in.begin() ; i != in.end() && (*i==13 || *i==10) ; ++i);
-
- for( ; i != in.end() ; ++i )
- {
- if( *i == 13 ) // skipping stupid characters (\r\n\ in dos mode)
- continue;
-
- if( *i == 10 )
- {
- ++was_enter;
- }
- else
- {
- if( was_enter == 1 )
- out << "
\n";
- else
- if( was_enter > 1 )
- out << "
\n";
-
- was_enter = 0;
- }
-
- if( !HtmlTryChar(out, *i) )
- out << *i;
- }
-
- out << "
\n";
-}
-
-
-std::string HtmlEscapeFormTxt(const std::string & in)
-{
- std::ostringstream out;
-
- HtmlEscapeFormTxt(out, in);
-
-return out.str();
-}
-
-
-const char * DateToStr(int year, int month, int day)
-{
-static const char * month_letter[] = { "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X", "XI", "XII" };
-static char buffer[100];
+static const wchar_t * month_letter[] = { L"I", L"II", L"III", L"IV", L"V", L"VI", L"VII", L"VIII", L"IX", L"X", L"XI", L"XII" };
+static wchar_t buffer[100];
--month;
@@ -279,19 +365,19 @@ static char buffer[100];
month = 11;
if( year == 0 )
- sprintf(buffer, "%s %02d", month_letter[month], day);
+ swprintf(buffer, sizeof(buffer)/sizeof(wchar_t), L"%ls %02d", month_letter[month], day);
else
- sprintf(buffer, "%02d %s %02d", year, month_letter[month], day);
+ swprintf(buffer, sizeof(buffer)/sizeof(wchar_t), L"%02d %ls %02d", year, month_letter[month], day);
// warning: not thread safe (we do not use threads)
return buffer;
}
-const char * DateToStr(int year, int month, int day, int hour, int min, int sec)
+const wchar_t * DateToStr(int year, int month, int day, int hour, int min, int sec)
{
-static const char * month_letter[] = { "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X", "XI", "XII" };
-static char buffer[100];
+static const wchar_t * month_letter[] = { L"I", L"II", L"III", L"IV", L"V", L"VI", L"VII", L"VIII", L"IX", L"X", L"XI", L"XII" };
+static wchar_t buffer[100];
--month;
@@ -302,28 +388,28 @@ static char buffer[100];
month = 11;
if( year == 0 )
- sprintf(buffer, "%s %02d %02d:%02d:%02d", month_letter[month], day, hour, min, sec);
+ swprintf(buffer, sizeof(buffer)/sizeof(wchar_t), L"%ls %02d %02d:%02d:%02d", month_letter[month], day, hour, min, sec);
else
- sprintf(buffer, "%02d %s %02d %02d:%02d:%02d", year, month_letter[month], day, hour, min, sec);
+ swprintf(buffer, sizeof(buffer)/sizeof(wchar_t), L"%02d %ls %02d %02d:%02d:%02d", year, month_letter[month], day, hour, min, sec);
// warning: not thread safe (we do not use threads)
return buffer;
}
-const char * DateToStr(const tm * ptm)
+const wchar_t * DateToStr(const tm * ptm)
{
return DateToStr(ptm->tm_year + 1900, ptm->tm_mon+1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min, ptm->tm_sec);
}
-const char * DateToStr(const tm & rtm)
+const wchar_t * DateToStr(const tm & rtm)
{
return DateToStr(rtm.tm_year + 1900, rtm.tm_mon+1, rtm.tm_mday, rtm.tm_hour, rtm.tm_min, rtm.tm_sec);
}
-const char * DateToStr(time_t t)
+const wchar_t * DateToStr(time_t t)
{
tm rtm = Time(t);
@@ -331,19 +417,19 @@ return DateToStr(rtm);
}
-const char * DateToStrWithoutHours(const tm * ptm)
+const wchar_t * DateToStrWithoutHours(const tm * ptm)
{
return DateToStr(ptm->tm_year + 1900, ptm->tm_mon+1, ptm->tm_mday);
}
-const char * DateToStrWithoutHours(const tm & rtm)
+const wchar_t * DateToStrWithoutHours(const tm & rtm)
{
return DateToStr(rtm.tm_year + 1900, rtm.tm_mon+1, rtm.tm_mday);
}
-const char * DateToStrWithoutHours(time_t t)
+const wchar_t * DateToStrWithoutHours(time_t t)
{
tm rtm = Time(t);
@@ -392,9 +478,9 @@ return DateToStrCookie(rtm);
}
-const char * IpToStr(unsigned int ip_)
+const wchar_t * IpToStr(unsigned int ip_)
{
-static char buffer[100];
+static wchar_t buffer[100];
union
{
@@ -404,23 +490,23 @@ static char buffer[100];
ip.ip = ip_;
- sprintf(buffer, "%u.%u.%u.%u", (int)ip.c[0], (int)ip.c[1], (int)ip.c[2], (int)ip.c[3]);
+ swprintf(buffer, sizeof(buffer)/sizeof(wchar_t), L"%u.%u.%u.%u", (int)ip.c[0], (int)ip.c[1], (int)ip.c[2], (int)ip.c[3]);
return buffer;
}
-const char * ToStr(int value)
+const wchar_t * ToStr(int value)
{
-static char buffer[100];
+static wchar_t buffer[100];
- sprintf(buffer, "%d", value);
+ swprintf(buffer, sizeof(buffer)/sizeof(wchar_t), L"%d", value);
return buffer;
}
-bool IsWhite(int s)
+bool IsWhite(wchar_t s)
{
if( s==' ' || s=='\t' || s==13 || s==160 )
return true;
@@ -430,64 +516,8 @@ return false;
-void TrimWhite(std::string & s)
-{
-std::string::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::string::npos);
-
- // looking for white characters at the beginning
- for(i=0 ; i0 && s[i]==c ; --i);
-
- if( i==0 && s[i]==c )
- {
- // the whole string has the 'c' characters
- s.clear();
- return;
- }
-
- // deleting 'c' characters at the end
- if( i != s.size() - 1 )
- s.erase(i+1, std::string::npos);
-
- // looking for the 'c' characters at the beginning
- for(i=0 ; i='A' && c<='Z' )
c = c - 'A' + 'a';
@@ -508,87 +547,24 @@ return c;
}
-void ToSmall(std::string & s)
+void ToSmall(std::wstring & s)
{
-std::string::size_type i;
+std::wstring::size_type i;
for(i=0 ; i
+void TrimWhite(StringType & s)
+{
+typename StringType::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, StringType::npos);
+
+ // looking for white characters at the beginning
+ for(i=0 ; i
+void Trim(StringType & s, wchar_t c)
+{
+typename StringType::size_type i;
+
+ if( s.empty() )
+ return;
+
+ // looking for the 'c' characters at the end
+ for(i=s.size()-1 ; i>0 && s[i]==c ; --i);
+
+ if( i==0 && s[i]==c )
+ {
+ // the whole string has the 'c' characters
+ s.clear();
+ return;
+ }
+
+ // deleting 'c' characters at the end
+ if( i != s.size() - 1 )
+ s.erase(i+1, StringType::npos);
+
+ // looking for the 'c' characters at the beginning
+ for(i=0 ; i
+bool IsSubString(const StringType1 * short_str, const StringType2 * long_str)
+{
+ while( *short_str && *long_str && wchar_t(*short_str) == wchar_t(*long_str) )
+ {
+ ++short_str;
+ ++long_str;
+ }
-bool IsFile(const char * file);
-bool IsFile(const std::string & file);
-bool CreateDir(const char * dir, int priv);
-bool CreateDir(const std::string & dir, int priv);
-bool CreateDirs(const char * base_dir, const char * dirs, int priv);
-bool CreateDirs(const std::string & base_dir, const std::string & dirs, int priv);
+ if( *short_str == 0 )
+ return true;
+
+return false;
+}
+
+
+template
+bool IsSubString(const StringType1 & short_str, const StringType2 & long_str)
+{
+ return IsSubString(short_str.c_str(), long_str.c_str());
+}
+
+
+
+template
+bool IsSubStringNoCase(const StringType1 * short_str, const StringType2 * long_str)
+{
+ while( *short_str && *long_str && ToSmall(*short_str) == ToSmall(*long_str) )
+ {
+ ++short_str;
+ ++long_str;
+ }
+
+ if( *short_str == 0 )
+ return true;
+
+return false;
+}
+
+
+template
+bool IsSubStringNoCase(const StringType1 & short_str, const StringType2 & long_str)
+{
+ return IsSubStringNoCase(short_str.c_str(), long_str.c_str());
+}
+
+
+
+template
+bool Equal(const StringType1 * str1, const StringType2 * str2)
+{
+ while( *str1 && *str2 && wchar_t(*str1) == wchar_t(*str2) )
+ {
+ ++str1;
+ ++str2;
+ }
+
+ if( *str1 == 0 && *str2 == 0 )
+ return true;
+
+return false;
+}
+
+
+template
+bool Equal(const StringType1 & str1, const StringType2 & str2)
+{
+ return Equal(str1.c_str(), str2.c_str());
+}
+
+
+
+template
+bool EqualNoCase(const StringType1 * str1, const StringType2 * str2)
+{
+ while( *str1 && *str2 && ToSmall(*str1) == ToSmall(*str2) )
+ {
+ ++str1;
+ ++str2;
+ }
+
+ if( *str1 == 0 && *str2 == 0 )
+ return true;
+
+return false;
+}
+
+
+template
+bool EqualNoCase(const StringType1 & str1, const StringType2 & str2)
+{
+ return EqualNoCase(str1.c_str(), str2.c_str());
+}
+
+
+
+template
+void NoLastSlash(StringType & s)
+{
+ if( s.empty() )
+ return;
+
+ size_t i = s.size();
+
+ for( ; i>0 && s[i-1]=='/' ; --i);
+
+ if( i < s.size() )
+ s.erase(i);
+}
+
+
+
+template
+void NoFirstHttp(StringType & s)
+{
+ if( s.empty() )
+ return;
+
+ const char http[] = "http://";
+ const char https[] = "https://";
+
+ if( IsSubStringNoCase(http, s.c_str()) )
+ {
+ s.erase(0, sizeof(http)/sizeof(char));
+ }
+ else
+ if( IsSubStringNoCase(https, s.c_str()) )
+ {
+ s.erase(0, sizeof(https)/sizeof(char));
+ }
+}
+
+
+
+
+
+bool ValidateEmail(const std::wstring & email);
+
+bool IsFile(const wchar_t * file);
+bool IsFile(const std::wstring & file);
+bool CreateDir(const wchar_t * dir, int priv);
+bool CreateDir(const std::wstring & dir, int priv);
+bool CreateDirs(const wchar_t * base_dir, const wchar_t * dirs, int priv);
+bool CreateDirs(const std::wstring & base_dir, const std::wstring & dirs, int priv);
bool CopyFile(FILE * in, FILE * out);
-bool CopyFile(const char * src, const char * dst);
-bool CopyFile(const std::string & src, const std::string & dst);
+bool CopyFile(const wchar_t * src, const wchar_t * dst);
+bool CopyFile(const std::wstring & src, const std::wstring & dst);
-const char * GetFileExt(const char * name);
-Item::Auth SelectFileType(const char * file_name);
+bool RemoveFile(const wchar_t * file);
+bool RemoveFile(const std::wstring & file);
+
+bool RenameFile(const wchar_t * from, const wchar_t * to);
+bool RenameFile(const std::wstring & from, const std::wstring & to);
+
+const wchar_t * GetFileExt(const wchar_t * name);
+Item::Auth SelectFileType(const wchar_t * file_name);
time_t Time(const tm & par);
time_t Time(const tm * par);
diff --git a/core/mount.cpp b/core/mount.cpp
index 597bed7..1db4d2e 100755
--- a/core/mount.cpp
+++ b/core/mount.cpp
@@ -8,7 +8,7 @@
*/
#include "mount.h"
-
+#include "misc.h"
@@ -43,7 +43,7 @@ return true;
-bool Mount::IsArg(int code, const char * arg)
+bool Mount::IsArg(int code, const wchar_t * arg)
{
ParamRow::ParamArg::iterator i;
@@ -63,7 +63,7 @@ return false;
}
-bool Mount::IsArg(int code, const std::string & arg)
+bool Mount::IsArg(int code, const std::wstring & arg)
{
return IsArg(code, arg.c_str());
}
@@ -81,7 +81,7 @@ bool Mount::IsArg(int code, int arg)
for(i=param[code].arg.begin() ; i!=param[code].arg.end() ; ++i)
{
- if( atoi(i->c_str()) == arg )
+ if( Atoi(*i) == arg )
return true;
}
@@ -89,7 +89,7 @@ return false;
}
-const std::string & Mount::Arg(int code, int arg) const
+const std::wstring & Mount::Arg(int code, int arg) const
{
if( code < 0 || code >= (int)param.size() )
return empty_str;
@@ -104,7 +104,7 @@ return param[code].arg[arg];
}
-const std::string & Mount::FirstArg(int code) const
+const std::wstring & Mount::FirstArg(int code) const
{
return Arg(code, 0);
}
diff --git a/core/mount.h b/core/mount.h
index aa4be46..8f4e536 100755
--- a/core/mount.h
+++ b/core/mount.h
@@ -23,7 +23,7 @@ public:
struct ParamRow
{
- typedef std::vector ParamArg;
+ typedef std::vector ParamArg;
bool defined;
ParamArg arg;
@@ -48,21 +48,21 @@ public:
bool IsPar(int code);
- bool IsArg(int code, const char * arg);
- bool IsArg(int code, const std::string & arg);
+ bool IsArg(int code, const wchar_t * arg);
+ bool IsArg(int code, const std::wstring & arg);
bool IsArg(int code, int arg);
// returning the arg argument if defined (or an empty string)
- const std::string & Arg(int code, int arg) const;
+ const std::wstring & Arg(int code, int arg) const;
// returning the first argument (arg=0) if defined (or an empty string)
- const std::string & FirstArg(int code) const;
+ const std::wstring & FirstArg(int code) const;
private:
// for Arg() methods when the argument is not defined
- const std::string empty_str;
+ const std::wstring empty_str;
};
diff --git a/core/mountparser.cpp b/core/mountparser.cpp
index cd11985..db00812 100755
--- a/core/mountparser.cpp
+++ b/core/mountparser.cpp
@@ -27,19 +27,19 @@ void MountParser::SetDirs(Dirs * pdirs)
}
-void MountParser::SetMountTypeTab(const std::vector & tab)
+void MountParser::SetMountTypeTab(const std::vector & tab)
{
mount_type_tab = &tab;
}
-void MountParser::SetMountFsTab(const std::vector & tab)
+void MountParser::SetMountFsTab(const std::vector & tab)
{
mount_fs_tab = &tab;
}
-void MountParser::SetMountParTab(const std::vector & tab)
+void MountParser::SetMountParTab(const std::vector & tab)
{
mount_par_tab = &tab;
}
@@ -72,7 +72,7 @@ void MountParser::SkipLine()
}
-void MountParser::ReadWordQuote(std::string & res)
+void MountParser::ReadWordQuote(std::wstring & res)
{
++pinput;
@@ -102,7 +102,7 @@ void MountParser::ReadWordQuote(std::string & res)
// a white character is the separator
-void MountParser::ReadWordWhite(std::string & res)
+void MountParser::ReadWordWhite(std::wstring & res)
{
while( *pinput && *pinput!=10 && !IsWhite(*pinput) )
{
@@ -113,7 +113,7 @@ void MountParser::ReadWordWhite(std::string & res)
// the comma or the second bracket ')' are the separators
-void MountParser::ReadWordComma(std::string & res)
+void MountParser::ReadWordComma(std::wstring & res)
{
while( *pinput && *pinput!=10 && *pinput!=',' && *pinput!=')' )
{
@@ -127,7 +127,7 @@ void MountParser::ReadWordComma(std::string & res)
}
-void MountParser::ReadWord(std::string & res, bool comma_bracket_separator)
+void MountParser::ReadWord(std::wstring & res, bool comma_bracket_separator)
{
res.clear();
SkipWhite();
@@ -192,7 +192,7 @@ void MountParser::ReadParamArgs(Mount::ParamRow::ParamArg & args)
-void MountParser::ReadParamName(std::string & res)
+void MountParser::ReadParamName(std::wstring & res)
{
SkipWhite();
res.clear();
@@ -205,7 +205,7 @@ void MountParser::ReadParamName(std::string & res)
}
-void MountParser::ReadParam(std::string & res, Mount::ParamRow::ParamArg & args)
+void MountParser::ReadParam(std::wstring & res, Mount::ParamRow::ParamArg & args)
{
ReadParamName(res);
@@ -221,7 +221,7 @@ void MountParser::ReadParam(std::string & res, Mount::ParamRow::ParamArg & args)
}
-int MountParser::FindIndex(const std::vector * tab, const std::string & value)
+int MountParser::FindIndex(const std::vector * tab, const std::wstring & value)
{
for(size_t i=0 ; i < tab->size() ; ++i)
{
@@ -373,7 +373,7 @@ void MountParser::ReadRow(std::map & output)
-Error MountParser::Parse(const std::string & input, std::map & output)
+Error MountParser::Parse(const std::wstring & input, std::map & output)
{
if( !dirs || !mount_type_tab || !mount_fs_tab || !mount_par_tab )
{
@@ -396,7 +396,7 @@ Error MountParser::Parse(const std::string & input, std::map & outp
while( *pinput && err == WINIX_ERR_OK )
ReadRow(output);
-
+
return err;
}
diff --git a/core/mountparser.h b/core/mountparser.h
index 37f2364..cfddffe 100755
--- a/core/mountparser.h
+++ b/core/mountparser.h
@@ -28,32 +28,32 @@ class MountParser
public:
MountParser();
- Error Parse(const std::string & input, std::map & output);
+ Error Parse(const std::wstring & input, std::map & output);
void SetDirs(Dirs * pdirs);
- void SetMountTypeTab(const std::vector & tab);
- void SetMountFsTab(const std::vector & tab);
- void SetMountParTab(const std::vector & tab);
+ void SetMountTypeTab(const std::vector & tab);
+ void SetMountFsTab(const std::vector & tab);
+ void SetMountParTab(const std::vector & tab);
private:
Dirs * dirs;
- const std::vector * mount_type_tab;
- const std::vector * mount_fs_tab;
- const std::vector * mount_par_tab;
+ const std::vector * mount_type_tab;
+ const std::vector * mount_fs_tab;
+ const std::vector * mount_par_tab;
bool IsWhite(int c);
void SkipWhite();
void SkipLine();
- void ReadWordQuote(std::string & res);
- void ReadWordWhite(std::string & res);
- void ReadWordComma(std::string & res);
- void ReadWord(std::string & res, bool comma_bracket_separator = false);
+ void ReadWordQuote(std::wstring & res);
+ void ReadWordWhite(std::wstring & res);
+ void ReadWordComma(std::wstring & res);
+ void ReadWord(std::wstring & res, bool comma_bracket_separator = false);
void ReadParamArgsLoop(Mount::ParamRow::ParamArg & args);
void ReadParamArgs(Mount::ParamRow::ParamArg & args);
- void ReadParamName(std::string & res);
- void ReadParam(std::string & res, Mount::ParamRow::ParamArg & args);
- int FindIndex(const std::vector * tab, const std::string & value);
+ void ReadParamName(std::wstring & res);
+ void ReadParam(std::wstring & res, Mount::ParamRow::ParamArg & args);
+ int FindIndex(const std::vector * tab, const std::wstring & value);
void ReadMountType();
void ReadMountPoint();
void ReadFs();
@@ -61,9 +61,9 @@ private:
void ReadMountParams();
void ReadRow(std::map & output);
- const char * pinput;
- std::string temp;
- std::string temp_arg;
+ const wchar_t * pinput;
+ std::wstring temp;
+ std::wstring temp_arg;
Mount::ParamRow::ParamArg param_args;
diff --git a/core/mounts.cpp b/core/mounts.cpp
index ee4fd7b..fc54e1e 100755
--- a/core/mounts.cpp
+++ b/core/mounts.cpp
@@ -24,28 +24,28 @@ Mounts::Mounts()
void Mounts::CreateMountType()
{
- mount_type_cms = AddMountType("cms");
- mount_type_thread = AddMountType("thread");
+ mount_type_cms = AddMountType(L"cms");
+ mount_type_thread = AddMountType(L"thread");
}
void Mounts::CreateMountFs()
{
- mount_fs_simplefs = AddMountFs("simplefs");
- mount_fs_hashfs = AddMountFs("hashfs");
+ mount_fs_simplefs = AddMountFs(L"simplefs");
+ mount_fs_hashfs = AddMountFs(L"hashfs");
}
void Mounts::CreateMountPar()
{
- mount_par_page = AddMountPar("page");
- mount_par_thread = AddMountPar("thread");
- mount_par_createthread_on = AddMountPar("createthread_on");
- mount_par_only_root_remove = AddMountPar("only_root_remove");
- mount_par_emacs_on = AddMountPar("emacs_on");
- mount_par_mkdir_on = AddMountPar("mkdir_on");
- mount_par_app = AddMountPar("app");
- mount_par_html_template = AddMountPar("html_template");
+ mount_par_page = AddMountPar(L"page");
+ mount_par_thread = AddMountPar(L"thread");
+ mount_par_createthread_on = AddMountPar(L"createthread_on");
+ mount_par_only_root_remove = AddMountPar(L"only_root_remove");
+ mount_par_emacs_on = AddMountPar(L"emacs_on");
+ mount_par_mkdir_on = AddMountPar(L"mkdir_on");
+ mount_par_app = AddMountPar(L"app");
+ mount_par_html_template = AddMountPar(L"html_template");
}
@@ -78,7 +78,7 @@ void Mounts::SetRequest(Request * prequest)
-int Mounts::AddMountType(const char * type)
+int Mounts::AddMountType(const wchar_t * type)
{
mount_type_tab.push_back(type);
@@ -86,13 +86,13 @@ return static_cast(mount_type_tab.size()) - 1;
}
-int Mounts::AddMountType(const std::string & type)
+int Mounts::AddMountType(const std::wstring & type)
{
return AddMountType(type.c_str());
}
-int Mounts::AddMountFs(const char * fs)
+int Mounts::AddMountFs(const wchar_t * fs)
{
mount_fs_tab.push_back(fs);
@@ -100,7 +100,7 @@ return static_cast(mount_fs_tab.size()) - 1;
}
-const std::string & Mounts::GetMountType(int id)
+const std::wstring & Mounts::GetMountType(int id)
{
if( id < 0 || id >= (int)mount_type_tab.size() )
return empty_str;
@@ -109,7 +109,7 @@ const std::string & Mounts::GetMountType(int id)
}
-int Mounts::FindMountType(const std::string & type)
+int Mounts::FindMountType(const std::wstring & type)
{
for(size_t i=0 ; i= (int)mount_fs_tab.size() )
return empty_str;
@@ -135,7 +135,7 @@ const std::string & Mounts::GetMountFs(int id)
}
-int Mounts::AddMountPar(const char * par)
+int Mounts::AddMountPar(const wchar_t * par)
{
mount_par_tab.push_back(par);
@@ -144,13 +144,13 @@ return static_cast(mount_par_tab.size()) - 1;
-int Mounts::AddMountPar(const std::string & par)
+int Mounts::AddMountPar(const std::wstring & par)
{
return AddMountPar(par.c_str());
}
-const std::string & Mounts::GetMountPar(int id)
+const std::wstring & Mounts::GetMountPar(int id)
{
if( id < 0 || id >= (int)mount_par_tab.size() )
return empty_str;
@@ -161,7 +161,7 @@ const std::string & Mounts::GetMountPar(int id)
// reading from 'mounts'
-Error Mounts::ReadMounts(const std::string & mounts)
+Error Mounts::ReadMounts(const std::wstring & mounts)
{
mount_parser.SetDirs(dirs);
mount_parser.SetMountTypeTab(mount_type_tab);
@@ -187,7 +187,7 @@ return err;
// reading from /etc/fstab
Error Mounts::ReadMounts()
{
- static std::string file = "fstab";
+ static std::wstring file = L"fstab";
Item * etc = dirs->GetEtcDir();
diff --git a/core/mounts.h b/core/mounts.h
index 95b9620..48efc44 100755
--- a/core/mounts.h
+++ b/core/mounts.h
@@ -31,9 +31,9 @@ public:
/*
mount point's types
*/
- int AddMountType(const char * type);
- int AddMountType(const std::string & type);
- const std::string & GetMountType(int id);
+ int AddMountType(const wchar_t * type);
+ int AddMountType(const std::wstring & type);
+ const std::wstring & GetMountType(int id);
// id of a specific mount type (the id is always valid)
int MountTypeCms() { return mount_type_cms; }
@@ -41,15 +41,15 @@ public:
// return -1 if there is no such a mount type
// or index otherwhise
- int FindMountType(const std::string & type);
+ int FindMountType(const std::wstring & type);
/*
file systems
*/
- int AddMountFs(const char * fs);
- int AddMountFs(const std::string & fs);
- const std::string & GetMountFs(int id);
+ int AddMountFs(const wchar_t * fs);
+ int AddMountFs(const std::wstring & fs);
+ const std::wstring & GetMountFs(int id);
// id of a specific file system (the id is always valid)
int MountFsSimplefs() { return mount_fs_simplefs; }
@@ -59,9 +59,9 @@ public:
/*
mount point's parameters
*/
- int AddMountPar(const char * par);
- int AddMountPar(const std::string & par);
- const std::string & GetMountPar(int id);
+ int AddMountPar(const wchar_t * par);
+ int AddMountPar(const std::wstring & par);
+ const std::wstring & GetMountPar(int id);
int MountParPage() { return mount_par_page; }
int MountParThread() { return mount_par_thread; }
@@ -83,7 +83,7 @@ public:
Mounts();
void CreateMounts();
- Error ReadMounts(const std::string & mounts);
+ Error ReadMounts(const std::wstring & mounts);
Error ReadMounts();
void CalcCurMount();
@@ -102,27 +102,27 @@ private:
Dirs * dirs;
Request * request;
- const std::string empty_str;
+ const std::wstring empty_str;
MountParser mount_parser;
// cms
// thread
- std::vector mount_type_tab;
+ std::vector mount_type_tab;
int mount_type_cms;
int mount_type_thread;
// simplefs
// hashfs
- std::vector mount_fs_tab;
+ std::vector mount_fs_tab;
int mount_fs_simplefs;
int mount_fs_hashfs;
// page
// thread
- std::vector mount_par_tab;
+ std::vector mount_par_tab;
int mount_par_page;
int mount_par_thread;
diff --git a/core/notify.cpp b/core/notify.cpp
index a4ac563..0b630a2 100755
--- a/core/notify.cpp
+++ b/core/notify.cpp
@@ -16,6 +16,7 @@
#include "notify.h"
#include "misc.h"
#include "request.h"
+#include "ezc.h"
@@ -97,12 +98,12 @@ void Notify::SendEmail(NotifyMsg & n)
obj->templates_notify->Generate(n.lang);
obj->Unlock();
- SendEmail(n.email, obj->templates_notify->notify_str.str());
+ SendEmail(n.email, obj->templates_notify->notify_str.Str());
}
-void Notify::SendEmail(const std::string & email, const std::string & message)
+void Notify::SendEmail(const std::wstring & email, const std::wstring & message)
{
nlog.PutDate(log1);
@@ -112,7 +113,8 @@ void Notify::SendEmail(const std::string & email, const std::string & message)
return;
}
- obj->command = "sendmail " + email;
+ obj->command = "sendmail ";
+ AssignString(email, obj->command, false);
FILE * sendmail = popen(obj->command.c_str(), "w");
if( !sendmail )
@@ -129,14 +131,24 @@ void Notify::SendEmail(const std::string & email, const std::string & message)
}
-void Notify::SendMessage(FILE * sendmail, const std::string & message)
+void Notify::SendMessage(FILE * sendmail, const std::wstring & message)
{
+char buf[10];
+size_t len;
+
for(size_t i=0 ; ibase_url;
CreateItemDir(link, false);
diff --git a/core/notify.h b/core/notify.h
index 94f21b7..f522495 100755
--- a/core/notify.h
+++ b/core/notify.h
@@ -63,11 +63,11 @@ private:
void Unlock();
static void CheckQueue();
static void SendEmail(NotifyMsg & n);
- static void SendEmail(const std::string & email);
- static void SendEmail(const std::string & email, const std::string & message);
- static void SendMessage(FILE * sendmail, const std::string & message);
- void CreateItemDir(std::string & dir, bool clear = true);
- void CreateItemLink(std::string & link);
+ static void SendEmail(const std::wstring & email);
+ static void SendEmail(const std::wstring & email, const std::wstring & message);
+ static void SendMessage(FILE * sendmail, const std::wstring & message);
+ void CreateItemDir(std::wstring & dir, bool clear = true);
+ void CreateItemLink(std::wstring & link);
pthread_t thread;
pthread_mutex_t mutex;
diff --git a/core/plugin.cpp b/core/plugin.cpp
index e8ab9eb..b8d6b52 100755
--- a/core/plugin.cpp
+++ b/core/plugin.cpp
@@ -11,6 +11,7 @@
#include
#include "plugin.h"
#include "pluginmsg.h"
+#include "misc.h"
@@ -110,7 +111,7 @@ return res;
}
-void Plugin::LoadPlugins(const std::string & plugins_dir, const std::vector & plugins)
+void Plugin::LoadPlugins(const std::wstring & plugins_dir, const std::vector & plugins)
{
for(size_t i=0 ; i(info.p1);
+ item.plugin_name = reinterpret_cast(info.p1);
plugins.push_back(item);
@@ -195,15 +196,27 @@ int old_current_plugin;
}
+void Plugin::LoadPlugin(const wchar_t * filename)
+{
+ AssignString(filename, afilename);
+ LoadPlugin(afilename.c_str());
+}
-bool Plugin::HasPlugin(const char * name)
+
+void Plugin::LoadPlugin(const std::wstring & filename)
+{
+ LoadPlugin(filename.c_str());
+}
+
+
+bool Plugin::HasPlugin(const wchar_t * name)
{
if( *name == 0 )
return false;
for(size_t i=0 ; i & plugins);
+ void LoadPlugin(const wchar_t * filename);
+ void LoadPlugin(const std::wstring & filename);
+
+ void LoadPlugins(const std::wstring & plugins_dir, const std::vector & plugins);
void UnloadPlugins();
- bool HasPlugin(const char * name);
- bool HasPlugin(const std::string & name);
+ bool HasPlugin(const wchar_t * name);
+ bool HasPlugin(const std::wstring & name);
void Call(int message);
void Call(int message, void * p1_);
@@ -170,12 +173,12 @@ private:
Templates * templates;
SessionManager * session_manager;
- std::string temp_path;
+ std::wstring temp_path;
struct PluginsItem
{
void * handle;
- const char * plugin_name; // plugin name (can be null if was not set by the plugin)
+ const wchar_t * plugin_name; // plugin name (can be null if was not set by the plugin)
};
typedef std::vector Plugins;
@@ -186,6 +189,8 @@ private:
PluginInfo info;
+ std::string afilename;
+
void * LoadInitFun(const char * filename, Fun1 & fun_init);
void Call(int message, Slots::iterator & slot);
diff --git a/core/postmultiparser.cpp b/core/postmultiparser.cpp
index 9059d8a..d120531 100755
--- a/core/postmultiparser.cpp
+++ b/core/postmultiparser.cpp
@@ -9,7 +9,8 @@
#include "postmultiparser.h"
#include "log.h"
-
+#include "ezc.h"
+#include "misc.h"
PostMultiParser::PostMultiParser()
@@ -283,7 +284,7 @@ bool has_boundary = false;
content.clear();
}
- if( config->post_file_max != 0 && content_len > (size_t)config->post_file_max )
+ if( config->post_file_max != 0 && content_len > config->post_file_max )
{
err = WINIX_ERR_INPUT_TOO_LARGE;
log << log1 << "PMP: content greater than " << config->post_file_max << " (skipping)" << logend;
@@ -369,10 +370,22 @@ void PostMultiParser::AddNormalPostVar()
return;
}
- std::pair res = post_tab->insert( std::make_pair(name, content) );
+
+ if( config->utf8 )
+ {
+ Ezc::UTF8ToWide(name, namew);
+ Ezc::UTF8ToWide(content, contentw);
+ }
+ else
+ {
+ AssignString(name, namew);
+ AssignString(content, contentw);
+ }
+
+ std::pair res = post_tab->insert( std::make_pair(namew, contentw) );
bool added = res.second;
- log << log2 << "PMP: POST var, name: \"" << name << "\"";
+ log << log2 << "PMP: POST var, name: \"" << namew << "\"";
if( !added )
log << log2 << " (skipped)";
@@ -390,12 +403,22 @@ void PostMultiParser::AddFilePostVar()
return;
}
- post_file_temp.filename = filename;
+ if( config->utf8 )
+ {
+ Ezc::UTF8ToWide(name, namew);
+ Ezc::UTF8ToWide(filename, post_file_temp.filename);
+ }
+ else
+ {
+ AssignString(name, namew);
+ AssignString(filename, post_file_temp.filename);
+ }
+
post_file_temp.tmp_filename = tmp_filename;
- std::pair res = post_file_tab->insert( std::make_pair(name, post_file_temp) );
+ std::pair res = post_file_tab->insert( std::make_pair(namew, post_file_temp) );
bool added = res.second;
- log << log2 << "PMP: POST FILE var, name: \"" << name << "\"";
+ log << log2 << "PMP: POST FILE var, name: \"" << namew << "\"";
if( !added )
log << log2 << " (skipped)";
@@ -450,7 +473,8 @@ void PostMultiParser::CheckBoundaryEnd()
void PostMultiParser::CreateTmpFile()
{
-char buf[100];
+wchar_t buf[1024];
+size_t buf_len = sizeof(buf)/sizeof(wchar_t);
if( config->auth_tmp_dir.empty() )
{
@@ -459,11 +483,13 @@ char buf[100];
return;
}
- sprintf(buf, "%s/winix_%u_%d_%u", config->auth_tmp_dir.c_str(), (unsigned)getpid(), tmp_filename_postfix, rand());
+ swprintf(buf, buf_len, L"%ls/winix_%u_%d_%u", config->auth_tmp_dir.c_str(), (unsigned)getpid(), tmp_filename_postfix, rand());
tmp_filename_postfix += 1;
- tmp_file.open(buf, std::ios_base::binary | std::ios_base::out);
- tmp_filename = buf;
+ AssignString(buf, atmp_filename);
+ AssignString(atmp_filename, tmp_filename); // this make sure that the names are exactly the same
+
+ tmp_file.open(atmp_filename.c_str(), std::ios_base::binary | std::ios_base::out);
if( !tmp_file )
{
@@ -509,7 +535,7 @@ void PostMultiParser::ReadPart()
if( err != WINIX_ERR_OK && !filename.empty() )
{
log << log1 << "PMP: deleting the tmp file: " << tmp_filename << logend;
- unlink(tmp_filename.c_str());
+ RemoveFile(tmp_filename);
}
}
@@ -544,6 +570,7 @@ void PostMultiParser::ReadChar()
+
Error PostMultiParser::Parse(FCGX_Stream * in_, PostTab & post_tab_, PostFileTab & post_file_tab_)
{
in = in_;
diff --git a/core/postmultiparser.h b/core/postmultiparser.h
index 5f22717..c9b5dcc 100755
--- a/core/postmultiparser.h
+++ b/core/postmultiparser.h
@@ -43,7 +43,8 @@ private:
FCGX_Stream * in;
unsigned char * in_buffer;
std::ofstream tmp_file;
- std::string tmp_filename;
+ std::wstring tmp_filename;
+ std::string atmp_filename;
int tmp_filename_postfix;
size_t in_buffer_ind;
size_t in_buffer_len;
@@ -62,6 +63,7 @@ private:
Error err;
std::string name, filename;
+ std::wstring namew, contentw;
PostFile post_file_temp;
void LogFirst(const std::string & to_log, size_t len);
diff --git a/core/postparser.h b/core/postparser.h
index 6f9cdbc..a8580b4 100755
--- a/core/postparser.h
+++ b/core/postparser.h
@@ -14,7 +14,7 @@
#include
#include "httpsimpleparser.h"
#include "requesttypes.h"
-
+#include "misc.h"
@@ -23,6 +23,8 @@ class PostParser : public HttpSimpleParser
FCGX_Stream * in;
PostTab * post_tab;
+ std::wstring temp_name, temp_value;
+ bool input_as_utf8;
protected:
@@ -35,9 +37,20 @@ protected:
virtual void Parameter(std::string & name, std::string & value)
{
- std::pair res = post_tab->insert( std::make_pair(name, value) );
+ if( input_as_utf8 )
+ {
+ Ezc::UTF8ToWide(name, temp_name);
+ Ezc::UTF8ToWide(value, temp_value);
+ }
+ else
+ {
+ AssignString(name, temp_name);
+ AssignString(value, temp_value);
+ }
+
+ std::pair res = post_tab->insert( std::make_pair(temp_name, temp_value) );
- log << log2 << "Method POST, name: \"" << name << "\", value: \"" << value << "\"";
+ log << log2 << "Method POST, name: \"" << temp_name << "\", value: \"" << temp_value << "\"";
if( res.second == false )
log << log2 << " (skipped)";
@@ -48,6 +61,18 @@ protected:
public:
+ PostParser()
+ {
+ input_as_utf8 = false;
+ }
+
+
+ void UTF8(bool utf)
+ {
+ input_as_utf8 = utf;
+ }
+
+
void Parse(FCGX_Stream * in_, PostTab & post_tab_)
{
in = in_;
diff --git a/core/rebus.cpp b/core/rebus.cpp
index eaabd51..8855155 100755
--- a/core/rebus.cpp
+++ b/core/rebus.cpp
@@ -24,12 +24,13 @@ void Rebus::SetRequest(Request * prequest)
bool Rebus::InitPair(int a, int b, Item & item)
{
-char buffer[100];
+wchar_t buffer[100];
+size_t buffer_len = sizeof(buffer) / sizeof(wchar_t);
bool add = false;
if( a+b <= 15 )
{
- sprintf(buffer, "%d+%d", a, b);
+ swprintf(buffer, buffer_len, L"%d+%d", a, b);
item.question = buffer;
item.answer = a+b;
add = true;
@@ -37,7 +38,7 @@ bool add = false;
if( a-b >= 0 )
{
- sprintf(buffer, "%d-%d", a, b);
+ swprintf(buffer, buffer_len, L"%d-%d", a, b);
item.question = buffer;
item.answer = a-b;
add = true;
@@ -91,23 +92,23 @@ return &table[0] + i;
-bool Rebus::IsAnswerOk(Rebus::Item * item, const std::string & answer)
+bool Rebus::IsAnswerOk(Rebus::Item * item, const std::wstring & answer)
{
if( item == 0 )
return false;
- char * end;
- const char * a = answer.c_str();
+ wchar_t * end;
+ const wchar_t * a = answer.c_str();
a = SkipWhite(a);
- int value = (int)strtol(a, &end, 10);
+ int value = (int)wcstol(a, &end, 10);
if( a == end )
// nothing has been read
return false;
log << log2 << "Rebus: your answer is: " << value << logend;
- end = (char*)SkipWhite(end);
+ end = (wchar_t*)SkipWhite(end);
if( *end != 0 )
{
@@ -145,7 +146,7 @@ bool Rebus::CheckRebus()
return false;
}
- if( IsAnswerOk(request->session->rebus_item, request->PostVar("rebus")) )
+ if( IsAnswerOk(request->session->rebus_item, request->PostVar(L"rebus")) )
return true;
log << log1 << "Rebus: rebus has an incorrect answer" << logend;
diff --git a/core/rebus.h b/core/rebus.h
index 38593eb..98937e7 100755
--- a/core/rebus.h
+++ b/core/rebus.h
@@ -25,7 +25,7 @@ public:
struct Item
{
int key;
- std::string question;
+ std::wstring question;
int answer;
};
@@ -34,7 +34,7 @@ public:
void SetRequest(Request * prequest);
void Init();
Item * Rand();
- bool IsAnswerOk(Item * item, const std::string & answer);
+ bool IsAnswerOk(Item * item, const std::wstring & answer);
bool CheckRebus();
private:
diff --git a/core/request.cpp b/core/request.cpp
index 33014b0..b455ea6 100755
--- a/core/request.cpp
+++ b/core/request.cpp
@@ -38,9 +38,9 @@ void Request::ClearPostFileTmp()
while( !post_file_tab.empty() )
{
- const std::string & tmp_filename = post_file_tab.begin()->second.tmp_filename;
+ const std::wstring & tmp_filename = post_file_tab.begin()->second.tmp_filename;
- if( unlink(tmp_filename.c_str()) == 0 )
+ if( RemoveFile(tmp_filename) )
log << log3 << "Request: deleted tmp file: " << tmp_filename << logend;
post_file_tab.erase(post_file_tab.begin());
@@ -66,9 +66,9 @@ void Request::Clear()
method = none;
role = responder;
- headers.str("");
- page.str("");
- debug.str("");
+ headers.Clear();
+ page.Clear();
+ debug.Clear();
env_request_method = &char_empty;
env_request_uri = &char_empty;
@@ -133,7 +133,7 @@ void Request::SetCookie(const char * name, long value, tm * expires)
-bool Request::IsPostVar(const char * var)
+bool Request::IsPostVar(const wchar_t * var)
{
PostTab::iterator p;
@@ -147,7 +147,7 @@ return true;
-const std::string & Request::PostVar(const char * var)
+const std::wstring & Request::PostVar(const wchar_t * var)
{
PostTab::iterator p = post_tab.find(var);
@@ -159,7 +159,7 @@ return p->second;
-bool Request::PostVar(const char * var, std::string & result)
+bool Request::PostVar(const wchar_t * var, std::wstring & result)
{
PostTab::iterator p = post_tab.find(var);
@@ -175,7 +175,7 @@ return true;
}
-std::string * Request::PostVarp(const char * var)
+std::wstring * Request::PostVarp(const wchar_t * var)
{
PostTab::iterator p = post_tab.find(var);
@@ -194,7 +194,7 @@ void Request::PrintGetTab()
for(GetTab::iterator i = get_tab.begin() ; i != get_tab.end() ; ++i)
debug << " \"" << *i << "\"\n";
- debug << std::endl;
+ debug << '\n';
}
@@ -207,7 +207,7 @@ char ** e;
for( e = env ; *e ; ++e )
debug << ' ' << *e << "\n";
- debug << std::endl;
+ debug << '\n';
}
@@ -225,14 +225,12 @@ return true;
-bool Request::IsParam(const char * param_name)
+bool Request::IsParam(const wchar_t * param_name)
{
ParamTab::iterator i;
-
+
for(i=param_tab.begin() ; i!=param_tab.end() ; ++i)
{
- // !! make sure that exists std::string::operator==(const char*)
- // (optimization)
if( i->name == param_name )
return true;
}
@@ -241,16 +239,28 @@ return false;
}
-const std::string & Request::ParamValue(const char * param_name)
+bool Request::IsParam(const std::wstring & param_name)
+{
+ ParamTab::iterator i;
+
+ for(i=param_tab.begin() ; i!=param_tab.end() ; ++i)
+ {
+ if( i->name == param_name )
+ return true;
+ }
+
+return false;
+}
+
+
+const std::wstring & Request::ParamValue(const wchar_t * param_name)
{
ParamTab::iterator i;
for(i=param_tab.begin() ; i!=param_tab.end() ; ++i)
{
if( i->name == param_name )
- {
return i->value;
- }
}
return str_empty;
diff --git a/core/request.h b/core/request.h
index 4be195a..4c98c3c 100755
--- a/core/request.h
+++ b/core/request.h
@@ -18,7 +18,7 @@
#include "item.h"
#include "error.h"
#include "config.h"
-
+#include "textstream.h"
class FunctionBase;
@@ -43,7 +43,9 @@ struct Request
enum Role { responder, authorizer } role;
// headers, page and debug
- std::ostringstream headers, page, debug;
+ //std::ostringstream headers, page, debug;
+ TextStream headers;
+ TextStream page, debug;
// raw parameters
GetTab get_tab;
@@ -99,10 +101,11 @@ struct Request
std::vector- item_tab;
// if not empty means an address for redirecting to
- std::string redirect_to;
+ std::wstring redirect_to;
+ std::string aredirect_to;
// send header X-LIGHTTPD-send-file with path to a file
- std::string x_sendfile;
+ std::wstring x_sendfile;
// send as attachment (causing header: content-disposition: attachment)
bool send_as_attachment;
@@ -120,16 +123,17 @@ struct Request
void PrintEnv();
- bool IsParam(const char * param_name);
- const std::string & ParamValue(const char * param_name); // returns empty string if there is no such a parameter
+ bool IsParam(const wchar_t * param_name);
+ bool IsParam(const std::wstring & param_name);
+ const std::wstring & ParamValue(const wchar_t * param_name); // returns empty string if there is no such a parameter
void SetCookie(const char * name, const char * value, tm * expires = 0);
void SetCookie(const char * name, long value, tm * expires = 0);
- bool IsPostVar(const char * var);
- const std::string & PostVar(const char * var); // !! zamienic na referencje nie do sta³ej (bez const)
- bool PostVar(const char * var, std::string & result);
- std::string * PostVarp(const char * var);
+ bool IsPostVar(const wchar_t * var);
+ const std::wstring & PostVar(const wchar_t * var); // !! zamienic na referencje nie do sta³ej (bez const)
+ bool PostVar(const wchar_t * var, std::wstring & result);
+ std::wstring * PostVarp(const wchar_t * var);
bool AllPostVarEmpty(); // returning true if all post vars are empty
@@ -147,7 +151,7 @@ private:
const char char_empty;
// used in ParamValue() and PostVar() when there is no such a param
- const std::string str_empty;
+ const std::wstring str_empty;
};
diff --git a/core/requesttypes.h b/core/requesttypes.h
index 0208bf1..9606cb2 100755
--- a/core/requesttypes.h
+++ b/core/requesttypes.h
@@ -20,25 +20,26 @@
struct PostFile
{
- std::string filename; // original file name
- std::string tmp_filename; // file with content (in /tmp)
+ std::wstring filename; // original file name
+ std::wstring tmp_filename; // file with content (in /tmp)
};
// parameters from get name:value
struct Param
{
- std::string name;
- std::string value;
+ std::wstring name;
+ std::wstring value;
};
// some global types used by Request class
-typedef std::vector GetTab;
-typedef std::map PostTab;
-typedef std::map PostFileTab;
-typedef std::map CookieTab;
-typedef std::vector ParamTab;
+typedef std::vector GetTab;
+typedef std::map PostTab;
+typedef std::map PostFileTab;
+typedef std::vector ParamTab;
+
+typedef std::map CookieTab;
diff --git a/core/system.cpp b/core/system.cpp
index a99e34c..9e1e0d6 100755
--- a/core/system.cpp
+++ b/core/system.cpp
@@ -61,7 +61,7 @@ void System::Init()
// !! mozna zrobic jakas obsluge kiedy nie mozemy sie redirectnac, np gdy wystapil blad
// !! moze zwracac jakas wartosc?
-void System::RedirectTo(const Item & item, const char * postfix)
+void System::RedirectTo(const Item & item, const wchar_t * postfix)
{
request->redirect_to = config->base_url;
@@ -86,9 +86,8 @@ void System::RedirectTo(const Item & item, const char * postfix)
-void System::RedirectTo(long item_id, const char * postfix)
+void System::RedirectTo(long item_id, const wchar_t * postfix)
{
-std::string path;
Item * pdir;
request->redirect_to = config->base_url;
@@ -339,7 +338,7 @@ size_t i = 0;
bool System::CanUseHtml(long user_id)
{
- return IsMemberOfGroup(user_id, "allow_html");
+ return IsMemberOfGroup(user_id, L"allow_html");
}
@@ -352,12 +351,12 @@ bool System::CanUseBBCode(long user_id)
bool System::CanUseRaw(long user_id)
{
- return IsMemberOfGroup(user_id, "allow_raw");
+ return IsMemberOfGroup(user_id, L"allow_raw");
}
-bool System::IsMemberOfGroup(long user_id, const char * group_name)
+bool System::IsMemberOfGroup(long user_id, const wchar_t * group_name)
{
User * puser = users.GetUser(user_id);
@@ -365,7 +364,7 @@ bool System::IsMemberOfGroup(long user_id, const char * group_name)
return false;
if( puser->super_user )
- return true;
+ return true; // !! ?? zakladamy ze administrator jest czlonkiem wszystkich grup? dlaczego?
long group = groups.GetGroupId(group_name);
@@ -373,10 +372,7 @@ bool System::IsMemberOfGroup(long user_id, const char * group_name)
// there is no such a group
return false;
- if( puser->IsMemberOf(group) )
- return true;
-
-return false;
+return puser->IsMemberOf(group);
}
@@ -384,7 +380,7 @@ return false;
-bool System::MakePathSimpleFs(std::string & path, long dir_id, bool create_dir)
+bool System::MakePathSimpleFs(std::wstring & path, long dir_id, bool create_dir)
{
if( config->auth_simplefs_dir.empty() )
{
@@ -407,16 +403,18 @@ return true;
// the path depends on id
-bool System::MakePathHashFs(std::string & path, long id, bool create_dir)
+bool System::MakePathHashFs(std::wstring & path, long id, bool create_dir)
{
-char buffer[50];
-char * hash = buffer;
+wchar_t buffer[50];
+wchar_t * hash = buffer;
+size_t buffer_len = sizeof(buffer)/sizeof(wchar_t);
// get 'id' as hexadecimal
buffer[0] = '0';
- sprintf(buffer+1, "%lx", (unsigned long)id);
+ swprintf(buffer+1, buffer_len, L"%lx", (unsigned long)id);
path = config->auth_hashfs_dir;
+
if( path.empty() )
{
log << log1 << "System: auth_hashfs_dir is not set in the config file" << logend;
@@ -426,7 +424,7 @@ char * hash = buffer;
path += '/';
// make sure that the length is even
- if( (strlen(hash) & 1) != 0 )
+ if( (wcslen(hash) & 1) != 0 )
hash = buffer + 1; // the first character was zero
// creating dirs without the last part
@@ -447,14 +445,14 @@ char * hash = buffer;
// one character more to make sure the path is unique
// (we can have a directory without the character)
- path += "_";
+ path += '_';
return true;
}
// making a complete path to a static file
-bool System::MakePath(const Item & item, std::string & path, bool create_dir)
+bool System::MakePath(const Item & item, std::wstring & path, bool create_dir)
{
bool res;
diff --git a/core/system.h b/core/system.h
index 3cfa695..4cdbd6f 100755
--- a/core/system.h
+++ b/core/system.h
@@ -57,8 +57,8 @@ public:
void SetDb(Db * pdb);
void Init();
- void RedirectTo(const Item & item, const char * postfix = 0);
- void RedirectTo(long item_id, const char * postfix = 0);
+ void RedirectTo(const Item & item, const wchar_t * postfix = 0);
+ void RedirectTo(long item_id, const wchar_t * postfix = 0);
void RedirectToLastDir();
void RedirectToLastItem(); // redirect to an item if exists or to the last directory
@@ -78,9 +78,9 @@ public:
bool CanUseBBCode(long user_id);
bool CanUseRaw(long user_id);
- bool IsMemberOfGroup(long user_id, const char * group_name);
+ bool IsMemberOfGroup(long user_id, const wchar_t * group_name);
- bool MakePath(const Item & item, std::string & path, bool create_dir);
+ bool MakePath(const Item & item, std::wstring & path, bool create_dir);
bool MakePath(Item & item, bool create_dir); // output path is: item.auth_path
Error AddFile(Item & item, bool notify = true);
@@ -98,9 +98,9 @@ private:
Config * config;
Db * db;
- std::string path;
- bool MakePathSimpleFs(std::string & path, long dir_id, bool create_dir);
- bool MakePathHashFs(std::string & path, long id, bool create_dir);
+ std::wstring path;
+ bool MakePathSimpleFs(std::wstring & path, long dir_id, bool create_dir);
+ bool MakePathHashFs(std::wstring & path, long id, bool create_dir);
};
diff --git a/core/textstream.cpp b/core/textstream.cpp
index 10c7bfc..db311c7 100755
--- a/core/textstream.cpp
+++ b/core/textstream.cpp
@@ -8,119 +8,6 @@
*/
#include "textstream.h"
+#include "misc.h"
-
-
-void TextStream::Clear()
-{
- buffer.clear();
-}
-
-const std::string & TextStream::Str() const
-{
- return buffer;
-}
-
-
-const char * TextStream::CStr() const
-{
- return buffer.c_str();
-}
-
-
-
-TextStream & TextStream::operator<<(const char * str)
-{
- buffer += str;
-
-return *this;
-}
-
-TextStream & TextStream::operator<<(const std::string * str)
-{
- buffer += *str;
-
-return *this;
-}
-
-TextStream & TextStream::operator<<(const std::string & str)
-{
- buffer += str;
-
-return *this;
-}
-
-TextStream & TextStream::operator<<(char v)
-{
- buffer += v;
-
-return *this;
-}
-
-
-TextStream & TextStream::operator<<(int v)
-{
-char buf[50];
-
- sprintf(buf, "%d", v);
- buffer += buf;
-
-return *this;
-}
-
-
-TextStream & TextStream::operator<<(long v)
-{
-char buf[50];
-
- sprintf(buf, "%ld", v);
- buffer += buf;
-
-return *this;
-}
-
-
-TextStream & TextStream::operator<<(unsigned int v)
-{
-char buf[50];
-
- sprintf(buf, "%u", v);
- buffer += buf;
-
-return *this;
-}
-
-
-TextStream & TextStream::operator<<(unsigned long v)
-{
-char buf[50];
-
- sprintf(buf, "%lu", v);
- buffer += buf;
-
-return *this;
-}
-
-
-TextStream & TextStream::operator<<(double v)
-{
-char buf[50];
-
- sprintf(buf, "%f", v);
- buffer += buf;
-
-return *this;
-}
-
-
-TextStream & TextStream::operator<<(const void * v)
-{
-char buf[50];
-
- sprintf(buf, "%p", v);
- buffer += buf;
-
-return *this;
-}
-
diff --git a/core/textstream.h b/core/textstream.h
index 98bd47e..4738177 100755
--- a/core/textstream.h
+++ b/core/textstream.h
@@ -11,22 +11,33 @@
#define headerfile_winix_core_textstream
#include
+#include "misc.h"
-
+template
class TextStream
{
public:
+ typedef typename StringType::value_type CharType;
+ typedef typename StringType::value_type char_type;
+
void Clear();
- const std::string & Str() const;
- const char * CStr() const;
+ bool Empty() const;
+ size_t Size() const;
+ const StringType & Str() const;
+ const CharType * CStr() const;
TextStream & operator<<(const char * str);
TextStream & operator<<(const std::string * str);
TextStream & operator<<(const std::string & str);
+ TextStream & operator<<(const wchar_t * str);
+ TextStream & operator<<(const std::wstring * str);
+ TextStream & operator<<(const std::wstring & str);
+
TextStream & operator<<(char);
+ TextStream & operator<<(wchar_t);
TextStream & operator<<(int);
TextStream & operator<<(long);
TextStream & operator<<(unsigned int);
@@ -34,14 +45,214 @@ public:
TextStream & operator<<(double);
TextStream & operator<<(const void *);// printing a pointer
+ TextStream & Write(const CharType * buf, size_t len);
+ TextStream & write(const CharType * buf, size_t len); // for compatibility with standard library (Ezc uses it)
+
protected:
- std::string buffer;
+ StringType buffer;
};
+template
+void TextStream::Clear()
+{
+ buffer.clear();
+}
+
+template
+bool TextStream::Empty() const
+{
+ return buffer.empty();
+}
+
+template
+size_t TextStream::Size() const
+{
+ return buffer.size();
+}
+
+template
+const StringType & TextStream::Str() const
+{
+ return buffer;
+}
+
+
+template
+const typename TextStream::CharType * TextStream::CStr() const
+{
+ return buffer.c_str();
+}
+
+
+
+template
+TextStream & TextStream::operator<<(const char * str)
+{
+ AssignString(str, buffer, false);
+
+return *this;
+}
+
+
+template
+TextStream & TextStream::operator<<(const std::string * str)
+{
+ AssignString(*str, buffer, false);
+
+return *this;
+}
+
+
+template
+TextStream & TextStream::operator<<(const std::string & str)
+{
+ AssignString(str, buffer, false);
+
+return *this;
+}
+
+
+
+template
+TextStream & TextStream::operator<<(const wchar_t * str)
+{
+ AssignString(str, buffer, false);
+
+return *this;
+}
+
+
+template
+TextStream & TextStream::operator<<(const std::wstring * str)
+{
+ AssignString(*str, buffer, false);
+
+return *this;
+}
+
+
+template
+TextStream & TextStream::operator<<(const std::wstring & str)
+{
+ AssignString(str, buffer, false);
+
+return *this;
+}
+
+
+
+template
+TextStream & TextStream::operator<<(char v)
+{
+ buffer += v;
+
+return *this;
+}
+
+
+template
+TextStream & TextStream::operator<<(wchar_t v)
+{
+ buffer += static_cast(v);
+
+return *this;
+}
+
+
+template
+TextStream & TextStream::operator<<(int v)
+{
+char buf[50];
+
+ sprintf(buf, "%d", v);
+ AssignString(buf, buffer, false);
+
+return *this;
+}
+
+
+template
+TextStream & TextStream::operator<<(long v)
+{
+char buf[50];
+
+ sprintf(buf, "%ld", v);
+ AssignString(buf, buffer, false);
+
+return *this;
+}
+
+
+template
+TextStream & TextStream::operator<<(unsigned int v)
+{
+char buf[50];
+
+ sprintf(buf, "%u", v);
+ AssignString(buf, buffer, false);
+
+return *this;
+}
+
+
+template
+TextStream & TextStream::operator<<(unsigned long v)
+{
+char buf[50];
+
+ sprintf(buf, "%lu", v);
+ AssignString(buf, buffer, false);
+
+return *this;
+}
+
+
+template
+TextStream & TextStream::operator<<(double v)
+{
+char buf[50];
+
+ sprintf(buf, "%f", v);
+ AssignString(buf, buffer, false);
+
+return *this;
+}
+
+
+template
+TextStream & TextStream::operator<<(const void * v)
+{
+char buf[50];
+
+ sprintf(buf, "%p", v);
+ AssignString(buf, buffer, false);
+
+return *this;
+}
+
+
+template
+TextStream & TextStream::Write(const TextStream::CharType * buf, size_t len)
+{
+ buffer.reserve(buffer.size() + len);
+
+ for(size_t i=0 ; i
+TextStream & TextStream::write(const TextStream::CharType * buf, size_t len)
+{
+ return Write(buf, len);
+}
+
#endif
diff --git a/core/ugcontainer.h b/core/ugcontainer.h
index bb7183f..9b43257 100755
--- a/core/ugcontainer.h
+++ b/core/ugcontainer.h
@@ -28,7 +28,7 @@ public:
typedef typename Table::size_type SizeType;
typedef typename std::map TableId;
- typedef typename std::map TableName;
+ typedef typename std::map TableName;
UGContainer();
@@ -41,10 +41,10 @@ public:
void Clear();
bool Is(long id);
- bool Is(const std::string & name);
+ bool Is(const std::wstring & name);
Iterator FindId(long id);
- Iterator FindName(const std::string & name);
+ Iterator FindName(const std::wstring & name);
Type & operator[](SizeType pos);
@@ -141,7 +141,7 @@ return true;
template
-bool UGContainer::Is(const std::string & name)
+bool UGContainer::Is(const std::wstring & name)
{
typename TableName::iterator i = table_name.find(name);
@@ -167,7 +167,7 @@ return table.begin() + i->second;
template
-typename UGContainer::Iterator UGContainer::FindName(const std::string & name)
+typename UGContainer::Iterator UGContainer::FindName(const std::wstring & name)
{
typename TableName::iterator i = table_name.find(name);
diff --git a/core/user.h b/core/user.h
index 7ad3a65..cc39820 100755
--- a/core/user.h
+++ b/core/user.h
@@ -17,10 +17,10 @@
struct User
{
long id;
- std::string name;
+ std::wstring name;
bool super_user;
std::vector groups;
- std::string email;
+ std::wstring email;
int cms_notify;
int thread_notify;
diff --git a/core/users.cpp b/core/users.cpp
index 09b5bab..56748b3 100755
--- a/core/users.cpp
+++ b/core/users.cpp
@@ -58,7 +58,7 @@ return (i != table.End());
}
-bool Users::IsUser(const std::string & name)
+bool Users::IsUser(const std::wstring & name)
{
return table.Is(name);
}
@@ -75,7 +75,7 @@ return &(*i);
}
-User * Users::GetUser(const std::string & name)
+User * Users::GetUser(const std::wstring & name)
{
Table::Iterator i = table.FindName(name);
@@ -87,7 +87,7 @@ return &(*i);
-long Users::GetUserId(const std::string & name)
+long Users::GetUserId(const std::wstring & name)
{
User * puser = GetUser(name);
diff --git a/core/users.h b/core/users.h
index aa37e54..2de710c 100755
--- a/core/users.h
+++ b/core/users.h
@@ -41,10 +41,10 @@ public:
void ReadUsers(Db * db);
void SetTimeZoneOffset(int offset); // !! temporarily one time_zone for all users
bool AddUser(const User & user);
- bool IsUser(const std::string & name);
+ bool IsUser(const std::wstring & name);
User * GetUser(long user_id);
- User * GetUser(const std::string & name);
- long GetUserId(const std::string & name);
+ User * GetUser(const std::wstring & name);
+ long GetUserId(const std::wstring & name);
Iterator Begin();
Iterator End();
SizeType Size();
diff --git a/db/Makefile.dep b/db/Makefile.dep
index c9316e4..298207a 100755
--- a/db/Makefile.dep
+++ b/db/Makefile.dep
@@ -1,16 +1,26 @@
# DO NOT DELETE
db.o: db.h dbbase.h dbconn.h dbtextstream.h ../core/textstream.h
-db.o: ../core/error.h ../core/log.h dbitemquery.h ../core/item.h
-db.o: dbitemcolumns.h ../core/user.h ../core/group.h ../core/thread.h
-db.o: ../core/dircontainer.h ../core/item.h ../core/ugcontainer.h
-db.o: ../core/log.h ../core/misc.h
+db.o: ../core/misc.h ../core/item.h ../core/error.h ../core/log.h
+db.o: ../core/textstream.h dbitemquery.h ../core/item.h dbitemcolumns.h
+db.o: ../core/user.h ../core/group.h ../core/thread.h ../core/dircontainer.h
+db.o: ../core/ugcontainer.h ../core/log.h ../core/misc.h
dbbase.o: dbbase.h dbconn.h dbtextstream.h ../core/textstream.h
-dbbase.o: ../core/error.h ../core/log.h ../core/log.h
-dbconn.o: dbconn.h dbtextstream.h ../core/textstream.h ../core/log.h
-dbconn.o: ../core/error.h ../core/log.h
+dbbase.o: ../core/misc.h ../core/item.h ../core/error.h ../core/log.h
+dbbase.o: ../core/textstream.h ../core/log.h ../../ezc/src/ezc.h
+dbbase.o: ../../ezc/src/utf8.h ../../ezc/src/generator.h
+dbbase.o: ../../ezc/src/pattern.h ../../ezc/src/stringconv.h
+dbbase.o: ../../ezc/src/functions.h ../../ezc/src/funinfo.h
+dbconn.o: dbconn.h dbtextstream.h ../core/textstream.h ../core/misc.h
+dbconn.o: ../core/item.h ../core/log.h ../core/error.h ../core/log.h
+dbconn.o: ../core/textstream.h
dbitemcolumns.o: dbitemcolumns.h ../core/item.h dbbase.h dbconn.h
-dbitemcolumns.o: dbtextstream.h ../core/textstream.h ../core/error.h
-dbitemcolumns.o: ../core/log.h
+dbitemcolumns.o: dbtextstream.h ../core/textstream.h ../core/misc.h
+dbitemcolumns.o: ../core/item.h ../core/error.h ../core/log.h
+dbitemcolumns.o: ../core/textstream.h
dbitemquery.o: dbitemquery.h ../core/item.h
-dbtextstream.o: dbtextstream.h ../core/textstream.h
+dbtextstream.o: dbtextstream.h ../core/textstream.h ../core/misc.h
+dbtextstream.o: ../core/item.h ../../ezc/src/ezc.h ../../ezc/src/utf8.h
+dbtextstream.o: ../../ezc/src/generator.h ../../ezc/src/pattern.h
+dbtextstream.o: ../../ezc/src/stringconv.h ../../ezc/src/functions.h
+dbtextstream.o: ../../ezc/src/funinfo.h
diff --git a/db/db.cpp b/db/db.cpp
index 119e89f..2dd754b 100755
--- a/db/db.cpp
+++ b/db/db.cpp
@@ -15,7 +15,7 @@
-bool Db::CheckUser(const std::string & login, const std::string & password, long & user_id)
+bool Db::CheckUser(const std::wstring & login, const std::wstring & password, long & user_id)
{
PGresult * r = 0;
bool user_ok = false;
@@ -60,7 +60,7 @@ return user_ok;
-Error Db::AddUser(User & user, const std::string & password)
+Error Db::AddUser(User & user, const std::wstring & password)
{
PGresult * r = 0;
Error status = WINIX_ERR_OK;
@@ -107,7 +107,8 @@ bool is_that_url;
PGresult * r = 0;
int index = 1;
const int max_index = 99;
-char appendix[20];
+wchar_t appendix[20];
+size_t appendix_len = sizeof(appendix) / sizeof(wchar_t);
appendix[0] = 0;
try
@@ -131,7 +132,7 @@ appendix[0] = 0;
if( Rows(r) != 0 )
{
- sprintf(appendix, "_(%d)", ++index);
+ swprintf(appendix, appendix_len, L"_(%d)", ++index);
is_that_url = true;
}
else
@@ -213,8 +214,8 @@ void Db::CheckAllUrlSubject()
for(int i = 0 ; i & item_tab, long id)
// !! nowy interfejs
-Error Db::GetItem(long parent_id, const std::string & url, Item & item)
+Error Db::GetItem(long parent_id, const std::wstring & url, Item & item)
{
PGresult * r = 0;
Error result = WINIX_ERR_OK;
@@ -883,7 +884,7 @@ return result;
-long Db::GetItemId(long parent_id, const std::string & url, Item::Type type)
+long Db::GetItemId(long parent_id, const std::wstring & url, Item::Type type)
{
PGresult * r = 0;
long result = -1;
@@ -916,13 +917,13 @@ return result;
-long Db::GetFileId(long parent_id, const std::string & url)
+long Db::GetFileId(long parent_id, const std::wstring & url)
{
return GetItemId(parent_id, url, Item::file);
}
-long Db::GetDirId(long parent_id, const std::string & url)
+long Db::GetDirId(long parent_id, const std::wstring & url)
{
return GetItemId(parent_id, url, Item::dir);
}
@@ -1321,9 +1322,9 @@ void Db::GetUsers(UGContainer & user_tab)
if( u.id != last_id )
{
- u.name = AssertValue(r, i, cname);
- u.super_user = static_cast( atoi( AssertValue(r, i, csuper_user) ) );
- u.email = AssertValue(r, i, cemail);
+ u.name = AssertValueWide(r, i, cname);
+ u.super_user = static_cast(AssertValueInt(r, i, csuper_user));
+ u.email = AssertValueWide(r, i, cemail);
u.cms_notify = AssertValueInt(r, i, ccms_notify);
u.thread_notify = AssertValueInt(r, i, cthread_notify);
@@ -1384,7 +1385,7 @@ void Db::GetGroups(UGContainer & group_tab)
if( g.id != last_id )
{
- g.name = AssertValue(r, i, cname);
+ g.name = AssertValueWide(r, i, cname);
log << log3 << "Db: get group, id:" << g.id << ", group:" << g.name << logend;
iter = group_tab.PushBack( g );
@@ -1510,7 +1511,7 @@ Error Db::GetThreads(long parent_id, std::vector & thread_tab)
thread.last_item.id = AssertValueLong(r, i, clast_item);
thread.last_item.date_modification = AssertValueTm(r, i, cdate_modification);
thread.last_item.user_id = AssertValueLong(r, i, cuser_id);
- thread.last_item.guest_name = AssertValue(r, i, cguest_name);
+ thread.last_item.guest_name = AssertValueWide(r, i, cguest_name);
thread_tab.push_back(thread);
}
diff --git a/db/db.h b/db/db.h
index d0b59c1..74e79b8 100755
--- a/db/db.h
+++ b/db/db.h
@@ -42,8 +42,8 @@ public:
- bool CheckUser(const std::string & login, const std::string & password, long & user_id);
- Error AddUser(User & user, const std::string & password);
+ bool CheckUser(const std::wstring & login, const std::wstring & password, long & user_id);
+ Error AddUser(User & user, const std::wstring & password);
Error AddItem(Item & item);
Error EditItemById(Item & item, bool with_url = true);
@@ -78,13 +78,13 @@ public:
long Size(long parent_id, Item::Type type = Item::none);
Error GetItemById(long item_id, Item & item);
- Error GetItem(long parent_id, const std::string & url, Item & item);
+ Error GetItem(long parent_id, const std::wstring & url, Item & item);
Error EditDefaultItem(long id, long new_default_item);
- Error EditTemplateItemById(long id, const std::string & new_html_template);
+ Error EditTemplateItemById(long id, const std::wstring & new_html_template);
- long GetItemId(long parent_id, const std::string & url, Item::Type type);
- long GetFileId(long parent_id, const std::string & url);
- long GetDirId(long parent_id, const std::string & url);
+ long GetItemId(long parent_id, const std::wstring & url, Item::Type type);
+ long GetFileId(long parent_id, const std::wstring & url);
+ long GetDirId(long parent_id, const std::wstring & url);
@@ -100,7 +100,7 @@ public:
protected:
DbTextStream query, query_create_url;
- std::string temp_url;
+ std::wstring temp_url;
bool AddItemCreateUrlSubject(Item & item);
diff --git a/db/dbbase.cpp b/db/dbbase.cpp
index bab662c..bf16607 100755
--- a/db/dbbase.cpp
+++ b/db/dbbase.cpp
@@ -7,13 +7,13 @@
*
*/
-#include "dbbase.h"
-#include "core/log.h"
-#include "core/error.h"
#include
#include
#include
-
+#include "dbbase.h"
+#include "core/log.h"
+#include "core/error.h"
+#include "ezc.h"
DbBase::DbBase()
@@ -86,7 +86,7 @@ return r;
}
-PGresult * DbBase::AssertQuery(const std::string & q)
+PGresult * DbBase::AssertQuery(const std::wstring & q)
{
return AssertQuery(q.c_str());
}
@@ -117,7 +117,6 @@ int DbBase::AssertColumn(PGresult * r, const char * column_name)
if( c == -1 )
{
log << log1 << "Db: there is no column: " << column_name << logend;
-
throw Error(WINIX_ERR_DB_NO_COLUMN);
}
@@ -132,7 +131,6 @@ const char * DbBase::AssertValue(PGresult * r, int row, int col)
if( !res )
{
log << log1 << "Db: there is no such an item in the result, row:" << row << ", col:" << col << logend;
-
throw Error(WINIX_ERR_NO_ITEM);
}
@@ -140,6 +138,24 @@ return res;
}
+const std::wstring & DbBase::AssertValueWide(PGresult * r, int row, int col)
+{
+ const char * res = AssertValue(r, row, col);
+ static std::wstring temp_wide_value;
+
+ Ezc::UTF8ToWide(res, temp_wide_value);
+
+return temp_wide_value;
+}
+
+
+void DbBase::AssertValueWide(PGresult * r, int row, int col, std::wstring & result)
+{
+ const char * res = AssertValue(r, row, col);
+ Ezc::UTF8ToWide(res, result);
+}
+
+
long DbBase::AssertValueLong(PGresult * r, int row, int col)
{
return strtol( AssertValue(r, row, col), 0, 10 );
@@ -300,9 +316,10 @@ return buffer;
-void DbBase::CreateIdList(const std::vector & id_tab, std::string & list, bool add_parentheses)
+void DbBase::CreateIdList(const std::vector & id_tab, std::wstring & list, bool add_parentheses)
{
-char buffer[50];
+wchar_t buffer[50];
+size_t buffer_len = sizeof(buffer) / sizeof(wchar_t);
list.clear();
@@ -311,7 +328,7 @@ char buffer[50];
for(size_t i=0 ; i & id_tab, std::string & list, bool add_parentheses = true);
+ void CreateIdList(const std::vector & id_tab, std::wstring & list, bool add_parentheses = true);
Error DoCommand(const char * command);
Error BeginTrans();
@@ -76,6 +78,7 @@ private:
DbTextStream bquery;
+
};
diff --git a/db/dbconn.cpp b/db/dbconn.cpp
index f727c7f..790be4a 100755
--- a/db/dbconn.cpp
+++ b/db/dbconn.cpp
@@ -147,7 +147,7 @@ bool was_connection = true;
void DbConn::SetDbParameters()
{
- if( PQsetClientEncoding(pg_conn, "LATIN2") == -1 )
+ if( PQsetClientEncoding(pg_conn, "UTF8") == -1 )
log << log1 << "Db: Can't set the proper client encoding" << logend;
}
diff --git a/db/dbitemcolumns.cpp b/db/dbitemcolumns.cpp
index 968e349..1ab8133 100755
--- a/db/dbitemcolumns.cpp
+++ b/db/dbitemcolumns.cpp
@@ -46,18 +46,18 @@ void DbItemColumns::SetItem(PGresult * r, long row, Item & item)
if( privileges != -1 ) item.privileges = DbBase::AssertValueInt(r, row, privileges);
if( date_creation != -1 ) item.date_creation = DbBase::AssertValueTm(r, row, date_creation);
if( date_modification != -1 ) item.date_modification = DbBase::AssertValueTm(r, row, date_modification);
- if( url != -1 ) item.url = DbBase::AssertValue(r, row, url);
+ if( url != -1 ) item.url = DbBase::AssertValueWide(r, row, url);
if( type != -1 ) item.type = static_cast( DbBase::AssertValueInt(r, row, type) );
if( parent_id != -1 ) item.parent_id = DbBase::AssertValueLong(r, row, parent_id);
if( content_id != -1 ) item.content_id = DbBase::AssertValueLong(r, row, content_id);
if( default_item != -1 ) item.default_item = DbBase::AssertValueLong(r, row, default_item);
- if( subject != -1 ) item.subject = DbBase::AssertValue(r, row, subject);
- if( content != -1 ) item.content = DbBase::AssertValue(r, row, content);
+ if( subject != -1 ) item.subject = DbBase::AssertValueWide(r, row, subject);
+ if( content != -1 ) item.content = DbBase::AssertValueWide(r, row, content);
if( content_type != -1 ) item.content_type = static_cast( DbBase::AssertValueInt(r, row, content_type) );
- if( guest_name != -1 ) item.guest_name = DbBase::AssertValue(r, row, guest_name);
+ if( guest_name != -1 ) item.guest_name = DbBase::AssertValueWide(r, row, guest_name);
if( auth != -1 ) item.auth = static_cast( DbBase::AssertValueInt(r, row, auth) );
- if( auth_path != -1 ) item.auth_path = DbBase::AssertValue(r, row, auth_path);
- if( html_template != -1 ) item.html_template = DbBase::AssertValue(r, row, html_template);
+ if( auth_path != -1 ) item.auth_path = DbBase::AssertValueWide(r, row, auth_path);
+ if( html_template != -1 ) item.html_template = DbBase::AssertValueWide(r, row, html_template);
if( modification_user_id != -1 ) item.modification_user_id = DbBase::AssertValueLong(r, row, modification_user_id);
}
diff --git a/db/dbtextstream.cpp b/db/dbtextstream.cpp
index 5f6a8bc..61311f6 100755
--- a/db/dbtextstream.cpp
+++ b/db/dbtextstream.cpp
@@ -8,7 +8,7 @@
*/
#include "dbtextstream.h"
-
+#include "ezc.h"
DbTextStream::DbTextStream()
@@ -54,12 +54,39 @@ DbTextStream & DbTextStream::PutText(const std::string & str)
+DbTextStream & DbTextStream::PutText(const wchar_t * str)
+{
+ Ezc::WideToUTF8(str, buffer, false);
+ was_param = false;
+
+return *this;
+}
+
+
+DbTextStream & DbTextStream::PutText(const std::wstring * str)
+{
+ return PutText(str->c_str());
+}
+
+
+DbTextStream & DbTextStream::PutText(const std::wstring & str)
+{
+ return PutText(str.c_str());
+}
+
+
+
DbTextStream & DbTextStream::operator<<(const RawText & raw)
{
return PutText(raw.par);
}
+DbTextStream & DbTextStream::operator<<(const RawText & raw)
+{
+ return PutText(raw.par);
+}
+
DbTextStream & DbTextStream::operator<<(RawText raw)
@@ -68,9 +95,24 @@ DbTextStream & DbTextStream::operator<<(RawText raw)
}
+DbTextStream & DbTextStream::operator<<(RawText raw)
+{
+ return PutText(raw.par.c_str());
+}
+
+
DbTextStream & DbTextStream::operator<<(RawText raw)
{
- TextStream::operator<<(raw.par);
+ TextStream::operator<<(raw.par);
+ was_param = false;
+
+return *this;
+}
+
+
+DbTextStream & DbTextStream::operator<<(RawText raw)
+{
+ TextStream::operator<<(raw.par);
was_param = false;
return *this;
@@ -79,7 +121,7 @@ return *this;
DbTextStream & DbTextStream::operator<<(RawText raw)
{
- TextStream::operator<<(raw.par);
+ TextStream::operator<<(raw.par);
was_param = false;
return *this;
@@ -88,7 +130,7 @@ return *this;
DbTextStream & DbTextStream::operator<<(RawText raw)
{
- TextStream::operator<<(raw.par);
+ TextStream::operator<<(raw.par);
was_param = false;
return *this;
@@ -97,7 +139,7 @@ return *this;
DbTextStream & DbTextStream::operator<<(RawText raw)
{
- TextStream::operator<<(raw.par);
+ TextStream::operator<<(raw.par);
was_param = false;
return *this;
@@ -106,7 +148,7 @@ return *this;
DbTextStream & DbTextStream::operator<<(RawText raw)
{
- TextStream::operator<<(raw.par);
+ TextStream::operator<<(raw.par);
was_param = false;
return *this;
@@ -115,7 +157,7 @@ return *this;
DbTextStream & DbTextStream::operator<<(RawText raw)
{
- TextStream::operator<<(raw.par);
+ TextStream::operator<<(raw.par);
was_param = false;
return *this;
@@ -124,7 +166,7 @@ return *this;
DbTextStream & DbTextStream::operator<<(RawText raw)
{
- TextStream::operator<<(raw.par);
+ TextStream::operator<<(raw.par);
was_param = false;
return *this;
@@ -185,6 +227,20 @@ return *this;
}
+DbTextStream & DbTextStream::ETextPutChar(wchar_t c)
+{
+ if( c == '\\' )
+ buffer += "\\\\";
+ else
+ if( c == '\'' )
+ buffer += "\\\'"; // don't use "''" because we use the method for PQconnectdb too
+ else
+ if( c != 0 )
+ Ezc::IntToUTF8(int(c), buffer, false);
+
+return *this;
+}
+
DbTextStream & DbTextStream::EPutText(const char * str)
{
@@ -218,6 +274,39 @@ DbTextStream & DbTextStream::EPutText(const std::string & str)
}
+DbTextStream & DbTextStream::EPutText(const wchar_t * str)
+{
+ if( was_param )
+ buffer += ", ";
+
+ if( ext_escape )
+ buffer += 'E';
+
+ buffer += '\'';
+
+ for( ; *str ; ++str )
+ ETextPutChar(*str);
+
+ buffer += '\'';
+ was_param = true;
+
+return *this;
+}
+
+
+DbTextStream & DbTextStream::EPutText(const std::wstring * str)
+{
+ return EPutText(str->c_str());
+}
+
+
+DbTextStream & DbTextStream::EPutText(const std::wstring & str)
+{
+ return EPutText(str.c_str());
+}
+
+
+
// this method can escaped 0 in the middle of the string
DbTextStream & DbTextStream::EPutBin(const char * str, size_t len)
{
@@ -273,6 +362,25 @@ DbTextStream & DbTextStream::operator<<(const std::string & str)
+DbTextStream & DbTextStream::operator<<(const wchar_t * str)
+{
+ return EPutText(str);
+}
+
+
+DbTextStream & DbTextStream::operator<<(const std::wstring * str)
+{
+ return EPutText(str);
+}
+
+
+DbTextStream & DbTextStream::operator<<(const std::wstring & str)
+{
+ return EPutText(str);
+}
+
+
+
DbTextStream & DbTextStream::operator<<(char v)
{
@@ -291,12 +399,29 @@ return *this;
}
+DbTextStream & DbTextStream::operator<<(wchar_t v)
+{
+ if( was_param )
+ buffer += ", ";
+
+ if( ext_escape )
+ buffer += 'E';
+
+ buffer += '\'';
+ ETextPutChar(v);
+ buffer += '\'';
+ was_param = true;
+
+return *this;
+}
+
+
DbTextStream & DbTextStream::operator<<(int v)
{
if( was_param )
buffer += ", ";
- TextStream::operator<<(v);
+ TextStream::operator<<(v);
was_param = true;
return *this;
@@ -308,7 +433,7 @@ DbTextStream & DbTextStream::operator<<(long v)
if( was_param )
buffer += ", ";
- TextStream::operator<<(v);
+ TextStream::operator<<(v);
was_param = true;
return *this;
@@ -320,7 +445,7 @@ DbTextStream & DbTextStream::operator<<(unsigned int v)
if( was_param )
buffer += ", ";
- TextStream::operator<<(v);
+ TextStream::operator<<(v);
was_param = true;
return *this;
@@ -332,7 +457,7 @@ DbTextStream & DbTextStream::operator<<(unsigned long v)
if( was_param )
buffer += ", ";
- TextStream::operator<<(v);
+ TextStream::operator<<(v);
was_param = true;
return *this;
@@ -344,7 +469,7 @@ DbTextStream & DbTextStream::operator<<(double v)
if( was_param )
buffer += ", ";
- TextStream::operator<<(v);
+ TextStream::operator<<(v);
was_param = true;
return *this;
@@ -357,7 +482,7 @@ DbTextStream & DbTextStream::operator<<(const void * v)
buffer += ", ";
buffer += '\''; // !! not needed here?
- TextStream::operator<<(v);
+ TextStream::operator<<(v);
buffer += '\'';
was_param = true;
diff --git a/db/dbtextstream.h b/db/dbtextstream.h
index a90fde1..0cb93d0 100755
--- a/db/dbtextstream.h
+++ b/db/dbtextstream.h
@@ -49,7 +49,7 @@
between key1 key2 and key3 are commas inserted automatically
*/
-class DbTextStream : public TextStream
+class DbTextStream : public TextStream
{
public:
@@ -83,6 +83,9 @@ public:
DbTextStream & PutText(const char *);
DbTextStream & PutText(const std::string *);
DbTextStream & PutText(const std::string &);
+ DbTextStream & PutText(const wchar_t * str);
+ DbTextStream & PutText(const std::wstring * str);
+ DbTextStream & PutText(const std::wstring & str);
/*
we need this template operator for such calling:
@@ -92,9 +95,15 @@ public:
template
DbTextStream & operator<<(const RawText & raw) { return PutText(raw.par); }
- DbTextStream & operator<<(const RawText