mirror of
https://github.com/tuxbox-neutrino/neutrino.git
synced 2025-08-30 00:41:17 +02:00
yWeb 2.8.a.4
- updated nhttpd - Code clean up - changes to nhttpd.conf - some changes for logo display git-svn-id: file:///home/bas/coolstream_public_svn/THIRDPARTY/applications/neutrino-experimental@416 e54a6e83-5905-42d5-8d5c-058d10e6a962
This commit is contained in:
@@ -8,36 +8,36 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// RFC 2616 / 14.25 If-Modified-Since
|
||||
//
|
||||
// The If-Modified-Since request-header field is used with a method to
|
||||
// make it conditional: if the requested variant has not been modified
|
||||
// since the time specified in this field, an entity will not be
|
||||
// returned from the server; instead, a 304 (not modified) response will
|
||||
// be returned without any message-body.
|
||||
// The If-Modified-Since request-header field is used with a method to
|
||||
// make it conditional: if the requested variant has not been modified
|
||||
// since the time specified in this field, an entity will not be
|
||||
// returned from the server; instead, a 304 (not modified) response will
|
||||
// be returned without any message-body.
|
||||
//
|
||||
// If-Modified-Since = "If-Modified-Since" ":" HTTP-date
|
||||
// An example of the field is:
|
||||
// If-Modified-Since = "If-Modified-Since" ":" HTTP-date
|
||||
// An example of the field is:
|
||||
//
|
||||
// If-Modified-Since: Sat, 29 Oct 1994 19:43:31 GMT
|
||||
// If-Modified-Since: Sat, 29 Oct 1994 19:43:31 GMT
|
||||
//
|
||||
// A GET method with an If-Modified-Since header and no Range header
|
||||
// requests that the identified entity be transferred only if it has
|
||||
// been modified since the date given by the If-Modified-Since header.
|
||||
// The algorithm for determining this includes the following cases:
|
||||
// A GET method with an If-Modified-Since header and no Range header
|
||||
// requests that the identified entity be transferred only if it has
|
||||
// been modified since the date given by the If-Modified-Since header.
|
||||
// The algorithm for determining this includes the following cases:
|
||||
//
|
||||
// a) If the request would normally result in anything other than a
|
||||
// 200 (OK) status, or if the passed If-Modified-Since date is
|
||||
// invalid, the response is exactly the same as for a normal GET.
|
||||
// A date which is later than the server's current time is
|
||||
// invalid.
|
||||
// a) If the request would normally result in anything other than a
|
||||
// 200 (OK) status, or if the passed If-Modified-Since date is
|
||||
// invalid, the response is exactly the same as for a normal GET.
|
||||
// A date which is later than the server's current time is
|
||||
// invalid.
|
||||
//
|
||||
// b) If the variant has been modified since the If-Modified-Since
|
||||
// date, the response is exactly the same as for a normal GET.
|
||||
// b) If the variant has been modified since the If-Modified-Since
|
||||
// date, the response is exactly the same as for a normal GET.
|
||||
//
|
||||
// c) If the variant has not been modified since a valid If-
|
||||
// Modified-Since date, the server SHOULD return a 304 (Not
|
||||
// Modified) response.
|
||||
// c) If the variant has not been modified since a valid If-
|
||||
// Modified-Since date, the server SHOULD return a 304 (Not
|
||||
// Modified) response.
|
||||
//
|
||||
// yjogol: ASSUMPTION Date-Format is ONLY RFC 1123 compatible!
|
||||
// yjogol: ASSUMPTION Date-Format is ONLY RFC 1123 compatible!
|
||||
//=============================================================================
|
||||
|
||||
// system
|
||||
@@ -56,35 +56,30 @@
|
||||
//=============================================================================
|
||||
CStringList CmodSendfile::sendfileTypes;
|
||||
|
||||
//=============================================================================
|
||||
// Constructor & Destructor & Initialization
|
||||
//=============================================================================
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// HOOK: Response Prepare Handler
|
||||
// Response Prepare Check.
|
||||
//-----------------------------------------------------------------------------
|
||||
THandleStatus CmodSendfile::Hook_PrepareResponse(CyhookHandler *hh)
|
||||
{
|
||||
THandleStatus CmodSendfile::Hook_PrepareResponse(CyhookHandler *hh) {
|
||||
hh->status = HANDLED_NONE;
|
||||
|
||||
int filed;
|
||||
log_level_printf(4,"mod_sendfile prepare hook start url:%s\n",hh->UrlData["fullurl"].c_str());
|
||||
log_level_printf(4, "mod_sendfile prepare hook start url:%s\n", hh->UrlData["fullurl"].c_str());
|
||||
std::string mime = sendfileTypes[hh->UrlData["fileext"]];
|
||||
if(((mime != "") || (hh->WebserverConfigList["mod_sendfile.sendAll"] == "true")) && (hh->UrlData["fileext"] != "yhtm"))
|
||||
{
|
||||
if (((mime != "") || (hh->WebserverConfigList["mod_sendfile.sendAll"] == "true"))
|
||||
&& (hh->UrlData["fileext"] != "yhtm")) {
|
||||
//TODO: Check allowed directories / actually in GetFileName
|
||||
// build filename
|
||||
std::string fullfilename = GetFileName(hh, hh->UrlData["path"], hh->UrlData["filename"]);
|
||||
std::string fullfilename = GetFileName(hh, hh->UrlData["path"],
|
||||
hh->UrlData["filename"]);
|
||||
|
||||
if( (filed = OpenFile(hh, fullfilename) ) != -1 ) //can access file?
|
||||
if ((filed = OpenFile(hh, fullfilename)) != -1) //can access file?
|
||||
{
|
||||
struct stat statbuf;
|
||||
hh->LastModified = (time_t)0;
|
||||
hh->LastModified = (time_t) 0;
|
||||
// It is a regular file?
|
||||
fstat(filed,&statbuf);
|
||||
if (S_ISREG(statbuf.st_mode))
|
||||
{
|
||||
fstat(filed, &statbuf);
|
||||
if (S_ISREG(statbuf.st_mode)) {
|
||||
// get file size and modify date
|
||||
hh->ContentLength = statbuf.st_size;
|
||||
hh->LastModified = statbuf.st_mtime;
|
||||
@@ -92,12 +87,11 @@ THandleStatus CmodSendfile::Hook_PrepareResponse(CyhookHandler *hh)
|
||||
close(filed);
|
||||
|
||||
// check If-Modified-Since
|
||||
time_t if_modified_since = (time_t)-1;
|
||||
if(hh->HeaderList["If-Modified-Since"] != "")
|
||||
{
|
||||
time_t if_modified_since = (time_t) - 1;
|
||||
if (hh->HeaderList["If-Modified-Since"] != "") {
|
||||
struct tm mod;
|
||||
if(strptime(hh->HeaderList["If-Modified-Since"].c_str(), RFC1123FMT, &mod) != NULL)
|
||||
{
|
||||
if (strptime(hh->HeaderList["If-Modified-Since"].c_str(),
|
||||
RFC1123FMT, &mod) != NULL) {
|
||||
mod.tm_isdst = 0; // daylight saving flag!
|
||||
if_modified_since = mktime(&mod);
|
||||
}
|
||||
@@ -106,24 +100,23 @@ THandleStatus CmodSendfile::Hook_PrepareResponse(CyhookHandler *hh)
|
||||
// normalize obj_last_modified to GMT
|
||||
struct tm *tmp = gmtime(&(hh->LastModified));
|
||||
time_t LastModifiedGMT = mktime(tmp);
|
||||
bool modified = (if_modified_since == (time_t)-1) || (if_modified_since < LastModifiedGMT);
|
||||
bool modified = (if_modified_since == (time_t) - 1)
|
||||
|| (if_modified_since < LastModifiedGMT);
|
||||
|
||||
// Send normal or not-modified header
|
||||
if(modified)
|
||||
{
|
||||
if (modified) {
|
||||
hh->SendFile(fullfilename);
|
||||
hh->ResponseMimeType = mime;
|
||||
}
|
||||
else
|
||||
} else
|
||||
hh->SetHeader(HTTP_NOT_MODIFIED, mime, HANDLED_READY);
|
||||
}
|
||||
else
|
||||
{
|
||||
aprintf("mod_sendfile: File not found. url:(%s)\n", hh->UrlData["url"].c_str());
|
||||
} else {
|
||||
aprintf("mod_sendfile: File not found. url:(%s) fullfilename:(%s)\n",
|
||||
hh->UrlData["url"].c_str(), fullfilename.c_str());
|
||||
hh->SetError(HTTP_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
log_level_printf(4,"mod_sendfile prepare hook end status:%d\n",(int)hh->status);
|
||||
log_level_printf(4, "mod_sendfile prepare hook end status:%d\n",
|
||||
(int) hh->status);
|
||||
|
||||
return hh->status;
|
||||
}
|
||||
@@ -132,21 +125,21 @@ THandleStatus CmodSendfile::Hook_PrepareResponse(CyhookHandler *hh)
|
||||
// HOOK: Hook_ReadConfig
|
||||
// This hook ist called from ReadConfig
|
||||
//-----------------------------------------------------------------------------
|
||||
THandleStatus CmodSendfile::Hook_ReadConfig(CConfigFile *Config, CStringList &ConfigList)
|
||||
{
|
||||
std::string exttypes = Config->getString("mod_sendfile.mime_types", HTTPD_SENDFILE_EXT);
|
||||
THandleStatus CmodSendfile::Hook_ReadConfig(CConfigFile *Config,
|
||||
CStringList &ConfigList) {
|
||||
std::string exttypes = Config->getString("mod_sendfile.mime_types",
|
||||
HTTPD_SENDFILE_EXT);
|
||||
ConfigList["mod_sendfile.mime_types"] = exttypes;
|
||||
ConfigList["mod_sendfile.sendAll"] = Config->getString("mod_sendfile.sendAll", HTTPD_SENDFILE_ALL);
|
||||
ConfigList["mod_sendfile.sendAll"] = Config->getString(
|
||||
"mod_sendfile.sendAll", HTTPD_SENDFILE_ALL);
|
||||
|
||||
bool ende = false;
|
||||
std::string item, ext, mime;
|
||||
sendfileTypes.clear();
|
||||
while(!ende)
|
||||
{
|
||||
if(!ySplitStringExact(exttypes,",",item,exttypes))
|
||||
while (!ende) {
|
||||
if (!ySplitStringExact(exttypes, ",", item, exttypes))
|
||||
ende = true;
|
||||
if(ySplitStringExact(item,":",ext,mime))
|
||||
{
|
||||
if (ySplitStringExact(item, ":", ext, mime)) {
|
||||
ext = trim(ext);
|
||||
sendfileTypes[ext] = trim(mime);
|
||||
}
|
||||
@@ -158,28 +151,25 @@ THandleStatus CmodSendfile::Hook_ReadConfig(CConfigFile *Config, CStringList &Co
|
||||
// Send File: Build Filename
|
||||
// First Look at PublicDocumentRoot than PrivateDocumentRoot than pure path
|
||||
//-----------------------------------------------------------------------------
|
||||
std::string CmodSendfile::GetFileName(CyhookHandler *hh, std::string path, std::string filename)
|
||||
{
|
||||
std::string CmodSendfile::GetFileName(CyhookHandler *hh, std::string path, std::string filename) {
|
||||
std::string tmpfilename;
|
||||
if(path[path.length()-1] != '/')
|
||||
if (path[path.length() - 1] != '/')
|
||||
tmpfilename = path + "/" + filename;
|
||||
else
|
||||
tmpfilename = path + filename;
|
||||
|
||||
if( access(std::string(hh->WebserverConfigList["PublicDocumentRoot"] + tmpfilename).c_str(),4) == 0)
|
||||
tmpfilename = hh->WebserverConfigList["PublicDocumentRoot"] + tmpfilename;
|
||||
else if( access(std::string(hh->WebserverConfigList["PublicDocumentRoot"] + tmpfilename + ".gz").c_str(),4) == 0)
|
||||
tmpfilename = hh->WebserverConfigList["PublicDocumentRoot"] + tmpfilename + ".gz";
|
||||
else if(access(std::string(hh->WebserverConfigList["PrivatDocumentRoot"] + tmpfilename).c_str(),4) == 0)
|
||||
tmpfilename = hh->WebserverConfigList["PrivatDocumentRoot"] + tmpfilename;
|
||||
else if(access(std::string(hh->WebserverConfigList["PrivatDocumentRoot"] + tmpfilename + ".gz").c_str(),4) == 0)
|
||||
tmpfilename = hh->WebserverConfigList["PrivatDocumentRoot"] + tmpfilename + ".gz";
|
||||
if (access(std::string(hh->WebserverConfigList["WebsiteMain.override_directory"] + tmpfilename).c_str(), 4) == 0)
|
||||
tmpfilename = hh->WebserverConfigList["WebsiteMain.override_directory"] + tmpfilename;
|
||||
else if (access(std::string(hh->WebserverConfigList["WebsiteMain.override_directory"] + tmpfilename + ".gz").c_str(), 4) == 0)
|
||||
tmpfilename = hh->WebserverConfigList["WebsiteMain.override_directory"] + tmpfilename + ".gz";
|
||||
else if (access(std::string(hh->WebserverConfigList["WebsiteMain.directory"] + tmpfilename).c_str(), 4) == 0)
|
||||
tmpfilename = hh->WebserverConfigList["WebsiteMain.directory"] + tmpfilename;
|
||||
else if (access(std::string(hh->WebserverConfigList["WebsiteMain.directory"] + tmpfilename + ".gz").c_str(), 4) == 0)
|
||||
tmpfilename = hh->WebserverConfigList["WebsiteMain.directory"] + tmpfilename + ".gz";
|
||||
#ifdef Y_CONFIG_FEATUE_SENDFILE_CAN_ACCESS_ALL
|
||||
else if(access(tmpfilename.c_str(),4) == 0)
|
||||
;
|
||||
;
|
||||
#endif
|
||||
else
|
||||
{
|
||||
else {
|
||||
return "";
|
||||
}
|
||||
return tmpfilename;
|
||||
@@ -187,15 +177,12 @@ std::string CmodSendfile::GetFileName(CyhookHandler *hh, std::string path, std::
|
||||
//-----------------------------------------------------------------------------
|
||||
// Send File: Open File and check file type
|
||||
//-----------------------------------------------------------------------------
|
||||
int CmodSendfile::OpenFile(CyhookHandler *, std::string fullfilename)
|
||||
{
|
||||
int fd= -1;
|
||||
int CmodSendfile::OpenFile(CyhookHandler *, std::string fullfilename) {
|
||||
int fd = -1;
|
||||
std::string tmpstring;
|
||||
if(fullfilename.length() > 0)
|
||||
{
|
||||
fd = open( fullfilename.c_str(), O_RDONLY );
|
||||
if (fd<=0)
|
||||
{
|
||||
if (fullfilename.length() > 0) {
|
||||
fd = open(fullfilename.c_str(), O_RDONLY);
|
||||
if (fd <= 0) {
|
||||
aprintf("cannot open file %s: ", fullfilename.c_str());
|
||||
dperror("");
|
||||
}
|
||||
@@ -203,15 +190,14 @@ int CmodSendfile::OpenFile(CyhookHandler *, std::string fullfilename)
|
||||
return fd;
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
// Send File: Determine MIME-Type fro File-Extention
|
||||
// Send File: Determine MIME-Type for File-Extention
|
||||
//-----------------------------------------------------------------------------
|
||||
std::string CmodSendfile::GetContentType(std::string ext)
|
||||
{
|
||||
std::string CmodSendfile::GetContentType(std::string ext) {
|
||||
std::string ctype = "text/plain";
|
||||
ext = string_tolower(ext);
|
||||
for (unsigned int i = 0;i < (sizeof(MimeFileExtensions)/sizeof(MimeFileExtensions[0])); i++)
|
||||
if (MimeFileExtensions[i].fileext == ext)
|
||||
{
|
||||
for (unsigned int i = 0; i < (sizeof(MimeFileExtensions)
|
||||
/ sizeof(MimeFileExtensions[0])); i++)
|
||||
if (MimeFileExtensions[i].fileext == ext) {
|
||||
ctype = MimeFileExtensions[i].mime;
|
||||
break;
|
||||
}
|
||||
|
Reference in New Issue
Block a user