changed: now we do not use std::string and char* in the Winix API

everywhere we are using std::wstring and wchar_t*
         (std::string and char* is used only locally in some places
         especially when creating a path to OS file system etc.)
added:   to the special thread when winix closes:
         a write function for curl: FetchPageOnExitCurlCallback()
         without this function the curl library will print
         the page's content to the standart output
changed: TextStream<> class from core can make
         UTF8<->wide strings conversions
removed: from config: utf8 option
         now winix expects UTF8 from the user's input (html forms, url-es)
         and outputs strings in the UTF8 format




git-svn-id: svn://ttmath.org/publicrep/winix/trunk@965 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
2014-10-09 20:44:56 +00:00
parent 4abf6642f7
commit 8196fb77d1
74 changed files with 1911 additions and 1612 deletions

View File

@@ -33,6 +33,9 @@
*/
#include "httpsimpleparser.h"
#include "misc.h"
#include "utf8/utf8.h"
namespace Winix
@@ -41,14 +44,12 @@ namespace Winix
void HttpSimpleParser::ToLower(std::string & s)
void HttpSimpleParser::ToLower(std::wstring & s)
{
std::string::iterator i;
for(i=s.begin() ; i!= s.end() ; ++i)
for(wchar_t & c : s)
{
if( *i>='A' && *i<='Z' )
*i = *i - 'A' + 'a';
if( c>='A' && c<='Z' )
c = c - 'A' + 'a';
}
}
@@ -70,38 +71,6 @@ void HttpSimpleParser::SkipWhiteChars()
void HttpSimpleParser::TrimWhiteChars(std::string & s)
{
if( s.empty() )
return;
std::string::size_type i;
for(i = 0 ; i<s.size() && IsWhite(s[i]) ; ++i);
if( i == s.size() )
{
// all characters are white
s.clear();
return;
}
if( i > 0 )
// there are some white characters at the beginning
s.erase(0, i);
// s is not empty now (i was not equal s.size())
// and we have some non white characters
// we stops at the last non white character
for(i = s.size()-1 ; i>0 && IsWhite(s[i]) ; --i);
if( i != s.size()-1 )
// there are some white characters at the end
// we're starting from i+1 even when i==0 (there are some non white characters)
s.erase(i+1, s.size() - i - 1);
}
int HttpSimpleParser::ParseHalfHex(int c)
@@ -152,33 +121,42 @@ void HttpSimpleParser::CheckSpecialChar()
void HttpSimpleParser::ReadName()
{
// we're checking 'separator' and '=' because the string is allowed not having '=' (the value is optional)
utf8_token.clear();
last_name.clear();
for( ; last_c!=-1 && last_c!=separator && last_c!='=' ; last_c = GetChar() )
{
if( recognize_special_chars )
CheckSpecialChar();
if( last_c != -1 )
last_name += last_c;
{
if( getchar_returns_utf8_chars )
utf8_token += last_c;
else
last_name += last_c;
}
}
if( getchar_returns_utf8_chars )
PT::UTF8ToWide(utf8_token, last_name);
if( last_c == '=' )
last_c = GetChar();
}
void HttpSimpleParser::ReadQuotedValue()
{
// skipping '"'
last_c = GetChar();
utf8_token.clear();
last_value.clear();
for( ; last_c!=-1 && last_c!='"' ; last_c = GetChar() )
{
@@ -186,9 +164,16 @@ void HttpSimpleParser::ReadQuotedValue()
CheckSpecialChar();
if( last_c != -1 )
last_value += last_c;
{
if( getchar_returns_utf8_chars )
utf8_token += last_c;
else
last_value += last_c;
}
}
if( getchar_returns_utf8_chars )
PT::UTF8ToWide(utf8_token, last_value);
if( last_c == '"' )
last_c = GetChar();
@@ -199,26 +184,39 @@ void HttpSimpleParser::ReadQuotedValue()
}
void HttpSimpleParser::ReadNormalValue()
{
utf8_token.clear();
last_value.clear();
for( ; last_c!=-1 && last_c!=separator ; last_c = GetChar() )
{
if( recognize_special_chars )
CheckSpecialChar();
if( last_c != -1 )
{
if( getchar_returns_utf8_chars )
utf8_token += last_c;
else
last_value += last_c;
}
}
if( getchar_returns_utf8_chars )
PT::UTF8ToWide(utf8_token, last_value);
}
void HttpSimpleParser::ReadValue()
{
if( skip_white_chars )
SkipWhiteChars();
if( value_can_be_quoted && last_c == '"' )
{
ReadQuotedValue();
}
else
{
for( ; last_c!=-1 && last_c!=separator ; last_c = GetChar() )
{
if( recognize_special_chars )
CheckSpecialChar();
if( last_c != -1 )
last_value += last_c;
}
}
ReadNormalValue();
if( last_c == separator )
@@ -228,6 +226,21 @@ void HttpSimpleParser::ReadValue()
/*
* there can be some important values like passwords so its better
* to clear them now
*/
void HttpSimpleParser::Clear()
{
Overwrite(last_name);
Overwrite(last_value);
Overwrite(utf8_token);
last_name.clear();
last_value.clear();
utf8_token.clear();
}
void HttpSimpleParser::Parse()
{
for( last_c = GetChar() ; last_c != -1 ; )
@@ -242,12 +255,14 @@ void HttpSimpleParser::Parse()
if( skip_white_chars )
{
TrimWhiteChars(last_name);
TrimWhiteChars(last_value);
TrimWhite(last_name);
TrimWhite(last_value);
}
Parameter(last_name, last_value); // user definied function
}
Clear();
}