added support for UTF-8
now the UTF-8 is a default charset git-svn-id: svn://ttmath.org/publicrep/winix/trunk@677 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
72
core/app.cpp
72
core/app.cpp
@@ -16,7 +16,7 @@
|
||||
#include "plugin.h"
|
||||
#include "misc.h"
|
||||
#include "functions/functions.h"
|
||||
|
||||
#include "ezc.h"
|
||||
|
||||
|
||||
|
||||
@@ -161,11 +161,11 @@ bool App::Init()
|
||||
2 ); // !! chwilowo
|
||||
//system.mounts.MountTypeTicket() );
|
||||
|
||||
|
||||
// init templates after functions are created
|
||||
templates.ReadIndexFileNames();
|
||||
templates.ReadTemplates();
|
||||
templates.CreateFunctions();
|
||||
|
||||
session_manager.LoadSessions();
|
||||
|
||||
plugin.Call(WINIX_PLUGIN_INIT);
|
||||
@@ -190,10 +190,11 @@ bool App::BaseUrlRedirect()
|
||||
if( config.base_url_http_host.empty() )
|
||||
return false;
|
||||
|
||||
if( config.base_url_http_host == request.env_http_host )
|
||||
if( Equal(config.base_url_http_host.c_str(), request.env_http_host) )
|
||||
return false;
|
||||
|
||||
request.redirect_to = config.base_url + request.env_request_uri;
|
||||
|
||||
request.redirect_to = config.base_url;
|
||||
AssignString(request.env_request_uri, request.redirect_to, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -202,10 +203,11 @@ bool App::BaseUrlRedirect()
|
||||
if( config.base_url_auth_http_host.empty() )
|
||||
return false;
|
||||
|
||||
if( config.base_url_auth_http_host == request.env_http_host )
|
||||
if( Equal(config.base_url_auth_http_host.c_str(), request.env_http_host) )
|
||||
return false;
|
||||
|
||||
request.redirect_to = config.base_url_auth + request.env_request_uri;
|
||||
request.redirect_to = config.base_url_auth;
|
||||
AssignString(request.env_request_uri, request.redirect_to, false);
|
||||
}
|
||||
|
||||
log << log3 << "RC: BaseUrlRedirect from: " << request.env_http_host << logend;
|
||||
@@ -309,13 +311,13 @@ bool sent = false;
|
||||
if( request.is_item && request.item.auth == Item::auth_none &&
|
||||
request.item.content_type == Item::ct_raw && request.status == WINIX_ERR_OK && request.function )
|
||||
{
|
||||
if( request.function->fun.url == "cat" )
|
||||
if( request.function == &functions.fun_cat )
|
||||
{
|
||||
request.page << request.item.content;
|
||||
sent = true;
|
||||
}
|
||||
else
|
||||
if( request.function->fun.url == "run" )
|
||||
if( request.function == &functions.fun_run )
|
||||
{
|
||||
templates.GenerateRunRaw();
|
||||
sent = true;
|
||||
@@ -358,7 +360,7 @@ void App::Make()
|
||||
if( request.session->spam_score > 0 )
|
||||
log << log1 << "App: spam score: " << request.session->spam_score << logend;
|
||||
|
||||
if( request.IsParam("noredirect") )
|
||||
if( request.IsParam(L"noredirect") )
|
||||
request.redirect_to.clear();
|
||||
|
||||
if( request.status == WINIX_ERR_OK )
|
||||
@@ -484,6 +486,7 @@ void App::LogAccess()
|
||||
void App::ReadGetPostVars()
|
||||
{
|
||||
// get parameters we have always
|
||||
get_parser.UTF8(config.utf8);
|
||||
get_parser.Parse(request.env_request_uri, request.get_tab);
|
||||
|
||||
if( request.method == Request::post )
|
||||
@@ -491,10 +494,14 @@ void App::ReadGetPostVars()
|
||||
if( IsSubStringNoCase("multipart/form-data", request.env_content_type) )
|
||||
{
|
||||
log << log3 << "Request: post content type: multipart/form-data" << logend;
|
||||
// !! dodac metode UTF8 do post_multi_parsera
|
||||
// (narazie bierze bezposrednio z konfigu)
|
||||
// w ogole wywalic zaleznosc od konfiga
|
||||
post_multi_parser.Parse(request.in, request.post_tab, request.post_file_tab);
|
||||
}
|
||||
else
|
||||
{
|
||||
post_parser.UTF8(config.utf8);
|
||||
post_parser.Parse(request.in, request.post_tab);
|
||||
}
|
||||
}
|
||||
@@ -560,14 +567,19 @@ void App::SendHeaders(bool compressing, Header header)
|
||||
if( !request.redirect_to.empty() )
|
||||
{
|
||||
FCGX_PutS("Status: 301 Moved Permanently\r\n", request.out);
|
||||
FCGX_FPrintF(request.out, "Location: %s\r\n", request.redirect_to.c_str());
|
||||
AssignString(request.redirect_to, request.aredirect_to);
|
||||
FCGX_FPrintF(request.out, "Location: %s\r\n", request.aredirect_to.c_str());
|
||||
log << log2 << "Redirect to: " << request.redirect_to << logend;
|
||||
}
|
||||
else
|
||||
if( !request.x_sendfile.empty() )
|
||||
{
|
||||
FCGX_FPrintF(request.out, "%s: %s\r\n", config.http_header_send_file.c_str(),
|
||||
request.x_sendfile.c_str());
|
||||
static std::string temp, temp2; // !! wrzucic gdzies to
|
||||
|
||||
AssignString(config.http_header_send_file, temp);
|
||||
AssignString(request.x_sendfile, temp2);
|
||||
FCGX_FPrintF(request.out, "%s: %s\r\n", temp.c_str(), temp2.c_str());
|
||||
|
||||
FCGX_PutS("Status: 200 OK\r\n", request.out);
|
||||
log << log2 << "Sending file: " << request.x_sendfile << logend;
|
||||
}
|
||||
@@ -598,7 +610,7 @@ void App::SendHeaders(bool compressing, Header header)
|
||||
if( compressing )
|
||||
FCGX_PutS("Content-Encoding: deflate\r\n", request.out);
|
||||
|
||||
FCGX_PutS(request.headers.str().c_str(), request.out);
|
||||
FCGX_PutS(request.headers.CStr(), request.out);
|
||||
FCGX_PutS("\r\n", request.out);
|
||||
}
|
||||
|
||||
@@ -617,12 +629,12 @@ void App::SetHtmlFilterConf()
|
||||
|
||||
// !! kopiowanie tych stringow bedzie zmienione
|
||||
// gdy bedziemy korzystac w przyszlosci z wlasnego stringstream
|
||||
void App::FilterCompressSend(bool compressing, const std::string & source_ref)
|
||||
void App::FilterCompressSend(bool compressing, const std::wstring & source_ref)
|
||||
{
|
||||
const std::string * source = &source_ref;
|
||||
const std::wstring * source = &source_ref;
|
||||
|
||||
bool raw = request.is_item && request.item.content_type == Item::ct_raw && request.status == WINIX_ERR_OK &&
|
||||
request.function && (request.function->fun.url == "cat" || request.function->fun.url == "run");
|
||||
request.function && (request.function == &functions.fun_cat || request.function == &functions.fun_run);
|
||||
|
||||
if( config.html_filter && !raw )
|
||||
{
|
||||
@@ -639,15 +651,19 @@ void App::FilterCompressSend(bool compressing, const std::string & source_ref)
|
||||
}
|
||||
|
||||
|
||||
// !! zrobic z tym porzadek
|
||||
std::string temp;
|
||||
Ezc::WideToUTF8(*source, temp);
|
||||
|
||||
if( compressing )
|
||||
compress.CompressAndPut(source->c_str(), source->length(), request.out);
|
||||
compress.CompressAndPut(temp.c_str(), temp.length(), request.out);
|
||||
else
|
||||
FCGX_PutS(source->c_str(), request.out);
|
||||
FCGX_PutS(temp.c_str(), request.out);
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool App::IsCompressionAllowed(const std::string & source)
|
||||
bool App::IsCompressionAllowed(const std::wstring & source)
|
||||
{
|
||||
return( config.compression &&
|
||||
request.role == Request::responder &&
|
||||
@@ -681,17 +697,15 @@ return true;
|
||||
}
|
||||
|
||||
|
||||
void App::AddDebugInfo(std::string & out)
|
||||
void App::AddDebugInfo(std::wstring & out)
|
||||
{
|
||||
if( config.debug_info )
|
||||
{
|
||||
const std::string & d = request.debug.str();
|
||||
|
||||
if( !d.empty() )
|
||||
if( !request.debug.Empty() )
|
||||
{
|
||||
out += "\n<!--\n";
|
||||
out += d;
|
||||
out += "\n-->\n";
|
||||
out += L"\n<!--\n";
|
||||
out += request.debug.Str();
|
||||
out += L"\n-->\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -700,7 +714,7 @@ void App::AddDebugInfo(std::string & out)
|
||||
|
||||
void App::SendAnswer()
|
||||
{
|
||||
const std::string & source = request.page.str();
|
||||
const std::wstring & source = request.page.Str();
|
||||
Header header = h_200;
|
||||
bool compressing = IsCompressionAllowed(source);
|
||||
Error status = request.status;
|
||||
@@ -755,7 +769,7 @@ void App::LogGroup(const char * msg, gid_t id, bool put_logend)
|
||||
void App::LogUsers()
|
||||
{
|
||||
uid_t eid, rid;
|
||||
|
||||
|
||||
eid = geteuid();
|
||||
rid = getuid();
|
||||
|
||||
|
Reference in New Issue
Block a user