From ccc02f41bf5c5c1b41746ac4817fdce5e3fd686a Mon Sep 17 00:00:00 2001 From: Tomasz Sowa Date: Thu, 7 Jul 2011 17:02:14 +0000 Subject: [PATCH] added: we can use different redirect codes now (int Request::redirect_type variable) we can set following integer values: 300 - Multiple Choices 301 - Moved Permanently 302 - Found 307 - Temporary Redirect 303 - See Other default is 303 for all redirects git-svn-id: svn://ttmath.org/publicrep/winix/trunk@749 e52654a7-88a9-db11-a3e9-0013d4bc506e --- core/app.cpp | 116 +++++++++++++++++++++++++++++-------------- core/app.h | 5 ++ core/confparser.h | 4 +- core/request.cpp | 3 +- core/request.h | 11 +++- core/requesttypes.h | 1 + core/slog.h | 6 +++ templates/locale.cpp | 5 -- templates/locale.h | 3 -- 9 files changed, 106 insertions(+), 48 deletions(-) diff --git a/core/app.cpp b/core/app.cpp index 727816e..9b1fa2a 100755 --- a/core/app.cpp +++ b/core/app.cpp @@ -598,6 +598,82 @@ void App::SendHeadersForbidden() } +void App::SendHeadersRedirect() +{ + switch(cur.request->redirect_type) + { + case 300: + FCGX_PutS("Status: 300 Multiple Choices\r\n", fcgi_request.out); + break; + + case 301: + FCGX_PutS("Status: 301 Moved Permanently\r\n", fcgi_request.out); + break; + + case 302: + FCGX_PutS("Status: 302 Found\r\n", fcgi_request.out); + break; + + case 307: + FCGX_PutS("Status: 307 Temporary Redirect\r\n", fcgi_request.out); + break; + + case 303: + default: + FCGX_PutS("Status: 303 See Other\r\n", fcgi_request.out); + break; + } + + UrlEncode(cur.request->redirect_to, cur.request->aredirect_to); + FCGX_FPrintF(fcgi_request.out, "Location: %s\r\n", cur.request->aredirect_to.c_str()); + log << log2 << "Redirect to: " << cur.request->aredirect_to << logend; +} + + +void App::SendHeadersSendFile() +{ + Ezc::WideToUTF8(config.http_header_send_file, sendfilea); + Ezc::WideToUTF8(cur.request->x_sendfile, sendfile2a); + FCGX_FPrintF(fcgi_request.out, "%s: %s\r\n", sendfilea.c_str(), sendfile2a.c_str()); + + FCGX_PutS("Status: 200 OK\r\n", fcgi_request.out); + log << log2 << "Sending file: " << cur.request->x_sendfile << logend; +} + + +void App::SendHeadersCompression(int compress_encoding) +{ + if( compress_encoding == 0 || compress_encoding == 1 ) + FCGX_PutS("Content-Encoding: deflate\r\n", fcgi_request.out); + else + FCGX_PutS("Content-Encoding: gzip\r\n", fcgi_request.out); +} + + +void App::SendHeadersNormal(Header header) +{ + switch( header ) + { + case h_404: + FCGX_PutS("Status: 404 Not Found\r\n", fcgi_request.out); + FCGX_PutS("Content-Type: text/html\r\n", fcgi_request.out); + log << log2 << "Request: response: 404 Not Found" << logend; + break; + + case h_403: + SendHeadersForbidden(); + break; + + default: + FCGX_PutS("Status: 200 OK\r\n", fcgi_request.out); + + if( cur.request->role != Request::authorizer ) + FCGX_PutS("Content-Type: text/html\r\n", fcgi_request.out); + } +} + + + void App::SendHeaders(bool compressing, int compress_encoding, Header header) { PrepareSessionCookie(); @@ -607,10 +683,7 @@ void App::SendHeaders(bool compressing, int compress_encoding, Header header) if( !cur.request->redirect_to.empty() ) { - FCGX_PutS("Status: 301 Moved Permanently\r\n", fcgi_request.out); - UrlEncode(cur.request->redirect_to, cur.request->aredirect_to); - FCGX_FPrintF(fcgi_request.out, "Location: %s\r\n", cur.request->aredirect_to.c_str()); - log << log2 << "Redirect to: " << cur.request->aredirect_to << logend; + SendHeadersRedirect(); } else if( system.mounts.pmount->type == system.mounts.MountTypeStatic() ) @@ -620,44 +693,15 @@ void App::SendHeaders(bool compressing, int compress_encoding, Header header) else if( !cur.request->x_sendfile.empty() ) { - static std::string temp, temp2; // !! wrzucic gdzies to - - Ezc::WideToUTF8(config.http_header_send_file, temp); - Ezc::WideToUTF8(cur.request->x_sendfile, temp2); - FCGX_FPrintF(fcgi_request.out, "%s: %s\r\n", temp.c_str(), temp2.c_str()); - - FCGX_PutS("Status: 200 OK\r\n", fcgi_request.out); - log << log2 << "Sending file: " << cur.request->x_sendfile << logend; + SendHeadersSendFile(); } else { - switch( header ) - { - case h_404: - FCGX_PutS("Status: 404 Not Found\r\n", fcgi_request.out); - FCGX_PutS("Content-Type: text/html\r\n", fcgi_request.out); - log << log2 << "Request: response: 404 Not Found" << logend; - break; - - case h_403: - SendHeadersForbidden(); - break; - - default: - FCGX_PutS("Status: 200 OK\r\n", fcgi_request.out); - - if( cur.request->role != Request::authorizer ) - FCGX_PutS("Content-Type: text/html\r\n", fcgi_request.out); - } + SendHeadersNormal(header); } if( compressing ) - { - if( compress_encoding == 0 || compress_encoding == 1 ) - FCGX_PutS("Content-Encoding: deflate\r\n", fcgi_request.out); - else - FCGX_PutS("Content-Encoding: gzip\r\n", fcgi_request.out); - } + SendHeadersCompression(compress_encoding); FCGX_PutS(cur.request->headers.CStr(), fcgi_request.out); FCGX_PutS("\r\n", fcgi_request.out); diff --git a/core/app.h b/core/app.h index afc6ac6..d7d8d1d 100755 --- a/core/app.h +++ b/core/app.h @@ -131,6 +131,7 @@ private: std::string url_to_fetch_on_exit; std::string source_a; std::string sendheadersstatic_t, sendheadersstatic_t2; + std::string sendfilea, sendfile2a; void ProcessRequestThrow(); void ProcessRequest(); @@ -157,6 +158,10 @@ private: void FilterCompressSend(bool compressing, int compress_encoding, const std::wstring & source_ref); void SendHeadersStatic(); void SendHeadersForbidden(); + void SendHeadersRedirect(); + void SendHeadersSendFile(); + void SendHeadersCompression(int compress_encoding); + void SendHeadersNormal(Header header); void SendHeaders(bool compressing, int compress_encoding, Header header); int SelectDeflateVersion(); void SelectCompression(size_t source_len, bool & compression_allowed, int & compression_encoding); diff --git a/core/confparser.h b/core/confparser.h index 5824f08..fe4f9d8 100755 --- a/core/confparser.h +++ b/core/confparser.h @@ -7,8 +7,8 @@ * */ -#ifndef headerfileconfparser -#define headerfileconfparser +#ifndef headerfile_winix_core_confparser +#define headerfile_winix_core_confparser #include #include diff --git a/core/request.cpp b/core/request.cpp index c93c0fc..fef009c 100755 --- a/core/request.cpp +++ b/core/request.cpp @@ -2,7 +2,7 @@ * This file is a part of Winix * and is not publicly distributed * - * Copyright (c) 2008-2010, Tomasz Sowa + * Copyright (c) 2008-2011, Tomasz Sowa * All rights reserved. * */ @@ -77,6 +77,7 @@ void Request::Clear() browser_msie = false; redirect_to.clear(); + redirect_type = 303; x_sendfile.clear(); send_as_attachment = false; } diff --git a/core/request.h b/core/request.h index 70babcc..4f928c6 100755 --- a/core/request.h +++ b/core/request.h @@ -2,7 +2,7 @@ * This file is a part of Winix * and is not publicly distributed * - * Copyright (c) 2008-2010, Tomasz Sowa + * Copyright (c) 2008-2011, Tomasz Sowa * All rights reserved. * */ @@ -102,6 +102,15 @@ struct Request std::wstring redirect_to; std::string aredirect_to; + // a redirect type + // following redirect types are supported: + // 300 Multiple Choices + // 301 Moved Permanently + // 302 Found + // 303 See Other (default) + // 307 Temporary Redirect + int redirect_type; + // send header X-LIGHTTPD-send-file with path to a file std::wstring x_sendfile; diff --git a/core/requesttypes.h b/core/requesttypes.h index 13a1c07..894220c 100755 --- a/core/requesttypes.h +++ b/core/requesttypes.h @@ -20,6 +20,7 @@ #define WINIX_POSTTABLE_MAXSIZE 50 + struct PostFile { std::wstring filename; // original file name diff --git a/core/slog.h b/core/slog.h index eabdda3..1290264 100755 --- a/core/slog.h +++ b/core/slog.h @@ -72,6 +72,12 @@ public: SLog & TranslateText(const char * str); SLog & TranslateText(const wchar_t * str); + template + SLog & operator<<(const TranslateTextHelper & raw) { return TranslateText(raw.par); } + + template + SLog & operator<<(const TranslateTextHelper & raw){ return TranslateText(raw.par); } + template SLog & operator<<(const TranslateTextHelper & raw) { return TranslateText(raw.par); } diff --git a/templates/locale.cpp b/templates/locale.cpp index 77dcd2f..63fc865 100755 --- a/templates/locale.cpp +++ b/templates/locale.cpp @@ -424,11 +424,6 @@ return locale_files[lang]; } -size_t Locale::Size() -{ - return loc_tab.size(); -} - void Locale::UTF8(bool utf) { diff --git a/templates/locale.h b/templates/locale.h index f49bbd6..a4584a8 100755 --- a/templates/locale.h +++ b/templates/locale.h @@ -64,9 +64,6 @@ public: - // how many languages we have - size_t Size(); - // setting/getting current language // default: 0 void SetLang(size_t lang);