added: a new mount type: static

some path in winix can be redirected to a specified static directory


git-svn-id: svn://ttmath.org/publicrep/winix/trunk@738 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
2011-06-14 23:45:42 +00:00
parent fb4742e165
commit c49c35cfbd
15 changed files with 355 additions and 31 deletions

View File

@@ -211,10 +211,11 @@ void App::ProcessRequestThrow()
plugin.Call(WINIX_SESSION_CHANGED);
functions.Parse();
functions.Parse(); // parsing directories,files,functions and parameters
system.mounts.CalcCurMount();
Make();
if( system.mounts.pmount->type != system.mounts.MountTypeStatic() )
Make();
}
SendAnswer();
@@ -418,15 +419,15 @@ void App::ReadEnvVariables()
// we store that values because FCGX_GetParam has O(n) complexity
// with this variables (env_*) we have O(1)
SetEnv(cur.request->env_request_method, "REQUEST_METHOD"); // !! mozna nie uzywac tego, teraz mamy w strukturze fcgi_request
SetEnv(cur.request->env_request_method, "REQUEST_METHOD"); // !! mozna nie uzywac tego, teraz mamy w strukturze fcgi_request
SetEnv(cur.request->env_request_uri, "REQUEST_URI");
SetEnv(cur.request->env_http_cookie, "HTTP_COOKIE");
SetEnv(cur.request->env_remote_addr, "REMOTE_ADDR");
SetEnv(cur.request->env_http_host, "HTTP_HOST");
SetEnv(cur.request->env_http_host, "HTTP_HOST");
SetEnv(cur.request->env_http_user_agent, "HTTP_USER_AGENT");
SetEnv(cur.request->env_fcgi_role, "FCGI_ROLE");
SetEnv(cur.request->env_content_type, "CONTENT_TYPE");
SetEnv(cur.request->env_http_accept_encoding,"HTTP_ACCEPT_ENCODING");
SetEnv(cur.request->env_fcgi_role, "FCGI_ROLE");
SetEnv(cur.request->env_content_type, "CONTENT_TYPE");
SetEnv(cur.request->env_http_accept_encoding, "HTTP_ACCEPT_ENCODING");
}
@@ -539,6 +540,59 @@ void App::PrepareSessionCookie()
void App::SendHeadersStatic()
{
if( PathHasUpDir(cur.request->env_request_uri) )
{
log << log1 << "App: incorrect path for a static file" << logend;
SendHeadersForbidden();
return;
}
const std::wstring & index_str = system.mounts.pmount->FirstArg(system.mounts.MountParStatic());
size_t index = Toi(index_str);
if( index >= config.static_dirs.size() )
{
log << log1 << "App: static dir with index " << index << " is not defined in the config" << logend;
SendHeadersForbidden();
return;
}
Ezc::WideToUTF8(config.http_header_send_file, sendheadersstatic_t);
Ezc::WideToUTF8(config.static_dirs[index], sendheadersstatic_t2);
Item * dir = system.dirs.GetDir(system.mounts.pmount->dir_id);
if( !dir )
{
log << log1 << "App: cannot find the mount directory" << logend;
SendHeadersForbidden();
return;
}
size_t how_many_dirs = system.dirs.DirLevel(dir->id);
const char * path = SkipDirs(cur.request->env_request_uri, how_many_dirs);
// the path begins with a slash only if how_many_dirs is zero
while( *path == '/' )
path += 1;
FCGX_FPrintF(fcgi_request.out, "%s: %s/%s\r\n", sendheadersstatic_t.c_str(), sendheadersstatic_t2.c_str(), path);
FCGX_PutS("Status: 200 OK\r\n", fcgi_request.out);
log << log2 << "Sending file from a static mountpoint: " << sendheadersstatic_t2 << "/" << path << logend;
}
void App::SendHeadersForbidden()
{
FCGX_PutS("Status: 403 Forbidden\r\n", fcgi_request.out);
FCGX_PutS("Content-Type: text/html\r\n", fcgi_request.out);
log << log2 << "Request: response: 403 Forbidden" << logend;
}
void App::SendHeaders(bool compressing, int compress_encoding, Header header)
{
@@ -555,6 +609,11 @@ void App::SendHeaders(bool compressing, int compress_encoding, Header header)
log << log2 << "Redirect to: " << cur.request->aredirect_to << logend;
}
else
if( system.mounts.pmount->type == system.mounts.MountTypeStatic() )
{
SendHeadersStatic();
}
else
if( !cur.request->x_sendfile.empty() )
{
static std::string temp, temp2; // !! wrzucic gdzies to
@@ -577,9 +636,7 @@ void App::SendHeaders(bool compressing, int compress_encoding, Header header)
break;
case h_403:
FCGX_PutS("Status: 403 Forbidden\r\n", fcgi_request.out);
FCGX_PutS("Content-Type: text/html\r\n", fcgi_request.out);
log << log2 << "Request: response: 403 Forbidden" << logend;
SendHeadersForbidden();
break;
default: