diff --git a/winixd/core/misc.cpp b/winixd/core/misc.cpp index 46a9805..3c790af 100644 --- a/winixd/core/misc.cpp +++ b/winixd/core/misc.cpp @@ -1264,8 +1264,15 @@ void UrlEncode(const char * in, std::string & out, bool clear_out) if( clear_out ) out.clear(); + pt::TextStream stream; + for(size_t i=0 ; in[i] != 0 ; ++i) - UrlEncode(in[i], out, false); + { + UrlEncode(in[i], stream, true); + + for(size_t s=0 ; s < stream.size() ; ++s) + out += stream[s]; + } } @@ -1275,39 +1282,44 @@ void UrlEncode(const std::string & in, std::string & out, bool clear_out) } - -void UrlEncode(const wchar_t * in, std::string & out, bool clear_out) -{ -static std::string ain; - - pt::wide_to_utf8(in, ain); - - if( clear_out ) - out.clear(); - - for(size_t i=0 ; i < ain.size() ; ++i) - UrlEncode(ain[i], out, false); -} +//void UrlEncode(const wchar_t * in, std::string & out, bool clear_out) +//{ +// if( clear_out ) +// out.clear(); +// +// pt::TextStream stream; +// +// for(size_t i=0 ; in[i] != 0 ; ++i) +// { +// UrlEncode(in[i], stream, true); +// +// for(size_t s=0 ; s < stream.size() ++i) +// out += stream[s]; +// } +//} -void UrlEncode(const std::wstring & in, std::string & out, bool clear_out) -{ - UrlEncode(in.c_str(), out, clear_out); -} +//void UrlEncode(const std::wstring & in, std::string & out, bool clear_out) +//{ +// UrlEncode(in.c_str(), out, clear_out); +//} void UrlEncode(const wchar_t * in, std::wstring & out, bool clear_out) { -static std::string ain; - - pt::wide_to_utf8(in, ain); - if( clear_out ) out.clear(); - for(size_t i=0 ; i < ain.size() ; ++i) - UrlEncode(ain[i], out, false); + pt::WTextStream stream; + + for(size_t i=0 ; in[i] != 0 ; ++i) + { + UrlEncode(in[i], stream, true); + + for(size_t s=0 ; s < stream.size() ; ++s) + out += stream[s]; + } } @@ -1318,6 +1330,27 @@ void UrlEncode(const std::wstring & in, std::wstring & out, bool clear_out) +void UrlEncode(const pt::TextStream & in, pt::TextStream & out, bool clear_out) +{ + if( clear_out ) + out.clear(); + + for(size_t i=0 ; i < in.size() ; ++i) + UrlEncode(in.get_char(i), out, false); +} + + +void UrlEncode(const pt::WTextStream & in, pt::WTextStream & out, bool clear_out) +{ + if( clear_out ) + out.clear(); + + for(size_t i=0 ; i < in.size() ; ++i) + UrlEncode(in.get_wchar(i), out, false); +} + + + bool UrlDecodeFromHex(int c, int & out) { diff --git a/winixd/core/misc.h b/winixd/core/misc.h index ea41768..d45d4ba 100644 --- a/winixd/core/misc.h +++ b/winixd/core/misc.h @@ -678,14 +678,11 @@ int SelectFileType(const std::wstring & file_name); -// thread safe -template -void UrlEncode(char c, - pt::TextStreamBase & out, - bool clear_out = true) +template +void UrlEncode(char c, StreamType & out, bool clear_out = true) { -char buffer[10]; -size_t buflen = sizeof(buffer)/sizeof(char); + char buffer[10]; + size_t buflen = sizeof(buffer)/sizeof(char); if( clear_out ) out.clear(); @@ -710,11 +707,33 @@ size_t buflen = sizeof(buffer)/sizeof(char); } -// thread safe -template -void UrlEncode(const char * in, - pt::TextStreamBase & out, - bool clear_out = true) + +template +void UrlEncode(wchar_t c, StreamType & out, bool clear_out = true) +{ +char buffer[10]; +size_t buflen = sizeof(buffer)/sizeof(char); + + if( clear_out ) + out.clear(); + + // this conversion is not using surrogate pairs if wchar_t is 2 bytes long + size_t utf8_len = pt::int_to_utf8(static_cast(c), buffer, buflen); + + if( utf8_len > 0 ) + { + for(size_t i=0 ; i < utf8_len ; ++i) + { + UrlEncode(buffer[i], out, false); + } + } +} + + + + +template +void UrlEncode(const char * in, StreamType & out, bool clear_out = true) { if( clear_out ) out.clear(); @@ -724,67 +743,44 @@ void UrlEncode(const char * in, } -// thread safe -template -void UrlEncode(const std::string & in, - pt::TextStreamBase & out, - bool clear_out = true) + +template +void UrlEncode(const std::string & in, StreamType & out, bool clear_out = true) { UrlEncode(in.c_str(), out, clear_out); } -// not thread safe -template -void UrlEncode(const wchar_t * in, - pt::TextStreamBase & out, - bool clear_out = true) +template +void UrlEncode(const wchar_t * in, StreamType & out, bool clear_out = true) { -static std::string ain; - - pt::wide_to_utf8(in, ain); - if( clear_out ) out.clear(); - for(size_t i=0 ; i < ain.size() ; ++i) - UrlEncode(ain[i], out, false); + for(size_t i=0 ; in[i] != 0 ; ++i) + UrlEncode(in[i], out, false); } -// not thread safe -template -void UrlEncode(const std::wstring & in, - pt::TextStreamBase & out, - bool clear_out = true) +template +void UrlEncode(const std::wstring & in, StreamType & out, bool clear_out = true) { UrlEncode(in.c_str(), out, clear_out); } -// no thread safe -template -void UrlEncode(char c, StringType & out, bool clear_out = true) -{ -static pt::TextStream tmp; - - UrlEncode(c, tmp); - tmp.to_str(out, clear_out); -} - - -// !! IMROVE ME we need some UrlEncode methods with pt::TextBuffer instead of std::string - - void UrlEncode(const char * in, std::string & out, bool clear_out = true); void UrlEncode(const std::string & in, std::string & out, bool clear_out = true); -void UrlEncode(const wchar_t * in, std::string & out, bool clear_out = true); -void UrlEncode(const std::wstring & in, std::string & out, bool clear_out = true); +//void UrlEncode(const wchar_t * in, std::string & out, bool clear_out = true); +//void UrlEncode(const std::wstring & in, std::string & out, bool clear_out = true); void UrlEncode(const wchar_t * in, std::wstring & out, bool clear_out = true); void UrlEncode(const std::wstring & in, std::wstring & out, bool clear_out = true); +void UrlEncode(const pt::TextStream & in, pt::TextStream & out, bool clear_out = true); +void UrlEncode(const pt::WTextStream & in, pt::WTextStream & out, bool clear_out = true); + /* diff --git a/winixd/templates/filters.cpp b/winixd/templates/filters.cpp index e9196fa..c0268ad 100644 --- a/winixd/templates/filters.cpp +++ b/winixd/templates/filters.cpp @@ -41,14 +41,13 @@ namespace Winix namespace TemplatesFunctions { -static std::string urlencode_tmp; +// not thread safe static std::string qencode_tmp; void fil_urlencode(Info & i) { - UrlEncode(i.in.Str(), urlencode_tmp); - i.out << R(urlencode_tmp); + UrlEncode(i.in.Str(), i.out); }